1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/webm/webm_audio_client.h"
7 #include "media/base/audio_decoder_config.h"
8 #include "media/base/channel_layout.h"
9 #include "media/webm/webm_constants.h"
13 WebMAudioClient::WebMAudioClient(const LogCB
& log_cb
)
18 WebMAudioClient::~WebMAudioClient() {
21 void WebMAudioClient::Reset() {
23 samples_per_second_
= -1;
24 output_samples_per_second_
= -1;
27 bool WebMAudioClient::InitializeConfig(
28 const std::string
& codec_id
, const std::vector
<uint8
>& codec_private
,
29 bool is_encrypted
, AudioDecoderConfig
* config
) {
32 AudioCodec audio_codec
= kUnknownAudioCodec
;
33 if (codec_id
== "A_VORBIS") {
34 audio_codec
= kCodecVorbis
;
36 MEDIA_LOG(log_cb_
) << "Unsupported audio codec_id " << codec_id
;
40 if (samples_per_second_
<= 0)
43 // Set channel layout default if a Channels element was not present.
47 ChannelLayout channel_layout
= GuessChannelLayout(channels_
);
49 if (channel_layout
== CHANNEL_LAYOUT_UNSUPPORTED
) {
50 MEDIA_LOG(log_cb_
) << "Unsupported channel count " << channels_
;
54 int samples_per_second
= samples_per_second_
;
55 if (output_samples_per_second_
> 0)
56 samples_per_second
= output_samples_per_second_
;
58 const uint8
* extra_data
= NULL
;
59 size_t extra_data_size
= 0;
60 if (codec_private
.size() > 0) {
61 extra_data
= &codec_private
[0];
62 extra_data_size
= codec_private
.size();
66 audio_codec
, kSampleFormatPlanarF32
, channel_layout
,
67 samples_per_second
, extra_data
, extra_data_size
, is_encrypted
, true);
68 return config
->IsValidConfig();
71 bool WebMAudioClient::OnUInt(int id
, int64 val
) {
72 if (id
== kWebMIdChannels
) {
73 if (channels_
!= -1) {
74 MEDIA_LOG(log_cb_
) << "Multiple values for id " << std::hex
<< id
75 << " specified. (" << channels_
<< " and " << val
85 bool WebMAudioClient::OnFloat(int id
, double val
) {
89 case kWebMIdSamplingFrequency
:
90 dst
= &samples_per_second_
;
92 case kWebMIdOutputSamplingFrequency
:
93 dst
= &output_samples_per_second_
;
103 MEDIA_LOG(log_cb_
) << "Multiple values for id " << std::hex
<< id
104 << " specified (" << *dst
<< " and " << val
<< ")";