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

Side by Side Diff: webrtc/modules/audio_device/audio_transport_capture.cc

Issue 2753453002: Adding AudioDeviceDataObserver interface (Closed)
Patch Set: Remove some unnecessary comments Created 3 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_device/include/audio_transport_capture.h"
12
13 namespace webrtc {
14
15 namespace {
16
17 // A wrapper over AudioDeviceModule that registers itself as AudioTransport
18 // callback and redirects the PCM data to AudioTransportCapture callback.
19 class ADMWrapper : public AudioDeviceModule, public AudioTransport {
the sun 2017/04/05 15:49:39 nit: final class
lliuu 2017/04/05 19:45:46 Unfortunately ADMWrapper cannot be final due to Re
the sun 2017/04/06 06:58:37 Ah!
20 public:
21 explicit ADMWrapper(const int32_t id,
the sun 2017/04/05 15:49:39 nit: explicit not needed with 3 args
lliuu 2017/04/05 19:45:46 Done.
22 const AudioLayer audio_layer,
23 AudioTransportCapture* capture_cb)
24 : impl_(AudioDeviceModule::Create(id, audio_layer)),
25 capture_callback_(capture_cb) {
26 // Register self as the audio transport callback for underlying ADM impl.
27 auto res = impl_->RegisterAudioCallback(this);
28 is_valid_ = (impl_.get() != nullptr) && (res == 0);
29 }
30 virtual ~ADMWrapper() {
31 audio_transport_ = nullptr;
32 capture_callback_ = nullptr;
33 }
34
35 bool IsValid() { return is_valid_; }
36
37 // RefCountedModule methods overrides.
38 int64_t TimeUntilNextProcess() override {
39 return impl_->TimeUntilNextProcess();
40 }
41 void Process() override { return impl_->Process(); }
42
43 // AudioTransport methods overrides.
44 int32_t RecordedDataIsAvailable(const void* audioSamples,
45 const size_t nSamples,
46 const size_t nBytesPerSample,
47 const size_t nChannels,
48 const uint32_t samplesPerSec,
49 const uint32_t totalDelayMS,
50 const int32_t clockDrift,
51 const uint32_t currentMicLevel,
52 const bool keyPressed,
53 uint32_t& newMicLevel) override {
54 int32_t res = 0;
55 // Capture PCM data before sending to sink.
56 if (capture_callback_) {
57 capture_callback_->CaptureRecordedData(
58 audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec);
59 }
60
61 // Send to sink.
62 if (audio_transport_) {
63 res = audio_transport_->RecordedDataIsAvailable(
64 audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec,
65 totalDelayMS, clockDrift, currentMicLevel, keyPressed, newMicLevel);
66 }
67
68 return res;
69 }
70
71 int32_t NeedMorePlayData(const size_t nSamples,
72 const size_t nBytesPerSample,
73 const size_t nChannels,
74 const uint32_t samplesPerSec,
75 void* audioSamples,
76 size_t& nSamplesOut,
77 int64_t* elapsed_time_ms,
78 int64_t* ntp_time_ms) override {
79 int32_t res = 0;
80 // Request data from sink.
81 if (audio_transport_) {
82 res = audio_transport_->NeedMorePlayData(
83 nSamples, nBytesPerSample, nChannels, samplesPerSec, audioSamples,
84 nSamplesOut, elapsed_time_ms, ntp_time_ms);
85 }
86
87 // Capture after data requested.
88 if (capture_callback_) {
89 capture_callback_->CapturePlayoutData(
90 audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec);
91 }
92
93 return res;
94 }
95
96 void PushCaptureData(int voe_channel,
97 const void* audio_data,
98 int bits_per_sample,
99 int sample_rate,
100 size_t number_of_channels,
101 size_t number_of_frames) override {
102 if (audio_transport_) {
the sun 2017/04/05 15:49:39 Won't be called from the default ADM implementatio
lliuu 2017/04/05 19:45:46 Done.
103 audio_transport_->PushCaptureData(voe_channel, audio_data,
104 bits_per_sample, sample_rate,
105 number_of_channels, number_of_frames);
106 }
107 }
108
109 void PullRenderData(int bits_per_sample,
110 int sample_rate,
111 size_t number_of_channels,
112 size_t number_of_frames,
113 void* audio_data,
114 int64_t* elapsed_time_ms,
115 int64_t* ntp_time_ms) override {
116 if (audio_transport_) {
the sun 2017/04/05 15:49:39 Won't be called from the default ADM implementatio
lliuu 2017/04/05 19:45:46 Done.
lliuu 2017/04/05 19:45:46 Done.
117 audio_transport_->PullRenderData(
118 bits_per_sample, sample_rate, number_of_channels, number_of_frames,
119 audio_data, elapsed_time_ms, ntp_time_ms);
120 }
121 }
122
123 // Override AudioDeviceModule's RegisterAudioCallback method to remember the
124 // actual audio transport sink (e.g.: voice engine).
125 int32_t RegisterAudioCallback(AudioTransport* audioCallback) override {
the sun 2017/04/05 15:49:39 nit: no need to copy obsolete casing; use audio_ca
lliuu 2017/04/05 19:45:46 Done.
126 // Remember the audio callback to forward PCM data
127 audio_transport_ = audioCallback;
128 return 0;
129 }
130
131 // AudioDeviceModule pass through method overrides.
132 int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override {
133 return impl_->ActiveAudioLayer(audioLayer);
134 }
135 ErrorCode LastError() const override { return impl_->LastError(); }
136 int32_t RegisterEventObserver(AudioDeviceObserver* eventCallback) override {
137 return impl_->RegisterEventObserver(eventCallback);
138 }
139 int32_t Init() override { return impl_->Init(); }
140 int32_t Terminate() override { return impl_->Terminate(); }
141 bool Initialized() const override { return impl_->Initialized(); }
142 int16_t PlayoutDevices() override { return impl_->PlayoutDevices(); }
143 int16_t RecordingDevices() override { return impl_->RecordingDevices(); }
144 int32_t PlayoutDeviceName(uint16_t index,
145 char name[kAdmMaxDeviceNameSize],
146 char guid[kAdmMaxGuidSize]) override {
147 return impl_->PlayoutDeviceName(index, name, guid);
148 }
149 int32_t RecordingDeviceName(uint16_t index,
150 char name[kAdmMaxDeviceNameSize],
151 char guid[kAdmMaxGuidSize]) override {
152 return impl_->RecordingDeviceName(index, name, guid);
153 }
154 int32_t SetPlayoutDevice(uint16_t index) override {
155 return impl_->SetPlayoutDevice(index);
156 }
157 int32_t SetPlayoutDevice(WindowsDeviceType device) override {
158 return impl_->SetPlayoutDevice(device);
159 }
160 int32_t SetRecordingDevice(uint16_t index) override {
161 return impl_->SetRecordingDevice(index);
162 }
163 int32_t SetRecordingDevice(WindowsDeviceType device) override {
164 return impl_->SetRecordingDevice(device);
165 }
166 int32_t PlayoutIsAvailable(bool* available) override {
167 return impl_->PlayoutIsAvailable(available);
168 }
169 int32_t InitPlayout() override { return impl_->InitPlayout(); }
170 bool PlayoutIsInitialized() const override {
171 return impl_->PlayoutIsInitialized();
172 }
173 int32_t RecordingIsAvailable(bool* available) override {
174 return impl_->RecordingIsAvailable(available);
175 }
176 int32_t InitRecording() override { return impl_->InitRecording(); }
177 bool RecordingIsInitialized() const override {
178 return impl_->RecordingIsInitialized();
179 }
180 int32_t StartPlayout() override { return impl_->StartPlayout(); }
181 int32_t StopPlayout() override { return impl_->StopPlayout(); }
182 bool Playing() const override { return impl_->Playing(); }
183 int32_t StartRecording() override { return impl_->StartRecording(); }
184 int32_t StopRecording() override { return impl_->StopRecording(); }
185 bool Recording() const override { return impl_->Recording(); }
186 int32_t SetAGC(bool enable) override { return impl_->SetAGC(enable); }
187 bool AGC() const override { return impl_->AGC(); }
188 int32_t SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight) override {
189 return impl_->SetWaveOutVolume(volumeLeft, volumeRight);
190 }
191 int32_t WaveOutVolume(uint16_t* volumeLeft,
192 uint16_t* volumeRight) const override {
193 return impl_->WaveOutVolume(volumeLeft, volumeRight);
194 }
195 int32_t InitSpeaker() override { return impl_->InitSpeaker(); }
196 bool SpeakerIsInitialized() const override {
197 return impl_->SpeakerIsInitialized();
198 }
199 int32_t InitMicrophone() override { return impl_->InitMicrophone(); }
200 bool MicrophoneIsInitialized() const override {
201 return impl_->MicrophoneIsInitialized();
202 }
203 int32_t SpeakerVolumeIsAvailable(bool* available) override {
204 return impl_->SpeakerVolumeIsAvailable(available);
205 }
206 int32_t SetSpeakerVolume(uint32_t volume) override {
207 return impl_->SetSpeakerVolume(volume);
208 }
209 int32_t SpeakerVolume(uint32_t* volume) const override {
210 return impl_->SpeakerVolume(volume);
211 }
212 int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override {
213 return impl_->MaxSpeakerVolume(maxVolume);
214 }
215 int32_t MinSpeakerVolume(uint32_t* minVolume) const override {
216 return impl_->MinSpeakerVolume(minVolume);
217 }
218 int32_t SpeakerVolumeStepSize(uint16_t* stepSize) const override {
219 return impl_->SpeakerVolumeStepSize(stepSize);
220 }
221 int32_t MicrophoneVolumeIsAvailable(bool* available) override {
222 return impl_->MicrophoneVolumeIsAvailable(available);
223 }
224 int32_t SetMicrophoneVolume(uint32_t volume) override {
225 return impl_->SetMicrophoneVolume(volume);
226 }
227 int32_t MicrophoneVolume(uint32_t* volume) const override {
228 return impl_->MicrophoneVolume(volume);
229 }
230 int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override {
231 return impl_->MaxMicrophoneVolume(maxVolume);
232 }
233 int32_t MinMicrophoneVolume(uint32_t* minVolume) const override {
234 return impl_->MinMicrophoneVolume(minVolume);
235 }
236 int32_t MicrophoneVolumeStepSize(uint16_t* stepSize) const override {
237 return impl_->MicrophoneVolumeStepSize(stepSize);
238 }
239 int32_t SpeakerMuteIsAvailable(bool* available) override {
240 return impl_->SpeakerMuteIsAvailable(available);
241 }
242 int32_t SetSpeakerMute(bool enable) override {
243 return impl_->SetSpeakerMute(enable);
244 }
245 int32_t SpeakerMute(bool* enabled) const override {
246 return impl_->SpeakerMute(enabled);
247 }
248 int32_t MicrophoneMuteIsAvailable(bool* available) override {
249 return impl_->MicrophoneMuteIsAvailable(available);
250 }
251 int32_t SetMicrophoneMute(bool enable) override {
252 return impl_->SetMicrophoneMute(enable);
253 }
254 int32_t MicrophoneMute(bool* enabled) const override {
255 return impl_->MicrophoneMute(enabled);
256 }
257 int32_t MicrophoneBoostIsAvailable(bool* available) override {
258 return impl_->MicrophoneBoostIsAvailable(available);
259 }
260 int32_t SetMicrophoneBoost(bool enable) override {
261 return impl_->SetMicrophoneBoost(enable);
262 }
263 int32_t MicrophoneBoost(bool* enabled) const override {
264 return impl_->MicrophoneBoost(enabled);
265 }
266 int32_t StereoPlayoutIsAvailable(bool* available) const override {
267 return impl_->StereoPlayoutIsAvailable(available);
268 }
269 int32_t SetStereoPlayout(bool enable) override {
270 return impl_->SetStereoPlayout(enable);
271 }
272 int32_t StereoPlayout(bool* enabled) const override {
273 return impl_->StereoPlayout(enabled);
274 }
275 int32_t StereoRecordingIsAvailable(bool* available) const override {
276 return impl_->StereoRecordingIsAvailable(available);
277 }
278 int32_t SetStereoRecording(bool enable) override {
279 return impl_->SetStereoRecording(enable);
280 }
281 int32_t StereoRecording(bool* enabled) const override {
282 return impl_->StereoRecording(enabled);
283 }
284 int32_t SetRecordingChannel(const ChannelType channel) override {
285 return impl_->SetRecordingChannel(channel);
286 }
287 int32_t RecordingChannel(ChannelType* channel) const override {
288 return impl_->RecordingChannel(channel);
289 }
290 int32_t SetPlayoutBuffer(const BufferType type, uint16_t sizeMS) override {
291 return impl_->SetPlayoutBuffer(type, sizeMS);
292 }
293 int32_t PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const override {
294 return impl_->PlayoutBuffer(type, sizeMS);
295 }
296 int32_t PlayoutDelay(uint16_t* delayMS) const override {
297 return impl_->PlayoutDelay(delayMS);
298 }
299 int32_t RecordingDelay(uint16_t* delayMS) const override {
300 return impl_->RecordingDelay(delayMS);
301 }
302 int32_t CPULoad(uint16_t* load) const override {
303 return impl_->CPULoad(load);
304 }
305 int32_t StartRawOutputFileRecording(
306 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) override {
307 return impl_->StartRawOutputFileRecording(pcmFileNameUTF8);
308 }
309 int32_t StopRawOutputFileRecording() override {
310 return impl_->StopRawOutputFileRecording();
311 }
312 int32_t StartRawInputFileRecording(
313 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) override {
314 return impl_->StartRawInputFileRecording(pcmFileNameUTF8);
315 }
316 int32_t StopRawInputFileRecording() override {
317 return impl_->StopRawInputFileRecording();
318 }
319 int32_t SetRecordingSampleRate(const uint32_t samplesPerSec) override {
320 return impl_->SetRecordingSampleRate(samplesPerSec);
321 }
322 int32_t RecordingSampleRate(uint32_t* samplesPerSec) const override {
323 return impl_->RecordingSampleRate(samplesPerSec);
324 }
325 int32_t SetPlayoutSampleRate(const uint32_t samplesPerSec) override {
326 return impl_->SetPlayoutSampleRate(samplesPerSec);
327 }
328 int32_t PlayoutSampleRate(uint32_t* samplesPerSec) const override {
329 return impl_->PlayoutSampleRate(samplesPerSec);
330 }
331 int32_t ResetAudioDevice() override { return impl_->ResetAudioDevice(); }
332 int32_t SetLoudspeakerStatus(bool enable) override {
333 return impl_->SetLoudspeakerStatus(enable);
334 }
335 int32_t GetLoudspeakerStatus(bool* enabled) const override {
336 return impl_->GetLoudspeakerStatus(enabled);
337 }
338 bool BuiltInAECIsAvailable() const override {
339 return impl_->BuiltInAECIsAvailable();
340 }
341 bool BuiltInAGCIsAvailable() const override {
342 return impl_->BuiltInAGCIsAvailable();
343 }
344 bool BuiltInNSIsAvailable() const override {
345 return impl_->BuiltInNSIsAvailable();
346 }
347 int32_t EnableBuiltInAEC(bool enable) override {
348 return impl_->EnableBuiltInAEC(enable);
349 }
350 int32_t EnableBuiltInAGC(bool enable) override {
351 return impl_->EnableBuiltInAGC(enable);
352 }
353 int32_t EnableBuiltInNS(bool enable) override {
354 return impl_->EnableBuiltInNS(enable);
355 }
356 // Only supported on iOS.
357 #if defined(WEBRTC_IOS)
358 int GetPlayoutAudioParameters(AudioParameters* params) const override {
359 return impl_->GetPlayoutAudioParameters(params);
360 }
361 int GetRecordAudioParameters(AudioParameters* params) const override {
362 return impl_->GetRecordAudioParameters(params);
363 }
364 #endif // WEBRTC_IOS
365
366 protected:
367 rtc::scoped_refptr<AudioDeviceModule> impl_;
368 AudioTransportCapture* capture_callback_ = nullptr;
369 AudioTransport* audio_transport_ = nullptr;
370 bool is_valid_ = false;
371 };
372
373 } // namespace
374
375 rtc::scoped_refptr<AudioDeviceModule> CreateAudioDeviceWithTransportCapture(
376 const int32_t id,
377 const AudioDeviceModule::AudioLayer audio_layer,
378 AudioTransportCapture* proc_callback) {
379 rtc::scoped_refptr<ADMWrapper> audio_device(
380 new rtc::RefCountedObject<ADMWrapper>(id, audio_layer, proc_callback));
381
382 if (!audio_device->IsValid()) {
383 return nullptr;
384 }
385
386 return audio_device;
387 }
388
389 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698