Commit 9788fb69 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dmime: Initialize performance in Init rather than InitAudio.

parent 50b09dcf
...@@ -40,10 +40,9 @@ struct performance ...@@ -40,10 +40,9 @@ struct performance
IDirectMusicGraph IDirectMusicGraph_iface; IDirectMusicGraph IDirectMusicGraph_iface;
IDirectMusicTool IDirectMusicTool_iface; IDirectMusicTool IDirectMusicTool_iface;
LONG ref; LONG ref;
IDirectMusic8 *dmusic; IDirectMusic *dmusic;
IDirectSound *dsound; IDirectSound *dsound;
IDirectMusicGraph *pToolGraph; IDirectMusicGraph *pToolGraph;
DMUS_AUDIOPARAMS params;
BOOL fAutoDownload; BOOL fAutoDownload;
char cMasterGrooveLevel; char cMasterGrooveLevel;
float fMasterTempo; float fMasterTempo;
...@@ -314,14 +313,74 @@ static ULONG WINAPI performance_Release(IDirectMusicPerformance8 *iface) ...@@ -314,14 +313,74 @@ static ULONG WINAPI performance_Release(IDirectMusicPerformance8 *iface)
return ref; return ref;
} }
/* IDirectMusicPerformanceImpl IDirectMusicPerformance Interface part: */ static HRESULT performance_init_dsound(struct performance *This, HWND hwnd)
{
IDirectSound *dsound;
HRESULT hr;
if (FAILED(hr = DirectSoundCreate(NULL, &dsound, NULL))) return hr;
if (!hwnd) hwnd = GetForegroundWindow();
hr = IDirectSound_SetCooperativeLevel(dsound, hwnd, DSSCL_PRIORITY);
if (SUCCEEDED(hr)) This->dsound = dsound;
else IDirectSound_Release(dsound);
return hr;
}
static HRESULT performance_init_dmusic(struct performance *This, IDirectSound *dsound)
{
IDirectMusic *dmusic;
HRESULT hr;
if (FAILED(hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
&IID_IDirectMusic8, (void **)&dmusic)))
return hr;
hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
if (SUCCEEDED(hr)) This->dmusic = dmusic;
else IDirectSound_Release(dmusic);
return hr;
}
static HRESULT WINAPI performance_Init(IDirectMusicPerformance8 *iface, IDirectMusic **dmusic, static HRESULT WINAPI performance_Init(IDirectMusicPerformance8 *iface, IDirectMusic **dmusic,
IDirectSound *dsound, HWND hwnd) IDirectSound *dsound, HWND hwnd)
{ {
struct performance *This = impl_from_IDirectMusicPerformance8(iface);
HRESULT hr;
TRACE("(%p, %p, %p, %p)\n", iface, dmusic, dsound, hwnd); TRACE("(%p, %p, %p, %p)\n", iface, dmusic, dsound, hwnd);
return IDirectMusicPerformance8_InitAudio(iface, dmusic, dsound ? &dsound : NULL, hwnd, 0, 0, if (This->dmusic) return DMUS_E_ALREADY_INITED;
0, NULL);
if ((This->dsound = dsound)) IDirectMusic8_AddRef(This->dsound);
else if (FAILED(hr = performance_init_dsound(This, hwnd))) return hr;
if (dmusic && (This->dmusic = *dmusic)) IDirectMusic_AddRef(This->dmusic);
else if (FAILED(hr = performance_init_dmusic(This, This->dsound)))
{
IDirectMusicPerformance_CloseDown(iface);
return hr;
}
if (FAILED(hr = IDirectMusic_GetMasterClock(This->dmusic, NULL, &This->master_clock))
|| FAILED(hr = IDirectMusicPerformance8_GetTime(iface, &This->init_time, NULL)))
{
IDirectMusicPerformance_CloseDown(iface);
return hr;
}
PostMessageToProcessMsgThread(This, PROCESSMSG_START);
if (dmusic && !*dmusic)
{
*dmusic = This->dmusic;
IDirectMusic_AddRef(*dmusic);
}
return S_OK;
} }
static HRESULT WINAPI performance_PlaySegment(IDirectMusicPerformance8 *iface, IDirectMusicSegment *pSegment, static HRESULT WINAPI performance_PlaySegment(IDirectMusicPerformance8 *iface, IDirectMusicSegment *pSegment,
...@@ -900,6 +959,7 @@ static HRESULT WINAPI performance_CloseDown(IDirectMusicPerformance8 *iface) ...@@ -900,6 +959,7 @@ static HRESULT WINAPI performance_CloseDown(IDirectMusicPerformance8 *iface)
IDirectMusic8_Release(This->dmusic); IDirectMusic8_Release(This->dmusic);
This->dmusic = NULL; This->dmusic = NULL;
} }
return S_OK; return S_OK;
} }
...@@ -960,57 +1020,21 @@ static HRESULT WINAPI performance_InitAudio(IDirectMusicPerformance8 *iface, IDi ...@@ -960,57 +1020,21 @@ static HRESULT WINAPI performance_InitAudio(IDirectMusicPerformance8 *iface, IDi
TRACE("(%p, %p, %p, %p, %lx, %lu, %lx, %p)\n", This, dmusic, dsound, hwnd, default_path_type, TRACE("(%p, %p, %p, %p, %lx, %lu, %lx, %p)\n", This, dmusic, dsound, hwnd, default_path_type,
num_channels, flags, params); num_channels, flags, params);
if (This->dmusic) if (flags) FIXME("flags parameter not used\n");
return DMUS_E_ALREADY_INITED; if (params) FIXME("params parameter not used\n");
if (!dmusic || !*dmusic) {
hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic8,
(void **)&This->dmusic);
if (FAILED(hr))
return hr;
} else {
This->dmusic = (IDirectMusic8 *)*dmusic;
IDirectMusic8_AddRef(This->dmusic);
}
if (FAILED(hr = IDirectMusic_GetMasterClock(This->dmusic, NULL, &This->master_clock)))
goto error;
if (!dsound || !*dsound) { if (FAILED(hr = IDirectMusicPerformance8_Init(iface, dmusic && *dmusic ? dmusic : NULL,
hr = DirectSoundCreate8(NULL, (IDirectSound8 **)&This->dsound, NULL); dsound ? *dsound : NULL, hwnd)))
if (FAILED(hr)) return hr;
goto error;
hr = IDirectSound_SetCooperativeLevel(This->dsound, hwnd ? hwnd : GetForegroundWindow(),
DSSCL_PRIORITY);
if (FAILED(hr))
goto error;
} else {
This->dsound = *dsound;
IDirectSound_AddRef(This->dsound);
}
hr = IDirectMusic8_SetDirectSound(This->dmusic, This->dsound, NULL); if (default_path_type)
if (FAILED(hr)) {
goto error;
if (!params) {
This->params.dwSize = sizeof(DMUS_AUDIOPARAMS);
This->params.fInitNow = FALSE;
This->params.dwValidData = DMUS_AUDIOPARAMS_FEATURES | DMUS_AUDIOPARAMS_VOICES |
DMUS_AUDIOPARAMS_SAMPLERATE | DMUS_AUDIOPARAMS_DEFAULTSYNTH;
This->params.dwVoices = 64;
This->params.dwSampleRate = 22050;
This->params.dwFeatures = flags;
This->params.clsidDefaultSynth = CLSID_DirectMusicSynthSink;
} else
This->params = *params;
if (default_path_type) {
hr = IDirectMusicPerformance8_CreateStandardAudioPath(iface, default_path_type, hr = IDirectMusicPerformance8_CreateStandardAudioPath(iface, default_path_type,
num_channels, FALSE, &This->pDefaultPath); num_channels, FALSE, &This->pDefaultPath);
if (FAILED(hr)) { if (FAILED(hr))
IDirectMusic8_SetDirectSound(This->dmusic, NULL, NULL); {
goto error; IDirectMusicPerformance_CloseDown(iface);
return hr;
} }
} }
...@@ -1023,27 +1047,7 @@ static HRESULT WINAPI performance_InitAudio(IDirectMusicPerformance8 *iface, IDi ...@@ -1023,27 +1047,7 @@ static HRESULT WINAPI performance_InitAudio(IDirectMusicPerformance8 *iface, IDi
IDirectMusic_AddRef(*dmusic); IDirectMusic_AddRef(*dmusic);
} }
if (FAILED(hr = IDirectMusicPerformance8_GetTime(iface, &This->init_time, NULL))) return hr;
PostMessageToProcessMsgThread(This, PROCESSMSG_START);
return S_OK; return S_OK;
error:
if (This->master_clock)
{
IReferenceClock_Release(This->master_clock);
This->master_clock = NULL;
}
if (This->dsound) {
IDirectSound_Release(This->dsound);
This->dsound = NULL;
}
if (This->dmusic) {
IDirectMusic8_Release(This->dmusic);
This->dmusic = NULL;
}
return hr;
} }
static HRESULT WINAPI performance_PlaySegmentEx(IDirectMusicPerformance8 *iface, IUnknown *pSource, static HRESULT WINAPI performance_PlaySegmentEx(IDirectMusicPerformance8 *iface, IUnknown *pSource,
......
...@@ -2009,7 +2009,7 @@ static void test_performance_InitAudio(void) ...@@ -2009,7 +2009,7 @@ static void test_performance_InitAudio(void)
hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL); hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL);
ok(hr == S_OK, "InitAudio failed: %#lx\n", hr); ok(hr == S_OK, "InitAudio failed: %#lx\n", hr);
ref = get_refcount(dsound); ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %ld expected 2\n", ref); ok(ref == 2, "dsound ref count got %ld expected 2\n", ref);
ref = get_refcount(dmusic); ref = get_refcount(dmusic);
ok(ref == 2, "dmusic ref count got %ld expected 2\n", ref); ok(ref == 2, "dmusic ref count got %ld expected 2\n", ref);
destroy_performance(performance, dmusic, dsound); destroy_performance(performance, dmusic, dsound);
...@@ -2023,7 +2023,7 @@ static void test_performance_InitAudio(void) ...@@ -2023,7 +2023,7 @@ static void test_performance_InitAudio(void)
hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, NULL, NULL, 0, 64, 0, NULL); hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, NULL, NULL, 0, 64, 0, NULL);
ok(hr == S_OK, "InitAudio failed: %#lx\n", hr); ok(hr == S_OK, "InitAudio failed: %#lx\n", hr);
ref = get_refcount(dsound); ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %ld expected 2\n", ref); ok(ref == 2, "dsound ref count got %ld expected 2\n", ref);
ref = get_refcount(dmusic); ref = get_refcount(dmusic);
ok(ref == 2, "dmusic ref count got %ld expected 2\n", ref); ok(ref == 2, "dmusic ref count got %ld expected 2\n", ref);
destroy_performance(performance, dmusic, dsound); destroy_performance(performance, dmusic, dsound);
...@@ -2053,7 +2053,7 @@ static void test_performance_InitAudio(void) ...@@ -2053,7 +2053,7 @@ static void test_performance_InitAudio(void)
hr = IDirectMusicPort_SetNumChannelGroups(port, 1); hr = IDirectMusicPort_SetNumChannelGroups(port, 1);
ok(hr == S_OK, "SetNumChannelGroups failed: %#lx\n", hr); ok(hr == S_OK, "SetNumChannelGroups failed: %#lx\n", hr);
hr = IDirectMusicPerformance8_Init(performance, &dmusic, dsound, 0); hr = IDirectMusicPerformance8_Init(performance, &dmusic, dsound, 0);
todo_wine ok(hr == S_OK, "Init failed: %#lx\n", hr); ok(hr == S_OK, "Init failed: %#lx\n", hr);
destroy_performance(performance, dmusic, dsound); destroy_performance(performance, dmusic, dsound);
/* InitAudio with perf channel count not a multiple of 16 rounds up */ /* InitAudio with perf channel count not a multiple of 16 rounds up */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment