Commit 9974670c by aquilescanta Committed by Oliver Woodman

Make DownloadHelper pass DrmSessionManager to MediaSources

PiperOrigin-RevId: 283795201
parent 9c23888f
...@@ -615,10 +615,21 @@ public class PlayerActivity extends AppCompatActivity ...@@ -615,10 +615,21 @@ public class PlayerActivity extends AppCompatActivity
} }
MediaSourceFactory adMediaSourceFactory = MediaSourceFactory adMediaSourceFactory =
new MediaSourceFactory() { new MediaSourceFactory() {
private DrmSessionManager<ExoMediaCrypto> drmSessionManager =
DrmSessionManager.getDummyDrmSessionManager();
@Override
@SuppressWarnings("unchecked") // Safe upcasting.
public MediaSourceFactory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
this.drmSessionManager = (DrmSessionManager<ExoMediaCrypto>) drmSessionManager;
return this;
}
@Override @Override
public MediaSource createMediaSource(Uri uri) { public MediaSource createMediaSource(Uri uri) {
return PlayerActivity.this.createLeafMediaSource( return PlayerActivity.this.createLeafMediaSource(
uri, /* extension=*/ null, DrmSessionManager.getDummyDrmSessionManager()); uri, /* extension=*/ null, drmSessionManager);
} }
@Override @Override
......
...@@ -263,9 +263,13 @@ public final class DownloadHelper { ...@@ -263,9 +263,13 @@ public final class DownloadHelper {
uri, uri,
/* cacheKey= */ null, /* cacheKey= */ null,
createMediaSourceInternal( createMediaSourceInternal(
DASH_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null), DASH_FACTORY_CONSTRUCTOR,
uri,
dataSourceFactory,
drmSessionManager,
/* streamKeys= */ null),
trackSelectorParameters, trackSelectorParameters,
Util.getRendererCapabilities(renderersFactory, drmSessionManager)); Util.getRendererCapabilities(renderersFactory, /* drmSessionManager= */ null));
} }
/** @deprecated Use {@link #forHls(Context, Uri, Factory, RenderersFactory)} */ /** @deprecated Use {@link #forHls(Context, Uri, Factory, RenderersFactory)} */
...@@ -329,9 +333,13 @@ public final class DownloadHelper { ...@@ -329,9 +333,13 @@ public final class DownloadHelper {
uri, uri,
/* cacheKey= */ null, /* cacheKey= */ null,
createMediaSourceInternal( createMediaSourceInternal(
HLS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null), HLS_FACTORY_CONSTRUCTOR,
uri,
dataSourceFactory,
drmSessionManager,
/* streamKeys= */ null),
trackSelectorParameters, trackSelectorParameters,
Util.getRendererCapabilities(renderersFactory, drmSessionManager)); Util.getRendererCapabilities(renderersFactory, /* drmSessionManager= */ null));
} }
/** @deprecated Use {@link #forSmoothStreaming(Context, Uri, Factory, RenderersFactory)} */ /** @deprecated Use {@link #forSmoothStreaming(Context, Uri, Factory, RenderersFactory)} */
...@@ -395,9 +403,24 @@ public final class DownloadHelper { ...@@ -395,9 +403,24 @@ public final class DownloadHelper {
uri, uri,
/* cacheKey= */ null, /* cacheKey= */ null,
createMediaSourceInternal( createMediaSourceInternal(
SS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null), SS_FACTORY_CONSTRUCTOR,
uri,
dataSourceFactory,
drmSessionManager,
/* streamKeys= */ null),
trackSelectorParameters, trackSelectorParameters,
Util.getRendererCapabilities(renderersFactory, drmSessionManager)); Util.getRendererCapabilities(renderersFactory, /* drmSessionManager= */ null));
}
/**
* Equivalent to {@link #createMediaSource(DownloadRequest, Factory, DrmSessionManager)
* createMediaSource(downloadRequest, dataSourceFactory,
* DrmSessionManager.getDummyDrmSessionManager())}.
*/
public static MediaSource createMediaSource(
DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory) {
return createMediaSource(
downloadRequest, dataSourceFactory, DrmSessionManager.getDummyDrmSessionManager());
} }
/** /**
...@@ -409,7 +432,9 @@ public final class DownloadHelper { ...@@ -409,7 +432,9 @@ public final class DownloadHelper {
* @return A MediaSource which only contains the tracks defined in {@code downloadRequest}. * @return A MediaSource which only contains the tracks defined in {@code downloadRequest}.
*/ */
public static MediaSource createMediaSource( public static MediaSource createMediaSource(
DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory) { DownloadRequest downloadRequest,
DataSource.Factory dataSourceFactory,
DrmSessionManager<?> drmSessionManager) {
@Nullable Constructor<? extends MediaSourceFactory> constructor; @Nullable Constructor<? extends MediaSourceFactory> constructor;
switch (downloadRequest.type) { switch (downloadRequest.type) {
case DownloadRequest.TYPE_DASH: case DownloadRequest.TYPE_DASH:
...@@ -428,7 +453,11 @@ public final class DownloadHelper { ...@@ -428,7 +453,11 @@ public final class DownloadHelper {
throw new IllegalStateException("Unsupported type: " + downloadRequest.type); throw new IllegalStateException("Unsupported type: " + downloadRequest.type);
} }
return createMediaSourceInternal( return createMediaSourceInternal(
constructor, downloadRequest.uri, dataSourceFactory, downloadRequest.streamKeys); constructor,
downloadRequest.uri,
dataSourceFactory,
drmSessionManager,
downloadRequest.streamKeys);
} }
private final String downloadType; private final String downloadType;
...@@ -888,12 +917,16 @@ public final class DownloadHelper { ...@@ -888,12 +917,16 @@ public final class DownloadHelper {
@Nullable Constructor<? extends MediaSourceFactory> constructor, @Nullable Constructor<? extends MediaSourceFactory> constructor,
Uri uri, Uri uri,
Factory dataSourceFactory, Factory dataSourceFactory,
@Nullable DrmSessionManager<?> drmSessionManager,
@Nullable List<StreamKey> streamKeys) { @Nullable List<StreamKey> streamKeys) {
if (constructor == null) { if (constructor == null) {
throw new IllegalStateException("Module missing to create media source."); throw new IllegalStateException("Module missing to create media source.");
} }
try { try {
MediaSourceFactory factory = constructor.newInstance(dataSourceFactory); MediaSourceFactory factory = constructor.newInstance(dataSourceFactory);
if (drmSessionManager != null) {
factory.setDrmSessionManager(drmSessionManager);
}
if (streamKeys != null) { if (streamKeys != null) {
factory.setStreamKeys(streamKeys); factory.setStreamKeys(streamKeys);
} }
......
...@@ -179,6 +179,13 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> { ...@@ -179,6 +179,13 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
return this; return this;
} }
/** @deprecated Use {@link ProgressiveMediaSource.Factory#setDrmSessionManager} instead. */
@Override
@Deprecated
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
throw new UnsupportedOperationException();
}
/** /**
* Returns a new {@link ExtractorMediaSource} using the current parameters. * Returns a new {@link ExtractorMediaSource} using the current parameters.
* *
......
...@@ -17,6 +17,8 @@ package com.google.android.exoplayer2.source; ...@@ -17,6 +17,8 @@ package com.google.android.exoplayer2.source;
import android.net.Uri; import android.net.Uri;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.offline.StreamKey; import com.google.android.exoplayer2.offline.StreamKey;
import java.util.List; import java.util.List;
...@@ -35,6 +37,15 @@ public interface MediaSourceFactory { ...@@ -35,6 +37,15 @@ public interface MediaSourceFactory {
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
MediaSourceFactory setDrmSessionManager(DrmSessionManager<?> drmSessionManager);
/**
* Creates a new {@link MediaSource} with the specified {@code uri}. * Creates a new {@link MediaSource} with the specified {@code uri}.
* *
* @param uri The URI to play. * @param uri The URI to play.
......
...@@ -133,20 +133,6 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -133,20 +133,6 @@ public final class ProgressiveMediaSource extends BaseMediaSource
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Sets the {@link LoadErrorHandlingPolicy}. The default value is created by calling {@link * Sets the {@link LoadErrorHandlingPolicy}. The default value is created by calling {@link
* DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy()}. * DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy()}.
* *
...@@ -178,6 +164,21 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -178,6 +164,21 @@ public final class ProgressiveMediaSource extends BaseMediaSource
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
@Override
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Returns a new {@link ProgressiveMediaSource} using the current parameters. * Returns a new {@link ProgressiveMediaSource} using the current parameters.
* *
* @param uri The {@link Uri}. * @param uri The {@link Uri}.
......
...@@ -137,20 +137,6 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -137,20 +137,6 @@ public final class DashMediaSource extends BaseMediaSource {
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Sets the minimum number of times to retry if a loading error occurs. See {@link * Sets the minimum number of times to retry if a loading error occurs. See {@link
* #setLoadErrorHandlingPolicy} for the default value. * #setLoadErrorHandlingPolicy} for the default value.
* *
...@@ -311,6 +297,21 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -311,6 +297,21 @@ public final class DashMediaSource extends BaseMediaSource {
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
@Override
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Returns a new {@link DashMediaSource} using the current parameters. * Returns a new {@link DashMediaSource} using the current parameters.
* *
* @param manifestUri The manifest {@link Uri}. * @param manifestUri The manifest {@link Uri}.
......
...@@ -161,20 +161,6 @@ public final class HlsMediaSource extends BaseMediaSource ...@@ -161,20 +161,6 @@ public final class HlsMediaSource extends BaseMediaSource
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Sets the {@link LoadErrorHandlingPolicy}. The default value is created by calling {@link * Sets the {@link LoadErrorHandlingPolicy}. The default value is created by calling {@link
* DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy()}. * DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy()}.
* *
...@@ -327,6 +313,21 @@ public final class HlsMediaSource extends BaseMediaSource ...@@ -327,6 +313,21 @@ public final class HlsMediaSource extends BaseMediaSource
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
@Override
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Returns a new {@link HlsMediaSource} using the current parameters. * Returns a new {@link HlsMediaSource} using the current parameters.
* *
* @return The new {@link HlsMediaSource}. * @return The new {@link HlsMediaSource}.
......
...@@ -122,20 +122,6 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -122,20 +122,6 @@ public final class SsMediaSource extends BaseMediaSource
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Sets the minimum number of times to retry if a loading error occurs. See {@link * Sets the minimum number of times to retry if a loading error occurs. See {@link
* #setLoadErrorHandlingPolicy} for the default value. * #setLoadErrorHandlingPolicy} for the default value.
* *
...@@ -277,6 +263,21 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -277,6 +263,21 @@ public final class SsMediaSource extends BaseMediaSource
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
@Override
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Returns a new {@link SsMediaSource} using the current parameters. * Returns a new {@link SsMediaSource} using the current parameters.
* *
* @param manifestUri The manifest {@link Uri}. * @param manifestUri The manifest {@link Uri}.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment