Search in sources :

Example 31 with DrmSession

use of com.google.android.exoplayer2.drm.DrmSession in project ExoPlayer by google.

the class MediaCodecRenderer method render.

@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
    if (pendingOutputEndOfStream) {
        pendingOutputEndOfStream = false;
        processEndOfStream();
    }
    if (pendingPlaybackException != null) {
        ExoPlaybackException playbackException = pendingPlaybackException;
        pendingPlaybackException = null;
        throw playbackException;
    }
    try {
        if (outputStreamEnded) {
            renderToEndOfStream();
            return;
        }
        if (inputFormat == null && !readSourceOmittingSampleData(FLAG_REQUIRE_FORMAT)) {
            // We still don't have a format and can't make progress without one.
            return;
        }
        // We have a format.
        maybeInitCodecOrBypass();
        if (bypassEnabled) {
            TraceUtil.beginSection("bypassRender");
            while (bypassRender(positionUs, elapsedRealtimeUs)) {
            }
            TraceUtil.endSection();
        } else if (codec != null) {
            long renderStartTimeMs = SystemClock.elapsedRealtime();
            TraceUtil.beginSection("drainAndFeed");
            while (drainOutputBuffer(positionUs, elapsedRealtimeUs) && shouldContinueRendering(renderStartTimeMs)) {
            }
            while (feedInputBuffer() && shouldContinueRendering(renderStartTimeMs)) {
            }
            TraceUtil.endSection();
        } else {
            decoderCounters.skippedInputBufferCount += skipSource(positionUs);
            // We need to read any format changes despite not having a codec so that drmSession can be
            // updated, and so that we have the most recent format should the codec be initialized. We
            // may also reach the end of the stream. FLAG_PEEK is used because we don't want to advance
            // the source further than skipSource has already done.
            readSourceOmittingSampleData(FLAG_PEEK);
        }
        decoderCounters.ensureUpdated();
    } catch (IllegalStateException e) {
        if (isMediaCodecException(e)) {
            onCodecError(e);
            boolean isRecoverable = Util.SDK_INT >= 21 && isRecoverableMediaCodecExceptionV21(e);
            if (isRecoverable) {
                releaseCodec();
            }
            throw createRendererException(createDecoderException(e, getCodecInfo()), inputFormat, isRecoverable, PlaybackException.ERROR_CODE_DECODING_FAILED);
        }
        throw e;
    }
}
Also used : ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException)

Example 32 with DrmSession

use of com.google.android.exoplayer2.drm.DrmSession in project ExoPlayer by google.

the class OfflineLicenseHelper method blockingKeyRequest.

private byte[] blockingKeyRequest(@Mode int licenseMode, @Nullable byte[] offlineLicenseKeySetId, Format format) throws DrmSessionException {
    drmSessionManager.setPlayer(handlerThread.getLooper(), PlayerId.UNSET);
    drmSessionManager.prepare();
    DrmSession drmSession = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId, format);
    DrmSessionException error = drmSession.getError();
    byte[] keySetId = drmSession.getOfflineLicenseKeySetId();
    drmSession.release(eventDispatcher);
    drmSessionManager.release();
    if (error != null) {
        throw error;
    }
    return Assertions.checkNotNull(keySetId);
}
Also used : DrmSessionException(com.google.android.exoplayer2.drm.DrmSession.DrmSessionException)

Aggregations

Test (org.junit.Test)18 FakeExoMediaDrm (com.google.android.exoplayer2.testutil.FakeExoMediaDrm)16 AppManagedProvider (com.google.android.exoplayer2.drm.ExoMediaDrm.AppManagedProvider)7 Nullable (androidx.annotation.Nullable)5 Format (com.google.android.exoplayer2.Format)5 DrmSessionReference (com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference)5 DrmSessionException (com.google.android.exoplayer2.drm.DrmSession.DrmSessionException)4 MediaSource (com.google.android.exoplayer2.source.MediaSource)4 DrmSession (com.google.android.exoplayer2.drm.DrmSession)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Looper (android.os.Looper)2 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 C (com.google.android.exoplayer2.C)2 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)2 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)2 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)2 ExoMediaCrypto (com.google.android.exoplayer2.drm.ExoMediaCrypto)2 TestUtil (com.google.android.exoplayer2.testutil.TestUtil)2 Assertions.checkNotNull (com.google.android.exoplayer2.util.Assertions.checkNotNull)2 MimeTypes (com.google.android.exoplayer2.util.MimeTypes)2