Fix ExoMediaCryptoType attachment

- Attach types for placeholder sessions. If a placeholder session will be
  attached and a downstream renderer doesn't know what to do with it, then
  this attachment is necessary to correctly determine that the renderer
  does not support the track.
- Attach types to sample formats. Without this, if playback fails due to
  a CryptoException, the ExoPlaybackException that gets thrown spuriously
  indicates that the format's DRM type was not supported.

PiperOrigin-RevId: 325214745
This commit is contained in:
olly 2020-08-06 14:00:06 +01:00 committed by kim-vde
parent f29af879c0
commit 283bed8cb2
5 changed files with 21 additions and 29 deletions

View File

@ -780,12 +780,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
trackFormat = trackFormat.buildUpon().setAverageBitrate(icyHeaders.bitrate).build();
}
}
if (trackFormat.drmInitData != null) {
trackFormat =
trackFormat.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(
trackFormat.drmInitData, MimeTypes.getTrackType(trackFormat.sampleMimeType)));
}
trackFormat =
trackFormat.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(
trackFormat.drmInitData, MimeTypes.getTrackType(trackFormat.sampleMimeType)));
trackArray[i] = new TrackGroup(trackFormat);
}
trackState = new TrackState(new TrackGroupArray(trackArray), trackIsAudioVideoFlags);

View File

@ -826,11 +826,15 @@ public class SampleQueue implements TrackOutput {
* @param outputFormatHolder The output {@link FormatHolder}.
*/
private void onFormatResult(Format newFormat, FormatHolder outputFormatHolder) {
outputFormatHolder.format = newFormat;
boolean isFirstFormat = downstreamFormat == null;
@Nullable DrmInitData oldDrmInitData = isFirstFormat ? null : downstreamFormat.drmInitData;
downstreamFormat = newFormat;
@Nullable DrmInitData newDrmInitData = newFormat.drmInitData;
outputFormatHolder.format =
newFormat.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(
newFormat.drmInitData, MimeTypes.getTrackType(newFormat.sampleMimeType)));
outputFormatHolder.drmSession = currentDrmSession;
if (!isFirstFormat && Util.areEqual(oldDrmInitData, newDrmInitData)) {
// Nothing to do.

View File

@ -25,7 +25,6 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.SeekParameters;
import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.offline.StreamKey;
@ -665,14 +664,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
Format[] formats = new Format[representations.size()];
for (int j = 0; j < formats.length; j++) {
Format format = representations.get(j).format;
DrmInitData drmInitData = format.drmInitData;
if (drmInitData != null) {
format =
format.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(
drmInitData, MimeTypes.getTrackType(format.sampleMimeType)));
}
formats[j] = format;
formats[j] =
format.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(
format.drmInitData, MimeTypes.getTrackType(format.sampleMimeType)));
}
AdaptationSet firstAdaptationSet = adaptationSets.get(adaptationSetIndices[0]);

View File

@ -1318,13 +1318,10 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
Format[] exposedFormats = new Format[trackGroup.length];
for (int j = 0; j < trackGroup.length; j++) {
Format format = trackGroup.getFormat(j);
if (format.drmInitData != null) {
format =
format.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(
format.drmInitData, MimeTypes.getTrackType(format.sampleMimeType)));
}
exposedFormats[j] = format;
exposedFormats[j] =
format.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(
format.drmInitData, MimeTypes.getTrackType(format.sampleMimeType)));
}
trackGroups[i] = new TrackGroup(exposedFormats);
}

View File

@ -266,12 +266,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
for (int j = 0; j < manifestFormats.length; j++) {
Format manifestFormat = manifestFormats[j];
exposedFormats[j] =
manifestFormat.drmInitData != null
? manifestFormat.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(
manifestFormat.drmInitData,
MimeTypes.getTrackType(manifestFormat.sampleMimeType)))
: manifestFormat;
manifestFormat.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType(
manifestFormat.drmInitData,
MimeTypes.getTrackType(manifestFormat.sampleMimeType)));
}
trackGroups[i] = new TrackGroup(exposedFormats);
}