diff options
Diffstat (limited to 'libavcodec/ituh263dec.c')
-rw-r--r-- | libavcodec/ituh263dec.c | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c index f062b246b4..ec9a4c4257 100644 --- a/libavcodec/ituh263dec.c +++ b/libavcodec/ituh263dec.c @@ -5,20 +5,20 @@ * Copyright (c) 2001 Juan J. Sierralta P * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -27,6 +27,8 @@ * h263 decoder. */ +#define UNCHECKED_BITSTREAM_READER 1 + //#define DEBUG #include <limits.h> @@ -40,9 +42,6 @@ #include "flv.h" #include "mpeg4video.h" -//#undef NDEBUG -//#include <assert.h> - // The defines below define the number of bits that are read at once for // reading vlc values. Changing these may improve speed and data cache needs // be aware though that decreasing them may need the number of stages that is @@ -103,11 +102,9 @@ static VLC cbpc_b_vlc; /* XXX: find a better solution to handle static init */ void ff_h263_decode_init_vlc(MpegEncContext *s) { - static int done = 0; + static volatile int done = 0; if (!done) { - done = 1; - INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, ff_h263_intra_MCBPC_bits, 1, 1, ff_h263_intra_MCBPC_code, 1, 1, 72); @@ -130,6 +127,7 @@ void ff_h263_decode_init_vlc(MpegEncContext *s) INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4, &ff_cbpc_b_tab[0][1], 2, 1, &ff_cbpc_b_tab[0][0], 2, 1, 8); + done = 1; } } @@ -208,16 +206,19 @@ static int h263_decode_gob_header(MpegEncContext *s) * @param end pointer to the end of the buffer * @return pointer to the next resync_marker, or end if none was found */ -const uint8_t *ff_h263_find_resync_marker(const uint8_t *restrict p, const uint8_t * restrict end) +const uint8_t *ff_h263_find_resync_marker(MpegEncContext *s, const uint8_t *av_restrict p, const uint8_t *av_restrict end) { - assert(p < end); + av_assert2(p < end); end-=2; p++; - for(;p<end; p+=2){ - if(!*p){ - if (!p[-1] && p[1]) return p - 1; - else if(!p[ 1] && p[2]) return p; + if(s->resync_marker){ + int prefix_len = ff_mpeg4_get_video_packet_prefix_length(s); + for(;p<end; p+=2){ + if(!*p){ + if (!p[-1] && ((p[1] >> (23-prefix_len)) == 1)) return p - 1; + else if (!p[ 1] && ((p[2] >> (23-prefix_len)) == 1)) return p; + } } } return end+2; @@ -347,7 +348,7 @@ static void preview_obmc(MpegEncContext *s){ s->block_index[i]+= 1; s->mb_x++; - assert(s->pict_type == AV_PICTURE_TYPE_P); + av_assert2(s->pict_type == AV_PICTURE_TYPE_P); do{ if (get_bits1(&s->gb)) { @@ -484,7 +485,7 @@ static int h263_decode_block(MpegEncContext * s, int16_t * block, level = get_bits(&s->gb, 8); if((level&0x7F) == 0){ av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); - if(s->err_recognition & AV_EF_BITSTREAM) + if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) return -1; } if (level == 255) @@ -565,11 +566,13 @@ static int h263_skip_b_part(MpegEncContext *s, int cbp) { LOCAL_ALIGNED_16(int16_t, dblock, [64]); int i, mbi; + int bli[6]; /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly * but real value should be restored in order to be used later (in OBMC condition) */ mbi = s->mb_intra; + memcpy(bli, s->block_last_index, sizeof(bli)); s->mb_intra = 0; for (i = 0; i < 6; i++) { if (h263_decode_block(s, dblock, i, cbp&32) < 0) @@ -577,6 +580,7 @@ static int h263_skip_b_part(MpegEncContext *s, int cbp) cbp+=cbp; } s->mb_intra = mbi; + memcpy(s->block_last_index, bli, sizeof(bli)); return 0; } @@ -606,7 +610,7 @@ int ff_h263_decode_mb(MpegEncContext *s, const int xy= s->mb_x + s->mb_y * s->mb_stride; int cbpb = 0, pb_mv_count = 0; - assert(!s->h263_pred); + av_assert2(!s->h263_pred); if (s->pict_type == AV_PICTURE_TYPE_P) { do{ @@ -746,7 +750,7 @@ int ff_h263_decode_mb(MpegEncContext *s, }else cbp=0; - assert(!s->mb_intra); + av_assert2(!s->mb_intra); if(IS_QUANT(mb_type)){ h263_decode_dquant(s); @@ -961,6 +965,8 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */ s->loop_filter= get_bits1(&s->gb); s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter; + if(s->avctx->lowres) + s->loop_filter = 0; s->h263_slice_structured= get_bits1(&s->gb); if (get_bits1(&s->gb) != 0) { @@ -1072,6 +1078,10 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if (s->width == 0 || s->height == 0) { + av_log(s->avctx, AV_LOG_ERROR, "dimensions 0\n"); + return -1; + } s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height; @@ -1128,7 +1138,7 @@ int ff_h263_decode_picture_header(MpegEncContext *s) } ff_h263_show_pict_info(s); - if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO")){ + if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){ int i,j; for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); av_log(s->avctx, AV_LOG_DEBUG, "\n"); |