use of com.google.android.exoplayer2.upstream.DefaultAllocator in project ExoPlayer by google.
the class ProgressiveMediaPeriodTest method testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback.
private static void testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback(ProgressiveMediaExtractor extractor) throws TimeoutException {
AtomicBoolean sourceInfoRefreshCalled = new AtomicBoolean(false);
ProgressiveMediaPeriod.Listener sourceInfoRefreshListener = (durationUs, isSeekable, isLive) -> sourceInfoRefreshCalled.set(true);
MediaPeriodId mediaPeriodId = new MediaPeriodId(/* periodUid= */
new Object());
ProgressiveMediaPeriod mediaPeriod = new ProgressiveMediaPeriod(Uri.parse("asset://android_asset/media/mp4/sample.mp4"), new AssetDataSource(ApplicationProvider.getApplicationContext()), extractor, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher().withParameters(/* windowIndex= */
0, mediaPeriodId), new DefaultLoadErrorHandlingPolicy(), new MediaSourceEventListener.EventDispatcher().withParameters(/* windowIndex= */
0, mediaPeriodId, /* mediaTimeOffsetMs= */
0), sourceInfoRefreshListener, new DefaultAllocator(/* trimOnReset= */
true, C.DEFAULT_BUFFER_SEGMENT_SIZE), /* customCacheKey= */
null, ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES);
AtomicBoolean prepareCallbackCalled = new AtomicBoolean(false);
AtomicBoolean sourceInfoRefreshCalledBeforeOnPrepared = new AtomicBoolean(false);
mediaPeriod.prepare(new MediaPeriod.Callback() {
@Override
public void onPrepared(MediaPeriod mediaPeriod) {
sourceInfoRefreshCalledBeforeOnPrepared.set(sourceInfoRefreshCalled.get());
prepareCallbackCalled.set(true);
}
@Override
public void onContinueLoadingRequested(MediaPeriod source) {
source.continueLoading(/* positionUs= */
0);
}
}, /* positionUs= */
0);
runMainLooperUntil(prepareCallbackCalled::get);
mediaPeriod.release();
assertThat(sourceInfoRefreshCalledBeforeOnPrepared.get()).isTrue();
}
use of com.google.android.exoplayer2.upstream.DefaultAllocator in project ExoPlayer by google.
the class RtspMediaPeriodTest method prepareMediaPeriod_withWwwAuthentication_refreshesSourceInfoAndCallsOnPrepared.
@Test
public void prepareMediaPeriod_withWwwAuthentication_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) {
String authorizationHeader = headers.get(RtspHeaders.AUTHORIZATION);
if (authorizationHeader == null) {
return new RtspResponse(/* status= */
401, new RtspHeaders.Builder().add(RtspHeaders.CSEQ, headers.get(RtspHeaders.CSEQ)).add(RtspHeaders.WWW_AUTHENTICATE, "Digest realm=\"RTSP server\"," + " nonce=\"0cdfe9719e7373b7d5bb2913e2115f3f\"," + " opaque=\"5ccc069c403ebaf9f0171e9517f40e41\"").add(RtspHeaders.WWW_AUTHENTICATE, "BASIC realm=\"WallyWorld\"").build());
}
if (!authorizationHeader.contains("Digest")) {
return new RtspResponse(401, new RtspHeaders.Builder().add(RtspHeaders.CSEQ, headers.get(RtspHeaders.CSEQ)).build());
}
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.getTestUriWithUserInfo("username", "password", 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);
}
use of com.google.android.exoplayer2.upstream.DefaultAllocator in project ExoPlayer by google.
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();
}
use of com.google.android.exoplayer2.upstream.DefaultAllocator in project ExoPlayer by google.
the class DecoderVideoRendererTest method enable_withoutMayRenderStartOfStream_doesNotRenderFirstFrameBeforeStart.
@Test
public void enable_withoutMayRenderStartOfStream_doesNotRenderFirstFrameBeforeStart() 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= */
false, /* startPositionUs= */
0, /* 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, never()).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
anyLong());
}
use of com.google.android.exoplayer2.upstream.DefaultAllocator in project ExoPlayer by google.
the class DecoderVideoRendererTest method replaceStream_whenStarted_rendersFirstFrameOfNewStream.
// TODO: Fix rendering of first frame at stream transition.
@Ignore
@Test
public void replaceStream_whenStarted_rendersFirstFrameOfNewStream() throws Exception {
FakeSampleStream fakeSampleStream1 = 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), END_OF_STREAM_ITEM));
fakeSampleStream1.writeData(/* startPositionUs= */
0);
FakeSampleStream fakeSampleStream2 = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
H264_FORMAT, ImmutableList.of(oneByteSample(/* timeUs= */
0), END_OF_STREAM_ITEM));
fakeSampleStream2.writeData(/* startPositionUs= */
0);
renderer.enable(RendererConfiguration.DEFAULT, new Format[] { H264_FORMAT }, fakeSampleStream1, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
true, /* startPositionUs= */
0, /* offsetUs */
0);
renderer.start();
boolean replacedStream = false;
for (int i = 0; i <= 10; i++) {
renderer.render(/* positionUs= */
i * 10, SystemClock.elapsedRealtime() * 1000);
if (!replacedStream && renderer.hasReadStreamToEnd()) {
renderer.replaceStream(new Format[] { H264_FORMAT }, fakeSampleStream2, /* startPositionUs= */
100, /* offsetUs= */
100);
replacedStream = true;
}
// Ensure pending messages are delivered.
ShadowLooper.idleMainLooper();
}
verify(eventListener, times(2)).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
anyLong());
}
Aggregations