mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
19cc2c822a
commit
ef728178a8
1 changed files with 33 additions and 19 deletions
|
|
@ -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
|
||||||
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
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue