From f8b1245922cf4c7692750e9198cf57598f9647d5 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 27 Apr 2011 15:42:16 -0700 Subject: [PATCH 01/23] asfdec: fix parsing of packets that overrun into padding. Signed-off-by: Ronald S. Bultje --- libavformat/asfdec.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c index 8e10d68b62..637ceed34a 100644 --- a/libavformat/asfdec.c +++ b/libavformat/asfdec.c @@ -853,8 +853,14 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){ if (asf->packet_flags & 0x01) { DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal if(asf->packet_frag_size > asf->packet_size_left - rsize){ - av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid\n"); - return -1; + if (asf->packet_frag_size > asf->packet_size_left - rsize + asf->packet_padsize) { + av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid (%d-%d)\n", asf->packet_size_left, rsize); + return -1; + } else { + int diff = asf->packet_frag_size - (asf->packet_size_left - rsize); + asf->packet_size_left += diff; + asf->packet_padsize -= diff; + } } //printf("Fragsize %d\n", asf->packet_frag_size); } else { From fb22c237152ea62f51b8e1c96a782bae4c8709c1 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 27 Apr 2011 08:28:51 -0700 Subject: [PATCH 02/23] mpegvideo: don't av_malloc(0). --- libavcodec/mpegvideo.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 5b400b6a4a..6ccc50f4f3 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -520,6 +520,8 @@ av_cold int MPV_common_init(MpegEncContext *s) s->flags= s->avctx->flags; s->flags2= s->avctx->flags2; + if (s->width && s->height) { + s->mb_width = (s->width + 15) / 16; s->mb_stride = s->mb_width + 1; s->b8_stride = s->mb_width*2 + 1; @@ -599,11 +601,16 @@ av_cold int MPV_common_init(MpegEncContext *s) FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail) } } + + } + FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, MAX_PICTURE_COUNT * sizeof(Picture), fail) for(i = 0; i < MAX_PICTURE_COUNT; i++) { avcodec_get_frame_defaults((AVFrame *)&s->picture[i]); } + if (s->width && s->height) { + FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail) if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){ @@ -658,9 +665,12 @@ av_cold int MPV_common_init(MpegEncContext *s) s->visualization_buffer[1] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); s->visualization_buffer[2] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); } + } s->context_initialized = 1; + if (s->width && s->height) { + s->thread_context[0]= s; threads = s->avctx->thread_count; @@ -676,6 +686,8 @@ av_cold int MPV_common_init(MpegEncContext *s) s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count; } + } + return 0; fail: MPV_common_end(s); From 25588d3b8a556eb5d0d3239d8c6aee968ea18896 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 27 Apr 2011 08:29:02 -0700 Subject: [PATCH 03/23] nutenc: don't av_malloc(0). --- libavformat/nutenc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index df5dc6fdf7..4ca761ab40 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -584,7 +584,8 @@ static int write_header(AVFormatContext *s){ nut->avf= s; nut->stream = av_mallocz(sizeof(StreamContext)*s->nb_streams); - nut->chapter = av_mallocz(sizeof(ChapterContext)*s->nb_chapters); + if (s->nb_chapters) + nut->chapter = av_mallocz(sizeof(ChapterContext)*s->nb_chapters); nut->time_base= av_mallocz(sizeof(AVRational )*(s->nb_streams + s->nb_chapters)); From f8af93ab99a132c268e4ce83736762555e928b96 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 27 Apr 2011 08:29:09 -0700 Subject: [PATCH 04/23] avfilter: don't av_malloc(0). --- libavfilter/avfilter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 135b9ff0a2..c71c046c53 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -587,7 +587,8 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in ret->av_class = &avfilter_class; ret->filter = filter; ret->name = inst_name ? av_strdup(inst_name) : NULL; - ret->priv = av_mallocz(filter->priv_size); + if (filter->priv_size) + ret->priv = av_mallocz(filter->priv_size); ret->input_count = pad_count(filter->inputs); if (ret->input_count) { From 76432655056b9c1477ade550e4b6d277556eb6b2 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Tue, 3 May 2011 08:19:42 -0400 Subject: [PATCH 05/23] nutenc: check malloc return values. --- libavformat/nutenc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 4ca761ab40..85340b158e 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -588,6 +588,12 @@ static int write_header(AVFormatContext *s){ nut->chapter = av_mallocz(sizeof(ChapterContext)*s->nb_chapters); nut->time_base= av_mallocz(sizeof(AVRational )*(s->nb_streams + s->nb_chapters)); + if (!nut->stream || (s->nb_chapters && !nut->chapter) || !nut->time_base) { + av_freep(&nut->stream); + av_freep(&nut->chapter); + av_freep(&nut->time_base); + return AVERROR(ENOMEM); + } for(i=0; inb_streams; i++){ AVStream *st= s->streams[i]; From d969e93a72102a4162a1b20ec0b4fe22c69f3ff7 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Tue, 3 May 2011 08:23:41 -0400 Subject: [PATCH 06/23] mpegvideo: reindent. --- libavcodec/mpegvideo.c | 231 ++++++++++++++++++++--------------------- 1 file changed, 113 insertions(+), 118 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 6ccc50f4f3..f4de8dded4 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -521,87 +521,85 @@ av_cold int MPV_common_init(MpegEncContext *s) s->flags2= s->avctx->flags2; if (s->width && s->height) { + s->mb_width = (s->width + 15) / 16; + s->mb_stride = s->mb_width + 1; + s->b8_stride = s->mb_width*2 + 1; + s->b4_stride = s->mb_width*4 + 1; + mb_array_size= s->mb_height * s->mb_stride; + mv_table_size= (s->mb_height+2) * s->mb_stride + 1; - s->mb_width = (s->width + 15) / 16; - s->mb_stride = s->mb_width + 1; - s->b8_stride = s->mb_width*2 + 1; - s->b4_stride = s->mb_width*4 + 1; - mb_array_size= s->mb_height * s->mb_stride; - mv_table_size= (s->mb_height+2) * s->mb_stride + 1; + /* set chroma shifts */ + avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift), + &(s->chroma_y_shift) ); - /* set chroma shifts */ - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift), - &(s->chroma_y_shift) ); + /* set default edge pos, will be overriden in decode_header if needed */ + s->h_edge_pos= s->mb_width*16; + s->v_edge_pos= s->mb_height*16; - /* set default edge pos, will be overriden in decode_header if needed */ - s->h_edge_pos= s->mb_width*16; - s->v_edge_pos= s->mb_height*16; + s->mb_num = s->mb_width * s->mb_height; - s->mb_num = s->mb_width * s->mb_height; + s->block_wrap[0]= + s->block_wrap[1]= + s->block_wrap[2]= + s->block_wrap[3]= s->b8_stride; + s->block_wrap[4]= + s->block_wrap[5]= s->mb_stride; - s->block_wrap[0]= - s->block_wrap[1]= - s->block_wrap[2]= - s->block_wrap[3]= s->b8_stride; - s->block_wrap[4]= - s->block_wrap[5]= s->mb_stride; + y_size = s->b8_stride * (2 * s->mb_height + 1); + c_size = s->mb_stride * (s->mb_height + 1); + yc_size = y_size + 2 * c_size; - y_size = s->b8_stride * (2 * s->mb_height + 1); - c_size = s->mb_stride * (s->mb_height + 1); - yc_size = y_size + 2 * c_size; + /* convert fourcc to upper case */ + s->codec_tag = ff_toupper4(s->avctx->codec_tag); - /* convert fourcc to upper case */ - s->codec_tag = ff_toupper4(s->avctx->codec_tag); + s->stream_codec_tag = ff_toupper4(s->avctx->stream_codec_tag); - s->stream_codec_tag = ff_toupper4(s->avctx->stream_codec_tag); + s->avctx->coded_frame= (AVFrame*)&s->current_picture; - s->avctx->coded_frame= (AVFrame*)&s->current_picture; - - FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num+1)*sizeof(int), fail) //error ressilience code looks cleaner with this - for(y=0; ymb_height; y++){ - for(x=0; xmb_width; x++){ - s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride; + FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num+1)*sizeof(int), fail) //error ressilience code looks cleaner with this + for(y=0; ymb_height; y++){ + for(x=0; xmb_width; x++){ + s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride; + } } - } - s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed? + s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed? - if (s->encoding) { - /* Allocate MV tables */ - FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) - s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1; - s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; - s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; - s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1; - s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1; - s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; + if (s->encoding) { + /* Allocate MV tables */ + FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) + s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1; + s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; + s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; + s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1; + s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1; + s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; - if(s->msmpeg4_version){ - FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int), fail); + if(s->msmpeg4_version){ + FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int), fail); + } + FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail); + + /* Allocate MB type table */ + FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type , mb_array_size * sizeof(uint16_t), fail) //needed for encoding + + FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail) + + FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix , 64*32 * sizeof(int), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix , 64*32 * sizeof(int), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail) + + if(s->avctx->noise_reduction){ + FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail) + } } - FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail); - - /* Allocate MB type table */ - FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type , mb_array_size * sizeof(uint16_t), fail) //needed for encoding - - FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail) - - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix , 64*32 * sizeof(int), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix , 64*32 * sizeof(int), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail) - - if(s->avctx->noise_reduction){ - FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail) - } - } - } FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, MAX_PICTURE_COUNT * sizeof(Picture), fail) @@ -610,11 +608,10 @@ av_cold int MPV_common_init(MpegEncContext *s) } if (s->width && s->height) { + FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail) - - if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){ - /* interlaced direct mode decoding tables */ + if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){ + /* interlaced direct mode decoding tables */ for(i=0; i<2; i++){ int j, k; for(j=0; j<2; j++){ @@ -628,64 +625,62 @@ av_cold int MPV_common_init(MpegEncContext *s) } FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i], mb_array_size * 2 * sizeof(uint8_t), fail) } - } - if (s->out_format == FMT_H263) { - /* cbp values */ - FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail); - s->coded_block= s->coded_block_base + s->b8_stride + 1; + } + if (s->out_format == FMT_H263) { + /* cbp values */ + FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail); + s->coded_block= s->coded_block_base + s->b8_stride + 1; - /* cbp, ac_pred, pred_dir */ - FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table , mb_array_size * sizeof(uint8_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail) - } + /* cbp, ac_pred, pred_dir */ + FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table , mb_array_size * sizeof(uint8_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail) + } - if (s->h263_pred || s->h263_plus || !s->encoding) { - /* dc values */ - //MN: we need these for error resilience of intra-frames - FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail); - s->dc_val[0] = s->dc_val_base + s->b8_stride + 1; - s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; - s->dc_val[2] = s->dc_val[1] + c_size; - for(i=0;idc_val_base[i] = 1024; - } + if (s->h263_pred || s->h263_plus || !s->encoding) { + /* dc values */ + //MN: we need these for error resilience of intra-frames + FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail); + s->dc_val[0] = s->dc_val_base + s->b8_stride + 1; + s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; + s->dc_val[2] = s->dc_val[1] + c_size; + for(i=0;idc_val_base[i] = 1024; + } - /* which mb is a intra block */ - FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail); - memset(s->mbintra_table, 1, mb_array_size); + /* which mb is a intra block */ + FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail); + memset(s->mbintra_table, 1, mb_array_size); - /* init macroblock skip table */ - FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size+2, fail); - //Note the +1 is for a quicker mpeg4 slice_end detection - FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail); + /* init macroblock skip table */ + FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size+2, fail); + //Note the +1 is for a quicker mpeg4 slice_end detection + FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail); - s->parse_context.state= -1; - if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ - s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); - s->visualization_buffer[1] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); - s->visualization_buffer[2] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); - } + s->parse_context.state= -1; + if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ + s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); + s->visualization_buffer[1] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); + s->visualization_buffer[2] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); + } } s->context_initialized = 1; if (s->width && s->height) { + s->thread_context[0]= s; + threads = s->avctx->thread_count; - s->thread_context[0]= s; - threads = s->avctx->thread_count; - - for(i=1; ithread_context[i]= av_malloc(sizeof(MpegEncContext)); - memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); - } - - for(i=0; ithread_context[i], s) < 0) - goto fail; - s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count; - s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count; - } + for(i=1; ithread_context[i]= av_malloc(sizeof(MpegEncContext)); + memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); + } + for(i=0; ithread_context[i], s) < 0) + goto fail; + s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count; + s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count; + } } return 0; From 0699dbb8478886826dedb1c33a0b74142a1cd863 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Tue, 3 May 2011 21:25:40 -0400 Subject: [PATCH 07/23] avfilter: check malloc return values. --- libavfilter/avfilter.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index c71c046c53..82350d1790 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -583,29 +583,53 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in return AVERROR(EINVAL); ret = av_mallocz(sizeof(AVFilterContext)); + if (!ret) + return AVERROR(ENOMEM); ret->av_class = &avfilter_class; ret->filter = filter; ret->name = inst_name ? av_strdup(inst_name) : NULL; - if (filter->priv_size) + if (filter->priv_size) { ret->priv = av_mallocz(filter->priv_size); + if (!ret->priv) + goto err; + } ret->input_count = pad_count(filter->inputs); if (ret->input_count) { ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->input_count); + if (!ret->input_pads) + goto err; memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count); ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->input_count); + if (!ret->inputs) + goto err; } ret->output_count = pad_count(filter->outputs); if (ret->output_count) { ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->output_count); + if (!ret->output_pads) + goto err; memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count); ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->output_count); + if (!ret->outputs) + goto err; } *filter_ctx = ret; return 0; + +err: + av_freep(&ret->inputs); + av_freep(&ret->input_pads); + ret->input_count = 0; + av_freep(&ret->outputs); + av_freep(&ret->output_pads); + ret->output_count = 0; + av_freep(&ret->priv); + av_free(ret); + return AVERROR(ENOMEM); } void avfilter_free(AVFilterContext *filter) From 0bd433a916cd8d98fce47742fbf6d0f90ec941c4 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sun, 24 Apr 2011 07:21:30 +0300 Subject: [PATCH 08/23] asfdec: fix assert failure on invalid files Add an extra size validity check in asf_read_frame_header(). Without this asf->packet_size_left may become negative, which triggers an assertion failure later. Signed-off-by: Ronald S. Bultje --- libavformat/asfdec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c index 637ceed34a..77c84490a0 100644 --- a/libavformat/asfdec.c +++ b/libavformat/asfdec.c @@ -864,6 +864,10 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){ } //printf("Fragsize %d\n", asf->packet_frag_size); } else { + if (rsize > asf->packet_size_left) { + av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n"); + return -1; + } asf->packet_frag_size = asf->packet_size_left - rsize; //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize); } From 47bc52f8216d9de3e50160adb929620ac31ede99 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 26 Apr 2011 09:09:05 -0700 Subject: [PATCH 09/23] get_bits: make cache unsigned to eliminate undefined signed overflow. --- libavcodec/get_bits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index 2d36b81397..185ff316bb 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -127,7 +127,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc # define OPEN_READER(name, gb) \ unsigned int name##_index = (gb)->index; \ - int name##_cache = 0 + unsigned int name##_cache = 0 # define CLOSE_READER(name, gb) (gb)->index = name##_index From aab6374bbe2b6ce4ca82141be6a5b7b8875bf051 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Sun, 24 Apr 2011 17:33:37 -0700 Subject: [PATCH 10/23] indeo3: Eliminate use of long. --- libavcodec/indeo3.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libavcodec/indeo3.c b/libavcodec/indeo3.c index 29a8d4ad8c..30b70850f8 100644 --- a/libavcodec/indeo3.c +++ b/libavcodec/indeo3.c @@ -149,13 +149,13 @@ static av_cold void iv_free_func(Indeo3DecodeContext *s) } struct ustr { - long xpos; - long ypos; - long width; - long height; - long split_flag; - long split_direction; - long usl7; + int xpos; + int ypos; + int width; + int height; + int split_flag; + int split_direction; + int usl7; }; @@ -203,12 +203,12 @@ struct ustr { static void iv_Decode_Chunk(Indeo3DecodeContext *s, uint8_t *cur, uint8_t *ref, int width, int height, - const uint8_t *buf1, long cb_offset, const uint8_t *hdr, + const uint8_t *buf1, int cb_offset, const uint8_t *hdr, const uint8_t *buf2, int min_width_160) { uint8_t bit_buf; - unsigned long bit_pos, lv, lv1, lv2; - long *width_tbl, width_tbl_arr[10]; + unsigned int bit_pos, lv, lv1, lv2; + int *width_tbl, width_tbl_arr[10]; const signed char *ref_vectors; uint8_t *cur_frm_pos, *ref_frm_pos, *cp, *cp2; uint32_t *cur_lp, *ref_lp; @@ -982,7 +982,7 @@ static int iv_decode_frame(AVCodecContext *avctx, Indeo3DecodeContext *s = avctx->priv_data; unsigned int image_width, image_height, chroma_width, chroma_height; - unsigned long flags, cb_offset, data_size, + unsigned int flags, cb_offset, data_size, y_offset, v_offset, u_offset, mc_vector_count; const uint8_t *hdr_pos, *buf_pos; From 1a5e4fd8c5b99478b4e08a69261930bb12aa948b Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 3 May 2011 11:19:31 -0700 Subject: [PATCH 11/23] Replace strncpy() with av_strlcpy(). --- ffmpeg.c | 3 +-- libavcodec/ac3enc.c | 43 ++++++++++++++++++++------------------- libavcodec/ass.c | 4 ++-- libavformat/movenc.c | 2 +- libavformat/mp3enc.c | 3 ++- libavutil/log.c | 3 ++- libpostproc/postprocess.c | 3 ++- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index d728f140f0..c5868110f2 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -3695,8 +3695,7 @@ static int opt_streamid(const char *opt, const char *arg) char *p; char idx_str[16]; - strncpy(idx_str, arg, sizeof(idx_str)); - idx_str[sizeof(idx_str)-1] = '\0'; + av_strlcpy(idx_str, arg, sizeof(idx_str)); p = strchr(idx_str, ':'); if (!p) { fprintf(stderr, diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index bf106eb22a..a35ff29d1a 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -33,6 +33,7 @@ #include "libavutil/audioconvert.h" #include "libavutil/avassert.h" +#include "libavutil/avstring.h" #include "libavutil/crc.h" #include "libavutil/opt.h" #include "avcodec.h" @@ -1578,10 +1579,10 @@ static void dprint_options(AVCodecContext *avctx) char strbuf[32]; switch (s->bitstream_id) { - case 6: strncpy(strbuf, "AC-3 (alt syntax)", 32); break; - case 8: strncpy(strbuf, "AC-3 (standard)", 32); break; - case 9: strncpy(strbuf, "AC-3 (dnet half-rate)", 32); break; - case 10: strncpy(strbuf, "AC-3 (dnet quater-rate", 32); break; + case 6: av_strlcpy(strbuf, "AC-3 (alt syntax)", 32); break; + case 8: av_strlcpy(strbuf, "AC-3 (standard)", 32); break; + case 9: av_strlcpy(strbuf, "AC-3 (dnet half-rate)", 32); break; + case 10: av_strlcpy(strbuf, "AC-3 (dnet quater-rate", 32); break; default: snprintf(strbuf, 32, "ERROR"); } av_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id); @@ -1608,9 +1609,9 @@ static void dprint_options(AVCodecContext *avctx) if (opt->audio_production_info) { av_dlog(avctx, "mixing_level: %ddB\n", opt->mixing_level); switch (opt->room_type) { - case 0: strncpy(strbuf, "notindicated", 32); break; - case 1: strncpy(strbuf, "large", 32); break; - case 2: strncpy(strbuf, "small", 32); break; + case 0: av_strlcpy(strbuf, "notindicated", 32); break; + case 1: av_strlcpy(strbuf, "large", 32); break; + case 2: av_strlcpy(strbuf, "small", 32); break; default: snprintf(strbuf, 32, "ERROR (%d)", opt->room_type); } av_dlog(avctx, "room_type: %s\n", strbuf); @@ -1622,9 +1623,9 @@ static void dprint_options(AVCodecContext *avctx) av_dlog(avctx, "dialnorm: %ddB\n", opt->dialogue_level); if (s->channel_mode == AC3_CHMODE_STEREO) { switch (opt->dolby_surround_mode) { - case 0: strncpy(strbuf, "notindicated", 32); break; - case 1: strncpy(strbuf, "on", 32); break; - case 2: strncpy(strbuf, "off", 32); break; + case 0: av_strlcpy(strbuf, "notindicated", 32); break; + case 1: av_strlcpy(strbuf, "on", 32); break; + case 2: av_strlcpy(strbuf, "off", 32); break; default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_mode); } av_dlog(avctx, "dsur_mode: %s\n", strbuf); @@ -1636,9 +1637,9 @@ static void dprint_options(AVCodecContext *avctx) if (s->bitstream_id == 6) { if (opt->extended_bsi_1) { switch (opt->preferred_stereo_downmix) { - case 0: strncpy(strbuf, "notindicated", 32); break; - case 1: strncpy(strbuf, "ltrt", 32); break; - case 2: strncpy(strbuf, "loro", 32); break; + case 0: av_strlcpy(strbuf, "notindicated", 32); break; + case 1: av_strlcpy(strbuf, "ltrt", 32); break; + case 2: av_strlcpy(strbuf, "loro", 32); break; default: snprintf(strbuf, 32, "ERROR (%d)", opt->preferred_stereo_downmix); } av_dlog(avctx, "dmix_mode: %s\n", strbuf); @@ -1655,23 +1656,23 @@ static void dprint_options(AVCodecContext *avctx) } if (opt->extended_bsi_2) { switch (opt->dolby_surround_ex_mode) { - case 0: strncpy(strbuf, "notindicated", 32); break; - case 1: strncpy(strbuf, "on", 32); break; - case 2: strncpy(strbuf, "off", 32); break; + case 0: av_strlcpy(strbuf, "notindicated", 32); break; + case 1: av_strlcpy(strbuf, "on", 32); break; + case 2: av_strlcpy(strbuf, "off", 32); break; default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_ex_mode); } av_dlog(avctx, "dsurex_mode: %s\n", strbuf); switch (opt->dolby_headphone_mode) { - case 0: strncpy(strbuf, "notindicated", 32); break; - case 1: strncpy(strbuf, "on", 32); break; - case 2: strncpy(strbuf, "off", 32); break; + case 0: av_strlcpy(strbuf, "notindicated", 32); break; + case 1: av_strlcpy(strbuf, "on", 32); break; + case 2: av_strlcpy(strbuf, "off", 32); break; default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_headphone_mode); } av_dlog(avctx, "dheadphone_mode: %s\n", strbuf); switch (opt->ad_converter_type) { - case 0: strncpy(strbuf, "standard", 32); break; - case 1: strncpy(strbuf, "hdcd", 32); break; + case 0: av_strlcpy(strbuf, "standard", 32); break; + case 1: av_strlcpy(strbuf, "hdcd", 32); break; default: snprintf(strbuf, 32, "ERROR (%d)", opt->ad_converter_type); } av_dlog(avctx, "ad_conv_type: %s\n", strbuf); diff --git a/libavcodec/ass.c b/libavcodec/ass.c index beb1ba1141..327a77bb45 100644 --- a/libavcodec/ass.c +++ b/libavcodec/ass.c @@ -21,6 +21,7 @@ #include "avcodec.h" #include "ass.h" +#include "libavutil/avstring.h" /** * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. @@ -117,8 +118,7 @@ int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, rects[sub->num_rects]->type = SUBTITLE_ASS; rects[sub->num_rects]->ass = av_malloc(len + dlen + 1); strcpy (rects[sub->num_rects]->ass , header); - strncpy(rects[sub->num_rects]->ass + len, dialog, dlen); - rects[sub->num_rects]->ass[len+dlen] = 0; + av_strlcpy(rects[sub->num_rects]->ass + len, dialog, dlen + 1); sub->num_rects++; return dlen; } diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 0458844fc3..0327bdf797 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -827,7 +827,7 @@ static int mov_write_video_tag(AVIOContext *pb, MOVTrack *track) memset(compressor_name,0,32); /* FIXME not sure, ISO 14496-1 draft where it shall be set to 0 */ if (track->mode == MODE_MOV && track->enc->codec && track->enc->codec->name) - strncpy(compressor_name,track->enc->codec->name,31); + av_strlcpy(compressor_name,track->enc->codec->name,32); avio_w8(pb, strlen(compressor_name)); avio_write(pb, compressor_name, 31); diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index d46e67b70c..10abe0994c 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -24,6 +24,7 @@ #include "id3v1.h" #include "id3v2.h" #include "rawenc.h" +#include "libavutil/avstring.h" #include "libavutil/intreadwrite.h" #include "libavutil/opt.h" @@ -32,7 +33,7 @@ static int id3v1_set_string(AVFormatContext *s, const char *key, { AVMetadataTag *tag; if ((tag = av_metadata_get(s->metadata, key, NULL, 0))) - strncpy(buf, tag->value, buf_size); + av_strlcpy(buf, tag->value, buf_size); return !!tag; } diff --git a/libavutil/log.c b/libavutil/log.c index cfeb21cd5a..ddfd31f6c3 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -26,6 +26,7 @@ #include #include +#include "avstring.h" #include "avutil.h" #include "log.h" @@ -120,7 +121,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) count=0; } colored_fputs(av_clip(level>>3, 0, 6), line); - strncpy(prev, line, sizeof line); + av_strlcpy(prev, line, sizeof line); } static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; diff --git a/libpostproc/postprocess.c b/libpostproc/postprocess.c index d7c99e29da..4864b02198 100644 --- a/libpostproc/postprocess.c +++ b/libpostproc/postprocess.c @@ -86,6 +86,7 @@ try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks //#define DEBUG_BRIGHTNESS #include "postprocess.h" #include "postprocess_internal.h" +#include "libavutil/avstring.h" unsigned postproc_version(void) { @@ -762,7 +763,7 @@ pp_mode *pp_get_mode_by_name_and_quality(const char *name, int quality) ppMode->maxClippedThreshold= 0.01; ppMode->error=0; - strncpy(temp, name, GET_MODE_BUFFER_SIZE); + av_strlcpy(temp, name, GET_MODE_BUFFER_SIZE); av_log(NULL, AV_LOG_DEBUG, "pp: %s\n", name); From 18b6a69ce9fcbd12476cfbe8ca9cd7e148dc21c5 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 4 May 2011 07:35:30 -0400 Subject: [PATCH 12/23] Revert "VC1: merge idct8x8, coeff adjustments and put_pixels." This reverts commit f8bed30d8b176fa030f6737765338bb4a2bcabc9. The reason for this is that the overlap filter, which runs after IDCT, should run on unclamped values, and thus IDCT and put_pixels() cannot be merged if we want to attempt to be bitexact. --- libavcodec/ppc/vc1dsp_altivec.c | 63 ++------------------------------- libavcodec/vc1.c | 28 +-------------- libavcodec/vc1dec.c | 58 +++++++++++++----------------- libavcodec/vc1dsp.c | 54 ++++++---------------------- libavcodec/vc1dsp.h | 6 +--- 5 files changed, 39 insertions(+), 170 deletions(-) diff --git a/libavcodec/ppc/vc1dsp_altivec.c b/libavcodec/ppc/vc1dsp_altivec.c index c52b5a9aff..307e0e9f6b 100644 --- a/libavcodec/ppc/vc1dsp_altivec.c +++ b/libavcodec/ppc/vc1dsp_altivec.c @@ -130,8 +130,7 @@ do { \ /** Do inverse transform on 8x8 block */ -static void vc1_inv_trans_8x8_altivec(DCTELEM block[64], - int sign, int rangered) +static void vc1_inv_trans_8x8_altivec(DCTELEM block[64]) { vector signed short src0, src1, src2, src3, src4, src5, src6, src7; vector signed int s0, s1, s2, s3, s4, s5, s6, s7; @@ -145,9 +144,6 @@ static void vc1_inv_trans_8x8_altivec(DCTELEM block[64], const vector unsigned int vec_2 = vec_splat_u32(2); const vector signed int vec_1s = vec_splat_s32(1); const vector unsigned int vec_1 = vec_splat_u32(1); - const vector unsigned short rangered_shift = vec_splat_u16(1); - const vector signed short signed_bias = vec_sl(vec_splat_s16(4), - vec_splat_u16(4)); src0 = vec_ld( 0, block); src1 = vec_ld( 16, block); @@ -217,27 +213,6 @@ static void vc1_inv_trans_8x8_altivec(DCTELEM block[64], src6 = vec_pack(sE, s6); src7 = vec_pack(sF, s7); - if (rangered) { - if (!sign) { - src0 = vec_sub(src0, signed_bias); - src1 = vec_sub(src1, signed_bias); - src2 = vec_sub(src2, signed_bias); - src3 = vec_sub(src3, signed_bias); - src4 = vec_sub(src4, signed_bias); - src5 = vec_sub(src5, signed_bias); - src6 = vec_sub(src6, signed_bias); - src7 = vec_sub(src7, signed_bias); - } - src0 = vec_sl(src0, rangered_shift); - src1 = vec_sl(src1, rangered_shift); - src2 = vec_sl(src2, rangered_shift); - src3 = vec_sl(src3, rangered_shift); - src4 = vec_sl(src4, rangered_shift); - src5 = vec_sl(src5, rangered_shift); - src6 = vec_sl(src6, rangered_shift); - src7 = vec_sl(src7, rangered_shift); - } - vec_st(src0, 0, block); vec_st(src1, 16, block); vec_st(src2, 32, block); @@ -248,36 +223,6 @@ static void vc1_inv_trans_8x8_altivec(DCTELEM block[64], vec_st(src7,112, block); } -static void vc1_inv_trans_8x8_add_altivec(uint8_t *dest, int stride, DCTELEM *b) -{ - vc1_inv_trans_8x8_altivec(b, 0, 0); - ff_add_pixels_clamped_c(b, dest, stride); -} - -static void vc1_inv_trans_8x8_put_signed_altivec(uint8_t *dest, int stride, DCTELEM *b) -{ - vc1_inv_trans_8x8_altivec(b, 1, 0); - ff_put_signed_pixels_clamped_c(b, dest, stride); -} - -static void vc1_inv_trans_8x8_put_signed_rangered_altivec(uint8_t *dest, int stride, DCTELEM *b) -{ - vc1_inv_trans_8x8_altivec(b, 1, 1); - ff_put_signed_pixels_clamped_c(b, dest, stride); -} - -static void vc1_inv_trans_8x8_put_altivec(uint8_t *dest, int stride, DCTELEM *b) -{ - vc1_inv_trans_8x8_altivec(b, 0, 0); - ff_put_pixels_clamped_c(b, dest, stride); -} - -static void vc1_inv_trans_8x8_put_rangered_altivec(uint8_t *dest, int stride, DCTELEM *b) -{ - vc1_inv_trans_8x8_altivec(b, 0, 1); - ff_put_pixels_clamped_c(b, dest, stride); -} - /** Do inverse transform on 8x4 part of block */ static void vc1_inv_trans_8x4_altivec(uint8_t *dest, int stride, DCTELEM *block) @@ -396,11 +341,7 @@ void ff_vc1dsp_init_altivec(VC1DSPContext* dsp) if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return; - dsp->vc1_inv_trans_8x8_add = vc1_inv_trans_8x8_add_altivec; - dsp->vc1_inv_trans_8x8_put_signed[0] = vc1_inv_trans_8x8_put_signed_altivec; - dsp->vc1_inv_trans_8x8_put_signed[1] = vc1_inv_trans_8x8_put_signed_rangered_altivec; - dsp->vc1_inv_trans_8x8_put[0] = vc1_inv_trans_8x8_put_altivec; - dsp->vc1_inv_trans_8x8_put[1] = vc1_inv_trans_8x8_put_rangered_altivec; + dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_altivec; dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_altivec; dsp->put_no_rnd_vc1_chroma_pixels_tab[0] = put_no_rnd_vc1_chroma_mc8_altivec; dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = avg_no_rnd_vc1_chroma_mc8_altivec; diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c index 536320ac2e..7b878c18d7 100644 --- a/libavcodec/vc1.c +++ b/libavcodec/vc1.c @@ -280,28 +280,6 @@ static int vop_dquant_decoding(VC1Context *v) static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb); -static void simple_idct_put_rangered(uint8_t *dest, int line_size, DCTELEM *block) -{ - int i; - ff_simple_idct(block); - for (i = 0; i < 64; i++) block[i] = (block[i] - 64) << 1; - ff_put_pixels_clamped_c(block, dest, line_size); -} - -static void simple_idct_put_signed(uint8_t *dest, int line_size, DCTELEM *block) -{ - ff_simple_idct(block); - ff_put_signed_pixels_clamped_c(block, dest, line_size); -} - -static void simple_idct_put_signed_rangered(uint8_t *dest, int line_size, DCTELEM *block) -{ - int i; - ff_simple_idct(block); - for (i = 0; i < 64; i++) block[i] <<= 1; - ff_put_signed_pixels_clamped_c(block, dest, line_size); -} - /** * Decode Simple/Main Profiles sequence header * @see Figure 7-8, p16-17 @@ -359,11 +337,7 @@ int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitConte v->res_fasttx = get_bits1(gb); if (!v->res_fasttx) { - v->vc1dsp.vc1_inv_trans_8x8_add = ff_simple_idct_add; - v->vc1dsp.vc1_inv_trans_8x8_put[0] = ff_simple_idct_put; - v->vc1dsp.vc1_inv_trans_8x8_put[1] = simple_idct_put_rangered; - v->vc1dsp.vc1_inv_trans_8x8_put_signed[0] = simple_idct_put_signed; - v->vc1dsp.vc1_inv_trans_8x8_put_signed[1] = simple_idct_put_signed_rangered; + v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct; v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add; v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add; v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add; diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 1d891ad418..70c7d268bc 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -2016,7 +2016,8 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquan if(i==1) v->vc1dsp.vc1_inv_trans_8x8_dc(dst, linesize, block); else{ - v->vc1dsp.vc1_inv_trans_8x8_add(dst, linesize, block); + v->vc1dsp.vc1_inv_trans_8x8(block); + s->dsp.add_pixels_clamped(block, dst, linesize); } } break; @@ -2258,7 +2259,7 @@ static int vc1_decode_p_mb(VC1Context *v) { MpegEncContext *s = &v->s; GetBitContext *gb = &s->gb; - int i; + int i, j; int mb_pos = s->mb_x + s->mb_y * s->mb_stride; int cbp; /* cbp decoding stuff */ int mqdiff, mquant; /* MB quantization */ @@ -2288,8 +2289,6 @@ static int vc1_decode_p_mb(VC1Context *v) { if (!skipped) { - vc1_idct_func idct8x8_fn; - GET_MVDATA(dmv_x, dmv_y); if (s->mb_intra) { @@ -2324,7 +2323,6 @@ static int vc1_decode_p_mb(VC1Context *v) VC1_TTMB_VLC_BITS, 2); if(!s->mb_intra) vc1_mc_1mv(v, 0); dst_idx = 0; - idct8x8_fn = v->vc1dsp.vc1_inv_trans_8x8_put_signed[!!v->rangeredfrm]; for (i=0; i<6; i++) { s->dc_val[0][s->block_index[i]] = 0; @@ -2342,9 +2340,9 @@ static int vc1_decode_p_mb(VC1Context *v) vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset); if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; - idct8x8_fn(s->dest[dst_idx] + off, - i & 4 ? s->uvlinesize : s->linesize, - s->block[i]); + v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); + if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1; + s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); if(v->pq >= 9 && v->overlap) { if(v->c_avail) v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); @@ -2380,7 +2378,6 @@ static int vc1_decode_p_mb(VC1Context *v) { int intra_count = 0, coded_inter = 0; int is_intra[6], is_coded[6]; - vc1_idct_func idct8x8_fn; /* Get CBPCY */ cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); for (i=0; i<6; i++) @@ -2431,7 +2428,6 @@ static int vc1_decode_p_mb(VC1Context *v) } if (!v->ttmbf && coded_inter) ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); - idct8x8_fn = v->vc1dsp.vc1_inv_trans_8x8_put_signed[!!v->rangeredfrm]; for (i=0; i<6; i++) { dst_idx += i >> 2; @@ -2447,9 +2443,9 @@ static int vc1_decode_p_mb(VC1Context *v) vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, (i&4)?v->codingset2:v->codingset); if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; - idct8x8_fn(s->dest[dst_idx] + off, - (i&4)?s->uvlinesize:s->linesize, - s->block[i]); + v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); + if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1; + s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize); if(v->pq >= 9 && v->overlap) { if(v->c_avail) v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); @@ -2497,7 +2493,7 @@ static void vc1_decode_b_mb(VC1Context *v) { MpegEncContext *s = &v->s; GetBitContext *gb = &s->gb; - int i; + int i, j; int mb_pos = s->mb_x + s->mb_y * s->mb_stride; int cbp = 0; /* cbp decoding stuff */ int mqdiff, mquant; /* MB quantization */ @@ -2510,7 +2506,6 @@ static void vc1_decode_b_mb(VC1Context *v) int skipped, direct; int dmv_x[2], dmv_y[2]; int bmvtype = BMV_TYPE_BACKWARD; - vc1_idct_func idct8x8_fn; mquant = v->pq; /* Loosy initialization */ s->mb_intra = 0; @@ -2608,7 +2603,6 @@ static void vc1_decode_b_mb(VC1Context *v) } } dst_idx = 0; - idct8x8_fn = v->vc1dsp.vc1_inv_trans_8x8_put_signed[!!v->rangeredfrm]; for (i=0; i<6; i++) { s->dc_val[0][s->block_index[i]] = 0; @@ -2626,9 +2620,9 @@ static void vc1_decode_b_mb(VC1Context *v) vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset); if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; - idct8x8_fn(s->dest[dst_idx] + off, - i & 4 ? s->uvlinesize : s->linesize, - s->block[i]); + v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); + if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1; + s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); } else if(val) { vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), NULL); if(!v->ttmbf && ttmb < 8) ttmb = -1; @@ -2641,12 +2635,11 @@ static void vc1_decode_b_mb(VC1Context *v) */ static void vc1_decode_i_blocks(VC1Context *v) { - int k; + int k, j; MpegEncContext *s = &v->s; int cbp, val; uint8_t *coded_val; int mb_pos; - vc1_idct_func idct8x8_fn; /* select codingmode used for VLC tables selection */ switch(v->y_ac_table_index){ @@ -2681,10 +2674,6 @@ static void vc1_decode_i_blocks(VC1Context *v) s->mb_x = s->mb_y = 0; s->mb_intra = 1; s->first_slice_line = 1; - if(v->pq >= 9 && v->overlap) { - idct8x8_fn = v->vc1dsp.vc1_inv_trans_8x8_put_signed[!!v->rangeredfrm]; - } else - idct8x8_fn = v->vc1dsp.vc1_inv_trans_8x8_put[!!v->rangeredfrm]; for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { s->mb_x = 0; ff_init_block_index(s); @@ -2721,9 +2710,14 @@ static void vc1_decode_i_blocks(VC1Context *v) vc1_decode_i_block(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2); if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) continue; - idct8x8_fn(dst[k], - k & 4 ? s->uvlinesize : s->linesize, - s->block[k]); + v->vc1dsp.vc1_inv_trans_8x8(s->block[k]); + if(v->pq >= 9 && v->overlap) { + if (v->rangeredfrm) for(j = 0; j < 64; j++) s->block[k][j] <<= 1; + s->dsp.put_signed_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize); + } else { + if (v->rangeredfrm) for(j = 0; j < 64; j++) s->block[k][j] = (s->block[k][j] - 64) << 1; + s->dsp.put_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize); + } } if(v->pq >= 9 && v->overlap) { @@ -2781,7 +2775,6 @@ static void vc1_decode_i_blocks_adv(VC1Context *v, int mby_start, int mby_end) int mqdiff; int overlap; GetBitContext *gb = &s->gb; - vc1_idct_func idct8x8_fn; /* select codingmode used for VLC tables selection */ switch(v->y_ac_table_index){ @@ -2819,7 +2812,6 @@ static void vc1_decode_i_blocks_adv(VC1Context *v, int mby_start, int mby_end) memset(&s->coded_block[s->block_index[0]-s->b8_stride], 0, s->b8_stride * sizeof(*s->coded_block)); } - idct8x8_fn = v->vc1dsp.vc1_inv_trans_8x8_put_signed[0]; for(; s->mb_y < mby_end; s->mb_y++) { s->mb_x = 0; ff_init_block_index(s); @@ -2876,9 +2868,9 @@ static void vc1_decode_i_blocks_adv(VC1Context *v, int mby_start, int mby_end) vc1_decode_i_block_adv(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant); if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) continue; - idct8x8_fn(dst[k], - k & 4 ? s->uvlinesize : s->linesize, - s->block[k]); + v->vc1dsp.vc1_inv_trans_8x8(s->block[k]); + s->dsp.put_signed_pixels_clamped(s->block[k], dst[k], + k & 4 ? s->uvlinesize : s->linesize); } if(overlap) { diff --git a/libavcodec/vc1dsp.c b/libavcodec/vc1dsp.c index 3d02db7bcc..e1315533c4 100644 --- a/libavcodec/vc1dsp.c +++ b/libavcodec/vc1dsp.c @@ -199,7 +199,7 @@ static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block) } } -static av_always_inline void vc1_inv_trans_8x8_c(DCTELEM block[64], int shl, int sub) +static void vc1_inv_trans_8x8_c(DCTELEM block[64]) { int i; register int t1,t2,t3,t4,t5,t6,t7,t8; @@ -254,50 +254,20 @@ static av_always_inline void vc1_inv_trans_8x8_c(DCTELEM block[64], int shl, int t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56]; t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56]; - dst[ 0] = (((t5 + t1 ) >> 7) - sub) << shl; - dst[ 8] = (((t6 + t2 ) >> 7) - sub) << shl; - dst[16] = (((t7 + t3 ) >> 7) - sub) << shl; - dst[24] = (((t8 + t4 ) >> 7) - sub) << shl; - dst[32] = (((t8 - t4 + 1) >> 7) - sub) << shl; - dst[40] = (((t7 - t3 + 1) >> 7) - sub) << shl; - dst[48] = (((t6 - t2 + 1) >> 7) - sub) << shl; - dst[56] = (((t5 - t1 + 1) >> 7) - sub) << shl; + dst[ 0] = (t5 + t1) >> 7; + dst[ 8] = (t6 + t2) >> 7; + dst[16] = (t7 + t3) >> 7; + dst[24] = (t8 + t4) >> 7; + dst[32] = (t8 - t4 + 1) >> 7; + dst[40] = (t7 - t3 + 1) >> 7; + dst[48] = (t6 - t2 + 1) >> 7; + dst[56] = (t5 - t1 + 1) >> 7; src++; dst++; } } -static void vc1_inv_trans_8x8_add_c(uint8_t *dest, int linesize, DCTELEM *block) -{ - vc1_inv_trans_8x8_c(block, 0, 0); - ff_add_pixels_clamped_c(block, dest, linesize); -} - -static void vc1_inv_trans_8x8_put_signed_c(uint8_t *dest, int linesize, DCTELEM *block) -{ - vc1_inv_trans_8x8_c(block, 0, 0); - ff_put_signed_pixels_clamped_c(block, dest, linesize); -} - -static void vc1_inv_trans_8x8_put_signed_rangered_c(uint8_t *dest, int linesize, DCTELEM *block) -{ - vc1_inv_trans_8x8_c(block, 1, 0); - ff_put_signed_pixels_clamped_c(block, dest, linesize); -} - -static void vc1_inv_trans_8x8_put_c(uint8_t *dest, int linesize, DCTELEM *block) -{ - vc1_inv_trans_8x8_c(block, 0, 0); - ff_put_pixels_clamped_c(block, dest, linesize); -} - -static void vc1_inv_trans_8x8_put_rangered_c(uint8_t *dest, int linesize, DCTELEM *block) -{ - vc1_inv_trans_8x8_c(block, 1, 64); - ff_put_pixels_clamped_c(block, dest, linesize); -} - /** Do inverse transform on 8x4 part of block */ static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block) @@ -692,11 +662,7 @@ static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*a } av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) { - dsp->vc1_inv_trans_8x8_add = vc1_inv_trans_8x8_add_c; - dsp->vc1_inv_trans_8x8_put_signed[0] = vc1_inv_trans_8x8_put_signed_c; - dsp->vc1_inv_trans_8x8_put_signed[1] = vc1_inv_trans_8x8_put_signed_rangered_c; - dsp->vc1_inv_trans_8x8_put[0] = vc1_inv_trans_8x8_put_c; - dsp->vc1_inv_trans_8x8_put[1] = vc1_inv_trans_8x8_put_rangered_c; + dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c; dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c; dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c; dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c; diff --git a/libavcodec/vc1dsp.h b/libavcodec/vc1dsp.h index 32bb25b7f7..7b1ae10809 100644 --- a/libavcodec/vc1dsp.h +++ b/libavcodec/vc1dsp.h @@ -30,13 +30,9 @@ #include "dsputil.h" -typedef void (*vc1_idct_func)(uint8_t *dest, int line_size, DCTELEM *block); - typedef struct VC1DSPContext { /* vc1 functions */ - vc1_idct_func vc1_inv_trans_8x8_add; - vc1_idct_func vc1_inv_trans_8x8_put_signed[2]; - vc1_idct_func vc1_inv_trans_8x8_put[2]; + void (*vc1_inv_trans_8x8)(DCTELEM *b); void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block); void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block); void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block); From 5c9f147e055c732b1b2a0c8350b4d08b9b30e0cd Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Mon, 2 May 2011 22:09:02 -0400 Subject: [PATCH 13/23] vc1dec: use s->start/end_mb_y instead of passing them as function args. --- libavcodec/vc1dec.c | 51 +++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 70c7d268bc..ccdc3e8521 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -2764,7 +2764,7 @@ static void vc1_decode_i_blocks(VC1Context *v) /** Decode blocks of I-frame for advanced profile */ -static void vc1_decode_i_blocks_adv(VC1Context *v, int mby_start, int mby_end) +static void vc1_decode_i_blocks_adv(VC1Context *v) { int k; MpegEncContext *s = &v->s; @@ -2805,14 +2805,14 @@ static void vc1_decode_i_blocks_adv(VC1Context *v, int mby_start, int mby_end) s->mb_x = s->mb_y = 0; s->mb_intra = 1; s->first_slice_line = 1; - s->mb_y = mby_start; - if (mby_start) { + s->mb_y = s->start_mb_y; + if (s->start_mb_y) { s->mb_x = 0; ff_init_block_index(s); memset(&s->coded_block[s->block_index[0]-s->b8_stride], 0, s->b8_stride * sizeof(*s->coded_block)); } - for(; s->mb_y < mby_end; s->mb_y++) { + for(; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; ff_init_block_index(s); for(;s->mb_x < s->mb_width; s->mb_x++) { @@ -2898,7 +2898,7 @@ static void vc1_decode_i_blocks_adv(VC1Context *v, int mby_start, int mby_end) if(v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq); if(get_bits_count(&s->gb) > v->bits) { - ff_er_add_slice(s, 0, mby_start, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); return; } @@ -2911,10 +2911,10 @@ static void vc1_decode_i_blocks_adv(VC1Context *v, int mby_start, int mby_end) } if (v->s.loop_filter) ff_draw_horiz_band(s, (s->mb_height-1)*16, 16); - ff_er_add_slice(s, 0, mby_start, s->mb_width - 1, mby_end - 1, (AC_END|DC_END|MV_END)); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END)); } -static void vc1_decode_p_blocks(VC1Context *v, int mby_start, int mby_end) +static void vc1_decode_p_blocks(VC1Context *v) { MpegEncContext *s = &v->s; int apply_loop_filter; @@ -2947,17 +2947,17 @@ static void vc1_decode_p_blocks(VC1Context *v, int mby_start, int mby_end) apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY); s->first_slice_line = 1; memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride); - for(s->mb_y = mby_start; s->mb_y < mby_end; s->mb_y++) { + for(s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; ff_init_block_index(s); for(; s->mb_x < s->mb_width; s->mb_x++) { ff_update_block_index(s); vc1_decode_p_mb(v); - if (s->mb_y != mby_start && apply_loop_filter) + if (s->mb_y != s->start_mb_y && apply_loop_filter) vc1_apply_p_loop_filter(v); if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { - ff_er_add_slice(s, 0, mby_start, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y); return; } @@ -2966,7 +2966,7 @@ static void vc1_decode_p_blocks(VC1Context *v, int mby_start, int mby_end) memmove(v->ttblk_base, v->ttblk, sizeof(v->ttblk_base[0])*s->mb_stride); memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0])*s->mb_stride); memmove(v->luma_mv_base, v->luma_mv, sizeof(v->luma_mv_base[0])*s->mb_stride); - if (s->mb_y != mby_start) ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16); + if (s->mb_y != s->start_mb_y) ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16); s->first_slice_line = 0; } if (apply_loop_filter) { @@ -2977,12 +2977,12 @@ static void vc1_decode_p_blocks(VC1Context *v, int mby_start, int mby_end) vc1_apply_p_loop_filter(v); } } - if (mby_end >= mby_start) - ff_draw_horiz_band(s, (mby_end-1) * 16, 16); - ff_er_add_slice(s, 0, mby_start, s->mb_width - 1, mby_end - 1, (AC_END|DC_END|MV_END)); + if (s->end_mb_y >= s->start_mb_y) + ff_draw_horiz_band(s, (s->end_mb_y-1) * 16, 16); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END)); } -static void vc1_decode_b_blocks(VC1Context *v, int mby_start, int mby_end) +static void vc1_decode_b_blocks(VC1Context *v) { MpegEncContext *s = &v->s; @@ -3012,7 +3012,7 @@ static void vc1_decode_b_blocks(VC1Context *v, int mby_start, int mby_end) } s->first_slice_line = 1; - for(s->mb_y = mby_start; s->mb_y < mby_end; s->mb_y++) { + for(s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; ff_init_block_index(s); for(; s->mb_x < s->mb_width; s->mb_x++) { @@ -3020,7 +3020,7 @@ static void vc1_decode_b_blocks(VC1Context *v, int mby_start, int mby_end) vc1_decode_b_mb(v); if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { - ff_er_add_slice(s, 0, mby_start, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y); return; } @@ -3034,7 +3034,7 @@ static void vc1_decode_b_blocks(VC1Context *v, int mby_start, int mby_end) } if (v->s.loop_filter) ff_draw_horiz_band(s, (s->mb_height-1)*16, 16); - ff_er_add_slice(s, 0, mby_start, s->mb_width - 1, mby_end - 1, (AC_END|DC_END|MV_END)); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END)); } static void vc1_decode_skip_blocks(VC1Context *v) @@ -3056,7 +3056,7 @@ static void vc1_decode_skip_blocks(VC1Context *v) s->pict_type = AV_PICTURE_TYPE_P; } -static void vc1_decode_blocks(VC1Context *v, int mby_start, int mby_end) +static void vc1_decode_blocks(VC1Context *v) { v->s.esc3_level_length = 0; @@ -3066,7 +3066,7 @@ static void vc1_decode_blocks(VC1Context *v, int mby_start, int mby_end) switch(v->s.pict_type) { case AV_PICTURE_TYPE_I: if(v->profile == PROFILE_ADVANCED) - vc1_decode_i_blocks_adv(v, mby_start, mby_end); + vc1_decode_i_blocks_adv(v); else vc1_decode_i_blocks(v); break; @@ -3074,16 +3074,16 @@ static void vc1_decode_blocks(VC1Context *v, int mby_start, int mby_end) if(v->p_frame_skipped) vc1_decode_skip_blocks(v); else - vc1_decode_p_blocks(v, mby_start, mby_end); + vc1_decode_p_blocks(v); break; case AV_PICTURE_TYPE_B: if(v->bi_type){ if(v->profile == PROFILE_ADVANCED) - vc1_decode_i_blocks_adv(v, mby_start, mby_end); + vc1_decode_i_blocks_adv(v); else vc1_decode_i_blocks(v); }else - vc1_decode_b_blocks(v, mby_start, mby_end); + vc1_decode_b_blocks(v); break; } } @@ -3539,8 +3539,9 @@ static int vc1_decode_frame(AVCodecContext *avctx, for (i = 0; i <= n_slices; i++) { if (i && get_bits1(&s->gb)) vc1_parse_frame_header_adv(v, &s->gb); - vc1_decode_blocks(v, i == 0 ? 0 : FFMAX(0, slices[i-1].mby_start), - i == n_slices ? s->mb_height : FFMIN(s->mb_height, slices[i].mby_start)); + s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start); + s->end_mb_y = (i == n_slices) ? s->mb_height : FFMIN(s->mb_height, slices[i].mby_start); + vc1_decode_blocks(v); if (i != n_slices) s->gb = slices[i].gb; } //av_log(s->avctx, AV_LOG_INFO, "Consumed %i/%i bits\n", get_bits_count(&s->gb), s->gb.size_in_bits); From 7d2e03afc8573f959aa3641eea5c9f981466bcd8 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 4 May 2011 07:40:53 -0400 Subject: [PATCH 14/23] vc1: make overlap filter for I-frames bit-exact. --- libavcodec/vc1.h | 2 + libavcodec/vc1dec.c | 279 +++++++++++++++++++++++++++++++++++++------- libavcodec/vc1dsp.c | 54 +++++++++ libavcodec/vc1dsp.h | 6 +- tests/ref/fate/vc1 | 30 ++--- 5 files changed, 311 insertions(+), 60 deletions(-) diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h index db8a7f42b2..96e5744228 100644 --- a/libavcodec/vc1.h +++ b/libavcodec/vc1.h @@ -317,6 +317,8 @@ typedef struct VC1Context{ int bi_type; int x8_type; + DCTELEM (*block)[6][64]; + int n_allocated_blks, cur_blk_idx, left_blk_idx, topleft_blk_idx, top_blk_idx; uint32_t *cbp_base, *cbp; uint8_t *is_intra_base, *is_intra; int16_t (*luma_mv_base)[2], (*luma_mv)[2]; diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index ccdc3e8521..5c931b122a 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -160,6 +160,72 @@ enum Imode { /** @} */ //Bitplane group +static void vc1_put_signed_blocks_clamped(VC1Context *v) +{ + MpegEncContext *s = &v->s; + + /* The put pixels loop is always one MB row behind the decoding loop, + * because we can only put pixels when overlap filtering is done, and + * for filtering of the bottom edge of a MB, we need the next MB row + * present as well. + * Within the row, the put pixels loop is also one MB col behind the + * decoding loop. The reason for this is again, because for filtering + * of the right MB edge, we need the next MB present. */ + if (!s->first_slice_line) { + if (s->mb_x) { + s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][0], + s->dest[0] - 16 * s->linesize - 16, + s->linesize); + s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][1], + s->dest[0] - 16 * s->linesize - 8, + s->linesize); + s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][2], + s->dest[0] - 8 * s->linesize - 16, + s->linesize); + s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][3], + s->dest[0] - 8 * s->linesize - 8, + s->linesize); + s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][4], + s->dest[1] - 8 * s->uvlinesize - 8, + s->uvlinesize); + s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][5], + s->dest[2] - 8 * s->uvlinesize - 8, + s->uvlinesize); + } + if (s->mb_x == s->mb_width - 1) { + s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][0], + s->dest[0] - 16 * s->linesize, + s->linesize); + s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][1], + s->dest[0] - 16 * s->linesize + 8, + s->linesize); + s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][2], + s->dest[0] - 8 * s->linesize, + s->linesize); + s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][3], + s->dest[0] - 8 * s->linesize + 8, + s->linesize); + s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][4], + s->dest[1] - 8 * s->uvlinesize, + s->uvlinesize); + s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][5], + s->dest[2] - 8 * s->uvlinesize, + s->uvlinesize); + } + } + +#define inc_blk_idx(idx) do { \ + idx++; \ + if (idx >= v->n_allocated_blks) \ + idx = 0; \ + } while (0) + + inc_blk_idx(v->topleft_blk_idx); + inc_blk_idx(v->top_blk_idx); + inc_blk_idx(v->left_blk_idx); + inc_blk_idx(v->cur_blk_idx); +} + static void vc1_loop_filter_iblk(VC1Context *v, int pq) { MpegEncContext *s = &v->s; @@ -187,6 +253,151 @@ static void vc1_loop_filter_iblk(VC1Context *v, int pq) } } +static void vc1_loop_filter_iblk_delayed(VC1Context *v, int pq) +{ + MpegEncContext *s = &v->s; + int j; + + /* The loopfilter runs 1 row and 1 column behind the overlap filter, which + * means it runs two rows/cols behind the decoding loop. */ + if (!s->first_slice_line) { + if (s->mb_x) { + if (s->mb_y >= s->start_mb_y + 2) { + v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 16 * s->linesize - 16, s->linesize, pq); + + if (s->mb_x >= 2) + v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 16, s->linesize, pq); + v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 8, s->linesize, pq); + for(j = 0; j < 2; j++) { + v->vc1dsp.vc1_v_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq); + if (s->mb_x >= 2) { + v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 16 * s->uvlinesize - 8, s->uvlinesize, pq); + } + } + } + v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 8 * s->linesize - 16, s->linesize, pq); + } + + if (s->mb_x == s->mb_width - 1) { + if (s->mb_y >= s->start_mb_y + 2) { + v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq); + + if (s->mb_x) + v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize, s->linesize, pq); + v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize + 8, s->linesize, pq); + for(j = 0; j < 2; j++) { + v->vc1dsp.vc1_v_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize, s->uvlinesize, pq); + if (s->mb_x >= 2) { + v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 16 * s->uvlinesize, s->uvlinesize, pq); + } + } + } + v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 8 * s->linesize, s->linesize, pq); + } + + if (s->mb_y == s->mb_height) { + if (s->mb_x) { + if (s->mb_x >= 2) + v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 16, s->linesize, pq); + v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 8, s->linesize, pq); + if (s->mb_x >= 2) { + for(j = 0; j < 2; j++) { + v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq); + } + } + } + + if (s->mb_x == s->mb_width - 1) { + if (s->mb_x) + v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq); + v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize + 8, s->linesize, pq); + if (s->mb_x) { + for(j = 0; j < 2; j++) { + v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize, s->uvlinesize, pq); + } + } + } + } + } +} + +static void vc1_smooth_overlap_filter_iblk(VC1Context *v) +{ + MpegEncContext *s = &v->s; + int mb_pos; + + if (v->condover == CONDOVER_NONE) + return; + + mb_pos = s->mb_x + s->mb_y * s->mb_stride; + + /* Within a MB, the horizontal overlap always runs before the vertical. + * To accomplish that, we run the H on left and internal borders of the + * currently decoded MB. Then, we wait for the next overlap iteration + * to do H overlap on the right edge of this MB, before moving over and + * running the V overlap. Therefore, the V overlap makes us trail by one + * MB col and the H overlap filter makes us trail by one MB row. This + * is reflected in the time at which we run the put_pixels loop. */ + if(v->condover == CONDOVER_ALL || v->pq >= 9 || v->over_flags_plane[mb_pos]) { + if(s->mb_x && (v->condover == CONDOVER_ALL || v->pq >= 9 || + v->over_flags_plane[mb_pos - 1])) { + v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][1], + v->block[v->cur_blk_idx][0]); + v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][3], + v->block[v->cur_blk_idx][2]); + if(!(s->flags & CODEC_FLAG_GRAY)) { + v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][4], + v->block[v->cur_blk_idx][4]); + v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][5], + v->block[v->cur_blk_idx][5]); + } + } + v->vc1dsp.vc1_h_s_overlap(v->block[v->cur_blk_idx][0], + v->block[v->cur_blk_idx][1]); + v->vc1dsp.vc1_h_s_overlap(v->block[v->cur_blk_idx][2], + v->block[v->cur_blk_idx][3]); + + if (s->mb_x == s->mb_width - 1) { + if(!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 || + v->over_flags_plane[mb_pos - s->mb_stride])) { + v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][2], + v->block[v->cur_blk_idx][0]); + v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][3], + v->block[v->cur_blk_idx][1]); + if(!(s->flags & CODEC_FLAG_GRAY)) { + v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][4], + v->block[v->cur_blk_idx][4]); + v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][5], + v->block[v->cur_blk_idx][5]); + } + } + v->vc1dsp.vc1_v_s_overlap(v->block[v->cur_blk_idx][0], + v->block[v->cur_blk_idx][2]); + v->vc1dsp.vc1_v_s_overlap(v->block[v->cur_blk_idx][1], + v->block[v->cur_blk_idx][3]); + } + } + if (s->mb_x && (v->condover == CONDOVER_ALL || v->over_flags_plane[mb_pos - 1])) { + if(!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 || + v->over_flags_plane[mb_pos - s->mb_stride - 1])) { + v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][2], + v->block[v->left_blk_idx][0]); + v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][3], + v->block[v->left_blk_idx][1]); + if(!(s->flags & CODEC_FLAG_GRAY)) { + v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][4], + v->block[v->left_blk_idx][4]); + v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][5], + v->block[v->left_blk_idx][5]); + } + } + v->vc1dsp.vc1_v_s_overlap(v->block[v->left_blk_idx][0], + v->block[v->left_blk_idx][2]); + v->vc1dsp.vc1_v_s_overlap(v->block[v->left_blk_idx][1], + v->block[v->left_blk_idx][3]); + } +} + /** Do motion compensation over 1 macroblock * Mostly adapted hpel_motion and qpel_motion from mpegvideo.c */ @@ -2773,7 +2984,6 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) int mb_pos; int mquant = v->pq; int mqdiff; - int overlap; GetBitContext *gb = &s->gb; /* select codingmode used for VLC tables selection */ @@ -2816,15 +3026,9 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) s->mb_x = 0; ff_init_block_index(s); for(;s->mb_x < s->mb_width; s->mb_x++) { - uint8_t *dst[6]; + DCTELEM (*block)[64] = v->block[v->cur_blk_idx]; ff_update_block_index(s); - dst[0] = s->dest[0]; - dst[1] = dst[0] + 8; - dst[2] = s->dest[0] + s->linesize * 8; - dst[3] = dst[2] + 8; - dst[4] = s->dest[1]; - dst[5] = s->dest[2]; - s->dsp.clear_blocks(s->block[0]); + s->dsp.clear_blocks(block[0]); mb_pos = s->mb_x + s->mb_y * s->mb_stride; s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA; s->current_picture.motion_val[1][s->block_index[0]][0] = 0; @@ -2837,13 +3041,8 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) else v->s.ac_pred = v->acpred_plane[mb_pos]; - if(v->condover == CONDOVER_SELECT) { - if(v->overflg_is_raw) - overlap = get_bits1(&v->s.gb); - else - overlap = v->over_flags_plane[mb_pos]; - } else - overlap = (v->condover == CONDOVER_ALL); + if (v->condover == CONDOVER_SELECT && v->overflg_is_raw) + v->over_flags_plane[mb_pos] = get_bits1(&v->s.gb); GET_MQUANT(); @@ -2865,37 +3064,15 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) v->a_avail = !s->first_slice_line || (k==2 || k==3); v->c_avail = !!s->mb_x || (k==1 || k==3); - vc1_decode_i_block_adv(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant); + vc1_decode_i_block_adv(v, block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant); if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) continue; - v->vc1dsp.vc1_inv_trans_8x8(s->block[k]); - s->dsp.put_signed_pixels_clamped(s->block[k], dst[k], - k & 4 ? s->uvlinesize : s->linesize); + v->vc1dsp.vc1_inv_trans_8x8(block[k]); } - if(overlap) { - if(s->mb_x) { - v->vc1dsp.vc1_h_overlap(s->dest[0], s->linesize); - v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize); - if(!(s->flags & CODEC_FLAG_GRAY)) { - v->vc1dsp.vc1_h_overlap(s->dest[1], s->uvlinesize); - v->vc1dsp.vc1_h_overlap(s->dest[2], s->uvlinesize); - } - } - v->vc1dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize); - v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); - if(!s->first_slice_line) { - v->vc1dsp.vc1_v_overlap(s->dest[0], s->linesize); - v->vc1dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize); - if(!(s->flags & CODEC_FLAG_GRAY)) { - v->vc1dsp.vc1_v_overlap(s->dest[1], s->uvlinesize); - v->vc1dsp.vc1_v_overlap(s->dest[2], s->uvlinesize); - } - } - v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize); - v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); - } - if(v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq); + vc1_smooth_overlap_filter_iblk(v); + vc1_put_signed_blocks_clamped(v); + if(v->s.loop_filter) vc1_loop_filter_iblk_delayed(v, v->pq); if(get_bits_count(&s->gb) > v->bits) { ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); @@ -2909,6 +3086,15 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16); s->first_slice_line = 0; } + + /* raw bottom MB row */ + s->mb_x = 0; + ff_init_block_index(s); + for(;s->mb_x < s->mb_width; s->mb_x++) { + ff_update_block_index(s); + vc1_put_signed_blocks_clamped(v); + if(v->s.loop_filter) vc1_loop_filter_iblk_delayed(v, v->pq); + } if (v->s.loop_filter) ff_draw_horiz_band(s, (s->mb_height-1)*16, 16); ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END)); @@ -3063,6 +3249,10 @@ static void vc1_decode_blocks(VC1Context *v) if(v->x8_type){ ff_intrax8_decode_picture(&v->x8, 2*v->pq+v->halfpq, v->pq*(!v->pquantizer) ); }else{ + v->cur_blk_idx = 0; + v->left_blk_idx = -1; + v->topleft_blk_idx = 1; + v->top_blk_idx = 2; switch(v->s.pict_type) { case AV_PICTURE_TYPE_I: if(v->profile == PROFILE_ADVANCED) @@ -3333,6 +3523,8 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) v->acpred_plane = av_malloc(s->mb_stride * s->mb_height); v->over_flags_plane = av_malloc(s->mb_stride * s->mb_height); + v->n_allocated_blks = s->mb_width + 2; + v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks); v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride); v->cbp = v->cbp_base + s->mb_stride; v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride); @@ -3598,6 +3790,7 @@ static av_cold int vc1_decode_end(AVCodecContext *avctx) av_freep(&v->acpred_plane); av_freep(&v->over_flags_plane); av_freep(&v->mb_type_base); + av_freep(&v->block); av_freep(&v->cbp_base); av_freep(&v->ttblk_base); av_freep(&v->is_intra_base); // FIXME use v->mb_type[] diff --git a/libavcodec/vc1dsp.c b/libavcodec/vc1dsp.c index e1315533c4..7d0e406677 100644 --- a/libavcodec/vc1dsp.c +++ b/libavcodec/vc1dsp.c @@ -78,6 +78,58 @@ static void vc1_h_overlap_c(uint8_t* src, int stride) } } +static void vc1_v_s_overlap_c(DCTELEM *top, DCTELEM *bottom) +{ + int i; + int a, b, c, d; + int d1, d2; + int rnd1 = 4, rnd2 = 3; + for(i = 0; i < 8; i++) { + a = top[48]; + b = top[56]; + c = bottom[0]; + d = bottom[8]; + d1 = a - d; + d2 = a - d + b - c; + + top[48] = ((a << 3) - d1 + rnd1) >> 3; + top[56] = ((b << 3) - d2 + rnd2) >> 3; + bottom[0] = ((c << 3) + d2 + rnd1) >> 3; + bottom[8] = ((d << 3) + d1 + rnd2) >> 3; + + bottom++; + top++; + rnd2 = 7 - rnd2; + rnd1 = 7 - rnd1; + } +} + +static void vc1_h_s_overlap_c(DCTELEM *left, DCTELEM *right) +{ + int i; + int a, b, c, d; + int d1, d2; + int rnd1 = 4, rnd2 = 3; + for(i = 0; i < 8; i++) { + a = left[6]; + b = left[7]; + c = right[0]; + d = right[1]; + d1 = a - d; + d2 = a - d + b - c; + + left[6] = ((a << 3) - d1 + rnd1) >> 3; + left[7] = ((b << 3) - d2 + rnd2) >> 3; + right[0] = ((c << 3) + d2 + rnd1) >> 3; + right[1] = ((d << 3) + d1 + rnd2) >> 3; + + right += 8; + left += 8; + rnd2 = 7 - rnd2; + rnd1 = 7 - rnd1; + } +} + /** * VC-1 in-loop deblocking filter for one line * @param src source block type @@ -672,6 +724,8 @@ av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) { dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_c; dsp->vc1_h_overlap = vc1_h_overlap_c; dsp->vc1_v_overlap = vc1_v_overlap_c; + dsp->vc1_h_s_overlap = vc1_h_s_overlap_c; + dsp->vc1_v_s_overlap = vc1_v_s_overlap_c; dsp->vc1_v_loop_filter4 = vc1_v_loop_filter4_c; dsp->vc1_h_loop_filter4 = vc1_h_loop_filter4_c; dsp->vc1_v_loop_filter8 = vc1_v_loop_filter8_c; diff --git a/libavcodec/vc1dsp.h b/libavcodec/vc1dsp.h index 7b1ae10809..e1b6ba0aa8 100644 --- a/libavcodec/vc1dsp.h +++ b/libavcodec/vc1dsp.h @@ -40,8 +40,10 @@ typedef struct VC1DSPContext { void (*vc1_inv_trans_8x4_dc)(uint8_t *dest, int line_size, DCTELEM *block); void (*vc1_inv_trans_4x8_dc)(uint8_t *dest, int line_size, DCTELEM *block); void (*vc1_inv_trans_4x4_dc)(uint8_t *dest, int line_size, DCTELEM *block); - void (*vc1_v_overlap)(uint8_t* src, int stride); - void (*vc1_h_overlap)(uint8_t* src, int stride); + void (*vc1_v_overlap)(uint8_t *src, int stride); + void (*vc1_h_overlap)(uint8_t *src, int stride); + void (*vc1_v_s_overlap)(DCTELEM *top, DCTELEM *bottom); + void (*vc1_h_s_overlap)(DCTELEM *left, DCTELEM *right); void (*vc1_v_loop_filter4)(uint8_t *src, int stride, int pq); void (*vc1_h_loop_filter4)(uint8_t *src, int stride, int pq); void (*vc1_v_loop_filter8)(uint8_t *src, int stride, int pq); diff --git a/tests/ref/fate/vc1 b/tests/ref/fate/vc1 index 69e9b4ad64..901f81a97f 100644 --- a/tests/ref/fate/vc1 +++ b/tests/ref/fate/vc1 @@ -1,15 +1,15 @@ -0, 0, 38016, 0xf4715db5 -0, 3600, 38016, 0xf4715db5 -0, 7200, 38016, 0xf4715db5 -0, 10800, 38016, 0xf46af0e1 -0, 14400, 38016, 0x9c1c2cf1 -0, 18000, 38016, 0xff12d87f -0, 21600, 38016, 0x7408432b -0, 25200, 38016, 0x7408432b -0, 28800, 38016, 0x8d11479a -0, 32400, 38016, 0x8d11479a -0, 36000, 38016, 0xc4a121ab -0, 39600, 38016, 0xc4a121ab -0, 43200, 38016, 0xc4a121ab -0, 46800, 38016, 0xc4a121ab -0, 50400, 38016, 0xc4a121ab +0, 0, 38016, 0xa6f15db5 +0, 3600, 38016, 0xa6f15db5 +0, 7200, 38016, 0xa6f15db5 +0, 10800, 38016, 0x5c4ef0e7 +0, 14400, 38016, 0x53a42d1d +0, 18000, 38016, 0x68f7d89e +0, 21600, 38016, 0xc15f4368 +0, 25200, 38016, 0xc15f4368 +0, 28800, 38016, 0xd1bd47a8 +0, 32400, 38016, 0xd1bd47a8 +0, 36000, 38016, 0xe1e821ca +0, 39600, 38016, 0xe1e821ca +0, 43200, 38016, 0xe1e821ca +0, 46800, 38016, 0xe1e821ca +0, 50400, 38016, 0xe1e821ca From eddd580b743692bc930692cb0c5a3e930ab45ad4 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Wed, 4 May 2011 17:57:37 +0100 Subject: [PATCH 15/23] matroskaenc: fix memory leak This fixes a memory leak occurring when no cue points are defined since commit 91819763. Signed-off-by: Mans Rullgard --- libavformat/matroskaenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index c0427f9854..781121a68f 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -403,8 +403,6 @@ static int64_t mkv_write_cues(AVIOContext *pb, mkv_cues *cues, int num_tracks) } end_ebml_master(pb, cues_element); - av_free(cues->entries); - av_free(cues); return currentpos; } @@ -1160,6 +1158,8 @@ static int mkv_write_trailer(AVFormatContext *s) end_ebml_master(pb, mkv->segment); av_free(mkv->tracks); + av_freep(&mkv->cues->entries); + av_freep(&mkv->cues); av_destruct_packet(&mkv->cur_audio_pkt); avio_flush(pb); return 0; From 35e376b0d25ec2e5bff25ca24c2d741cccb27b10 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Tue, 3 May 2011 16:08:53 +0200 Subject: [PATCH 16/23] flashsv: K&R cosmetics --- libavcodec/flashsv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c index 1e8afdb0db..a958bdaa53 100644 --- a/libavcodec/flashsv.c +++ b/libavcodec/flashsv.c @@ -148,7 +148,7 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data, if ((avctx->width != s->image_width) || (avctx->height != s->image_height)) { av_log(avctx, AV_LOG_ERROR, "Frame width or height differs from first frames!\n"); av_log(avctx, AV_LOG_ERROR, "fh = %d, fv %d vs ch = %d, cv = %d\n", avctx->height, - avctx->width,s->image_height, s->image_width); + avctx->width, s->image_height, s->image_width); return -1; } @@ -195,7 +195,7 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data, s->zstream.next_in = buf + (get_bits_count(&gb) / 8); s->zstream.avail_in = size; s->zstream.next_out = s->tmpblock; - s->zstream.avail_out = s->block_size*3; + s->zstream.avail_out = s->block_size * 3; ret = inflate(&(s->zstream), Z_FINISH); if (ret == Z_DATA_ERROR) { av_log(avctx, AV_LOG_ERROR, "Zlib resync occurred\n"); From 091018e0dd0e2600b62324bce0e7146d7d300f44 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 4 May 2011 14:21:27 +0200 Subject: [PATCH 17/23] Fix standalone compilation of MXPEG decoder. --- libavcodec/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1b704126dd..7434157e8f 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -272,7 +272,7 @@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4data.o h263dec.o \ OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o OBJS-$(CONFIG_MSZH_DECODER) += lcldec.o -OBJS-$(CONFIG_MXPEG_DECODER) += mxpegdec.o +OBJS-$(CONFIG_MXPEG_DECODER) += mxpegdec.o mjpegdec.o mjpeg.o OBJS-$(CONFIG_NELLYMOSER_DECODER) += nellymoserdec.o nellymoser.o OBJS-$(CONFIG_NELLYMOSER_ENCODER) += nellymoserenc.o nellymoser.o OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o From 61165a1bba939e520d01b5f029100fd700b51f2f Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 4 May 2011 18:47:07 +0200 Subject: [PATCH 18/23] Fix standalone compilation of WTV demuxer. --- libavcodec/Makefile | 1 + libavformat/Makefile | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 7434157e8f..1d8452ac03 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -546,6 +546,7 @@ OBJS-$(CONFIG_SPDIF_DEMUXER) += aacadtsdec.o mpeg4audio.o OBJS-$(CONFIG_WEBM_MUXER) += xiph.o mpeg4audio.o \ flacdec.o flacdata.o flac.o \ mpegaudiodata.o +OBJS-$(CONFIG_WTV_DEMUXER) += mpeg4audio.o mpegaudiodata.o # external codec libraries OBJS-$(CONFIG_LIBDIRAC_DECODER) += libdiracdec.o diff --git a/libavformat/Makefile b/libavformat/Makefile index e2e3982125..ba978af7a4 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -295,7 +295,8 @@ OBJS-$(CONFIG_WEBM_MUXER) += matroskaenc.o matroska.o \ flacenc_header.o avlanguage.o OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood.o OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood.o -OBJS-$(CONFIG_WTV_DEMUXER) += wtv.o asf.o asfdec.o mpegts.o riff.o +OBJS-$(CONFIG_WTV_DEMUXER) += wtv.o asfdec.o asf.o asfcrypt.o \ + avlanguage.o mpegts.o isom.o riff.o OBJS-$(CONFIG_WV_DEMUXER) += wv.o apetag.o OBJS-$(CONFIG_XA_DEMUXER) += xa.o OBJS-$(CONFIG_XWMA_DEMUXER) += xwma.o riff.o From 56c8227d465fe50ea48790ae316a82cafd9e822b Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 4 May 2011 18:48:26 +0200 Subject: [PATCH 19/23] Fix standalone compilation of IMC decoder. --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 2b5aeab3c3..1339f07890 100755 --- a/configure +++ b/configure @@ -1279,7 +1279,7 @@ h264_dxva2_hwaccel_deps="dxva2api_h" h264_dxva2_hwaccel_select="dxva2 h264_decoder" h264_vaapi_hwaccel_select="vaapi" h264_vdpau_decoder_select="vdpau h264_decoder" -imc_decoder_select="fft mdct" +imc_decoder_select="fft mdct sinewin" jpegls_decoder_select="golomb" jpegls_encoder_select="golomb" ljpeg_encoder_select="aandct" From a33657ce5b065df045c7567517641f40e7aab1f8 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 4 May 2011 18:48:51 +0200 Subject: [PATCH 20/23] Fix standalone compilation of binkaudio_dct / binkaudio_rdft decoders. --- configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 1339f07890..e79bd0ee6e 100755 --- a/configure +++ b/configure @@ -1248,8 +1248,8 @@ amrnb_decoder_select="lsp" amrwb_decoder_select="lsp" atrac1_decoder_select="mdct sinewin" atrac3_decoder_select="mdct" -binkaudio_dct_decoder_select="mdct rdft dct" -binkaudio_rdft_decoder_select="mdct rdft" +binkaudio_dct_decoder_select="mdct rdft dct sinewin" +binkaudio_rdft_decoder_select="mdct rdft sinewin" cavs_decoder_select="golomb" cook_decoder_select="mdct sinewin" cscd_decoder_suggest="zlib" From 3d2690592577ad4b4318cc7a6dcab63481a5acae Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 4 May 2011 19:17:30 +0200 Subject: [PATCH 21/23] Fix standalone compilation of ac3_fixed encoder. --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index e79bd0ee6e..7b3f5b4745 100755 --- a/configure +++ b/configure @@ -1242,7 +1242,7 @@ aac_encoder_select="mdct sinewin" aac_latm_decoder_select="aac_decoder aac_latm_parser" ac3_decoder_select="mdct ac3dsp ac3_parser" ac3_encoder_select="mdct ac3dsp" -ac3_fixed_encoder_select="ac3dsp" +ac3_fixed_encoder_select="mdct ac3dsp" alac_encoder_select="lpc" amrnb_decoder_select="lsp" amrwb_decoder_select="lsp" From 8799541a0a7bd84c04a2fac73bf819aaf53fc302 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 4 May 2011 19:20:03 +0200 Subject: [PATCH 22/23] Fix standalone compilation of pipe protocol. file_check() is not only used by the file protocol, adjust #ifdef accordingly. --- libavformat/file.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libavformat/file.c b/libavformat/file.c index 6a3ed5acb0..649640a927 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -51,6 +51,19 @@ static int file_get_handle(URLContext *h) return (intptr_t) h->priv_data; } +static int file_check(URLContext *h, int mask) +{ + struct stat st; + int ret = stat(h->filename, &st); + if (ret < 0) + return AVERROR(errno); + + ret |= st.st_mode&S_IRUSR ? mask&AVIO_FLAG_READ : 0; + ret |= st.st_mode&S_IWUSR ? mask&AVIO_FLAG_WRITE : 0; + + return ret; +} + #if CONFIG_FILE_PROTOCOL static int file_open(URLContext *h, const char *filename, int flags) @@ -95,19 +108,6 @@ static int file_close(URLContext *h) return close(fd); } -static int file_check(URLContext *h, int mask) -{ - struct stat st; - int ret = stat(h->filename, &st); - if (ret < 0) - return AVERROR(errno); - - ret |= st.st_mode&S_IRUSR ? mask&AVIO_FLAG_READ : 0; - ret |= st.st_mode&S_IWUSR ? mask&AVIO_FLAG_WRITE : 0; - - return ret; -} - URLProtocol ff_file_protocol = { .name = "file", .url_open = file_open, From af1ca249e8eb685823dd0dade3aa3c1d119a61ec Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 4 May 2011 20:54:53 +0200 Subject: [PATCH 23/23] doc: Check standalone compilation before submitting new components. --- doc/developer.texi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/developer.texi b/doc/developer.texi index ab736d76b2..37b9f3e889 100644 --- a/doc/developer.texi +++ b/doc/developer.texi @@ -299,8 +299,13 @@ send a reminder by email. Your patch should eventually be dealt with. configure? @item Did you @code{git add} the appropriate files before committing? +@item + Did you make sure it compiles standalone, i.e. with + @code{configure --disable-everything --enable-decoder=foo} + (or @code{--enable-demuxer} or whatever your component is)? @end enumerate + @section patch submission checklist @enumerate