mirror of
https://github.com/androidx/media.git
synced 2025-05-18 13:09:56 +08:00
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:
parent
72728ba054
commit
ecc834d704
@ -578,10 +578,17 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<? extends ExoMediaCrypto> getExoMediaCryptoType(DrmInitData drmInitData) {
|
||||
return canAcquireSession(drmInitData)
|
||||
? Assertions.checkNotNull(exoMediaDrm).getExoMediaCryptoType()
|
||||
: null;
|
||||
public Class<? extends ExoMediaCrypto> getExoMediaCryptoType(
|
||||
@Nullable DrmInitData drmInitData, int trackType) {
|
||||
Class<? extends ExoMediaCrypto> exoMediaCryptoType =
|
||||
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.
|
||||
|
@ -49,8 +49,9 @@ public interface DrmSessionManager {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<ExoMediaCrypto> getExoMediaCryptoType(DrmInitData drmInitData) {
|
||||
return null;
|
||||
public Class<UnsupportedMediaCrypto> getExoMediaCryptoType(
|
||||
@Nullable DrmInitData drmInitData, int trackType) {
|
||||
return drmInitData != null ? UnsupportedMediaCrypto.class : null;
|
||||
}
|
||||
};
|
||||
|
||||
@ -118,9 +119,23 @@ public interface DrmSessionManager {
|
||||
DrmInitData drmInitData);
|
||||
|
||||
/**
|
||||
* Returns the {@link ExoMediaCrypto} type returned by sessions acquired using the given {@link
|
||||
* DrmInitData}, or null if a session cannot be acquired with the given {@link DrmInitData}.
|
||||
* Returns the {@link ExoMediaCrypto} type associated to sessions acquired using the given
|
||||
* 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
|
||||
Class<? extends ExoMediaCrypto> getExoMediaCryptoType(DrmInitData drmInitData);
|
||||
Class<? extends ExoMediaCrypto> getExoMediaCryptoType(
|
||||
@Nullable DrmInitData drmInitData, int trackType);
|
||||
}
|
||||
|
@ -142,9 +142,7 @@ public final class DummyExoMediaDrm implements ExoMediaDrm {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<ExoMediaCrypto> getExoMediaCryptoType() {
|
||||
// No ExoMediaCrypto type is supported.
|
||||
return null;
|
||||
public Class<UnsupportedMediaCrypto> getExoMediaCryptoType() {
|
||||
return UnsupportedMediaCrypto.class;
|
||||
}
|
||||
}
|
||||
|
@ -369,10 +369,6 @@ public interface ExoMediaDrm {
|
||||
*/
|
||||
ExoMediaCrypto createMediaCrypto(byte[] sessionId) throws MediaCryptoException;
|
||||
|
||||
/**
|
||||
* Returns the {@link ExoMediaCrypto} type created by {@link #createMediaCrypto(byte[])}, or null
|
||||
* if this instance cannot create any {@link ExoMediaCrypto} instances.
|
||||
*/
|
||||
@Nullable
|
||||
/** Returns the {@link ExoMediaCrypto} type created by {@link #createMediaCrypto(byte[])}. */
|
||||
Class<? extends ExoMediaCrypto> getExoMediaCryptoType();
|
||||
}
|
||||
|
@ -787,7 +787,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
if (trackFormat.drmInitData != null) {
|
||||
trackFormat =
|
||||
trackFormat.copyWithExoMediaCryptoType(
|
||||
drmSessionManager.getExoMediaCryptoType(trackFormat.drmInitData));
|
||||
drmSessionManager.getExoMediaCryptoType(
|
||||
trackFormat.drmInitData, MimeTypes.getTrackType(trackFormat.sampleMimeType)));
|
||||
}
|
||||
trackArray[i] = new TrackGroup(trackFormat);
|
||||
}
|
||||
|
@ -674,7 +674,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
if (drmInitData != null) {
|
||||
format =
|
||||
format.copyWithExoMediaCryptoType(
|
||||
drmSessionManager.getExoMediaCryptoType(drmInitData));
|
||||
drmSessionManager.getExoMediaCryptoType(
|
||||
drmInitData, MimeTypes.getTrackType(format.sampleMimeType)));
|
||||
}
|
||||
formats[j] = format;
|
||||
}
|
||||
|
@ -1313,7 +1313,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
if (format.drmInitData != null) {
|
||||
format =
|
||||
format.copyWithExoMediaCryptoType(
|
||||
drmSessionManager.getExoMediaCryptoType(format.drmInitData));
|
||||
drmSessionManager.getExoMediaCryptoType(
|
||||
format.drmInitData, MimeTypes.getTrackType(format.sampleMimeType)));
|
||||
}
|
||||
exposedFormats[j] = format;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
|
||||
import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -274,7 +275,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
exposedFormats[j] =
|
||||
manifestFormat.drmInitData != null
|
||||
? manifestFormat.copyWithExoMediaCryptoType(
|
||||
drmSessionManager.getExoMediaCryptoType(manifestFormat.drmInitData))
|
||||
drmSessionManager.getExoMediaCryptoType(
|
||||
manifestFormat.drmInitData,
|
||||
MimeTypes.getTrackType(manifestFormat.sampleMimeType)))
|
||||
: manifestFormat;
|
||||
}
|
||||
trackGroups[i] = new TrackGroup(exposedFormats);
|
||||
|
@ -269,9 +269,8 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
||||
return new FakeExoMediaCrypto();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Class<? extends ExoMediaCrypto> getExoMediaCryptoType() {
|
||||
public Class<FakeExoMediaCrypto> getExoMediaCryptoType() {
|
||||
return FakeExoMediaCrypto.class;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user