mf/session: Implement support for sinks that provide sample allocators.
[wine.git] / dlls / evr / main.c
blob301330a51e2040dce83c1a548cace2035b8d3b92
1 /*
2 * Copyright (C) 2015 Austin English
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
26 #include "ole2.h"
27 #include "rpcproxy.h"
29 #include "evr_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(evr);
35 static HINSTANCE instance_evr;
37 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
39 if (reason == DLL_WINE_PREATTACH)
40 return FALSE; /* prefer native version */
41 else if (reason == DLL_PROCESS_ATTACH)
43 instance_evr = instance;
44 DisableThreadLibraryCalls(instance);
46 else if (reason == DLL_PROCESS_DETACH && !reserved)
48 strmbase_release_typelibs();
50 return TRUE;
53 typedef struct {
54 IClassFactory IClassFactory_iface;
56 LONG ref;
57 HRESULT (*pfnCreateInstance)(IUnknown *unk_outer, void **ppobj);
58 } IClassFactoryImpl;
60 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
62 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
65 struct object_creation_info
67 const CLSID *clsid;
68 HRESULT (*pfnCreateInstance)(IUnknown *unk_outer, void **ppobj);
71 static const struct object_creation_info object_creation[] =
73 { &CLSID_EnhancedVideoRenderer, evr_filter_create },
74 { &CLSID_MFVideoMixer9, evr_mixer_create },
75 { &CLSID_MFVideoPresenter9, evr_presenter_create },
78 static HRESULT WINAPI classfactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
80 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
82 if (IsEqualGUID(riid, &IID_IUnknown)
83 || IsEqualGUID(riid, &IID_IClassFactory))
85 IClassFactory_AddRef(iface);
86 *ppobj = &This->IClassFactory_iface;
87 return S_OK;
90 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
91 return E_NOINTERFACE;
94 static ULONG WINAPI classfactory_AddRef(IClassFactory *iface)
96 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
97 return InterlockedIncrement(&This->ref);
100 static ULONG WINAPI classfactory_Release(IClassFactory *iface)
102 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
103 ULONG ref = InterlockedDecrement(&This->ref);
105 if (ref == 0)
106 HeapFree(GetProcessHeap(), 0, This);
108 return ref;
111 static HRESULT WINAPI classfactory_CreateInstance(IClassFactory *iface, IUnknown *outer_unk, REFIID riid, void **ppobj)
113 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
114 HRESULT hres;
115 IUnknown *unk;
117 TRACE("(%p)->(%p,%s,%p)\n", This, outer_unk, debugstr_guid(riid), ppobj);
119 *ppobj = NULL;
121 if (outer_unk && !IsEqualGUID(riid, &IID_IUnknown))
122 return E_NOINTERFACE;
124 hres = This->pfnCreateInstance(outer_unk, (void **) &unk);
125 if (SUCCEEDED(hres))
127 hres = IUnknown_QueryInterface(unk, riid, ppobj);
128 IUnknown_Release(unk);
130 return hres;
133 static HRESULT WINAPI classfactory_LockServer(IClassFactory *iface, BOOL dolock)
135 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
136 FIXME("(%p)->(%d), stub!\n", This, dolock);
137 return S_OK;
140 static const IClassFactoryVtbl classfactory_Vtbl =
142 classfactory_QueryInterface,
143 classfactory_AddRef,
144 classfactory_Release,
145 classfactory_CreateInstance,
146 classfactory_LockServer
149 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
151 unsigned int i;
152 IClassFactoryImpl *factory;
154 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
156 if (!IsEqualGUID(&IID_IClassFactory, riid)
157 && !IsEqualGUID( &IID_IUnknown, riid))
158 return E_NOINTERFACE;
160 for (i = 0; i < ARRAY_SIZE(object_creation); i++)
162 if (IsEqualGUID(object_creation[i].clsid, rclsid))
163 break;
166 if (i == ARRAY_SIZE(object_creation))
168 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
169 return CLASS_E_CLASSNOTAVAILABLE;
172 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
173 if (factory == NULL)
174 return E_OUTOFMEMORY;
176 factory->IClassFactory_iface.lpVtbl = &classfactory_Vtbl;
177 factory->ref = 1;
179 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
181 *ppv = &(factory->IClassFactory_iface);
182 return S_OK;
185 HRESULT WINAPI DllCanUnloadNow(void)
187 return S_FALSE;
190 HRESULT WINAPI DllRegisterServer(void)
192 return __wine_register_resources(instance_evr);
195 HRESULT WINAPI DllUnregisterServer(void)
197 return __wine_unregister_resources(instance_evr);
200 HRESULT WINAPI MFCreateVideoMixerAndPresenter(IUnknown *mixer_outer, IUnknown *presenter_outer,
201 REFIID riid_mixer, void **mixer, REFIID riid_presenter, void **presenter)
203 HRESULT hr;
205 TRACE("%p, %p, %s, %p, %s, %p.\n", mixer_outer, presenter_outer, debugstr_guid(riid_mixer), mixer,
206 debugstr_guid(riid_presenter), presenter);
208 if (!mixer || !presenter)
209 return E_POINTER;
211 *mixer = *presenter = NULL;
213 if (SUCCEEDED(hr = CoCreateInstance(&CLSID_MFVideoMixer9, mixer_outer, CLSCTX_INPROC_SERVER, riid_mixer, mixer)))
214 hr = CoCreateInstance(&CLSID_MFVideoPresenter9, presenter_outer, CLSCTX_INPROC_SERVER, riid_presenter, presenter);
216 if (FAILED(hr))
218 if (*mixer)
219 IUnknown_Release((IUnknown *)*mixer);
220 if (*presenter)
221 IUnknown_Release((IUnknown *)*presenter);
222 *mixer = *presenter = NULL;
225 return hr;