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 #ifndef MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
6 #define MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 6 #define MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "media/audio/point.h" |
14 #include "media/base/audio_bus.h" | 15 #include "media/base/audio_bus.h" |
15 #include "media/base/channel_layout.h" | 16 #include "media/base/channel_layout.h" |
16 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
17 | 18 |
18 namespace media { | 19 namespace media { |
19 | 20 |
20 // Use a struct-in-struct approach to ensure that we can calculate the required | 21 // Use a struct-in-struct approach to ensure that we can calculate the required |
21 // size as sizeof(AudioInputBufferParameters) + #(bytes in audio buffer) without | 22 // size as sizeof(AudioInputBufferParameters) + #(bytes in audio buffer) without |
22 // using packing. Also align AudioInputBufferParameters instead of in | 23 // using packing. Also align AudioInputBufferParameters instead of in |
23 // AudioInputBuffer to be able to calculate size like so. Use a macro for the | 24 // AudioInputBuffer to be able to calculate size like so. Use a macro for the |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // effects should be enabled. | 74 // effects should be enabled. |
74 enum PlatformEffectsMask { | 75 enum PlatformEffectsMask { |
75 NO_EFFECTS = 0x0, | 76 NO_EFFECTS = 0x0, |
76 ECHO_CANCELLER = 0x1, | 77 ECHO_CANCELLER = 0x1, |
77 DUCKING = 0x2, // Enables ducking if the OS supports it. | 78 DUCKING = 0x2, // Enables ducking if the OS supports it. |
78 KEYBOARD_MIC = 0x4, | 79 KEYBOARD_MIC = 0x4, |
79 HOTWORD = 0x8, | 80 HOTWORD = 0x8, |
80 }; | 81 }; |
81 | 82 |
82 AudioParameters(); | 83 AudioParameters(); |
83 AudioParameters(Format format, ChannelLayout channel_layout, | 84 AudioParameters( |
84 int sample_rate, int bits_per_sample, | 85 Format format, |
85 int frames_per_buffer); | 86 ChannelLayout channel_layout, |
86 AudioParameters(Format format, ChannelLayout channel_layout, | 87 int sample_rate, |
87 int sample_rate, int bits_per_sample, | 88 int bits_per_sample, |
88 int frames_per_buffer, int effects); | 89 int frames_per_buffer, |
89 AudioParameters(Format format, ChannelLayout channel_layout, | 90 const std::vector<Point>& mic_positions = std::vector<Point>(), |
90 int channels, int sample_rate, int bits_per_sample, | 91 int effects = NO_EFFECTS); |
91 int frames_per_buffer, int effects); | 92 AudioParameters( |
| 93 Format format, |
| 94 int channels, |
| 95 ChannelLayout channel_layout, |
| 96 int sample_rate, |
| 97 int bits_per_sample, |
| 98 int frames_per_buffer, |
| 99 const std::vector<Point>& mic_positions = std::vector<Point>(), |
| 100 int effects = NO_EFFECTS); |
| 101 |
| 102 ~AudioParameters(); |
92 | 103 |
93 void Reset(Format format, ChannelLayout channel_layout, | 104 void Reset(Format format, ChannelLayout channel_layout, |
94 int channels, int sample_rate, int bits_per_sample, | 105 int channels, int sample_rate, int bits_per_sample, |
95 int frames_per_buffer); | 106 int frames_per_buffer); |
96 | 107 |
97 // Checks that all values are in the expected range. All limits are specified | 108 // Checks that all values are in the expected range. All limits are specified |
98 // in media::Limits. | 109 // in media::Limits. |
99 bool IsValid() const; | 110 bool IsValid() const; |
100 | 111 |
101 // Returns a human-readable string describing |*this|. For debugging & test | 112 // Returns a human-readable string describing |*this|. For debugging & test |
(...skipping 16 matching lines...) Expand all Loading... |
118 // Comparison with other AudioParams. | 129 // Comparison with other AudioParams. |
119 bool Equals(const AudioParameters& other) const; | 130 bool Equals(const AudioParameters& other) const; |
120 | 131 |
121 Format format() const { return format_; } | 132 Format format() const { return format_; } |
122 ChannelLayout channel_layout() const { return channel_layout_; } | 133 ChannelLayout channel_layout() const { return channel_layout_; } |
123 int sample_rate() const { return sample_rate_; } | 134 int sample_rate() const { return sample_rate_; } |
124 int bits_per_sample() const { return bits_per_sample_; } | 135 int bits_per_sample() const { return bits_per_sample_; } |
125 int frames_per_buffer() const { return frames_per_buffer_; } | 136 int frames_per_buffer() const { return frames_per_buffer_; } |
126 int channels() const { return channels_; } | 137 int channels() const { return channels_; } |
127 int effects() const { return effects_; } | 138 int effects() const { return effects_; } |
| 139 const std::vector<Point>& mic_positions() const { return mic_positions_; } |
128 | 140 |
129 private: | 141 private: |
130 // These members are mutable to support entire struct assignment. They should | 142 // These members are mutable to support entire struct assignment. They should |
131 // not be mutated individually. | 143 // not be mutated individually. |
132 Format format_; // Format of the stream. | 144 Format format_; // Format of the stream. |
133 ChannelLayout channel_layout_; // Order of surround sound channels. | 145 ChannelLayout channel_layout_; // Order of surround sound channels. |
134 int sample_rate_; // Sampling frequency/rate. | 146 int sample_rate_; // Sampling frequency/rate. |
135 int bits_per_sample_; // Number of bits per sample. | 147 int bits_per_sample_; // Number of bits per sample. |
136 int frames_per_buffer_; // Number of frames in a buffer. | 148 int frames_per_buffer_; // Number of frames in a buffer. |
137 | 149 |
138 int channels_; // Number of channels. Value set based on | 150 int channels_; // Number of channels. Value set based on |
139 // |channel_layout|. | 151 // |channel_layout|. |
| 152 |
| 153 // Microphone positions using Cartesian coordinates: |
| 154 // x: the horizontal dimension, with positive to the right from the camera's |
| 155 // perspective. |
| 156 // y: the depth dimension, with positive forward from the camera's |
| 157 // perspective. |
| 158 // z: the vertical dimension, with positive upwards. |
| 159 // |
| 160 // Usually, the center of the microphone array will be treated as the origin |
| 161 // (often the position of the camera). |
| 162 // |
| 163 // An empty vector indicates unknown positions. |
| 164 std::vector<Point> mic_positions_; |
| 165 |
140 int effects_; // Bitmask using PlatformEffectsMask. | 166 int effects_; // Bitmask using PlatformEffectsMask. |
141 }; | 167 }; |
142 | 168 |
143 // Comparison is useful when AudioParameters is used with std structures. | 169 // Comparison is useful when AudioParameters is used with std structures. |
144 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { | 170 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { |
145 if (a.format() != b.format()) | 171 if (a.format() != b.format()) |
146 return a.format() < b.format(); | 172 return a.format() < b.format(); |
147 if (a.channels() != b.channels()) | 173 if (a.channels() != b.channels()) |
148 return a.channels() < b.channels(); | 174 return a.channels() < b.channels(); |
149 if (a.sample_rate() != b.sample_rate()) | 175 if (a.sample_rate() != b.sample_rate()) |
150 return a.sample_rate() < b.sample_rate(); | 176 return a.sample_rate() < b.sample_rate(); |
151 if (a.bits_per_sample() != b.bits_per_sample()) | 177 if (a.bits_per_sample() != b.bits_per_sample()) |
152 return a.bits_per_sample() < b.bits_per_sample(); | 178 return a.bits_per_sample() < b.bits_per_sample(); |
153 return a.frames_per_buffer() < b.frames_per_buffer(); | 179 return a.frames_per_buffer() < b.frames_per_buffer(); |
154 } | 180 } |
155 | 181 |
156 } // namespace media | 182 } // namespace media |
157 | 183 |
158 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 184 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
OLD | NEW |