Controling H.264 decoding latency
There is a new parameter in AVBlocks 1.8 called MaxDecFrameBuffering (corresponding to max_dec_frame_buffering
from the AVC / H.264 standard).
It controls the decoded picture buffer size of the decoder and indirectly affects the decoding latency.
Here are some key notes about using this parameter:
- It must be set to the output pin (see the sample code below)
- The supported values are 0 and 1. A negative value is ignored.
- MaxDecFrameBuffering(0) achieves decoding latency of 0 frames for progressive streams and 1 frame for interlaced streams.
- MaxDecFrameBuffering(1) achieves decoding latency of 1 frame both for progressive and interlaced streams.
- If the stream has B-frames (or more precisely the total number of reference frames is greater than 1) the decoding will still succeed, but decoding latency will be greater than the required one, as a safety guard.
- With MaxDecFrameBuffering (0|1) only one decoding thread is used, so it hurts performance and it must be used only when low decoding latency is the primary goal.
The following code can be used to set the MaxDecFrameBuffering
parameter to an output pin:
void setH264DecodingLatency(primo::avblocks::MediaPin* pin, int32_t desiredLatency)
{
using namespace primo::avblocks;
using namespace primo::avblocks::Param;
ParameterList* params ( Library::createParameterList() );
IntParameter* maxDecFrameBuffering (Library::createIntParameter() );
maxDecFrameBuffering->setName(Decoder::Video::H264::VUI::MaxDecFrameBuffering);
maxDecFrameBuffering->setValue(desiredLatency);
params->add(maxDecFrameBuffering);
maxDecFrameBuffering->release();
pin->setParams(params);
params->release();
}