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