다음을 통해 공유


고정 범주 작업

[이 페이지와 연결된 기능인 DirectShow는 레거시 기능입니다. MediaPlayer, IMFMediaEngineMedia Foundation의 오디오/비디오 캡처로 대체되었습니다. 이러한 기능은 Windows 10 및 Windows 11 최적화되었습니다. 가능한 경우 새 코드에서 DirectShow 대신 MediaPlayer, IMFMediaEngine오디오/비디오 캡처를 사용하는 것이 좋습니다. 가능한 경우 레거시 API를 사용하는 기존 코드를 다시 작성하여 새 API를 사용하도록 제안합니다.]

지정된 핀 범주가 있는 핀을 필터에서 검색하려면 ICaptureGraphBuilder2::FindPin 메서드를 사용할 수 있습니다. 다음 예제에서는 비디오 미리 보기 핀을 검색합니다.

int i = 0;
hr = pBuild->FindPin(
    pFilter,               // Pointer to a filter to search.
    PINDIR_OUTPUT,         // Which pin direction?
    &PIN_CATEGORY_PREVIEW, // Which category? (NULL means "any category")
    &MEDIATYPE_Video,      // What media type? (NULL means "any type")
    FALSE,                 // Must be connected?
    i,                     // Get the i'th matching pin (0 = first match)
    &pPin                  // Receives a pointer to the pin.
);

첫 번째 매개 변수는 필터의 IBaseFilter 인터페이스에 대한 포인터입니다. 다음 세 가지 매개 변수는 방향, 핀 범주 및 미디어 형식을 지정합니다. 다섯 번째 매개 변수의 FALSE 값은 핀이 연결되거나 연결되지 않을 수 있음을 나타냅니다. (이러한 매개 변수의 정확한 정의는 메서드에 대한 설명서를 참조하세요.) 메서드가 일치하는 핀을 찾으면 pPin 매개 변수의 IPin 인터페이스에 대한 포인터를 반환합니다.

FindPin 메서드는 편리하지만 원하는 경우 사용자 고유의 도우미 함수를 작성할 수도 있습니다. 핀의 범주를 확인하려면 Pin 속성 집합 항목에 설명된 대로 IKsPropertySet::Get 메서드를 호출합니다.

다음 코드는 핀이 지정된 범주와 일치하는지 여부를 확인하는 도우미 함수를 보여줍니다.

// Returns TRUE if a pin matches the specified pin category.

BOOL PinMatchesCategory(IPin *pPin, REFGUID Category)
{
    BOOL bFound = FALSE;

    IKsPropertySet *pKs = NULL;
    HRESULT hr = pPin->QueryInterface(IID_PPV_ARGS(&pKs));
    if (SUCCEEDED(hr))
    {
        GUID PinCategory;
        DWORD cbReturned;
        hr = pKs->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0, 
            &PinCategory, sizeof(GUID), &cbReturned);
        if (SUCCEEDED(hr) && (cbReturned == sizeof(GUID)))
        {
            bFound = (PinCategory == Category);
        }
        pKs->Release();
    }
    return bFound;
}

다음 예제는 FindPin 메서드와 유사한 범주별 핀을 검색하는 함수입니다.

// Finds the first pin that matches a specified pin category and direction.

HRESULT FindPinByCategory(
    IBaseFilter *pFilter, // Pointer to the filter to search.
    PIN_DIRECTION PinDir, // Direction of the pin.
    REFGUID Category,     // Pin category.
    IPin **ppPin)         // Receives a pointer to the pin.
{
    *ppPin = 0;

    HRESULT hr = S_OK;
    BOOL bFound = FALSE;

    IEnumPins *pEnum = 0;
    IPin *pPin = 0;

    hr = pFilter->EnumPins(&pEnum);
    if (FAILED(hr))
    {
        goto done;
    }

    while (hr = pEnum->Next(1, &pPin, 0), hr == S_OK)
    {
        PIN_DIRECTION ThisPinDir;
        hr = pPin->QueryDirection(&ThisPinDir);
        if (FAILED(hr))
        {
            goto done;
        }
        if ((ThisPinDir == PinDir) && 
            PinMatchesCategory(pPin, Category))
        {
            *ppPin = pPin;
            (*ppPin)->AddRef();   // The caller must release the interface.
            bFound = TRUE;
            break;
        }
        SafeRelease(&pPin);
    }

done:
    SafeRelease(&pPin);
    SafeRelease(&pEnum);
    if (SUCCEEDED(hr) && !bFound)
    {
        hr = E_FAIL;
    }
    return hr;
}

다음 코드는 이전 함수를 사용하여 필터에서 비디오 포트 핀을 검색합니다.

IPin *pVP; 
hr = FindPinByCategory(pFilter, PINDIR_OUTPUT, 
    PIN_CATEGORY_VIDEOPORT, &pVP);
if (SUCCEEDED(hr))
{
    // Use pVP ... 
    // Release when you are done.
    pVP->Release();
}

속성 집합에 대한 자세한 내용은 WDK(Windows 드라이버 키트) 설명서를 참조하세요.

고급 캡처 항목

Pin 속성 집합

DirectShow 비디오 캡처 필터