mirror of
https://github.com/androidx/media.git
synced 2025-05-12 10:09:55 +08:00
Make DownloadHelper pass DrmSessionManager to MediaSources
PiperOrigin-RevId: 283795201
This commit is contained in:
parent
9c23888f1c
commit
9974670cc7
@ -615,10 +615,21 @@ public class PlayerActivity extends AppCompatActivity
|
||||
}
|
||||
MediaSourceFactory adMediaSourceFactory =
|
||||
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
|
||||
public MediaSource createMediaSource(Uri uri) {
|
||||
return PlayerActivity.this.createLeafMediaSource(
|
||||
uri, /* extension=*/ null, DrmSessionManager.getDummyDrmSessionManager());
|
||||
uri, /* extension=*/ null, drmSessionManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -263,9 +263,13 @@ public final class DownloadHelper {
|
||||
uri,
|
||||
/* cacheKey= */ null,
|
||||
createMediaSourceInternal(
|
||||
DASH_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
|
||||
DASH_FACTORY_CONSTRUCTOR,
|
||||
uri,
|
||||
dataSourceFactory,
|
||||
drmSessionManager,
|
||||
/* streamKeys= */ null),
|
||||
trackSelectorParameters,
|
||||
Util.getRendererCapabilities(renderersFactory, drmSessionManager));
|
||||
Util.getRendererCapabilities(renderersFactory, /* drmSessionManager= */ null));
|
||||
}
|
||||
|
||||
/** @deprecated Use {@link #forHls(Context, Uri, Factory, RenderersFactory)} */
|
||||
@ -329,9 +333,13 @@ public final class DownloadHelper {
|
||||
uri,
|
||||
/* cacheKey= */ null,
|
||||
createMediaSourceInternal(
|
||||
HLS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
|
||||
HLS_FACTORY_CONSTRUCTOR,
|
||||
uri,
|
||||
dataSourceFactory,
|
||||
drmSessionManager,
|
||||
/* streamKeys= */ null),
|
||||
trackSelectorParameters,
|
||||
Util.getRendererCapabilities(renderersFactory, drmSessionManager));
|
||||
Util.getRendererCapabilities(renderersFactory, /* drmSessionManager= */ null));
|
||||
}
|
||||
|
||||
/** @deprecated Use {@link #forSmoothStreaming(Context, Uri, Factory, RenderersFactory)} */
|
||||
@ -395,9 +403,24 @@ public final class DownloadHelper {
|
||||
uri,
|
||||
/* cacheKey= */ null,
|
||||
createMediaSourceInternal(
|
||||
SS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
|
||||
SS_FACTORY_CONSTRUCTOR,
|
||||
uri,
|
||||
dataSourceFactory,
|
||||
drmSessionManager,
|
||||
/* streamKeys= */ null),
|
||||
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 {
|
||||
* @return A MediaSource which only contains the tracks defined in {@code downloadRequest}.
|
||||
*/
|
||||
public static MediaSource createMediaSource(
|
||||
DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory) {
|
||||
DownloadRequest downloadRequest,
|
||||
DataSource.Factory dataSourceFactory,
|
||||
DrmSessionManager<?> drmSessionManager) {
|
||||
@Nullable Constructor<? extends MediaSourceFactory> constructor;
|
||||
switch (downloadRequest.type) {
|
||||
case DownloadRequest.TYPE_DASH:
|
||||
@ -428,7 +453,11 @@ public final class DownloadHelper {
|
||||
throw new IllegalStateException("Unsupported type: " + downloadRequest.type);
|
||||
}
|
||||
return createMediaSourceInternal(
|
||||
constructor, downloadRequest.uri, dataSourceFactory, downloadRequest.streamKeys);
|
||||
constructor,
|
||||
downloadRequest.uri,
|
||||
dataSourceFactory,
|
||||
drmSessionManager,
|
||||
downloadRequest.streamKeys);
|
||||
}
|
||||
|
||||
private final String downloadType;
|
||||
@ -888,12 +917,16 @@ public final class DownloadHelper {
|
||||
@Nullable Constructor<? extends MediaSourceFactory> constructor,
|
||||
Uri uri,
|
||||
Factory dataSourceFactory,
|
||||
@Nullable DrmSessionManager<?> drmSessionManager,
|
||||
@Nullable List<StreamKey> streamKeys) {
|
||||
if (constructor == null) {
|
||||
throw new IllegalStateException("Module missing to create media source.");
|
||||
}
|
||||
try {
|
||||
MediaSourceFactory factory = constructor.newInstance(dataSourceFactory);
|
||||
if (drmSessionManager != null) {
|
||||
factory.setDrmSessionManager(drmSessionManager);
|
||||
}
|
||||
if (streamKeys != null) {
|
||||
factory.setStreamKeys(streamKeys);
|
||||
}
|
||||
|
@ -179,6 +179,13 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
|
||||
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.
|
||||
*
|
||||
|
@ -17,6 +17,8 @@ package com.google.android.exoplayer2.source;
|
||||
|
||||
import android.net.Uri;
|
||||
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 java.util.List;
|
||||
|
||||
@ -34,6 +36,15 @@ public interface MediaSourceFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
*
|
||||
|
@ -132,20 +132,6 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy()}.
|
||||
@ -177,6 +163,21 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -136,20 +136,6 @@ public final class DashMediaSource extends BaseMediaSource {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* #setLoadErrorHandlingPolicy} for the default value.
|
||||
@ -310,6 +296,21 @@ public final class DashMediaSource extends BaseMediaSource {
|
||||
return mediaSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -160,20 +160,6 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy()}.
|
||||
@ -326,6 +312,21 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||
return mediaSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -121,20 +121,6 @@ public final class SsMediaSource extends BaseMediaSource
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* #setLoadErrorHandlingPolicy} for the default value.
|
||||
@ -276,6 +262,21 @@ public final class SsMediaSource extends BaseMediaSource
|
||||
return mediaSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user