Line data Source code
1 : /*
2 : * Copyright (c) 2012 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/voice_engine/voe_hardware_impl.h"
12 :
13 : #include <assert.h>
14 :
15 : #include "webrtc/system_wrappers/include/trace.h"
16 : #include "webrtc/voice_engine/include/voe_errors.h"
17 : #include "webrtc/voice_engine/voice_engine_impl.h"
18 :
19 : namespace webrtc {
20 :
21 0 : VoEHardware* VoEHardware::GetInterface(VoiceEngine* voiceEngine) {
22 0 : if (NULL == voiceEngine) {
23 0 : return NULL;
24 : }
25 0 : VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
26 0 : s->AddRef();
27 0 : return s;
28 : }
29 :
30 0 : VoEHardwareImpl::VoEHardwareImpl(voe::SharedData* shared) : _shared(shared) {
31 : WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
32 : "VoEHardwareImpl() - ctor");
33 0 : }
34 :
35 0 : VoEHardwareImpl::~VoEHardwareImpl() {
36 : WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
37 : "~VoEHardwareImpl() - dtor");
38 0 : }
39 :
40 0 : int VoEHardwareImpl::SetAudioDeviceLayer(AudioLayers audioLayer) {
41 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
42 : "SetAudioDeviceLayer(audioLayer=%d)", audioLayer);
43 :
44 : // Don't allow a change if VoE is initialized
45 0 : if (_shared->statistics().Initialized()) {
46 0 : _shared->SetLastError(VE_ALREADY_INITED, kTraceError);
47 0 : return -1;
48 : }
49 :
50 : // Map to AudioDeviceModule::AudioLayer
51 : AudioDeviceModule::AudioLayer wantedLayer(
52 0 : AudioDeviceModule::kPlatformDefaultAudio);
53 0 : switch (audioLayer) {
54 : case kAudioPlatformDefault:
55 : // already set above
56 0 : break;
57 : case kAudioWindowsCore:
58 0 : wantedLayer = AudioDeviceModule::kWindowsCoreAudio;
59 0 : break;
60 : case kAudioWindowsWave:
61 0 : wantedLayer = AudioDeviceModule::kWindowsWaveAudio;
62 0 : break;
63 : case kAudioLinuxAlsa:
64 0 : wantedLayer = AudioDeviceModule::kLinuxAlsaAudio;
65 0 : break;
66 : case kAudioLinuxPulse:
67 0 : wantedLayer = AudioDeviceModule::kLinuxPulseAudio;
68 0 : break;
69 : case kAudioSndio:
70 0 : wantedLayer = AudioDeviceModule::kSndioAudio;
71 0 : break;
72 : }
73 :
74 : // Save the audio device layer for Init()
75 0 : _shared->set_audio_device_layer(wantedLayer);
76 :
77 0 : return 0;
78 : }
79 :
80 0 : int VoEHardwareImpl::GetAudioDeviceLayer(AudioLayers& audioLayer) {
81 : // Can always be called regardless of VoE state
82 :
83 : AudioDeviceModule::AudioLayer activeLayer(
84 0 : AudioDeviceModule::kPlatformDefaultAudio);
85 :
86 0 : if (_shared->audio_device()) {
87 : // Get active audio layer from ADM
88 0 : if (_shared->audio_device()->ActiveAudioLayer(&activeLayer) != 0) {
89 0 : _shared->SetLastError(VE_UNDEFINED_SC_ERR, kTraceError,
90 0 : " Audio Device error");
91 0 : return -1;
92 : }
93 : } else {
94 : // Return VoE's internal layer setting
95 0 : activeLayer = _shared->audio_device_layer();
96 : }
97 :
98 : // Map to AudioLayers
99 0 : switch (activeLayer) {
100 : case AudioDeviceModule::kPlatformDefaultAudio:
101 0 : audioLayer = kAudioPlatformDefault;
102 0 : break;
103 : case AudioDeviceModule::kWindowsCoreAudio:
104 0 : audioLayer = kAudioWindowsCore;
105 0 : break;
106 : case AudioDeviceModule::kWindowsWaveAudio:
107 0 : audioLayer = kAudioWindowsWave;
108 0 : break;
109 : case AudioDeviceModule::kLinuxAlsaAudio:
110 0 : audioLayer = kAudioLinuxAlsa;
111 0 : break;
112 : case AudioDeviceModule::kLinuxPulseAudio:
113 0 : audioLayer = kAudioLinuxPulse;
114 0 : break;
115 : case AudioDeviceModule::kSndioAudio:
116 0 : audioLayer = kAudioSndio;
117 0 : break;
118 : default:
119 0 : _shared->SetLastError(VE_UNDEFINED_SC_ERR, kTraceError,
120 0 : " unknown audio layer");
121 : }
122 :
123 0 : return 0;
124 : }
125 0 : int VoEHardwareImpl::GetNumOfRecordingDevices(int& devices) {
126 0 : if (!_shared->statistics().Initialized()) {
127 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
128 0 : return -1;
129 : }
130 :
131 0 : devices = static_cast<int>(_shared->audio_device()->RecordingDevices());
132 :
133 0 : return 0;
134 : }
135 :
136 0 : int VoEHardwareImpl::GetNumOfPlayoutDevices(int& devices) {
137 0 : if (!_shared->statistics().Initialized()) {
138 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
139 0 : return -1;
140 : }
141 :
142 0 : devices = static_cast<int>(_shared->audio_device()->PlayoutDevices());
143 :
144 0 : return 0;
145 : }
146 :
147 0 : int VoEHardwareImpl::GetRecordingDeviceName(int index,
148 : char strNameUTF8[128],
149 : char strGuidUTF8[128]) {
150 0 : if (!_shared->statistics().Initialized()) {
151 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
152 0 : return -1;
153 : }
154 0 : if (strNameUTF8 == NULL) {
155 0 : _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
156 0 : "GetRecordingDeviceName() invalid argument");
157 0 : return -1;
158 : }
159 :
160 : // Note that strGuidUTF8 is allowed to be NULL
161 :
162 : // Init len variable to length of supplied vectors
163 0 : const uint16_t strLen = 128;
164 :
165 : // Check if length has been changed in module
166 : static_assert(strLen == kAdmMaxDeviceNameSize, "");
167 : static_assert(strLen == kAdmMaxGuidSize, "");
168 :
169 : char name[strLen];
170 : char guid[strLen];
171 :
172 : // Get names from module
173 0 : if (_shared->audio_device()->RecordingDeviceName(index, name, guid) != 0) {
174 0 : _shared->SetLastError(VE_CANNOT_RETRIEVE_DEVICE_NAME, kTraceError,
175 0 : "GetRecordingDeviceName() failed to get device name");
176 0 : return -1;
177 : }
178 :
179 : // Copy to vectors supplied by user
180 0 : strncpy(strNameUTF8, name, strLen);
181 :
182 0 : if (strGuidUTF8 != NULL) {
183 0 : strncpy(strGuidUTF8, guid, strLen);
184 : }
185 :
186 0 : return 0;
187 : }
188 :
189 0 : int VoEHardwareImpl::GetPlayoutDeviceName(int index,
190 : char strNameUTF8[128],
191 : char strGuidUTF8[128]) {
192 0 : if (!_shared->statistics().Initialized()) {
193 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
194 0 : return -1;
195 : }
196 0 : if (strNameUTF8 == NULL) {
197 0 : _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
198 0 : "GetPlayoutDeviceName() invalid argument");
199 0 : return -1;
200 : }
201 :
202 : // Note that strGuidUTF8 is allowed to be NULL
203 :
204 : // Init len variable to length of supplied vectors
205 0 : const uint16_t strLen = 128;
206 :
207 : // Check if length has been changed in module
208 : static_assert(strLen == kAdmMaxDeviceNameSize, "");
209 : static_assert(strLen == kAdmMaxGuidSize, "");
210 :
211 : char name[strLen];
212 : char guid[strLen];
213 :
214 : // Get names from module
215 0 : if (_shared->audio_device()->PlayoutDeviceName(index, name, guid) != 0) {
216 0 : _shared->SetLastError(VE_CANNOT_RETRIEVE_DEVICE_NAME, kTraceError,
217 0 : "GetPlayoutDeviceName() failed to get device name");
218 0 : return -1;
219 : }
220 :
221 : // Copy to vectors supplied by user
222 0 : strncpy(strNameUTF8, name, strLen);
223 :
224 0 : if (strGuidUTF8 != NULL) {
225 0 : strncpy(strGuidUTF8, guid, strLen);
226 : }
227 :
228 0 : return 0;
229 : }
230 :
231 0 : int VoEHardwareImpl::SetRecordingDevice(int index,
232 : StereoChannel recordingChannel) {
233 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
234 : "SetRecordingDevice(index=%d, recordingChannel=%d)", index,
235 : (int)recordingChannel);
236 0 : rtc::CritScope cs(_shared->crit_sec());
237 :
238 0 : if (!_shared->statistics().Initialized()) {
239 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
240 0 : return -1;
241 : }
242 :
243 0 : bool isRecording(false);
244 :
245 : // Store state about activated recording to be able to restore it after the
246 : // recording device has been modified.
247 0 : if (_shared->audio_device()->Recording()) {
248 : WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
249 : "SetRecordingDevice() device is modified while recording"
250 : " is active...");
251 0 : isRecording = true;
252 0 : if (_shared->audio_device()->StopRecording() == -1) {
253 0 : _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
254 0 : "SetRecordingDevice() unable to stop recording");
255 0 : return -1;
256 : }
257 : }
258 :
259 : // We let the module do the index sanity
260 :
261 : // Set recording channel
262 0 : AudioDeviceModule::ChannelType recCh = AudioDeviceModule::kChannelBoth;
263 0 : switch (recordingChannel) {
264 : case kStereoLeft:
265 0 : recCh = AudioDeviceModule::kChannelLeft;
266 0 : break;
267 : case kStereoRight:
268 0 : recCh = AudioDeviceModule::kChannelRight;
269 0 : break;
270 : case kStereoBoth:
271 : // default setting kChannelBoth (<=> mono)
272 0 : break;
273 : }
274 :
275 0 : if (_shared->audio_device()->SetRecordingChannel(recCh) != 0) {
276 0 : _shared->SetLastError(
277 : VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning,
278 0 : "SetRecordingChannel() unable to set the recording channel");
279 : }
280 :
281 : // Map indices to unsigned since underlying functions need that
282 0 : uint16_t indexU = static_cast<uint16_t>(index);
283 :
284 0 : int32_t res(0);
285 :
286 0 : if (index == -1) {
287 0 : res = _shared->audio_device()->SetRecordingDevice(
288 0 : AudioDeviceModule::kDefaultCommunicationDevice);
289 0 : } else if (index == -2) {
290 0 : res = _shared->audio_device()->SetRecordingDevice(
291 0 : AudioDeviceModule::kDefaultDevice);
292 : } else {
293 0 : res = _shared->audio_device()->SetRecordingDevice(indexU);
294 : }
295 :
296 0 : if (res != 0) {
297 0 : _shared->SetLastError(
298 : VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
299 0 : "SetRecordingDevice() unable to set the recording device");
300 0 : return -1;
301 : }
302 :
303 : // Init microphone, so user can do volume settings etc
304 0 : if (_shared->audio_device()->InitMicrophone() == -1) {
305 0 : _shared->SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceWarning,
306 0 : "SetRecordingDevice() cannot access microphone");
307 : }
308 :
309 : // Set number of channels
310 0 : bool available = false;
311 0 : if (_shared->audio_device()->StereoRecordingIsAvailable(&available) != 0) {
312 0 : _shared->SetLastError(
313 : VE_SOUNDCARD_ERROR, kTraceWarning,
314 0 : "StereoRecordingIsAvailable() failed to query stereo recording");
315 : }
316 :
317 0 : if (_shared->audio_device()->SetStereoRecording(available) != 0) {
318 0 : _shared->SetLastError(
319 : VE_SOUNDCARD_ERROR, kTraceWarning,
320 0 : "SetRecordingDevice() failed to set mono recording mode");
321 : }
322 :
323 : // Restore recording if it was enabled already when calling this function.
324 0 : if (isRecording) {
325 0 : if (!_shared->ext_recording())
326 : {
327 : WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
328 : "SetRecordingDevice() recording is now being restored...");
329 0 : if (_shared->audio_device()->InitRecording() != 0) {
330 : WEBRTC_TRACE(kTraceError, kTraceVoice,
331 : VoEId(_shared->instance_id(), -1),
332 : "SetRecordingDevice() failed to initialize recording");
333 0 : return -1;
334 : }
335 0 : if (_shared->audio_device()->StartRecording() != 0) {
336 : WEBRTC_TRACE(kTraceError, kTraceVoice,
337 : VoEId(_shared->instance_id(), -1),
338 : "SetRecordingDevice() failed to start recording");
339 0 : return -1;
340 : }
341 : }
342 : }
343 :
344 0 : return 0;
345 : }
346 :
347 0 : int VoEHardwareImpl::SetPlayoutDevice(int index) {
348 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
349 : "SetPlayoutDevice(index=%d)", index);
350 0 : rtc::CritScope cs(_shared->crit_sec());
351 :
352 0 : if (!_shared->statistics().Initialized()) {
353 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
354 0 : return -1;
355 : }
356 :
357 0 : bool isPlaying(false);
358 :
359 : // Store state about activated playout to be able to restore it after the
360 : // playout device has been modified.
361 0 : if (_shared->audio_device()->Playing()) {
362 : WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
363 : "SetPlayoutDevice() device is modified while playout is "
364 : "active...");
365 0 : isPlaying = true;
366 0 : if (_shared->audio_device()->StopPlayout() == -1) {
367 0 : _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
368 0 : "SetPlayoutDevice() unable to stop playout");
369 0 : return -1;
370 : }
371 : }
372 :
373 : // We let the module do the index sanity
374 :
375 : // Map indices to unsigned since underlying functions need that
376 0 : uint16_t indexU = static_cast<uint16_t>(index);
377 :
378 0 : int32_t res(0);
379 :
380 0 : if (index == -1) {
381 0 : res = _shared->audio_device()->SetPlayoutDevice(
382 0 : AudioDeviceModule::kDefaultCommunicationDevice);
383 0 : } else if (index == -2) {
384 0 : res = _shared->audio_device()->SetPlayoutDevice(
385 0 : AudioDeviceModule::kDefaultDevice);
386 : } else {
387 0 : res = _shared->audio_device()->SetPlayoutDevice(indexU);
388 : }
389 :
390 0 : if (res != 0) {
391 0 : _shared->SetLastError(
392 : VE_SOUNDCARD_ERROR, kTraceError,
393 0 : "SetPlayoutDevice() unable to set the playout device");
394 0 : return -1;
395 : }
396 :
397 : // Init speaker, so user can do volume settings etc
398 0 : if (_shared->audio_device()->InitSpeaker() == -1) {
399 0 : _shared->SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceWarning,
400 0 : "SetPlayoutDevice() cannot access speaker");
401 : }
402 :
403 : // Set number of channels
404 0 : bool available = false;
405 0 : _shared->audio_device()->StereoPlayoutIsAvailable(&available);
406 0 : if (_shared->audio_device()->SetStereoPlayout(available) != 0) {
407 0 : _shared->SetLastError(
408 : VE_SOUNDCARD_ERROR, kTraceWarning,
409 0 : "SetPlayoutDevice() failed to set stereo playout mode");
410 : }
411 :
412 : // Restore playout if it was enabled already when calling this function.
413 0 : if (isPlaying) {
414 0 : if (!_shared->ext_playout())
415 : {
416 : WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
417 : "SetPlayoutDevice() playout is now being restored...");
418 0 : if (_shared->audio_device()->InitPlayout() != 0) {
419 : WEBRTC_TRACE(kTraceError, kTraceVoice,
420 : VoEId(_shared->instance_id(), -1),
421 : "SetPlayoutDevice() failed to initialize playout");
422 0 : return -1;
423 : }
424 0 : if (_shared->audio_device()->StartPlayout() != 0) {
425 : WEBRTC_TRACE(kTraceError, kTraceVoice,
426 : VoEId(_shared->instance_id(), -1),
427 : "SetPlayoutDevice() failed to start playout");
428 0 : return -1;
429 : }
430 : }
431 : }
432 :
433 0 : return 0;
434 : }
435 :
436 0 : int VoEHardwareImpl::GetRecordingDeviceStatus(bool& isAvailable)
437 : {
438 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
439 : "GetRecordingDeviceStatus()");
440 :
441 0 : if (!_shared->statistics().Initialized())
442 : {
443 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
444 0 : return -1;
445 : }
446 :
447 : // We let the module do isRecording sanity
448 :
449 0 : bool available(false);
450 :
451 : // Check availability
452 0 : if (_shared->audio_device()->RecordingIsAvailable(&available) != 0)
453 : {
454 0 : _shared->SetLastError(VE_UNDEFINED_SC_REC_ERR, kTraceError,
455 0 : " Audio Device error");
456 0 : return -1;
457 : }
458 :
459 0 : isAvailable = available;
460 :
461 : WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
462 : VoEId(_shared->instance_id(), -1),
463 : " Output: isAvailable = %d)", (int) isAvailable);
464 :
465 0 : return 0;
466 : }
467 :
468 0 : int VoEHardwareImpl::GetPlayoutDeviceStatus(bool& isAvailable)
469 : {
470 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
471 : "GetPlayoutDeviceStatus()");
472 :
473 0 : if (!_shared->statistics().Initialized())
474 : {
475 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
476 0 : return -1;
477 : }
478 :
479 : // We let the module do isPlaying sanity
480 :
481 0 : bool available(false);
482 :
483 : // Check availability
484 0 : if (_shared->audio_device()->PlayoutIsAvailable(&available) != 0)
485 : {
486 0 : _shared->SetLastError(VE_PLAY_UNDEFINED_SC_ERR, kTraceError,
487 0 : " Audio Device error");
488 0 : return -1;
489 : }
490 :
491 0 : isAvailable = available;
492 :
493 : WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
494 : VoEId(_shared->instance_id(), -1),
495 : " Output: isAvailable = %d)", (int) isAvailable);
496 :
497 0 : return 0;
498 : }
499 :
500 0 : int VoEHardwareImpl::ResetAudioDevice()
501 : {
502 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
503 : "ResetAudioDevice()");
504 :
505 0 : if (!_shared->statistics().Initialized())
506 : {
507 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
508 0 : return -1;
509 : }
510 :
511 : #if defined(WEBRTC_IOS)
512 : if (_shared->audio_device()->ResetAudioDevice() < 0)
513 : {
514 : _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceError,
515 : " Failed to reset sound device");
516 : return -1;
517 : }
518 : return 0;
519 : #else
520 0 : _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
521 0 : " no support for resetting sound device");
522 0 : return -1;
523 : #endif
524 : }
525 :
526 0 : int VoEHardwareImpl::AudioDeviceControl(unsigned int par1, unsigned int par2,
527 : unsigned int par3)
528 : {
529 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
530 : "AudioDeviceControl(%i, %i, %i)", par1, par2, par3);
531 0 : if (!_shared->statistics().Initialized())
532 : {
533 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
534 0 : return -1;
535 : }
536 0 : _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
537 0 : " no support for resetting sound device");
538 0 : return -1;
539 : }
540 :
541 0 : int VoEHardwareImpl::SetLoudspeakerStatus(bool enable)
542 : {
543 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
544 : "SetLoudspeakerStatus(enable=%i)", (int) enable);
545 :
546 0 : if (!_shared->statistics().Initialized())
547 : {
548 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
549 0 : return -1;
550 : }
551 : #if defined(WEBRTC_ANDROID)
552 : if (_shared->audio_device()->SetLoudspeakerStatus(enable) < 0)
553 : {
554 : _shared->SetLastError(VE_IGNORED_FUNCTION, kTraceError,
555 : " Failed to set loudspeaker status");
556 : return -1;
557 : }
558 :
559 : return 0;
560 : #else
561 0 : _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
562 0 : " no support for setting loudspeaker status");
563 0 : return -1;
564 : #endif
565 : }
566 :
567 0 : int VoEHardwareImpl::GetLoudspeakerStatus(bool& enabled)
568 : {
569 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
570 : "GetLoudspeakerStatus()");
571 :
572 : #if defined(WEBRTC_ANDROID)
573 : if (!_shared->statistics().Initialized())
574 : {
575 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
576 : return -1;
577 : }
578 :
579 : if (_shared->audio_device()->GetLoudspeakerStatus(&enabled) < 0)
580 : {
581 : _shared->SetLastError(VE_IGNORED_FUNCTION, kTraceError,
582 : " Failed to get loudspeaker status");
583 : return -1;
584 : }
585 :
586 : return 0;
587 : #else
588 0 : _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
589 0 : " no support for setting loudspeaker status");
590 0 : return -1;
591 : #endif
592 : }
593 :
594 0 : int VoEHardwareImpl::GetCPULoad(int& loadPercent)
595 : {
596 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
597 : "GetCPULoad()");
598 :
599 0 : if (!_shared->statistics().Initialized())
600 : {
601 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
602 0 : return -1;
603 : }
604 :
605 : // Get CPU load from ADM
606 0 : uint16_t load(0);
607 0 : if (_shared->audio_device()->CPULoad(&load) != 0)
608 : {
609 0 : _shared->SetLastError(VE_CPU_INFO_ERROR, kTraceError,
610 0 : " error getting system CPU load");
611 0 : return -1;
612 : }
613 :
614 0 : loadPercent = static_cast<int> (load);
615 :
616 : WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
617 : VoEId(_shared->instance_id(), -1),
618 : " Output: loadPercent = %d", loadPercent);
619 :
620 0 : return 0;
621 : }
622 :
623 0 : int VoEHardwareImpl::SetRecordingSampleRate(unsigned int samples_per_sec) {
624 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
625 : "%s", __FUNCTION__);
626 0 : if (!_shared->statistics().Initialized()) {
627 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
628 0 : return false;
629 : }
630 0 : return _shared->audio_device()->SetRecordingSampleRate(samples_per_sec);
631 : }
632 :
633 0 : int VoEHardwareImpl::RecordingSampleRate(unsigned int* samples_per_sec) const {
634 0 : if (!_shared->statistics().Initialized()) {
635 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
636 0 : return false;
637 : }
638 0 : return _shared->audio_device()->RecordingSampleRate(samples_per_sec);
639 : }
640 :
641 0 : int VoEHardwareImpl::SetPlayoutSampleRate(unsigned int samples_per_sec) {
642 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
643 : "%s", __FUNCTION__);
644 0 : if (!_shared->statistics().Initialized()) {
645 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
646 0 : return false;
647 : }
648 0 : return _shared->audio_device()->SetPlayoutSampleRate(samples_per_sec);
649 : }
650 :
651 0 : int VoEHardwareImpl::PlayoutSampleRate(unsigned int* samples_per_sec) const {
652 0 : if (!_shared->statistics().Initialized()) {
653 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
654 0 : return false;
655 : }
656 0 : return _shared->audio_device()->PlayoutSampleRate(samples_per_sec);
657 : }
658 :
659 0 : bool VoEHardwareImpl::BuiltInAECIsAvailable() const {
660 0 : if (!_shared->statistics().Initialized()) {
661 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
662 0 : return false;
663 : }
664 0 : return _shared->audio_device()->BuiltInAECIsAvailable();
665 : }
666 :
667 0 : int VoEHardwareImpl::EnableBuiltInAEC(bool enable)
668 : {
669 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
670 : "%s", __FUNCTION__);
671 0 : if (!_shared->statistics().Initialized())
672 : {
673 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
674 0 : return -1;
675 : }
676 :
677 0 : return _shared->audio_device()->EnableBuiltInAEC(enable);
678 : }
679 :
680 0 : bool VoEHardwareImpl::BuiltInAGCIsAvailable() const {
681 0 : if (!_shared->statistics().Initialized()) {
682 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
683 0 : return false;
684 : }
685 0 : return _shared->audio_device()->BuiltInAGCIsAvailable();
686 : }
687 :
688 0 : int VoEHardwareImpl::EnableBuiltInAGC(bool enable) {
689 0 : if (!_shared->statistics().Initialized()) {
690 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
691 0 : return -1;
692 : }
693 0 : return _shared->audio_device()->EnableBuiltInAGC(enable);
694 : }
695 :
696 0 : bool VoEHardwareImpl::BuiltInNSIsAvailable() const {
697 0 : if (!_shared->statistics().Initialized()) {
698 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
699 0 : return false;
700 : }
701 0 : return _shared->audio_device()->BuiltInNSIsAvailable();
702 : }
703 :
704 0 : int VoEHardwareImpl::EnableBuiltInNS(bool enable) {
705 0 : if (!_shared->statistics().Initialized()) {
706 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
707 0 : return -1;
708 : }
709 0 : return _shared->audio_device()->EnableBuiltInNS(enable);
710 : }
711 :
712 : } // namespace webrtc
|