Microsoft DirectX 9.0

Step 3B. Implement the GetMediaType Method

Note   This step is not required for filters that derive from CTransInPlaceFilter.

The CTransformFilter::GetMediaType method returns one of the filter's preferred output types, referenced by index number. This method is never called unless the filter's input pin is already connected. Therefore, you can use the media type from the upstream connection to determine the preferred output types. 

An encoder typically offers a single preferred type, representing the target format. Decoders generally support a range of output formats, and offer them in order of descending quality or efficiency. For example, the list might be UYVY, Y211, RGB-24, RGB-565, RGB-555, and RGB-8, in that order. Effect filters may require an exact match between the output format and the input format.

The following example returns a single output type, which is constructed by modifying the input type to specify RLE8 compression:

HRESULT CRleFilter::GetMediaType(int iPosition, CMediaType *pMediaType)
{
    ASSERT(m_pInput->IsConnected());
    if (iPosition < 0)
    {
        return E_INVALIDARG;
    }
    if (iPosition == 0)
    {
        HRESULT hr = m_pInput->ConnectionMediaType(pMediaType);
        if (FAILED(hr))
        {
            return hr;
        }
        FOURCCMap fccMap = FCC('MRLE'); 
        pMediaType->subtype = static_cast<GUID>(fccMap);
        pMediaType->SetVariableSize();
        pMediaType->SetTemporalCompression(FALSE);

        ASSERT(pMediaType->formattype == FORMAT_VideoInfo);
        VIDEOINFOHEADER *pVih =
            reinterpret_cast<VIDEOINFOHEADER*>(pMediaType->pbFormat);
        pVih->bmiHeader.biCompression = BI_RLE8;
        pVih->bmiHeader.biSizeImage = DIBSIZE(pVih->bmiHeader); 
        return S_OK;
    }
    // else
    return VFW_S_NO_MORE_ITEMS;
}

In this example, the method calls IPin::ConnectionMediaType to get the input type from the input pin. Then it changes some of the fields to indicate the compression format, as follows: