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

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: Created 5 years 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_(false),
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 void AudioDecoderConfig::Initialize(AudioCodec codec, 33 void AudioDecoderConfig::Initialize(AudioCodec codec,
34 SampleFormat sample_format, 34 SampleFormat sample_format,
35 ChannelLayout channel_layout, 35 ChannelLayout channel_layout,
36 int samples_per_second, 36 int samples_per_second,
37 const std::vector<uint8_t>& extra_data, 37 const std::vector<uint8_t>& extra_data,
38 bool is_encrypted, 38 const EncryptionScheme& encryption_scheme,
39 base::TimeDelta seek_preroll, 39 base::TimeDelta seek_preroll,
40 int codec_delay) { 40 int codec_delay) {
41 codec_ = codec; 41 codec_ = codec;
42 channel_layout_ = channel_layout; 42 channel_layout_ = channel_layout;
43 samples_per_second_ = samples_per_second; 43 samples_per_second_ = samples_per_second;
44 sample_format_ = sample_format; 44 sample_format_ = sample_format;
45 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format); 45 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format);
46 extra_data_ = extra_data; 46 extra_data_ = extra_data;
47 is_encrypted_ = is_encrypted; 47 encryption_scheme_ = encryption_scheme;
48 seek_preroll_ = seek_preroll; 48 seek_preroll_ = seek_preroll;
49 codec_delay_ = codec_delay; 49 codec_delay_ = codec_delay;
50 50
51 int channels = ChannelLayoutToChannelCount(channel_layout_); 51 int channels = ChannelLayoutToChannelCount(channel_layout_);
52 bytes_per_frame_ = channels * bytes_per_channel_; 52 bytes_per_frame_ = channels * bytes_per_channel_;
53 } 53 }
54 54
55 AudioDecoderConfig::~AudioDecoderConfig() {} 55 AudioDecoderConfig::~AudioDecoderConfig() {}
56 56
57 bool AudioDecoderConfig::IsValidConfig() const { 57 bool AudioDecoderConfig::IsValidConfig() const {
58 return codec_ != kUnknownAudioCodec && 58 return codec_ != kUnknownAudioCodec &&
59 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && 59 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED &&
60 bytes_per_channel_ > 0 && 60 bytes_per_channel_ > 0 &&
61 bytes_per_channel_ <= limits::kMaxBytesPerSample && 61 bytes_per_channel_ <= limits::kMaxBytesPerSample &&
62 samples_per_second_ > 0 && 62 samples_per_second_ > 0 &&
63 samples_per_second_ <= limits::kMaxSampleRate && 63 samples_per_second_ <= limits::kMaxSampleRate &&
64 sample_format_ != kUnknownSampleFormat && 64 sample_format_ != kUnknownSampleFormat &&
65 seek_preroll_ >= base::TimeDelta() && 65 seek_preroll_ >= base::TimeDelta() &&
66 codec_delay_ >= 0; 66 codec_delay_ >= 0;
67 } 67 }
68 68
69 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { 69 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const {
70 return ((codec() == config.codec()) && 70 return ((codec() == config.codec()) &&
71 (bytes_per_channel() == config.bytes_per_channel()) && 71 (bytes_per_channel() == config.bytes_per_channel()) &&
72 (channel_layout() == config.channel_layout()) && 72 (channel_layout() == config.channel_layout()) &&
73 (samples_per_second() == config.samples_per_second()) && 73 (samples_per_second() == config.samples_per_second()) &&
74 (extra_data() == config.extra_data()) && 74 (extra_data() == config.extra_data()) &&
75 (is_encrypted() == config.is_encrypted()) && 75 (encryption_scheme().Matches(config.encryption_scheme())) &&
76 (sample_format() == config.sample_format()) && 76 (sample_format() == config.sample_format()) &&
77 (seek_preroll() == config.seek_preroll()) && 77 (seek_preroll() == config.seek_preroll()) &&
78 (codec_delay() == config.codec_delay())); 78 (codec_delay() == config.codec_delay()));
79 } 79 }
80 80
81 std::string AudioDecoderConfig::AsHumanReadableString() const { 81 std::string AudioDecoderConfig::AsHumanReadableString() const {
82 std::ostringstream s; 82 std::ostringstream s;
83 s << "codec: " << GetHumanReadableCodecName() 83 s << "codec: " << GetHumanReadableCodecName()
84 << " bytes_per_channel: " << bytes_per_channel() 84 << " bytes_per_channel: " << bytes_per_channel()
85 << " channel_layout: " << channel_layout() 85 << " channel_layout: " << channel_layout()
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 case kCodecOpus: 123 case kCodecOpus:
124 return "opus"; 124 return "opus";
125 case kCodecALAC: 125 case kCodecALAC:
126 return "alac"; 126 return "alac";
127 } 127 }
128 NOTREACHED(); 128 NOTREACHED();
129 return ""; 129 return "";
130 } 130 }
131 131
132 } // namespace media 132 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698