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

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

Issue 1228823003: Update audio code to use size_t more correctly, webrtc/modules/audio_device/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments Created 5 years, 4 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_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H
12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H 12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H
13 13
14 #include <stddef.h>
15
14 #include "webrtc/typedefs.h" 16 #include "webrtc/typedefs.h"
15 17
16 namespace webrtc { 18 namespace webrtc {
17 19
18 static const int kAdmMaxDeviceNameSize = 128; 20 static const int kAdmMaxDeviceNameSize = 128;
19 static const int kAdmMaxFileNameSize = 512; 21 static const int kAdmMaxFileNameSize = 512;
20 static const int kAdmMaxGuidSize = 128; 22 static const int kAdmMaxGuidSize = 128;
21 23
22 static const int kAdmMinPlayoutBufferSizeMs = 10; 24 static const int kAdmMinPlayoutBufferSizeMs = 10;
23 static const int kAdmMaxPlayoutBufferSizeMs = 250; 25 static const int kAdmMaxPlayoutBufferSizeMs = 250;
(...skipping 14 matching lines...) Expand all
38 virtual ~AudioDeviceObserver() {} 40 virtual ~AudioDeviceObserver() {}
39 }; 41 };
40 42
41 // ---------------------------------------------------------------------------- 43 // ----------------------------------------------------------------------------
42 // AudioTransport 44 // AudioTransport
43 // ---------------------------------------------------------------------------- 45 // ----------------------------------------------------------------------------
44 46
45 class AudioTransport { 47 class AudioTransport {
46 public: 48 public:
47 virtual int32_t RecordedDataIsAvailable(const void* audioSamples, 49 virtual int32_t RecordedDataIsAvailable(const void* audioSamples,
48 const uint32_t nSamples, 50 const size_t nSamples,
49 const uint8_t nBytesPerSample, 51 const size_t nBytesPerSample,
50 const uint8_t nChannels, 52 const uint8_t nChannels,
51 const uint32_t samplesPerSec, 53 const uint32_t samplesPerSec,
52 const uint32_t totalDelayMS, 54 const uint32_t totalDelayMS,
53 const int32_t clockDrift, 55 const int32_t clockDrift,
54 const uint32_t currentMicLevel, 56 const uint32_t currentMicLevel,
55 const bool keyPressed, 57 const bool keyPressed,
56 uint32_t& newMicLevel) = 0; 58 uint32_t& newMicLevel) = 0;
57 59
58 virtual int32_t NeedMorePlayData(const uint32_t nSamples, 60 virtual int32_t NeedMorePlayData(const size_t nSamples,
59 const uint8_t nBytesPerSample, 61 const size_t nBytesPerSample,
60 const uint8_t nChannels, 62 const uint8_t nChannels,
61 const uint32_t samplesPerSec, 63 const uint32_t samplesPerSec,
62 void* audioSamples, 64 void* audioSamples,
63 uint32_t& nSamplesOut, 65 size_t& nSamplesOut,
64 int64_t* elapsed_time_ms, 66 int64_t* elapsed_time_ms,
65 int64_t* ntp_time_ms) = 0; 67 int64_t* ntp_time_ms) = 0;
66 68
67 // Method to pass captured data directly and unmixed to network channels. 69 // Method to pass captured data directly and unmixed to network channels.
68 // |channel_ids| contains a list of VoE channels which are the 70 // |channel_ids| contains a list of VoE channels which are the
69 // sinks to the capture data. |audio_delay_milliseconds| is the sum of 71 // sinks to the capture data. |audio_delay_milliseconds| is the sum of
70 // recording delay and playout delay of the hardware. |current_volume| is 72 // recording delay and playout delay of the hardware. |current_volume| is
71 // in the range of [0, 255], representing the current microphone analog 73 // in the range of [0, 255], representing the current microphone analog
72 // volume. |key_pressed| is used by the typing detection. 74 // volume. |key_pressed| is used by the typing detection.
73 // |need_audio_processing| specify if the data needs to be processed by APM. 75 // |need_audio_processing| specify if the data needs to be processed by APM.
74 // Currently WebRtc supports only one APM, and Chrome will make sure only 76 // Currently WebRtc supports only one APM, and Chrome will make sure only
75 // one stream goes through APM. When |need_audio_processing| is false, the 77 // one stream goes through APM. When |need_audio_processing| is false, the
76 // values of |audio_delay_milliseconds|, |current_volume| and |key_pressed| 78 // values of |audio_delay_milliseconds|, |current_volume| and |key_pressed|
77 // will be ignored. 79 // will be ignored.
78 // The return value is the new microphone volume, in the range of |0, 255]. 80 // The return value is the new microphone volume, in the range of |0, 255].
79 // When the volume does not need to be updated, it returns 0. 81 // When the volume does not need to be updated, it returns 0.
80 // TODO(xians): Remove this interface after Chrome and Libjingle switches 82 // TODO(xians): Remove this interface after Chrome and Libjingle switches
81 // to OnData(). 83 // to OnData().
82 virtual int OnDataAvailable(const int voe_channels[], 84 virtual int OnDataAvailable(const int voe_channels[],
83 int number_of_voe_channels, 85 int number_of_voe_channels,
84 const int16_t* audio_data, 86 const int16_t* audio_data,
85 int sample_rate, 87 int sample_rate,
86 int number_of_channels, 88 int number_of_channels,
87 int number_of_frames, 89 size_t number_of_frames,
88 int audio_delay_milliseconds, 90 int audio_delay_milliseconds,
89 int current_volume, 91 int current_volume,
90 bool key_pressed, 92 bool key_pressed,
91 bool need_audio_processing) { 93 bool need_audio_processing) {
92 return 0; 94 return 0;
93 } 95 }
94 96
95 // Method to pass the captured audio data to the specific VoE channel. 97 // Method to pass the captured audio data to the specific VoE channel.
96 // |voe_channel| is the id of the VoE channel which is the sink to the 98 // |voe_channel| is the id of the VoE channel which is the sink to the
97 // capture data. 99 // capture data.
98 // TODO(xians): Remove this interface after Libjingle switches to 100 // TODO(xians): Remove this interface after Libjingle switches to
99 // PushCaptureData(). 101 // PushCaptureData().
100 virtual void OnData(int voe_channel, 102 virtual void OnData(int voe_channel,
101 const void* audio_data, 103 const void* audio_data,
102 int bits_per_sample, 104 int bits_per_sample,
103 int sample_rate, 105 int sample_rate,
104 int number_of_channels, 106 int number_of_channels,
105 int number_of_frames) {} 107 size_t number_of_frames) {}
106 108
107 // Method to push the captured audio data to the specific VoE channel. 109 // Method to push the captured audio data to the specific VoE channel.
108 // The data will not undergo audio processing. 110 // The data will not undergo audio processing.
109 // |voe_channel| is the id of the VoE channel which is the sink to the 111 // |voe_channel| is the id of the VoE channel which is the sink to the
110 // capture data. 112 // capture data.
111 // TODO(xians): Make the interface pure virtual after Libjingle 113 // TODO(xians): Make the interface pure virtual after Libjingle
112 // has its implementation. 114 // has its implementation.
113 virtual void PushCaptureData(int voe_channel, 115 virtual void PushCaptureData(int voe_channel,
114 const void* audio_data, 116 const void* audio_data,
115 int bits_per_sample, 117 int bits_per_sample,
116 int sample_rate, 118 int sample_rate,
117 int number_of_channels, 119 int number_of_channels,
118 int number_of_frames) {} 120 size_t number_of_frames) {}
119 121
120 // Method to pull mixed render audio data from all active VoE channels. 122 // Method to pull mixed render audio data from all active VoE channels.
121 // The data will not be passed as reference for audio processing internally. 123 // The data will not be passed as reference for audio processing internally.
122 // TODO(xians): Support getting the unmixed render data from specific VoE 124 // TODO(xians): Support getting the unmixed render data from specific VoE
123 // channel. 125 // channel.
124 virtual void PullRenderData(int bits_per_sample, 126 virtual void PullRenderData(int bits_per_sample,
125 int sample_rate, 127 int sample_rate,
126 int number_of_channels, 128 int number_of_channels,
127 int number_of_frames, 129 size_t number_of_frames,
128 void* audio_data, 130 void* audio_data,
129 int64_t* elapsed_time_ms, 131 int64_t* elapsed_time_ms,
130 int64_t* ntp_time_ms) {} 132 int64_t* ntp_time_ms) {}
131 133
132 protected: 134 protected:
133 virtual ~AudioTransport() {} 135 virtual ~AudioTransport() {}
134 }; 136 };
135 137
136 // Helper class for storage of fundamental audio parameters such as sample rate, 138 // Helper class for storage of fundamental audio parameters such as sample rate,
137 // number of channels, native buffer size etc. 139 // number of channels, native buffer size etc.
138 // Note that one audio frame can contain more than one channel sample and each 140 // Note that one audio frame can contain more than one channel sample and each
139 // sample is assumed to be a 16-bit PCM sample. Hence, one audio frame in 141 // sample is assumed to be a 16-bit PCM sample. Hence, one audio frame in
140 // stereo contains 2 * (16/8) = 4 bytes of data. 142 // stereo contains 2 * (16/8) = 4 bytes of data.
141 class AudioParameters { 143 class AudioParameters {
142 public: 144 public:
143 // This implementation does only support 16-bit PCM samples. 145 // This implementation does only support 16-bit PCM samples.
144 enum { kBitsPerSample = 16 }; 146 enum { kBitsPerSample = 16 };
145 AudioParameters() 147 AudioParameters()
146 : sample_rate_(0), 148 : sample_rate_(0),
147 channels_(0), 149 channels_(0),
148 frames_per_buffer_(0), 150 frames_per_buffer_(0),
149 frames_per_10ms_buffer_(0) {} 151 frames_per_10ms_buffer_(0) {}
150 AudioParameters(int sample_rate, int channels, int frames_per_buffer) 152 AudioParameters(int sample_rate, int channels, int frames_per_buffer)
151 : sample_rate_(sample_rate), 153 : sample_rate_(sample_rate),
152 channels_(channels), 154 channels_(channels),
153 frames_per_buffer_(frames_per_buffer), 155 frames_per_buffer_(frames_per_buffer),
154 frames_per_10ms_buffer_(sample_rate / 100) {} 156 frames_per_10ms_buffer_(static_cast<size_t>(sample_rate / 100)) {}
155 void reset(int sample_rate, int channels, int frames_per_buffer) { 157 void reset(int sample_rate, int channels, int frames_per_buffer) {
156 sample_rate_ = sample_rate; 158 sample_rate_ = sample_rate;
157 channels_ = channels; 159 channels_ = channels;
158 frames_per_buffer_ = frames_per_buffer; 160 frames_per_buffer_ = frames_per_buffer;
159 frames_per_10ms_buffer_ = (sample_rate / 100); 161 frames_per_10ms_buffer_ = static_cast<size_t>(sample_rate / 100);
160 } 162 }
161 int bits_per_sample() const { return kBitsPerSample; } 163 int bits_per_sample() const { return kBitsPerSample; }
162 int sample_rate() const { return sample_rate_; } 164 int sample_rate() const { return sample_rate_; }
163 int channels() const { return channels_; } 165 int channels() const { return channels_; }
164 int frames_per_buffer() const { return frames_per_buffer_; } 166 int frames_per_buffer() const { return frames_per_buffer_; }
165 int frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; } 167 size_t frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; }
166 bool is_valid() const { 168 bool is_valid() const {
167 return ((sample_rate_ > 0) && (channels_ > 0) && (frames_per_buffer_ > 0)); 169 return ((sample_rate_ > 0) && (channels_ > 0) && (frames_per_buffer_ > 0));
168 } 170 }
169 int GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; } 171 int GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; }
170 int GetBytesPerBuffer() const { 172 int GetBytesPerBuffer() const {
171 return frames_per_buffer_ * GetBytesPerFrame(); 173 return frames_per_buffer_ * GetBytesPerFrame();
172 } 174 }
173 int GetBytesPer10msBuffer() const { 175 size_t GetBytesPer10msBuffer() const {
174 return frames_per_10ms_buffer_ * GetBytesPerFrame(); 176 return frames_per_10ms_buffer_ * GetBytesPerFrame();
175 } 177 }
176 float GetBufferSizeInMilliseconds() const { 178 float GetBufferSizeInMilliseconds() const {
177 if (sample_rate_ == 0) 179 if (sample_rate_ == 0)
178 return 0.0f; 180 return 0.0f;
179 return frames_per_buffer_ / (sample_rate_ / 1000.0f); 181 return frames_per_buffer_ / (sample_rate_ / 1000.0f);
180 } 182 }
181 183
182 private: 184 private:
183 int sample_rate_; 185 int sample_rate_;
184 int channels_; 186 int channels_;
185 int frames_per_buffer_; 187 int frames_per_buffer_;
186 int frames_per_10ms_buffer_; 188 size_t frames_per_10ms_buffer_;
187 }; 189 };
188 190
189 } // namespace webrtc 191 } // namespace webrtc
190 192
191 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H 193 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/dummy/file_audio_device.cc ('k') | webrtc/modules/audio_device/mock_audio_device_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698