fbe472b886f1d60f567edd9342444deeb8fc141c
[reactos.git] / reactos / dll / directx / wine / amstream / main.c
1 /*
2 * MultiMedia Streams Base Functions (AMSTREAM.DLL)
3 *
4 * Copyright 2004 Christian Costa
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #define WIN32_NO_STATUS
22 #define WIN32_LEAN_AND_MEAN
23
24 //#include <stdarg.h>
25 //#include <string.h>
26
27 #define COBJMACROS
28
29 //#include "windef.h"
30 //#include "winbase.h"
31 //#include "winuser.h"
32 //#include "winerror.h"
33
34 //#include <ole2.h>
35 #include <objbase.h>
36 #include <rpcproxy.h>
37
38 #include "amstream_private.h"
39 #include <amstream.h>
40
41 #include <wine/debug.h>
42
43 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
44
45 static HINSTANCE instance;
46 static DWORD dll_ref = 0;
47
48 /* For the moment, do nothing here. */
49 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
50 {
51 switch(fdwReason) {
52 case DLL_PROCESS_ATTACH:
53 instance = hInstDLL;
54 DisableThreadLibraryCalls(hInstDLL);
55 break;
56 }
57 return TRUE;
58 }
59
60 /******************************************************************************
61 * Multimedia Streams ClassFactory
62 */
63 typedef struct {
64 IClassFactory IClassFactory_iface;
65 LONG ref;
66 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
67 } IClassFactoryImpl;
68
69 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
70 {
71 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
72 }
73
74 struct object_creation_info
75 {
76 const CLSID *clsid;
77 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
78 };
79
80 static const struct object_creation_info object_creation[] =
81 {
82 { &CLSID_AMMultiMediaStream, AM_create },
83 { &CLSID_AMDirectDrawStream, AM_create },
84 { &CLSID_AMAudioData, AMAudioData_create },
85 { &CLSID_MediaStreamFilter, MediaStreamFilter_create }
86 };
87
88 static HRESULT WINAPI AMCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
89 {
90 if (IsEqualGUID(riid, &IID_IUnknown)
91 || IsEqualGUID(riid, &IID_IClassFactory))
92 {
93 IClassFactory_AddRef(iface);
94 *ppobj = iface;
95 return S_OK;
96 }
97
98 *ppobj = NULL;
99 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
100 return E_NOINTERFACE;
101 }
102
103 static ULONG WINAPI AMCF_AddRef(IClassFactory *iface)
104 {
105 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
106 return InterlockedIncrement(&This->ref);
107 }
108
109 static ULONG WINAPI AMCF_Release(IClassFactory *iface)
110 {
111 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
112 ULONG ref = InterlockedDecrement(&This->ref);
113
114 if (ref == 0)
115 HeapFree(GetProcessHeap(), 0, This);
116
117 return ref;
118 }
119
120
121 static HRESULT WINAPI AMCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
122 REFIID riid, void **ppobj)
123 {
124 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
125 HRESULT hres;
126 LPUNKNOWN punk;
127
128 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
129
130 *ppobj = NULL;
131 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
132 if (SUCCEEDED(hres)) {
133 hres = IUnknown_QueryInterface(punk, riid, ppobj);
134 IUnknown_Release(punk);
135 }
136 return hres;
137 }
138
139 static HRESULT WINAPI AMCF_LockServer(IClassFactory *iface, BOOL dolock)
140 {
141 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
142 FIXME("(%p)->(%d),stub!\n",This,dolock);
143 return S_OK;
144 }
145
146 static const IClassFactoryVtbl DSCF_Vtbl =
147 {
148 AMCF_QueryInterface,
149 AMCF_AddRef,
150 AMCF_Release,
151 AMCF_CreateInstance,
152 AMCF_LockServer
153 };
154
155 /*******************************************************************************
156 * DllGetClassObject [AMSTREAM.@]
157 * Retrieves class object from a DLL object
158 *
159 * NOTES
160 * Docs say returns STDAPI
161 *
162 * PARAMS
163 * rclsid [I] CLSID for the class object
164 * riid [I] Reference to identifier of interface for class object
165 * ppv [O] Address of variable to receive interface pointer for riid
166 *
167 * RETURNS
168 * Success: S_OK
169 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
170 * E_UNEXPECTED
171 */
172 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
173 {
174 unsigned int i;
175 IClassFactoryImpl *factory;
176
177 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
178
179 if ( !IsEqualGUID( &IID_IClassFactory, riid )
180 && ! IsEqualGUID( &IID_IUnknown, riid) )
181 return E_NOINTERFACE;
182
183 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
184 {
185 if (IsEqualGUID(object_creation[i].clsid, rclsid))
186 break;
187 }
188
189 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
190 {
191 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
192 return CLASS_E_CLASSNOTAVAILABLE;
193 }
194
195 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
196 if (factory == NULL) return E_OUTOFMEMORY;
197
198 factory->IClassFactory_iface.lpVtbl = &DSCF_Vtbl;
199 factory->ref = 1;
200
201 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
202
203 *ppv = &factory->IClassFactory_iface;
204 return S_OK;
205 }
206
207 /***********************************************************************
208 * DllCanUnloadNow (AMSTREAM.@)
209 */
210 HRESULT WINAPI DllCanUnloadNow(void)
211 {
212 return dll_ref != 0 ? S_FALSE : S_OK;
213 }
214
215 /***********************************************************************
216 * DllRegisterServer (AMSTREAM.@)
217 */
218 HRESULT WINAPI DllRegisterServer(void)
219 {
220 return __wine_register_resources( instance );
221 }
222
223 /***********************************************************************
224 * DllUnregisterServer (AMSTREAM.@)
225 */
226 HRESULT WINAPI DllUnregisterServer(void)
227 {
228 return __wine_unregister_resources( instance );
229 }