gdi32: Try to coalesce into wider bands.
[wine.git] / dlls / quartz / main.c
blob32865f3e986a2f1950b9a7c93afcbb6b9a3c282e
1 /* DirectShow Base Functions (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/debug.h"
23 #include "quartz_private.h"
24 #include "wine/unicode.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
28 extern HRESULT WINAPI QUARTZ_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
29 extern HRESULT WINAPI QUARTZ_DllCanUnloadNow(void) DECLSPEC_HIDDEN;
30 extern BOOL WINAPI QUARTZ_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
32 /* For the moment, do nothing here. */
33 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
35 return QUARTZ_DllMain( hInstDLL, fdwReason, lpv );
38 static HRESULT SeekingPassThru_create(IUnknown *pUnkOuter, LPVOID *ppObj)
40 return PosPassThru_Construct(pUnkOuter,ppObj); /* from strmbase */
43 /******************************************************************************
44 * DirectShow ClassFactory
46 typedef struct {
47 IClassFactory IClassFactory_iface;
48 LONG ref;
49 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
50 } IClassFactoryImpl;
52 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
54 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
57 struct object_creation_info
59 const CLSID *clsid;
60 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
63 static const struct object_creation_info object_creation[] =
65 { &CLSID_SeekingPassThru, SeekingPassThru_create },
66 { &CLSID_FilterGraph, FilterGraph_create },
67 { &CLSID_FilterGraphNoThread, FilterGraphNoThread_create },
68 { &CLSID_FilterMapper, FilterMapper_create },
69 { &CLSID_FilterMapper2, FilterMapper2_create },
70 { &CLSID_AsyncReader, AsyncReader_create },
71 { &CLSID_MemoryAllocator, StdMemAllocator_create },
72 { &CLSID_AviSplitter, AVISplitter_create },
73 { &CLSID_MPEG1Splitter, MPEGSplitter_create },
74 { &CLSID_VideoRenderer, VideoRenderer_create },
75 { &CLSID_NullRenderer, NullRenderer_create },
76 { &CLSID_VideoMixingRenderer, VMR7Impl_create },
77 { &CLSID_VideoMixingRenderer9, VMR9Impl_create },
78 { &CLSID_VideoRendererDefault, VideoRendererDefault_create },
79 { &CLSID_DSoundRender, DSoundRender_create },
80 { &CLSID_AudioRender, DSoundRender_create },
81 { &CLSID_AVIDec, AVIDec_create },
82 { &CLSID_SystemClock, QUARTZ_CreateSystemClock },
83 { &CLSID_ACMWrapper, ACMWrapper_create },
84 { &CLSID_WAVEParser, WAVEParser_create }
87 static HRESULT WINAPI DSCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
89 if (IsEqualGUID(riid, &IID_IUnknown)
90 || IsEqualGUID(riid, &IID_IClassFactory))
92 IClassFactory_AddRef(iface);
93 *ppobj = iface;
94 return S_OK;
97 *ppobj = NULL;
98 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
99 return E_NOINTERFACE;
102 static ULONG WINAPI DSCF_AddRef(IClassFactory *iface)
104 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
105 return InterlockedIncrement(&This->ref);
108 static ULONG WINAPI DSCF_Release(IClassFactory *iface)
110 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
111 ULONG ref = InterlockedDecrement(&This->ref);
113 if (ref == 0)
114 CoTaskMemFree(This);
116 return ref;
120 static HRESULT WINAPI DSCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
121 REFIID riid, void **ppobj)
123 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
124 HRESULT hres;
125 LPUNKNOWN punk;
127 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
129 *ppobj = NULL;
130 if(pOuter && !IsEqualGUID(&IID_IUnknown, riid))
131 return E_NOINTERFACE;
133 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
134 if (SUCCEEDED(hres)) {
135 hres = IUnknown_QueryInterface(punk, riid, ppobj);
136 IUnknown_Release(punk);
138 return hres;
141 static HRESULT WINAPI DSCF_LockServer(IClassFactory *iface, BOOL dolock)
143 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
144 FIXME("(%p)->(%d),stub!\n",This,dolock);
145 return S_OK;
148 static const IClassFactoryVtbl DSCF_Vtbl =
150 DSCF_QueryInterface,
151 DSCF_AddRef,
152 DSCF_Release,
153 DSCF_CreateInstance,
154 DSCF_LockServer
157 /*******************************************************************************
158 * DllGetClassObject [QUARTZ.@]
159 * Retrieves class object from a DLL object
161 * NOTES
162 * Docs say returns STDAPI
164 * PARAMS
165 * rclsid [I] CLSID for the class object
166 * riid [I] Reference to identifier of interface for class object
167 * ppv [O] Address of variable to receive interface pointer for riid
169 * RETURNS
170 * Success: S_OK
171 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
172 * E_UNEXPECTED
174 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
176 unsigned int i;
178 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
180 if (IsEqualGUID( &IID_IClassFactory, riid ) || IsEqualGUID( &IID_IUnknown, riid))
182 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
184 if (IsEqualGUID(object_creation[i].clsid, rclsid))
186 IClassFactoryImpl *factory = CoTaskMemAlloc(sizeof(*factory));
187 if (factory == NULL) return E_OUTOFMEMORY;
189 factory->IClassFactory_iface.lpVtbl = &DSCF_Vtbl;
190 factory->ref = 1;
192 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
194 *ppv = &factory->IClassFactory_iface;
195 return S_OK;
199 return QUARTZ_DllGetClassObject( rclsid, riid, ppv );
202 /***********************************************************************
203 * DllCanUnloadNow (QUARTZ.@)
205 HRESULT WINAPI DllCanUnloadNow(void)
207 return QUARTZ_DllCanUnloadNow();
211 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
212 { { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } , #name },
214 static const struct {
215 const GUID riid;
216 const char *name;
217 } InterfaceDesc[] =
219 #include "uuids.h"
220 { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
223 /***********************************************************************
224 * proxies
226 HRESULT CALLBACK ICaptureGraphBuilder_FindInterface_Proxy( ICaptureGraphBuilder *This,
227 const GUID *pCategory,
228 IBaseFilter *pf,
229 REFIID riid,
230 void **ppint )
232 return ICaptureGraphBuilder_RemoteFindInterface_Proxy( This, pCategory, pf,
233 riid, (IUnknown **)ppint );
236 HRESULT __RPC_STUB ICaptureGraphBuilder_FindInterface_Stub( ICaptureGraphBuilder *This,
237 const GUID *pCategory,
238 IBaseFilter *pf,
239 REFIID riid,
240 IUnknown **ppint )
242 return ICaptureGraphBuilder_FindInterface( This, pCategory, pf, riid, (void **)ppint );
245 HRESULT CALLBACK ICaptureGraphBuilder2_FindInterface_Proxy( ICaptureGraphBuilder2 *This,
246 const GUID *pCategory,
247 const GUID *pType,
248 IBaseFilter *pf,
249 REFIID riid,
250 void **ppint )
252 return ICaptureGraphBuilder2_RemoteFindInterface_Proxy( This, pCategory, pType,
253 pf, riid, (IUnknown **)ppint );
256 HRESULT __RPC_STUB ICaptureGraphBuilder2_FindInterface_Stub( ICaptureGraphBuilder2 *This,
257 const GUID *pCategory,
258 const GUID *pType,
259 IBaseFilter *pf,
260 REFIID riid,
261 IUnknown **ppint )
263 return ICaptureGraphBuilder2_FindInterface( This, pCategory, pType, pf, riid, (void **)ppint );
266 /***********************************************************************
267 * qzdebugstr_guid (internal)
269 * Gives a text version of DirectShow GUIDs
271 const char * qzdebugstr_guid( const GUID * id )
273 int i;
275 for (i=0; InterfaceDesc[i].name; i++)
276 if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
278 return debugstr_guid(id);
281 LONG WINAPI AmpFactorToDB(LONG ampfactor)
283 FIXME("(%d) Stub!\n", ampfactor);
284 return 0;
287 LONG WINAPI DBToAmpFactor(LONG db)
289 FIXME("(%d) Stub!\n", db);
290 /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
291 if (db < -1000)
292 return 0;
293 return 100;
296 /***********************************************************************
297 * AMGetErrorTextA (QUARTZ.@)
299 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
301 DWORD res;
302 WCHAR errorW[MAX_ERROR_TEXT_LEN];
304 TRACE("(%x,%p,%d)\n", hr, buffer, maxlen);
305 if (!buffer)
306 return 0;
308 res = AMGetErrorTextW(hr, errorW, sizeof(errorW)/sizeof(*errorW));
309 return WideCharToMultiByte(CP_ACP, 0, errorW, res, buffer, maxlen, 0, 0);
312 /***********************************************************************
313 * AMGetErrorTextW (QUARTZ.@)
315 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
317 unsigned int len;
318 static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
319 WCHAR error[MAX_ERROR_TEXT_LEN];
321 FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
323 if (!buffer) return 0;
324 wsprintfW(error, format, hr);
325 if ((len = strlenW(error)) >= maxlen) return 0;
326 lstrcpyW(buffer, error);
327 return len;