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 "media/audio/sample_rates.h" | 10 #include "media/audio/sample_rates.h" |
10 #include "media/base/limits.h" | 11 #include "media/base/limits.h" |
11 #include "media/base/sample_format.h" | 12 #include "media/base/sample_format.h" |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 | 15 |
15 AudioDecoderConfig::AudioDecoderConfig() | 16 AudioDecoderConfig::AudioDecoderConfig() |
16 : codec_(kUnknownAudioCodec), | 17 : codec_(kUnknownAudioCodec), |
17 sample_format_(kUnknownSampleFormat), | 18 sample_format_(kUnknownSampleFormat), |
18 bytes_per_channel_(0), | 19 bytes_per_channel_(0), |
19 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), | 20 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), |
20 samples_per_second_(0), | 21 samples_per_second_(0), |
21 bytes_per_frame_(0), | 22 bytes_per_frame_(0), |
22 is_encrypted_(false) { | 23 is_encrypted_(false), |
24 seek_pre_roll_(base::TimeDelta()), | |
acolwell GONE FROM CHROMIUM
2013/09/03 20:14:01
nit: not needed here and the line below.
vignesh
2013/09/03 22:43:03
Done.
| |
25 codec_delay_(base::TimeDelta()) { | |
23 } | 26 } |
24 | 27 |
25 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, | 28 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, |
26 SampleFormat sample_format, | 29 SampleFormat sample_format, |
27 ChannelLayout channel_layout, | 30 ChannelLayout channel_layout, |
28 int samples_per_second, | 31 int samples_per_second, |
29 const uint8* extra_data, | 32 const uint8* extra_data, |
30 size_t extra_data_size, | 33 size_t extra_data_size, |
31 bool is_encrypted) { | 34 bool is_encrypted) { |
32 Initialize(codec, sample_format, channel_layout, samples_per_second, | 35 Initialize(codec, sample_format, channel_layout, samples_per_second, |
33 extra_data, extra_data_size, is_encrypted, true); | 36 extra_data, extra_data_size, is_encrypted, true, |
37 base::TimeDelta(), base::TimeDelta()); | |
34 } | 38 } |
35 | 39 |
36 void AudioDecoderConfig::Initialize(AudioCodec codec, | 40 void AudioDecoderConfig::Initialize(AudioCodec codec, |
37 SampleFormat sample_format, | 41 SampleFormat sample_format, |
38 ChannelLayout channel_layout, | 42 ChannelLayout channel_layout, |
39 int samples_per_second, | 43 int samples_per_second, |
40 const uint8* extra_data, | 44 const uint8* extra_data, |
41 size_t extra_data_size, | 45 size_t extra_data_size, |
42 bool is_encrypted, | 46 bool is_encrypted, |
43 bool record_stats) { | 47 bool record_stats, |
48 base::TimeDelta seek_pre_roll, | |
49 base::TimeDelta codec_delay) { | |
44 CHECK((extra_data_size != 0) == (extra_data != NULL)); | 50 CHECK((extra_data_size != 0) == (extra_data != NULL)); |
45 | 51 |
46 if (record_stats) { | 52 if (record_stats) { |
47 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax); | 53 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax); |
48 UMA_HISTOGRAM_ENUMERATION("Media.AudioSampleFormat", sample_format, | 54 UMA_HISTOGRAM_ENUMERATION("Media.AudioSampleFormat", sample_format, |
49 kSampleFormatMax); | 55 kSampleFormatMax); |
50 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout, | 56 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout, |
51 CHANNEL_LAYOUT_MAX); | 57 CHANNEL_LAYOUT_MAX); |
52 AudioSampleRate asr = media::AsAudioSampleRate(samples_per_second); | 58 AudioSampleRate asr = media::AsAudioSampleRate(samples_per_second); |
53 if (asr != kUnexpectedAudioSampleRate) { | 59 if (asr != kUnexpectedAudioSampleRate) { |
54 UMA_HISTOGRAM_ENUMERATION("Media.AudioSamplesPerSecond", asr, | 60 UMA_HISTOGRAM_ENUMERATION("Media.AudioSamplesPerSecond", asr, |
55 kUnexpectedAudioSampleRate); | 61 kUnexpectedAudioSampleRate); |
56 } else { | 62 } else { |
57 UMA_HISTOGRAM_COUNTS( | 63 UMA_HISTOGRAM_COUNTS( |
58 "Media.AudioSamplesPerSecondUnexpected", samples_per_second); | 64 "Media.AudioSamplesPerSecondUnexpected", samples_per_second); |
59 } | 65 } |
60 } | 66 } |
61 | 67 |
62 codec_ = codec; | 68 codec_ = codec; |
63 channel_layout_ = channel_layout; | 69 channel_layout_ = channel_layout; |
64 samples_per_second_ = samples_per_second; | 70 samples_per_second_ = samples_per_second; |
65 sample_format_ = sample_format; | 71 sample_format_ = sample_format; |
66 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format); | 72 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format); |
67 extra_data_.assign(extra_data, extra_data + extra_data_size); | 73 extra_data_.assign(extra_data, extra_data + extra_data_size); |
68 is_encrypted_ = is_encrypted; | 74 is_encrypted_ = is_encrypted; |
75 seek_pre_roll_ = seek_pre_roll; | |
76 codec_delay_ = codec_delay; | |
69 | 77 |
70 int channels = ChannelLayoutToChannelCount(channel_layout_); | 78 int channels = ChannelLayoutToChannelCount(channel_layout_); |
71 bytes_per_frame_ = channels * bytes_per_channel_; | 79 bytes_per_frame_ = channels * bytes_per_channel_; |
72 } | 80 } |
73 | 81 |
74 AudioDecoderConfig::~AudioDecoderConfig() {} | 82 AudioDecoderConfig::~AudioDecoderConfig() {} |
75 | 83 |
76 bool AudioDecoderConfig::IsValidConfig() const { | 84 bool AudioDecoderConfig::IsValidConfig() const { |
77 return codec_ != kUnknownAudioCodec && | 85 return codec_ != kUnknownAudioCodec && |
78 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && | 86 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && |
79 bytes_per_channel_ > 0 && | 87 bytes_per_channel_ > 0 && |
80 bytes_per_channel_ <= limits::kMaxBytesPerSample && | 88 bytes_per_channel_ <= limits::kMaxBytesPerSample && |
81 samples_per_second_ > 0 && | 89 samples_per_second_ > 0 && |
82 samples_per_second_ <= limits::kMaxSampleRate && | 90 samples_per_second_ <= limits::kMaxSampleRate && |
83 sample_format_ != kUnknownSampleFormat; | 91 sample_format_ != kUnknownSampleFormat; |
acolwell GONE FROM CHROMIUM
2013/09/03 20:14:01
Checks should be added here to make sure seek_prer
vignesh
2013/09/03 22:43:03
Done.
| |
84 } | 92 } |
85 | 93 |
86 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { | 94 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { |
87 return ((codec() == config.codec()) && | 95 return ((codec() == config.codec()) && |
88 (bytes_per_channel() == config.bytes_per_channel()) && | 96 (bytes_per_channel() == config.bytes_per_channel()) && |
89 (channel_layout() == config.channel_layout()) && | 97 (channel_layout() == config.channel_layout()) && |
90 (samples_per_second() == config.samples_per_second()) && | 98 (samples_per_second() == config.samples_per_second()) && |
91 (extra_data_size() == config.extra_data_size()) && | 99 (extra_data_size() == config.extra_data_size()) && |
92 (!extra_data() || !memcmp(extra_data(), config.extra_data(), | 100 (!extra_data() || !memcmp(extra_data(), config.extra_data(), |
93 extra_data_size())) && | 101 extra_data_size())) && |
94 (is_encrypted() == config.is_encrypted()) && | 102 (is_encrypted() == config.is_encrypted()) && |
95 (sample_format() == config.sample_format())); | 103 (sample_format() == config.sample_format()) && |
104 (seek_pre_roll() == config.seek_pre_roll()) && | |
105 (codec_delay() == config.codec_delay())); | |
96 } | 106 } |
97 | 107 |
98 } // namespace media | 108 } // namespace media |
OLD | NEW |