IAudioEndpointVolume

image.png

AudioDeviceWindowsCore

image.png

源码分析

H:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\media\engine\adm_helpers.cc
void Init(AudioDeviceModule* adm) 方法

webrtc::adm_helpers::Init

  1. void Init(AudioDeviceModule* adm) {
  2. ***
  3. // Recording device.
  4. {
  5. if (adm->SetRecordingDevice(AUDIO_DEVICE_ID) != 0) {
  6. RTC_LOG(LS_ERROR) << "Unable to set recording device.";
  7. return;
  8. }
  9. if (adm->InitMicrophone() != 0) {
  10. RTC_LOG(LS_ERROR) << "Unable to access microphone.";
  11. }
  12. // Set number of channels
  13. bool available = false;
  14. if (adm->StereoRecordingIsAvailable(&available) != 0) {
  15. RTC_LOG(LS_ERROR) << "Failed to query stereo recording.";
  16. }
  17. if (adm->SetStereoRecording(available) != 0) {
  18. RTC_LOG(LS_ERROR) << "Failed to set stereo recording mode.";
  19. }
  20. }
  21. }
  22. adm->InitMicrophone()
  23. ->
  24. AudioDeviceModuleImpl::InitMicrophone
  25. ->
  26. AudioDeviceWindowsCore::InitMicrophone
  27. ->
  28. AudioDeviceWindowsCore::InitMicrophoneLocked

AudioDeviceWindowsCore::InitMicrophoneLocked

  1. int32_t AudioDeviceWindowsCore::InitMicrophoneLocked() {
  2. **
  3. if (_usingInputDeviceIndex) {
  4. **
  5. } else {
  6. ERole role;
  7. (_inputDevice == AudioDeviceModule::kDefaultDevice)
  8. ? role = eConsole
  9. : role = eCommunications;
  10. // Refresh the selected capture endpoint device using role
  11. ret = _GetDefaultDevice(eCapture, role, &_ptrDeviceIn);
  12. }
  13. **
  14. SAFE_RELEASE(_ptrCaptureVolume);
  15. ret = _ptrDeviceIn->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL,
  16. reinterpret_cast<void**>(&_ptrCaptureVolume));
  17. if (ret != 0 || _ptrCaptureVolume == NULL) {
  18. RTC_LOG(LS_ERROR) << "failed to initialize the capture volume";
  19. SAFE_RELEASE(_ptrCaptureVolume);
  20. return -1;
  21. }
  22. _microphoneIsInitialized = true;
  23. return 0;
  24. }

image.png