Assorted spelling fixes.
[wine] / dlls / qcap / qcap_main.c
1 /*
2  * Qcap implementation, dllentry points
3  *
4  * Copyright (C) 2003 Dominik Strasser
5  * Copyright (C) 2005 Rolf Kalbermatter
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 #include "config.h"
22
23 #include <assert.h>
24 #include <stdio.h>
25 #include <stdarg.h>
26
27 #define COBJMACROS
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winerror.h"
34 #include "objbase.h"
35 #include "uuids.h"
36 #include "strmif.h"
37
38 #include "dllsetup.h"
39 #include "qcap_main.h"
40
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(qcap);
45
46 static LONG objects_ref = 0;
47 static LONG server_locks = 0;
48
49 static const WCHAR wAudioCaptFilter[] =
50 {'A','u','d','i','o',' ','C','a','p','t','u','r','e',' ','F','i','l','t','e','r',0};
51 static const WCHAR wAVICompressor[] =
52 {'A','V','I',' ','C','o','m','p','r','e','s','s','o','r',0};
53 static const WCHAR wVFWCaptFilter[] =
54 {'V','F','W',' ','C','a','p','t','u','r','e',' ','F','i','l','t','e','r',0};
55 static const WCHAR wVFWCaptFilterProp[] =
56 {'V','F','W',' ','C','a','p','t','u','r','e',' ','F','i','l','t','e','r',' ',
57  'P','r','o','p','e','r','t','y',' ','P','a','g','e',0};
58 static const WCHAR wAVIMux[] =
59 {'A','V','I',' ','m','u','x',0};
60 static const WCHAR wAVIMuxPropPage[] =
61 {'A','V','I',' ','m','u','x',' ','P','r','o','p','e','r','t','y',' ','P','a','g','e',0};
62 static const WCHAR wAVIMuxPropPage1[] =
63 {'A','V','I',' ','m','u','x',' ','P','r','o','p','e','r','t','y',' ','P','a','g','e','1',0};
64 static const WCHAR wFileWriter[] =
65 {'F','i','l','e',' ','W','r','i','t','e','r',0};
66 static const WCHAR wCaptGraphBuilder[] =
67 {'C','a','p','t','u','r','e',' ','G','r','a','p','h',' ','B','u','i','l','d','e','r',0};
68 static const WCHAR wCaptGraphBuilder2[] =
69 {'C','a','p','t','u','r','e',' ','G','r','a','p','h',' ','B','u','i','l','d','e','r','2',0};
70 static const WCHAR wInfPinTeeFilter[] =
71 {'I','n','f','i','n','i','t','e',' ','P','i','n',' ','T','e','e',' ','F','i',
72  'l','t','e','r',0};
73 static const WCHAR wSmartTeeFilter[] =
74 {'S','m','a','r','t',' ','T','e','e',' ','F','i','l','t','e','r',0};
75 static const WCHAR wAudioInMixerProp[] =
76 {'A','u','d','i','o','I','n','p','u','t','M','i','x','e','r',' ','P','r','o',
77  'p','e','r','t','y',' ','P','a','g','e',0};
78  
79 static CFactoryTemplate const g_cTemplates[] = {
80 /*
81     {
82         wAudioCaptureFilter, 
83         &CLSID_AudioCaptureFilter,
84         QCAP_createAudioCaptureFilter,
85         NULL,
86         NULL
87     },{
88         wAVICompressor, 
89         &CLSID_AVICompressor, 
90         QCAP_createAVICompressor,
91         NULL,
92         NULL
93     },*/{
94         wVFWCaptFilter,
95         &CLSID_VfwCapture,
96         QCAP_createVFWCaptureFilter,
97         NULL,
98         NULL
99     },/*{
100         wVFWCaptFilterProp,
101         &CLSID_VFWCaptureFilterPropertyPage,
102         QCAP_createVFWCaptureFilterPropertyPage,
103         NULL,
104         NULL
105     },{
106         wAVIMux,
107         &CLSID_AVImux,
108         QCAP_createAVImux,
109         NULL,
110         NULL
111     },{
112         wAVIMuxPropPage,
113         &CLSID_AVImuxPropertyPage,
114         QCAP_createAVImuxPropertyPage,
115         NULL,
116         NULL
117     },{
118         wAVIMuxPropPage1,
119         &CLSID_AVImuxPropertyPage1,
120         QCAP_createAVImuxPropertyPage1,
121         NULL,
122         NULL
123     },{
124         wFileWriter,
125         &CLSID_FileWriter,
126         QCAP_createFileWriter,
127         NULL,
128         NULL
129     },*/{
130         wCaptGraphBuilder,
131         &CLSID_CaptureGraphBuilder,
132         QCAP_createCaptureGraphBuilder2,
133         NULL,
134         NULL
135     },{
136         wCaptGraphBuilder2,
137         &CLSID_CaptureGraphBuilder2,
138         QCAP_createCaptureGraphBuilder2,
139         NULL,
140         NULL
141     }/*,{
142         wInfPinTeeFilter, 
143         &CLSID_InfinitePinTeeFilter, 
144         QCAP_createInfinitePinTeeFilter,
145         NULL,
146         NULL
147     },{
148         wSmartTeeFilter,
149         &CLSID_SmartTeeFilter,
150         QCAP_createSmartTeeFilter,
151         NULL,
152         NULL
153     },{
154         wAudioInMixerProp,
155         &CLSID_AudioInputMixerPropertyPage,
156         QCAP_createAudioInputMixerPropertyPage,
157         NULL,
158         NULL
159     }*/
160 };
161
162 static int g_numTemplates = sizeof(g_cTemplates) / sizeof(g_cTemplates[0]);
163
164 /***********************************************************************
165  *    Dll EntryPoint (QCAP.@)
166  */
167 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
168 {
169     switch (fdwReason)
170     {
171         case DLL_PROCESS_ATTACH:
172             DisableThreadLibraryCalls(hInstDLL);
173             SetupInitializeServers(g_cTemplates, g_numTemplates, TRUE);
174             break;
175         case DLL_PROCESS_DETACH:
176             SetupInitializeServers(g_cTemplates, g_numTemplates, FALSE);
177             break;
178     }
179     return TRUE;
180 }
181
182 /***********************************************************************
183  *    DllRegisterServer (QCAP.@)
184  */
185 HRESULT WINAPI DllRegisterServer(void)
186 {
187     TRACE("()\n");
188
189     return SetupRegisterServers(g_cTemplates, g_numTemplates, TRUE);
190 }
191
192 /***********************************************************************
193  *    DllUnregisterServer (QCAP.@)
194  */
195 HRESULT WINAPI DllUnregisterServer(void)
196 {
197     TRACE("\n");
198
199     return SetupRegisterServers(g_cTemplates, g_numTemplates, FALSE);
200 }
201
202 /***********************************************************************
203  *    DllCanUnloadNow (QCAP.@)
204  */
205 HRESULT WINAPI DllCanUnloadNow(void)
206 {
207     TRACE("\n");
208
209     if (objects_ref == 0 && server_locks == 0)
210         return S_OK;
211     return S_FALSE;     
212 }
213
214 /******************************************************************************
215  * DLL ClassFactory
216  */
217 typedef struct {
218     IClassFactory ITF_IClassFactory;
219
220     LONG ref;
221     LPFNNewCOMObject pfnCreateInstance;
222 } IClassFactoryImpl;
223
224 static HRESULT WINAPI
225 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
226 {
227     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
228
229     if (IsEqualGUID(riid, &IID_IUnknown) ||
230         IsEqualGUID(riid, &IID_IClassFactory))
231     {
232         IClassFactory_AddRef(iface);
233         *ppobj = This;
234         return S_OK;
235     }
236
237     WARN("(%p)->(%s,%p), not found\n", This, debugstr_guid(riid), ppobj);
238     return E_NOINTERFACE;
239 }
240
241 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
242 {
243     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
244     return InterlockedIncrement(&This->ref);
245 }
246
247 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
248 {
249     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
250
251     ULONG ref = InterlockedDecrement(&This->ref);
252
253     if (ref == 0)
254         HeapFree(GetProcessHeap(), 0, This);
255
256     return ref;
257 }
258
259 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
260                                           REFIID riid, LPVOID *ppobj)
261 {
262     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
263     HRESULT hres = ERROR_SUCCESS;
264     LPUNKNOWN punk;
265
266     TRACE("(%p)->(%p,%s,%p)\n", This, pOuter, debugstr_guid(riid), ppobj);
267
268     if (!ppobj)
269         return E_POINTER;
270
271     /* Enforce the normal OLE rules regarding interfaces and delegation */
272     if (pOuter && !IsEqualGUID(riid, &IID_IUnknown))
273         return E_NOINTERFACE;
274
275     *ppobj = NULL;
276     punk = This->pfnCreateInstance(pOuter, &hres);
277     if (!punk)
278     {
279         /* No object created, update error if it isn't done already and return */
280         if (!FAILED(hres))
281             hres = E_OUTOFMEMORY;
282     return hres;
283     }
284
285     if (SUCCEEDED(hres))
286     {
287         hres = IUnknown_QueryInterface(punk, riid, ppobj);
288     }
289     /* Releasing the object. If everything was successful, QueryInterface
290        should have incremented the refcount once more, otherwise this will
291        purge the object. */
292     IUnknown_Release(punk);
293     return hres;
294 }
295
296 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
297 {
298     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
299     TRACE("(%p)->(%d)\n",This, dolock);
300
301     if (dolock)
302         InterlockedIncrement(&server_locks);
303     else
304         InterlockedDecrement(&server_locks);
305     return S_OK;
306 }
307
308 static const IClassFactoryVtbl DSCF_Vtbl =
309 {
310     DSCF_QueryInterface,
311     DSCF_AddRef,
312     DSCF_Release,
313     DSCF_CreateInstance,
314     DSCF_LockServer
315 };
316
317 /***********************************************************************
318  *    DllGetClassObject (QCAP.@)
319  */
320 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
321 {
322     const CFactoryTemplate *pList = g_cTemplates;
323     IClassFactoryImpl *factory;
324     int i;
325
326     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
327
328     if (!ppv)
329         return E_POINTER;
330
331     *ppv = NULL;
332
333     if (!IsEqualGUID(&IID_IClassFactory, riid) &&
334         !IsEqualGUID(&IID_IUnknown, riid))
335         return E_NOINTERFACE;
336
337     for (i = 0; i < g_numTemplates; i++, pList++)
338     {
339         if (IsEqualGUID(pList->m_ClsID, rclsid))
340             break;
341     }
342
343     if (i == g_numTemplates)
344     {
345         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
346         return CLASS_E_CLASSNOTAVAILABLE;
347     }
348
349     factory = HeapAlloc(GetProcessHeap(), 0, sizeof(IClassFactoryImpl));
350     if (!factory)
351         return E_OUTOFMEMORY;
352
353     factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
354     factory->ref = 1;
355
356     factory->pfnCreateInstance = pList->m_lpfnNew;
357
358     *ppv = &(factory->ITF_IClassFactory);
359     return S_OK;
360 }
361
362 DWORD ObjectRefCount(BOOL increment)
363 {
364     if (increment)
365         return InterlockedIncrement(&objects_ref);
366     return InterlockedDecrement(&objects_ref);
367 }