aizvorski / h264bitstream

A complete set of functions to read and write H.264 video bitstreams, in particular to examine or modify headers.
GNU Lesser General Public License v2.1
717 stars 238 forks source link

more_rbsp_data function is wrong #2

Closed alexvazquezfente closed 10 years ago

alexvazquezfente commented 10 years ago

I am using the h264bitstream command to help me writing an h.264 decoder and i think the implementation of function more_rbsp_data() in h264bitstream_data is wrong. The parser is not detecting PPS with transform_8x8_mode_flag = 1 (nor the remaining PPS syntax elements) due to more_rbsp_data() interpreting that bit as the rsbp_stop_bit. Also, sei messages are not correctly parsed. This is a working implementation:

int more_rbsp_data(h264_stream_t* h, bs_t* bs) {

  /* no more data */
  if (bs_eof(bs)) return 0;

  /* no rbsp_stop_bit yet */
  if (bs_peek_u1(bs) == 0) return 1;

  /* next bit is 1, is it the rsbp_stop_bit? only if the rest of bits are 0 */
  bs_t aux;
  bs_clone(&aux, bs);
  bs_skip_u1(&aux);
  while(!bs_eof(&aux)) {
    /* A later bit was 1, it wasn't the rsbp_stop_bit */
    if (bs_read_u1(&aux) == 1) return 1;
  }

  /* All following bits were 0, it was the rsbp_stop_bit */
  return 0;

}
aizvorski commented 10 years ago

Thank you. Fixed per your suggestion: https://github.com/aizvorski/h264bitstream/commit/3e3ad236f8fc506555a8d3e70f9415f87d96a512