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(); trackFormat = trackFormat.buildUpon().setAverageBitrate(icyHeaders.bitrate).build();
} }
} }
if (trackFormat.drmInitData != null) {
trackFormat = trackFormat =
trackFormat.copyWithExoMediaCryptoType( trackFormat.copyWithExoMediaCryptoType(
drmSessionManager.getExoMediaCryptoType( drmSessionManager.getExoMediaCryptoType(
trackFormat.drmInitData, MimeTypes.getTrackType(trackFormat.sampleMimeType))); trackFormat.drmInitData, MimeTypes.getTrackType(trackFormat.sampleMimeType)));
}
trackArray[i] = new TrackGroup(trackFormat); trackArray[i] = new TrackGroup(trackFormat);
} }
trackState = new TrackState(new TrackGroupArray(trackArray), trackIsAudioVideoFlags); trackState = new TrackState(new TrackGroupArray(trackArray), trackIsAudioVideoFlags);

View File

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

View File

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

View File

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

View File

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