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 ...@@ -447,8 +447,10 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
&& (masterPlaylist.muxedAudioFormat != null || masterPlaylist.audios.isEmpty())) { && (masterPlaylist.muxedAudioFormat != null || masterPlaylist.audios.isEmpty())) {
muxedTrackGroups.add( muxedTrackGroups.add(
new TrackGroup( new TrackGroup(
deriveMuxedAudioFormat( deriveAudioFormat(
variants[0].format, masterPlaylist.muxedAudioFormat, Format.NO_VALUE))); variants[0].format,
masterPlaylist.muxedAudioFormat,
/* isPrimaryTrackInVariant= */ false)));
} }
List<Format> ccFormats = masterPlaylist.muxedCaptionFormats; List<Format> ccFormats = masterPlaylist.muxedCaptionFormats;
if (ccFormats != null) { if (ccFormats != null) {
...@@ -462,8 +464,10 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper ...@@ -462,8 +464,10 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
for (int i = 0; i < audioFormats.length; i++) { for (int i = 0; i < audioFormats.length; i++) {
Format variantFormat = variants[i].format; Format variantFormat = variants[i].format;
audioFormats[i] = audioFormats[i] =
deriveMuxedAudioFormat( deriveAudioFormat(
variantFormat, masterPlaylist.muxedAudioFormat, variantFormat.bitrate); variantFormat,
masterPlaylist.muxedAudioFormat,
/* isPrimaryTrackInVariant= */ true);
} }
muxedTrackGroups.add(new TrackGroup(audioFormats)); muxedTrackGroups.add(new TrackGroup(audioFormats));
} else { } else {
...@@ -508,45 +512,55 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper ...@@ -508,45 +512,55 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
private static Format deriveVideoFormat(Format variantFormat) { private static Format deriveVideoFormat(Format variantFormat) {
String codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_VIDEO); String codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_VIDEO);
String mimeType = MimeTypes.getMediaMimeType(codecs); String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
return Format.createVideoSampleFormat( return Format.createVideoContainerFormat(
variantFormat.id, variantFormat.id,
mimeType, variantFormat.label,
variantFormat.containerMimeType,
sampleMimeType,
codecs, codecs,
variantFormat.bitrate, variantFormat.bitrate,
Format.NO_VALUE,
variantFormat.width, variantFormat.width,
variantFormat.height, variantFormat.height,
variantFormat.frameRate, variantFormat.frameRate,
null, /* initializationData= */ null,
null); variantFormat.selectionFlags);
} }
private static Format deriveMuxedAudioFormat( private static Format deriveAudioFormat(
Format variantFormat, Format mediaTagFormat, int bitrate) { Format variantFormat, Format mediaTagFormat, boolean isPrimaryTrackInVariant) {
String codecs; String codecs;
int channelCount = Format.NO_VALUE; int channelCount = Format.NO_VALUE;
int selectionFlags = 0; int selectionFlags = 0;
String language = null; String language = null;
String label = null;
if (mediaTagFormat != null) { if (mediaTagFormat != null) {
codecs = mediaTagFormat.codecs; codecs = mediaTagFormat.codecs;
channelCount = mediaTagFormat.channelCount; channelCount = mediaTagFormat.channelCount;
selectionFlags = mediaTagFormat.selectionFlags; selectionFlags = mediaTagFormat.selectionFlags;
language = mediaTagFormat.language; language = mediaTagFormat.language;
label = mediaTagFormat.label;
} else { } else {
codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_AUDIO); 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); String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
return Format.createAudioSampleFormat( int bitrate = isPrimaryTrackInVariant ? variantFormat.bitrate : Format.NO_VALUE;
return Format.createAudioContainerFormat(
variantFormat.id, variantFormat.id,
mimeType, label,
variantFormat.containerMimeType,
sampleMimeType,
codecs, codecs,
bitrate, bitrate,
Format.NO_VALUE,
channelCount, channelCount,
Format.NO_VALUE, /* sampleRate= */ Format.NO_VALUE,
null, /* initializationData= */ null,
null,
selectionFlags, selectionFlags,
language); 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