Chromium Code Reviews| 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" | 7 #include "base/logging.h" |
| 8 #include "media/base/limits.h" | 8 #include "media/base/limits.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 AudioParameters::AudioParameters() | 12 AudioParameters::AudioParameters() |
| 13 : AudioParameters(AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_NONE, 0, 0, 0) {} | 13 : AudioParameters(AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_NONE, 0, 0, 0) {} |
| 14 | 14 |
| 15 AudioParameters::AudioParameters(Format format, | 15 AudioParameters::AudioParameters(Format format, |
| 16 ChannelLayout channel_layout, | 16 ChannelLayout channel_layout, |
| 17 int sample_rate, | 17 int sample_rate, |
| 18 int bits_per_sample, | 18 int bits_per_sample, |
| 19 int frames_per_buffer) { | 19 int frames_per_buffer) { |
| 20 Reset(format, channel_layout, sample_rate, bits_per_sample, | 20 Reset(format, channel_layout, sample_rate, bits_per_sample, |
| 21 frames_per_buffer); | 21 frames_per_buffer); |
| 22 } | 22 } |
| 23 | 23 |
| 24 AudioParameters::~AudioParameters() {} | |
|
aluebs-chromium
2015/09/10 02:41:39
Again, maybe I am missing something, but why do yo
ajm
2015/09/10 19:33:04
chromium-style violation, as in MediaStreamDevice.
aluebs-chromium
2015/09/11 01:58:42
Thanks for clarifying :)
| |
| 25 | |
| 26 AudioParameters::AudioParameters(const AudioParameters&) = default; | |
| 27 AudioParameters& AudioParameters::operator=(const AudioParameters&) = default; | |
|
ajm
2015/09/10 19:33:04
Likewise, had to move these to the implementation
| |
| 28 | |
| 24 void AudioParameters::Reset(Format format, | 29 void AudioParameters::Reset(Format format, |
| 25 ChannelLayout channel_layout, | 30 ChannelLayout channel_layout, |
| 26 int sample_rate, | 31 int sample_rate, |
| 27 int bits_per_sample, | 32 int bits_per_sample, |
| 28 int frames_per_buffer) { | 33 int frames_per_buffer) { |
| 29 format_ = format; | 34 format_ = format; |
| 30 channel_layout_ = channel_layout; | 35 channel_layout_ = channel_layout; |
| 31 channels_ = ChannelLayoutToChannelCount(channel_layout); | 36 channels_ = ChannelLayoutToChannelCount(channel_layout); |
| 32 sample_rate_ = sample_rate; | 37 sample_rate_ = sample_rate; |
| 33 bits_per_sample_ = bits_per_sample; | 38 bits_per_sample_ = bits_per_sample; |
| 34 frames_per_buffer_ = frames_per_buffer; | 39 frames_per_buffer_ = frames_per_buffer; |
| 35 effects_ = NO_EFFECTS; | 40 effects_ = NO_EFFECTS; |
| 41 mic_positions_.clear(); | |
| 36 } | 42 } |
| 37 | 43 |
| 38 bool AudioParameters::IsValid() const { | 44 bool AudioParameters::IsValid() const { |
| 39 return (channels_ > 0) && (channels_ <= media::limits::kMaxChannels) && | 45 return (channels_ > 0) && (channels_ <= media::limits::kMaxChannels) && |
| 40 (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) && | 46 (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) && |
| 41 (sample_rate_ >= media::limits::kMinSampleRate) && | 47 (sample_rate_ >= media::limits::kMinSampleRate) && |
| 42 (sample_rate_ <= media::limits::kMaxSampleRate) && | 48 (sample_rate_ <= media::limits::kMaxSampleRate) && |
| 43 (bits_per_sample_ > 0) && | 49 (bits_per_sample_ > 0) && |
| 44 (bits_per_sample_ <= media::limits::kMaxBitsPerSample) && | 50 (bits_per_sample_ <= media::limits::kMaxBitsPerSample) && |
| 45 (frames_per_buffer_ > 0) && | 51 (frames_per_buffer_ > 0) && |
| 46 (frames_per_buffer_ <= media::limits::kMaxSamplesPerPacket) && | 52 (frames_per_buffer_ <= media::limits::kMaxSamplesPerPacket) && |
| 47 (channel_layout_ == CHANNEL_LAYOUT_DISCRETE || | 53 (channel_layout_ == CHANNEL_LAYOUT_DISCRETE || |
| 48 channels_ == ChannelLayoutToChannelCount(channel_layout_)); | 54 channels_ == ChannelLayoutToChannelCount(channel_layout_)); |
| 49 } | 55 } |
| 50 | 56 |
| 51 std::string AudioParameters::AsHumanReadableString() const { | 57 std::string AudioParameters::AsHumanReadableString() const { |
| 52 std::ostringstream s; | 58 std::ostringstream s; |
| 53 s << "format: " << format() << " channel_layout: " << channel_layout() | 59 s << "format: " << format() << " channel_layout: " << channel_layout() |
| 54 << " channels: " << channels() << " sample_rate: " << sample_rate() | 60 << " channels: " << channels() << " sample_rate: " << sample_rate() |
| 55 << " bits_per_sample: " << bits_per_sample() | 61 << " bits_per_sample: " << bits_per_sample() |
| 56 << " frames_per_buffer: " << frames_per_buffer() | 62 << " frames_per_buffer: " << frames_per_buffer() |
| 57 << " effects: " << effects(); | 63 << " effects: " << effects() |
| 64 << " mic_positions: " << PointsToString(mic_positions_); | |
| 58 return s.str(); | 65 return s.str(); |
| 59 } | 66 } |
| 60 | 67 |
| 61 int AudioParameters::GetBytesPerBuffer() const { | 68 int AudioParameters::GetBytesPerBuffer() const { |
| 62 return frames_per_buffer_ * GetBytesPerFrame(); | 69 return frames_per_buffer_ * GetBytesPerFrame(); |
| 63 } | 70 } |
| 64 | 71 |
| 65 int AudioParameters::GetBytesPerSecond() const { | 72 int AudioParameters::GetBytesPerSecond() const { |
| 66 return sample_rate_ * GetBytesPerFrame(); | 73 return sample_rate_ * GetBytesPerFrame(); |
| 67 } | 74 } |
| 68 | 75 |
| 69 int AudioParameters::GetBytesPerFrame() const { | 76 int AudioParameters::GetBytesPerFrame() const { |
| 70 return channels_ * bits_per_sample_ / 8; | 77 return channels_ * bits_per_sample_ / 8; |
| 71 } | 78 } |
| 72 | 79 |
| 73 base::TimeDelta AudioParameters::GetBufferDuration() const { | 80 base::TimeDelta AudioParameters::GetBufferDuration() const { |
| 74 return base::TimeDelta::FromMicroseconds(static_cast<int64>( | 81 return base::TimeDelta::FromMicroseconds(static_cast<int64>( |
| 75 frames_per_buffer_ * base::Time::kMicrosecondsPerSecond / | 82 frames_per_buffer_ * base::Time::kMicrosecondsPerSecond / |
| 76 static_cast<float>(sample_rate_))); | 83 static_cast<float>(sample_rate_))); |
| 77 } | 84 } |
| 78 | 85 |
| 79 bool AudioParameters::Equals(const AudioParameters& other) const { | 86 bool AudioParameters::Equals(const AudioParameters& other) const { |
| 80 return format_ == other.format() && | 87 return format_ == other.format() && sample_rate_ == other.sample_rate() && |
| 81 sample_rate_ == other.sample_rate() && | |
| 82 channel_layout_ == other.channel_layout() && | 88 channel_layout_ == other.channel_layout() && |
| 83 channels_ == other.channels() && | 89 channels_ == other.channels() && |
| 84 bits_per_sample_ == other.bits_per_sample() && | 90 bits_per_sample_ == other.bits_per_sample() && |
| 85 frames_per_buffer_ == other.frames_per_buffer() && | 91 frames_per_buffer_ == other.frames_per_buffer() && |
| 86 effects_ == other.effects(); | 92 effects_ == other.effects() && mic_positions_ == other.mic_positions_; |
| 87 } | 93 } |
| 88 | 94 |
| 89 } // namespace media | 95 } // namespace media |
| OLD | NEW |