Skip to content

Commit

Permalink
Rename MediaSourceDrmHelper to DefaultDrmSessionManagerProvider
Browse files Browse the repository at this point in the history
Also move it to the `drm` package, and extract a
`DrmSessionManagerProvider` interface.

I'll add `MediaSourceFactory.setDrmSessionProvider()` in a follow-up
change.

Issue: #8466
PiperOrigin-RevId: 352582559
  • Loading branch information
icbaker authored and ojw28 committed Jan 19, 2021
1 parent 3069251 commit b2a42ea
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.source;
package com.google.android.exoplayer2.drm;

import static com.google.android.exoplayer2.drm.DefaultDrmSessionManager.MODE_PLAYBACK;

import androidx.annotation.Nullable;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.drm.FrameworkMediaDrm;
import com.google.android.exoplayer2.drm.HttpMediaDrmCallback;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource;
Expand All @@ -31,8 +27,8 @@
import com.google.common.primitives.Ints;
import java.util.Map;

/** A helper to create a {@link DrmSessionManager} from a {@link MediaItem}. */
public final class MediaSourceDrmHelper {
/** Default implementation of {@link DrmSessionManagerProvider}. */
public final class DefaultDrmSessionManagerProvider implements DrmSessionManagerProvider {

@Nullable private HttpDataSource.Factory drmHttpDataSourceFactory;
@Nullable private String userAgent;
Expand Down Expand Up @@ -62,8 +58,8 @@ public void setDrmUserAgent(@Nullable String userAgent) {
this.userAgent = userAgent;
}

/** Creates a {@link DrmSessionManager} for the given media item. */
public DrmSessionManager create(MediaItem mediaItem) {
@Override
public DrmSessionManager get(MediaItem mediaItem) {
Assertions.checkNotNull(mediaItem.playbackProperties);
@Nullable
MediaItem.DrmConfiguration drmConfiguration = mediaItem.playbackProperties.drmConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.drm;

import com.google.android.exoplayer2.MediaItem;

/**
* A provider to obtain a {@link DrmSessionManager} suitable for playing the content described by a
* {@link MediaItem}.
*/
public interface DrmSessionManagerProvider {

/** Returns a {@link DrmSessionManager} for the given media item. */
DrmSessionManager get(MediaItem mediaItem);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
Expand Down Expand Up @@ -100,7 +101,7 @@ public interface AdsLoaderProvider {

private static final String TAG = "DefaultMediaSourceFactory";

private final MediaSourceDrmHelper mediaSourceDrmHelper;
private final DefaultDrmSessionManagerProvider drmSessionManagerProvider;
private final DataSource.Factory dataSourceFactory;
private final SparseArray<MediaSourceFactory> mediaSourceFactories;
@C.ContentType private final int[] supportedTypes;
Expand Down Expand Up @@ -157,7 +158,7 @@ public DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory) {
public DefaultMediaSourceFactory(
DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
this.dataSourceFactory = dataSourceFactory;
mediaSourceDrmHelper = new MediaSourceDrmHelper();
drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
mediaSourceFactories = loadDelegates(dataSourceFactory, extractorsFactory);
supportedTypes = new int[mediaSourceFactories.size()];
for (int i = 0; i < mediaSourceFactories.size(); i++) {
Expand Down Expand Up @@ -257,13 +258,13 @@ public DefaultMediaSourceFactory setLiveMaxSpeed(float maxSpeed) {
@Override
public DefaultMediaSourceFactory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory) {
mediaSourceDrmHelper.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
drmSessionManagerProvider.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
return this;
}

@Override
public DefaultMediaSourceFactory setDrmUserAgent(@Nullable String userAgent) {
mediaSourceDrmHelper.setDrmUserAgent(userAgent);
drmSessionManagerProvider.setDrmUserAgent(userAgent);
return this;
}

Expand Down Expand Up @@ -310,7 +311,7 @@ public MediaSource createMediaSource(MediaItem mediaItem) {
Assertions.checkNotNull(
mediaSourceFactory, "No suitable media source factory found for content type: " + type);
mediaSourceFactory.setDrmSessionManager(
drmSessionManager != null ? drmSessionManager : mediaSourceDrmHelper.create(mediaItem));
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem));
mediaSourceFactory.setStreamKeys(
!mediaItem.playbackProperties.streamKeys.isEmpty()
? mediaItem.playbackProperties.streamKeys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.Extractor;
Expand Down Expand Up @@ -51,7 +52,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
public static final class Factory implements MediaSourceFactory {

private final DataSource.Factory dataSourceFactory;
private final MediaSourceDrmHelper mediaSourceDrmHelper;
private final DefaultDrmSessionManagerProvider drmSessionManagerProvider;

private ExtractorsFactory extractorsFactory;
@Nullable private DrmSessionManager drmSessionManager;
Expand Down Expand Up @@ -79,7 +80,7 @@ public Factory(DataSource.Factory dataSourceFactory) {
public Factory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
this.dataSourceFactory = dataSourceFactory;
this.extractorsFactory = extractorsFactory;
mediaSourceDrmHelper = new MediaSourceDrmHelper();
drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES;
}
Expand Down Expand Up @@ -156,13 +157,13 @@ public Factory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManage
@Override
public Factory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory) {
mediaSourceDrmHelper.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
drmSessionManagerProvider.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
return this;
}

@Override
public Factory setDrmUserAgent(@Nullable String userAgent) {
mediaSourceDrmHelper.setDrmUserAgent(userAgent);
drmSessionManagerProvider.setDrmUserAgent(userAgent);
return this;
}

Expand Down Expand Up @@ -198,7 +199,7 @@ public ProgressiveMediaSource createMediaSource(MediaItem mediaItem) {
mediaItem,
dataSourceFactory,
extractorsFactory,
drmSessionManager != null ? drmSessionManager : mediaSourceDrmHelper.create(mediaItem),
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
continueLoadingCheckIntervalBytes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import org.junit.Test;
import org.junit.runner.RunWith;

/** Unit tests for {@link MediaSourceDrmHelper}. */
/** Unit tests for {@link DefaultDrmSessionManagerProvider}. */
@RunWith(AndroidJUnit4.class)
public class MediaSourceDrmHelperTest {
public class DefaultDrmSessionManagerProviderTest {

@Test
public void create_noDrmProperties_createsNoopManager() {
DrmSessionManager drmSessionManager =
new MediaSourceDrmHelper().create(MediaItem.fromUri(Uri.EMPTY));
new DefaultDrmSessionManagerProvider().get(MediaItem.fromUri(Uri.EMPTY));

assertThat(drmSessionManager).isEqualTo(DrmSessionManager.DUMMY);
}
Expand All @@ -46,7 +47,7 @@ public void create_createsManager() {
.setDrmUuid(C.WIDEVINE_UUID)
.build();

DrmSessionManager drmSessionManager = new MediaSourceDrmHelper().create(mediaItem);
DrmSessionManager drmSessionManager = new DefaultDrmSessionManagerProvider().get(mediaItem);

assertThat(drmSessionManager).isNotEqualTo(DrmSessionManager.DUMMY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider;
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.offline.FilteringManifestParser;
Expand All @@ -44,7 +45,6 @@
import com.google.android.exoplayer2.source.MediaLoadData;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceDrmHelper;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.MediaSourceFactory;
Expand Down Expand Up @@ -99,7 +99,7 @@ public final class DashMediaSource extends BaseMediaSource {
public static final class Factory implements MediaSourceFactory {

private final DashChunkSource.Factory chunkSourceFactory;
private final MediaSourceDrmHelper mediaSourceDrmHelper;
private final DefaultDrmSessionManagerProvider drmSessionManagerProvider;
@Nullable private final DataSource.Factory manifestDataSourceFactory;

@Nullable private DrmSessionManager drmSessionManager;
Expand Down Expand Up @@ -135,7 +135,7 @@ public Factory(
@Nullable DataSource.Factory manifestDataSourceFactory) {
this.chunkSourceFactory = checkNotNull(chunkSourceFactory);
this.manifestDataSourceFactory = manifestDataSourceFactory;
mediaSourceDrmHelper = new MediaSourceDrmHelper();
drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
targetLiveOffsetOverrideMs = C.TIME_UNSET;
fallbackTargetLiveOffsetMs = DEFAULT_FALLBACK_TARGET_LIVE_OFFSET_MS;
Expand Down Expand Up @@ -174,13 +174,13 @@ public Factory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManage
@Override
public Factory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory) {
mediaSourceDrmHelper.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
drmSessionManagerProvider.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
return this;
}

@Override
public Factory setDrmUserAgent(@Nullable String userAgent) {
mediaSourceDrmHelper.setDrmUserAgent(userAgent);
drmSessionManagerProvider.setDrmUserAgent(userAgent);
return this;
}

Expand Down Expand Up @@ -319,7 +319,7 @@ public DashMediaSource createMediaSource(DashManifest manifest, MediaItem mediaI
/* manifestParser= */ null,
chunkSourceFactory,
compositeSequenceableLoaderFactory,
drmSessionManager != null ? drmSessionManager : mediaSourceDrmHelper.create(mediaItem),
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
fallbackTargetLiveOffsetMs);
}
Expand Down Expand Up @@ -385,7 +385,7 @@ public DashMediaSource createMediaSource(MediaItem mediaItem) {
manifestParser,
chunkSourceFactory,
compositeSequenceableLoaderFactory,
drmSessionManager != null ? drmSessionManager : mediaSourceDrmHelper.create(mediaItem),
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
fallbackTargetLiveOffsetMs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider;
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.Extractor;
Expand All @@ -35,7 +36,6 @@
import com.google.android.exoplayer2.source.DefaultCompositeSequenceableLoaderFactory;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceDrmHelper;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.SequenceableLoader;
Expand Down Expand Up @@ -94,7 +94,7 @@ public final class HlsMediaSource extends BaseMediaSource
public static final class Factory implements MediaSourceFactory {

private final HlsDataSourceFactory hlsDataSourceFactory;
private final MediaSourceDrmHelper mediaSourceDrmHelper;
private final DefaultDrmSessionManagerProvider drmSessionManagerProvider;

private HlsExtractorFactory extractorFactory;
private HlsPlaylistParserFactory playlistParserFactory;
Expand Down Expand Up @@ -128,7 +128,7 @@ public Factory(DataSource.Factory dataSourceFactory) {
*/
public Factory(HlsDataSourceFactory hlsDataSourceFactory) {
this.hlsDataSourceFactory = checkNotNull(hlsDataSourceFactory);
mediaSourceDrmHelper = new MediaSourceDrmHelper();
drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
playlistParserFactory = new DefaultHlsPlaylistParserFactory();
playlistTrackerFactory = DefaultHlsPlaylistTracker.FACTORY;
extractorFactory = HlsExtractorFactory.DEFAULT;
Expand Down Expand Up @@ -289,13 +289,13 @@ public Factory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManage
@Override
public Factory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory) {
mediaSourceDrmHelper.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
drmSessionManagerProvider.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
return this;
}

@Override
public MediaSourceFactory setDrmUserAgent(@Nullable String userAgent) {
mediaSourceDrmHelper.setDrmUserAgent(userAgent);
drmSessionManagerProvider.setDrmUserAgent(userAgent);
return this;
}

Expand Down Expand Up @@ -369,7 +369,7 @@ public HlsMediaSource createMediaSource(MediaItem mediaItem) {
hlsDataSourceFactory,
extractorFactory,
compositeSequenceableLoaderFactory,
drmSessionManager != null ? drmSessionManager : mediaSourceDrmHelper.create(mediaItem),
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
playlistTrackerFactory.createTracker(
hlsDataSourceFactory, loadErrorHandlingPolicy, playlistParserFactory),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider;
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.offline.FilteringManifestParser;
Expand All @@ -38,7 +39,6 @@
import com.google.android.exoplayer2.source.MediaLoadData;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceDrmHelper;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.MediaSourceFactory;
Expand Down Expand Up @@ -78,7 +78,7 @@ public final class SsMediaSource extends BaseMediaSource
public static final class Factory implements MediaSourceFactory {

private final SsChunkSource.Factory chunkSourceFactory;
private final MediaSourceDrmHelper mediaSourceDrmHelper;
private final DefaultDrmSessionManagerProvider drmSessionManagerProvider;
@Nullable private final DataSource.Factory manifestDataSourceFactory;

private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
Expand Down Expand Up @@ -113,7 +113,7 @@ public Factory(
@Nullable DataSource.Factory manifestDataSourceFactory) {
this.chunkSourceFactory = checkNotNull(chunkSourceFactory);
this.manifestDataSourceFactory = manifestDataSourceFactory;
mediaSourceDrmHelper = new MediaSourceDrmHelper();
drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
livePresentationDelayMs = DEFAULT_LIVE_PRESENTATION_DELAY_MS;
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
Expand Down Expand Up @@ -200,13 +200,13 @@ public Factory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManage
@Override
public Factory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory) {
mediaSourceDrmHelper.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
drmSessionManagerProvider.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
return this;
}

@Override
public Factory setDrmUserAgent(@Nullable String userAgent) {
mediaSourceDrmHelper.setDrmUserAgent(userAgent);
drmSessionManagerProvider.setDrmUserAgent(userAgent);
return this;
}

Expand Down Expand Up @@ -277,7 +277,7 @@ public SsMediaSource createMediaSource(SsManifest manifest, MediaItem mediaItem)
/* manifestParser= */ null,
chunkSourceFactory,
compositeSequenceableLoaderFactory,
drmSessionManager != null ? drmSessionManager : mediaSourceDrmHelper.create(mediaItem),
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
livePresentationDelayMs);
}
Expand Down Expand Up @@ -321,7 +321,7 @@ public SsMediaSource createMediaSource(MediaItem mediaItem) {
manifestParser,
chunkSourceFactory,
compositeSequenceableLoaderFactory,
drmSessionManager != null ? drmSessionManager : mediaSourceDrmHelper.create(mediaItem),
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
livePresentationDelayMs);
}
Expand Down

0 comments on commit b2a42ea

Please sign in to comment.