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
46 IClassFactory IClassFactory_iface
;
48 HRESULT (*create_instance
)(IUnknown
*outer
, IUnknown
**out
);
51 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
53 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
56 struct object_creation_info
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
);
93 WARN("(%p)->(%s,%p), not found\n", iface
, debugstr_guid(riid
), ppobj
);
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
);
115 static HRESULT WINAPI
DSCF_CreateInstance(IClassFactory
*iface
, IUnknown
*pOuter
,
116 REFIID riid
, void **ppobj
)
118 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
122 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
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
);
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
);
142 InterlockedIncrement(&object_locks
);
144 InterlockedDecrement(&object_locks
);
148 static const IClassFactoryVtbl DSCF_Vtbl
=
157 /*******************************************************************************
158 * DllGetClassObject [QUARTZ.@]
159 * Retrieves class object from a DLL object
162 * Docs say returns STDAPI
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
171 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
174 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
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
;
192 factory
->create_instance
= object_creation
[i
].create_instance
;
194 *ppv
= &factory
->IClassFactory_iface
;
199 return QUARTZ_DllGetClassObject( rclsid
, riid
, ppv
);
202 /***********************************************************************
203 * DllCanUnloadNow (QUARTZ.@)
205 HRESULT WINAPI
DllCanUnloadNow(void)
207 if (!object_locks
&& QUARTZ_DllCanUnloadNow() == S_OK
)
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 {
222 { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL
}
225 /***********************************************************************
228 HRESULT CALLBACK
ICaptureGraphBuilder_FindInterface_Proxy( ICaptureGraphBuilder
*This
,
229 const GUID
*pCategory
,
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
,
244 return ICaptureGraphBuilder_FindInterface( This
, pCategory
, pf
, riid
, (void **)ppint
);
247 HRESULT CALLBACK
ICaptureGraphBuilder2_FindInterface_Proxy( ICaptureGraphBuilder2
*This
,
248 const GUID
*pCategory
,
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
,
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
)
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
);
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 */
298 /***********************************************************************
299 * AMGetErrorTextA (QUARTZ.@)
301 DWORD WINAPI
AMGetErrorTextA(HRESULT hr
, LPSTR buffer
, DWORD maxlen
)
304 WCHAR errorW
[MAX_ERROR_TEXT_LEN
];
306 TRACE("(%x,%p,%d)\n", hr
, buffer
, maxlen
);
310 res
= AMGetErrorTextW(hr
, errorW
, ARRAY_SIZE(errorW
));
314 res
= WideCharToMultiByte(CP_ACP
, 0, errorW
, -1, NULL
, 0, 0, 0);
315 if (res
> maxlen
|| !res
)
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
)
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
)
334 wcscpy(buffer
, error
);