Commit ef728178 by olly Committed by Oliver Woodman

Improve format derivation for chunkless preparation

1. Copy label into derived formats
2. If audio is the primary track type, copy additional fields from
   the variant formats. This is probably a no-op in practice, since
   I don't think variant formats have these fields set anyway, but
   it seems like the right thing to do in case they ever are set in
   the future.

Note: It's a bit strange to use createXContainerFormat rather than
createXSampleFormat, but in practice the methods used here are
better matched for what we're trying to do.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204467287
parent 19cc2c82
......@@ -447,8 +447,10 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
&& (masterPlaylist.muxedAudioFormat != null || masterPlaylist.audios.isEmpty())) {
muxedTrackGroups.add(
new TrackGroup(
deriveMuxedAudioFormat(
variants[0].format, masterPlaylist.muxedAudioFormat, Format.NO_VALUE)));
deriveAudioFormat(
variants[0].format,
masterPlaylist.muxedAudioFormat,
/* isPrimaryTrackInVariant= */ false)));
}
List<Format> ccFormats = masterPlaylist.muxedCaptionFormats;
if (ccFormats != null) {
......@@ -462,8 +464,10 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
for (int i = 0; i < audioFormats.length; i++) {
Format variantFormat = variants[i].format;
audioFormats[i] =
deriveMuxedAudioFormat(
variantFormat, masterPlaylist.muxedAudioFormat, variantFormat.bitrate);
deriveAudioFormat(
variantFormat,
masterPlaylist.muxedAudioFormat,
/* isPrimaryTrackInVariant= */ true);
}
muxedTrackGroups.add(new TrackGroup(audioFormats));
} else {
......@@ -508,45 +512,55 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
private static Format deriveVideoFormat(Format variantFormat) {
String codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_VIDEO);
String mimeType = MimeTypes.getMediaMimeType(codecs);
return Format.createVideoSampleFormat(
String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
return Format.createVideoContainerFormat(
variantFormat.id,
mimeType,
variantFormat.label,
variantFormat.containerMimeType,
sampleMimeType,
codecs,
variantFormat.bitrate,
Format.NO_VALUE,
variantFormat.width,
variantFormat.height,
variantFormat.frameRate,
null,
null);
/* initializationData= */ null,
variantFormat.selectionFlags);
}
private static Format deriveMuxedAudioFormat(
Format variantFormat, Format mediaTagFormat, int bitrate) {
private static Format deriveAudioFormat(
Format variantFormat, Format mediaTagFormat, boolean isPrimaryTrackInVariant) {
String codecs;
int channelCount = Format.NO_VALUE;
int selectionFlags = 0;
String language = null;
String label = null;
if (mediaTagFormat != null) {
codecs = mediaTagFormat.codecs;
channelCount = mediaTagFormat.channelCount;
selectionFlags = mediaTagFormat.selectionFlags;
language = mediaTagFormat.language;
label = mediaTagFormat.label;
} else {
codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_AUDIO);
if (isPrimaryTrackInVariant) {
channelCount = variantFormat.channelCount;
selectionFlags = variantFormat.selectionFlags;
language = variantFormat.label;
label = variantFormat.label;
}
}
String mimeType = MimeTypes.getMediaMimeType(codecs);
return Format.createAudioSampleFormat(
String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
int bitrate = isPrimaryTrackInVariant ? variantFormat.bitrate : Format.NO_VALUE;
return Format.createAudioContainerFormat(
variantFormat.id,
mimeType,
label,
variantFormat.containerMimeType,
sampleMimeType,
codecs,
bitrate,
Format.NO_VALUE,
channelCount,
Format.NO_VALUE,
null,
null,
/* sampleRate= */ Format.NO_VALUE,
/* initializationData= */ null,
selectionFlags,
language);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment