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

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: ddorwin 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 encryption_scheme_(),
20 codec_delay_(0) { 20 codec_delay_(0) {}
21 }
22 21
23 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, 22 AudioDecoderConfig::AudioDecoderConfig(
24 SampleFormat sample_format, 23 AudioCodec codec,
25 ChannelLayout channel_layout, 24 SampleFormat sample_format,
26 int samples_per_second, 25 ChannelLayout channel_layout,
27 const std::vector<uint8_t>& extra_data, 26 int samples_per_second,
28 bool is_encrypted) { 27 const std::vector<uint8_t>& extra_data,
28 const EncryptionScheme& encryption_scheme) {
29 Initialize(codec, sample_format, channel_layout, samples_per_second, 29 Initialize(codec, sample_format, channel_layout, samples_per_second,
30 extra_data, is_encrypted, base::TimeDelta(), 0); 30 extra_data, encryption_scheme, base::TimeDelta(), 0);
31 } 31 }
32 32
33 AudioDecoderConfig::AudioDecoderConfig(const AudioDecoderConfig& other) = 33 AudioDecoderConfig::AudioDecoderConfig(const AudioDecoderConfig& other) =
34 default; 34 default;
35 35
36 void AudioDecoderConfig::Initialize(AudioCodec codec, 36 void AudioDecoderConfig::Initialize(AudioCodec codec,
37 SampleFormat sample_format, 37 SampleFormat sample_format,
38 ChannelLayout channel_layout, 38 ChannelLayout channel_layout,
39 int samples_per_second, 39 int samples_per_second,
40 const std::vector<uint8_t>& extra_data, 40 const std::vector<uint8_t>& extra_data,
41 bool is_encrypted, 41 const EncryptionScheme& encryption_scheme,
42 base::TimeDelta seek_preroll, 42 base::TimeDelta seek_preroll,
43 int codec_delay) { 43 int codec_delay) {
44 codec_ = codec; 44 codec_ = codec;
45 channel_layout_ = channel_layout; 45 channel_layout_ = channel_layout;
46 samples_per_second_ = samples_per_second; 46 samples_per_second_ = samples_per_second;
47 sample_format_ = sample_format; 47 sample_format_ = sample_format;
48 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format); 48 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format);
49 extra_data_ = extra_data; 49 extra_data_ = extra_data;
50 is_encrypted_ = is_encrypted; 50 encryption_scheme_ = encryption_scheme;
51 seek_preroll_ = seek_preroll; 51 seek_preroll_ = seek_preroll;
52 codec_delay_ = codec_delay; 52 codec_delay_ = codec_delay;
53 53
54 int channels = ChannelLayoutToChannelCount(channel_layout_); 54 int channels = ChannelLayoutToChannelCount(channel_layout_);
55 bytes_per_frame_ = channels * bytes_per_channel_; 55 bytes_per_frame_ = channels * bytes_per_channel_;
56 } 56 }
57 57
58 AudioDecoderConfig::~AudioDecoderConfig() {} 58 AudioDecoderConfig::~AudioDecoderConfig() {}
59 59
60 bool AudioDecoderConfig::IsValidConfig() const { 60 bool AudioDecoderConfig::IsValidConfig() const {
61 return codec_ != kUnknownAudioCodec && 61 return codec_ != kUnknownAudioCodec &&
62 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && 62 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED &&
63 bytes_per_channel_ > 0 && 63 bytes_per_channel_ > 0 &&
64 bytes_per_channel_ <= limits::kMaxBytesPerSample && 64 bytes_per_channel_ <= limits::kMaxBytesPerSample &&
65 samples_per_second_ > 0 && 65 samples_per_second_ > 0 &&
66 samples_per_second_ <= limits::kMaxSampleRate && 66 samples_per_second_ <= limits::kMaxSampleRate &&
67 sample_format_ != kUnknownSampleFormat && 67 sample_format_ != kUnknownSampleFormat &&
68 seek_preroll_ >= base::TimeDelta() && 68 seek_preroll_ >= base::TimeDelta() &&
69 codec_delay_ >= 0; 69 codec_delay_ >= 0;
70 } 70 }
71 71
72 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { 72 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const {
73 return ((codec() == config.codec()) && 73 return ((codec() == config.codec()) &&
74 (bytes_per_channel() == config.bytes_per_channel()) && 74 (bytes_per_channel() == config.bytes_per_channel()) &&
75 (channel_layout() == config.channel_layout()) && 75 (channel_layout() == config.channel_layout()) &&
76 (samples_per_second() == config.samples_per_second()) && 76 (samples_per_second() == config.samples_per_second()) &&
77 (extra_data() == config.extra_data()) && 77 (extra_data() == config.extra_data()) &&
78 (is_encrypted() == config.is_encrypted()) && 78 (encryption_scheme().Matches(config.encryption_scheme())) &&
79 (sample_format() == config.sample_format()) && 79 (sample_format() == config.sample_format()) &&
80 (seek_preroll() == config.seek_preroll()) && 80 (seek_preroll() == config.seek_preroll()) &&
81 (codec_delay() == config.codec_delay())); 81 (codec_delay() == config.codec_delay()));
82 } 82 }
83 83
84 std::string AudioDecoderConfig::AsHumanReadableString() const { 84 std::string AudioDecoderConfig::AsHumanReadableString() const {
85 std::ostringstream s; 85 std::ostringstream s;
86 s << "codec: " << GetCodecName(codec()) 86 s << "codec: " << GetCodecName(codec())
87 << " bytes_per_channel: " << bytes_per_channel() 87 << " bytes_per_channel: " << bytes_per_channel()
88 << " channel_layout: " << channel_layout() 88 << " channel_layout: " << channel_layout()
89 << " samples_per_second: " << samples_per_second() 89 << " samples_per_second: " << samples_per_second()
90 << " sample_format: " << sample_format() 90 << " sample_format: " << sample_format()
91 << " bytes_per_frame: " << bytes_per_frame() 91 << " bytes_per_frame: " << bytes_per_frame()
92 << " seek_preroll: " << seek_preroll().InMilliseconds() << "ms" 92 << " seek_preroll: " << seek_preroll().InMilliseconds() << "ms"
93 << " codec_delay: " << codec_delay() << " has extra data? " 93 << " codec_delay: " << codec_delay() << " has extra data? "
94 << (extra_data().empty() ? "false" : "true") << " encrypted? " 94 << (extra_data().empty() ? "false" : "true") << " encrypted? "
95 << (is_encrypted() ? "true" : "false"); 95 << (is_encrypted() ? "true" : "false");
96 return s.str(); 96 return s.str();
97 } 97 }
98 98
99 bool AudioDecoderConfig::is_encrypted() const {
100 return encryption_scheme_.is_encrypted();
101 }
102
99 } // namespace media 103 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698