DecodeHeader return MFX_ERR_UNKNOWN occasionally.

DecodeHeader return MFX_ERR_UNKNOWN occasionally.

The same h264 stream was sent by IP packets to MSDK decoder. Every IP packet includes one h264 frame. DecodeHeader is used to initialize the decoder and is called in loop to wait having enough h264 stream data.  But DecodeHeader returns MFX_ERR_UNKNOWN sometime. In order to avoid data corrupted due to transimission, I recorded h264 stream once MFX_ERR_UNKNOWN is returned. And then compared it with the h264 stream in which DecodeHeader return MFX_ERR_NONE byte by byte. No difference, except lengths are different, and the longer one returns MFX_ERR_UNKNOWN. Please see the attached binary and ascii files. The names ending with "+" represents good case.

My enviorment: Win8 64bit, Intel Media SDK 2012 R3, Ivy Bridge i7-3770, graphics driver v9.17.10.2857.

My questions are

  1. what are reasons causing DecodeHeader works unstably? Besides mfxBitStream, DecodeHeader has another argument mfxVideoParam.
  2. Once DecodeHeader returns MFX_ERR_UNKNOWN, should to reset decoder itself. Our observation is once this case happens, the decoder cannot be initialized properly even adding new data.

Thanks in advance.

Jiuxiang

9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Jiuxiang,

I do not see any attached files?

In any case, it seems you are facing a known DecodeHeader limitation.

The H.264 DecodeHeader behavior is currently to parse the header until finding a NAL delimiter after the header (SPS/PPS). SPS/PPS is normally followed by I slice NAL header such as: 0x00 0x00 0x00 0x01 0x65. If no NAL delimiter is found in the provided stream, then DecodeHeader will not succeed.

So, to avoid this, you need to check if the bit stream only contains SPS/PSS. If so, you have to manually insert a "dummy" NAL delimiter after the header, before calling DecodeHeader.

Hopefully this will work for you. Sorry for the inconvenience.

Regards,
Petter

Hi Peter,

Sorry forgetting attach the data. I attached again. Please help me to check these data.

Thanks

Jiuxiang

Attachments: 

Hi Jiuxiang,

I do not see anything wrong with the files you provided. The binary files are both processed successfully by DecodeHeader and following frames decoded successfully.

Not sure what may be going wrong on your side. Could you make check to make sure you are not encountering the scenario I described in my earlier post.

Regards,
Petter

Hi Petter,

Thank you for your reply. Decode ProcessHeader returns -1 occasionally. Please see my attached files which shew the screen shots from my application running. Fail case.jpg includes a break point on the code with a console which shows execution. StreamCmp.jpg shows the comparison of bit stream of this experiment (Failcase.jpg) with that from a successful case. I made carefully check, but can not find where is the bug.

Thanks.
Jiuxiang

Attachments: 

AttachmentSize
Downloadimage/jpeg fail-case.jpg279.21 KB
Downloadimage/jpeg streamcmp.jpg378.09 KB

Hi Jiuxiang,

I see your screen shots but I cannot deduce much from them. From what I understand your application fails during DecodeHeader using the streams provided earlier. It is certainly strange since I'm able to process the streams using DecodeHeader without issues.

If you feed the streams into Media SDK "sample_decode" does it work?

Does it always fail or just intermittently?

What does your function that reads more data into bitstream look like? Make sure that new data is appended, not overwriting what is already in bitstream buffer.

Could you also please share some details on your system configuration such as driver version, OS, Media SDK versions etc.?

Regards,
Petter

Hi Petter,

Thank you for your reply. It just fails intermittently. The decoder initialization worked fine when it ran in Win 7. In my previous post, I asked if MSDK 2012 R3 decoder supports DX11, your answer was yes. I made change from DX9 decoder to DX11 decoder and it works fine except this issue. The strange thing is that it does not always fail and MSDK "sample_decode" works fine with those streams which fails in my app.

Bitstream in the read function is appended and not overwritten when the function gets IP packets. We are very careful to initialize the decoder. At beginning, I doubted it was bitstream reading problem, so I wrote the bitstream into a file to check if a bitstream miss some bytes.

The system configuration is as follows:
OS is Win8-64bit (Embedded)
Graphics driver: 9.17.10.2857
MSDK: 2012 R3
CPU: Intel Core i7-3770
IDE: Visual Studio 2012

I attached the header process function and the code to call this function.

Thanks
Jiuxiang

mfxStatus H264Decoder::InitDecoder()
{
....
do{
sts = ProcessHeader();
} while(sts == MFX_ERR_MORE_DATA || sts == MFX_ERR_UNKNOWN);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
......
return sts;
}
mfxStatus H264Decoder::ProcessHeader()
{
MSDK_CHECK_POINTER(m_pmfxDEC, MFX_ERR_NULL_PTR);
mfxStatus sts = MFX_ERR_NONE;
static int firstPH = 0;
printf("[%u] Processing/Decoding Header... (%u bytes available)\n", m_nLayer, GetBufferedEncodedDataLength());
// parse bit stream and fill mfx params
//#ifdef CIRCULAR_INPUT_BUFFER
//sts = m_pmfxDEC->DecodeHeader(m_inputBuffer.startFrameRead(), &m_mfxVideoParams);
//#else
sts = m_pmfxDEC->DecodeHeader(&m_mfxBS, &m_mfxVideoParams);
//#endif
printf("Decoding Header return Status %d\n", sts);
if (MFX_ERR_MORE_DATA == sts || MFX_ERR_UNKNOWN == sts)
{
Sleep(500);
printf("[%u] Need more data to decode header!\n", m_nLayer);
//#ifndef CIRCULAR_INPUT_BUFFER
ReadNextBitstream(false);
//#endif
}
// to watch if the data losing when return MFX_ERR_UNKNOWN
if(MFX_ERR_UNKNOWN == sts && firstPH == 0)
{
uofstream myFile("c:\\data\\h264streambinary.h264", ios::out | ios::binary);
uofstream myFile1("c:\\data\\h264streambascii.h264", ios::out );
myFile.write( m_mfxBS.Data, m_mfxBS.DataLength);
myFile.close();
myFile1 << std::hex << endl;
char buffer[3];
for(int i = 0; i < m_mfxBS.DataLength; i++)
{
sprintf(buffer,"%02X ",m_mfxBS.Data[i]);
myFile1 << buffer;
if((i+1) % 16 == 0)
myFile1 <

Hi Jiuxiang,

Thanks for sharing your configuration details.

Interesting to hear that sample_decode (using DX11, right?) works without issues. That seems to indicate that there is potentially something going wrong in your application.

Could you share the code you use to allocate, initialize and fill data into m_mfxBS ?

Regards,
Petter

Hi Petter,

Thank you for your suggestions. Your suggestion brought me a big brainstorming. This problem was solved by using synchronization of decode threads.

Thanks,
Jiuxiang

Leave a Comment

Please sign in to add a comment. Not a member? Join today