BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / media / base / audio_decoder_config.cc
blob6dc5b2f65327a3f09b5b0f2af17c63b222393a43
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
3 // found in the LICENSE file.
5 #include "media/base/audio_decoder_config.h"
7 #include "base/logging.h"
8 #include "media/base/limits.h"
10 namespace media {
12 AudioDecoderConfig::AudioDecoderConfig()
13 : codec_(kUnknownAudioCodec),
14 sample_format_(kUnknownSampleFormat),
15 bytes_per_channel_(0),
16 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED),
17 samples_per_second_(0),
18 bytes_per_frame_(0),
19 is_encrypted_(false),
20 codec_delay_(0) {
23 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec,
24 SampleFormat sample_format,
25 ChannelLayout channel_layout,
26 int samples_per_second,
27 const uint8* extra_data,
28 size_t extra_data_size,
29 bool is_encrypted) {
30 Initialize(codec, sample_format, channel_layout, samples_per_second,
31 extra_data, extra_data_size, is_encrypted, base::TimeDelta(), 0);
34 void AudioDecoderConfig::Initialize(AudioCodec codec,
35 SampleFormat sample_format,
36 ChannelLayout channel_layout,
37 int samples_per_second,
38 const uint8* extra_data,
39 size_t extra_data_size,
40 bool is_encrypted,
41 base::TimeDelta seek_preroll,
42 int codec_delay) {
43 CHECK((extra_data_size != 0) == (extra_data != NULL));
45 codec_ = codec;
46 channel_layout_ = channel_layout;
47 samples_per_second_ = samples_per_second;
48 sample_format_ = sample_format;
49 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format);
50 extra_data_.assign(extra_data, extra_data + extra_data_size);
51 is_encrypted_ = is_encrypted;
52 seek_preroll_ = seek_preroll;
53 codec_delay_ = codec_delay;
55 int channels = ChannelLayoutToChannelCount(channel_layout_);
56 bytes_per_frame_ = channels * bytes_per_channel_;
59 AudioDecoderConfig::~AudioDecoderConfig() {}
61 bool AudioDecoderConfig::IsValidConfig() const {
62 return codec_ != kUnknownAudioCodec &&
63 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED &&
64 bytes_per_channel_ > 0 &&
65 bytes_per_channel_ <= limits::kMaxBytesPerSample &&
66 samples_per_second_ > 0 &&
67 samples_per_second_ <= limits::kMaxSampleRate &&
68 sample_format_ != kUnknownSampleFormat &&
69 seek_preroll_ >= base::TimeDelta() &&
70 codec_delay_ >= 0;
73 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const {
74 return ((codec() == config.codec()) &&
75 (bytes_per_channel() == config.bytes_per_channel()) &&
76 (channel_layout() == config.channel_layout()) &&
77 (samples_per_second() == config.samples_per_second()) &&
78 (extra_data_size() == config.extra_data_size()) &&
79 (!extra_data() || !memcmp(extra_data(), config.extra_data(),
80 extra_data_size())) &&
81 (is_encrypted() == config.is_encrypted()) &&
82 (sample_format() == config.sample_format()) &&
83 (seek_preroll() == config.seek_preroll()) &&
84 (codec_delay() == config.codec_delay()));
87 std::string AudioDecoderConfig::AsHumanReadableString() const {
88 std::ostringstream s;
89 s << "codec: " << GetHumanReadableCodecName()
90 << " bytes_per_channel: " << bytes_per_channel()
91 << " channel_layout: " << channel_layout()
92 << " samples_per_second: " << samples_per_second()
93 << " sample_format: " << sample_format()
94 << " bytes_per_frame: " << bytes_per_frame()
95 << " seek_preroll: " << seek_preroll().InMilliseconds() << "ms"
96 << " codec_delay: " << codec_delay()
97 << " has extra data? " << (extra_data() ? "true" : "false")
98 << " encrypted? " << (is_encrypted() ? "true" : "false");
99 return s.str();
102 // These names come from src/third_party/ffmpeg/libavcodec/codec_desc.c
103 std::string AudioDecoderConfig::GetHumanReadableCodecName() const {
104 switch (codec()) {
105 case kUnknownAudioCodec:
106 return "unknown";
107 case kCodecAAC:
108 return "aac";
109 case kCodecMP3:
110 return "mp3";
111 case kCodecPCM:
112 case kCodecPCM_S16BE:
113 case kCodecPCM_S24BE:
114 return "pcm";
115 case kCodecVorbis:
116 return "vorbis";
117 case kCodecFLAC:
118 return "flac";
119 case kCodecAMR_NB:
120 return "amr_nb";
121 case kCodecAMR_WB:
122 return "amr_wb";
123 case kCodecGSM_MS:
124 return "gsm_ms";
125 case kCodecPCM_ALAW:
126 return "pcm_alaw";
127 case kCodecPCM_MULAW:
128 return "pcm_mulaw";
129 case kCodecOpus:
130 return "opus";
131 case kCodecALAC:
132 return "alac";
134 NOTREACHED();
135 return "";
138 } // namespace media