- Bugfix when adding filters to graph due to not initializing
[wine/multimedia.git] / dlls / quartz / main.c
blob3f3e19b44b155e2f71f066e08d5d992b6002ae59
1 /* DirectShow Base Functions (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
5 * This file contains the (internal) driver registration functions,
6 * driver enumeration APIs and DirectDraw creation functions.
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.
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.
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
23 #include "config.h"
24 #include "wine/debug.h"
26 #include "quartz_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
30 static DWORD dll_ref = 0;
32 /* For the moment, do nothing here. */
33 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
35 switch(fdwReason) {
36 case DLL_PROCESS_ATTACH:
37 DisableThreadLibraryCalls(hInstDLL);
38 break;
39 case DLL_PROCESS_DETACH:
40 break;
42 return TRUE;
45 /******************************************************************************
46 * DirectShow ClassFactory
48 typedef struct {
49 IClassFactory ITF_IClassFactory;
51 DWORD ref;
52 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
53 } IClassFactoryImpl;
55 struct object_creation_info
57 const CLSID *clsid;
58 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
61 static const struct object_creation_info object_creation[] =
63 { &CLSID_FilterGraph, FILTERGRAPH_create },
64 { &CLSID_FilterMapper, FilterMapper2_create },
65 { &CLSID_FilterMapper2, FilterMapper2_create },
68 static HRESULT WINAPI
69 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
71 ICOM_THIS(IClassFactoryImpl,iface);
73 if (IsEqualGUID(riid, &IID_IUnknown)
74 || IsEqualGUID(riid, &IID_IClassFactory))
76 IClassFactory_AddRef(iface);
77 *ppobj = This;
78 return S_OK;
81 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
82 return E_NOINTERFACE;
85 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface) {
86 ICOM_THIS(IClassFactoryImpl,iface);
87 return ++(This->ref);
90 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) {
91 ICOM_THIS(IClassFactoryImpl,iface);
93 ULONG ref = --This->ref;
95 if (ref == 0)
96 HeapFree(GetProcessHeap(), 0, This);
98 return ref;
102 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
103 REFIID riid, LPVOID *ppobj) {
104 ICOM_THIS(IClassFactoryImpl,iface);
105 HRESULT hres;
106 LPUNKNOWN punk;
108 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
110 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
111 if (FAILED(hres)) {
112 *ppobj = NULL;
113 return hres;
115 hres = IUnknown_QueryInterface(punk, riid, ppobj);
116 if (FAILED(hres)) {
117 *ppobj = NULL;
118 return hres;
120 IUnknown_Release(punk);
121 return hres;
124 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
125 ICOM_THIS(IClassFactoryImpl,iface);
126 FIXME("(%p)->(%d),stub!\n",This,dolock);
127 return S_OK;
130 static ICOM_VTABLE(IClassFactory) DSCF_Vtbl =
132 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
133 DSCF_QueryInterface,
134 DSCF_AddRef,
135 DSCF_Release,
136 DSCF_CreateInstance,
137 DSCF_LockServer
140 /*******************************************************************************
141 * DllGetClassObject [QUARTZ.@]
142 * Retrieves class object from a DLL object
144 * NOTES
145 * Docs say returns STDAPI
147 * PARAMS
148 * rclsid [I] CLSID for the class object
149 * riid [I] Reference to identifier of interface for class object
150 * ppv [O] Address of variable to receive interface pointer for riid
152 * RETURNS
153 * Success: S_OK
154 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
155 * E_UNEXPECTED
157 DWORD WINAPI QUARTZ_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
159 int i;
160 IClassFactoryImpl *factory;
162 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
164 if ( !IsEqualGUID( &IID_IClassFactory, riid )
165 && ! IsEqualGUID( &IID_IUnknown, riid) )
166 return E_NOINTERFACE;
168 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
170 if (IsEqualGUID(object_creation[i].clsid, rclsid))
171 break;
174 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
176 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
177 return CLASS_E_CLASSNOTAVAILABLE;
180 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
181 if (factory == NULL) return E_OUTOFMEMORY;
183 factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
184 factory->ref = 1;
186 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
188 *ppv = &(factory->ITF_IClassFactory);
189 return S_OK;
192 /***********************************************************************
193 * DllRegisterServer (QUARTZ.@)
195 HRESULT WINAPI QUARTZ_DllRegisterServer()
197 FIXME("(): stub\n");
198 return 0;
201 /***********************************************************************
202 * DllCanUnloadNow (QUARTZ.@)
204 HRESULT WINAPI QUARTZ_DllCanUnloadNow()
206 return dll_ref != 0 ? S_FALSE : S_OK;
210 static struct {
211 const GUID riid;
212 char *name;
213 } InterfaceDesc[] =
215 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
216 { { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } , #name },
217 #include <uuids.h>
218 { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
221 /***********************************************************************
222 * qzdebugstr_guid (internal)
224 * Gives a text version of DirectShow GUIDs
226 const char * qzdebugstr_guid( const GUID * id )
228 int i;
229 char * name = NULL;
231 for (i=0;InterfaceDesc[i].name && !name;i++) {
232 if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
234 return debugstr_guid(id);
237 /***********************************************************************
238 * qzdebugstr_State (internal)
240 * Gives a text version of the FILTER_STATE enumeration
242 const char * qzdebugstr_State(FILTER_STATE state)
244 switch (state)
246 case State_Stopped:
247 return "State_Stopped";
248 case State_Running:
249 return "State_Running";
250 case State_Paused:
251 return "State_Paused";
252 default:
253 return "State_Unknown";