Вопрос

I am using a source filter of a webcam. When I use the filter in graphstudio it has two output pins. However in code the call to IEnumPins->next always returns S_FALSE. I also looked for another interface that could create pins but didn't find such a thing.

enter image description here

How do I add pins to the webcam filter? If they're available in graphstudio they should be in code too, right?

Here is my code.. I checked for return values and returned them if they are not ok. But everything seems to work fine except that the webcam filter doesn't return any pins

CoInitialize(NULL);

    IGraphBuilder* graphBuilder = NULL;
    IMediaControl* mediaControl = NULL;
    IMediaEvent* mediaEvent = NULL;

    HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IFilterGraph, (void **)&graphBuilder);

    HANDLE fileHandle = CreateFile(L"D:\\TEMP\\debug1.log", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL);

    graphBuilder->SetLogFile((DWORD_PTR)fileHandle);
    graphBuilder->QueryInterface(IID_IMediaControl, (void **)&mediaControl);
    graphBuilder->QueryInterface(IID_IMediaEvent, (void **)&mediaEvent);

    IBaseFilter* source = NULL;


    static const GUID CLSID_Webcam =
    { 0x17CCA71B, 0xECD7, 0x11D0, { 0xB9, 0x08, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96 } };
    hr = CoCreateInstance(CLSID_Webcam, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&source);
    if (FAILED(hr))
        return hr;
    hr = graphBuilder->AddFilter(source, L"logitech");
    if (FAILED(hr))
        return hr;


    IPin* camOut = GetPin(source, PINDIR_OUTPUT);
    ...

The GetPin function uses EnumPins method to find pin:

IPin *GetPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir)
{
    BOOL       bFound = FALSE;
    IEnumPins  *pEnum;
    IPin       *pPin;

    pFilter->EnumPins(&pEnum);
    while (pEnum->Next(1, &pPin, 0) == S_OK)
    {
        PIN_DIRECTION PinDirThis;
        pPin->QueryDirection(&PinDirThis);
        if (bFound = (PinDir == PinDirThis))
            break;
        pPin->Release();
    }
    pEnum->Release();
    return (bFound ? pPin : 0);
}

Also, I don't think that this is 32/64bit problem. I compile to x64 and I also used the 64bit version of graphstudionext. And i also made sure that the guid of the webcam filter is correct. (At least if you can trust graphstudionext)

Это было полезно?

Решение

This is an indication that your code deals with another filter or has bugs otherwise. You normally don't "create" pins, especially on video device backed source filter. Typical reasons are: (a) you are effectively creating a different filter, (b) direct bug in your code, (c) 32/64-bit issue with different filters in the two environments. There can hardly be anything else. Stepping and inspecting your code thoroughly, adding debug output should take you to the solution.

UPDATE. Video capture devices like this cannot be instantiated using CoCreateInstance. You have to create them using monikers. typically through enumeration, as described on MSDN (with source code snippet): Selecting a Capture Device.

The code below is incorrect, FYI this GUID is declared in SDK as CLSID_Proxy.

 static const GUID CLSID_Webcam =
{ 0x17CCA71B, 0xECD7, 0x11D0, { 0xB9, 0x08, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96 } };
hr = CoCreateInstance(CLSID_Webcam, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&source);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top