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