Skip to content

Commit

Permalink
Add MediaSourceFactory#setDrmSessionManagerProvider()
Browse files Browse the repository at this point in the history
Deprecate other DRM config methods.

Issue: #8466
PiperOrigin-RevId: 353251452
  • Loading branch information
icbaker authored and kim-vde committed Jan 22, 2021
1 parent 9825e5f commit 5b9fa7d
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 40 deletions.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@
waiting for the response. This fixes (harmless) `IllegalStateException:
sending message to a Handler on a dead thread` log messages
([#8328](https://github.com/google/ExoPlayer/issues/8328)).
* Allow apps to fully customize DRM behaviour per-`MediaItem` by passing a
`DrmSessionManagerProvider` to `MediaSourceFactory`
([#8466](https://github.com/google/ExoPlayer/issues/8466)).
* Analytics:
* Pass a `DecoderReuseEvaluation` to `AnalyticsListener`'s
`onVideoInputFormatChanged` and `onAudioInputFormatChanged` methods. The
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 The Android Open Source Project
* Copyright 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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.drm.DrmSessionManagerProvider;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.offline.StreamKey;
Expand Down Expand Up @@ -101,14 +102,14 @@ public interface AdsLoaderProvider {

private static final String TAG = "DefaultMediaSourceFactory";

private final DefaultDrmSessionManagerProvider drmSessionManagerProvider;
private final DataSource.Factory dataSourceFactory;
private final SparseArray<MediaSourceFactory> mediaSourceFactories;
@C.ContentType private final int[] supportedTypes;

@Nullable private AdsLoaderProvider adsLoaderProvider;
@Nullable private AdViewProvider adViewProvider;
@Nullable private DrmSessionManager drmSessionManager;
private boolean usingCustomDrmSessionManagerProvider;
private DrmSessionManagerProvider drmSessionManagerProvider;
@Nullable private List<StreamKey> streamKeys;
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private long liveTargetOffsetMs;
Expand Down Expand Up @@ -258,20 +259,42 @@ public DefaultMediaSourceFactory setLiveMaxSpeed(float maxSpeed) {
@Override
public DefaultMediaSourceFactory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory) {
drmSessionManagerProvider.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
if (!usingCustomDrmSessionManagerProvider) {
((DefaultDrmSessionManagerProvider) drmSessionManagerProvider)
.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
}
return this;
}

@Override
public DefaultMediaSourceFactory setDrmUserAgent(@Nullable String userAgent) {
drmSessionManagerProvider.setDrmUserAgent(userAgent);
if (!usingCustomDrmSessionManagerProvider) {
((DefaultDrmSessionManagerProvider) drmSessionManagerProvider).setDrmUserAgent(userAgent);
}
return this;
}

@Override
public DefaultMediaSourceFactory setDrmSessionManager(
@Nullable DrmSessionManager drmSessionManager) {
this.drmSessionManager = drmSessionManager;
if (drmSessionManager == null) {
setDrmSessionManagerProvider(null);
} else {
setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager);
}
return this;
}

@Override
public DefaultMediaSourceFactory setDrmSessionManagerProvider(
@Nullable DrmSessionManagerProvider drmSessionManagerProvider) {
if (drmSessionManagerProvider != null) {
this.drmSessionManagerProvider = drmSessionManagerProvider;
this.usingCustomDrmSessionManagerProvider = true;
} else {
this.drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
this.usingCustomDrmSessionManagerProvider = false;
}
return this;
}

Expand Down Expand Up @@ -310,8 +333,7 @@ public MediaSource createMediaSource(MediaItem mediaItem) {
@Nullable MediaSourceFactory mediaSourceFactory = mediaSourceFactories.get(type);
Assertions.checkNotNull(
mediaSourceFactory, "No suitable media source factory found for content type: " + type);
mediaSourceFactory.setDrmSessionManager(
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem));
mediaSourceFactory.setDrmSessionManagerProvider(drmSessionManagerProvider);
mediaSourceFactory.setStreamKeys(
!mediaItem.playbackProperties.streamKeys.isEmpty()
? mediaItem.playbackProperties.streamKeys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.drm.DrmSessionManagerProvider;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
Expand Down Expand Up @@ -154,6 +155,18 @@ public Factory setContinueLoadingCheckIntervalBytes(int continueLoadingCheckInte
return this;
}

/**
* @deprecated Use {@link
* ProgressiveMediaSource.Factory#setDrmSessionManagerProvider(DrmSessionManagerProvider)}
* instead.
*/
@Deprecated
@Override
public Factory setDrmSessionManagerProvider(
@Nullable DrmSessionManagerProvider drmSessionManagerProvider) {
throw new UnsupportedOperationException();
}

/** @deprecated Use {@link ProgressiveMediaSource.Factory#setDrmSessionManager} instead. */
@Deprecated
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.drm.DrmSessionManagerProvider;
import com.google.android.exoplayer2.drm.HttpMediaDrmCallback;
import com.google.android.exoplayer2.offline.StreamKey;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
Expand Down Expand Up @@ -56,41 +58,80 @@ default MediaSourceFactory setStreamKeys(@Nullable List<StreamKey> streamKeys) {
return this;
}

/**
* Sets the {@link DrmSessionManagerProvider} used to obtain a {@link DrmSessionManager} for a
* {@link MediaItem}.
*
* <p>If not set, {@link DefaultDrmSessionManagerProvider} is used.
*
* <p>If set, calls to the following (deprecated) methods are ignored:
*
* <ul>
* <li>{@link #setDrmUserAgent(String)}
* <li>{@link #setDrmHttpDataSourceFactory(HttpDataSource.Factory)}
* </ul>
*
* @return This factory, for convenience.
*/
MediaSourceFactory setDrmSessionManagerProvider(
@Nullable DrmSessionManagerProvider drmSessionManagerProvider);

/**
* Sets the {@link DrmSessionManager} to use for all media items regardless of their {@link
* MediaItem.DrmConfiguration}.
*
* <p>Calling this with a non-null {@code drmSessionManager} is equivalent to calling {@code
* setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager)}.
*
* @param drmSessionManager The {@link DrmSessionManager}, or {@code null} to use the {@link
* DefaultDrmSessionManager}.
* @return This factory, for convenience.
* @deprecated Use {@link #setDrmSessionManagerProvider(DrmSessionManagerProvider)} and pass an
* implementation that always returns the same instance.
*/
@Deprecated
MediaSourceFactory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManager);

/**
* Sets the {@link HttpDataSource.Factory} to be used for creating {@link HttpMediaDrmCallback
* HttpMediaDrmCallbacks} to execute key and provisioning requests over HTTP.
*
* <p>In case a {@link DrmSessionManager} has been set by {@link
* #setDrmSessionManager(DrmSessionManager)}, this data source factory is ignored.
* <p>Calls to this method are ignored if either a {@link
* #setDrmSessionManagerProvider(DrmSessionManagerProvider) DrmSessionManager provider} or {@link
* #setDrmSessionManager(DrmSessionManager) concrete DrmSessionManager} are provided.
*
* @param drmHttpDataSourceFactory The HTTP data source factory, or {@code null} to use {@link
* DefaultHttpDataSourceFactory}.
* @return This factory, for convenience.
* @deprecated Use {@link #setDrmSessionManagerProvider(DrmSessionManagerProvider)} and pass an
* implementation that configures the returned {@link DrmSessionManager} with the desired
* {@link HttpDataSource.Factory}.
*/
@Deprecated
MediaSourceFactory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory);

/**
* Sets the optional user agent to be used for DRM requests.
*
* <p>In case a factory has been set by {@link
* #setDrmHttpDataSourceFactory(HttpDataSource.Factory)} or a {@link DrmSessionManager} has been
* set by {@link #setDrmSessionManager(DrmSessionManager)}, this user agent is ignored.
* <p>Calls to this method are ignored if any of the following are provided:
*
* <ul>
* <li>A {@link #setDrmSessionManagerProvider(DrmSessionManagerProvider) DrmSessionManager
* provider}.
* <li>A {@link #setDrmSessionManager(DrmSessionManager) concrete DrmSessionManager}.
* <li>A {@link #setDrmHttpDataSourceFactory(HttpDataSource.Factory) DRM
* HttpDataSource.Factory}.
* </ul>
*
* @param userAgent The user agent to be used for DRM requests, or {@code null} to use the
* default.
* @return This factory, for convenience.
* @deprecated Use {@link #setDrmSessionManagerProvider(DrmSessionManagerProvider)} and pass an
* implementation that configures the returned {@link DrmSessionManager} with the desired
* {@code userAgent}.
*/
@Deprecated
MediaSourceFactory setDrmUserAgent(@Nullable String userAgent);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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.drm.DrmSessionManagerProvider;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
Expand Down Expand Up @@ -52,10 +53,10 @@ public final class ProgressiveMediaSource extends BaseMediaSource
public static final class Factory implements MediaSourceFactory {

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

private ExtractorsFactory extractorsFactory;
@Nullable private DrmSessionManager drmSessionManager;
private boolean usingCustomDrmSessionManagerProvider;
private DrmSessionManagerProvider drmSessionManagerProvider;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private int continueLoadingCheckIntervalBytes;
@Nullable private String customCacheKey;
Expand Down Expand Up @@ -149,21 +150,42 @@ public Factory setContinueLoadingCheckIntervalBytes(int continueLoadingCheckInte
}

@Override
public Factory setDrmSessionManagerProvider(
@Nullable DrmSessionManagerProvider drmSessionManagerProvider) {
if (drmSessionManagerProvider != null) {
this.drmSessionManagerProvider = drmSessionManagerProvider;
this.usingCustomDrmSessionManagerProvider = true;
} else {
this.drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
this.usingCustomDrmSessionManagerProvider = false;
}
return this;
}

public Factory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManager) {
this.drmSessionManager = drmSessionManager;
if (drmSessionManager == null) {
setDrmSessionManagerProvider(null);
} else {
setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager);
}
return this;
}

@Override
public Factory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory) {
drmSessionManagerProvider.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
if (!usingCustomDrmSessionManagerProvider) {
((DefaultDrmSessionManagerProvider) drmSessionManagerProvider)
.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
}
return this;
}

@Override
public Factory setDrmUserAgent(@Nullable String userAgent) {
drmSessionManagerProvider.setDrmUserAgent(userAgent);
if (!usingCustomDrmSessionManagerProvider) {
((DefaultDrmSessionManagerProvider) drmSessionManagerProvider).setDrmUserAgent(userAgent);
}
return this;
}

Expand Down Expand Up @@ -199,7 +221,7 @@ public ProgressiveMediaSource createMediaSource(MediaItem mediaItem) {
mediaItem,
dataSourceFactory,
extractorsFactory,
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem),
drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
continueLoadingCheckIntervalBytes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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.drm.DrmSessionManagerProvider;
import com.google.android.exoplayer2.offline.FilteringManifestParser;
import com.google.android.exoplayer2.offline.StreamKey;
import com.google.android.exoplayer2.source.BaseMediaSource;
Expand Down Expand Up @@ -99,10 +100,10 @@ public final class DashMediaSource extends BaseMediaSource {
public static final class Factory implements MediaSourceFactory {

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

@Nullable private DrmSessionManager drmSessionManager;
private boolean usingCustomDrmSessionManagerProvider;
private DrmSessionManagerProvider drmSessionManagerProvider;
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private long targetLiveOffsetOverrideMs;
Expand Down Expand Up @@ -165,22 +166,44 @@ public Factory setStreamKeys(@Nullable List<StreamKey> streamKeys) {
return this;
}

@Override
public Factory setDrmSessionManagerProvider(
@Nullable DrmSessionManagerProvider drmSessionManagerProvider) {
if (drmSessionManagerProvider != null) {
this.drmSessionManagerProvider = drmSessionManagerProvider;
this.usingCustomDrmSessionManagerProvider = true;
} else {
this.drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
this.usingCustomDrmSessionManagerProvider = false;
}
return this;
}

@Override
public Factory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManager) {
this.drmSessionManager = drmSessionManager;
if (drmSessionManager == null) {
setDrmSessionManagerProvider(null);
} else {
setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager);
}
return this;
}

@Override
public Factory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory) {
drmSessionManagerProvider.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
if (!usingCustomDrmSessionManagerProvider) {
((DefaultDrmSessionManagerProvider) drmSessionManagerProvider)
.setDrmHttpDataSourceFactory(drmHttpDataSourceFactory);
}
return this;
}

@Override
public Factory setDrmUserAgent(@Nullable String userAgent) {
drmSessionManagerProvider.setDrmUserAgent(userAgent);
if (!usingCustomDrmSessionManagerProvider) {
((DefaultDrmSessionManagerProvider) drmSessionManagerProvider).setDrmUserAgent(userAgent);
}
return this;
}

Expand Down Expand Up @@ -319,7 +342,7 @@ public DashMediaSource createMediaSource(DashManifest manifest, MediaItem mediaI
/* manifestParser= */ null,
chunkSourceFactory,
compositeSequenceableLoaderFactory,
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem),
drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
fallbackTargetLiveOffsetMs);
}
Expand Down Expand Up @@ -385,7 +408,7 @@ public DashMediaSource createMediaSource(MediaItem mediaItem) {
manifestParser,
chunkSourceFactory,
compositeSequenceableLoaderFactory,
drmSessionManager != null ? drmSessionManager : drmSessionManagerProvider.get(mediaItem),
drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
fallbackTargetLiveOffsetMs);
}
Expand Down
Loading

0 comments on commit 5b9fa7d

Please sign in to comment.