Search in sources :

Example 1 with SessionInfoListener

use of androidx.media3.exoplayer.rtsp.RtspClient.SessionInfoListener in project media by androidx.

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();
}
Also used : SocketFactory(javax.net.SocketFactory) ImmutableList(com.google.common.collect.ImmutableList) AtomicReference(java.util.concurrent.atomic.AtomicReference) Uri(android.net.Uri) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SessionInfoListener(androidx.media3.exoplayer.rtsp.RtspClient.SessionInfoListener) InetAddress(java.net.InetAddress) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 2 with SessionInfoListener

use of androidx.media3.exoplayer.rtsp.RtspClient.SessionInfoListener in project media by androidx.

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);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) AtomicReference(java.util.concurrent.atomic.AtomicReference) Uri(android.net.Uri) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SessionInfoListener(androidx.media3.exoplayer.rtsp.RtspClient.SessionInfoListener) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Aggregations

Uri (android.net.Uri)2 Nullable (androidx.annotation.Nullable)2 SessionInfoListener (androidx.media3.exoplayer.rtsp.RtspClient.SessionInfoListener)2 ImmutableList (com.google.common.collect.ImmutableList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.Test)2 InetAddress (java.net.InetAddress)1 SocketFactory (javax.net.SocketFactory)1