Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: media/base/audio_decoder_config.cc

Issue 23014009: media: Opus support for WebM in Media Source (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing errors causing try bot failure Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/audio_decoder_config.h ('k') | media/base/decoder_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) {
23 } 24 }
24 25
25 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, 26 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec,
26 SampleFormat sample_format, 27 SampleFormat sample_format,
27 ChannelLayout channel_layout, 28 ChannelLayout channel_layout,
28 int samples_per_second, 29 int samples_per_second,
29 const uint8* extra_data, 30 const uint8* extra_data,
30 size_t extra_data_size, 31 size_t extra_data_size,
31 bool is_encrypted) { 32 bool is_encrypted) {
32 Initialize(codec, sample_format, channel_layout, samples_per_second, 33 Initialize(codec, sample_format, channel_layout, samples_per_second,
33 extra_data, extra_data_size, is_encrypted, true); 34 extra_data, extra_data_size, is_encrypted, true,
35 base::TimeDelta(), base::TimeDelta());
34 } 36 }
35 37
36 void AudioDecoderConfig::Initialize(AudioCodec codec, 38 void AudioDecoderConfig::Initialize(AudioCodec codec,
37 SampleFormat sample_format, 39 SampleFormat sample_format,
38 ChannelLayout channel_layout, 40 ChannelLayout channel_layout,
39 int samples_per_second, 41 int samples_per_second,
40 const uint8* extra_data, 42 const uint8* extra_data,
41 size_t extra_data_size, 43 size_t extra_data_size,
42 bool is_encrypted, 44 bool is_encrypted,
43 bool record_stats) { 45 bool record_stats,
46 base::TimeDelta seek_preroll,
47 base::TimeDelta codec_delay) {
44 CHECK((extra_data_size != 0) == (extra_data != NULL)); 48 CHECK((extra_data_size != 0) == (extra_data != NULL));
45 49
46 if (record_stats) { 50 if (record_stats) {
47 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax); 51 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax);
48 UMA_HISTOGRAM_ENUMERATION("Media.AudioSampleFormat", sample_format, 52 UMA_HISTOGRAM_ENUMERATION("Media.AudioSampleFormat", sample_format,
49 kSampleFormatMax); 53 kSampleFormatMax);
50 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout, 54 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout,
51 CHANNEL_LAYOUT_MAX); 55 CHANNEL_LAYOUT_MAX);
52 AudioSampleRate asr = media::AsAudioSampleRate(samples_per_second); 56 AudioSampleRate asr = media::AsAudioSampleRate(samples_per_second);
53 if (asr != kUnexpectedAudioSampleRate) { 57 if (asr != kUnexpectedAudioSampleRate) {
54 UMA_HISTOGRAM_ENUMERATION("Media.AudioSamplesPerSecond", asr, 58 UMA_HISTOGRAM_ENUMERATION("Media.AudioSamplesPerSecond", asr,
55 kUnexpectedAudioSampleRate); 59 kUnexpectedAudioSampleRate);
56 } else { 60 } else {
57 UMA_HISTOGRAM_COUNTS( 61 UMA_HISTOGRAM_COUNTS(
58 "Media.AudioSamplesPerSecondUnexpected", samples_per_second); 62 "Media.AudioSamplesPerSecondUnexpected", samples_per_second);
59 } 63 }
60 } 64 }
61 65
62 codec_ = codec; 66 codec_ = codec;
63 channel_layout_ = channel_layout; 67 channel_layout_ = channel_layout;
64 samples_per_second_ = samples_per_second; 68 samples_per_second_ = samples_per_second;
65 sample_format_ = sample_format; 69 sample_format_ = sample_format;
66 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format); 70 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format);
67 extra_data_.assign(extra_data, extra_data + extra_data_size); 71 extra_data_.assign(extra_data, extra_data + extra_data_size);
68 is_encrypted_ = is_encrypted; 72 is_encrypted_ = is_encrypted;
73 seek_preroll_ = seek_preroll;
74 codec_delay_ = codec_delay;
69 75
70 int channels = ChannelLayoutToChannelCount(channel_layout_); 76 int channels = ChannelLayoutToChannelCount(channel_layout_);
71 bytes_per_frame_ = channels * bytes_per_channel_; 77 bytes_per_frame_ = channels * bytes_per_channel_;
72 } 78 }
73 79
74 AudioDecoderConfig::~AudioDecoderConfig() {} 80 AudioDecoderConfig::~AudioDecoderConfig() {}
75 81
76 bool AudioDecoderConfig::IsValidConfig() const { 82 bool AudioDecoderConfig::IsValidConfig() const {
77 return codec_ != kUnknownAudioCodec && 83 return codec_ != kUnknownAudioCodec &&
78 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && 84 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED &&
79 bytes_per_channel_ > 0 && 85 bytes_per_channel_ > 0 &&
80 bytes_per_channel_ <= limits::kMaxBytesPerSample && 86 bytes_per_channel_ <= limits::kMaxBytesPerSample &&
81 samples_per_second_ > 0 && 87 samples_per_second_ > 0 &&
82 samples_per_second_ <= limits::kMaxSampleRate && 88 samples_per_second_ <= limits::kMaxSampleRate &&
83 sample_format_ != kUnknownSampleFormat; 89 sample_format_ != kUnknownSampleFormat &&
90 seek_preroll_ >= base::TimeDelta() &&
91 codec_delay_ >= base::TimeDelta();
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_preroll() == config.seek_preroll()) &&
105 (codec_delay() == config.codec_delay()));
96 } 106 }
97 107
98 } // namespace media 108 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_decoder_config.h ('k') | media/base/decoder_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698