Hi,
I am currently working on decoders, and I am a bit puzzled by frame management.
I have a decoding loop which looks like this :
sts = MFX_ERR_MORE_SURFACE;
while ((sts == MFX_ERR_MORE_SURFACE) || (sts == MFX_ERR_MORE_DATA))
{
if (bNeedFrame == 0)
{
// find an available frame
// now, pElement->mfxFrame is a fresh buffer
}
pFrameOut = NULL;
memset(&sSyncPoint, 0, sizeof(sSyncPoint));
sts =
MFXVideoDECODE_DecodeFrameAsync(hMfxSession,
&sBitstream,
&pElement->mfxFrame,
&pFrameOut, &sSyncPoint);
if (sts == MFX_ERR_MORE_DATA)
{
// refill bitstream
}
else if (sts == MFX_ERR_MORE_SURFACE)
bNeedFrame = 0;
else if (sts == MFX_ERR_NONE)
{
if (pFrameOut == &pElement->mfxFrame)
bNeedFrame = 0;
}
if ((sts == MFX_ERR_NONE) && (sSyncPoint != NULL))
sts =
MFXVideoCORE_SyncOperation(hMfxSession, sSyncPoint,
MSDK_DEC_WAIT_INTERVAL);
if ((sts == MFX_ERR_NONE) && (pFrameOut != NULL))
{
// use decoded frame
}
}
This piece of software is used for both h264 and mpeg2 standards. I want to produce exactly one frame at a time in this part of the code. I do not know how to handle my bNeedFrame flag. I thought two options were possible :
- Either I reset it before entering the loop, making the loop looking for a available buffer. However, if I do that, the h264 decoder consumes more buffers that allocated. This way, the decoder uses more than the number of buffers suggested in MFXVideoDECODE_QueryIOSurf function.
- Or I let the decoder inform me that he needs fresh buffers : entering the loop, I use the old working buffer and wait for the decoder to produce a MFX_ERR_MORE_SURFACE status. This does not work either, in mpeg2 the decoder seems to overwrite old surfaces with new ones without querying for new surfaces.



