mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add DummyExoMediaDrm
Allows streamlining the way we handle unsupported DRM. In general, either: * The device does not support the CDM. For example, phones don't support PlayReady. * The device does not support the protection scheme. For example, API < 25 devices do not support AES-CBC. Currently we handle both cases differently. A dummy ExoMediaDrm will allow the existence of dummy DefaultDrmSessionManagers. PiperOrigin-RevId: 269315687
This commit is contained in:
parent
9face09361
commit
5630273155
3 changed files with 144 additions and 2 deletions
|
|
@ -410,7 +410,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto>
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public DrmSession<T> acquirePlaceholderSession(Looper playbackLooper) {
|
public DrmSession<T> acquirePlaceholderSession(Looper playbackLooper) {
|
||||||
if (!allowPlaceholderSessions) {
|
if (!allowPlaceholderSessions || mediaDrm.getExoMediaCryptoType() == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
maybeCreateMediaDrmHandler(playbackLooper);
|
maybeCreateMediaDrmHandler(playbackLooper);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.exoplayer2.drm;
|
||||||
|
|
||||||
|
import android.media.MediaDrmException;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/** An {@link ExoMediaDrm} that does not support any protection schemes. */
|
||||||
|
@RequiresApi(18)
|
||||||
|
public final class DummyExoMediaDrm<T extends ExoMediaCrypto> implements ExoMediaDrm<T> {
|
||||||
|
|
||||||
|
/** Returns a new instance. */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T extends ExoMediaCrypto> DummyExoMediaDrm<T> getInstance() {
|
||||||
|
return (DummyExoMediaDrm<T>) new DummyExoMediaDrm<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOnEventListener(OnEventListener<? super T> listener) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOnKeyStatusChangeListener(OnKeyStatusChangeListener<? super T> listener) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] openSession() throws MediaDrmException {
|
||||||
|
throw new MediaDrmException("Attempting to open a session using a dummy ExoMediaDrm.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeSession(byte[] sessionId) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyRequest getKeyRequest(
|
||||||
|
byte[] scope,
|
||||||
|
@Nullable List<DrmInitData.SchemeData> schemeDatas,
|
||||||
|
int keyType,
|
||||||
|
@Nullable HashMap<String, String> optionalParameters) {
|
||||||
|
// Should not be invoked. No session should exist.
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public byte[] provideKeyResponse(byte[] scope, byte[] response) {
|
||||||
|
// Should not be invoked. No session should exist.
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProvisionRequest getProvisionRequest() {
|
||||||
|
// Should not be invoked. No provision should be required.
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void provideProvisionResponse(byte[] response) {
|
||||||
|
// Should not be invoked. No provision should be required.
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> queryKeyStatus(byte[] sessionId) {
|
||||||
|
// Should not be invoked. No session should exist.
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acquire() {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void release() {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void restoreKeys(byte[] sessionId, byte[] keySetId) {
|
||||||
|
// Should not be invoked. No session should exist.
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPropertyString(String propertyName) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getPropertyByteArray(String propertyName) {
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPropertyString(String propertyName, String value) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPropertyByteArray(String propertyName, byte[] value) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T createMediaCrypto(byte[] sessionId) {
|
||||||
|
// Should not be invoked. No session should exist.
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Class<T> getExoMediaCryptoType() {
|
||||||
|
// No ExoMediaCrypto type is supported.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -293,6 +293,10 @@ public interface ExoMediaDrm<T extends ExoMediaCrypto> {
|
||||||
*/
|
*/
|
||||||
T createMediaCrypto(byte[] sessionId) throws MediaCryptoException;
|
T createMediaCrypto(byte[] sessionId) throws MediaCryptoException;
|
||||||
|
|
||||||
/** Returns the {@link ExoMediaCrypto} type created by {@link #createMediaCrypto(byte[])}. */
|
/**
|
||||||
|
* Returns the {@link ExoMediaCrypto} type created by {@link #createMediaCrypto(byte[])}, or null
|
||||||
|
* if this instance cannot create any {@link ExoMediaCrypto} instances.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
Class<T> getExoMediaCryptoType();
|
Class<T> getExoMediaCryptoType();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue