| 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 } | 21 } |
| 21 | 22 |
| 22 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, | 23 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, |
| 23 int bits_per_channel, | 24 int bits_per_channel, |
| 24 ChannelLayout channel_layout, | 25 ChannelLayout channel_layout, |
| 25 int samples_per_second, | 26 int samples_per_second, |
| 26 const uint8* extra_data, | 27 const uint8* extra_data, |
| 27 size_t extra_data_size) { | 28 size_t extra_data_size, |
| 29 bool is_encrypted) { |
| 28 Initialize(codec, bits_per_channel, channel_layout, samples_per_second, | 30 Initialize(codec, bits_per_channel, channel_layout, samples_per_second, |
| 29 extra_data, extra_data_size, true); | 31 extra_data, extra_data_size, is_encrypted, true); |
| 30 } | 32 } |
| 31 | 33 |
| 32 void AudioDecoderConfig::Initialize(AudioCodec codec, | 34 void AudioDecoderConfig::Initialize(AudioCodec codec, |
| 33 int bits_per_channel, | 35 int bits_per_channel, |
| 34 ChannelLayout channel_layout, | 36 ChannelLayout channel_layout, |
| 35 int samples_per_second, | 37 int samples_per_second, |
| 36 const uint8* extra_data, | 38 const uint8* extra_data, |
| 37 size_t extra_data_size, | 39 size_t extra_data_size, |
| 40 bool is_encrypted, |
| 38 bool record_stats) { | 41 bool record_stats) { |
| 39 CHECK((extra_data_size != 0) == (extra_data != NULL)); | 42 CHECK((extra_data_size != 0) == (extra_data != NULL)); |
| 40 | 43 |
| 41 if (record_stats) { | 44 if (record_stats) { |
| 42 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax + 1); | 45 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax + 1); |
| 43 // Fake enum histogram to get exact integral buckets. Expect to never see | 46 // Fake enum histogram to get exact integral buckets. Expect to never see |
| 44 // any values over 32 and even that is huge. | 47 // any values over 32 and even that is huge. |
| 45 UMA_HISTOGRAM_ENUMERATION("Media.AudioBitsPerChannel", bits_per_channel, | 48 UMA_HISTOGRAM_ENUMERATION("Media.AudioBitsPerChannel", bits_per_channel, |
| 46 40); | 49 40); |
| 47 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout, | 50 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 61 channel_layout_ = channel_layout; | 64 channel_layout_ = channel_layout; |
| 62 samples_per_second_ = samples_per_second; | 65 samples_per_second_ = samples_per_second; |
| 63 extra_data_size_ = extra_data_size; | 66 extra_data_size_ = extra_data_size; |
| 64 | 67 |
| 65 if (extra_data_size_ > 0) { | 68 if (extra_data_size_ > 0) { |
| 66 extra_data_.reset(new uint8[extra_data_size_]); | 69 extra_data_.reset(new uint8[extra_data_size_]); |
| 67 memcpy(extra_data_.get(), extra_data, extra_data_size_); | 70 memcpy(extra_data_.get(), extra_data, extra_data_size_); |
| 68 } else { | 71 } else { |
| 69 extra_data_.reset(); | 72 extra_data_.reset(); |
| 70 } | 73 } |
| 74 |
| 75 is_encrypted_ = is_encrypted; |
| 71 } | 76 } |
| 72 | 77 |
| 73 AudioDecoderConfig::~AudioDecoderConfig() {} | 78 AudioDecoderConfig::~AudioDecoderConfig() {} |
| 74 | 79 |
| 75 bool AudioDecoderConfig::IsValidConfig() const { | 80 bool AudioDecoderConfig::IsValidConfig() const { |
| 76 return codec_ != kUnknownAudioCodec && | 81 return codec_ != kUnknownAudioCodec && |
| 77 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && | 82 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && |
| 78 bits_per_channel_ > 0 && | 83 bits_per_channel_ > 0 && |
| 79 bits_per_channel_ <= limits::kMaxBitsPerSample && | 84 bits_per_channel_ <= limits::kMaxBitsPerSample && |
| 80 samples_per_second_ > 0 && | 85 samples_per_second_ > 0 && |
| 81 samples_per_second_ <= limits::kMaxSampleRate; | 86 samples_per_second_ <= limits::kMaxSampleRate; |
| 82 } | 87 } |
| 83 | 88 |
| 84 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { | 89 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { |
| 85 return ((codec() == config.codec()) && | 90 return ((codec() == config.codec()) && |
| 86 (bits_per_channel() == config.bits_per_channel()) && | 91 (bits_per_channel() == config.bits_per_channel()) && |
| 87 (channel_layout() == config.channel_layout()) && | 92 (channel_layout() == config.channel_layout()) && |
| 88 (samples_per_second() == config.samples_per_second()) && | 93 (samples_per_second() == config.samples_per_second()) && |
| 89 (extra_data_size() == config.extra_data_size()) && | 94 (extra_data_size() == config.extra_data_size()) && |
| 90 (!extra_data() || !memcmp(extra_data(), config.extra_data(), | 95 (!extra_data() || !memcmp(extra_data(), config.extra_data(), |
| 91 extra_data_size()))); | 96 extra_data_size())) && |
| 97 (is_encrypted() == config.is_encrypted())); |
| 92 } | 98 } |
| 93 | 99 |
| 94 void AudioDecoderConfig::CopyFrom(const AudioDecoderConfig& audio_config) { | 100 void AudioDecoderConfig::CopyFrom(const AudioDecoderConfig& audio_config) { |
| 95 Initialize(audio_config.codec(), | 101 Initialize(audio_config.codec(), |
| 96 audio_config.bits_per_channel(), | 102 audio_config.bits_per_channel(), |
| 97 audio_config.channel_layout(), | 103 audio_config.channel_layout(), |
| 98 audio_config.samples_per_second(), | 104 audio_config.samples_per_second(), |
| 99 audio_config.extra_data(), | 105 audio_config.extra_data(), |
| 100 audio_config.extra_data_size(), | 106 audio_config.extra_data_size(), |
| 107 audio_config.is_encrypted(), |
| 101 false); | 108 false); |
| 102 } | 109 } |
| 103 | 110 |
| 104 AudioCodec AudioDecoderConfig::codec() const { | 111 AudioCodec AudioDecoderConfig::codec() const { |
| 105 return codec_; | 112 return codec_; |
| 106 } | 113 } |
| 107 | 114 |
| 108 int AudioDecoderConfig::bits_per_channel() const { | 115 int AudioDecoderConfig::bits_per_channel() const { |
| 109 return bits_per_channel_; | 116 return bits_per_channel_; |
| 110 } | 117 } |
| 111 | 118 |
| 112 ChannelLayout AudioDecoderConfig::channel_layout() const { | 119 ChannelLayout AudioDecoderConfig::channel_layout() const { |
| 113 return channel_layout_; | 120 return channel_layout_; |
| 114 } | 121 } |
| 115 | 122 |
| 116 int AudioDecoderConfig::samples_per_second() const { | 123 int AudioDecoderConfig::samples_per_second() const { |
| 117 return samples_per_second_; | 124 return samples_per_second_; |
| 118 } | 125 } |
| 119 | 126 |
| 120 uint8* AudioDecoderConfig::extra_data() const { | 127 uint8* AudioDecoderConfig::extra_data() const { |
| 121 return extra_data_.get(); | 128 return extra_data_.get(); |
| 122 } | 129 } |
| 123 | 130 |
| 124 size_t AudioDecoderConfig::extra_data_size() const { | 131 size_t AudioDecoderConfig::extra_data_size() const { |
| 125 return extra_data_size_; | 132 return extra_data_size_; |
| 126 } | 133 } |
| 127 | 134 |
| 135 bool AudioDecoderConfig::is_encrypted() const { |
| 136 return is_encrypted_; |
| 137 } |
| 138 |
| 128 } // namespace media | 139 } // namespace media |
| OLD | NEW |