Commit 745f1aa5 authored by Ghislain MARY's avatar Ghislain MARY

Use the IAudioClient2 interface instead of IAudioClient and set the...

Use the IAudioClient2 interface instead of IAudioClient and set the Communications category for the audio session.
parent 03b26ec5
...@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mswasapi_writer.h" #include "mswasapi_writer.h"
const IID IID_IAudioClient = __uuidof(IAudioClient); const IID IID_IAudioClient2 = __uuidof(IAudioClient2);
const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient); const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient); const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
......
...@@ -53,6 +53,7 @@ MSWASAPIReader::MSWASAPIReader() ...@@ -53,6 +53,7 @@ MSWASAPIReader::MSWASAPIReader()
{ {
HRESULT result; HRESULT result;
WAVEFORMATEX *pWfx = NULL; WAVEFORMATEX *pWfx = NULL;
AudioClientProperties properties;
mCaptureId = GetDefaultAudioCaptureId(Communications); mCaptureId = GetDefaultAudioCaptureId(Communications);
if (mCaptureId == NULL) { if (mCaptureId == NULL) {
...@@ -65,8 +66,13 @@ MSWASAPIReader::MSWASAPIReader() ...@@ -65,8 +66,13 @@ MSWASAPIReader::MSWASAPIReader()
goto error; goto error;
} }
result = ActivateAudioInterface(mCaptureId, IID_IAudioClient, (void **)&mAudioClient); result = ActivateAudioInterface(mCaptureId, IID_IAudioClient2, (void **)&mAudioClient);
REPORT_ERROR("Could not activate the MSWASAPI audio input interface [%i]", result); REPORT_ERROR("Could not activate the MSWASAPI audio input interface [%i]", result);
properties.cbSize = sizeof AudioClientProperties;
properties.bIsOffload = false;
properties.eCategory = AudioCategory_Communications;
result = mAudioClient->SetClientProperties(&properties);
REPORT_ERROR("Could not set properties of the MSWASAPI audio output interface [%i]", result);
result = mAudioClient->GetMixFormat(&pWfx); result = mAudioClient->GetMixFormat(&pWfx);
REPORT_ERROR("Could not get the mix format of the MSWASAPI audio input interface [%i]", result); REPORT_ERROR("Could not get the mix format of the MSWASAPI audio input interface [%i]", result);
mRate = pWfx->nSamplesPerSec; mRate = pWfx->nSamplesPerSec;
...@@ -98,6 +104,7 @@ int MSWASAPIReader::activate() ...@@ -98,6 +104,7 @@ int MSWASAPIReader::activate()
WAVEFORMATPCMEX proposedWfx; WAVEFORMATPCMEX proposedWfx;
WAVEFORMATEX *pUsedWfx = NULL; WAVEFORMATEX *pUsedWfx = NULL;
WAVEFORMATEX *pSupportedWfx = NULL; WAVEFORMATEX *pSupportedWfx = NULL;
DWORD flags = AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED | AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE | AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED;
if (!mIsInitialized) goto error; if (!mIsInitialized) goto error;
...@@ -123,7 +130,7 @@ int MSWASAPIReader::activate() ...@@ -123,7 +130,7 @@ int MSWASAPIReader::activate()
} else { } else {
REPORT_ERROR("Audio format not supported by the MSWASAPI audio input interface [%i]", result); REPORT_ERROR("Audio format not supported by the MSWASAPI audio input interface [%i]", result);
} }
result = mAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, requestedDuration, 0, pUsedWfx, NULL); result = mAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, flags, requestedDuration, 0, pUsedWfx, NULL);
REPORT_ERROR("Could not initialize the MSWASAPI audio input interface [%i]", result); REPORT_ERROR("Could not initialize the MSWASAPI audio input interface [%i]", result);
result = mAudioClient->GetBufferSize(&mBufferFrameCount); result = mAudioClient->GetBufferSize(&mBufferFrameCount);
REPORT_ERROR("Could not get buffer size for the MSWASAPI audio input interface [%i]", result); REPORT_ERROR("Could not get buffer size for the MSWASAPI audio input interface [%i]", result);
......
...@@ -21,6 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -21,6 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#pragma once
#include "mediastreamer2/msfilter.h" #include "mediastreamer2/msfilter.h"
#include <objbase.h> #include <objbase.h>
...@@ -48,7 +51,7 @@ private: ...@@ -48,7 +51,7 @@ private:
static bool smInstantiated; static bool smInstantiated;
LPCWSTR mCaptureId; LPCWSTR mCaptureId;
IAudioClient *mAudioClient; IAudioClient2 *mAudioClient;
IAudioCaptureClient *mAudioCaptureClient; IAudioCaptureClient *mAudioCaptureClient;
UINT32 mBufferFrameCount; UINT32 mBufferFrameCount;
bool mIsInitialized; bool mIsInitialized;
......
...@@ -52,6 +52,7 @@ MSWASAPIWriter::MSWASAPIWriter() ...@@ -52,6 +52,7 @@ MSWASAPIWriter::MSWASAPIWriter()
{ {
HRESULT result; HRESULT result;
WAVEFORMATEX *pWfx = NULL; WAVEFORMATEX *pWfx = NULL;
AudioClientProperties properties;
mRenderId = GetDefaultAudioRenderId(Communications); mRenderId = GetDefaultAudioRenderId(Communications);
if (mRenderId == NULL) { if (mRenderId == NULL) {
...@@ -64,8 +65,13 @@ MSWASAPIWriter::MSWASAPIWriter() ...@@ -64,8 +65,13 @@ MSWASAPIWriter::MSWASAPIWriter()
goto error; goto error;
} }
result = ActivateAudioInterface(mRenderId, IID_IAudioClient, (void **)&mAudioClient); result = ActivateAudioInterface(mRenderId, IID_IAudioClient2, (void **)&mAudioClient);
REPORT_ERROR("Could not activate the MSWASAPI audio output interface [%i]", result); REPORT_ERROR("Could not activate the MSWASAPI audio output interface [%i]", result);
properties.cbSize = sizeof AudioClientProperties;
properties.bIsOffload = false;
properties.eCategory = AudioCategory_Communications;
result = mAudioClient->SetClientProperties(&properties);
REPORT_ERROR("Could not set properties of the MSWASAPI audio output interface [%i]", result);
result = mAudioClient->GetMixFormat(&pWfx); result = mAudioClient->GetMixFormat(&pWfx);
REPORT_ERROR("Could not get the mix format of the MSWASAPI audio output interface [%i]", result); REPORT_ERROR("Could not get the mix format of the MSWASAPI audio output interface [%i]", result);
mRate = pWfx->nSamplesPerSec; mRate = pWfx->nSamplesPerSec;
......
...@@ -21,6 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -21,6 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#pragma once
#include "mediastreamer2/msfilter.h" #include "mediastreamer2/msfilter.h"
#include <objbase.h> #include <objbase.h>
...@@ -48,7 +51,7 @@ private: ...@@ -48,7 +51,7 @@ private:
static bool smInstantiated; static bool smInstantiated;
LPCWSTR mRenderId; LPCWSTR mRenderId;
IAudioClient *mAudioClient; IAudioClient2 *mAudioClient;
IAudioRenderClient *mAudioRenderClient; IAudioRenderClient *mAudioRenderClient;
UINT32 mBufferFrameCount; UINT32 mBufferFrameCount;
bool mIsInitialized; bool mIsInitialized;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment