Community
cancel
Showing results for 
Search instead for 
Did you mean: 
vucetica
Beginner
81 Views

Bad frames comming out from mpeg2 and h264 decoder

Hi all,
I'm trying to decode mpeg2 (the same with h264) stream using the following algorithm (enforced by the framework around my decoder):
1. Input data stream arrives in chunks, and I feed DataIn with those bytes ("read" method shown above is called by the framework).
2. Then framework calls status = decoder.GetFrame(DataIn, DataOut) in order to get decoded frame.
3. If status is UMC::UMC_OK, framework calls decode again.
4. If status != UMC::UMC_OK framework calls "read" method where I append new data to the remaining bytes of DataIn and reinitialize DataIn:
[cpp]bool read(Buffer &buffer, unsigned int length)
{
  // Initialize new buffer for DataIn (bufferIn)
  size_t dataInDataSize = initialized ? DataIn.GetDataSize() : 0;
  size_t bufferInLength = length + dataInDataSize;
  Ipp8u* bufferIn = new Ipp8u[bufferInLength];

  // Get valid data from DataIn and free the buffer
  memcpy(bufferIn, DataIn.GetDataPointer(), DataIn.GetDataSize()); 
  void* bufferPointer = DataIn.GetBufferPointer();
  delete[] bufferPointer;

  // Get new data
  buffer.read(bufferIn + dataInDataSize, length);

  // Initialize new buffer for DataIn
  UMC_CHK(DataIn.SetBufferPointer(bufferIn, bufferInLength));
  UMC_CHK(DataIn.SetDataSize(bufferInLength));

  return true;
}[/cpp]
5. This works good for some files
6. For some other files, decoder.GetFrame returns UMC::UMC_OK, but decoded frame is highly corrupted (and IsInvalid() reports 0). Frame looks like it misses some data in order to be fully decoded (green/pink shadows, or some I/P frame is missing), but the strange thing is that decoder reports UMC::UMC_OK so I do not know when to force another "read" and add some more data to DataIn.
7. When I force "read" method till DataIn is filled to some big number of bytes (for example width * height), frames are decoded OK, but this is not a good solution, since I have some latency when I wait for buffer to be filled that much (and most likely that many bytes are not neccessary for decoding).
Framework works something like this:
[cpp]void f()
{
  bool doRead = true;
  while(true)
  {
    if(doRead)
    {    
        // fetch some data into buffer
        myDecoder.read(buffer, length);
    }
    else
        doRead = !myDecoder.decode();
    
  }
}[/cpp]
What am I doing wrong with this decoder? Thanks.
Kind Regards,
Aleksandar
0 Kudos
5 Replies
Chao_Y_Intel
Employee
81 Views


Hi Aleksandar,

When you call decoder->GetFrame(input, out) to decoder a frame data, it need to make sure the whole frame data are in the input buffer, or the decoder may not return the correct full frame data.

Is it the case your code?

Thanks,
Chao

vucetica
Beginner
81 Views

Hi Chao,
You are right, but it is strange that GetFrame returns UMC_OK and incorrect image. Shouldn't GetFrame return UMC_NOT_ENOUGH_DAtA or some other error, so I know that I have to fill up input buffer with some more data?

Thanks,
Aleksandar
Chao_Y_Intel
Employee
81 Views


Aleksandar,

Considering the input bitstream may always include error data, the decoder will also try to recover the error. The decoder itself actually does not know if the input data is only for part of the frame data, or the input data is for full frame. Often, the splitter provides a full frame data, and feed it into the decoder.

Thanks,
Chao

vucetica
Beginner
81 Views

So, are you saying that splitter from the framework I'm using doesn't do it's job well?
I beleive that feeding MP2Splitter in my "read" method will not do the job since data arriving there is already "splitted"? I was thinking that splitter might be able to recognize when I have enough data for a full frame.
Thanks,
Aleksandar
vucetica
Beginner
81 Views

Is there any sequence of bits by which I can recognize beginning of a frame? Thanks.
Reply