Pixel Fusion v1.0.2版本的 MD5 值为:7c04c460c2996569d4ad075cd671a946
以下内容为反编译后的 FrameworkMediaDrm.java 源代码,内容仅作参考
package io.bidmachine.media3.exoplayer.drm;
import android.annotation.SuppressLint;
import android.media.DeniedByServerException;
import android.media.MediaCrypto;
import android.media.MediaCryptoException;
import android.media.MediaDrm;
import android.media.MediaDrmException;
import android.media.NotProvisionedException;
import android.media.UnsupportedSchemeException;
import android.media.metrics.LogSessionId;
import android.os.Handler;
import android.os.PersistableBundle;
import android.text.TextUtils;
import androidx.annotation.DoNotInline;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import io.bidmachine.media3.common.C;
import io.bidmachine.media3.common.DrmInitData;
import io.bidmachine.media3.common.util.Assertions;
import io.bidmachine.media3.common.util.Log;
import io.bidmachine.media3.common.util.ParsableByteArray;
import io.bidmachine.media3.common.util.UnstableApi;
import io.bidmachine.media3.common.util.Util;
import io.bidmachine.media3.exoplayer.analytics.PlayerId;
import io.bidmachine.media3.exoplayer.drm.ExoMediaDrm;
import io.bidmachine.media3.extractor.mp4.PsshAtomUtil;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@RequiresApi(18)
public final class FrameworkMediaDrm implements ExoMediaDrm {
private static final String CENC_SCHEME_MIME_TYPE = "cenc";
@UnstableApi
public static final ExoMediaDrm.Provider DEFAULT_PROVIDER = new ExoMediaDrm.Provider() {
@Override
public final ExoMediaDrm acquireExoMediaDrm(UUID uuid) {
ExoMediaDrm lambda$static$0;
lambda$static$0 = FrameworkMediaDrm.lambda$static$0(uuid);
return lambda$static$0;
}
};
private static final String MOCK_LA_URL = "<LA_URL>https://x</LA_URL>";
private static final String MOCK_LA_URL_VALUE = "https://x";
private static final String TAG = "FrameworkMediaDrm";
private static final int UTF_16_BYTES_PER_CHARACTER = 2;
private final MediaDrm mediaDrm;
private int referenceCount;
private final UUID uuid;
@RequiresApi(31)
public static class BbdcDCacCa {
private BbdcDCacCa() {
}
@DoNotInline
public static boolean requiresSecureDecoder(MediaDrm mediaDrm, String str) {
boolean requiresSecureDecoder;
requiresSecureDecoder = mediaDrm.requiresSecureDecoder(str);
return requiresSecureDecoder;
}
@DoNotInline
public static void setLogSessionIdOnMediaDrmSession(MediaDrm mediaDrm, byte[] bArr, PlayerId playerId) {
LogSessionId logSessionId;
boolean equals;
MediaDrm.PlaybackComponent playbackComponent;
LogSessionId logSessionId2 = playerId.getLogSessionId();
logSessionId = LogSessionId.LOG_SESSION_ID_NONE;
equals = logSessionId2.equals(logSessionId);
if (!equals) {
playbackComponent = mediaDrm.getPlaybackComponent(bArr);
((MediaDrm.PlaybackComponent) Assertions.checkNotNull(playbackComponent)).setLogSessionId(logSessionId2);
}
}
}
private FrameworkMediaDrm(UUID uuid) throws UnsupportedSchemeException {
Assertions.checkNotNull(uuid);
Assertions.checkArgument(!C.COMMON_PSSH_UUID.equals(uuid), "Use C.CLEARKEY_UUID instead");
this.uuid = uuid;
MediaDrm mediaDrm = new MediaDrm(adjustUuid(uuid));
this.mediaDrm = mediaDrm;
this.referenceCount = 1;
if (C.WIDEVINE_UUID.equals(uuid) && needsForceWidevineL3Workaround()) {
forceWidevineL3(mediaDrm);
}
}
private static byte[] addLaUrlAttributeIfMissing(byte[] bArr) {
ParsableByteArray parsableByteArray = new ParsableByteArray(bArr);
int readLittleEndianInt = parsableByteArray.readLittleEndianInt();
short readLittleEndianShort = parsableByteArray.readLittleEndianShort();
short readLittleEndianShort2 = parsableByteArray.readLittleEndianShort();
if (readLittleEndianShort == 1 && readLittleEndianShort2 == 1) {
short readLittleEndianShort3 = parsableByteArray.readLittleEndianShort();
Charset charset = com.google.common.base.dcadbB.f57051CdCaB;
String readString = parsableByteArray.readString(readLittleEndianShort3, charset);
if (readString.contains("<LA_URL>")) {
return bArr;
}
int indexOf = readString.indexOf("</DATA>");
if (indexOf == -1) {
Log.w("FrameworkMediaDrm", "Could not find the </DATA> tag. Skipping LA_URL workaround.");
}
String str = readString.substring(0, indexOf) + "<LA_URL>https://x</LA_URL>" + readString.substring(indexOf);
int i = readLittleEndianInt + 52;
ByteBuffer allocate = ByteBuffer.allocate(i);
allocate.order(ByteOrder.LITTLE_ENDIAN);
allocate.putInt(i);
allocate.putShort(readLittleEndianShort);
allocate.putShort(readLittleEndianShort2);
allocate.putShort((short) (str.length() * 2));
allocate.put(str.getBytes(charset));
return allocate.array();
}
Log.i("FrameworkMediaDrm", "Unexpected record count or type. Skipping LA_URL workaround.");
return bArr;
}
private static String adjustLicenseServerUrl(String str) {
if ("<LA_URL>https://x</LA_URL>".equals(str)) {
return "";
}
if (Util.SDK_INT == 33 && "https://default.url".equals(str)) {
return "";
}
return str;
}
private static byte[] adjustRequestData(UUID uuid, byte[] bArr) {
if (C.CLEARKEY_UUID.equals(uuid)) {
return io.bidmachine.media3.exoplayer.drm.BbdcDCacCa.adjustRequestData(bArr);
}
return bArr;
}
private static byte[] adjustRequestInitData(UUID uuid, byte[] bArr) {
UUID uuid2 = C.PLAYREADY_UUID;
if (uuid2.equals(uuid)) {
byte[] parseSchemeSpecificData = PsshAtomUtil.parseSchemeSpecificData(bArr, uuid);
if (parseSchemeSpecificData != null) {
bArr = parseSchemeSpecificData;
}
bArr = PsshAtomUtil.buildPsshAtom(uuid2, addLaUrlAttributeIfMissing(bArr));
}
if (Util.SDK_INT >= 23 || !C.WIDEVINE_UUID.equals(uuid)) {
if (uuid2.equals(uuid) && "Amazon".equals(Util.MANUFACTURER)) {
String str = Util.MODEL;
if (!"AFTB".equals(str)) {
if (!"AFTS".equals(str)) {
if (!"AFTM".equals(str)) {
}
}
}
}
return bArr;
}
byte[] parseSchemeSpecificData2 = PsshAtomUtil.parseSchemeSpecificData(bArr, uuid);
if (parseSchemeSpecificData2 != null) {
return parseSchemeSpecificData2;
}
return bArr;
}
private static String adjustRequestMimeType(UUID uuid, String str) {
if (Util.SDK_INT < 26 && C.CLEARKEY_UUID.equals(uuid) && ("video/mp4".equals(str) || "audio/mp4".equals(str))) {
return "cenc";
}
return str;
}
private static UUID adjustUuid(UUID uuid) {
if (Util.SDK_INT < 27 && C.CLEARKEY_UUID.equals(uuid)) {
return C.COMMON_PSSH_UUID;
}
return uuid;
}
private static void forceWidevineL3(MediaDrm mediaDrm) {
mediaDrm.setPropertyString("securityLevel", "L3");
}
private static DrmInitData.SchemeData getSchemeData(UUID uuid, List<DrmInitData.SchemeData> list) {
boolean z;
if (!C.WIDEVINE_UUID.equals(uuid)) {
return list.get(0);
}
if (Util.SDK_INT >= 28 && list.size() > 1) {
DrmInitData.SchemeData schemeData = list.get(0);
int i = 0;
for (int i2 = 0; i2 < list.size(); i2++) {
DrmInitData.SchemeData schemeData2 = list.get(i2);
byte[] bArr = (byte[]) Assertions.checkNotNull(schemeData2.data);
if (Util.areEqual(schemeData2.mimeType, schemeData.mimeType) && Util.areEqual(schemeData2.licenseServerUrl, schemeData.licenseServerUrl) && PsshAtomUtil.isPsshAtom(bArr)) {
i += bArr.length;
} else {
z = false;
break;
}
}
z = true;
if (z) {
byte[] bArr2 = new byte[i];
int i3 = 0;
for (int i4 = 0; i4 < list.size(); i4++) {
byte[] bArr3 = (byte[]) Assertions.checkNotNull(list.get(i4).data);
int length = bArr3.length;
System.arraycopy(bArr3, 0, bArr2, i3, length);
i3 += length;
}
return schemeData.copyWithData(bArr2);
}
}
for (int i5 = 0; i5 < list.size(); i5++) {
DrmInitData.SchemeData schemeData3 = list.get(i5);
int parseVersion = PsshAtomUtil.parseVersion((byte[]) Assertions.checkNotNull(schemeData3.data));
int i6 = Util.SDK_INT;
if (i6 < 23 && parseVersion == 0) {
return schemeData3;
}
if (i6 >= 23 && parseVersion == 1) {
return schemeData3;
}
}
return list.get(0);
}
public static boolean isCryptoSchemeSupported(UUID uuid) {
return MediaDrm.isCryptoSchemeSupported(adjustUuid(uuid));
}
public void lambda$setOnEventListener$1(ExoMediaDrm.OnEventListener onEventListener, MediaDrm mediaDrm, byte[] bArr, int i, int i2, byte[] bArr2) {
onEventListener.onEvent(this, bArr, i, i2, bArr2);
}
public void lambda$setOnExpirationUpdateListener$3(ExoMediaDrm.OnExpirationUpdateListener onExpirationUpdateListener, MediaDrm mediaDrm, byte[] bArr, long j) {
onExpirationUpdateListener.onExpirationUpdate(this, bArr, j);
}
public void lambda$setOnKeyStatusChangeListener$2(ExoMediaDrm.OnKeyStatusChangeListener onKeyStatusChangeListener, MediaDrm mediaDrm, byte[] bArr, List list, boolean z) {
int statusCode;
byte[] keyId;
ArrayList arrayList = new ArrayList();
Iterator it = list.iterator();
while (it.hasNext()) {
MediaDrm.KeyStatus keyStatus = (MediaDrm.KeyStatus) it.next();
statusCode = keyStatus.getStatusCode();
keyId = keyStatus.getKeyId();
arrayList.add(new ExoMediaDrm.KeyStatus(statusCode, keyId));
}
onKeyStatusChangeListener.onKeyStatusChange(this, bArr, arrayList, z);
}
public static ExoMediaDrm lambda$static$0(UUID uuid) {
try {
return newInstance(uuid);
} catch (UnsupportedDrmException unused) {
Log.e("FrameworkMediaDrm", "Failed to instantiate a FrameworkMediaDrm for uuid: " + uuid + ".");
return new DummyExoMediaDrm();
}
}
private static boolean needsForceWidevineL3Workaround() {
return "ASUS_Z00AD".equals(Util.MODEL);
}
@UnstableApi
public static FrameworkMediaDrm newInstance(UUID uuid) throws UnsupportedDrmException {
try {
return new FrameworkMediaDrm(uuid);
} catch (UnsupportedSchemeException e) {
throw new UnsupportedDrmException(1, e);
} catch (Exception e2) {
throw new UnsupportedDrmException(2, e2);
}
}
@Override
@UnstableApi
public synchronized void acquire() {
boolean z;
if (this.referenceCount > 0) {
z = true;
} else {
z = false;
}
Assertions.checkState(z);
this.referenceCount++;
}
@Override
@UnstableApi
public void closeSession(byte[] bArr) {
this.mediaDrm.closeSession(bArr);
}
@Override
@UnstableApi
public int getCryptoType() {
return 2;
}
@Override
@SuppressLint({"WrongConstant"})
@UnstableApi
public ExoMediaDrm.KeyRequest getKeyRequest(byte[] bArr, @Nullable List<DrmInitData.SchemeData> list, int i, @Nullable HashMap<String, String> hashMap) throws NotProvisionedException {
DrmInitData.SchemeData schemeData;
byte[] bArr2;
String str;
int i2;
if (list != null) {
schemeData = getSchemeData(this.uuid, list);
bArr2 = adjustRequestInitData(this.uuid, (byte[]) Assertions.checkNotNull(schemeData.data));
str = adjustRequestMimeType(this.uuid, schemeData.mimeType);
} else {
schemeData = null;
bArr2 = null;
str = null;
}
MediaDrm.KeyRequest keyRequest = this.mediaDrm.getKeyRequest(bArr, bArr2, str, i, hashMap);
byte[] adjustRequestData = adjustRequestData(this.uuid, keyRequest.getData());
String adjustLicenseServerUrl = adjustLicenseServerUrl(keyRequest.getDefaultUrl());
if (TextUtils.isEmpty(adjustLicenseServerUrl) && schemeData != null && !TextUtils.isEmpty(schemeData.licenseServerUrl)) {
adjustLicenseServerUrl = schemeData.licenseServerUrl;
}
if (Util.SDK_INT >= 23) {
i2 = keyRequest.getRequestType();
} else {
i2 = Integer.MIN_VALUE;
}
return new ExoMediaDrm.KeyRequest(adjustRequestData, adjustLicenseServerUrl, i2);
}
@Override
@Nullable
@UnstableApi
public PersistableBundle getMetrics() {
PersistableBundle metrics;
if (Util.SDK_INT >= 28) {
metrics = this.mediaDrm.getMetrics();
return metrics;
}
return null;
}
@Override
@UnstableApi
public byte[] getPropertyByteArray(String str) {
return this.mediaDrm.getPropertyByteArray(str);
}
@Override
@UnstableApi
public String getPropertyString(String str) {
return this.mediaDrm.getPropertyString(str);
}
@Override
@UnstableApi
public ExoMediaDrm.ProvisionRequest getProvisionRequest() {
MediaDrm.ProvisionRequest provisionRequest = this.mediaDrm.getProvisionRequest();
return new ExoMediaDrm.ProvisionRequest(provisionRequest.getData(), provisionRequest.getDefaultUrl());
}
@Override
@UnstableApi
public byte[] openSession() throws MediaDrmException {
return this.mediaDrm.openSession();
}
@Override
@Nullable
@UnstableApi
public byte[] provideKeyResponse(byte[] bArr, byte[] bArr2) throws NotProvisionedException, DeniedByServerException {
if (C.CLEARKEY_UUID.equals(this.uuid)) {
bArr2 = io.bidmachine.media3.exoplayer.drm.BbdcDCacCa.adjustResponseData(bArr2);
}
return this.mediaDrm.provideKeyResponse(bArr, bArr2);
}
@Override
@UnstableApi
public void provideProvisionResponse(byte[] bArr) throws DeniedByServerException {
this.mediaDrm.provideProvisionResponse(bArr);
}
@Override
@UnstableApi
public Map<String, String> queryKeyStatus(byte[] bArr) {
return this.mediaDrm.queryKeyStatus(bArr);
}
@Override
@UnstableApi
public synchronized void release() {
int i = this.referenceCount - 1;
this.referenceCount = i;
if (i == 0) {
this.mediaDrm.release();
}
}
@Override
@UnstableApi
public boolean requiresSecureDecoder(byte[] bArr, String str) {
if (Util.SDK_INT >= 31) {
return BbdcDCacCa.requiresSecureDecoder(this.mediaDrm, str);
}
try {
MediaCrypto mediaCrypto = new MediaCrypto(this.uuid, bArr);
try {
return mediaCrypto.requiresSecureDecoderComponent(str);
} finally {
mediaCrypto.release();
}
} catch (MediaCryptoException unused) {
return true;
}
}
@Override
@UnstableApi
public void restoreKeys(byte[] bArr, byte[] bArr2) {
this.mediaDrm.restoreKeys(bArr, bArr2);
}
@Override
@UnstableApi
public void setOnEventListener(@Nullable final ExoMediaDrm.OnEventListener onEventListener) {
MediaDrm.OnEventListener onEventListener2;
MediaDrm mediaDrm = this.mediaDrm;
if (onEventListener == null) {
onEventListener2 = null;
} else {
onEventListener2 = new MediaDrm.OnEventListener() {
@Override
public final void onEvent(MediaDrm mediaDrm2, byte[] bArr, int i, int i2, byte[] bArr2) {
FrameworkMediaDrm.this.lambda$setOnEventListener$1(onEventListener, mediaDrm2, bArr, i, i2, bArr2);
}
};
}
mediaDrm.setOnEventListener(onEventListener2);
}
@Override
@RequiresApi(23)
@UnstableApi
public void setOnExpirationUpdateListener(@Nullable final ExoMediaDrm.OnExpirationUpdateListener onExpirationUpdateListener) {
MediaDrm.OnExpirationUpdateListener onExpirationUpdateListener2;
if (Util.SDK_INT >= 23) {
MediaDrm mediaDrm = this.mediaDrm;
if (onExpirationUpdateListener == null) {
onExpirationUpdateListener2 = null;
} else {
onExpirationUpdateListener2 = new MediaDrm.OnExpirationUpdateListener() {
@Override
public final void onExpirationUpdate(MediaDrm mediaDrm2, byte[] bArr, long j) {
FrameworkMediaDrm.this.lambda$setOnExpirationUpdateListener$3(onExpirationUpdateListener, mediaDrm2, bArr, j);
}
};
}
mediaDrm.setOnExpirationUpdateListener(onExpirationUpdateListener2, (Handler) null);
return;
}
throw new UnsupportedOperationException();
}
@Override
@RequiresApi(23)
@UnstableApi
public void setOnKeyStatusChangeListener(@Nullable final ExoMediaDrm.OnKeyStatusChangeListener onKeyStatusChangeListener) {
MediaDrm.OnKeyStatusChangeListener onKeyStatusChangeListener2;
if (Util.SDK_INT >= 23) {
MediaDrm mediaDrm = this.mediaDrm;
if (onKeyStatusChangeListener == null) {
onKeyStatusChangeListener2 = null;
} else {
onKeyStatusChangeListener2 = new MediaDrm.OnKeyStatusChangeListener() {
@Override
public final void onKeyStatusChange(MediaDrm mediaDrm2, byte[] bArr, List list, boolean z) {
FrameworkMediaDrm.this.lambda$setOnKeyStatusChangeListener$2(onKeyStatusChangeListener, mediaDrm2, bArr, list, z);
}
};
}
mediaDrm.setOnKeyStatusChangeListener(onKeyStatusChangeListener2, (Handler) null);
return;
}
throw new UnsupportedOperationException();
}
@Override
@UnstableApi
public void setPlayerIdForSession(byte[] bArr, PlayerId playerId) {
if (Util.SDK_INT >= 31) {
try {
BbdcDCacCa.setLogSessionIdOnMediaDrmSession(this.mediaDrm, bArr, playerId);
} catch (UnsupportedOperationException unused) {
Log.w("FrameworkMediaDrm", "setLogSessionId failed.");
}
}
}
@Override
@UnstableApi
public void setPropertyByteArray(String str, byte[] bArr) {
this.mediaDrm.setPropertyByteArray(str, bArr);
}
@Override
@UnstableApi
public void setPropertyString(String str, String str2) {
this.mediaDrm.setPropertyString(str, str2);
}
@Override
@UnstableApi
public FrameworkCryptoConfig createCryptoConfig(byte[] bArr) throws MediaCryptoException {
return new FrameworkCryptoConfig(adjustUuid(this.uuid), bArr, Util.SDK_INT < 21 && C.WIDEVINE_UUID.equals(this.uuid) && "L3".equals(getPropertyString("securityLevel")));
}
}