@@ -95,6 +95,8 @@ struct state_acap_wasapi {
9595 UINT32 bufferSize;
9696};
9797
98+ enum { IDX_LOOP = -2 , IDX_DFL = -1 };
99+
98100static string get_name (IMMDevice *pDevice);
99101static void show_help ();
100102string wasapi_get_default_device_id (EDataFlow dataFlow, IMMDeviceEnumerator *enumerator);
@@ -238,36 +240,44 @@ static void show_help() {
238240 printf (" \n Device " TBOLD (" name" ) " can be a substring (selects first matching device).\n " );
239241}
240242
243+ static void
244+ parse_fmt (const char *cfg, int *req_index, char *req_dev_name,
245+ size_t req_dev_name_sz, wchar_t *req_deviceID, size_t req_deviceID_sz)
246+ {
247+ if (strlen (cfg) == 0 ) {
248+ return ;
249+ }
250+
251+ if (isdigit (cfg[0 ])) {
252+ *req_index = atoi (cfg);
253+ } else if (strcmp (cfg, " loopback" ) == 0 ) {
254+ *req_index = IDX_LOOP;
255+ } else if (cfg[0 ] == ' {' ) { // ID
256+ const char *uuid = cfg;
257+ mbstate_t state{};
258+ mbsrtowcs (req_deviceID, &uuid, req_deviceID_sz - 1 , &state);
259+ assert (uuid == NULL );
260+ } else { // name
261+ snprintf (req_dev_name, req_dev_name_sz, " %s" , cfg);
262+ }
263+ }
264+
241265static void * audio_cap_wasapi_init (struct module *parent, const char *cfg)
242266{
267+ if (strcmp (cfg, " help" ) == 0 ) {
268+ show_help ();
269+ return INIT_NOERR;
270+ }
243271 UNUSED (parent);
244272 WAVEFORMATEX *pwfx = NULL ;
245273
246- enum { IDX_LOOP = -2 , IDX_DFL = -1 };
247274 int index = IDX_DFL; // or
248275 char req_dev_name[1024 ] = " " ; // or
249276 wchar_t deviceID[1024 ] = L" " ;
250277
251- if (strlen (cfg) > 0 ) {
252- if (strcmp (cfg, " help" ) == 0 ) {
253- show_help ();
254- return INIT_NOERR;
255- }
256- if (isdigit (cfg[0 ])) {
257- index = atoi (cfg);
258- } else if (strcmp (cfg, " loopback" ) == 0 ) {
259- index = IDX_LOOP;
260- } else if (cfg[0 ] == ' {' ) { // ID
261- const char *uuid = cfg;
262- mbstate_t state{};
263- mbsrtowcs (deviceID, &uuid,
264- (sizeof deviceID / sizeof deviceID[0 ]) - 1 ,
265- &state);
266- assert (uuid == NULL );
267- } else { // name
268- snprintf_ch (req_dev_name, " %s" , cfg);
269- }
270- }
278+ parse_fmt (cfg, &index, req_dev_name, sizeof req_dev_name, deviceID,
279+ sizeof deviceID);
280+
271281 auto s = new state_acap_wasapi ();
272282 if (!com_initialize (&s->com_initialized , MOD_NAME)) {
273283 delete s;
0 commit comments