Requisiti di aggiunta per i filtri di acquisizione

[La funzionalità associata a questa pagina, DirectShow, è una funzionalità legacy. È stata sostituita da MediaPlayer, IMFMediaEngine e Audio/Video Capture in Media Foundation. Queste funzionalità sono state ottimizzate per Windows 10 e Windows 11. Microsoft consiglia vivamente che il nuovo codice usi MediaPlayer, IMFMediaEngine e Audio/Video Capture in Media Foundation invece di DirectShow, quando possibile. Microsoft suggerisce che il codice esistente che usa le API legacy venga riscritto per usare le nuove API, se possibile.

Questo argomento descrive i requisiti per l'implementazione di un pin di output in un filtro di acquisizione DirectShow.

Nome pin

È possibile assegnare un pin a qualsiasi nome. Se il nome del pin inizia con il carattere tilde (~), Filter Graph Manager non esegue automaticamente il rendering del pin quando un'applicazione chiama IGraphBuilder::RenderFile. Ad esempio, se il filtro ha un pin di acquisizione e un pin di anteprima, è possibile denominarli rispettivamente "~Capture" e "Preview". Se un'applicazione esegue il rendering di tale filtro in un grafico, il pin di anteprima si connetterà al renderer predefinito e non si connetterà nulla al pin di acquisizione, ovvero un comportamento predefinito ragionevole. Ciò può essere applicato anche ai pin che recapitano dati informativi che non devono essere sottoposti a rendering o pin che necessitano di proprietà personalizzate impostate. Si noti che i pin con il prefisso tilde (~) possono comunque essere connessi manualmente dall'applicazione.

Aggiungi categoria

Un filtro di acquisizione ha sempre un pin di acquisizione e potrebbe avere un pin di anteprima. Alcuni filtri di acquisizione potrebbero avere altri pin di output, per distribuire altri tipi di dati, ad esempio le informazioni di controllo. Ogni pin di output deve esporre l'interfaccia IKsPropertySet . Le applicazioni usano questa interfaccia per determinare la categoria di puntini. Il pin restituisce in genere PIN_CATEGORY_CAPTURE o PIN_CATEGORY_PREVIEW. Per altre informazioni, vedere Pin Property Set.For more information, see Pin Property Set.

L'esempio seguente mostra come implementare IKsPropertySet per restituire la categoria di pin in un pin di acquisizione:

// Set: Cannot set any properties.
HRESULT CMyCapturePin::Set(REFGUID guidPropSet, DWORD dwID,
    void *pInstanceData, DWORD cbInstanceData, void *pPropData, 
    DWORD cbPropData)
{
    return E_NOTIMPL;
}

// Get: Return the pin category (our only property). 
HRESULT CMyCapturePin::Get(
    REFGUID guidPropSet,   // Which property set.
    DWORD dwPropID,        // Which property in that set.
    void *pInstanceData,   // Instance data (ignore).
    DWORD cbInstanceData,  // Size of the instance data (ignore).
    void *pPropData,       // Buffer to receive the property data.
    DWORD cbPropData,      // Size of the buffer.
    DWORD *pcbReturned     // Return the size of the property.
)
{
    if (guidPropSet != AMPROPSETID_Pin) 
        return E_PROP_SET_UNSUPPORTED;
    if (dwPropID != AMPROPERTY_PIN_CATEGORY)
        return E_PROP_ID_UNSUPPORTED;
    if (pPropData == NULL && pcbReturned == NULL)
        return E_POINTER;
    if (pcbReturned)
        *pcbReturned = sizeof(GUID);
    if (pPropData == NULL)  // Caller just wants to know the size.
        return S_OK;
    if (cbPropData < sizeof(GUID)) // The buffer is too small.
        return E_UNEXPECTED;
    *(GUID *)pPropData = PIN_CATEGORY_CAPTURE;
    return S_OK;
}

// QuerySupported: Query whether the pin supports the specified property.
HRESULT CMyCapturePin::QuerySupported(REFGUID guidPropSet, DWORD dwPropID,
    DWORD *pTypeSupport)
{
    if (guidPropSet != AMPROPSETID_Pin)
        return E_PROP_SET_UNSUPPORTED;
    if (dwPropID != AMPROPERTY_PIN_CATEGORY)
        return E_PROP_ID_UNSUPPORTED;
    if (pTypeSupport)
        // We support getting this property, but not setting it.
        *pTypeSupport = KSPROPERTY_SUPPORT_GET; 
    return S_OK;
}

Scrittura di filtri di acquisizione