user32: Further implementation of MNS_NOTIFYBYPOS.
[wine] / dlls / quartz / main.c
1 /*              DirectShow Base Functions (QUARTZ.DLL)
2  *
3  * Copyright 2002 Lionel Ulmer
4  *
5  * This file contains the (internal) driver registration functions,
6  * driver enumeration APIs and DirectDraw creation functions.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24 #include "wine/debug.h"
25
26 #include "quartz_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
29
30 static DWORD dll_ref = 0;
31
32 /* For the moment, do nothing here. */
33 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
34 {
35     switch(fdwReason) {
36         case DLL_PROCESS_ATTACH:
37             DisableThreadLibraryCalls(hInstDLL);
38             break;
39         case DLL_PROCESS_DETACH:
40             break;
41     }
42     return TRUE;
43 }
44
45 /******************************************************************************
46  * DirectShow ClassFactory
47  */
48 typedef struct {
49     IClassFactory ITF_IClassFactory;
50
51     LONG ref;
52     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
53 } IClassFactoryImpl;
54
55 struct object_creation_info
56 {
57     const CLSID *clsid;
58     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
59 };
60
61 static const struct object_creation_info object_creation[] =
62 {
63     { &CLSID_SeekingPassThru, SeekingPassThru_create },
64     { &CLSID_FilterGraph, FilterGraph_create },
65     { &CLSID_FilterGraphNoThread, FilterGraphNoThread_create },
66     { &CLSID_FilterMapper, FilterMapper_create },
67     { &CLSID_FilterMapper2, FilterMapper2_create },
68     { &CLSID_AsyncReader, AsyncReader_create },
69     { &CLSID_MemoryAllocator, StdMemAllocator_create },
70     { &CLSID_AviSplitter, AVISplitter_create },
71     { &CLSID_MPEG1Splitter, MPEGSplitter_create },
72     { &CLSID_VideoRenderer, VideoRenderer_create },
73     { &CLSID_NullRenderer, NullRenderer_create },
74     { &CLSID_VideoRendererDefault, VideoRendererDefault_create },
75     { &CLSID_DSoundRender, DSoundRender_create },
76     { &CLSID_AVIDec, AVIDec_create },
77     { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
78     { &CLSID_ACMWrapper, &ACMWrapper_create },
79     { &CLSID_WAVEParser, &WAVEParser_create }
80 };
81
82 static HRESULT WINAPI
83 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
84 {
85     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
86
87     if (IsEqualGUID(riid, &IID_IUnknown)
88         || IsEqualGUID(riid, &IID_IClassFactory))
89     {
90         IClassFactory_AddRef(iface);
91         *ppobj = This;
92         return S_OK;
93     }
94
95     *ppobj = NULL;
96     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
97     return E_NOINTERFACE;
98 }
99
100 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
101 {
102     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
103     return InterlockedIncrement(&This->ref);
104 }
105
106 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
107 {
108     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
109
110     ULONG ref = InterlockedDecrement(&This->ref);
111
112     if (ref == 0)
113         CoTaskMemFree(This);
114
115     return ref;
116 }
117
118
119 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
120                                           REFIID riid, LPVOID *ppobj)
121 {
122     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
123     HRESULT hres;
124     LPUNKNOWN punk;
125     
126     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
127
128     *ppobj = NULL;
129     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
130     if (SUCCEEDED(hres)) {
131         hres = IUnknown_QueryInterface(punk, riid, ppobj);
132         IUnknown_Release(punk);
133     }
134     return hres;
135 }
136
137 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
138 {
139     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
140     FIXME("(%p)->(%d),stub!\n",This,dolock);
141     return S_OK;
142 }
143
144 static const IClassFactoryVtbl DSCF_Vtbl =
145 {
146     DSCF_QueryInterface,
147     DSCF_AddRef,
148     DSCF_Release,
149     DSCF_CreateInstance,
150     DSCF_LockServer
151 };
152
153 /*******************************************************************************
154  * DllGetClassObject [QUARTZ.@]
155  * Retrieves class object from a DLL object
156  *
157  * NOTES
158  *    Docs say returns STDAPI
159  *
160  * PARAMS
161  *    rclsid [I] CLSID for the class object
162  *    riid   [I] Reference to identifier of interface for class object
163  *    ppv    [O] Address of variable to receive interface pointer for riid
164  *
165  * RETURNS
166  *    Success: S_OK
167  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
168  *             E_UNEXPECTED
169  */
170 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
171 {
172     unsigned int i;
173     IClassFactoryImpl *factory;
174     
175     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
176     
177     if ( !IsEqualGUID( &IID_IClassFactory, riid )
178          && ! IsEqualGUID( &IID_IUnknown, riid) )
179         return E_NOINTERFACE;
180
181     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
182     {
183         if (IsEqualGUID(object_creation[i].clsid, rclsid))
184             break;
185     }
186
187     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
188     {
189         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
190         return CLASS_E_CLASSNOTAVAILABLE;
191     }
192
193     factory = CoTaskMemAlloc(sizeof(*factory));
194     if (factory == NULL) return E_OUTOFMEMORY;
195
196     factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
197     factory->ref = 1;
198
199     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
200
201     *ppv = &(factory->ITF_IClassFactory);
202     return S_OK;
203 }
204
205 /***********************************************************************
206  *              DllCanUnloadNow (QUARTZ.@)
207  */
208 HRESULT WINAPI DllCanUnloadNow(void)
209 {
210     return dll_ref != 0 ? S_FALSE : S_OK;
211 }
212
213
214 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
215     { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } } , #name },
216
217 static const struct {
218         const GUID      riid;
219         const char      *name;
220 } InterfaceDesc[] =
221 {
222 #include "uuids.h"
223     { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
224 };
225
226 /***********************************************************************
227  *              qzdebugstr_guid (internal)
228  *
229  * Gives a text version of DirectShow GUIDs
230  */
231 const char * qzdebugstr_guid( const GUID * id )
232 {
233     int i;
234     char * name = NULL;
235
236     for (i=0;InterfaceDesc[i].name && !name;i++) {
237         if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
238     }
239     return debugstr_guid(id);
240 }
241
242 /***********************************************************************
243  *              qzdebugstr_State (internal)
244  *
245  * Gives a text version of the FILTER_STATE enumeration
246  */
247 const char * qzdebugstr_State(FILTER_STATE state)
248 {
249     switch (state)
250     {
251     case State_Stopped:
252         return "State_Stopped";
253     case State_Running:
254         return "State_Running";
255     case State_Paused:
256         return "State_Paused";
257     default:
258         return "State_Unknown";
259     }
260 }
261
262 LONG WINAPI AmpFactorToDB(LONG ampfactor)
263 {
264     FIXME("(%d) Stub!\n", ampfactor);
265     return 0;
266 }
267
268 LONG WINAPI DBToAmpFactor(LONG db)
269 {
270     FIXME("(%d) Stub!\n", db);
271     /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
272     if (db < -1000)
273         return 0;
274     return 100;
275 }
276
277 /***********************************************************************
278  *              AMGetErrorTextA (QUARTZ.@)
279  */
280 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
281 {
282     int len;
283     static const char format[] = "Error: 0x%x";
284     char error[MAX_ERROR_TEXT_LEN];
285
286     FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
287
288     if (!buffer) return 0;
289     wsprintfA(error, format, hr);
290     if ((len = lstrlenA(error)) >= maxlen) return 0; 
291     lstrcpyA(buffer, error);
292     return len;
293 }
294
295 /***********************************************************************
296  *              AMGetErrorTextW (QUARTZ.@)
297  */
298 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
299 {
300     int len;
301     static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
302     WCHAR error[MAX_ERROR_TEXT_LEN];
303
304     FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
305
306     if (!buffer) return 0;
307     wsprintfW(error, format, hr);
308     if ((len = lstrlenW(error)) >= maxlen) return 0; 
309     lstrcpyW(buffer, error);
310     return len;
311 }