mcicda: Exclude unused headers.
[wine] / dlls / qcap / vfwcapture.c
1 /* Video For Windows Steering structure
2  *
3  * Copyright 2005 Maarten Lankhorst
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  *
19  */
20
21 #define NONAMELESSSTRUCT
22 #define NONAMELESSUNION
23 #define COBJMACROS
24
25 #include "config.h"
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wtypes.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "dshow.h"
34
35 #include "qcap_main.h"
36 #include "wine/debug.h"
37
38 #include "pin.h"
39 #include "capture.h"
40 #include "uuids.h"
41 #include "mmreg.h"
42 #include "vfwmsgs.h"
43 #include "amvideo.h"
44 #include "strmif.h"
45 #include "ddraw.h"
46 #include "ocidl.h"
47 #include "oleauto.h"
48
49 WINE_DEFAULT_DEBUG_CHANNEL(qcap);
50
51 #define ICOM_THIS_MULTI(impl,field,iface) \
52     impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
53
54 static const IBaseFilterVtbl VfwCapture_Vtbl;
55 static const IAMStreamConfigVtbl IAMStreamConfig_VTable;
56 static const IAMVideoProcAmpVtbl IAMVideoProcAmp_VTable;
57 static const IPersistPropertyBagVtbl IPersistPropertyBag_VTable;
58 static const IPinVtbl VfwPin_Vtbl;
59
60 static HRESULT VfwPin_Construct( IBaseFilter *, LPCRITICAL_SECTION, IPin ** );
61
62 typedef struct VfwCapture
63 {
64     const IBaseFilterVtbl * lpVtbl;
65     const IAMStreamConfigVtbl * IAMStreamConfig_vtbl;
66     const IAMVideoProcAmpVtbl * IAMVideoProcAmp_vtbl;
67     const IPersistPropertyBagVtbl * IPersistPropertyBag_vtbl;
68
69     BOOL init;
70     Capture *driver_info;
71     LONG refCount;
72     FILTER_INFO filterInfo;
73     FILTER_STATE state;
74     CRITICAL_SECTION csFilter;
75
76     IPin * pOutputPin;
77 } VfwCapture;
78
79 /* VfwPin implementation */
80 typedef struct VfwPinImpl
81 {
82     OutputPin pin;
83     Capture *driver_info;
84     const IKsPropertySetVtbl * KSP_VT;
85 } VfwPinImpl;
86
87
88 IUnknown * WINAPI QCAP_createVFWCaptureFilter(IUnknown *pUnkOuter, HRESULT *phr)
89 {
90     VfwCapture *pVfwCapture;
91     HRESULT hr;
92
93     TRACE("%p - %p\n", pUnkOuter, phr);
94
95     *phr = CLASS_E_NOAGGREGATION;
96     if (pUnkOuter)
97         return NULL;
98     *phr = E_OUTOFMEMORY;
99
100     pVfwCapture = CoTaskMemAlloc( sizeof(VfwCapture) );
101
102     if (!pVfwCapture)
103         return NULL;
104
105     pVfwCapture->lpVtbl = &VfwCapture_Vtbl;
106     pVfwCapture->IAMStreamConfig_vtbl = &IAMStreamConfig_VTable;
107     pVfwCapture->IAMVideoProcAmp_vtbl = &IAMVideoProcAmp_VTable;
108     pVfwCapture->IPersistPropertyBag_vtbl = &IPersistPropertyBag_VTable;
109     pVfwCapture->refCount = 1;
110     pVfwCapture->filterInfo.achName[0] = '\0';
111     pVfwCapture->filterInfo.pGraph = NULL;
112     pVfwCapture->state = State_Stopped;
113     pVfwCapture->init = FALSE;
114     InitializeCriticalSection(&pVfwCapture->csFilter);
115     pVfwCapture->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": VfwCapture.csFilter");
116     hr = VfwPin_Construct((IBaseFilter *)&pVfwCapture->lpVtbl,
117                    &pVfwCapture->csFilter, &pVfwCapture->pOutputPin);
118     if (!SUCCEEDED(hr))
119     {
120         CoTaskMemFree(pVfwCapture);
121         return NULL;
122     }
123     TRACE("-- created at %p\n", pVfwCapture);
124
125     ObjectRefCount(TRUE);
126     *phr = S_OK;
127     return (IUnknown *)pVfwCapture;
128 }
129
130 static HRESULT WINAPI VfwCapture_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
131 {
132     VfwCapture *This = (VfwCapture *)iface;
133     TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
134     *ppv = NULL;
135
136     if (IsEqualIID(riid, &IID_IUnknown) ||
137         IsEqualIID(riid, &IID_IPersist) ||
138         IsEqualIID(riid, &IID_IMediaFilter) ||
139         IsEqualIID(riid, &IID_IBaseFilter))
140     {
141         *ppv = This;
142     }
143     else if (IsEqualIID(riid, &IID_IAMStreamConfig))
144         *ppv = &(This->IAMStreamConfig_vtbl);
145     else if (IsEqualIID(riid, &IID_IAMVideoProcAmp))
146         *ppv = &(This->IAMVideoProcAmp_vtbl);
147     else if (IsEqualIID(riid, &IID_IPersistPropertyBag))
148         *ppv = &(This->IPersistPropertyBag_vtbl);
149
150     if (!IsEqualIID(riid, &IID_IUnknown) &&
151         !IsEqualIID(riid, &IID_IPersist) &&
152         !IsEqualIID(riid, &IID_IPersistPropertyBag) &&
153         !This->init)
154     {
155         FIXME("Capture system not initialised when looking for %s, "
156               "trying it on primary device now\n", debugstr_guid(riid));
157         This->driver_info = qcap_driver_init( This->pOutputPin, 0 );
158         if (!This->driver_info)
159         {
160             ERR("VfwCapture initialisation failed\n");
161             return E_UNEXPECTED;
162         }
163         This->init = TRUE;
164     }
165
166     if (*ppv)
167     {
168         TRACE("Returning %s interface\n", debugstr_guid(riid));
169         IUnknown_AddRef((IUnknown *)(*ppv));
170         return S_OK;
171     }
172
173     FIXME("No interface for %s!\n", debugstr_guid(riid));
174     return E_NOINTERFACE;
175 }
176
177 static ULONG WINAPI VfwCapture_AddRef(IBaseFilter * iface)
178 {
179     VfwCapture *This = (VfwCapture *)iface;
180     ULONG refCount = InterlockedIncrement(&This->refCount);
181
182     TRACE("%p->() New refcount: %d\n", This, refCount);
183
184     return refCount;
185 }
186
187 static ULONG WINAPI VfwCapture_Release(IBaseFilter * iface)
188 {
189     VfwCapture *This = (VfwCapture *)iface;
190     ULONG refCount = InterlockedDecrement(&This->refCount);
191
192     TRACE("%p->() New refcount: %d\n", This, refCount);
193
194     if (!refCount)
195     {
196         IPinImpl *pin;
197
198         TRACE("destroying everything\n");
199         if (This->init)
200         {
201             if (This->state != State_Stopped)
202                 qcap_driver_stop(This->driver_info, &This->state);
203             qcap_driver_destroy(This->driver_info);
204         }
205         pin = (IPinImpl*) This->pOutputPin;
206         if (pin->pConnectedTo != NULL)
207         {
208             IPin_Disconnect(pin->pConnectedTo);
209             IPin_Disconnect(This->pOutputPin);
210         }
211         IPin_Release(This->pOutputPin);
212         This->csFilter.DebugInfo->Spare[0] = 0;
213         DeleteCriticalSection(&This->csFilter);
214         This->lpVtbl = NULL;
215         CoTaskMemFree(This);
216         ObjectRefCount(FALSE);
217     }
218     return refCount;
219 }
220
221 /** IPersist methods **/
222
223 static HRESULT WINAPI VfwCapture_GetClassID(IBaseFilter * iface, CLSID * pClsid)
224 {
225     TRACE("(%p)\n", pClsid);
226     *pClsid = CLSID_VfwCapture;
227     return S_OK;
228 }
229
230 /** IMediaFilter methods **/
231
232 static HRESULT WINAPI VfwCapture_Stop(IBaseFilter * iface)
233 {
234     VfwCapture *This = (VfwCapture *)iface;
235
236     TRACE("()\n");
237     return qcap_driver_stop(This->driver_info, &This->state);
238 }
239
240 static HRESULT WINAPI VfwCapture_Pause(IBaseFilter * iface)
241 {
242     VfwCapture *This = (VfwCapture *)iface;
243
244     TRACE("()\n");
245     return qcap_driver_pause(This->driver_info, &This->state);
246 }
247
248 static HRESULT WINAPI VfwCapture_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
249 {
250     VfwCapture *This = (VfwCapture *)iface;
251     TRACE("(%x%08x)\n", (ULONG)(tStart >> 32), (ULONG)tStart);
252     return qcap_driver_run(This->driver_info, &This->state);
253 }
254
255 static HRESULT WINAPI
256 VfwCapture_GetState( IBaseFilter * iface, DWORD dwMilliSecsTimeout,
257                      FILTER_STATE *pState )
258 {
259     VfwCapture *This = (VfwCapture *)iface;
260
261     TRACE("(%u, %p)\n", dwMilliSecsTimeout, pState);
262
263     *pState = This->state;
264     return S_OK;
265 }
266
267 static HRESULT WINAPI
268 VfwCapture_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
269 {
270     TRACE("(%p)\n", pClock);
271
272     return S_OK;
273 }
274
275 static HRESULT WINAPI
276 VfwCapture_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
277 {
278     TRACE("(%p)\n", ppClock);
279
280     return S_OK;
281 }
282
283 /** IBaseFilter methods **/
284
285 static HRESULT WINAPI
286 VfwCapture_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
287 {
288     ENUMPINDETAILS epd;
289     VfwCapture *This = (VfwCapture *)iface;
290
291     TRACE("(%p)\n", ppEnum);
292
293     epd.cPins = 1;
294     epd.ppPins = &This->pOutputPin;
295     return IEnumPinsImpl_Construct(&epd, ppEnum);
296 }
297
298 static HRESULT WINAPI VfwCapture_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
299 {
300     FIXME("(%s, %p) - stub\n", debugstr_w(Id), ppPin);
301     return E_NOTIMPL;
302 }
303
304 static HRESULT WINAPI VfwCapture_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
305 {
306     VfwCapture *This = (VfwCapture *)iface;
307
308     TRACE("(%p)\n", pInfo);
309
310     lstrcpyW(pInfo->achName, This->filterInfo.achName);
311     pInfo->pGraph = This->filterInfo.pGraph;
312
313     if (pInfo->pGraph)
314         IFilterGraph_AddRef(pInfo->pGraph);
315     return S_OK;
316 }
317
318 static HRESULT WINAPI
319 VfwCapture_JoinFilterGraph( IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName )
320 {
321     VfwCapture *This = (VfwCapture *)iface;
322
323     TRACE("(%p, %s)\n", pGraph, debugstr_w(pName));
324
325     if (pName)
326         lstrcpyW(This->filterInfo.achName, pName);
327     else
328         *This->filterInfo.achName = 0;
329     This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
330
331     return S_OK;
332 }
333
334 static HRESULT WINAPI
335 VfwCapture_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
336 {
337     FIXME("(%p) - stub\n", pVendorInfo);
338     return E_NOTIMPL;
339 }
340
341 static const IBaseFilterVtbl VfwCapture_Vtbl =
342 {
343     VfwCapture_QueryInterface,
344     VfwCapture_AddRef,
345     VfwCapture_Release,
346     VfwCapture_GetClassID,
347     VfwCapture_Stop,
348     VfwCapture_Pause,
349     VfwCapture_Run,
350     VfwCapture_GetState,
351     VfwCapture_SetSyncSource,
352     VfwCapture_GetSyncSource,
353     VfwCapture_EnumPins,
354     VfwCapture_FindPin,
355     VfwCapture_QueryFilterInfo,
356     VfwCapture_JoinFilterGraph,
357     VfwCapture_QueryVendorInfo
358 };
359
360 /* AMStreamConfig interface, we only need to implement {G,S}etFormat */
361 static HRESULT WINAPI
362 AMStreamConfig_QueryInterface( IAMStreamConfig * iface, REFIID riid, LPVOID * ppv )
363 {
364     ICOM_THIS_MULTI(VfwCapture, IAMStreamConfig_vtbl, iface);
365
366     TRACE("%p --> %s\n", This, debugstr_guid(riid));
367
368     if (IsEqualIID(riid, &IID_IUnknown) ||
369         IsEqualIID(riid, &IID_IAMStreamConfig))
370     {
371         IAMStreamConfig_AddRef(iface);
372         *ppv = iface;
373         return S_OK;
374     }
375
376     FIXME("No interface for iid %s\n", debugstr_guid(riid));
377     return E_NOINTERFACE;
378 }
379
380 static ULONG WINAPI AMStreamConfig_AddRef( IAMStreamConfig * iface )
381 {
382     ICOM_THIS_MULTI(VfwCapture, IAMStreamConfig_vtbl, iface);
383
384     TRACE("%p --> Forwarding to VfwCapture (%p)\n", iface, This);
385     return IUnknown_AddRef((IUnknown *)This);
386 }
387
388 static ULONG WINAPI AMStreamConfig_Release( IAMStreamConfig * iface )
389 {
390     ICOM_THIS_MULTI(VfwCapture, IAMStreamConfig_vtbl, iface);
391
392     TRACE("%p --> Forwarding to VfwCapture (%p)\n", iface, This);
393     return IUnknown_Release((IUnknown *)This);
394 }
395
396 static HRESULT WINAPI
397 AMStreamConfig_SetFormat(IAMStreamConfig *iface, AM_MEDIA_TYPE *pmt)
398 {
399     HRESULT hr;
400     ICOM_THIS_MULTI(VfwCapture, IAMStreamConfig_vtbl, iface);
401     IPinImpl *pin;
402
403     TRACE("(%p): %p->%p\n", iface, pmt, pmt->pbFormat);
404
405     if (This->state != State_Stopped)
406     {
407         TRACE("Returning not stopped error\n");
408         return VFW_E_NOT_STOPPED;
409     }
410
411     dump_AM_MEDIA_TYPE(pmt);
412
413     pin = (IPinImpl *)This->pOutputPin;
414     if (pin->pConnectedTo != NULL)
415     {
416         hr = IPin_QueryAccept(pin->pConnectedTo, pmt);
417         TRACE("Would accept: %d\n", hr);
418         if (hr == S_FALSE)
419             return VFW_E_INVALIDMEDIATYPE;
420     }
421
422     hr = qcap_driver_set_format(This->driver_info, pmt);
423     if (SUCCEEDED(hr) && This->filterInfo.pGraph && pin->pConnectedTo )
424     {
425         hr = IFilterGraph_Reconnect(This->filterInfo.pGraph, This->pOutputPin);
426         if (SUCCEEDED(hr))
427             TRACE("Reconnection completed, with new media format..\n");
428     }
429     TRACE("Returning: %d\n", hr);
430     return hr;
431 }
432
433 static HRESULT WINAPI
434 AMStreamConfig_GetFormat( IAMStreamConfig *iface, AM_MEDIA_TYPE **pmt )
435 {
436     ICOM_THIS_MULTI(VfwCapture, IAMStreamConfig_vtbl, iface);
437
438     TRACE("%p -> (%p)\n", iface, pmt);
439     return qcap_driver_get_format(This->driver_info, pmt);
440 }
441
442 static HRESULT WINAPI
443 AMStreamConfig_GetNumberOfCapabilities( IAMStreamConfig *iface, int *piCount,
444                                         int *piSize )
445 {
446     FIXME("%p: %p %p - stub, intentional\n", iface, piCount, piSize);
447     return E_NOTIMPL; /* Not implemented for this interface */
448 }
449
450 static HRESULT WINAPI
451 AMStreamConfig_GetStreamCaps( IAMStreamConfig *iface, int iIndex,
452                               AM_MEDIA_TYPE **pmt, BYTE *pSCC )
453 {
454     FIXME("%p: %d %p %p - stub, intentional\n", iface, iIndex, pmt, pSCC);
455     return E_NOTIMPL; /* Not implemented for this interface */
456 }
457
458 static const IAMStreamConfigVtbl IAMStreamConfig_VTable =
459 {
460     AMStreamConfig_QueryInterface,
461     AMStreamConfig_AddRef,
462     AMStreamConfig_Release,
463     AMStreamConfig_SetFormat,
464     AMStreamConfig_GetFormat,
465     AMStreamConfig_GetNumberOfCapabilities,
466     AMStreamConfig_GetStreamCaps
467 };
468
469 static HRESULT WINAPI
470 AMVideoProcAmp_QueryInterface( IAMVideoProcAmp * iface, REFIID riid,
471                                LPVOID * ppv )
472 {
473     if (IsEqualIID(riid, &IID_IUnknown) ||
474         IsEqualIID(riid, &IID_IAMVideoProcAmp))
475     {
476         *ppv = iface;
477         IAMVideoProcAmp_AddRef( iface );
478         return S_OK;
479     }
480
481     FIXME("No interface for iid %s\n", debugstr_guid(riid));
482     return E_NOINTERFACE;
483 }
484
485 static ULONG WINAPI AMVideoProcAmp_AddRef(IAMVideoProcAmp * iface)
486 {
487     ICOM_THIS_MULTI(VfwCapture, IAMVideoProcAmp_vtbl, iface);
488
489     return IUnknown_AddRef((IUnknown *)This);
490 }
491
492 static ULONG WINAPI AMVideoProcAmp_Release(IAMVideoProcAmp * iface)
493 {
494     ICOM_THIS_MULTI(VfwCapture, IAMVideoProcAmp_vtbl, iface);
495
496     return IUnknown_Release((IUnknown *)This);
497 }
498
499 static HRESULT WINAPI
500 AMVideoProcAmp_GetRange( IAMVideoProcAmp * iface, long Property, long *pMin,
501         long *pMax, long *pSteppingDelta, long *pDefault, long *pCapsFlags )
502 {
503     ICOM_THIS_MULTI(VfwCapture, IAMVideoProcAmp_vtbl, iface);
504
505     return qcap_driver_get_prop_range( This->driver_info, Property, pMin, pMax,
506                    pSteppingDelta, pDefault, pCapsFlags );
507 }
508
509 static HRESULT WINAPI
510 AMVideoProcAmp_Set( IAMVideoProcAmp * iface, long Property, long lValue,
511                     long Flags )
512 {
513     ICOM_THIS_MULTI(VfwCapture, IAMVideoProcAmp_vtbl, iface);
514
515     return qcap_driver_set_prop(This->driver_info, Property, lValue, Flags);
516 }
517
518 static HRESULT WINAPI
519 AMVideoProcAmp_Get( IAMVideoProcAmp * iface, long Property, long *lValue,
520                     long *Flags )
521 {
522     ICOM_THIS_MULTI(VfwCapture, IAMVideoProcAmp_vtbl, iface);
523
524     return qcap_driver_get_prop(This->driver_info, Property, lValue, Flags);
525 }
526
527 static const IAMVideoProcAmpVtbl IAMVideoProcAmp_VTable =
528 {
529     AMVideoProcAmp_QueryInterface,
530     AMVideoProcAmp_AddRef,
531     AMVideoProcAmp_Release,
532     AMVideoProcAmp_GetRange,
533     AMVideoProcAmp_Set,
534     AMVideoProcAmp_Get,
535 };
536
537 static HRESULT WINAPI
538 PPB_QueryInterface( IPersistPropertyBag * iface, REFIID riid, LPVOID * ppv )
539 {
540     if (IsEqualIID(riid, &IID_IUnknown) ||
541         IsEqualIID(riid, &IID_IPersist) ||
542         IsEqualIID(riid, &IID_IPersistPropertyBag))
543     {
544         IPersistPropertyBag_AddRef(iface);
545         *ppv = iface;
546         return S_OK;
547     }
548     if (IsEqualIID(riid, &IID_IBaseFilter))
549     {
550         /* FIXME: native devenum asks for IBaseFilter, should we return it? */
551         IPersistPropertyBag_AddRef(iface);
552         *ppv = iface;
553         return S_OK;
554     }
555
556     FIXME("No interface for iid %s\n", debugstr_guid(riid));
557     return E_NOINTERFACE;
558 }
559
560 static ULONG WINAPI PPB_AddRef(IPersistPropertyBag * iface)
561 {
562     ICOM_THIS_MULTI(VfwCapture, IPersistPropertyBag_vtbl, iface);
563
564     TRACE("%p --> Forwarding to VfwCapture (%p)\n", iface, This);
565
566     return IUnknown_AddRef((IUnknown *)This);
567 }
568
569 static ULONG WINAPI PPB_Release(IPersistPropertyBag * iface)
570 {
571     ICOM_THIS_MULTI(VfwCapture, IPersistPropertyBag_vtbl, iface);
572
573     TRACE("%p --> Forwarding to VfwCapture (%p)\n", iface, This);
574
575     return IUnknown_Release((IUnknown *)This);
576 }
577
578 static HRESULT WINAPI
579 PPB_GetClassID( IPersistPropertyBag * iface, CLSID * pClassID )
580 {
581     ICOM_THIS_MULTI(VfwCapture, IPersistPropertyBag_vtbl, iface);
582
583     FIXME("%p - stub\n", This);
584
585     return E_NOTIMPL;
586 }
587
588 static HRESULT WINAPI PPB_InitNew(IPersistPropertyBag * iface)
589 {
590     ICOM_THIS_MULTI(VfwCapture, IPersistPropertyBag_vtbl, iface);
591
592     FIXME("%p - stub\n", This);
593
594     return E_NOTIMPL;
595 }
596
597 static HRESULT WINAPI
598 PPB_Load( IPersistPropertyBag * iface, IPropertyBag *pPropBag,
599           IErrorLog *pErrorLog )
600 {
601     ICOM_THIS_MULTI(VfwCapture, IPersistPropertyBag_vtbl, iface);
602     HRESULT hr;
603     VARIANT var;
604     const OLECHAR VFWIndex[] = {'V','F','W','I','n','d','e','x',0};
605
606     TRACE("%p/%p-> (%p, %p)\n", iface, This, pPropBag, pErrorLog);
607
608     V_VT(&var) = VT_I4;
609     hr = IPropertyBag_Read(pPropBag, (LPCOLESTR)VFWIndex, &var, pErrorLog);
610
611     if (SUCCEEDED(hr))
612     {
613         VfwPinImpl *pin;
614
615         This->driver_info = qcap_driver_init( This->pOutputPin,
616                var.__VARIANT_NAME_1.__VARIANT_NAME_2.__VARIANT_NAME_3.ulVal );
617         if (This->driver_info)
618         {
619             pin = (VfwPinImpl *)This->pOutputPin;
620             pin->driver_info = This->driver_info;
621             This->init = TRUE;
622             hr = S_OK;
623         }
624         else
625             hr = E_FAIL;
626     }
627
628     return hr;
629 }
630
631 static HRESULT WINAPI
632 PPB_Save( IPersistPropertyBag * iface, IPropertyBag *pPropBag,
633           BOOL fClearDirty, BOOL fSaveAllProperties )
634 {
635     ICOM_THIS_MULTI(VfwCapture, IPersistPropertyBag_vtbl, iface);
636     FIXME("%p - stub\n", This);
637     return E_NOTIMPL;
638 }
639
640 static const IPersistPropertyBagVtbl IPersistPropertyBag_VTable =
641 {
642     PPB_QueryInterface,
643     PPB_AddRef,
644     PPB_Release,
645     PPB_GetClassID,
646     PPB_InitNew,
647     PPB_Load,
648     PPB_Save
649 };
650
651 /* IKsPropertySet interface */
652 static HRESULT WINAPI
653 KSP_QueryInterface( IKsPropertySet * iface, REFIID riid, LPVOID * ppv )
654 {
655     if (IsEqualIID(riid, &IID_IUnknown) ||
656         IsEqualIID(riid, &IID_IKsPropertySet))
657     {
658         *ppv = (LPVOID)iface;
659         IKsPropertySet_AddRef( iface );
660         return S_OK;
661     }
662
663     FIXME("No interface for iid %s\n", debugstr_guid(riid));
664     return E_NOINTERFACE;
665 }
666
667 static ULONG WINAPI KSP_AddRef(IKsPropertySet * iface)
668 {
669     ICOM_THIS_MULTI(VfwPinImpl, KSP_VT, iface);
670
671     TRACE("%p --> Forwarding to VfwPin (%p)\n", iface, This);
672
673     return IUnknown_AddRef((IUnknown *)This);
674 }
675
676 static ULONG WINAPI KSP_Release(IKsPropertySet * iface)
677 {
678     ICOM_THIS_MULTI(VfwPinImpl, KSP_VT, iface);
679
680     TRACE("%p --> Forwarding to VfwPin (%p)\n", iface, This);
681
682     return IUnknown_Release((IUnknown *)This);
683 }
684
685 static HRESULT WINAPI
686 KSP_Set( IKsPropertySet * iface, REFGUID guidPropSet, DWORD dwPropID,
687          LPVOID pInstanceData, DWORD cbInstanceData, LPVOID pPropData,
688          DWORD cbPropData )
689 {
690     FIXME("%p: stub\n", iface);
691     return E_NOTIMPL;
692 }
693
694 static HRESULT WINAPI
695 KSP_Get( IKsPropertySet * iface, REFGUID guidPropSet, DWORD dwPropID,
696          LPVOID pInstanceData, DWORD cbInstanceData, LPVOID pPropData,
697          DWORD cbPropData, DWORD *pcbReturned )
698 {
699     LPGUID pGuid;
700
701     TRACE("()\n");
702
703     if (!IsEqualIID(guidPropSet, &AMPROPSETID_Pin))
704         return E_PROP_SET_UNSUPPORTED;
705     if (pPropData == NULL && pcbReturned == NULL)
706         return E_POINTER;
707     if (pcbReturned)
708         *pcbReturned = sizeof(GUID);
709     if (pPropData == NULL)
710         return S_OK;
711     if (cbPropData < sizeof(GUID))
712         return E_UNEXPECTED;
713     pGuid = pPropData;
714     *pGuid = PIN_CATEGORY_PREVIEW;
715     FIXME("() Not adding a pin with PIN_CATEGORY_CAPTURE\n");
716     return S_OK;
717 }
718
719 static HRESULT WINAPI
720 KSP_QuerySupported( IKsPropertySet * iface, REFGUID guidPropSet,
721                     DWORD dwPropID, DWORD *pTypeSupport )
722 {
723    FIXME("%p: stub\n", iface);
724    return E_NOTIMPL;
725 }
726
727 static const IKsPropertySetVtbl KSP_VTable =
728 {
729    KSP_QueryInterface,
730    KSP_AddRef,
731    KSP_Release,
732    KSP_Set,
733    KSP_Get,
734    KSP_QuerySupported
735 };
736
737 static HRESULT
738 VfwPin_Construct( IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec,
739                   IPin ** ppPin )
740 {
741     static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
742     ALLOCATOR_PROPERTIES ap;
743     VfwPinImpl * pPinImpl;
744     PIN_INFO piOutput;
745     HRESULT hr;
746
747     pPinImpl = CoTaskMemAlloc( sizeof(*pPinImpl) );
748     if (!pPinImpl)
749         return E_OUTOFMEMORY;
750
751     /* What we put here doesn't matter, the
752        driver function should override it then commit */
753     ap.cBuffers = 3;
754     ap.cbBuffer = 230400;
755     ap.cbAlign = 1;
756     ap.cbPrefix = 0;
757
758     piOutput.dir = PINDIR_OUTPUT;
759     piOutput.pFilter = pBaseFilter;
760     lstrcpyW(piOutput.achName, wszOutputPinName);
761     ObjectRefCount(TRUE);
762
763     hr = OutputPin_Init(&piOutput, &ap, pBaseFilter, NULL, pCritSec, &pPinImpl->pin);
764     if (SUCCEEDED(hr))
765     {
766         pPinImpl->KSP_VT = &KSP_VTable;
767         pPinImpl->pin.pin.lpVtbl = &VfwPin_Vtbl;
768         *ppPin = (IPin *)(&pPinImpl->pin.pin.lpVtbl);
769         return S_OK;
770     }
771     return E_FAIL;
772 }
773
774 static HRESULT WINAPI VfwPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
775 {
776     VfwPinImpl *This = (VfwPinImpl *)iface;
777
778     TRACE("%s %p\n", debugstr_guid(riid), ppv);
779
780     *ppv = NULL;
781     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IPin))
782         *ppv = (LPVOID)This;
783     else if (IsEqualIID(riid, &IID_IKsPropertySet))
784         *ppv = (LPVOID)&(This->KSP_VT);
785
786     if (*ppv)
787     {
788         IUnknown_AddRef((IUnknown *)(*ppv));
789         return S_OK;
790     }
791
792     FIXME("No interface for %s!\n", debugstr_guid(riid));
793     return E_NOINTERFACE;
794 }
795
796 static ULONG WINAPI VfwPin_AddRef(IPin * iface)
797 {
798     VfwPinImpl *This = (VfwPinImpl *)iface;
799     ULONG refCount = InterlockedIncrement(&This->pin.pin.refCount);
800
801     TRACE("() -> new refcount: %u\n", refCount);
802
803     return refCount;
804 }
805
806 static ULONG WINAPI
807 VfwPin_Release(IPin * iface)
808 {
809    VfwPinImpl *This = (VfwPinImpl *)iface;
810    ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
811
812    TRACE("() -> new refcount: %u\n", refCount);
813
814    if (!refCount)
815    {
816       CoTaskMemFree(This);
817       ObjectRefCount(FALSE);
818    }
819    return refCount;
820 }
821
822 static HRESULT WINAPI
823 VfwPin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
824 {
825     ENUMMEDIADETAILS emd;
826     AM_MEDIA_TYPE *pmt;
827     HRESULT hr;
828
829     VfwPinImpl *This = (VfwPinImpl *)iface;
830     emd.cMediaTypes = 1;
831     hr = qcap_driver_get_format(This->driver_info, &pmt);
832     emd.pMediaTypes = pmt;
833     if (SUCCEEDED(hr))
834         hr = IEnumMediaTypesImpl_Construct(&emd, ppEnum);
835     TRACE("%p -- %x\n", This, hr);
836     DeleteMediaType(pmt);
837     return hr;
838 }
839
840 static HRESULT WINAPI
841 VfwPin_QueryInternalConnections(IPin * iface, IPin ** apPin, ULONG * cPin)
842 {
843     TRACE("(%p)->(%p, %p)\n", iface, apPin, cPin);
844     return E_NOTIMPL;
845 }
846
847 static HRESULT WINAPI VfwPin_EndOfStream(IPin * iface)
848 {
849     TRACE("()\n");
850     return E_UNEXPECTED;
851 }
852
853 static HRESULT WINAPI VfwPin_BeginFlush(IPin * iface)
854 {
855     TRACE("(%p)->()\n", iface);
856     return E_UNEXPECTED;
857 }
858
859 static HRESULT WINAPI VfwPin_EndFlush(IPin * iface)
860 {
861     TRACE("(%p)->()\n", iface);
862     return E_UNEXPECTED;
863 }
864
865 static HRESULT WINAPI
866 VfwPin_NewSegment(IPin * iface, REFERENCE_TIME tStart,
867                   REFERENCE_TIME tStop, double dRate)
868 {
869     TRACE("(%p)->(%s, %s, %e)\n", iface, wine_dbgstr_longlong(tStart),
870            wine_dbgstr_longlong(tStop), dRate);
871     return E_UNEXPECTED;
872 }
873
874 static const IPinVtbl VfwPin_Vtbl =
875 {
876     VfwPin_QueryInterface,
877     VfwPin_AddRef,
878     VfwPin_Release,
879     OutputPin_Connect,
880     OutputPin_ReceiveConnection,
881     OutputPin_Disconnect,
882     IPinImpl_ConnectedTo,
883     IPinImpl_ConnectionMediaType,
884     IPinImpl_QueryPinInfo,
885     IPinImpl_QueryDirection,
886     IPinImpl_QueryId,
887     IPinImpl_QueryAccept,
888     VfwPin_EnumMediaTypes,
889     VfwPin_QueryInternalConnections,
890     VfwPin_EndOfStream,
891     VfwPin_BeginFlush,
892     VfwPin_EndFlush,
893     VfwPin_NewSegment
894 };