Search in sources :

Example 11 with AudioSink

use of com.google.android.exoplayer2.audio.AudioSink in project ExoPlayer by google.

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(com.google.android.exoplayer2.testutil.FakeSampleStream) MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Test(org.junit.Test)

Aggregations

Format (com.google.android.exoplayer2.Format)5 MediaFormat (android.media.MediaFormat)4 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)4 Test (org.junit.Test)4 Nullable (androidx.annotation.Nullable)3 MediaCodecInfo (com.google.android.exoplayer2.mediacodec.MediaCodecInfo)3 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)3 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)3 Handler (android.os.Handler)2 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)2 PlaybackException (com.google.android.exoplayer2.PlaybackException)2 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)2 MediaCodecAudioRenderer (com.google.android.exoplayer2.audio.MediaCodecAudioRenderer)2 MetadataRenderer (com.google.android.exoplayer2.metadata.MetadataRenderer)2 TextRenderer (com.google.android.exoplayer2.text.TextRenderer)2 MediaCodecVideoRenderer (com.google.android.exoplayer2.video.MediaCodecVideoRenderer)2 CameraMotionRenderer (com.google.android.exoplayer2.video.spherical.CameraMotionRenderer)2 Before (org.junit.Before)2 SuppressLint (android.annotation.SuppressLint)1 Looper (android.os.Looper)1