Reputation: 14820
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;
}
Upvotes: 0
Views: 608
Reputation: 891
The iPosition is used to offer different mediatypes, like other resolutions or different encoding or in your exampel maybe a raw h246. If you only offer one type, thats ok, but don't forget to send VFW_S_NO_MORE_ITEMS
if the iPosition is to high.
The sps/pps changes are send with the mediasamples. You simply add your new mediatype to the current sample in FillBuffer
. Some decoders didn't even need that, they just read the sps/pps from the datastream.
Upvotes: 3