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

Side by Side Diff: webrtc/modules/audio_device/include/audio_device_defines.h

Issue 1254883002: Refactor the AudioDevice for iOS and improve the performance and stability (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Extended unit test for FineAudioBuffer with recorded data Created 5 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H 11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFINES_H_
12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H 12 #define WEBRTC_MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFINES_H_
13 13
14 #include <stddef.h> 14 #include <stddef.h>
15 15
16 #include "webrtc/typedefs.h" 16 #include "webrtc/typedefs.h"
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 static const int kAdmMaxDeviceNameSize = 128; 20 static const int kAdmMaxDeviceNameSize = 128;
21 static const int kAdmMaxFileNameSize = 512; 21 static const int kAdmMaxFileNameSize = 512;
22 static const int kAdmMaxGuidSize = 128; 22 static const int kAdmMaxGuidSize = 128;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 channels_(channels), 154 channels_(channels),
155 frames_per_buffer_(frames_per_buffer), 155 frames_per_buffer_(frames_per_buffer),
156 frames_per_10ms_buffer_(static_cast<size_t>(sample_rate / 100)) {} 156 frames_per_10ms_buffer_(static_cast<size_t>(sample_rate / 100)) {}
157 void reset(int sample_rate, int channels, size_t frames_per_buffer) { 157 void reset(int sample_rate, int channels, size_t frames_per_buffer) {
158 sample_rate_ = sample_rate; 158 sample_rate_ = sample_rate;
159 channels_ = channels; 159 channels_ = channels;
160 frames_per_buffer_ = frames_per_buffer; 160 frames_per_buffer_ = frames_per_buffer;
161 frames_per_10ms_buffer_ = static_cast<size_t>(sample_rate / 100); 161 frames_per_10ms_buffer_ = static_cast<size_t>(sample_rate / 100);
162 } 162 }
163 size_t bits_per_sample() const { return kBitsPerSample; } 163 size_t bits_per_sample() const { return kBitsPerSample; }
164 void reset(int sample_rate, int channels, double milliseconds_per_buffer) {
tkchin_webrtc 2015/09/01 20:54:50 nit: ms_per_buffer is prob ok
henrika_webrtc 2015/09/03 13:44:41 Done.
165 reset(sample_rate, channels,
166 static_cast<size_t>(sample_rate * milliseconds_per_buffer + 0.5));
167 }
168 void reset(int sample_rate, int channels) {
169 reset(sample_rate, channels, static_cast<size_t>(0));
tkchin_webrtc 2015/09/01 20:54:50 nit: 0u?
henrika_webrtc 2015/09/03 13:44:41 pkasting just landed this static_cast in a CL wher
170 }
164 int sample_rate() const { return sample_rate_; } 171 int sample_rate() const { return sample_rate_; }
165 int channels() const { return channels_; } 172 int channels() const { return channels_; }
166 size_t frames_per_buffer() const { return frames_per_buffer_; } 173 size_t frames_per_buffer() const { return frames_per_buffer_; }
167 size_t frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; } 174 size_t frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; }
168 bool is_valid() const {
169 return ((sample_rate_ > 0) && (channels_ > 0) && (frames_per_buffer_ > 0));
170 }
171 size_t GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; } 175 size_t GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; }
172 size_t GetBytesPerBuffer() const { 176 size_t GetBytesPerBuffer() const {
173 return frames_per_buffer_ * GetBytesPerFrame(); 177 return frames_per_buffer_ * GetBytesPerFrame();
174 } 178 }
179 // The WebRTC audio device buffer (ADB) only requires that the sample rate
180 // and number of channels are configured. Hence, to be "valid", only these
181 // two attributes must be set.
182 bool is_valid() const { return ((sample_rate_ > 0) && (channels_ > 0)); }
183 // Most platforms also require that a native buffer size is defined.
184 // An audio parameter instance is considered to be "complete" if it is both
185 // "valid" (can be used by the ADB) and also has a native frame size.
186 bool is_complete() const { return (is_valid() && (frames_per_buffer_ > 0)); }
tkchin_webrtc 2015/09/01 20:54:50 When is it useful to be valid but incomplete?
henrika_webrtc 2015/09/03 13:44:41 Good question. Perhaps the current notation is not
175 size_t GetBytesPer10msBuffer() const { 187 size_t GetBytesPer10msBuffer() const {
176 return frames_per_10ms_buffer_ * GetBytesPerFrame(); 188 return frames_per_10ms_buffer_ * GetBytesPerFrame();
177 } 189 }
178 float GetBufferSizeInMilliseconds() const { 190 double GetBufferSizeInMilliseconds() const {
179 if (sample_rate_ == 0) 191 if (sample_rate_ == 0)
180 return 0.0f; 192 return 0.0;
181 return frames_per_buffer_ / (sample_rate_ / 1000.0f); 193 return frames_per_buffer_ / (sample_rate_ / 1000.0);
194 }
195 double GetBufferSizeInSeconds() const {
196 if (sample_rate_ == 0)
197 return 0.0;
198 return static_cast<double>(frames_per_buffer_) / (sample_rate_);
182 } 199 }
183 200
184 private: 201 private:
185 int sample_rate_; 202 int sample_rate_;
186 int channels_; 203 int channels_;
187 size_t frames_per_buffer_; 204 size_t frames_per_buffer_;
188 size_t frames_per_10ms_buffer_; 205 size_t frames_per_10ms_buffer_;
189 }; 206 };
190 207
191 } // namespace webrtc 208 } // namespace webrtc
192 209
193 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H 210 #endif // WEBRTC_MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFINES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698