Skip to content

Commit 6b78164

Browse files
committed
Experimental: Merge muxed audio format if primary is audio
1 parent bc3360e commit 6b78164

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -1392,23 +1392,33 @@ private void buildTracksFromSampleStreams() {
13921392
Format sampleFormat = Assertions.checkStateNotNull(sampleQueues[i].getUpstreamFormat());
13931393
if (i == primaryExtractorTrackIndex) {
13941394
Format[] formats = new Format[chunkSourceTrackCount];
1395+
boolean mergeMuxedAudioFormat =
1396+
primaryExtractorTrackType == C.TRACK_TYPE_AUDIO && muxedAudioFormat != null;
13951397
if (chunkSourceTrackCount == 1) {
1396-
formats[0] = sampleFormat.withManifestFormatInfo(chunkSourceTrackGroup.getFormat(0));
1398+
Format playlistFormat = chunkSourceTrackGroup.getFormat(0);
1399+
if (mergeMuxedAudioFormat) {
1400+
playlistFormat = playlistFormat.withManifestFormatInfo(muxedAudioFormat);
1401+
}
1402+
formats[0] = sampleFormat.withManifestFormatInfo(playlistFormat);
13971403
} else {
13981404
for (int j = 0; j < chunkSourceTrackCount; j++) {
1399-
formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true);
1405+
Format playlistFormat = chunkSourceTrackGroup.getFormat(j);
1406+
if (mergeMuxedAudioFormat) {
1407+
playlistFormat = playlistFormat.withManifestFormatInfo(muxedAudioFormat);
1408+
}
1409+
formats[j] = deriveFormat(playlistFormat, sampleFormat, true);
14001410
}
14011411
}
14021412
trackGroups[i] = new TrackGroup(formats);
14031413
primaryTrackGroupIndex = i;
14041414
} else {
14051415
@Nullable
1406-
Format trackFormat =
1416+
Format playlistFormat =
14071417
primaryExtractorTrackType == C.TRACK_TYPE_VIDEO
14081418
&& MimeTypes.isAudio(sampleFormat.sampleMimeType)
14091419
? muxedAudioFormat
14101420
: null;
1411-
trackGroups[i] = new TrackGroup(deriveFormat(trackFormat, sampleFormat, false));
1421+
trackGroups[i] = new TrackGroup(deriveFormat(playlistFormat, sampleFormat, false));
14121422
}
14131423
}
14141424
this.trackGroups = createTrackGroupArrayWithDrmInfo(trackGroups);

0 commit comments

Comments
 (0)