Search in sources :

Example 26 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class DefaultRenderersFactoryAsserts method assertExtensionRendererCreated.

/**
 * Asserts that an extension renderer of type {@code clazz} is not instantiated for {@link
 * DefaultRenderersFactory#EXTENSION_RENDERER_MODE_OFF}, and that it's instantiated in the correct
 * position relative to other renderers of the same type for {@link
 * DefaultRenderersFactory#EXTENSION_RENDERER_MODE_ON} and {@link
 * DefaultRenderersFactory#EXTENSION_RENDERER_MODE_PREFER}, assuming no other extension renderers
 * can be loaded.
 *
 * @param clazz The extension renderer class.
 * @param type The type of the renderer.
 */
public static void assertExtensionRendererCreated(Class<? extends Renderer> clazz, @C.TrackType int type) {
    // In EXTENSION_RENDERER_MODE_OFF the renderer should not be created.
    Renderer[] renderers = createRenderers(EXTENSION_RENDERER_MODE_OFF);
    for (Renderer renderer : renderers) {
        assertThat(renderer).isNotInstanceOf(clazz);
    }
    // In EXTENSION_RENDERER_MODE_ON the renderer should be created and last of its type.
    renderers = createRenderers(EXTENSION_RENDERER_MODE_ON);
    boolean found = false;
    for (Renderer renderer : renderers) {
        if (!found) {
            if (clazz.isInstance(renderer)) {
                found = true;
            }
        } else {
            assertThat(renderer.getTrackType()).isNotEqualTo(type);
        }
    }
    assertThat(found).isTrue();
    // In EXTENSION_RENDERER_MODE_PREFER the renderer should be created and first of its type.
    renderers = createRenderers(EXTENSION_RENDERER_MODE_PREFER);
    found = false;
    for (Renderer renderer : renderers) {
        if (!found) {
            if (clazz.isInstance(renderer)) {
                found = true;
            } else {
                assertThat(renderer.getTrackType()).isNotEqualTo(type);
            }
        } else {
            assertThat(renderer).isNotInstanceOf(clazz);
        }
    }
    assertThat(found).isTrue();
}
Also used : Renderer(com.google.android.exoplayer2.Renderer)

Example 27 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class ExoPlayerTest method release_triggersAllPendingEventsInAnalyticsListeners.

@Test
public void release_triggersAllPendingEventsInAnalyticsListeners() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(ApplicationProvider.getApplicationContext()).setRenderersFactory((handler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeVideoRenderer(handler, videoListener) }).build();
    AnalyticsListener listener = mock(AnalyticsListener.class);
    player.addAnalyticsListener(listener);
    // Do something that requires clean-up callbacks like decoder disabling.
    player.setMediaSource(new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_READY);
    player.release();
    ShadowLooper.runMainLooperToNextTask();
    verify(listener).onVideoDisabled(any(), any());
    verify(listener).onPlayerReleased(any());
}
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) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 28 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class DownloadHelperTest method setUp.

@Before
public void setUp() {
    FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
    FakeRenderer textRenderer = new FakeRenderer(C.TRACK_TYPE_TEXT);
    RenderersFactory renderersFactory = (handler, videoListener, audioListener, metadata, text) -> new Renderer[] { textRenderer, audioRenderer, videoRenderer };
    downloadHelper = new DownloadHelper(testMediaItem, new TestMediaSource(), DownloadHelper.DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT, DownloadHelper.getRendererCapabilities(renderersFactory));
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) RunWith(org.junit.runner.RunWith) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) AtomicReference(java.util.concurrent.atomic.AtomicReference) ShadowLooper.shadowMainLooper(org.robolectric.shadows.ShadowLooper.shadowMainLooper) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) Format(com.google.android.exoplayer2.Format) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo) C(com.google.android.exoplayer2.C) Allocator(com.google.android.exoplayer2.upstream.Allocator) Before(org.junit.Before) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) MediaItem(com.google.android.exoplayer2.MediaItem) EventDispatcher(com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher) Callback(com.google.android.exoplayer2.offline.DownloadHelper.Callback) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) IOException(java.io.IOException) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Truth.assertThat(com.google.common.truth.Truth.assertThat) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) CountDownLatch(java.util.concurrent.CountDownLatch) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) List(java.util.List) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Renderer(com.google.android.exoplayer2.Renderer) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) Renderer(com.google.android.exoplayer2.Renderer) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) Before(org.junit.Before)

Example 29 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class DecoderVideoRendererTest method setUp.

@Before
public void setUp() {
    surface = new Surface(new SurfaceTexture(/* texName= */
    0));
    renderer = new DecoderVideoRenderer(/* allowedJoiningTimeMs= */
    0, new Handler(), eventListener, /* maxDroppedFramesToNotify= */
    -1) {

        private final Phaser inputBuffersInCodecPhaser = new Phaser();

        @C.VideoOutputMode
        private int outputMode;

        @Override
        public String getName() {
            return "TestVideoRenderer";
        }

        @Override
        @Capabilities
        public int supportsFormat(Format format) {
            return RendererCapabilities.create(C.FORMAT_HANDLED);
        }

        @Override
        protected void setDecoderOutputMode(@C.VideoOutputMode int outputMode) {
            this.outputMode = outputMode;
        }

        @Override
        protected void renderOutputBufferToSurface(VideoDecoderOutputBuffer outputBuffer, Surface surface) {
        // Do nothing.
        }

        @Override
        protected void onQueueInputBuffer(DecoderInputBuffer buffer) {
            // Decoding is done on a background thread we have no control about from the test.
            // Ensure the background calls are predictably serialized by waiting for them to finish:
            // 1. Register queued input buffers here.
            // 2. Deregister the input buffer when it's cleared. If an input buffer is cleared it
            // will have been fully handled by the decoder.
            // 3. Send a message on the test thread to wait for all currently pending input buffers
            // to be cleared.
            // 4. The tests need to call ShadowLooper.idleMainThread() to execute the wait message
            // sent in step (3).
            int currentPhase = inputBuffersInCodecPhaser.register();
            new Handler().post(() -> inputBuffersInCodecPhaser.awaitAdvance(currentPhase));
            super.onQueueInputBuffer(buffer);
        }

        @Override
        protected SimpleDecoder<DecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException> createDecoder(Format format, @Nullable CryptoConfig cryptoConfig) {
            return new SimpleDecoder<DecoderInputBuffer, VideoDecoderOutputBuffer, DecoderException>(new DecoderInputBuffer[10], new VideoDecoderOutputBuffer[10]) {

                @Override
                protected DecoderInputBuffer createInputBuffer() {
                    return new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT) {

                        @Override
                        public void clear() {
                            super.clear();
                            inputBuffersInCodecPhaser.arriveAndDeregister();
                        }
                    };
                }

                @Override
                protected VideoDecoderOutputBuffer createOutputBuffer() {
                    return new VideoDecoderOutputBuffer(this::releaseOutputBuffer);
                }

                @Override
                protected DecoderException createUnexpectedDecodeException(Throwable error) {
                    return new DecoderException("error", error);
                }

                @Nullable
                @Override
                protected DecoderException decode(DecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) {
                    outputBuffer.init(inputBuffer.timeUs, outputMode, /* supplementalData= */
                    null);
                    return null;
                }

                @Override
                public String getName() {
                    return "TestDecoder";
                }
            };
        }
    };
    renderer.setOutput(surface);
}
Also used : SimpleDecoder(com.google.android.exoplayer2.decoder.SimpleDecoder) Handler(android.os.Handler) Surface(android.view.Surface) VideoDecoderOutputBuffer(com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer) DecoderException(com.google.android.exoplayer2.decoder.DecoderException) SurfaceTexture(android.graphics.SurfaceTexture) Format(com.google.android.exoplayer2.Format) DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Phaser(java.util.concurrent.Phaser) CryptoConfig(com.google.android.exoplayer2.decoder.CryptoConfig) Nullable(androidx.annotation.Nullable) Before(org.junit.Before)

Example 30 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class ExoPlayerTest method rendererError_isReportedWithReadingMediaPeriodId.

@Test
public void rendererError_isReportedWithReadingMediaPeriodId() throws Exception {
    FakeMediaSource source0 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
    FakeMediaSource source1 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
    RenderersFactory renderersFactory = (eventHandler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeRenderer(C.TRACK_TYPE_VIDEO), new FakeRenderer(C.TRACK_TYPE_AUDIO) {

        @Override
        protected void onEnabled(boolean joining, boolean mayRenderStartOfStream) throws ExoPlaybackException {
            // transition while the reading and playing period are different.
            throw createRendererException(new IllegalStateException(), ExoPlayerTestRunner.AUDIO_FORMAT, PlaybackException.ERROR_CODE_UNSPECIFIED);
        }
    } };
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderersFactory(renderersFactory).build();
    player.setMediaSources(ImmutableList.of(source0, source1));
    player.prepare();
    player.play();
    ExoPlaybackException error = TestPlayerRunHelper.runUntilError(player);
    Object period1Uid = player.getCurrentTimeline().getPeriod(/* periodIndex= */
    1, new Timeline.Period(), /* setIds= */
    true).uid;
    assertThat(error.mediaPeriodId.periodUid).isEqualTo(period1Uid);
    // Verify test setup by checking that playing period was indeed different.
    assertThat(player.getCurrentMediaItemIndex()).isEqualTo(0);
}
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) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)36 FakeRenderer (com.google.android.exoplayer2.testutil.FakeRenderer)27 Nullable (androidx.annotation.Nullable)25 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)25 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)25 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)24 TextRenderer (com.google.android.exoplayer2.text.TextRenderer)21 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)19 ArrayList (java.util.ArrayList)18 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)17 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)17 MediaSource (com.google.android.exoplayer2.source.MediaSource)16 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)16 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)16 Format (com.google.android.exoplayer2.Format)15 Listener (com.google.android.exoplayer2.Player.Listener)15 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)15 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)14 InOrder (org.mockito.InOrder)14 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)13