Search in sources :

Example 16 with DrmSession

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

the class DefaultDrmSessionManagerTest method keepaliveDisabled_sessionsReleasedImmediately.

@Test(timeout = 10_000)
public void keepaliveDisabled_sessionsReleasedImmediately() 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);
    drmSession.release(/* eventDispatcher= */
    null);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
}
Also used : FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Example 17 with DrmSession

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

the class DefaultDrmSessionManagerTest method managerRelease_allKeepaliveSessionsImmediatelyReleased.

@Test(timeout = 10_000)
public void managerRelease_allKeepaliveSessionsImmediatelyReleased() 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 drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    waitForOpenedWithKeys(drmSession);
    drmSession.release(/* eventDispatcher= */
    null);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    drmSessionManager.release();
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
}
Also used : FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Example 18 with DrmSession

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

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

Example 19 with DrmSession

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

the class DefaultDrmSessionManagerTest method keyRefreshEvent_triggersKeyRefresh.

@Test(timeout = 10_000)
public void keyRefreshEvent_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);
    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);
    drmSessionManager.release();
    exoMediaDrm.release();
}
Also used : AppManagedProvider(androidx.media3.exoplayer.drm.ExoMediaDrm.AppManagedProvider) FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Example 20 with DrmSession

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

the class DefaultDrmSessionManagerTest method keepaliveEnabled_sessionsKeptForRequestedTime.

@Test(timeout = 10_000)
public void keepaliveEnabled_sessionsKeptForRequestedTime() 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 drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    waitForOpenedWithKeys(drmSession);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    drmSession.release(/* eventDispatcher= */
    null);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    ShadowLooper.idleMainLooper(10, SECONDS);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
}
Also used : 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