mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Fix MediaDrm leaks in OfflineLicenseHelper
PiperOrigin-RevId: 280176216
This commit is contained in:
parent
65b49a49f7
commit
51711a0c97
3 changed files with 29 additions and 15 deletions
|
|
@ -5,6 +5,8 @@
|
||||||
* Require an end time or duration for SubRip (SRT) and SubStation Alpha
|
* Require an end time or duration for SubRip (SRT) and SubStation Alpha
|
||||||
(SSA/ASS) subtitles. This applies to both sidecar files & subtitles
|
(SSA/ASS) subtitles. This applies to both sidecar files & subtitles
|
||||||
[embedded in Matroska streams](https://matroska.org/technical/specs/subtitles/index.html).
|
[embedded in Matroska streams](https://matroska.org/technical/specs/subtitles/index.html).
|
||||||
|
* Use `ExoMediaDrm.Provider` in `OfflineLicenseHelper` to avoid `ExoMediaDrm`
|
||||||
|
leaks ([#4721](https://github.com/google/ExoPlayer/issues/4721)).
|
||||||
|
|
||||||
### 2.11.0 (not yet released) ###
|
### 2.11.0 (not yet released) ###
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
|
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import java.util.HashMap;
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/** Helper class to download, renew and release offline licenses. */
|
/** Helper class to download, renew and release offline licenses. */
|
||||||
|
|
@ -89,21 +90,21 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
|
||||||
* @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
|
* @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
|
||||||
* include their own license URL.
|
* include their own license URL.
|
||||||
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
|
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
|
||||||
* to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
|
* to {@link MediaDrm#getKeyRequest}. May be null.
|
||||||
* @return A new instance which uses Widevine CDM.
|
* @return A new instance which uses Widevine CDM.
|
||||||
* @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
|
* @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
|
||||||
* instantiated.
|
* instantiated.
|
||||||
* @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
|
* @see DefaultDrmSessionManager.Builder
|
||||||
* MediaDrmCallback, HashMap)
|
|
||||||
*/
|
*/
|
||||||
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
|
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
|
||||||
String defaultLicenseUrl,
|
String defaultLicenseUrl,
|
||||||
boolean forceDefaultLicenseUrl,
|
boolean forceDefaultLicenseUrl,
|
||||||
Factory httpDataSourceFactory,
|
Factory httpDataSourceFactory,
|
||||||
@Nullable HashMap<String, String> optionalKeyRequestParameters)
|
@Nullable Map<String, String> optionalKeyRequestParameters)
|
||||||
throws UnsupportedDrmException {
|
throws UnsupportedDrmException {
|
||||||
return new OfflineLicenseHelper<>(C.WIDEVINE_UUID,
|
return new OfflineLicenseHelper<>(
|
||||||
FrameworkMediaDrm.newInstance(C.WIDEVINE_UUID),
|
C.WIDEVINE_UUID,
|
||||||
|
FrameworkMediaDrm.DEFAULT_PROVIDER,
|
||||||
new HttpMediaDrmCallback(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory),
|
new HttpMediaDrmCallback(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory),
|
||||||
optionalKeyRequestParameters);
|
optionalKeyRequestParameters);
|
||||||
}
|
}
|
||||||
|
|
@ -112,18 +113,18 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
|
||||||
* Constructs an instance. Call {@link #release()} when the instance is no longer required.
|
* Constructs an instance. Call {@link #release()} when the instance is no longer required.
|
||||||
*
|
*
|
||||||
* @param uuid The UUID of the drm scheme.
|
* @param uuid The UUID of the drm scheme.
|
||||||
* @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
|
* @param mediaDrmProvider A {@link ExoMediaDrm.Provider}.
|
||||||
* @param callback Performs key and provisioning requests.
|
* @param callback Performs key and provisioning requests.
|
||||||
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
|
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
|
||||||
* to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
|
* to {@link MediaDrm#getKeyRequest}. May be null.
|
||||||
* @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
|
* @see DefaultDrmSessionManager.Builder
|
||||||
* MediaDrmCallback, HashMap)
|
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public OfflineLicenseHelper(
|
public OfflineLicenseHelper(
|
||||||
UUID uuid,
|
UUID uuid,
|
||||||
ExoMediaDrm<T> mediaDrm,
|
ExoMediaDrm.Provider<T> mediaDrmProvider,
|
||||||
MediaDrmCallback callback,
|
MediaDrmCallback callback,
|
||||||
@Nullable HashMap<String, String> optionalKeyRequestParameters) {
|
@Nullable Map<String, String> optionalKeyRequestParameters) {
|
||||||
handlerThread = new HandlerThread("OfflineLicenseHelper");
|
handlerThread = new HandlerThread("OfflineLicenseHelper");
|
||||||
handlerThread.start();
|
handlerThread.start();
|
||||||
conditionVariable = new ConditionVariable();
|
conditionVariable = new ConditionVariable();
|
||||||
|
|
@ -149,8 +150,15 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
|
||||||
conditionVariable.open();
|
conditionVariable.open();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (optionalKeyRequestParameters == null) {
|
||||||
|
optionalKeyRequestParameters = Collections.emptyMap();
|
||||||
|
}
|
||||||
drmSessionManager =
|
drmSessionManager =
|
||||||
new DefaultDrmSessionManager<>(uuid, mediaDrm, callback, optionalKeyRequestParameters);
|
(DefaultDrmSessionManager<T>)
|
||||||
|
new DefaultDrmSessionManager.Builder()
|
||||||
|
.setUuidAndExoMediaDrmProvider(uuid, mediaDrmProvider)
|
||||||
|
.setKeyRequestParameters(optionalKeyRequestParameters)
|
||||||
|
.build(callback);
|
||||||
drmSessionManager.addListener(new Handler(handlerThread.getLooper()), eventListener);
|
drmSessionManager.addListener(new Handler(handlerThread.getLooper()), eventListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,11 @@ public class OfflineLicenseHelperTest {
|
||||||
.thenReturn(
|
.thenReturn(
|
||||||
new ExoMediaDrm.KeyRequest(/* data= */ new byte[0], /* licenseServerUrl= */ ""));
|
new ExoMediaDrm.KeyRequest(/* data= */ new byte[0], /* licenseServerUrl= */ ""));
|
||||||
offlineLicenseHelper =
|
offlineLicenseHelper =
|
||||||
new OfflineLicenseHelper<>(C.WIDEVINE_UUID, mediaDrm, mediaDrmCallback, null);
|
new OfflineLicenseHelper<>(
|
||||||
|
C.WIDEVINE_UUID,
|
||||||
|
new ExoMediaDrm.AppManagedProvider<>(mediaDrm),
|
||||||
|
mediaDrmCallback,
|
||||||
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue