Search in sources :

Example 16 with DrmSession

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

the class DefaultDrmSessionManager method acquireSession.

// DrmSessionManager implementation.
@Override
public DrmSession<T> acquireSession(Looper playbackLooper, DrmInitData drmInitData) {
    Assertions.checkState(this.playbackLooper == null || this.playbackLooper == playbackLooper);
    if (++openCount != 1) {
        return this;
    }
    if (this.playbackLooper == null) {
        this.playbackLooper = playbackLooper;
        mediaDrmHandler = new MediaDrmHandler(playbackLooper);
        postResponseHandler = new PostResponseHandler(playbackLooper);
    }
    requestHandlerThread = new HandlerThread("DrmRequestHandler");
    requestHandlerThread.start();
    postRequestHandler = new PostRequestHandler(requestHandlerThread.getLooper());
    if (offlineLicenseKeySetId == null) {
        SchemeData schemeData = drmInitData.get(uuid);
        if (schemeData == null) {
            onError(new IllegalStateException("Media does not support uuid: " + uuid));
            return this;
        }
        schemeInitData = schemeData.data;
        schemeMimeType = schemeData.mimeType;
        if (Util.SDK_INT < 21) {
            // Prior to L the Widevine CDM required data to be extracted from the PSSH atom.
            byte[] psshData = PsshAtomUtil.parseSchemeSpecificData(schemeInitData, C.WIDEVINE_UUID);
            if (psshData == null) {
            // Extraction failed. schemeData isn't a Widevine PSSH atom, so leave it unchanged.
            } else {
                schemeInitData = psshData;
            }
        }
        if (Util.SDK_INT < 26 && C.CLEARKEY_UUID.equals(uuid) && (MimeTypes.VIDEO_MP4.equals(schemeMimeType) || MimeTypes.AUDIO_MP4.equals(schemeMimeType))) {
            // Prior to API level 26 the ClearKey CDM only accepted "cenc" as the scheme for MP4.
            schemeMimeType = CENC_SCHEME_MIME_TYPE;
        }
    }
    state = STATE_OPENING;
    openInternal(true);
    return this;
}
Also used : HandlerThread(android.os.HandlerThread) SchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData)

Example 17 with DrmSession

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

the class OfflineLicenseHelper method blockingKeyRequest.

private void blockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId, DrmInitData drmInitData) throws DrmSessionException {
    DrmSession<T> session = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId, drmInitData);
    DrmSessionException error = session.getError();
    if (error != null) {
        throw error;
    }
    drmSessionManager.releaseSession(session);
}
Also used : DrmSessionException(com.google.android.exoplayer2.drm.DrmSession.DrmSessionException)

Example 18 with DrmSession

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

the class SimpleDecoderAudioRenderer method onInputFormatChanged.

private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = inputFormat;
    inputFormat = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(inputFormat.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (inputFormat.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), inputFormat.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    if (decoderReceivedBuffers) {
        // Signal end of stream and wait for any final output buffers before re-initialization.
        decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
    } else {
        // There aren't any final output buffers, so release the decoder immediately.
        releaseDecoder();
        maybeInitDecoder();
        audioTrackNeedsConfigure = true;
    }
    eventDispatcher.inputFormatChanged(newFormat);
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 19 with DrmSession

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

the class LibvpxVideoRenderer method onInputFormatChanged.

private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = format;
    format = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(format.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (format.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), format.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    eventDispatcher.inputFormatChanged(format);
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 20 with DrmSession

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

the class LibvpxVideoRenderer method render.

@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
    if (outputStreamEnded) {
        return;
    }
    if (format == null) {
        // We don't have a format yet, so try and read one.
        flagsOnlyBuffer.clear();
        int result = readSource(formatHolder, flagsOnlyBuffer, true);
        if (result == C.RESULT_FORMAT_READ) {
            onInputFormatChanged(formatHolder.format);
        } else if (result == C.RESULT_BUFFER_READ) {
            // End of stream read having not read a format.
            Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
            inputStreamEnded = true;
            outputStreamEnded = true;
            return;
        } else {
            // We still don't have a format and can't make progress without one.
            return;
        }
    }
    if (isRendererAvailable()) {
        drmSession = pendingDrmSession;
        ExoMediaCrypto mediaCrypto = null;
        if (drmSession != null) {
            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();
            } else {
                // The drm session isn't open yet.
                return;
            }
        }
        try {
            if (decoder == null) {
                // If we don't have a decoder yet, we need to instantiate one.
                long codecInitializingTimestamp = SystemClock.elapsedRealtime();
                TraceUtil.beginSection("createVpxDecoder");
                decoder = new VpxDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE, mediaCrypto);
                decoder.setOutputMode(outputMode);
                TraceUtil.endSection();
                long codecInitializedTimestamp = SystemClock.elapsedRealtime();
                eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp, codecInitializedTimestamp - codecInitializingTimestamp);
                decoderCounters.decoderInitCount++;
            }
            TraceUtil.beginSection("drainAndFeed");
            while (drainOutputBuffer(positionUs)) {
            }
            while (feedInputBuffer()) {
            }
            TraceUtil.endSection();
        } catch (VpxDecoderException e) {
            throw ExoPlaybackException.createForRenderer(e, getIndex());
        }
    } else {
        skipToKeyframeBefore(positionUs);
    }
    decoderCounters.ensureUpdated();
}
Also used : ExoMediaCrypto(com.google.android.exoplayer2.drm.ExoMediaCrypto)

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