Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
Announcements
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.

Unexpected MFX_ERR_NOT_ENOUGH_BUFFER

koby_s_
Beginner
371 Views

Hi

I am trying to encode H264 stream. Sometimes, m_mfxSession->SyncOperation return MFX_ERR_NOT_ENOUGH_BUFFER.
I allocating mfxBitstream buffers according the the value in mfxVideoParam.mfx.BufferSizeInKB * 1000.
Trying to increase the buffer (up to 10MB !) doesn't help and SyncOperation keeps on returning MFX_ERR_NOT_ENOUGH_BUFFER
I attached a code snippet that waits for the bitstream

mfxStatus intel_h264_encoder::PutBS()
{
	mfxStatus	sts				= MFX_ERR_NONE;
	ExtendedBS *pBitstreamEx	= m_BSPool.front();
	
	sts = m_mfxSession.SyncOperation(pBitstreamEx->Syncp, MSDK_WAIT_INTERVAL);

	int i = 0;
	while (sts == MFX_ERR_NOT_ENOUGH_BUFFER)
	{
		LOG << "intel_h264_encoder::PutBS - sync op failed due to NOT ENOUGH BUFFER, extending buffer. #i=" << i++ << " profile=" << m_profile.profile_name;
		mfxStatus allocateBufferSts = AllocateSufficientBuffer(&pBitstreamEx->Bitstream);
		if (allocateBufferSts == MFX_ERR_NONE)
		{
			LOG << "intel_h264_encoder::PutBS - buffer extended, trying to sync again #i=" << i << " profile=" << m_profile.profile_name;
			sts = m_mfxSession.SyncOperation(pBitstreamEx->Syncp, MSDK_WAIT_INTERVAL);
			
			if (sts == MFX_ERR_NONE)
				LOG << "intel_h264_encoder::PutBS - sync op OK after buffer extension" << " profile=" << m_profile.profile_name;
		}
		else if (allocateBufferSts == MFX_ERR_MEMORY_ALLOC)	//
		{
			LOG << "intel_h264_encoder::PutBS - buffer extended to maximum=" << pBitstreamEx->Bitstream.MaxLength << ", GOING TO FAIL #i=" << i << " profile=" << m_profile.profile_name;
			// set original error code
			sts = MFX_ERR_NOT_ENOUGH_BUFFER;
			break;
		}
	}


	if (sts < MFX_ERR_NONE)
	{
		LOG << "intel_h264_encoder::PutBS - sync op failed. sts=" << sts << " profile=" << m_profile.profile_name;
		pBitstreamEx->Bitstream.DataLength = 0;
		pBitstreamEx->Bitstream.DataOffset = 0;

		m_BSPool.pop_front();
		m_pBSStore->Release(pBitstreamEx);

		return sts;
	}

	// don't send samples if draining the encoder
	if (m_run)
	{
		m_encoded_frames++;

		int64_t pts = pBitstreamEx->Bitstream.TimeStamp;
		int64_t dts = pBitstreamEx->Bitstream.DecodeTimeStamp;

		bool b = compressed_frame_ready(pBitstreamEx->Bitstream.Data, pts, dts);
	}

	pBitstreamEx->Bitstream.DataLength = 0;
	pBitstreamEx->Bitstream.DataOffset = 0;

	m_BSPool.pop_front();
	m_pBSStore->Release(pBitstreamEx);

	return sts;
} //

 

 

My question are:
why SyncOperation return NOT_ENOUGH_BUFFER error?
Should I increase the allocated buffer size (double it to BufferSizeInKB * 2 * 1000 maybe )  ?
Can I increase the buffer once I got a valid sync point but SyncOperation fail with NOT_ENOUGH_BUFFER (like I do in the above code)
How should I recover from this situation?
If i will not perform SyncOperation on that SyncPoint, all the subsequent calls will fail with MFX_ERR_ABORT
It seems that the only solution is to reset the encoder.
Any help will be appreciated!

Thanks
Koby

0 Kudos
0 Replies
Reply