Search in sources :

Example 16 with ExoPlaybackException

use of androidx.media3.exoplayer.ExoPlaybackException in project media by androidx.

the class ExoPlayerImplInternal method resetInternal.

private void resetInternal(boolean resetRenderers, boolean resetPosition, boolean releaseMediaSourceList, boolean resetError) {
    handler.removeMessages(MSG_DO_SOME_WORK);
    pendingRecoverableRendererError = null;
    isRebuffering = false;
    mediaClock.stop();
    rendererPositionUs = MediaPeriodQueue.INITIAL_RENDERER_POSITION_OFFSET_US;
    for (Renderer renderer : renderers) {
        try {
            disableRenderer(renderer);
        } catch (ExoPlaybackException | RuntimeException e) {
            // There's nothing we can do.
            Log.e(TAG, "Disable failed.", e);
        }
    }
    if (resetRenderers) {
        for (Renderer renderer : renderers) {
            if (renderersToReset.remove(renderer)) {
                try {
                    renderer.reset();
                } catch (RuntimeException e) {
                    // There's nothing we can do.
                    Log.e(TAG, "Reset failed.", e);
                }
            }
        }
    }
    enabledRendererCount = 0;
    MediaPeriodId mediaPeriodId = playbackInfo.periodId;
    long startPositionUs = playbackInfo.positionUs;
    long requestedContentPositionUs = playbackInfo.periodId.isAd() || isUsingPlaceholderPeriod(playbackInfo, period) ? playbackInfo.requestedContentPositionUs : playbackInfo.positionUs;
    boolean resetTrackInfo = false;
    if (resetPosition) {
        pendingInitialSeekPosition = null;
        Pair<MediaPeriodId, Long> firstPeriodAndPositionUs = getPlaceholderFirstMediaPeriodPositionUs(playbackInfo.timeline);
        mediaPeriodId = firstPeriodAndPositionUs.first;
        startPositionUs = firstPeriodAndPositionUs.second;
        requestedContentPositionUs = C.TIME_UNSET;
        if (!mediaPeriodId.equals(playbackInfo.periodId)) {
            resetTrackInfo = true;
        }
    }
    queue.clear();
    shouldContinueLoading = false;
    playbackInfo = new PlaybackInfo(playbackInfo.timeline, mediaPeriodId, requestedContentPositionUs, /* discontinuityStartPositionUs= */
    startPositionUs, playbackInfo.playbackState, resetError ? null : playbackInfo.playbackError, /* isLoading= */
    false, resetTrackInfo ? TrackGroupArray.EMPTY : playbackInfo.trackGroups, resetTrackInfo ? emptyTrackSelectorResult : playbackInfo.trackSelectorResult, resetTrackInfo ? ImmutableList.of() : playbackInfo.staticMetadata, mediaPeriodId, playbackInfo.playWhenReady, playbackInfo.playbackSuppressionReason, playbackInfo.playbackParameters, /* bufferedPositionUs= */
    startPositionUs, /* totalBufferedDurationUs= */
    0, /* positionUs= */
    startPositionUs, offloadSchedulingEnabled, /* sleepingForOffload= */
    false);
    if (releaseMediaSourceList) {
        mediaSourceList.release();
    }
}
Also used : TextRenderer(androidx.media3.exoplayer.text.TextRenderer) MetadataRenderer(androidx.media3.exoplayer.metadata.MetadataRenderer) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)

Example 17 with ExoPlaybackException

use of androidx.media3.exoplayer.ExoPlaybackException in project media by androidx.

the class DecoderAudioRenderer method maybeInitDecoder.

private void maybeInitDecoder() throws ExoPlaybackException {
    if (decoder != null) {
        return;
    }
    setDecoderDrmSession(sourceDrmSession);
    CryptoConfig cryptoConfig = null;
    if (decoderDrmSession != null) {
        cryptoConfig = decoderDrmSession.getCryptoConfig();
        if (cryptoConfig == null) {
            DrmSessionException drmError = decoderDrmSession.getError();
            if (drmError != null) {
            // Continue for now. We may be able to avoid failure if a new input format causes the
            // session to be replaced without it having been used.
            } else {
                // The drm session isn't open yet.
                return;
            }
        }
    }
    try {
        long codecInitializingTimestamp = SystemClock.elapsedRealtime();
        TraceUtil.beginSection("createAudioDecoder");
        decoder = createDecoder(inputFormat, cryptoConfig);
        TraceUtil.endSection();
        long codecInitializedTimestamp = SystemClock.elapsedRealtime();
        eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp, codecInitializedTimestamp - codecInitializingTimestamp);
        decoderCounters.decoderInitCount++;
    } catch (DecoderException e) {
        Log.e(TAG, "Audio codec error", e);
        eventDispatcher.audioCodecError(e);
        throw createRendererException(e, inputFormat, PlaybackException.ERROR_CODE_DECODER_INIT_FAILED);
    } catch (OutOfMemoryError e) {
        throw createRendererException(e, inputFormat, PlaybackException.ERROR_CODE_DECODER_INIT_FAILED);
    }
}
Also used : DecoderException(androidx.media3.decoder.DecoderException) DrmSessionException(androidx.media3.exoplayer.drm.DrmSession.DrmSessionException) CryptoConfig(androidx.media3.decoder.CryptoConfig)

Example 18 with ExoPlaybackException

use of androidx.media3.exoplayer.ExoPlaybackException in project media by androidx.

the class DecoderAudioRenderer method handleMessage.

@Override
public void handleMessage(@MessageType int messageType, @Nullable Object message) throws ExoPlaybackException {
    switch(messageType) {
        case MSG_SET_VOLUME:
            audioSink.setVolume((Float) message);
            break;
        case MSG_SET_AUDIO_ATTRIBUTES:
            AudioAttributes audioAttributes = (AudioAttributes) message;
            audioSink.setAudioAttributes(audioAttributes);
            break;
        case MSG_SET_AUX_EFFECT_INFO:
            AuxEffectInfo auxEffectInfo = (AuxEffectInfo) message;
            audioSink.setAuxEffectInfo(auxEffectInfo);
            break;
        case MSG_SET_SKIP_SILENCE_ENABLED:
            audioSink.setSkipSilenceEnabled((Boolean) message);
            break;
        case MSG_SET_AUDIO_SESSION_ID:
            audioSink.setAudioSessionId((Integer) message);
            break;
        case MSG_SET_CAMERA_MOTION_LISTENER:
        case MSG_SET_CHANGE_FRAME_RATE_STRATEGY:
        case MSG_SET_SCALING_MODE:
        case MSG_SET_VIDEO_FRAME_METADATA_LISTENER:
        case MSG_SET_VIDEO_OUTPUT:
        case MSG_SET_WAKEUP_LISTENER:
        default:
            super.handleMessage(messageType, message);
            break;
    }
}
Also used : AuxEffectInfo(androidx.media3.common.AuxEffectInfo) AudioAttributes(androidx.media3.common.AudioAttributes)

Example 19 with ExoPlaybackException

use of androidx.media3.exoplayer.ExoPlaybackException in project media by androidx.

the class DecoderAudioRenderer method feedInputBuffer.

private boolean feedInputBuffer() throws DecoderException, ExoPlaybackException {
    if (decoder == null || decoderReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM || inputStreamEnded) {
        // We need to reinitialize the decoder or the input stream has ended.
        return false;
    }
    if (inputBuffer == null) {
        inputBuffer = decoder.dequeueInputBuffer();
        if (inputBuffer == null) {
            return false;
        }
    }
    if (decoderReinitializationState == REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM) {
        inputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
        decoder.queueInputBuffer(inputBuffer);
        inputBuffer = null;
        decoderReinitializationState = REINITIALIZATION_STATE_WAIT_END_OF_STREAM;
        return false;
    }
    FormatHolder formatHolder = getFormatHolder();
    switch(readSource(formatHolder, inputBuffer, /* readFlags= */
    0)) {
        case C.RESULT_NOTHING_READ:
            return false;
        case C.RESULT_FORMAT_READ:
            onInputFormatChanged(formatHolder);
            return true;
        case C.RESULT_BUFFER_READ:
            if (inputBuffer.isEndOfStream()) {
                inputStreamEnded = true;
                decoder.queueInputBuffer(inputBuffer);
                inputBuffer = null;
                return false;
            }
            inputBuffer.flip();
            inputBuffer.format = inputFormat;
            onQueueInputBuffer(inputBuffer);
            decoder.queueInputBuffer(inputBuffer);
            decoderReceivedBuffers = true;
            decoderCounters.queuedInputBufferCount++;
            inputBuffer = null;
            return true;
        default:
            throw new IllegalStateException();
    }
}
Also used : FormatHolder(androidx.media3.exoplayer.FormatHolder)

Example 20 with ExoPlaybackException

use of androidx.media3.exoplayer.ExoPlaybackException in project media by androidx.

the class DecoderAudioRenderer method onEnabled.

@Override
protected void onEnabled(boolean joining, boolean mayRenderStartOfStream) throws ExoPlaybackException {
    decoderCounters = new DecoderCounters();
    eventDispatcher.enabled(decoderCounters);
    if (getConfiguration().tunneling) {
        audioSink.enableTunnelingV21();
    } else {
        audioSink.disableTunneling();
    }
    audioSink.setPlayerId(getPlayerId());
}
Also used : DecoderCounters(androidx.media3.exoplayer.DecoderCounters)

Aggregations

Test (org.junit.Test)50 Nullable (androidx.annotation.Nullable)24 FakeMediaClockRenderer (androidx.media3.test.utils.FakeMediaClockRenderer)24 Format (androidx.media3.common.Format)23 TrackGroupArray (androidx.media3.common.TrackGroupArray)19 Timeline (androidx.media3.common.Timeline)18 IOException (java.io.IOException)16 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)15 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)14 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)13 ActionSchedule (androidx.media3.test.utils.ActionSchedule)13 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)13 FakeTimeline (androidx.media3.test.utils.FakeTimeline)13 TrackGroup (androidx.media3.common.TrackGroup)12 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)11 Surface (android.view.Surface)9 TracksInfo (androidx.media3.common.TracksInfo)9 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)9 PlaybackException (androidx.media3.common.PlaybackException)8 Player (androidx.media3.common.Player)8