Parameter meaning of CBasePin::GetMediaType(int iPosition, ...) method

Posted by user325320 on Stack Overflow See other posts from Stack Overflow or by user325320
Published on 2012-08-28T03:35:58Z Indexed on 2012/08/28 3:38 UTC
Read the original article Hit count: 193

Filed under:

Thanks to everyone who views my question.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd368709(v=vs.85).aspx

It is not very clear from the documentation regarding the iPosition parameter for

virtual HRESULT GetMediaType(
  int iPosition,
  CMediaType *pMediaType
);

It is said "Zero-based index value.", but what kind of index it is? the index of the samples?

I have a source filter sending the H.264 NALU flows (MEDIASUBTYPE_AVC1) and it works very well except that the SPS/PPS may be changed after the video is played for a while.

The SPS and PPS are appended to the MPEG2VIDEOINFO structure, which is passed in CMediaType::SetFormat method when GetMediaType method is called.

and there is another version of GetMediaType which accepts the iPosition parameter. It seems I can use this method to update the SPS / PPS.

My question is: What does the iPosition param mean, and how does Decoder Filter know which SPS/PPS are assigned for each NALU sample.

HRESULT GetMediaType(int iPosition, CMediaType *pMediaType)
{
    ATLTRACE( "\nGetMediaType( iPosition = %d ) ", iPosition);
    CheckPointer(pMediaType,E_POINTER);  
    CAutoLock lock(m_pFilter->pStateLock());

    if (iPosition < 0)
    {
        return E_INVALIDARG;
    }
    if (iPosition == 0)
    {
        pMediaType->InitMediaType();
        pMediaType->SetType(&MEDIATYPE_Video); 
        pMediaType->SetFormatType(&FORMAT_MPEG2Video);  
        pMediaType->SetSubtype(&MEDIASUBTYPE_AVC1);
        pMediaType->SetVariableSize();

    }

    int nCurrentSampleID;
    DWORD dwSize = m_pFlvFile->GetVideoFormatBufferSize(nCurrentSampleID);
    LPBYTE pBuffer = pMediaType->ReallocFormatBuffer(dwSize);
    memcpy( pBuffer, m_pFlvFile->GetVideoFormatBuffer(nCurrentSampleID), dwSize);

    pMediaType->SetFormat(pBuffer, dwSize);


    return S_OK;
}

© Stack Overflow or respective owner

Related posts about directshow