[PATCH v7 2/4] winepulse: Return device-specific values for GetMixFormat

Claire Girka wine at gitlab.winehq.org
Mon Jul 4 13:52:55 CDT 2022


From: Claire Girka <claire at sitedethib.com>

When GetMixFormat is used, return values specific to the selected device
instead of those of the default one. This is especially useful when the
default audio device features less channels than one specifically selected
by the application.
---
 dlls/winepulse.drv/mmdevdrv.c | 21 +++++++++++++---
 dlls/winepulse.drv/pulse.c    | 46 +++++++++++++++++++++++++++++++++++
 dlls/winepulse.drv/unixlib.h  |  9 +++++++
 3 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c
index 3cbbc1d8115..61875b7352d 100644
--- a/dlls/winepulse.drv/mmdevdrv.c
+++ b/dlls/winepulse.drv/mmdevdrv.c
@@ -1136,17 +1136,30 @@ static HRESULT WINAPI AudioClient_GetMixFormat(IAudioClient3 *iface,
         WAVEFORMATEX **pwfx)
 {
     ACImpl *This = impl_from_IAudioClient3(iface);
+    struct get_mix_format_params params;
 
     TRACE("(%p)->(%p)\n", This, pwfx);
 
     if (!pwfx)
         return E_POINTER;
+    *pwfx = NULL;
 
-    *pwfx = clone_format(&pulse_config.modes[This->dataflow == eCapture].format.Format);
-    if (!*pwfx)
+    params.pulse_name = This->pulse_name;
+    params.flow = This->dataflow;
+    params.fmt = CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE));
+    if (!params.fmt)
         return E_OUTOFMEMORY;
-    dump_fmt(*pwfx);
-    return S_OK;
+
+    pulse_call(get_mix_format, &params);
+
+    if (SUCCEEDED(params.result)) {
+        *pwfx = &params.fmt->Format;
+        dump_fmt(*pwfx);
+    } else {
+        CoTaskMemFree(params.fmt);
+    }
+
+    return params.result;
 }
 
 static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient3 *iface,
diff --git a/dlls/winepulse.drv/pulse.c b/dlls/winepulse.drv/pulse.c
index a22d6717e0c..94dc2790b2b 100644
--- a/dlls/winepulse.drv/pulse.c
+++ b/dlls/winepulse.drv/pulse.c
@@ -740,6 +740,30 @@ static void pulse_probe_settings(int render, const char *pulse_name, WAVEFORMATE
         fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
 }
 
+static NTSTATUS pulse_get_mix_format(void *args)
+{
+    struct get_mix_format_params *params = args;
+    struct list *list = (params->flow == eRender) ? &g_phys_speakers : &g_phys_sources;
+    PhysDevice *dev;
+
+    if (params->pulse_name[0]) {
+        LIST_FOR_EACH_ENTRY(dev, list, PhysDevice, entry) {
+            if (strcmp(params->pulse_name, dev->pulse_name))
+                continue;
+
+            *params->fmt = dev->fmt;
+            params->result = S_OK;
+
+            return STATUS_SUCCESS;
+        }
+    }
+
+    *params->fmt = pulse_fmt[params->flow == eCapture];
+    params->result = S_OK;
+
+    return STATUS_SUCCESS;
+}
+
 /* some poorly-behaved applications call audio functions during DllMain, so we
  * have to do as much as possible without creating a new thread. this function
  * sets up a synchronous connection to verify the server is running and query
@@ -2317,6 +2341,7 @@ const unixlib_entry_t __wine_unix_call_funcs[] =
     pulse_test_connect,
     pulse_is_started,
     pulse_get_prop_value,
+    pulse_get_mix_format,
 };
 
 #ifdef _WIN64
@@ -2671,6 +2696,26 @@ static NTSTATUS pulse_wow64_get_prop_value(void *args)
     return STATUS_SUCCESS;
 }
 
+static NTSTATUS pulse_wow64_get_mix_format(void *args)
+{
+    struct
+    {
+        PTR32 pulse_name;
+        EDataFlow flow;
+        HRESULT result;
+        PTR32 fmt;
+    } *params32 = args;
+    struct get_mix_format_params params =
+    {
+        .pulse_name = ULongToPtr(params32->pulse_name),
+        .flow = params32->flow,
+        .fmt = ULongToPtr(params32->fmt),
+    };
+    pulse_get_mix_format(&params);
+    params32->result = params.result;
+    return STATUS_SUCCESS;
+}
+
 const unixlib_entry_t __wine_unix_call_wow64_funcs[] =
 {
     pulse_process_attach,
@@ -2698,6 +2743,7 @@ const unixlib_entry_t __wine_unix_call_wow64_funcs[] =
     pulse_wow64_test_connect,
     pulse_is_started,
     pulse_wow64_get_prop_value,
+    pulse_wow64_get_mix_format,
 };
 
 #endif /* _WIN64 */
diff --git a/dlls/winepulse.drv/unixlib.h b/dlls/winepulse.drv/unixlib.h
index f224f26c909..95e9dac65b8 100644
--- a/dlls/winepulse.drv/unixlib.h
+++ b/dlls/winepulse.drv/unixlib.h
@@ -159,6 +159,14 @@ struct get_current_padding_params
     UINT32 *padding;
 };
 
+struct get_mix_format_params
+{
+    const char *pulse_name;
+    EDataFlow flow;
+    HRESULT result;
+    WAVEFORMATEXTENSIBLE *fmt;
+};
+
 struct get_next_packet_size_params
 {
     stream_handle stream;
@@ -252,4 +260,5 @@ enum unix_funcs
     test_connect,
     is_started,
     get_prop_value,
+    get_mix_format,
 };
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/337



More information about the wine-devel mailing list