Search in sources :

Example 1 with MediaCryptoException

use of android.media.MediaCryptoException in project ExoPlayer by google.

the class MediaCodecRenderer method maybeInitCodecOrBypass.

protected final void maybeInitCodecOrBypass() throws ExoPlaybackException {
    if (codec != null || bypassEnabled || inputFormat == null) {
        // We have a codec, are bypassing it, or don't have a format to decide how to render.
        return;
    }
    if (sourceDrmSession == null && shouldUseBypass(inputFormat)) {
        initBypass(inputFormat);
        return;
    }
    setCodecDrmSession(sourceDrmSession);
    String mimeType = inputFormat.sampleMimeType;
    if (codecDrmSession != null) {
        if (mediaCrypto == null) {
            @Nullable FrameworkCryptoConfig sessionCryptoConfig = getFrameworkCryptoConfig(codecDrmSession);
            if (sessionCryptoConfig == null) {
                @Nullable DrmSessionException drmError = codecDrmSession.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;
                }
            } else {
                try {
                    mediaCrypto = new MediaCrypto(sessionCryptoConfig.uuid, sessionCryptoConfig.sessionId);
                } catch (MediaCryptoException e) {
                    throw createRendererException(e, inputFormat, PlaybackException.ERROR_CODE_DRM_SYSTEM_ERROR);
                }
                mediaCryptoRequiresSecureDecoder = !sessionCryptoConfig.forceAllowInsecureDecoderComponents && mediaCrypto.requiresSecureDecoderComponent(mimeType);
            }
        }
        if (FrameworkCryptoConfig.WORKAROUND_DEVICE_NEEDS_KEYS_TO_CONFIGURE_CODEC) {
            @DrmSession.State int drmSessionState = codecDrmSession.getState();
            if (drmSessionState == DrmSession.STATE_ERROR) {
                DrmSessionException drmSessionException = Assertions.checkNotNull(codecDrmSession.getError());
                throw createRendererException(drmSessionException, inputFormat, drmSessionException.errorCode);
            } else if (drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS) {
                // Wait for keys.
                return;
            }
        }
    }
    try {
        maybeInitCodecWithFallback(mediaCrypto, mediaCryptoRequiresSecureDecoder);
    } catch (DecoderInitializationException e) {
        throw createRendererException(e, inputFormat, PlaybackException.ERROR_CODE_DECODER_INIT_FAILED);
    }
}
Also used : DrmSessionException(com.google.android.exoplayer2.drm.DrmSession.DrmSessionException) FrameworkCryptoConfig(com.google.android.exoplayer2.drm.FrameworkCryptoConfig) Nullable(androidx.annotation.Nullable) MediaCrypto(android.media.MediaCrypto) MediaCryptoException(android.media.MediaCryptoException)

Aggregations

MediaCrypto (android.media.MediaCrypto)1 MediaCryptoException (android.media.MediaCryptoException)1 Nullable (androidx.annotation.Nullable)1 DrmSessionException (com.google.android.exoplayer2.drm.DrmSession.DrmSessionException)1 FrameworkCryptoConfig (com.google.android.exoplayer2.drm.FrameworkCryptoConfig)1