Search in sources :

Example 1 with EventDispatcher

use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.

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(androidx.media3.exoplayer.drm.DrmSession.DrmSessionException)

Example 2 with EventDispatcher

use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.

the class DefaultHlsPlaylistTracker method start.

// HlsPlaylistTracker implementation.
@Override
public void start(Uri initialPlaylistUri, EventDispatcher eventDispatcher, PrimaryPlaylistListener primaryPlaylistListener) {
    this.playlistRefreshHandler = Util.createHandlerForCurrentLooper();
    this.eventDispatcher = eventDispatcher;
    this.primaryPlaylistListener = primaryPlaylistListener;
    ParsingLoadable<HlsPlaylist> multivariantPlaylistLoadable = new ParsingLoadable<>(dataSourceFactory.createDataSource(C.DATA_TYPE_MANIFEST), initialPlaylistUri, C.DATA_TYPE_MANIFEST, playlistParserFactory.createPlaylistParser());
    Assertions.checkState(initialPlaylistLoader == null);
    initialPlaylistLoader = new Loader("DefaultHlsPlaylistTracker:MultivariantPlaylist");
    long elapsedRealtime = initialPlaylistLoader.startLoading(multivariantPlaylistLoadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(multivariantPlaylistLoadable.type));
    eventDispatcher.loadStarted(new LoadEventInfo(multivariantPlaylistLoadable.loadTaskId, multivariantPlaylistLoadable.dataSpec, elapsedRealtime), multivariantPlaylistLoadable.type);
}
Also used : LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) ParsingLoadable(androidx.media3.exoplayer.upstream.ParsingLoadable) Loader(androidx.media3.exoplayer.upstream.Loader)

Example 3 with EventDispatcher

use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.

the class FakeMediaSource method finishSourcePreparation.

private void finishSourcePreparation(boolean sendManifestLoadEvents) {
    refreshSourceInfo(Assertions.checkStateNotNull(timeline));
    if (!timeline.isEmpty() && sendManifestLoadEvents) {
        MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MANIFEST, C.TRACK_TYPE_UNKNOWN, /* trackFormat= */
        null, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
        null, /* mediaStartTimeMs= */
        C.TIME_UNSET, /* mediaEndTimeMs = */
        C.TIME_UNSET);
        long elapsedRealTimeMs = SystemClock.elapsedRealtime();
        MediaSourceEventListener.EventDispatcher eventDispatcher = createEventDispatcher(/* mediaPeriodId= */
        null);
        long loadTaskId = LoadEventInfo.getNewId();
        eventDispatcher.loadStarted(new LoadEventInfo(loadTaskId, FAKE_DATA_SPEC, FAKE_DATA_SPEC.uri, /* responseHeaders= */
        ImmutableMap.of(), elapsedRealTimeMs, /* loadDurationMs= */
        0, /* bytesLoaded= */
        0), mediaLoadData);
        eventDispatcher.loadCompleted(new LoadEventInfo(loadTaskId, FAKE_DATA_SPEC, FAKE_DATA_SPEC.uri, /* responseHeaders= */
        ImmutableMap.of(), elapsedRealTimeMs, /* loadDurationMs= */
        0, /* bytesLoaded= */
        MANIFEST_LOAD_BYTES), mediaLoadData);
    }
}
Also used : MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener)

Example 4 with EventDispatcher

use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.

the class DefaultDrmSessionManager method acquireSession.

// Must be called on the playback thread.
@Nullable
private DrmSession acquireSession(Looper playbackLooper, @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, Format format, boolean shouldReleasePreacquiredSessionsBeforeRetrying) {
    maybeCreateMediaDrmHandler(playbackLooper);
    if (format.drmInitData == null) {
        // Content is not encrypted.
        return maybeAcquirePlaceholderSession(MimeTypes.getTrackType(format.sampleMimeType), shouldReleasePreacquiredSessionsBeforeRetrying);
    }
    @Nullable List<SchemeData> schemeDatas = null;
    if (offlineLicenseKeySetId == null) {
        schemeDatas = getSchemeDatas(checkNotNull(format.drmInitData), uuid, false);
        if (schemeDatas.isEmpty()) {
            final MissingSchemeDataException error = new MissingSchemeDataException(uuid);
            Log.e(TAG, "DRM error", error);
            if (eventDispatcher != null) {
                eventDispatcher.drmSessionManagerError(error);
            }
            return new ErrorStateDrmSession(new DrmSessionException(error, PlaybackException.ERROR_CODE_DRM_CONTENT_ERROR));
        }
    }
    @Nullable DefaultDrmSession session;
    if (!multiSession) {
        session = noMultiSessionDrmSession;
    } else {
        // Only use an existing session if it has matching init data.
        session = null;
        for (DefaultDrmSession existingSession : sessions) {
            if (Util.areEqual(existingSession.schemeDatas, schemeDatas)) {
                session = existingSession;
                break;
            }
        }
    }
    if (session == null) {
        // Create a new session.
        session = createAndAcquireSessionWithRetry(schemeDatas, /* isPlaceholderSession= */
        false, eventDispatcher, shouldReleasePreacquiredSessionsBeforeRetrying);
        if (!multiSession) {
            noMultiSessionDrmSession = session;
        }
        sessions.add(session);
    } else {
        session.acquire(eventDispatcher);
    }
    return session;
}
Also used : DrmSessionException(androidx.media3.exoplayer.drm.DrmSession.DrmSessionException) SchemeData(androidx.media3.common.DrmInitData.SchemeData) Nullable(androidx.annotation.Nullable) Nullable(androidx.annotation.Nullable)

Example 5 with EventDispatcher

use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.

the class DefaultDrmSessionManagerTest method managerRelease_keepaliveDisabled_doesntReleaseAnySessions.

@Test(timeout = 10_000)
public void managerRelease_keepaliveDisabled_doesntReleaseAnySessions() throws Exception {
    FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS);
    DrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm()).setSessionKeepaliveMs(C.TIME_UNSET).build(/* mediaDrmCallback= */
    licenseServer);
    drmSessionManager.prepare();
    drmSessionManager.setPlayer(/* playbackLooper= */
    Looper.myLooper(), PlayerId.UNSET);
    DrmSession drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    waitForOpenedWithKeys(drmSession);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    // Release the manager, the session should still be open (though it's unusable because
    // the underlying ExoMediaDrm is released).
    drmSessionManager.release();
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
}
Also used : FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 FakeExoMediaDrm (androidx.media3.test.utils.FakeExoMediaDrm)15 AppManagedProvider (androidx.media3.exoplayer.drm.ExoMediaDrm.AppManagedProvider)7 DrmSessionReference (androidx.media3.exoplayer.drm.DrmSessionManager.DrmSessionReference)5 Nullable (androidx.annotation.Nullable)3 C (androidx.media3.common.C)3 Format (androidx.media3.common.Format)3 DrmSessionException (androidx.media3.exoplayer.drm.DrmSession.DrmSessionException)3 MediaSource (androidx.media3.exoplayer.source.MediaSource)3 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)3 ImmutableList (com.google.common.collect.ImmutableList)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 RunWith (org.junit.runner.RunWith)3 Looper (android.os.Looper)2 DrmInitData (androidx.media3.common.DrmInitData)2 MimeTypes (androidx.media3.common.MimeTypes)2 Assertions.checkNotNull (androidx.media3.common.util.Assertions.checkNotNull)2 Util (androidx.media3.common.util.Util)2 DecoderInputBuffer (androidx.media3.decoder.DecoderInputBuffer)2 FormatHolder (androidx.media3.exoplayer.FormatHolder)2