comparison mpegvideo.c @ 1938:e2501e6e7ff7 libavcodec

unify table indexing (motion_val,dc_val,ac_val,coded_block changed) minor +-1 bugfix
author michael
date Fri, 16 Apr 2004 01:01:45 +0000
parents ea20f38b8d57
children a3f44c9168aa
comparison
equal deleted inserted replaced
1937:4d91a9342d95 1938:e2501e6e7ff7
273 static void copy_picture(Picture *dst, Picture *src){ 273 static void copy_picture(Picture *dst, Picture *src){
274 *dst = *src; 274 *dst = *src;
275 dst->type= FF_BUFFER_TYPE_COPY; 275 dst->type= FF_BUFFER_TYPE_COPY;
276 } 276 }
277 277
278 static void copy_picture_attributes(AVFrame *dst, AVFrame *src){ 278 static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){
279 int i;
280
279 dst->pict_type = src->pict_type; 281 dst->pict_type = src->pict_type;
280 dst->quality = src->quality; 282 dst->quality = src->quality;
281 dst->coded_picture_number = src->coded_picture_number; 283 dst->coded_picture_number = src->coded_picture_number;
282 dst->display_picture_number = src->display_picture_number; 284 dst->display_picture_number = src->display_picture_number;
283 // dst->reference = src->reference; 285 // dst->reference = src->reference;
284 dst->pts = src->pts; 286 dst->pts = src->pts;
285 dst->interlaced_frame = src->interlaced_frame; 287 dst->interlaced_frame = src->interlaced_frame;
286 dst->top_field_first = src->top_field_first; 288 dst->top_field_first = src->top_field_first;
289
290 if(src->motion_val[0] && src->motion_val[0] != dst->motion_val[0]){
291 if(src->motion_subsample_log2 != dst->motion_subsample_log2)
292 av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesnt match!\n");
293 else{
294 int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1;
295 int height= ((16*s->mb_height)>>src->motion_subsample_log2);
296
297 for(i=0; i<2; i++)
298 memcpy(dst->motion_val[i], src->motion_val[i], stride*height*sizeof(int16_t));
299 }
300 }
287 } 301 }
288 302
289 /** 303 /**
290 * allocates a Picture 304 * allocates a Picture
291 * The pixels are allocated/set by calling get_buffer() if shared=0 305 * The pixels are allocated/set by calling get_buffer() if shared=0
345 CHECKED_ALLOCZ(pic->ref_index[i] , b8_array_size * sizeof(uint8_t)) 359 CHECKED_ALLOCZ(pic->ref_index[i] , b8_array_size * sizeof(uint8_t))
346 } 360 }
347 pic->motion_subsample_log2= 2; 361 pic->motion_subsample_log2= 2;
348 }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){ 362 }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
349 for(i=0; i<2; i++){ 363 for(i=0; i<2; i++){
350 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+2) * sizeof(int16_t)*2) //FIXME 364 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+2) * sizeof(int16_t))
351 pic->motion_val[i]= pic->motion_val_base[i]+2; 365 pic->motion_val[i]= pic->motion_val_base[i]+2;
352 } 366 }
353 pic->motion_subsample_log2= 3; 367 pic->motion_subsample_log2= 3;
354 } 368 }
355 if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { 369 if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
589 s->mb_num = s->mb_width * s->mb_height; 603 s->mb_num = s->mb_width * s->mb_height;
590 604
591 s->block_wrap[0]= 605 s->block_wrap[0]=
592 s->block_wrap[1]= 606 s->block_wrap[1]=
593 s->block_wrap[2]= 607 s->block_wrap[2]=
594 s->block_wrap[3]= s->mb_width*2 + 2; 608 s->block_wrap[3]= s->b8_stride;
595 s->block_wrap[4]= 609 s->block_wrap[4]=
596 s->block_wrap[5]= s->mb_width + 2; 610 s->block_wrap[5]= s->mb_stride;
597 611
598 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); 612 y_size = s->b8_stride * (2 * s->mb_height + 1);
599 c_size = (s->mb_width + 2) * (s->mb_height + 2); 613 c_size = s->mb_stride * (s->mb_height + 1);
600 yc_size = y_size + 2 * c_size; 614 yc_size = y_size + 2 * c_size;
601 615
602 /* convert fourcc to upper case */ 616 /* convert fourcc to upper case */
603 s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF) 617 s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF)
604 + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 ) 618 + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 )
676 CHECKED_ALLOCZ(s->p_field_select_table[i] , mb_array_size * 2 * sizeof(uint8_t)) 690 CHECKED_ALLOCZ(s->p_field_select_table[i] , mb_array_size * 2 * sizeof(uint8_t))
677 } 691 }
678 } 692 }
679 if (s->out_format == FMT_H263) { 693 if (s->out_format == FMT_H263) {
680 /* ac values */ 694 /* ac values */
681 CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(int16_t) * 16); 695 CHECKED_ALLOCZ(s->ac_val_base, yc_size * sizeof(int16_t) * 16);
682 s->ac_val[1] = s->ac_val[0] + y_size; 696 s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
697 s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
683 s->ac_val[2] = s->ac_val[1] + c_size; 698 s->ac_val[2] = s->ac_val[1] + c_size;
684 699
685 /* cbp values */ 700 /* cbp values */
686 CHECKED_ALLOCZ(s->coded_block, y_size); 701 CHECKED_ALLOCZ(s->coded_block_base, y_size);
702 s->coded_block= s->coded_block_base + s->b8_stride + 1;
687 703
688 /* divx501 bitstream reorder buffer */ 704 /* divx501 bitstream reorder buffer */
689 CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE); 705 CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE);
690 706
691 /* cbp, ac_pred, pred_dir */ 707 /* cbp, ac_pred, pred_dir */
694 } 710 }
695 711
696 if (s->h263_pred || s->h263_plus || !s->encoding) { 712 if (s->h263_pred || s->h263_plus || !s->encoding) {
697 /* dc values */ 713 /* dc values */
698 //MN: we need these for error resilience of intra-frames 714 //MN: we need these for error resilience of intra-frames
699 CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(int16_t)); 715 CHECKED_ALLOCZ(s->dc_val_base, yc_size * sizeof(int16_t));
700 s->dc_val[1] = s->dc_val[0] + y_size; 716 s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
717 s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
701 s->dc_val[2] = s->dc_val[1] + c_size; 718 s->dc_val[2] = s->dc_val[1] + c_size;
702 for(i=0;i<yc_size;i++) 719 for(i=0;i<yc_size;i++)
703 s->dc_val[0][i] = 1024; 720 s->dc_val_base[i] = 1024;
704 } 721 }
705 722
706 /* which mb is a intra block */ 723 /* which mb is a intra block */
707 CHECKED_ALLOCZ(s->mbintra_table, mb_array_size); 724 CHECKED_ALLOCZ(s->mbintra_table, mb_array_size);
708 memset(s->mbintra_table, 1, mb_array_size); 725 memset(s->mbintra_table, 1, mb_array_size);
779 s->p_field_mv_table[i][j]=NULL; 796 s->p_field_mv_table[i][j]=NULL;
780 } 797 }
781 av_freep(&s->p_field_select_table[i]); 798 av_freep(&s->p_field_select_table[i]);
782 } 799 }
783 800
784 av_freep(&s->dc_val[0]); 801 av_freep(&s->dc_val_base);
785 av_freep(&s->ac_val[0]); 802 av_freep(&s->ac_val_base);
786 av_freep(&s->coded_block); 803 av_freep(&s->coded_block_base);
787 av_freep(&s->mbintra_table); 804 av_freep(&s->mbintra_table);
788 av_freep(&s->cbp_table); 805 av_freep(&s->cbp_table);
789 av_freep(&s->pred_dir_table); 806 av_freep(&s->pred_dir_table);
790 807
791 av_freep(&s->mbskip_table); 808 av_freep(&s->mbskip_table);
1682 break; 1699 break;
1683 } 1700 }
1684 if(!USES_LIST(pict->mb_type[mb_index], direction)) 1701 if(!USES_LIST(pict->mb_type[mb_index], direction))
1685 continue; 1702 continue;
1686 1703
1704 //FIXME for h264
1687 if(IS_8X8(pict->mb_type[mb_index])){ 1705 if(IS_8X8(pict->mb_type[mb_index])){
1688 int i; 1706 int i;
1689 for(i=0; i<4; i++){ 1707 for(i=0; i<4; i++){
1690 int sx= mb_x*16 + 4 + 8*(i&1); 1708 int sx= mb_x*16 + 4 + 8*(i&1);
1691 int sy= mb_y*16 + 4 + 8*(i>>1); 1709 int sy= mb_y*16 + 4 + 8*(i>>1);
1692 int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2); 1710 int xy= mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride;
1693 int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; 1711 int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
1694 int my= (pict->motion_val[direction][xy][1]>>shift) + sy; 1712 int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
1695 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); 1713 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
1696 } 1714 }
1697 }else if(IS_16X8(pict->mb_type[mb_index])){ 1715 }else if(IS_16X8(pict->mb_type[mb_index])){
1698 int i; 1716 int i;
1699 for(i=0; i<2; i++){ 1717 for(i=0; i<2; i++){
1700 int sx=mb_x*16 + 8; 1718 int sx=mb_x*16 + 8;
1701 int sy=mb_y*16 + 4 + 8*i; 1719 int sy=mb_y*16 + 4 + 8*i;
1702 int xy=1 + mb_x*2 + (mb_y*2 + 1 + i)*(s->mb_width*2 + 2); 1720 int xy= mb_x*2 + (mb_y*2 + i)*s->b8_stride;
1703 int mx=(pict->motion_val[direction][xy][0]>>shift) + sx; 1721 int mx=(pict->motion_val[direction][xy][0]>>shift) + sx;
1704 int my=(pict->motion_val[direction][xy][1]>>shift) + sy; 1722 int my=(pict->motion_val[direction][xy][1]>>shift) + sy;
1705 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); 1723 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
1706 } 1724 }
1707 }else{ 1725 }else{
1708 int sx= mb_x*16 + 8; 1726 int sx= mb_x*16 + 8;
1709 int sy= mb_y*16 + 8; 1727 int sy= mb_y*16 + 8;
1710 int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); 1728 int xy= mb_x*2 + mb_y*2*s->b8_stride;
1711 int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; 1729 int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
1712 int my= (pict->motion_val[direction][xy][1]>>shift) + sy; 1730 int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
1713 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); 1731 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
1714 } 1732 }
1715 } 1733 }
1882 } 1900 }
1883 } 1901 }
1884 } 1902 }
1885 } 1903 }
1886 } 1904 }
1887 copy_picture_attributes(pic, pic_arg); 1905 copy_picture_attributes(s, pic, pic_arg);
1888 1906
1889 pic->display_picture_number= s->input_picture_number++; 1907 pic->display_picture_number= s->input_picture_number++;
1890 if(pic->pts != AV_NOPTS_VALUE){ 1908 if(pic->pts != AV_NOPTS_VALUE){
1891 s->user_specified_pts= pic->pts; 1909 s->user_specified_pts= pic->pts;
1892 }else{ 1910 }else{
2011 /* mark us unused / free shared pic */ 2029 /* mark us unused / free shared pic */
2012 for(i=0; i<4; i++) 2030 for(i=0; i<4; i++)
2013 s->reordered_input_picture[0]->data[i]= NULL; 2031 s->reordered_input_picture[0]->data[i]= NULL;
2014 s->reordered_input_picture[0]->type= 0; 2032 s->reordered_input_picture[0]->type= 0;
2015 2033
2016 copy_picture_attributes((AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]); 2034 copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]);
2017 pic->reference = s->reordered_input_picture[0]->reference; 2035 pic->reference = s->reordered_input_picture[0]->reference;
2018 2036
2019 alloc_picture(s, pic, 0); 2037 alloc_picture(s, pic, 0);
2020 2038
2021 s->current_picture_ptr= pic; 2039 s->current_picture_ptr= pic;
2744 mb_y = s->mb_y; 2762 mb_y = s->mb_y;
2745 2763
2746 if(s->obmc && s->pict_type != B_TYPE){ 2764 if(s->obmc && s->pict_type != B_TYPE){
2747 int16_t mv_cache[4][4][2]; 2765 int16_t mv_cache[4][4][2];
2748 const int xy= s->mb_x + s->mb_y*s->mb_stride; 2766 const int xy= s->mb_x + s->mb_y*s->mb_stride;
2749 const int mot_stride= s->mb_width*2 + 2; 2767 const int mot_stride= s->b8_stride;
2750 const int mot_xy= 1 + mb_x*2 + (mb_y*2 + 1)*mot_stride; 2768 const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
2751 2769
2752 assert(!s->mb_skiped); 2770 assert(!s->mb_skiped);
2753 2771
2754 memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4); 2772 memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4);
2755 memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); 2773 memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
3001 /** 3019 /**
3002 * cleans dc, ac, coded_block for the current non intra MB 3020 * cleans dc, ac, coded_block for the current non intra MB
3003 */ 3021 */
3004 void ff_clean_intra_table_entries(MpegEncContext *s) 3022 void ff_clean_intra_table_entries(MpegEncContext *s)
3005 { 3023 {
3006 int wrap = s->block_wrap[0]; 3024 int wrap = s->b8_stride;
3007 int xy = s->block_index[0]; 3025 int xy = s->block_index[0];
3008 3026
3009 s->dc_val[0][xy ] = 3027 s->dc_val[0][xy ] =
3010 s->dc_val[0][xy + 1 ] = 3028 s->dc_val[0][xy + 1 ] =
3011 s->dc_val[0][xy + wrap] = 3029 s->dc_val[0][xy + wrap] =
3018 s->coded_block[xy + 1 ] = 3036 s->coded_block[xy + 1 ] =
3019 s->coded_block[xy + wrap] = 3037 s->coded_block[xy + wrap] =
3020 s->coded_block[xy + 1 + wrap] = 0; 3038 s->coded_block[xy + 1 + wrap] = 0;
3021 } 3039 }
3022 /* chroma */ 3040 /* chroma */
3023 wrap = s->block_wrap[4]; 3041 wrap = s->mb_stride;
3024 xy = s->mb_x + 1 + (s->mb_y + 1) * wrap; 3042 xy = s->mb_x + s->mb_y * wrap;
3025 s->dc_val[1][xy] = 3043 s->dc_val[1][xy] =
3026 s->dc_val[2][xy] = 1024; 3044 s->dc_val[2][xy] = 1024;
3027 /* ac pred */ 3045 /* ac pred */
3028 memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t)); 3046 memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
3029 memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t)); 3047 memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
3030 3048
3031 s->mbintra_table[s->mb_x + s->mb_y*s->mb_stride]= 0; 3049 s->mbintra_table[xy]= 0;
3032 } 3050 }
3033 3051
3034 /* generic function called after a macroblock has been parsed by the 3052 /* generic function called after a macroblock has been parsed by the
3035 decoder or after it has been encoded by the encoder. 3053 decoder or after it has been encoded by the encoder.
3036 3054
3346 3364
3347 void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename 3365 void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
3348 const int linesize= s->current_picture.linesize[0]; //not s->linesize as this woulnd be wrong for field pics 3366 const int linesize= s->current_picture.linesize[0]; //not s->linesize as this woulnd be wrong for field pics
3349 const int uvlinesize= s->current_picture.linesize[1]; 3367 const int uvlinesize= s->current_picture.linesize[1];
3350 3368
3351 s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1 + s->mb_x*2; 3369 s->block_index[0]= s->b8_stride*(s->mb_y*2 ) - 2 + s->mb_x*2;
3352 s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1) + s->mb_x*2; 3370 s->block_index[1]= s->b8_stride*(s->mb_y*2 ) - 1 + s->mb_x*2;
3353 s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1 + s->mb_x*2; 3371 s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2;
3354 s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2) + s->mb_x*2; 3372 s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
3355 s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x; 3373 s->block_index[4]= s->mb_stride*(s->mb_y + 1) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
3356 s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x; 3374 s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
3357 3375
3358 if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME){ 3376 if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME){
3359 s->dest[0] = s->current_picture.data[0] + s->mb_x * 16 - 16; 3377 s->dest[0] = s->current_picture.data[0] + s->mb_x * 16 - 16;
3360 s->dest[1] = s->current_picture.data[1] + s->mb_x * 8 - 8; 3378 s->dest[1] = s->current_picture.data[1] + s->mb_x * 8 - 8;
3361 s->dest[2] = s->current_picture.data[2] + s->mb_x * 8 - 8; 3379 s->dest[2] = s->current_picture.data[2] + s->mb_x * 8 - 8;