Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startcode emulation prevention #8

Open
andrey-utkin opened this issue Apr 17, 2016 · 0 comments
Open

Add startcode emulation prevention #8

andrey-utkin opened this issue Apr 17, 2016 · 0 comments

Comments

@andrey-utkin
Copy link

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];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant