7 #include "packager/media/formats/mp2t/ac3_header.h"
9 #include "packager/media/base/bit_reader.h"
10 #include "packager/media/base/bit_writer.h"
11 #include "packager/media/formats/mp2t/mp2t_common.h"
19 const uint32_t kAc3SampleRateTable[] = {48000, 44100, 32000};
22 const uint8_t kAc3NumChannelsTable[] = {2, 1, 2, 3, 3, 4, 4, 5};
26 const size_t kFrameSizeCodeTable[][3] = {
28 {96, 69, 64}, {96, 70, 64}, {120, 87, 80},
29 {120, 88, 80}, {144, 104, 96}, {144, 105, 96},
30 {168, 121, 112}, {168, 122, 112}, {192, 139, 128},
31 {192, 140, 128}, {240, 174, 160}, {240, 175, 160},
32 {288, 208, 192}, {288, 209, 192}, {336, 243, 224},
33 {336, 244, 224}, {384, 278, 256}, {384, 279, 256},
34 {480, 348, 320}, {480, 349, 320}, {576, 417, 384},
35 {576, 418, 384}, {672, 487, 448}, {672, 488, 448},
36 {768, 557, 512}, {768, 558, 512}, {960, 696, 640},
37 {960, 697, 640}, {1152, 835, 768}, {1152, 836, 768},
38 {1344, 975, 896}, {1344, 976, 896}, {1536, 1114, 1024},
39 {1536, 1115, 1024}, {1728, 1253, 1152}, {1728, 1254, 1152},
40 {1920, 1393, 1280}, {1920, 1394, 1280},
46 size_t CalcFrameSize(uint8_t fscod, uint8_t frmsizecod) {
47 const size_t kNumFscode = arraysize(kAc3SampleRateTable);
48 DCHECK_LT(fscod, kNumFscode);
49 DCHECK_LT(frmsizecod, arraysize(kFrameSizeCodeTable));
52 const int index = kNumFscode - 1 - fscod;
53 return kFrameSizeCodeTable[frmsizecod][index] * 2;
61 return buf[0] == 0x0B && buf[1] == 0x77;
66 const size_t kMinAc3FrameSize = 10u;
67 return kMinAc3FrameSize;
73 const size_t kSamplesPerAc3Frame = 1536;
74 return kSamplesPerAc3Frame;
78 BitReader frame(audio_frame, audio_frame_size);
83 RCHECK(frame.
ReadBits(16, &syncword));
84 RCHECK(syncword == 0x0B77);
88 RCHECK(fscod_ < arraysize(kAc3SampleRateTable));
89 RCHECK(frame.
ReadBits(6, &frmsizecod_));
90 RCHECK(frmsizecod_ < arraysize(kFrameSizeCodeTable));
97 RCHECK(acmod_ < arraysize(kAc3NumChannelsTable));
99 if ((acmod_ & 0x01) && (acmod_ != 0x01))
120 return CalcFrameSize(fscod_, frmsizecod_);
124 size_t num_bytes)
const {
125 DCHECK_GT(num_bytes,
static_cast<size_t>(4));
126 uint8_t fscod = data[4] >> 6;
127 uint8_t frmsizecod = data[4] & 0x3f;
128 return CalcFrameSize(fscod, frmsizecod);
141 const uint8_t bit_rate_code = frmsizecod_ >> 1;
152 DCHECK_LT(fscod_, arraysize(kAc3SampleRateTable));
153 return kAc3SampleRateTable[fscod_];
157 DCHECK_LT(acmod_, arraysize(kAc3NumChannelsTable));
158 return kAc3NumChannelsTable[acmod_] + (lfeon_ ? 1 : 0);