Search in sources :

Example 1 with DecoderInitializationException

use of com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException in project ExoPlayer by google.

the class MediaCodecRenderer method maybeInitCodec.

@SuppressWarnings("deprecation")
protected final void maybeInitCodec() throws ExoPlaybackException {
    if (!shouldInitCodec()) {
        return;
    }
    drmSession = pendingDrmSession;
    String mimeType = format.sampleMimeType;
    MediaCrypto mediaCrypto = null;
    boolean drmSessionRequiresSecureDecoder = false;
    if (drmSession != null) {
        @DrmSession.State int drmSessionState = drmSession.getState();
        if (drmSessionState == DrmSession.STATE_ERROR) {
            throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
        } else if (drmSessionState == DrmSession.STATE_OPENED || drmSessionState == DrmSession.STATE_OPENED_WITH_KEYS) {
            mediaCrypto = drmSession.getMediaCrypto().getWrappedMediaCrypto();
            drmSessionRequiresSecureDecoder = drmSession.requiresSecureDecoderComponent(mimeType);
        } else {
            // The drm session isn't open yet.
            return;
        }
    }
    MediaCodecInfo decoderInfo = null;
    try {
        decoderInfo = getDecoderInfo(mediaCodecSelector, format, drmSessionRequiresSecureDecoder);
        if (decoderInfo == null && drmSessionRequiresSecureDecoder) {
            // The drm session indicates that a secure decoder is required, but the device does not have
            // one. Assuming that supportsFormat indicated support for the media being played, we know
            // that it does not require a secure output path. Most CDM implementations allow playback to
            // proceed with a non-secure decoder in this case, so we try our luck.
            decoderInfo = getDecoderInfo(mediaCodecSelector, format, false);
            if (decoderInfo != null) {
                Log.w(TAG, "Drm session requires secure decoder for " + mimeType + ", but " + "no secure decoder available. Trying to proceed with " + decoderInfo.name + ".");
            }
        }
    } catch (DecoderQueryException e) {
        throwDecoderInitError(new DecoderInitializationException(format, e, drmSessionRequiresSecureDecoder, DecoderInitializationException.DECODER_QUERY_ERROR));
    }
    if (decoderInfo == null) {
        throwDecoderInitError(new DecoderInitializationException(format, null, drmSessionRequiresSecureDecoder, DecoderInitializationException.NO_SUITABLE_DECODER_ERROR));
    }
    String codecName = decoderInfo.name;
    codecIsAdaptive = decoderInfo.adaptive;
    codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, format);
    codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName);
    codecNeedsAdaptationWorkaround = codecNeedsAdaptationWorkaround(codecName);
    codecNeedsEosPropagationWorkaround = codecNeedsEosPropagationWorkaround(codecName);
    codecNeedsEosFlushWorkaround = codecNeedsEosFlushWorkaround(codecName);
    codecNeedsEosOutputExceptionWorkaround = codecNeedsEosOutputExceptionWorkaround(codecName);
    codecNeedsMonoChannelCountWorkaround = codecNeedsMonoChannelCountWorkaround(codecName, format);
    try {
        long codecInitializingTimestamp = SystemClock.elapsedRealtime();
        TraceUtil.beginSection("createCodec:" + codecName);
        codec = MediaCodec.createByCodecName(codecName);
        TraceUtil.endSection();
        TraceUtil.beginSection("configureCodec");
        configureCodec(decoderInfo, codec, format, mediaCrypto);
        TraceUtil.endSection();
        TraceUtil.beginSection("startCodec");
        codec.start();
        TraceUtil.endSection();
        long codecInitializedTimestamp = SystemClock.elapsedRealtime();
        onCodecInitialized(codecName, codecInitializedTimestamp, codecInitializedTimestamp - codecInitializingTimestamp);
        inputBuffers = codec.getInputBuffers();
        outputBuffers = codec.getOutputBuffers();
    } catch (Exception e) {
        throwDecoderInitError(new DecoderInitializationException(format, e, drmSessionRequiresSecureDecoder, codecName));
    }
    codecHotswapDeadlineMs = getState() == STATE_STARTED ? (SystemClock.elapsedRealtime() + MAX_CODEC_HOTSWAP_TIME_MS) : C.TIME_UNSET;
    inputIndex = C.INDEX_UNSET;
    outputIndex = C.INDEX_UNSET;
    waitingForFirstSyncFrame = true;
    decoderCounters.decoderInitCount++;
}
Also used : DecoderQueryException(com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) CodecException(android.media.MediaCodec.CodecException) CryptoException(android.media.MediaCodec.CryptoException) DecoderQueryException(com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException) FrameworkMediaCrypto(com.google.android.exoplayer2.drm.FrameworkMediaCrypto) MediaCrypto(android.media.MediaCrypto)

Example 2 with DecoderInitializationException

use of com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException in project ExoPlayer by google.

the class PlayerActivity method onPlayerError.

@Override
public void onPlayerError(ExoPlaybackException e) {
    String errorString = null;
    if (e.type == ExoPlaybackException.TYPE_RENDERER) {
        Exception cause = e.getRendererException();
        if (cause instanceof DecoderInitializationException) {
            // Special case for decoder initialization failures.
            DecoderInitializationException decoderInitializationException = (DecoderInitializationException) cause;
            if (decoderInitializationException.decoderName == null) {
                if (decoderInitializationException.getCause() instanceof DecoderQueryException) {
                    errorString = getString(R.string.error_querying_decoders);
                } else if (decoderInitializationException.secureDecoderRequired) {
                    errorString = getString(R.string.error_no_secure_decoder, decoderInitializationException.mimeType);
                } else {
                    errorString = getString(R.string.error_no_decoder, decoderInitializationException.mimeType);
                }
            } else {
                errorString = getString(R.string.error_instantiating_decoder, decoderInitializationException.decoderName);
            }
        }
    }
    if (errorString != null) {
        showToast(errorString);
    }
    needRetrySource = true;
    if (isBehindLiveWindow(e)) {
        clearResumePosition();
        initializePlayer();
    } else {
        updateResumePosition();
        updateButtonVisibilities();
        showControls();
    }
}
Also used : DecoderQueryException(com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException) DecoderInitializationException(com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) UnsupportedDrmException(com.google.android.exoplayer2.drm.UnsupportedDrmException) DecoderInitializationException(com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException) DecoderQueryException(com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException) BehindLiveWindowException(com.google.android.exoplayer2.source.BehindLiveWindowException)

Example 3 with DecoderInitializationException

use of com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException in project react-native-video by react-native-community.

the class ReactExoplayerView method onPlayerError.

@Override
public void onPlayerError(ExoPlaybackException e) {
    String errorString = null;
    if (e.type == ExoPlaybackException.TYPE_RENDERER) {
        Exception cause = e.getRendererException();
        if (cause instanceof MediaCodecRenderer.DecoderInitializationException) {
            // Special case for decoder initialization failures.
            MediaCodecRenderer.DecoderInitializationException decoderInitializationException = (MediaCodecRenderer.DecoderInitializationException) cause;
            if (decoderInitializationException.decoderName == null) {
                if (decoderInitializationException.getCause() instanceof MediaCodecUtil.DecoderQueryException) {
                    errorString = getResources().getString(R.string.error_querying_decoders);
                } else if (decoderInitializationException.secureDecoderRequired) {
                    errorString = getResources().getString(R.string.error_no_secure_decoder, decoderInitializationException.mimeType);
                } else {
                    errorString = getResources().getString(R.string.error_no_decoder, decoderInitializationException.mimeType);
                }
            } else {
                errorString = getResources().getString(R.string.error_instantiating_decoder, decoderInitializationException.decoderName);
            }
        }
    }
    if (errorString != null) {
        eventEmitter.error(errorString, e);
    }
    playerNeedsSource = true;
}
Also used : ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) MediaCodecRenderer(com.google.android.exoplayer2.mediacodec.MediaCodecRenderer)

Aggregations

ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)3 DecoderQueryException (com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException)2 CodecException (android.media.MediaCodec.CodecException)1 CryptoException (android.media.MediaCodec.CryptoException)1 MediaCrypto (android.media.MediaCrypto)1 FrameworkMediaCrypto (com.google.android.exoplayer2.drm.FrameworkMediaCrypto)1 UnsupportedDrmException (com.google.android.exoplayer2.drm.UnsupportedDrmException)1 MediaCodecRenderer (com.google.android.exoplayer2.mediacodec.MediaCodecRenderer)1 DecoderInitializationException (com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException)1 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)1