kernel32: Add stub for SetThreadStackGuarantee.
[wine] / dlls / quartz / main.c
1 /*              DirectShow Base Functions (QUARTZ.DLL)
2  *
3  * Copyright 2002 Lionel Ulmer
4  *
5  * This library 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 library 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 library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "config.h"
21 #include "wine/debug.h"
22
23 #include "quartz_private.h"
24 #include "wine/unicode.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
27
28 extern HRESULT WINAPI QUARTZ_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
29 extern HRESULT WINAPI QUARTZ_DllCanUnloadNow(void) DECLSPEC_HIDDEN;
30 extern BOOL WINAPI QUARTZ_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
31
32 static DWORD dll_ref = 0;
33
34 /* For the moment, do nothing here. */
35 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
36 {
37     return QUARTZ_DllMain( hInstDLL, fdwReason, lpv );
38 }
39
40 static HRESULT SeekingPassThru_create(IUnknown *pUnkOuter, LPVOID *ppObj)
41 {
42     return PosPassThru_Construct(pUnkOuter,ppObj); /* from strmbase */
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_VideoMixingRenderer9, VMR9Impl_create },
75     { &CLSID_VideoRendererDefault, VideoRendererDefault_create },
76     { &CLSID_DSoundRender, DSoundRender_create },
77     { &CLSID_AudioRender, DSoundRender_create },
78     { &CLSID_AVIDec, AVIDec_create },
79     { &CLSID_SystemClock, QUARTZ_CreateSystemClock },
80     { &CLSID_ACMWrapper, ACMWrapper_create },
81     { &CLSID_WAVEParser, WAVEParser_create }
82 };
83
84 static HRESULT WINAPI
85 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
86 {
87     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
88
89     if (IsEqualGUID(riid, &IID_IUnknown)
90         || IsEqualGUID(riid, &IID_IClassFactory))
91     {
92         IClassFactory_AddRef(iface);
93         *ppobj = This;
94         return S_OK;
95     }
96
97     *ppobj = NULL;
98     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
99     return E_NOINTERFACE;
100 }
101
102 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
103 {
104     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
105     return InterlockedIncrement(&This->ref);
106 }
107
108 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
109 {
110     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
111
112     ULONG ref = InterlockedDecrement(&This->ref);
113
114     if (ref == 0)
115         CoTaskMemFree(This);
116
117     return ref;
118 }
119
120
121 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
122                                           REFIID riid, LPVOID *ppobj)
123 {
124     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
125     HRESULT hres;
126     LPUNKNOWN punk;
127     
128     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
129
130     *ppobj = NULL;
131     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
132     if (SUCCEEDED(hres)) {
133         hres = IUnknown_QueryInterface(punk, riid, ppobj);
134         IUnknown_Release(punk);
135     }
136     return hres;
137 }
138
139 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
140 {
141     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
142     FIXME("(%p)->(%d),stub!\n",This,dolock);
143     return S_OK;
144 }
145
146 static const IClassFactoryVtbl DSCF_Vtbl =
147 {
148     DSCF_QueryInterface,
149     DSCF_AddRef,
150     DSCF_Release,
151     DSCF_CreateInstance,
152     DSCF_LockServer
153 };
154
155 /*******************************************************************************
156  * DllGetClassObject [QUARTZ.@]
157  * Retrieves class object from a DLL object
158  *
159  * NOTES
160  *    Docs say returns STDAPI
161  *
162  * PARAMS
163  *    rclsid [I] CLSID for the class object
164  *    riid   [I] Reference to identifier of interface for class object
165  *    ppv    [O] Address of variable to receive interface pointer for riid
166  *
167  * RETURNS
168  *    Success: S_OK
169  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
170  *             E_UNEXPECTED
171  */
172 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
173 {
174     unsigned int i;
175
176     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
177
178     if (IsEqualGUID( &IID_IClassFactory, riid ) || IsEqualGUID( &IID_IUnknown, riid))
179     {
180         for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
181         {
182             if (IsEqualGUID(object_creation[i].clsid, rclsid))
183             {
184                 IClassFactoryImpl *factory = CoTaskMemAlloc(sizeof(*factory));
185                 if (factory == NULL) return E_OUTOFMEMORY;
186
187                 factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
188                 factory->ref = 1;
189
190                 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
191
192                 *ppv = &factory->ITF_IClassFactory;
193                 return S_OK;
194             }
195         }
196     }
197     return QUARTZ_DllGetClassObject( rclsid, riid, ppv );
198 }
199
200 /***********************************************************************
201  *              DllCanUnloadNow (QUARTZ.@)
202  */
203 HRESULT WINAPI DllCanUnloadNow(void)
204 {
205     if (dll_ref) return S_FALSE;
206     return QUARTZ_DllCanUnloadNow();
207 }
208
209
210 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
211     { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } } , #name },
212
213 static const struct {
214         const GUID      riid;
215         const char      *name;
216 } InterfaceDesc[] =
217 {
218 #include "uuids.h"
219     { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
220 };
221
222 /***********************************************************************
223  *              proxies
224  */
225 HRESULT CALLBACK ICaptureGraphBuilder_FindInterface_Proxy( ICaptureGraphBuilder *This,
226                                                            const GUID *pCategory,
227                                                            IBaseFilter *pf,
228                                                            REFIID riid,
229                                                            void **ppint )
230 {
231     return ICaptureGraphBuilder_RemoteFindInterface_Proxy( This, pCategory, pf,
232                                                            riid, (IUnknown **)ppint );
233 }
234
235 HRESULT __RPC_STUB ICaptureGraphBuilder_FindInterface_Stub( ICaptureGraphBuilder *This,
236                                                             const GUID *pCategory,
237                                                             IBaseFilter *pf,
238                                                             REFIID riid,
239                                                             IUnknown **ppint )
240 {
241     return ICaptureGraphBuilder_FindInterface( This, pCategory, pf, riid, (void **)ppint );
242 }
243
244 HRESULT CALLBACK ICaptureGraphBuilder2_FindInterface_Proxy( ICaptureGraphBuilder2 *This,
245                                                             const GUID *pCategory,
246                                                             const GUID *pType,
247                                                             IBaseFilter *pf,
248                                                             REFIID riid,
249                                                             void **ppint )
250 {
251     return ICaptureGraphBuilder2_RemoteFindInterface_Proxy( This, pCategory, pType,
252                                                             pf, riid, (IUnknown **)ppint );
253 }
254
255 HRESULT __RPC_STUB ICaptureGraphBuilder2_FindInterface_Stub( ICaptureGraphBuilder2 *This,
256                                                              const GUID *pCategory,
257                                                              const GUID *pType,
258                                                              IBaseFilter *pf,
259                                                              REFIID riid,
260                                                              IUnknown **ppint )
261 {
262     return ICaptureGraphBuilder2_FindInterface( This, pCategory, pType, pf, riid, (void **)ppint );
263 }
264
265 /***********************************************************************
266  *              qzdebugstr_guid (internal)
267  *
268  * Gives a text version of DirectShow GUIDs
269  */
270 const char * qzdebugstr_guid( const GUID * id )
271 {
272     int i;
273     char * name = NULL;
274
275     for (i=0;InterfaceDesc[i].name && !name;i++) {
276         if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
277     }
278     return debugstr_guid(id);
279 }
280
281 LONG WINAPI AmpFactorToDB(LONG ampfactor)
282 {
283     FIXME("(%d) Stub!\n", ampfactor);
284     return 0;
285 }
286
287 LONG WINAPI DBToAmpFactor(LONG db)
288 {
289     FIXME("(%d) Stub!\n", db);
290     /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
291     if (db < -1000)
292         return 0;
293     return 100;
294 }
295
296 /***********************************************************************
297  *              AMGetErrorTextA (QUARTZ.@)
298  */
299 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
300 {
301     DWORD res;
302     WCHAR errorW[MAX_ERROR_TEXT_LEN];
303
304     TRACE("(%x,%p,%d)\n", hr, buffer, maxlen);
305     if (!buffer)
306         return 0;
307
308     res = AMGetErrorTextW(hr, errorW, sizeof(errorW)/sizeof(*errorW));
309     return WideCharToMultiByte(CP_ACP, 0, errorW, res, buffer, maxlen, 0, 0);
310 }
311
312 /***********************************************************************
313  *              AMGetErrorTextW (QUARTZ.@)
314  */
315 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
316 {
317     unsigned int len;
318     static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
319     WCHAR error[MAX_ERROR_TEXT_LEN];
320
321     FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
322
323     if (!buffer) return 0;
324     wsprintfW(error, format, hr);
325     if ((len = strlenW(error)) >= maxlen) return 0;
326     lstrcpyW(buffer, error);
327     return len;
328 }