urlmon: Make session object thread safe.
[wine/winequartzdrv.git] / dlls / quartz / main.c
blob73c506220392374aa05bee3e74f91a17eefcb700
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 LONG 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_FilterGraphNoThread, FilterGraphNoThread_create },
65 { &CLSID_FilterMapper, FilterMapper_create },
66 { &CLSID_FilterMapper2, FilterMapper2_create },
67 { &CLSID_AsyncReader, AsyncReader_create },
68 { &CLSID_MemoryAllocator, StdMemAllocator_create },
69 { &CLSID_AviSplitter, AVISplitter_create },
70 { &CLSID_MPEG1Splitter, MPEGSplitter_create },
71 { &CLSID_VideoRenderer, VideoRenderer_create },
72 { &CLSID_VideoRendererDefault, VideoRendererDefault_create },
73 { &CLSID_DSoundRender, DSoundRender_create },
74 { &CLSID_AVIDec, AVIDec_create },
75 { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
76 { &CLSID_ACMWrapper, &ACMWrapper_create },
77 { &CLSID_WAVEParser, &WAVEParser_create }
80 static HRESULT WINAPI
81 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
83 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
85 if (IsEqualGUID(riid, &IID_IUnknown)
86 || IsEqualGUID(riid, &IID_IClassFactory))
88 IClassFactory_AddRef(iface);
89 *ppobj = This;
90 return S_OK;
93 *ppobj = NULL;
94 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
95 return E_NOINTERFACE;
98 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
100 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
101 return InterlockedIncrement(&This->ref);
104 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
106 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
108 ULONG ref = InterlockedDecrement(&This->ref);
110 if (ref == 0)
111 CoTaskMemFree(This);
113 return ref;
117 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
118 REFIID riid, LPVOID *ppobj)
120 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
121 HRESULT hres;
122 LPUNKNOWN punk;
124 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
126 *ppobj = NULL;
127 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
128 if (SUCCEEDED(hres)) {
129 hres = IUnknown_QueryInterface(punk, riid, ppobj);
130 IUnknown_Release(punk);
132 return hres;
135 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
137 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
138 FIXME("(%p)->(%d),stub!\n",This,dolock);
139 return S_OK;
142 static const IClassFactoryVtbl DSCF_Vtbl =
144 DSCF_QueryInterface,
145 DSCF_AddRef,
146 DSCF_Release,
147 DSCF_CreateInstance,
148 DSCF_LockServer
151 /*******************************************************************************
152 * DllGetClassObject [QUARTZ.@]
153 * Retrieves class object from a DLL object
155 * NOTES
156 * Docs say returns STDAPI
158 * PARAMS
159 * rclsid [I] CLSID for the class object
160 * riid [I] Reference to identifier of interface for class object
161 * ppv [O] Address of variable to receive interface pointer for riid
163 * RETURNS
164 * Success: S_OK
165 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
166 * E_UNEXPECTED
168 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
170 unsigned int i;
171 IClassFactoryImpl *factory;
173 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
175 if ( !IsEqualGUID( &IID_IClassFactory, riid )
176 && ! IsEqualGUID( &IID_IUnknown, riid) )
177 return E_NOINTERFACE;
179 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
181 if (IsEqualGUID(object_creation[i].clsid, rclsid))
182 break;
185 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
187 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
188 return CLASS_E_CLASSNOTAVAILABLE;
191 factory = CoTaskMemAlloc(sizeof(*factory));
192 if (factory == NULL) return E_OUTOFMEMORY;
194 factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
195 factory->ref = 1;
197 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
199 *ppv = &(factory->ITF_IClassFactory);
200 return S_OK;
203 /***********************************************************************
204 * DllCanUnloadNow (QUARTZ.@)
206 HRESULT WINAPI DllCanUnloadNow(void)
208 return dll_ref != 0 ? S_FALSE : S_OK;
212 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
213 { { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } , #name },
215 static const struct {
216 const GUID riid;
217 const char *name;
218 } InterfaceDesc[] =
220 #include "uuids.h"
221 { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
224 /***********************************************************************
225 * qzdebugstr_guid (internal)
227 * Gives a text version of DirectShow GUIDs
229 const char * qzdebugstr_guid( const GUID * id )
231 int i;
232 char * name = NULL;
234 for (i=0;InterfaceDesc[i].name && !name;i++) {
235 if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
237 return debugstr_guid(id);
240 /***********************************************************************
241 * qzdebugstr_State (internal)
243 * Gives a text version of the FILTER_STATE enumeration
245 const char * qzdebugstr_State(FILTER_STATE state)
247 switch (state)
249 case State_Stopped:
250 return "State_Stopped";
251 case State_Running:
252 return "State_Running";
253 case State_Paused:
254 return "State_Paused";
255 default:
256 return "State_Unknown";
260 LONG WINAPI AmpFactorToDB(LONG ampfactor)
262 FIXME("(%d) Stub!\n", ampfactor);
263 return 0;
266 LONG WINAPI DBToAmpFactor(LONG db)
268 FIXME("(%d) Stub!\n", db);
269 /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
270 if (db < -1000)
271 return 0;
272 return 100;
275 /***********************************************************************
276 * AMGetErrorTextA (QUARTZ.@)
278 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
280 int len;
281 static const char format[] = "Error: 0x%x";
282 char error[MAX_ERROR_TEXT_LEN];
284 FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
286 if (!buffer) return 0;
287 wsprintfA(error, format, hr);
288 if ((len = lstrlenA(error)) >= maxlen) return 0;
289 lstrcpyA(buffer, error);
290 return len;
293 /***********************************************************************
294 * AMGetErrorTextW (QUARTZ.@)
296 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
298 int len;
299 static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
300 WCHAR error[MAX_ERROR_TEXT_LEN];
302 FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
304 if (!buffer) return 0;
305 wsprintfW(error, format, hr);
306 if ((len = lstrlenW(error)) >= maxlen) return 0;
307 lstrcpyW(buffer, error);
308 return len;