use of com.google.android.exoplayer2.source.rtsp.RtspClient.SessionInfoListener in project ExoPlayer by google.
the class RtspClientTest method connectServerAndClient_serverDoesNotSupportDescribe_doesNotUpdateTimeline.
@Test
public void connectServerAndClient_serverDoesNotSupportDescribe_doesNotUpdateTimeline() throws Exception {
AtomicBoolean clientHasSentDescribeRequest = new AtomicBoolean();
class ResponseProvider implements RtspServer.ResponseProvider {
@Override
public RtspResponse getOptionsResponse() {
return new RtspResponse(/* status= */
200, new RtspHeaders.Builder().add(RtspHeaders.PUBLIC, "OPTIONS").build());
}
@Override
public RtspResponse getDescribeResponse(Uri requestedUri, RtspHeaders headers) {
clientHasSentDescribeRequest.set(true);
return RtspTestUtils.RTSP_ERROR_METHOD_NOT_ALLOWED;
}
}
rtspServer = new RtspServer(new ResponseProvider());
AtomicReference<String> failureMessage = new AtomicReference<>();
rtspClient = new RtspClient(new SessionInfoListener() {
@Override
public void onSessionTimelineUpdated(RtspSessionTiming timing, ImmutableList<RtspMediaTrack> tracks) {
}
@Override
public void onSessionTimelineRequestFailed(String message, @Nullable Throwable cause) {
failureMessage.set(message);
}
}, EMPTY_PLAYBACK_LISTENER, /* userAgent= */
"ExoPlayer:RtspClientTest", RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()), SocketFactory.getDefault(), /* debugLoggingEnabled= */
false);
rtspClient.start();
RobolectricUtil.runMainLooperUntil(() -> failureMessage.get() != null);
assertThat(failureMessage.get()).contains("DESCRIBE not supported.");
assertThat(clientHasSentDescribeRequest.get()).isFalse();
assertThat(rtspClient.getState()).isEqualTo(RtspClient.RTSP_STATE_UNINITIALIZED);
}
use of com.google.android.exoplayer2.source.rtsp.RtspClient.SessionInfoListener 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();
}
Aggregations