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