7 #include <packager/media/codecs/hls_audio_util.h>
9 #include <absl/log/check.h>
11 #include <packager/media/base/buffer_writer.h>
12 #include <packager/media/base/fourccs.h>
13 #include <packager/media/codecs/aac_audio_specific_config.h>
18 bool WriteAudioSetupInformation(Codec codec,
19 const uint8_t* audio_specific_config,
20 size_t audio_specific_config_size,
21 BufferWriter* audio_setup_information) {
22 uint32_t audio_type = FOURCC_NULL;
25 AACAudioSpecificConfig config;
26 const bool result = config.Parse(std::vector<uint8_t>(
27 audio_specific_config,
28 audio_specific_config + audio_specific_config_size));
30 AACAudioSpecificConfig::AudioObjectType audio_object_type;
32 LOG(WARNING) <<
"Failed to parse config. Assuming AAC-LC.";
33 audio_object_type = AACAudioSpecificConfig::AOT_AAC_LC;
35 audio_object_type = config.GetAudioObjectType();
38 switch (audio_object_type) {
39 case AACAudioSpecificConfig::AOT_AAC_LC:
40 audio_type = FOURCC_zaac;
42 case AACAudioSpecificConfig::AOT_SBR:
43 audio_type = FOURCC_zach;
45 case AACAudioSpecificConfig::AOT_PS:
46 audio_type = FOURCC_zacp;
49 LOG(ERROR) <<
"Unknown object type for aac " << audio_object_type;
54 audio_type = FOURCC_zac3;
57 audio_type = FOURCC_zec3;
60 LOG(ERROR) <<
"Codec " << codec <<
" is not supported in encrypted TS.";
64 DCHECK_NE(audio_type, FOURCC_NULL);
65 audio_setup_information->AppendInt(audio_type);
67 audio_setup_information->AppendInt(
static_cast<uint16_t
>(0x0000));
69 audio_setup_information->AppendInt(
static_cast<uint8_t
>(0x01));
72 if (audio_specific_config_size > 0xFF) {
73 LOG(ERROR) <<
"Audio specific config should not be larger than one byte "
74 << audio_specific_config_size;
77 audio_setup_information->AppendInt(
78 static_cast<uint8_t
>(audio_specific_config_size));
80 audio_setup_information->AppendArray(audio_specific_config,
81 audio_specific_config_size);
All the methods that are virtual are virtual for mocking.