Search in sources :

Example 1 with DefaultAllocator

use of androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.

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);
}
Also used : Uri(android.net.Uri) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Util(androidx.media3.common.util.Util) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator) SocketFactory(javax.net.SocketFactory) C(androidx.media3.common.C) AtomicLong(java.util.concurrent.atomic.AtomicLong) ImmutableList(com.google.common.collect.ImmutableList) RobolectricUtil(androidx.media3.test.utils.robolectric.RobolectricUtil) After(org.junit.After) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod) Uri(android.net.Uri) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod) Test(org.junit.Test)

Example 2 with DefaultAllocator

use of androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.

the class DecoderAudioRendererTest method immediatelyReadEndOfStreamPlaysAudioSinkToEndOfStream.

@Test
public void immediatelyReadEndOfStreamPlaysAudioSinkToEndOfStream() throws Exception {
    FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
    true, /* individualAllocationSize= */
    1024), /* mediaSourceEventDispatcher= */
    null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), FORMAT, ImmutableList.of(END_OF_STREAM_ITEM));
    fakeSampleStream.writeData(/* startPositionUs= */
    0);
    audioRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { FORMAT }, fakeSampleStream, /* positionUs= */
    0, /* joining= */
    false, /* mayRenderStartOfStream= */
    true, /* startPositionUs= */
    0, /* offsetUs= */
    0);
    audioRenderer.setCurrentStreamFinal();
    when(mockAudioSink.isEnded()).thenReturn(true);
    while (!audioRenderer.isEnded()) {
        audioRenderer.render(0, 0);
    }
    verify(mockAudioSink, times(1)).playToEndOfStream();
    audioRenderer.disable();
    audioRenderer.reset();
    verify(mockAudioSink, times(1)).reset();
}
Also used : FakeSampleStream(androidx.media3.test.utils.FakeSampleStream) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) Test(org.junit.Test)

Example 3 with DefaultAllocator

use of androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.

the class MediaCodecAudioRendererTest method render_configuresAudioSink_afterFormatChange.

@Test
public void render_configuresAudioSink_afterFormatChange() throws Exception {
    Format changedFormat = AUDIO_AAC.buildUpon().setSampleRate(48_000).setEncoderDelay(400).build();
    FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
    true, /* individualAllocationSize= */
    1024), /* mediaSourceEventDispatcher= */
    null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
    AUDIO_AAC, ImmutableList.of(oneByteSample(/* timeUs= */
    0, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(/* timeUs= */
    50, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(/* timeUs= */
    100, C.BUFFER_FLAG_KEY_FRAME), format(changedFormat), oneByteSample(/* timeUs= */
    150, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(/* timeUs= */
    200, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(/* timeUs= */
    250, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
    fakeSampleStream.writeData(/* startPositionUs= */
    0);
    mediaCodecAudioRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { AUDIO_AAC, changedFormat }, fakeSampleStream, /* positionUs= */
    0, /* joining= */
    false, /* mayRenderStartOfStream= */
    false, /* startPositionUs= */
    0, /* offsetUs */
    0);
    mediaCodecAudioRenderer.start();
    mediaCodecAudioRenderer.render(/* positionUs= */
    0, SystemClock.elapsedRealtime() * 1000);
    mediaCodecAudioRenderer.render(/* positionUs= */
    250, SystemClock.elapsedRealtime() * 1000);
    mediaCodecAudioRenderer.setCurrentStreamFinal();
    int positionUs = 500;
    do {
        mediaCodecAudioRenderer.render(positionUs, SystemClock.elapsedRealtime() * 1000);
        positionUs += 250;
    } while (!mediaCodecAudioRenderer.isEnded());
    verify(audioSink).configure(getAudioSinkFormat(AUDIO_AAC), /* specifiedBufferSize= */
    0, /* outputChannels= */
    null);
    verify(audioSink).configure(getAudioSinkFormat(changedFormat), /* specifiedBufferSize= */
    0, /* outputChannels= */
    null);
}
Also used : FakeSampleStream(androidx.media3.test.utils.FakeSampleStream) MediaFormat(android.media.MediaFormat) Format(androidx.media3.common.Format) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) Test(org.junit.Test)

Example 4 with DefaultAllocator

use of androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.

the class MetadataRendererTest method runRenderer.

private static List<Metadata> runRenderer(byte[] input) throws ExoPlaybackException {
    List<Metadata> metadata = new ArrayList<>();
    MetadataRenderer renderer = new MetadataRenderer(metadata::add, /* outputLooper= */
    null);
    FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
    true, /* individualAllocationSize= */
    1024), /* mediaSourceEventDispatcher= */
    null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), EMSG_FORMAT, ImmutableList.of(sample(/* timeUs= */
    0, C.BUFFER_FLAG_KEY_FRAME, input), END_OF_STREAM_ITEM));
    fakeSampleStream.writeData(/* startPositionUs= */
    0);
    renderer.replaceStream(new Format[] { EMSG_FORMAT }, fakeSampleStream, /* startPositionUs= */
    0L, /* offsetUs= */
    0L);
    // Read the format
    renderer.render(/* positionUs= */
    0, /* elapsedRealtimeUs= */
    0);
    // Read the data
    renderer.render(/* positionUs= */
    0, /* elapsedRealtimeUs= */
    0);
    return Collections.unmodifiableList(metadata);
}
Also used : FakeSampleStream(androidx.media3.test.utils.FakeSampleStream) Metadata(androidx.media3.common.Metadata) ArrayList(java.util.ArrayList) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener)

Example 5 with DefaultAllocator

use of androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.

the class DecoderVideoRendererTest method enable_withMayRenderStartOfStream_rendersFirstFrameBeforeStart.

@Test
public void enable_withMayRenderStartOfStream_rendersFirstFrameBeforeStart() throws Exception {
    FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
    true, /* individualAllocationSize= */
    1024), /* mediaSourceEventDispatcher= */
    null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
    H264_FORMAT, ImmutableList.of(oneByteSample(/* timeUs= */
    0, C.BUFFER_FLAG_KEY_FRAME)));
    fakeSampleStream.writeData(/* startPositionUs= */
    0);
    renderer.enable(RendererConfiguration.DEFAULT, new Format[] { H264_FORMAT }, fakeSampleStream, /* positionUs= */
    0, /* joining= */
    false, /* mayRenderStartOfStream= */
    true, /* startPositionUs= */
    0L, /* offsetUs */
    0);
    for (int i = 0; i < 10; i++) {
        renderer.render(/* positionUs= */
        0, SystemClock.elapsedRealtime() * 1000);
        // Ensure pending messages are delivered.
        ShadowLooper.idleMainLooper();
    }
    verify(eventListener).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
    anyLong());
}
Also used : FakeSampleStream(androidx.media3.test.utils.FakeSampleStream) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) Test(org.junit.Test)

Aggregations

DefaultAllocator (androidx.media3.exoplayer.upstream.DefaultAllocator)24 DrmSessionEventListener (androidx.media3.exoplayer.drm.DrmSessionEventListener)21 Test (org.junit.Test)21 FakeSampleStream (androidx.media3.test.utils.FakeSampleStream)19 MediaFormat (android.media.MediaFormat)4 C (androidx.media3.common.C)4 Format (androidx.media3.common.Format)4 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 RunWith (org.junit.runner.RunWith)4 Uri (android.net.Uri)3 ImmutableList (com.google.common.collect.ImmutableList)3 After (org.junit.After)3 ShadowLooper (org.robolectric.shadows.ShadowLooper)3 Nullable (androidx.annotation.Nullable)2 VideoSize (androidx.media3.common.VideoSize)2 Util (androidx.media3.common.util.Util)2 PlayerId (androidx.media3.exoplayer.analytics.PlayerId)2 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)2 MediaPeriod (androidx.media3.exoplayer.source.MediaPeriod)2