Search in sources :

Example 6 with DrmSession

use of androidx.media3.exoplayer.drm.DrmSession in project media by androidx.

the class DefaultDrmSessionManagerTest method managerReleasedBeforeSession_keepaliveEnabled_managerOnlyReleasesOneKeepaliveReference.

// https://github.com/google/ExoPlayer/issues/9193
@Test(timeout = 10_000)
public void managerReleasedBeforeSession_keepaliveEnabled_managerOnlyReleasesOneKeepaliveReference() throws Exception {
    FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS);
    FakeExoMediaDrm exoMediaDrm = new FakeExoMediaDrm.Builder().build();
    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));
    waitForOpenedWithKeys(drmSession);
    // Release the manager (there's still an explicit reference to the session from acquireSession).
    // This should immediately release the manager's internal keepalive session reference.
    drmSessionManager.release();
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    // Ensure the manager doesn't release a *second* keepalive session reference after the timer
    // expires.
    ShadowLooper.idleMainLooper(10, SECONDS);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    // Release the explicit session reference.
    drmSession.release(/* eventDispatcher= */
    null);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
}
Also used : AppManagedProvider(androidx.media3.exoplayer.drm.ExoMediaDrm.AppManagedProvider) FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Example 7 with DrmSession

use of androidx.media3.exoplayer.drm.DrmSession in project media by androidx.

the class DefaultDrmSessionManagerTest method provisioningUndoneWhileManagerIsActive_deviceReprovisioned.

@Test
public void provisioningUndoneWhileManagerIsActive_deviceReprovisioned() {
    FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS);
    FakeExoMediaDrm mediaDrm = new FakeExoMediaDrm.Builder().setProvisionsRequired(2).build();
    DefaultDrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, new AppManagedProvider(mediaDrm)).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));
    // Confirm that opening the session threw NotProvisionedException (otherwise state would be
    // OPENED)
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENING);
    waitForOpenedWithKeys(drmSession);
    drmSession.release(/* eventDispatcher= */
    null);
    mediaDrm.resetProvisioning();
    drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    // Confirm that opening the session threw NotProvisionedException (otherwise state would be
    // OPENED)
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENING);
    waitForOpenedWithKeys(drmSession);
    assertThat(licenseServer.getReceivedProvisionRequests()).hasSize(4);
}
Also used : AppManagedProvider(androidx.media3.exoplayer.drm.ExoMediaDrm.AppManagedProvider) FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Example 8 with DrmSession

use of androidx.media3.exoplayer.drm.DrmSession in project media by androidx.

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(androidx.media3.exoplayer.drm.ExoMediaDrm.AppManagedProvider) FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Example 9 with DrmSession

use of androidx.media3.exoplayer.drm.DrmSession in project media by androidx.

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(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Example 10 with DrmSession

use of androidx.media3.exoplayer.drm.DrmSession in project media by androidx.

the class DefaultDrmSessionManagerTest method maxConcurrentSessionsExceeded_allPreacquiredAndKeepaliveSessionsEagerlyReleased.

@Test(timeout = 10_000)
public void maxConcurrentSessionsExceeded_allPreacquiredAndKeepaliveSessionsEagerlyReleased() 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.Builder().setMaxConcurrentSessions(1).build()).setSessionKeepaliveMs(10_000).setMultiSession(true).build(/* mediaDrmCallback= */
    licenseServer);
    drmSessionManager.prepare();
    drmSessionManager.setPlayer(/* playbackLooper= */
    Looper.myLooper(), PlayerId.UNSET);
    DrmSessionReference firstDrmSessionReference = checkNotNull(drmSessionManager.preacquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    DrmSession firstDrmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    waitForOpenedWithKeys(firstDrmSession);
    firstDrmSession.release(/* eventDispatcher= */
    null);
    // The direct reference to firstDrmSession has been released, it's being kept alive by both
    // firstDrmSessionReference and 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 both it's internal keep-alive reference and the
    // reference represented by firstDrmSessionReference in order to acquire secondDrmSession.
    assertThat(firstDrmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
    waitForOpenedWithKeys(secondDrmSession);
    assertThat(secondDrmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    // Not needed (because the manager has already released this reference) but we call it anyway
    // for completeness.
    firstDrmSessionReference.release();
    // Clean-up
    secondDrmSession.release(/* eventDispatcher= */
    null);
    drmSessionManager.release();
}
Also used : Assertions.checkNotNull(androidx.media3.common.util.Assertions.checkNotNull) DrmInitData(androidx.media3.common.DrmInitData) AppManagedProvider(androidx.media3.exoplayer.drm.ExoMediaDrm.AppManagedProvider) Assert.assertThrows(org.junit.Assert.assertThrows) DrmSessionReference(androidx.media3.exoplayer.drm.DrmSessionManager.DrmSessionReference) RunWith(org.junit.runner.RunWith) FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Looper(android.os.Looper) TestUtil(androidx.media3.test.utils.TestUtil) MediaSource(androidx.media3.exoplayer.source.MediaSource) ImmutableSet(com.google.common.collect.ImmutableSet) ShadowLooper(org.robolectric.shadows.ShadowLooper) MimeTypes(androidx.media3.common.MimeTypes) Test(org.junit.Test) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) Util(androidx.media3.common.util.Util) Format(androidx.media3.common.Format) C(androidx.media3.common.C) Nullable(androidx.annotation.Nullable) PlayerId(androidx.media3.exoplayer.analytics.PlayerId) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Format(androidx.media3.common.Format) DrmInitData(androidx.media3.common.DrmInitData) DrmSessionReference(androidx.media3.exoplayer.drm.DrmSessionManager.DrmSessionReference) FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Aggregations

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