Search in sources :

Example 6 with DrmSessionManager

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

the class SampleQueue method onFormatResult.

/**
 * Sets the downstream format, performs DRM resource management, and populates the {@code
 * outputFormatHolder}.
 *
 * @param newFormat The new downstream format.
 * @param outputFormatHolder The output {@link FormatHolder}.
 */
private void onFormatResult(Format newFormat, FormatHolder outputFormatHolder) {
    boolean isFirstFormat = downstreamFormat == null;
    @Nullable DrmInitData oldDrmInitData = isFirstFormat ? null : downstreamFormat.drmInitData;
    downstreamFormat = newFormat;
    @Nullable DrmInitData newDrmInitData = newFormat.drmInitData;
    outputFormatHolder.format = drmSessionManager != null ? newFormat.copyWithCryptoType(drmSessionManager.getCryptoType(newFormat)) : newFormat;
    outputFormatHolder.drmSession = currentDrmSession;
    if (drmSessionManager == null) {
        // This sample queue is not expected to handle DRM. Nothing to do.
        return;
    }
    if (!isFirstFormat && Util.areEqual(oldDrmInitData, newDrmInitData)) {
        // Nothing to do.
        return;
    }
    // Ensure we acquire the new session before releasing the previous one in case the same session
    // is being used for both DrmInitData.
    @Nullable DrmSession previousSession = currentDrmSession;
    currentDrmSession = drmSessionManager.acquireSession(drmEventDispatcher, newFormat);
    outputFormatHolder.drmSession = currentDrmSession;
    if (previousSession != null) {
        previousSession.release(drmEventDispatcher);
    }
}
Also used : DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) DrmSession(com.google.android.exoplayer2.drm.DrmSession) Nullable(androidx.annotation.Nullable)

Example 7 with DrmSessionManager

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

the class DefaultDrmSessionManagerProviderTest method create_reusesCachedInstanceWherePossible.

@Test
public void create_reusesCachedInstanceWherePossible() {
    MediaItem mediaItem1 = new MediaItem.Builder().setUri("https://example.test/content-1").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).build()).build();
    // Same DRM info as item1, but different URL to check it doesn't prevent re-using a manager.
    MediaItem mediaItem2 = new MediaItem.Builder().setUri("https://example.test/content-2").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).build()).build();
    // Different DRM info to 1 and 2, needs a different manager instance.
    MediaItem mediaItem3 = new MediaItem.Builder().setUri("https://example.test/content-3").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).setLicenseUri("https://example.test/license").build()).build();
    DefaultDrmSessionManagerProvider provider = new DefaultDrmSessionManagerProvider();
    DrmSessionManager drmSessionManager1 = provider.get(mediaItem1);
    DrmSessionManager drmSessionManager2 = provider.get(mediaItem2);
    DrmSessionManager drmSessionManager3 = provider.get(mediaItem3);
    // Get a manager for the first item again - expect it to be a different instance to last time
    // since we only cache one.
    DrmSessionManager drmSessionManager4 = provider.get(mediaItem1);
    assertThat(drmSessionManager1).isSameInstanceAs(drmSessionManager2);
    assertThat(drmSessionManager1).isNotSameInstanceAs(drmSessionManager3);
    assertThat(drmSessionManager1).isNotSameInstanceAs(drmSessionManager4);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultDrmSessionManagerProvider(com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider) Test(org.junit.Test)

Example 8 with DrmSessionManager

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

the class DefaultDrmSessionManagerProviderTest method create_createsManager.

@Test
public void create_createsManager() {
    MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).setLicenseUri(Uri.EMPTY).build()).build();
    DrmSessionManager drmSessionManager = new DefaultDrmSessionManagerProvider().get(mediaItem);
    assertThat(drmSessionManager).isNotEqualTo(DrmSessionManager.DRM_UNSUPPORTED);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultDrmSessionManagerProvider(com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider) Test(org.junit.Test)

Example 9 with DrmSessionManager

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

the class SsMediaPeriod method buildTrackGroups.

private static TrackGroupArray buildTrackGroups(SsManifest manifest, DrmSessionManager drmSessionManager) {
    TrackGroup[] trackGroups = new TrackGroup[manifest.streamElements.length];
    for (int i = 0; i < manifest.streamElements.length; i++) {
        Format[] manifestFormats = manifest.streamElements[i].formats;
        Format[] exposedFormats = new Format[manifestFormats.length];
        for (int j = 0; j < manifestFormats.length; j++) {
            Format manifestFormat = manifestFormats[j];
            exposedFormats[j] = manifestFormat.copyWithCryptoType(drmSessionManager.getCryptoType(manifestFormat));
        }
        trackGroups[i] = new TrackGroup(/* id= */
        Integer.toString(i), exposedFormats);
    }
    return new TrackGroupArray(trackGroups);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray)

Example 10 with DrmSessionManager

use of com.google.android.exoplayer2.drm.DrmSessionManager 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)33 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)20 FakeExoMediaDrm (com.google.android.exoplayer2.testutil.FakeExoMediaDrm)17 Nullable (androidx.annotation.Nullable)16 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)16 MediaSource (com.google.android.exoplayer2.source.MediaSource)15 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)14 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)12 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)12 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)12 Allocator (com.google.android.exoplayer2.upstream.Allocator)12 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)12 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)11 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)10 Format (com.google.android.exoplayer2.Format)9 AppManagedProvider (com.google.android.exoplayer2.drm.ExoMediaDrm.AppManagedProvider)7 Util (com.google.android.exoplayer2.util.Util)7 Intent (android.content.Intent)6 Uri (android.net.Uri)6 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)6