Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 4da180d

Browse files
authored
Fix C2362 error when build audio_device_core_win with MSVC. (#172)
1 parent 9f7e0a6 commit 4da180d

File tree

1 file changed

+42
-25
lines changed

1 file changed

+42
-25
lines changed

modules/audio_device/win/audio_device_core_win.cc

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -845,14 +845,15 @@ int32_t AudioDeviceWindowsCore::SpeakerVolumeIsAvailable(bool& available) {
845845
IAudioSessionManager* pManager = NULL;
846846
ISimpleAudioVolume* pVolume = NULL;
847847

848+
float volume(0.0f);
849+
848850
hr = _ptrDeviceOut->Activate(__uuidof(IAudioSessionManager), CLSCTX_ALL, NULL,
849851
(void**)&pManager);
850852
EXIT_ON_ERROR(hr);
851853

852854
hr = pManager->GetSimpleAudioVolume(NULL, FALSE, &pVolume);
853855
EXIT_ON_ERROR(hr);
854856

855-
float volume(0.0f);
856857
hr = pVolume->GetMasterVolume(&volume);
857858
if (FAILED(hr)) {
858859
available = false;
@@ -1031,12 +1032,13 @@ int32_t AudioDeviceWindowsCore::SetSpeakerMute(bool enable) {
10311032
HRESULT hr = S_OK;
10321033
IAudioEndpointVolume* pVolume = NULL;
10331034

1035+
const BOOL mute(enable);
1036+
10341037
// Set the speaker system mute state.
10351038
hr = _ptrDeviceOut->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL,
10361039
reinterpret_cast<void**>(&pVolume));
10371040
EXIT_ON_ERROR(hr);
10381041

1039-
const BOOL mute(enable);
10401042
hr = pVolume->SetMute(mute, NULL);
10411043
EXIT_ON_ERROR(hr);
10421044

@@ -1138,12 +1140,13 @@ int32_t AudioDeviceWindowsCore::SetMicrophoneMute(bool enable) {
11381140
HRESULT hr = S_OK;
11391141
IAudioEndpointVolume* pVolume = NULL;
11401142

1143+
const BOOL mute(enable);
1144+
11411145
// Set the microphone system mute state.
11421146
hr = _ptrDeviceIn->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL,
11431147
reinterpret_cast<void**>(&pVolume));
11441148
EXIT_ON_ERROR(hr);
11451149

1146-
const BOOL mute(enable);
11471150
hr = pVolume->SetMute(mute, NULL);
11481151
EXIT_ON_ERROR(hr);
11491152

@@ -1286,11 +1289,12 @@ int32_t AudioDeviceWindowsCore::MicrophoneVolumeIsAvailable(bool& available) {
12861289
HRESULT hr = S_OK;
12871290
IAudioEndpointVolume* pVolume = NULL;
12881291

1292+
float volume(0.0f);
1293+
12891294
hr = _ptrDeviceIn->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL,
12901295
reinterpret_cast<void**>(&pVolume));
12911296
EXIT_ON_ERROR(hr);
12921297

1293-
float volume(0.0f);
12941298
hr = pVolume->GetMasterVolumeLevelScalar(&volume);
12951299
if (FAILED(hr)) {
12961300
available = false;
@@ -1878,6 +1882,11 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
18781882
WAVEFORMATEX Wfx = WAVEFORMATEX();
18791883
WAVEFORMATEX* pWfxClosestMatch = NULL;
18801884

1885+
UINT bufferFrameCount(0);
1886+
REFERENCE_TIME hnsBufferDuration =
1887+
0; // ask for minimum buffer size (default)
1888+
const int freqs[] = {48000, 44100, 16000, 96000, 32000, 8000};
1889+
18811890
// Create COM object with IAudioClient interface.
18821891
SAFE_RELEASE(_ptrClientOut);
18831892
hr = _ptrDeviceOut->Activate(__uuidof(IAudioClient), CLSCTX_ALL, NULL,
@@ -1911,7 +1920,6 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
19111920
Wfx.wBitsPerSample = 16;
19121921
Wfx.cbSize = 0;
19131922

1914-
const int freqs[] = {48000, 44100, 16000, 96000, 32000, 8000};
19151923
hr = S_FALSE;
19161924

19171925
// Iterate over frequencies and channels, in order of priority
@@ -1997,8 +2005,7 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
19972005
// buffer.
19982006
// ****************************************************************************
19992007
//
2000-
REFERENCE_TIME hnsBufferDuration =
2001-
0; // ask for minimum buffer size (default)
2008+
20022009
if (_devicePlaySampleRate == 44100) {
20032010
// Ask for a larger buffer size (30ms) when using 44.1kHz as render rate.
20042011
// There seems to be a larger risk of underruns for 44.1 compared
@@ -2008,6 +2015,7 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
20082015
// read by GetBufferSize() and it is 20ms on most machines.
20092016
hnsBufferDuration = 30 * 10000;
20102017
}
2018+
20112019
hr = _ptrClientOut->Initialize(
20122020
AUDCLNT_SHAREMODE_SHARED, // share Audio Engine with other applications
20132021
AUDCLNT_STREAMFLAGS_EVENTCALLBACK, // processing of the audio buffer by
@@ -2038,7 +2046,6 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
20382046

20392047
// Get the actual size of the shared (endpoint buffer).
20402048
// Typical value is 960 audio frames <=> 20ms @ 48kHz sample rate.
2041-
UINT bufferFrameCount(0);
20422049
hr = _ptrClientOut->GetBufferSize(&bufferFrameCount);
20432050
if (SUCCEEDED(hr)) {
20442051
RTC_LOG(LS_VERBOSE) << "IAudioClient::GetBufferSize() => "
@@ -2195,6 +2202,10 @@ int32_t AudioDeviceWindowsCore::InitRecording() {
21952202
WAVEFORMATEXTENSIBLE Wfx = WAVEFORMATEXTENSIBLE();
21962203
WAVEFORMATEX* pWfxClosestMatch = NULL;
21972204

2205+
UINT bufferFrameCount(0);
2206+
2207+
const int freqs[6] = {48000, 44100, 16000, 96000, 32000, 8000};
2208+
21982209
// Create COM object with IAudioClient interface.
21992210
SAFE_RELEASE(_ptrClientIn);
22002211
hr = _ptrDeviceIn->Activate(__uuidof(IAudioClient), CLSCTX_ALL, NULL,
@@ -2231,7 +2242,6 @@ int32_t AudioDeviceWindowsCore::InitRecording() {
22312242
Wfx.Samples.wValidBitsPerSample = Wfx.Format.wBitsPerSample;
22322243
Wfx.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
22332244

2234-
const int freqs[6] = {48000, 44100, 16000, 96000, 32000, 8000};
22352245
hr = S_FALSE;
22362246

22372247
// Iterate over frequencies and channels, in order of priority
@@ -2328,7 +2338,6 @@ int32_t AudioDeviceWindowsCore::InitRecording() {
23282338

23292339
// Get the actual size of the shared (endpoint buffer).
23302340
// Typical value is 960 audio frames <=> 20ms @ 48kHz sample rate.
2331-
UINT bufferFrameCount(0);
23322341
hr = _ptrClientIn->GetBufferSize(&bufferFrameCount);
23332342
if (SUCCEEDED(hr)) {
23342343
RTC_LOG(LS_VERBOSE) << "IAudioClient::GetBufferSize() => "
@@ -2734,6 +2743,14 @@ DWORD AudioDeviceWindowsCore::DoRenderThread() {
27342743
//
27352744
UINT32 bufferLength = 0;
27362745
hr = _ptrClientOut->GetBufferSize(&bufferLength);
2746+
2747+
REFERENCE_TIME devPeriod = 0;
2748+
REFERENCE_TIME devPeriodMin = 0;
2749+
double endpointBufferSizeMS =
2750+
10.0 * ((double)bufferLength / (double)_devicePlayBlockSize);
2751+
BYTE* pData = NULL;
2752+
int playout_delay = 0;
2753+
27372754
EXIT_ON_ERROR(hr);
27382755
RTC_LOG(LS_VERBOSE) << "[REND] size of buffer : " << bufferLength;
27392756

@@ -2755,29 +2772,24 @@ DWORD AudioDeviceWindowsCore::DoRenderThread() {
27552772
// an audio application can achieve. Typical value: 100000 <=> 0.01 sec =
27562773
// 10ms.
27572774
//
2758-
REFERENCE_TIME devPeriod = 0;
2759-
REFERENCE_TIME devPeriodMin = 0;
27602775
_ptrClientOut->GetDevicePeriod(&devPeriod, &devPeriodMin);
27612776
RTC_LOG(LS_VERBOSE) << "[REND] device period : " << (DWORD)devPeriod
27622777
<< " (" << (double)(devPeriod / 10000.0) << " ms)";
27632778

27642779
// Derive initial rendering delay.
27652780
// Example: 10*(960/480) + 15 = 20 + 15 = 35ms
27662781
//
2767-
int playout_delay = 10 * (bufferLength / _playBlockSize) +
2782+
playout_delay = 10 * (bufferLength / _playBlockSize) +
27682783
(int)((latency + devPeriod) / 10000);
27692784
_sndCardPlayDelay = playout_delay;
27702785
_writtenSamples = 0;
27712786
RTC_LOG(LS_VERBOSE) << "[REND] initial delay : " << playout_delay;
27722787

2773-
double endpointBufferSizeMS =
2774-
10.0 * ((double)bufferLength / (double)_devicePlayBlockSize);
27752788
RTC_LOG(LS_VERBOSE) << "[REND] endpointBufferSizeMS : "
27762789
<< endpointBufferSizeMS;
27772790

27782791
// Before starting the stream, fill the rendering buffer with silence.
27792792
//
2780-
BYTE* pData = NULL;
27812793
hr = _ptrRenderClient->GetBuffer(bufferLength, &pData);
27822794
EXIT_ON_ERROR(hr);
27832795

@@ -3152,6 +3164,9 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread() {
31523164

31533165
_Lock();
31543166

3167+
double endpointBufferSizeMS = 0;
3168+
double extraDelayMS = 0;
3169+
31553170
// Get size of capturing buffer (length is expressed as the number of audio
31563171
// frames the buffer can hold). This value is fixed during the capturing
31573172
// session.
@@ -3163,14 +3178,18 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread() {
31633178
return 1;
31643179
}
31653180
hr = _ptrClientIn->GetBufferSize(&bufferLength);
3181+
3182+
const UINT32 syncBufferSize = 2 * (bufferLength * _recAudioFrameSize);
3183+
REFERENCE_TIME devPeriod = 0;
3184+
REFERENCE_TIME devPeriodMin = 0;
3185+
31663186
EXIT_ON_ERROR(hr);
31673187
RTC_LOG(LS_VERBOSE) << "[CAPT] size of buffer : " << bufferLength;
31683188

31693189
// Allocate memory for sync buffer.
31703190
// It is used for compensation between native 44.1 and internal 44.0 and
31713191
// for cases when the capture buffer is larger than 10ms.
31723192
//
3173-
const UINT32 syncBufferSize = 2 * (bufferLength * _recAudioFrameSize);
31743193
syncBuffer = new BYTE[syncBufferSize];
31753194
if (syncBuffer == NULL) {
31763195
return (DWORD)E_POINTER;
@@ -3189,16 +3208,14 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread() {
31893208
// Get the length of the periodic interval separating successive processing
31903209
// passes by the audio engine on the data in the endpoint buffer.
31913210
//
3192-
REFERENCE_TIME devPeriod = 0;
3193-
REFERENCE_TIME devPeriodMin = 0;
31943211
_ptrClientIn->GetDevicePeriod(&devPeriod, &devPeriodMin);
31953212
RTC_LOG(LS_VERBOSE) << "[CAPT] device period : " << (DWORD)devPeriod
31963213
<< " (" << (double)(devPeriod / 10000.0) << " ms)";
31973214

3198-
double extraDelayMS = (double)((latency + devPeriod) / 10000.0);
3215+
extraDelayMS = (double)((latency + devPeriod) / 10000.0);
31993216
RTC_LOG(LS_VERBOSE) << "[CAPT] extraDelayMS : " << extraDelayMS;
32003217

3201-
double endpointBufferSizeMS =
3218+
endpointBufferSizeMS =
32023219
10.0 * ((double)bufferLength / (double)_recBlockSize);
32033220
RTC_LOG(LS_VERBOSE) << "[CAPT] endpointBufferSizeMS : "
32043221
<< endpointBufferSizeMS;
@@ -4012,6 +4029,10 @@ int32_t AudioDeviceWindowsCore::_EnumerateEndpointDevicesAll(
40124029
IAudioEndpointVolume* pEndpointVolume = NULL;
40134030
LPWSTR pwszID = NULL;
40144031

4032+
DWORD dwHwSupportMask = 0;
4033+
UINT count = 0;
4034+
UINT nChannelCount(0);
4035+
40154036
// Generate a collection of audio endpoint devices in the system.
40164037
// Get states for *all* endpoint devices.
40174038
// Output: IMMDeviceCollection interface.
@@ -4024,8 +4045,6 @@ int32_t AudioDeviceWindowsCore::_EnumerateEndpointDevicesAll(
40244045

40254046
// use the IMMDeviceCollection interface...
40264047

4027-
UINT count = 0;
4028-
40294048
// Retrieve a count of the devices in the device collection.
40304049
hr = pCollection->GetCount(&count);
40314050
EXIT_ON_ERROR(hr);
@@ -4092,7 +4111,6 @@ int32_t AudioDeviceWindowsCore::_EnumerateEndpointDevicesAll(
40924111
<< ") : UNPLUGGED";
40934112

40944113
// Check the hardware volume capabilities.
4095-
DWORD dwHwSupportMask = 0;
40964114
hr = pEndpoint->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL,
40974115
(void**)&pEndpointVolume);
40984116
CONTINUE_ON_ERROR(hr);
@@ -4113,7 +4131,6 @@ int32_t AudioDeviceWindowsCore::_EnumerateEndpointDevicesAll(
41134131

41144132
// Check the channel count (#channels in the audio stream that enters or
41154133
// leaves the audio endpoint device)
4116-
UINT nChannelCount(0);
41174134
hr = pEndpointVolume->GetChannelCount(&nChannelCount);
41184135
CONTINUE_ON_ERROR(hr);
41194136
RTC_LOG(LS_VERBOSE) << "#channels : " << nChannelCount;

0 commit comments

Comments
 (0)