5 #include <packager/media/formats/webm/webm_audio_client.h>
7 #include <absl/log/log.h>
9 #include <packager/media/formats/webm/webm_constants.h>
13 const int32_t kWebMTimeScale = 1000000;
19 WebMAudioClient::WebMAudioClient() {
23 WebMAudioClient::~WebMAudioClient() {
28 samples_per_second_ = -1;
29 output_samples_per_second_ = -1;
34 const std::string& codec_id,
35 const std::vector<uint8_t>& codec_private,
38 const std::string& language,
40 Codec audio_codec = kUnknownCodec;
41 if (codec_id ==
"A_VORBIS") {
42 audio_codec = kCodecVorbis;
43 }
else if (codec_id ==
"A_OPUS") {
44 audio_codec = kCodecOpus;
46 LOG(ERROR) <<
"Unsupported audio codec_id " << codec_id;
47 return std::shared_ptr<AudioStreamInfo>();
50 if (samples_per_second_ <= 0)
51 return std::shared_ptr<AudioStreamInfo>();
57 uint32_t sampling_frequency = samples_per_second_;
60 if (audio_codec == kCodecOpus) {
61 sampling_frequency = 48000;
64 const uint8_t* codec_config = NULL;
65 size_t codec_config_size = 0;
66 if (codec_private.size() > 0) {
67 codec_config = &codec_private[0];
68 codec_config_size = codec_private.size();
71 const uint8_t kSampleSizeInBits = 16u;
72 return std::make_shared<AudioStreamInfo>(
73 track_num, kWebMTimeScale, 0, audio_codec,
75 codec_config_size, kSampleSizeInBits, channels_, sampling_frequency,
76 seek_preroll < 0 ? 0 : seek_preroll, codec_delay < 0 ? 0 : codec_delay, 0,
77 0, language, is_encrypted);
80 bool WebMAudioClient::OnUInt(
int id, int64_t val) {
81 if (
id == kWebMIdChannels) {
82 if (channels_ != -1) {
83 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id
84 <<
" specified. (" << channels_ <<
" and " << val <<
")";
93 bool WebMAudioClient::OnFloat(
int id,
double val) {
97 case kWebMIdSamplingFrequency:
98 dst = &samples_per_second_;
100 case kWebMIdOutputSamplingFrequency:
101 dst = &output_samples_per_second_;
111 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
112 << *dst <<
" and " << val <<
")";
All the methods that are virtual are virtual for mocking.