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 "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "media/audio/sample_rates.h" | 10 #include "media/audio/sample_rates.h" |
11 #include "media/base/limits.h" | 11 #include "media/base/limits.h" |
12 #include "media/base/sample_format.h" | 12 #include "media/base/sample_format.h" |
13 | 13 |
14 namespace media { | 14 namespace media { |
15 | 15 |
16 AudioDecoderConfig::AudioDecoderConfig() | 16 AudioDecoderConfig::AudioDecoderConfig() |
17 : codec_(kUnknownAudioCodec), | 17 : codec_(kUnknownAudioCodec), |
18 sample_format_(kUnknownSampleFormat), | 18 sample_format_(kUnknownSampleFormat), |
19 bytes_per_channel_(0), | 19 bytes_per_channel_(0), |
20 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), | 20 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), |
21 samples_per_second_(0), | 21 samples_per_second_(0), |
22 bytes_per_frame_(0), | 22 bytes_per_frame_(0), |
23 is_encrypted_(false) { | 23 is_encrypted_(false), |
| 24 codec_delay_(0) { |
24 } | 25 } |
25 | 26 |
26 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, | 27 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, |
27 SampleFormat sample_format, | 28 SampleFormat sample_format, |
28 ChannelLayout channel_layout, | 29 ChannelLayout channel_layout, |
29 int samples_per_second, | 30 int samples_per_second, |
30 const uint8* extra_data, | 31 const uint8* extra_data, |
31 size_t extra_data_size, | 32 size_t extra_data_size, |
32 bool is_encrypted) { | 33 bool is_encrypted) { |
33 Initialize(codec, sample_format, channel_layout, samples_per_second, | 34 Initialize(codec, sample_format, channel_layout, samples_per_second, |
34 extra_data, extra_data_size, is_encrypted, true, | 35 extra_data, extra_data_size, is_encrypted, true, |
35 base::TimeDelta(), base::TimeDelta()); | 36 base::TimeDelta(), 0); |
36 } | 37 } |
37 | 38 |
38 void AudioDecoderConfig::Initialize(AudioCodec codec, | 39 void AudioDecoderConfig::Initialize(AudioCodec codec, |
39 SampleFormat sample_format, | 40 SampleFormat sample_format, |
40 ChannelLayout channel_layout, | 41 ChannelLayout channel_layout, |
41 int samples_per_second, | 42 int samples_per_second, |
42 const uint8* extra_data, | 43 const uint8* extra_data, |
43 size_t extra_data_size, | 44 size_t extra_data_size, |
44 bool is_encrypted, | 45 bool is_encrypted, |
45 bool record_stats, | 46 bool record_stats, |
46 base::TimeDelta seek_preroll, | 47 base::TimeDelta seek_preroll, |
47 base::TimeDelta codec_delay) { | 48 int codec_delay) { |
48 CHECK((extra_data_size != 0) == (extra_data != NULL)); | 49 CHECK((extra_data_size != 0) == (extra_data != NULL)); |
49 | 50 |
50 if (record_stats) { | 51 if (record_stats) { |
51 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax + 1); | 52 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax + 1); |
52 UMA_HISTOGRAM_ENUMERATION("Media.AudioSampleFormat", sample_format, | 53 UMA_HISTOGRAM_ENUMERATION("Media.AudioSampleFormat", sample_format, |
53 kSampleFormatMax + 1); | 54 kSampleFormatMax + 1); |
54 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout, | 55 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout, |
55 CHANNEL_LAYOUT_MAX + 1); | 56 CHANNEL_LAYOUT_MAX + 1); |
56 AudioSampleRate asr; | 57 AudioSampleRate asr; |
57 if (ToAudioSampleRate(samples_per_second, &asr)) { | 58 if (ToAudioSampleRate(samples_per_second, &asr)) { |
(...skipping 23 matching lines...) Expand all Loading... |
81 | 82 |
82 bool AudioDecoderConfig::IsValidConfig() const { | 83 bool AudioDecoderConfig::IsValidConfig() const { |
83 return codec_ != kUnknownAudioCodec && | 84 return codec_ != kUnknownAudioCodec && |
84 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && | 85 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && |
85 bytes_per_channel_ > 0 && | 86 bytes_per_channel_ > 0 && |
86 bytes_per_channel_ <= limits::kMaxBytesPerSample && | 87 bytes_per_channel_ <= limits::kMaxBytesPerSample && |
87 samples_per_second_ > 0 && | 88 samples_per_second_ > 0 && |
88 samples_per_second_ <= limits::kMaxSampleRate && | 89 samples_per_second_ <= limits::kMaxSampleRate && |
89 sample_format_ != kUnknownSampleFormat && | 90 sample_format_ != kUnknownSampleFormat && |
90 seek_preroll_ >= base::TimeDelta() && | 91 seek_preroll_ >= base::TimeDelta() && |
91 codec_delay_ >= base::TimeDelta(); | 92 codec_delay_ >= 0; |
92 } | 93 } |
93 | 94 |
94 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { | 95 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { |
95 return ((codec() == config.codec()) && | 96 return ((codec() == config.codec()) && |
96 (bytes_per_channel() == config.bytes_per_channel()) && | 97 (bytes_per_channel() == config.bytes_per_channel()) && |
97 (channel_layout() == config.channel_layout()) && | 98 (channel_layout() == config.channel_layout()) && |
98 (samples_per_second() == config.samples_per_second()) && | 99 (samples_per_second() == config.samples_per_second()) && |
99 (extra_data_size() == config.extra_data_size()) && | 100 (extra_data_size() == config.extra_data_size()) && |
100 (!extra_data() || !memcmp(extra_data(), config.extra_data(), | 101 (!extra_data() || !memcmp(extra_data(), config.extra_data(), |
101 extra_data_size())) && | 102 extra_data_size())) && |
102 (is_encrypted() == config.is_encrypted()) && | 103 (is_encrypted() == config.is_encrypted()) && |
103 (sample_format() == config.sample_format()) && | 104 (sample_format() == config.sample_format()) && |
104 (seek_preroll() == config.seek_preroll()) && | 105 (seek_preroll() == config.seek_preroll()) && |
105 (codec_delay() == config.codec_delay())); | 106 (codec_delay() == config.codec_delay())); |
106 } | 107 } |
107 | 108 |
108 std::string AudioDecoderConfig::AsHumanReadableString() const { | 109 std::string AudioDecoderConfig::AsHumanReadableString() const { |
109 std::ostringstream s; | 110 std::ostringstream s; |
110 s << "codec: " << codec() | 111 s << "codec: " << codec() |
111 << " bytes_per_channel: " << bytes_per_channel() | 112 << " bytes_per_channel: " << bytes_per_channel() |
112 << " channel_layout: " << channel_layout() | 113 << " channel_layout: " << channel_layout() |
113 << " samples_per_second: " << samples_per_second() | 114 << " samples_per_second: " << samples_per_second() |
114 << " sample_format: " << sample_format() | 115 << " sample_format: " << sample_format() |
115 << " bytes_per_frame: " << bytes_per_frame() | 116 << " bytes_per_frame: " << bytes_per_frame() |
116 << " seek_preroll: " << seek_preroll().InMilliseconds() << "ms" | 117 << " seek_preroll: " << seek_preroll().InMilliseconds() << "ms" |
117 << " codec_delay: " << codec_delay().InMilliseconds() << "ms" | 118 << " codec_delay: " << codec_delay() |
118 << " has extra data? " << (extra_data() ? "true" : "false") | 119 << " has extra data? " << (extra_data() ? "true" : "false") |
119 << " encrypted? " << (is_encrypted() ? "true" : "false"); | 120 << " encrypted? " << (is_encrypted() ? "true" : "false"); |
120 return s.str(); | 121 return s.str(); |
121 } | 122 } |
122 | 123 |
123 } // namespace media | 124 } // namespace media |
OLD | NEW |