Rebase against 6dd84c53b55ecfa2e2735a914cb126fa0c4b23a5

This commit is contained in:
Alistair Leslie-Hughes 2019-12-21 14:28:42 +11:00
parent 5905340060
commit ae0343f628
3 changed files with 1 additions and 386 deletions

View File

@ -1,208 +0,0 @@
From a6c2b72782900c1c66852a8f936886e8df194ab2 Mon Sep 17 00:00:00 2001
From: Michael Stefaniuc <mstefani@winehq.org>
Date: Thu, 19 Dec 2019 23:20:18 +0100
Subject: [PATCH 1/3] dmime: Use a rbtree to store the PChannels of a
performance
The PChannel id is a 32bit, potentially random identifier and not an
array index.
Fixes also the handling of channel group "dwGroup" 0. As it is invalid
it is used to mark uninitialized PChannels.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=17766
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=24740
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=31562
Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
---
dlls/dmime/performance.c | 109 +++++++++++++++++++++++++++------------
1 file changed, 75 insertions(+), 34 deletions(-)
diff --git a/dlls/dmime/performance.c b/dlls/dmime/performance.c
index 615a3f8b14..2124c1fe35 100644
--- a/dlls/dmime/performance.c
+++ b/dlls/dmime/performance.c
@@ -19,10 +19,18 @@
*/
#include "dmime_private.h"
+#include "wine/heap.h"
+#include "wine/rbtree.h"
#include "dmobject.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmime);
+struct pchannel_block {
+ DWORD block_num; /* Block 0 is PChannels 0-15, Block 1 is PChannels 16-31, etc */
+ DMUSIC_PRIVATE_PCHANNEL pchannel[16];
+ struct wine_rb_entry entry;
+};
+
typedef struct IDirectMusicPerformance8Impl {
IDirectMusicPerformance8 IDirectMusicPerformance8_iface;
LONG ref;
@@ -35,7 +43,7 @@ typedef struct IDirectMusicPerformance8Impl {
float fMasterTempo;
long lMasterVolume;
/* performance channels */
- DMUSIC_PRIVATE_PCHANNEL PChannel[32];
+ struct wine_rb_tree pchannels;
/* IDirectMusicPerformance8Impl fields */
IDirectMusicAudioPath *pDefaultPath;
HANDLE hNotification;
@@ -192,6 +200,49 @@ static BOOL PostMessageToProcessMsgThread(IDirectMusicPerformance8Impl* This, UI
return PostThreadMessageA(This->procThreadId, iMsg, 0, 0);
}
+static int pchannel_block_compare(const void *key, const struct wine_rb_entry *entry)
+{
+ const struct pchannel_block *b = WINE_RB_ENTRY_VALUE(entry, const struct pchannel_block, entry);
+
+ return *(DWORD *)key - b->block_num;
+}
+
+static void pchannel_block_free(struct wine_rb_entry *entry, void *context)
+{
+ struct pchannel_block *b = WINE_RB_ENTRY_VALUE(entry, struct pchannel_block, entry);
+
+ heap_free(b);
+}
+
+static struct pchannel_block *pchannel_block_set(struct wine_rb_tree *tree, DWORD block_num,
+ IDirectMusicPort *port, DWORD group, BOOL only_set_new)
+{
+ struct pchannel_block *block;
+ struct wine_rb_entry *entry;
+ unsigned int i;
+
+ entry = wine_rb_get(tree, &block_num);
+ if (entry) {
+ block = WINE_RB_ENTRY_VALUE(entry, struct pchannel_block, entry);
+ if (only_set_new)
+ return block;
+ } else {
+ if (!(block = heap_alloc(sizeof(*block))))
+ return NULL;
+ block->block_num = block_num;
+ }
+
+ for (i = 0; i < 16; ++i) {
+ block->pchannel[i].port = port;
+ block->pchannel[i].group = group;
+ block->pchannel[i].channel = i;
+ }
+ if (!entry)
+ wine_rb_put(tree, &block->block_num, &block->entry);
+
+ return block;
+}
+
static inline IDirectMusicPerformance8Impl *impl_from_IDirectMusicPerformance8(IDirectMusicPerformance8 *iface)
{
return CONTAINING_RECORD(iface, IDirectMusicPerformance8Impl, IDirectMusicPerformance8_iface);
@@ -236,6 +287,7 @@ static ULONG WINAPI IDirectMusicPerformance8Impl_Release(IDirectMusicPerformance
TRACE("(%p): ReleaseRef to %d\n", This, ref);
if (ref == 0) {
+ wine_rb_destroy(&This->pchannels, pchannel_block_free, NULL);
This->safe.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&This->safe);
HeapFree(GetProcessHeap(), 0, This);
@@ -579,7 +631,6 @@ static HRESULT WINAPI IDirectMusicPerformance8Impl_AddPort(IDirectMusicPerforman
GUID port_guid;
IDirectMusicPort* pDefaultPort = NULL;
DMUS_PORTPARAMS params;
- int i, j;
hr = IDirectMusic8_GetDefaultPort(This->dmusic, &port_guid);
if (FAILED(hr)) return hr;
ZeroMemory(&params, sizeof(params));
@@ -591,15 +642,7 @@ static HRESULT WINAPI IDirectMusicPerformance8Impl_AddPort(IDirectMusicPerforman
if (FAILED(hr)) return hr;
hr = IDirectMusicPort_Activate(pDefaultPort, TRUE);
if (FAILED(hr)) { IDirectMusicPort_Release(pDefaultPort); return hr; }
- j = 0;
- for (i = 0; i < 16; ++i) {
- if (NULL == This->PChannel[i].port) {
- This->PChannel[i].port = pPort;
- This->PChannel[i].group = 0;
- This->PChannel[i].channel = j; /* FIXME: should this be assigned? */
- j++;
- }
- }
+ IDirectMusicPerformance8_AssignPChannelBlock(iface, 0, pDefaultPort, 1);
} else {
IDirectMusicPort_AddRef(pPort);
}
@@ -621,41 +664,38 @@ static HRESULT WINAPI IDirectMusicPerformance8Impl_RemovePort(IDirectMusicPerfor
}
static HRESULT WINAPI IDirectMusicPerformance8Impl_AssignPChannelBlock(IDirectMusicPerformance8 *iface,
- DWORD dwBlockNum, IDirectMusicPort *pPort, DWORD dwGroup)
+ DWORD block_num, IDirectMusicPort *port, DWORD group)
{
- IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
- int i, j, range /* min value in range */;
-
- FIXME("(%p, %d, %p, %d): semi-stub\n", This, dwBlockNum, pPort, dwGroup-1);
- if (NULL == pPort) return E_POINTER;
-
- range = 16 * dwBlockNum;
- j = 0;
- for (i = range; i < range+16; i++) {
- /*TRACE("Setting PChannel[%i] to port %p, group %ld, MIDI port %i\n", i, pPort, dwGroup-1, j); */
- This->PChannel[i].port = pPort;
- This->PChannel[i].group = dwGroup - 1; /* first index is always zero */
- This->PChannel[i].channel = j; /* FIXME: should this be assigned? */
- j++;
- }
- /*if (dwGroup > 2) return S_FALSE;*/
+ IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
- return S_OK;
+ FIXME("(%p, %d, %p, %d): semi-stub\n", This, block_num, port, group);
+
+ if (!port)
+ return E_POINTER;
+ if (block_num > MAXDWORD / 16)
+ return E_INVALIDARG;
+
+ pchannel_block_set(&This->pchannels, block_num, port, group, FALSE);
+
+ return S_OK;
}
static HRESULT WINAPI IDirectMusicPerformance8Impl_AssignPChannel(IDirectMusicPerformance8 *iface,
- DWORD PChannel, IDirectMusicPort *port, DWORD group, DWORD MChannel)
+ DWORD pchannel, IDirectMusicPort *port, DWORD group, DWORD channel)
{
IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
+ struct pchannel_block *block;
- TRACE("(%p)->(%d, %p, %d, %d)\n", This, PChannel, port, group, MChannel);
+ FIXME("(%p)->(%d, %p, %d, %d) semi-stub\n", This, pchannel, port, group, channel);
if (!port)
return E_POINTER;
- This->PChannel[PChannel].port = port;
- This->PChannel[PChannel].group = group;
- This->PChannel[PChannel].channel = MChannel;
+ block = pchannel_block_set(&This->pchannels, pchannel / 16, port, 0, TRUE);
+ if (block) {
+ block->pchannel[pchannel % 16].group = group;
+ block->pchannel[pchannel % 16].channel = channel;
+ }
return S_OK;
}
@@ -1211,6 +1251,7 @@ HRESULT WINAPI create_dmperformance(REFIID lpcGUID, void **ppobj)
obj->pDefaultPath = NULL;
InitializeCriticalSection(&obj->safe);
obj->safe.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDirectMusicPerformance8Impl*->safe");
+ wine_rb_init(&obj->pchannels, pchannel_block_compare);
obj->rtLatencyTime = 100; /* 100 ms TO FIX */
obj->dwBumperLength = 50; /* 50 ms default */
--
2.17.1

View File

@ -1,173 +0,0 @@
From bc158e53fb1df19ee8029c899bf2801f4a99ef33 Mon Sep 17 00:00:00 2001
From: Michael Stefaniuc <mstefani@winehq.org>
Date: Thu, 19 Dec 2019 23:20:19 +0100
Subject: [PATCH 2/3] dmime/tests: Add PChannel tests
Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
---
dlls/dmime/tests/performance.c | 126 ++++++++++++++++++++++++++++++++-
1 file changed, 124 insertions(+), 2 deletions(-)
diff --git a/dlls/dmime/tests/performance.c b/dlls/dmime/tests/performance.c
index 1d17e5200e..4c340252aa 100644
--- a/dlls/dmime/tests/performance.c
+++ b/dlls/dmime/tests/performance.c
@@ -100,10 +100,18 @@ static HRESULT test_InitAudio(void)
return hr;
port = NULL;
+ hr = IDirectMusicPerformance8_PChannelInfo(performance, 128, &port, NULL, NULL);
+ todo_wine ok(hr == E_INVALIDARG, "PChannelInfo failed, got %08x\n", hr);
+ hr = IDirectMusicPerformance8_PChannelInfo(performance, 127, &port, NULL, NULL);
+ ok(hr == S_OK, "PChannelInfo failed, got %08x\n", hr);
hr = IDirectMusicPerformance8_PChannelInfo(performance, 0, &port, NULL, NULL);
- ok(hr == S_OK, "Failed to call PChannelInfo (%x)\n", hr);
+ ok(hr == S_OK, "PChannelInfo failed, got %08x\n", hr);
ok(port != NULL, "IDirectMusicPort not set\n");
- if (hr == S_OK && port != NULL)
+ hr = IDirectMusicPerformance8_AssignPChannel(performance, 0, port, 0, 0);
+ todo_wine ok(hr == DMUS_E_AUDIOPATHS_IN_USE, "AssignPChannel failed (%08x)\n", hr);
+ hr = IDirectMusicPerformance8_AssignPChannelBlock(performance, 0, port, 0);
+ todo_wine ok(hr == DMUS_E_AUDIOPATHS_IN_USE, "AssignPChannelBlock failed (%08x)\n", hr);
+ if (port)
IDirectMusicPort_Release(port);
hr = IDirectMusicPerformance8_GetDefaultAudioPath(performance, &path);
@@ -120,6 +128,8 @@ static HRESULT test_InitAudio(void)
create_performance(&performance, NULL, NULL, FALSE);
hr = IDirectMusicPerformance8_InitAudio(performance, NULL, NULL, NULL, 0, 64, 0, NULL);
ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
+ hr = IDirectMusicPerformance8_PChannelInfo(performance, 0, &port, NULL, NULL);
+ todo_wine ok(hr == E_INVALIDARG, "PChannelInfo failed, got %08x\n", hr);
destroy_performance(performance, NULL, NULL);
/* Refcounts for auto generated dmusic and dsound */
@@ -322,6 +332,117 @@ static void test_createport(void)
IDirectMusicPerformance_Release(perf);
}
+static void test_pchannel(void)
+{
+ IDirectMusicPerformance8 *perf;
+ IDirectMusicPort *port = NULL, *port2;
+ DWORD channel, group;
+ unsigned int i;
+ HRESULT hr;
+
+ create_performance(&perf, NULL, NULL, FALSE);
+ hr = IDirectMusicPerformance8_Init(perf, NULL, NULL, NULL);
+ ok(hr == S_OK, "Init failed: %08x\n", hr);
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, 0, &port, NULL, NULL);
+ todo_wine ok(hr == E_INVALIDARG && !port, "PChannelInfo failed, got %08x, %p\n", hr, port);
+
+ /* Add default port. Sets PChannels 0-15 to the corresponding channels in group 1 */
+ hr = IDirectMusicPerformance8_AddPort(perf, NULL);
+ ok(hr == S_OK, "AddPort of default port failed: %08x\n", hr);
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, 0, NULL, NULL, NULL);
+ ok(hr == S_OK, "PChannelInfo failed, got %08x\n", hr);
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, 0, &port, NULL, NULL);
+ ok(hr == S_OK && port, "PChannelInfo failed, got %08x, %p\n", hr, port);
+ for (i = 1; i < 16; i++) {
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, &group, &channel);
+ todo_wine ok(hr == S_OK && port == port2 && group == 1 && channel == i,
+ "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
+ IDirectMusicPort_Release(port2);
+ }
+
+ /* Unset PChannels fail to retrieve */
+ todo_wine {
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, 16, &port2, NULL, NULL);
+ ok(hr == E_INVALIDARG, "PChannelInfo failed, got %08x, %p\n", hr, port);
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, MAXDWORD - 16, &port2, NULL, NULL);
+ ok(hr == E_INVALIDARG, "PChannelInfo failed, got %08x, %p\n", hr, port);
+ }
+
+ /* Channel group 0 can be set just fine */
+ hr = IDirectMusicPerformance8_AssignPChannel(perf, 0, port, 0, 0);
+ ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
+ hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, 0, port, 0);
+ ok(hr == S_OK, "AssignPChannelBlock failed, got %08x\n", hr);
+ for (i = 1; i < 16; i++) {
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, &group, &channel);
+ todo_wine ok(hr == S_OK && port == port2 && group == 0 && channel == i,
+ "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
+ IDirectMusicPort_Release(port2);
+ }
+
+ /* Last PChannel Block can be set only individually but not read */
+ hr = IDirectMusicPerformance8_AssignPChannel(perf, MAXDWORD, port, 0, 3);
+ ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
+ port2 = (IDirectMusicPort *)0xdeadbeef;
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, MAXDWORD, &port2, NULL, NULL);
+ todo_wine ok(hr == E_INVALIDARG && port2 == (IDirectMusicPort *)0xdeadbeef,
+ "PChannelInfo failed, got %08x, %p\n", hr, port2);
+ hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, MAXDWORD, port, 0);
+ ok(hr == E_INVALIDARG, "AssignPChannelBlock failed, got %08x\n", hr);
+ hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, MAXDWORD / 16, port, 1);
+ todo_wine ok(hr == E_INVALIDARG, "AssignPChannelBlock failed, got %08x\n", hr);
+ for (i = MAXDWORD - 15; i < MAXDWORD; i++) {
+ hr = IDirectMusicPerformance8_AssignPChannel(perf, i, port, 0, 0);
+ ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, NULL, NULL);
+ todo_wine ok(hr == E_INVALIDARG && port2 == (IDirectMusicPort *)0xdeadbeef,
+ "PChannelInfo failed, got %08x, %p\n", hr, port2);
+ }
+
+ /* Second to last PChannel Block can be set only individually and read */
+ hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, MAXDWORD / 16 - 1, port, 1);
+ todo_wine ok(hr == E_INVALIDARG, "AssignPChannelBlock failed, got %08x\n", hr);
+ for (i = MAXDWORD - 31; i < MAXDWORD - 15; i++) {
+ hr = IDirectMusicPerformance8_AssignPChannel(perf, i, port, 1, 7);
+ ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, &group, &channel);
+ todo_wine ok(hr == S_OK && port2 == port && group == 1 && channel == 7,
+ "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
+ IDirectMusicPort_Release(port2);
+ }
+
+ /* Third to last PChannel Block behaves normal */
+ hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, MAXDWORD / 16 - 2, port, 0);
+ ok(hr == S_OK, "AssignPChannelBlock failed, got %08x\n", hr);
+ for (i = MAXDWORD - 47; i < MAXDWORD - 31; i++) {
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, &group, &channel);
+ todo_wine ok(hr == S_OK && port2 == port && group == 0 && channel == i % 16,
+ "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
+ IDirectMusicPort_Release(port2);
+ }
+
+ /* One PChannel set in a Block, rest is initialized too */
+ hr = IDirectMusicPerformance8_AssignPChannel(perf, 4711, port, 1, 13);
+ ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, 4711, &port2, &group, &channel);
+ todo_wine ok(hr == S_OK && port2 == port && group == 1 && channel == 13,
+ "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
+ IDirectMusicPort_Release(port2);
+ group = channel = 0xdeadbeef;
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, 4712, &port2, &group, &channel);
+ todo_wine ok(hr == S_OK && port2 == port && group == 0 && channel == 8,
+ "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
+ IDirectMusicPort_Release(port2);
+ group = channel = 0xdeadbeef;
+ hr = IDirectMusicPerformance8_PChannelInfo(perf, 4719, &port2, &group, &channel);
+ todo_wine ok(hr == S_OK && port2 == port && group == 0 && channel == 15,
+ "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
+ IDirectMusicPort_Release(port2);
+
+ IDirectMusicPort_Release(port);
+ destroy_performance(perf, NULL, NULL);
+}
+
static void test_COM(void)
{
IDirectMusicPerformance *dmp = (IDirectMusicPerformance*)0xdeadbeef;
@@ -504,6 +625,7 @@ START_TEST( performance )
test_COM();
test_createport();
+ test_pchannel();
test_notification_type();
CoUninitialize();
--
2.17.1

View File

@ -52,7 +52,7 @@ usage()
# Get the upstream commit sha
upstream_commit()
{
echo "fa66c1b3011a32036b42c436320212aa3b30ae3f"
echo "6dd84c53b55ecfa2e2735a914cb126fa0c4b23a5"
}
# Show version information
@ -3172,12 +3172,8 @@ fi
# | * dlls/dmime/performance.c, dlls/dmime/tests/performance.c
# |
if test "$enable_dmime_PChannel_range" -eq 1; then
patch_apply dmime-PChannel-range/0001-dmime-Use-a-rbtree-to-store-the-PChannels-of-a-perfo.patch
patch_apply dmime-PChannel-range/0002-dmime-tests-Add-PChannel-tests.patch
patch_apply dmime-PChannel-range/0003-dmime-Implement-IDirectMusicPerformance8_PChannelInf.patch
(
printf '%s\n' '+ { "Michael Stefaniuc", "dmime: Use a rbtree to store the PChannels of a performance.", 1 },';
printf '%s\n' '+ { "Michael Stefaniuc", "dmime/tests: Add PChannel tests.", 1 },';
printf '%s\n' '+ { "Michael Stefaniuc", "dmime: Implement IDirectMusicPerformance8_PChannelInfo().", 1 },';
) >> "$patchlist"
fi