Document injection of DrmSessionManagers into MediaSources instead of Renderers

PiperOrigin-RevId: 263532499
This commit is contained in:
aquilescanta 2019-08-15 11:38:05 +01:00 committed by Andrew Lewis
parent 4b75d3338e
commit 6a122f4740
5 changed files with 113 additions and 48 deletions

View file

@ -36,6 +36,8 @@
quality video can be loaded up to the full default buffer duration.
* Replace `ExoPlayerFactory` by `SimpleExoPlayer.Builder` and
`ExoPlayer.Builder`.
* Inject `DrmSessionManager` into the `MediaSources` instead of `Renderers`
([#5619](https://github.com/google/ExoPlayer/issues/5619)).
### 2.10.4 ###

View file

@ -21,6 +21,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
@ -34,7 +35,11 @@ public final class ExoPlayerFactory {
private ExoPlayerFactory() {}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
@ -49,7 +54,11 @@ public final class ExoPlayerFactory {
context, renderersFactory, trackSelector, loadControl, drmSessionManager);
}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
@ -98,7 +107,11 @@ public final class ExoPlayerFactory {
return newSimpleInstance(context, renderersFactory, trackSelector, loadControl);
}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
@ -111,7 +124,11 @@ public final class ExoPlayerFactory {
context, renderersFactory, trackSelector, loadControl, drmSessionManager);
}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
@ -140,7 +157,11 @@ public final class ExoPlayerFactory {
Util.getLooper());
}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
@ -153,7 +174,11 @@ public final class ExoPlayerFactory {
context, renderersFactory, trackSelector, loadControl, drmSessionManager, Util.getLooper());
}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
@ -174,7 +199,11 @@ public final class ExoPlayerFactory {
Util.getLooper());
}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
@ -194,7 +223,11 @@ public final class ExoPlayerFactory {
Util.getLooper());
}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
@ -214,7 +247,11 @@ public final class ExoPlayerFactory {
looper);
}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
@ -236,7 +273,11 @@ public final class ExoPlayerFactory {
looper);
}
/** @deprecated Use {@link SimpleExoPlayer.Builder} instead. */
/**
* @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
* be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
* MediaSource} factories.
*/
@Deprecated
public static SimpleExoPlayer newSimpleInstance(
Context context,

View file

@ -92,7 +92,6 @@ public class SimpleExoPlayer extends BasePlayer
private Clock clock;
private TrackSelector trackSelector;
private LoadControl loadControl;
private DrmSessionManager<FrameworkMediaCrypto> drmSessionManager;
private BandwidthMeter bandwidthMeter;
private AnalyticsCollector analyticsCollector;
private Looper looper;
@ -111,7 +110,6 @@ public class SimpleExoPlayer extends BasePlayer
* <li>{@link RenderersFactory}: {@link DefaultRenderersFactory}
* <li>{@link TrackSelector}: {@link DefaultTrackSelector}
* <li>{@link LoadControl}: {@link DefaultLoadControl}
* <li>{@link DrmSessionManager}: {@link DrmSessionManager#getDummyDrmSessionManager()}
* <li>{@link BandwidthMeter}: {@link DefaultBandwidthMeter#getSingletonInstance(Context)}
* <li>{@link Looper}: The {@link Looper} associated with the current thread, or the {@link
* Looper} of the application's main thread if the current thread doesn't have a {@link
@ -141,7 +139,6 @@ public class SimpleExoPlayer extends BasePlayer
renderersFactory,
new DefaultTrackSelector(context),
new DefaultLoadControl(),
DrmSessionManager.getDummyDrmSessionManager(),
DefaultBandwidthMeter.getSingletonInstance(context),
Util.getLooper(),
new AnalyticsCollector(Clock.DEFAULT),
@ -160,7 +157,6 @@ public class SimpleExoPlayer extends BasePlayer
* player.
* @param trackSelector A {@link TrackSelector}.
* @param loadControl A {@link LoadControl}.
* @param drmSessionManager A {@link DrmSessionManager}.
* @param bandwidthMeter A {@link BandwidthMeter}.
* @param looper A {@link Looper} that must be used for all calls to the player.
* @param analyticsCollector An {@link AnalyticsCollector}.
@ -171,7 +167,6 @@ public class SimpleExoPlayer extends BasePlayer
RenderersFactory renderersFactory,
TrackSelector trackSelector,
LoadControl loadControl,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
BandwidthMeter bandwidthMeter,
Looper looper,
AnalyticsCollector analyticsCollector,
@ -180,7 +175,6 @@ public class SimpleExoPlayer extends BasePlayer
this.renderersFactory = renderersFactory;
this.trackSelector = trackSelector;
this.loadControl = loadControl;
this.drmSessionManager = drmSessionManager;
this.bandwidthMeter = bandwidthMeter;
this.looper = looper;
this.analyticsCollector = analyticsCollector;
@ -213,19 +207,6 @@ public class SimpleExoPlayer extends BasePlayer
return this;
}
/**
* Sets the {@link DrmSessionManager} that will be used for DRM protected playbacks.
*
* @param drmSessionManager A {@link DrmSessionManager}.
* @return This builder.
* @throws IllegalStateException If {@link #build()} has already been called.
*/
public Builder setDrmSessionManager(DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
Assertions.checkState(!buildCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Sets the {@link BandwidthMeter} that will be used by the player.
*
@ -294,7 +275,6 @@ public class SimpleExoPlayer extends BasePlayer
renderersFactory,
trackSelector,
loadControl,
drmSessionManager,
bandwidthMeter,
analyticsCollector,
clock,
@ -354,7 +334,11 @@ public class SimpleExoPlayer extends BasePlayer
* will not be used for DRM protected playbacks.
* @param looper The {@link Looper} which must be used for all calls to the player and which is
* used to call listeners on.
* @deprecated Use {@link #SimpleExoPlayer(Context, RenderersFactory, TrackSelector, LoadControl,
* BandwidthMeter, AnalyticsCollector, Clock, Looper)} instead, and pass the {@link
* DrmSessionManager} to the {@link MediaSource} factories.
*/
@Deprecated
protected SimpleExoPlayer(
Context context,
RenderersFactory renderersFactory,
@ -386,7 +370,11 @@ public class SimpleExoPlayer extends BasePlayer
* player events.
* @param looper The {@link Looper} which must be used for all calls to the player and which is
* used to call listeners on.
* @deprecated Use {@link #SimpleExoPlayer(Context, RenderersFactory, TrackSelector, LoadControl,
* BandwidthMeter, AnalyticsCollector, Clock, Looper)} instead, and pass the {@link
* DrmSessionManager} to the {@link MediaSource} factories.
*/
@Deprecated
protected SimpleExoPlayer(
Context context,
RenderersFactory renderersFactory,
@ -408,6 +396,41 @@ public class SimpleExoPlayer extends BasePlayer
looper);
}
/**
* @param context A {@link Context}.
* @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
* @param trackSelector The {@link TrackSelector} that will be used by the instance.
* @param loadControl The {@link LoadControl} that will be used by the instance.
* @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
* @param analyticsCollector A factory for creating the {@link AnalyticsCollector} that will
* collect and forward all player events.
* @param clock The {@link Clock} that will be used by the instance. Should always be {@link
* Clock#DEFAULT}, unless the player is being used from a test.
* @param looper The {@link Looper} which must be used for all calls to the player and which is
* used to call listeners on.
*/
@SuppressWarnings("deprecation")
protected SimpleExoPlayer(
Context context,
RenderersFactory renderersFactory,
TrackSelector trackSelector,
LoadControl loadControl,
BandwidthMeter bandwidthMeter,
AnalyticsCollector analyticsCollector,
Clock clock,
Looper looper) {
this(
context,
renderersFactory,
trackSelector,
loadControl,
DrmSessionManager.getDummyDrmSessionManager(),
bandwidthMeter,
analyticsCollector,
clock,
looper);
}
/**
* @param context A {@link Context}.
* @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
@ -422,7 +445,11 @@ public class SimpleExoPlayer extends BasePlayer
* Clock#DEFAULT}, unless the player is being used from a test.
* @param looper The {@link Looper} which must be used for all calls to the player and which is
* used to call listeners on.
* @deprecated Use {@link #SimpleExoPlayer(Context, RenderersFactory, TrackSelector, LoadControl,
* BandwidthMeter, AnalyticsCollector, Clock, Looper)} instead, and pass the {@link
* DrmSessionManager} to the {@link MediaSource} factories.
*/
@Deprecated
protected SimpleExoPlayer(
Context context,
RenderersFactory renderersFactory,

View file

@ -257,10 +257,10 @@ public final class DashTestRunner {
}
@Override
protected DefaultDrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManager(
protected DrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManager(
final String userAgent) {
if (widevineLicenseUrl == null) {
return null;
return DrmSessionManager.getDummyDrmSessionManager();
}
try {
MediaDrmCallback drmCallback = new HttpMediaDrmCallback(widevineLicenseUrl,
@ -283,27 +283,25 @@ public final class DashTestRunner {
@Override
protected SimpleExoPlayer buildExoPlayer(
HostActivity host,
Surface surface,
MappingTrackSelector trackSelector,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
HostActivity host, Surface surface, MappingTrackSelector trackSelector) {
SimpleExoPlayer player =
new SimpleExoPlayer.Builder(host, new DebugRenderersFactory(host))
.setTrackSelector(trackSelector)
.setDrmSessionManager(drmSessionManager)
.build();
player.setVideoSurface(surface);
return player;
}
@Override
protected MediaSource buildSource(HostActivity host, String userAgent) {
protected MediaSource buildSource(
HostActivity host, String userAgent, DrmSessionManager<?> drmSessionManager) {
DataSource.Factory dataSourceFactory =
this.dataSourceFactory != null
? this.dataSourceFactory
: new DefaultDataSourceFactory(host, userAgent);
Uri manifestUri = Uri.parse(manifestUrl);
return new DashMediaSource.Factory(dataSourceFactory)
.setDrmSessionManager(drmSessionManager)
.setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(MIN_LOADABLE_RETRY_COUNT))
.createMediaSource(manifestUri);
}

View file

@ -130,8 +130,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
// Build the player.
trackSelector = buildTrackSelector(host);
String userAgent = "ExoPlayerPlaybackTests";
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = buildDrmSessionManager(userAgent);
player = buildExoPlayer(host, surface, trackSelector, drmSessionManager);
player = buildExoPlayer(host, surface, trackSelector);
player.setPlayWhenReady(true);
player.addAnalyticsListener(this);
player.addAnalyticsListener(new EventLogger(trackSelector, tag));
@ -141,7 +140,8 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
pendingSchedule.start(player, trackSelector, surface, actionHandler, /* callback= */ null);
pendingSchedule = null;
}
player.prepare(buildSource(host, Util.getUserAgent(host, userAgent)));
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = buildDrmSessionManager(userAgent);
player.prepare(buildSource(host, Util.getUserAgent(host, userAgent), drmSessionManager));
}
@Override
@ -230,7 +230,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
protected DrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManager(String userAgent) {
// Do nothing. Interested subclasses may override.
return null;
return DrmSessionManager.getDummyDrmSessionManager();
}
protected DefaultTrackSelector buildTrackSelector(HostActivity host) {
@ -238,23 +238,20 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
}
protected SimpleExoPlayer buildExoPlayer(
HostActivity host,
Surface surface,
MappingTrackSelector trackSelector,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
HostActivity host, Surface surface, MappingTrackSelector trackSelector) {
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(host);
renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
renderersFactory.setAllowedVideoJoiningTimeMs(/* allowedVideoJoiningTimeMs= */ 0);
SimpleExoPlayer player =
new SimpleExoPlayer.Builder(host, renderersFactory)
.setTrackSelector(trackSelector)
.setDrmSessionManager(drmSessionManager)
.build();
player.setVideoSurface(surface);
return player;
}
protected abstract MediaSource buildSource(HostActivity host, String userAgent);
protected abstract MediaSource buildSource(
HostActivity host, String userAgent, DrmSessionManager<?> drmSessionManager);
protected void onPlayerErrorInternal(ExoPlaybackException error) {
// Do nothing. Interested subclasses may override.