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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 return 0; | 32 return 0; |
33 } | 33 } |
34 | 34 |
35 AudioDecoderConfig::AudioDecoderConfig() | 35 AudioDecoderConfig::AudioDecoderConfig() |
36 : codec_(kUnknownAudioCodec), | 36 : codec_(kUnknownAudioCodec), |
37 sample_format_(kUnknownSampleFormat), | 37 sample_format_(kUnknownSampleFormat), |
38 bits_per_channel_(0), | 38 bits_per_channel_(0), |
39 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), | 39 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), |
40 samples_per_second_(0), | 40 samples_per_second_(0), |
41 bytes_per_frame_(0), | 41 bytes_per_frame_(0), |
42 extra_data_size_(0), | |
43 is_encrypted_(false) { | 42 is_encrypted_(false) { |
44 } | 43 } |
45 | 44 |
46 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, | 45 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, |
47 SampleFormat sample_format, | 46 SampleFormat sample_format, |
48 ChannelLayout channel_layout, | 47 ChannelLayout channel_layout, |
49 int samples_per_second, | 48 int samples_per_second, |
50 const uint8* extra_data, | 49 const uint8* extra_data, |
51 size_t extra_data_size, | 50 size_t extra_data_size, |
52 bool is_encrypted) { | 51 bool is_encrypted) { |
(...skipping 23 matching lines...) Expand all Loading... |
76 kUnexpectedAudioSampleRate); | 75 kUnexpectedAudioSampleRate); |
77 } else { | 76 } else { |
78 UMA_HISTOGRAM_COUNTS( | 77 UMA_HISTOGRAM_COUNTS( |
79 "Media.AudioSamplesPerSecondUnexpected", samples_per_second); | 78 "Media.AudioSamplesPerSecondUnexpected", samples_per_second); |
80 } | 79 } |
81 } | 80 } |
82 | 81 |
83 codec_ = codec; | 82 codec_ = codec; |
84 channel_layout_ = channel_layout; | 83 channel_layout_ = channel_layout; |
85 samples_per_second_ = samples_per_second; | 84 samples_per_second_ = samples_per_second; |
86 extra_data_size_ = extra_data_size; | |
87 sample_format_ = sample_format; | 85 sample_format_ = sample_format; |
88 bits_per_channel_ = SampleFormatToBitsPerChannel(sample_format); | 86 bits_per_channel_ = SampleFormatToBitsPerChannel(sample_format); |
89 | 87 extra_data_.assign(extra_data, extra_data + extra_data_size); |
90 if (extra_data_size_ > 0) { | |
91 extra_data_.reset(new uint8[extra_data_size_]); | |
92 memcpy(extra_data_.get(), extra_data, extra_data_size_); | |
93 } else { | |
94 extra_data_.reset(); | |
95 } | |
96 | |
97 is_encrypted_ = is_encrypted; | 88 is_encrypted_ = is_encrypted; |
98 | 89 |
99 int channels = ChannelLayoutToChannelCount(channel_layout_); | 90 int channels = ChannelLayoutToChannelCount(channel_layout_); |
100 bytes_per_frame_ = channels * bits_per_channel_ / 8; | 91 bytes_per_frame_ = channels * bits_per_channel_ / 8; |
101 } | 92 } |
102 | 93 |
103 AudioDecoderConfig::~AudioDecoderConfig() {} | 94 AudioDecoderConfig::~AudioDecoderConfig() {} |
104 | 95 |
105 bool AudioDecoderConfig::IsValidConfig() const { | 96 bool AudioDecoderConfig::IsValidConfig() const { |
106 return codec_ != kUnknownAudioCodec && | 97 return codec_ != kUnknownAudioCodec && |
(...skipping 10 matching lines...) Expand all Loading... |
117 (bits_per_channel() == config.bits_per_channel()) && | 108 (bits_per_channel() == config.bits_per_channel()) && |
118 (channel_layout() == config.channel_layout()) && | 109 (channel_layout() == config.channel_layout()) && |
119 (samples_per_second() == config.samples_per_second()) && | 110 (samples_per_second() == config.samples_per_second()) && |
120 (extra_data_size() == config.extra_data_size()) && | 111 (extra_data_size() == config.extra_data_size()) && |
121 (!extra_data() || !memcmp(extra_data(), config.extra_data(), | 112 (!extra_data() || !memcmp(extra_data(), config.extra_data(), |
122 extra_data_size())) && | 113 extra_data_size())) && |
123 (is_encrypted() == config.is_encrypted()) && | 114 (is_encrypted() == config.is_encrypted()) && |
124 (sample_format() == config.sample_format())); | 115 (sample_format() == config.sample_format())); |
125 } | 116 } |
126 | 117 |
127 void AudioDecoderConfig::CopyFrom(const AudioDecoderConfig& audio_config) { | |
128 Initialize(audio_config.codec(), | |
129 audio_config.sample_format(), | |
130 audio_config.channel_layout(), | |
131 audio_config.samples_per_second(), | |
132 audio_config.extra_data(), | |
133 audio_config.extra_data_size(), | |
134 audio_config.is_encrypted(), | |
135 false); | |
136 } | |
137 | |
138 } // namespace media | 118 } // namespace media |
OLD | NEW |