Skip to content

Commit

Permalink
Parse and set peakBitrate for Dolby TrueHD(AC-3) and (E-)AC-3
Browse files Browse the repository at this point in the history
#minor-release

PiperOrigin-RevId: 490527831
  • Loading branch information
rohitjoins authored and icbaker committed Nov 24, 2022
1 parent e61ff42 commit 01eddb3
Show file tree
Hide file tree
Showing 31 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,18 @@ public static Format parseAc3AnnexFFormat(
if ((nextByte & 0x04) != 0) { // lfeon
channelCount++;
}
// bit_rate_code - 5 bits. 2 bits from previous byte and 3 bits from next.
int halfFrmsizecod = ((nextByte & 0x03) << 3) | ((data.readUnsignedByte() & 0xE0) >> 5);
int constantBitrate = BITRATE_BY_HALF_FRMSIZECOD[halfFrmsizecod];
return new Format.Builder()
.setId(trackId)
.setSampleMimeType(MimeTypes.AUDIO_AC3)
.setChannelCount(channelCount)
.setSampleRate(sampleRate)
.setDrmInitData(drmInitData)
.setLanguage(language)
.setAverageBitrate(constantBitrate)
.setPeakBitrate(constantBitrate)
.build();
}

Expand All @@ -178,7 +183,9 @@ public static Format parseAc3AnnexFFormat(
*/
public static Format parseEAc3AnnexFFormat(
ParsableByteArray data, String trackId, String language, @Nullable DrmInitData drmInitData) {
data.skipBytes(2); // data_rate, num_ind_sub
// 13 bits for data_rate, 3 bits for num_ind_sub which are ignored.
int peakBitrate =
((data.readUnsignedByte() & 0xFF) << 5) | ((data.readUnsignedByte() & 0xF8) >> 3);

// Read the first independent substream.
int fscod = (data.readUnsignedByte() & 0xC0) >> 6;
Expand Down Expand Up @@ -214,6 +221,7 @@ public static Format parseEAc3AnnexFFormat(
.setSampleRate(sampleRate)
.setDrmInitData(drmInitData)
.setLanguage(language)
.setPeakBitrate(peakBitrate)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 13824
sample count = 9
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
maxInputSize = 1566
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 9216
sample count = 6
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
maxInputSize = 1566
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 4608
sample count = 3
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
maxInputSize = 1566
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 1536
sample count = 1
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
maxInputSize = 1566
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 13824
sample count = 9
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
maxInputSize = 1566
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 13824
sample count = 9
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 10752
sample count = 7
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 6144
sample count = 4
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 1536
sample count = 1
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ track 0:
total output bytes = 13824
sample count = 9
format 0:
averageBitrate = 384
peakBitrate = 384
id = 1
sampleMimeType = audio/ac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 216000
sample count = 54
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
maxInputSize = 4030
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 144000
sample count = 36
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
maxInputSize = 4030
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 72000
sample count = 18
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
maxInputSize = 4030
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 4000
sample count = 1
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
maxInputSize = 4030
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 216000
sample count = 54
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
maxInputSize = 4030
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 216000
sample count = 54
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 148000
sample count = 37
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 76000
sample count = 19
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 4000
sample count = 1
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 216000
sample count = 54
format 0:
peakBitrate = 1000
id = 1
sampleMimeType = audio/eac3
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 163840
sample count = 64
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
maxInputSize = 2590
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 110080
sample count = 43
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
maxInputSize = 2590
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 56320
sample count = 22
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
maxInputSize = 2590
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 2560
sample count = 1
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
maxInputSize = 2590
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 163840
sample count = 64
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
maxInputSize = 2590
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 163840
sample count = 64
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 110080
sample count = 43
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 56320
sample count = 22
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 2560
sample count = 1
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
channelCount = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ track 0:
total output bytes = 163840
sample count = 64
format 0:
peakBitrate = 640
id = 1
sampleMimeType = audio/eac3-joc
channelCount = 6
Expand Down

0 comments on commit 01eddb3

Please sign in to comment.