strmbase: do not lock in BaseOutputPinImpl_GetDeliveryBuffer the MemInputPin will...
[wine] / dlls / dmusic / dmusic_private.h
1 /* DirectMusic Private Include
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #ifndef __WINE_DMUSIC_PRIVATE_H
21 #define __WINE_DMUSIC_PRIVATE_H
22
23 #include <stdarg.h>
24
25 #define COBJMACROS
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnt.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32
33 #include "wine/debug.h"
34 #include "wine/list.h"
35 #include "wine/unicode.h"
36 #include "winreg.h"
37 #include "objbase.h"
38
39 #include "dmusici.h"
40 #include "dmusicf.h"
41 #include "dmusics.h"
42
43 /*****************************************************************************
44  * Interfaces
45  */
46 typedef struct IDirectMusic8Impl IDirectMusic8Impl;
47 typedef struct IDirectMusicBufferImpl IDirectMusicBufferImpl;
48 typedef struct IDirectMusicDownloadedInstrumentImpl IDirectMusicDownloadedInstrumentImpl;
49 typedef struct IDirectMusicDownloadImpl IDirectMusicDownloadImpl;
50 typedef struct IDirectMusicPortDownloadImpl IDirectMusicPortDownloadImpl;
51 typedef struct IDirectMusicPortImpl IDirectMusicPortImpl;
52 typedef struct IDirectMusicThruImpl IDirectMusicThruImpl;
53 typedef struct IReferenceClockImpl IReferenceClockImpl;
54
55 typedef struct IDirectMusicCollectionImpl IDirectMusicCollectionImpl;
56 typedef struct IDirectMusicInstrumentImpl IDirectMusicInstrumentImpl;
57
58
59 /*****************************************************************************
60  * Some stuff to make my life easier :=)
61  */
62  
63 /* some sort of aux. midi channel: big fake at the moment; accepts only priority
64    changes... more coming soon */
65 typedef struct DMUSIC_PRIVATE_MCHANNEL_ {
66         DWORD priority;
67 } DMUSIC_PRIVATE_MCHANNEL, *LPDMUSIC_PRIVATE_MCHANNEL;
68
69 /* some sort of aux. channel group: collection of 16 midi channels */
70 typedef struct DMUSIC_PRIVATE_CHANNEL_GROUP_ {
71         DMUSIC_PRIVATE_MCHANNEL channel[16]; /* 16 channels in a group */
72 } DMUSIC_PRIVATE_CHANNEL_GROUP, *LPDMUSIC_PRIVATE_CHANNEL_GROUP;
73
74
75 /*****************************************************************************
76  * ClassFactory
77  */
78
79 /* CLSID */
80 extern HRESULT WINAPI DMUSIC_CreateDirectMusicImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
81 extern HRESULT WINAPI DMUSIC_CreateDirectMusicCollectionImpl(LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
82
83 /* Internal */
84 extern HRESULT DMUSIC_CreateDirectMusicBufferImpl(LPDMUS_BUFFERDESC desc, LPVOID* ret_iface) DECLSPEC_HIDDEN;
85 extern HRESULT DMUSIC_CreateDirectMusicDownloadedInstrumentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
86 extern HRESULT DMUSIC_CreateDirectMusicDownloadImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
87 extern HRESULT DMUSIC_CreateReferenceClockImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
88 extern HRESULT DMUSIC_CreateDirectMusicInstrumentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
89
90 /*****************************************************************************
91  * IDirectMusic8Impl implementation structure
92  */
93 struct IDirectMusic8Impl {
94     /* IUnknown fields */
95     IDirectMusic8 IDirectMusic8_iface;
96     LONG ref;
97
98     /* IDirectMusicImpl fields */
99     IReferenceClockImpl* pMasterClock;
100     IDirectMusicPort** ppPorts;
101     int nrofports;
102 };
103
104 /*****************************************************************************
105  * IDirectMusicBufferImpl implementation structure
106  */
107 struct IDirectMusicBufferImpl {
108     /* IUnknown fields */
109     IDirectMusicBuffer IDirectMusicBuffer_iface;
110     LONG ref;
111
112     /* IDirectMusicBufferImpl fields */
113     GUID format;
114     DWORD size;
115     LPBYTE data;
116     DWORD write_pos;
117     REFERENCE_TIME start_time;
118 };
119
120 /*****************************************************************************
121  * IDirectMusicDownloadedInstrumentImpl implementation structure
122  */
123 struct IDirectMusicDownloadedInstrumentImpl {
124   /* IUnknown fields */
125   const IDirectMusicDownloadedInstrumentVtbl *lpVtbl;
126   LONG           ref;
127
128   /* IDirectMusicDownloadedInstrumentImpl fields */
129 };
130
131 /*****************************************************************************
132  * IDirectMusicDownloadImpl implementation structure
133  */
134 struct IDirectMusicDownloadImpl {
135   /* IUnknown fields */
136   const IDirectMusicDownloadVtbl *lpVtbl;
137   LONG           ref;
138
139   /* IDirectMusicDownloadImpl fields */
140 };
141
142 /*****************************************************************************
143  * IDirectMusicPortImpl implementation structure
144  */
145 struct IDirectMusicPortImpl {
146   /* IUnknown fields */
147   const IDirectMusicPortVtbl *lpVtbl;
148   const IDirectMusicPortDownloadVtbl *lpDownloadVtbl;
149   const IDirectMusicThruVtbl *lpThruVtbl;
150   LONG           ref;
151
152   /* IDirectMusicPortImpl fields */
153   IDirectSound* pDirectSound;
154   IReferenceClock* pLatencyClock;
155   BOOL fActive;
156   DMUS_PORTCAPS caps;
157   DMUS_PORTPARAMS params;
158   int nrofgroups;
159   DMUSIC_PRIVATE_CHANNEL_GROUP group[1];
160 };
161
162 /** Internal factory */
163 extern HRESULT DMUSIC_CreateDirectMusicPortImpl (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter, LPDMUS_PORTPARAMS pPortParams, LPDMUS_PORTCAPS pPortCaps) DECLSPEC_HIDDEN;
164
165 /*****************************************************************************
166  * IReferenceClockImpl implementation structure
167  */
168 struct IReferenceClockImpl {
169   /* IUnknown fields */
170   const IReferenceClockVtbl *lpVtbl;
171   LONG           ref;
172
173   /* IReferenceClockImpl fields */
174   REFERENCE_TIME rtTime;
175   DMUS_CLOCKINFO pClockInfo;
176 };
177
178 typedef struct _DMUS_PRIVATE_INSTRUMENT_ENTRY {
179         struct list entry; /* for listing elements */
180         IDirectMusicInstrument* pInstrument;
181 } DMUS_PRIVATE_INSTRUMENTENTRY, *LPDMUS_PRIVATE_INSTRUMENTENTRY;
182
183 typedef struct _DMUS_PRIVATE_POOLCUE {
184         struct list entry; /* for listing elements */
185 } DMUS_PRIVATE_POOLCUE, *LPDMUS_PRIVATE_POOLCUE;
186
187 /*****************************************************************************
188  * IDirectMusicCollectionImpl implementation structure
189  */
190 struct IDirectMusicCollectionImpl {
191   /* IUnknown fields */
192   const IUnknownVtbl *UnknownVtbl;
193   const IDirectMusicCollectionVtbl *CollectionVtbl;
194   const IDirectMusicObjectVtbl *ObjectVtbl;
195   const IPersistStreamVtbl *PersistStreamVtbl;
196   LONG           ref;
197
198   /* IDirectMusicCollectionImpl fields */
199   IStream *pStm; /* stream from which we load collection and later instruments */
200   LARGE_INTEGER liCollectionPosition; /* offset in a stream where collection was loaded from */
201   LARGE_INTEGER liWavePoolTablePosition; /* offset in a stream where wave pool table can be found */
202   LPDMUS_OBJECTDESC pDesc;
203   CHAR* szCopyright; /* FIXME: should probably placed somewhere else */
204   LPDLSHEADER pHeader;
205   /* pool table */
206   LPPOOLTABLE pPoolTable;
207   LPPOOLCUE pPoolCues;
208   /* instruments */
209   struct list Instruments;
210 };
211
212 /*****************************************************************************
213  * IDirectMusicInstrumentImpl implementation structure
214  */
215 struct IDirectMusicInstrumentImpl {
216   /* IUnknown fields */
217   IDirectMusicInstrument IDirectMusicInstrument_iface;
218   LONG           ref;
219
220   /* IDirectMusicInstrumentImpl fields */
221   LARGE_INTEGER liInstrumentPosition; /* offset in a stream where instrument chunk can be found */
222   LPGUID pInstrumentID;
223   LPINSTHEADER pHeader;
224   WCHAR wszName[DMUS_MAX_NAME];
225   /* instrument data */
226 };
227
228 static inline IDirectMusicInstrumentImpl *impl_from_IDirectMusicInstrument(IDirectMusicInstrument *iface)
229 {
230     return CONTAINING_RECORD(iface, IDirectMusicInstrumentImpl, IDirectMusicInstrument_iface);
231 }
232
233 /* custom :) */
234 extern HRESULT IDirectMusicInstrumentImpl_Custom_Load (LPDIRECTMUSICINSTRUMENT iface, LPSTREAM pStm) DECLSPEC_HIDDEN;
235
236 /**********************************************************************
237  * Dll lifetime tracking declaration for dmusic.dll
238  */
239 extern LONG DMUSIC_refCount DECLSPEC_HIDDEN;
240 static inline void DMUSIC_LockModule(void) { InterlockedIncrement( &DMUSIC_refCount ); }
241 static inline void DMUSIC_UnlockModule(void) { InterlockedDecrement( &DMUSIC_refCount ); }
242
243
244 /*****************************************************************************
245  * Misc.
246  */
247 /* my custom ICOM stuff */
248 #define ICOM_NAME_MULTI(impl,field,iface,name)  impl* const name=(impl*)((char*)(iface) - offsetof(impl,field))
249 #define ICOM_THIS_MULTI(impl,field,iface) ICOM_NAME_MULTI(impl,field,iface,This)
250  
251 /* for simpler reading */
252 typedef struct _DMUS_PRIVATE_CHUNK {
253         FOURCC fccID; /* FOURCC ID of the chunk */
254         DWORD dwSize; /* size of the chunk */
255 } DMUS_PRIVATE_CHUNK, *LPDMUS_PRIVATE_CHUNK;
256
257 /* used for generic dumping (copied from ddraw) */
258 typedef struct {
259     DWORD val;
260     const char* name;
261 } flag_info;
262
263 typedef struct {
264     const GUID *guid;
265     const char* name;
266 } guid_info;
267
268 /* used for initialising structs (primarily for DMUS_OBJECTDESC) */
269 #define DM_STRUCT_INIT(x)                               \
270         do {                                                            \
271                 memset((x), 0, sizeof(*(x)));   \
272                 (x)->dwSize = sizeof(*x);               \
273         } while (0)
274
275 #define FE(x) { x, #x } 
276 #define GE(x) { &x, #x }
277
278 /* dwPatch from MIDILOCALE */
279 extern DWORD MIDILOCALE2Patch (const MIDILOCALE *pLocale) DECLSPEC_HIDDEN;
280 /* MIDILOCALE from dwPatch */
281 extern void Patch2MIDILOCALE (DWORD dwPatch, LPMIDILOCALE pLocale) DECLSPEC_HIDDEN;
282
283 /* check whether the given DWORD is even (return 0) or odd (return 1) */
284 extern int even_or_odd (DWORD number) DECLSPEC_HIDDEN;
285 /* FOURCC to string conversion for debug messages */
286 extern const char *debugstr_fourcc (DWORD fourcc) DECLSPEC_HIDDEN;
287 /* returns name of given GUID */
288 extern const char *debugstr_dmguid (const GUID *id) DECLSPEC_HIDDEN;
289 /* Dump whole DMUS_OBJECTDESC struct */
290 extern void dump_DMUS_OBJECTDESC(LPDMUS_OBJECTDESC desc) DECLSPEC_HIDDEN;
291 /* Dump whole DMUS_PORTPARAMS struct */
292 extern void dump_DMUS_PORTPARAMS(LPDMUS_PORTPARAMS params) DECLSPEC_HIDDEN;
293
294 #endif /* __WINE_DMUSIC_PRIVATE_H */