Skip to content

Add startcode emulation prevention #8

@andrey-utkin

Description

@andrey-utkin

The problem with that particular stream is that you haven't added emulation prevention bytes to escape zeroes, so the decoder is getting confused by occasional sequences that look like start codes. For that stream, there are several glitches in the first 1000 frames, and I was able to manually add the emulation prevention bytes to make it decode without problems.

So, I think that in your driver, in the function:

static void tw5864_handle_frame(struct tw5864_h264_frame *frame)

rather than the stright copy with:

memcpy(dst, frame->vlc.addr + skip_bytes, frame_len);

you want something like:

size_t i, j;
int zero_run;
u8 *src;
...
src = frame->vlc.addr + skip_bytes;
zero_run = 0;
for (i = j = 0; i < frame_len; i++) {
  if (zero_run < 2) {
    if (src[i] == 0)
      ++zero_run;
    else
      zero_run = 0;
  } else {
    if ((src[i] & ~0x03) == 0) {
      dst[j++] = 0x03;
    zero_run = src[i] == 0;
  }
  dst[j++] = src[i];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions