xinput1_3: Move HID data into struct xinput_controller.
[wine.git] / dlls / qcap / capturegraph.c
blobe5c7d9c11205cd4b70e4d379b1c288cb5ae39fc6
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
21 #include "qcap_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
25 /***********************************************************************
26 * ICaptureGraphBuilder & ICaptureGraphBuilder2 implementation
28 typedef struct CaptureGraphImpl
30 ICaptureGraphBuilder2 ICaptureGraphBuilder2_iface;
31 ICaptureGraphBuilder ICaptureGraphBuilder_iface;
32 LONG ref;
33 IGraphBuilder *mygraph;
34 CRITICAL_SECTION csFilter;
35 } CaptureGraphImpl;
37 static const ICaptureGraphBuilderVtbl builder_Vtbl;
38 static const ICaptureGraphBuilder2Vtbl builder2_Vtbl;
40 static inline CaptureGraphImpl *impl_from_ICaptureGraphBuilder(ICaptureGraphBuilder *iface)
42 return CONTAINING_RECORD(iface, CaptureGraphImpl, ICaptureGraphBuilder_iface);
45 static inline CaptureGraphImpl *impl_from_ICaptureGraphBuilder2(ICaptureGraphBuilder2 *iface)
47 return CONTAINING_RECORD(iface, CaptureGraphImpl, ICaptureGraphBuilder2_iface);
51 HRESULT capture_graph_create(IUnknown *outer, IUnknown **out)
53 CaptureGraphImpl *object;
55 if (outer)
56 return CLASS_E_NOAGGREGATION;
58 if (!(object = calloc(1, sizeof(*object))))
59 return E_OUTOFMEMORY;
61 object->ICaptureGraphBuilder2_iface.lpVtbl = &builder2_Vtbl;
62 object->ICaptureGraphBuilder_iface.lpVtbl = &builder_Vtbl;
63 object->ref = 1;
64 object->mygraph = NULL;
65 InitializeCriticalSection(&object->csFilter);
66 object->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": CaptureGraphImpl.csFilter");
68 TRACE("Created capture graph builder %p.\n", object);
69 ObjectRefCount(TRUE);
70 *out = (IUnknown *)&object->ICaptureGraphBuilder_iface;
71 return S_OK;
74 static HRESULT WINAPI
75 fnCaptureGraphBuilder2_QueryInterface(ICaptureGraphBuilder2 * iface,
76 REFIID riid,
77 LPVOID * ppv)
79 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
81 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
83 *ppv = NULL;
84 if (IsEqualIID(riid, &IID_IUnknown))
85 *ppv = &This->ICaptureGraphBuilder2_iface;
86 else if (IsEqualIID(riid, &IID_ICaptureGraphBuilder))
87 *ppv = &This->ICaptureGraphBuilder_iface;
88 else if (IsEqualIID(riid, &IID_ICaptureGraphBuilder2))
89 *ppv = &This->ICaptureGraphBuilder2_iface;
91 if (*ppv)
93 IUnknown_AddRef((IUnknown *)(*ppv));
94 TRACE ("-- Interface = %p\n", *ppv);
95 return S_OK;
98 TRACE ("-- Interface: E_NOINTERFACE\n");
99 return E_NOINTERFACE;
102 static ULONG WINAPI
103 fnCaptureGraphBuilder2_AddRef(ICaptureGraphBuilder2 * iface)
105 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
106 DWORD ref = InterlockedIncrement(&This->ref);
108 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, ref - 1);
109 return ref;
112 static ULONG WINAPI fnCaptureGraphBuilder2_Release(ICaptureGraphBuilder2 * iface)
114 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
115 DWORD ref = InterlockedDecrement(&This->ref);
117 TRACE("(%p/%p)->() Release from %d\n", This, iface, ref + 1);
119 if (!ref)
121 This->csFilter.DebugInfo->Spare[0] = 0;
122 DeleteCriticalSection(&This->csFilter);
123 if (This->mygraph)
124 IGraphBuilder_Release(This->mygraph);
125 free(This);
126 ObjectRefCount(FALSE);
128 return ref;
131 static HRESULT WINAPI
132 fnCaptureGraphBuilder2_SetFilterGraph(ICaptureGraphBuilder2 * iface,
133 IGraphBuilder *pfg)
135 /* The graph builder will automatically create a filter graph if you don't call
136 this method. If you call this method after the graph builder has created its
137 own filter graph, the call will fail. */
138 IMediaEvent *pmev;
139 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
141 TRACE("(%p/%p)->(%p)\n", This, iface, pfg);
143 if (This->mygraph)
144 return E_UNEXPECTED;
146 if (!pfg)
147 return E_POINTER;
149 This->mygraph = pfg;
150 IGraphBuilder_AddRef(This->mygraph);
151 if (SUCCEEDED(IGraphBuilder_QueryInterface(This->mygraph,
152 &IID_IMediaEvent, (LPVOID *)&pmev)))
154 IMediaEvent_CancelDefaultHandling(pmev, EC_REPAINT);
155 IMediaEvent_Release(pmev);
157 return S_OK;
160 static HRESULT WINAPI
161 fnCaptureGraphBuilder2_GetFilterGraph(ICaptureGraphBuilder2 * iface,
162 IGraphBuilder **pfg)
164 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
166 TRACE("(%p/%p)->(%p)\n", This, iface, pfg);
168 if (!pfg)
169 return E_POINTER;
171 *pfg = This->mygraph;
172 if (!This->mygraph)
174 TRACE("(%p) Getting NULL filtergraph\n", iface);
175 return E_UNEXPECTED;
178 IGraphBuilder_AddRef(This->mygraph);
180 TRACE("(%p) return filtergraph %p\n", iface, *pfg);
181 return S_OK;
184 static HRESULT WINAPI
185 fnCaptureGraphBuilder2_SetOutputFileName(ICaptureGraphBuilder2 * iface,
186 const GUID *pType,
187 LPCOLESTR lpstrFile,
188 IBaseFilter **ppf,
189 IFileSinkFilter **ppSink)
191 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
193 FIXME("(%p/%p)->(%s, %s, %p, %p) Stub!\n", This, iface,
194 debugstr_guid(pType), debugstr_w(lpstrFile), ppf, ppSink);
196 return E_NOTIMPL;
199 static BOOL pin_has_majortype(IPin *pin, const GUID *majortype)
201 IEnumMediaTypes *enummt;
202 AM_MEDIA_TYPE *mt;
204 if (FAILED(IPin_EnumMediaTypes(pin, &enummt)))
205 return FALSE;
207 while (IEnumMediaTypes_Next(enummt, 1, &mt, NULL) == S_OK)
209 if (IsEqualGUID(&mt->majortype, majortype))
211 DeleteMediaType(mt);
212 IEnumMediaTypes_Release(enummt);
213 return TRUE;
215 DeleteMediaType(mt);
217 IEnumMediaTypes_Release(enummt);
218 return FALSE;
221 static BOOL pin_matches(IPin *pin, PIN_DIRECTION dir, const GUID *category,
222 const GUID *majortype, BOOL unconnected)
224 PIN_DIRECTION candidate_dir;
225 HRESULT hr;
226 IPin *peer;
228 if (FAILED(hr = IPin_QueryDirection(pin, &candidate_dir)))
229 ERR("Failed to query direction, hr %#x.\n", hr);
231 if (dir != candidate_dir)
232 return FALSE;
234 if (unconnected && IPin_ConnectedTo(pin, &peer) == S_OK && peer)
236 IPin_Release(peer);
237 return FALSE;
240 if (category)
242 IKsPropertySet *set;
243 GUID property;
244 DWORD size;
246 if (FAILED(IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **)&set)))
247 return FALSE;
249 hr = IKsPropertySet_Get(set, &AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,
250 NULL, 0, &property, sizeof(property), &size);
251 IKsPropertySet_Release(set);
252 if (FAILED(hr) || !IsEqualGUID(&property, category))
253 return FALSE;
256 if (majortype && !pin_has_majortype(pin, majortype))
257 return FALSE;
259 return TRUE;
262 static HRESULT find_interface_recurse(PIN_DIRECTION dir, const GUID *category,
263 const GUID *majortype, IBaseFilter *filter, REFIID iid, void **out)
265 BOOL found_category = FALSE;
266 IEnumPins *enumpins;
267 IPin *pin, *peer;
268 PIN_INFO info;
269 HRESULT hr;
271 TRACE("Looking for %s pins, category %s, majortype %s from filter %p.\n",
272 dir == PINDIR_INPUT ? "sink" : "source", debugstr_guid(category),
273 debugstr_guid(majortype), filter);
275 if (FAILED(hr = IBaseFilter_EnumPins(filter, &enumpins)))
277 ERR("Failed to enumerate pins, hr %#x.\n", hr);
278 return hr;
281 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
283 if (!pin_matches(pin, dir, category, majortype, FALSE))
285 IPin_Release(pin);
286 continue;
289 if (category)
290 found_category = TRUE;
292 if (IPin_QueryInterface(pin, iid, out) == S_OK)
294 IPin_Release(pin);
295 IEnumPins_Release(enumpins);
296 return S_OK;
299 hr = IPin_ConnectedTo(pin, &peer);
300 IPin_Release(pin);
301 if (hr == S_OK)
303 if (IPin_QueryInterface(peer, iid, out) == S_OK)
305 IPin_Release(peer);
306 IEnumPins_Release(enumpins);
307 return S_OK;
310 IPin_QueryPinInfo(peer, &info);
311 IPin_Release(peer);
313 if (IBaseFilter_QueryInterface(info.pFilter, iid, out) == S_OK)
315 IBaseFilter_Release(info.pFilter);
316 IEnumPins_Release(enumpins);
317 return S_OK;
320 hr = find_interface_recurse(dir, NULL, NULL, info.pFilter, iid, out);
321 IBaseFilter_Release(info.pFilter);
322 if (hr == S_OK)
324 IEnumPins_Release(enumpins);
325 return S_OK;
329 IEnumPins_Release(enumpins);
331 if (category && !found_category)
332 return E_NOINTERFACE;
334 return E_FAIL;
337 static HRESULT WINAPI fnCaptureGraphBuilder2_FindInterface(ICaptureGraphBuilder2 *iface,
338 const GUID *category, const GUID *majortype, IBaseFilter *filter, REFIID iid, void **out)
340 CaptureGraphImpl *graph = impl_from_ICaptureGraphBuilder2(iface);
341 HRESULT hr;
343 TRACE("graph %p, category %s, majortype %s, filter %p, iid %s, out %p.\n",
344 graph, debugstr_guid(category), debugstr_guid(majortype), filter, debugstr_guid(iid), out);
346 if (!filter)
347 return E_POINTER;
349 if (category && IsEqualGUID(category, &LOOK_DOWNSTREAM_ONLY))
350 return find_interface_recurse(PINDIR_OUTPUT, NULL, NULL, filter, iid, out);
352 if (category && IsEqualGUID(category, &LOOK_UPSTREAM_ONLY))
353 return find_interface_recurse(PINDIR_INPUT, NULL, NULL, filter, iid, out);
355 if (IBaseFilter_QueryInterface(filter, iid, out) == S_OK)
356 return S_OK;
358 if (!category)
359 majortype = NULL;
361 hr = find_interface_recurse(PINDIR_OUTPUT, category, majortype, filter, iid, out);
362 if (hr == S_OK || hr == E_NOINTERFACE)
363 return hr;
365 return find_interface_recurse(PINDIR_INPUT, NULL, NULL, filter, iid, out);
368 static HRESULT match_smart_tee_pin(CaptureGraphImpl *This,
369 const GUID *pCategory,
370 const GUID *pType,
371 IUnknown *pSource,
372 IPin **source_out)
374 IPin *capture = NULL;
375 IPin *preview = NULL;
376 IPin *peer = NULL;
377 IBaseFilter *smartTee = NULL;
378 BOOL needSmartTee = FALSE;
379 HRESULT hr;
381 TRACE("(%p, %s, %s, %p, %p)\n", This, debugstr_guid(pCategory), debugstr_guid(pType), pSource, source_out);
382 hr = ICaptureGraphBuilder2_FindPin(&This->ICaptureGraphBuilder2_iface, pSource,
383 PINDIR_OUTPUT, &PIN_CATEGORY_CAPTURE, pType, FALSE, 0, &capture);
384 if (SUCCEEDED(hr)) {
385 hr = ICaptureGraphBuilder2_FindPin(&This->ICaptureGraphBuilder2_iface, pSource,
386 PINDIR_OUTPUT, &PIN_CATEGORY_PREVIEW, pType, FALSE, 0, &preview);
387 if (FAILED(hr))
388 needSmartTee = TRUE;
389 } else {
390 hr = E_INVALIDARG;
391 goto end;
393 if (!needSmartTee) {
394 if (IsEqualIID(pCategory, &PIN_CATEGORY_CAPTURE)) {
395 hr = IPin_ConnectedTo(capture, &peer);
396 if (hr == VFW_E_NOT_CONNECTED) {
397 *source_out = capture;
398 IPin_AddRef(*source_out);
399 hr = S_OK;
400 } else
401 hr = E_INVALIDARG;
402 } else {
403 hr = IPin_ConnectedTo(preview, &peer);
404 if (hr == VFW_E_NOT_CONNECTED) {
405 *source_out = preview;
406 IPin_AddRef(*source_out);
407 hr = S_OK;
408 } else
409 hr = E_INVALIDARG;
411 goto end;
413 hr = IPin_ConnectedTo(capture, &peer);
414 if (SUCCEEDED(hr)) {
415 PIN_INFO pinInfo;
416 GUID classID;
417 hr = IPin_QueryPinInfo(peer, &pinInfo);
418 if (SUCCEEDED(hr)) {
419 hr = IBaseFilter_GetClassID(pinInfo.pFilter, &classID);
420 if (SUCCEEDED(hr)) {
421 if (IsEqualIID(&classID, &CLSID_SmartTee)) {
422 smartTee = pinInfo.pFilter;
423 IBaseFilter_AddRef(smartTee);
426 IBaseFilter_Release(pinInfo.pFilter);
428 if (!smartTee) {
429 hr = E_INVALIDARG;
430 goto end;
432 } else if (hr == VFW_E_NOT_CONNECTED) {
433 hr = CoCreateInstance(&CLSID_SmartTee, NULL, CLSCTX_INPROC_SERVER,
434 &IID_IBaseFilter, (LPVOID*)&smartTee);
435 if (SUCCEEDED(hr)) {
436 hr = IGraphBuilder_AddFilter(This->mygraph, smartTee, NULL);
437 if (SUCCEEDED(hr)) {
438 IPin *smartTeeInput = NULL;
439 hr = IBaseFilter_FindPin(smartTee, L"Input", &smartTeeInput);
440 if (SUCCEEDED(hr)) {
441 hr = IGraphBuilder_ConnectDirect(This->mygraph, capture, smartTeeInput, NULL);
442 IPin_Release(smartTeeInput);
446 if (FAILED(hr)) {
447 TRACE("adding SmartTee failed with hr=0x%08x\n", hr);
448 hr = E_INVALIDARG;
449 goto end;
451 } else {
452 hr = E_INVALIDARG;
453 goto end;
455 if (IsEqualIID(pCategory, &PIN_CATEGORY_CAPTURE))
456 hr = IBaseFilter_FindPin(smartTee, L"Capture", source_out);
457 else {
458 hr = IBaseFilter_FindPin(smartTee, L"Preview", source_out);
459 if (SUCCEEDED(hr))
460 hr = VFW_S_NOPREVIEWPIN;
463 end:
464 if (capture)
465 IPin_Release(capture);
466 if (preview)
467 IPin_Release(preview);
468 if (peer)
469 IPin_Release(peer);
470 if (smartTee)
471 IBaseFilter_Release(smartTee);
472 TRACE("for %s returning hr=0x%08x, *source_out=%p\n", IsEqualIID(pCategory, &PIN_CATEGORY_CAPTURE) ? "capture" : "preview", hr, source_out ? *source_out : 0);
473 return hr;
476 static HRESULT find_unconnected_source_from_filter(CaptureGraphImpl *capture_graph,
477 const GUID *category, const GUID *majortype, IBaseFilter *filter, IPin **ret);
479 static HRESULT find_unconnected_source_from_pin(CaptureGraphImpl *capture_graph,
480 const GUID *category, const GUID *majortype, IPin *pin, IPin **ret)
482 PIN_DIRECTION dir;
483 PIN_INFO info;
484 HRESULT hr;
485 IPin *peer;
487 IPin_QueryDirection(pin, &dir);
488 if (dir != PINDIR_OUTPUT)
489 return VFW_E_INVALID_DIRECTION;
491 if (category && (IsEqualGUID(category, &PIN_CATEGORY_CAPTURE)
492 || IsEqualGUID(category, &PIN_CATEGORY_PREVIEW)))
494 if (FAILED(hr = match_smart_tee_pin(capture_graph, category, majortype, (IUnknown *)pin, &pin)))
495 return hr;
497 if (FAILED(IPin_ConnectedTo(pin, &peer)))
499 *ret = pin;
500 return S_OK;
503 else
505 if (FAILED(IPin_ConnectedTo(pin, &peer)))
507 if (!pin_matches(pin, PINDIR_OUTPUT, category, majortype, FALSE))
508 return E_FAIL;
510 IPin_AddRef(*ret = pin);
511 return S_OK;
513 IPin_AddRef(pin);
516 IPin_QueryPinInfo(peer, &info);
517 hr = find_unconnected_source_from_filter(capture_graph, category, majortype, info.pFilter, ret);
518 IBaseFilter_Release(info.pFilter);
519 IPin_Release(peer);
520 IPin_Release(pin);
521 return hr;
524 static HRESULT find_unconnected_source_from_filter(CaptureGraphImpl *capture_graph,
525 const GUID *category, const GUID *majortype, IBaseFilter *filter, IPin **ret)
527 IEnumPins *enumpins;
528 IPin *pin, *peer;
529 HRESULT hr;
531 if (category && (IsEqualGUID(category, &PIN_CATEGORY_CAPTURE)
532 || IsEqualGUID(category, &PIN_CATEGORY_PREVIEW)))
534 if (FAILED(hr = match_smart_tee_pin(capture_graph, category, majortype, (IUnknown *)filter, &pin)))
535 return hr;
537 if (FAILED(IPin_ConnectedTo(pin, &peer)))
539 *ret = pin;
540 return hr;
543 IPin_Release(peer);
544 IPin_Release(pin);
545 return E_INVALIDARG;
548 if (FAILED(hr = IBaseFilter_EnumPins(filter, &enumpins)))
549 return hr;
551 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
553 if (SUCCEEDED(hr = find_unconnected_source_from_pin(capture_graph, category, majortype, pin, ret)))
555 IEnumPins_Release(enumpins);
556 IPin_Release(pin);
557 return hr;
559 IPin_Release(pin);
561 IEnumPins_Release(enumpins);
563 return E_INVALIDARG;
566 static HRESULT WINAPI fnCaptureGraphBuilder2_RenderStream(ICaptureGraphBuilder2 *iface,
567 const GUID *category, const GUID *majortype, IUnknown *source,
568 IBaseFilter *pfCompressor, IBaseFilter *pfRenderer)
570 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
571 IPin *source_out = NULL, *renderer_in;
572 BOOL rendererNeedsRelease = FALSE;
573 HRESULT hr, return_hr = S_OK;
574 IBaseFilter *filter;
575 IPin *pin;
577 TRACE("graph %p, category %s, majortype %s, source %p, intermediate %p, sink %p.\n",
578 This, debugstr_guid(category), debugstr_guid(majortype), source, pfCompressor, pfRenderer);
580 if (!This->mygraph)
582 FIXME("Need a capture graph\n");
583 return E_UNEXPECTED;
586 if (category && IsEqualGUID(category, &PIN_CATEGORY_VBI))
588 FIXME("Tee/Sink-to-Sink filter not supported\n");
589 return E_NOTIMPL;
592 if (IUnknown_QueryInterface(source, &IID_IPin, (void **)&pin) == S_OK)
594 hr = find_unconnected_source_from_pin(This, category, majortype, pin, &source_out);
595 IPin_Release(pin);
597 else if (IUnknown_QueryInterface(source, &IID_IBaseFilter, (void **)&filter) == S_OK)
599 hr = find_unconnected_source_from_filter(This, category, majortype, filter, &source_out);
600 IBaseFilter_Release(filter);
602 else
604 WARN("Source object does not expose IBaseFilter or IPin.\n");
605 return E_INVALIDARG;
607 if (FAILED(hr))
608 return hr;
609 return_hr = hr;
611 if (!pfRenderer)
613 IEnumMediaTypes *enumMedia = NULL;
614 hr = IPin_EnumMediaTypes(source_out, &enumMedia);
615 if (SUCCEEDED(hr)) {
616 AM_MEDIA_TYPE *mediaType;
617 hr = IEnumMediaTypes_Next(enumMedia, 1, &mediaType, NULL);
618 if (SUCCEEDED(hr)) {
619 if (IsEqualIID(&mediaType->majortype, &MEDIATYPE_Video)) {
620 hr = CoCreateInstance(&CLSID_VideoRenderer, NULL, CLSCTX_INPROC_SERVER,
621 &IID_IBaseFilter, (void**)&pfRenderer);
622 } else if (IsEqualIID(&mediaType->majortype, &MEDIATYPE_Audio)) {
623 hr = CoCreateInstance(&CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER,
624 &IID_IBaseFilter, (void**)&pfRenderer);
625 } else {
626 FIXME("cannot automatically load renderer for majortype %s\n", debugstr_guid(&mediaType->majortype));
627 hr = E_FAIL;
629 if (SUCCEEDED(hr)) {
630 rendererNeedsRelease = TRUE;
631 hr = IGraphBuilder_AddFilter(This->mygraph, pfRenderer, NULL);
633 DeleteMediaType(mediaType);
635 IEnumMediaTypes_Release(enumMedia);
637 if (FAILED(hr)) {
638 if (rendererNeedsRelease)
639 IBaseFilter_Release(pfRenderer);
640 IPin_Release(source_out);
641 return hr;
645 hr = ICaptureGraphBuilder2_FindPin(iface, (IUnknown*)pfRenderer, PINDIR_INPUT, NULL, NULL, TRUE, 0, &renderer_in);
646 if (FAILED(hr))
648 if (rendererNeedsRelease)
649 IBaseFilter_Release(pfRenderer);
650 IPin_Release(source_out);
651 return hr;
654 if (!pfCompressor)
655 hr = IGraphBuilder_Connect(This->mygraph, source_out, renderer_in);
656 else
658 IPin *compressor_in, *compressor_out;
660 hr = ICaptureGraphBuilder2_FindPin(iface, (IUnknown*)pfCompressor,
661 PINDIR_INPUT, NULL, NULL, TRUE, 0, &compressor_in);
662 if (SUCCEEDED(hr))
664 hr = IGraphBuilder_Connect(This->mygraph, source_out, compressor_in);
665 IPin_Release(compressor_in);
668 if (SUCCEEDED(hr))
670 hr = ICaptureGraphBuilder2_FindPin(iface, (IUnknown*)pfCompressor,
671 PINDIR_OUTPUT, NULL, NULL, TRUE, 0, &compressor_out);
672 if (SUCCEEDED(hr))
674 hr = IGraphBuilder_Connect(This->mygraph, compressor_out, renderer_in);
675 IPin_Release(compressor_out);
680 IPin_Release(source_out);
681 IPin_Release(renderer_in);
682 if (rendererNeedsRelease)
683 IBaseFilter_Release(pfRenderer);
684 if (SUCCEEDED(hr))
685 return return_hr;
686 return hr;
689 static HRESULT WINAPI
690 fnCaptureGraphBuilder2_ControlStream(ICaptureGraphBuilder2 * iface,
691 const GUID *pCategory,
692 const GUID *pType,
693 IBaseFilter *pFilter,
694 REFERENCE_TIME *pstart,
695 REFERENCE_TIME *pstop,
696 WORD wStartCookie,
697 WORD wStopCookie)
699 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
701 FIXME("(%p/%p)->(%s, %s, %p, %p, %p, %i, %i) Stub!\n", This, iface,
702 debugstr_guid(pCategory), debugstr_guid(pType),
703 pFilter, pstart, pstop, wStartCookie, wStopCookie);
705 return E_NOTIMPL;
708 static HRESULT WINAPI
709 fnCaptureGraphBuilder2_AllocCapFile(ICaptureGraphBuilder2 * iface,
710 LPCOLESTR lpwstr,
711 DWORDLONG dwlSize)
713 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
715 FIXME("(%p/%p)->(%s, 0x%s) Stub!\n", This, iface,
716 debugstr_w(lpwstr), wine_dbgstr_longlong(dwlSize));
718 return E_NOTIMPL;
721 static HRESULT WINAPI
722 fnCaptureGraphBuilder2_CopyCaptureFile(ICaptureGraphBuilder2 * iface,
723 LPOLESTR lpwstrOld,
724 LPOLESTR lpwstrNew,
725 int fAllowEscAbort,
726 IAMCopyCaptureFileProgress *pCallback)
728 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
730 FIXME("(%p/%p)->(%s, %s, %i, %p) Stub!\n", This, iface,
731 debugstr_w(lpwstrOld), debugstr_w(lpwstrNew),
732 fAllowEscAbort, pCallback);
734 return E_NOTIMPL;
737 static HRESULT WINAPI
738 fnCaptureGraphBuilder2_FindPin(ICaptureGraphBuilder2 * iface,
739 IUnknown *pSource,
740 PIN_DIRECTION pindir,
741 const GUID *pCategory,
742 const GUID *pType,
743 BOOL fUnconnected,
744 INT num,
745 IPin **ppPin)
747 HRESULT hr;
748 IEnumPins *enumpins = NULL;
749 IPin *pin;
750 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder2(iface);
752 TRACE("(%p/%p)->(%p, %x, %s, %s, %d, %i, %p)\n", This, iface,
753 pSource, pindir, debugstr_guid(pCategory), debugstr_guid(pType),
754 fUnconnected, num, ppPin);
756 pin = NULL;
758 hr = IUnknown_QueryInterface(pSource, &IID_IPin, (void**)&pin);
759 if (hr == E_NOINTERFACE)
761 IBaseFilter *filter = NULL;
762 int numcurrent = 0;
764 hr = IUnknown_QueryInterface(pSource, &IID_IBaseFilter, (void**)&filter);
765 if (hr == E_NOINTERFACE)
767 WARN("Input not filter or pin?!\n");
768 return E_NOINTERFACE;
771 hr = IBaseFilter_EnumPins(filter, &enumpins);
772 if (FAILED(hr))
774 WARN("Could not enumerate\n");
775 IBaseFilter_Release(filter);
776 return hr;
779 while (1)
781 ULONG fetched;
783 hr = IEnumPins_Next(enumpins, 1, &pin, &fetched);
784 if (hr == VFW_E_ENUM_OUT_OF_SYNC)
786 numcurrent = 0;
787 IEnumPins_Reset(enumpins);
788 pin = NULL;
789 continue;
791 if (hr != S_OK)
792 break;
793 if (fetched != 1)
795 hr = E_FAIL;
796 break;
799 TRACE("Testing match\n");
800 if (pin_matches(pin, pindir, pCategory, pType, fUnconnected) && numcurrent++ == num)
801 break;
802 IPin_Release(pin);
803 pin = NULL;
805 IEnumPins_Release(enumpins);
806 IBaseFilter_Release(filter);
808 if (hr != S_OK)
810 WARN("Could not find %s pin # %d\n", (pindir == PINDIR_OUTPUT ? "output" : "input"), numcurrent);
811 return E_FAIL;
814 else if (!pin_matches(pin, pindir, pCategory, pType, fUnconnected))
816 IPin_Release(pin);
817 return E_FAIL;
820 *ppPin = pin;
821 return S_OK;
824 static const ICaptureGraphBuilder2Vtbl builder2_Vtbl =
826 fnCaptureGraphBuilder2_QueryInterface,
827 fnCaptureGraphBuilder2_AddRef,
828 fnCaptureGraphBuilder2_Release,
829 fnCaptureGraphBuilder2_SetFilterGraph,
830 fnCaptureGraphBuilder2_GetFilterGraph,
831 fnCaptureGraphBuilder2_SetOutputFileName,
832 fnCaptureGraphBuilder2_FindInterface,
833 fnCaptureGraphBuilder2_RenderStream,
834 fnCaptureGraphBuilder2_ControlStream,
835 fnCaptureGraphBuilder2_AllocCapFile,
836 fnCaptureGraphBuilder2_CopyCaptureFile,
837 fnCaptureGraphBuilder2_FindPin
841 static HRESULT WINAPI
842 fnCaptureGraphBuilder_QueryInterface(ICaptureGraphBuilder * iface,
843 REFIID riid, LPVOID * ppv)
845 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
846 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
847 return ICaptureGraphBuilder2_QueryInterface(&This->ICaptureGraphBuilder2_iface, riid, ppv);
850 static ULONG WINAPI
851 fnCaptureGraphBuilder_AddRef(ICaptureGraphBuilder * iface)
853 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
854 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
855 return ICaptureGraphBuilder2_AddRef(&This->ICaptureGraphBuilder2_iface);
858 static ULONG WINAPI
859 fnCaptureGraphBuilder_Release(ICaptureGraphBuilder * iface)
861 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
862 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
863 return ICaptureGraphBuilder2_Release(&This->ICaptureGraphBuilder2_iface);
866 static HRESULT WINAPI
867 fnCaptureGraphBuilder_SetFiltergraph(ICaptureGraphBuilder * iface,
868 IGraphBuilder *pfg)
870 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
871 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
872 return ICaptureGraphBuilder2_SetFiltergraph(&This->ICaptureGraphBuilder2_iface, pfg);
875 static HRESULT WINAPI
876 fnCaptureGraphBuilder_GetFiltergraph(ICaptureGraphBuilder * iface,
877 IGraphBuilder **pfg)
879 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
880 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
881 return ICaptureGraphBuilder2_GetFiltergraph(&This->ICaptureGraphBuilder2_iface, pfg);
884 static HRESULT WINAPI
885 fnCaptureGraphBuilder_SetOutputFileName(ICaptureGraphBuilder * iface,
886 const GUID *pType, LPCOLESTR lpstrFile,
887 IBaseFilter **ppf, IFileSinkFilter **ppSink)
889 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
890 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
891 return ICaptureGraphBuilder2_SetOutputFileName(&This->ICaptureGraphBuilder2_iface, pType,
892 lpstrFile, ppf, ppSink);
895 static HRESULT WINAPI
896 fnCaptureGraphBuilder_FindInterface(ICaptureGraphBuilder * iface,
897 const GUID *pCategory, IBaseFilter *pf,
898 REFIID riid, void **ppint)
900 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
901 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
902 return ICaptureGraphBuilder2_FindInterface(&This->ICaptureGraphBuilder2_iface, pCategory, NULL,
903 pf, riid, ppint);
906 static HRESULT WINAPI
907 fnCaptureGraphBuilder_RenderStream(ICaptureGraphBuilder * iface,
908 const GUID *pCategory, IUnknown *pSource,
909 IBaseFilter *pfCompressor, IBaseFilter *pfRenderer)
911 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
912 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
913 return ICaptureGraphBuilder2_RenderStream(&This->ICaptureGraphBuilder2_iface, pCategory, NULL,
914 pSource, pfCompressor, pfRenderer);
917 static HRESULT WINAPI
918 fnCaptureGraphBuilder_ControlStream(ICaptureGraphBuilder * iface,
919 const GUID *pCategory, IBaseFilter *pFilter,
920 REFERENCE_TIME *pstart, REFERENCE_TIME *pstop,
921 WORD wStartCookie, WORD wStopCookie)
923 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
924 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
925 return ICaptureGraphBuilder2_ControlStream(&This->ICaptureGraphBuilder2_iface, pCategory, NULL,
926 pFilter, pstart, pstop, wStartCookie, wStopCookie);
929 static HRESULT WINAPI
930 fnCaptureGraphBuilder_AllocCapFile(ICaptureGraphBuilder * iface,
931 LPCOLESTR lpstr, DWORDLONG dwlSize)
933 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
934 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
935 return ICaptureGraphBuilder2_AllocCapFile(&This->ICaptureGraphBuilder2_iface, lpstr, dwlSize);
938 static HRESULT WINAPI
939 fnCaptureGraphBuilder_CopyCaptureFile(ICaptureGraphBuilder * iface,
940 LPOLESTR lpwstrOld, LPOLESTR lpwstrNew,
941 int fAllowEscAbort,
942 IAMCopyCaptureFileProgress *pCallback)
944 CaptureGraphImpl *This = impl_from_ICaptureGraphBuilder(iface);
945 TRACE("%p --> Forwarding to v2 (%p)\n", iface, This);
946 return ICaptureGraphBuilder2_CopyCaptureFile(&This->ICaptureGraphBuilder2_iface, lpwstrOld,
947 lpwstrNew, fAllowEscAbort, pCallback);
950 static const ICaptureGraphBuilderVtbl builder_Vtbl =
952 fnCaptureGraphBuilder_QueryInterface,
953 fnCaptureGraphBuilder_AddRef,
954 fnCaptureGraphBuilder_Release,
955 fnCaptureGraphBuilder_SetFiltergraph,
956 fnCaptureGraphBuilder_GetFiltergraph,
957 fnCaptureGraphBuilder_SetOutputFileName,
958 fnCaptureGraphBuilder_FindInterface,
959 fnCaptureGraphBuilder_RenderStream,
960 fnCaptureGraphBuilder_ControlStream,
961 fnCaptureGraphBuilder_AllocCapFile,
962 fnCaptureGraphBuilder_CopyCaptureFile