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;
15 namespace edash_packager {
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,
35 const std::string& language,
37 AudioCodec audio_codec = kUnknownAudioCodec;
38 if (codec_id ==
"A_VORBIS") {
39 audio_codec = kCodecVorbis;
40 }
else if (codec_id ==
"A_OPUS") {
41 audio_codec = kCodecOpus;
43 LOG(ERROR) <<
"Unsupported audio codec_id " << codec_id;
44 return scoped_refptr<AudioStreamInfo>();
47 if (samples_per_second_ <= 0)
48 return scoped_refptr<AudioStreamInfo>();
54 uint32_t sampling_frequency = samples_per_second_;
57 if (audio_codec == kCodecOpus) {
58 sampling_frequency = 48000;
61 const uint8_t* extra_data = NULL;
62 size_t extra_data_size = 0;
63 if (codec_private.size() > 0) {
64 extra_data = &codec_private[0];
65 extra_data_size = codec_private.size();
68 const uint32_t kSampleSizeInBits = 4u;
70 track_num, kWebMTimeScale, 0, audio_codec,
72 kSampleSizeInBits, channels_, sampling_frequency, 0, 0, extra_data,
73 extra_data_size, is_encrypted));
76 bool WebMAudioClient::OnUInt(
int id, int64_t val) {
77 if (
id == kWebMIdChannels) {
78 if (channels_ != -1) {
79 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id
80 <<
" specified. (" << channels_ <<
" and " << val <<
")";
89 bool WebMAudioClient::OnFloat(
int id,
double val) {
93 case kWebMIdSamplingFrequency:
94 dst = &samples_per_second_;
96 case kWebMIdOutputSamplingFrequency:
97 dst = &output_samples_per_second_;
107 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
108 << *dst <<
" and " << val <<
")";