Make DrmSessionManager.getExoMediaCryptoType cover placeholder sessions

getExoMediaCryptoType will only return null for drmInitData == null and
track types for which placeholder sessions are not used. This change
will allow renderers to abstract themselves from format.drmInitData.

PiperOrigin-RevId: 322131219
This commit is contained in:
aquilescanta 2020-07-20 14:30:23 +01:00 committed by Oliver Woodman
parent 72728ba054
commit ecc834d704
9 changed files with 45 additions and 24 deletions

View File

@ -578,10 +578,17 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
@Override @Override
@Nullable @Nullable
public Class<? extends ExoMediaCrypto> getExoMediaCryptoType(DrmInitData drmInitData) { public Class<? extends ExoMediaCrypto> getExoMediaCryptoType(
return canAcquireSession(drmInitData) @Nullable DrmInitData drmInitData, int trackType) {
? Assertions.checkNotNull(exoMediaDrm).getExoMediaCryptoType() Class<? extends ExoMediaCrypto> exoMediaCryptoType =
: null; Assertions.checkNotNull(exoMediaDrm).getExoMediaCryptoType();
if (drmInitData == null) {
return Util.linearSearch(useDrmSessionsForClearContentTrackTypes, trackType) != C.INDEX_UNSET
? exoMediaCryptoType
: null;
} else {
return canAcquireSession(drmInitData) ? exoMediaCryptoType : UnsupportedMediaCrypto.class;
}
} }
// Internal methods. // Internal methods.

View File

@ -49,8 +49,9 @@ public interface DrmSessionManager {
@Override @Override
@Nullable @Nullable
public Class<ExoMediaCrypto> getExoMediaCryptoType(DrmInitData drmInitData) { public Class<UnsupportedMediaCrypto> getExoMediaCryptoType(
return null; @Nullable DrmInitData drmInitData, int trackType) {
return drmInitData != null ? UnsupportedMediaCrypto.class : null;
} }
}; };
@ -118,9 +119,23 @@ public interface DrmSessionManager {
DrmInitData drmInitData); DrmInitData drmInitData);
/** /**
* Returns the {@link ExoMediaCrypto} type returned by sessions acquired using the given {@link * Returns the {@link ExoMediaCrypto} type associated to sessions acquired using the given
* DrmInitData}, or null if a session cannot be acquired with the given {@link DrmInitData}. * parameters. Returns the {@link UnsupportedMediaCrypto} type if this DRM session manager does
* not support the given {@link DrmInitData}. If {@code drmInitData} is null, returns an {@link
* ExoMediaCrypto} type if this DRM session manager would associate a {@link
* #acquirePlaceholderSession placeholder session} to the given {@code trackType}, or null
* otherwise.
*
* @param drmInitData The {@link DrmInitData} to acquire sessions with. May be null for
* unencrypted content (See {@link #acquirePlaceholderSession placeholder sessions}).
* @param trackType The type of the track to which {@code drmInitData} belongs. Must be one of the
* {@link C}{@code .TRACK_TYPE_*} constants.
* @return The {@link ExoMediaCrypto} type associated to sessions acquired using the given
* parameters, or the {@link UnsupportedMediaCrypto} type if the provided {@code drmInitData}
* is not supported, or {@code null} if {@code drmInitData} is null and no DRM session will be
* associated to the given {@code trackType}.
*/ */
@Nullable @Nullable
Class<? extends ExoMediaCrypto> getExoMediaCryptoType(DrmInitData drmInitData); Class<? extends ExoMediaCrypto> getExoMediaCryptoType(
@Nullable DrmInitData drmInitData, int trackType);
} }

View File

@ -142,9 +142,7 @@ public final class DummyExoMediaDrm implements ExoMediaDrm {
} }
@Override @Override
@Nullable public Class<UnsupportedMediaCrypto> getExoMediaCryptoType() {
public Class<ExoMediaCrypto> getExoMediaCryptoType() { return UnsupportedMediaCrypto.class;
// No ExoMediaCrypto type is supported.
return null;
} }
} }

View File

@ -369,10 +369,6 @@ public interface ExoMediaDrm {
*/ */
ExoMediaCrypto createMediaCrypto(byte[] sessionId) throws MediaCryptoException; ExoMediaCrypto 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<? extends ExoMediaCrypto> getExoMediaCryptoType(); Class<? extends ExoMediaCrypto> getExoMediaCryptoType();
} }

View File

@ -787,7 +787,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (trackFormat.drmInitData != null) { if (trackFormat.drmInitData != null) {
trackFormat = trackFormat =
trackFormat.copyWithExoMediaCryptoType( trackFormat.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(trackFormat.drmInitData)); drmSessionManager.getExoMediaCryptoType(
trackFormat.drmInitData, MimeTypes.getTrackType(trackFormat.sampleMimeType)));
} }
trackArray[i] = new TrackGroup(trackFormat); trackArray[i] = new TrackGroup(trackFormat);
} }

View File

@ -674,7 +674,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
if (drmInitData != null) { if (drmInitData != null) {
format = format =
format.copyWithExoMediaCryptoType( format.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(drmInitData)); drmSessionManager.getExoMediaCryptoType(
drmInitData, MimeTypes.getTrackType(format.sampleMimeType)));
} }
formats[j] = format; formats[j] = format;
} }

View File

@ -1313,7 +1313,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
if (format.drmInitData != null) { if (format.drmInitData != null) {
format = format =
format.copyWithExoMediaCryptoType( format.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(format.drmInitData)); drmSessionManager.getExoMediaCryptoType(
format.drmInitData, MimeTypes.getTrackType(format.sampleMimeType)));
} }
exposedFormats[j] = format; exposedFormats[j] = format;
} }

View File

@ -36,6 +36,7 @@ import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.LoaderErrorThrower; import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.MimeTypes;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -274,7 +275,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
exposedFormats[j] = exposedFormats[j] =
manifestFormat.drmInitData != null manifestFormat.drmInitData != null
? manifestFormat.copyWithExoMediaCryptoType( ? manifestFormat.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(manifestFormat.drmInitData)) drmSessionManager.getExoMediaCryptoType(
manifestFormat.drmInitData,
MimeTypes.getTrackType(manifestFormat.sampleMimeType)))
: manifestFormat; : manifestFormat;
} }
trackGroups[i] = new TrackGroup(exposedFormats); trackGroups[i] = new TrackGroup(exposedFormats);

View File

@ -269,9 +269,8 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
return new FakeExoMediaCrypto(); return new FakeExoMediaCrypto();
} }
@Nullable
@Override @Override
public Class<? extends ExoMediaCrypto> getExoMediaCryptoType() { public Class<FakeExoMediaCrypto> getExoMediaCryptoType() {
return FakeExoMediaCrypto.class; return FakeExoMediaCrypto.class;
} }