windowscodecs: Implement IWICImagingFactory::CreateBitmapFromSource.
[wine/multimedia.git] / dlls / quartz / main.c
blob2a4071c5603b383729fdbc6f3dff6bd1b75aad11
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 static DWORD dll_ref = 0;
34 /* For the moment, do nothing here. */
35 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
37 return QUARTZ_DllMain( hInstDLL, fdwReason, lpv );
40 static HRESULT SeekingPassThru_create(IUnknown *pUnkOuter, LPVOID *ppObj)
42 return PosPassThru_Construct(pUnkOuter,ppObj); /* from strmbase */
45 /******************************************************************************
46 * DirectShow ClassFactory
48 typedef struct {
49 IClassFactory IClassFactory_iface;
50 LONG ref;
51 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
52 } IClassFactoryImpl;
54 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
56 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
59 struct object_creation_info
61 const CLSID *clsid;
62 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
65 static const struct object_creation_info object_creation[] =
67 { &CLSID_SeekingPassThru, SeekingPassThru_create },
68 { &CLSID_FilterGraph, FilterGraph_create },
69 { &CLSID_FilterGraphNoThread, FilterGraphNoThread_create },
70 { &CLSID_FilterMapper, FilterMapper_create },
71 { &CLSID_FilterMapper2, FilterMapper2_create },
72 { &CLSID_AsyncReader, AsyncReader_create },
73 { &CLSID_MemoryAllocator, StdMemAllocator_create },
74 { &CLSID_AviSplitter, AVISplitter_create },
75 { &CLSID_MPEG1Splitter, MPEGSplitter_create },
76 { &CLSID_VideoRenderer, VideoRenderer_create },
77 { &CLSID_NullRenderer, NullRenderer_create },
78 { &CLSID_VideoMixingRenderer9, VMR9Impl_create },
79 { &CLSID_VideoRendererDefault, VideoRendererDefault_create },
80 { &CLSID_DSoundRender, DSoundRender_create },
81 { &CLSID_AudioRender, DSoundRender_create },
82 { &CLSID_AVIDec, AVIDec_create },
83 { &CLSID_SystemClock, QUARTZ_CreateSystemClock },
84 { &CLSID_ACMWrapper, ACMWrapper_create },
85 { &CLSID_WAVEParser, WAVEParser_create }
88 static HRESULT WINAPI DSCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
90 if (IsEqualGUID(riid, &IID_IUnknown)
91 || IsEqualGUID(riid, &IID_IClassFactory))
93 IClassFactory_AddRef(iface);
94 *ppobj = iface;
95 return S_OK;
98 *ppobj = NULL;
99 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
100 return E_NOINTERFACE;
103 static ULONG WINAPI DSCF_AddRef(IClassFactory *iface)
105 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
106 return InterlockedIncrement(&This->ref);
109 static ULONG WINAPI DSCF_Release(IClassFactory *iface)
111 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
112 ULONG ref = InterlockedDecrement(&This->ref);
114 if (ref == 0)
115 CoTaskMemFree(This);
117 return ref;
121 static HRESULT WINAPI DSCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
122 REFIID riid, void **ppobj)
124 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
125 HRESULT hres;
126 LPUNKNOWN punk;
128 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
130 *ppobj = NULL;
131 if(pOuter && !IsEqualGUID(&IID_IUnknown, riid))
132 return E_NOINTERFACE;
134 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
135 if (SUCCEEDED(hres)) {
136 hres = IUnknown_QueryInterface(punk, riid, ppobj);
137 IUnknown_Release(punk);
139 return hres;
142 static HRESULT WINAPI DSCF_LockServer(IClassFactory *iface, BOOL dolock)
144 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
145 FIXME("(%p)->(%d),stub!\n",This,dolock);
146 return S_OK;
149 static const IClassFactoryVtbl DSCF_Vtbl =
151 DSCF_QueryInterface,
152 DSCF_AddRef,
153 DSCF_Release,
154 DSCF_CreateInstance,
155 DSCF_LockServer
158 /*******************************************************************************
159 * DllGetClassObject [QUARTZ.@]
160 * Retrieves class object from a DLL object
162 * NOTES
163 * Docs say returns STDAPI
165 * PARAMS
166 * rclsid [I] CLSID for the class object
167 * riid [I] Reference to identifier of interface for class object
168 * ppv [O] Address of variable to receive interface pointer for riid
170 * RETURNS
171 * Success: S_OK
172 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
173 * E_UNEXPECTED
175 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
177 unsigned int i;
179 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
181 if (IsEqualGUID( &IID_IClassFactory, riid ) || IsEqualGUID( &IID_IUnknown, riid))
183 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
185 if (IsEqualGUID(object_creation[i].clsid, rclsid))
187 IClassFactoryImpl *factory = CoTaskMemAlloc(sizeof(*factory));
188 if (factory == NULL) return E_OUTOFMEMORY;
190 factory->IClassFactory_iface.lpVtbl = &DSCF_Vtbl;
191 factory->ref = 1;
193 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
195 *ppv = &factory->IClassFactory_iface;
196 return S_OK;
200 return QUARTZ_DllGetClassObject( rclsid, riid, ppv );
203 /***********************************************************************
204 * DllCanUnloadNow (QUARTZ.@)
206 HRESULT WINAPI DllCanUnloadNow(void)
208 if (dll_ref) return S_FALSE;
209 return QUARTZ_DllCanUnloadNow();
213 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
214 { { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } , #name },
216 static const struct {
217 const GUID riid;
218 const char *name;
219 } InterfaceDesc[] =
221 #include "uuids.h"
222 { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
225 /***********************************************************************
226 * proxies
228 HRESULT CALLBACK ICaptureGraphBuilder_FindInterface_Proxy( ICaptureGraphBuilder *This,
229 const GUID *pCategory,
230 IBaseFilter *pf,
231 REFIID riid,
232 void **ppint )
234 return ICaptureGraphBuilder_RemoteFindInterface_Proxy( This, pCategory, pf,
235 riid, (IUnknown **)ppint );
238 HRESULT __RPC_STUB ICaptureGraphBuilder_FindInterface_Stub( ICaptureGraphBuilder *This,
239 const GUID *pCategory,
240 IBaseFilter *pf,
241 REFIID riid,
242 IUnknown **ppint )
244 return ICaptureGraphBuilder_FindInterface( This, pCategory, pf, riid, (void **)ppint );
247 HRESULT CALLBACK ICaptureGraphBuilder2_FindInterface_Proxy( ICaptureGraphBuilder2 *This,
248 const GUID *pCategory,
249 const GUID *pType,
250 IBaseFilter *pf,
251 REFIID riid,
252 void **ppint )
254 return ICaptureGraphBuilder2_RemoteFindInterface_Proxy( This, pCategory, pType,
255 pf, riid, (IUnknown **)ppint );
258 HRESULT __RPC_STUB ICaptureGraphBuilder2_FindInterface_Stub( ICaptureGraphBuilder2 *This,
259 const GUID *pCategory,
260 const GUID *pType,
261 IBaseFilter *pf,
262 REFIID riid,
263 IUnknown **ppint )
265 return ICaptureGraphBuilder2_FindInterface( This, pCategory, pType, pf, riid, (void **)ppint );
268 /***********************************************************************
269 * qzdebugstr_guid (internal)
271 * Gives a text version of DirectShow GUIDs
273 const char * qzdebugstr_guid( const GUID * id )
275 int i;
276 char * name = NULL;
278 for (i=0;InterfaceDesc[i].name && !name;i++) {
279 if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
281 return debugstr_guid(id);
284 LONG WINAPI AmpFactorToDB(LONG ampfactor)
286 FIXME("(%d) Stub!\n", ampfactor);
287 return 0;
290 LONG WINAPI DBToAmpFactor(LONG db)
292 FIXME("(%d) Stub!\n", db);
293 /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
294 if (db < -1000)
295 return 0;
296 return 100;
299 /***********************************************************************
300 * AMGetErrorTextA (QUARTZ.@)
302 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
304 DWORD res;
305 WCHAR errorW[MAX_ERROR_TEXT_LEN];
307 TRACE("(%x,%p,%d)\n", hr, buffer, maxlen);
308 if (!buffer)
309 return 0;
311 res = AMGetErrorTextW(hr, errorW, sizeof(errorW)/sizeof(*errorW));
312 return WideCharToMultiByte(CP_ACP, 0, errorW, res, buffer, maxlen, 0, 0);
315 /***********************************************************************
316 * AMGetErrorTextW (QUARTZ.@)
318 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
320 unsigned int len;
321 static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
322 WCHAR error[MAX_ERROR_TEXT_LEN];
324 FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
326 if (!buffer) return 0;
327 wsprintfW(error, format, hr);
328 if ((len = strlenW(error)) >= maxlen) return 0;
329 lstrcpyW(buffer, error);
330 return len;