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