| OLD | NEW |
| 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/audio/audio_parameters.h" | 5 #include "media/audio/audio_parameters.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 8 #include "media/base/limits.h" | 7 #include "media/base/limits.h" |
| 9 | 8 |
| 10 namespace media { | 9 namespace media { |
| 11 | 10 |
| 12 AudioParameters::AudioParameters() | 11 AudioParameters::AudioParameters() |
| 13 : format_(AUDIO_PCM_LINEAR), | 12 : format_(AUDIO_PCM_LINEAR), |
| 14 channel_layout_(CHANNEL_LAYOUT_NONE), | 13 channel_layout_(CHANNEL_LAYOUT_NONE), |
| 15 sample_rate_(0), | 14 sample_rate_(0), |
| 16 bits_per_sample_(0), | 15 bits_per_sample_(0), |
| 17 frames_per_buffer_(0), | 16 frames_per_buffer_(0), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 38 : format_(format), | 37 : format_(format), |
| 39 channel_layout_(channel_layout), | 38 channel_layout_(channel_layout), |
| 40 sample_rate_(sample_rate), | 39 sample_rate_(sample_rate), |
| 41 bits_per_sample_(bits_per_sample), | 40 bits_per_sample_(bits_per_sample), |
| 42 frames_per_buffer_(frames_per_buffer), | 41 frames_per_buffer_(frames_per_buffer), |
| 43 channels_(ChannelLayoutToChannelCount(channel_layout)), | 42 channels_(ChannelLayoutToChannelCount(channel_layout)), |
| 44 input_channels_(input_channels) { | 43 input_channels_(input_channels) { |
| 45 } | 44 } |
| 46 | 45 |
| 47 void AudioParameters::Reset(Format format, ChannelLayout channel_layout, | 46 void AudioParameters::Reset(Format format, ChannelLayout channel_layout, |
| 48 int channels, int input_channels, | 47 int input_channels, |
| 49 int sample_rate, int bits_per_sample, | 48 int sample_rate, int bits_per_sample, |
| 50 int frames_per_buffer) { | 49 int frames_per_buffer) { |
| 51 if (channel_layout != CHANNEL_LAYOUT_DISCRETE) | |
| 52 DCHECK_EQ(channels, ChannelLayoutToChannelCount(channel_layout)); | |
| 53 | |
| 54 format_ = format; | 50 format_ = format; |
| 55 channel_layout_ = channel_layout; | 51 channel_layout_ = channel_layout; |
| 56 channels_ = channels; | |
| 57 input_channels_ = input_channels; | 52 input_channels_ = input_channels; |
| 58 sample_rate_ = sample_rate; | 53 sample_rate_ = sample_rate; |
| 59 bits_per_sample_ = bits_per_sample; | 54 bits_per_sample_ = bits_per_sample; |
| 60 frames_per_buffer_ = frames_per_buffer; | 55 frames_per_buffer_ = frames_per_buffer; |
| 56 channels_ = ChannelLayoutToChannelCount(channel_layout); |
| 61 } | 57 } |
| 62 | 58 |
| 63 bool AudioParameters::IsValid() const { | 59 bool AudioParameters::IsValid() const { |
| 64 return (format_ >= AUDIO_PCM_LINEAR) && | 60 return (format_ >= AUDIO_PCM_LINEAR) && |
| 65 (format_ < AUDIO_LAST_FORMAT) && | 61 (format_ < AUDIO_LAST_FORMAT) && |
| 66 (channels_ > 0) && | 62 (channels_ > 0) && |
| 67 (channels_ <= media::limits::kMaxChannels) && | 63 (channels_ <= media::limits::kMaxChannels) && |
| 68 (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) && | 64 (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) && |
| 69 (channel_layout_ < CHANNEL_LAYOUT_MAX) && | 65 (channel_layout_ < CHANNEL_LAYOUT_MAX) && |
| 70 (input_channels_ >= 0) && | 66 (input_channels_ >= 0) && |
| (...skipping 11 matching lines...) Expand all Loading... |
| 82 } | 78 } |
| 83 | 79 |
| 84 int AudioParameters::GetBytesPerSecond() const { | 80 int AudioParameters::GetBytesPerSecond() const { |
| 85 return sample_rate_ * GetBytesPerFrame(); | 81 return sample_rate_ * GetBytesPerFrame(); |
| 86 } | 82 } |
| 87 | 83 |
| 88 int AudioParameters::GetBytesPerFrame() const { | 84 int AudioParameters::GetBytesPerFrame() const { |
| 89 return channels_ * bits_per_sample_ / 8; | 85 return channels_ * bits_per_sample_ / 8; |
| 90 } | 86 } |
| 91 | 87 |
| 92 void AudioParameters::SetDiscreteChannels(int channels) { | |
| 93 channel_layout_ = CHANNEL_LAYOUT_DISCRETE; | |
| 94 channels_ = channels; | |
| 95 } | |
| 96 | |
| 97 } // namespace media | 88 } // namespace media |
| OLD | NEW |