Accept VT_BOOL mixed with another type as valid combination in
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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     DWORD 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_FilterGraph, FILTERGRAPH_create },
64     { &CLSID_FilterMapper, FilterMapper2_create },
65     { &CLSID_FilterMapper2, FilterMapper2_create },
66     { &CLSID_AsyncReader, AsyncReader_create },
67     { &CLSID_MemoryAllocator, StdMemAllocator_create },
68     { &CLSID_AviSplitter, AVISplitter_create },
69 };
70
71 static HRESULT WINAPI
72 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
73 {
74     ICOM_THIS(IClassFactoryImpl,iface);
75
76     if (IsEqualGUID(riid, &IID_IUnknown)
77         || IsEqualGUID(riid, &IID_IClassFactory))
78     {
79         IClassFactory_AddRef(iface);
80         *ppobj = This;
81         return S_OK;
82     }
83
84     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
85     return E_NOINTERFACE;
86 }
87
88 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface) {
89     ICOM_THIS(IClassFactoryImpl,iface);
90     return ++(This->ref);
91 }
92
93 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) {
94     ICOM_THIS(IClassFactoryImpl,iface);
95
96     ULONG ref = --This->ref;
97
98     if (ref == 0)
99         HeapFree(GetProcessHeap(), 0, This);
100
101     return ref;
102 }
103
104
105 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
106                                           REFIID riid, LPVOID *ppobj) {
107     ICOM_THIS(IClassFactoryImpl,iface);
108     HRESULT hres;
109     LPUNKNOWN punk;
110     
111     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
112
113     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
114     if (FAILED(hres)) {
115         *ppobj = NULL;
116         return hres;
117     }
118     hres = IUnknown_QueryInterface(punk, riid, ppobj);
119     if (FAILED(hres)) {
120         *ppobj = NULL;
121         return hres;
122     }
123     IUnknown_Release(punk);
124     return hres;
125 }
126
127 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
128     ICOM_THIS(IClassFactoryImpl,iface);
129     FIXME("(%p)->(%d),stub!\n",This,dolock);
130     return S_OK;
131 }
132
133 static ICOM_VTABLE(IClassFactory) DSCF_Vtbl =
134 {
135     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
136     DSCF_QueryInterface,
137     DSCF_AddRef,
138     DSCF_Release,
139     DSCF_CreateInstance,
140     DSCF_LockServer
141 };
142
143 /*******************************************************************************
144  * DllGetClassObject [QUARTZ.@]
145  * Retrieves class object from a DLL object
146  *
147  * NOTES
148  *    Docs say returns STDAPI
149  *
150  * PARAMS
151  *    rclsid [I] CLSID for the class object
152  *    riid   [I] Reference to identifier of interface for class object
153  *    ppv    [O] Address of variable to receive interface pointer for riid
154  *
155  * RETURNS
156  *    Success: S_OK
157  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
158  *             E_UNEXPECTED
159  */
160 DWORD WINAPI QUARTZ_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
161 {
162     int i;
163     IClassFactoryImpl *factory;
164     
165     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
166     
167     if ( !IsEqualGUID( &IID_IClassFactory, riid )
168          && ! IsEqualGUID( &IID_IUnknown, riid) )
169         return E_NOINTERFACE;
170
171     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
172     {
173         if (IsEqualGUID(object_creation[i].clsid, rclsid))
174             break;
175     }
176
177     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
178     {
179         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
180         return CLASS_E_CLASSNOTAVAILABLE;
181     }
182
183     factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
184     if (factory == NULL) return E_OUTOFMEMORY;
185
186     factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
187     factory->ref = 1;
188
189     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
190
191     *ppv = &(factory->ITF_IClassFactory);
192     return S_OK;
193 }
194
195 /***********************************************************************
196  *              DllCanUnloadNow (QUARTZ.@)
197  */
198 HRESULT WINAPI QUARTZ_DllCanUnloadNow()
199 {
200     return dll_ref != 0 ? S_FALSE : S_OK;
201 }
202
203
204 static struct {
205         const GUID      riid;
206         const char      *name;
207 } InterfaceDesc[] =
208 {
209     #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
210     { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } } , #name },
211         #include <uuids.h>
212         { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
213 };
214
215 /***********************************************************************
216  *              qzdebugstr_guid (internal)
217  *
218  * Gives a text version of DirectShow GUIDs
219  */
220 const char * qzdebugstr_guid( const GUID * id )
221 {
222     int i;
223     char * name = NULL;
224
225     for (i=0;InterfaceDesc[i].name && !name;i++) {
226         if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
227     }
228     return debugstr_guid(id);
229 }
230
231 /***********************************************************************
232  *              qzdebugstr_State (internal)
233  *
234  * Gives a text version of the FILTER_STATE enumeration
235  */
236 const char * qzdebugstr_State(FILTER_STATE state)
237 {
238     switch (state)
239     {
240     case State_Stopped:
241         return "State_Stopped";
242     case State_Running:
243         return "State_Running";
244     case State_Paused:
245         return "State_Paused";
246     default:
247         return "State_Unknown";
248     }
249 }