From 89d474eeed64e139e31b68311ff173905142301f Mon Sep 17 00:00:00 2001 From: Julian Scheel Date: Fri, 9 Apr 2010 18:55:47 +0200 Subject: skip stuffing bytes properly skip the emulation_prevention_three_byte in the bitstream, which fixes some glitches which could happen whenever such a stuffing byte was in one of the parsed sections --- src/video_dec/libvdpau/h264_parser.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/video_dec/libvdpau/h264_parser.c b/src/video_dec/libvdpau/h264_parser.c index bb010a342..75e065c12 100644 --- a/src/video_dec/libvdpau/h264_parser.c +++ b/src/video_dec/libvdpau/h264_parser.c @@ -157,6 +157,17 @@ static inline uint32_t bits_read(struct buf_reader *buf) return bits_read; } +/* skips stuffing bytes in the buf_reader */ +static inline void skip_emulation_prevention_three_byte(struct buf_reader *buf) +{ + if(buf->cur_pos - buf->buf > 2 && + *(buf->cur_pos-2) == 0x00 && + *(buf->cur_pos-1) == 0x00 && + *buf->cur_pos == 0x03) { + buf->cur_pos++; + } +} + /* * read len bits from the buffer and return them * @return right aligned bits @@ -179,6 +190,8 @@ static inline uint32_t read_bits(struct buf_reader *buf, int len) if (buf->cur_offset == 0) { buf->cur_pos++; buf->cur_offset = 8; + + skip_emulation_prevention_three_byte(buf); } return bits; } @@ -187,6 +200,8 @@ static inline uint32_t read_bits(struct buf_reader *buf, int len) len -= buf->cur_offset; buf->cur_pos++; buf->cur_offset = 8; + + skip_emulation_prevention_three_byte(buf); } } return bits; @@ -259,11 +274,7 @@ struct nal_unit* parse_nal_header(struct buf_reader *buf, switch (nal->nal_unit_type) { case NAL_SPS: - decode_nal(&ibuf.buf, &ibuf.len, buf->cur_pos, buf->len - 1); - ibuf.cur_pos = ibuf.buf; - - parse_sps(&ibuf, &nal->sps); - free(ibuf.buf); + parse_sps(buf, &nal->sps); break; case NAL_PPS: parse_pps(buf, &nal->pps); -- cgit v1.2.3