TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / dswave / dswave_main.c
blobb02f3720d0ea5e4778092d4c850fffc9490e5b95
1 /* DirectMusic Wave Main
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include <stdio.h>
24 #include <stdarg.h>
26 #define COBJMACROS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnt.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winreg.h"
34 #include "objbase.h"
35 #include "rpcproxy.h"
36 #include "initguid.h"
37 #include "dmusici.h"
39 #include "dswave_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dswave);
43 static HINSTANCE instance;
44 LONG DSWAVE_refCount = 0;
46 typedef struct {
47 IClassFactory IClassFactory_iface;
48 } IClassFactoryImpl;
50 /******************************************************************
51 * DirectMusicWave ClassFactory
53 static HRESULT WINAPI WaveCF_QueryInterface(IClassFactory * iface, REFIID riid, void **ppv)
55 if (ppv == NULL)
56 return E_POINTER;
58 if (IsEqualGUID(&IID_IUnknown, riid))
59 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
60 else if (IsEqualGUID(&IID_IClassFactory, riid))
61 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
62 else {
63 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
64 *ppv = NULL;
65 return E_NOINTERFACE;
68 *ppv = iface;
69 IUnknown_AddRef((IUnknown*)*ppv);
70 return S_OK;
73 static ULONG WINAPI WaveCF_AddRef(IClassFactory * iface)
75 DSWAVE_LockModule();
77 return 2; /* non-heap based object */
80 static ULONG WINAPI WaveCF_Release(IClassFactory * iface)
82 DSWAVE_UnlockModule();
84 return 1; /* non-heap based object */
87 static HRESULT WINAPI WaveCF_CreateInstance(IClassFactory * iface, IUnknown *outer_unk, REFIID riid,
88 void **ret_iface)
90 TRACE ("(%p, %s, %p)\n", outer_unk, debugstr_dmguid(riid), ret_iface);
92 if (outer_unk) {
93 *ret_iface = NULL;
94 return CLASS_E_NOAGGREGATION;
97 return create_dswave(riid, ret_iface);
100 static HRESULT WINAPI WaveCF_LockServer(IClassFactory * iface, BOOL dolock)
102 TRACE("(%d)\n", dolock);
104 if (dolock)
105 DSWAVE_LockModule();
106 else
107 DSWAVE_UnlockModule();
109 return S_OK;
112 static const IClassFactoryVtbl WaveCF_Vtbl = {
113 WaveCF_QueryInterface,
114 WaveCF_AddRef,
115 WaveCF_Release,
116 WaveCF_CreateInstance,
117 WaveCF_LockServer
120 static IClassFactoryImpl Wave_CF = {{&WaveCF_Vtbl}};
122 /******************************************************************
123 * DllMain
127 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
128 if (fdwReason == DLL_PROCESS_ATTACH) {
129 instance = hinstDLL;
130 DisableThreadLibraryCalls(hinstDLL);
133 return TRUE;
137 /******************************************************************
138 * DllCanUnloadNow (DSWAVE.@)
142 HRESULT WINAPI DllCanUnloadNow(void)
144 return DSWAVE_refCount != 0 ? S_FALSE : S_OK;
148 /******************************************************************
149 * DllGetClassObject (DSWAVE.@)
153 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
155 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
156 if (IsEqualCLSID (rclsid, &CLSID_DirectSoundWave) && IsEqualIID (riid, &IID_IClassFactory)) {
157 *ppv = &Wave_CF;
158 IClassFactory_AddRef((IClassFactory*)*ppv);
159 return S_OK;
162 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
163 return CLASS_E_CLASSNOTAVAILABLE;
166 /***********************************************************************
167 * DllRegisterServer (DSWAVE.@)
169 HRESULT WINAPI DllRegisterServer(void)
171 return __wine_register_resources( instance );
174 /***********************************************************************
175 * DllUnregisterServer (DSWAVE.@)
177 HRESULT WINAPI DllUnregisterServer(void)
179 return __wine_unregister_resources( instance );
182 /******************************************************************
183 * Helper functions
187 /* FOURCC to string conversion for debug messages */
188 const char *debugstr_fourcc (DWORD fourcc) {
189 if (!fourcc) return "'null'";
190 return wine_dbg_sprintf ("\'%c%c%c%c\'",
191 (char)(fourcc), (char)(fourcc >> 8),
192 (char)(fourcc >> 16), (char)(fourcc >> 24));
195 /* DMUS_VERSION struct to string conversion for debug messages */
196 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
197 if (!version) return "'null'";
198 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
199 (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF),
200 (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
203 /* returns name of given GUID */
204 const char *debugstr_dmguid (const GUID *id) {
205 static const guid_info guids[] = {
206 /* CLSIDs */
207 GE(CLSID_AudioVBScript),
208 GE(CLSID_DirectMusic),
209 GE(CLSID_DirectMusicAudioPathConfig),
210 GE(CLSID_DirectMusicAuditionTrack),
211 GE(CLSID_DirectMusicBand),
212 GE(CLSID_DirectMusicBandTrack),
213 GE(CLSID_DirectMusicChordMapTrack),
214 GE(CLSID_DirectMusicChordMap),
215 GE(CLSID_DirectMusicChordTrack),
216 GE(CLSID_DirectMusicCollection),
217 GE(CLSID_DirectMusicCommandTrack),
218 GE(CLSID_DirectMusicComposer),
219 GE(CLSID_DirectMusicContainer),
220 GE(CLSID_DirectMusicGraph),
221 GE(CLSID_DirectMusicLoader),
222 GE(CLSID_DirectMusicLyricsTrack),
223 GE(CLSID_DirectMusicMarkerTrack),
224 GE(CLSID_DirectMusicMelodyFormulationTrack),
225 GE(CLSID_DirectMusicMotifTrack),
226 GE(CLSID_DirectMusicMuteTrack),
227 GE(CLSID_DirectMusicParamControlTrack),
228 GE(CLSID_DirectMusicPatternTrack),
229 GE(CLSID_DirectMusicPerformance),
230 GE(CLSID_DirectMusicScript),
231 GE(CLSID_DirectMusicScriptAutoImpSegment),
232 GE(CLSID_DirectMusicScriptAutoImpPerformance),
233 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
234 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
235 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
236 GE(CLSID_DirectMusicScriptAutoImpSong),
237 GE(CLSID_DirectMusicScriptSourceCodeLoader),
238 GE(CLSID_DirectMusicScriptTrack),
239 GE(CLSID_DirectMusicSection),
240 GE(CLSID_DirectMusicSegment),
241 GE(CLSID_DirectMusicSegmentState),
242 GE(CLSID_DirectMusicSegmentTriggerTrack),
243 GE(CLSID_DirectMusicSegTriggerTrack),
244 GE(CLSID_DirectMusicSeqTrack),
245 GE(CLSID_DirectMusicSignPostTrack),
246 GE(CLSID_DirectMusicSong),
247 GE(CLSID_DirectMusicStyle),
248 GE(CLSID_DirectMusicStyleTrack),
249 GE(CLSID_DirectMusicSynth),
250 GE(CLSID_DirectMusicSynthSink),
251 GE(CLSID_DirectMusicSysExTrack),
252 GE(CLSID_DirectMusicTemplate),
253 GE(CLSID_DirectMusicTempoTrack),
254 GE(CLSID_DirectMusicTimeSigTrack),
255 GE(CLSID_DirectMusicWaveTrack),
256 GE(CLSID_DirectSoundWave),
257 /* IIDs */
258 GE(IID_IDirectMusic),
259 GE(IID_IDirectMusic2),
260 GE(IID_IDirectMusic8),
261 GE(IID_IDirectMusicAudioPath),
262 GE(IID_IDirectMusicBand),
263 GE(IID_IDirectMusicBuffer),
264 GE(IID_IDirectMusicChordMap),
265 GE(IID_IDirectMusicCollection),
266 GE(IID_IDirectMusicComposer),
267 GE(IID_IDirectMusicContainer),
268 GE(IID_IDirectMusicDownload),
269 GE(IID_IDirectMusicDownloadedInstrument),
270 GE(IID_IDirectMusicGetLoader),
271 GE(IID_IDirectMusicGraph),
272 GE(IID_IDirectMusicInstrument),
273 GE(IID_IDirectMusicLoader),
274 GE(IID_IDirectMusicLoader8),
275 GE(IID_IDirectMusicObject),
276 GE(IID_IDirectMusicPatternTrack),
277 GE(IID_IDirectMusicPerformance),
278 GE(IID_IDirectMusicPerformance2),
279 GE(IID_IDirectMusicPerformance8),
280 GE(IID_IDirectMusicPort),
281 GE(IID_IDirectMusicPortDownload),
282 GE(IID_IDirectMusicScript),
283 GE(IID_IDirectMusicSegment),
284 GE(IID_IDirectMusicSegment2),
285 GE(IID_IDirectMusicSegment8),
286 GE(IID_IDirectMusicSegmentState),
287 GE(IID_IDirectMusicSegmentState8),
288 GE(IID_IDirectMusicStyle),
289 GE(IID_IDirectMusicStyle8),
290 GE(IID_IDirectMusicSynth),
291 GE(IID_IDirectMusicSynth8),
292 GE(IID_IDirectMusicSynthSink),
293 GE(IID_IDirectMusicThru),
294 GE(IID_IDirectMusicTool),
295 GE(IID_IDirectMusicTool8),
296 GE(IID_IDirectMusicTrack),
297 GE(IID_IDirectMusicTrack8),
298 GE(IID_IUnknown),
299 GE(IID_IPersistStream),
300 GE(IID_IStream),
301 GE(IID_IClassFactory),
302 /* GUIDs */
303 GE(GUID_DirectMusicAllTypes),
304 GE(GUID_NOTIFICATION_CHORD),
305 GE(GUID_NOTIFICATION_COMMAND),
306 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
307 GE(GUID_NOTIFICATION_PERFORMANCE),
308 GE(GUID_NOTIFICATION_RECOMPOSE),
309 GE(GUID_NOTIFICATION_SEGMENT),
310 GE(GUID_BandParam),
311 GE(GUID_ChordParam),
312 GE(GUID_CommandParam),
313 GE(GUID_CommandParam2),
314 GE(GUID_CommandParamNext),
315 GE(GUID_IDirectMusicBand),
316 GE(GUID_IDirectMusicChordMap),
317 GE(GUID_IDirectMusicStyle),
318 GE(GUID_MuteParam),
319 GE(GUID_Play_Marker),
320 GE(GUID_RhythmParam),
321 GE(GUID_TempoParam),
322 GE(GUID_TimeSignature),
323 GE(GUID_Valid_Start_Time),
324 GE(GUID_Clear_All_Bands),
325 GE(GUID_ConnectToDLSCollection),
326 GE(GUID_Disable_Auto_Download),
327 GE(GUID_DisableTempo),
328 GE(GUID_DisableTimeSig),
329 GE(GUID_Download),
330 GE(GUID_DownloadToAudioPath),
331 GE(GUID_Enable_Auto_Download),
332 GE(GUID_EnableTempo),
333 GE(GUID_EnableTimeSig),
334 GE(GUID_IgnoreBankSelectForGM),
335 GE(GUID_SeedVariations),
336 GE(GUID_StandardMIDIFile),
337 GE(GUID_Unload),
338 GE(GUID_UnloadFromAudioPath),
339 GE(GUID_Variations),
340 GE(GUID_PerfMasterTempo),
341 GE(GUID_PerfMasterVolume),
342 GE(GUID_PerfMasterGrooveLevel),
343 GE(GUID_PerfAutoDownload),
344 GE(GUID_DefaultGMCollection),
345 GE(GUID_Synth_Default),
346 GE(GUID_Buffer_Reverb),
347 GE(GUID_Buffer_EnvReverb),
348 GE(GUID_Buffer_Stereo),
349 GE(GUID_Buffer_3D_Dry),
350 GE(GUID_Buffer_Mono),
351 GE(GUID_DMUS_PROP_GM_Hardware),
352 GE(GUID_DMUS_PROP_GS_Capable),
353 GE(GUID_DMUS_PROP_GS_Hardware),
354 GE(GUID_DMUS_PROP_DLS1),
355 GE(GUID_DMUS_PROP_DLS2),
356 GE(GUID_DMUS_PROP_Effects),
357 GE(GUID_DMUS_PROP_INSTRUMENT2),
358 GE(GUID_DMUS_PROP_LegacyCaps),
359 GE(GUID_DMUS_PROP_MemorySize),
360 GE(GUID_DMUS_PROP_SampleMemorySize),
361 GE(GUID_DMUS_PROP_SamplePlaybackRate),
362 GE(GUID_DMUS_PROP_SetSynthSink),
363 GE(GUID_DMUS_PROP_SinkUsesDSound),
364 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
365 GE(GUID_DMUS_PROP_SynthSink_WAVE),
366 GE(GUID_DMUS_PROP_Volume),
367 GE(GUID_DMUS_PROP_WavesReverb),
368 GE(GUID_DMUS_PROP_WriteLatency),
369 GE(GUID_DMUS_PROP_WritePeriod),
370 GE(GUID_DMUS_PROP_XG_Capable),
371 GE(GUID_DMUS_PROP_XG_Hardware)
374 unsigned int i;
376 if (!id) return "(null)";
378 for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
379 if (IsEqualGUID(id, guids[i].guid))
380 return guids[i].name;
382 /* if we didn't find it, act like standard debugstr_guid */
383 return debugstr_guid(id);
386 /* generic flag-dumping function */
387 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
388 char buffer[128] = "", *ptr = &buffer[0];
389 unsigned int i;
390 int size = sizeof(buffer);
392 for (i=0; i < num_names; i++)
394 if ((flags & names[i].val) || /* standard flag*/
395 ((!flags) && (!names[i].val))) { /* zero value only */
396 int cnt = snprintf(ptr, size, "%s ", names[i].name);
397 if (cnt < 0 || cnt >= size) break;
398 size -= cnt;
399 ptr += cnt;
403 return wine_dbg_sprintf("%s", buffer);
406 /* dump DMUS_OBJ flags */
407 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
408 static const flag_info flags[] = {
409 FE(DMUS_OBJ_OBJECT),
410 FE(DMUS_OBJ_CLASS),
411 FE(DMUS_OBJ_NAME),
412 FE(DMUS_OBJ_CATEGORY),
413 FE(DMUS_OBJ_FILENAME),
414 FE(DMUS_OBJ_FULLPATH),
415 FE(DMUS_OBJ_URL),
416 FE(DMUS_OBJ_VERSION),
417 FE(DMUS_OBJ_DATE),
418 FE(DMUS_OBJ_LOADED),
419 FE(DMUS_OBJ_MEMORY),
420 FE(DMUS_OBJ_STREAM)
422 return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
425 /* dump whole DMUS_OBJECTDESC struct */
426 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
427 if (pDesc) {
428 char buffer[1024] = "", *ptr = &buffer[0];
430 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
431 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
432 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
433 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
434 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
435 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
436 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
437 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
438 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
439 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
440 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n - pbMemData = %p\n",
441 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
442 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
444 return wine_dbg_sprintf("%s", buffer);
445 } else {
446 return wine_dbg_sprintf("(NULL)");