From 45857b50dc251e67f7b0d609ba276a5aebf11677 Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 16 Nov 2021 14:27:18 +0000 Subject: [PATCH] HLS: Merge muxedAudioFormat into primary audio tracks Issue: google/ExoPlayer#9608 #minor-release PiperOrigin-RevId: 410236626 --- RELEASENOTES.md | 4 +++ .../source/hls/HlsSampleStreamWrapper.java | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 091a5240e6..c91933ba7c 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -2,6 +2,10 @@ ### dev-v2 (not yet released) +* HLS: + * Correctly populate `Format.label` for audio only HLS streams + ([#9608](https://github.com/google/ExoPlayer/issues/9608)). + ### 2.16.1 (2021-11-11) * Core Library: diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java index da4fbad97d..6695c329da 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java @@ -1392,23 +1392,31 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; Format sampleFormat = Assertions.checkStateNotNull(sampleQueues[i].getUpstreamFormat()); if (i == primaryExtractorTrackIndex) { Format[] formats = new Format[chunkSourceTrackCount]; - if (chunkSourceTrackCount == 1) { - formats[0] = sampleFormat.withManifestFormatInfo(chunkSourceTrackGroup.getFormat(0)); - } else { - for (int j = 0; j < chunkSourceTrackCount; j++) { - formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true); + for (int j = 0; j < chunkSourceTrackCount; j++) { + Format playlistFormat = chunkSourceTrackGroup.getFormat(j); + if (primaryExtractorTrackType == C.TRACK_TYPE_AUDIO && muxedAudioFormat != null) { + playlistFormat = playlistFormat.withManifestFormatInfo(muxedAudioFormat); } + // If there's only a single variant (chunkSourceTrackCount == 1) then we can safely + // retain all fields from sampleFormat. Else we need to use deriveFormat to retain only + // the fields that will be the same for all variants. + formats[j] = + chunkSourceTrackCount == 1 + ? sampleFormat.withManifestFormatInfo(playlistFormat) + : deriveFormat(playlistFormat, sampleFormat, /* propagateBitrates= */ true); } trackGroups[i] = new TrackGroup(formats); primaryTrackGroupIndex = i; } else { @Nullable - Format trackFormat = + Format playlistFormat = primaryExtractorTrackType == C.TRACK_TYPE_VIDEO && MimeTypes.isAudio(sampleFormat.sampleMimeType) ? muxedAudioFormat : null; - trackGroups[i] = new TrackGroup(deriveFormat(trackFormat, sampleFormat, false)); + trackGroups[i] = + new TrackGroup( + deriveFormat(playlistFormat, sampleFormat, /* propagateBitrates= */ false)); } } this.trackGroups = createTrackGroupArrayWithDrmInfo(trackGroups); @@ -1496,8 +1504,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; * sample format that may have been obtained from a chunk belonging to a different track in the * same track group. * + *

Note: Since the sample format may have been obtained from a chunk belonging to a different + * track, it should not be used as a source for data that may vary between tracks. + * * @param playlistFormat The format information obtained from the master playlist. - * @param sampleFormat The format information obtained from the samples. + * @param sampleFormat The format information obtained from samples within a chunk. The chunk may + * belong to a different track in the same track group. * @param propagateBitrates Whether the bitrates from the playlist format should be included in * the derived format. * @return The derived track format.