views:

296

answers:

1

I have built the ezrgb24 sample project successfully, which is in the DirectShow SDK. But I encountered a confused problem when I debug it.

The following Copy method was called by the Transform method.

HRESULT CEZrgb24::Copy(IMediaSample *pSource, IMediaSample *pDest) const
{
    ...
    // Copy the sample data
    BYTE *pSourceBuffer, *pDestBuffer;
    long lSourceSize = pSource->GetActualDataLength();

#ifdef DEBUG
    long lDestSize = pDest->GetSize();
    ASSERT(lDestSize >= lSourceSize);
#endif

    ...
}

The assert statment failed. With graphedit, I checked the filter's input media type is RGB24 and the output is also RGB24. I cannot understand why the buffer size of the output will be smaller than acural data size of the input. Who can help me?

Thanks.

--------------------------------------------------2009/8/20 edited

O, I found the actually input media subtye is of RGB32 but output's subtype is RGB24. But why the type can be RGB32 for both the CEZrgb24::CheckInputType method and the CEZrgb24::CheckTransform only return OK for RGB24.

--------------------------------------------------2009/8/21 edited

I hit the problem. Modify the CEZrgb24::Copy methold as following,

HRESULT CEZrgb24::Copy(IMediaSample *pSource, IMediaSample *pDest) const
{
    ...
    // Copy the sample data
    BYTE *pSourceBuffer, *pDestBuffer;
    long lSourceSize = m_pInput->CurrentMediaType().GetSampleSize();

#ifdef DEBUG
    long lDestSize = m_pOutput->CurrentMediaType().GetSampleSize();
    ASSERT(lDestSize >= lSourceSize);
#endif

    ...
}

Now, the assert successed.

A: 

Well that would imply that you aren't making sure that the CMediaType for the output is valid.

In ::CheckTransform it will return E_FAIL unless mtIn and mtOut are the same, while CanPerformEZrgb24 confirms that the SubType is RGB_24. One of these tests MUST be allowing RGB32 to get through. This implies you have modified the code slightly.

Check the following functions look like the following:

HRESULT CEZrgb24::CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)
{
    CheckPointer(mtIn,E_POINTER);
    CheckPointer(mtOut,E_POINTER);

    if (CanPerformEZrgb24(mtIn)) 
    {
        if (*mtIn == *mtOut) 
        {
            return NOERROR;
        }
    }
    return E_FAIL;
}

BOOL CEZrgb24::CanPerformEZrgb24(const CMediaType *pMediaType) const
{
    CheckPointer(pMediaType,FALSE);

    if (IsEqualGUID(*pMediaType->Type(), MEDIATYPE_Video)) 
    {
        if (IsEqualGUID(*pMediaType->Subtype(), MEDIASUBTYPE_RGB24)) 
        {
            VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER *) pMediaType->Format();
            return (pvi->bmiHeader.biBitCount == 24);
        }
    }

    return FALSE;

}
Goz
I did not modify them. I just built and debug the project.
Cook Schelling
I tried to modify a statement, CopyMemory( (PVOID) pDestBuffer,(PVOID) pSourceBuffer,lSourceSize), of the CEZrgb24::Copy as CopyMemory( (PVOID) pDestBuffer,(PVOID) pSourceBuffer,min(lSourceSize, lDestSize)). And it works although there are a few frames rendered as red.
Cook Schelling