Add missing cast.
[wine] / dlls / quartz / fgraph.c
1 /*
2  * Implementation of CLSID_FilterGraph.
3  *
4  * hidenori@a2.ctktv.ne.jp
5  */
6
7 #include "config.h"
8
9 #include "windef.h"
10 #include "winbase.h"
11 #include "wingdi.h"
12 #include "winuser.h"
13 #include "winerror.h"
14 #include "strmif.h"
15 #include "control.h"
16 #include "uuids.h"
17
18 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(quartz);
20
21 #include "quartz_private.h"
22 #include "fgraph.h"
23
24 /***************************************************************************
25  *
26  *      new/delete for CFilterGraph
27  *
28  */
29
30 /* can I use offsetof safely? - FIXME? */
31 static QUARTZ_IFEntry IFEntries[] =
32 {
33   { &IID_IPersist, offsetof(CFilterGraph,persist)-offsetof(CFilterGraph,unk) },
34   { &IID_IDispatch, offsetof(CFilterGraph,disp)-offsetof(CFilterGraph,unk) },
35   { &IID_IFilterGraph, offsetof(CFilterGraph,fgraph)-offsetof(CFilterGraph,unk) },
36   { &IID_IGraphBuilder, offsetof(CFilterGraph,fgraph)-offsetof(CFilterGraph,unk) },
37   { &IID_IFilterGraph2, offsetof(CFilterGraph,fgraph)-offsetof(CFilterGraph,unk) },
38   { &IID_IGraphVersion, offsetof(CFilterGraph,graphversion)-offsetof(CFilterGraph,unk) },
39   { &IID_IGraphConfig, offsetof(CFilterGraph,grphconf)-offsetof(CFilterGraph,unk) },
40   { &IID_IMediaControl, offsetof(CFilterGraph,mediacontrol)-offsetof(CFilterGraph,unk) },
41   { &IID_IMediaFilter, offsetof(CFilterGraph,mediafilter)-offsetof(CFilterGraph,unk) },
42   { &IID_IMediaEvent, offsetof(CFilterGraph,mediaevent)-offsetof(CFilterGraph,unk) },
43   { &IID_IMediaEventEx, offsetof(CFilterGraph,mediaevent)-offsetof(CFilterGraph,unk) },
44   { &IID_IMediaEventSink, offsetof(CFilterGraph,mediaeventsink)-offsetof(CFilterGraph,unk) },
45   { &IID_IMediaPosition, offsetof(CFilterGraph,mediaposition)-offsetof(CFilterGraph,unk) },
46   { &IID_IMediaSeeking, offsetof(CFilterGraph,mediaseeking)-offsetof(CFilterGraph,unk) },
47   { &IID_IBasicVideo, offsetof(CFilterGraph,basvid)-offsetof(CFilterGraph,unk) },
48   { &IID_IBasicVideo2, offsetof(CFilterGraph,basvid)-offsetof(CFilterGraph,unk) },
49   { &IID_IBasicAudio, offsetof(CFilterGraph,basaud)-offsetof(CFilterGraph,unk) },
50   { &IID_IVideoWindow, offsetof(CFilterGraph,vidwin)-offsetof(CFilterGraph,unk) },
51 };
52
53
54 struct FGInitEntry
55 {
56         HRESULT (*pInit)(CFilterGraph*);
57         void (*pUninit)(CFilterGraph*);
58 };
59
60 static const struct FGInitEntry FGRAPH_Init[] =
61 {
62         #define FGENT(a)        {&CFilterGraph_Init##a,&CFilterGraph_Uninit##a},
63
64         FGENT(IPersist)
65         FGENT(IDispatch)
66         FGENT(IFilterGraph2)
67         FGENT(IGraphVersion)
68         FGENT(IGraphConfig)
69         FGENT(IMediaControl)
70         FGENT(IMediaFilter)
71         FGENT(IMediaEventEx)
72         FGENT(IMediaEventSink)
73         FGENT(IMediaPosition)
74         FGENT(IMediaSeeking)
75         FGENT(IBasicVideo2)
76         FGENT(IBasicAudio)
77         FGENT(IVideoWindow)
78
79         #undef  FGENT
80         { NULL, NULL },
81 };
82
83
84 static void QUARTZ_DestroyFilterGraph(IUnknown* punk)
85 {
86         CFilterGraph_THIS(punk,unk);
87         int     i;
88
89         TRACE( "(%p)\n", punk );
90
91         /* At first, call Stop. */
92         IMediaControl_Stop( CFilterGraph_IMediaControl(This) );
93         IMediaFilter_Stop( CFilterGraph_IMediaFilter(This) );
94
95         i = 0;
96         while ( FGRAPH_Init[i].pInit != NULL )
97         {
98                 FGRAPH_Init[i].pUninit( This );
99                 i++;
100         }
101
102         TRACE( "succeeded.\n" );
103 }
104
105 HRESULT QUARTZ_CreateFilterGraph(IUnknown* punkOuter,void** ppobj)
106 {
107         CFilterGraph*   pfg;
108         HRESULT hr;
109         int     i;
110
111         TRACE("(%p,%p)\n",punkOuter,ppobj);
112
113         pfg = (CFilterGraph*)QUARTZ_AllocObj( sizeof(CFilterGraph) );
114         if ( pfg == NULL )
115                 return E_OUTOFMEMORY;
116
117         QUARTZ_IUnkInit( &pfg->unk, punkOuter );
118
119         i = 0;
120         hr = NOERROR;
121         while ( FGRAPH_Init[i].pInit != NULL )
122         {
123                 hr = FGRAPH_Init[i].pInit( pfg );
124                 if ( FAILED(hr) )
125                         break;
126                 i++;
127         }
128
129         if ( FAILED(hr) )
130         {
131                 while ( --i >= 0 )
132                         FGRAPH_Init[i].pUninit( pfg );
133                 QUARTZ_FreeObj( pfg );
134                 return hr;
135         }
136
137         pfg->unk.pEntries = IFEntries;
138         pfg->unk.dwEntries = sizeof(IFEntries)/sizeof(IFEntries[0]);
139         pfg->unk.pOnFinalRelease = QUARTZ_DestroyFilterGraph;
140
141         *ppobj = (void*)(&pfg->unk);
142
143         return S_OK;
144 }
145
146
147 /***************************************************************************
148  *
149  *      CFilterGraph::IPersist
150  *
151  */
152
153 static HRESULT WINAPI
154 IPersist_fnQueryInterface(IPersist* iface,REFIID riid,void** ppobj)
155 {
156         CFilterGraph_THIS(iface,persist);
157
158         TRACE("(%p)->()\n",This);
159
160         return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
161 }
162
163 static ULONG WINAPI
164 IPersist_fnAddRef(IPersist* iface)
165 {
166         CFilterGraph_THIS(iface,persist);
167
168         TRACE("(%p)->()\n",This);
169
170         return IUnknown_AddRef(This->unk.punkControl);
171 }
172
173 static ULONG WINAPI
174 IPersist_fnRelease(IPersist* iface)
175 {
176         CFilterGraph_THIS(iface,persist);
177
178         TRACE("(%p)->()\n",This);
179
180         return IUnknown_Release(This->unk.punkControl);
181 }
182
183
184 static HRESULT WINAPI
185 IPersist_fnGetClassID(IPersist* iface,CLSID* pclsid)
186 {
187         CFilterGraph_THIS(iface,persist);
188
189         TRACE("(%p)->()\n",This);
190
191         if ( pclsid == NULL )
192                 return E_POINTER;
193         memcpy( pclsid, &CLSID_FilterGraph, sizeof(CLSID) );
194
195         return E_NOTIMPL;
196 }
197
198
199 static ICOM_VTABLE(IPersist) ipersist =
200 {
201         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
202         /* IUnknown fields */
203         IPersist_fnQueryInterface,
204         IPersist_fnAddRef,
205         IPersist_fnRelease,
206         /* IPersist fields */
207         IPersist_fnGetClassID,
208 };
209
210 HRESULT CFilterGraph_InitIPersist( CFilterGraph* pfg )
211 {
212         TRACE("(%p)\n",pfg);
213         ICOM_VTBL(&pfg->persist) = &ipersist;
214
215         return NOERROR;
216 }
217
218 void CFilterGraph_UninitIPersist( CFilterGraph* pfg )
219 {
220         TRACE("(%p)\n",pfg);
221 }
222
223 /***************************************************************************
224  *
225  *      CFilterGraph::IDispatch
226  *
227  */
228
229 static HRESULT WINAPI
230 IDispatch_fnQueryInterface(IDispatch* iface,REFIID riid,void** ppobj)
231 {
232         CFilterGraph_THIS(iface,disp);
233
234         TRACE("(%p)->()\n",This);
235
236         return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
237 }
238
239 static ULONG WINAPI
240 IDispatch_fnAddRef(IDispatch* iface)
241 {
242         CFilterGraph_THIS(iface,disp);
243
244         TRACE("(%p)->()\n",This);
245
246         return IUnknown_AddRef(This->unk.punkControl);
247 }
248
249 static ULONG WINAPI
250 IDispatch_fnRelease(IDispatch* iface)
251 {
252         CFilterGraph_THIS(iface,disp);
253
254         TRACE("(%p)->()\n",This);
255
256         return IUnknown_Release(This->unk.punkControl);
257 }
258
259 static HRESULT WINAPI
260 IDispatch_fnGetTypeInfoCount(IDispatch* iface,UINT* pcTypeInfo)
261 {
262         CFilterGraph_THIS(iface,disp);
263
264         FIXME("(%p)->()\n",This);
265
266         return E_NOTIMPL;
267 }
268
269 static HRESULT WINAPI
270 IDispatch_fnGetTypeInfo(IDispatch* iface,UINT iTypeInfo, LCID lcid, ITypeInfo** ppobj)
271 {
272         CFilterGraph_THIS(iface,disp);
273
274         FIXME("(%p)->()\n",This);
275
276         return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI
280 IDispatch_fnGetIDsOfNames(IDispatch* iface,REFIID riid, LPOLESTR* ppwszName, UINT cNames, LCID lcid, DISPID* pDispId)
281 {
282         CFilterGraph_THIS(iface,disp);
283
284         FIXME("(%p)->()\n",This);
285
286         return E_NOTIMPL;
287 }
288
289 static HRESULT WINAPI
290 IDispatch_fnInvoke(IDispatch* iface,DISPID DispId, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarRes, EXCEPINFO* pExcepInfo, UINT* puArgErr)
291 {
292         CFilterGraph_THIS(iface,disp);
293
294         FIXME("(%p)->()\n",This);
295
296         return E_NOTIMPL;
297 }
298
299
300
301 static ICOM_VTABLE(IDispatch) idispatch =
302 {
303         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
304         /* IUnknown fields */
305         IDispatch_fnQueryInterface,
306         IDispatch_fnAddRef,
307         IDispatch_fnRelease,
308         /* IDispatch fields */
309         IDispatch_fnGetTypeInfoCount,
310         IDispatch_fnGetTypeInfo,
311         IDispatch_fnGetIDsOfNames,
312         IDispatch_fnInvoke,
313 };
314
315
316 HRESULT CFilterGraph_InitIDispatch( CFilterGraph* pfg )
317 {
318         TRACE("(%p)\n",pfg);
319         ICOM_VTBL(&pfg->disp) = &idispatch;
320
321         return NOERROR;
322 }
323
324 void CFilterGraph_UninitIDispatch( CFilterGraph* pfg )
325 {
326         TRACE("(%p)\n",pfg);
327 }