amstream: Store parent as struct ddraw_stream in ddraw stream sample.
[wine/zf.git] / dlls / quartz / main.c
blob303cc30a9311c5e244da0cab9e4351655dceb5a2
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 "wine/debug.h"
22 #include "quartz_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
26 extern HRESULT WINAPI QUARTZ_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
27 extern HRESULT WINAPI QUARTZ_DllCanUnloadNow(void) DECLSPEC_HIDDEN;
28 extern BOOL WINAPI QUARTZ_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
30 LONG object_locks = 0;
32 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved)
34 if (reason == DLL_PROCESS_DETACH && !reserved)
36 video_window_unregister_class();
37 strmbase_release_typelibs();
39 return QUARTZ_DllMain(instance, reason, reserved);
42 /******************************************************************************
43 * DirectShow ClassFactory
45 typedef struct {
46 IClassFactory IClassFactory_iface;
47 LONG ref;
48 HRESULT (*create_instance)(IUnknown *outer, IUnknown **out);
49 } IClassFactoryImpl;
51 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
53 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
56 struct object_creation_info
58 const CLSID *clsid;
59 HRESULT (*create_instance)(IUnknown *outer, IUnknown **out);
62 static const struct object_creation_info object_creation[] =
64 { &CLSID_ACMWrapper, acm_wrapper_create },
65 { &CLSID_AsyncReader, async_reader_create },
66 { &CLSID_AudioRender, dsound_render_create },
67 { &CLSID_AVIDec, avi_dec_create },
68 { &CLSID_DSoundRender, dsound_render_create },
69 { &CLSID_FilterGraph, filter_graph_create },
70 { &CLSID_FilterGraphNoThread, filter_graph_no_thread_create },
71 { &CLSID_FilterMapper, filter_mapper_create },
72 { &CLSID_FilterMapper2, filter_mapper_create },
73 { &CLSID_MemoryAllocator, mem_allocator_create },
74 { &CLSID_SeekingPassThru, seeking_passthrough_create },
75 { &CLSID_SystemClock, system_clock_create },
76 { &CLSID_VideoRenderer, video_renderer_create },
77 { &CLSID_VideoMixingRenderer, vmr7_create },
78 { &CLSID_VideoMixingRenderer9, vmr9_create },
79 { &CLSID_VideoRendererDefault, video_renderer_default_create },
82 static HRESULT WINAPI DSCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
84 if (IsEqualGUID(riid, &IID_IUnknown)
85 || IsEqualGUID(riid, &IID_IClassFactory))
87 IClassFactory_AddRef(iface);
88 *ppobj = iface;
89 return S_OK;
92 *ppobj = NULL;
93 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
94 return E_NOINTERFACE;
97 static ULONG WINAPI DSCF_AddRef(IClassFactory *iface)
99 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
100 return InterlockedIncrement(&This->ref);
103 static ULONG WINAPI DSCF_Release(IClassFactory *iface)
105 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
106 ULONG ref = InterlockedDecrement(&This->ref);
108 if (ref == 0)
109 CoTaskMemFree(This);
111 return ref;
115 static HRESULT WINAPI DSCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
116 REFIID riid, void **ppobj)
118 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
119 HRESULT hres;
120 LPUNKNOWN punk;
122 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
124 *ppobj = NULL;
125 if(pOuter && !IsEqualGUID(&IID_IUnknown, riid))
126 return E_NOINTERFACE;
128 if (SUCCEEDED(hres = This->create_instance(pOuter, &punk)))
130 InterlockedIncrement(&object_locks);
131 hres = IUnknown_QueryInterface(punk, riid, ppobj);
132 IUnknown_Release(punk);
134 return hres;
137 static HRESULT WINAPI DSCF_LockServer(IClassFactory *iface, BOOL dolock)
139 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
140 FIXME("(%p)->(%d),stub!\n",This,dolock);
141 if(dolock)
142 InterlockedIncrement(&object_locks);
143 else
144 InterlockedDecrement(&object_locks);
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 < ARRAY_SIZE(object_creation); 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->create_instance = object_creation[i].create_instance;
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 if (!object_locks && QUARTZ_DllCanUnloadNow() == S_OK)
208 return S_OK;
209 return S_FALSE;
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;
277 for (i=0; InterfaceDesc[i].name; i++)
278 if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
280 return debugstr_guid(id);
283 LONG WINAPI AmpFactorToDB(LONG ampfactor)
285 FIXME("(%d) Stub!\n", ampfactor);
286 return 0;
289 LONG WINAPI DBToAmpFactor(LONG db)
291 FIXME("(%d) Stub!\n", db);
292 /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
293 if (db < -1000)
294 return 0;
295 return 100;
298 /***********************************************************************
299 * AMGetErrorTextA (QUARTZ.@)
301 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
303 DWORD res;
304 WCHAR errorW[MAX_ERROR_TEXT_LEN];
306 TRACE("(%x,%p,%d)\n", hr, buffer, maxlen);
307 if (!buffer)
308 return 0;
310 res = AMGetErrorTextW(hr, errorW, ARRAY_SIZE(errorW));
311 if (!res)
312 return 0;
314 res = WideCharToMultiByte(CP_ACP, 0, errorW, -1, NULL, 0, 0, 0);
315 if (res > maxlen || !res)
316 return 0;
317 return WideCharToMultiByte(CP_ACP, 0, errorW, -1, buffer, maxlen, 0, 0) - 1;
320 /***********************************************************************
321 * AMGetErrorTextW (QUARTZ.@)
323 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
325 unsigned int len;
326 WCHAR error[MAX_ERROR_TEXT_LEN];
328 FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
330 if (!buffer) return 0;
331 swprintf(error, ARRAY_SIZE(error), L"Error: 0x%lx", hr);
332 if ((len = wcslen(error)) >= maxlen)
333 return 0;
334 wcscpy(buffer, error);
335 return len;