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