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

Side by Side Diff: webrtc/modules/audio_device/mac/audio_device_mac.cc

Issue 3006803002: Removes unused APIs from the ADM (part II) (Closed)
Patch Set: nit Created 3 years, 3 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) 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 _inputDeviceIndex(0), 118 _inputDeviceIndex(0),
119 _outputDeviceIndex(0), 119 _outputDeviceIndex(0),
120 _inputDeviceID(kAudioObjectUnknown), 120 _inputDeviceID(kAudioObjectUnknown),
121 _outputDeviceID(kAudioObjectUnknown), 121 _outputDeviceID(kAudioObjectUnknown),
122 _inputDeviceIsSpecified(false), 122 _inputDeviceIsSpecified(false),
123 _outputDeviceIsSpecified(false), 123 _outputDeviceIsSpecified(false),
124 _recChannels(N_REC_CHANNELS), 124 _recChannels(N_REC_CHANNELS),
125 _playChannels(N_PLAY_CHANNELS), 125 _playChannels(N_PLAY_CHANNELS),
126 _captureBufData(NULL), 126 _captureBufData(NULL),
127 _renderBufData(NULL), 127 _renderBufData(NULL),
128 _playBufType(AudioDeviceModule::kFixedBufferSize),
129 _initialized(false), 128 _initialized(false),
130 _isShutDown(false), 129 _isShutDown(false),
131 _recording(false), 130 _recording(false),
132 _playing(false), 131 _playing(false),
133 _recIsInitialized(false), 132 _recIsInitialized(false),
134 _playIsInitialized(false), 133 _playIsInitialized(false),
135 _AGC(false), 134 _AGC(false),
136 _renderDeviceIsAlive(1), 135 _renderDeviceIsAlive(1),
137 _captureDeviceIsAlive(1), 136 _captureDeviceIsAlive(1),
138 _twoDevices(true), 137 _twoDevices(true),
139 _doStop(false), 138 _doStop(false),
140 _doStopRec(false), 139 _doStopRec(false),
141 _macBookPro(false), 140 _macBookPro(false),
142 _macBookProPanRight(false), 141 _macBookProPanRight(false),
143 _captureLatencyUs(0), 142 _captureLatencyUs(0),
144 _renderLatencyUs(0), 143 _renderLatencyUs(0),
145 _captureDelayUs(0), 144 _captureDelayUs(0),
146 _renderDelayUs(0), 145 _renderDelayUs(0),
147 _renderDelayOffsetSamples(0), 146 _renderDelayOffsetSamples(0),
148 _playBufDelayFixed(20),
149 _playWarning(0), 147 _playWarning(0),
150 _playError(0), 148 _playError(0),
151 _recWarning(0), 149 _recWarning(0),
152 _recError(0), 150 _recError(0),
153 _paCaptureBuffer(NULL), 151 _paCaptureBuffer(NULL),
154 _paRenderBuffer(NULL), 152 _paRenderBuffer(NULL),
155 _captureBufSizeSamples(0), 153 _captureBufSizeSamples(0),
156 _renderBufSizeSamples(0), 154 _renderBufSizeSamples(0),
157 prev_key_state_(), 155 prev_key_state_(),
158 get_mic_volume_counter_ms_(0) { 156 get_mic_volume_counter_ms_(0) {
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 uint32_t minVol(0); 561 uint32_t minVol(0);
564 562
565 if (_mixerManager.MinSpeakerVolume(minVol) == -1) { 563 if (_mixerManager.MinSpeakerVolume(minVol) == -1) {
566 return -1; 564 return -1;
567 } 565 }
568 566
569 minVolume = minVol; 567 minVolume = minVol;
570 return 0; 568 return 0;
571 } 569 }
572 570
573 int32_t AudioDeviceMac::SpeakerVolumeStepSize(uint16_t& stepSize) const {
574 uint16_t delta(0);
575
576 if (_mixerManager.SpeakerVolumeStepSize(delta) == -1) {
577 return -1;
578 }
579
580 stepSize = delta;
581 return 0;
582 }
583
584 int32_t AudioDeviceMac::SpeakerMuteIsAvailable(bool& available) { 571 int32_t AudioDeviceMac::SpeakerMuteIsAvailable(bool& available) {
585 bool isAvailable(false); 572 bool isAvailable(false);
586 bool wasInitialized = _mixerManager.SpeakerIsInitialized(); 573 bool wasInitialized = _mixerManager.SpeakerIsInitialized();
587 574
588 // Make an attempt to open up the 575 // Make an attempt to open up the
589 // output mixer corresponding to the currently selected output device. 576 // output mixer corresponding to the currently selected output device.
590 // 577 //
591 if (!wasInitialized && InitSpeaker() == -1) { 578 if (!wasInitialized && InitSpeaker() == -1) {
592 // If we end up here it means that the selected speaker has no volume 579 // If we end up here it means that the selected speaker has no volume
593 // control, hence it is safe to state that there is no mute control 580 // control, hence it is safe to state that there is no mute control
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 bool muted(0); 650 bool muted(0);
664 651
665 if (_mixerManager.MicrophoneMute(muted) == -1) { 652 if (_mixerManager.MicrophoneMute(muted) == -1) {
666 return -1; 653 return -1;
667 } 654 }
668 655
669 enabled = muted; 656 enabled = muted;
670 return 0; 657 return 0;
671 } 658 }
672 659
673 int32_t AudioDeviceMac::MicrophoneBoostIsAvailable(bool& available) {
674 bool isAvailable(false);
675 bool wasInitialized = _mixerManager.MicrophoneIsInitialized();
676
677 // Enumerate all avaliable microphone and make an attempt to open up the
678 // input mixer corresponding to the currently selected input device.
679 //
680 if (!wasInitialized && InitMicrophone() == -1) {
681 // If we end up here it means that the selected microphone has no volume
682 // control, hence it is safe to state that there is no boost control
683 // already at this stage.
684 available = false;
685 return 0;
686 }
687
688 // Check if the selected microphone has a boost control
689 //
690 _mixerManager.MicrophoneBoostIsAvailable(isAvailable);
691 available = isAvailable;
692
693 // Close the initialized input mixer
694 //
695 if (!wasInitialized) {
696 _mixerManager.CloseMicrophone();
697 }
698
699 return 0;
700 }
701
702 int32_t AudioDeviceMac::SetMicrophoneBoost(bool enable) {
703 return (_mixerManager.SetMicrophoneBoost(enable));
704 }
705
706 int32_t AudioDeviceMac::MicrophoneBoost(bool& enabled) const {
707 bool onOff(0);
708
709 if (_mixerManager.MicrophoneBoost(onOff) == -1) {
710 return -1;
711 }
712
713 enabled = onOff;
714 return 0;
715 }
716
717 int32_t AudioDeviceMac::StereoRecordingIsAvailable(bool& available) { 660 int32_t AudioDeviceMac::StereoRecordingIsAvailable(bool& available) {
718 bool isAvailable(false); 661 bool isAvailable(false);
719 bool wasInitialized = _mixerManager.MicrophoneIsInitialized(); 662 bool wasInitialized = _mixerManager.MicrophoneIsInitialized();
720 663
721 if (!wasInitialized && InitMicrophone() == -1) { 664 if (!wasInitialized && InitMicrophone() == -1) {
722 // Cannot open the specified device 665 // Cannot open the specified device
723 available = false; 666 available = false;
724 return 0; 667 return 0;
725 } 668 }
726 669
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 uint32_t minVol(0); 809 uint32_t minVol(0);
867 810
868 if (_mixerManager.MinMicrophoneVolume(minVol) == -1) { 811 if (_mixerManager.MinMicrophoneVolume(minVol) == -1) {
869 return -1; 812 return -1;
870 } 813 }
871 814
872 minVolume = minVol; 815 minVolume = minVol;
873 return 0; 816 return 0;
874 } 817 }
875 818
876 int32_t AudioDeviceMac::MicrophoneVolumeStepSize(uint16_t& stepSize) const {
877 uint16_t delta(0);
878
879 if (_mixerManager.MicrophoneVolumeStepSize(delta) == -1) {
880 return -1;
881 }
882
883 stepSize = delta;
884 return 0;
885 }
886
887 int16_t AudioDeviceMac::PlayoutDevices() { 819 int16_t AudioDeviceMac::PlayoutDevices() {
888 AudioDeviceID playDevices[MaxNumberDevices]; 820 AudioDeviceID playDevices[MaxNumberDevices];
889 return GetNumberDevices(kAudioDevicePropertyScopeOutput, playDevices, 821 return GetNumberDevices(kAudioDevicePropertyScopeOutput, playDevices,
890 MaxNumberDevices); 822 MaxNumberDevices);
891 } 823 }
892 824
893 int32_t AudioDeviceMac::SetPlayoutDevice(uint16_t index) { 825 int32_t AudioDeviceMac::SetPlayoutDevice(uint16_t index) {
894 rtc::CritScope lock(&_critSect); 826 rtc::CritScope lock(&_critSect);
895 827
896 if (_playIsInitialized) { 828 if (_playIsInitialized) {
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 int32_t captureDelayUs = AtomicGet32(&_captureDelayUs); 1548 int32_t captureDelayUs = AtomicGet32(&_captureDelayUs);
1617 delayMS = 1549 delayMS =
1618 static_cast<uint16_t>(1e-3 * (captureDelayUs + _captureLatencyUs) + 0.5); 1550 static_cast<uint16_t>(1e-3 * (captureDelayUs + _captureLatencyUs) + 0.5);
1619 return 0; 1551 return 0;
1620 } 1552 }
1621 1553
1622 bool AudioDeviceMac::Playing() const { 1554 bool AudioDeviceMac::Playing() const {
1623 return (_playing); 1555 return (_playing);
1624 } 1556 }
1625 1557
1626 int32_t AudioDeviceMac::SetPlayoutBuffer(
1627 const AudioDeviceModule::BufferType type,
1628 uint16_t sizeMS) {
1629 if (type != AudioDeviceModule::kFixedBufferSize) {
1630 LOG(LS_ERROR) << "Adaptive buffer size not supported on this platform";
1631 return -1;
1632 }
1633
1634 _playBufType = type;
1635 _playBufDelayFixed = sizeMS;
1636 return 0;
1637 }
1638
1639 int32_t AudioDeviceMac::PlayoutBuffer(AudioDeviceModule::BufferType& type,
1640 uint16_t& sizeMS) const {
1641 type = _playBufType;
1642 sizeMS = _playBufDelayFixed;
1643
1644 return 0;
1645 }
1646
1647 // Not implemented for Mac.
1648 int32_t AudioDeviceMac::CPULoad(uint16_t& /*load*/) const {
1649 LOG(LS_WARNING) << "API call not supported on this platform";
1650
1651 return -1;
1652 }
1653
1654 bool AudioDeviceMac::PlayoutWarning() const { 1558 bool AudioDeviceMac::PlayoutWarning() const {
1655 return (_playWarning > 0); 1559 return (_playWarning > 0);
1656 } 1560 }
1657 1561
1658 bool AudioDeviceMac::PlayoutError() const { 1562 bool AudioDeviceMac::PlayoutError() const {
1659 return (_playError > 0); 1563 return (_playError > 0);
1660 } 1564 }
1661 1565
1662 bool AudioDeviceMac::RecordingWarning() const { 1566 bool AudioDeviceMac::RecordingWarning() const {
1663 return (_recWarning > 0); 1567 return (_recWarning > 0);
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; 1875 kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
1972 #ifdef WEBRTC_ARCH_BIG_ENDIAN 1876 #ifdef WEBRTC_ARCH_BIG_ENDIAN
1973 _outDesiredFormat.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian; 1877 _outDesiredFormat.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
1974 #endif 1878 #endif
1975 _outDesiredFormat.mFormatID = kAudioFormatLinearPCM; 1879 _outDesiredFormat.mFormatID = kAudioFormatLinearPCM;
1976 1880
1977 OSStatus err = noErr; 1881 OSStatus err = noErr;
1978 WEBRTC_CA_RETURN_ON_ERR(AudioConverterNew( 1882 WEBRTC_CA_RETURN_ON_ERR(AudioConverterNew(
1979 &_outDesiredFormat, &_outStreamFormat, &_renderConverter)); 1883 &_outDesiredFormat, &_outStreamFormat, &_renderConverter));
1980 1884
1981 // Try to set buffer size to desired value (_playBufDelayFixed). 1885 // Try to set buffer size to desired value set to 20ms.
1886 const uint16_t kPlayBufDelayFixed = 20;
1982 UInt32 bufByteCount = static_cast<UInt32>( 1887 UInt32 bufByteCount = static_cast<UInt32>(
1983 (_outStreamFormat.mSampleRate / 1000.0) * _playBufDelayFixed * 1888 (_outStreamFormat.mSampleRate / 1000.0) * kPlayBufDelayFixed *
1984 _outStreamFormat.mChannelsPerFrame * sizeof(Float32)); 1889 _outStreamFormat.mChannelsPerFrame * sizeof(Float32));
1985 if (_outStreamFormat.mFramesPerPacket != 0) { 1890 if (_outStreamFormat.mFramesPerPacket != 0) {
1986 if (bufByteCount % _outStreamFormat.mFramesPerPacket != 0) { 1891 if (bufByteCount % _outStreamFormat.mFramesPerPacket != 0) {
1987 bufByteCount = (static_cast<UInt32>(bufByteCount / 1892 bufByteCount = (static_cast<UInt32>(bufByteCount /
1988 _outStreamFormat.mFramesPerPacket) + 1893 _outStreamFormat.mFramesPerPacket) +
1989 1) * 1894 1) *
1990 _outStreamFormat.mFramesPerPacket; 1895 _outStreamFormat.mFramesPerPacket;
1991 } 1896 }
1992 } 1897 }
1993 1898
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
2697 bool keyState = 2602 bool keyState =
2698 CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key_index); 2603 CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key_index);
2699 // A false -> true change in keymap means a key is pressed. 2604 // A false -> true change in keymap means a key is pressed.
2700 key_down |= (keyState && !prev_key_state_[key_index]); 2605 key_down |= (keyState && !prev_key_state_[key_index]);
2701 // Save current state. 2606 // Save current state.
2702 prev_key_state_[key_index] = keyState; 2607 prev_key_state_[key_index] = keyState;
2703 } 2608 }
2704 return key_down; 2609 return key_down;
2705 } 2610 }
2706 } // namespace webrtc 2611 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/mac/audio_device_mac.h ('k') | webrtc/modules/audio_device/mac/audio_mixer_manager_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698