cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / webm / webm_audio_client.cc
blobe52f44b4a9a7f33ee8bf8119b044999e4e4c8eee
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"
11 namespace media {
13 WebMAudioClient::WebMAudioClient(const LogCB& log_cb)
14 : log_cb_(log_cb) {
15 Reset();
18 WebMAudioClient::~WebMAudioClient() {
21 void WebMAudioClient::Reset() {
22 channels_ = -1;
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) {
30 DCHECK(config);
32 AudioCodec audio_codec = kUnknownAudioCodec;
33 if (codec_id == "A_VORBIS") {
34 audio_codec = kCodecVorbis;
35 } else {
36 MEDIA_LOG(log_cb_) << "Unsupported audio codec_id " << codec_id;
37 return false;
40 if (samples_per_second_ <= 0)
41 return false;
43 // Set channel layout default if a Channels element was not present.
44 if (channels_ == -1)
45 channels_ = 1;
47 ChannelLayout channel_layout = GuessChannelLayout(channels_);
49 if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED) {
50 MEDIA_LOG(log_cb_) << "Unsupported channel count " << channels_;
51 return false;
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();
65 config->Initialize(
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
76 << ")";
77 return false;
80 channels_ = val;
82 return true;
85 bool WebMAudioClient::OnFloat(int id, double val) {
86 double* dst = NULL;
88 switch (id) {
89 case kWebMIdSamplingFrequency:
90 dst = &samples_per_second_;
91 break;
92 case kWebMIdOutputSamplingFrequency:
93 dst = &output_samples_per_second_;
94 break;
95 default:
96 return true;
99 if (val <= 0)
100 return false;
102 if (*dst != -1) {
103 MEDIA_LOG(log_cb_) << "Multiple values for id " << std::hex << id
104 << " specified (" << *dst << " and " << val << ")";
105 return false;
108 *dst = val;
109 return true;
112 } // namespace media