mshtml: Added PutProperty implementation.
[wine] / dlls / quartz / main.c
1 /*              DirectShow Base Functions (QUARTZ.DLL)
2  *
3  * Copyright 2002 Lionel Ulmer
4  *
5  * This file contains the (internal) driver registration functions,
6  * driver enumeration APIs and DirectDraw creation functions.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24 #include "wine/debug.h"
25
26 #include "quartz_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
29
30 static DWORD dll_ref = 0;
31
32 /* For the moment, do nothing here. */
33 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
34 {
35     switch(fdwReason) {
36         case DLL_PROCESS_ATTACH:
37             DisableThreadLibraryCalls(hInstDLL);
38             break;
39         case DLL_PROCESS_DETACH:
40             break;
41     }
42     return TRUE;
43 }
44
45 /******************************************************************************
46  * DirectShow ClassFactory
47  */
48 typedef struct {
49     IClassFactory ITF_IClassFactory;
50
51     LONG ref;
52     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
53 } IClassFactoryImpl;
54
55 struct object_creation_info
56 {
57     const CLSID *clsid;
58     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
59 };
60
61 static const struct object_creation_info object_creation[] =
62 {
63     { &CLSID_FilterGraph, FilterGraph_create },
64     { &CLSID_FilterGraphNoThread, FilterGraphNoThread_create },
65     { &CLSID_FilterMapper, FilterMapper_create },
66     { &CLSID_FilterMapper2, FilterMapper2_create },
67     { &CLSID_AsyncReader, AsyncReader_create },
68     { &CLSID_MemoryAllocator, StdMemAllocator_create },
69     { &CLSID_AviSplitter, AVISplitter_create },
70     { &CLSID_MPEG1Splitter, MPEGSplitter_create },
71     { &CLSID_VideoRenderer, VideoRenderer_create },
72     { &CLSID_DSoundRender, DSoundRender_create },
73     { &CLSID_AVIDec, AVIDec_create },
74     { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
75     { &CLSID_ACMWrapper, &ACMWrapper_create },
76     { &CLSID_WAVEParser, &WAVEParser_create }
77 };
78
79 static HRESULT WINAPI
80 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
81 {
82     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
83
84     if (IsEqualGUID(riid, &IID_IUnknown)
85         || IsEqualGUID(riid, &IID_IClassFactory))
86     {
87         IClassFactory_AddRef(iface);
88         *ppobj = This;
89         return S_OK;
90     }
91
92     *ppobj = NULL;
93     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
94     return E_NOINTERFACE;
95 }
96
97 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
98 {
99     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
100     return InterlockedIncrement(&This->ref);
101 }
102
103 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
104 {
105     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
106
107     ULONG ref = InterlockedDecrement(&This->ref);
108
109     if (ref == 0)
110         CoTaskMemFree(This);
111
112     return ref;
113 }
114
115
116 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
117                                           REFIID riid, LPVOID *ppobj)
118 {
119     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
120     HRESULT hres;
121     LPUNKNOWN punk;
122     
123     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
124
125     *ppobj = NULL;
126     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
127     if (SUCCEEDED(hres)) {
128         hres = IUnknown_QueryInterface(punk, riid, ppobj);
129         IUnknown_Release(punk);
130     }
131     return hres;
132 }
133
134 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
135 {
136     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
137     FIXME("(%p)->(%d),stub!\n",This,dolock);
138     return S_OK;
139 }
140
141 static const IClassFactoryVtbl DSCF_Vtbl =
142 {
143     DSCF_QueryInterface,
144     DSCF_AddRef,
145     DSCF_Release,
146     DSCF_CreateInstance,
147     DSCF_LockServer
148 };
149
150 /*******************************************************************************
151  * DllGetClassObject [QUARTZ.@]
152  * Retrieves class object from a DLL object
153  *
154  * NOTES
155  *    Docs say returns STDAPI
156  *
157  * PARAMS
158  *    rclsid [I] CLSID for the class object
159  *    riid   [I] Reference to identifier of interface for class object
160  *    ppv    [O] Address of variable to receive interface pointer for riid
161  *
162  * RETURNS
163  *    Success: S_OK
164  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
165  *             E_UNEXPECTED
166  */
167 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
168 {
169     unsigned int i;
170     IClassFactoryImpl *factory;
171     
172     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
173     
174     if ( !IsEqualGUID( &IID_IClassFactory, riid )
175          && ! IsEqualGUID( &IID_IUnknown, riid) )
176         return E_NOINTERFACE;
177
178     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
179     {
180         if (IsEqualGUID(object_creation[i].clsid, rclsid))
181             break;
182     }
183
184     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
185     {
186         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
187         return CLASS_E_CLASSNOTAVAILABLE;
188     }
189
190     factory = CoTaskMemAlloc(sizeof(*factory));
191     if (factory == NULL) return E_OUTOFMEMORY;
192
193     factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
194     factory->ref = 1;
195
196     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
197
198     *ppv = &(factory->ITF_IClassFactory);
199     return S_OK;
200 }
201
202 /***********************************************************************
203  *              DllCanUnloadNow (QUARTZ.@)
204  */
205 HRESULT WINAPI DllCanUnloadNow(void)
206 {
207     return dll_ref != 0 ? S_FALSE : S_OK;
208 }
209
210
211 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
212     { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } } , #name },
213
214 static const struct {
215         const GUID      riid;
216         const char      *name;
217 } InterfaceDesc[] =
218 {
219 #include "uuids.h"
220     { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
221 };
222
223 /***********************************************************************
224  *              qzdebugstr_guid (internal)
225  *
226  * Gives a text version of DirectShow GUIDs
227  */
228 const char * qzdebugstr_guid( const GUID * id )
229 {
230     int i;
231     char * name = NULL;
232
233     for (i=0;InterfaceDesc[i].name && !name;i++) {
234         if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
235     }
236     return debugstr_guid(id);
237 }
238
239 /***********************************************************************
240  *              qzdebugstr_State (internal)
241  *
242  * Gives a text version of the FILTER_STATE enumeration
243  */
244 const char * qzdebugstr_State(FILTER_STATE state)
245 {
246     switch (state)
247     {
248     case State_Stopped:
249         return "State_Stopped";
250     case State_Running:
251         return "State_Running";
252     case State_Paused:
253         return "State_Paused";
254     default:
255         return "State_Unknown";
256     }
257 }
258
259 LONG WINAPI AmpFactorToDB(LONG ampfactor)
260 {
261     FIXME("(%d) Stub!\n", ampfactor);
262     return 0;
263 }
264
265 LONG WINAPI DBToAmpFactor(LONG db)
266 {
267     FIXME("(%d) Stub!\n", db);
268     /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
269     if (db < -1000)
270         return 0;
271     return 100;
272 }
273
274 /***********************************************************************
275  *              AMGetErrorTextA (QUARTZ.@)
276  */
277 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
278 {
279     int len;
280     static const char format[] = "Error: 0x%x";
281     char error[MAX_ERROR_TEXT_LEN];
282
283     FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
284
285     if (!buffer) return 0;
286     wsprintfA(error, format, hr);
287     if ((len = lstrlenA(error)) >= maxlen) return 0; 
288     lstrcpyA(buffer, error);
289     return len;
290 }
291
292 /***********************************************************************
293  *              AMGetErrorTextW (QUARTZ.@)
294  */
295 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
296 {
297     int len;
298     static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
299     WCHAR error[MAX_ERROR_TEXT_LEN];
300
301     FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
302
303     if (!buffer) return 0;
304     wsprintfW(error, format, hr);
305     if ((len = lstrlenW(error)) >= maxlen) return 0; 
306     lstrcpyW(buffer, error);
307     return len;
308 }