Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / media / audio / audio_parameters.cc
bloba78eb84a4cd1e615f18ec0a67660095c20e97491
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/audio/audio_parameters.h"
7 #include "base/logging.h"
8 #include "media/base/limits.h"
10 namespace media {
12 AudioParameters::AudioParameters()
13 : AudioParameters(AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_NONE, 0, 0, 0) {}
15 AudioParameters::AudioParameters(Format format,
16 ChannelLayout channel_layout,
17 int sample_rate,
18 int bits_per_sample,
19 int frames_per_buffer) {
20 Reset(format, channel_layout, sample_rate, bits_per_sample,
21 frames_per_buffer);
24 void AudioParameters::Reset(Format format,
25 ChannelLayout channel_layout,
26 int sample_rate,
27 int bits_per_sample,
28 int frames_per_buffer) {
29 format_ = format;
30 channel_layout_ = channel_layout;
31 channels_ = ChannelLayoutToChannelCount(channel_layout);
32 sample_rate_ = sample_rate;
33 bits_per_sample_ = bits_per_sample;
34 frames_per_buffer_ = frames_per_buffer;
35 effects_ = NO_EFFECTS;
38 bool AudioParameters::IsValid() const {
39 return (channels_ > 0) && (channels_ <= media::limits::kMaxChannels) &&
40 (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) &&
41 (sample_rate_ >= media::limits::kMinSampleRate) &&
42 (sample_rate_ <= media::limits::kMaxSampleRate) &&
43 (bits_per_sample_ > 0) &&
44 (bits_per_sample_ <= media::limits::kMaxBitsPerSample) &&
45 (frames_per_buffer_ > 0) &&
46 (frames_per_buffer_ <= media::limits::kMaxSamplesPerPacket) &&
47 (channel_layout_ == CHANNEL_LAYOUT_DISCRETE ||
48 channels_ == ChannelLayoutToChannelCount(channel_layout_));
51 std::string AudioParameters::AsHumanReadableString() const {
52 std::ostringstream s;
53 s << "format: " << format() << " channel_layout: " << channel_layout()
54 << " channels: " << channels() << " sample_rate: " << sample_rate()
55 << " bits_per_sample: " << bits_per_sample()
56 << " frames_per_buffer: " << frames_per_buffer()
57 << " effects: " << effects();
58 return s.str();
61 int AudioParameters::GetBytesPerBuffer() const {
62 return frames_per_buffer_ * GetBytesPerFrame();
65 int AudioParameters::GetBytesPerSecond() const {
66 return sample_rate_ * GetBytesPerFrame();
69 int AudioParameters::GetBytesPerFrame() const {
70 return channels_ * bits_per_sample_ / 8;
73 base::TimeDelta AudioParameters::GetBufferDuration() const {
74 return base::TimeDelta::FromMicroseconds(static_cast<int64>(
75 frames_per_buffer_ * base::Time::kMicrosecondsPerSecond /
76 static_cast<float>(sample_rate_)));
79 bool AudioParameters::Equals(const AudioParameters& other) const {
80 return format_ == other.format() &&
81 sample_rate_ == other.sample_rate() &&
82 channel_layout_ == other.channel_layout() &&
83 channels_ == other.channels() &&
84 bits_per_sample_ == other.bits_per_sample() &&
85 frames_per_buffer_ == other.frames_per_buffer() &&
86 effects_ == other.effects();
89 } // namespace media