vfwcapture.c 22.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Video For Windows Steering structure
 *
 * Copyright 2005 Maarten Lankhorst
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
 *
 */

#define COBJMACROS

#include "config.h"
#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "wtypes.h"
#include "wingdi.h"
#include "winuser.h"
#include "dshow.h"

#include "qcap_main.h"
#include "wine/debug.h"

#include "capture.h"
#include "uuids.h"
#include "vfwmsgs.h"
#include "amvideo.h"
#include "strmif.h"
#include "ddraw.h"
#include "ocidl.h"
#include "oleauto.h"

WINE_DEFAULT_DEBUG_CHANNEL(qcap);

static const IBaseFilterVtbl VfwCapture_Vtbl;
static const IAMStreamConfigVtbl IAMStreamConfig_VTable;
static const IAMVideoProcAmpVtbl IAMVideoProcAmp_VTable;
static const IPersistPropertyBagVtbl IPersistPropertyBag_VTable;
static const IPinVtbl VfwPin_Vtbl;

static HRESULT VfwPin_Construct( IBaseFilter *, LPCRITICAL_SECTION, IPin ** );

typedef struct VfwCapture
{
57
    IUnknown IUnknown_inner;
58
    BaseFilter filter;
59 60 61
    IAMStreamConfig IAMStreamConfig_iface;
    IAMVideoProcAmp IAMVideoProcAmp_iface;
    IPersistPropertyBag IPersistPropertyBag_iface;
62
    IUnknown *outer_unk;
63
    BOOL init;
64
    Capture *driver_info;
65 66 67 68

    IPin * pOutputPin;
} VfwCapture;

69 70 71 72 73
static inline VfwCapture *impl_from_IUnknown(IUnknown *iface)
{
    return CONTAINING_RECORD(iface, VfwCapture, IUnknown_inner);
}

74 75 76 77 78 79 80 81 82 83
static inline VfwCapture *impl_from_BaseFilter(BaseFilter *iface)
{
    return CONTAINING_RECORD(iface, VfwCapture, filter);
}

static inline VfwCapture *impl_from_IBaseFilter(IBaseFilter *iface)
{
    return CONTAINING_RECORD(iface, VfwCapture, filter.IBaseFilter_iface);
}

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
static inline VfwCapture *impl_from_IAMStreamConfig(IAMStreamConfig *iface)
{
    return CONTAINING_RECORD(iface, VfwCapture, IAMStreamConfig_iface);
}

static inline VfwCapture *impl_from_IAMVideoProcAmp(IAMVideoProcAmp *iface)
{
    return CONTAINING_RECORD(iface, VfwCapture, IAMVideoProcAmp_iface);
}

static inline VfwCapture *impl_from_IPersistPropertyBag(IPersistPropertyBag *iface)
{
    return CONTAINING_RECORD(iface, VfwCapture, IPersistPropertyBag_iface);
}

99 100 101
/* VfwPin implementation */
typedef struct VfwPinImpl
{
102
    BaseOutputPin pin;
103
    IKsPropertySet IKsPropertySet_iface;
104
    VfwCapture *parent;
105 106
} VfwPinImpl;

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

/* VfwCapture inner IUnknown */
static HRESULT WINAPI unknown_inner_QueryInterface(IUnknown *iface, REFIID riid, void **ret_iface)
{
    VfwCapture *This = impl_from_IUnknown(iface);

    TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ret_iface);

    *ret_iface = NULL;

    if (IsEqualIID(riid, &IID_IUnknown))
        *ret_iface = &This->IUnknown_inner;
    else if (IsEqualIID(riid, &IID_IPersist) || IsEqualIID(riid, &IID_IMediaFilter) ||
        IsEqualIID(riid, &IID_IBaseFilter))
        *ret_iface = &This->filter.IBaseFilter_iface;
    else if (IsEqualIID(riid, &IID_IPersistPropertyBag))
        *ret_iface = &This->IPersistPropertyBag_iface;
    else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
        FIXME("IAMFilterMiscFlags not supported yet!\n");
    else if (IsEqualIID(riid, &IID_ISpecifyPropertyPages))
        FIXME("ISpecifyPropertyPages not supported yet!\n");
    else if (IsEqualIID(riid, &IID_IAMVfwCaptureDialogs))
        FIXME("IAMVfwCaptureDialogs not supported yet!\n");
    else if (IsEqualIID(riid, &IID_IAMStreamConfig))
        *ret_iface = &This->IAMStreamConfig_iface;
    else if (IsEqualIID(riid, &IID_IAMVideoProcAmp))
        *ret_iface = &This->IAMVideoProcAmp_iface;
    else
        WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ret_iface);

    if (!*ret_iface)
        return E_NOINTERFACE;

    IUnknown_AddRef((IUnknown*)*ret_iface);
    return S_OK;
}

static ULONG WINAPI unknown_inner_AddRef(IUnknown *iface)
{
    VfwCapture *This = impl_from_IUnknown(iface);
    ULONG ref = BaseFilterImpl_AddRef(&This->filter.IBaseFilter_iface);

    TRACE("(%p) ref=%d\n", This, ref);

    return ref;
}

static ULONG WINAPI unknown_inner_Release(IUnknown *iface)
{
    VfwCapture *This = impl_from_IUnknown(iface);
    ULONG ref = InterlockedDecrement(&This->filter.refCount);

    TRACE("(%p) ref=%d\n", This, ref);

    if (!ref)
    {
        IPin *conn = NULL;

        TRACE("destroying everything\n");
        if (This->init)
        {
            if (This->filter.state != State_Stopped)
                qcap_driver_stop(This->driver_info, &This->filter.state);
            qcap_driver_destroy(This->driver_info);
        }
        IPin_ConnectedTo(This->pOutputPin, &conn);
        if (conn)
        {
            IPin_Disconnect(conn);
            IPin_Disconnect(This->pOutputPin);
            IPin_Release(conn);
        }
        IPin_Release(This->pOutputPin);
        BaseFilter_Destroy(&This->filter);
        CoTaskMemFree(This);
        ObjectRefCount(FALSE);
    }

    return ref;
}

static const IUnknownVtbl unknown_inner_vtbl =
{
    unknown_inner_QueryInterface,
    unknown_inner_AddRef,
    unknown_inner_Release,
};

195
static IPin* WINAPI VfwCapture_GetPin(BaseFilter *iface, int pos)
196
{
197
    VfwCapture *This = impl_from_BaseFilter(iface);
198 199 200 201 202 203 204 205

    if (pos >= 1 || pos < 0)
        return NULL;

    IPin_AddRef(This->pOutputPin);
    return This->pOutputPin;
}

206
static LONG WINAPI VfwCapture_GetPinCount(BaseFilter *iface)
207 208 209
{
    return 1;
}
210

211 212 213 214 215
static const BaseFilterFuncTable BaseFuncTable = {
    VfwCapture_GetPin,
    VfwCapture_GetPinCount
};

216 217 218 219 220 221 222 223 224 225 226 227
IUnknown * WINAPI QCAP_createVFWCaptureFilter(IUnknown *pUnkOuter, HRESULT *phr)
{
    VfwCapture *pVfwCapture;
    HRESULT hr;

    TRACE("%p - %p\n", pUnkOuter, phr);

    *phr = E_OUTOFMEMORY;
    pVfwCapture = CoTaskMemAlloc( sizeof(VfwCapture) );
    if (!pVfwCapture)
        return NULL;

228
    BaseFilter_Init(&pVfwCapture->filter, &VfwCapture_Vtbl, &CLSID_VfwCapture, (DWORD_PTR)(__FILE__ ": VfwCapture.csFilter"), &BaseFuncTable);
229

230
    pVfwCapture->IUnknown_inner.lpVtbl = &unknown_inner_vtbl;
231 232 233
    pVfwCapture->IAMStreamConfig_iface.lpVtbl = &IAMStreamConfig_VTable;
    pVfwCapture->IAMVideoProcAmp_iface.lpVtbl = &IAMVideoProcAmp_VTable;
    pVfwCapture->IPersistPropertyBag_iface.lpVtbl = &IPersistPropertyBag_VTable;
234
    pVfwCapture->init = FALSE;
235

236 237 238 239 240
    if (pUnkOuter)
        pVfwCapture->outer_unk = pUnkOuter;
    else
        pVfwCapture->outer_unk = &pVfwCapture->IUnknown_inner;

241
    hr = VfwPin_Construct(&pVfwCapture->filter.IBaseFilter_iface,
242
                   &pVfwCapture->filter.csFilter, &pVfwCapture->pOutputPin);
243
    if (FAILED(hr))
244 245 246 247 248 249 250 251
    {
        CoTaskMemFree(pVfwCapture);
        return NULL;
    }
    TRACE("-- created at %p\n", pVfwCapture);

    ObjectRefCount(TRUE);
    *phr = S_OK;
252
    return &pVfwCapture->IUnknown_inner;
253 254
}

255
static HRESULT WINAPI VfwCapture_QueryInterface(IBaseFilter *iface, REFIID riid, void **ret_iface)
256
{
257
    VfwCapture *This = impl_from_IBaseFilter(iface);
258

259 260
    return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface);
}
261

262 263 264
static ULONG WINAPI VfwCapture_AddRef(IBaseFilter *iface)
{
    VfwCapture *This = impl_from_IBaseFilter(iface);
265

266
    return IUnknown_AddRef(This->outer_unk);
267 268 269 270
}

static ULONG WINAPI VfwCapture_Release(IBaseFilter * iface)
{
271
    VfwCapture *This = impl_from_IBaseFilter(iface);
272

273
    return IUnknown_Release(This->outer_unk);
274 275 276 277 278 279
}

/** IMediaFilter methods **/

static HRESULT WINAPI VfwCapture_Stop(IBaseFilter * iface)
{
280
    VfwCapture *This = impl_from_IBaseFilter(iface);
281 282

    TRACE("()\n");
283
    return qcap_driver_stop(This->driver_info, &This->filter.state);
284 285 286 287
}

static HRESULT WINAPI VfwCapture_Pause(IBaseFilter * iface)
{
288
    VfwCapture *This = impl_from_IBaseFilter(iface);
289 290

    TRACE("()\n");
291
    return qcap_driver_pause(This->driver_info, &This->filter.state);
292 293 294 295
}

static HRESULT WINAPI VfwCapture_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
{
296
    VfwCapture *This = impl_from_IBaseFilter(iface);
297
    TRACE("(%s)\n", wine_dbgstr_longlong(tStart));
298
    return qcap_driver_run(This->driver_info, &This->filter.state);
299 300 301 302 303 304 305 306 307 308 309 310
}

/** IBaseFilter methods **/
static HRESULT WINAPI VfwCapture_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
{
    FIXME("(%s, %p) - stub\n", debugstr_w(Id), ppPin);
    return E_NOTIMPL;
}

static const IBaseFilterVtbl VfwCapture_Vtbl =
{
    VfwCapture_QueryInterface,
311
    VfwCapture_AddRef,
312
    VfwCapture_Release,
313
    BaseFilterImpl_GetClassID,
314 315 316
    VfwCapture_Stop,
    VfwCapture_Pause,
    VfwCapture_Run,
317 318 319
    BaseFilterImpl_GetState,
    BaseFilterImpl_SetSyncSource,
    BaseFilterImpl_GetSyncSource,
320
    BaseFilterImpl_EnumPins,
321
    VfwCapture_FindPin,
322 323 324
    BaseFilterImpl_QueryFilterInfo,
    BaseFilterImpl_JoinFilterGraph,
    BaseFilterImpl_QueryVendorInfo
325 326 327
};

/* AMStreamConfig interface, we only need to implement {G,S}etFormat */
328 329
static HRESULT WINAPI AMStreamConfig_QueryInterface(IAMStreamConfig *iface, REFIID riid,
        void **ret_iface)
330
{
331
    VfwCapture *This = impl_from_IAMStreamConfig(iface);
332

333
    return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface);
334 335 336 337
}

static ULONG WINAPI AMStreamConfig_AddRef( IAMStreamConfig * iface )
{
338
    VfwCapture *This = impl_from_IAMStreamConfig(iface);
339

340
    return IUnknown_AddRef(This->outer_unk);
341 342 343 344
}

static ULONG WINAPI AMStreamConfig_Release( IAMStreamConfig * iface )
{
345
    VfwCapture *This = impl_from_IAMStreamConfig(iface);
346

347
    return IUnknown_Release(This->outer_unk);
348 349 350 351 352 353
}

static HRESULT WINAPI
AMStreamConfig_SetFormat(IAMStreamConfig *iface, AM_MEDIA_TYPE *pmt)
{
    HRESULT hr;
354
    VfwCapture *This = impl_from_IAMStreamConfig(iface);
355
    BasePin *pin;
356

357
    TRACE("(%p): %p->%p\n", iface, pmt, pmt ? pmt->pbFormat : NULL);
358

359
    if (This->filter.state != State_Stopped)
360 361 362 363 364
    {
        TRACE("Returning not stopped error\n");
        return VFW_E_NOT_STOPPED;
    }

365 366 367 368 369 370
    if (!pmt)
    {
        TRACE("pmt is NULL\n");
        return E_POINTER;
    }

371 372
    dump_AM_MEDIA_TYPE(pmt);

373
    pin = (BasePin *)This->pOutputPin;
374 375 376
    if (pin->pConnectedTo != NULL)
    {
        hr = IPin_QueryAccept(pin->pConnectedTo, pmt);
377
        TRACE("Would accept: %d\n", hr);
378 379 380 381
        if (hr == S_FALSE)
            return VFW_E_INVALIDMEDIATYPE;
    }

382
    hr = qcap_driver_set_format(This->driver_info, pmt);
383
    if (SUCCEEDED(hr) && This->filter.filterInfo.pGraph && pin->pConnectedTo )
384
    {
385
        hr = IFilterGraph_Reconnect(This->filter.filterInfo.pGraph, This->pOutputPin);
386 387 388
        if (SUCCEEDED(hr))
            TRACE("Reconnection completed, with new media format..\n");
    }
389
    TRACE("Returning: %d\n", hr);
390 391 392 393 394 395
    return hr;
}

static HRESULT WINAPI
AMStreamConfig_GetFormat( IAMStreamConfig *iface, AM_MEDIA_TYPE **pmt )
{
396
    VfwCapture *This = impl_from_IAMStreamConfig(iface);
397 398

    TRACE("%p -> (%p)\n", iface, pmt);
399
    return qcap_driver_get_format(This->driver_info, pmt);
400 401 402 403 404 405 406
}

static HRESULT WINAPI
AMStreamConfig_GetNumberOfCapabilities( IAMStreamConfig *iface, int *piCount,
                                        int *piSize )
{
    FIXME("%p: %p %p - stub, intentional\n", iface, piCount, piSize);
407
    *piCount = 0;
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
    return E_NOTIMPL; /* Not implemented for this interface */
}

static HRESULT WINAPI
AMStreamConfig_GetStreamCaps( IAMStreamConfig *iface, int iIndex,
                              AM_MEDIA_TYPE **pmt, BYTE *pSCC )
{
    FIXME("%p: %d %p %p - stub, intentional\n", iface, iIndex, pmt, pSCC);
    return E_NOTIMPL; /* Not implemented for this interface */
}

static const IAMStreamConfigVtbl IAMStreamConfig_VTable =
{
    AMStreamConfig_QueryInterface,
    AMStreamConfig_AddRef,
    AMStreamConfig_Release,
    AMStreamConfig_SetFormat,
    AMStreamConfig_GetFormat,
    AMStreamConfig_GetNumberOfCapabilities,
    AMStreamConfig_GetStreamCaps
};

430 431
static HRESULT WINAPI AMVideoProcAmp_QueryInterface(IAMVideoProcAmp *iface, REFIID riid,
        void **ret_iface)
432
{
433
    VfwCapture *This = impl_from_IAMVideoProcAmp(iface);
434

435
    return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface);
436 437 438 439
}

static ULONG WINAPI AMVideoProcAmp_AddRef(IAMVideoProcAmp * iface)
{
440
    VfwCapture *This = impl_from_IAMVideoProcAmp(iface);
441

442
    return IUnknown_AddRef(This->outer_unk);
443 444 445 446
}

static ULONG WINAPI AMVideoProcAmp_Release(IAMVideoProcAmp * iface)
{
447
    VfwCapture *This = impl_from_IAMVideoProcAmp(iface);
448

449
    return IUnknown_Release(This->outer_unk);
450 451 452
}

static HRESULT WINAPI
453 454
AMVideoProcAmp_GetRange( IAMVideoProcAmp * iface, LONG Property, LONG *pMin,
        LONG *pMax, LONG *pSteppingDelta, LONG *pDefault, LONG *pCapsFlags )
455
{
456
    VfwCapture *This = impl_from_IAMVideoProcAmp(iface);
457

458
    return qcap_driver_get_prop_range( This->driver_info, Property, pMin, pMax,
459 460 461 462
                   pSteppingDelta, pDefault, pCapsFlags );
}

static HRESULT WINAPI
463 464
AMVideoProcAmp_Set( IAMVideoProcAmp * iface, LONG Property, LONG lValue,
                    LONG Flags )
465
{
466
    VfwCapture *This = impl_from_IAMVideoProcAmp(iface);
467

468
    return qcap_driver_set_prop(This->driver_info, Property, lValue, Flags);
469 470 471
}

static HRESULT WINAPI
472 473
AMVideoProcAmp_Get( IAMVideoProcAmp * iface, LONG Property, LONG *lValue,
                    LONG *Flags )
474
{
475
    VfwCapture *This = impl_from_IAMVideoProcAmp(iface);
476

477
    return qcap_driver_get_prop(This->driver_info, Property, lValue, Flags);
478 479 480 481 482 483 484 485 486 487 488 489
}

static const IAMVideoProcAmpVtbl IAMVideoProcAmp_VTable =
{
    AMVideoProcAmp_QueryInterface,
    AMVideoProcAmp_AddRef,
    AMVideoProcAmp_Release,
    AMVideoProcAmp_GetRange,
    AMVideoProcAmp_Set,
    AMVideoProcAmp_Get,
};

490
static HRESULT WINAPI PPB_QueryInterface(IPersistPropertyBag *iface, REFIID riid, void **ret_iface)
491
{
492
    VfwCapture *This = impl_from_IPersistPropertyBag(iface);
493

494
    return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface);
495 496 497 498
}

static ULONG WINAPI PPB_AddRef(IPersistPropertyBag * iface)
{
499
    VfwCapture *This = impl_from_IPersistPropertyBag(iface);
500

501
    return IUnknown_AddRef(This->outer_unk);
502 503 504 505
}

static ULONG WINAPI PPB_Release(IPersistPropertyBag * iface)
{
506
    VfwCapture *This = impl_from_IPersistPropertyBag(iface);
507

508
    return IUnknown_Release(This->outer_unk);
509 510 511 512 513
}

static HRESULT WINAPI
PPB_GetClassID( IPersistPropertyBag * iface, CLSID * pClassID )
{
514
    VfwCapture *This = impl_from_IPersistPropertyBag(iface);
515 516 517 518 519 520 521 522

    FIXME("%p - stub\n", This);

    return E_NOTIMPL;
}

static HRESULT WINAPI PPB_InitNew(IPersistPropertyBag * iface)
{
523
    VfwCapture *This = impl_from_IPersistPropertyBag(iface);
524 525 526 527 528 529 530 531 532 533

    FIXME("%p - stub\n", This);

    return E_NOTIMPL;
}

static HRESULT WINAPI
PPB_Load( IPersistPropertyBag * iface, IPropertyBag *pPropBag,
          IErrorLog *pErrorLog )
{
534
    VfwCapture *This = impl_from_IPersistPropertyBag(iface);
535 536 537 538 539 540 541
    HRESULT hr;
    VARIANT var;
    const OLECHAR VFWIndex[] = {'V','F','W','I','n','d','e','x',0};

    TRACE("%p/%p-> (%p, %p)\n", iface, This, pPropBag, pErrorLog);

    V_VT(&var) = VT_I4;
542
    hr = IPropertyBag_Read(pPropBag, VFWIndex, &var, pErrorLog);
543 544 545 546 547

    if (SUCCEEDED(hr))
    {
        VfwPinImpl *pin;

548 549 550 551 552
        This->driver_info = qcap_driver_init( This->pOutputPin,
               var.__VARIANT_NAME_1.__VARIANT_NAME_2.__VARIANT_NAME_3.ulVal );
        if (This->driver_info)
        {
            pin = (VfwPinImpl *)This->pOutputPin;
553
            pin->parent = This;
554
            This->init = TRUE;
555 556 557 558
            hr = S_OK;
        }
        else
            hr = E_FAIL;
559 560 561 562 563 564 565 566 567
    }

    return hr;
}

static HRESULT WINAPI
PPB_Save( IPersistPropertyBag * iface, IPropertyBag *pPropBag,
          BOOL fClearDirty, BOOL fSaveAllProperties )
{
568
    VfwCapture *This = impl_from_IPersistPropertyBag(iface);
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
    FIXME("%p - stub\n", This);
    return E_NOTIMPL;
}

static const IPersistPropertyBagVtbl IPersistPropertyBag_VTable =
{
    PPB_QueryInterface,
    PPB_AddRef,
    PPB_Release,
    PPB_GetClassID,
    PPB_InitNew,
    PPB_Load,
    PPB_Save
};

/* IKsPropertySet interface */
585
static inline VfwPinImpl *impl_from_IKsPropertySet(IKsPropertySet *iface)
586
{
587 588
    return CONTAINING_RECORD(iface, VfwPinImpl, IKsPropertySet_iface);
}
589

590 591 592 593 594
static HRESULT WINAPI KSP_QueryInterface(IKsPropertySet * iface, REFIID riid, void **ret_iface)
{
    VfwPinImpl *This = impl_from_IKsPropertySet(iface);

    return IPin_QueryInterface(&This->pin.pin.IPin_iface, riid, ret_iface);
595 596 597 598
}

static ULONG WINAPI KSP_AddRef(IKsPropertySet * iface)
{
599
    VfwPinImpl *This = impl_from_IKsPropertySet(iface);
600

601
    return IPin_AddRef(&This->pin.pin.IPin_iface);
602 603 604 605
}

static ULONG WINAPI KSP_Release(IKsPropertySet * iface)
{
606
    VfwPinImpl *This = impl_from_IKsPropertySet(iface);
607

608
    return IPin_Release(&This->pin.pin.IPin_iface);
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
}

static HRESULT WINAPI
KSP_Set( IKsPropertySet * iface, REFGUID guidPropSet, DWORD dwPropID,
         LPVOID pInstanceData, DWORD cbInstanceData, LPVOID pPropData,
         DWORD cbPropData )
{
    FIXME("%p: stub\n", iface);
    return E_NOTIMPL;
}

static HRESULT WINAPI
KSP_Get( IKsPropertySet * iface, REFGUID guidPropSet, DWORD dwPropID,
         LPVOID pInstanceData, DWORD cbInstanceData, LPVOID pPropData,
         DWORD cbPropData, DWORD *pcbReturned )
{
    LPGUID pGuid;

    TRACE("()\n");

    if (!IsEqualIID(guidPropSet, &AMPROPSETID_Pin))
        return E_PROP_SET_UNSUPPORTED;
    if (pPropData == NULL && pcbReturned == NULL)
        return E_POINTER;
    if (pcbReturned)
        *pcbReturned = sizeof(GUID);
    if (pPropData == NULL)
        return S_OK;
    if (cbPropData < sizeof(GUID))
        return E_UNEXPECTED;
    pGuid = pPropData;
640 641
    *pGuid = PIN_CATEGORY_CAPTURE;
    FIXME("() Not adding a pin with PIN_CATEGORY_PREVIEW\n");
642 643 644 645 646 647 648 649 650 651 652
    return S_OK;
}

static HRESULT WINAPI
KSP_QuerySupported( IKsPropertySet * iface, REFGUID guidPropSet,
                    DWORD dwPropID, DWORD *pTypeSupport )
{
   FIXME("%p: stub\n", iface);
   return E_NOTIMPL;
}

653
static const IKsPropertySetVtbl IKsPropertySet_VTable =
654 655 656 657 658 659 660 661 662
{
   KSP_QueryInterface,
   KSP_AddRef,
   KSP_Release,
   KSP_Set,
   KSP_Get,
   KSP_QuerySupported
};

663
static inline VfwPinImpl *impl_from_BasePin(BasePin *pin)
664
{
665 666 667 668 669 670
    return CONTAINING_RECORD(pin, VfwPinImpl, pin.pin);
}

static HRESULT WINAPI VfwPin_GetMediaType(BasePin *pin, int iPosition, AM_MEDIA_TYPE *pmt)
{
    VfwPinImpl *This = impl_from_BasePin(pin);
671 672 673 674 675 676 677 678
    AM_MEDIA_TYPE *vfw_pmt;
    HRESULT hr;

    if (iPosition < 0)
        return E_INVALIDARG;
    if (iPosition > 0)
        return VFW_S_NO_MORE_ITEMS;

679
    hr = qcap_driver_get_format(This->parent->driver_info, &vfw_pmt);
680 681 682 683
    if (SUCCEEDED(hr)) {
        CopyMediaType(pmt, vfw_pmt);
        DeleteMediaType(vfw_pmt);
    }
684 685 686
    return hr;
}

687
static LONG WINAPI VfwPin_GetMediaTypeVersion(BasePin *iface)
688 689 690 691
{
    return 1;
}

692
static HRESULT WINAPI VfwPin_DecideBufferSize(BaseOutputPin *iface, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
{
    ALLOCATOR_PROPERTIES actual;

    /* What we put here doesn't matter, the
       driver function should override it then commit */
    if (!ppropInputRequest->cBuffers)
        ppropInputRequest->cBuffers = 3;
    if (!ppropInputRequest->cbBuffer)
        ppropInputRequest->cbBuffer = 230400;
    if (!ppropInputRequest->cbAlign)
        ppropInputRequest->cbAlign = 1;

    return IMemAllocator_SetProperties(pAlloc, ppropInputRequest, &actual);
}

708
static const BaseOutputPinFuncTable output_BaseOutputFuncTable = {
709 710 711 712 713 714
    {
        NULL,
        BaseOutputPinImpl_AttemptConnection,
        VfwPin_GetMediaTypeVersion,
        VfwPin_GetMediaType
    },
715 716 717
    VfwPin_DecideBufferSize,
    BaseOutputPinImpl_DecideAllocator,
    BaseOutputPinImpl_BreakConnect
718 719
};

720 721 722 723 724 725 726 727
static HRESULT
VfwPin_Construct( IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec,
                  IPin ** ppPin )
{
    static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
    PIN_INFO piOutput;
    HRESULT hr;

728
    *ppPin = NULL;
729 730 731 732 733

    piOutput.dir = PINDIR_OUTPUT;
    piOutput.pFilter = pBaseFilter;
    lstrcpyW(piOutput.achName, wszOutputPinName);

734
    hr = BaseOutputPin_Construct(&VfwPin_Vtbl, sizeof(VfwPinImpl), &piOutput, &output_BaseOutputFuncTable, pCritSec, ppPin);
735

736 737
    if (SUCCEEDED(hr))
    {
738
        VfwPinImpl *pPinImpl = (VfwPinImpl*)*ppPin;
739
        pPinImpl->IKsPropertySet_iface.lpVtbl = &IKsPropertySet_VTable;
740
        ObjectRefCount(TRUE);
741
    }
742

743
    return hr;
744 745
}

746 747 748 749 750
static inline VfwPinImpl *impl_from_IPin(IPin *iface)
{
    return CONTAINING_RECORD(iface, VfwPinImpl, pin.pin.IPin_iface);
}

751 752
static HRESULT WINAPI VfwPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
{
753
    VfwPinImpl *This = impl_from_IPin(iface);
754 755 756 757 758

    TRACE("%s %p\n", debugstr_guid(riid), ppv);

    *ppv = NULL;
    if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IPin))
759
        *ppv = This;
760
    else if (IsEqualIID(riid, &IID_IKsPropertySet))
761
        *ppv = &This->IKsPropertySet_iface;
762 763
    else if (IsEqualIID(riid, &IID_IAMStreamConfig))
        return IUnknown_QueryInterface((IUnknown *)This->parent, riid, ppv);
764 765 766 767 768 769 770 771 772 773 774 775 776 777

    if (*ppv)
    {
        IUnknown_AddRef((IUnknown *)(*ppv));
        return S_OK;
    }

    FIXME("No interface for %s!\n", debugstr_guid(riid));
    return E_NOINTERFACE;
}

static ULONG WINAPI
VfwPin_Release(IPin * iface)
{
778
   VfwPinImpl *This = impl_from_IPin(iface);
779 780
   ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);

781
   TRACE("() -> new refcount: %u\n", refCount);
782 783 784

   if (!refCount)
   {
785
      BaseOutputPin_Destroy(&This->pin);
786 787 788 789 790 791 792 793
      ObjectRefCount(FALSE);
   }
   return refCount;
}

static HRESULT WINAPI
VfwPin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
{
794
    VfwPinImpl *This = impl_from_IPin(iface);
795 796 797
    AM_MEDIA_TYPE *pmt;
    HRESULT hr;

798
    hr = qcap_driver_get_format(This->parent->driver_info, &pmt);
799
    if (SUCCEEDED(hr)) {
800
        hr = BasePinImpl_EnumMediaTypes(iface, ppEnum);
801 802
        DeleteMediaType(pmt);
    }
803
    TRACE("%p -- %x\n", This, hr);
804 805 806 807 808 809 810 811 812 813 814 815 816
    return hr;
}

static HRESULT WINAPI
VfwPin_QueryInternalConnections(IPin * iface, IPin ** apPin, ULONG * cPin)
{
    TRACE("(%p)->(%p, %p)\n", iface, apPin, cPin);
    return E_NOTIMPL;
}

static const IPinVtbl VfwPin_Vtbl =
{
    VfwPin_QueryInterface,
817
    BasePinImpl_AddRef,
818
    VfwPin_Release,
819 820 821
    BaseOutputPinImpl_Connect,
    BaseOutputPinImpl_ReceiveConnection,
    BaseOutputPinImpl_Disconnect,
822 823 824 825 826 827
    BasePinImpl_ConnectedTo,
    BasePinImpl_ConnectionMediaType,
    BasePinImpl_QueryPinInfo,
    BasePinImpl_QueryDirection,
    BasePinImpl_QueryId,
    BasePinImpl_QueryAccept,
828 829
    VfwPin_EnumMediaTypes,
    VfwPin_QueryInternalConnections,
830 831 832
    BaseOutputPinImpl_EndOfStream,
    BaseOutputPinImpl_BeginFlush,
    BaseOutputPinImpl_EndFlush,
833
    BasePinImpl_NewSegment
834
};