Search in sources :

Example 11 with MediaDrmCallback

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

the class DefaultDrmSessionManagerTest method sessionReacquired_keepaliveTimeOutCancelled.

@Test(timeout = 10_000)
public void sessionReacquired_keepaliveTimeOutCancelled() throws Exception {
    FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS);
    DrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm()).setSessionKeepaliveMs(10_000).build(/* mediaDrmCallback= */
    licenseServer);
    drmSessionManager.prepare();
    drmSessionManager.setPlayer(/* playbackLooper= */
    Looper.myLooper(), PlayerId.UNSET);
    DrmSession firstDrmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    waitForOpenedWithKeys(firstDrmSession);
    firstDrmSession.release(/* eventDispatcher= */
    null);
    ShadowLooper.idleMainLooper(5, SECONDS);
    // Acquire a session for the same init data 5s in to the 10s timeout (so expect the same
    // instance).
    DrmSession secondDrmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    assertThat(secondDrmSession).isSameInstanceAs(firstDrmSession);
    // Let the timeout definitely expire, and check the session didn't get released.
    ShadowLooper.idleMainLooper(10, SECONDS);
    assertThat(secondDrmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
}
Also used : FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) Test(org.junit.Test)

Example 12 with MediaDrmCallback

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

the class DefaultDrmSessionManagerTest method preacquireSession_releaseBeforeUnderlyingAcquisitionCompletesReleasesSessionOnceAcquired.

@Test(timeout = 10_000)
public void preacquireSession_releaseBeforeUnderlyingAcquisitionCompletesReleasesSessionOnceAcquired() 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);
    DrmSessionReference sessionReference = drmSessionManager.preacquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA);
    // Release the pre-acquired reference before the underlying session has had a chance to be
    // constructed.
    sessionReference.release();
    // Acquiring the same session triggers a second key load (because the pre-acquired session was
    // fully released).
    DrmSession drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED);
    waitForOpenedWithKeys(drmSession);
    drmSession.release(/* eventDispatcher= */
    null);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
}
Also used : DrmSessionReference(com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference) FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) Test(org.junit.Test)

Example 13 with MediaDrmCallback

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

the class DefaultDrmSessionManagerTest method keyRefreshEvent_whileManagerIsReleasing_triggersKeyRefresh.

@Test(timeout = 10_000)
public void keyRefreshEvent_whileManagerIsReleasing_triggersKeyRefresh() throws Exception {
    FakeExoMediaDrm exoMediaDrm = new FakeExoMediaDrm();
    FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS);
    DrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, new AppManagedProvider(exoMediaDrm)).build(/* mediaDrmCallback= */
    licenseServer);
    drmSessionManager.prepare();
    drmSessionManager.setPlayer(/* playbackLooper= */
    Looper.myLooper(), PlayerId.UNSET);
    DefaultDrmSession drmSession = (DefaultDrmSession) checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    waitForOpenedWithKeys(drmSession);
    assertThat(licenseServer.getReceivedSchemeDatas()).hasSize(1);
    drmSessionManager.release();
    exoMediaDrm.triggerEvent(drmSession::hasSessionId, ExoMediaDrm.EVENT_KEY_REQUIRED, /* extra= */
    0, /* data= */
    Util.EMPTY_BYTE_ARRAY);
    while (licenseServer.getReceivedSchemeDatas().size() == 1) {
        // Allow the key refresh event to be handled.
        ShadowLooper.idleMainLooper();
    }
    assertThat(licenseServer.getReceivedSchemeDatas()).hasSize(2);
    assertThat(ImmutableSet.copyOf(licenseServer.getReceivedSchemeDatas())).hasSize(1);
    drmSession.release(/* eventDispatcher= */
    null);
    exoMediaDrm.release();
}
Also used : AppManagedProvider(com.google.android.exoplayer2.drm.ExoMediaDrm.AppManagedProvider) FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) Test(org.junit.Test)

Example 14 with MediaDrmCallback

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

the class DefaultDrmSessionManagerTest method preacquireSession_releaseManagerBeforeAcquisition_acquisitionDoesntHappen.

@Test(timeout = 10_000)
public void preacquireSession_releaseManagerBeforeAcquisition_acquisitionDoesntHappen() 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);
    DrmSessionReference sessionReference = drmSessionManager.preacquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA);
    // Release the manager before the underlying session has had a chance to be constructed. This
    // will release all pre-acquired sessions.
    drmSessionManager.release();
    // Allow the acquisition event to be handled on the main/playback thread.
    ShadowLooper.idleMainLooper();
    // Re-prepare the manager so we can fully acquire the same session, and check the previous
    // pre-acquisition didn't do anything.
    drmSessionManager.prepare();
    DrmSession drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED);
    waitForOpenedWithKeys(drmSession);
    drmSession.release(/* eventDispatcher= */
    null);
    // If the (still unreleased) pre-acquired session above was linked to the same underlying
    // session then the state would still be OPENED_WITH_KEYS.
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
    // Release the pre-acquired session from above (this is a no-op, but we do it anyway for
    // correctness).
    sessionReference.release();
    drmSessionManager.release();
}
Also used : DrmSessionReference(com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference) FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) Test(org.junit.Test)

Example 15 with MediaDrmCallback

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

the class DefaultDrmSessionManagerTest method maxConcurrentSessionsExceeded_allKeepAliveSessionsEagerlyReleased.

@Test(timeout = 10_000)
public void maxConcurrentSessionsExceeded_allKeepAliveSessionsEagerlyReleased() throws Exception {
    ImmutableList<DrmInitData.SchemeData> secondSchemeDatas = ImmutableList.of(DRM_SCHEME_DATAS.get(0).copyWithData(TestUtil.createByteArray(4, 5, 6)));
    FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS, secondSchemeDatas);
    Format secondFormatWithDrmInitData = new Format.Builder().setDrmInitData(new DrmInitData(secondSchemeDatas)).build();
    DrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm(/* maxConcurrentSessions= */
    1)).setSessionKeepaliveMs(10_000).setMultiSession(true).build(/* mediaDrmCallback= */
    licenseServer);
    drmSessionManager.prepare();
    drmSessionManager.setPlayer(/* playbackLooper= */
    Looper.myLooper(), PlayerId.UNSET);
    DrmSession firstDrmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    waitForOpenedWithKeys(firstDrmSession);
    firstDrmSession.release(/* eventDispatcher= */
    null);
    // All external references to firstDrmSession have been released, it's being kept alive by
    // drmSessionManager's internal reference.
    assertThat(firstDrmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    DrmSession secondDrmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, secondFormatWithDrmInitData));
    // The drmSessionManager had to release firstDrmSession in order to acquire secondDrmSession.
    assertThat(firstDrmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
    waitForOpenedWithKeys(secondDrmSession);
    assertThat(secondDrmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
}
Also used : Util(com.google.android.exoplayer2.util.Util) ImmutableSet(com.google.common.collect.ImmutableSet) ShadowLooper(org.robolectric.shadows.ShadowLooper) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestUtil(com.google.android.exoplayer2.testutil.TestUtil) Format(com.google.android.exoplayer2.Format) AppManagedProvider(com.google.android.exoplayer2.drm.ExoMediaDrm.AppManagedProvider) Nullable(androidx.annotation.Nullable) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Looper(android.os.Looper) Assertions.checkNotNull(com.google.android.exoplayer2.util.Assertions.checkNotNull) SECONDS(java.util.concurrent.TimeUnit.SECONDS) DrmSessionReference(com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference) MediaSource(com.google.android.exoplayer2.source.MediaSource) C(com.google.android.exoplayer2.C) Format(com.google.android.exoplayer2.Format) FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) Test(org.junit.Test)

Aggregations

FakeExoMediaDrm (com.google.android.exoplayer2.testutil.FakeExoMediaDrm)17 Test (org.junit.Test)17 AppManagedProvider (com.google.android.exoplayer2.drm.ExoMediaDrm.AppManagedProvider)7 DrmSessionReference (com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference)5 MediaSource (com.google.android.exoplayer2.source.MediaSource)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Looper (android.os.Looper)2 Nullable (androidx.annotation.Nullable)2 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 C (com.google.android.exoplayer2.C)2 Format (com.google.android.exoplayer2.Format)2 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)2 DefaultDrmSessionManager (com.google.android.exoplayer2.drm.DefaultDrmSessionManager)2 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)2 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)2 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)2 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)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