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();
}
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());
}
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));
}
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);
}
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);
}
Aggregations