1 /* Capture Graph Builder, Minimal edition
3 * Copyright 2005 Maarten Lankhorst
4 * Copyright 2005 Rolf Kalbermatter
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
44 #include "qcap_main.h"
46 #include "wine/unicode.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(qcap
);
51 /***********************************************************************
52 * ICaptureGraphBuilder & ICaptureGraphBuilder2 implementation
54 typedef struct CaptureGraphImpl
56 const ICaptureGraphBuilder2Vtbl
* lpVtbl2
;
57 const ICaptureGraphBuilderVtbl
* lpVtbl
;
59 IGraphBuilder
*mygraph
;
61 CRITICAL_SECTION csFilter
;
64 static const ICaptureGraphBuilderVtbl builder_Vtbl
;
65 static const ICaptureGraphBuilder2Vtbl builder2_Vtbl
;
67 static inline CaptureGraphImpl
*impl_from_ICaptureGraphBuilder( ICaptureGraphBuilder
*iface
)
69 return (CaptureGraphImpl
*)((char*)iface
- FIELD_OFFSET(CaptureGraphImpl
, lpVtbl
));
72 static inline CaptureGraphImpl
*impl_from_ICaptureGraphBuilder2( ICaptureGraphBuilder2
*iface
)
74 return (CaptureGraphImpl
*)((char*)iface
- FIELD_OFFSET(CaptureGraphImpl
, lpVtbl2
));
78 converts This to an interface pointer
80 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl2)
81 #define _ICaptureGraphBuilder_(This) (ICaptureGraphBuilder*)&(This->lpVtbl)
82 #define _ICaptureGraphBuilder2_(This) (ICaptureGraphBuilder2*)&(This->lpVtbl2)
85 IUnknown
* CALLBACK
QCAP_createCaptureGraphBuilder2(IUnknown
*pUnkOuter
,
88 CaptureGraphImpl
* pCapture
= NULL
;
90 TRACE("(%p, %p)\n", pUnkOuter
, phr
);
92 *phr
= CLASS_E_NOAGGREGATION
;
99 pCapture
= CoTaskMemAlloc(sizeof(CaptureGraphImpl
));
102 pCapture
->lpVtbl2
= &builder2_Vtbl
;
103 pCapture
->lpVtbl
= &builder_Vtbl
;
105 pCapture
->mygraph
= NULL
;
106 InitializeCriticalSection(&pCapture
->csFilter
);
107 pCapture
->csFilter
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": CaptureGraphImpl.csFilter");
109 ObjectRefCount(TRUE
);
111 return (IUnknown
*)pCapture
;
114 static HRESULT WINAPI
115 fnCaptureGraphBuilder2_QueryInterface(ICaptureGraphBuilder2
* iface
,
119 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
121 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, debugstr_guid(riid
), ppv
);
124 if (IsEqualIID(riid
, &IID_IUnknown
))
125 *ppv
= _IUnknown_(This
);
126 else if (IsEqualIID(riid
, &IID_ICaptureGraphBuilder
))
127 *ppv
= _ICaptureGraphBuilder_(This
);
128 else if (IsEqualIID(riid
, &IID_ICaptureGraphBuilder2
))
129 *ppv
= _ICaptureGraphBuilder2_(This
);
133 IUnknown_AddRef((IUnknown
*)(*ppv
));
134 TRACE ("-- Interface = %p\n", *ppv
);
138 TRACE ("-- Interface: E_NOINTERFACE\n");
139 return E_NOINTERFACE
;
143 fnCaptureGraphBuilder2_AddRef(ICaptureGraphBuilder2
* iface
)
145 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
146 DWORD ref
= InterlockedIncrement(&This
->ref
);
148 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, ref
- 1);
153 fnCaptureGraphBuilder2_Release(ICaptureGraphBuilder2
* iface
)
155 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
156 DWORD ref
= InterlockedDecrement(&This
->ref
);
158 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, ref
+ 1);
162 FIXME("Release IGraphFilter or w/e\n");
163 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
164 DeleteCriticalSection(&This
->csFilter
);
166 This
->lpVtbl2
= NULL
;
167 if (This
->mygraph
!= NULL
)
168 IGraphBuilder_Release(This
->mygraph
);
170 ObjectRefCount(FALSE
);
175 static HRESULT WINAPI
176 fnCaptureGraphBuilder2_SetFilterGraph(ICaptureGraphBuilder2
* iface
,
179 /* The graph builder will automatically create a filter graph if you don't call
180 this method. If you call this method after the graph builder has created its
181 own filter graph, the call will fail. */
183 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
185 TRACE("(%p/%p)->(%p)\n", This
, iface
, pfg
);
194 IGraphBuilder_AddRef(This
->mygraph
);
195 if (SUCCEEDED(IUnknown_QueryInterface(This
->mygraph
,
196 &IID_IMediaEvent
, (LPVOID
*)&pmev
)))
198 IMediaEvent_CancelDefaultHandling(pmev
, EC_REPAINT
);
199 IMediaEvent_Release(pmev
);
204 static HRESULT WINAPI
205 fnCaptureGraphBuilder2_GetFilterGraph(ICaptureGraphBuilder2
* iface
,
208 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
210 TRACE("(%p/%p)->(%p)\n", This
, iface
, pfg
);
215 *pfg
= This
->mygraph
;
218 TRACE("(%p) Getting NULL filtergraph\n", iface
);
222 IGraphBuilder_AddRef(This
->mygraph
);
224 TRACE("(%p) return filtergraph %p\n", iface
, *pfg
);
228 static HRESULT WINAPI
229 fnCaptureGraphBuilder2_SetOutputFileName(ICaptureGraphBuilder2
* iface
,
233 IFileSinkFilter
**ppSink
)
235 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
237 FIXME("(%p/%p)->(%s, %s, %p, %p) Stub!\n", This
, iface
,
238 debugstr_guid(pType
), debugstr_w(lpstrFile
), ppf
, ppSink
);
243 static HRESULT WINAPI
244 fnCaptureGraphBuilder2_FindInterface(ICaptureGraphBuilder2
* iface
,
245 const GUID
*pCategory
,
251 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
253 FIXME("(%p/%p)->(%s, %s, %p, %s, %p) - workaround stub!\n", This
, iface
,
254 debugstr_guid(pCategory
), debugstr_guid(pType
),
255 pf
, debugstr_guid(riid
), ppint
);
257 return IBaseFilter_QueryInterface(pf
, riid
, ppint
);
258 /* Looks for the specified interface on the filter, upstream and
259 * downstream from the filter, and, optionally, only on the output
260 * pin of the given category.
264 static HRESULT WINAPI
265 fnCaptureGraphBuilder2_RenderStream(ICaptureGraphBuilder2
* iface
,
266 const GUID
*pCategory
,
269 IBaseFilter
*pfCompressor
,
270 IBaseFilter
*pfRenderer
)
272 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
274 FIXME("(%p/%p)->(%s, %s, %p, %p, %p) Stub!\n", This
, iface
,
275 debugstr_guid(pCategory
), debugstr_guid(pType
),
276 pSource
, pfCompressor
, pfRenderer
);
281 static HRESULT WINAPI
282 fnCaptureGraphBuilder2_ControlStream(ICaptureGraphBuilder2
* iface
,
283 const GUID
*pCategory
,
285 IBaseFilter
*pFilter
,
286 REFERENCE_TIME
*pstart
,
287 REFERENCE_TIME
*pstop
,
291 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
293 FIXME("(%p/%p)->(%s, %s, %p, %p, %p, %i, %i) Stub!\n", This
, iface
,
294 debugstr_guid(pCategory
), debugstr_guid(pType
),
295 pFilter
, pstart
, pstop
, wStartCookie
, wStopCookie
);
300 static HRESULT WINAPI
301 fnCaptureGraphBuilder2_AllocCapFile(ICaptureGraphBuilder2
* iface
,
305 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
307 FIXME("(%p/%p)->(%s, 0x%s) Stub!\n", This
, iface
,
308 debugstr_w(lpwstr
), wine_dbgstr_longlong(dwlSize
));
313 static HRESULT WINAPI
314 fnCaptureGraphBuilder2_CopyCaptureFile(ICaptureGraphBuilder2
* iface
,
318 IAMCopyCaptureFileProgress
*pCallback
)
320 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
322 FIXME("(%p/%p)->(%s, %s, %i, %p) Stub!\n", This
, iface
,
323 debugstr_w(lpwstrOld
), debugstr_w(lpwstrNew
),
324 fAllowEscAbort
, pCallback
);
329 static HRESULT WINAPI
330 fnCaptureGraphBuilder2_FindPin(ICaptureGraphBuilder2
* iface
,
332 PIN_DIRECTION pindir
,
333 const GUID
*pCategory
,
339 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder2(iface
);
341 FIXME("(%p/%p)->(%p, %x, %s, %s, %d, %i, %p) Stub!\n", This
, iface
,
342 pSource
, pindir
, debugstr_guid(pCategory
), debugstr_guid(pType
),
343 fUnconnected
, num
, ppPin
);
348 static const ICaptureGraphBuilder2Vtbl builder2_Vtbl
=
350 fnCaptureGraphBuilder2_QueryInterface
,
351 fnCaptureGraphBuilder2_AddRef
,
352 fnCaptureGraphBuilder2_Release
,
353 fnCaptureGraphBuilder2_SetFilterGraph
,
354 fnCaptureGraphBuilder2_GetFilterGraph
,
355 fnCaptureGraphBuilder2_SetOutputFileName
,
356 fnCaptureGraphBuilder2_FindInterface
,
357 fnCaptureGraphBuilder2_RenderStream
,
358 fnCaptureGraphBuilder2_ControlStream
,
359 fnCaptureGraphBuilder2_AllocCapFile
,
360 fnCaptureGraphBuilder2_CopyCaptureFile
,
361 fnCaptureGraphBuilder2_FindPin
365 static HRESULT WINAPI
366 fnCaptureGraphBuilder_QueryInterface(ICaptureGraphBuilder
* iface
,
367 REFIID riid
, LPVOID
* ppv
)
369 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
370 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
371 return IUnknown_QueryInterface(_ICaptureGraphBuilder2_(This
), riid
, ppv
);
375 fnCaptureGraphBuilder_AddRef(ICaptureGraphBuilder
* iface
)
377 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
378 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
379 return IUnknown_AddRef(_ICaptureGraphBuilder2_(This
));
383 fnCaptureGraphBuilder_Release(ICaptureGraphBuilder
* iface
)
385 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
386 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
387 return IUnknown_Release(_ICaptureGraphBuilder2_(This
));
390 static HRESULT WINAPI
391 fnCaptureGraphBuilder_SetFiltergraph(ICaptureGraphBuilder
* iface
,
394 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
395 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
396 return ICaptureGraphBuilder2_SetFiltergraph(_ICaptureGraphBuilder2_(This
), pfg
);
399 static HRESULT WINAPI
400 fnCaptureGraphBuilder_GetFiltergraph(ICaptureGraphBuilder
* iface
,
403 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
404 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
405 return ICaptureGraphBuilder2_GetFiltergraph(_ICaptureGraphBuilder2_(This
), pfg
);
408 static HRESULT WINAPI
409 fnCaptureGraphBuilder_SetOutputFileName(ICaptureGraphBuilder
* iface
,
410 const GUID
*pType
, LPCOLESTR lpstrFile
,
411 IBaseFilter
**ppf
, IFileSinkFilter
**ppSink
)
413 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
414 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
415 return ICaptureGraphBuilder2_SetOutputFileName(_ICaptureGraphBuilder2_(This
),
416 pType
, lpstrFile
, ppf
, ppSink
);
419 static HRESULT WINAPI
420 fnCaptureGraphBuilder_FindInterface(ICaptureGraphBuilder
* iface
,
421 const GUID
*pCategory
, IBaseFilter
*pf
,
422 REFIID riid
, void **ppint
)
424 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
425 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
426 return ICaptureGraphBuilder2_FindInterface(_ICaptureGraphBuilder2_(This
),
427 pCategory
, NULL
, pf
, riid
, ppint
);
430 static HRESULT WINAPI
431 fnCaptureGraphBuilder_RenderStream(ICaptureGraphBuilder
* iface
,
432 const GUID
*pCategory
, IUnknown
*pSource
,
433 IBaseFilter
*pfCompressor
, IBaseFilter
*pfRenderer
)
435 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
436 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
437 return ICaptureGraphBuilder2_RenderStream(_ICaptureGraphBuilder2_(This
),
438 pCategory
, NULL
, pSource
,
439 pfCompressor
, pfRenderer
);
442 static HRESULT WINAPI
443 fnCaptureGraphBuilder_ControlStream(ICaptureGraphBuilder
* iface
,
444 const GUID
*pCategory
, IBaseFilter
*pFilter
,
445 REFERENCE_TIME
*pstart
, REFERENCE_TIME
*pstop
,
446 WORD wStartCookie
, WORD wStopCookie
)
448 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
449 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
450 return ICaptureGraphBuilder2_ControlStream(_ICaptureGraphBuilder2_(This
),
451 pCategory
, NULL
, pFilter
, pstart
,
452 pstop
, wStartCookie
, wStopCookie
);
455 static HRESULT WINAPI
456 fnCaptureGraphBuilder_AllocCapFile(ICaptureGraphBuilder
* iface
,
457 LPCOLESTR lpstr
, DWORDLONG dwlSize
)
459 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
460 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
461 return ICaptureGraphBuilder2_AllocCapFile(_ICaptureGraphBuilder2_(This
),
465 static HRESULT WINAPI
466 fnCaptureGraphBuilder_CopyCaptureFile(ICaptureGraphBuilder
* iface
,
467 LPOLESTR lpwstrOld
, LPOLESTR lpwstrNew
,
469 IAMCopyCaptureFileProgress
*pCallback
)
471 CaptureGraphImpl
*This
= impl_from_ICaptureGraphBuilder(iface
);
472 TRACE("%p --> Forwarding to v2 (%p)\n", iface
, This
);
473 return ICaptureGraphBuilder2_CopyCaptureFile(_ICaptureGraphBuilder2_(This
),
474 lpwstrOld
, lpwstrNew
,
475 fAllowEscAbort
, pCallback
);
478 static const ICaptureGraphBuilderVtbl builder_Vtbl
=
480 fnCaptureGraphBuilder_QueryInterface
,
481 fnCaptureGraphBuilder_AddRef
,
482 fnCaptureGraphBuilder_Release
,
483 fnCaptureGraphBuilder_SetFiltergraph
,
484 fnCaptureGraphBuilder_GetFiltergraph
,
485 fnCaptureGraphBuilder_SetOutputFileName
,
486 fnCaptureGraphBuilder_FindInterface
,
487 fnCaptureGraphBuilder_RenderStream
,
488 fnCaptureGraphBuilder_ControlStream
,
489 fnCaptureGraphBuilder_AllocCapFile
,
490 fnCaptureGraphBuilder_CopyCaptureFile