7 #include <packager/media/codecs/ac3_audio_util.h>
9 #include <absl/strings/escaping.h>
11 #include <packager/media/base/bit_reader.h>
12 #include <packager/media/base/rcheck.h>
13 #include <packager/utils/bytes_to_string_view.h>
21 const uint8_t kAc3NumChannelsTable[] = {2, 1, 2, 3, 3, 4, 4, 5};
23 bool ExtractAc3Data(
const std::vector<uint8_t>& ac3_data,
24 uint8_t* audio_coding_mode,
25 bool* lfe_channel_on) {
26 BitReader bit_reader(ac3_data.data(), ac3_data.size());
34 RCHECK(bit_reader.SkipBits(10));
35 RCHECK(bit_reader.ReadBits(3, audio_coding_mode));
36 RCHECK(bit_reader.ReadBits(1, lfe_channel_on));
42 size_t GetAc3NumChannels(
const std::vector<uint8_t>& ac3_data) {
43 uint8_t audio_coding_mode;
45 if (!ExtractAc3Data(ac3_data, &audio_coding_mode, &lfe_channel_on)) {
46 LOG(WARNING) <<
"Seeing invalid AC3 data: "
47 << absl::BytesToHexString(
51 return kAc3NumChannelsTable[audio_coding_mode] + (lfe_channel_on ? 1 : 0);
All the methods that are virtual are virtual for mocking.
std::string_view byte_vector_to_string_view(const std::vector< uint8_t > &bytes)
Convert byte vector to string_view.