Search in sources :

Example 1 with EventDispatcher

use of com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher in project ExoPlayer by google.

the class HlsMediaSource method prepareSource.

@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
    Assertions.checkState(playlistTracker == null);
    playlistTracker = new HlsPlaylistTracker(manifestUri, dataSourceFactory, eventDispatcher, minLoadableRetryCount, this);
    sourceListener = listener;
    playlistTracker.start();
}
Also used : HlsPlaylistTracker(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker)

Example 2 with EventDispatcher

use of com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher in project ExoPlayer by google.

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(com.google.android.exoplayer2.drm.DrmSession.DrmSessionException) SchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData) Nullable(androidx.annotation.Nullable) Nullable(androidx.annotation.Nullable)

Example 3 with EventDispatcher

use of com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher in project ExoPlayer by google.

the class OfflineLicenseHelper method getLicenseDurationRemainingSec.

/**
 * Returns the remaining license and playback durations in seconds, for an offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license.
 * @return The remaining license and playback durations, in seconds.
 * @throws DrmSessionException Thrown when a DRM session error occurs.
 */
public synchronized Pair<Long, Long> getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId) throws DrmSessionException {
    Assertions.checkNotNull(offlineLicenseKeySetId);
    drmSessionManager.setPlayer(handlerThread.getLooper(), PlayerId.UNSET);
    drmSessionManager.prepare();
    DrmSession drmSession = openBlockingKeyRequest(DefaultDrmSessionManager.MODE_QUERY, offlineLicenseKeySetId, FORMAT_WITH_EMPTY_DRM_INIT_DATA);
    DrmSessionException error = drmSession.getError();
    Pair<Long, Long> licenseDurationRemainingSec = WidevineUtil.getLicenseDurationRemainingSec(drmSession);
    drmSession.release(eventDispatcher);
    drmSessionManager.release();
    if (error != null) {
        if (error.getCause() instanceof KeysExpiredException) {
            return Pair.create(0L, 0L);
        }
        throw error;
    }
    return Assertions.checkNotNull(licenseDurationRemainingSec);
}
Also used : DrmSessionException(com.google.android.exoplayer2.drm.DrmSession.DrmSessionException)

Example 4 with EventDispatcher

use of com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher in project ExoPlayer by google.

the class MergingMediaPeriodTest method prepareMergingPeriod.

private MergingMediaPeriod prepareMergingPeriod(MergingPeriodDefinition... definitions) throws Exception {
    MediaPeriod[] mediaPeriods = new MediaPeriod[definitions.length];
    long[] timeOffsetsUs = new long[definitions.length];
    for (int i = 0; i < definitions.length; i++) {
        MergingPeriodDefinition definition = definitions[i];
        timeOffsetsUs[i] = definition.timeOffsetUs;
        TrackGroup[] trackGroups = new TrackGroup[definition.formats.length];
        for (int j = 0; j < definition.formats.length; j++) {
            trackGroups[j] = new TrackGroup(definition.formats[j]);
        }
        mediaPeriods[i] = new FakeMediaPeriodWithSelectTracksPosition(new TrackGroupArray(trackGroups), new EventDispatcher().withParameters(/* windowIndex= */
        i, new MediaPeriodId(/* periodUid= */
        i), /* mediaTimeOffsetMs= */
        0), /* trackDataFactory= */
        (unusedFormat, unusedMediaPeriodId) -> ImmutableList.of(oneByteSample(definition.singleSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
    }
    MergingMediaPeriod mergingMediaPeriod = new MergingMediaPeriod(new DefaultCompositeSequenceableLoaderFactory(), timeOffsetsUs, mediaPeriods);
    CountDownLatch prepareCountDown = new CountDownLatch(1);
    mergingMediaPeriod.prepare(new MediaPeriod.Callback() {

        @Override
        public void onPrepared(MediaPeriod mediaPeriod) {
            prepareCountDown.countDown();
        }

        @Override
        public void onContinueLoadingRequested(MediaPeriod source) {
            mergingMediaPeriod.continueLoading(/* positionUs= */
            0);
        }
    }, /* positionUs= */
    0);
    prepareCountDown.await();
    return mergingMediaPeriod;
}
Also used : FLAG_REQUIRE_FORMAT(com.google.android.exoplayer2.source.SampleStream.FLAG_REQUIRE_FORMAT) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) EventDispatcher(com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) Format(com.google.android.exoplayer2.Format) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) CountDownLatch(java.util.concurrent.CountDownLatch) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) FormatHolder(com.google.android.exoplayer2.FormatHolder) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ImmutableList(com.google.common.collect.ImmutableList) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) C(com.google.android.exoplayer2.C) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) CountDownLatch(java.util.concurrent.CountDownLatch) EventDispatcher(com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod)

Example 5 with EventDispatcher

use of com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher in project ExoPlayer by google.

the class DefaultDrmSessionManagerTest method managerRelease_mediaDrmNotReleasedUntilLastSessionReleased.

@Test(timeout = 10_000)
public void managerRelease_mediaDrmNotReleasedUntilLastSessionReleased() throws Exception {
    FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS);
    FakeExoMediaDrm exoMediaDrm = new FakeExoMediaDrm();
    DrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, new AppManagedProvider(exoMediaDrm)).setSessionKeepaliveMs(10_000).build(/* mediaDrmCallback= */
    licenseServer);
    drmSessionManager.prepare();
    drmSessionManager.setPlayer(/* playbackLooper= */
    Looper.myLooper(), PlayerId.UNSET);
    DrmSession drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    drmSessionManager.release();
    // The manager is now in a 'releasing' state because the session is still active - so the
    // ExoMediaDrm instance should still be active (with 1 reference held by this test, and 1 held
    // by the manager).
    assertThat(exoMediaDrm.getReferenceCount()).isEqualTo(2);
    // And re-preparing the session shouldn't acquire another reference.
    drmSessionManager.prepare();
    assertThat(exoMediaDrm.getReferenceCount()).isEqualTo(2);
    drmSessionManager.release();
    drmSession.release(/* eventDispatcher= */
    null);
    // The final session has been released, so now the ExoMediaDrm should be released too.
    assertThat(exoMediaDrm.getReferenceCount()).isEqualTo(1);
    // Re-preparing the fully released manager should now acquire another ExoMediaDrm reference.
    drmSessionManager.prepare();
    assertThat(exoMediaDrm.getReferenceCount()).isEqualTo(2);
    drmSessionManager.release();
    exoMediaDrm.release();
}
Also used : AppManagedProvider(com.google.android.exoplayer2.drm.ExoMediaDrm.AppManagedProvider) FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 FakeExoMediaDrm (com.google.android.exoplayer2.testutil.FakeExoMediaDrm)15 AppManagedProvider (com.google.android.exoplayer2.drm.ExoMediaDrm.AppManagedProvider)7 DrmSessionReference (com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference)5 Nullable (androidx.annotation.Nullable)3 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)3 C (com.google.android.exoplayer2.C)3 Format (com.google.android.exoplayer2.Format)3 DrmSessionException (com.google.android.exoplayer2.drm.DrmSession.DrmSessionException)3 MediaSource (com.google.android.exoplayer2.source.MediaSource)3 ImmutableList (com.google.common.collect.ImmutableList)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 RunWith (org.junit.runner.RunWith)3 Looper (android.os.Looper)2 FormatHolder (com.google.android.exoplayer2.FormatHolder)2 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)2 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)2