Commit afbeb426 by aquilescanta Committed by kim-vde

Add UnsupportedMediaCrypto

ExoMediaCrypto with the sole purpose of being unsupported. So all
renderers checking whether the type is supported will report
encrypted content as unsupported, unless the source producing
the format replaces it with a valid value.

PiperOrigin-RevId: 319824703
parent 6cf15de7
...@@ -20,6 +20,7 @@ import android.os.Parcelable; ...@@ -20,6 +20,7 @@ import android.os.Parcelable;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.drm.DrmInitData; import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.drm.ExoMediaCrypto; import com.google.android.exoplayer2.drm.ExoMediaCrypto;
import com.google.android.exoplayer2.drm.UnsupportedMediaCrypto;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
...@@ -788,9 +789,9 @@ public final class Format implements Parcelable { ...@@ -788,9 +789,9 @@ public final class Format implements Parcelable {
// Provided by source. // Provided by source.
/** /**
* The type of the {@link ExoMediaCrypto} provided by the media source, if the media source can * The type of the {@link ExoMediaCrypto} that the source will associate to the content that this
* acquire a DRM session for {@link #drmInitData}. Null if the media source cannot acquire a * format describes, or null if the source will not associate an {@link ExoMediaCrypto}. Cannot be
* session for {@link #drmInitData}, or if not applicable. * null if {@link #drmInitData} is not null.
*/ */
@Nullable public final Class<? extends ExoMediaCrypto> exoMediaCryptoType; @Nullable public final Class<? extends ExoMediaCrypto> exoMediaCryptoType;
...@@ -1287,6 +1288,13 @@ public final class Format implements Parcelable { ...@@ -1287,6 +1288,13 @@ public final class Format implements Parcelable {
// Text specific. // Text specific.
this.accessibilityChannel = accessibilityChannel; this.accessibilityChannel = accessibilityChannel;
// Provided by source. // Provided by source.
if (exoMediaCryptoType == null && drmInitData != null) {
// Described content is encrypted but no exoMediaCryptoType has been assigned. Use
// UnsupportedMediaCrypto (not supported by any Renderers), so MediaSources are forced to
// replace
// this value in order to have Renderers flag this Format as supported.
exoMediaCryptoType = UnsupportedMediaCrypto.class;
}
this.exoMediaCryptoType = exoMediaCryptoType; this.exoMediaCryptoType = exoMediaCryptoType;
} }
...@@ -1334,7 +1342,10 @@ public final class Format implements Parcelable { ...@@ -1334,7 +1342,10 @@ public final class Format implements Parcelable {
// Text specific. // Text specific.
accessibilityChannel = in.readInt(); accessibilityChannel = in.readInt();
// Provided by source. // Provided by source.
exoMediaCryptoType = null; // If the described content is encrypted. Use UnsupportedMediaCrypto (not supported by any
// Renderers), so MediaSources are forced to replace this value in order to have Renderers flag
// this Format as supported.
exoMediaCryptoType = drmInitData != null ? UnsupportedMediaCrypto.class : null;
} }
/** Returns a {@link Format.Builder} initialized with the values of this instance. */ /** Returns a {@link Format.Builder} initialized with the values of this instance. */
......
/*
* Copyright 2020 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;
/** {@link ExoMediaCrypto} type that cannot be used to handle any type of protected content. */
public final class UnsupportedMediaCrypto implements ExoMediaCrypto {}
...@@ -24,6 +24,7 @@ import android.os.Parcel; ...@@ -24,6 +24,7 @@ import android.os.Parcel;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.drm.DrmInitData; import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.drm.ExoMediaCrypto; import com.google.android.exoplayer2.drm.ExoMediaCrypto;
import com.google.android.exoplayer2.drm.UnsupportedMediaCrypto;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.id3.TextInformationFrame; import com.google.android.exoplayer2.metadata.id3.TextInformationFrame;
import com.google.android.exoplayer2.testutil.TestUtil; import com.google.android.exoplayer2.testutil.TestUtil;
...@@ -53,9 +54,10 @@ public final class FormatTest { ...@@ -53,9 +54,10 @@ public final class FormatTest {
parcel.setDataPosition(0); parcel.setDataPosition(0);
Format formatFromParcel = Format.CREATOR.createFromParcel(parcel); Format formatFromParcel = Format.CREATOR.createFromParcel(parcel);
Format expectedFormat = formatToParcel.buildUpon().setExoMediaCryptoType(null).build(); Format expectedFormat =
formatToParcel.buildUpon().setExoMediaCryptoType(UnsupportedMediaCrypto.class).build();
assertThat(formatFromParcel.exoMediaCryptoType).isNull(); assertThat(formatFromParcel.exoMediaCryptoType).isEqualTo(UnsupportedMediaCrypto.class);
assertThat(formatFromParcel).isEqualTo(expectedFormat); assertThat(formatFromParcel).isEqualTo(expectedFormat);
parcel.recycle(); parcel.recycle();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment