GetSimpleAudioVolume
AudioDeviceWindowsCore
GetSimpleAudioVolume 返回值赋值到 _ptrRenderSimpleVolume
源码分析
h:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\media\engine\webrtc_voice_engine.cc
WebRtcVoiceEngine::Init
void WebRtcVoiceEngine::Init() {
***
RTC_CHECK(adm());
webrtc::adm_helpers::Init(adm());
***
}
这时候进入到
H:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\media\engine\adm_helpers.cc
void Init(AudioDeviceModule adm) 方法
这时候进入到
H:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\media\engine\adm_helpers.cc
void Init(AudioDeviceModule adm) 方法
webrtc::adm_helpers::Init
void Init(AudioDeviceModule* adm) {
RTC_DCHECK(adm);
****
// Playout device.
{
if (adm->SetPlayoutDevice(AUDIO_DEVICE_ID) != 0) {
RTC_LOG(LS_ERROR) << "Unable to set playout device.";
return;
}
if (adm->InitSpeaker() != 0) {
RTC_LOG(LS_ERROR) << "Unable to access speaker.";
}
***
}
AudioDeviceModuleImpl::InitSpeaker
int32_t AudioDeviceModuleImpl::InitSpeaker() {
RTC_LOG(INFO) << __FUNCTION__;
CHECKinitialized_();
return audio_device_->InitSpeaker();
}
AudioDeviceWindowsCore::InitSpeaker
int32_t AudioDeviceWindowsCore::InitSpeaker() {
MutexLock lock(&mutex_);
return InitSpeakerLocked();
}
AudioDeviceWindowsCore::InitSpeakerLocked
int32_t AudioDeviceWindowsCore::InitSpeakerLocked() {
if (_playing) {
return -1;
}
if (_ptrDeviceOut == NULL) {
return -1;
}
if (_usingOutputDeviceIndex) {
int16_t nDevices = PlayoutDevicesLocked();
if (_outputDeviceIndex > (nDevices - 1)) {
RTC_LOG(LS_ERROR) << "current device selection is invalid => unable to"
" initialize";
return -1;
}
}
int32_t ret(0);
SAFE_RELEASE(_ptrDeviceOut);
if (_usingOutputDeviceIndex) {
// Refresh the selected rendering endpoint device using current index
ret = _GetListDevice(eRender, _outputDeviceIndex, &_ptrDeviceOut);
} else {
ERole role;
(_outputDevice == AudioDeviceModule::kDefaultDevice)
? role = eConsole
: role = eCommunications;
// Refresh the selected rendering endpoint device using role
// 里面会调用 _ptrEnumerator->GetDefaultAudioEndpoint(dir, role, ppDevice)
// 刷新是必须的,避免操作时设备已经没有了。
ret = _GetDefaultDevice(eRender, role, &_ptrDeviceOut);
}
if (ret != 0 || (_ptrDeviceOut == NULL)) {
RTC_LOG(LS_ERROR) << "failed to initialize the rendering enpoint device";
SAFE_RELEASE(_ptrDeviceOut);
return -1;
}
IAudioSessionManager* pManager = NULL;
ret = _ptrDeviceOut->Activate(__uuidof(IAudioSessionManager), CLSCTX_ALL,
NULL, (void**)&pManager);
if (ret != 0 || pManager == NULL) {
RTC_LOG(LS_ERROR) << "failed to initialize the render manager";
SAFE_RELEASE(pManager);
return -1;
}
//通过上面的pManager来获取操作音频音量对象,NULL音频流使用默认session,FALSE非跨进程
SAFE_RELEASE(_ptrRenderSimpleVolume);
ret = pManager->GetSimpleAudioVolume(NULL, FALSE, &_ptrRenderSimpleVolume);
if (ret != 0 || _ptrRenderSimpleVolume == NULL) {
RTC_LOG(LS_ERROR) << "failed to initialize the render simple volume";
SAFE_RELEASE(pManager);
SAFE_RELEASE(_ptrRenderSimpleVolume);
return -1;
}
SAFE_RELEASE(pManager);
_speakerIsInitialized = true;
return 0;
}