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
This commit is contained in:
aquilescanta 2020-07-06 19:52:54 +01:00 committed by kim-vde
parent 6cf15de7e9
commit afbeb4267a
3 changed files with 38 additions and 6 deletions

View file

@ -20,6 +20,7 @@ import android.os.Parcelable;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.drm.DrmInitData;
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.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes;
@ -788,9 +789,9 @@ public final class Format implements Parcelable {
// Provided by source.
/**
* The type of the {@link ExoMediaCrypto} provided by the media source, if the media source can
* acquire a DRM session for {@link #drmInitData}. Null if the media source cannot acquire a
* session for {@link #drmInitData}, or if not applicable.
* The type of the {@link ExoMediaCrypto} that the source will associate to the content that this
* format describes, or null if the source will not associate an {@link ExoMediaCrypto}. Cannot be
* null if {@link #drmInitData} is not null.
*/
@Nullable public final Class<? extends ExoMediaCrypto> exoMediaCryptoType;
@ -1287,6 +1288,13 @@ public final class Format implements Parcelable {
// Text specific.
this.accessibilityChannel = accessibilityChannel;
// 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;
}
@ -1334,7 +1342,10 @@ public final class Format implements Parcelable {
// Text specific.
accessibilityChannel = in.readInt();
// 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. */

View file

@ -0,0 +1,19 @@
/*
* 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 {}

View file

@ -24,6 +24,7 @@ import android.os.Parcel;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.drm.DrmInitData;
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.id3.TextInformationFrame;
import com.google.android.exoplayer2.testutil.TestUtil;
@ -53,9 +54,10 @@ public final class FormatTest {
parcel.setDataPosition(0);
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);
parcel.recycle();