Add DefaultDrmSessionManager.Builder

Issue:#6334
Issue:#4721
Issue:#6334
Issue:#4867
PiperOrigin-RevId: 271577773
This commit is contained in:
aquilescanta 2019-09-27 16:42:58 +01:00 committed by Oliver Woodman
parent 22c3be75ea
commit b50da6d72e
2 changed files with 154 additions and 6 deletions

View file

@ -2,13 +2,22 @@
### dev-v2 (not yet released) ###
* DRM:
* Inject `DrmSessionManager` into the `MediaSources` instead of `Renderers`
([#5619](https://github.com/google/ExoPlayer/issues/5619)).
* Add a `DefaultDrmSessionManager.Builder`.
* Add support for the use of secure decoders in clear sections of content
([#4867](https://github.com/google/ExoPlayer/issues/4867)).
* Add basic DRM support to the Cast demo app.
* Add support for custom `LoadErrorHandlingPolicies` in key and provisioning
requests ([#6334](https://github.com/google/ExoPlayer/issues/6334)).
* Remove `DefaultDrmSessionManager` factory methods that leak `ExoMediaDrm`
instances ([#4721](https://github.com/google/ExoPlayer/issues/4721)).
* Remove the `DataSpec.FLAG_ALLOW_ICY_METADATA` flag. Instead, set the header
`IcyHeaders.REQUEST_HEADER_ENABLE_METADATA_NAME` in the `DataSpec`
`httpRequestHeaders`.
* DASH: Support negative @r values in segment timelines
([#1787](https://github.com/google/ExoPlayer/issues/1787)).
* Remove `DefaultDrmSessionManager` factory methods that leak `ExoMediaDrm`
instances ([#4721](https://github.com/google/ExoPlayer/issues/4721)).
* Add `allowedCapturePolicy` field to `AudioAttributes` wrapper to allow to
opt-out of audio recording.
* Add `DataSpec.httpRequestHeaders` to set HTTP request headers when connecting
@ -24,7 +33,6 @@
display by default.
* Add `PlaybackStatsListener` to collect `PlaybackStats` for playbacks analysis
and analytics reporting (TODO: link to developer guide page/blog post).
* Add basic DRM support to the Cast demo app.
* Assume that encrypted content requires secure decoders in renderer support
checks ([#5568](https://github.com/google/ExoPlayer/issues/5568)).
* Decoders: Prefer decoders that advertise format support over ones that do not,
@ -50,8 +58,6 @@
the `Player` set later using `AnalyticsCollector.setPlayer`.
* Replace `ExoPlayerFactory` by `SimpleExoPlayer.Builder` and
`ExoPlayer.Builder`.
* Inject `DrmSessionManager` into the `MediaSources` instead of `Renderers`
([#5619](https://github.com/google/ExoPlayer/issues/5619)).
* Fix issue where player errors are thrown too early at playlist transitions
([#5407](https://github.com/google/ExoPlayer/issues/5407)).
* Deprecate `setTag` parameter of `Timeline.getWindow`. Tags will always be set.

View file

@ -39,6 +39,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/** A {@link DrmSessionManager} that supports playbacks using {@link ExoMediaDrm}. */
@ -46,6 +47,148 @@ import java.util.UUID;
public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
implements DrmSessionManager<T>, ProvisioningManager<T> {
/**
* Builder for {@link DefaultDrmSessionManager} instances.
*
* <p>See {@link #Builder} for the list of default values.
*/
public static final class Builder {
private final HashMap<String, String> keyRequestParameters;
private UUID uuid;
private ExoMediaDrm.Provider<ExoMediaCrypto> exoMediaDrmProvider;
private boolean multiSession;
private boolean allowPlaceholderSessions;
@Flags private int flags;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
/**
* Creates a builder with default values.
*
* <ul>
* <li>{@link #setKeyRequestParameters keyRequestParameters}: An empty map.
* <li>{@link #setUuidAndExoMediaDrmProvider UUID}: {@link C#WIDEVINE_UUID}.
* <li>{@link #setUuidAndExoMediaDrmProvider ExoMediaDrm.Provider}: {@link
* FrameworkMediaDrm#DEFAULT_PROVIDER}.
* <li>{@link #setMultiSession multiSession}: Not allowed by default.
* <li>{@link #setAllowPlaceholderSessions allowPlaceholderSession}: Not allowed by default.
* <li>{@link #setPlayClearSamplesWithoutKeys playClearSamplesWithoutKeys}: Not allowed by
* default.
* <li>{@link #setLoadErrorHandlingPolicy LoadErrorHandlingPolicy}: {@link
* DefaultLoadErrorHandlingPolicy}.
* </ul>
*/
@SuppressWarnings("unchecked")
public Builder() {
keyRequestParameters = new HashMap<>();
uuid = C.WIDEVINE_UUID;
exoMediaDrmProvider = (ExoMediaDrm.Provider) FrameworkMediaDrm.DEFAULT_PROVIDER;
multiSession = false;
allowPlaceholderSessions = false;
flags = 0;
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
}
/**
* Sets the parameters to pass to {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}.
*
* @param keyRequestParameters A map with parameters.
* @return This builder.
*/
public Builder setKeyRequestParameters(Map<String, String> keyRequestParameters) {
this.keyRequestParameters.clear();
this.keyRequestParameters.putAll(Assertions.checkNotNull(keyRequestParameters));
return this;
}
/**
* Sets the UUID of the DRM scheme and the {@link ExoMediaDrm.Provider} to use.
*
* @param uuid The UUID of the DRM scheme.
* @param exoMediaDrmProvider The {@link ExoMediaDrm.Provider}.
* @return This builder.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public Builder setUuidAndExoMediaDrmProvider(
UUID uuid, ExoMediaDrm.Provider exoMediaDrmProvider) {
this.uuid = Assertions.checkNotNull(uuid);
this.exoMediaDrmProvider = Assertions.checkNotNull(exoMediaDrmProvider);
return this;
}
/**
* Sets whether this session manager is allowed to acquire multiple simultaneous sessions.
*
* <p>Users should pass false when a single key request will obtain all keys required to decrypt
* the associated content. {@code multiSession} is required when content uses key rotation.
*
* @param multiSession Whether this session manager is allowed to acquire multiple simultaneous
* sessions.
* @return This builder.
*/
public Builder setMultiSession(boolean multiSession) {
this.multiSession = multiSession;
return this;
}
/**
* Sets whether this session manager is allowed to acquire placeholder sessions.
*
* <p>Placeholder sessions allow the use of secure renderers to play clear content.
*
* @param allowPlaceholderSessions Whether this session manager is allowed to acquire
* placeholder sessions.
* @return This builder.
*/
public Builder setAllowPlaceholderSessions(boolean allowPlaceholderSessions) {
this.allowPlaceholderSessions = allowPlaceholderSessions;
return this;
}
/**
* Sets whether clear samples should be played when keys are not available. Keys are considered
* unavailable when the load request is taking place, or when the key request has failed.
*
* <p>This option does not affect placeholder sessions.
*
* @param playClearSamplesWithoutKeys Whether clear samples should be played when keys are not
* available.
* @return This builder.
*/
public Builder setPlayClearSamplesWithoutKeys(boolean playClearSamplesWithoutKeys) {
if (playClearSamplesWithoutKeys) {
this.flags |= FLAG_PLAY_CLEAR_SAMPLES_WITHOUT_KEYS;
} else {
this.flags &= ~FLAG_PLAY_CLEAR_SAMPLES_WITHOUT_KEYS;
}
return this;
}
/**
* Sets the {@link LoadErrorHandlingPolicy} for key and provisioning requests.
*
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
* @return This builder.
*/
public Builder setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
this.loadErrorHandlingPolicy = Assertions.checkNotNull(loadErrorHandlingPolicy);
return this;
}
/** Builds a {@link DefaultDrmSessionManager} instance. */
public DefaultDrmSessionManager<ExoMediaCrypto> build(MediaDrmCallback mediaDrmCallback) {
return new DefaultDrmSessionManager<>(
uuid,
exoMediaDrmProvider,
mediaDrmCallback,
keyRequestParameters,
multiSession,
allowPlaceholderSessions,
flags,
loadErrorHandlingPolicy);
}
}
/**
* Signals that the {@link DrmInitData} passed to {@link #acquireSession} does not contain does
* not contain scheme data for the required UUID.
@ -200,7 +343,6 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
this.optionalKeyRequestParameters = optionalKeyRequestParameters;
this.eventDispatcher = new EventDispatcher<>();
this.multiSession = multiSession;
// TODO: Allow customization once this class has a Builder.
this.allowPlaceholderSessions = allowPlaceholderSessions;
this.flags = flags;
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;