private void updateCurrentPosition() { long newCurrentPositionUs = audioSink.getCurrentPositionUs(isEnded()); if (newCurrentPositionUs != AudioSink.CURRENT_POSITION_NOT_SET) { currentPositionUs = allowPositionDiscontinuity ? newCurrentPositionUs : Math.max(currentPositionUs, newCurrentPositionUs); allowPositionDiscontinuity = false; } }
@Override protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException { audioSink.reset(); currentPositionUs = positionUs; allowFirstBufferPositionDiscontinuity = true; allowPositionDiscontinuity = true; inputStreamEnded = false; outputStreamEnded = false; if (decoder != null) { flushDecoder(); } }
private void processEndOfStream() throws ExoPlaybackException { outputStreamEnded = true; try { audioSink.playToEndOfStream(); } catch (AudioSink.WriteException e) { throw ExoPlaybackException.createForRenderer(e, getIndex()); } }
audioSink.playToEndOfStream(); } catch (AudioSink.WriteException e) { throw ExoPlaybackException.createForRenderer(e, getIndex()); int result = readSource(formatHolder, flagsOnlyBuffer, true); if (result == C.RESULT_FORMAT_READ) { onInputFormatChanged(formatHolder.format); } else if (result == C.RESULT_BUFFER_READ) { processEndOfStream(); return; } else { maybeInitDecoder(); while (drainOutputBuffer()) {} while (feedInputBuffer()) {} TraceUtil.endSection(); } catch (AudioDecoderException | AudioSink.ConfigurationException | AudioSink.InitializationException | AudioSink.WriteException e) { throw ExoPlaybackException.createForRenderer(e, getIndex());
@Test public void testImmediatelyReadEndOfStreamPlaysAudioSinkToEndOfStream() throws Exception { audioRenderer.enable( RendererConfiguration.DEFAULT, new Format[] {FORMAT}, new FakeSampleStream(FORMAT, /* eventDispatcher= */ null, /* shouldOutputSample= */ false), 0, false, 0); audioRenderer.setCurrentStreamFinal(); when(mockAudioSink.isEnded()).thenReturn(true); while (!audioRenderer.isEnded()) { audioRenderer.render(0, 0); } verify(mockAudioSink, times(1)).playToEndOfStream(); audioRenderer.disable(); verify(mockAudioSink, times(1)).release(); }
if (decoderReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM) { releaseDecoder(); maybeInitDecoder(); outputBuffer.release(); outputBuffer = null; processEndOfStream(); Format outputFormat = getOutputFormat(); audioSink.configure(outputFormat.pcmEncoding, outputFormat.channelCount, outputFormat.sampleRate, 0, null, encoderDelay, encoderPadding);
if (drmSessionManager == null) { throw ExoPlaybackException.createForRenderer( new IllegalStateException("Media requires a DrmSessionManager"), getIndex()); } else { releaseDecoder(); maybeInitDecoder(); audioTrackNeedsConfigure = true;
long codecInitializingTimestamp = SystemClock.elapsedRealtime(); TraceUtil.beginSection("createAudioDecoder"); decoder = createDecoder(inputFormat, mediaCrypto); TraceUtil.endSection(); long codecInitializedTimestamp = SystemClock.elapsedRealtime(); decoderCounters.decoderInitCount++; } catch (AudioDecoderException e) { throw ExoPlaybackException.createForRenderer(e, getIndex());
@Override protected void onEnabled(boolean joining) throws ExoPlaybackException { decoderCounters = new DecoderCounters(); eventDispatcher.enabled(decoderCounters); int tunnelingAudioSessionId = getConfiguration().tunnelingAudioSessionId; if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) { audioSink.enableTunnelingV21(tunnelingAudioSessionId); } else { audioSink.disableTunneling(); } }
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException { if (drmSession == null || (!bufferEncrypted && playClearSamplesWithoutKeys)) { return false; } @DrmSession.State int drmSessionState = drmSession.getState(); if (drmSessionState == DrmSession.STATE_ERROR) { throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex()); } return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS; }