summaryrefslogtreecommitdiffstats
path: root/plugins/pluginWASAPI
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pluginWASAPI')
-rwxr-xr-xplugins/pluginWASAPI/dllmain_wasapi.cxx105
-rwxr-xr-xplugins/pluginWASAPI/plugin_wasapi_config.h12
-rwxr-xr-xplugins/pluginWASAPI/plugin_wasapi_consumer_audio.cxx953
-rwxr-xr-xplugins/pluginWASAPI/plugin_wasapi_producer_audio.cxx968
-rwxr-xr-xplugins/pluginWASAPI/plugin_wasapi_tdav.cxx6
-rwxr-xr-xplugins/pluginWASAPI/plugin_wasapi_utils.cxx76
-rwxr-xr-xplugins/pluginWASAPI/plugin_wasapi_utils.h16
7 files changed, 1008 insertions, 1128 deletions
diff --git a/plugins/pluginWASAPI/dllmain_wasapi.cxx b/plugins/pluginWASAPI/dllmain_wasapi.cxx
index ff13977..1ba8313 100755
--- a/plugins/pluginWASAPI/dllmain_wasapi.cxx
+++ b/plugins/pluginWASAPI/dllmain_wasapi.cxx
@@ -1,18 +1,18 @@
/* Copyright (C) 2013 Mamadou DIOP
* Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/
@@ -48,87 +48,80 @@ PLUGIN_WASAPI_END_DECLS /* END */
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
- )
+ )
{
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- break;
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
+ switch (ul_reason_for_call) {
+ case DLL_PROCESS_ATTACH:
+ break;
+ case DLL_THREAD_ATTACH:
+ break;
+ case DLL_THREAD_DETACH:
+ break;
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
}
-typedef enum PLUGIN_INDEX_E
-{
+typedef enum PLUGIN_INDEX_E {
#if PLUGIN_WASAPI_ENABLE
- PLUGIN_INDEX_CONSUMER,
- PLUGIN_INDEX_PRODUCER,
+ PLUGIN_INDEX_CONSUMER,
+ PLUGIN_INDEX_PRODUCER,
#endif
-
- PLUGIN_INDEX_COUNT
+
+ PLUGIN_INDEX_COUNT
}
PLUGIN_INDEX_T;
int __plugin_get_def_count()
{
- return PLUGIN_INDEX_COUNT;
+ return PLUGIN_INDEX_COUNT;
}
tsk_plugin_def_type_t __plugin_get_def_type_at(int index)
{
#if PLUGIN_WASAPI_ENABLE
- switch(index){
- case PLUGIN_INDEX_CONSUMER:
- {
- return tsk_plugin_def_type_consumer;
- }
- case PLUGIN_INDEX_PRODUCER:
- {
- return tsk_plugin_def_type_producer;
- }
- }
+ switch(index) {
+ case PLUGIN_INDEX_CONSUMER: {
+ return tsk_plugin_def_type_consumer;
+ }
+ case PLUGIN_INDEX_PRODUCER: {
+ return tsk_plugin_def_type_producer;
+ }
+ }
#endif
- TSK_DEBUG_ERROR("No plugin at index %d", index);
- return tsk_plugin_def_type_none;
+ TSK_DEBUG_ERROR("No plugin at index %d", index);
+ return tsk_plugin_def_type_none;
}
tsk_plugin_def_media_type_t __plugin_get_def_media_type_at(int index)
{
#if PLUGIN_WASAPI_ENABLE
- switch(index){
- case PLUGIN_INDEX_CONSUMER:
- case PLUGIN_INDEX_PRODUCER:
- {
- return tsk_plugin_def_media_type_audio;
- }
- }
+ switch(index) {
+ case PLUGIN_INDEX_CONSUMER:
+ case PLUGIN_INDEX_PRODUCER: {
+ return tsk_plugin_def_media_type_audio;
+ }
+ }
#endif
- TSK_DEBUG_ERROR("No plugin at index %d", index);
- return tsk_plugin_def_media_type_none;
+ TSK_DEBUG_ERROR("No plugin at index %d", index);
+ return tsk_plugin_def_media_type_none;
}
tsk_plugin_def_ptr_const_t __plugin_get_def_at(int index)
{
#if PLUGIN_WASAPI_ENABLE
- switch(index){
- case PLUGIN_INDEX_CONSUMER:
- {
- return plugin_wasapi_consumer_audio_plugin_def_t;
- }
- case PLUGIN_INDEX_PRODUCER:
- {
- return plugin_wasapi_producer_audio_plugin_def_t;
- }
- }
+ switch(index) {
+ case PLUGIN_INDEX_CONSUMER: {
+ return plugin_wasapi_consumer_audio_plugin_def_t;
+ }
+ case PLUGIN_INDEX_PRODUCER: {
+ return plugin_wasapi_producer_audio_plugin_def_t;
+ }
+ }
#endif
- TSK_DEBUG_ERROR("No plugin at index %d", index);
- return tsk_null;
+ TSK_DEBUG_ERROR("No plugin at index %d", index);
+ return tsk_null;
}
diff --git a/plugins/pluginWASAPI/plugin_wasapi_config.h b/plugins/pluginWASAPI/plugin_wasapi_config.h
index d5f742f..822c575 100755
--- a/plugins/pluginWASAPI/plugin_wasapi_config.h
+++ b/plugins/pluginWASAPI/plugin_wasapi_config.h
@@ -1,18 +1,18 @@
/* Copyright (C) 2013 Mamadou DIOP
* Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/
@@ -51,12 +51,12 @@
# define PLUGIN_WASAPI_UNDER_X86 1
#endif
-// Guards against C++ name mangling
+// Guards against C++ name mangling
#ifdef __cplusplus
# define PLUGIN_WASAPI_BEGIN_DECLS extern "C" {
# define PLUGIN_WASAPI_END_DECLS }
#else
-# define PLUGIN_WASAPI_BEGIN_DECLS
+# define PLUGIN_WASAPI_BEGIN_DECLS
# define PLUGIN_WASAPI_END_DECLS
#endif
@@ -72,7 +72,7 @@
#endif
#if HAVE_CONFIG_H
- #include <config.h>
+#include <config.h>
#endif
#endif // PLUGIN_WASAPI_CONFIG_H
diff --git a/plugins/pluginWASAPI/plugin_wasapi_consumer_audio.cxx b/plugins/pluginWASAPI/plugin_wasapi_consumer_audio.cxx
index 97db2eb..74d0383 100755
--- a/plugins/pluginWASAPI/plugin_wasapi_consumer_audio.cxx
+++ b/plugins/pluginWASAPI/plugin_wasapi_consumer_audio.cxx
@@ -1,18 +1,18 @@
/*Copyright (C) 2013 Mamadou Diop
* Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/
@@ -22,7 +22,7 @@
*/
#include "plugin_wasapi_utils.h"
-#include "tinydav/audio/tdav_consumer_audio.h"
+#include "tinydav/audio/tdav_consumer_audio.h"
#include "tsk_thread.h"
#include "tsk_memory.h"
@@ -52,58 +52,55 @@ struct plugin_wasapi_consumer_audio_s;
class AudioRender sealed
{
public:
- AudioRender();
- virtual ~AudioRender();
-
- int Prepare(struct plugin_wasapi_consumer_audio_s* wasapi, const tmedia_codec_t* codec);
- int UnPrepare();
- int Start();
- int Stop();
- int Pause();
- int Consume(const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr);
+ AudioRender();
+ virtual ~AudioRender();
+
+ int Prepare(struct plugin_wasapi_consumer_audio_s* wasapi, const tmedia_codec_t* codec);
+ int UnPrepare();
+ int Start();
+ int Stop();
+ int Pause();
+ int Consume(const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr);
private:
- tsk_size_t Read(void* data, tsk_size_t size);
- static void* TSK_STDCALL AsyncThread(void *pArg);
+ tsk_size_t Read(void* data, tsk_size_t size);
+ static void* TSK_STDCALL AsyncThread(void *pArg);
private:
- tsk_mutex_handle_t* m_hMutex;
- const struct plugin_wasapi_consumer_audio_s* m_pWrappedConsumer; // Must not take ref() otherwise dtor() will be never called (circular reference)
+ tsk_mutex_handle_t* m_hMutex;
+ const struct plugin_wasapi_consumer_audio_s* m_pWrappedConsumer; // Must not take ref() otherwise dtor() will be never called (circular reference)
#if PLUGIN_WASAPI_UNDER_WINDOWS_PHONE
- IAudioClient2* m_pDevice;
+ IAudioClient2* m_pDevice;
#else
- IAudioClient* m_pDevice;
+ IAudioClient* m_pDevice;
#endif
- IAudioRenderClient* m_pClient;
- tsk_condwait_handle_t* m_hCondWait;
- tsk_thread_handle_t* m_ppTread[1];
- INT32 m_nBytesPerNotif;
- INT32 m_nSourceFrameSizeInBytes;
- UINT32 m_nMaxFrameCount;
- UINT32 m_nPtime;
- UINT32 m_nChannels;
-
- struct
- {
- struct
- {
- void* buffer;
- tsk_size_t size;
- } chunck;
- tsk_ssize_t leftBytes;
- SpeexBuffer* buffer;
- tsk_size_t size;
- } m_ring;
-
- bool m_bStarted;
- bool m_bPrepared;
- bool m_bPaused;
+ IAudioRenderClient* m_pClient;
+ tsk_condwait_handle_t* m_hCondWait;
+ tsk_thread_handle_t* m_ppTread[1];
+ INT32 m_nBytesPerNotif;
+ INT32 m_nSourceFrameSizeInBytes;
+ UINT32 m_nMaxFrameCount;
+ UINT32 m_nPtime;
+ UINT32 m_nChannels;
+
+ struct {
+ struct {
+ void* buffer;
+ tsk_size_t size;
+ } chunck;
+ tsk_ssize_t leftBytes;
+ SpeexBuffer* buffer;
+ tsk_size_t size;
+ } m_ring;
+
+ bool m_bStarted;
+ bool m_bPrepared;
+ bool m_bPaused;
};
-typedef struct plugin_wasapi_consumer_audio_s
-{
- TDAV_DECLARE_CONSUMER_AUDIO;
+typedef struct plugin_wasapi_consumer_audio_s {
+ TDAV_DECLARE_CONSUMER_AUDIO;
- AudioRender* pAudioRender;
+ AudioRender* pAudioRender;
}
plugin_wasapi_consumer_audio_t;
@@ -111,88 +108,83 @@ plugin_wasapi_consumer_audio_t;
/* ============ Media consumer Interface ================= */
static int plugin_wasapi_consumer_audio_set(tmedia_consumer_t* self, const tmedia_param_t* param)
-{
- return tdav_consumer_audio_set(TDAV_CONSUMER_AUDIO(self), param);
+{
+ return tdav_consumer_audio_set(TDAV_CONSUMER_AUDIO(self), param);
}
static int plugin_wasapi_consumer_audio_prepare(tmedia_consumer_t* self, const tmedia_codec_t* codec)
{
- plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
-
- if(!wasapi || !codec || !wasapi->pAudioRender)
- {
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
-
- TMEDIA_CONSUMER(wasapi)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_DECODING(codec);
- TMEDIA_CONSUMER(wasapi)->audio.in.channels = TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(codec);
- TMEDIA_CONSUMER(wasapi)->audio.in.rate = TMEDIA_CODEC_RATE_DECODING(codec);
-
- TSK_DEBUG_INFO("WASAPI consumer: in.channels=%d, out.channles=%d, in.rate=%d, out.rate=%d, ptime=%d",
- TMEDIA_CONSUMER(wasapi)->audio.in.channels,
- TMEDIA_CONSUMER(wasapi)->audio.out.channels,
- TMEDIA_CONSUMER(wasapi)->audio.in.rate,
- TMEDIA_CONSUMER(wasapi)->audio.out.rate,
- TMEDIA_CONSUMER(wasapi)->audio.ptime);
-
- return wasapi->pAudioRender->Prepare(wasapi, codec);
+ plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
+
+ if(!wasapi || !codec || !wasapi->pAudioRender) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ TMEDIA_CONSUMER(wasapi)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_DECODING(codec);
+ TMEDIA_CONSUMER(wasapi)->audio.in.channels = TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(codec);
+ TMEDIA_CONSUMER(wasapi)->audio.in.rate = TMEDIA_CODEC_RATE_DECODING(codec);
+
+ TSK_DEBUG_INFO("WASAPI consumer: in.channels=%d, out.channles=%d, in.rate=%d, out.rate=%d, ptime=%d",
+ TMEDIA_CONSUMER(wasapi)->audio.in.channels,
+ TMEDIA_CONSUMER(wasapi)->audio.out.channels,
+ TMEDIA_CONSUMER(wasapi)->audio.in.rate,
+ TMEDIA_CONSUMER(wasapi)->audio.out.rate,
+ TMEDIA_CONSUMER(wasapi)->audio.ptime);
+
+ return wasapi->pAudioRender->Prepare(wasapi, codec);
}
static int plugin_wasapi_consumer_audio_start(tmedia_consumer_t* self)
{
- plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
+ plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
- TSK_DEBUG_INFO("plugin_wasapi_consumer_audio_start()");
+ TSK_DEBUG_INFO("plugin_wasapi_consumer_audio_start()");
- if(!wasapi || !wasapi->pAudioRender)
- {
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(!wasapi || !wasapi->pAudioRender) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
- return wasapi->pAudioRender->Start();
+ return wasapi->pAudioRender->Start();
}
static int plugin_wasapi_consumer_audio_consume(tmedia_consumer_t* self, const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr)
-{
- plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
- if(!wasapi || !wasapi->pAudioRender || !buffer || !size)
- {
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
-
- return wasapi->pAudioRender->Consume(buffer, size, proto_hdr);
+{
+ plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
+ if(!wasapi || !wasapi->pAudioRender || !buffer || !size) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ return wasapi->pAudioRender->Consume(buffer, size, proto_hdr);
}
static int plugin_wasapi_consumer_audio_pause(tmedia_consumer_t* self)
{
- plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
+ plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
- if(!wasapi || !wasapi->pAudioRender)
- {
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(!wasapi || !wasapi->pAudioRender) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
- return wasapi->pAudioRender->Pause();
+ return wasapi->pAudioRender->Pause();
}
static int plugin_wasapi_consumer_audio_stop(tmedia_consumer_t* self)
{
- plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
+ plugin_wasapi_consumer_audio_t* wasapi = (plugin_wasapi_consumer_audio_t*)self;
- TSK_DEBUG_INFO("plugin_wasapi_consumer_audio_stop()");
+ TSK_DEBUG_INFO("plugin_wasapi_consumer_audio_stop()");
- if(!wasapi || !wasapi->pAudioRender)
- {
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(!wasapi || !wasapi->pAudioRender) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
- return wasapi->pAudioRender->Stop();
+ return wasapi->pAudioRender->Stop();
}
@@ -202,425 +194,386 @@ static int plugin_wasapi_consumer_audio_stop(tmedia_consumer_t* self)
AudioRender::AudioRender()
-: m_pDevice(NULL)
-, m_hMutex(NULL)
-, m_pClient(NULL)
-, m_hCondWait(NULL)
-, m_pWrappedConsumer(NULL)
-, m_nBytesPerNotif(0)
-, m_nSourceFrameSizeInBytes(0)
-, m_nMaxFrameCount(0)
-, m_nPtime(0)
-, m_nChannels(1)
-, m_bStarted(false)
-, m_bPrepared(false)
-, m_bPaused(false)
+ : m_pDevice(NULL)
+ , m_hMutex(NULL)
+ , m_pClient(NULL)
+ , m_hCondWait(NULL)
+ , m_pWrappedConsumer(NULL)
+ , m_nBytesPerNotif(0)
+ , m_nSourceFrameSizeInBytes(0)
+ , m_nMaxFrameCount(0)
+ , m_nPtime(0)
+ , m_nChannels(1)
+ , m_bStarted(false)
+ , m_bPrepared(false)
+ , m_bPaused(false)
{
- m_ppTread[0] = NULL;
- memset(&m_ring, 0, sizeof(m_ring));
+ m_ppTread[0] = NULL;
+ memset(&m_ring, 0, sizeof(m_ring));
- if(!(m_hMutex = tsk_mutex_create()))
- {
- TSK_DEBUG_ERROR("Failed to create mutex");
- }
+ if(!(m_hMutex = tsk_mutex_create())) {
+ TSK_DEBUG_ERROR("Failed to create mutex");
+ }
}
AudioRender::~AudioRender()
{
- Stop();
- UnPrepare();
+ Stop();
+ UnPrepare();
- tsk_mutex_destroy(&m_hMutex);
+ tsk_mutex_destroy(&m_hMutex);
}
int AudioRender::Prepare(plugin_wasapi_consumer_audio_t* wasapi, const tmedia_codec_t* codec)
{
- HRESULT hr = E_FAIL;
- int ret = 0;
- WAVEFORMATEX wfx = {0};
+ HRESULT hr = E_FAIL;
+ int ret = 0;
+ WAVEFORMATEX wfx = {0};
#if PLUGIN_WASAPI_UNDER_WINDOWS_PHONE
- AudioClientProperties properties = {0};
+ AudioClientProperties properties = {0};
#endif
- LPCWSTR pwstrRenderId = NULL;
- IMMDeviceEnumerator *pEnumerator = NULL;
- IMMDevice *pDevice = NULL;
-
- tsk_mutex_lock(m_hMutex);
-
- if(m_bPrepared)
- {
- TSK_DEBUG_INFO("#WASAPI: Audio consumer already prepared");
- goto bail;
- }
-
- if(!wasapi || !codec)
- {
- TSK_DEBUG_ERROR("Invalid parameter");
- CHECK_HR(hr = E_FAIL);
- }
-
- if(m_pDevice || m_pClient)
- {
- TSK_DEBUG_ERROR("consumer already prepared");
- CHECK_HR(hr = E_FAIL);
- }
+ LPCWSTR pwstrRenderId = NULL;
+ IMMDeviceEnumerator *pEnumerator = NULL;
+ IMMDevice *pDevice = NULL;
+
+ tsk_mutex_lock(m_hMutex);
+
+ if(m_bPrepared) {
+ TSK_DEBUG_INFO("#WASAPI: Audio consumer already prepared");
+ goto bail;
+ }
+
+ if(!wasapi || !codec) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ CHECK_HR(hr = E_FAIL);
+ }
+
+ if(m_pDevice || m_pClient) {
+ TSK_DEBUG_ERROR("consumer already prepared");
+ CHECK_HR(hr = E_FAIL);
+ }
#if PLUGIN_WASAPI_UNDER_WINDOWS_PHONE
- pwstrRenderId = GetDefaultAudioRenderId(AudioDeviceRole::Communications);
+ pwstrRenderId = GetDefaultAudioRenderId(AudioDeviceRole::Communications);
- if (NULL == pwstrRenderId)
- {
- PLUGIN_WASAPI_ERROR("GetDefaultAudioRenderId", HRESULT_FROM_WIN32(GetLastError()));
- CHECK_HR(hr = E_FAIL);
- }
+ if (NULL == pwstrRenderId) {
+ PLUGIN_WASAPI_ERROR("GetDefaultAudioRenderId", HRESULT_FROM_WIN32(GetLastError()));
+ CHECK_HR(hr = E_FAIL);
+ }
- CHECK_HR(hr = ActivateAudioInterface(pwstrRenderId, __uuidof(IAudioClient2), (void**)&m_pDevice));
+ CHECK_HR(hr = ActivateAudioInterface(pwstrRenderId, __uuidof(IAudioClient2), (void**)&m_pDevice));
- // Win8 or WP8 only
- properties.cbSize = sizeof AudioClientProperties;
- properties.eCategory = AudioCategory_Communications;
- CHECK_HR(hr = m_pDevice->SetClientProperties(&properties));
+ // Win8 or WP8 only
+ properties.cbSize = sizeof AudioClientProperties;
+ properties.eCategory = AudioCategory_Communications;
+ CHECK_HR(hr = m_pDevice->SetClientProperties(&properties));
#else
- CHECK_HR(hr = CoCreateInstance(
- CLSID_MMDeviceEnumerator, NULL,
- CLSCTX_ALL, IID_IMMDeviceEnumerator,
- (void**)&pEnumerator));
+ CHECK_HR(hr = CoCreateInstance(
+ CLSID_MMDeviceEnumerator, NULL,
+ CLSCTX_ALL, IID_IMMDeviceEnumerator,
+ (void**)&pEnumerator));
CHECK_HR(hr = pEnumerator->GetDefaultAudioEndpoint(
- eRender, eCommunications, &pDevice));
+ eRender, eCommunications, &pDevice));
CHECK_HR(hr = pDevice->Activate(
- IID_IAudioClient, CLSCTX_ALL,
- NULL, (void**)&m_pDevice));
+ IID_IAudioClient, CLSCTX_ALL,
+ NULL, (void**)&m_pDevice));
#endif
-
-
-
-
- /* Set best format */
- {
- wfx.wFormatTag = WAVE_FORMAT_PCM;
- wfx.nChannels = TMEDIA_CONSUMER(wasapi)->audio.in.channels;
- wfx.nSamplesPerSec = TMEDIA_CONSUMER(wasapi)->audio.in.rate;
- wfx.wBitsPerSample = TMEDIA_CONSUMER(wasapi)->audio.bits_per_sample;
- wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample/8);
- wfx.nAvgBytesPerSec = (wfx.nSamplesPerSec * wfx.nBlockAlign);
-
- PWAVEFORMATEX pwfxClosestMatch = NULL;
- hr = m_pDevice->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, &wfx, &pwfxClosestMatch);
- if(hr != S_OK && hr != S_FALSE)
- {
- PLUGIN_WASAPI_ERROR(HRESULT_FROM_WIN32(GetLastError()));
- CHECK_HR(hr = E_FAIL);
- }
-
- if(hr == S_FALSE)
- {
- if(!pwfxClosestMatch)
- {
- TSK_DEBUG_ERROR("malloc(%d) failed", sizeof(WAVEFORMATEX));
- CHECK_HR(hr = E_OUTOFMEMORY);
- }
-
- wfx.nSamplesPerSec = pwfxClosestMatch->nSamplesPerSec;
- wfx.nChannels = pwfxClosestMatch->nChannels;
+
+
+
+
+ /* Set best format */
+ {
+ wfx.wFormatTag = WAVE_FORMAT_PCM;
+ wfx.nChannels = TMEDIA_CONSUMER(wasapi)->audio.in.channels;
+ wfx.nSamplesPerSec = TMEDIA_CONSUMER(wasapi)->audio.in.rate;
+ wfx.wBitsPerSample = TMEDIA_CONSUMER(wasapi)->audio.bits_per_sample;
+ wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample/8);
+ wfx.nAvgBytesPerSec = (wfx.nSamplesPerSec * wfx.nBlockAlign);
+
+ PWAVEFORMATEX pwfxClosestMatch = NULL;
+ hr = m_pDevice->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, &wfx, &pwfxClosestMatch);
+ if(hr != S_OK && hr != S_FALSE) {
+ PLUGIN_WASAPI_ERROR(HRESULT_FROM_WIN32(GetLastError()));
+ CHECK_HR(hr = E_FAIL);
+ }
+
+ if(hr == S_FALSE) {
+ if(!pwfxClosestMatch) {
+ TSK_DEBUG_ERROR("malloc(%d) failed", sizeof(WAVEFORMATEX));
+ CHECK_HR(hr = E_OUTOFMEMORY);
+ }
+
+ wfx.nSamplesPerSec = pwfxClosestMatch->nSamplesPerSec;
+ wfx.nChannels = pwfxClosestMatch->nChannels;
#if 0
- wfx.wBitsPerSample = pwfxClosestMatch->wBitsPerSample;
+ wfx.wBitsPerSample = pwfxClosestMatch->wBitsPerSample;
#endif
- wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8);
- wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
- // Request resampler
- TMEDIA_CONSUMER(wasapi)->audio.out.rate = (uint32_t)wfx.nSamplesPerSec;
- TMEDIA_CONSUMER(wasapi)->audio.bits_per_sample = (uint8_t)wfx.wBitsPerSample;
- TMEDIA_CONSUMER(wasapi)->audio.out.channels = (uint8_t)wfx.nChannels;
-
- TSK_DEBUG_INFO("Audio device format fallback: rate=%d, bps=%d, channels=%d", wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels);
- }
- if(pwfxClosestMatch)
- {
- CoTaskMemFree(pwfxClosestMatch);
- }
- }
-
- m_nSourceFrameSizeInBytes = (wfx.wBitsPerSample >> 3) * wfx.nChannels;
- m_nBytesPerNotif = ((wfx.nAvgBytesPerSec * TMEDIA_CONSUMER(wasapi)->audio.ptime)/1000) * wfx.nChannels;
-
- // Initialize
- CHECK_HR(hr = m_pDevice->Initialize(
- AUDCLNT_SHAREMODE_SHARED,
- 0x00000000,
- (PLUGIN_WASAPI_CONSUMER_NOTIF_POS_COUNT * WASAPI_MILLIS_TO_100NS(TMEDIA_CONSUMER(wasapi)->audio.ptime)) ,
- 0,
- &wfx,
- NULL));
-
- REFERENCE_TIME DefaultDevicePeriod, MinimumDevicePeriod;
- CHECK_HR(hr = m_pDevice->GetDevicePeriod(&DefaultDevicePeriod, &MinimumDevicePeriod));
-
- CHECK_HR(hr = m_pDevice->GetBufferSize(&m_nMaxFrameCount));
- TSK_DEBUG_INFO("#WASAPI (Playback): BufferSize=%u, DefaultDevicePeriod=%lld ms, MinimumDevicePeriod=%lldms", m_nMaxFrameCount, WASAPI_100NS_TO_MILLIS(DefaultDevicePeriod), WASAPI_100NS_TO_MILLIS(MinimumDevicePeriod));
-
- if(!m_hCondWait)
- {
- if(!(m_hCondWait = tsk_condwait_create()))
- {
- PLUGIN_WASAPI_ERROR(HRESULT_FROM_WIN32(GetLastError()));
- CHECK_HR(hr = E_FAIL);
- }
- }
-
- CHECK_HR(hr = m_pDevice->GetService(__uuidof(IAudioRenderClient), (void**)&m_pClient));
-
- int packetperbuffer = (1000 / TMEDIA_CONSUMER(wasapi)->audio.ptime);
- m_ring.chunck.size = (wfx.nSamplesPerSec * (wfx.wBitsPerSample >> 3) / packetperbuffer) * wfx.nChannels;
- m_ring.size = PLUGIN_WASAPI_CONSUMER_NOTIF_POS_COUNT * m_ring.chunck.size;
- if(!(m_ring.chunck.buffer = tsk_realloc(m_ring.chunck.buffer, m_ring.chunck.size)))
- {
- m_ring.size = 0;
- TSK_DEBUG_ERROR("Failed to allocate new buffer");
- CHECK_HR(hr = E_OUTOFMEMORY);
- }
- if(!m_ring.buffer)
- {
- m_ring.buffer = speex_buffer_init(m_ring.size);
- }
- else
- {
- int sret;
- if((sret = speex_buffer_resize(m_ring.buffer, m_ring.size)) < 0)
- {
- TSK_DEBUG_ERROR("speex_buffer_resize(%d) failed with error code=%d", m_ring.size, sret);
- CHECK_HR(hr = E_OUTOFMEMORY);
- }
- }
- if(!m_ring.buffer)
- {
- TSK_DEBUG_ERROR("Failed to create a new ring buffer with size = %d", m_ring.size);
- CHECK_HR(hr = E_OUTOFMEMORY);
- }
+ wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8);
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ // Request resampler
+ TMEDIA_CONSUMER(wasapi)->audio.out.rate = (uint32_t)wfx.nSamplesPerSec;
+ TMEDIA_CONSUMER(wasapi)->audio.bits_per_sample = (uint8_t)wfx.wBitsPerSample;
+ TMEDIA_CONSUMER(wasapi)->audio.out.channels = (uint8_t)wfx.nChannels;
+
+ TSK_DEBUG_INFO("Audio device format fallback: rate=%d, bps=%d, channels=%d", wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels);
+ }
+ if(pwfxClosestMatch) {
+ CoTaskMemFree(pwfxClosestMatch);
+ }
+ }
+
+ m_nSourceFrameSizeInBytes = (wfx.wBitsPerSample >> 3) * wfx.nChannels;
+ m_nBytesPerNotif = ((wfx.nAvgBytesPerSec * TMEDIA_CONSUMER(wasapi)->audio.ptime)/1000) * wfx.nChannels;
+
+ // Initialize
+ CHECK_HR(hr = m_pDevice->Initialize(
+ AUDCLNT_SHAREMODE_SHARED,
+ 0x00000000,
+ (PLUGIN_WASAPI_CONSUMER_NOTIF_POS_COUNT * WASAPI_MILLIS_TO_100NS(TMEDIA_CONSUMER(wasapi)->audio.ptime)) ,
+ 0,
+ &wfx,
+ NULL));
+
+ REFERENCE_TIME DefaultDevicePeriod, MinimumDevicePeriod;
+ CHECK_HR(hr = m_pDevice->GetDevicePeriod(&DefaultDevicePeriod, &MinimumDevicePeriod));
+
+ CHECK_HR(hr = m_pDevice->GetBufferSize(&m_nMaxFrameCount));
+ TSK_DEBUG_INFO("#WASAPI (Playback): BufferSize=%u, DefaultDevicePeriod=%lld ms, MinimumDevicePeriod=%lldms", m_nMaxFrameCount, WASAPI_100NS_TO_MILLIS(DefaultDevicePeriod), WASAPI_100NS_TO_MILLIS(MinimumDevicePeriod));
+
+ if(!m_hCondWait) {
+ if(!(m_hCondWait = tsk_condwait_create())) {
+ PLUGIN_WASAPI_ERROR(HRESULT_FROM_WIN32(GetLastError()));
+ CHECK_HR(hr = E_FAIL);
+ }
+ }
+
+ CHECK_HR(hr = m_pDevice->GetService(__uuidof(IAudioRenderClient), (void**)&m_pClient));
+
+ int packetperbuffer = (1000 / TMEDIA_CONSUMER(wasapi)->audio.ptime);
+ m_ring.chunck.size = (wfx.nSamplesPerSec * (wfx.wBitsPerSample >> 3) / packetperbuffer) * wfx.nChannels;
+ m_ring.size = PLUGIN_WASAPI_CONSUMER_NOTIF_POS_COUNT * m_ring.chunck.size;
+ if(!(m_ring.chunck.buffer = tsk_realloc(m_ring.chunck.buffer, m_ring.chunck.size))) {
+ m_ring.size = 0;
+ TSK_DEBUG_ERROR("Failed to allocate new buffer");
+ CHECK_HR(hr = E_OUTOFMEMORY);
+ }
+ if(!m_ring.buffer) {
+ m_ring.buffer = speex_buffer_init(m_ring.size);
+ }
+ else {
+ int sret;
+ if((sret = speex_buffer_resize(m_ring.buffer, m_ring.size)) < 0) {
+ TSK_DEBUG_ERROR("speex_buffer_resize(%d) failed with error code=%d", m_ring.size, sret);
+ CHECK_HR(hr = E_OUTOFMEMORY);
+ }
+ }
+ if(!m_ring.buffer) {
+ TSK_DEBUG_ERROR("Failed to create a new ring buffer with size = %d", m_ring.size);
+ CHECK_HR(hr = E_OUTOFMEMORY);
+ }
bail:
- ret = SUCCEEDED(hr) ? 0 : -1;
- if (pwstrRenderId)
- {
- CoTaskMemFree((LPVOID)pwstrRenderId);
- }
- if(ret != 0)
- {
- UnPrepare();
- }
-
- if((m_bPrepared = (ret == 0)))
- {
- m_pWrappedConsumer = wasapi;
- m_nPtime = TMEDIA_CONSUMER(wasapi)->audio.ptime;
- m_nChannels = TMEDIA_CONSUMER(wasapi)->audio.out.channels;
- }
-
- tsk_mutex_unlock(m_hMutex);
-
- SafeRelease(&pEnumerator);
- SafeRelease(&pDevice);
-
- return ret;
+ ret = SUCCEEDED(hr) ? 0 : -1;
+ if (pwstrRenderId) {
+ CoTaskMemFree((LPVOID)pwstrRenderId);
+ }
+ if(ret != 0) {
+ UnPrepare();
+ }
+
+ if((m_bPrepared = (ret == 0))) {
+ m_pWrappedConsumer = wasapi;
+ m_nPtime = TMEDIA_CONSUMER(wasapi)->audio.ptime;
+ m_nChannels = TMEDIA_CONSUMER(wasapi)->audio.out.channels;
+ }
+
+ tsk_mutex_unlock(m_hMutex);
+
+ SafeRelease(&pEnumerator);
+ SafeRelease(&pDevice);
+
+ return ret;
}
int AudioRender::UnPrepare()
{
- tsk_mutex_lock(m_hMutex);
-
- if(m_hCondWait)
- {
- tsk_condwait_destroy(&m_hCondWait);
- }
- if(m_pDevice)
- {
- m_pDevice->Release(), m_pDevice = NULL;
- }
- if(m_pClient)
- {
- m_pClient->Release(), m_pClient = NULL;
- }
-
- TSK_FREE(m_ring.chunck.buffer);
- if(m_ring.buffer)
- {
- speex_buffer_destroy(m_ring.buffer);
- m_ring.buffer = NULL;
- }
-
- m_pWrappedConsumer = NULL;
-
- m_bPrepared = false;
-
- tsk_mutex_unlock(m_hMutex);
-
- return 0;
+ tsk_mutex_lock(m_hMutex);
+
+ if(m_hCondWait) {
+ tsk_condwait_destroy(&m_hCondWait);
+ }
+ if(m_pDevice) {
+ m_pDevice->Release(), m_pDevice = NULL;
+ }
+ if(m_pClient) {
+ m_pClient->Release(), m_pClient = NULL;
+ }
+
+ TSK_FREE(m_ring.chunck.buffer);
+ if(m_ring.buffer) {
+ speex_buffer_destroy(m_ring.buffer);
+ m_ring.buffer = NULL;
+ }
+
+ m_pWrappedConsumer = NULL;
+
+ m_bPrepared = false;
+
+ tsk_mutex_unlock(m_hMutex);
+
+ return 0;
}
int AudioRender::Start()
{
- tsk_mutex_lock(m_hMutex);
-
- if(m_bStarted)
- {
- TSK_DEBUG_INFO("#WASAPI: Audio consumer already started");
- goto bail;
- }
- if(!m_bPrepared)
- {
- TSK_DEBUG_ERROR("Audio consumer not prepared");
- goto bail;
- }
-
- m_bStarted = true;
- if(!m_ppTread[0] && tsk_thread_create(m_ppTread, AudioRender::AsyncThread, this) != 0)
- {
- m_bStarted = false;
- goto bail;
- }
-
- HRESULT hr = m_pDevice->Start();
- if(!SUCCEEDED(hr))
- {
- PLUGIN_WASAPI_ERROR(hr);
- Stop();
- }
- m_bPaused = false;
+ tsk_mutex_lock(m_hMutex);
+
+ if(m_bStarted) {
+ TSK_DEBUG_INFO("#WASAPI: Audio consumer already started");
+ goto bail;
+ }
+ if(!m_bPrepared) {
+ TSK_DEBUG_ERROR("Audio consumer not prepared");
+ goto bail;
+ }
+
+ m_bStarted = true;
+ if(!m_ppTread[0] && tsk_thread_create(m_ppTread, AudioRender::AsyncThread, this) != 0) {
+ m_bStarted = false;
+ goto bail;
+ }
+
+ HRESULT hr = m_pDevice->Start();
+ if(!SUCCEEDED(hr)) {
+ PLUGIN_WASAPI_ERROR(hr);
+ Stop();
+ }
+ m_bPaused = false;
bail:
- tsk_mutex_unlock(m_hMutex);
+ tsk_mutex_unlock(m_hMutex);
- return (m_bStarted ? 0 : -2);
+ return (m_bStarted ? 0 : -2);
}
int AudioRender::Stop()
{
- m_bStarted = false;
+ m_bStarted = false;
- tsk_mutex_lock(m_hMutex);
+ tsk_mutex_lock(m_hMutex);
- if (m_hCondWait)
- {
- tsk_condwait_broadcast(m_hCondWait);
- }
+ if (m_hCondWait) {
+ tsk_condwait_broadcast(m_hCondWait);
+ }
- if (m_ppTread[0])
- {
- tsk_thread_join(m_ppTread);
- }
+ if (m_ppTread[0]) {
+ tsk_thread_join(m_ppTread);
+ }
- if(m_pDevice)
- {
- m_pDevice->Stop();
- }
+ if(m_pDevice) {
+ m_pDevice->Stop();
+ }
- // will be prepared again before next start()
- UnPrepare();
+ // will be prepared again before next start()
+ UnPrepare();
- tsk_mutex_unlock(m_hMutex);
+ tsk_mutex_unlock(m_hMutex);
- return 0;
+ return 0;
}
int AudioRender::Pause()
{
- m_bPaused = true;
+ m_bPaused = true;
- return 0;
+ return 0;
}
int AudioRender::Consume(const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr)
{
- return tdav_consumer_audio_put(TDAV_CONSUMER_AUDIO(m_pWrappedConsumer), buffer, size, proto_hdr);
+ return tdav_consumer_audio_put(TDAV_CONSUMER_AUDIO(m_pWrappedConsumer), buffer, size, proto_hdr);
}
tsk_size_t AudioRender::Read(void* data, tsk_size_t size)
{
- tsk_ssize_t retSize = 0;
-
- m_ring.leftBytes += size;
- while (m_ring.leftBytes >= (tsk_ssize_t)m_ring.chunck.size)
- {
- m_ring.leftBytes -= m_ring.chunck.size;
- retSize = (tsk_ssize_t)tdav_consumer_audio_get(TDAV_CONSUMER_AUDIO(m_pWrappedConsumer), m_ring.chunck.buffer, m_ring.chunck.size);
- tdav_consumer_audio_tick(TDAV_CONSUMER_AUDIO(m_pWrappedConsumer));
- speex_buffer_write(m_ring.buffer, m_ring.chunck.buffer, retSize);
- }
- // IMPORTANT: looks like there is a bug in speex: continously trying to read more than avail
- // many times can corrupt the buffer. At least on OS X 1.5
- int avail = speex_buffer_get_available(m_ring.buffer);
- //if(speex_buffer_get_available(m_ring.buffer) >= (tsk_ssize_t)size)
- //{
- retSize = speex_buffer_read(m_ring.buffer, data, TSK_MIN((int)size,avail));
- //}
- //else
- //{
- //memset(data, 0, size);
- //}
-
- return retSize;
+ tsk_ssize_t retSize = 0;
+
+ m_ring.leftBytes += size;
+ while (m_ring.leftBytes >= (tsk_ssize_t)m_ring.chunck.size) {
+ m_ring.leftBytes -= m_ring.chunck.size;
+ retSize = (tsk_ssize_t)tdav_consumer_audio_get(TDAV_CONSUMER_AUDIO(m_pWrappedConsumer), m_ring.chunck.buffer, m_ring.chunck.size);
+ tdav_consumer_audio_tick(TDAV_CONSUMER_AUDIO(m_pWrappedConsumer));
+ speex_buffer_write(m_ring.buffer, m_ring.chunck.buffer, retSize);
+ }
+ // IMPORTANT: looks like there is a bug in speex: continously trying to read more than avail
+ // many times can corrupt the buffer. At least on OS X 1.5
+ int avail = speex_buffer_get_available(m_ring.buffer);
+ //if(speex_buffer_get_available(m_ring.buffer) >= (tsk_ssize_t)size)
+ //{
+ retSize = speex_buffer_read(m_ring.buffer, data, TSK_MIN((int)size,avail));
+ //}
+ //else
+ //{
+ //memset(data, 0, size);
+ //}
+
+ return retSize;
}
void* TSK_STDCALL AudioRender::AsyncThread(void *pArg)
{
- HRESULT hr = S_OK;
- INT32 nFramesToWrite;
- UINT32 nPadding, nRead;
- int waitResult = 0;
- AudioRender* This = (AudioRender*)pArg;
+ HRESULT hr = S_OK;
+ INT32 nFramesToWrite;
+ UINT32 nPadding, nRead;
+ int waitResult = 0;
+ AudioRender* This = (AudioRender*)pArg;
- TSK_DEBUG_INFO("#WASAPI: __playback_thread -- START");
+ TSK_DEBUG_INFO("#WASAPI: __playback_thread -- START");
#define BREAK_WHILE tsk_mutex_unlock(This->m_hMutex); break;
- while(This->m_bStarted && SUCCEEDED(hr))
- {
- waitResult = tsk_condwait_timedwait(This->m_hCondWait, This->m_nPtime);
-
- tsk_mutex_lock(This->m_hMutex);
-
- if(!This->m_bStarted)
- {
- BREAK_WHILE;
- }
-
- if(waitResult == 0)
- {
- hr = This->m_pDevice->GetCurrentPadding(&nPadding);
- if (SUCCEEDED(hr))
- {
- BYTE* pRenderBuffer = NULL;
- nFramesToWrite = This->m_nMaxFrameCount - nPadding;
-
- if (nFramesToWrite > 0)
- {
- hr = This->m_pClient->GetBuffer(nFramesToWrite, &pRenderBuffer);
- if (SUCCEEDED(hr))
- {
- nRead = This->Read(pRenderBuffer, (nFramesToWrite * This->m_nSourceFrameSizeInBytes));
-
- // Release the buffer
- hr = This->m_pClient->ReleaseBuffer((nRead / This->m_nSourceFrameSizeInBytes), (nRead == 0) ? AUDCLNT_BUFFERFLAGS_SILENT: 0);
- }
- }
- }
- }
- else
- {
- BREAK_WHILE;
- }
-
- tsk_mutex_lock(This->m_hMutex);
- }// end-of-while
-
- if (!SUCCEEDED(hr))
- {
- PLUGIN_WASAPI_ERROR(hr);
- }
-
- TSK_DEBUG_INFO("WASAPI: __playback_thread(%s) -- STOP", (SUCCEEDED(hr) && waitResult == 0) ? "OK": "NOK");
-
- return NULL;
+ while(This->m_bStarted && SUCCEEDED(hr)) {
+ waitResult = tsk_condwait_timedwait(This->m_hCondWait, This->m_nPtime);
+
+ tsk_mutex_lock(This->m_hMutex);
+
+ if(!This->m_bStarted) {
+ BREAK_WHILE;
+ }
+
+ if(waitResult == 0) {
+ hr = This->m_pDevice->GetCurrentPadding(&nPadding);
+ if (SUCCEEDED(hr)) {
+ BYTE* pRenderBuffer = NULL;
+ nFramesToWrite = This->m_nMaxFrameCount - nPadding;
+
+ if (nFramesToWrite > 0) {
+ hr = This->m_pClient->GetBuffer(nFramesToWrite, &pRenderBuffer);
+ if (SUCCEEDED(hr)) {
+ nRead = This->Read(pRenderBuffer, (nFramesToWrite * This->m_nSourceFrameSizeInBytes));
+
+ // Release the buffer
+ hr = This->m_pClient->ReleaseBuffer((nRead / This->m_nSourceFrameSizeInBytes), (nRead == 0) ? AUDCLNT_BUFFERFLAGS_SILENT: 0);
+ }
+ }
+ }
+ }
+ else {
+ BREAK_WHILE;
+ }
+
+ tsk_mutex_lock(This->m_hMutex);
+ }// end-of-while
+
+ if (!SUCCEEDED(hr)) {
+ PLUGIN_WASAPI_ERROR(hr);
+ }
+
+ TSK_DEBUG_INFO("WASAPI: __playback_thread(%s) -- STOP", (SUCCEEDED(hr) && waitResult == 0) ? "OK": "NOK");
+
+ return NULL;
}
@@ -635,66 +588,60 @@ void* TSK_STDCALL AudioRender::AsyncThread(void *pArg)
/* constructor */
static tsk_object_t* plugin_wasapi_consumer_audio_ctor(tsk_object_t * self, va_list * app)
{
- plugin_wasapi_consumer_audio_t *wasapi = (plugin_wasapi_consumer_audio_t*)self;
- if(wasapi)
- {
- WASAPIUtils::Startup();
-
- /* init base */
- tdav_consumer_audio_init(TDAV_CONSUMER_AUDIO(wasapi));
- /* init self */
-
- wasapi->pAudioRender = new AudioRender();
- if(!wasapi->pAudioRender)
- {
- TSK_DEBUG_ERROR("Failed to create renderer");
- return tsk_null;
- }
- }
- return self;
+ plugin_wasapi_consumer_audio_t *wasapi = (plugin_wasapi_consumer_audio_t*)self;
+ if(wasapi) {
+ WASAPIUtils::Startup();
+
+ /* init base */
+ tdav_consumer_audio_init(TDAV_CONSUMER_AUDIO(wasapi));
+ /* init self */
+
+ wasapi->pAudioRender = new AudioRender();
+ if(!wasapi->pAudioRender) {
+ TSK_DEBUG_ERROR("Failed to create renderer");
+ return tsk_null;
+ }
+ }
+ return self;
}
/* destructor */
static tsk_object_t* plugin_wasapi_consumer_audio_dtor(tsk_object_t * self)
-{
- plugin_wasapi_consumer_audio_t *wasapi = (plugin_wasapi_consumer_audio_t*)self;
- if(wasapi)
- {
- /* stop */
- plugin_wasapi_consumer_audio_stop((tmedia_consumer_t*)self);
- /* deinit base */
- tdav_consumer_audio_deinit(TDAV_CONSUMER_AUDIO(wasapi));
- /* deinit self */
- if(wasapi->pAudioRender)
- {
- delete wasapi->pAudioRender;
- wasapi->pAudioRender = NULL;
- }
- }
-
- return self;
+{
+ plugin_wasapi_consumer_audio_t *wasapi = (plugin_wasapi_consumer_audio_t*)self;
+ if(wasapi) {
+ /* stop */
+ plugin_wasapi_consumer_audio_stop((tmedia_consumer_t*)self);
+ /* deinit base */
+ tdav_consumer_audio_deinit(TDAV_CONSUMER_AUDIO(wasapi));
+ /* deinit self */
+ if(wasapi->pAudioRender) {
+ delete wasapi->pAudioRender;
+ wasapi->pAudioRender = NULL;
+ }
+ }
+
+ return self;
}
/* object definition */
-static const tsk_object_def_t plugin_wasapi_consumer_audio_def_s =
-{
- sizeof(plugin_wasapi_consumer_audio_t),
- plugin_wasapi_consumer_audio_ctor,
- plugin_wasapi_consumer_audio_dtor,
- tdav_consumer_audio_cmp,
+static const tsk_object_def_t plugin_wasapi_consumer_audio_def_s = {
+ sizeof(plugin_wasapi_consumer_audio_t),
+ plugin_wasapi_consumer_audio_ctor,
+ plugin_wasapi_consumer_audio_dtor,
+ tdav_consumer_audio_cmp,
};
/* plugin definition*/
-static const tmedia_consumer_plugin_def_t plugin_wasapi_consumer_audio_plugin_def_s =
-{
- &plugin_wasapi_consumer_audio_def_s,
-
- tmedia_audio,
- "Microsoft Windows Audio Session API (WASAPI) consumer",
-
- plugin_wasapi_consumer_audio_set,
- plugin_wasapi_consumer_audio_prepare,
- plugin_wasapi_consumer_audio_start,
- plugin_wasapi_consumer_audio_consume,
- plugin_wasapi_consumer_audio_pause,
- plugin_wasapi_consumer_audio_stop
+static const tmedia_consumer_plugin_def_t plugin_wasapi_consumer_audio_plugin_def_s = {
+ &plugin_wasapi_consumer_audio_def_s,
+
+ tmedia_audio,
+ "Microsoft Windows Audio Session API (WASAPI) consumer",
+
+ plugin_wasapi_consumer_audio_set,
+ plugin_wasapi_consumer_audio_prepare,
+ plugin_wasapi_consumer_audio_start,
+ plugin_wasapi_consumer_audio_consume,
+ plugin_wasapi_consumer_audio_pause,
+ plugin_wasapi_consumer_audio_stop
};
const tmedia_consumer_plugin_def_t *plugin_wasapi_consumer_audio_plugin_def_t = &plugin_wasapi_consumer_audio_plugin_def_s;
diff --git a/plugins/pluginWASAPI/plugin_wasapi_producer_audio.cxx b/plugins/pluginWASAPI/plugin_wasapi_producer_audio.cxx
index 6f44ab0..92e03f7 100755
--- a/plugins/pluginWASAPI/plugin_wasapi_producer_audio.cxx
+++ b/plugins/pluginWASAPI/plugin_wasapi_producer_audio.cxx
@@ -1,18 +1,18 @@
/*Copyright (C) 2013 Mamadou Diop
* Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/
@@ -22,7 +22,7 @@
*/
#include "plugin_wasapi_utils.h"
-#include "tinydav/audio/tdav_producer_audio.h"
+#include "tinydav/audio/tdav_producer_audio.h"
#include "tsk_thread.h"
#include "tsk_memory.h"
@@ -56,156 +56,147 @@ struct plugin_wasapi_producer_audio_s;
class AudioCapture
{
public:
- AudioCapture();
- virtual ~AudioCapture();
+ AudioCapture();
+ virtual ~AudioCapture();
- int Prepare(struct plugin_wasapi_producer_audio_s* wasapi, const tmedia_codec_t* codec);
- int UnPrepare();
- int Start();
- int Stop();
- int Pause();
+ int Prepare(struct plugin_wasapi_producer_audio_s* wasapi, const tmedia_codec_t* codec);
+ int UnPrepare();
+ int Start();
+ int Stop();
+ int Pause();
private:
- static void* TSK_STDCALL AsyncThread(void *pArg);
+ static void* TSK_STDCALL AsyncThread(void *pArg);
private:
- tsk_mutex_handle_t* m_hMutex;
+ tsk_mutex_handle_t* m_hMutex;
#if PLUGIN_WASAPI_UNDER_WINDOWS_PHONE
- IAudioClient2* m_pDevice;
+ IAudioClient2* m_pDevice;
#else
- IAudioClient* m_pDevice;
+ IAudioClient* m_pDevice;
#endif
- IAudioCaptureClient* m_pClient;
- HANDLE m_hCaptureEvent;
- HANDLE m_hShutdownEvent;
- tsk_thread_handle_t* m_ppTread[1];
- INT32 m_nBytesPerNotif;
- INT32 m_nSourceFrameSizeInBytes;
-
- struct
- {
- tmedia_producer_enc_cb_f fn;
- const void* pcData;
- } m_callback;
-
- struct
- {
- struct
- {
- void* buffer;
- tsk_size_t size;
- } chunck;
- SpeexBuffer* buffer;
- tsk_size_t size;
- } m_ring;
- bool m_bStarted;
- bool m_bPrepared;
- bool m_bPaused;
+ IAudioCaptureClient* m_pClient;
+ HANDLE m_hCaptureEvent;
+ HANDLE m_hShutdownEvent;
+ tsk_thread_handle_t* m_ppTread[1];
+ INT32 m_nBytesPerNotif;
+ INT32 m_nSourceFrameSizeInBytes;
+
+ struct {
+ tmedia_producer_enc_cb_f fn;
+ const void* pcData;
+ } m_callback;
+
+ struct {
+ struct {
+ void* buffer;
+ tsk_size_t size;
+ } chunck;
+ SpeexBuffer* buffer;
+ tsk_size_t size;
+ } m_ring;
+ bool m_bStarted;
+ bool m_bPrepared;
+ bool m_bPaused;
};
-typedef struct plugin_wasapi_producer_audio_s
-{
- TDAV_DECLARE_PRODUCER_AUDIO;
- AudioCapture* pAudioCapture;
+typedef struct plugin_wasapi_producer_audio_s {
+ TDAV_DECLARE_PRODUCER_AUDIO;
+ AudioCapture* pAudioCapture;
}
plugin_wasapi_producer_audio_t;
/* ============ Media Producer Interface ================= */
static int plugin_wasapi_producer_audio_set(tmedia_producer_t* self, const tmedia_param_t* param)
-{
- plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
- if(param->plugin_type == tmedia_ppt_producer)
- {
- if(param->value_type == tmedia_pvt_int32)
- {
- if(tsk_striequals(param->key, "volume"))
- {
- return 0;
- }
- else if(tsk_striequals(param->key, "mute"))
- {
- //wasapi->mute = (TSK_TO_INT32((uint8_t*)param->value) != 0);
+{
+ plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
+ if(param->plugin_type == tmedia_ppt_producer) {
+ if(param->value_type == tmedia_pvt_int32) {
+ if(tsk_striequals(param->key, "volume")) {
+ return 0;
+ }
+ else if(tsk_striequals(param->key, "mute")) {
+ //wasapi->mute = (TSK_TO_INT32((uint8_t*)param->value) != 0);
#if !FIXME_SEND_SILENCE_ON_MUTE
- //if(wasapi->started){
- // if(wasapi->mute){
- //IDirectSoundCaptureBuffer_Stop(wasapi->captureBuffer);
- // }
- // else{
- //IDirectSoundCaptureBuffer_Start(wasapi->captureBuffer, DSBPLAY_LOOPING);
- // }
- //}
+ //if(wasapi->started){
+ // if(wasapi->mute){
+ //IDirectSoundCaptureBuffer_Stop(wasapi->captureBuffer);
+ // }
+ // else{
+ //IDirectSoundCaptureBuffer_Start(wasapi->captureBuffer, DSBPLAY_LOOPING);
+ // }
+ //}
#endif
- return 0;
- }
- }
- }
- return tdav_producer_audio_set(TDAV_PRODUCER_AUDIO(self), param);
+ return 0;
+ }
+ }
+ }
+ return tdav_producer_audio_set(TDAV_PRODUCER_AUDIO(self), param);
}
static int plugin_wasapi_producer_audio_prepare(tmedia_producer_t* self, const tmedia_codec_t* codec)
{
- plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
+ plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
- if(!wasapi || !codec || !wasapi->pAudioCapture)
- {
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(!wasapi || !codec || !wasapi->pAudioCapture) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
- /* codec should have ptime */
- TMEDIA_PRODUCER(wasapi)->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec);
- TMEDIA_PRODUCER(wasapi)->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec);
- TMEDIA_PRODUCER(wasapi)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec);
+ /* codec should have ptime */
+ TMEDIA_PRODUCER(wasapi)->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec);
+ TMEDIA_PRODUCER(wasapi)->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec);
+ TMEDIA_PRODUCER(wasapi)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec);
- TSK_DEBUG_INFO("WASAPI producer: channels=%d, rate=%d, ptime=%d",
- TMEDIA_PRODUCER(wasapi)->audio.channels,
- TMEDIA_PRODUCER(wasapi)->audio.rate,
- TMEDIA_PRODUCER(wasapi)->audio.ptime);
+ TSK_DEBUG_INFO("WASAPI producer: channels=%d, rate=%d, ptime=%d",
+ TMEDIA_PRODUCER(wasapi)->audio.channels,
+ TMEDIA_PRODUCER(wasapi)->audio.rate,
+ TMEDIA_PRODUCER(wasapi)->audio.ptime);
- return wasapi->pAudioCapture->Prepare(wasapi, codec);
+ return wasapi->pAudioCapture->Prepare(wasapi, codec);
}
static int plugin_wasapi_producer_audio_start(tmedia_producer_t* self)
{
- plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
+ plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
- TSK_DEBUG_INFO("plugin_wasapi_producer_audio_start()");
+ TSK_DEBUG_INFO("plugin_wasapi_producer_audio_start()");
- if(!wasapi || !wasapi->pAudioCapture){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(!wasapi || !wasapi->pAudioCapture) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
- return wasapi->pAudioCapture->Start();
+ return wasapi->pAudioCapture->Start();
}
static int plugin_wasapi_producer_audio_pause(tmedia_producer_t* self)
{
- plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
+ plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
- if(!wasapi || !wasapi->pAudioCapture){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(!wasapi || !wasapi->pAudioCapture) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
- return wasapi->pAudioCapture->Pause();
+ return wasapi->pAudioCapture->Pause();
}
static int plugin_wasapi_producer_audio_stop(tmedia_producer_t* self)
{
- plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
+ plugin_wasapi_producer_audio_t* wasapi = (plugin_wasapi_producer_audio_t*)self;
- TSK_DEBUG_INFO("plugin_wasapi_producer_audio_stop()");
+ TSK_DEBUG_INFO("plugin_wasapi_producer_audio_stop()");
- if(!wasapi || !wasapi->pAudioCapture){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(!wasapi || !wasapi->pAudioCapture) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
- return wasapi->pAudioCapture->Stop();
+ return wasapi->pAudioCapture->Stop();
}
@@ -215,426 +206,383 @@ static int plugin_wasapi_producer_audio_stop(tmedia_producer_t* self)
AudioCapture::AudioCapture()
-: m_pDevice(NULL)
-, m_hMutex(NULL)
-, m_pClient(NULL)
-, m_hCaptureEvent(NULL)
-, m_hShutdownEvent(NULL)
-, m_nBytesPerNotif(0)
-, m_nSourceFrameSizeInBytes(0)
-, m_bStarted(false)
-, m_bPrepared(false)
-, m_bPaused(false)
+ : m_pDevice(NULL)
+ , m_hMutex(NULL)
+ , m_pClient(NULL)
+ , m_hCaptureEvent(NULL)
+ , m_hShutdownEvent(NULL)
+ , m_nBytesPerNotif(0)
+ , m_nSourceFrameSizeInBytes(0)
+ , m_bStarted(false)
+ , m_bPrepared(false)
+ , m_bPaused(false)
{
- m_ppTread[0] = NULL;
- memset(&m_ring, 0, sizeof(m_ring));
+ m_ppTread[0] = NULL;
+ memset(&m_ring, 0, sizeof(m_ring));
- m_callback.fn = NULL, m_callback.pcData = NULL;
+ m_callback.fn = NULL, m_callback.pcData = NULL;
- if(!(m_hMutex = tsk_mutex_create()))
- {
- TSK_DEBUG_ERROR("Failed to create mutex");
- }
+ if(!(m_hMutex = tsk_mutex_create())) {
+ TSK_DEBUG_ERROR("Failed to create mutex");
+ }
}
AudioCapture::~AudioCapture()
{
- Stop();
- UnPrepare();
+ Stop();
+ UnPrepare();
- tsk_mutex_destroy(&m_hMutex);
+ tsk_mutex_destroy(&m_hMutex);
}
int AudioCapture::Prepare(plugin_wasapi_producer_audio_t* wasapi, const tmedia_codec_t* codec)
{
- HRESULT hr = S_OK;
- int ret = 0;
- WAVEFORMATEX wfx = {0};
+ HRESULT hr = S_OK;
+ int ret = 0;
+ WAVEFORMATEX wfx = {0};
#if PLUGIN_WASAPI_UNDER_WINDOWS_PHONE
- AudioClientProperties properties = {0};
+ AudioClientProperties properties = {0};
#endif
- IMMDeviceEnumerator *pEnumerator = NULL;
- LPCWSTR pwstrCaptureId = NULL;
- IMMDevice *pDevice = NULL;
-
- tsk_mutex_lock(m_hMutex);
-
- if(m_bPrepared)
- {
- TSK_DEBUG_INFO("#WASAPI: Audio producer already prepared");
- goto bail;
- }
-
- if(!wasapi || !codec)
- {
- TSK_DEBUG_ERROR("Invalid parameter");
- CHECK_HR(hr = E_FAIL);
- }
-
- if(m_pDevice || m_pClient)
- {
- TSK_DEBUG_ERROR("Producer already prepared");
- CHECK_HR(hr = E_FAIL);
- }
+ IMMDeviceEnumerator *pEnumerator = NULL;
+ LPCWSTR pwstrCaptureId = NULL;
+ IMMDevice *pDevice = NULL;
+
+ tsk_mutex_lock(m_hMutex);
+
+ if(m_bPrepared) {
+ TSK_DEBUG_INFO("#WASAPI: Audio producer already prepared");
+ goto bail;
+ }
+
+ if(!wasapi || !codec) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ CHECK_HR(hr = E_FAIL);
+ }
+
+ if(m_pDevice || m_pClient) {
+ TSK_DEBUG_ERROR("Producer already prepared");
+ CHECK_HR(hr = E_FAIL);
+ }
#if PLUGIN_WASAPI_UNDER_WINDOWS_PHONE
- pwstrCaptureId = GetDefaultAudioCaptureId(AudioDeviceRole::Communications);
- if (NULL == pwstrCaptureId)
- {
- PLUGIN_WASAPI_ERROR("GetDefaultAudioCaptureId", HRESULT_FROM_WIN32(GetLastError()));
- CHECK_HR(hr = E_FAIL);
- }
- CHECK_HR(hr = ActivateAudioInterface(pwstrCaptureId, __uuidof(IAudioClient2), (void**)&m_pDevice));
-
- // Win8 or WP8 only
- properties.cbSize = sizeof AudioClientProperties;
- properties.eCategory = AudioCategory_Communications;
- CHECK_HR(hr = m_pDevice->SetClientProperties(&properties));
+ pwstrCaptureId = GetDefaultAudioCaptureId(AudioDeviceRole::Communications);
+ if (NULL == pwstrCaptureId) {
+ PLUGIN_WASAPI_ERROR("GetDefaultAudioCaptureId", HRESULT_FROM_WIN32(GetLastError()));
+ CHECK_HR(hr = E_FAIL);
+ }
+ CHECK_HR(hr = ActivateAudioInterface(pwstrCaptureId, __uuidof(IAudioClient2), (void**)&m_pDevice));
+
+ // Win8 or WP8 only
+ properties.cbSize = sizeof AudioClientProperties;
+ properties.eCategory = AudioCategory_Communications;
+ CHECK_HR(hr = m_pDevice->SetClientProperties(&properties));
#else
- CHECK_HR(hr = CoCreateInstance(
- CLSID_MMDeviceEnumerator, NULL,
- CLSCTX_ALL, IID_IMMDeviceEnumerator,
- (void**)&pEnumerator));
+ CHECK_HR(hr = CoCreateInstance(
+ CLSID_MMDeviceEnumerator, NULL,
+ CLSCTX_ALL, IID_IMMDeviceEnumerator,
+ (void**)&pEnumerator));
CHECK_HR(hr = pEnumerator->GetDefaultAudioEndpoint(
- eCapture, eCommunications, &pDevice));
+ eCapture, eCommunications, &pDevice));
CHECK_HR(hr = pDevice->Activate(
- IID_IAudioClient, CLSCTX_ALL,
- NULL, (void**)&m_pDevice));
+ IID_IAudioClient, CLSCTX_ALL,
+ NULL, (void**)&m_pDevice));
#endif
-
-
- /* Set best format */
- {
- wfx.wFormatTag = WAVE_FORMAT_PCM;
- wfx.nChannels = TMEDIA_PRODUCER(wasapi)->audio.channels;
- wfx.nSamplesPerSec = TMEDIA_PRODUCER(wasapi)->audio.rate;
- wfx.wBitsPerSample = TMEDIA_PRODUCER(wasapi)->audio.bits_per_sample;
- wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample/8);
- wfx.nAvgBytesPerSec = (wfx.nSamplesPerSec * wfx.nBlockAlign);
-
- PWAVEFORMATEX pwfxClosestMatch = NULL;
- hr = m_pDevice->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, &wfx, &pwfxClosestMatch);
- if(hr != S_OK && hr != S_FALSE)
- {
- CHECK_HR(hr);
- }
-
- if(hr == S_FALSE)
- {
- if(!pwfxClosestMatch)
- {
- CHECK_HR(hr = E_OUTOFMEMORY);
- }
- wfx.nChannels = pwfxClosestMatch->nChannels;
- wfx.nSamplesPerSec = pwfxClosestMatch->nSamplesPerSec;
+
+
+ /* Set best format */
+ {
+ wfx.wFormatTag = WAVE_FORMAT_PCM;
+ wfx.nChannels = TMEDIA_PRODUCER(wasapi)->audio.channels;
+ wfx.nSamplesPerSec = TMEDIA_PRODUCER(wasapi)->audio.rate;
+ wfx.wBitsPerSample = TMEDIA_PRODUCER(wasapi)->audio.bits_per_sample;
+ wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample/8);
+ wfx.nAvgBytesPerSec = (wfx.nSamplesPerSec * wfx.nBlockAlign);
+
+ PWAVEFORMATEX pwfxClosestMatch = NULL;
+ hr = m_pDevice->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, &wfx, &pwfxClosestMatch);
+ if(hr != S_OK && hr != S_FALSE) {
+ CHECK_HR(hr);
+ }
+
+ if(hr == S_FALSE) {
+ if(!pwfxClosestMatch) {
+ CHECK_HR(hr = E_OUTOFMEMORY);
+ }
+ wfx.nChannels = pwfxClosestMatch->nChannels;
+ wfx.nSamplesPerSec = pwfxClosestMatch->nSamplesPerSec;
#if 0
- wfx.wBitsPerSample = pwfxClosestMatch->wBitsPerSample;
+ wfx.wBitsPerSample = pwfxClosestMatch->wBitsPerSample;
#endif
- wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8);
- wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
- // Request resampler
- TMEDIA_PRODUCER(wasapi)->audio.rate = (uint32_t)wfx.nSamplesPerSec;
- TMEDIA_PRODUCER(wasapi)->audio.bits_per_sample = (uint8_t)wfx.wBitsPerSample;
- TMEDIA_PRODUCER(wasapi)->audio.channels = (uint8_t)wfx.nChannels;
-
- TSK_DEBUG_INFO("Audio device format fallback: rate=%d, bps=%d, channels=%d", wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels);
- }
- if(pwfxClosestMatch)
- {
- CoTaskMemFree(pwfxClosestMatch);
- }
- }
-
- m_nSourceFrameSizeInBytes = (wfx.wBitsPerSample >> 3) * wfx.nChannels;
- m_nBytesPerNotif = ((wfx.nAvgBytesPerSec * TMEDIA_PRODUCER(wasapi)->audio.ptime)/1000) * wfx.nChannels;
-
- // Initialize
- CHECK_HR(hr = m_pDevice->Initialize(
- AUDCLNT_SHAREMODE_SHARED,
- AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
- (PLUGIN_WASAPI_PRODUCER_NOTIF_POS_COUNT * WASAPI_MILLIS_TO_100NS(TMEDIA_PRODUCER(wasapi)->audio.ptime)),
- 0,
- &wfx,
- NULL));
-
- REFERENCE_TIME DefaultDevicePeriod, MinimumDevicePeriod;
- CHECK_HR(hr = m_pDevice->GetDevicePeriod(&DefaultDevicePeriod, &MinimumDevicePeriod));
- TSK_DEBUG_INFO("#WASAPI(Capture): DefaultDevicePeriod=%lld ms, MinimumDevicePeriod=%lldms", WASAPI_100NS_TO_MILLIS(DefaultDevicePeriod), WASAPI_100NS_TO_MILLIS(MinimumDevicePeriod));
-
- if(!m_hCaptureEvent)
- {
- if(!(m_hCaptureEvent = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS)))
- {
- PLUGIN_WASAPI_ERROR(HRESULT_FROM_WIN32(GetLastError()));
- CHECK_HR(hr = E_FAIL);
- }
- }
- if(!m_hShutdownEvent)
- {
- if(!(m_hShutdownEvent = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS)))
- {
- PLUGIN_WASAPI_ERROR(HRESULT_FROM_WIN32(GetLastError()));
- CHECK_HR(hr = E_FAIL);
- }
- }
-
- CHECK_HR(hr = m_pDevice->SetEventHandle(m_hCaptureEvent));
-
- CHECK_HR(hr = m_pDevice->GetService(__uuidof(IAudioCaptureClient), (void**)&m_pClient));
-
- int packetperbuffer = (1000 / TMEDIA_PRODUCER(wasapi)->audio.ptime);
- m_ring.chunck.size = (wfx.nSamplesPerSec * (wfx.wBitsPerSample >> 3) / packetperbuffer) * wfx.nChannels;
- TSK_DEBUG_INFO("#WASAPI: Audio producer ring chunk size = %u", m_ring.chunck.size);
- // allocate our chunck buffer
- if(!(m_ring.chunck.buffer = tsk_realloc(m_ring.chunck.buffer, m_ring.chunck.size)))
- {
- TSK_DEBUG_ERROR("Failed to allocate new buffer");
- CHECK_HR(hr = E_OUTOFMEMORY);
- }
- // create ringbuffer
- m_ring.size = PLUGIN_WASAPI_PRODUCER_NOTIF_POS_COUNT * m_ring.chunck.size;
- TSK_DEBUG_INFO("#WASAPI: Audio producer ring size = %u", m_ring.size);
- if(!m_ring.buffer)
- {
- m_ring.buffer = speex_buffer_init(m_ring.size);
- }
- else
- {
- int sret;
- if((sret = speex_buffer_resize(m_ring.buffer, m_ring.size)) < 0)
- {
- TSK_DEBUG_ERROR("speex_buffer_resize(%d) failed with error code=%d", m_ring.size, sret);
- CHECK_HR(hr = E_OUTOFMEMORY);
- }
- }
- if(!m_ring.buffer)
- {
- TSK_DEBUG_ERROR("Failed to create a new ring buffer with size = %d", m_ring.size);
- CHECK_HR(hr = E_OUTOFMEMORY);
- }
-
- m_callback.fn = TMEDIA_PRODUCER(wasapi)->enc_cb.callback;
- m_callback.pcData = TMEDIA_PRODUCER(wasapi)->enc_cb.callback_data;
+ wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8);
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ // Request resampler
+ TMEDIA_PRODUCER(wasapi)->audio.rate = (uint32_t)wfx.nSamplesPerSec;
+ TMEDIA_PRODUCER(wasapi)->audio.bits_per_sample = (uint8_t)wfx.wBitsPerSample;
+ TMEDIA_PRODUCER(wasapi)->audio.channels = (uint8_t)wfx.nChannels;
+
+ TSK_DEBUG_INFO("Audio device format fallback: rate=%d, bps=%d, channels=%d", wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels);
+ }
+ if(pwfxClosestMatch) {
+ CoTaskMemFree(pwfxClosestMatch);
+ }
+ }
+
+ m_nSourceFrameSizeInBytes = (wfx.wBitsPerSample >> 3) * wfx.nChannels;
+ m_nBytesPerNotif = ((wfx.nAvgBytesPerSec * TMEDIA_PRODUCER(wasapi)->audio.ptime)/1000) * wfx.nChannels;
+
+ // Initialize
+ CHECK_HR(hr = m_pDevice->Initialize(
+ AUDCLNT_SHAREMODE_SHARED,
+ AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
+ (PLUGIN_WASAPI_PRODUCER_NOTIF_POS_COUNT * WASAPI_MILLIS_TO_100NS(TMEDIA_PRODUCER(wasapi)->audio.ptime)),
+ 0,
+ &wfx,
+ NULL));
+
+ REFERENCE_TIME DefaultDevicePeriod, MinimumDevicePeriod;
+ CHECK_HR(hr = m_pDevice->GetDevicePeriod(&DefaultDevicePeriod, &MinimumDevicePeriod));
+ TSK_DEBUG_INFO("#WASAPI(Capture): DefaultDevicePeriod=%lld ms, MinimumDevicePeriod=%lldms", WASAPI_100NS_TO_MILLIS(DefaultDevicePeriod), WASAPI_100NS_TO_MILLIS(MinimumDevicePeriod));
+
+ if(!m_hCaptureEvent) {
+ if(!(m_hCaptureEvent = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS))) {
+ PLUGIN_WASAPI_ERROR(HRESULT_FROM_WIN32(GetLastError()));
+ CHECK_HR(hr = E_FAIL);
+ }
+ }
+ if(!m_hShutdownEvent) {
+ if(!(m_hShutdownEvent = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS))) {
+ PLUGIN_WASAPI_ERROR(HRESULT_FROM_WIN32(GetLastError()));
+ CHECK_HR(hr = E_FAIL);
+ }
+ }
+
+ CHECK_HR(hr = m_pDevice->SetEventHandle(m_hCaptureEvent));
+
+ CHECK_HR(hr = m_pDevice->GetService(__uuidof(IAudioCaptureClient), (void**)&m_pClient));
+
+ int packetperbuffer = (1000 / TMEDIA_PRODUCER(wasapi)->audio.ptime);
+ m_ring.chunck.size = (wfx.nSamplesPerSec * (wfx.wBitsPerSample >> 3) / packetperbuffer) * wfx.nChannels;
+ TSK_DEBUG_INFO("#WASAPI: Audio producer ring chunk size = %u", m_ring.chunck.size);
+ // allocate our chunck buffer
+ if(!(m_ring.chunck.buffer = tsk_realloc(m_ring.chunck.buffer, m_ring.chunck.size))) {
+ TSK_DEBUG_ERROR("Failed to allocate new buffer");
+ CHECK_HR(hr = E_OUTOFMEMORY);
+ }
+ // create ringbuffer
+ m_ring.size = PLUGIN_WASAPI_PRODUCER_NOTIF_POS_COUNT * m_ring.chunck.size;
+ TSK_DEBUG_INFO("#WASAPI: Audio producer ring size = %u", m_ring.size);
+ if(!m_ring.buffer) {
+ m_ring.buffer = speex_buffer_init(m_ring.size);
+ }
+ else {
+ int sret;
+ if((sret = speex_buffer_resize(m_ring.buffer, m_ring.size)) < 0) {
+ TSK_DEBUG_ERROR("speex_buffer_resize(%d) failed with error code=%d", m_ring.size, sret);
+ CHECK_HR(hr = E_OUTOFMEMORY);
+ }
+ }
+ if(!m_ring.buffer) {
+ TSK_DEBUG_ERROR("Failed to create a new ring buffer with size = %d", m_ring.size);
+ CHECK_HR(hr = E_OUTOFMEMORY);
+ }
+
+ m_callback.fn = TMEDIA_PRODUCER(wasapi)->enc_cb.callback;
+ m_callback.pcData = TMEDIA_PRODUCER(wasapi)->enc_cb.callback_data;
bail:
- ret = SUCCEEDED(hr) ? 0 : -1;
- if (pwstrCaptureId)
- {
- CoTaskMemFree((LPVOID)pwstrCaptureId);
- }
- if(ret != 0)
- {
- UnPrepare();
- }
- m_bPrepared = (ret == 0);
-
- tsk_mutex_unlock(m_hMutex);
-
- SafeRelease(&pEnumerator);
- SafeRelease(&pDevice);
-
- return ret;
+ ret = SUCCEEDED(hr) ? 0 : -1;
+ if (pwstrCaptureId) {
+ CoTaskMemFree((LPVOID)pwstrCaptureId);
+ }
+ if(ret != 0) {
+ UnPrepare();
+ }
+ m_bPrepared = (ret == 0);
+
+ tsk_mutex_unlock(m_hMutex);
+
+ SafeRelease(&pEnumerator);
+ SafeRelease(&pDevice);
+
+ return ret;
}
int AudioCapture::UnPrepare()
{
- tsk_mutex_lock(m_hMutex);
-
- if(m_hCaptureEvent)
- {
- CloseHandle(m_hCaptureEvent), m_hCaptureEvent = NULL;
- }
- if(m_hShutdownEvent)
- {
- CloseHandle(m_hShutdownEvent), m_hShutdownEvent = NULL;
- }
- if(m_pDevice)
- {
- m_pDevice->Release(), m_pDevice = NULL;
- }
- if(m_pClient)
- {
- m_pClient->Release(), m_pClient = NULL;
- }
-
- TSK_FREE(m_ring.chunck.buffer);
- if(m_ring.buffer)
- {
- speex_buffer_destroy(m_ring.buffer);
- m_ring.buffer = NULL;
- }
-
- m_callback.fn = NULL;
- m_callback.pcData = NULL;
-
- m_bPrepared = false;
-
- tsk_mutex_unlock(m_hMutex);
-
- return 0;
+ tsk_mutex_lock(m_hMutex);
+
+ if(m_hCaptureEvent) {
+ CloseHandle(m_hCaptureEvent), m_hCaptureEvent = NULL;
+ }
+ if(m_hShutdownEvent) {
+ CloseHandle(m_hShutdownEvent), m_hShutdownEvent = NULL;
+ }
+ if(m_pDevice) {
+ m_pDevice->Release(), m_pDevice = NULL;
+ }
+ if(m_pClient) {
+ m_pClient->Release(), m_pClient = NULL;
+ }
+
+ TSK_FREE(m_ring.chunck.buffer);
+ if(m_ring.buffer) {
+ speex_buffer_destroy(m_ring.buffer);
+ m_ring.buffer = NULL;
+ }
+
+ m_callback.fn = NULL;
+ m_callback.pcData = NULL;
+
+ m_bPrepared = false;
+
+ tsk_mutex_unlock(m_hMutex);
+
+ return 0;
}
int AudioCapture::Start()
{
- tsk_mutex_lock(m_hMutex);
-
- if(m_bStarted)
- {
- TSK_DEBUG_INFO("#WASAPI: Audio producer already started");
- goto bail;
- }
- if(!m_bPrepared)
- {
- TSK_DEBUG_ERROR("Audio producer not prepared");
- goto bail;
- }
-
- m_bStarted = true;
- if(!m_ppTread[0] && tsk_thread_create(m_ppTread, AudioCapture::AsyncThread, this) != 0)
- {
- m_bStarted = false;
- goto bail;
- }
-
- HRESULT hr = m_pDevice->Start();
- if(!SUCCEEDED(hr))
- {
- PLUGIN_WASAPI_ERROR(hr);
- Stop();
- }
- m_bPaused = false;
+ tsk_mutex_lock(m_hMutex);
+
+ if(m_bStarted) {
+ TSK_DEBUG_INFO("#WASAPI: Audio producer already started");
+ goto bail;
+ }
+ if(!m_bPrepared) {
+ TSK_DEBUG_ERROR("Audio producer not prepared");
+ goto bail;
+ }
+
+ m_bStarted = true;
+ if(!m_ppTread[0] && tsk_thread_create(m_ppTread, AudioCapture::AsyncThread, this) != 0) {
+ m_bStarted = false;
+ goto bail;
+ }
+
+ HRESULT hr = m_pDevice->Start();
+ if(!SUCCEEDED(hr)) {
+ PLUGIN_WASAPI_ERROR(hr);
+ Stop();
+ }
+ m_bPaused = false;
bail:
- tsk_mutex_unlock(m_hMutex);
+ tsk_mutex_unlock(m_hMutex);
- return (m_bStarted ? 0 : -2);
+ return (m_bStarted ? 0 : -2);
}
int AudioCapture::Stop()
{
- m_bStarted = false;
+ m_bStarted = false;
- tsk_mutex_lock(m_hMutex);
+ tsk_mutex_lock(m_hMutex);
- if (m_hShutdownEvent)
- {
- SetEvent(m_hShutdownEvent);
- }
+ if (m_hShutdownEvent) {
+ SetEvent(m_hShutdownEvent);
+ }
- if (m_ppTread[0])
- {
- tsk_thread_join(m_ppTread);
- }
+ if (m_ppTread[0]) {
+ tsk_thread_join(m_ppTread);
+ }
- if(m_pDevice)
- {
- m_pDevice->Stop();
- }
+ if(m_pDevice) {
+ m_pDevice->Stop();
+ }
- // will be prepared again before next start()
- UnPrepare();
+ // will be prepared again before next start()
+ UnPrepare();
- tsk_mutex_unlock(m_hMutex);
+ tsk_mutex_unlock(m_hMutex);
- return 0;
+ return 0;
}
int AudioCapture::Pause()
{
- tsk_mutex_lock(m_hMutex);
+ tsk_mutex_lock(m_hMutex);
- m_bPaused = true;
+ m_bPaused = true;
- tsk_mutex_unlock(m_hMutex);
+ tsk_mutex_unlock(m_hMutex);
- return 0;
+ return 0;
}
void* TSK_STDCALL AudioCapture::AsyncThread(void *pArg)
{
- HRESULT hr = S_OK;
- BYTE* pbData = NULL;
- UINT32 nFrames = 0;
- DWORD dwFlags = 0;
- UINT32 incomingBufferSize;
- INT32 avail;
- UINT32 nNextPacketSize;
- AudioCapture* This = (AudioCapture*)pArg;
-
- HANDLE eventHandles[] = {
- This->m_hCaptureEvent, // WAIT_OBJECT0
- This->m_hShutdownEvent // WAIT_OBJECT1
- };
-
- TSK_DEBUG_INFO("#WASAPI: __record_thread -- START");
+ HRESULT hr = S_OK;
+ BYTE* pbData = NULL;
+ UINT32 nFrames = 0;
+ DWORD dwFlags = 0;
+ UINT32 incomingBufferSize;
+ INT32 avail;
+ UINT32 nNextPacketSize;
+ AudioCapture* This = (AudioCapture*)pArg;
+
+ HANDLE eventHandles[] = {
+ This->m_hCaptureEvent, // WAIT_OBJECT0
+ This->m_hShutdownEvent // WAIT_OBJECT1
+ };
+
+ TSK_DEBUG_INFO("#WASAPI: __record_thread -- START");
#define BREAK_WHILE tsk_mutex_unlock(This->m_hMutex); break;
- while(This->m_bStarted && SUCCEEDED(hr))
- {
- DWORD waitResult = WaitForMultipleObjectsEx(SIZEOF_ARRAY(eventHandles), eventHandles, FALSE, INFINITE, FALSE);
-
- tsk_mutex_lock(This->m_hMutex);
-
- if(!This->m_bStarted)
- {
- BREAK_WHILE;
- }
-
- if(waitResult == WAIT_OBJECT_0 && This->m_callback.fn)
- {
- hr = This->m_pClient->GetNextPacketSize(&nNextPacketSize);
- while(SUCCEEDED(hr) && nNextPacketSize >0)
- {
- hr = This->m_pClient->GetBuffer(&pbData, &nFrames, &dwFlags, NULL, NULL);
- if(SUCCEEDED(hr) && pbData && nFrames)
- {
- if((dwFlags & AUDCLNT_BUFFERFLAGS_SILENT) != AUDCLNT_BUFFERFLAGS_SILENT)
- {
- incomingBufferSize = nFrames * This->m_nSourceFrameSizeInBytes;
- speex_buffer_write(This->m_ring.buffer, pbData, incomingBufferSize);
- avail = speex_buffer_get_available(This->m_ring.buffer);
- while (This->m_bStarted && avail >= (INT32)This->m_ring.chunck.size)
- {
- avail -= speex_buffer_read(This->m_ring.buffer, This->m_ring.chunck.buffer, This->m_ring.chunck.size);
+ while(This->m_bStarted && SUCCEEDED(hr)) {
+ DWORD waitResult = WaitForMultipleObjectsEx(SIZEOF_ARRAY(eventHandles), eventHandles, FALSE, INFINITE, FALSE);
+
+ tsk_mutex_lock(This->m_hMutex);
+
+ if(!This->m_bStarted) {
+ BREAK_WHILE;
+ }
+
+ if(waitResult == WAIT_OBJECT_0 && This->m_callback.fn) {
+ hr = This->m_pClient->GetNextPacketSize(&nNextPacketSize);
+ while(SUCCEEDED(hr) && nNextPacketSize >0) {
+ hr = This->m_pClient->GetBuffer(&pbData, &nFrames, &dwFlags, NULL, NULL);
+ if(SUCCEEDED(hr) && pbData && nFrames) {
+ if((dwFlags & AUDCLNT_BUFFERFLAGS_SILENT) != AUDCLNT_BUFFERFLAGS_SILENT) {
+ incomingBufferSize = nFrames * This->m_nSourceFrameSizeInBytes;
+ speex_buffer_write(This->m_ring.buffer, pbData, incomingBufferSize);
+ avail = speex_buffer_get_available(This->m_ring.buffer);
+ while (This->m_bStarted && avail >= (INT32)This->m_ring.chunck.size) {
+ avail -= speex_buffer_read(This->m_ring.buffer, This->m_ring.chunck.buffer, This->m_ring.chunck.size);
#if 0
- {
- static FILE* f = fopen("./wasapi_producer.raw", "w+");
- fwrite(This->m_ring.chunck.buffer, 1, This->m_ring.chunck.size, f);
- }
+ {
+ static FILE* f = fopen("./wasapi_producer.raw", "w+");
+ fwrite(This->m_ring.chunck.buffer, 1, This->m_ring.chunck.size, f);
+ }
#endif
- This->m_callback.fn(This->m_callback.pcData, This->m_ring.chunck.buffer, This->m_ring.chunck.size);
- }
- }
-
- if (SUCCEEDED(hr))
- {
- hr = This->m_pClient->ReleaseBuffer(nFrames);
- }
- if (SUCCEEDED(hr))
- {
- hr = This->m_pClient->GetNextPacketSize(&nNextPacketSize);
- }
- }
- }
- }
- else if(waitResult != WAIT_OBJECT_0)
- {
- BREAK_WHILE;
- }
-
- tsk_mutex_unlock(This->m_hMutex);
- }// end-of-while
-
- if (!SUCCEEDED(hr))
- {
- PLUGIN_WASAPI_ERROR(hr);
- }
-
- TSK_DEBUG_INFO("WASAPI: __record_thread(%s) -- STOP", SUCCEEDED(hr) ? "OK": "NOK");
-
- return NULL;
+ This->m_callback.fn(This->m_callback.pcData, This->m_ring.chunck.buffer, This->m_ring.chunck.size);
+ }
+ }
+
+ if (SUCCEEDED(hr)) {
+ hr = This->m_pClient->ReleaseBuffer(nFrames);
+ }
+ if (SUCCEEDED(hr)) {
+ hr = This->m_pClient->GetNextPacketSize(&nNextPacketSize);
+ }
+ }
+ }
+ }
+ else if(waitResult != WAIT_OBJECT_0) {
+ BREAK_WHILE;
+ }
+
+ tsk_mutex_unlock(This->m_hMutex);
+ }// end-of-while
+
+ if (!SUCCEEDED(hr)) {
+ PLUGIN_WASAPI_ERROR(hr);
+ }
+
+ TSK_DEBUG_INFO("WASAPI: __record_thread(%s) -- STOP", SUCCEEDED(hr) ? "OK": "NOK");
+
+ return NULL;
}
@@ -649,64 +597,58 @@ void* TSK_STDCALL AudioCapture::AsyncThread(void *pArg)
/* constructor */
static tsk_object_t* plugin_wasapi_producer_audio_ctor(tsk_object_t * self, va_list * app)
{
- plugin_wasapi_producer_audio_t *wasapi = (plugin_wasapi_producer_audio_t*)self;
- if(wasapi)
- {
- WASAPIUtils::Startup();
-
- /* init base */
- tdav_producer_audio_init(TDAV_PRODUCER_AUDIO(wasapi));
- /* init self */
-
- wasapi->pAudioCapture = new AudioCapture();
- if(!wasapi->pAudioCapture)
- {
- TSK_DEBUG_ERROR("Failed to create Audio capture device");
- return tsk_null;
- }
- }
- return self;
+ plugin_wasapi_producer_audio_t *wasapi = (plugin_wasapi_producer_audio_t*)self;
+ if(wasapi) {
+ WASAPIUtils::Startup();
+
+ /* init base */
+ tdav_producer_audio_init(TDAV_PRODUCER_AUDIO(wasapi));
+ /* init self */
+
+ wasapi->pAudioCapture = new AudioCapture();
+ if(!wasapi->pAudioCapture) {
+ TSK_DEBUG_ERROR("Failed to create Audio capture device");
+ return tsk_null;
+ }
+ }
+ return self;
}
/* destructor */
static tsk_object_t* plugin_wasapi_producer_audio_dtor(tsk_object_t * self)
-{
- plugin_wasapi_producer_audio_t *wasapi = (plugin_wasapi_producer_audio_t*)self;
- if(wasapi)
- {
- /* stop */
- plugin_wasapi_producer_audio_stop((tmedia_producer_t*)self);
- /* deinit base */
- tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(wasapi));
- /* deinit self */
- if(wasapi->pAudioCapture)
- {
- delete wasapi->pAudioCapture;
- wasapi->pAudioCapture = NULL;
- }
- }
-
- return self;
+{
+ plugin_wasapi_producer_audio_t *wasapi = (plugin_wasapi_producer_audio_t*)self;
+ if(wasapi) {
+ /* stop */
+ plugin_wasapi_producer_audio_stop((tmedia_producer_t*)self);
+ /* deinit base */
+ tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(wasapi));
+ /* deinit self */
+ if(wasapi->pAudioCapture) {
+ delete wasapi->pAudioCapture;
+ wasapi->pAudioCapture = NULL;
+ }
+ }
+
+ return self;
}
/* object definition */
-static const tsk_object_def_t plugin_wasapi_producer_audio_def_s =
-{
- sizeof(plugin_wasapi_producer_audio_t),
- plugin_wasapi_producer_audio_ctor,
- plugin_wasapi_producer_audio_dtor,
- tdav_producer_audio_cmp,
+static const tsk_object_def_t plugin_wasapi_producer_audio_def_s = {
+ sizeof(plugin_wasapi_producer_audio_t),
+ plugin_wasapi_producer_audio_ctor,
+ plugin_wasapi_producer_audio_dtor,
+ tdav_producer_audio_cmp,
};
/* plugin definition*/
-static const tmedia_producer_plugin_def_t plugin_wasapi_producer_audio_plugin_def_s =
-{
- &plugin_wasapi_producer_audio_def_s,
+static const tmedia_producer_plugin_def_t plugin_wasapi_producer_audio_plugin_def_s = {
+ &plugin_wasapi_producer_audio_def_s,
- tmedia_audio,
- "Microsoft Windows Audio Session API (WASAPI) producer",
+ tmedia_audio,
+ "Microsoft Windows Audio Session API (WASAPI) producer",
- plugin_wasapi_producer_audio_set,
- plugin_wasapi_producer_audio_prepare,
- plugin_wasapi_producer_audio_start,
- plugin_wasapi_producer_audio_pause,
- plugin_wasapi_producer_audio_stop
+ plugin_wasapi_producer_audio_set,
+ plugin_wasapi_producer_audio_prepare,
+ plugin_wasapi_producer_audio_start,
+ plugin_wasapi_producer_audio_pause,
+ plugin_wasapi_producer_audio_stop
};
const tmedia_producer_plugin_def_t *plugin_wasapi_producer_audio_plugin_def_t = &plugin_wasapi_producer_audio_plugin_def_s;
diff --git a/plugins/pluginWASAPI/plugin_wasapi_tdav.cxx b/plugins/pluginWASAPI/plugin_wasapi_tdav.cxx
index e7a15e9..ebfc85f 100755
--- a/plugins/pluginWASAPI/plugin_wasapi_tdav.cxx
+++ b/plugins/pluginWASAPI/plugin_wasapi_tdav.cxx
@@ -1,18 +1,18 @@
/* Copyright (C) 2013 Mamadou DIOP
* Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/
diff --git a/plugins/pluginWASAPI/plugin_wasapi_utils.cxx b/plugins/pluginWASAPI/plugin_wasapi_utils.cxx
index bc2d45e..e967cff 100755
--- a/plugins/pluginWASAPI/plugin_wasapi_utils.cxx
+++ b/plugins/pluginWASAPI/plugin_wasapi_utils.cxx
@@ -1,18 +1,18 @@
/* Copyright (C) 2013 Mamadou DIOP
* Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/
@@ -24,58 +24,56 @@ bool WASAPIUtils::g_bStarted = false;
HRESULT WASAPIUtils::Startup()
{
- if(!g_bStarted)
- {
- HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
- if(SUCCEEDED(hr) || hr == 0x80010106) // 0x80010106 when called from managed code (e.g. Boghe) - More info: http://support.microsoft.com/kb/824480
- {
- hr = S_OK;
- }
- g_bStarted = SUCCEEDED(hr);
- return hr;
- }
- return S_OK;
+ if(!g_bStarted) {
+ HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+ if(SUCCEEDED(hr) || hr == 0x80010106) { // 0x80010106 when called from managed code (e.g. Boghe) - More info: http://support.microsoft.com/kb/824480
+ hr = S_OK;
+ }
+ g_bStarted = SUCCEEDED(hr);
+ return hr;
+ }
+ return S_OK;
}
HRESULT WASAPIUtils::Shutdown()
{
- return S_OK;
+ return S_OK;
}
void WASAPIUtils::PrintError(const char* pcFileName, const char* pcFuncName, unsigned nLineNumber, HRESULT hr)
{
- CHAR message[1024] = {0};
+ CHAR message[1024] = {0};
#if PLUGIN_WASAPI_UNDER_WINDOWS_RT
- // FormatMessageA not allowed on the Store
- static WCHAR wBuff[1024] = {0};
- FormatMessageW(
- FORMAT_MESSAGE_FROM_SYSTEM,
- tsk_null,
- hr,
- 0,
- wBuff,
- sizeof(wBuff)-1,
- tsk_null);
- WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wBuff, wcslen(wBuff), message, sizeof(message) - 1, NULL, NULL);
+ // FormatMessageA not allowed on the Store
+ static WCHAR wBuff[1024] = {0};
+ FormatMessageW(
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ tsk_null,
+ hr,
+ 0,
+ wBuff,
+ sizeof(wBuff)-1,
+ tsk_null);
+ WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wBuff, wcslen(wBuff), message, sizeof(message) - 1, NULL, NULL);
#else
#ifdef _WIN32_WCE
- FormatMessage
+ FormatMessage
#else
- FormatMessageA
+ FormatMessageA
#endif
- (
+ (
#if !PLUGIN_WASAPI_UNDER_WINDOWS_RT
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
#endif
- FORMAT_MESSAGE_FROM_SYSTEM,
- tsk_null,
- hr,
- 0,
- message,
- sizeof(message) - 1,
- tsk_null);
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ tsk_null,
+ hr,
+ 0,
+ message,
+ sizeof(message) - 1,
+ tsk_null);
#endif
- TSK_DEBUG_ERROR("[WASAPI] File:%s\n Function=%s\n Line:%u\n Message:%s", pcFileName, pcFuncName, nLineNumber, message);
+ TSK_DEBUG_ERROR("[WASAPI] File:%s\n Function=%s\n Line:%u\n Message:%s", pcFileName, pcFuncName, nLineNumber, message);
} \ No newline at end of file
diff --git a/plugins/pluginWASAPI/plugin_wasapi_utils.h b/plugins/pluginWASAPI/plugin_wasapi_utils.h
index 218a7f8..7237619 100755
--- a/plugins/pluginWASAPI/plugin_wasapi_utils.h
+++ b/plugins/pluginWASAPI/plugin_wasapi_utils.h
@@ -1,18 +1,18 @@
/* Copyright (C) 2013 Mamadou DIOP
* Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/
@@ -31,7 +31,7 @@
(*ppT)->Release(); \
*ppT = NULL; \
} \
-}
+}
#undef CHECK_HR
// In CHECK_HR(x) When (x) is a function it will be executed twice when used in "TSK_DEBUG_ERROR(x)" and "If(x)"
@@ -42,12 +42,12 @@
class WASAPIUtils
{
public:
- static HRESULT Startup();
- static HRESULT Shutdown();
- static void PrintError(const char* pcFileName, const char* pcFuncName, unsigned nLineNumber, HRESULT hr);
+ static HRESULT Startup();
+ static HRESULT Shutdown();
+ static void PrintError(const char* pcFileName, const char* pcFuncName, unsigned nLineNumber, HRESULT hr);
private:
- static bool g_bStarted;
+ static bool g_bStarted;
};
#endif /* PLUGIN_WASAPI_UTILS_H */
OpenPOWER on IntegriCloud