From abc8d376de6a8618e2911aa4f6e04f75270b2404 Mon Sep 17 00:00:00 2001 From: Andreas Bierfert Date: Tue, 17 Sep 2013 19:16:48 +0200 Subject: [PATCH] 1.7.2-1 - version upgrade - workaround for rhbz#968860 - upgraded winepulse --- .gitignore | 4 +- sources | 4 +- wine-1.5.17-osmesa-check.patch | 38 - ...ulse-1.7.0.patch => wine-pulse-1.7.1.patch | 4170 ++++++++++++----- ...-Load-winealsa-if-winepulse-is-found.patch | 29 - wine.spec | 43 +- 6 files changed, 2997 insertions(+), 1291 deletions(-) delete mode 100644 wine-1.5.17-osmesa-check.patch rename wine-pulse-1.7.0.patch => wine-pulse-1.7.1.patch (62%) delete mode 100644 wine-pulse-winmm-Load-winealsa-if-winepulse-is-found.patch diff --git a/.gitignore b/.gitignore index 5c22f89..97e4a39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /wine-1.6.tar.bz2.sign /wine-1.6.tar.bz2 -/wine-1.7.1.tar.bz2 -/wine-1.7.1.tar.bz2.sign +/wine-1.7.2.tar.bz2 +/wine-1.7.2.tar.bz2.sign diff --git a/sources b/sources index 0b979a5..49e3f0b 100644 --- a/sources +++ b/sources @@ -1,2 +1,2 @@ -3a3fae3e541ccaf1b891d89b5594ecc5 wine-1.7.1.tar.bz2 -6bc7fe035e8968b32fa2a805a1e6320e wine-1.7.1.tar.bz2.sign +17ece5f22c691bd6067c86f0dd68cfd7 wine-1.7.2.tar.bz2 +f88fbe903d2e7356a44eeb89e70d41ba wine-1.7.2.tar.bz2.sign diff --git a/wine-1.5.17-osmesa-check.patch b/wine-1.5.17-osmesa-check.patch deleted file mode 100644 index 8236192..0000000 --- a/wine-1.5.17-osmesa-check.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 1ede664b18bd8a88359a3cebb291ad49833ee033 Mon Sep 17 00:00:00 2001 -From: Alexandre Rostovtsev -Date: Tue, 7 Aug 2012 01:29:01 -0400 -Subject: [PATCH] Do not check for libGL symbols when checking libOSMesa - -If mesa had been built with shared glapi, glAccum is not available in -libOSMesa without explicitly linking to libGL. In addition, in -mesa-8.0.x and earlier, libOSMesa needs to be explicitly linked to -libglapi if mesa was built with shared glapi, see -https://bugs.gentoo.org/show_bug.cgi?id=399813 -And in mesa-8.1.x, libOSMesa in addition needs libdl, libpthread, and -libstdc++, see https://bugs.gentoo.org/show_bug.cgi?id=431832 ---- - configure.ac | 8 +++++++- - 1 file changed, 7 insertions(+), 1 deletion(-) - -diff --git a/configure.ac b/configure.ac -index cc32c24..275b792 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1128,7 +1128,13 @@ This probably prevents linking to OpenGL. Try deleting the file and restarting c - - if test "x$with_osmesa" != "xno" - then -- WINE_CHECK_SONAME(OSMesa,glAccum,,,[$X_LIBS $X_PRE_LIBS $XLIB -lm $X_EXTRA_LIBS]) -+ WINE_CHECK_SONAME(OSMesa,OSMesaCreateContext,,,[$X_LIBS $X_PRE_LIBS $XLIB -lm $X_EXTRA_LIBS]) -+ if test "x$ac_cv_lib_soname_OSMesa" = "x"; then -+ osmesa_save_CC=$CC -+ CC=$CXX -+ WINE_CHECK_SONAME(OSMesa,OSMesaCreateContext,,,[-lglapi -lpthread -ldl $X_LIBS $X_PRE_LIBS $XLIB -lm $X_EXTRA_LIBS]) -+ CC=$osmesa_save_CC -+ fi - WINE_NOTICE_WITH(osmesa,[test "x$ac_cv_lib_soname_OSMesa" = "x"], - [libOSMesa ${notice_platform}development files not found (or too old), OpenGL rendering in bitmaps won't be supported.]) - fi --- -1.8.0 - diff --git a/wine-pulse-1.7.0.patch b/wine-pulse-1.7.1.patch similarity index 62% rename from wine-pulse-1.7.0.patch rename to wine-pulse-1.7.1.patch index 27aea6b..22235c4 100644 --- a/wine-pulse-1.7.0.patch +++ b/wine-pulse-1.7.1.patch @@ -1,6 +1,58 @@ ---- wine-1.7.0/configure 2013-08-02 20:09:56.000000000 +0200 -+++ wine-1.7.0-multimedia/configure 2013-08-17 08:36:36.681595552 +0200 -@@ -656,6 +656,8 @@ +From bea77093864177659aa16aab5d81b213015990b9 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:00 +0200 +Subject: winmm: Load winealsa if winepulse is found + +Fixes midi on winepulse +--- + dlls/winmm/lolvldrv.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/dlls/winmm/lolvldrv.c b/dlls/winmm/lolvldrv.c +index f387323..3b1be27 100644 +--- a/dlls/winmm/lolvldrv.c ++++ b/dlls/winmm/lolvldrv.c +@@ -543,7 +543,10 @@ static void MMDRV_Init(void) + drvA = HeapAlloc(GetProcessHeap(), 0, size); + WideCharToMultiByte(CP_ACP, 0, pv.u.pwszVal, -1, drvA, size, NULL, NULL); + +- MMDRV_Install(drvA, drvA, FALSE); ++ if (!strcasecmp(drvA, "winepulse.drv")) ++ MMDRV_Install("winealsa.drv", "winealsa.drv", 0); ++ else ++ MMDRV_Install(drvA, drvA, FALSE); + + HeapFree(GetProcessHeap(), 0, drvA); + PropVariantClear(&pv); +-- +1.8.3.1 + + +From 713158f967a19d0c257ccdbffd63dc21ab53444f Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:00 +0200 +Subject: winepulse: Add initial stub for pulseaudio support + +--- +Just the basic of initialization and pulseaudio mainloop support is +added here. +--- + configure | 97 +++++++++++- + configure.ac | 31 +++- + dlls/mmdevapi/main.c | 2 +- + dlls/winepulse.drv/Makefile.in | 9 ++ + dlls/winepulse.drv/mmdevdrv.c | 290 ++++++++++++++++++++++++++++++++++ + dlls/winepulse.drv/winepulse.drv.spec | 5 + + 6 files changed, 429 insertions(+), 5 deletions(-) + create mode 100644 dlls/winepulse.drv/Makefile.in + create mode 100644 dlls/winepulse.drv/mmdevdrv.c + create mode 100644 dlls/winepulse.drv/winepulse.drv.spec + +diff --git a/configure b/configure +index d0f15d0..e4dba75 100755 +--- a/configure ++++ b/configure +@@ -657,6 +657,8 @@ OSS4INCL ALSALIBS GSTREAMER_LIBS GSTREAMER_CFLAGS @@ -9,7 +61,7 @@ LIBGETTEXTPO ZLIB FREETYPE_LIBS -@@ -837,6 +839,7 @@ +@@ -838,6 +840,7 @@ with_osmesa with_oss with_png with_pthread @@ -17,7 +69,7 @@ with_sane with_tiff with_v4l -@@ -1558,6 +1561,7 @@ +@@ -1559,6 +1562,7 @@ Optional Packages: --without-oss do not use the OSS sound support --without-png do not use PNG --without-pthread do not use the pthread library @@ -25,7 +77,7 @@ --without-sane do not use SANE (scanner support) --without-tiff do not use TIFF --without-v4l do not use v4l1 (v4l support) -@@ -2787,6 +2791,12 @@ +@@ -2788,6 +2792,12 @@ if test "${with_pthread+set}" = set; then : fi @@ -38,7 +90,7 @@ # Check whether --with-sane was given. if test "${with_sane+set}" = set; then : withval=$with_sane; -@@ -11193,6 +11203,87 @@ +@@ -11109,6 +11119,87 @@ esac fi fi @@ -126,7 +178,7 @@ if test "x$with_gstreamer" != "xno" then if test -n "$GSTREAMER_CFLAGS"; then : -@@ -12422,12 +12513,13 @@ +@@ -12386,12 +12477,13 @@ fi test -n "$ALSALIBS" || enable_winealsa_drv=${enable_winealsa_drv:-no} test -n "$COREAUDIO" || enable_winecoreaudio_drv=${enable_winecoreaudio_drv:-no} @@ -142,7 +194,7 @@ then as_fn_append wine_warnings "|No sound system was found. Windows applications will be silent." fi -@@ -16473,6 +16565,7 @@ +@@ -16439,6 +16531,7 @@ wine_fn_config_dll winemp3.acm enable_winemp3_acm wine_fn_config_dll wineoss.drv enable_wineoss_drv wine_fn_config_dll wineps.drv enable_wineps_drv install-lib,po wine_fn_config_dll wineps16.drv16 enable_win16 @@ -150,9 +202,11 @@ wine_fn_config_dll wineqtdecoder enable_wineqtdecoder wine_fn_config_dll winex11.drv enable_winex11_drv wine_fn_config_dll wing.dll16 enable_win16 ---- wine-1.7.0/configure.ac 2013-08-02 20:09:56.000000000 +0200 -+++ wine-1.7.0-multimedia/configure.ac 2013-08-17 08:36:36.682595549 +0200 -@@ -67,6 +67,7 @@ +diff --git a/configure.ac b/configure.ac +index d8033cf..abb40e9 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -67,6 +67,7 @@ AC_ARG_WITH(oss, AS_HELP_STRING([--without-oss],[do not use the OSS sound AC_ARG_WITH(png, AS_HELP_STRING([--without-png],[do not use PNG])) AC_ARG_WITH(pthread, AS_HELP_STRING([--without-pthread],[do not use the pthread library]), [if test "x$withval" = "xno"; then ac_cv_header_pthread_h=no; fi]) @@ -160,7 +214,7 @@ AC_ARG_WITH(sane, AS_HELP_STRING([--without-sane],[do not use SANE (scanner support)])) AC_ARG_WITH(tiff, AS_HELP_STRING([--without-tiff],[do not use TIFF])) AC_ARG_WITH(v4l, AS_HELP_STRING([--without-v4l],[do not use v4l1 (v4l support)])) -@@ -1517,6 +1518,30 @@ +@@ -1513,6 +1514,30 @@ then [GetText ${notice_platform}development files not found (or too old), po files can't be rebuilt.]) fi @@ -191,7 +245,7 @@ dnl **** Check for gstreamer **** if test "x$with_gstreamer" != "xno" then -@@ -1727,13 +1752,14 @@ +@@ -1731,13 +1756,14 @@ WINE_CHECK_SONAME(odbc,SQLConnect,,[AC_DEFINE_UNQUOTED(SONAME_LIBODBC,["libodbc. dnl **** Disable unsupported winmm drivers **** test -n "$ALSALIBS" || enable_winealsa_drv=${enable_winealsa_drv:-no} test -n "$COREAUDIO" || enable_winecoreaudio_drv=${enable_winecoreaudio_drv:-no} @@ -208,7 +262,7 @@ then WINE_WARNING([No sound system was found. Windows applications will be silent.]) fi -@@ -3113,6 +3139,7 @@ +@@ -3121,6 +3147,7 @@ WINE_CONFIG_DLL(winemp3.acm) WINE_CONFIG_DLL(wineoss.drv) WINE_CONFIG_DLL(wineps.drv,,[install-lib,po]) WINE_CONFIG_DLL(wineps16.drv16,enable_win16) @@ -216,9 +270,11 @@ WINE_CONFIG_DLL(wineqtdecoder) WINE_CONFIG_DLL(winex11.drv) WINE_CONFIG_DLL(wing.dll16,enable_win16) ---- wine-1.7.0/dlls/mmdevapi/main.c 2013-08-02 20:09:56.000000000 +0200 -+++ wine-1.7.0-multimedia/dlls/mmdevapi/main.c 2013-08-17 08:36:36.910594852 +0200 -@@ -110,7 +110,7 @@ +diff --git a/dlls/mmdevapi/main.c b/dlls/mmdevapi/main.c +index 447813f..b9ae99e 100644 +--- a/dlls/mmdevapi/main.c ++++ b/dlls/mmdevapi/main.c +@@ -110,7 +110,7 @@ static BOOL init_driver(void) { static const WCHAR drv_value[] = {'A','u','d','i','o',0}; @@ -227,9 +283,11 @@ 'c','o','r','e','a','u','d','i','o',0}; DriverFuncs driver; -diff -uhNr wine-1.7.0/dlls/winepulse.drv/Makefile.in wine-1.7.0-multimedia/dlls/winepulse.drv/Makefile.in ---- wine-1.7.0/dlls/winepulse.drv/Makefile.in 1970-01-01 01:00:00.000000000 +0100 -+++ wine-1.7.0-multimedia/dlls/winepulse.drv/Makefile.in 2013-08-17 08:36:37.219593908 +0200 +diff --git a/dlls/winepulse.drv/Makefile.in b/dlls/winepulse.drv/Makefile.in +new file mode 100644 +index 0000000..0f595f1 +--- /dev/null ++++ b/dlls/winepulse.drv/Makefile.in @@ -0,0 +1,9 @@ +MODULE = winepulse.drv +IMPORTS = dxguid uuid winmm user32 advapi32 ole32 @@ -240,10 +298,12 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/Makefile.in wine-1.7.0-multimedia/dlls/ + mmdevdrv.c + +@MAKE_DLL_RULES@ -diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/winepulse.drv/mmdevdrv.c ---- wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c 1970-01-01 01:00:00.000000000 +0100 -+++ wine-1.7.0-multimedia/dlls/winepulse.drv/mmdevdrv.c 2013-08-17 08:36:37.219593908 +0200 -@@ -0,0 +1,3221 @@ +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +new file mode 100644 +index 0000000..d187bdc +--- /dev/null ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -0,0 +1,290 @@ +/* + * Copyright 2011-2012 Maarten Lankhorst + * Copyright 2010-2011 Maarten Lankhorst for CodeWeavers @@ -268,8 +328,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + +#define NONAMELESSUNION +#define COBJMACROS -+#define _GNU_SOURCE -+ +#include "config.h" +#include +#include @@ -278,7 +336,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w +#include +#include +#include -+#include + +#include + @@ -308,7 +365,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w +#define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER) + +WINE_DEFAULT_DEBUG_CHANNEL(pulse); -+WINE_DECLARE_DEBUG_CHANNEL(winediag); + +static const REFERENCE_TIME MinimumPeriod = 30000; +static const REFERENCE_TIME DefaultPeriod = 100000; @@ -317,13 +373,8 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w +static pa_mainloop *pulse_ml; + +static HANDLE pulse_thread; -+static pthread_mutex_t pulse_lock; ++static pthread_mutex_t pulse_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t pulse_cond = PTHREAD_COND_INITIALIZER; -+static struct list g_sessions = LIST_INIT(g_sessions); -+ -+/* Mixer format + period times */ -+static WAVEFORMATEXTENSIBLE pulse_fmt[2]; -+static REFERENCE_TIME pulse_min_period[2], pulse_def_period[2]; + +static DWORD pulse_stream_volume; + @@ -331,19 +382,10 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + 'W','i','n','e','\\','P','u','l','s','e',0}; +const WCHAR pulse_streamW[] = { 'S','t','r','e','a','m','V','o','l',0 }; + -+static GUID pulse_render_guid = -+{ 0xfd47d9cc, 0x4218, 0x4135, { 0x9c, 0xe2, 0x0c, 0x19, 0x5c, 0x87, 0x40, 0x5b } }; -+static GUID pulse_capture_guid = -+{ 0x25da76d0, 0x033c, 0x4235, { 0x90, 0x02, 0x19, 0xf4, 0x88, 0x94, 0xac, 0x6f } }; -+ -+static HANDLE warn_once; -+ +BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) +{ + if (reason == DLL_PROCESS_ATTACH) { + HKEY key; -+ pthread_mutexattr_t attr; -+ + if (RegOpenKeyW(HKEY_CURRENT_USER, pulse_keyW, &key) == ERROR_SUCCESS) { + DWORD size = sizeof(pulse_stream_volume); + RegQueryValueExW(key, pulse_streamW, 0, NULL, @@ -351,155 +393,21 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + RegCloseKey(key); + } + DisableThreadLibraryCalls(dll); -+ -+ pthread_mutexattr_init(&attr); -+ pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); -+ -+ if (pthread_mutex_init(&pulse_lock, &attr) != 0) -+ pthread_mutex_init(&pulse_lock, NULL); + } else if (reason == DLL_PROCESS_DETACH) { -+ if (pulse_thread) -+ SetThreadPriority(pulse_thread, 0); + if (pulse_ctx) { + pa_context_disconnect(pulse_ctx); + pa_context_unref(pulse_ctx); + } + if (pulse_ml) + pa_mainloop_quit(pulse_ml, 0); -+ if (pulse_thread) -+ CloseHandle(pulse_thread); -+ if (warn_once) -+ CloseHandle(warn_once); ++ CloseHandle(pulse_thread); + } + return TRUE; +} + -+typedef struct ACImpl ACImpl; -+ -+typedef struct _AudioSession { -+ GUID guid; -+ struct list clients; -+ -+ IMMDevice *device; -+ -+ float master_vol; -+ UINT32 channel_count; -+ float *channel_vols; -+ BOOL mute; -+ -+ struct list entry; -+} AudioSession; -+ -+typedef struct _AudioSessionWrapper { -+ IAudioSessionControl2 IAudioSessionControl2_iface; -+ IChannelAudioVolume IChannelAudioVolume_iface; -+ ISimpleAudioVolume ISimpleAudioVolume_iface; -+ -+ LONG ref; -+ -+ ACImpl *client; -+ AudioSession *session; -+} AudioSessionWrapper; -+ -+typedef struct _ACPacket { -+ struct list entry; -+ UINT64 qpcpos; -+ BYTE *data; -+ UINT32 discont; -+} ACPacket; -+ -+struct ACImpl { -+ IAudioClient IAudioClient_iface; -+ IAudioRenderClient IAudioRenderClient_iface; -+ IAudioCaptureClient IAudioCaptureClient_iface; -+ IAudioClock IAudioClock_iface; -+ IAudioClock2 IAudioClock2_iface; -+ IAudioStreamVolume IAudioStreamVolume_iface; -+ IUnknown *marshal; -+ IMMDevice *parent; -+ struct list entry; -+ float vol[PA_CHANNELS_MAX]; -+ -+ LONG ref; -+ EDataFlow dataflow; -+ DWORD flags; -+ AUDCLNT_SHAREMODE share; -+ HANDLE event; -+ -+ UINT32 bufsize_frames, bufsize_bytes, locked, capture_period, pad, started, peek_ofs; -+ void *locked_ptr, *tmp_buffer; -+ -+ pa_stream *stream; -+ pa_sample_spec ss; -+ pa_channel_map map; -+ -+ INT64 clock_lastpos, clock_written; -+ -+ AudioSession *session; -+ AudioSessionWrapper *session_wrapper; -+ struct list packet_free_head; -+ struct list packet_filled_head; -+}; + +static const WCHAR defaultW[] = {'P','u','l','s','e','a','u','d','i','o',0}; + -+static const IAudioClientVtbl AudioClient_Vtbl; -+static const IAudioRenderClientVtbl AudioRenderClient_Vtbl; -+static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl; -+static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; -+static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl; -+static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl; -+static const IAudioClockVtbl AudioClock_Vtbl; -+static const IAudioClock2Vtbl AudioClock2_Vtbl; -+static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl; -+ -+static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client); -+ -+static inline ACImpl *impl_from_IAudioClient(IAudioClient *iface) -+{ -+ return CONTAINING_RECORD(iface, ACImpl, IAudioClient_iface); -+} -+ -+static inline ACImpl *impl_from_IAudioRenderClient(IAudioRenderClient *iface) -+{ -+ return CONTAINING_RECORD(iface, ACImpl, IAudioRenderClient_iface); -+} -+ -+static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface) -+{ -+ return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface); -+} -+ -+static inline AudioSessionWrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface) -+{ -+ return CONTAINING_RECORD(iface, AudioSessionWrapper, IAudioSessionControl2_iface); -+} -+ -+static inline AudioSessionWrapper *impl_from_ISimpleAudioVolume(ISimpleAudioVolume *iface) -+{ -+ return CONTAINING_RECORD(iface, AudioSessionWrapper, ISimpleAudioVolume_iface); -+} -+ -+static inline AudioSessionWrapper *impl_from_IChannelAudioVolume(IChannelAudioVolume *iface) -+{ -+ return CONTAINING_RECORD(iface, AudioSessionWrapper, IChannelAudioVolume_iface); -+} -+ -+static inline ACImpl *impl_from_IAudioClock(IAudioClock *iface) -+{ -+ return CONTAINING_RECORD(iface, ACImpl, IAudioClock_iface); -+} -+ -+static inline ACImpl *impl_from_IAudioClock2(IAudioClock2 *iface) -+{ -+ return CONTAINING_RECORD(iface, ACImpl, IAudioClock2_iface); -+} -+ -+static inline ACImpl *impl_from_IAudioStreamVolume(IAudioStreamVolume *iface) -+{ -+ return CONTAINING_RECORD(iface, ACImpl, IAudioStreamVolume_iface); -+} -+ +/* Following pulseaudio design here, mainloop has the lock taken whenever + * it is handling something for pulse, and the lock is required whenever + * doing any pa_* call that can affect the state in any way @@ -537,159 +445,44 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w +} + +static void pulse_contextcallback(pa_context *c, void *userdata); -+static void pulse_stream_state(pa_stream *s, void *user); -+ -+static const enum pa_channel_position pulse_pos_from_wfx[] = { -+ PA_CHANNEL_POSITION_FRONT_LEFT, -+ PA_CHANNEL_POSITION_FRONT_RIGHT, -+ PA_CHANNEL_POSITION_FRONT_CENTER, -+ PA_CHANNEL_POSITION_LFE, -+ PA_CHANNEL_POSITION_REAR_LEFT, -+ PA_CHANNEL_POSITION_REAR_RIGHT, -+ PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER, -+ PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER, -+ PA_CHANNEL_POSITION_REAR_CENTER, -+ PA_CHANNEL_POSITION_SIDE_LEFT, -+ PA_CHANNEL_POSITION_SIDE_RIGHT, -+ PA_CHANNEL_POSITION_TOP_CENTER, -+ PA_CHANNEL_POSITION_TOP_FRONT_LEFT, -+ PA_CHANNEL_POSITION_TOP_FRONT_CENTER, -+ PA_CHANNEL_POSITION_TOP_FRONT_RIGHT, -+ PA_CHANNEL_POSITION_TOP_REAR_LEFT, -+ PA_CHANNEL_POSITION_TOP_REAR_CENTER, -+ PA_CHANNEL_POSITION_TOP_REAR_RIGHT -+}; + -+static void pulse_probe_settings(int render, WAVEFORMATEXTENSIBLE *fmt) { -+ WAVEFORMATEX *wfx = &fmt->Format; -+ pa_stream *stream; -+ pa_channel_map map; -+ pa_sample_spec ss; -+ pa_buffer_attr attr; -+ int ret, i; -+ unsigned int length = 0; ++static HRESULT pulse_connect(void) ++{ ++ int len; ++ WCHAR path[PATH_MAX], *name; ++ char *str; + -+ pa_channel_map_init_auto(&map, 2, PA_CHANNEL_MAP_ALSA); -+ ss.rate = 48000; -+ ss.format = PA_SAMPLE_FLOAT32LE; -+ ss.channels = map.channels; ++ if (!pulse_thread) ++ { ++ if (!(pulse_thread = CreateThread(NULL, 0, pulse_mainloop_thread, NULL, 0, NULL))) ++ { ++ ERR("Failed to create mainloop thread."); ++ return E_FAIL; ++ } ++ SetThreadPriority(pulse_thread, THREAD_PRIORITY_TIME_CRITICAL); ++ pthread_cond_wait(&pulse_cond, &pulse_lock); ++ } + -+ attr.maxlength = -1; -+ attr.tlength = -1; -+ attr.minreq = attr.fragsize = pa_frame_size(&ss); -+ attr.prebuf = 0; ++ if (pulse_ctx && PA_CONTEXT_IS_GOOD(pa_context_get_state(pulse_ctx))) ++ return S_OK; ++ if (pulse_ctx) ++ pa_context_unref(pulse_ctx); + -+ stream = pa_stream_new(pulse_ctx, "format test stream", &ss, &map); -+ if (stream) -+ pa_stream_set_state_callback(stream, pulse_stream_state, NULL); -+ if (!stream) -+ ret = -1; -+ else if (render) -+ ret = pa_stream_connect_playback(stream, NULL, &attr, -+ PA_STREAM_START_CORKED|PA_STREAM_FIX_RATE|PA_STREAM_FIX_CHANNELS|PA_STREAM_EARLY_REQUESTS, NULL, NULL); ++ GetModuleFileNameW(NULL, path, sizeof(path)/sizeof(*path)); ++ name = strrchrW(path, '\\'); ++ if (!name) ++ name = path; + else -+ ret = pa_stream_connect_record(stream, NULL, &attr, PA_STREAM_START_CORKED|PA_STREAM_FIX_RATE|PA_STREAM_FIX_CHANNELS|PA_STREAM_EARLY_REQUESTS); -+ if (ret >= 0) { -+ while (pa_stream_get_state(stream) == PA_STREAM_CREATING) -+ pthread_cond_wait(&pulse_cond, &pulse_lock); -+ if (pa_stream_get_state(stream) == PA_STREAM_READY) { -+ ss = *pa_stream_get_sample_spec(stream); -+ map = *pa_stream_get_channel_map(stream); -+ if (render) -+ length = pa_stream_get_buffer_attr(stream)->minreq; -+ else -+ length = pa_stream_get_buffer_attr(stream)->fragsize; -+ pa_stream_disconnect(stream); -+ while (pa_stream_get_state(stream) == PA_STREAM_READY) -+ pthread_cond_wait(&pulse_cond, &pulse_lock); -+ } -+ } -+ if (stream) -+ pa_stream_unref(stream); -+ if (length) -+ pulse_def_period[!render] = pulse_min_period[!render] = pa_bytes_to_usec(10 * length, &ss); -+ else -+ pulse_min_period[!render] = MinimumPeriod; -+ if (pulse_def_period[!render] <= DefaultPeriod) -+ pulse_def_period[!render] = DefaultPeriod; -+ -+ wfx->wFormatTag = WAVE_FORMAT_EXTENSIBLE; -+ wfx->cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); -+ wfx->nChannels = ss.channels; -+ wfx->wBitsPerSample = 8 * pa_sample_size_of_format(ss.format); -+ wfx->nSamplesPerSec = ss.rate; -+ wfx->nBlockAlign = pa_frame_size(&ss); -+ wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign; -+ if (ss.format != PA_SAMPLE_S24_32LE) -+ fmt->Samples.wValidBitsPerSample = wfx->wBitsPerSample; -+ else -+ fmt->Samples.wValidBitsPerSample = 24; -+ if (ss.format == PA_SAMPLE_FLOAT32LE) -+ fmt->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; -+ else -+ fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; -+ -+ fmt->dwChannelMask = 0; -+ for (i = 0; i < map.channels; ++i) -+ switch (map.map[i]) { -+ default: FIXME("Unhandled channel %s\n", pa_channel_position_to_string(map.map[i])); break; -+ case PA_CHANNEL_POSITION_FRONT_LEFT: fmt->dwChannelMask |= SPEAKER_FRONT_LEFT; break; -+ case PA_CHANNEL_POSITION_MONO: -+ case PA_CHANNEL_POSITION_FRONT_CENTER: fmt->dwChannelMask |= SPEAKER_FRONT_CENTER; break; -+ case PA_CHANNEL_POSITION_FRONT_RIGHT: fmt->dwChannelMask |= SPEAKER_FRONT_RIGHT; break; -+ case PA_CHANNEL_POSITION_REAR_LEFT: fmt->dwChannelMask |= SPEAKER_BACK_LEFT; break; -+ case PA_CHANNEL_POSITION_REAR_CENTER: fmt->dwChannelMask |= SPEAKER_BACK_CENTER; break; -+ case PA_CHANNEL_POSITION_REAR_RIGHT: fmt->dwChannelMask |= SPEAKER_BACK_RIGHT; break; -+ case PA_CHANNEL_POSITION_LFE: fmt->dwChannelMask |= SPEAKER_LOW_FREQUENCY; break; -+ case PA_CHANNEL_POSITION_SIDE_LEFT: fmt->dwChannelMask |= SPEAKER_SIDE_LEFT; break; -+ case PA_CHANNEL_POSITION_SIDE_RIGHT: fmt->dwChannelMask |= SPEAKER_SIDE_RIGHT; break; -+ case PA_CHANNEL_POSITION_TOP_CENTER: fmt->dwChannelMask |= SPEAKER_TOP_CENTER; break; -+ case PA_CHANNEL_POSITION_TOP_FRONT_LEFT: fmt->dwChannelMask |= SPEAKER_TOP_FRONT_LEFT; break; -+ case PA_CHANNEL_POSITION_TOP_FRONT_CENTER: fmt->dwChannelMask |= SPEAKER_TOP_FRONT_CENTER; break; -+ case PA_CHANNEL_POSITION_TOP_FRONT_RIGHT: fmt->dwChannelMask |= SPEAKER_TOP_FRONT_RIGHT; break; -+ case PA_CHANNEL_POSITION_TOP_REAR_LEFT: fmt->dwChannelMask |= SPEAKER_TOP_BACK_LEFT; break; -+ case PA_CHANNEL_POSITION_TOP_REAR_CENTER: fmt->dwChannelMask |= SPEAKER_TOP_BACK_CENTER; break; -+ case PA_CHANNEL_POSITION_TOP_REAR_RIGHT: fmt->dwChannelMask |= SPEAKER_TOP_BACK_RIGHT; break; -+ } -+} -+ -+static HRESULT pulse_connect(void) -+{ -+ int len; -+ WCHAR path[PATH_MAX], *name; -+ char *str; -+ -+ if (!pulse_thread) -+ { -+ if (!(pulse_thread = CreateThread(NULL, 0, pulse_mainloop_thread, NULL, 0, NULL))) -+ { -+ ERR("Failed to create mainloop thread."); -+ return E_FAIL; -+ } -+ SetThreadPriority(pulse_thread, THREAD_PRIORITY_TIME_CRITICAL); -+ pthread_cond_wait(&pulse_cond, &pulse_lock); -+ } -+ -+ if (pulse_ctx && PA_CONTEXT_IS_GOOD(pa_context_get_state(pulse_ctx))) -+ return S_OK; -+ if (pulse_ctx) -+ pa_context_unref(pulse_ctx); -+ -+ GetModuleFileNameW(NULL, path, sizeof(path)/sizeof(*path)); -+ name = strrchrW(path, '\\'); -+ if (!name) -+ name = path; -+ else -+ name++; -+ len = WideCharToMultiByte(CP_UNIXCP, 0, name, -1, NULL, 0, NULL, NULL); -+ str = pa_xmalloc(len); -+ WideCharToMultiByte(CP_UNIXCP, 0, name, -1, str, len, NULL, NULL); -+ TRACE("Name: %s\n", str); -+ pulse_ctx = pa_context_new(pa_mainloop_get_api(pulse_ml), str); -+ pa_xfree(str); -+ if (!pulse_ctx) { -+ ERR("Failed to create context\n"); -+ return E_FAIL; ++ name++; ++ len = WideCharToMultiByte(CP_UNIXCP, 0, name, -1, NULL, 0, NULL, NULL); ++ str = pa_xmalloc(len); ++ WideCharToMultiByte(CP_UNIXCP, 0, name, -1, str, len, NULL, NULL); ++ TRACE("Name: %s\n", str); ++ pulse_ctx = pa_context_new(pa_mainloop_get_api(pulse_ml), str); ++ pa_xfree(str); ++ if (!pulse_ctx) { ++ ERR("Failed to create context\n"); ++ return E_FAIL; + } + + pa_context_set_state_callback(pulse_ctx, pulse_contextcallback, NULL); @@ -712,8 +505,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + TRACE("Connected to server %s with protocol version: %i.\n", + pa_context_get_server(pulse_ctx), + pa_context_get_server_protocol_version(pulse_ctx)); -+ pulse_probe_settings(1, &pulse_fmt[0]); -+ pulse_probe_settings(0, &pulse_fmt[1]); + return S_OK; + +fail: @@ -745,187 +536,238 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + pthread_cond_signal(&pulse_cond); +} + -+static HRESULT pulse_stream_valid(ACImpl *This) { -+ if (!This->stream) -+ return AUDCLNT_E_NOT_INITIALIZED; -+ if (!This->stream || pa_stream_get_state(This->stream) != PA_STREAM_READY) -+ return AUDCLNT_E_DEVICE_INVALIDATED; -+ return S_OK; -+} -+ -+static void dump_attr(const pa_buffer_attr *attr) { -+ TRACE("maxlength: %u\n", attr->maxlength); -+ TRACE("minreq: %u\n", attr->minreq); -+ TRACE("fragsize: %u\n", attr->fragsize); -+ TRACE("tlength: %u\n", attr->tlength); -+ TRACE("prebuf: %u\n", attr->prebuf); -+} -+ -+static void pulse_op_cb(pa_stream *s, int success, void *user) { -+ TRACE("Success: %i\n", success); -+ *(int*)user = success; -+ pthread_cond_signal(&pulse_cond); -+} -+ -+static void pulse_ctx_op_cb(pa_context *c, int success, void *user) { -+ TRACE("Success: %i\n", success); -+ *(int*)user = success; -+ pthread_cond_signal(&pulse_cond); -+} -+ -+static void pulse_attr_update(pa_stream *s, void *user) { -+ const pa_buffer_attr *attr = pa_stream_get_buffer_attr(s); -+ TRACE("New attributes or device moved:\n"); -+ dump_attr(attr); -+} -+ -+static void pulse_wr_callback(pa_stream *s, size_t bytes, void *userdata) ++HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, void ***keys, ++ UINT *num, UINT *def_index) +{ -+ ACImpl *This = userdata; -+ UINT32 oldpad = This->pad; -+ -+ if (bytes < This->bufsize_bytes) -+ This->pad = This->bufsize_bytes - bytes; -+ else -+ This->pad = 0; ++ HRESULT hr = S_OK; ++ TRACE("%d %p %p %p\n", flow, ids, num, def_index); + -+ if (oldpad == This->pad) -+ return; ++ pthread_mutex_lock(&pulse_lock); ++ hr = pulse_connect(); ++ pthread_mutex_unlock(&pulse_lock); ++ if (FAILED(hr)) ++ return hr; ++ *num = 1; ++ *def_index = 0; + -+ assert(oldpad > This->pad); ++ *ids = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR *)); ++ if (!*ids) ++ return E_OUTOFMEMORY; + -+ This->clock_written += oldpad - This->pad; -+ TRACE("New pad: %zu (-%zu)\n", This->pad / pa_frame_size(&This->ss), (oldpad - This->pad) / pa_frame_size(&This->ss)); ++ (*ids)[0] = HeapAlloc(GetProcessHeap(), 0, sizeof(defaultW)); ++ if (!(*ids)[0]) { ++ HeapFree(GetProcessHeap(), 0, *ids); ++ return E_OUTOFMEMORY; ++ } + -+ if (This->event) -+ SetEvent(This->event); -+} ++ lstrcpyW((*ids)[0], defaultW); + -+static void pulse_underflow_callback(pa_stream *s, void *userdata) -+{ -+ WARN("Underflow\n"); -+} ++ *keys = HeapAlloc(GetProcessHeap(), 0, sizeof(void *)); ++ (*keys)[0] = NULL; + -+/* Latency is periodically updated even when nothing is played, -+ * because of PA_STREAM_AUTO_TIMING_UPDATE so use it as timer -+ * -+ * Perfect for passing all tests :) -+ */ -+static void pulse_latency_callback(pa_stream *s, void *userdata) -+{ -+ ACImpl *This = userdata; -+ if (!This->pad && This->event) -+ SetEvent(This->event); ++ return S_OK; +} + -+static void pulse_started_callback(pa_stream *s, void *userdata) ++int WINAPI AUDDRV_GetPriority(void) +{ -+ TRACE("(Re)started playing\n"); ++ HRESULT hr; ++ pthread_mutex_lock(&pulse_lock); ++ hr = pulse_connect(); ++ pthread_mutex_unlock(&pulse_lock); ++ return SUCCEEDED(hr) ? 3 : 0; +} + -+static void pulse_rd_loop(ACImpl *This, size_t bytes) ++HRESULT WINAPI AUDDRV_GetAudioEndpoint(void *key, IMMDevice *dev, ++ EDataFlow dataflow, IAudioClient **out) +{ -+ while (bytes >= This->capture_period) { -+ ACPacket *p, *next; -+ LARGE_INTEGER stamp, freq; -+ BYTE *dst, *src; -+ size_t src_len, copy, rem = This->capture_period; -+ if (!(p = (ACPacket*)list_head(&This->packet_free_head))) { -+ p = (ACPacket*)list_head(&This->packet_filled_head); -+ if (!p->discont) { -+ next = (ACPacket*)p->entry.next; -+ next->discont = 1; -+ } else -+ p = (ACPacket*)list_tail(&This->packet_filled_head); -+ assert(This->pad == This->bufsize_bytes); -+ } else { -+ assert(This->pad < This->bufsize_bytes); -+ This->pad += This->capture_period; -+ assert(This->pad <= This->bufsize_bytes); -+ } -+ QueryPerformanceCounter(&stamp); -+ QueryPerformanceFrequency(&freq); -+ p->qpcpos = (stamp.QuadPart * (INT64)10000000) / freq.QuadPart; -+ p->discont = 0; -+ list_remove(&p->entry); -+ list_add_tail(&This->packet_filled_head, &p->entry); -+ -+ dst = p->data; -+ while (rem) { -+ pa_stream_peek(This->stream, (const void**)&src, &src_len); -+ assert(src_len); -+ assert(This->peek_ofs < src_len); -+ src += This->peek_ofs; -+ src_len -= This->peek_ofs; -+ assert(src_len <= bytes); -+ -+ copy = rem; -+ if (copy > src_len) -+ copy = src_len; -+ memcpy(dst, src, rem); -+ src += copy; -+ src_len -= copy; -+ dst += copy; -+ rem -= copy; ++ TRACE("%p %p %d %p\n", key, dev, dataflow, out); ++ if (dataflow != eRender && dataflow != eCapture) ++ return E_UNEXPECTED; + -+ if (!src_len) { -+ This->peek_ofs = 0; -+ pa_stream_drop(This->stream); -+ } else -+ This->peek_ofs += copy; -+ } -+ bytes -= This->capture_period; -+ } ++ *out = NULL; ++ return E_NOTIMPL; +} + -+static void pulse_rd_drop(ACImpl *This, size_t bytes) ++HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device, ++ IAudioSessionManager2 **out) +{ -+ while (bytes >= This->capture_period) { -+ size_t src_len, copy, rem = This->capture_period; -+ while (rem) { -+ const void *src; -+ pa_stream_peek(This->stream, &src, &src_len); -+ assert(src_len); -+ assert(This->peek_ofs < src_len); -+ src_len -= This->peek_ofs; -+ assert(src_len <= bytes); ++ *out = NULL; ++ return E_NOTIMPL; ++} +diff --git a/dlls/winepulse.drv/winepulse.drv.spec b/dlls/winepulse.drv/winepulse.drv.spec +new file mode 100644 +index 0000000..a089166 +--- /dev/null ++++ b/dlls/winepulse.drv/winepulse.drv.spec +@@ -0,0 +1,5 @@ ++# MMDevAPI driver functions ++@ stdcall -private GetPriority() AUDDRV_GetPriority ++@ stdcall -private GetEndpointIDs(long ptr ptr ptr ptr) AUDDRV_GetEndpointIDs ++@ stdcall -private GetAudioEndpoint(ptr ptr long ptr) AUDDRV_GetAudioEndpoint ++@ stdcall -private GetAudioSessionManager(ptr ptr) AUDDRV_GetAudioSessionManager +-- +1.8.3.1 + + +From 0592b9ae849869a6af44c7dc21ad2d9b1aebbfaa Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:00 +0200 +Subject: winepulse: Add format and period probing + +--- + dlls/winepulse.drv/mmdevdrv.c | 128 ++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 128 insertions(+) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index d187bdc..40db26d 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -70,6 +70,10 @@ static HANDLE pulse_thread; + static pthread_mutex_t pulse_lock = PTHREAD_MUTEX_INITIALIZER; + static pthread_cond_t pulse_cond = PTHREAD_COND_INITIALIZER; + ++/* Mixer format + period times */ ++static WAVEFORMATEXTENSIBLE pulse_fmt[2]; ++static REFERENCE_TIME pulse_min_period[2], pulse_def_period[2]; + -+ copy = rem; -+ if (copy > src_len) -+ copy = src_len; + static DWORD pulse_stream_volume; + + const WCHAR pulse_keyW[] = {'S','o','f','t','w','a','r','e','\\', +@@ -139,6 +143,121 @@ static DWORD CALLBACK pulse_mainloop_thread(void *tmp) { + } + + static void pulse_contextcallback(pa_context *c, void *userdata); ++static void pulse_stream_state(pa_stream *s, void *user); + -+ src_len -= copy; -+ rem -= copy; ++static const enum pa_channel_position pulse_pos_from_wfx[] = { ++ PA_CHANNEL_POSITION_FRONT_LEFT, ++ PA_CHANNEL_POSITION_FRONT_RIGHT, ++ PA_CHANNEL_POSITION_FRONT_CENTER, ++ PA_CHANNEL_POSITION_LFE, ++ PA_CHANNEL_POSITION_REAR_LEFT, ++ PA_CHANNEL_POSITION_REAR_RIGHT, ++ PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER, ++ PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER, ++ PA_CHANNEL_POSITION_REAR_CENTER, ++ PA_CHANNEL_POSITION_SIDE_LEFT, ++ PA_CHANNEL_POSITION_SIDE_RIGHT, ++ PA_CHANNEL_POSITION_TOP_CENTER, ++ PA_CHANNEL_POSITION_TOP_FRONT_LEFT, ++ PA_CHANNEL_POSITION_TOP_FRONT_CENTER, ++ PA_CHANNEL_POSITION_TOP_FRONT_RIGHT, ++ PA_CHANNEL_POSITION_TOP_REAR_LEFT, ++ PA_CHANNEL_POSITION_TOP_REAR_CENTER, ++ PA_CHANNEL_POSITION_TOP_REAR_RIGHT ++}; + -+ if (!src_len) { -+ This->peek_ofs = 0; -+ pa_stream_drop(This->stream); -+ } else -+ This->peek_ofs += copy; -+ bytes -= copy; -+ } -+ } -+} ++static void pulse_probe_settings(int render, WAVEFORMATEXTENSIBLE *fmt) { ++ WAVEFORMATEX *wfx = &fmt->Format; ++ pa_stream *stream; ++ pa_channel_map map; ++ pa_sample_spec ss; ++ pa_buffer_attr attr; ++ int ret, i; ++ unsigned int length = 0; + -+static void pulse_rd_callback(pa_stream *s, size_t bytes, void *userdata) -+{ -+ ACImpl *This = userdata; ++ pa_channel_map_init_auto(&map, 2, PA_CHANNEL_MAP_ALSA); ++ ss.rate = 48000; ++ ss.format = PA_SAMPLE_FLOAT32LE; ++ ss.channels = map.channels; + -+ TRACE("Readable total: %zu, fragsize: %u\n", bytes, pa_stream_get_buffer_attr(s)->fragsize); -+ assert(bytes >= This->peek_ofs); -+ bytes -= This->peek_ofs; -+ if (bytes < This->capture_period) -+ return; ++ attr.maxlength = -1; ++ attr.tlength = -1; ++ attr.minreq = attr.fragsize = pa_frame_size(&ss); ++ attr.prebuf = 0; + -+ if (This->started) -+ pulse_rd_loop(This, bytes); ++ stream = pa_stream_new(pulse_ctx, "format test stream", &ss, &map); ++ if (stream) ++ pa_stream_set_state_callback(stream, pulse_stream_state, NULL); ++ if (!stream) ++ ret = -1; ++ else if (render) ++ ret = pa_stream_connect_playback(stream, NULL, &attr, ++ PA_STREAM_START_CORKED|PA_STREAM_FIX_RATE|PA_STREAM_FIX_CHANNELS|PA_STREAM_EARLY_REQUESTS, NULL, NULL); + else -+ pulse_rd_drop(This, bytes); ++ ret = pa_stream_connect_record(stream, NULL, &attr, PA_STREAM_START_CORKED|PA_STREAM_FIX_RATE|PA_STREAM_FIX_CHANNELS|PA_STREAM_EARLY_REQUESTS); ++ if (ret >= 0) { ++ while (pa_stream_get_state(stream) == PA_STREAM_CREATING) ++ pthread_cond_wait(&pulse_cond, &pulse_lock); ++ if (pa_stream_get_state(stream) == PA_STREAM_READY) { ++ ss = *pa_stream_get_sample_spec(stream); ++ map = *pa_stream_get_channel_map(stream); ++ if (render) ++ length = pa_stream_get_buffer_attr(stream)->minreq; ++ else ++ length = pa_stream_get_buffer_attr(stream)->fragsize; ++ pa_stream_disconnect(stream); ++ while (pa_stream_get_state(stream) == PA_STREAM_READY) ++ pthread_cond_wait(&pulse_cond, &pulse_lock); ++ } ++ } ++ if (stream) ++ pa_stream_unref(stream); ++ if (length) ++ pulse_def_period[!render] = pulse_min_period[!render] = pa_bytes_to_usec(10 * length, &ss); ++ else ++ pulse_min_period[!render] = MinimumPeriod; ++ if (pulse_def_period[!render] <= DefaultPeriod) ++ pulse_def_period[!render] = DefaultPeriod; + -+ if (This->event) -+ SetEvent(This->event); -+} ++ wfx->wFormatTag = WAVE_FORMAT_EXTENSIBLE; ++ wfx->cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); ++ wfx->nChannels = ss.channels; ++ wfx->wBitsPerSample = 8 * pa_sample_size_of_format(ss.format); ++ wfx->nSamplesPerSec = ss.rate; ++ wfx->nBlockAlign = pa_frame_size(&ss); ++ wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign; ++ if (ss.format != PA_SAMPLE_S24_32LE) ++ fmt->Samples.wValidBitsPerSample = wfx->wBitsPerSample; ++ else ++ fmt->Samples.wValidBitsPerSample = 24; ++ if (ss.format == PA_SAMPLE_FLOAT32LE) ++ fmt->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; ++ else ++ fmt->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + ++ fmt->dwChannelMask = 0; ++ for (i = 0; i < map.channels; ++i) ++ switch (map.map[i]) { ++ default: FIXME("Unhandled channel %s\n", pa_channel_position_to_string(map.map[i])); break; ++ case PA_CHANNEL_POSITION_FRONT_LEFT: fmt->dwChannelMask |= SPEAKER_FRONT_LEFT; break; ++ case PA_CHANNEL_POSITION_MONO: ++ case PA_CHANNEL_POSITION_FRONT_CENTER: fmt->dwChannelMask |= SPEAKER_FRONT_CENTER; break; ++ case PA_CHANNEL_POSITION_FRONT_RIGHT: fmt->dwChannelMask |= SPEAKER_FRONT_RIGHT; break; ++ case PA_CHANNEL_POSITION_REAR_LEFT: fmt->dwChannelMask |= SPEAKER_BACK_LEFT; break; ++ case PA_CHANNEL_POSITION_REAR_CENTER: fmt->dwChannelMask |= SPEAKER_BACK_CENTER; break; ++ case PA_CHANNEL_POSITION_REAR_RIGHT: fmt->dwChannelMask |= SPEAKER_BACK_RIGHT; break; ++ case PA_CHANNEL_POSITION_LFE: fmt->dwChannelMask |= SPEAKER_LOW_FREQUENCY; break; ++ case PA_CHANNEL_POSITION_SIDE_LEFT: fmt->dwChannelMask |= SPEAKER_SIDE_LEFT; break; ++ case PA_CHANNEL_POSITION_SIDE_RIGHT: fmt->dwChannelMask |= SPEAKER_SIDE_RIGHT; break; ++ case PA_CHANNEL_POSITION_TOP_CENTER: fmt->dwChannelMask |= SPEAKER_TOP_CENTER; break; ++ case PA_CHANNEL_POSITION_TOP_FRONT_LEFT: fmt->dwChannelMask |= SPEAKER_TOP_FRONT_LEFT; break; ++ case PA_CHANNEL_POSITION_TOP_FRONT_CENTER: fmt->dwChannelMask |= SPEAKER_TOP_FRONT_CENTER; break; ++ case PA_CHANNEL_POSITION_TOP_FRONT_RIGHT: fmt->dwChannelMask |= SPEAKER_TOP_FRONT_RIGHT; break; ++ case PA_CHANNEL_POSITION_TOP_REAR_LEFT: fmt->dwChannelMask |= SPEAKER_TOP_BACK_LEFT; break; ++ case PA_CHANNEL_POSITION_TOP_REAR_CENTER: fmt->dwChannelMask |= SPEAKER_TOP_BACK_CENTER; break; ++ case PA_CHANNEL_POSITION_TOP_REAR_RIGHT: fmt->dwChannelMask |= SPEAKER_TOP_BACK_RIGHT; break; ++ } ++} + + static HRESULT pulse_connect(void) + { +@@ -199,6 +318,8 @@ static HRESULT pulse_connect(void) + TRACE("Connected to server %s with protocol version: %i.\n", + pa_context_get_server(pulse_ctx), + pa_context_get_server_protocol_version(pulse_ctx)); ++ pulse_probe_settings(1, &pulse_fmt[0]); ++ pulse_probe_settings(0, &pulse_fmt[1]); + return S_OK; + + fail: +@@ -230,6 +351,13 @@ static void pulse_contextcallback(pa_context *c, void *userdata) { + pthread_cond_signal(&pulse_cond); + } + +static void pulse_stream_state(pa_stream *s, void *user) +{ + pa_stream_state_t state = pa_stream_get_state(s); @@ -933,419 +775,532 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + pthread_cond_signal(&pulse_cond); +} + -+static HRESULT pulse_stream_connect(ACImpl *This, UINT32 period_bytes) { -+ int ret; -+ char buffer[64]; -+ static LONG number; -+ pa_buffer_attr attr; -+ if (This->stream) { -+ pa_stream_disconnect(This->stream); -+ while (pa_stream_get_state(This->stream) == PA_STREAM_READY) -+ pthread_cond_wait(&pulse_cond, &pulse_lock); -+ pa_stream_unref(This->stream); -+ } -+ ret = InterlockedIncrement(&number); -+ sprintf(buffer, "audio stream #%i", ret); -+ This->stream = pa_stream_new(pulse_ctx, buffer, &This->ss, &This->map); -+ pa_stream_set_state_callback(This->stream, pulse_stream_state, This); -+ pa_stream_set_buffer_attr_callback(This->stream, pulse_attr_update, This); -+ pa_stream_set_moved_callback(This->stream, pulse_attr_update, This); -+ -+ /* Pulseaudio will fill in correct values */ -+ attr.minreq = attr.fragsize = period_bytes; -+ attr.maxlength = attr.tlength = This->bufsize_bytes; -+ attr.prebuf = pa_frame_size(&This->ss); -+ dump_attr(&attr); -+ if (This->dataflow == eRender) -+ ret = pa_stream_connect_playback(This->stream, NULL, &attr, -+ PA_STREAM_START_CORKED|PA_STREAM_START_UNMUTED|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_EARLY_REQUESTS, NULL, NULL); -+ else -+ ret = pa_stream_connect_record(This->stream, NULL, &attr, -+ PA_STREAM_START_CORKED|PA_STREAM_START_UNMUTED|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_EARLY_REQUESTS); -+ if (ret < 0) { -+ WARN("Returns %i\n", ret); -+ return AUDCLNT_E_ENDPOINT_CREATE_FAILED; -+ } -+ while (pa_stream_get_state(This->stream) == PA_STREAM_CREATING) -+ pthread_cond_wait(&pulse_cond, &pulse_lock); -+ if (pa_stream_get_state(This->stream) != PA_STREAM_READY) -+ return AUDCLNT_E_ENDPOINT_CREATE_FAILED; + HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, void ***keys, + UINT *num, UINT *def_index) + { +-- +1.8.3.1 + + +From 15e7e60bbac3a58698954d9f341d65db165a031b Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:00 +0200 +Subject: winepulse: Add audioclient + +--- +Without AudioRenderClient and AudioCaptureClient it won't work, +but it's easier to review +--- + dlls/winepulse.drv/mmdevdrv.c | 1041 ++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 1040 insertions(+), 1 deletion(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 40db26d..37d85ff 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -103,9 +103,55 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) + return TRUE; + } + ++typedef struct ACImpl ACImpl; + -+ if (This->dataflow == eRender) { -+ pa_stream_set_write_callback(This->stream, pulse_wr_callback, This); -+ pa_stream_set_underflow_callback(This->stream, pulse_underflow_callback, This); -+ pa_stream_set_started_callback(This->stream, pulse_started_callback, This); -+ } else -+ pa_stream_set_read_callback(This->stream, pulse_rd_callback, This); -+ return S_OK; -+} ++typedef struct _ACPacket { ++ struct list entry; ++ UINT64 qpcpos; ++ BYTE *data; ++ UINT32 discont; ++} ACPacket; + -+HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, const WCHAR ***ids, GUID **keys, -+ UINT *num, UINT *def_index) -+{ -+ HRESULT hr = S_OK; -+ WCHAR *id; ++struct ACImpl { ++ IAudioClient IAudioClient_iface; ++ IAudioRenderClient IAudioRenderClient_iface; ++ IAudioCaptureClient IAudioCaptureClient_iface; ++ IAudioClock IAudioClock_iface; ++ IAudioClock2 IAudioClock2_iface; ++ IAudioStreamVolume IAudioStreamVolume_iface; ++ IMMDevice *parent; ++ struct list entry; ++ float vol[PA_CHANNELS_MAX]; + -+ TRACE("%d %p %p %p\n", flow, ids, num, def_index); ++ LONG ref; ++ EDataFlow dataflow; ++ DWORD flags; ++ AUDCLNT_SHAREMODE share; ++ HANDLE event; + -+ pthread_mutex_lock(&pulse_lock); -+ hr = pulse_connect(); -+ pthread_mutex_unlock(&pulse_lock); -+ if (FAILED(hr)) -+ return hr; -+ *num = 1; -+ *def_index = 0; ++ UINT32 bufsize_frames, bufsize_bytes, locked, capture_period, pad, started, peek_ofs; ++ void *locked_ptr, *tmp_buffer; + -+ *ids = HeapAlloc(GetProcessHeap(), 0, sizeof(**ids)); -+ *keys = NULL; -+ if (!*ids) -+ return E_OUTOFMEMORY; ++ pa_stream *stream; ++ pa_sample_spec ss; ++ pa_channel_map map; + -+ (*ids)[0] = id = HeapAlloc(GetProcessHeap(), 0, sizeof(defaultW)); -+ *keys = HeapAlloc(GetProcessHeap(), 0, sizeof(**keys)); -+ if (!*keys || !id) { -+ HeapFree(GetProcessHeap(), 0, id); -+ HeapFree(GetProcessHeap(), 0, *keys); -+ HeapFree(GetProcessHeap(), 0, *ids); -+ *ids = NULL; -+ *keys = NULL; -+ return E_OUTOFMEMORY; -+ } -+ memcpy(id, defaultW, sizeof(defaultW)); ++ INT64 clock_lastpos, clock_written; ++ pa_usec_t clock_pulse; + -+ if (flow == eRender) -+ (*keys)[0] = pulse_render_guid; -+ else -+ (*keys)[0] = pulse_capture_guid; ++ struct list packet_free_head; ++ struct list packet_filled_head; ++}; + + static const WCHAR defaultW[] = {'P','u','l','s','e','a','u','d','i','o',0}; + ++static const IAudioClientVtbl AudioClient_Vtbl; + -+ return S_OK; ++static inline ACImpl *impl_from_IAudioClient(IAudioClient *iface) ++{ ++ return CONTAINING_RECORD(iface, ACImpl, IAudioClient_iface); +} + -+int WINAPI AUDDRV_GetPriority(void) -+{ -+ HRESULT hr; -+ if (getenv("WINENOPULSE")) { -+ FIXME_(winediag)("winepulse has been temporarily disabled through the environment\n"); -+ return 0; -+ } -+ pthread_mutex_lock(&pulse_lock); -+ hr = pulse_connect(); -+ pthread_mutex_unlock(&pulse_lock); -+ return SUCCEEDED(hr) ? 3 : 0; + /* Following pulseaudio design here, mainloop has the lock taken whenever + * it is handling something for pulse, and the lock is required whenever + * doing any pa_* call that can affect the state in any way +@@ -351,6 +397,192 @@ static void pulse_contextcallback(pa_context *c, void *userdata) { + pthread_cond_signal(&pulse_cond); + } + ++static HRESULT pulse_stream_valid(ACImpl *This) { ++ if (!This->stream) ++ return AUDCLNT_E_NOT_INITIALIZED; ++ if (!This->stream || pa_stream_get_state(This->stream) != PA_STREAM_READY) ++ return AUDCLNT_E_DEVICE_INVALIDATED; ++ return S_OK; +} + -+HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient **out) -+{ -+ HRESULT hr; -+ ACImpl *This; -+ int i; -+ EDataFlow dataflow; -+ -+ /* Give one visible warning per session -+ * Sadly wine has chosen not to accept the winepulse patch, so support ourselves -+ */ -+ if (!warn_once && (warn_once = CreateEventA(0, 0, 0, "__winepulse_warn_event")) && GetLastError() != ERROR_ALREADY_EXISTS) { -+ FIXME_(winediag)("Winepulse is not officially supported by the wine project\n"); -+ FIXME_(winediag)("For sound related feedback and support, please visit http://ubuntuforums.org/showthread.php?t=1960599\n"); -+ } else { -+ WARN_(winediag)("Winepulse is not officially supported by the wine project\n"); -+ WARN_(winediag)("For sound related feedback and support, please visit http://ubuntuforums.org/showthread.php?t=1960599\n"); -+ } -+ -+ TRACE("%s %p %p\n", debugstr_guid(guid), dev, out); -+ if (IsEqualGUID(guid, &pulse_render_guid)) -+ dataflow = eRender; -+ else if (IsEqualGUID(guid, &pulse_capture_guid)) -+ dataflow = eCapture; -+ else -+ return E_UNEXPECTED; -+ -+ *out = NULL; -+ pthread_mutex_lock(&pulse_lock); -+ hr = pulse_connect(); -+ pthread_mutex_unlock(&pulse_lock); -+ if (FAILED(hr)) -+ return hr; -+ -+ This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This)); -+ if (!This) -+ return E_OUTOFMEMORY; -+ -+ This->IAudioClient_iface.lpVtbl = &AudioClient_Vtbl; -+ This->IAudioRenderClient_iface.lpVtbl = &AudioRenderClient_Vtbl; -+ This->IAudioCaptureClient_iface.lpVtbl = &AudioCaptureClient_Vtbl; -+ This->IAudioClock_iface.lpVtbl = &AudioClock_Vtbl; -+ This->IAudioClock2_iface.lpVtbl = &AudioClock2_Vtbl; -+ This->IAudioStreamVolume_iface.lpVtbl = &AudioStreamVolume_Vtbl; -+ This->dataflow = dataflow; -+ This->parent = dev; -+ for (i = 0; i < PA_CHANNELS_MAX; ++i) -+ This->vol[i] = 1.f; -+ -+ hr = CoCreateFreeThreadedMarshaler((IUnknown*)This, &This->marshal); -+ if (hr) { -+ HeapFree(GetProcessHeap(), 0, This); -+ return hr; -+ } -+ IMMDevice_AddRef(This->parent); ++static void dump_attr(const pa_buffer_attr *attr) { ++ TRACE("maxlength: %u\n", attr->maxlength); ++ TRACE("minreq: %u\n", attr->minreq); ++ TRACE("fragsize: %u\n", attr->fragsize); ++ TRACE("tlength: %u\n", attr->tlength); ++ TRACE("prebuf: %u\n", attr->prebuf); ++} + -+ *out = &This->IAudioClient_iface; -+ IAudioClient_AddRef(&This->IAudioClient_iface); ++static void pulse_op_cb(pa_stream *s, int success, void *user) { ++ TRACE("Success: %i\n", success); ++ *(int*)user = success; ++ pthread_cond_signal(&pulse_cond); ++} + -+ return S_OK; ++static void pulse_attr_update(pa_stream *s, void *user) { ++ const pa_buffer_attr *attr = pa_stream_get_buffer_attr(s); ++ TRACE("New attributes or device moved:\n"); ++ dump_attr(attr); +} + -+static HRESULT WINAPI AudioClient_QueryInterface(IAudioClient *iface, -+ REFIID riid, void **ppv) ++static void pulse_wr_callback(pa_stream *s, size_t bytes, void *userdata) +{ -+ ACImpl *This = impl_from_IAudioClient(iface); ++ ACImpl *This = userdata; ++ pa_usec_t time; ++ UINT32 oldpad = This->pad; + -+ TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); ++ if (bytes < This->bufsize_bytes) ++ This->pad = This->bufsize_bytes - bytes; ++ else ++ This->pad = 0; + -+ if (!ppv) -+ return E_POINTER; ++ assert(oldpad >= This->pad); + -+ *ppv = NULL; -+ if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IAudioClient)) -+ *ppv = iface; -+ if (*ppv) { -+ IUnknown_AddRef((IUnknown*)*ppv); -+ return S_OK; -+ } ++ if (0 && This->pad && pa_stream_get_time(This->stream, &time) >= 0) ++ This->clock_pulse = time; ++ else ++ This->clock_pulse = PA_USEC_INVALID; + -+ if (IsEqualIID(riid, &IID_IMarshal)) -+ return IUnknown_QueryInterface(This->marshal, riid, ppv); ++ This->clock_written += oldpad - This->pad; ++ TRACE("New pad: %u (-%u)\n", This->pad / pa_frame_size(&This->ss), (oldpad - This->pad) / pa_frame_size(&This->ss)); + -+ WARN("Unknown interface %s\n", debugstr_guid(riid)); -+ return E_NOINTERFACE; ++ if (This->event) ++ SetEvent(This->event); +} + -+static ULONG WINAPI AudioClient_AddRef(IAudioClient *iface) ++static void pulse_underflow_callback(pa_stream *s, void *userdata) +{ -+ ACImpl *This = impl_from_IAudioClient(iface); -+ ULONG ref; -+ ref = InterlockedIncrement(&This->ref); -+ TRACE("(%p) Refcount now %u\n", This, ref); -+ return ref; ++ ACImpl *This = userdata; ++ This->clock_pulse = PA_USEC_INVALID; ++ WARN("Underflow\n"); +} + -+static ULONG WINAPI AudioClient_Release(IAudioClient *iface) ++/* Latency is periodically updated even when nothing is played, ++ * because of PA_STREAM_AUTO_TIMING_UPDATE so use it as timer ++ * ++ * Perfect for passing all tests :) ++ */ ++static void pulse_latency_callback(pa_stream *s, void *userdata) +{ -+ ACImpl *This = impl_from_IAudioClient(iface); -+ ULONG ref; -+ ref = InterlockedDecrement(&This->ref); -+ TRACE("(%p) Refcount now %u\n", This, ref); -+ if (!ref) { -+ if (This->stream) { -+ pthread_mutex_lock(&pulse_lock); -+ if (PA_STREAM_IS_GOOD(pa_stream_get_state(This->stream))) { -+ pa_stream_disconnect(This->stream); -+ while (PA_STREAM_IS_GOOD(pa_stream_get_state(This->stream))) -+ pthread_cond_wait(&pulse_cond, &pulse_lock); -+ } -+ pa_stream_unref(This->stream); -+ This->stream = NULL; -+ list_remove(&This->entry); -+ pthread_mutex_unlock(&pulse_lock); -+ } -+ IUnknown_Release(This->marshal); -+ IMMDevice_Release(This->parent); -+ HeapFree(GetProcessHeap(), 0, This->tmp_buffer); -+ HeapFree(GetProcessHeap(), 0, This); -+ } -+ return ref; ++ ACImpl *This = userdata; ++ if (!This->pad && This->event) ++ SetEvent(This->event); +} + -+static void dump_fmt(const WAVEFORMATEX *fmt) ++static void pulse_started_callback(pa_stream *s, void *userdata) +{ -+ TRACE("wFormatTag: 0x%x (", fmt->wFormatTag); -+ switch(fmt->wFormatTag) { -+ case WAVE_FORMAT_PCM: -+ TRACE("WAVE_FORMAT_PCM"); -+ break; -+ case WAVE_FORMAT_IEEE_FLOAT: -+ TRACE("WAVE_FORMAT_IEEE_FLOAT"); -+ break; -+ case WAVE_FORMAT_EXTENSIBLE: -+ TRACE("WAVE_FORMAT_EXTENSIBLE"); -+ break; -+ default: -+ TRACE("Unknown"); -+ break; -+ } -+ TRACE(")\n"); -+ -+ TRACE("nChannels: %u\n", fmt->nChannels); -+ TRACE("nSamplesPerSec: %u\n", fmt->nSamplesPerSec); -+ TRACE("nAvgBytesPerSec: %u\n", fmt->nAvgBytesPerSec); -+ TRACE("nBlockAlign: %u\n", fmt->nBlockAlign); -+ TRACE("wBitsPerSample: %u\n", fmt->wBitsPerSample); -+ TRACE("cbSize: %u\n", fmt->cbSize); ++ ACImpl *This = userdata; ++ pa_usec_t time; + -+ if (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE) { -+ WAVEFORMATEXTENSIBLE *fmtex = (void*)fmt; -+ TRACE("dwChannelMask: %08x\n", fmtex->dwChannelMask); -+ TRACE("Samples: %04x\n", fmtex->Samples.wReserved); -+ TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex->SubFormat)); -+ } ++ TRACE("(Re)started playing\n"); ++ assert(This->clock_pulse == PA_USEC_INVALID); ++ if (0 && pa_stream_get_time(This->stream, &time) >= 0) ++ This->clock_pulse = time; ++ if (This->event) ++ SetEvent(This->event); +} + -+static WAVEFORMATEX *clone_format(const WAVEFORMATEX *fmt) ++static void pulse_rd_loop(ACImpl *This, size_t bytes) +{ -+ WAVEFORMATEX *ret; -+ size_t size; -+ -+ if (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE) -+ size = sizeof(WAVEFORMATEXTENSIBLE); -+ else -+ size = sizeof(WAVEFORMATEX); -+ -+ ret = CoTaskMemAlloc(size); -+ if (!ret) -+ return NULL; ++ while (bytes >= This->capture_period) { ++ ACPacket *p, *next; ++ LARGE_INTEGER stamp, freq; ++ BYTE *dst, *src; ++ UINT32 src_len, copy, rem = This->capture_period; ++ if (!(p = (ACPacket*)list_head(&This->packet_free_head))) { ++ p = (ACPacket*)list_head(&This->packet_filled_head); ++ if (!p->discont) { ++ next = (ACPacket*)p->entry.next; ++ next->discont = 1; ++ } else ++ p = (ACPacket*)list_tail(&This->packet_filled_head); ++ assert(This->pad == This->bufsize_bytes); ++ } else { ++ assert(This->pad < This->bufsize_bytes); ++ This->pad += This->capture_period; ++ assert(This->pad <= This->bufsize_bytes); ++ } ++ QueryPerformanceCounter(&stamp); ++ QueryPerformanceFrequency(&freq); ++ p->qpcpos = (stamp.QuadPart * (INT64)10000000) / freq.QuadPart; ++ p->discont = 0; ++ list_remove(&p->entry); ++ list_add_tail(&This->packet_filled_head, &p->entry); + -+ memcpy(ret, fmt, size); ++ dst = p->data; ++ while (rem) { ++ pa_stream_peek(This->stream, (const void**)&src, &src_len); ++ assert(src_len && src_len <= bytes); ++ assert(This->peek_ofs < src_len); ++ src += This->peek_ofs; ++ src_len -= This->peek_ofs; + -+ ret->cbSize = size - sizeof(WAVEFORMATEX); ++ copy = rem; ++ if (copy > src_len) ++ copy = src_len; ++ memcpy(dst, src, rem); ++ src += copy; ++ src_len -= copy; ++ dst += copy; ++ rem -= copy; + -+ return ret; ++ if (!src_len) { ++ This->peek_ofs = 0; ++ pa_stream_drop(This->stream); ++ } else ++ This->peek_ofs += copy; ++ } ++ bytes -= This->capture_period; ++ } +} + -+static DWORD get_channel_mask(unsigned int channels) ++static void pulse_rd_drop(ACImpl *This, size_t bytes) +{ -+ switch(channels) { -+ case 0: -+ return 0; -+ case 1: -+ return SPEAKER_FRONT_CENTER; -+ case 2: -+ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; -+ case 3: -+ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | -+ SPEAKER_LOW_FREQUENCY; -+ case 4: -+ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | -+ SPEAKER_BACK_RIGHT; -+ case 5: -+ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | -+ SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY; -+ case 6: -+ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | -+ SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY | SPEAKER_FRONT_CENTER; -+ case 7: -+ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | -+ SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY | SPEAKER_FRONT_CENTER | -+ SPEAKER_BACK_CENTER; -+ case 8: -+ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | -+ SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY | SPEAKER_FRONT_CENTER | -+ SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT; ++ while (bytes >= This->capture_period) { ++ UINT32 src_len, copy, rem = This->capture_period; ++ while (rem) { ++ const void *src; ++ pa_stream_peek(This->stream, &src, &src_len); ++ assert(src_len && src_len <= bytes); ++ assert(This->peek_ofs < src_len); ++ src_len -= This->peek_ofs; ++ ++ copy = rem; ++ if (copy > src_len) ++ copy = src_len; ++ ++ src_len -= copy; ++ rem -= copy; ++ ++ if (!src_len) { ++ This->peek_ofs = 0; ++ pa_stream_drop(This->stream); ++ } else ++ This->peek_ofs += copy; ++ bytes -= copy; ++ } + } -+ FIXME("Unknown speaker configuration: %u\n", channels); -+ return 0; +} + -+static void session_init_vols(AudioSession *session, UINT channels) ++static void pulse_rd_callback(pa_stream *s, size_t bytes, void *userdata) +{ -+ if (session->channel_count < channels) { -+ UINT i; ++ ACImpl *This = userdata; + -+ if (session->channel_vols) -+ session->channel_vols = HeapReAlloc(GetProcessHeap(), 0, -+ session->channel_vols, sizeof(float) * channels); -+ else -+ session->channel_vols = HeapAlloc(GetProcessHeap(), 0, -+ sizeof(float) * channels); -+ if (!session->channel_vols) -+ return; ++ TRACE("Readable total: %u, fragsize: %u\n", bytes, pa_stream_get_buffer_attr(s)->fragsize); ++ assert(bytes >= This->peek_ofs); ++ bytes -= This->peek_ofs; ++ if (bytes < This->capture_period) ++ return; + -+ for(i = session->channel_count; i < channels; ++i) -+ session->channel_vols[i] = 1.f; ++ if (This->started) ++ pulse_rd_loop(This, bytes); ++ else ++ pulse_rd_drop(This, bytes); + -+ session->channel_count = channels; -+ } ++ if (This->event) ++ SetEvent(This->event); +} + -+static AudioSession *create_session(const GUID *guid, IMMDevice *device, -+ UINT num_channels) -+{ -+ AudioSession *ret; + static void pulse_stream_state(pa_stream *s, void *user) + { + pa_stream_state_t state = pa_stream_get_state(s); +@@ -358,6 +590,53 @@ static void pulse_stream_state(pa_stream *s, void *user) + pthread_cond_signal(&pulse_cond); + } + ++static HRESULT pulse_stream_connect(ACImpl *This, UINT32 period_bytes) { ++ int ret; ++ char buffer[64]; ++ static LONG number; ++ pa_buffer_attr attr; ++ if (This->stream) { ++ pa_stream_disconnect(This->stream); ++ while (pa_stream_get_state(This->stream) == PA_STREAM_READY) ++ pthread_cond_wait(&pulse_cond, &pulse_lock); ++ pa_stream_unref(This->stream); ++ } ++ ret = InterlockedIncrement(&number); ++ sprintf(buffer, "audio stream #%i", ret); ++ This->stream = pa_stream_new(pulse_ctx, buffer, &This->ss, &This->map); ++ pa_stream_set_state_callback(This->stream, pulse_stream_state, This); ++ pa_stream_set_buffer_attr_callback(This->stream, pulse_attr_update, This); ++ pa_stream_set_moved_callback(This->stream, pulse_attr_update, This); + -+ ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AudioSession)); -+ if (!ret) -+ return NULL; ++ /* Pulseaudio will fill in correct values */ ++ attr.minreq = attr.fragsize = period_bytes; ++ attr.maxlength = attr.tlength = This->bufsize_bytes; ++ attr.prebuf = pa_frame_size(&This->ss); ++ dump_attr(&attr); ++ if (This->dataflow == eRender) ++ ret = pa_stream_connect_playback(This->stream, NULL, &attr, ++ PA_STREAM_START_CORKED|PA_STREAM_START_UNMUTED|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_EARLY_REQUESTS, NULL, NULL); ++ else ++ ret = pa_stream_connect_record(This->stream, NULL, &attr, ++ PA_STREAM_START_CORKED|PA_STREAM_START_UNMUTED|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_EARLY_REQUESTS); ++ if (ret < 0) { ++ WARN("Returns %i\n", ret); ++ return AUDCLNT_E_ENDPOINT_CREATE_FAILED; ++ } ++ while (pa_stream_get_state(This->stream) == PA_STREAM_CREATING) ++ pthread_cond_wait(&pulse_cond, &pulse_lock); ++ if (pa_stream_get_state(This->stream) != PA_STREAM_READY) ++ return AUDCLNT_E_ENDPOINT_CREATE_FAILED; + -+ memcpy(&ret->guid, guid, sizeof(GUID)); ++ if (This->dataflow == eRender) { ++ pa_stream_set_write_callback(This->stream, pulse_wr_callback, This); ++ pa_stream_set_underflow_callback(This->stream, pulse_underflow_callback, This); ++ pa_stream_set_started_callback(This->stream, pulse_started_callback, This); ++ } else ++ pa_stream_set_read_callback(This->stream, pulse_rd_callback, This); ++ return S_OK; ++} + -+ ret->device = device; + HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, void ***keys, + UINT *num, UINT *def_index) + { +@@ -402,14 +681,774 @@ int WINAPI AUDDRV_GetPriority(void) + HRESULT WINAPI AUDDRV_GetAudioEndpoint(void *key, IMMDevice *dev, + EDataFlow dataflow, IAudioClient **out) + { ++ HRESULT hr; ++ ACImpl *This; ++ int i; + -+ list_init(&ret->clients); + TRACE("%p %p %d %p\n", key, dev, dataflow, out); + if (dataflow != eRender && dataflow != eCapture) + return E_UNEXPECTED; + + *out = NULL; +- return E_NOTIMPL; ++ pthread_mutex_lock(&pulse_lock); ++ hr = pulse_connect(); ++ pthread_mutex_unlock(&pulse_lock); ++ if (FAILED(hr)) ++ return hr; + -+ list_add_head(&g_sessions, &ret->entry); ++ This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This)); ++ if (!This) ++ return E_OUTOFMEMORY; + -+ session_init_vols(ret, num_channels); ++ This->IAudioClient_iface.lpVtbl = &AudioClient_Vtbl; ++ This->dataflow = dataflow; ++ This->parent = dev; ++ This->clock_pulse = PA_USEC_INVALID; ++ for (i = 0; i < PA_CHANNELS_MAX; ++i) ++ This->vol[i] = 1.f; ++ IMMDevice_AddRef(This->parent); + -+ ret->master_vol = 1.f; ++ *out = &This->IAudioClient_iface; ++ IAudioClient_AddRef(&This->IAudioClient_iface); + -+ return ret; ++ return S_OK; +} + -+/* if channels == 0, then this will return or create a session with -+ * matching dataflow and GUID. otherwise, channels must also match */ -+static HRESULT get_audio_session(const GUID *sessionguid, -+ IMMDevice *device, UINT channels, AudioSession **out) ++static HRESULT WINAPI AudioClient_QueryInterface(IAudioClient *iface, ++ REFIID riid, void **ppv) +{ -+ AudioSession *session; -+ -+ if (!sessionguid || IsEqualGUID(sessionguid, &GUID_NULL)) { -+ *out = create_session(&GUID_NULL, device, channels); -+ if (!*out) -+ return E_OUTOFMEMORY; ++ TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + ++ if (!ppv) ++ return E_POINTER; ++ *ppv = NULL; ++ if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IAudioClient)) ++ *ppv = iface; ++ if (*ppv) { ++ IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; + } ++ WARN("Unknown interface %s\n", debugstr_guid(riid)); ++ return E_NOINTERFACE; ++} + -+ *out = NULL; -+ LIST_FOR_EACH_ENTRY(session, &g_sessions, AudioSession, entry) { -+ if (session->device == device && -+ IsEqualGUID(sessionguid, &session->guid)) { -+ session_init_vols(session, channels); -+ *out = session; -+ break; -+ } -+ } ++static ULONG WINAPI AudioClient_AddRef(IAudioClient *iface) ++{ ++ ACImpl *This = impl_from_IAudioClient(iface); ++ ULONG ref; ++ ref = InterlockedIncrement(&This->ref); ++ TRACE("(%p) Refcount now %u\n", This, ref); ++ return ref; ++} + -+ if (!*out) { -+ *out = create_session(sessionguid, device, channels); -+ if (!*out) -+ return E_OUTOFMEMORY; ++static ULONG WINAPI AudioClient_Release(IAudioClient *iface) ++{ ++ ACImpl *This = impl_from_IAudioClient(iface); ++ ULONG ref; ++ ref = InterlockedDecrement(&This->ref); ++ TRACE("(%p) Refcount now %u\n", This, ref); ++ if (!ref) { ++ if (This->stream) { ++ pthread_mutex_lock(&pulse_lock); ++ if (PA_STREAM_IS_GOOD(pa_stream_get_state(This->stream))) { ++ pa_stream_disconnect(This->stream); ++ while (PA_STREAM_IS_GOOD(pa_stream_get_state(This->stream))) ++ pthread_cond_wait(&pulse_cond, &pulse_lock); ++ } ++ pa_stream_unref(This->stream); ++ This->stream = NULL; ++ list_remove(&This->entry); ++ pthread_mutex_unlock(&pulse_lock); ++ } ++ IMMDevice_Release(This->parent); ++ HeapFree(GetProcessHeap(), 0, This->tmp_buffer); ++ HeapFree(GetProcessHeap(), 0, This); + } -+ -+ return S_OK; ++ return ref; +} + -+static HRESULT pulse_spec_from_waveformat(ACImpl *This, const WAVEFORMATEX *fmt) ++static void dump_fmt(const WAVEFORMATEX *fmt) +{ -+ pa_channel_map_init(&This->map); -+ This->ss.rate = fmt->nSamplesPerSec; -+ This->ss.format = PA_SAMPLE_INVALID; ++ TRACE("wFormatTag: 0x%x (", fmt->wFormatTag); + switch(fmt->wFormatTag) { ++ case WAVE_FORMAT_PCM: ++ TRACE("WAVE_FORMAT_PCM"); ++ break; + case WAVE_FORMAT_IEEE_FLOAT: -+ if (!fmt->nChannels || fmt->nChannels > 2 || fmt->wBitsPerSample != 32) -+ break; -+ This->ss.format = PA_SAMPLE_FLOAT32LE; -+ pa_channel_map_init_auto(&This->map, fmt->nChannels, PA_CHANNEL_MAP_ALSA); ++ TRACE("WAVE_FORMAT_IEEE_FLOAT"); + break; -+ case WAVE_FORMAT_PCM: -+ if (!fmt->nChannels || fmt->nChannels > 2) -+ break; -+ if (fmt->wBitsPerSample == 8) -+ This->ss.format = PA_SAMPLE_U8; -+ else if (fmt->wBitsPerSample == 16) -+ This->ss.format = PA_SAMPLE_S16LE; -+ else -+ return AUDCLNT_E_UNSUPPORTED_FORMAT; -+ pa_channel_map_init_auto(&This->map, fmt->nChannels, PA_CHANNEL_MAP_ALSA); ++ case WAVE_FORMAT_EXTENSIBLE: ++ TRACE("WAVE_FORMAT_EXTENSIBLE"); ++ break; ++ default: ++ TRACE("Unknown"); ++ break; ++ } ++ TRACE(")\n"); ++ ++ TRACE("nChannels: %u\n", fmt->nChannels); ++ TRACE("nSamplesPerSec: %u\n", fmt->nSamplesPerSec); ++ TRACE("nAvgBytesPerSec: %u\n", fmt->nAvgBytesPerSec); ++ TRACE("nBlockAlign: %u\n", fmt->nBlockAlign); ++ TRACE("wBitsPerSample: %u\n", fmt->wBitsPerSample); ++ TRACE("cbSize: %u\n", fmt->cbSize); ++ ++ if (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE) { ++ WAVEFORMATEXTENSIBLE *fmtex = (void*)fmt; ++ TRACE("dwChannelMask: %08x\n", fmtex->dwChannelMask); ++ TRACE("Samples: %04x\n", fmtex->Samples.wReserved); ++ TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex->SubFormat)); ++ } ++} ++ ++static WAVEFORMATEX *clone_format(const WAVEFORMATEX *fmt) ++{ ++ WAVEFORMATEX *ret; ++ size_t size; ++ ++ if (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE) ++ size = sizeof(WAVEFORMATEXTENSIBLE); ++ else ++ size = sizeof(WAVEFORMATEX); ++ ++ ret = CoTaskMemAlloc(size); ++ if (!ret) ++ return NULL; ++ ++ memcpy(ret, fmt, size); ++ ++ ret->cbSize = size - sizeof(WAVEFORMATEX); ++ ++ return ret; ++} ++ ++static DWORD get_channel_mask(unsigned int channels) ++{ ++ switch(channels) { ++ case 0: ++ return 0; ++ case 1: ++ return SPEAKER_FRONT_CENTER; ++ case 2: ++ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; ++ case 3: ++ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | ++ SPEAKER_LOW_FREQUENCY; ++ case 4: ++ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | ++ SPEAKER_BACK_RIGHT; ++ case 5: ++ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | ++ SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY; ++ case 6: ++ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | ++ SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY | SPEAKER_FRONT_CENTER; ++ case 7: ++ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | ++ SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY | SPEAKER_FRONT_CENTER | ++ SPEAKER_BACK_CENTER; ++ case 8: ++ return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | ++ SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY | SPEAKER_FRONT_CENTER | ++ SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT; ++ } ++ FIXME("Unknown speaker configuration: %u\n", channels); ++ return 0; ++} ++ ++static HRESULT pulse_spec_from_waveformat(ACImpl *This, const WAVEFORMATEX *fmt) ++{ ++ pa_channel_map_init(&This->map); ++ This->ss.rate = fmt->nSamplesPerSec; ++ This->ss.format = PA_SAMPLE_INVALID; ++ switch(fmt->wFormatTag) { ++ case WAVE_FORMAT_IEEE_FLOAT: ++ if (!fmt->nChannels || fmt->nChannels > 2 || fmt->wBitsPerSample != 32) ++ break; ++ This->ss.format = PA_SAMPLE_FLOAT32LE; ++ pa_channel_map_init_auto(&This->map, fmt->nChannels, PA_CHANNEL_MAP_ALSA); ++ break; ++ case WAVE_FORMAT_PCM: ++ if (!fmt->nChannels || fmt->nChannels > 2) ++ break; ++ if (fmt->wBitsPerSample == 8) ++ This->ss.format = PA_SAMPLE_U8; ++ else if (fmt->wBitsPerSample == 16) ++ This->ss.format = PA_SAMPLE_S16LE; ++ pa_channel_map_init_auto(&This->map, fmt->nChannels, PA_CHANNEL_MAP_ALSA); + break; + case WAVE_FORMAT_EXTENSIBLE: { + WAVEFORMATEXTENSIBLE *wfe = (WAVEFORMATEXTENSIBLE*)fmt; @@ -1381,13 +1336,12 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + This->ss.format = PA_SAMPLE_S24_32LE; + else if (valid == 32) + This->ss.format = PA_SAMPLE_S32LE; -+ break; + default: -+ return AUDCLNT_E_UNSUPPORTED_FORMAT; ++ break; + } + } + This->map.channels = fmt->nChannels; -+ if (!mask || (mask & (SPEAKER_ALL|SPEAKER_RESERVED))) ++ if (!mask) + mask = get_channel_mask(fmt->nChannels); + for (j = 0; j < sizeof(pulse_pos_from_wfx)/sizeof(*pulse_pos_from_wfx) && i < fmt->nChannels; ++j) { + if (mask & (1 << j)) @@ -1398,29 +1352,19 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + if (mask == SPEAKER_FRONT_CENTER) + This->map.map[0] = PA_CHANNEL_POSITION_MONO; + ++ if ((mask & SPEAKER_ALL) && i < fmt->nChannels) { ++ This->map.map[i++] = PA_CHANNEL_POSITION_MONO; ++ FIXME("Is the 'all' channel mapped correctly?\n"); ++ } ++ + if (i < fmt->nChannels || (mask & SPEAKER_RESERVED)) { + This->map.channels = 0; -+ ERR("Invalid channel mask: %i/%i and %x(%x)\n", i, fmt->nChannels, mask, wfe->dwChannelMask); ++ ERR("Invalid channel mask: %i/%i and %x\n", i, fmt->nChannels, mask); + break; + } + break; + } -+ case WAVE_FORMAT_ALAW: -+ case WAVE_FORMAT_MULAW: -+ if (fmt->wBitsPerSample != 8) { -+ FIXME("Unsupported bpp %u for LAW\n", fmt->wBitsPerSample); -+ return AUDCLNT_E_UNSUPPORTED_FORMAT; -+ } -+ if (fmt->nChannels != 1 && fmt->nChannels != 2) { -+ FIXME("Unsupported channels %u for LAW\n", fmt->nChannels); -+ return AUDCLNT_E_UNSUPPORTED_FORMAT; -+ } -+ This->ss.format = fmt->wFormatTag == WAVE_FORMAT_MULAW ? PA_SAMPLE_ULAW : PA_SAMPLE_ALAW; -+ pa_channel_map_init_auto(&This->map, fmt->nChannels, PA_CHANNEL_MAP_ALSA); -+ break; -+ default: -+ WARN("Unhandled tag %x\n", fmt->wFormatTag); -+ return AUDCLNT_E_UNSUPPORTED_FORMAT; ++ default: FIXME("Unhandled tag %x\n", fmt->wFormatTag); + } + This->ss.channels = This->map.channels; + if (!pa_channel_map_valid(&This->map) || This->ss.format == PA_SAMPLE_INVALID) { @@ -1429,8 +1373,8 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + return AUDCLNT_E_UNSUPPORTED_FORMAT; + } + return S_OK; -+} -+ + } + +static HRESULT WINAPI AudioClient_Initialize(IAudioClient *iface, + AUDCLNT_SHAREMODE mode, DWORD flags, REFERENCE_TIME duration, + REFERENCE_TIME period, const WAVEFORMATEX *fmt, @@ -1474,25 +1418,9 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + goto exit; + + if (mode == AUDCLNT_SHAREMODE_SHARED) { -+ REFERENCE_TIME def = pulse_def_period[This->dataflow == eCapture]; -+ REFERENCE_TIME min = pulse_min_period[This->dataflow == eCapture]; -+ -+ /* Switch to low latency mode if below 2 default periods, -+ * which is 20 ms by default, this will increase the amount -+ * of interrupts but allows very low latency. In dsound I -+ * managed to get a total latency of ~8ms, which is well below -+ * default -+ */ -+ if (duration < 2 * def) -+ period = min; -+ else -+ period = def; ++ period = pulse_def_period[This->dataflow == eCapture]; + if (duration < 2 * period) + duration = 2 * period; -+ -+ /* Uh oh, really low latency requested.. */ -+ if (duration <= 2 * period) -+ period /= 2; + } + period_bytes = pa_frame_size(&This->ss) * MulDiv(period, This->ss.rate, 10000000); + @@ -1539,10 +1467,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + assert(!capture_packets || data - This->bufsize_bytes == This->tmp_buffer); + } + } -+ if (SUCCEEDED(hr)) -+ hr = get_audio_session(sessionguid, This->parent, fmt->nChannels, &This->session); -+ if (SUCCEEDED(hr)) -+ list_add_tail(&This->session->clients, &This->entry); + +exit: + if (FAILED(hr)) { @@ -1662,184 +1586,76 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + ACImpl *This = impl_from_IAudioClient(iface); + HRESULT hr = S_OK; + WAVEFORMATEX *closest = NULL; -+ BOOL exclusive; + + TRACE("(%p)->(%x, %p, %p)\n", This, mode, fmt, out); + -+ if (!fmt) ++ if (!fmt || (mode == AUDCLNT_SHAREMODE_SHARED && !out)) + return E_POINTER; + + if (out) + *out = NULL; -+ -+ if (mode == AUDCLNT_SHAREMODE_EXCLUSIVE) { -+ exclusive = 1; -+ out = NULL; -+ } else if (mode == AUDCLNT_SHAREMODE_SHARED) { -+ exclusive = 0; -+ if (!out) -+ return E_POINTER; -+ } else ++ if (mode != AUDCLNT_SHAREMODE_SHARED && mode != AUDCLNT_SHAREMODE_EXCLUSIVE) ++ return E_INVALIDARG; ++ if (mode == AUDCLNT_SHAREMODE_EXCLUSIVE) ++ return This->dataflow == eCapture ? AUDCLNT_E_UNSUPPORTED_FORMAT : AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED; ++ if (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE && ++ fmt->cbSize < sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)) + return E_INVALIDARG; + -+ if (fmt->nChannels == 0) -+ return AUDCLNT_E_UNSUPPORTED_FORMAT; ++ dump_fmt(fmt); + + closest = clone_format(fmt); + if (!closest) -+ return E_OUTOFMEMORY; ++ hr = E_OUTOFMEMORY; + -+ dump_fmt(fmt); ++ if (hr == S_OK || !out) { ++ CoTaskMemFree(closest); ++ if (out) ++ *out = NULL; ++ } else if (closest) { ++ closest->nBlockAlign = ++ closest->nChannels * closest->wBitsPerSample / 8; ++ closest->nAvgBytesPerSec = ++ closest->nBlockAlign * closest->nSamplesPerSec; ++ *out = closest; ++ } + -+ switch (fmt->wFormatTag) { -+ case WAVE_FORMAT_EXTENSIBLE: { -+ WAVEFORMATEXTENSIBLE *ext = (WAVEFORMATEXTENSIBLE*)closest; ++ TRACE("returning: %08x %p\n", hr, out ? *out : NULL); ++ return hr; ++} + -+ if ((fmt->cbSize != sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) && -+ fmt->cbSize != sizeof(WAVEFORMATEXTENSIBLE)) || -+ fmt->nBlockAlign != fmt->wBitsPerSample / 8 * fmt->nChannels || -+ ext->Samples.wValidBitsPerSample > fmt->wBitsPerSample || -+ fmt->nAvgBytesPerSec != fmt->nBlockAlign * fmt->nSamplesPerSec) { -+ hr = E_INVALIDARG; -+ break; -+ } ++static HRESULT WINAPI AudioClient_GetMixFormat(IAudioClient *iface, ++ WAVEFORMATEX **pwfx) ++{ ++ ACImpl *This = impl_from_IAudioClient(iface); ++ WAVEFORMATEXTENSIBLE *fmt = &pulse_fmt[This->dataflow == eCapture]; + -+ if (exclusive) { -+ UINT32 mask = 0, i, channels = 0; ++ TRACE("(%p)->(%p)\n", This, pwfx); + -+ if (!(ext->dwChannelMask & (SPEAKER_ALL | SPEAKER_RESERVED))) { -+ for (i = 1; !(i & SPEAKER_RESERVED); i <<= 1) { -+ if (i & ext->dwChannelMask) { -+ mask |= i; -+ channels++; -+ } -+ } ++ if (!pwfx) ++ return E_POINTER; + -+ if (channels != fmt->nChannels || (ext->dwChannelMask & ~mask)) { -+ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; -+ break; -+ } -+ } else { -+ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; -+ break; -+ } -+ } ++ *pwfx = clone_format(&fmt->Format); ++ if (!*pwfx) ++ return E_OUTOFMEMORY; ++ dump_fmt(*pwfx); ++ return S_OK; ++} + -+ if (IsEqualGUID(&ext->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) { -+ if (fmt->wBitsPerSample != 32) { -+ hr = E_INVALIDARG; -+ break; -+ } ++static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient *iface, ++ REFERENCE_TIME *defperiod, REFERENCE_TIME *minperiod) ++{ ++ ACImpl *This = impl_from_IAudioClient(iface); + -+ if (ext->Samples.wValidBitsPerSample != fmt->wBitsPerSample) { -+ hr = S_FALSE; -+ ext->Samples.wValidBitsPerSample = fmt->wBitsPerSample; -+ } -+ } else if (IsEqualGUID(&ext->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) { -+ if (!fmt->wBitsPerSample || fmt->wBitsPerSample > 32 || fmt->wBitsPerSample % 8) { -+ hr = E_INVALIDARG; -+ break; -+ } ++ TRACE("(%p)->(%p, %p)\n", This, defperiod, minperiod); + -+ if (ext->Samples.wValidBitsPerSample != fmt->wBitsPerSample && -+ !(fmt->wBitsPerSample == 32 && -+ ext->Samples.wValidBitsPerSample == 24)) { -+ hr = S_FALSE; -+ ext->Samples.wValidBitsPerSample = fmt->wBitsPerSample; -+ break; -+ } -+ } else { -+ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; -+ break; -+ } ++ if (!defperiod && !minperiod) ++ return E_POINTER; + -+ break; -+ } -+ -+ case WAVE_FORMAT_ALAW: -+ case WAVE_FORMAT_MULAW: -+ if (fmt->wBitsPerSample != 8) { -+ hr = E_INVALIDARG; -+ break; -+ } -+ /* Fall-through */ -+ case WAVE_FORMAT_IEEE_FLOAT: -+ if (fmt->wFormatTag == WAVE_FORMAT_IEEE_FLOAT && fmt->wBitsPerSample != 32) { -+ hr = E_INVALIDARG; -+ break; -+ } -+ /* Fall-through */ -+ case WAVE_FORMAT_PCM: -+ if (fmt->wFormatTag == WAVE_FORMAT_PCM && -+ (!fmt->wBitsPerSample || fmt->wBitsPerSample > 32 || fmt->wBitsPerSample % 8)) { -+ hr = E_INVALIDARG; -+ break; -+ } -+ -+ if (fmt->nChannels > 2) { -+ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; -+ break; -+ } -+ /* -+ * fmt->cbSize, fmt->nBlockAlign and fmt->nAvgBytesPerSec seem to be -+ * ignored, invalid values are happily accepted. -+ */ -+ break; -+ default: -+ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; -+ break; -+ } -+ -+ if (exclusive && hr != S_OK) { -+ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; -+ CoTaskMemFree(closest); -+ } else if (hr != S_FALSE) -+ CoTaskMemFree(closest); -+ else -+ *out = closest; -+ -+ /* Winepulse does not currently support exclusive mode, if you know of an -+ * application that uses it, I will correct this.. -+ */ -+ if (hr == S_OK && exclusive) -+ return This->dataflow == eCapture ? AUDCLNT_E_UNSUPPORTED_FORMAT : AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED; -+ -+ TRACE("returning: %08x %p\n", hr, out ? *out : NULL); -+ return hr; -+} -+ -+static HRESULT WINAPI AudioClient_GetMixFormat(IAudioClient *iface, -+ WAVEFORMATEX **pwfx) -+{ -+ ACImpl *This = impl_from_IAudioClient(iface); -+ WAVEFORMATEXTENSIBLE *fmt = &pulse_fmt[This->dataflow == eCapture]; -+ -+ TRACE("(%p)->(%p)\n", This, pwfx); -+ -+ if (!pwfx) -+ return E_POINTER; -+ -+ *pwfx = clone_format(&fmt->Format); -+ if (!*pwfx) -+ return E_OUTOFMEMORY; -+ dump_fmt(*pwfx); -+ return S_OK; -+} -+ -+static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient *iface, -+ REFERENCE_TIME *defperiod, REFERENCE_TIME *minperiod) -+{ -+ ACImpl *This = impl_from_IAudioClient(iface); -+ -+ TRACE("(%p)->(%p, %p)\n", This, defperiod, minperiod); -+ -+ if (!defperiod && !minperiod) -+ return E_POINTER; -+ -+ if (defperiod) -+ *defperiod = pulse_def_period[This->dataflow == eCapture]; -+ if (minperiod) -+ *minperiod = pulse_min_period[This->dataflow == eCapture]; ++ if (defperiod) ++ *defperiod = pulse_def_period[This->dataflow == eCapture]; ++ if (minperiod) ++ *minperiod = pulse_min_period[This->dataflow == eCapture]; + + return S_OK; +} @@ -1869,6 +1685,7 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + pthread_mutex_unlock(&pulse_lock); + return AUDCLNT_E_NOT_STOPPED; + } ++ This->clock_pulse = PA_USEC_INVALID; + + if (pa_stream_is_corked(This->stream)) { + o = pa_stream_cork(This->stream, 0, pulse_op_cb, &success); @@ -1924,6 +1741,7 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + } + if (SUCCEEDED(hr)) { + This->started = FALSE; ++ This->clock_pulse = PA_USEC_INVALID; + } + pthread_mutex_unlock(&pulse_lock); + return hr; @@ -2028,34 +1846,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + if (FAILED(hr)) + return hr; + -+ if (IsEqualIID(riid, &IID_IAudioRenderClient)) { -+ if (This->dataflow != eRender) -+ return AUDCLNT_E_WRONG_ENDPOINT_TYPE; -+ *ppv = &This->IAudioRenderClient_iface; -+ } else if (IsEqualIID(riid, &IID_IAudioCaptureClient)) { -+ if (This->dataflow != eCapture) -+ return AUDCLNT_E_WRONG_ENDPOINT_TYPE; -+ *ppv = &This->IAudioCaptureClient_iface; -+ } else if (IsEqualIID(riid, &IID_IAudioClock)) { -+ *ppv = &This->IAudioClock_iface; -+ } else if (IsEqualIID(riid, &IID_IAudioStreamVolume)) { -+ *ppv = &This->IAudioStreamVolume_iface; -+ } else if (IsEqualIID(riid, &IID_IAudioSessionControl) || -+ IsEqualIID(riid, &IID_IChannelAudioVolume) || -+ IsEqualIID(riid, &IID_ISimpleAudioVolume)) { -+ if (!This->session_wrapper) { -+ This->session_wrapper = AudioSessionWrapper_Create(This); -+ if (!This->session_wrapper) -+ return E_OUTOFMEMORY; -+ } -+ if (IsEqualIID(riid, &IID_IAudioSessionControl)) -+ *ppv = &This->session_wrapper->IAudioSessionControl2_iface; -+ else if (IsEqualIID(riid, &IID_IChannelAudioVolume)) -+ *ppv = &This->session_wrapper->IChannelAudioVolume_iface; -+ else if (IsEqualIID(riid, &IID_ISimpleAudioVolume)) -+ *ppv = &This->session_wrapper->ISimpleAudioVolume_iface; -+ } -+ + if (*ppv) { + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; @@ -2084,10 +1874,90 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + AudioClient_GetService +}; + + HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device, + IAudioSessionManager2 **out) + { +-- +1.8.3.1 + + +From 661173dce9c098337555fddb2400c9467b938ae7 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:00 +0200 +Subject: winepulse: Add IAudioRenderClient and IAudioCaptureClient + +--- + dlls/winepulse.drv/mmdevdrv.c | 301 ++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 301 insertions(+) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 37d85ff..01cfd25 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -146,12 +146,27 @@ struct ACImpl { + static const WCHAR defaultW[] = {'P','u','l','s','e','a','u','d','i','o',0}; + + static const IAudioClientVtbl AudioClient_Vtbl; ++static const IAudioRenderClientVtbl AudioRenderClient_Vtbl; ++static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl; ++static const IAudioClockVtbl AudioClock_Vtbl; ++static const IAudioClock2Vtbl AudioClock2_Vtbl; ++static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl; + + static inline ACImpl *impl_from_IAudioClient(IAudioClient *iface) + { + return CONTAINING_RECORD(iface, ACImpl, IAudioClient_iface); + } + ++static inline ACImpl *impl_from_IAudioRenderClient(IAudioRenderClient *iface) ++{ ++ return CONTAINING_RECORD(iface, ACImpl, IAudioRenderClient_iface); ++} ++ ++static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface) ++{ ++ return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface); ++} ++ + /* Following pulseaudio design here, mainloop has the lock taken whenever + * it is handling something for pulse, and the lock is required whenever + * doing any pa_* call that can affect the state in any way +@@ -701,6 +716,11 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(void *key, IMMDevice *dev, + return E_OUTOFMEMORY; + + This->IAudioClient_iface.lpVtbl = &AudioClient_Vtbl; ++ This->IAudioRenderClient_iface.lpVtbl = &AudioRenderClient_Vtbl; ++ This->IAudioCaptureClient_iface.lpVtbl = &AudioCaptureClient_Vtbl; ++ This->IAudioClock_iface.lpVtbl = &AudioClock_Vtbl; ++ This->IAudioClock2_iface.lpVtbl = &AudioClock2_Vtbl; ++ This->IAudioStreamVolume_iface.lpVtbl = &AudioStreamVolume_Vtbl; + This->dataflow = dataflow; + This->parent = dev; + This->clock_pulse = PA_USEC_INVALID; +@@ -1421,6 +1441,16 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient *iface, REFIID riid, + if (FAILED(hr)) + return hr; + ++ if (IsEqualIID(riid, &IID_IAudioRenderClient)) { ++ if (This->dataflow != eRender) ++ return AUDCLNT_E_WRONG_ENDPOINT_TYPE; ++ *ppv = &This->IAudioRenderClient_iface; ++ } else if (IsEqualIID(riid, &IID_IAudioCaptureClient)) { ++ if (This->dataflow != eCapture) ++ return AUDCLNT_E_WRONG_ENDPOINT_TYPE; ++ *ppv = &This->IAudioCaptureClient_iface; ++ } ++ + if (*ppv) { + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; +@@ -1449,6 +1479,277 @@ static const IAudioClientVtbl AudioClient_Vtbl = + AudioClient_GetService + }; + +static HRESULT WINAPI AudioRenderClient_QueryInterface( + IAudioRenderClient *iface, REFIID riid, void **ppv) +{ -+ ACImpl *This = impl_from_IAudioRenderClient(iface); + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + + if (!ppv) @@ -2102,9 +1972,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + return S_OK; + } + -+ if (IsEqualIID(riid, &IID_IMarshal)) -+ return IUnknown_QueryInterface(This->marshal, riid, ppv); -+ + WARN("Unknown interface %s\n", debugstr_guid(riid)); + return E_NOINTERFACE; +} @@ -2125,8 +1992,7 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + UINT32 frames, BYTE **data) +{ + ACImpl *This = impl_from_IAudioRenderClient(iface); -+ size_t avail, req, bytes = frames * pa_frame_size(&This->ss); -+ UINT32 pad; ++ UINT32 avail, pad, req, bytes = frames * pa_frame_size(&This->ss); + HRESULT hr = S_OK; + int ret = -1; + @@ -2151,7 +2017,7 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + avail = This->bufsize_frames - pad; + if (avail < frames || bytes > This->bufsize_bytes) { + pthread_mutex_unlock(&pulse_lock); -+ WARN("Wanted to write %u, but only %zu available\n", frames, avail); ++ WARN("Wanted to write %u, but only %u available\n", frames, avail); + return AUDCLNT_E_BUFFER_TOO_LARGE; + } + @@ -2159,7 +2025,7 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + req = bytes; + ret = pa_stream_begin_write(This->stream, &This->locked_ptr, &req); + if (ret < 0 || req < bytes) { -+ FIXME("%p Not using pulse locked data: %i %zu/%u %u/%u\n", This, ret, req/pa_frame_size(&This->ss), frames, pad, This->bufsize_frames); ++ FIXME("%p Not using pulse locked data: %i %u/%u %u/%u\n", This, ret, req/pa_frame_size(&This->ss), frames, pad, This->bufsize_frames); + if (ret >= 0) + pa_stream_cancel_write(This->stream); + *data = This->tmp_buffer; @@ -2170,16 +2036,11 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + return hr; +} + -+static void pulse_free_noop(void *buf) -+{ -+} -+ +static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( + IAudioRenderClient *iface, UINT32 written_frames, DWORD flags) +{ + ACImpl *This = impl_from_IAudioRenderClient(iface); + UINT32 written_bytes = written_frames * pa_frame_size(&This->ss); -+// UINT32 period; + + TRACE("(%p)->(%u, %x)\n", This, written_frames, flags); + @@ -2209,16 +2070,11 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + if (This->locked_ptr) + pa_stream_write(This->stream, This->locked_ptr, written_bytes, NULL, 0, PA_SEEK_RELATIVE); + else -+ pa_stream_write(This->stream, This->tmp_buffer, written_bytes, pulse_free_noop, 0, PA_SEEK_RELATIVE); ++ pa_stream_write(This->stream, This->tmp_buffer, written_bytes, NULL, 0, PA_SEEK_RELATIVE); + This->pad += written_bytes; + This->locked_ptr = NULL; -+ TRACE("Released %u, pad %zu\n", written_frames, This->pad / pa_frame_size(&This->ss)); ++ TRACE("Released %u, pad %u\n", written_frames, This->pad / pa_frame_size(&This->ss)); + assert(This->pad <= This->bufsize_bytes); -+ -+// period = pa_stream_get_buffer_attr(This->stream)->minreq; -+ /* Require a minimum of 3 periods filled, if possible */ -+// if (This->event && This->pad + period <= This->bufsize_bytes && This->pad < period * 3) -+// SetEvent(This->event); + pthread_mutex_unlock(&pulse_lock); + return S_OK; +} @@ -2234,7 +2090,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w +static HRESULT WINAPI AudioCaptureClient_QueryInterface( + IAudioCaptureClient *iface, REFIID riid, void **ppv) +{ -+ ACImpl *This = impl_from_IAudioCaptureClient(iface); + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + + if (!ppv) @@ -2249,9 +2104,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + return S_OK; + } + -+ if (IsEqualIID(riid, &IID_IMarshal)) -+ return IUnknown_QueryInterface(This->marshal, riid, ppv); -+ + WARN("Unknown interface %s\n", debugstr_guid(riid)); + return E_NOINTERFACE; +} @@ -2352,7 +2204,7 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + TRACE("(%p)->(%p)\n", This, frames); + if (!frames) + return E_POINTER; -+ ++ + pthread_mutex_lock(&pulse_lock); + ACImpl_GetCapturePad(This, NULL); + p = This->locked_ptr; @@ -2374,6 +2226,56 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + AudioCaptureClient_GetNextPacketSize +}; + + HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device, + IAudioSessionManager2 **out) + { +-- +1.8.3.1 + + +From 15c7c6f1934c5b859292ced84a4967df4553a656 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:00 +0200 +Subject: winepulse: Add IAudioClock and IAudioClock2 + +--- + dlls/winepulse.drv/mmdevdrv.c | 172 ++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 172 insertions(+) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 01cfd25..3ed2288 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -167,6 +167,16 @@ static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface) + return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface); + } + ++static inline ACImpl *impl_from_IAudioClock(IAudioClock *iface) ++{ ++ return CONTAINING_RECORD(iface, ACImpl, IAudioClock_iface); ++} ++ ++static inline ACImpl *impl_from_IAudioClock2(IAudioClock2 *iface) ++{ ++ return CONTAINING_RECORD(iface, ACImpl, IAudioClock2_iface); ++} ++ + /* Following pulseaudio design here, mainloop has the lock taken whenever + * it is handling something for pulse, and the lock is required whenever + * doing any pa_* call that can affect the state in any way +@@ -1449,6 +1459,8 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient *iface, REFIID riid, + if (This->dataflow != eCapture) + return AUDCLNT_E_WRONG_ENDPOINT_TYPE; + *ppv = &This->IAudioCaptureClient_iface; ++ } else if (IsEqualIID(riid, &IID_IAudioClock)) { ++ *ppv = &This->IAudioClock_iface; + } + + if (*ppv) { +@@ -1750,6 +1762,166 @@ static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl = + AudioCaptureClient_GetNextPacketSize + }; + +static HRESULT WINAPI AudioClock_QueryInterface(IAudioClock *iface, + REFIID riid, void **ppv) +{ @@ -2394,9 +2296,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + return S_OK; + } + -+ if (IsEqualIID(riid, &IID_IMarshal)) -+ return IUnknown_QueryInterface(This->marshal, riid, ppv); -+ + WARN("Unknown interface %s\n", debugstr_guid(riid)); + return E_NOINTERFACE; +} @@ -2432,6 +2331,7 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + UINT64 *qpctime) +{ + ACImpl *This = impl_from_IAudioClock(iface); ++ pa_usec_t time; + HRESULT hr; + + TRACE("(%p)->(%p, %p)\n", This, pos, qpctime); @@ -2447,7 +2347,14 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + } + + *pos = This->clock_written; -+ ++ if (This->clock_pulse != PA_USEC_INVALID && pa_stream_get_time(This->stream, &time) >= 0) { ++ UINT32 delta = pa_usec_to_bytes(time - This->clock_pulse, &This->ss); ++ if (delta < This->pad) ++ *pos += delta; ++ else ++ *pos += This->pad; ++ } ++ + /* Make time never go backwards */ + if (*pos < This->clock_lastpos) + *pos = This->clock_lastpos; @@ -2529,11 +2436,72 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + AudioClock2_GetDevicePosition +}; + + HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device, + IAudioSessionManager2 **out) + { +-- +1.8.3.1 + + +From 29b389b7073aa9787fe341bae3c420485f3d4146 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse: Add audiostreamvolume + +--- +Pulse allows streams to set volume, but for various reasons it's +better off being disabled by default. + +It can be enabled with HKCU\Software\Wine\Pulse\StreamVol=0x1 +--- + dlls/winepulse.drv/mmdevdrv.c | 236 ++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 236 insertions(+) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 3ed2288..b7414c2 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -177,6 +177,11 @@ static inline ACImpl *impl_from_IAudioClock2(IAudioClock2 *iface) + return CONTAINING_RECORD(iface, ACImpl, IAudioClock2_iface); + } + ++static inline ACImpl *impl_from_IAudioStreamVolume(IAudioStreamVolume *iface) ++{ ++ return CONTAINING_RECORD(iface, ACImpl, IAudioStreamVolume_iface); ++} ++ + /* Following pulseaudio design here, mainloop has the lock taken whenever + * it is handling something for pulse, and the lock is required whenever + * doing any pa_* call that can affect the state in any way +@@ -444,6 +449,12 @@ static void pulse_op_cb(pa_stream *s, int success, void *user) { + pthread_cond_signal(&pulse_cond); + } + ++static void pulse_ctx_op_cb(pa_context *c, int success, void *user) { ++ TRACE("Success: %i\n", success); ++ *(int*)user = success; ++ pthread_cond_signal(&pulse_cond); ++} ++ + static void pulse_attr_update(pa_stream *s, void *user) { + const pa_buffer_attr *attr = pa_stream_get_buffer_attr(s); + TRACE("New attributes or device moved:\n"); +@@ -1461,6 +1472,8 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient *iface, REFIID riid, + *ppv = &This->IAudioCaptureClient_iface; + } else if (IsEqualIID(riid, &IID_IAudioClock)) { + *ppv = &This->IAudioClock_iface; ++ } else if (IsEqualIID(riid, &IID_IAudioStreamVolume)) { ++ *ppv = &This->IAudioStreamVolume_iface; + } + + if (*ppv) { +@@ -1922,6 +1935,229 @@ static const IAudioClock2Vtbl AudioClock2_Vtbl = + AudioClock2_GetDevicePosition + }; + +static HRESULT WINAPI AudioStreamVolume_QueryInterface( + IAudioStreamVolume *iface, REFIID riid, void **ppv) +{ -+ ACImpl *This = impl_from_IAudioStreamVolume(iface); -+ + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + + if (!ppv) @@ -2548,9 +2516,6 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + return S_OK; + } + -+ if (IsEqualIID(riid, &IID_IMarshal)) -+ return IUnknown_QueryInterface(This->marshal, riid, ppv); -+ + WARN("Unknown interface %s\n", debugstr_guid(riid)); + return E_NOINTERFACE; +} @@ -2757,32 +2722,263 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + AudioStreamVolume_GetAllVolumes +}; + -+static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client) -+{ -+ AudioSessionWrapper *ret; + HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device, + IAudioSessionManager2 **out) + { +-- +1.8.3.1 + + +From f27ca64fa41672126627e3bd51002d89467f362a Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse: Add session support + +--- +Copied verbatim from winealsa +--- + dlls/winepulse.drv/mmdevdrv.c | 849 +++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 848 insertions(+), 1 deletion(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index b7414c2..64ee62e 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -69,6 +69,7 @@ static pa_mainloop *pulse_ml; + static HANDLE pulse_thread; + static pthread_mutex_t pulse_lock = PTHREAD_MUTEX_INITIALIZER; + static pthread_cond_t pulse_cond = PTHREAD_COND_INITIALIZER; ++static struct list g_sessions = LIST_INIT(g_sessions); + + /* Mixer format + period times */ + static WAVEFORMATEXTENSIBLE pulse_fmt[2]; +@@ -105,6 +106,31 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) + + typedef struct ACImpl ACImpl; + ++typedef struct _AudioSession { ++ GUID guid; ++ struct list clients; + -+ ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, -+ sizeof(AudioSessionWrapper)); -+ if (!ret) -+ return NULL; ++ IMMDevice *device; + -+ ret->IAudioSessionControl2_iface.lpVtbl = &AudioSessionControl2_Vtbl; -+ ret->ISimpleAudioVolume_iface.lpVtbl = &SimpleAudioVolume_Vtbl; -+ ret->IChannelAudioVolume_iface.lpVtbl = &ChannelAudioVolume_Vtbl; ++ float master_vol; ++ UINT32 channel_count; ++ float *channel_vols; ++ BOOL mute; + -+ ret->ref = !client; ++ struct list entry; ++} AudioSession; + -+ ret->client = client; -+ if (client) { -+ ret->session = client->session; -+ AudioClient_AddRef(&client->IAudioClient_iface); -+ } ++typedef struct _AudioSessionWrapper { ++ IAudioSessionControl2 IAudioSessionControl2_iface; ++ IChannelAudioVolume IChannelAudioVolume_iface; ++ ISimpleAudioVolume ISimpleAudioVolume_iface; + -+ return ret; -+} ++ LONG ref; + -+static HRESULT WINAPI AudioSessionControl_QueryInterface( -+ IAudioSessionControl2 *iface, REFIID riid, void **ppv) ++ ACImpl *client; ++ AudioSession *session; ++} AudioSessionWrapper; ++ + typedef struct _ACPacket { + struct list entry; + UINT64 qpcpos; +@@ -139,6 +165,8 @@ struct ACImpl { + INT64 clock_lastpos, clock_written; + pa_usec_t clock_pulse; + ++ AudioSession *session; ++ AudioSessionWrapper *session_wrapper; + struct list packet_free_head; + struct list packet_filled_head; + }; +@@ -148,10 +176,15 @@ static const WCHAR defaultW[] = {'P','u','l','s','e','a','u','d','i','o',0}; + static const IAudioClientVtbl AudioClient_Vtbl; + static const IAudioRenderClientVtbl AudioRenderClient_Vtbl; + static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl; ++static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; ++static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl; ++static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl; + static const IAudioClockVtbl AudioClock_Vtbl; + static const IAudioClock2Vtbl AudioClock2_Vtbl; + static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl; + ++static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client); ++ + static inline ACImpl *impl_from_IAudioClient(IAudioClient *iface) + { + return CONTAINING_RECORD(iface, ACImpl, IAudioClient_iface); +@@ -167,6 +200,21 @@ static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface) + return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface); + } + ++static inline AudioSessionWrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface) ++{ ++ return CONTAINING_RECORD(iface, AudioSessionWrapper, IAudioSessionControl2_iface); ++} ++ ++static inline AudioSessionWrapper *impl_from_ISimpleAudioVolume(ISimpleAudioVolume *iface) ++{ ++ return CONTAINING_RECORD(iface, AudioSessionWrapper, ISimpleAudioVolume_iface); ++} ++ ++static inline AudioSessionWrapper *impl_from_IChannelAudioVolume(IChannelAudioVolume *iface) ++{ ++ return CONTAINING_RECORD(iface, AudioSessionWrapper, IChannelAudioVolume_iface); ++} ++ + static inline ACImpl *impl_from_IAudioClock(IAudioClock *iface) + { + return CONTAINING_RECORD(iface, ACImpl, IAudioClock_iface); +@@ -897,6 +945,85 @@ static DWORD get_channel_mask(unsigned int channels) + return 0; + } + ++static void session_init_vols(AudioSession *session, UINT channels) ++{ ++ if (session->channel_count < channels) { ++ UINT i; ++ ++ if (session->channel_vols) ++ session->channel_vols = HeapReAlloc(GetProcessHeap(), 0, ++ session->channel_vols, sizeof(float) * channels); ++ else ++ session->channel_vols = HeapAlloc(GetProcessHeap(), 0, ++ sizeof(float) * channels); ++ if (!session->channel_vols) ++ return; ++ ++ for(i = session->channel_count; i < channels; ++i) ++ session->channel_vols[i] = 1.f; ++ ++ session->channel_count = channels; ++ } ++} ++ ++static AudioSession *create_session(const GUID *guid, IMMDevice *device, ++ UINT num_channels) ++{ ++ AudioSession *ret; ++ ++ ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AudioSession)); ++ if (!ret) ++ return NULL; ++ ++ memcpy(&ret->guid, guid, sizeof(GUID)); ++ ++ ret->device = device; ++ ++ list_init(&ret->clients); ++ ++ list_add_head(&g_sessions, &ret->entry); ++ ++ session_init_vols(ret, num_channels); ++ ++ ret->master_vol = 1.f; ++ ++ return ret; ++} ++ ++/* if channels == 0, then this will return or create a session with ++ * matching dataflow and GUID. otherwise, channels must also match */ ++static HRESULT get_audio_session(const GUID *sessionguid, ++ IMMDevice *device, UINT channels, AudioSession **out) ++{ ++ AudioSession *session; ++ ++ if (!sessionguid || IsEqualGUID(sessionguid, &GUID_NULL)) { ++ *out = create_session(&GUID_NULL, device, channels); ++ if (!*out) ++ return E_OUTOFMEMORY; ++ ++ return S_OK; ++ } ++ ++ *out = NULL; ++ LIST_FOR_EACH_ENTRY(session, &g_sessions, AudioSession, entry) { ++ if (session->device == device && ++ IsEqualGUID(sessionguid, &session->guid)) { ++ session_init_vols(session, channels); ++ *out = session; ++ break; ++ } ++ } ++ ++ if (!*out) { ++ *out = create_session(sessionguid, device, channels); ++ if (!*out) ++ return E_OUTOFMEMORY; ++ } ++ ++ return S_OK; ++} ++ + static HRESULT pulse_spec_from_waveformat(ACImpl *This, const WAVEFORMATEX *fmt) + { + pa_channel_map_init(&This->map); +@@ -1083,6 +1210,10 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient *iface, + assert(!capture_packets || data - This->bufsize_bytes == This->tmp_buffer); + } + } ++ if (SUCCEEDED(hr)) ++ hr = get_audio_session(sessionguid, This->parent, fmt->nChannels, &This->session); ++ if (SUCCEEDED(hr)) ++ list_add_tail(&This->session->clients, &This->entry); + + exit: + if (FAILED(hr)) { +@@ -1474,6 +1605,20 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient *iface, REFIID riid, + *ppv = &This->IAudioClock_iface; + } else if (IsEqualIID(riid, &IID_IAudioStreamVolume)) { + *ppv = &This->IAudioStreamVolume_iface; ++ } else if (IsEqualIID(riid, &IID_IAudioSessionControl) || ++ IsEqualIID(riid, &IID_IChannelAudioVolume) || ++ IsEqualIID(riid, &IID_ISimpleAudioVolume)) { ++ if (!This->session_wrapper) { ++ This->session_wrapper = AudioSessionWrapper_Create(This); ++ if (!This->session_wrapper) ++ return E_OUTOFMEMORY; ++ } ++ if (IsEqualIID(riid, &IID_IAudioSessionControl)) ++ *ppv = &This->session_wrapper->IAudioSessionControl2_iface; ++ else if (IsEqualIID(riid, &IID_IChannelAudioVolume)) ++ *ppv = &This->session_wrapper->IChannelAudioVolume_iface; ++ else if (IsEqualIID(riid, &IID_ISimpleAudioVolume)) ++ *ppv = &This->session_wrapper->ISimpleAudioVolume_iface; + } + + if (*ppv) { +@@ -2158,9 +2303,711 @@ static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl = + AudioStreamVolume_GetAllVolumes + }; + ++static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client) ++{ ++ AudioSessionWrapper *ret; ++ ++ ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ++ sizeof(AudioSessionWrapper)); ++ if (!ret) ++ return NULL; ++ ++ ret->IAudioSessionControl2_iface.lpVtbl = &AudioSessionControl2_Vtbl; ++ ret->ISimpleAudioVolume_iface.lpVtbl = &SimpleAudioVolume_Vtbl; ++ ret->IChannelAudioVolume_iface.lpVtbl = &ChannelAudioVolume_Vtbl; ++ ++ ret->ref = !client; ++ ++ ret->client = client; ++ if (client) { ++ ret->session = client->session; ++ AudioClient_AddRef(&client->IAudioClient_iface); ++ } ++ ++ return ret; ++} ++ ++static HRESULT WINAPI AudioSessionControl_QueryInterface( ++ IAudioSessionControl2 *iface, REFIID riid, void **ppv) +{ + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + @@ -3353,124 +3549,1698 @@ diff -uhNr wine-1.7.0/dlls/winepulse.drv/mmdevdrv.c wine-1.7.0-multimedia/dlls/w + TRACE("(%p)->(%d, %f, %s)\n", session, index, level, + wine_dbgstr_guid(context)); + -+ if (level < 0.f || level > 1.f) -+ return E_INVALIDARG; ++ if (level < 0.f || level > 1.f) ++ return E_INVALIDARG; ++ ++ if (index >= session->channel_count) ++ return E_INVALIDARG; ++ ++ if (context) ++ FIXME("Notifications not supported yet\n"); ++ ++ TRACE("Pulseaudio does not support session volume control\n"); ++ ++ pthread_mutex_lock(&pulse_lock); ++ session->channel_vols[index] = level; ++ pthread_mutex_unlock(&pulse_lock); ++ ++ return S_OK; ++} ++ ++static HRESULT WINAPI ChannelAudioVolume_GetChannelVolume( ++ IChannelAudioVolume *iface, UINT32 index, float *level) ++{ ++ AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); ++ AudioSession *session = This->session; ++ ++ TRACE("(%p)->(%d, %p)\n", session, index, level); ++ ++ if (!level) ++ return NULL_PTR_ERR; ++ ++ if (index >= session->channel_count) ++ return E_INVALIDARG; ++ ++ *level = session->channel_vols[index]; ++ ++ return S_OK; ++} ++ ++static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes( ++ IChannelAudioVolume *iface, UINT32 count, const float *levels, ++ const GUID *context) ++{ ++ AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); ++ AudioSession *session = This->session; ++ int i; ++ ++ TRACE("(%p)->(%d, %p, %s)\n", session, count, levels, ++ wine_dbgstr_guid(context)); ++ ++ if (!levels) ++ return NULL_PTR_ERR; ++ ++ if (count != session->channel_count) ++ return E_INVALIDARG; ++ ++ if (context) ++ FIXME("Notifications not supported yet\n"); ++ ++ TRACE("Pulseaudio does not support session volume control\n"); ++ ++ pthread_mutex_lock(&pulse_lock); ++ for(i = 0; i < count; ++i) ++ session->channel_vols[i] = levels[i]; ++ pthread_mutex_unlock(&pulse_lock); ++ return S_OK; ++} ++ ++static HRESULT WINAPI ChannelAudioVolume_GetAllVolumes( ++ IChannelAudioVolume *iface, UINT32 count, float *levels) ++{ ++ AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); ++ AudioSession *session = This->session; ++ int i; ++ ++ TRACE("(%p)->(%d, %p)\n", session, count, levels); ++ ++ if (!levels) ++ return NULL_PTR_ERR; ++ ++ if (count != session->channel_count) ++ return E_INVALIDARG; ++ ++ for(i = 0; i < count; ++i) ++ levels[i] = session->channel_vols[i]; ++ ++ return S_OK; ++} ++ ++static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl = ++{ ++ ChannelAudioVolume_QueryInterface, ++ ChannelAudioVolume_AddRef, ++ ChannelAudioVolume_Release, ++ ChannelAudioVolume_GetChannelCount, ++ ChannelAudioVolume_SetChannelVolume, ++ ChannelAudioVolume_GetChannelVolume, ++ ChannelAudioVolume_SetAllVolumes, ++ ChannelAudioVolume_GetAllVolumes ++}; ++ + HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device, + IAudioSessionManager2 **out) + { ++ SessionMgr *This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SessionMgr)); + *out = NULL; +- return E_NOTIMPL; ++ if (!This) ++ return E_OUTOFMEMORY; ++ This->IAudioSessionManager2_iface.lpVtbl = &AudioSessionManager2_Vtbl; ++ This->device = device; ++ This->ref = 1; ++ *out = &This->IAudioSessionManager2_iface; ++ return S_OK; + } +-- +1.8.3.1 + + +From 707d4aeae111fa01b393333bca419311e5e5ce36 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: fix fdels trailing whitespaces + +Happy? :P +--- + dlls/winepulse.drv/mmdevdrv.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 64ee62e..5a71a3d 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -1898,7 +1898,7 @@ static HRESULT WINAPI AudioCaptureClient_GetNextPacketSize( + TRACE("(%p)->(%p)\n", This, frames); + if (!frames) + return E_POINTER; +- ++ + pthread_mutex_lock(&pulse_lock); + ACImpl_GetCapturePad(This, NULL); + p = This->locked_ptr; +@@ -1998,7 +1998,7 @@ static HRESULT WINAPI AudioClock_GetPosition(IAudioClock *iface, UINT64 *pos, + else + *pos += This->pad; + } +- ++ + /* Make time never go backwards */ + if (*pos < This->clock_lastpos) + *pos = This->clock_lastpos; +-- +1.8.3.1 + + +From 1651eaf16902a65aaaab0145f91c6b88c4e17c56 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse v12 + +Changes since v11: +- Fix incorrect assertions which may fail on moving a capture device +- Whitespace apply fixes + +Changes since v10: +- Make some members static +- Fix small memory leak in GetService +--- + dlls/winepulse.drv/mmdevdrv.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 5a71a3d..960af3c 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -596,10 +596,11 @@ static void pulse_rd_loop(ACImpl *This, size_t bytes) + dst = p->data; + while (rem) { + pa_stream_peek(This->stream, (const void**)&src, &src_len); +- assert(src_len && src_len <= bytes); ++ assert(src_len); + assert(This->peek_ofs < src_len); + src += This->peek_ofs; + src_len -= This->peek_ofs; ++ assert(src_len <= bytes); + + copy = rem; + if (copy > src_len) +@@ -627,9 +628,10 @@ static void pulse_rd_drop(ACImpl *This, size_t bytes) + while (rem) { + const void *src; + pa_stream_peek(This->stream, &src, &src_len); +- assert(src_len && src_len <= bytes); ++ assert(src_len); + assert(This->peek_ofs < src_len); + src_len -= This->peek_ofs; ++ assert(src_len <= bytes); + + copy = rem; + if (copy > src_len) +-- +1.8.3.1 + + +From ed285cd6a055b9f2d063810e2621669c36d95340 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse v15: Add support for missing formats, and silence an error + for missing format tags + +--- + dlls/winepulse.drv/mmdevdrv.c | 17 ++++++++++++++++- + 1 file changed, 16 insertions(+), 1 deletion(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 960af3c..f52f119 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -1109,7 +1109,22 @@ static HRESULT pulse_spec_from_waveformat(ACImpl *This, const WAVEFORMATEX *fmt) + } + break; + } +- default: FIXME("Unhandled tag %x\n", fmt->wFormatTag); ++ case WAVE_FORMAT_ALAW: ++ case WAVE_FORMAT_MULAW: ++ if (fmt->wBitsPerSample != 8) { ++ FIXME("Unsupported bpp %u for LAW\n", fmt->wBitsPerSample); ++ return AUDCLNT_E_UNSUPPORTED_FORMAT; ++ } ++ if (fmt->nChannels != 1 && fmt->nChannels != 2) { ++ FIXME("Unsupported channels %u for LAW\n", fmt->nChannels); ++ return AUDCLNT_E_UNSUPPORTED_FORMAT; ++ } ++ This->ss.format = fmt->wFormatTag == WAVE_FORMAT_MULAW ? PA_SAMPLE_ULAW : PA_SAMPLE_ALAW; ++ pa_channel_map_init_auto(&This->map, fmt->nChannels, PA_CHANNEL_MAP_ALSA); ++ break; ++ default: ++ WARN("Unhandled tag %x\n", fmt->wFormatTag); ++ return AUDCLNT_E_UNSUPPORTED_FORMAT; + } + This->ss.channels = This->map.channels; + if (!pa_channel_map_valid(&This->map) || This->ss.format == PA_SAMPLE_INVALID) { +-- +1.8.3.1 + + +From c5243abaaa882c77e681104c414254c4641b3b3b Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse v16: Add official warning wine doesn't want to support + winepulse + +And give an alternative place to ask for support. +I wish it didn't have to come to this. +--- + dlls/winepulse.drv/mmdevdrv.c | 25 +++++++++++++++++++++++-- + 1 file changed, 23 insertions(+), 2 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index f52f119..76a2e0e 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -59,6 +59,7 @@ + #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER) + + WINE_DEFAULT_DEBUG_CHANNEL(pulse); ++WINE_DECLARE_DEBUG_CHANNEL(winediag); + + static const REFERENCE_TIME MinimumPeriod = 30000; + static const REFERENCE_TIME DefaultPeriod = 100000; +@@ -81,6 +82,8 @@ const WCHAR pulse_keyW[] = {'S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','P','u','l','s','e',0}; + const WCHAR pulse_streamW[] = { 'S','t','r','e','a','m','V','o','l',0 }; + ++static HANDLE warn_once; ++ + BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) + { + if (reason == DLL_PROCESS_ATTACH) { +@@ -99,7 +102,10 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) + } + if (pulse_ml) + pa_mainloop_quit(pulse_ml, 0); +- CloseHandle(pulse_thread); ++ if (pulse_thread) ++ CloseHandle(pulse_thread); ++ if (warn_once) ++ CloseHandle(warn_once); + } + return TRUE; + } +@@ -758,6 +764,10 @@ HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, void ***keys, + int WINAPI AUDDRV_GetPriority(void) + { + HRESULT hr; ++ if (getenv("WINENOPULSE")) { ++ FIXME_(winediag)("winepulse has been temporarily disabled through the environment\n"); ++ return 0; ++ } + pthread_mutex_lock(&pulse_lock); + hr = pulse_connect(); + pthread_mutex_unlock(&pulse_lock); +@@ -771,7 +781,18 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(void *key, IMMDevice *dev, + ACImpl *This; + int i; + +- TRACE("%p %p %d %p\n", key, dev, dataflow, out); ++ /* Give one visible warning per session ++ * Sadly wine has chosen not to accept the winepulse patch, so support ourselves ++ */ ++ if (!warn_once && (warn_once = CreateEventA(0, 0, 0, "__winepulse_warn_event")) && GetLastError() != ERROR_ALREADY_EXISTS) { ++ FIXME_(winediag)("Winepulse is not officially supported by the wine project\n"); ++ FIXME_(winediag)("For sound related feedback and support, please visit http://ubuntuforums.org/showthread.php?t=1960599\n"); ++ } else { ++ WARN_(winediag)("Winepulse is not officially supported by the wine project\n"); ++ WARN_(winediag)("For sound related feedback and support, please visit http://ubuntuforums.org/showthread.php?t=1960599\n"); ++ } ++ ++ TRACE("%s %p %p\n", debugstr_guid(guid), dev, out); + if (dataflow != eRender && dataflow != eCapture) + return E_UNEXPECTED; + +-- +1.8.3.1 + + +From a5cebf016e4ff02b9f18586432351c4af690e7f1 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse v17: Fix winmm tests + +Handle dwChannelMask = SPEAKER_ALL better so WAVE_FORMAT_EXTENSIBLE tests pass too +--- + dlls/winepulse.drv/mmdevdrv.c | 72 +++++++++++++++++++++++++++++++++---------- + 1 file changed, 56 insertions(+), 16 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 76a2e0e..6e75674 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -1066,6 +1066,8 @@ static HRESULT pulse_spec_from_waveformat(ACImpl *This, const WAVEFORMATEX *fmt) + This->ss.format = PA_SAMPLE_U8; + else if (fmt->wBitsPerSample == 16) + This->ss.format = PA_SAMPLE_S16LE; ++ else ++ return AUDCLNT_E_UNSUPPORTED_FORMAT; + pa_channel_map_init_auto(&This->map, fmt->nChannels, PA_CHANNEL_MAP_ALSA); + break; + case WAVE_FORMAT_EXTENSIBLE: { +@@ -1102,13 +1104,16 @@ static HRESULT pulse_spec_from_waveformat(ACImpl *This, const WAVEFORMATEX *fmt) + This->ss.format = PA_SAMPLE_S24_32LE; + else if (valid == 32) + This->ss.format = PA_SAMPLE_S32LE; +- default: + break; ++ default: ++ return AUDCLNT_E_UNSUPPORTED_FORMAT; + } + } + This->map.channels = fmt->nChannels; +- if (!mask) ++ if (!mask || mask == SPEAKER_ALL) + mask = get_channel_mask(fmt->nChannels); ++ else if (mask == ~0U && fmt->nChannels == 1) ++ mask = SPEAKER_FRONT_CENTER; + for (j = 0; j < sizeof(pulse_pos_from_wfx)/sizeof(*pulse_pos_from_wfx) && i < fmt->nChannels; ++j) { + if (mask & (1 << j)) + This->map.map[i++] = pulse_pos_from_wfx[j]; +@@ -1118,14 +1123,9 @@ static HRESULT pulse_spec_from_waveformat(ACImpl *This, const WAVEFORMATEX *fmt) + if (mask == SPEAKER_FRONT_CENTER) + This->map.map[0] = PA_CHANNEL_POSITION_MONO; + +- if ((mask & SPEAKER_ALL) && i < fmt->nChannels) { +- This->map.map[i++] = PA_CHANNEL_POSITION_MONO; +- FIXME("Is the 'all' channel mapped correctly?\n"); +- } +- + if (i < fmt->nChannels || (mask & SPEAKER_RESERVED)) { + This->map.channels = 0; +- ERR("Invalid channel mask: %i/%i and %x\n", i, fmt->nChannels, mask); ++ ERR("Invalid channel mask: %i/%i and %x(%x)\n", i, fmt->nChannels, mask, wfe->dwChannelMask); + break; + } + break; +@@ -1383,15 +1383,55 @@ static HRESULT WINAPI AudioClient_IsFormatSupported(IAudioClient *iface, + return E_INVALIDARG; + if (mode == AUDCLNT_SHAREMODE_EXCLUSIVE) + return This->dataflow == eCapture ? AUDCLNT_E_UNSUPPORTED_FORMAT : AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED; +- if (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE && +- fmt->cbSize < sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)) +- return E_INVALIDARG; +- +- dump_fmt(fmt); +- ++ switch (fmt->wFormatTag) { ++ case WAVE_FORMAT_EXTENSIBLE: ++ if (fmt->cbSize < sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)) ++ return E_INVALIDARG; ++ dump_fmt(fmt); ++ break; ++ case WAVE_FORMAT_ALAW: ++ case WAVE_FORMAT_MULAW: ++ case WAVE_FORMAT_IEEE_FLOAT: ++ case WAVE_FORMAT_PCM: ++ dump_fmt(fmt); ++ break; ++ default: ++ dump_fmt(fmt); ++ return AUDCLNT_E_UNSUPPORTED_FORMAT; ++ } ++ if (fmt->nChannels == 0) ++ return AUDCLNT_E_UNSUPPORTED_FORMAT; + closest = clone_format(fmt); +- if (!closest) +- hr = E_OUTOFMEMORY; ++ if (!closest) { ++ if (out) ++ *out = NULL; ++ return E_OUTOFMEMORY; ++ } ++ ++ if (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE) { ++ UINT32 mask = 0, i, channels = 0; ++ WAVEFORMATEXTENSIBLE *ext = (WAVEFORMATEXTENSIBLE*)closest; ++ ++ if ((fmt->nChannels > 1 && ext->dwChannelMask == SPEAKER_ALL) || ++ (fmt->nChannels == 1 && ext->dwChannelMask == ~0U)) { ++ mask = ext->dwChannelMask; ++ channels = fmt->nChannels; ++ } else if (ext->dwChannelMask) { ++ for (i = 1; !(i & SPEAKER_RESERVED); i <<= 1) { ++ if (i & ext->dwChannelMask) { ++ mask |= i; ++ channels++; ++ } ++ } ++ if (channels < fmt->nChannels) ++ mask = get_channel_mask(fmt->nChannels); ++ } else ++ mask = ext->dwChannelMask; ++ if (ext->dwChannelMask != mask) { ++ ext->dwChannelMask = mask; ++ hr = S_FALSE; ++ } ++ } + + if (hr == S_OK || !out) { + CoTaskMemFree(closest); +-- +1.8.3.1 + + +From e8d2b8cd838e449d210e9b61c63d280d936a7314 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse v18: Latency and compilation improvements + +Changes since v17: +- Remove clock_pulse interpolation + * Couldn't work, sadly +- Allow 2 * MinimumPeriod for shared buffers +- Fix all compiler warnings when compiling with 64-bits +- Dynamically select low latency mode if less than 2 default periods are request + * This requires the rtkit patch to be useful +--- + dlls/winepulse.drv/mmdevdrv.c | 55 +++++++++++++++++-------------------------- + 1 file changed, 22 insertions(+), 33 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 6e75674..8e76826 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -169,7 +169,6 @@ struct ACImpl { + pa_channel_map map; + + INT64 clock_lastpos, clock_written; +- pa_usec_t clock_pulse; + + AudioSession *session; + AudioSessionWrapper *session_wrapper; +@@ -518,7 +517,6 @@ static void pulse_attr_update(pa_stream *s, void *user) { + static void pulse_wr_callback(pa_stream *s, size_t bytes, void *userdata) + { + ACImpl *This = userdata; +- pa_usec_t time; + UINT32 oldpad = This->pad; + + if (bytes < This->bufsize_bytes) +@@ -528,13 +526,8 @@ static void pulse_wr_callback(pa_stream *s, size_t bytes, void *userdata) + + assert(oldpad >= This->pad); + +- if (0 && This->pad && pa_stream_get_time(This->stream, &time) >= 0) +- This->clock_pulse = time; +- else +- This->clock_pulse = PA_USEC_INVALID; +- + This->clock_written += oldpad - This->pad; +- TRACE("New pad: %u (-%u)\n", This->pad / pa_frame_size(&This->ss), (oldpad - This->pad) / pa_frame_size(&This->ss)); ++ TRACE("New pad: %zu (-%zu)\n", This->pad / pa_frame_size(&This->ss), (oldpad - This->pad) / pa_frame_size(&This->ss)); + + if (This->event) + SetEvent(This->event); +@@ -542,8 +535,6 @@ static void pulse_wr_callback(pa_stream *s, size_t bytes, void *userdata) + + static void pulse_underflow_callback(pa_stream *s, void *userdata) + { +- ACImpl *This = userdata; +- This->clock_pulse = PA_USEC_INVALID; + WARN("Underflow\n"); + } + +@@ -562,12 +553,8 @@ static void pulse_latency_callback(pa_stream *s, void *userdata) + static void pulse_started_callback(pa_stream *s, void *userdata) + { + ACImpl *This = userdata; +- pa_usec_t time; + + TRACE("(Re)started playing\n"); +- assert(This->clock_pulse == PA_USEC_INVALID); +- if (0 && pa_stream_get_time(This->stream, &time) >= 0) +- This->clock_pulse = time; + if (This->event) + SetEvent(This->event); + } +@@ -578,7 +565,7 @@ static void pulse_rd_loop(ACImpl *This, size_t bytes) + ACPacket *p, *next; + LARGE_INTEGER stamp, freq; + BYTE *dst, *src; +- UINT32 src_len, copy, rem = This->capture_period; ++ size_t src_len, copy, rem = This->capture_period; + if (!(p = (ACPacket*)list_head(&This->packet_free_head))) { + p = (ACPacket*)list_head(&This->packet_filled_head); + if (!p->discont) { +@@ -630,7 +617,7 @@ static void pulse_rd_loop(ACImpl *This, size_t bytes) + static void pulse_rd_drop(ACImpl *This, size_t bytes) + { + while (bytes >= This->capture_period) { +- UINT32 src_len, copy, rem = This->capture_period; ++ size_t src_len, copy, rem = This->capture_period; + while (rem) { + const void *src; + pa_stream_peek(This->stream, &src, &src_len); +@@ -660,7 +647,7 @@ static void pulse_rd_callback(pa_stream *s, size_t bytes, void *userdata) + { + ACImpl *This = userdata; + +- TRACE("Readable total: %u, fragsize: %u\n", bytes, pa_stream_get_buffer_attr(s)->fragsize); ++ TRACE("Readable total: %zu, fragsize: %u\n", bytes, pa_stream_get_buffer_attr(s)->fragsize); + assert(bytes >= This->peek_ofs); + bytes -= This->peek_ofs; + if (bytes < This->capture_period) +@@ -815,7 +802,6 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(void *key, IMMDevice *dev, + This->IAudioStreamVolume_iface.lpVtbl = &AudioStreamVolume_Vtbl; + This->dataflow = dataflow; + This->parent = dev; +- This->clock_pulse = PA_USEC_INVALID; + for (i = 0; i < PA_CHANNELS_MAX; ++i) + This->vol[i] = 1.f; + IMMDevice_AddRef(This->parent); +@@ -1199,7 +1185,19 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient *iface, + goto exit; + + if (mode == AUDCLNT_SHAREMODE_SHARED) { +- period = pulse_def_period[This->dataflow == eCapture]; ++ REFERENCE_TIME def = pulse_def_period[This->dataflow == eCapture]; ++ REFERENCE_TIME min = pulse_min_period[This->dataflow == eCapture]; ++ ++ /* Switch to low latency mode if below 2 default periods, ++ * which is 20 ms by default, this will increase the amount ++ * of interrupts but allows very low latency. In dsound I ++ * managed to get a total latency of ~8ms, which is well below ++ * default ++ */ ++ if (duration < 2 * def) ++ period = min; ++ else ++ period = def; + if (duration < 2 * period) + duration = 2 * period; + } +@@ -1510,7 +1508,6 @@ static HRESULT WINAPI AudioClient_Start(IAudioClient *iface) + pthread_mutex_unlock(&pulse_lock); + return AUDCLNT_E_NOT_STOPPED; + } +- This->clock_pulse = PA_USEC_INVALID; + + if (pa_stream_is_corked(This->stream)) { + o = pa_stream_cork(This->stream, 0, pulse_op_cb, &success); +@@ -1566,7 +1563,6 @@ static HRESULT WINAPI AudioClient_Stop(IAudioClient *iface) + } + if (SUCCEEDED(hr)) { + This->started = FALSE; +- This->clock_pulse = PA_USEC_INVALID; + } + pthread_mutex_unlock(&pulse_lock); + return hr; +@@ -1764,7 +1760,8 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, + UINT32 frames, BYTE **data) + { + ACImpl *This = impl_from_IAudioRenderClient(iface); +- UINT32 avail, pad, req, bytes = frames * pa_frame_size(&This->ss); ++ size_t avail, req, bytes = frames * pa_frame_size(&This->ss); ++ UINT32 pad; + HRESULT hr = S_OK; + int ret = -1; + +@@ -1789,7 +1786,7 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, + avail = This->bufsize_frames - pad; + if (avail < frames || bytes > This->bufsize_bytes) { + pthread_mutex_unlock(&pulse_lock); +- WARN("Wanted to write %u, but only %u available\n", frames, avail); ++ WARN("Wanted to write %u, but only %zu available\n", frames, avail); + return AUDCLNT_E_BUFFER_TOO_LARGE; + } + +@@ -1797,7 +1794,7 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, + req = bytes; + ret = pa_stream_begin_write(This->stream, &This->locked_ptr, &req); + if (ret < 0 || req < bytes) { +- FIXME("%p Not using pulse locked data: %i %u/%u %u/%u\n", This, ret, req/pa_frame_size(&This->ss), frames, pad, This->bufsize_frames); ++ FIXME("%p Not using pulse locked data: %i %zu/%u %u/%u\n", This, ret, req/pa_frame_size(&This->ss), frames, pad, This->bufsize_frames); + if (ret >= 0) + pa_stream_cancel_write(This->stream); + *data = This->tmp_buffer; +@@ -1845,7 +1842,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( + pa_stream_write(This->stream, This->tmp_buffer, written_bytes, NULL, 0, PA_SEEK_RELATIVE); + This->pad += written_bytes; + This->locked_ptr = NULL; +- TRACE("Released %u, pad %u\n", written_frames, This->pad / pa_frame_size(&This->ss)); ++ TRACE("Released %u, pad %zu\n", written_frames, This->pad / pa_frame_size(&This->ss)); + assert(This->pad <= This->bufsize_bytes); + pthread_mutex_unlock(&pulse_lock); + return S_OK; +@@ -2053,7 +2050,6 @@ static HRESULT WINAPI AudioClock_GetPosition(IAudioClock *iface, UINT64 *pos, + UINT64 *qpctime) + { + ACImpl *This = impl_from_IAudioClock(iface); +- pa_usec_t time; + HRESULT hr; + + TRACE("(%p)->(%p, %p)\n", This, pos, qpctime); +@@ -2069,13 +2065,6 @@ static HRESULT WINAPI AudioClock_GetPosition(IAudioClock *iface, UINT64 *pos, + } + + *pos = This->clock_written; +- if (This->clock_pulse != PA_USEC_INVALID && pa_stream_get_time(This->stream, &time) >= 0) { +- UINT32 delta = pa_usec_to_bytes(time - This->clock_pulse, &This->ss); +- if (delta < This->pad) +- *pos += delta; +- else +- *pos += This->pad; +- } + + /* Make time never go backwards */ + if (*pos < This->clock_lastpos) +-- +1.8.3.1 + + +From 4d4c24badcf4e9d985366eea3785a401c564a6b3 Mon Sep 17 00:00:00 2001 +From: Juergen Tretthahn +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse: API Compatibility with 1.5.2 onward, v2 + +V2: Add winepulse.drv.spec to commit too +V1: Original version + +Commit e87cb774d131963d2642d075977571585ec5da8d changed the driver api +leave this commit out to build for builds prior to this + +Not needed for: 1.5.1, 1.5 and 1.4 builds +--- + dlls/winepulse.drv/mmdevdrv.c | 34 ++++++++++++++++++++++------------ + dlls/winepulse.drv/winepulse.drv.spec | 2 +- + 2 files changed, 23 insertions(+), 13 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 8e76826..b374b53 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -82,6 +82,11 @@ const WCHAR pulse_keyW[] = {'S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','P','u','l','s','e',0}; + const WCHAR pulse_streamW[] = { 'S','t','r','e','a','m','V','o','l',0 }; + ++static GUID pulse_render_guid = ++{ 0xfd47d9cc, 0x4218, 0x4135, { 0x9c, 0xe2, 0x0c, 0x19, 0x5c, 0x87, 0x40, 0x5b } }; ++static GUID pulse_capture_guid = ++{ 0x25da76d0, 0x033c, 0x4235, { 0x90, 0x02, 0x19, 0xf4, 0x88, 0x94, 0xac, 0x6f } }; ++ + static HANDLE warn_once; + + BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) +@@ -716,7 +721,7 @@ static HRESULT pulse_stream_connect(ACImpl *This, UINT32 period_bytes) { + return S_OK; + } + +-HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, void ***keys, ++HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, const WCHAR ***ids, GUID **keys, + UINT *num, UINT *def_index) + { + HRESULT hr = S_OK; +@@ -730,20 +735,21 @@ HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, void ***keys, + *num = 1; + *def_index = 0; + +- *ids = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR *)); ++ *ids = HeapAlloc(GetProcessHeap(), 0, sizeof(**ids)); + if (!*ids) + return E_OUTOFMEMORY; ++ (*ids)[0] = defaultW; + +- (*ids)[0] = HeapAlloc(GetProcessHeap(), 0, sizeof(defaultW)); +- if (!(*ids)[0]) { ++ *keys = HeapAlloc(GetProcessHeap(), 0, sizeof(**keys)); ++ if (!*keys) { + HeapFree(GetProcessHeap(), 0, *ids); ++ *ids = NULL; + return E_OUTOFMEMORY; + } +- +- lstrcpyW((*ids)[0], defaultW); +- +- *keys = HeapAlloc(GetProcessHeap(), 0, sizeof(void *)); +- (*keys)[0] = NULL; ++ if (flow == eRender) ++ (*keys)[0] = pulse_render_guid; ++ else ++ (*keys)[0] = pulse_capture_guid; + + return S_OK; + } +@@ -761,12 +767,12 @@ int WINAPI AUDDRV_GetPriority(void) + return SUCCEEDED(hr) ? 3 : 0; + } + +-HRESULT WINAPI AUDDRV_GetAudioEndpoint(void *key, IMMDevice *dev, +- EDataFlow dataflow, IAudioClient **out) ++HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient **out) + { + HRESULT hr; + ACImpl *This; + int i; ++ EDataFlow dataflow; + + /* Give one visible warning per session + * Sadly wine has chosen not to accept the winepulse patch, so support ourselves +@@ -780,7 +786,11 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(void *key, IMMDevice *dev, + } + + TRACE("%s %p %p\n", debugstr_guid(guid), dev, out); +- if (dataflow != eRender && dataflow != eCapture) ++ if (IsEqualGUID(guid, &pulse_render_guid)) ++ dataflow = eRender; ++ else if (IsEqualGUID(guid, &pulse_capture_guid)) ++ dataflow = eCapture; ++ else + return E_UNEXPECTED; + + *out = NULL; +diff --git a/dlls/winepulse.drv/winepulse.drv.spec b/dlls/winepulse.drv/winepulse.drv.spec +index a089166..612bf46 100644 +--- a/dlls/winepulse.drv/winepulse.drv.spec ++++ b/dlls/winepulse.drv/winepulse.drv.spec +@@ -1,5 +1,5 @@ + # MMDevAPI driver functions + @ stdcall -private GetPriority() AUDDRV_GetPriority + @ stdcall -private GetEndpointIDs(long ptr ptr ptr ptr) AUDDRV_GetEndpointIDs +-@ stdcall -private GetAudioEndpoint(ptr ptr long ptr) AUDDRV_GetAudioEndpoint ++@ stdcall -private GetAudioEndpoint(ptr ptr ptr) AUDDRV_GetAudioEndpoint + @ stdcall -private GetAudioSessionManager(ptr ptr) AUDDRV_GetAudioSessionManager +-- +1.8.3.1 + + +From 5d0fdcf25dec628ef0ad2da8d004328133f8aecc Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse: Fix low latency support + +Some games request a 20 ms buffer and will only fill 20 ms. +Since 10 ms periods are too long in this case for winepulse, +fill change period size to 5 ms and force a trigger if +there's still data left to fill. +--- + dlls/winepulse.drv/mmdevdrv.c | 14 ++++++++++++-- + 1 file changed, 12 insertions(+), 2 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index b374b53..7c07f54 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -1205,11 +1205,15 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient *iface, + * default + */ + if (duration < 2 * def) +- period = min; ++ period = min; + else +- period = def; ++ period = def; + if (duration < 2 * period) + duration = 2 * period; ++ ++ /* Uh oh, really low latency requested.. */ ++ if (duration <= 2 * period) ++ period /= 2; + } + period_bytes = pa_frame_size(&This->ss) * MulDiv(period, This->ss.rate, 10000000); + +@@ -1820,6 +1824,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( + { + ACImpl *This = impl_from_IAudioRenderClient(iface); + UINT32 written_bytes = written_frames * pa_frame_size(&This->ss); ++ UINT32 period; + + TRACE("(%p)->(%u, %x)\n", This, written_frames, flags); + +@@ -1854,6 +1859,11 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( + This->locked_ptr = NULL; + TRACE("Released %u, pad %zu\n", written_frames, This->pad / pa_frame_size(&This->ss)); + assert(This->pad <= This->bufsize_bytes); ++ ++ period = pa_stream_get_buffer_attr(This->stream)->minreq; ++ /* Require a minimum of 3 periods filled, if possible */ ++ if (This->event && This->pad + period <= This->bufsize_bytes && This->pad < period * 3) ++ SetEvent(This->event); + pthread_mutex_unlock(&pulse_lock); + return S_OK; + } +-- +1.8.3.1 + + +From 7c89c29a77330d842a996afe4d1e942538c36c3c Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse: drop realtime priority before thread destruction + +prevents having to handle a kernel RT Watchdog Timeout. +--- + dlls/winepulse.drv/mmdevdrv.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 7c07f54..ba68102 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -101,6 +101,8 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) + } + DisableThreadLibraryCalls(dll); + } else if (reason == DLL_PROCESS_DETACH) { ++ if (pulse_thread) ++ SetThreadPriority(pulse_thread, 0); + if (pulse_ctx) { + pa_context_disconnect(pulse_ctx); + pa_context_unref(pulse_ctx); +-- +1.8.3.1 + + +From 8720fd591a0f45d5e0df2ff874a494fac8e9c414 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:01 +0200 +Subject: winepulse: remove bogus SetEvent from pulse_started_callback + +--- + dlls/winepulse.drv/mmdevdrv.c | 4 ---- + 1 file changed, 4 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index ba68102..68de00c 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -559,11 +559,7 @@ static void pulse_latency_callback(pa_stream *s, void *userdata) + + static void pulse_started_callback(pa_stream *s, void *userdata) + { +- ACImpl *This = userdata; +- + TRACE("(Re)started playing\n"); +- if (This->event) +- SetEvent(This->event); + } + + static void pulse_rd_loop(ACImpl *This, size_t bytes) +-- +1.8.3.1 + + +From 33fa776e9ac616fe2ef9064c9a85f3fb5cbfe2fd Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:02 +0200 +Subject: winepulse: disable the setevent part of the latency hack + +If you get playback glitches in skyrim or other games as a result of +this patch, PLEASE REPORT TO ME! +--- + dlls/winepulse.drv/mmdevdrv.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 68de00c..643d55e 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -1822,7 +1822,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( + { + ACImpl *This = impl_from_IAudioRenderClient(iface); + UINT32 written_bytes = written_frames * pa_frame_size(&This->ss); +- UINT32 period; ++// UINT32 period; + + TRACE("(%p)->(%u, %x)\n", This, written_frames, flags); + +@@ -1858,10 +1858,10 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( + TRACE("Released %u, pad %zu\n", written_frames, This->pad / pa_frame_size(&This->ss)); + assert(This->pad <= This->bufsize_bytes); + +- period = pa_stream_get_buffer_attr(This->stream)->minreq; ++// period = pa_stream_get_buffer_attr(This->stream)->minreq; + /* Require a minimum of 3 periods filled, if possible */ +- if (This->event && This->pad + period <= This->bufsize_bytes && This->pad < period * 3) +- SetEvent(This->event); ++// if (This->event && This->pad + period <= This->bufsize_bytes && This->pad < period * 3) ++// SetEvent(This->event); + pthread_mutex_unlock(&pulse_lock); + return S_OK; + } +-- +1.8.3.1 + + +From e04f9881ce89fa1fd544d490b6dfbd7feb9ca9d9 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:02 +0200 +Subject: winepulse v20: fix the checks in IsFormatSupported + +Thanks to DGhost001 for reporting and isolating the issue. +--- + dlls/winepulse.drv/mmdevdrv.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 643d55e..86dd10a 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -1443,6 +1443,10 @@ static HRESULT WINAPI AudioClient_IsFormatSupported(IAudioClient *iface, + } + } + ++ if (fmt->nBlockAlign != fmt->nChannels * fmt->wBitsPerSample / 8 || ++ fmt->nAvgBytesPerSec != fmt->nBlockAlign * fmt->nSamplesPerSec) ++ hr = S_FALSE; ++ + if (hr == S_OK || !out) { + CoTaskMemFree(closest); + if (out) +-- +1.8.3.1 + + +From e85aa72f7fc24e2a760fc84226bc50c588569197 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:02 +0200 +Subject: winepulse: fixup IsFormatSupported calls + +--- + dlls/mmdevapi/tests/render.c | 164 +++++++++++++++++++++++++++++++++++++++ + dlls/winepulse.drv/mmdevdrv.c | 176 ++++++++++++++++++++++++++++-------------- + 2 files changed, 283 insertions(+), 57 deletions(-) + +diff --git a/dlls/mmdevapi/tests/render.c b/dlls/mmdevapi/tests/render.c +index 7cfd440..57fa4b1 100644 +--- a/dlls/mmdevapi/tests/render.c ++++ b/dlls/mmdevapi/tests/render.c +@@ -474,6 +474,169 @@ static void test_formats(AUDCLNT_SHAREMODE mode) + } + } + ++static void test_formats2(void) ++{ ++ IAudioClient *ac; ++ HRESULT hr; ++ WAVEFORMATEX *pwfx, *pwfx2; ++ WAVEFORMATEXTENSIBLE *pwfe, wfe, *pwfe2; ++ ++ hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, ++ NULL, (void**)&ac); ++ ++ ok(hr == S_OK, "Activation failed with %08x\n", hr); ++ if (hr != S_OK) ++ return; ++ ++ hr = IAudioClient_GetMixFormat(ac, &pwfx); ++ ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr); ++ if (hr != S_OK) ++ return; ++ ++ ok(pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE, "Invalid wFormatTag\n"); ++ if (pwfx->wFormatTag != WAVE_FORMAT_EXTENSIBLE) { ++ CoTaskMemFree(pwfx); ++ return; ++ } ++ ++ pwfe = (WAVEFORMATEXTENSIBLE*)pwfx; ++ ok(pwfe->Samples.wValidBitsPerSample, "wValidBitsPerSample should be non-zero\n"); ++ ++ if (pwfx->nChannels > 2) { ++ trace("Limiting channels to 2\n"); ++ pwfx->nChannels = 2; ++ pwfx->nBlockAlign = pwfx->wBitsPerSample / 8 * pwfx->nChannels; ++ pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec; ++ pwfe->dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; ++ } ++ ++ wfe = *pwfe; ++ pwfx->nAvgBytesPerSec = pwfx->nBlockAlign = 0; ++ ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL); ++ ok(hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED, ++ "Exclusive IsFormatSupported with nAvgBytesPerSec=0 and nBlockAlign=0 returned %08x\n", hr); ++ ++ pwfx2 = NULL; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok((hr == E_INVALIDARG || hr == AUDCLNT_E_UNSUPPORTED_FORMAT) && !pwfx2, ++ "Shared IsFormatSupported with nAvgBytesPerSec=0 and nBlockAlign=0 returned %08x %p\n", hr, pwfx2); ++ CoTaskMemFree(pwfx2); ++ ++ pwfx->wFormatTag = WAVE_FORMAT_PCM; ++ pwfx2 = NULL; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok((hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT) && !pwfx2, ++ "Shared IsFormatSupported with nAvgBytesPerSec=0 and nBlockAlign=0 returned %08x %p\n", hr, pwfx2); ++ CoTaskMemFree(pwfx2); ++ ++ *pwfe = wfe; ++ pwfe->dwChannelMask = 0; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL); ++ ok(hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED, ++ "Exclusive IsFormatSupported with dwChannelMask=0 returned %08x\n", hr); ++ ++ pwfx2 = NULL; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok(hr == S_OK, ++ "Shared IsFormatSupported with dwChannelMask=0 returned %08x\n", hr); ++ CoTaskMemFree(pwfx2); ++ ++ ++ pwfe->dwChannelMask = 0x3ffff; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL); ++ ok(hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED, ++ "Exclusive IsFormatSupported with dwChannelMask=0x3ffff returned %08x\n", hr); ++ ++ pwfx2 = NULL; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok(hr == S_OK && !pwfx2, ++ "Shared IsFormatSupported with dwChannelMask=0x3ffff returned %08x %p\n", hr, pwfx2); ++ CoTaskMemFree(pwfx2); ++ ++ ++ pwfe->dwChannelMask = 0x40000000; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL); ++ ok(hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED, ++ "Exclusive IsFormatSupported with dwChannelMask=0x40000000 returned %08x\n", hr); ++ ++ pwfx2 = NULL; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok(hr == S_OK && !pwfx2, ++ "Shared IsFormatSupported with dwChannelMask=0x40000000 returned %08x %p\n", hr, pwfx2); ++ CoTaskMemFree(pwfx2); ++ ++ pwfe->dwChannelMask = SPEAKER_ALL | SPEAKER_RESERVED; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL); ++ ok(hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED, ++ "Exclusive IsFormatSupported with dwChannelMask=SPEAKER_ALL | SPEAKER_RESERVED returned %08x\n", hr); ++ ++ pwfx2 = NULL; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok(hr == S_OK && !pwfx2, ++ "Shared IsFormatSupported with dwChannelMask=SPEAKER_ALL | SPEAKER_RESERVED returned %08x %p\n", hr, pwfx2); ++ CoTaskMemFree(pwfx2); ++ ++ *pwfe = wfe; ++ pwfe->Samples.wValidBitsPerSample = 0; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL); ++ ok(hr == AUDCLNT_E_UNSUPPORTED_FORMAT || hr == AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED, ++ "Exclusive IsFormatSupported with wValidBitsPerSample=0 returned %08x\n", hr); ++ ++ pwfx2 = NULL; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok((hr == S_FALSE || hr == AUDCLNT_E_UNSUPPORTED_FORMAT) && pwfx2, ++ "Shared IsFormatSupported with wValidBitsPerSample=0 returned %08x %p\n", hr, pwfx2); ++ if (pwfx2) { ++ pwfe2 = (WAVEFORMATEXTENSIBLE*)pwfx2; ++ ok(pwfe2->Samples.wValidBitsPerSample == pwfx->wBitsPerSample, ++ "Shared IsFormatSupported had wValidBitsPerSample set to %u, not %u\n", ++ pwfe2->Samples.wValidBitsPerSample, pwfx->wBitsPerSample); ++ CoTaskMemFree(pwfx2); ++ } ++ ++ pwfx2 = NULL; ++ pwfe->Samples.wValidBitsPerSample = pwfx->wBitsPerSample + 1; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok((hr == E_INVALIDARG || hr == AUDCLNT_E_UNSUPPORTED_FORMAT) && !pwfx2, ++ "Shared IsFormatSupported with wValidBitsPerSample += 1 returned %08x %p\n", hr, pwfx2); ++ ++ *pwfe = wfe; ++ memset(&pwfe->SubFormat, 0xff, 16); ++ pwfx2 = NULL; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok(hr == AUDCLNT_E_UNSUPPORTED_FORMAT && !pwfx2, ++ "Shared IsFormatSupported with SubFormat=-1 returned %08x %p\n", hr, pwfx2); ++ CoTaskMemFree(pwfx2); ++ ++ *pwfe = wfe; ++ pwfx2 = NULL; ++ pwfe->Samples.wValidBitsPerSample = pwfx->wBitsPerSample = 256; ++ pwfx->nBlockAlign = pwfx->wBitsPerSample / 8 * pwfx->nChannels; ++ pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok((hr == E_INVALIDARG || hr == AUDCLNT_E_UNSUPPORTED_FORMAT) && !pwfx2, ++ "Shared IsFormatSupported with wBitsPerSample=256 returned %08x %p\n", hr, pwfx2); ++ CoTaskMemFree(pwfx2); ++ ++ *pwfe = wfe; ++ pwfx2 = NULL; ++ pwfe->Samples.wValidBitsPerSample = pwfx->wBitsPerSample - 1; ++ hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ++ ok(hr == S_FALSE && pwfx2, ++ "Shared IsFormatSupported with wValidBitsPerSample-=1 returned %08x %p\n", hr, pwfx2); ++ if (pwfx2) { ++ pwfe2 = (WAVEFORMATEXTENSIBLE*)pwfx2; ++ ok(pwfe2->Samples.wValidBitsPerSample == pwfx->wBitsPerSample, ++ "Shared IsFormatSupported had wValidBitsPerSample set to %u, not %u\n", ++ pwfe2->Samples.wValidBitsPerSample, pwfx->wBitsPerSample); ++ CoTaskMemFree(pwfx2); ++ } ++ ++ CoTaskMemFree(pwfx); ++ IAudioClient_Release(ac); ++} ++ + static void test_references(void) + { + IAudioClient *ac; +@@ -2241,6 +2404,7 @@ START_TEST(render) + test_audioclient(); + test_formats(AUDCLNT_SHAREMODE_EXCLUSIVE); + test_formats(AUDCLNT_SHAREMODE_SHARED); ++ test_formats2(); + test_references(); + test_marshal(); + trace("Output to a MS-DOS console is particularly slow and disturbs timing.\n"); +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 86dd10a..554a9fc 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -1104,10 +1104,8 @@ static HRESULT pulse_spec_from_waveformat(ACImpl *This, const WAVEFORMATEX *fmt) + } + } + This->map.channels = fmt->nChannels; +- if (!mask || mask == SPEAKER_ALL) ++ if (!mask || (mask & (SPEAKER_ALL|SPEAKER_RESERVED))) + mask = get_channel_mask(fmt->nChannels); +- else if (mask == ~0U && fmt->nChannels == 1) +- mask = SPEAKER_FRONT_CENTER; + for (j = 0; j < sizeof(pulse_pos_from_wfx)/sizeof(*pulse_pos_from_wfx) && i < fmt->nChannels; ++j) { + if (mask & (1 << j)) + This->map.map[i++] = pulse_pos_from_wfx[j]; +@@ -1381,83 +1379,147 @@ static HRESULT WINAPI AudioClient_IsFormatSupported(IAudioClient *iface, + ACImpl *This = impl_from_IAudioClient(iface); + HRESULT hr = S_OK; + WAVEFORMATEX *closest = NULL; ++ BOOL exclusive; + + TRACE("(%p)->(%x, %p, %p)\n", This, mode, fmt, out); + +- if (!fmt || (mode == AUDCLNT_SHAREMODE_SHARED && !out)) ++ if (!fmt) + return E_POINTER; + + if (out) + *out = NULL; +- if (mode != AUDCLNT_SHAREMODE_SHARED && mode != AUDCLNT_SHAREMODE_EXCLUSIVE) ++ ++ if (mode == AUDCLNT_SHAREMODE_EXCLUSIVE) { ++ exclusive = 1; ++ out = NULL; ++ } else if (mode == AUDCLNT_SHAREMODE_SHARED) { ++ exclusive = 0; ++ if (!out) ++ return E_POINTER; ++ } else + return E_INVALIDARG; +- if (mode == AUDCLNT_SHAREMODE_EXCLUSIVE) +- return This->dataflow == eCapture ? AUDCLNT_E_UNSUPPORTED_FORMAT : AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED; +- switch (fmt->wFormatTag) { +- case WAVE_FORMAT_EXTENSIBLE: +- if (fmt->cbSize < sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)) +- return E_INVALIDARG; +- dump_fmt(fmt); +- break; +- case WAVE_FORMAT_ALAW: +- case WAVE_FORMAT_MULAW: +- case WAVE_FORMAT_IEEE_FLOAT: +- case WAVE_FORMAT_PCM: +- dump_fmt(fmt); +- break; +- default: +- dump_fmt(fmt); +- return AUDCLNT_E_UNSUPPORTED_FORMAT; +- } ++ + if (fmt->nChannels == 0) + return AUDCLNT_E_UNSUPPORTED_FORMAT; ++ + closest = clone_format(fmt); +- if (!closest) { +- if (out) +- *out = NULL; ++ if (!closest) + return E_OUTOFMEMORY; +- } + +- if (fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE) { +- UINT32 mask = 0, i, channels = 0; ++ dump_fmt(fmt); ++ ++ switch (fmt->wFormatTag) { ++ case WAVE_FORMAT_EXTENSIBLE: { + WAVEFORMATEXTENSIBLE *ext = (WAVEFORMATEXTENSIBLE*)closest; + +- if ((fmt->nChannels > 1 && ext->dwChannelMask == SPEAKER_ALL) || +- (fmt->nChannels == 1 && ext->dwChannelMask == ~0U)) { +- mask = ext->dwChannelMask; +- channels = fmt->nChannels; +- } else if (ext->dwChannelMask) { +- for (i = 1; !(i & SPEAKER_RESERVED); i <<= 1) { +- if (i & ext->dwChannelMask) { +- mask |= i; +- channels++; ++ if ((fmt->cbSize != sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) && ++ fmt->cbSize != sizeof(WAVEFORMATEXTENSIBLE)) || ++ fmt->nBlockAlign != fmt->wBitsPerSample / 8 * fmt->nChannels || ++ ext->Samples.wValidBitsPerSample > fmt->wBitsPerSample || ++ fmt->nAvgBytesPerSec != fmt->nBlockAlign * fmt->nSamplesPerSec) { ++ hr = E_INVALIDARG; ++ break; ++ } ++ ++ if (exclusive) { ++ UINT32 mask = 0, i, channels = 0; + -+ if (index >= session->channel_count) -+ return E_INVALIDARG; ++ if (!(ext->dwChannelMask & (SPEAKER_ALL | SPEAKER_RESERVED))) { ++ for (i = 1; !(i & SPEAKER_RESERVED); i <<= 1) { ++ if (i & ext->dwChannelMask) { ++ mask |= i; ++ channels++; ++ } ++ } + -+ if (context) -+ FIXME("Notifications not supported yet\n"); ++ if (channels != fmt->nChannels || (ext->dwChannelMask & ~mask)) { ++ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; ++ break; + } ++ } else { ++ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; ++ break; + } +- if (channels < fmt->nChannels) +- mask = get_channel_mask(fmt->nChannels); +- } else +- mask = ext->dwChannelMask; +- if (ext->dwChannelMask != mask) { +- ext->dwChannelMask = mask; +- hr = S_FALSE; + } + -+ TRACE("Pulseaudio does not support session volume control\n"); ++ if (IsEqualGUID(&ext->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) { ++ if (fmt->wBitsPerSample != 32) { ++ hr = E_INVALIDARG; ++ break; ++ } + -+ pthread_mutex_lock(&pulse_lock); -+ session->channel_vols[index] = level; -+ pthread_mutex_unlock(&pulse_lock); ++ if (ext->Samples.wValidBitsPerSample != fmt->wBitsPerSample) { ++ hr = S_FALSE; ++ ext->Samples.wValidBitsPerSample = fmt->wBitsPerSample; ++ } ++ } else if (IsEqualGUID(&ext->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) { ++ if (!fmt->wBitsPerSample || fmt->wBitsPerSample > 32 || fmt->wBitsPerSample % 8) { ++ hr = E_INVALIDARG; ++ break; ++ } + -+ return S_OK; -+} ++ if (ext->Samples.wValidBitsPerSample != fmt->wBitsPerSample && ++ !(fmt->wBitsPerSample == 32 && ++ ext->Samples.wValidBitsPerSample == 24)) { ++ hr = S_FALSE; ++ ext->Samples.wValidBitsPerSample = fmt->wBitsPerSample; ++ break; ++ } ++ } else { ++ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; ++ break; ++ } + -+static HRESULT WINAPI ChannelAudioVolume_GetChannelVolume( -+ IChannelAudioVolume *iface, UINT32 index, float *level) -+{ -+ AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); -+ AudioSession *session = This->session; ++ break; + } + +- if (fmt->nBlockAlign != fmt->nChannels * fmt->wBitsPerSample / 8 || +- fmt->nAvgBytesPerSec != fmt->nBlockAlign * fmt->nSamplesPerSec) +- hr = S_FALSE; ++ case WAVE_FORMAT_ALAW: ++ case WAVE_FORMAT_MULAW: ++ if (fmt->wBitsPerSample != 8) { ++ hr = E_INVALIDARG; ++ break; ++ } ++ /* Fall-through */ ++ case WAVE_FORMAT_IEEE_FLOAT: ++ if (fmt->wFormatTag == WAVE_FORMAT_IEEE_FLOAT && fmt->wBitsPerSample != 32) { ++ hr = E_INVALIDARG; ++ break; ++ } ++ /* Fall-through */ ++ case WAVE_FORMAT_PCM: ++ if (fmt->wFormatTag == WAVE_FORMAT_PCM && ++ (!fmt->wBitsPerSample || fmt->wBitsPerSample > 32 || fmt->wBitsPerSample % 8)) { ++ hr = E_INVALIDARG; ++ break; ++ } + -+ TRACE("(%p)->(%d, %p)\n", session, index, level); ++ if (fmt->nChannels > 2) { ++ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; ++ break; ++ } ++ /* ++ * fmt->cbSize, fmt->nBlockAlign and fmt->nAvgBytesPerSec seem to be ++ * ignored, invalid values are happily accepted. ++ */ ++ break; ++ default: ++ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; ++ break; ++ } + +- if (hr == S_OK || !out) { ++ if (exclusive && hr != S_OK) { ++ hr = AUDCLNT_E_UNSUPPORTED_FORMAT; + CoTaskMemFree(closest); +- if (out) +- *out = NULL; +- } else if (closest) { +- closest->nBlockAlign = +- closest->nChannels * closest->wBitsPerSample / 8; +- closest->nAvgBytesPerSec = +- closest->nBlockAlign * closest->nSamplesPerSec; ++ } else if (hr != S_FALSE) ++ CoTaskMemFree(closest); ++ else + *out = closest; +- } + -+ if (!level) -+ return NULL_PTR_ERR; ++ /* Winepulse does not currently support exclusive mode, if you know of an ++ * application that uses it, I will correct this.. ++ */ ++ if (hr == S_OK && exclusive) ++ return This->dataflow == eCapture ? AUDCLNT_E_UNSUPPORTED_FORMAT : AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED; + + TRACE("returning: %08x %p\n", hr, out ? *out : NULL); + return hr; +-- +1.8.3.1 + + +From 1d7e52afd87f0b37f625580f185d060f021f3fd3 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:02 +0200 +Subject: winepulse v21: return early if padding didn't update + +--- + dlls/winepulse.drv/mmdevdrv.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 554a9fc..a4575d5 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -531,7 +531,10 @@ static void pulse_wr_callback(pa_stream *s, size_t bytes, void *userdata) + else + This->pad = 0; + +- assert(oldpad >= This->pad); ++ if (oldpad == This->pad) ++ return; + -+ if (index >= session->channel_count) -+ return E_INVALIDARG; ++ assert(oldpad > This->pad); + + This->clock_written += oldpad - This->pad; + TRACE("New pad: %zu (-%zu)\n", This->pad / pa_frame_size(&This->ss), (oldpad - This->pad) / pa_frame_size(&This->ss)); +-- +1.8.3.1 + + +From 9f245548f8bca9db1892bc7560db2d66217a9a44 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:02 +0200 +Subject: winepulse: fix unneeded free in write.. + +--- + dlls/winepulse.drv/mmdevdrv.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index a4575d5..3ca68fd 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -1886,6 +1886,10 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, + return hr; + } + ++static void pulse_free_noop(void *buf) ++{ ++} + -+ *level = session->channel_vols[index]; + static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( + IAudioRenderClient *iface, UINT32 written_frames, DWORD flags) + { +@@ -1921,7 +1925,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( + if (This->locked_ptr) + pa_stream_write(This->stream, This->locked_ptr, written_bytes, NULL, 0, PA_SEEK_RELATIVE); + else +- pa_stream_write(This->stream, This->tmp_buffer, written_bytes, NULL, 0, PA_SEEK_RELATIVE); ++ pa_stream_write(This->stream, This->tmp_buffer, written_bytes, pulse_free_noop, 0, PA_SEEK_RELATIVE); + This->pad += written_bytes; + This->locked_ptr = NULL; + TRACE("Released %u, pad %zu\n", written_frames, This->pad / pa_frame_size(&This->ss)); +-- +1.8.3.1 + + +From eecbc197a50ddee696590019e8aa644108f3efb2 Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:02 +0200 +Subject: winepulse v23: fixup a invalid free in mmdevapi + +array members of ids should be dynamically allocated, judging from valgrind output. +--- + dlls/winepulse.drv/mmdevdrv.c | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 3ca68fd..5b041a2 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -726,6 +726,8 @@ HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, const WCHAR ***ids, GUID ** + UINT *num, UINT *def_index) + { + HRESULT hr = S_OK; ++ WCHAR *id; + -+ return S_OK; -+} + TRACE("%d %p %p %p\n", flow, ids, num, def_index); + + pthread_mutex_lock(&pulse_lock); +@@ -737,16 +739,22 @@ HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, const WCHAR ***ids, GUID ** + *def_index = 0; + + *ids = HeapAlloc(GetProcessHeap(), 0, sizeof(**ids)); ++ *keys = NULL; + if (!*ids) + return E_OUTOFMEMORY; +- (*ids)[0] = defaultW; + ++ (*ids)[0] = id = HeapAlloc(GetProcessHeap(), 0, sizeof(defaultW)); + *keys = HeapAlloc(GetProcessHeap(), 0, sizeof(**keys)); +- if (!*keys) { ++ if (!*keys || !id) { ++ HeapFree(GetProcessHeap(), 0, id); ++ HeapFree(GetProcessHeap(), 0, *keys); + HeapFree(GetProcessHeap(), 0, *ids); + *ids = NULL; ++ *keys = NULL; + return E_OUTOFMEMORY; + } ++ memcpy(id, defaultW, sizeof(defaultW)); + -+static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes( -+ IChannelAudioVolume *iface, UINT32 count, const float *levels, -+ const GUID *context) -+{ -+ AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); -+ AudioSession *session = This->session; -+ int i; + if (flow == eRender) + (*keys)[0] = pulse_render_guid; + else +-- +1.8.3.1 + +From 8513286932d086a28eeab6652b81990b7cb3f36d Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:03 +0200 +Subject: winepulse: use a pi-mutex for serialization. + +The winepulse thread is realtime, to prevent blocking it indefinitely +use priority inheritance. Only initialize and release are potentially +unsafe, the rest should be ok with -rt. +--- + dlls/winepulse.drv/mmdevdrv.c | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index 5b041a2..a09ce7f 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -22,6 +22,8 @@ + + #define NONAMELESSUNION + #define COBJMACROS ++#define _GNU_SOURCE + -+ TRACE("(%p)->(%d, %p, %s)\n", session, count, levels, -+ wine_dbgstr_guid(context)); + #include "config.h" + #include + #include +@@ -30,6 +32,7 @@ + #include + #include + #include ++#include + + #include + +@@ -68,7 +71,7 @@ static pa_context *pulse_ctx; + static pa_mainloop *pulse_ml; + + static HANDLE pulse_thread; +-static pthread_mutex_t pulse_lock = PTHREAD_MUTEX_INITIALIZER; ++static pthread_mutex_t pulse_lock; + static pthread_cond_t pulse_cond = PTHREAD_COND_INITIALIZER; + static struct list g_sessions = LIST_INIT(g_sessions); + +@@ -93,6 +96,8 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) + { + if (reason == DLL_PROCESS_ATTACH) { + HKEY key; ++ pthread_mutexattr_t attr; + -+ if (!levels) -+ return NULL_PTR_ERR; + if (RegOpenKeyW(HKEY_CURRENT_USER, pulse_keyW, &key) == ERROR_SUCCESS) { + DWORD size = sizeof(pulse_stream_volume); + RegQueryValueExW(key, pulse_streamW, 0, NULL, +@@ -100,6 +105,12 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) + RegCloseKey(key); + } + DisableThreadLibraryCalls(dll); + -+ if (count != session->channel_count) -+ return E_INVALIDARG; ++ pthread_mutexattr_init(&attr); ++ pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); + -+ if (context) -+ FIXME("Notifications not supported yet\n"); ++ if (pthread_mutex_init(&pulse_lock, &attr) != 0) ++ pthread_mutex_init(&pulse_lock, NULL); + } else if (reason == DLL_PROCESS_DETACH) { + if (pulse_thread) + SetThreadPriority(pulse_thread, 0); +-- +1.8.3.1 + + +From 5a091534be9dcb6cdfa8bdf9f4e642b42acd35de Mon Sep 17 00:00:00 2001 +From: Maarten Lankhorst +Date: Sat, 31 Aug 2013 08:36:03 +0200 +Subject: winepulse: add support for IMarshal + +Fixes bug 32161 for winepulse. Based On Jeff Klein's patches for the +other drivers. +--- + dlls/winepulse.drv/mmdevdrv.c | 31 +++++++++++++++++++++++++++++++ + 1 file changed, 31 insertions(+) + +diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c +index a09ce7f..f052a08 100644 +--- a/dlls/winepulse.drv/mmdevdrv.c ++++ b/dlls/winepulse.drv/mmdevdrv.c +@@ -169,6 +169,7 @@ struct ACImpl { + IAudioClock IAudioClock_iface; + IAudioClock2 IAudioClock2_iface; + IAudioStreamVolume IAudioStreamVolume_iface; ++ IUnknown *marshal; + IMMDevice *parent; + struct list entry; + float vol[PA_CHANNELS_MAX]; +@@ -834,6 +835,12 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient + This->parent = dev; + for (i = 0; i < PA_CHANNELS_MAX; ++i) + This->vol[i] = 1.f; + -+ TRACE("Pulseaudio does not support session volume control\n"); ++ hr = CoCreateFreeThreadedMarshaler((IUnknown*)This, &This->marshal); ++ if (hr) { ++ HeapFree(GetProcessHeap(), 0, This); ++ return hr; ++ } + IMMDevice_AddRef(This->parent); + + *out = &This->IAudioClient_iface; +@@ -845,10 +852,13 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient + static HRESULT WINAPI AudioClient_QueryInterface(IAudioClient *iface, + REFIID riid, void **ppv) + { ++ ACImpl *This = impl_from_IAudioClient(iface); + -+ pthread_mutex_lock(&pulse_lock); -+ for(i = 0; i < count; ++i) -+ session->channel_vols[i] = levels[i]; -+ pthread_mutex_unlock(&pulse_lock); -+ return S_OK; -+} + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + + if (!ppv) + return E_POINTER; + -+static HRESULT WINAPI ChannelAudioVolume_GetAllVolumes( -+ IChannelAudioVolume *iface, UINT32 count, float *levels) -+{ -+ AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); -+ AudioSession *session = This->session; -+ int i; + *ppv = NULL; + if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IAudioClient)) + *ppv = iface; +@@ -856,6 +866,10 @@ static HRESULT WINAPI AudioClient_QueryInterface(IAudioClient *iface, + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; + } + -+ TRACE("(%p)->(%d, %p)\n", session, count, levels); ++ if (IsEqualIID(riid, &IID_IMarshal)) ++ return IUnknown_QueryInterface(This->marshal, riid, ppv); + -+ if (!levels) -+ return NULL_PTR_ERR; + WARN("Unknown interface %s\n", debugstr_guid(riid)); + return E_NOINTERFACE; + } +@@ -888,6 +902,7 @@ static ULONG WINAPI AudioClient_Release(IAudioClient *iface) + list_remove(&This->entry); + pthread_mutex_unlock(&pulse_lock); + } ++ IUnknown_Release(This->marshal); + IMMDevice_Release(This->parent); + HeapFree(GetProcessHeap(), 0, This->tmp_buffer); + HeapFree(GetProcessHeap(), 0, This); +@@ -1826,6 +1841,7 @@ static const IAudioClientVtbl AudioClient_Vtbl = + static HRESULT WINAPI AudioRenderClient_QueryInterface( + IAudioRenderClient *iface, REFIID riid, void **ppv) + { ++ ACImpl *This = impl_from_IAudioRenderClient(iface); + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + + if (!ppv) +@@ -1840,6 +1856,9 @@ static HRESULT WINAPI AudioRenderClient_QueryInterface( + return S_OK; + } + ++ if (IsEqualIID(riid, &IID_IMarshal)) ++ return IUnknown_QueryInterface(This->marshal, riid, ppv); + -+ if (count != session->channel_count) -+ return E_INVALIDARG; + WARN("Unknown interface %s\n", debugstr_guid(riid)); + return E_NOINTERFACE; + } +@@ -1969,6 +1988,7 @@ static const IAudioRenderClientVtbl AudioRenderClient_Vtbl = { + static HRESULT WINAPI AudioCaptureClient_QueryInterface( + IAudioCaptureClient *iface, REFIID riid, void **ppv) + { ++ ACImpl *This = impl_from_IAudioCaptureClient(iface); + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + + if (!ppv) +@@ -1983,6 +2003,9 @@ static HRESULT WINAPI AudioCaptureClient_QueryInterface( + return S_OK; + } + ++ if (IsEqualIID(riid, &IID_IMarshal)) ++ return IUnknown_QueryInterface(This->marshal, riid, ppv); + -+ for(i = 0; i < count; ++i) -+ levels[i] = session->channel_vols[i]; + WARN("Unknown interface %s\n", debugstr_guid(riid)); + return E_NOINTERFACE; + } +@@ -2125,6 +2148,9 @@ static HRESULT WINAPI AudioClock_QueryInterface(IAudioClock *iface, + return S_OK; + } + ++ if (IsEqualIID(riid, &IID_IMarshal)) ++ return IUnknown_QueryInterface(This->marshal, riid, ppv); + -+ return S_OK; -+} + WARN("Unknown interface %s\n", debugstr_guid(riid)); + return E_NOINTERFACE; + } +@@ -2260,6 +2286,8 @@ static const IAudioClock2Vtbl AudioClock2_Vtbl = + static HRESULT WINAPI AudioStreamVolume_QueryInterface( + IAudioStreamVolume *iface, REFIID riid, void **ppv) + { ++ ACImpl *This = impl_from_IAudioStreamVolume(iface); + -+static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl = -+{ -+ ChannelAudioVolume_QueryInterface, -+ ChannelAudioVolume_AddRef, -+ ChannelAudioVolume_Release, -+ ChannelAudioVolume_GetChannelCount, -+ ChannelAudioVolume_SetChannelVolume, -+ ChannelAudioVolume_GetChannelVolume, -+ ChannelAudioVolume_SetAllVolumes, -+ ChannelAudioVolume_GetAllVolumes -+}; + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + + if (!ppv) +@@ -2274,6 +2302,9 @@ static HRESULT WINAPI AudioStreamVolume_QueryInterface( + return S_OK; + } + ++ if (IsEqualIID(riid, &IID_IMarshal)) ++ return IUnknown_QueryInterface(This->marshal, riid, ppv); + -+HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device, -+ IAudioSessionManager2 **out) -+{ -+ SessionMgr *This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SessionMgr)); -+ *out = NULL; -+ if (!This) -+ return E_OUTOFMEMORY; -+ This->IAudioSessionManager2_iface.lpVtbl = &AudioSessionManager2_Vtbl; -+ This->device = device; -+ This->ref = 1; -+ *out = &This->IAudioSessionManager2_iface; -+ return S_OK; -+} -diff -uhNr wine-1.7.0/dlls/winepulse.drv/winepulse.drv.spec wine-1.7.0-multimedia/dlls/winepulse.drv/winepulse.drv.spec ---- wine-1.7.0/dlls/winepulse.drv/winepulse.drv.spec 1970-01-01 01:00:00.000000000 +0100 -+++ wine-1.7.0-multimedia/dlls/winepulse.drv/winepulse.drv.spec 2013-08-17 08:36:37.219593908 +0200 -@@ -0,0 +1,5 @@ -+# MMDevAPI driver functions -+@ stdcall -private GetPriority() AUDDRV_GetPriority -+@ stdcall -private GetEndpointIDs(long ptr ptr ptr ptr) AUDDRV_GetEndpointIDs -+@ stdcall -private GetAudioEndpoint(ptr ptr ptr) AUDDRV_GetAudioEndpoint -+@ stdcall -private GetAudioSessionManager(ptr ptr) AUDDRV_GetAudioSessionManager + WARN("Unknown interface %s\n", debugstr_guid(riid)); + return E_NOINTERFACE; + } +-- +1.8.3.1 + diff --git a/wine-pulse-winmm-Load-winealsa-if-winepulse-is-found.patch b/wine-pulse-winmm-Load-winealsa-if-winepulse-is-found.patch deleted file mode 100644 index f99c72b..0000000 --- a/wine-pulse-winmm-Load-winealsa-if-winepulse-is-found.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 8f39a12639ee1d39c8caaf5f2ab72540d281814e Mon Sep 17 00:00:00 2001 -From: Maarten Lankhorst -Date: Sat, 29 Dec 2012 01:02:30 +0100 -Subject: [PATCH] winmm: Load winealsa if winepulse is found - -Fixes midi on winepulse ---- - dlls/winmm/lolvldrv.c | 5 ++++- - 1 files changed, 4 insertions(+), 1 deletions(-) - -diff --git a/dlls/winmm/lolvldrv.c b/dlls/winmm/lolvldrv.c -index f387323..3b1be27 100644 ---- a/dlls/winmm/lolvldrv.c -+++ b/dlls/winmm/lolvldrv.c -@@ -543,7 +543,10 @@ static void MMDRV_Init(void) - drvA = HeapAlloc(GetProcessHeap(), 0, size); - WideCharToMultiByte(CP_ACP, 0, pv.u.pwszVal, -1, drvA, size, NULL, NULL); - -- MMDRV_Install(drvA, drvA, FALSE); -+ if (!strcasecmp(drvA, "winepulse.drv")) -+ MMDRV_Install("winealsa.drv", "winealsa.drv", 0); -+ else -+ MMDRV_Install(drvA, drvA, FALSE); - - HeapFree(GetProcessHeap(), 0, drvA); - PropVariantClear(&pv); --- -1.6.5.GIT - diff --git a/wine.spec b/wine.spec index 2620450..0b52ab2 100644 --- a/wine.spec +++ b/wine.spec @@ -3,8 +3,8 @@ %global winemono 0.0.8 Name: wine -Version: 1.7.1 -Release: 2%{?dist} +Version: 1.7.2 +Release: 1%{?dist} Summary: A compatibility layer for windows applications Group: Applications/Emulators @@ -32,9 +32,6 @@ Source108: wine-wordpad.desktop Source109: wine-oleview.desktop # build fixes -# do not check for glAccum -# wget http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-emulation/wine/files/wine-1.5.17-osmesa-check.patch?revision=1.1 -Patch1: wine-1.5.17-osmesa-check.patch # wine bugs @@ -56,16 +53,14 @@ Patch511: wine-cjk.patch ## winepulse backend # http://repo.or.cz/w/wine/multimedia.git -# Fri, 2 Aug 2013 21:19:49 +0000 -# configure -# configure.ac -# dlls/mmdevapi/main.c -# dlls/winepulse.drv -# -Patch1001: wine-pulse-1.7.0.patch -# use winealsa for midi in the pa backend -# http://repo.or.cz/w/wine/multimedia.git/commit/8f39a12639ee1d39c8caaf5f2ab72540d281814e -Patch1002: wine-pulse-winmm-Load-winealsa-if-winepulse-is-found.patch +# Sat, 31 Aug 2013 06:36:03 +0000 +# based on wine tree 1.7.1 +## +# git clone http://repo.or.cz/w/wine/multimedia.git +# cd multimedia.git +# git format-patch -k --stdout bea77093864177659aa16aab5d81b213015990b9~..eecbc197a50ddee696590019e8aa644108f3efb2 > ~/cvs/fedora/rpms/wine/wine-pulse-1.7.1.patch +# git format-patch -k --stdout 8513286932d086a28eeab6652b81990b7cb3f36d~..5a091534be9dcb6cdfa8bdf9f4e642b42acd35de --stdout >> ~/cvs/fedora/rpms/wine/wine-pulse-1.7.1.patch +Patch1001: wine-pulse-1.7.1.patch %if !%{?no64bit} ExclusiveArch: %{ix86} x86_64 %{arm} @@ -152,7 +147,8 @@ Requires: wine-openal(x86-32) = %{version}-%{release} Requires: mingw32-wine-gecko = %winegecko Requires: wine-mono = %winemono %endif -# Requires: samba-winbind-clients(x86-32) wait for rhbz#968860 +# wait for rhbz#968860 to require arch-specific samba-winbind-clients +Requires: /usr/bin/ntlm_auth Requires: mesa-dri-drivers(x86-32) %endif @@ -177,7 +173,6 @@ Requires: wine-openal(x86-64) = %{version}-%{release} Requires: mingw64-wine-gecko = %winegecko Requires: wine-mono = %winemono %endif -# Requires: samba-winbind-clients(x86-64) wait for rhbz#968860 Requires: mesa-dri-drivers(x86-64) Requires: wine-wow(x86-64) = %{version}-%{release} Conflicts: wine-wow(x86-32) = %{version}-%{release} @@ -536,12 +531,9 @@ This package adds an openal driver for wine. %prep %setup -q -%patch1 -p1 -b.osmesa - %patch511 -p1 -b.cjk %patch1001 -p1 -b.winepulse -%patch1002 -p1 -b.winepulse-midi autoreconf @@ -983,6 +975,7 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %{_libdir}/wine/atl.dll.so %{_libdir}/wine/atl80.dll.so %{_libdir}/wine/atl100.dll.so +%{_libdir}/wine/atl110.dll.so %{_libdir}/wine/authz.dll.so %{_libdir}/wine/avicap32.dll.so %{_libdir}/wine/avifil32.dll.so @@ -1016,6 +1009,8 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %{_libdir}/wine/d3drm.dll.so %{_libdir}/wine/d3dx9_*.dll.so %{_libdir}/wine/d3dx10_*.dll.so +%{_libdir}/wine/d3dx11_42.dll.so +%{_libdir}/wine/d3dx11_43.dll.so %{_libdir}/wine/d3dxof.dll.so %{_libdir}/wine/dbgeng.dll.so %{_libdir}/wine/dbghelp.dll.so @@ -1170,6 +1165,7 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %{_libdir}/wine/msxml6.dll.so %{_libdir}/wine/nddeapi.dll.so %{_libdir}/wine/netapi32.dll.so +%{_libdir}/wine/netcfgx.dll.so %{_libdir}/wine/netsh.exe.so %{_libdir}/wine/newdev.dll.so %{_libdir}/wine/normaliz.dll.so @@ -1314,6 +1310,7 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %{_libdir}/wine/xinput1_1.dll.so %{_libdir}/wine/xinput1_2.dll.so %{_libdir}/wine/xinput1_3.dll.so +%{_libdir}/wine/xinput1_4.dll.so %{_libdir}/wine/xinput9_1_0.dll.so %{_libdir}/wine/xmllite.dll.so %{_libdir}/wine/xolehlp.dll.so @@ -1558,6 +1555,12 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %endif %changelog +* Sun Sep 15 2013 Andreas Bierfert +- 1.7.2-1 +- version upgrade +- workaround for rhbz#968860 +- upgraded winepulse + * Sat Aug 31 2013 Andreas Bierfert - 1.7.1-2 - fix icons with patch provided by Frank Dana (rhbz#997543)