// Copyright 2018 Google LLC. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd #include #include #include #include #include namespace shaka { namespace media { namespace { // ASTC Standard A/52:2012 Table 5.8 Audio Coding Mode. const uint8_t kAc3NumChannelsTable[] = {2, 1, 2, 3, 3, 4, 4, 5}; bool ExtractAc3Data(const std::vector& ac3_data, uint8_t* audio_coding_mode, bool* lfe_channel_on) { BitReader bit_reader(ac3_data.data(), ac3_data.size()); // fscod: 2 bits // bsid: 5 bits // bsmod: 3 bits // acmod: 3 bits // lfeon: 1 bit // bit_rate_code: 5 bits RCHECK(bit_reader.SkipBits(10)); RCHECK(bit_reader.ReadBits(3, audio_coding_mode)); RCHECK(bit_reader.ReadBits(1, lfe_channel_on)); return true; } } // namespace size_t GetAc3NumChannels(const std::vector& ac3_data) { uint8_t audio_coding_mode; bool lfe_channel_on; if (!ExtractAc3Data(ac3_data, &audio_coding_mode, &lfe_channel_on)) { LOG(WARNING) << "Seeing invalid AC3 data: " << absl::BytesToHexString( byte_vector_to_string_view(ac3_data)); return 0; } return kAc3NumChannelsTable[audio_coding_mode] + (lfe_channel_on ? 1 : 0); } } // namespace media } // namespace shaka