OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 _recordingFramesIn10MS(0), | 75 _recordingFramesIn10MS(0), |
76 _playoutFramesIn10MS(0), | 76 _playoutFramesIn10MS(0), |
77 _recordingFreq(ALSA_CAPTURE_FREQ), | 77 _recordingFreq(ALSA_CAPTURE_FREQ), |
78 _playoutFreq(ALSA_PLAYOUT_FREQ), | 78 _playoutFreq(ALSA_PLAYOUT_FREQ), |
79 _recChannels(ALSA_CAPTURE_CH), | 79 _recChannels(ALSA_CAPTURE_CH), |
80 _playChannels(ALSA_PLAYOUT_CH), | 80 _playChannels(ALSA_PLAYOUT_CH), |
81 _recordingBuffer(NULL), | 81 _recordingBuffer(NULL), |
82 _playoutBuffer(NULL), | 82 _playoutBuffer(NULL), |
83 _recordingFramesLeft(0), | 83 _recordingFramesLeft(0), |
84 _playoutFramesLeft(0), | 84 _playoutFramesLeft(0), |
85 _playBufType(AudioDeviceModule::kFixedBufferSize), | |
86 _initialized(false), | 85 _initialized(false), |
87 _recording(false), | 86 _recording(false), |
88 _playing(false), | 87 _playing(false), |
89 _recIsInitialized(false), | 88 _recIsInitialized(false), |
90 _playIsInitialized(false), | 89 _playIsInitialized(false), |
91 _AGC(false), | 90 _AGC(false), |
92 _recordingDelay(0), | 91 _recordingDelay(0), |
93 _playoutDelay(0), | 92 _playoutDelay(0), |
94 _playWarning(0), | 93 _playWarning(0), |
95 _playError(0), | 94 _playError(0), |
96 _recWarning(0), | 95 _recWarning(0), |
97 _recError(0), | 96 _recError(0) |
98 _playBufDelay(80), | |
99 _playBufDelayFixed(80) | |
100 { | 97 { |
101 memset(_oldKeyState, 0, sizeof(_oldKeyState)); | 98 memset(_oldKeyState, 0, sizeof(_oldKeyState)); |
102 LOG(LS_INFO) << __FUNCTION__ << " created"; | 99 LOG(LS_INFO) << __FUNCTION__ << " created"; |
103 } | 100 } |
104 | 101 |
105 // ---------------------------------------------------------------------------- | 102 // ---------------------------------------------------------------------------- |
106 // AudioDeviceLinuxALSA - dtor | 103 // AudioDeviceLinuxALSA - dtor |
107 // ---------------------------------------------------------------------------- | 104 // ---------------------------------------------------------------------------- |
108 | 105 |
109 AudioDeviceLinuxALSA::~AudioDeviceLinuxALSA() | 106 AudioDeviceLinuxALSA::~AudioDeviceLinuxALSA() |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 if (_mixerManager.MinSpeakerVolume(minVol) == -1) | 343 if (_mixerManager.MinSpeakerVolume(minVol) == -1) |
347 { | 344 { |
348 return -1; | 345 return -1; |
349 } | 346 } |
350 | 347 |
351 minVolume = minVol; | 348 minVolume = minVol; |
352 | 349 |
353 return 0; | 350 return 0; |
354 } | 351 } |
355 | 352 |
356 int32_t AudioDeviceLinuxALSA::SpeakerVolumeStepSize( | |
357 uint16_t& stepSize) const | |
358 { | |
359 | |
360 uint16_t delta(0); | |
361 | |
362 if (_mixerManager.SpeakerVolumeStepSize(delta) == -1) | |
363 { | |
364 return -1; | |
365 } | |
366 | |
367 stepSize = delta; | |
368 | |
369 return 0; | |
370 } | |
371 | |
372 int32_t AudioDeviceLinuxALSA::SpeakerMuteIsAvailable(bool& available) | 353 int32_t AudioDeviceLinuxALSA::SpeakerMuteIsAvailable(bool& available) |
373 { | 354 { |
374 | 355 |
375 bool isAvailable(false); | 356 bool isAvailable(false); |
376 bool wasInitialized = _mixerManager.SpeakerIsInitialized(); | 357 bool wasInitialized = _mixerManager.SpeakerIsInitialized(); |
377 | 358 |
378 // Make an attempt to open up the | 359 // Make an attempt to open up the |
379 // output mixer corresponding to the currently selected output device. | 360 // output mixer corresponding to the currently selected output device. |
380 // | 361 // |
381 if (!wasInitialized && InitSpeaker() == -1) | 362 if (!wasInitialized && InitSpeaker() == -1) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 451 |
471 if (_mixerManager.MicrophoneMute(muted) == -1) | 452 if (_mixerManager.MicrophoneMute(muted) == -1) |
472 { | 453 { |
473 return -1; | 454 return -1; |
474 } | 455 } |
475 | 456 |
476 enabled = muted; | 457 enabled = muted; |
477 return 0; | 458 return 0; |
478 } | 459 } |
479 | 460 |
480 int32_t AudioDeviceLinuxALSA::MicrophoneBoostIsAvailable(bool& available) | |
481 { | |
482 | |
483 bool isAvailable(false); | |
484 bool wasInitialized = _mixerManager.MicrophoneIsInitialized(); | |
485 | |
486 // Enumerate all avaliable microphone and make an attempt to open up the | |
487 // input mixer corresponding to the currently selected input device. | |
488 // | |
489 if (!wasInitialized && InitMicrophone() == -1) | |
490 { | |
491 // If we end up here it means that the selected microphone has no volume | |
492 // control, hence it is safe to state that there is no boost control | |
493 // already at this stage. | |
494 available = false; | |
495 return 0; | |
496 } | |
497 | |
498 // Check if the selected microphone has a boost control | |
499 _mixerManager.MicrophoneBoostIsAvailable(isAvailable); | |
500 available = isAvailable; | |
501 | |
502 // Close the initialized input mixer | |
503 if (!wasInitialized) | |
504 { | |
505 _mixerManager.CloseMicrophone(); | |
506 } | |
507 | |
508 return 0; | |
509 } | |
510 | |
511 int32_t AudioDeviceLinuxALSA::SetMicrophoneBoost(bool enable) | |
512 { | |
513 | |
514 return (_mixerManager.SetMicrophoneBoost(enable)); | |
515 } | |
516 | |
517 int32_t AudioDeviceLinuxALSA::MicrophoneBoost(bool& enabled) const | |
518 { | |
519 | |
520 bool onOff(0); | |
521 | |
522 if (_mixerManager.MicrophoneBoost(onOff) == -1) | |
523 { | |
524 return -1; | |
525 } | |
526 | |
527 enabled = onOff; | |
528 | |
529 return 0; | |
530 } | |
531 | |
532 int32_t AudioDeviceLinuxALSA::StereoRecordingIsAvailable(bool& available) | 461 int32_t AudioDeviceLinuxALSA::StereoRecordingIsAvailable(bool& available) |
533 { | 462 { |
534 | 463 |
535 rtc::CritScope lock(&_critSect); | 464 rtc::CritScope lock(&_critSect); |
536 | 465 |
537 // If we already have initialized in stereo it's obviously available | 466 // If we already have initialized in stereo it's obviously available |
538 if (_recIsInitialized && (2 == _recChannels)) | 467 if (_recIsInitialized && (2 == _recChannels)) |
539 { | 468 { |
540 available = true; | 469 available = true; |
541 return 0; | 470 return 0; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 if (_mixerManager.MinMicrophoneVolume(minVol) == -1) | 691 if (_mixerManager.MinMicrophoneVolume(minVol) == -1) |
763 { | 692 { |
764 return -1; | 693 return -1; |
765 } | 694 } |
766 | 695 |
767 minVolume = minVol; | 696 minVolume = minVol; |
768 | 697 |
769 return 0; | 698 return 0; |
770 } | 699 } |
771 | 700 |
772 int32_t AudioDeviceLinuxALSA::MicrophoneVolumeStepSize( | |
773 uint16_t& stepSize) const | |
774 { | |
775 | |
776 uint16_t delta(0); | |
777 | |
778 if (_mixerManager.MicrophoneVolumeStepSize(delta) == -1) | |
779 { | |
780 return -1; | |
781 } | |
782 | |
783 stepSize = delta; | |
784 | |
785 return 0; | |
786 } | |
787 | |
788 int16_t AudioDeviceLinuxALSA::PlayoutDevices() | 701 int16_t AudioDeviceLinuxALSA::PlayoutDevices() |
789 { | 702 { |
790 | 703 |
791 return (int16_t)GetDevicesInfo(0, true); | 704 return (int16_t)GetDevicesInfo(0, true); |
792 } | 705 } |
793 | 706 |
794 int32_t AudioDeviceLinuxALSA::SetPlayoutDevice(uint16_t index) | 707 int32_t AudioDeviceLinuxALSA::SetPlayoutDevice(uint16_t index) |
795 { | 708 { |
796 | 709 |
797 if (_playIsInitialized) | 710 if (_playIsInitialized) |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 { | 1439 { |
1527 // Adding 10ms adjusted value to the record delay due to 10ms buffering. | 1440 // Adding 10ms adjusted value to the record delay due to 10ms buffering. |
1528 delayMS = (uint16_t)(10 + _recordingDelay * 1000 / _recordingFreq); | 1441 delayMS = (uint16_t)(10 + _recordingDelay * 1000 / _recordingFreq); |
1529 return 0; | 1442 return 0; |
1530 } | 1443 } |
1531 | 1444 |
1532 bool AudioDeviceLinuxALSA::Playing() const | 1445 bool AudioDeviceLinuxALSA::Playing() const |
1533 { | 1446 { |
1534 return (_playing); | 1447 return (_playing); |
1535 } | 1448 } |
1536 // ---------------------------------------------------------------------------- | |
1537 // SetPlayoutBuffer | |
1538 // ---------------------------------------------------------------------------- | |
1539 | |
1540 int32_t AudioDeviceLinuxALSA::SetPlayoutBuffer( | |
1541 const AudioDeviceModule::BufferType type, | |
1542 uint16_t sizeMS) | |
1543 { | |
1544 _playBufType = type; | |
1545 if (type == AudioDeviceModule::kFixedBufferSize) | |
1546 { | |
1547 _playBufDelayFixed = sizeMS; | |
1548 } | |
1549 return 0; | |
1550 } | |
1551 | |
1552 int32_t AudioDeviceLinuxALSA::PlayoutBuffer( | |
1553 AudioDeviceModule::BufferType& type, | |
1554 uint16_t& sizeMS) const | |
1555 { | |
1556 type = _playBufType; | |
1557 if (type == AudioDeviceModule::kFixedBufferSize) | |
1558 { | |
1559 sizeMS = _playBufDelayFixed; | |
1560 } | |
1561 else | |
1562 { | |
1563 sizeMS = _playBufDelay; | |
1564 } | |
1565 | |
1566 return 0; | |
1567 } | |
1568 | |
1569 int32_t AudioDeviceLinuxALSA::CPULoad(uint16_t& load) const | |
1570 { | |
1571 | |
1572 LOG(LS_WARNING) << "API call not supported on this platform"; | |
1573 return -1; | |
1574 } | |
1575 | 1449 |
1576 bool AudioDeviceLinuxALSA::PlayoutWarning() const | 1450 bool AudioDeviceLinuxALSA::PlayoutWarning() const |
1577 { | 1451 { |
1578 rtc::CritScope lock(&_critSect); | 1452 rtc::CritScope lock(&_critSect); |
1579 return (_playWarning > 0); | 1453 return (_playWarning > 0); |
1580 } | 1454 } |
1581 | 1455 |
1582 bool AudioDeviceLinuxALSA::PlayoutError() const | 1456 bool AudioDeviceLinuxALSA::PlayoutError() const |
1583 { | 1457 { |
1584 rtc::CritScope lock(&_critSect); | 1458 rtc::CritScope lock(&_critSect); |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 state |= (szKey[i] ^ _oldKeyState[i]) & szKey[i]; | 2009 state |= (szKey[i] ^ _oldKeyState[i]) & szKey[i]; |
2136 | 2010 |
2137 // Save old state | 2011 // Save old state |
2138 memcpy((char*)_oldKeyState, (char*)szKey, sizeof(_oldKeyState)); | 2012 memcpy((char*)_oldKeyState, (char*)szKey, sizeof(_oldKeyState)); |
2139 return (state != 0); | 2013 return (state != 0); |
2140 #else | 2014 #else |
2141 return false; | 2015 return false; |
2142 #endif | 2016 #endif |
2143 } | 2017 } |
2144 } // namespace webrtc | 2018 } // namespace webrtc |
OLD | NEW |