Skip to content

Commit 29bda3b

Browse files
committed
Add AC-4 Level-4 ISO base media file format support
1 parent b8c559e commit 29bda3b

File tree

3 files changed

+657
-12
lines changed

3 files changed

+657
-12
lines changed

libraries/common/src/main/java/androidx/media3/common/util/Util.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,22 @@ public static int getAudioTrackChannelConfig(int channelCount) {
22642264
}
22652265
case 12:
22662266
return AudioFormat.CHANNEL_OUT_7POINT1POINT4;
2267+
case 24:
2268+
return Util.SDK_INT >= 32
2269+
? AudioFormat.CHANNEL_OUT_7POINT1POINT4 |
2270+
AudioFormat.CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
2271+
AudioFormat.CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
2272+
AudioFormat.CHANNEL_OUT_BACK_CENTER |
2273+
AudioFormat.CHANNEL_OUT_TOP_CENTER |
2274+
AudioFormat.CHANNEL_OUT_TOP_FRONT_CENTER |
2275+
AudioFormat.CHANNEL_OUT_TOP_BACK_CENTER |
2276+
AudioFormat.CHANNEL_OUT_TOP_SIDE_LEFT |
2277+
AudioFormat.CHANNEL_OUT_TOP_SIDE_RIGHT |
2278+
AudioFormat.CHANNEL_OUT_BOTTOM_FRONT_LEFT |
2279+
AudioFormat.CHANNEL_OUT_BOTTOM_FRONT_RIGHT |
2280+
AudioFormat.CHANNEL_OUT_BOTTOM_FRONT_CENTER |
2281+
AudioFormat.CHANNEL_OUT_LOW_FREQUENCY_2
2282+
: AudioFormat.CHANNEL_INVALID;
22672283
default:
22682284
return AudioFormat.CHANNEL_INVALID;
22692285
}

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/trackselection/DefaultTrackSelector.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,13 +4242,23 @@ public boolean isEnabled() {
42424242
}
42434243

42444244
public boolean canBeSpatialized(AudioAttributes audioAttributes, Format format) {
4245-
// For E-AC3 JOC, the format is object based. When the channel count is 16, this maps to 12
4246-
// linear channels and the rest are used for objects. See
4247-
// https://github.com/google/ExoPlayer/pull/10322#discussion_r895265881
4248-
int linearChannelCount =
4249-
MimeTypes.AUDIO_E_AC3_JOC.equals(format.sampleMimeType) && format.channelCount == 16
4250-
? 12
4251-
: format.channelCount;
4245+
int linearChannelCount;
4246+
if (MimeTypes.AUDIO_E_AC3_JOC.equals(format.sampleMimeType)) {
4247+
// For E-AC3 JOC, the format is object based. When the channel count is 16, this maps to 12
4248+
// linear channels and the rest are used for objects. See
4249+
// https://github.com/google/ExoPlayer/pull/10322#discussion_r895265881
4250+
linearChannelCount = format.channelCount == 16 ? 12 : format.channelCount;
4251+
} else if (MimeTypes.AUDIO_AC4.equals(format.sampleMimeType)) {
4252+
// For AC-4 level 3 or level 4, the format may be object based. When the channel count is
4253+
// 18 (level 3 17.1 OBI) or 21 (level 4 20.1 OBI), it is mapped to 24 linear channels
4254+
// (There are some channels used for metadata transfer).
4255+
linearChannelCount = (format.channelCount == 18 || format.channelCount == 21)
4256+
? 24
4257+
: format.channelCount;
4258+
} else {
4259+
linearChannelCount = format.channelCount;
4260+
}
4261+
42524262
AudioFormat.Builder builder =
42534263
new AudioFormat.Builder()
42544264
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)

0 commit comments

Comments
 (0)