use of com.google.android.exoplayer2.robolectric.RobolectricUtil.runMainLooperUntil in project ExoPlayer by google.
the class RtspClientTest method connectServerAndClient_usesCustomSocketFactory.
@Test
public void connectServerAndClient_usesCustomSocketFactory() throws Exception {
class ResponseProvider implements RtspServer.ResponseProvider {
@Override
public RtspResponse getOptionsResponse() {
return new RtspResponse(/* status= */
200, new RtspHeaders.Builder().add(RtspHeaders.PUBLIC, "OPTIONS, DESCRIBE").build());
}
@Override
public RtspResponse getDescribeResponse(Uri requestedUri, RtspHeaders headers) {
return RtspTestUtils.newDescribeResponseWithSdpMessage(SESSION_DESCRIPTION, rtpPacketStreamDumps, requestedUri);
}
}
rtspServer = new RtspServer(new ResponseProvider());
AtomicBoolean didCallCreateSocket = new AtomicBoolean();
SocketFactory socketFactory = new SocketFactory() {
@Override
public Socket createSocket(String host, int port) throws IOException {
didCallCreateSocket.set(true);
return SocketFactory.getDefault().createSocket(host, port);
}
@Override
public Socket createSocket(String s, int i, InetAddress inetAddress, int i1) throws IOException {
didCallCreateSocket.set(true);
return SocketFactory.getDefault().createSocket(s, i, inetAddress, i1);
}
@Override
public Socket createSocket(InetAddress inetAddress, int i) throws IOException {
didCallCreateSocket.set(true);
return SocketFactory.getDefault().createSocket(inetAddress, i);
}
@Override
public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress1, int i1) throws IOException {
didCallCreateSocket.set(true);
return SocketFactory.getDefault().createSocket(inetAddress, i, inetAddress1, i1);
}
};
AtomicReference<ImmutableList<RtspMediaTrack>> tracksInSession = new AtomicReference<>();
rtspClient = new RtspClient(new SessionInfoListener() {
@Override
public void onSessionTimelineUpdated(RtspSessionTiming timing, ImmutableList<RtspMediaTrack> tracks) {
tracksInSession.set(tracks);
}
@Override
public void onSessionTimelineRequestFailed(String message, @Nullable Throwable cause) {
}
}, EMPTY_PLAYBACK_LISTENER, /* userAgent= */
"ExoPlayer:RtspClientTest", RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()), socketFactory, /* debugLoggingEnabled= */
false);
rtspClient.start();
RobolectricUtil.runMainLooperUntil(() -> tracksInSession.get() != null);
assertThat(didCallCreateSocket.get()).isTrue();
}
use of com.google.android.exoplayer2.robolectric.RobolectricUtil.runMainLooperUntil in project ExoPlayer by google.
the class RtspMediaPeriodTest method prepareMediaPeriod_refreshesSourceInfoAndCallsOnPrepared.
@Test
public void prepareMediaPeriod_refreshesSourceInfoAndCallsOnPrepared() throws Exception {
RtpPacketStreamDump rtpPacketStreamDump = RtspTestUtils.readRtpPacketStreamDump("media/rtsp/aac-dump.json");
rtspServer = new RtspServer(new RtspServer.ResponseProvider() {
@Override
public RtspResponse getOptionsResponse() {
return new RtspResponse(/* status= */
200, new RtspHeaders.Builder().add(RtspHeaders.PUBLIC, "OPTIONS, DESCRIBE").build());
}
@Override
public RtspResponse getDescribeResponse(Uri requestedUri, RtspHeaders headers) {
return RtspTestUtils.newDescribeResponseWithSdpMessage("v=0\r\n" + "o=- 1606776316530225 1 IN IP4 127.0.0.1\r\n" + "s=Exoplayer test\r\n" + "t=0 0\r\n" + // The session is 50.46s long.
"a=range:npt=0-50.46\r\n", ImmutableList.of(rtpPacketStreamDump), requestedUri);
}
});
AtomicBoolean prepareCallbackCalled = new AtomicBoolean();
AtomicLong refreshedSourceDurationMs = new AtomicLong();
mediaPeriod = new RtspMediaPeriod(new DefaultAllocator(/* trimOnReset= */
true, C.DEFAULT_BUFFER_SEGMENT_SIZE), new TransferRtpDataChannelFactory(DEFAULT_TIMEOUT_MS), RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()), /* listener= */
timing -> refreshedSourceDurationMs.set(timing.getDurationMs()), /* userAgent= */
"ExoPlayer:RtspPeriodTest", /* socketFactory= */
SocketFactory.getDefault(), /* debugLoggingEnabled= */
false);
mediaPeriod.prepare(new MediaPeriod.Callback() {
@Override
public void onPrepared(MediaPeriod mediaPeriod) {
prepareCallbackCalled.set(true);
}
@Override
public void onContinueLoadingRequested(MediaPeriod source) {
source.continueLoading(/* positionUs= */
0);
}
}, /* positionUs= */
0);
RobolectricUtil.runMainLooperUntil(prepareCallbackCalled::get);
mediaPeriod.release();
assertThat(refreshedSourceDurationMs.get()).isEqualTo(50_460);
}
use of com.google.android.exoplayer2.robolectric.RobolectricUtil.runMainLooperUntil in project ExoPlayer by google.
the class DefaultHlsPlaylistTrackerTest method runPlaylistTrackerAndCollectMediaPlaylists.
private static List<HlsMediaPlaylist> runPlaylistTrackerAndCollectMediaPlaylists(DataSource.Factory dataSourceFactory, Uri multivariantPlaylistUri, int awaitedMediaPlaylistCount) throws TimeoutException {
DefaultHlsPlaylistTracker defaultHlsPlaylistTracker = new DefaultHlsPlaylistTracker(dataType -> dataSourceFactory.createDataSource(), new DefaultLoadErrorHandlingPolicy(), new DefaultHlsPlaylistParserFactory());
List<HlsMediaPlaylist> mediaPlaylists = new ArrayList<>();
AtomicInteger playlistCounter = new AtomicInteger();
defaultHlsPlaylistTracker.start(multivariantPlaylistUri, new MediaSourceEventListener.EventDispatcher(), mediaPlaylist -> {
mediaPlaylists.add(mediaPlaylist);
playlistCounter.addAndGet(1);
});
RobolectricUtil.runMainLooperUntil(() -> playlistCounter.get() >= awaitedMediaPlaylistCount);
defaultHlsPlaylistTracker.stop();
return mediaPlaylists;
}
Aggregations