[vlc-devel] [PATCH 2/2] wasapi: add loopback mode
Rémi Denis-Courmont
remi at remlab.net
Sun Mar 22 13:44:17 CET 2015
---
modules/access/wasapi.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/modules/access/wasapi.c b/modules/access/wasapi.c
index 387546c..3a0c67e 100644
--- a/modules/access/wasapi.c
+++ b/modules/access/wasapi.c
@@ -73,6 +73,7 @@ struct demux_sys_t
IAudioClient *client;
es_out_id_t *es;
+ bool loopback;
size_t frame_size;
mtime_t caching;
mtime_t start_time;
@@ -82,12 +83,14 @@ struct demux_sys_t
SYNCHRONIZATION_BARRIER ready;
};
-static IAudioClient *GetClient(demux_t *demux)
+static IAudioClient *GetClient(demux_t *demux, bool loopback)
{
IMMDeviceEnumerator *e;
IMMDevice *dev;
void *pv;
HRESULT hr;
+ EDataFlow flow = loopback ? eRender : eCapture;
+ ERole role = loopback ? eConsole : eCommunications;
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
&IID_IMMDeviceEnumerator, &pv);
@@ -98,8 +101,7 @@ static IAudioClient *GetClient(demux_t *demux)
}
e = pv;
- hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(e, eCapture,
- eCommunications, &dev);
+ hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(e, flow, role, &dev);
IMMDeviceEnumerator_Release(e);
if (FAILED(hr))
{
@@ -214,7 +216,7 @@ static int vlc_FromWave(const WAVEFORMATEX *restrict wf,
return 0;
}
-static es_out_id_t *CreateES(demux_t *demux, IAudioClient *client,
+static es_out_id_t *CreateES(demux_t *demux, IAudioClient *client, bool loop,
mtime_t caching, size_t *restrict frame_size)
{
es_format_t fmt;
@@ -241,7 +243,10 @@ static es_out_id_t *CreateES(demux_t *demux, IAudioClient *client,
* fmt.audio.i_rate;
*frame_size = fmt.audio.i_bitspersample * fmt.audio.i_channels / 8;
- DWORD flags = AUDCLNT_STREAMFLAGS_EVENTCALLBACK; /* TODO: loopback */
+ DWORD flags = AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
+ if (loop)
+ flags |= AUDCLNT_STREAMFLAGS_LOOPBACK;
+
/* Request at least thrice the PTS delay */
REFERENCE_TIME bufsize = caching * INT64_C(10000) * 3;
@@ -368,6 +373,7 @@ static int Open(vlc_object_t *obj)
sys->client = NULL;
sys->es = NULL;
+ sys->loopback = var_InheritBool(obj, "wasapi-loopback");
sys->caching = INT64_C(1000) * var_InheritInteger(obj, "live-caching");
sys->start_time = mdate();
for (unsigned i = 0; i < 2; i++)
@@ -385,13 +391,14 @@ static int Open(vlc_object_t *obj)
goto error;
}
- sys->client = GetClient(demux);
+ sys->client = GetClient(demux, sys->loopback);
if (sys->client == NULL) {
CoUninitialize();
goto error;
}
- sys->es = CreateES(demux, sys->client, sys->caching, &sys->frame_size);
+ sys->es = CreateES(demux, sys->client, sys->loopback, sys->caching,
+ &sys->frame_size);
if (sys->es == NULL)
goto error;
@@ -455,6 +462,9 @@ static void Close (vlc_object_t *obj)
free(sys);
}
+#define LOOPBACK_TEXT N_("Loopback mode")
+#define LOOPBACK_LONGTEXT N_("Record an audio rendering endpoint.")
+
vlc_module_begin()
set_shortname(N_("WASAPI"))
set_description(N_("Windows Audio Session API input"))
@@ -462,6 +472,8 @@ vlc_module_begin()
set_category(CAT_INPUT)
set_subcategory(SUBCAT_INPUT_ACCESS)
+ add_bool("wasapi-loopback", false, LOOPBACK_TEXT, LOOPBACK_LONGTEXT, true)
+
add_shortcut("wasapi")
set_callbacks(Open, Close)
vlc_module_end()
--
2.1.4
More information about the vlc-devel
mailing list