Mailbox support for texture layers.
[chromium-blink-merge.git] / media / audio / audio_parameters.cc
blob0d9263ff5a6fdd2e7122342dae02e26e6d9fc099
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 "media/base/limits.h"
9 namespace media {
11 AudioParameters::AudioParameters()
12 : format_(AUDIO_PCM_LINEAR),
13 channel_layout_(CHANNEL_LAYOUT_NONE),
14 sample_rate_(0),
15 bits_per_sample_(0),
16 frames_per_buffer_(0),
17 channels_(0) {
20 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout,
21 int sample_rate, int bits_per_sample,
22 int frames_per_buffer)
23 : format_(format),
24 channel_layout_(channel_layout),
25 sample_rate_(sample_rate),
26 bits_per_sample_(bits_per_sample),
27 frames_per_buffer_(frames_per_buffer),
28 channels_(ChannelLayoutToChannelCount(channel_layout)) {
31 void AudioParameters::Reset(Format format, ChannelLayout channel_layout,
32 int sample_rate, int bits_per_sample,
33 int frames_per_buffer) {
34 format_ = format;
35 channel_layout_ = channel_layout;
36 sample_rate_ = sample_rate;
37 bits_per_sample_ = bits_per_sample;
38 frames_per_buffer_ = frames_per_buffer;
39 channels_ = ChannelLayoutToChannelCount(channel_layout);
42 bool AudioParameters::IsValid() const {
43 return (format_ >= AUDIO_PCM_LINEAR) &&
44 (format_ < AUDIO_LAST_FORMAT) &&
45 (channels_ > 0) &&
46 (channels_ <= media::limits::kMaxChannels) &&
47 (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) &&
48 (channel_layout_ < CHANNEL_LAYOUT_MAX) &&
49 (sample_rate_ >= media::limits::kMinSampleRate) &&
50 (sample_rate_ <= media::limits::kMaxSampleRate) &&
51 (bits_per_sample_ > 0) &&
52 (bits_per_sample_ <= media::limits::kMaxBitsPerSample) &&
53 (frames_per_buffer_ > 0) &&
54 (frames_per_buffer_ <= media::limits::kMaxSamplesPerPacket);
57 int AudioParameters::GetBytesPerBuffer() const {
58 return frames_per_buffer_ * GetBytesPerFrame();
61 int AudioParameters::GetBytesPerSecond() const {
62 return sample_rate_ * GetBytesPerFrame();
65 int AudioParameters::GetBytesPerFrame() const {
66 return channels_ * bits_per_sample_ / 8;
69 } // namespace media