diff options
Diffstat (limited to 'libavcodec/mpeg12.c')
-rw-r--r-- | libavcodec/mpeg12.c | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index c0c680d..ab6c19c 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -3,20 +3,20 @@ * Copyright (c) 2000, 2001 Fabrice Bellard * 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 */ @@ -25,7 +25,12 @@ * MPEG-1/2 decoder */ +#define UNCHECKED_BITSTREAM_READER 1 + #include "libavutil/attributes.h" +#include "libavutil/avassert.h" +#include "libavutil/timecode.h" + #include "internal.h" #include "avcodec.h" #include "mpegvideo.h" @@ -62,24 +67,17 @@ static const uint8_t table_mb_btype[11][2] = { { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT }; -#define INIT_2D_VLC_RL(rl, static_size)\ -{\ - static RL_VLC_ELEM rl_vlc_table[static_size];\ - INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\ - &rl.table_vlc[0][1], 4, 2,\ - &rl.table_vlc[0][0], 4, 2, static_size);\ -\ - rl.rl_vlc[0] = rl_vlc_table;\ - init_2d_vlc_rl(&rl);\ -} - -static av_cold void init_2d_vlc_rl(RLTable *rl) +av_cold void ff_init_2d_vlc_rl(RLTable *rl, unsigned static_size, int flags) { int i; - - for (i = 0; i < rl->vlc.table_size; i++) { - int code = rl->vlc.table[i][0]; - int len = rl->vlc.table[i][1]; + VLC_TYPE table[680][2] = {{0}}; + VLC vlc = { .table = table, .table_allocated = static_size }; + av_assert0(static_size <= FF_ARRAY_ELEMS(table)); + init_vlc(&vlc, TEX_VLC_BITS, rl->n + 2, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC | flags); + + for (i = 0; i < vlc.table_size; i++) { + int code = vlc.table[i][0]; + int len = vlc.table[i][1]; int level, run; if (len == 0) { // illegal code @@ -168,8 +166,8 @@ av_cold void ff_mpeg12_init_vlcs(void) ff_rl_init(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]); ff_rl_init(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]); - INIT_2D_VLC_RL(ff_rl_mpeg1, 680); - INIT_2D_VLC_RL(ff_rl_mpeg2, 674); + INIT_2D_VLC_RL(ff_rl_mpeg1, 680, 0); + INIT_2D_VLC_RL(ff_rl_mpeg2, 674, 0); } } @@ -195,7 +193,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, */ for (i = 0; i < buf_size; i++) { - assert(pc->frame_start_found >= 0 && pc->frame_start_found <= 4); + av_assert1(pc->frame_start_found >= 0 && pc->frame_start_found <= 4); if (pc->frame_start_found & 1) { if (state == EXT_START_CODE && (buf[i] & 0xF0) != 0x80) pc->frame_start_found--; @@ -229,7 +227,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, } } if (pc->frame_start_found == 0 && s && state == PICTURE_START_CODE) { - ff_fetch_timestamp(s, i - 3, 1); + ff_fetch_timestamp(s, i - 3, 1, i > 3); } } } @@ -262,16 +260,18 @@ int ff_mpeg1_decode_block_intra(GetBitContext *gb, { OPEN_READER(re, gb); + UPDATE_CACHE(re, gb); + if (((int32_t)GET_CACHE(re, gb)) <= (int32_t)0xBFFFFFFF) + goto end; + /* now quantify & encode AC coefficients */ while (1) { int level, run, j; - UPDATE_CACHE(re, gb); - GET_RL_VLC(level, run, re, gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); + GET_RL_VLC(level, run, re, gb, rl->rl_vlc[0], + TEX_VLC_BITS, 2, 0); - if (level == 127) { - break; - } else if (level != 0) { + if (level != 0) { i += run; if (i > MAX_INDEX) break; @@ -281,7 +281,7 @@ int ff_mpeg1_decode_block_intra(GetBitContext *gb, level = (level - 1) | 1; level = (level ^ SHOW_SBITS(re, gb, 1)) - SHOW_SBITS(re, gb, 1); - LAST_SKIP_BITS(re, gb, 1); + SKIP_BITS(re, gb, 1); } else { /* escape */ run = SHOW_UBITS(re, gb, 6) + 1; @@ -292,10 +292,10 @@ int ff_mpeg1_decode_block_intra(GetBitContext *gb, if (level == -128) { level = SHOW_UBITS(re, gb, 8) - 256; - LAST_SKIP_BITS(re, gb, 8); + SKIP_BITS(re, gb, 8); } else if (level == 0) { level = SHOW_UBITS(re, gb, 8); - LAST_SKIP_BITS(re, gb, 8); + SKIP_BITS(re, gb, 8); } i += run; @@ -315,7 +315,13 @@ int ff_mpeg1_decode_block_intra(GetBitContext *gb, } block[j] = level; + if (((int32_t)GET_CACHE(re, gb)) <= (int32_t)0xBFFFFFFF) + break; + + UPDATE_CACHE(re, gb); } +end: + LAST_SKIP_BITS(re, gb, 2); CLOSE_READER(re, gb); } |