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

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

Issue 1490613005: media config: expand is_encrypted to a struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missed a couple comments Created 4 years, 9 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
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 "media/base/limits.h" 8 #include "media/base/limits.h"
9 9
10 namespace media { 10 namespace media {
11 11
12 AudioDecoderConfig::AudioDecoderConfig() 12 AudioDecoderConfig::AudioDecoderConfig()
13 : codec_(kUnknownAudioCodec), 13 : codec_(kUnknownAudioCodec),
14 sample_format_(kUnknownSampleFormat), 14 sample_format_(kUnknownSampleFormat),
15 bytes_per_channel_(0), 15 bytes_per_channel_(0),
16 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), 16 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED),
17 samples_per_second_(0), 17 samples_per_second_(0),
18 bytes_per_frame_(0), 18 bytes_per_frame_(0),
19 is_encrypted_(false), 19 codec_delay_(0) {}
20 codec_delay_(0) {
21 }
22 20
23 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, 21 AudioDecoderConfig::AudioDecoderConfig(
24 SampleFormat sample_format, 22 AudioCodec codec,
25 ChannelLayout channel_layout, 23 SampleFormat sample_format,
26 int samples_per_second, 24 ChannelLayout channel_layout,
27 const std::vector<uint8_t>& extra_data, 25 int samples_per_second,
28 bool is_encrypted) { 26 const std::vector<uint8_t>& extra_data,
27 const EncryptionScheme& encryption_scheme) {
29 Initialize(codec, sample_format, channel_layout, samples_per_second, 28 Initialize(codec, sample_format, channel_layout, samples_per_second,
30 extra_data, is_encrypted, base::TimeDelta(), 0); 29 extra_data, encryption_scheme, base::TimeDelta(), 0);
31 } 30 }
32 31
33 AudioDecoderConfig::AudioDecoderConfig(const AudioDecoderConfig& other) = 32 AudioDecoderConfig::AudioDecoderConfig(const AudioDecoderConfig& other) =
34 default; 33 default;
35 34
36 void AudioDecoderConfig::Initialize(AudioCodec codec, 35 void AudioDecoderConfig::Initialize(AudioCodec codec,
37 SampleFormat sample_format, 36 SampleFormat sample_format,
38 ChannelLayout channel_layout, 37 ChannelLayout channel_layout,
39 int samples_per_second, 38 int samples_per_second,
40 const std::vector<uint8_t>& extra_data, 39 const std::vector<uint8_t>& extra_data,
41 bool is_encrypted, 40 const EncryptionScheme& encryption_scheme,
42 base::TimeDelta seek_preroll, 41 base::TimeDelta seek_preroll,
43 int codec_delay) { 42 int codec_delay) {
44 codec_ = codec; 43 codec_ = codec;
45 channel_layout_ = channel_layout; 44 channel_layout_ = channel_layout;
46 samples_per_second_ = samples_per_second; 45 samples_per_second_ = samples_per_second;
47 sample_format_ = sample_format; 46 sample_format_ = sample_format;
48 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format); 47 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format);
49 extra_data_ = extra_data; 48 extra_data_ = extra_data;
50 is_encrypted_ = is_encrypted; 49 encryption_scheme_ = encryption_scheme;
51 seek_preroll_ = seek_preroll; 50 seek_preroll_ = seek_preroll;
52 codec_delay_ = codec_delay; 51 codec_delay_ = codec_delay;
53 52
54 int channels = ChannelLayoutToChannelCount(channel_layout_); 53 int channels = ChannelLayoutToChannelCount(channel_layout_);
55 bytes_per_frame_ = channels * bytes_per_channel_; 54 bytes_per_frame_ = channels * bytes_per_channel_;
56 } 55 }
57 56
58 AudioDecoderConfig::~AudioDecoderConfig() {} 57 AudioDecoderConfig::~AudioDecoderConfig() {}
59 58
60 bool AudioDecoderConfig::IsValidConfig() const { 59 bool AudioDecoderConfig::IsValidConfig() const {
61 return codec_ != kUnknownAudioCodec && 60 return codec_ != kUnknownAudioCodec &&
62 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && 61 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED &&
63 bytes_per_channel_ > 0 && 62 bytes_per_channel_ > 0 &&
64 bytes_per_channel_ <= limits::kMaxBytesPerSample && 63 bytes_per_channel_ <= limits::kMaxBytesPerSample &&
65 samples_per_second_ > 0 && 64 samples_per_second_ > 0 &&
66 samples_per_second_ <= limits::kMaxSampleRate && 65 samples_per_second_ <= limits::kMaxSampleRate &&
67 sample_format_ != kUnknownSampleFormat && 66 sample_format_ != kUnknownSampleFormat &&
68 seek_preroll_ >= base::TimeDelta() && 67 seek_preroll_ >= base::TimeDelta() &&
69 codec_delay_ >= 0; 68 codec_delay_ >= 0;
70 } 69 }
71 70
72 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { 71 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const {
73 return ((codec() == config.codec()) && 72 return ((codec() == config.codec()) &&
74 (bytes_per_channel() == config.bytes_per_channel()) && 73 (bytes_per_channel() == config.bytes_per_channel()) &&
75 (channel_layout() == config.channel_layout()) && 74 (channel_layout() == config.channel_layout()) &&
76 (samples_per_second() == config.samples_per_second()) && 75 (samples_per_second() == config.samples_per_second()) &&
77 (extra_data() == config.extra_data()) && 76 (extra_data() == config.extra_data()) &&
78 (is_encrypted() == config.is_encrypted()) && 77 (encryption_scheme().Matches(config.encryption_scheme())) &&
79 (sample_format() == config.sample_format()) && 78 (sample_format() == config.sample_format()) &&
80 (seek_preroll() == config.seek_preroll()) && 79 (seek_preroll() == config.seek_preroll()) &&
81 (codec_delay() == config.codec_delay())); 80 (codec_delay() == config.codec_delay()));
82 } 81 }
83 82
84 std::string AudioDecoderConfig::AsHumanReadableString() const { 83 std::string AudioDecoderConfig::AsHumanReadableString() const {
85 std::ostringstream s; 84 std::ostringstream s;
86 s << "codec: " << GetCodecName(codec()) 85 s << "codec: " << GetCodecName(codec())
87 << " bytes_per_channel: " << bytes_per_channel() 86 << " bytes_per_channel: " << bytes_per_channel()
88 << " channel_layout: " << channel_layout() 87 << " channel_layout: " << channel_layout()
89 << " samples_per_second: " << samples_per_second() 88 << " samples_per_second: " << samples_per_second()
90 << " sample_format: " << sample_format() 89 << " sample_format: " << sample_format()
91 << " bytes_per_frame: " << bytes_per_frame() 90 << " bytes_per_frame: " << bytes_per_frame()
92 << " seek_preroll: " << seek_preroll().InMilliseconds() << "ms" 91 << " seek_preroll: " << seek_preroll().InMilliseconds() << "ms"
93 << " codec_delay: " << codec_delay() << " has extra data? " 92 << " codec_delay: " << codec_delay() << " has extra data? "
94 << (extra_data().empty() ? "false" : "true") << " encrypted? " 93 << (extra_data().empty() ? "false" : "true") << " encrypted? "
95 << (is_encrypted() ? "true" : "false"); 94 << (is_encrypted() ? "true" : "false");
96 return s.str(); 95 return s.str();
97 } 96 }
98 97
99 } // namespace media 98 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698