From d966413a49c8168e8cb9211e182e2c324d7249bf Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Fri, 14 Feb 2020 01:21:05 +0100 Subject: [PATCH] dmime: Split out the perf default port creation. Signed-off-by: Michael Stefaniuc Signed-off-by: Alexandre Julliard --- dlls/dmime/performance.c | 80 ++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/dlls/dmime/performance.c b/dlls/dmime/performance.c index c492ebdcb1f..b12247ea31d 100644 --- a/dlls/dmime/performance.c +++ b/dlls/dmime/performance.c @@ -624,39 +624,57 @@ static HRESULT WINAPI IDirectMusicPerformance8Impl_RemoveNotificationType(IDirec return S_OK; } -static HRESULT WINAPI IDirectMusicPerformance8Impl_AddPort(IDirectMusicPerformance8 *iface, - IDirectMusicPort *pPort) +static HRESULT perf_dmport_create(IDirectMusicPerformance8Impl *perf, DMUS_PORTPARAMS *params) { - IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface); - HRESULT hr = E_FAIL; + IDirectMusicPort *port; + GUID guid; + unsigned int i; + HRESULT hr; - FIXME("(%p, %p): stub\n", This, pPort); - if (!This->dmusic) - return DMUS_E_NOT_INIT; - if (NULL == pPort) { - GUID port_guid; - IDirectMusicPort* pDefaultPort = NULL; - DMUS_PORTPARAMS params; - hr = IDirectMusic8_GetDefaultPort(This->dmusic, &port_guid); - if (FAILED(hr)) return hr; - ZeroMemory(¶ms, sizeof(params)); - params.dwSize = sizeof(params); - params.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS | DMUS_PORTPARAMS_SHARE; - params.dwChannelGroups = 1; - params.fShare = TRUE; - hr = IDirectMusic8_CreatePort(This->dmusic, &port_guid, ¶ms, &pDefaultPort, NULL); - if (FAILED(hr)) return hr; - hr = IDirectMusicPort_Activate(pDefaultPort, TRUE); - if (FAILED(hr)) { IDirectMusicPort_Release(pDefaultPort); return hr; } - IDirectMusicPerformance8_AssignPChannelBlock(iface, 0, pDefaultPort, 1); - } else { - IDirectMusicPort_AddRef(pPort); - } - /** - * We should remember added Ports (for example using a list) - * and control if Port is registered for each api who use ports - */ - return S_OK; + if (FAILED(hr = IDirectMusic8_GetDefaultPort(perf->dmusic, &guid))) + return hr; + + params->dwSize = sizeof(params); + params->dwValidParams |= DMUS_PORTPARAMS_SHARE; + params->fShare = TRUE; + + if (FAILED(hr = IDirectMusic8_CreatePort(perf->dmusic, &guid, params, &port, NULL))) + return hr; + if (FAILED(hr = IDirectMusicPort_Activate(port, TRUE))) { + IDirectMusicPort_Release(port); + return hr; + } + for (i = 0; i < params->dwChannelGroups; i++) + pchannel_block_set(&perf->pchannels, i, port, i + 1, FALSE); + + return S_OK; +} + +static HRESULT WINAPI IDirectMusicPerformance8Impl_AddPort(IDirectMusicPerformance8 *iface, + IDirectMusicPort *port) +{ + IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface); + + FIXME("(%p, %p): semi-stub\n", This, port); + + if (!This->dmusic) + return DMUS_E_NOT_INIT; + + if (!port) { + DMUS_PORTPARAMS params = { + .dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS, + .dwChannelGroups = 1 + }; + + return perf_dmport_create(This, ¶ms); + } + + IDirectMusicPort_AddRef(port); + /** + * We should remember added Ports (for example using a list) + * and control if Port is registered for each api who use ports + */ + return S_OK; } static HRESULT WINAPI IDirectMusicPerformance8Impl_RemovePort(IDirectMusicPerformance8 *iface,