Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / media / base / audio_decoder_config.cc
blob780bada49e9530b17d88e681ab5b3cc4185b466a
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 "base/metrics/histogram.h"
9 #include "media/audio/sample_rates.h"
10 #include "media/base/limits.h"
12 namespace media {
14 AudioDecoderConfig::AudioDecoderConfig()
15 : codec_(kUnknownAudioCodec),
16 sample_format_(kUnknownSampleFormat),
17 bytes_per_channel_(0),
18 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED),
19 samples_per_second_(0),
20 bytes_per_frame_(0),
21 is_encrypted_(false),
22 codec_delay_(0) {
25 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec,
26 SampleFormat sample_format,
27 ChannelLayout channel_layout,
28 int samples_per_second,
29 const uint8* extra_data,
30 size_t extra_data_size,
31 bool is_encrypted) {
32 Initialize(codec, sample_format, channel_layout, samples_per_second,
33 extra_data, extra_data_size, is_encrypted, true,
34 base::TimeDelta(), 0);
37 void AudioDecoderConfig::Initialize(AudioCodec codec,
38 SampleFormat sample_format,
39 ChannelLayout channel_layout,
40 int samples_per_second,
41 const uint8* extra_data,
42 size_t extra_data_size,
43 bool is_encrypted,
44 bool record_stats,
45 base::TimeDelta seek_preroll,
46 int codec_delay) {
47 CHECK((extra_data_size != 0) == (extra_data != NULL));
49 if (record_stats) {
50 UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax + 1);
51 UMA_HISTOGRAM_ENUMERATION("Media.AudioSampleFormat", sample_format,
52 kSampleFormatMax + 1);
53 UMA_HISTOGRAM_ENUMERATION("Media.AudioChannelLayout", channel_layout,
54 CHANNEL_LAYOUT_MAX + 1);
55 AudioSampleRate asr;
56 if (ToAudioSampleRate(samples_per_second, &asr)) {
57 UMA_HISTOGRAM_ENUMERATION("Media.AudioSamplesPerSecond", asr,
58 kAudioSampleRateMax + 1);
59 } else {
60 UMA_HISTOGRAM_COUNTS(
61 "Media.AudioSamplesPerSecondUnexpected", samples_per_second);
65 codec_ = codec;
66 channel_layout_ = channel_layout;
67 samples_per_second_ = samples_per_second;
68 sample_format_ = sample_format;
69 bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format);
70 extra_data_.assign(extra_data, extra_data + extra_data_size);
71 is_encrypted_ = is_encrypted;
72 seek_preroll_ = seek_preroll;
73 codec_delay_ = codec_delay;
75 int channels = ChannelLayoutToChannelCount(channel_layout_);
76 bytes_per_frame_ = channels * bytes_per_channel_;
79 AudioDecoderConfig::~AudioDecoderConfig() {}
81 bool AudioDecoderConfig::IsValidConfig() const {
82 return codec_ != kUnknownAudioCodec &&
83 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED &&
84 bytes_per_channel_ > 0 &&
85 bytes_per_channel_ <= limits::kMaxBytesPerSample &&
86 samples_per_second_ > 0 &&
87 samples_per_second_ <= limits::kMaxSampleRate &&
88 sample_format_ != kUnknownSampleFormat &&
89 seek_preroll_ >= base::TimeDelta() &&
90 codec_delay_ >= 0;
93 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const {
94 return ((codec() == config.codec()) &&
95 (bytes_per_channel() == config.bytes_per_channel()) &&
96 (channel_layout() == config.channel_layout()) &&
97 (samples_per_second() == config.samples_per_second()) &&
98 (extra_data_size() == config.extra_data_size()) &&
99 (!extra_data() || !memcmp(extra_data(), config.extra_data(),
100 extra_data_size())) &&
101 (is_encrypted() == config.is_encrypted()) &&
102 (sample_format() == config.sample_format()) &&
103 (seek_preroll() == config.seek_preroll()) &&
104 (codec_delay() == config.codec_delay()));
107 std::string AudioDecoderConfig::AsHumanReadableString() const {
108 std::ostringstream s;
109 s << "codec: " << GetHumanReadableCodecName()
110 << " bytes_per_channel: " << bytes_per_channel()
111 << " channel_layout: " << channel_layout()
112 << " samples_per_second: " << samples_per_second()
113 << " sample_format: " << sample_format()
114 << " bytes_per_frame: " << bytes_per_frame()
115 << " seek_preroll: " << seek_preroll().InMilliseconds() << "ms"
116 << " codec_delay: " << codec_delay()
117 << " has extra data? " << (extra_data() ? "true" : "false")
118 << " encrypted? " << (is_encrypted() ? "true" : "false");
119 return s.str();
122 // These names come from src/third_party/ffmpeg/libavcodec/codec_desc.c
123 std::string AudioDecoderConfig::GetHumanReadableCodecName() const {
124 switch (codec()) {
125 case kUnknownAudioCodec:
126 return "unknown";
127 case kCodecAAC:
128 return "aac";
129 case kCodecMP3:
130 return "mp3";
131 case kCodecPCM:
132 case kCodecPCM_S16BE:
133 case kCodecPCM_S24BE:
134 return "pcm";
135 case kCodecVorbis:
136 return "vorbis";
137 case kCodecFLAC:
138 return "flac";
139 case kCodecAMR_NB:
140 return "amr_nb";
141 case kCodecAMR_WB:
142 return "amr_wb";
143 case kCodecGSM_MS:
144 return "gsm_ms";
145 case kCodecPCM_ALAW:
146 return "pcm_alaw";
147 case kCodecPCM_MULAW:
148 return "pcm_mulaw";
149 case kCodecOpus:
150 return "opus";
151 case kCodecALAC:
152 return "alac";
154 NOTREACHED();
155 return "";
158 } // namespace media