Fix signed/unsigned comparison warnings.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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     DWORD 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_FilterMapper, FilterMapper2_create },
65     { &CLSID_FilterMapper2, FilterMapper2_create },
66     { &CLSID_AsyncReader, AsyncReader_create },
67     { &CLSID_MemoryAllocator, StdMemAllocator_create },
68     { &CLSID_AviSplitter, AVISplitter_create },
69     { &CLSID_VideoRenderer, VideoRenderer_create },
70     { &CLSID_DSoundRender, DSoundRender_create },
71     { &CLSID_AVIDec, AVIDec_create },
72     { &CLSID_SystemClock, &QUARTZ_CreateSystemClock }
73 };
74
75 static HRESULT WINAPI
76 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
77 {
78     ICOM_THIS(IClassFactoryImpl,iface);
79
80     if (IsEqualGUID(riid, &IID_IUnknown)
81         || IsEqualGUID(riid, &IID_IClassFactory))
82     {
83         IClassFactory_AddRef(iface);
84         *ppobj = This;
85         return S_OK;
86     }
87
88     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
89     return E_NOINTERFACE;
90 }
91
92 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface) {
93     ICOM_THIS(IClassFactoryImpl,iface);
94     return ++(This->ref);
95 }
96
97 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) {
98     ICOM_THIS(IClassFactoryImpl,iface);
99
100     ULONG ref = --This->ref;
101
102     if (ref == 0)
103         HeapFree(GetProcessHeap(), 0, This);
104
105     return ref;
106 }
107
108
109 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
110                                           REFIID riid, LPVOID *ppobj) {
111     ICOM_THIS(IClassFactoryImpl,iface);
112     HRESULT hres;
113     LPUNKNOWN punk;
114     
115     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
116
117     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
118     if (FAILED(hres)) {
119         *ppobj = NULL;
120         return hres;
121     }
122     hres = IUnknown_QueryInterface(punk, riid, ppobj);
123     if (FAILED(hres)) {
124         *ppobj = NULL;
125         return hres;
126     }
127     IUnknown_Release(punk);
128     return hres;
129 }
130
131 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
132     ICOM_THIS(IClassFactoryImpl,iface);
133     FIXME("(%p)->(%d),stub!\n",This,dolock);
134     return S_OK;
135 }
136
137 static IClassFactoryVtbl DSCF_Vtbl =
138 {
139     DSCF_QueryInterface,
140     DSCF_AddRef,
141     DSCF_Release,
142     DSCF_CreateInstance,
143     DSCF_LockServer
144 };
145
146 /*******************************************************************************
147  * DllGetClassObject [QUARTZ.@]
148  * Retrieves class object from a DLL object
149  *
150  * NOTES
151  *    Docs say returns STDAPI
152  *
153  * PARAMS
154  *    rclsid [I] CLSID for the class object
155  *    riid   [I] Reference to identifier of interface for class object
156  *    ppv    [O] Address of variable to receive interface pointer for riid
157  *
158  * RETURNS
159  *    Success: S_OK
160  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
161  *             E_UNEXPECTED
162  */
163 DWORD WINAPI QUARTZ_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
164 {
165     int i;
166     IClassFactoryImpl *factory;
167     
168     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
169     
170     if ( !IsEqualGUID( &IID_IClassFactory, riid )
171          && ! IsEqualGUID( &IID_IUnknown, riid) )
172         return E_NOINTERFACE;
173
174     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
175     {
176         if (IsEqualGUID(object_creation[i].clsid, rclsid))
177             break;
178     }
179
180     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
181     {
182         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
183         return CLASS_E_CLASSNOTAVAILABLE;
184     }
185
186     factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
187     if (factory == NULL) return E_OUTOFMEMORY;
188
189     factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
190     factory->ref = 1;
191
192     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
193
194     *ppv = &(factory->ITF_IClassFactory);
195     return S_OK;
196 }
197
198 /***********************************************************************
199  *              DllCanUnloadNow (QUARTZ.@)
200  */
201 HRESULT WINAPI QUARTZ_DllCanUnloadNow()
202 {
203     return dll_ref != 0 ? S_FALSE : S_OK;
204 }
205
206
207 static struct {
208         const GUID      riid;
209         const char      *name;
210 } InterfaceDesc[] =
211 {
212     #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
213     { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } } , #name },
214         #include "uuids.h"
215         { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
216 };
217
218 /***********************************************************************
219  *              qzdebugstr_guid (internal)
220  *
221  * Gives a text version of DirectShow GUIDs
222  */
223 const char * qzdebugstr_guid( const GUID * id )
224 {
225     int i;
226     char * name = NULL;
227
228     for (i=0;InterfaceDesc[i].name && !name;i++) {
229         if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
230     }
231     return debugstr_guid(id);
232 }
233
234 /***********************************************************************
235  *              qzdebugstr_State (internal)
236  *
237  * Gives a text version of the FILTER_STATE enumeration
238  */
239 const char * qzdebugstr_State(FILTER_STATE state)
240 {
241     switch (state)
242     {
243     case State_Stopped:
244         return "State_Stopped";
245     case State_Running:
246         return "State_Running";
247     case State_Paused:
248         return "State_Paused";
249     default:
250         return "State_Unknown";
251     }
252 }
253
254 LONG AmpFactorToDB(LONG ampfactor)
255 {
256     FIXME("(%ld) Stub!\n", ampfactor);
257     return 0;
258 }
259
260 LONG DBToAmpFactor(LONG db)
261 {
262     FIXME("(%ld) Stub!\n", db);
263     /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
264     if (db < -1000)
265         return 0;
266     return 100;
267 }