5 #include "packager/media/formats/webm/webm_audio_client.h"
7 #include "packager/base/logging.h"
8 #include "packager/media/formats/webm/webm_constants.h"
12 const uint32_t kWebMTimeScale = 1000000u;
18 WebMAudioClient::WebMAudioClient() {
22 WebMAudioClient::~WebMAudioClient() {
27 samples_per_second_ = -1;
28 output_samples_per_second_ = -1;
33 const std::string& codec_id,
34 const std::vector<uint8_t>& codec_private,
37 const std::string& language,
39 Codec audio_codec = kUnknownCodec;
40 if (codec_id ==
"A_VORBIS") {
41 audio_codec = kCodecVorbis;
42 }
else if (codec_id ==
"A_OPUS") {
43 audio_codec = kCodecOpus;
45 LOG(ERROR) <<
"Unsupported audio codec_id " << codec_id;
46 return std::shared_ptr<AudioStreamInfo>();
49 if (samples_per_second_ <= 0)
50 return std::shared_ptr<AudioStreamInfo>();
56 uint32_t sampling_frequency = samples_per_second_;
59 if (audio_codec == kCodecOpus) {
60 sampling_frequency = 48000;
63 const uint8_t* codec_config = NULL;
64 size_t codec_config_size = 0;
65 if (codec_private.size() > 0) {
66 codec_config = &codec_private[0];
67 codec_config_size = codec_private.size();
70 const uint8_t kSampleSizeInBits = 16u;
71 return std::make_shared<AudioStreamInfo>(
72 track_num, kWebMTimeScale, 0, audio_codec,
74 codec_config_size, kSampleSizeInBits, channels_, sampling_frequency,
75 seek_preroll < 0 ? 0 : seek_preroll, codec_delay < 0 ? 0 : codec_delay, 0,
76 0, language, is_encrypted);
79 bool WebMAudioClient::OnUInt(
int id, int64_t val) {
80 if (
id == kWebMIdChannels) {
81 if (channels_ != -1) {
82 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id
83 <<
" specified. (" << channels_ <<
" and " << val <<
")";
92 bool WebMAudioClient::OnFloat(
int id,
double val) {
96 case kWebMIdSamplingFrequency:
97 dst = &samples_per_second_;
99 case kWebMIdOutputSamplingFrequency:
100 dst = &output_samples_per_second_;
110 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
111 << *dst <<
" and " << val <<
")";