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

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

Issue 1316523002: Convert channel counts to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Rebase onto cleanup change Created 4 years, 11 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
(...skipping 26 matching lines...) Expand all
37 virtual void OnWarningIsReported(const WarningCode warning) = 0; 37 virtual void OnWarningIsReported(const WarningCode warning) = 0;
38 38
39 protected: 39 protected:
40 virtual ~AudioDeviceObserver() {} 40 virtual ~AudioDeviceObserver() {}
41 }; 41 };
42 42
43 // ---------------------------------------------------------------------------- 43 // ----------------------------------------------------------------------------
44 // AudioTransport 44 // AudioTransport
45 // ---------------------------------------------------------------------------- 45 // ----------------------------------------------------------------------------
46 46
47 class AudioTransport { 47 class AudioTransport {
henrika_webrtc 2015/12/29 09:00:57 Note that this interface is used in Chrome and in
48 public: 48 public:
49 virtual int32_t RecordedDataIsAvailable(const void* audioSamples, 49 virtual int32_t RecordedDataIsAvailable(const void* audioSamples,
50 const size_t nSamples, 50 const size_t nSamples,
51 const size_t nBytesPerSample, 51 const size_t nBytesPerSample,
52 const uint8_t nChannels, 52 const size_t nChannels,
53 const uint32_t samplesPerSec, 53 const uint32_t samplesPerSec,
54 const uint32_t totalDelayMS, 54 const uint32_t totalDelayMS,
55 const int32_t clockDrift, 55 const int32_t clockDrift,
56 const uint32_t currentMicLevel, 56 const uint32_t currentMicLevel,
57 const bool keyPressed, 57 const bool keyPressed,
58 uint32_t& newMicLevel) = 0; 58 uint32_t& newMicLevel) = 0;
59 59
60 virtual int32_t NeedMorePlayData(const size_t nSamples, 60 virtual int32_t NeedMorePlayData(const size_t nSamples,
61 const size_t nBytesPerSample, 61 const size_t nBytesPerSample,
62 const uint8_t nChannels, 62 const size_t nChannels,
63 const uint32_t samplesPerSec, 63 const uint32_t samplesPerSec,
64 void* audioSamples, 64 void* audioSamples,
65 size_t& nSamplesOut, 65 size_t& nSamplesOut,
66 int64_t* elapsed_time_ms, 66 int64_t* elapsed_time_ms,
67 int64_t* ntp_time_ms) = 0; 67 int64_t* ntp_time_ms) = 0;
68 68
69 // Method to pass captured data directly and unmixed to network channels. 69 // Method to pass captured data directly and unmixed to network channels.
70 // |channel_ids| contains a list of VoE channels which are the 70 // |channel_ids| contains a list of VoE channels which are the
71 // 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
72 // recording delay and playout delay of the hardware. |current_volume| is 72 // recording delay and playout delay of the hardware. |current_volume| is
73 // in the range of [0, 255], representing the current microphone analog 73 // in the range of [0, 255], representing the current microphone analog
74 // volume. |key_pressed| is used by the typing detection. 74 // volume. |key_pressed| is used by the typing detection.
75 // |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.
76 // 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
77 // 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
78 // values of |audio_delay_milliseconds|, |current_volume| and |key_pressed| 78 // values of |audio_delay_milliseconds|, |current_volume| and |key_pressed|
79 // will be ignored. 79 // will be ignored.
80 // 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].
81 // 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.
82 // TODO(xians): Remove this interface after Chrome and Libjingle switches 82 // TODO(xians): Remove this interface after Chrome and Libjingle switches
83 // to OnData(). 83 // to OnData().
84 virtual int OnDataAvailable(const int voe_channels[], 84 virtual int OnDataAvailable(const int voe_channels[],
85 int number_of_voe_channels, 85 size_t number_of_voe_channels,
86 const int16_t* audio_data, 86 const int16_t* audio_data,
87 int sample_rate, 87 int sample_rate,
88 int number_of_channels, 88 size_t number_of_channels,
89 size_t number_of_frames, 89 size_t number_of_frames,
90 int audio_delay_milliseconds, 90 int audio_delay_milliseconds,
91 int current_volume, 91 int current_volume,
92 bool key_pressed, 92 bool key_pressed,
93 bool need_audio_processing) { 93 bool need_audio_processing) {
94 return 0; 94 return 0;
95 } 95 }
96 96
97 // 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.
98 // |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
99 // capture data. 99 // capture data.
100 // TODO(xians): Remove this interface after Libjingle switches to 100 // TODO(xians): Remove this interface after Libjingle switches to
101 // PushCaptureData(). 101 // PushCaptureData().
102 virtual void OnData(int voe_channel, 102 virtual void OnData(int voe_channel,
103 const void* audio_data, 103 const void* audio_data,
104 int bits_per_sample, 104 int bits_per_sample,
105 int sample_rate, 105 int sample_rate,
106 int number_of_channels, 106 size_t number_of_channels,
107 size_t number_of_frames) {} 107 size_t number_of_frames) {}
108 108
109 // 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.
110 // The data will not undergo audio processing. 110 // The data will not undergo audio processing.
111 // |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
112 // capture data. 112 // capture data.
113 // TODO(xians): Make the interface pure virtual after Libjingle 113 // TODO(xians): Make the interface pure virtual after Libjingle
114 // has its implementation. 114 // has its implementation.
115 virtual void PushCaptureData(int voe_channel, 115 virtual void PushCaptureData(int voe_channel,
116 const void* audio_data, 116 const void* audio_data,
117 int bits_per_sample, 117 int bits_per_sample,
118 int sample_rate, 118 int sample_rate,
119 int number_of_channels, 119 size_t number_of_channels,
120 size_t number_of_frames) {} 120 size_t number_of_frames) {}
121 121
122 // 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.
123 // 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.
124 // TODO(xians): Support getting the unmixed render data from specific VoE 124 // TODO(xians): Support getting the unmixed render data from specific VoE
125 // channel. 125 // channel.
126 virtual void PullRenderData(int bits_per_sample, 126 virtual void PullRenderData(int bits_per_sample,
127 int sample_rate, 127 int sample_rate,
128 int number_of_channels, 128 size_t number_of_channels,
henrika_webrtc 2015/12/29 09:00:57 I think this change will break Chrome here: https
129 size_t number_of_frames, 129 size_t number_of_frames,
130 void* audio_data, 130 void* audio_data,
131 int64_t* elapsed_time_ms, 131 int64_t* elapsed_time_ms,
132 int64_t* ntp_time_ms) {} 132 int64_t* ntp_time_ms) {}
133 133
134 protected: 134 protected:
135 virtual ~AudioTransport() {} 135 virtual ~AudioTransport() {}
136 }; 136 };
137 137
138 // 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,
139 // number of channels, native buffer size etc. 139 // number of channels, native buffer size etc.
140 // 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
141 // 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
142 // stereo contains 2 * (16/8) = 4 bytes of data. 142 // stereo contains 2 * (16/8) = 4 bytes of data.
143 class AudioParameters { 143 class AudioParameters {
144 public: 144 public:
145 // This implementation does only support 16-bit PCM samples. 145 // This implementation does only support 16-bit PCM samples.
146 static const size_t kBitsPerSample = 16; 146 static const size_t kBitsPerSample = 16;
147 AudioParameters() 147 AudioParameters()
148 : sample_rate_(0), 148 : sample_rate_(0),
149 channels_(0), 149 channels_(0),
150 frames_per_buffer_(0), 150 frames_per_buffer_(0),
151 frames_per_10ms_buffer_(0) {} 151 frames_per_10ms_buffer_(0) {}
152 AudioParameters(int sample_rate, int channels, size_t frames_per_buffer) 152 AudioParameters(int sample_rate, size_t channels, size_t frames_per_buffer)
153 : sample_rate_(sample_rate), 153 : sample_rate_(sample_rate),
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, size_t 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 ms_per_buffer) { 164 void reset(int sample_rate, size_t channels, double ms_per_buffer) {
165 reset(sample_rate, channels, 165 reset(sample_rate, channels,
166 static_cast<size_t>(sample_rate * ms_per_buffer + 0.5)); 166 static_cast<size_t>(sample_rate * ms_per_buffer + 0.5));
167 } 167 }
168 void reset(int sample_rate, int channels) { 168 void reset(int sample_rate, size_t channels) {
169 reset(sample_rate, channels, static_cast<size_t>(0)); 169 reset(sample_rate, channels, static_cast<size_t>(0));
170 } 170 }
171 int sample_rate() const { return sample_rate_; } 171 int sample_rate() const { return sample_rate_; }
172 int channels() const { return channels_; } 172 size_t channels() const { return channels_; }
173 size_t frames_per_buffer() const { return frames_per_buffer_; } 173 size_t frames_per_buffer() const { return frames_per_buffer_; }
174 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_; }
175 size_t GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; } 175 size_t GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; }
176 size_t GetBytesPerBuffer() const { 176 size_t GetBytesPerBuffer() const {
177 return frames_per_buffer_ * GetBytesPerFrame(); 177 return frames_per_buffer_ * GetBytesPerFrame();
178 } 178 }
179 // The WebRTC audio device buffer (ADB) only requires that the sample rate 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 180 // and number of channels are configured. Hence, to be "valid", only these
181 // two attributes must be set. 181 // two attributes must be set.
182 bool is_valid() const { return ((sample_rate_ > 0) && (channels_ > 0)); } 182 bool is_valid() const { return ((sample_rate_ > 0) && (channels_ > 0)); }
(...skipping 10 matching lines...) Expand all
193 return frames_per_buffer_ / (sample_rate_ / 1000.0); 193 return frames_per_buffer_ / (sample_rate_ / 1000.0);
194 } 194 }
195 double GetBufferSizeInSeconds() const { 195 double GetBufferSizeInSeconds() const {
196 if (sample_rate_ == 0) 196 if (sample_rate_ == 0)
197 return 0.0; 197 return 0.0;
198 return static_cast<double>(frames_per_buffer_) / (sample_rate_); 198 return static_cast<double>(frames_per_buffer_) / (sample_rate_);
199 } 199 }
200 200
201 private: 201 private:
202 int sample_rate_; 202 int sample_rate_;
203 int channels_; 203 size_t channels_;
204 size_t frames_per_buffer_; 204 size_t frames_per_buffer_;
205 size_t frames_per_10ms_buffer_; 205 size_t frames_per_10ms_buffer_;
206 }; 206 };
207 207
208 } // namespace webrtc 208 } // namespace webrtc
209 209
210 #endif // WEBRTC_MODULES_AUDIO_DEVICE_INCLUDE_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