7 #include <packager/media/base/audio_stream_info.h>
11 #include <absl/log/log.h>
12 #include <absl/strings/str_format.h>
14 #include <packager/macros/compiler.h>
15 #include <packager/macros/logging.h>
16 #include <packager/media/base/limits.h>
22 std::string AudioCodecToString(Codec codec) {
57 NOTIMPLEMENTED() <<
"Unknown Audio Codec: " << codec;
58 return "UnknownCodec";
62 FourCC CodecToFourCC(Codec codec) {
78 const std::string& codec_string,
79 const uint8_t* codec_config,
80 size_t codec_config_size,
83 uint32_t sampling_frequency,
84 uint64_t seek_preroll_ns,
85 uint64_t codec_delay_ns,
88 const std::string& language,
100 sample_bits_(sample_bits),
101 num_channels_(num_channels),
102 sampling_frequency_(sampling_frequency),
103 seek_preroll_ns_(seek_preroll_ns),
104 codec_delay_ns_(codec_delay_ns),
105 max_bitrate_(max_bitrate),
106 avg_bitrate_(avg_bitrate) {}
108 AudioStreamInfo::~AudioStreamInfo() {}
111 return codec() != kUnknownCodec && num_channels_ != 0 &&
112 num_channels_ <= limits::kMaxChannels && sample_bits_ > 0 &&
113 sample_bits_ <= limits::kMaxBitsPerSample && sampling_frequency_ > 0 &&
114 sampling_frequency_ <= limits::kMaxSampleRate;
118 std::string str = absl::StrFormat(
119 "%s codec: %s\n sample_bits: %d\n num_channels: %d\n "
120 "sampling_frequency: %d\n language: %s\n",
122 sample_bits_, num_channels_, sampling_frequency_, language().c_str());
123 if (seek_preroll_ns_ != 0) {
124 absl::StrAppendFormat(&str,
" seek_preroll_ns: %" PRIu64
"\n",
127 if (codec_delay_ns_ != 0) {
128 absl::StrAppendFormat(&str,
" codec_delay_ns: %" PRIu64
"\n",
139 uint8_t audio_object_type) {
142 return "mp4a.40." + absl::StrFormat(
"%hhu", audio_object_type);
168 return absl::StrFormat(
169 "ac-4.%02d.%02d.%02d", (audio_object_type & 0xE0) >> 5,
170 (audio_object_type & 0x18) >> 3, audio_object_type & 0x7);
186 const int iamf_codec = (audio_object_type & 0xF) + kCodecAudio;
188 const std::string iamf_codec_string =
189 absl::StrFormat(
"iamf.%03d.%03d", (audio_object_type & 0xC0) >> 6,
190 (audio_object_type & 0x30) >> 4);
192 switch (iamf_codec) {
194 return absl::StrFormat(
"%s.%s", iamf_codec_string,
"Opus");
196 return absl::StrFormat(
"%s.%s", iamf_codec_string,
"mp4a.40.2");
198 return absl::StrFormat(
"%s.%s", iamf_codec_string,
"fLaC");
200 return absl::StrFormat(
"%s.%s", iamf_codec_string,
"ipcm");
202 LOG(WARNING) <<
"Unknown IAMF codec: " << iamf_codec;
220 return absl::StrFormat(
"%s.0x%02x",
221 FourCCToString(CodecToFourCC(codec)).c_str(),
224 NOTIMPLEMENTED() <<
"Codec: " << codec;
All the methods that are virtual are virtual for mocking.