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 int64 seek_preroll
, int64 codec_delay
, bool is_encrypted
,
30 AudioDecoderConfig
* config
) {
33 AudioCodec audio_codec
= kUnknownAudioCodec
;
34 if (codec_id
== "A_VORBIS") {
35 audio_codec
= kCodecVorbis
;
36 } else if (codec_id
== "A_OPUS") {
37 audio_codec
= kCodecOpus
;
39 MEDIA_LOG(log_cb_
) << "Unsupported audio codec_id " << codec_id
;
43 if (samples_per_second_
<= 0)
46 // Set channel layout default if a Channels element was not present.
50 ChannelLayout channel_layout
= GuessChannelLayout(channels_
);
52 if (channel_layout
== CHANNEL_LAYOUT_UNSUPPORTED
) {
53 MEDIA_LOG(log_cb_
) << "Unsupported channel count " << channels_
;
57 int samples_per_second
= samples_per_second_
;
58 if (output_samples_per_second_
> 0)
59 samples_per_second
= output_samples_per_second_
;
61 const uint8
* 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();
70 (audio_codec
== kCodecOpus
) ? kSampleFormatS16
: kSampleFormatPlanarF32
,
72 samples_per_second
, extra_data
, extra_data_size
, is_encrypted
, true,
73 base::TimeDelta::FromMicroseconds(
74 (seek_preroll
!= -1 ? seek_preroll
: 0) / 1000),
75 base::TimeDelta::FromMicroseconds(
76 (codec_delay
!= -1 ? codec_delay
: 0) / 1000));
77 return config
->IsValidConfig();
80 bool WebMAudioClient::OnUInt(int id
, int64 val
) {
81 if (id
== kWebMIdChannels
) {
82 if (channels_
!= -1) {
83 MEDIA_LOG(log_cb_
) << "Multiple values for id " << std::hex
<< id
84 << " specified. (" << channels_
<< " and " << val
94 bool WebMAudioClient::OnFloat(int id
, double val
) {
98 case kWebMIdSamplingFrequency
:
99 dst
= &samples_per_second_
;
101 case kWebMIdOutputSamplingFrequency
:
102 dst
= &output_samples_per_second_
;
112 MEDIA_LOG(log_cb_
) << "Multiple values for id " << std::hex
<< id
113 << " specified (" << *dst
<< " and " << val
<< ")";