Search in sources :

Example 26 with MediaPeriod

use of com.google.android.exoplayer2.source.MediaPeriod in project ExoPlayer by google.

the class ExoPlayerTest method infiniteLoading_withSmallAllocations_oomIsPreventedByLoadControl_andThrowsStuckBufferingIllegalStateException.

@Test
public void infiniteLoading_withSmallAllocations_oomIsPreventedByLoadControl_andThrowsStuckBufferingIllegalStateException() {
    DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setTargetBufferBytes(10 * C.DEFAULT_BUFFER_SEGMENT_SIZE).build();
    // Return no end of stream signal to prevent playback from ending.
    FakeMediaPeriod.TrackDataFactory trackDataWithoutEos = (format, periodId) -> ImmutableList.of();
    MediaSource continuouslyAllocatingMediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            return new FakeMediaPeriod(trackGroupArray, allocator, trackDataWithoutEos, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            false) {

                private final List<Allocation> allocations = new ArrayList<>();

                private Callback callback;

                @Override
                public synchronized void prepare(Callback callback, long positionUs) {
                    this.callback = callback;
                    super.prepare(callback, positionUs);
                }

                @Override
                public long getBufferedPositionUs() {
                    // Pretend not to make loading progress, so that continueLoading keeps being called.
                    return 0;
                }

                @Override
                public long getNextLoadPositionUs() {
                    // Pretend not to make loading progress, so that continueLoading keeps being called.
                    return 0;
                }

                @Override
                public boolean continueLoading(long positionUs) {
                    allocations.add(allocator.allocate());
                    callback.onContinueLoadingRequested(this);
                    return true;
                }
            };
        }
    };
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(continuouslyAllocatingMediaSource).setLoadControl(loadControl).build();
    ExoPlaybackException exception = assertThrows(ExoPlaybackException.class, () -> testRunner.start().blockUntilEnded(TIMEOUT_MS));
    assertThat(exception.type).isEqualTo(ExoPlaybackException.TYPE_UNEXPECTED);
    assertThat(exception.getUnexpectedException()).isInstanceOf(IllegalStateException.class);
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) COMMAND_SEEK_TO_NEXT_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Uri(android.net.Uri) BinaryFrame(com.google.android.exoplayer2.metadata.id3.BinaryFrame) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeTrackSelector(com.google.android.exoplayer2.testutil.FakeTrackSelector) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) COMMAND_SEEK_TO_PREVIOUS(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) TestPlayerRunHelper.runUntilTimelineChanged(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilTimelineChanged) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) TestPlayerRunHelper.playUntilStartOfMediaItem(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM) Looper(android.os.Looper) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) COMMAND_GET_TRACK_INFOS(com.google.android.exoplayer2.Player.COMMAND_GET_TRACK_INFOS) TextInformationFrame(com.google.android.exoplayer2.metadata.id3.TextInformationFrame) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) Surface(android.view.Surface) DEFAULT_WINDOW_DURATION_US(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Range(com.google.common.collect.Range) FakeClock(com.google.android.exoplayer2.testutil.FakeClock) CountDownLatch(java.util.concurrent.CountDownLatch) COMMAND_STOP(com.google.android.exoplayer2.Player.COMMAND_STOP) Nullable(androidx.annotation.Nullable) ArgumentMatchers.anyFloat(org.mockito.ArgumentMatchers.anyFloat) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) COMMAND_GET_TEXT(com.google.android.exoplayer2.Player.COMMAND_GET_TEXT) Mockito.mock(org.mockito.Mockito.mock) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled) Iterables(com.google.common.collect.Iterables) COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) Listener(com.google.android.exoplayer2.Player.Listener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TestPlayerRunHelper.runUntilPositionDiscontinuity(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPositionDiscontinuity) FakeChunkSource(com.google.android.exoplayer2.testutil.FakeChunkSource) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) Before(org.junit.Before) DiscontinuityReason(com.google.android.exoplayer2.Player.DiscontinuityReason) COMMAND_GET_CURRENT_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_GET_CURRENT_MEDIA_ITEM) Clock(com.google.android.exoplayer2.util.Clock) ShadowLooper(org.robolectric.shadows.ShadowLooper) COMMAND_GET_TIMELINE(com.google.android.exoplayer2.Player.COMMAND_GET_TIMELINE) PlayerTarget(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerTarget) COMMAND_SET_TRACK_SELECTION_PARAMETERS(com.google.android.exoplayer2.Player.COMMAND_SET_TRACK_SELECTION_PARAMETERS) TestPlayerRunHelper.runUntilReceiveOffloadSchedulingEnabledNewState(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilReceiveOffloadSchedulingEnabledNewState) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) TrackSelectionArray(com.google.android.exoplayer2.trackselection.TrackSelectionArray) TestUtil.assertTimelinesSame(com.google.android.exoplayer2.testutil.TestUtil.assertTimelinesSame) TestPlayerRunHelper(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito.never(org.mockito.Mockito.never) COMMAND_SEEK_TO_DEFAULT_POSITION(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_DEFAULT_POSITION) COMMAND_GET_AUDIO_ATTRIBUTES(com.google.android.exoplayer2.Player.COMMAND_GET_AUDIO_ATTRIBUTES) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) Loader(com.google.android.exoplayer2.upstream.Loader) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) Mockito.reset(org.mockito.Mockito.reset) COMMAND_PREPARE(com.google.android.exoplayer2.Player.COMMAND_PREPARE) Assertions(com.google.android.exoplayer2.util.Assertions) COMMAND_CHANGE_MEDIA_ITEMS(com.google.android.exoplayer2.Player.COMMAND_CHANGE_MEDIA_ITEMS) Util(com.google.android.exoplayer2.util.Util) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) COMMAND_SEEK_TO_NEXT(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) Random(java.util.Random) TestPlayerRunHelper.playUntilPosition(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilPosition) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArgumentMatcher(org.mockito.ArgumentMatcher) Allocation(com.google.android.exoplayer2.upstream.Allocation) COMMAND_SET_VOLUME(com.google.android.exoplayer2.Player.COMMAND_SET_VOLUME) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) Mockito.atLeast(org.mockito.Mockito.atLeast) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) Assert.fail(org.junit.Assert.fail) COMMAND_SEEK_BACK(com.google.android.exoplayer2.Player.COMMAND_SEEK_BACK) MediaSource(com.google.android.exoplayer2.source.MediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) COMMAND_GET_MEDIA_ITEMS_METADATA(com.google.android.exoplayer2.Player.COMMAND_GET_MEDIA_ITEMS_METADATA) RobolectricUtil.runMainLooperUntil(com.google.android.exoplayer2.robolectric.RobolectricUtil.runMainLooperUntil) TestPlayerRunHelper.runUntilPlaybackState(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPlaybackState) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) COMMAND_ADJUST_DEVICE_VOLUME(com.google.android.exoplayer2.Player.COMMAND_ADJUST_DEVICE_VOLUME) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Collectors(java.util.stream.Collectors) COMMAND_SET_REPEAT_MODE(com.google.android.exoplayer2.Player.COMMAND_SET_REPEAT_MODE) COMMAND_SET_SHUFFLE_MODE(com.google.android.exoplayer2.Player.COMMAND_SET_SHUFFLE_MODE) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) List(java.util.List) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) COMMAND_GET_VOLUME(com.google.android.exoplayer2.Player.COMMAND_GET_VOLUME) Mockito.inOrder(org.mockito.Mockito.inOrder) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) FakeAdaptiveDataSet(com.google.android.exoplayer2.testutil.FakeAdaptiveDataSet) COMMAND_PLAY_PAUSE(com.google.android.exoplayer2.Player.COMMAND_PLAY_PAUSE) Action(com.google.android.exoplayer2.testutil.Action) AdditionalMatchers.not(org.mockito.AdditionalMatchers.not) AudioAttributes(com.google.android.exoplayer2.audio.AudioAttributes) Metadata(com.google.android.exoplayer2.metadata.Metadata) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) COMMAND_GET_DEVICE_VOLUME(com.google.android.exoplayer2.Player.COMMAND_GET_DEVICE_VOLUME) COMMAND_SEEK_FORWARD(com.google.android.exoplayer2.Player.COMMAND_SEEK_FORWARD) Context(android.content.Context) COMMAND_SEEK_TO_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_MEDIA_ITEM) COMMAND_SET_MEDIA_ITEMS_METADATA(com.google.android.exoplayer2.Player.COMMAND_SET_MEDIA_ITEMS_METADATA) DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) Assert.assertThrows(org.junit.Assert.assertThrows) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Intent(android.content.Intent) AtomicReference(java.util.concurrent.atomic.AtomicReference) STATE_ENDED(com.google.android.exoplayer2.Player.STATE_ENDED) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) AudioManager(android.media.AudioManager) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) ShadowAudioManager(org.robolectric.shadows.ShadowAudioManager) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ImmutableList(com.google.common.collect.ImmutableList) TestPlayerRunHelper.runUntilSleepingForOffload(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilSleepingForOffload) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) COMMAND_SET_DEVICE_VOLUME(com.google.android.exoplayer2.Player.COMMAND_SET_DEVICE_VOLUME) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) COMMAND_SET_SPEED_AND_PITCH(com.google.android.exoplayer2.Player.COMMAND_SET_SPEED_AND_PITCH) Allocator(com.google.android.exoplayer2.upstream.Allocator) SurfaceTexture(android.graphics.SurfaceTexture) COMMAND_SET_VIDEO_SURFACE(com.google.android.exoplayer2.Player.COMMAND_SET_VIDEO_SURFACE) Window(com.google.android.exoplayer2.Timeline.Window) FakeSampleStreamItem(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem) InOrder(org.mockito.InOrder) PositionInfo(com.google.android.exoplayer2.Player.PositionInfo) Truth.assertThat(com.google.common.truth.Truth.assertThat) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) Mockito.verify(org.mockito.Mockito.verify) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSourceFactory(com.google.android.exoplayer2.testutil.FakeMediaSourceFactory) Mockito(org.mockito.Mockito) FakeTrackSelection(com.google.android.exoplayer2.testutil.FakeTrackSelection) Collections(java.util.Collections) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Allocator(com.google.android.exoplayer2.upstream.Allocator) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 27 with MediaPeriod

use of com.google.android.exoplayer2.source.MediaPeriod in project ExoPlayer by google.

the class ExoPlayerTest method setPlaybackSpeedBeforePreparationCompletesSucceeds.

@Test
public void setPlaybackSpeedBeforePreparationCompletesSucceeds() throws Exception {
    // Test that no exception is thrown when playback parameters are updated between creating a
    // period and preparation of the period completing.
    final CountDownLatch createPeriodCalledCountDownLatch = new CountDownLatch(1);
    final FakeMediaPeriod[] fakeMediaPeriodHolder = new FakeMediaPeriod[1];
    MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            // Defer completing preparation of the period until playback parameters have been set.
            fakeMediaPeriodHolder[0] = new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            true);
            createPeriodCalledCountDownLatch.countDown();
            return fakeMediaPeriodHolder[0];
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            try {
                player.getClock().onThreadBlocked();
                createPeriodCalledCountDownLatch.await();
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
        }
    }).setPlaybackParameters(new PlaybackParameters(/* speed= */
    2f)).executeRunnable(() -> fakeMediaPeriodHolder[0].setPreparationComplete()).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
}
Also used : TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Allocator(com.google.android.exoplayer2.upstream.Allocator) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) CountDownLatch(java.util.concurrent.CountDownLatch) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 28 with MediaPeriod

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

Example 29 with MediaPeriod

use of com.google.android.exoplayer2.source.MediaPeriod in project ExoPlayer by google.

the class SsMediaSource method createPeriod.

@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
    MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher = createEventDispatcher(id);
    DrmSessionEventListener.EventDispatcher drmEventDispatcher = createDrmEventDispatcher(id);
    SsMediaPeriod period = new SsMediaPeriod(manifest, chunkSourceFactory, mediaTransferListener, compositeSequenceableLoaderFactory, drmSessionManager, drmEventDispatcher, loadErrorHandlingPolicy, mediaSourceEventDispatcher, manifestLoaderErrorThrower, allocator);
    mediaPeriods.add(period);
    return period;
}
Also used : EventDispatcher(com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener)

Example 30 with MediaPeriod

use of com.google.android.exoplayer2.source.MediaPeriod in project ExoPlayer by google.

the class DashMediaSource method createPeriod.

@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
    int periodIndex = (Integer) id.periodUid - firstPeriodId;
    MediaSourceEventListener.EventDispatcher periodEventDispatcher = createEventDispatcher(id, manifest.getPeriod(periodIndex).startMs);
    DrmSessionEventListener.EventDispatcher drmEventDispatcher = createDrmEventDispatcher(id);
    DashMediaPeriod mediaPeriod = new DashMediaPeriod(firstPeriodId + periodIndex, manifest, baseUrlExclusionList, periodIndex, chunkSourceFactory, mediaTransferListener, drmSessionManager, drmEventDispatcher, loadErrorHandlingPolicy, periodEventDispatcher, elapsedRealtimeOffsetMs, manifestLoadErrorThrower, allocator, compositeSequenceableLoaderFactory, playerEmsgCallback, getPlayerId());
    periodsById.put(mediaPeriod.id, mediaPeriod);
    return mediaPeriod;
}
Also used : EventDispatcher(com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener)

Aggregations

MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)23 Test (org.junit.Test)21 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)18 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)17 Nullable (androidx.annotation.Nullable)15 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)15 Allocator (com.google.android.exoplayer2.upstream.Allocator)15 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)14 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)14 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)14 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)13 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)11 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)8 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)7 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)7 MediaSource (com.google.android.exoplayer2.source.MediaSource)7 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)7 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)7