OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/audio_decoder_config.h" | 5 #include "media/base/audio_decoder_config.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "media/audio/sample_rates.h" | 9 #include "media/audio/sample_rates.h" |
10 #include "media/base/limits.h" | 10 #include "media/base/limits.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 | 13 |
14 AudioDecoderConfig::AudioDecoderConfig() | 14 AudioDecoderConfig::AudioDecoderConfig() |
15 : codec_(kUnknownAudioCodec), | 15 : codec_(kUnknownAudioCodec), |
16 bits_per_channel_(0), | 16 bits_per_channel_(0), |
17 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), | 17 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), |
18 samples_per_second_(0), | 18 samples_per_second_(0), |
19 extra_data_size_(0), | 19 extra_data_size_(0), |
20 is_encrypted_(false) { | 20 is_encrypted_(false), |
21 sample_format_(kUnknownSampleFormat) { | |
21 } | 22 } |
22 | 23 |
23 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, | 24 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, |
24 int bits_per_channel, | 25 int bits_per_channel, |
25 ChannelLayout channel_layout, | 26 ChannelLayout channel_layout, |
26 int samples_per_second, | 27 int samples_per_second, |
27 const uint8* extra_data, | 28 const uint8* extra_data, |
28 size_t extra_data_size, | 29 size_t extra_data_size, |
30 SampleFormat sample_format, | |
29 bool is_encrypted) { | 31 bool is_encrypted) { |
30 Initialize(codec, bits_per_channel, channel_layout, samples_per_second, | 32 Initialize(codec, bits_per_channel, channel_layout, samples_per_second, |
31 extra_data, extra_data_size, is_encrypted, true); | 33 extra_data, extra_data_size, sample_format, is_encrypted, true); |
32 } | 34 } |
33 | 35 |
34 void AudioDecoderConfig::Initialize(AudioCodec codec, | 36 void AudioDecoderConfig::Initialize(AudioCodec codec, |
35 int bits_per_channel, | 37 int bits_per_channel, |
36 ChannelLayout channel_layout, | 38 ChannelLayout channel_layout, |
37 int samples_per_second, | 39 int samples_per_second, |
38 const uint8* extra_data, | 40 const uint8* extra_data, |
39 size_t extra_data_size, | 41 size_t extra_data_size, |
42 SampleFormat sample_format, | |
40 bool is_encrypted, | 43 bool is_encrypted, |
41 bool record_stats) { | 44 bool record_stats) { |
42 CHECK((extra_data_size != 0) == (extra_data != NULL)); | 45 CHECK((extra_data_size != 0) == (extra_data != NULL)); |
43 | 46 |
44 if (record_stats) { | 47 if (record_stats) { |
45 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax + 1); | 48 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax + 1); |
46 // Fake enum histogram to get exact integral buckets. Expect to never see | 49 // Fake enum histogram to get exact integral buckets. Expect to never see |
47 // any values over 32 and even that is huge. | 50 // any values over 32 and even that is huge. |
48 UMA_HISTOGRAM_ENUMERATION("Media.AudioBitsPerChannel", bits_per_channel, | 51 UMA_HISTOGRAM_ENUMERATION("Media.AudioBitsPerChannel", bits_per_channel, |
49 40); | 52 40); |
50 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout, | 53 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout, |
51 CHANNEL_LAYOUT_MAX); | 54 CHANNEL_LAYOUT_MAX); |
52 AudioSampleRate asr = media::AsAudioSampleRate(samples_per_second); | 55 AudioSampleRate asr = media::AsAudioSampleRate(samples_per_second); |
53 if (asr != kUnexpectedAudioSampleRate) { | 56 if (asr != kUnexpectedAudioSampleRate) { |
54 UMA_HISTOGRAM_ENUMERATION("Media.AudioSamplesPerSecond", asr, | 57 UMA_HISTOGRAM_ENUMERATION("Media.AudioSamplesPerSecond", asr, |
55 kUnexpectedAudioSampleRate); | 58 kUnexpectedAudioSampleRate); |
56 } else { | 59 } else { |
57 UMA_HISTOGRAM_COUNTS( | 60 UMA_HISTOGRAM_COUNTS( |
58 "Media.AudioSamplesPerSecondUnexpected", samples_per_second); | 61 "Media.AudioSamplesPerSecondUnexpected", samples_per_second); |
59 } | 62 } |
63 | |
64 // TODO(dalecurtis): Is it worth recording SampleFormat here? All aac and | |
65 // vorbis are going to be kFormatFLTP. Float PCM and AMR will be kFormatFLT. | |
scherkus (not reviewing)
2012/12/06 17:25:32
is there any way to get the pre-conversion-to-floa
scherkus (not reviewing)
2012/12/06 17:25:32
s/kFormat/kSampleFormat/g
DaleCurtis
2012/12/06 22:15:41
The data isn't converted to float, it's decoded in
DaleCurtis
2012/12/11 03:03:44
Also I don't intend to check this message in, I wa
scherkus (not reviewing)
2012/12/11 21:18:47
What about deprecating AudioBitsPerChannel in favo
DaleCurtis
2012/12/12 01:02:57
Done.
| |
60 } | 66 } |
61 | 67 |
62 codec_ = codec; | 68 codec_ = codec; |
63 bits_per_channel_ = bits_per_channel; | 69 bits_per_channel_ = bits_per_channel; |
64 channel_layout_ = channel_layout; | 70 channel_layout_ = channel_layout; |
65 samples_per_second_ = samples_per_second; | 71 samples_per_second_ = samples_per_second; |
66 extra_data_size_ = extra_data_size; | 72 extra_data_size_ = extra_data_size; |
73 sample_format_ = sample_format; | |
67 | 74 |
68 if (extra_data_size_ > 0) { | 75 if (extra_data_size_ > 0) { |
69 extra_data_.reset(new uint8[extra_data_size_]); | 76 extra_data_.reset(new uint8[extra_data_size_]); |
70 memcpy(extra_data_.get(), extra_data, extra_data_size_); | 77 memcpy(extra_data_.get(), extra_data, extra_data_size_); |
71 } else { | 78 } else { |
72 extra_data_.reset(); | 79 extra_data_.reset(); |
73 } | 80 } |
74 | 81 |
75 is_encrypted_ = is_encrypted; | 82 is_encrypted_ = is_encrypted; |
76 } | 83 } |
77 | 84 |
78 AudioDecoderConfig::~AudioDecoderConfig() {} | 85 AudioDecoderConfig::~AudioDecoderConfig() {} |
79 | 86 |
80 bool AudioDecoderConfig::IsValidConfig() const { | 87 bool AudioDecoderConfig::IsValidConfig() const { |
81 return codec_ != kUnknownAudioCodec && | 88 return codec_ != kUnknownAudioCodec && |
82 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && | 89 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && |
83 bits_per_channel_ > 0 && | 90 bits_per_channel_ > 0 && |
84 bits_per_channel_ <= limits::kMaxBitsPerSample && | 91 bits_per_channel_ <= limits::kMaxBitsPerSample && |
85 samples_per_second_ > 0 && | 92 samples_per_second_ > 0 && |
86 samples_per_second_ <= limits::kMaxSampleRate; | 93 samples_per_second_ <= limits::kMaxSampleRate && |
94 sample_format_ != kUnknownSampleFormat; | |
87 } | 95 } |
88 | 96 |
89 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { | 97 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { |
90 return ((codec() == config.codec()) && | 98 return ((codec() == config.codec()) && |
91 (bits_per_channel() == config.bits_per_channel()) && | 99 (bits_per_channel() == config.bits_per_channel()) && |
92 (channel_layout() == config.channel_layout()) && | 100 (channel_layout() == config.channel_layout()) && |
93 (samples_per_second() == config.samples_per_second()) && | 101 (samples_per_second() == config.samples_per_second()) && |
94 (extra_data_size() == config.extra_data_size()) && | 102 (extra_data_size() == config.extra_data_size()) && |
95 (!extra_data() || !memcmp(extra_data(), config.extra_data(), | 103 (!extra_data() || !memcmp(extra_data(), config.extra_data(), |
96 extra_data_size())) && | 104 extra_data_size())) && |
97 (is_encrypted() == config.is_encrypted())); | 105 (is_encrypted() == config.is_encrypted()) && |
106 (sample_format() == config.sample_format())); | |
98 } | 107 } |
99 | 108 |
100 void AudioDecoderConfig::CopyFrom(const AudioDecoderConfig& audio_config) { | 109 void AudioDecoderConfig::CopyFrom(const AudioDecoderConfig& audio_config) { |
101 Initialize(audio_config.codec(), | 110 Initialize(audio_config.codec(), |
102 audio_config.bits_per_channel(), | 111 audio_config.bits_per_channel(), |
103 audio_config.channel_layout(), | 112 audio_config.channel_layout(), |
104 audio_config.samples_per_second(), | 113 audio_config.samples_per_second(), |
105 audio_config.extra_data(), | 114 audio_config.extra_data(), |
106 audio_config.extra_data_size(), | 115 audio_config.extra_data_size(), |
116 audio_config.sample_format(), | |
107 audio_config.is_encrypted(), | 117 audio_config.is_encrypted(), |
108 false); | 118 false); |
109 } | 119 } |
110 | 120 |
111 AudioCodec AudioDecoderConfig::codec() const { | |
112 return codec_; | |
113 } | |
114 | |
115 int AudioDecoderConfig::bits_per_channel() const { | |
116 return bits_per_channel_; | |
117 } | |
118 | |
119 ChannelLayout AudioDecoderConfig::channel_layout() const { | |
120 return channel_layout_; | |
121 } | |
122 | |
123 int AudioDecoderConfig::samples_per_second() const { | |
124 return samples_per_second_; | |
125 } | |
126 | |
127 uint8* AudioDecoderConfig::extra_data() const { | |
128 return extra_data_.get(); | |
129 } | |
130 | |
131 size_t AudioDecoderConfig::extra_data_size() const { | |
132 return extra_data_size_; | |
133 } | |
134 | |
135 bool AudioDecoderConfig::is_encrypted() const { | |
136 return is_encrypted_; | |
137 } | |
138 | |
139 } // namespace media | 121 } // namespace media |
OLD | NEW |