Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: media/audio/audio_parameters.cc

Issue 1907973003: media: Move audio_parameters and audio_point to media/base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/audio_parameters.h ('k') | media/audio/audio_parameters_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "media/audio/audio_parameters.h"
6
7 #include "base/logging.h"
8 #include "media/base/limits.h"
9
10 namespace media {
11
12 AudioParameters::AudioParameters()
13 : AudioParameters(AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_NONE, 0, 0, 0) {}
14
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);
22 }
23
24 AudioParameters::~AudioParameters() {}
25
26 AudioParameters::AudioParameters(const AudioParameters&) = default;
27 AudioParameters& AudioParameters::operator=(const AudioParameters&) = default;
28
29 void AudioParameters::Reset(Format format,
30 ChannelLayout channel_layout,
31 int sample_rate,
32 int bits_per_sample,
33 int frames_per_buffer) {
34 format_ = format;
35 channel_layout_ = channel_layout;
36 channels_ = ChannelLayoutToChannelCount(channel_layout);
37 sample_rate_ = sample_rate;
38 bits_per_sample_ = bits_per_sample;
39 frames_per_buffer_ = frames_per_buffer;
40 effects_ = NO_EFFECTS;
41 mic_positions_.clear();
42 }
43
44 bool AudioParameters::IsValid() const {
45 return (channels_ > 0) && (channels_ <= media::limits::kMaxChannels) &&
46 (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) &&
47 (sample_rate_ >= media::limits::kMinSampleRate) &&
48 (sample_rate_ <= media::limits::kMaxSampleRate) &&
49 (bits_per_sample_ > 0) &&
50 (bits_per_sample_ <= media::limits::kMaxBitsPerSample) &&
51 (frames_per_buffer_ > 0) &&
52 (frames_per_buffer_ <= media::limits::kMaxSamplesPerPacket) &&
53 (channel_layout_ == CHANNEL_LAYOUT_DISCRETE ||
54 channels_ == ChannelLayoutToChannelCount(channel_layout_));
55 }
56
57 std::string AudioParameters::AsHumanReadableString() const {
58 std::ostringstream s;
59 s << "format: " << format() << " channel_layout: " << channel_layout()
60 << " channels: " << channels() << " sample_rate: " << sample_rate()
61 << " bits_per_sample: " << bits_per_sample()
62 << " frames_per_buffer: " << frames_per_buffer()
63 << " effects: " << effects()
64 << " mic_positions: " << PointsToString(mic_positions_);
65 return s.str();
66 }
67
68 int AudioParameters::GetBytesPerBuffer() const {
69 return frames_per_buffer_ * GetBytesPerFrame();
70 }
71
72 int AudioParameters::GetBytesPerSecond() const {
73 return sample_rate_ * GetBytesPerFrame();
74 }
75
76 int AudioParameters::GetBytesPerFrame() const {
77 return channels_ * bits_per_sample_ / 8;
78 }
79
80 double AudioParameters::GetMicrosecondsPerFrame() const {
81 return static_cast<double>(base::Time::kMicrosecondsPerSecond) / sample_rate_;
82 }
83
84 base::TimeDelta AudioParameters::GetBufferDuration() const {
85 return base::TimeDelta::FromMicroseconds(static_cast<int64_t>(
86 frames_per_buffer_ * base::Time::kMicrosecondsPerSecond /
87 static_cast<float>(sample_rate_)));
88 }
89
90 bool AudioParameters::Equals(const AudioParameters& other) const {
91 return format_ == other.format() && sample_rate_ == other.sample_rate() &&
92 channel_layout_ == other.channel_layout() &&
93 channels_ == other.channels() &&
94 bits_per_sample_ == other.bits_per_sample() &&
95 frames_per_buffer_ == other.frames_per_buffer() &&
96 effects_ == other.effects() && mic_positions_ == other.mic_positions_;
97 }
98
99 // static
100 AudioParameters AudioParameters::UnavailableDeviceParams() {
101 return media::AudioParameters(
102 media::AudioParameters::AUDIO_FAKE, media::CHANNEL_LAYOUT_STEREO,
103 media::AudioParameters::kAudioCDSampleRate, 16,
104 media::AudioParameters::kAudioCDSampleRate / 10);
105 }
106
107 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_parameters.h ('k') | media/audio/audio_parameters_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698