提交 41f55277 编写于 作者: M Michael Niedermayer

Merge remote-tracking branch 'qatar/master'

* qatar/master: (34 commits)
  h264: reset h->ref_count in case of errors in ff_h264_decode_ref_pic_list_reordering()
  error_resilience: fix the check for missing references in ff_er_frame_end() for H264
  4xm: prevent NULL dereference with invalid huffman table
  4xmdemux: prevent use of uninitialized memory
  4xm: clear FF_INPUT_BUFFER_PADDING_SIZE bytes in temporary buffers
  ptx: check for out of bound reads
  tiffdec: fix out of bound reads/writes
  eacmv: check for out of bound reads
  eacmv: fix potential pointer arithmetic overflows
  adpcm: fix out of bound reads due to integer overflow
  anm: prevent infinite loop
  avsdemux: check for out of bound writes
  avs: check for out of bound reads
  avsdemux: check for corrupted data
  AVOptions: refactor set_number/write_number
  AVOptions: cosmetics, rename static av_set_number2() to write_number().
  AVOptions: cosmetics, move and rename static av_set_number().
  AVOptions: split av_set_string3 into opt type-specific functions
  avidec: fix signed overflow in avi_sync()
  mxfdec: Fix some buffer overreads caused by the misuse of AVPacket related functions.
  ...

Conflicts:
	Changelog
	configure
	libavcodec/ptx.c
	libavcodec/ra144.c
	libavcodec/vaapi_vc1.c
	libavcodec/vc1.c
	libavcodec/version.h
	libavformat/4xm.c
	libavformat/avidec.c
Merged-by: NMichael Niedermayer <michaelni@gmx.at>
......@@ -62,6 +62,7 @@ easier to use. The changes are:
- CELT in Ogg demuxing
- G.723.1 demuxer and decoder
- libmodplug support (--enable-libmodplug)
- VC-1 interlaced decoding
version 0.8:
......
......@@ -3163,6 +3163,7 @@ check_cflags -Wtype-limits
check_cflags -Wundef
check_cflags -Wmissing-prototypes
check_cflags -Wno-pointer-to-int-cast
check_cflags -Wstrict-prototypes
enabled extra_warnings && check_cflags -Winline
# add some linker flags
......
......@@ -60,7 +60,6 @@ static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
avctx->pix_fmt = PIX_FMT_RGB555;
if (buf_end - buf < offset)
return AVERROR_INVALIDDATA;
if (offset != 0x2c)
......
......@@ -1544,22 +1544,22 @@ void ff_copy_and_dup(int16_t *target, const int16_t *source, int offset)
int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx)
{
int b, i, j;
int buffer1[10];
int buffer2[10];
int buffer1[LPC_ORDER];
int buffer2[LPC_ORDER];
int *bp1 = buffer1;
int *bp2 = buffer2;
for (i=0; i < 10; i++)
for (i=0; i < LPC_ORDER; i++)
buffer2[i] = coefs[i];
refl[9] = bp2[9];
refl[LPC_ORDER-1] = bp2[LPC_ORDER-1];
if ((unsigned) bp2[9] + 0x1000 > 0x1fff) {
if ((unsigned) bp2[LPC_ORDER-1] + 0x1000 > 0x1fff) {
av_log(avctx, AV_LOG_ERROR, "Overflow. Broken sample?\n");
return 1;
}
for (i=8; i >= 0; i--) {
for (i = LPC_ORDER-2; i >= 0; i--) {
b = 0x1000-((bp2[i+1] * bp2[i+1]) >> 12);
if (!b)
......@@ -1584,12 +1584,12 @@ int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx)
*/
void ff_eval_coefs(int *coefs, const int *refl)
{
int buffer[10];
int buffer[LPC_ORDER];
int *b1 = buffer;
int *b2 = coefs;
int i, j;
for (i=0; i < 10; i++) {
for (i=0; i < LPC_ORDER; i++) {
b1[i] = refl[i] << 4;
for (j=0; j < i; j++)
......@@ -1598,7 +1598,7 @@ void ff_eval_coefs(int *coefs, const int *refl)
FFSWAP(int *, b1, b2);
}
for (i=0; i < 10; i++)
for (i=0; i < LPC_ORDER; i++)
coefs[i] >>= 4;
}
......@@ -1606,7 +1606,7 @@ void ff_int_to_int16(int16_t *out, const int *inp)
{
int i;
for (i=0; i < 10; i++)
for (i = 0; i < LPC_ORDER; i++)
*out++ = *inp++;
}
......@@ -1629,9 +1629,9 @@ unsigned int ff_rms(const int *data)
{
int i;
unsigned int res = 0x10000;
int b = 10;
int b = LPC_ORDER;
for (i=0; i < 10; i++) {
for (i = 0; i < LPC_ORDER; i++) {
res = (((0x1000000 - data[i]*data[i]) >> 12) * res) >> 12;
if (res == 0)
......@@ -1648,13 +1648,13 @@ unsigned int ff_rms(const int *data)
int ff_interp(RA144Context *ractx, int16_t *out, int a, int copyold, int energy)
{
int work[10];
int work[LPC_ORDER];
int b = NBLOCKS - a;
int i;
// Interpolate block coefficients from the this frame's forth block and
// last frame's forth block.
for (i=0; i<10; i++)
for (i = 0; i < LPC_ORDER; i++)
out[i] = (a * ractx->lpc_coef[0][i] + b * ractx->lpc_coef[1][i])>> 2;
if (ff_eval_refl(work, out, ractx->avctx)) {
......@@ -1690,7 +1690,7 @@ void ff_subblock_synthesis(RA144Context *ractx, const uint16_t *lpc_coefs,
int cba_idx, int cb1_idx, int cb2_idx,
int gval, int gain)
{
uint16_t buffer_a[40];
uint16_t buffer_a[BLOCKSIZE];
uint16_t *block;
int m[3];
......@@ -1711,10 +1711,10 @@ void ff_subblock_synthesis(RA144Context *ractx, const uint16_t *lpc_coefs,
ff_add_wav(block, gain, cba_idx, m, cba_idx? buffer_a: NULL,
ff_cb1_vects[cb1_idx], ff_cb2_vects[cb2_idx]);
memcpy(ractx->curr_sblock, ractx->curr_sblock + 40,
10*sizeof(*ractx->curr_sblock));
memcpy(ractx->curr_sblock, ractx->curr_sblock + BLOCKSIZE,
LPC_ORDER*sizeof(*ractx->curr_sblock));
if (ff_celp_lp_synthesis_filter(ractx->curr_sblock + 10, lpc_coefs,
block, BLOCKSIZE, 10, 1, 0, 0xfff))
memset(ractx->curr_sblock, 0, 50*sizeof(*ractx->curr_sblock));
if (ff_celp_lp_synthesis_filter(ractx->curr_sblock + LPC_ORDER, lpc_coefs,
block, BLOCKSIZE, LPC_ORDER, 1, 0, 0xfff))
memset(ractx->curr_sblock, 0, (LPC_ORDER+BLOCKSIZE)*sizeof(*ractx->curr_sblock));
}
......@@ -59,29 +59,33 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *vdata,
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
unsigned int refl_rms[4]; // RMS of the reflection coefficients
uint16_t block_coefs[4][10]; // LPC coefficients of each sub-block
unsigned int lpc_refl[10]; // LPC reflection coefficients of the frame
static const uint8_t sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
unsigned int refl_rms[NBLOCKS]; // RMS of the reflection coefficients
uint16_t block_coefs[NBLOCKS][LPC_ORDER]; // LPC coefficients of each sub-block
unsigned int lpc_refl[LPC_ORDER]; // LPC reflection coefficients of the frame
int i, j;
int out_size;
int16_t *data = vdata;
unsigned int energy;
RA144Context *ractx = avctx->priv_data;
GetBitContext gb;
if (*data_size < 2*160)
return -1;
out_size = NBLOCKS * BLOCKSIZE * av_get_bytes_per_sample(avctx->sample_fmt);
if (*data_size < out_size) {
av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
return AVERROR(EINVAL);
}
if(buf_size < 20) {
if(buf_size < FRAMESIZE) {
av_log(avctx, AV_LOG_ERROR,
"Frame too small (%d bytes). Truncated file?\n", buf_size);
*data_size = 0;
return buf_size;
}
init_get_bits(&gb, buf, 20 * 8);
init_get_bits(&gb, buf, FRAMESIZE * 8);
for (i=0; i<10; i++)
for (i = 0; i < LPC_ORDER; i++)
lpc_refl[i] = ff_lpc_refl_cb[i][get_bits(&gb, sizes[i])];
ff_eval_coefs(ractx->lpc_coef[0], lpc_refl);
......@@ -98,7 +102,7 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *vdata,
ff_int_to_int16(block_coefs[3], ractx->lpc_coef[0]);
for (i=0; i < 4; i++) {
for (i=0; i < NBLOCKS; i++) {
do_output_subblock(ractx, block_coefs[i], refl_rms[i], &gb);
for (j=0; j < BLOCKSIZE; j++)
......@@ -110,8 +114,8 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *vdata,
FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);
*data_size = 2*160;
return 20;
*data_size = out_size;
return FRAMESIZE;
}
AVCodec ff_ra_144_decoder = {
......
......@@ -31,6 +31,9 @@
#define MAX_BACKWARD_FILTER_LEN 40
#define MAX_BACKWARD_FILTER_NONREC 35
#define RA288_BLOCK_SIZE 5
#define RA288_BLOCKS_PER_FRAME 32
typedef struct {
float sp_lpc[36]; ///< LPC coefficients for speech data (spec: A)
float gain_lpc[10]; ///< LPC coefficients for gain (spec: GB)
......@@ -165,7 +168,7 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
float *out = data;
int i, j;
int i, j, out_size;
RA288Context *ractx = avctx->priv_data;
GetBitContext gb;
......@@ -176,18 +179,22 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data,
return 0;
}
if (*data_size < 32*5*4)
return -1;
out_size = RA288_BLOCK_SIZE * RA288_BLOCKS_PER_FRAME *
av_get_bytes_per_sample(avctx->sample_fmt);
if (*data_size < out_size) {
av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
return AVERROR(EINVAL);
}
init_get_bits(&gb, buf, avctx->block_align * 8);
for (i=0; i < 32; i++) {
for (i=0; i < RA288_BLOCKS_PER_FRAME; i++) {
float gain = amptable[get_bits(&gb, 3)];
int cb_coef = get_bits(&gb, 6 + (i&1));
decode(ractx, gain, cb_coef);
for (j=0; j < 5; j++)
for (j=0; j < RA288_BLOCK_SIZE; j++)
*(out++) = ractx->sp_hist[70 + 36 + j];
if ((i & 7) == 3) {
......@@ -199,7 +206,7 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data,
}
}
*data_size = (char *)out - (char *)data;
*data_size = out_size;
return avctx->block_align;
}
......
此差异已折叠。
......@@ -105,12 +105,25 @@ enum MVModes {
};
//@}
/** MBMODE for interlaced frame P-picture */
//@{
enum MBModesIntfr {
MV_PMODE_INTFR_1MV,
MV_PMODE_INTFR_2MV_FIELD,
MV_PMODE_INTFR_2MV,
MV_PMODE_INTFR_4MV_FIELD,
MV_PMODE_INTFR_4MV,
MV_PMODE_INTFR_INTRA,
};
//@}
/** @name MV types for B frames */
//@{
enum BMVTypes {
BMV_TYPE_BACKWARD,
BMV_TYPE_FORWARD,
BMV_TYPE_INTERPOLATED
BMV_TYPE_INTERPOLATED,
BMV_TYPE_DIRECT
};
//@}
......@@ -260,16 +273,18 @@ typedef struct VC1Context{
* -# 2 -> [-512, 511.f] x [-128, 127.f]
* -# 3 -> [-1024, 1023.f] x [-256, 255.f]
*/
uint8_t mvrange;
uint8_t mvrange; ///< Extended MV range flag
uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
VLC *cbpcy_vlc; ///< CBPCY VLC table
int tt_index; ///< Index for Transform Type tables
int tt_index; ///< Index for Transform Type tables (to decode TTMB)
uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs
uint8_t* forward_mb_plane; ///< bitplane for "forward" MBs
int mv_type_is_raw; ///< mv type mb plane is not coded
int dmb_is_raw; ///< direct mb plane is raw
int fmb_is_raw; ///< forward mb plane is raw
int skip_is_raw; ///< skip mb plane is not coded
uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation
uint8_t luty[256], lutuv[256];///< lookup tables used for intensity compensation
int use_ic; ///< use intensity compensation in B-frames
int rnd; ///< rounding control
......@@ -307,6 +322,44 @@ typedef struct VC1Context{
uint8_t range_mapuv;
//@}
/** Frame decoding info for interlaced picture */
uint8_t dmvrange; ///< Extended differential MV range flag
int fourmvswitch;
int intcomp;
uint8_t lumscale2; ///< for interlaced field P picture
uint8_t lumshift2;
uint8_t luty2[256], lutuv2[256]; // lookup tables used for intensity compensation
VLC* mbmode_vlc;
VLC* imv_vlc;
VLC* twomvbp_vlc;
VLC* fourmvbp_vlc;
uint8_t twomvbp;
uint8_t fourmvbp;
uint8_t* fieldtx_plane;
int fieldtx_is_raw;
int8_t zzi_8x8[64];
uint8_t *blk_mv_type_base, *blk_mv_type; ///< 0: frame MV, 1: field MV (interlaced frame)
uint8_t *mv_f_base, *mv_f[2]; ///< 0: MV obtained from same field, 1: opposite field
uint8_t *mv_f_last_base, *mv_f_last[2];
uint8_t *mv_f_next_base, *mv_f_next[2];
int field_mode; ///< 1 for interlaced field pictures
int fptype;
int second_field;
int refdist; ///< distance of the current picture from reference
int numref; ///< number of past field pictures used as reference
// 0 corresponds to 1 and 1 corresponds to 2 references
int reffield; ///< if numref = 0 (1 reference) then reffield decides which
// field to use among the two fields from previous frame
int intcompfield; ///< which of the two fields to be intensity compensated
// 0: both fields, 1: bottom field, 2: top field
int cur_field_type; ///< 0: top, 1: bottom
int ref_field_type[2]; ///< forward and backward reference field type (top or bottom)
int blocks_off, mb_off;
int qs_last; ///< if qpel has been used in the previous (tr.) picture
int bmvtype;
int frfd, brfd; ///< reference frame distance (forward or backward)
int pic_header_flag;
/** Frame decoding info for sprite modes */
//@{
int new_sprite;
......
此差异已折叠。
......@@ -44,6 +44,9 @@ extern const uint8_t ff_vc1_mv_pmode_table2[2][4];
extern const int ff_vc1_fps_nr[5], ff_vc1_fps_dr[2];
extern const uint8_t ff_vc1_pquant_table[3][32];
/* MBMODE table for interlaced frame P-picture */
extern const uint8_t ff_vc1_mbmode_intfrp[2][15][4];
/** @name VC-1 VLC tables and defines
* @todo TODO move this into the context
*/
......@@ -63,14 +66,32 @@ extern VLC ff_vc1_ttmb_vlc[3];
extern VLC ff_vc1_mv_diff_vlc[4];
#define VC1_CBPCY_P_VLC_BITS 9 //14
extern VLC ff_vc1_cbpcy_p_vlc[4];
#define VC1_ICBPCY_VLC_BITS 9
extern VLC ff_vc1_icbpcy_vlc[8];
#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6
extern VLC ff_vc1_4mv_block_pattern_vlc[4];
#define VC1_2MV_BLOCK_PATTERN_VLC_BITS 3
extern VLC ff_vc1_2mv_block_pattern_vlc[4];
#define VC1_TTBLK_VLC_BITS 5
extern VLC ff_vc1_ttblk_vlc[3];
#define VC1_SUBBLKPAT_VLC_BITS 6
extern VLC ff_vc1_subblkpat_vlc[3];
#define VC1_INTFR_4MV_MBMODE_VLC_BITS 9
extern VLC ff_vc1_intfr_4mv_mbmode_vlc[4];
#define VC1_INTFR_NON4MV_MBMODE_VLC_BITS 6
extern VLC ff_vc1_intfr_non4mv_mbmode_vlc[4];
#define VC1_IF_MMV_MBMODE_VLC_BITS 5
extern VLC ff_vc1_if_mmv_mbmode_vlc[8];
#define VC1_IF_1MV_MBMODE_VLC_BITS 5
extern VLC ff_vc1_if_1mv_mbmode_vlc[8];
#define VC1_1REF_MVDATA_VLC_BITS 9
extern VLC ff_vc1_1ref_mvdata_vlc[4];
#define VC1_2REF_MVDATA_VLC_BITS 9
extern VLC ff_vc1_2ref_mvdata_vlc[8];
extern VLC ff_vc1_ac_coeff_table[8];
#define VC1_IF_MBMODE_VLC_BITS 5
//@}
......@@ -101,12 +122,20 @@ extern const uint8_t ff_vc1_norm6_spec[64][5];
extern const uint8_t ff_vc1_4mv_block_pattern_codes[4][16];
extern const uint8_t ff_vc1_4mv_block_pattern_bits[4][16];
/* 2MV Block pattern VLC tables */
extern const uint8_t ff_vc1_2mv_block_pattern_codes[4][4];
extern const uint8_t ff_vc1_2mv_block_pattern_bits[4][4];
extern const uint8_t wmv3_dc_scale_table[32];
/* P-Picture CBPCY VLC tables */
extern const uint16_t ff_vc1_cbpcy_p_codes[4][64];
extern const uint8_t ff_vc1_cbpcy_p_bits[4][64];
/* Interlaced CBPCY VLC tables (Table 124 - Table 131) */
extern const uint16_t ff_vc1_icbpcy_p_codes[8][63];
extern const uint8_t ff_vc1_icbpcy_p_bits[8][63];
/* MacroBlock Transform Type: 7.1.3.11, p89
* 8x8:B
* 8x4:B:btm 8x4:B:top 8x4:B:both,
......@@ -131,6 +160,26 @@ extern const uint8_t ff_vc1_subblkpat_bits[3][15];
extern const uint16_t ff_vc1_mv_diff_codes[4][73];
extern const uint8_t ff_vc1_mv_diff_bits[4][73];
/* Interlaced frame picture MBMODE VLC tables (p. 246, p. 360) */
extern const uint16_t ff_vc1_intfr_4mv_mbmode_codes[4][15];
extern const uint8_t ff_vc1_intfr_4mv_mbmode_bits[4][15];
extern const uint8_t ff_vc1_intfr_non4mv_mbmode_codes[4][9];
extern const uint8_t ff_vc1_intfr_non4mv_mbmode_bits[4][9];
/* Interlaced field picture MBMODE VLC tables (p. 356 - 11.4.1, 11.4.2) */
extern const uint8_t ff_vc1_if_mmv_mbmode_codes[8][8];
extern const uint8_t ff_vc1_if_mmv_mbmode_bits[8][8];
extern const uint8_t ff_vc1_if_1mv_mbmode_codes[8][6];
extern const uint8_t ff_vc1_if_1mv_mbmode_bits[8][6];
/* Interlaced frame/field picture MVDATA VLC tables */
/* 1-reference tables */
extern const uint32_t ff_vc1_1ref_mvdata_codes[4][72];
extern const uint8_t ff_vc1_1ref_mvdata_bits[4][72];
/* 2-reference tables */
extern const uint32_t ff_vc1_2ref_mvdata_codes[8][126];
extern const uint8_t ff_vc1_2ref_mvdata_bits[8][126];
/* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */
/* Scantables/ZZ scan are at 11.9 (p262) and 8.1.1.12 (p10) */
......@@ -141,8 +190,14 @@ extern const int8_t ff_vc1_adv_interlaced_8x8_zz [64];
extern const int8_t ff_vc1_adv_interlaced_8x4_zz [32];
extern const int8_t ff_vc1_adv_interlaced_4x8_zz [32];
extern const int8_t ff_vc1_adv_interlaced_4x4_zz [16];
extern const int8_t ff_vc1_intra_horz_8x8_zz [64];
extern const int8_t ff_vc1_intra_vert_8x8_zz [64];
/* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */
extern const int32_t ff_vc1_dqscale[63];
/* P Interlaced field picture MV predictor scaling values (Table 114) */
extern const uint16_t vc1_field_mvpred_scales[2][7][4];
/* B Interlaced field picture backward MV predictor scaling values for first field (Table 115) */
extern const uint16_t vc1_b_field_mvpred_scales[7][4];
#endif /* AVCODEC_VC1DATA_H */
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册