From 8d7ec294c4460e8a8c657f2423983b728d7903d4 Mon Sep 17 00:00:00 2001 From: Wolfgang Hesseler Date: Tue, 9 Dec 2003 01:49:56 +0000 Subject: [PATCH] move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler ) cleanups & fixes by me Originally committed as revision 2579 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/avcodec.h | 48 +++++++++++++++++++++++++++- libavcodec/error_resilience.c | 62 ++++++++++++++++++------------------ libavcodec/h263.c | 74 +++++++++++++++++++++---------------------- libavcodec/motion_est.c | 52 +++++++++++++++--------------- libavcodec/mpeg12.c | 60 +++++++++++++++++++++++------------ libavcodec/mpegvideo.c | 59 +++++++++++++++------------------- libavcodec/mpegvideo.h | 28 ---------------- libavcodec/wmv2.c | 8 ++--- 8 files changed, 209 insertions(+), 182 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index a877366..13ab436 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -17,7 +17,7 @@ extern "C" { #define FFMPEG_VERSION_INT 0x000408 #define FFMPEG_VERSION "0.4.8" -#define LIBAVCODEC_BUILD 4694 +#define LIBAVCODEC_BUILD 4695 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT #define LIBAVCODEC_VERSION FFMPEG_VERSION @@ -282,6 +282,30 @@ static const __attribute__((unused)) int Motion_Est_QTab[] = #define CODEC_CAP_PARSE_ONLY 0x0004 #define CODEC_CAP_TRUNCATED 0x0008 +//the following defines might change, so dont expect compatibility if u use them +#define MB_TYPE_INTRA4x4 0x0001 +#define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific +#define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific +#define MB_TYPE_16x16 0x0008 +#define MB_TYPE_16x8 0x0010 +#define MB_TYPE_8x16 0x0020 +#define MB_TYPE_8x8 0x0040 +#define MB_TYPE_INTERLACED 0x0080 +#define MB_TYPE_DIRECT2 0x0100 //FIXME +#define MB_TYPE_ACPRED 0x0200 +#define MB_TYPE_GMC 0x0400 +#define MB_TYPE_SKIP 0x0800 +#define MB_TYPE_P0L0 0x1000 +#define MB_TYPE_P1L0 0x2000 +#define MB_TYPE_P0L1 0x4000 +#define MB_TYPE_P1L1 0x8000 +#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0) +#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1) +#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1) +#define MB_TYPE_QUANT 0x00010000 +#define MB_TYPE_CBP 0x00020000 +//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...) + /** * Pan Scan area. * this specifies the area which should be displayed. Note there may be multiple such areas for one frame @@ -405,6 +429,28 @@ typedef struct AVPanScan{ uint8_t *mbskip_table;\ \ /**\ + * Motion vector table\ + * - encoding: unused\ + * - decoding: set by lavc\ + */\ + int16_t (*motion_val[2])[2];\ +\ + /**\ + * Macroblock type table\ + * mb_type_base + mb_width + 2\ + * - encoding: unused\ + * - decoding: set by lavc\ + */\ + uint32_t *mb_type;\ +\ + /**\ + * Macroblock size: (0->16x16, 1->8x8, 2-> 4x4, 3-> 2x2)\ + * - encoding: unused\ + * - decoding: set by lavc\ + */\ + uint8_t motion_subsample_log2;\ +\ + /**\ * for some private data of the user\ * - encoding: unused\ * - decoding: set by user\ diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index e41a2cf..adec943 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -209,8 +209,8 @@ static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int st int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR); int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR); int offset= b_x*8 + b_y*stride*8; - int16_t *left_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ( b_x <<(1-is_luma))]; - int16_t *right_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ((b_x+1)<<(1-is_luma))]; + int16_t *left_mv= s->current_picture.motion_val[0][s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ( b_x <<(1-is_luma))]; + int16_t *right_mv= s->current_picture.motion_val[0][s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ((b_x+1)<<(1-is_luma))]; if(!(left_damage||right_damage)) continue; // both undamaged @@ -269,8 +269,8 @@ static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int st int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR); int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR); int offset= b_x*8 + b_y*stride*8; - int16_t *top_mv= s->motion_val[s->block_wrap[0]*(( b_y <<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; - int16_t *bottom_mv= s->motion_val[s->block_wrap[0]*(((b_y+1)<<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; + int16_t *top_mv= s->current_picture.motion_val[0][s->block_wrap[0]*(( b_y <<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; + int16_t *bottom_mv= s->current_picture.motion_val[0][s->block_wrap[0]*(((b_y+1)<<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; if(!(top_damage||bottom_damage)) continue; // both undamaged @@ -380,8 +380,8 @@ int score_sum=0; int best_pred=0; const int mot_stride= mb_width*2+2; const int mot_index= mb_x*2 + 1 + (mb_y*2+1)*mot_stride; - int prev_x= s->motion_val[mot_index][0]; - int prev_y= s->motion_val[mot_index][1]; + int prev_x= s->current_picture.motion_val[0][mot_index][0]; + int prev_y= s->current_picture.motion_val[0][mot_index][1]; if((mb_x^mb_y^pass)&1) continue; @@ -406,23 +406,23 @@ int score_sum=0; none_left=0; if(mb_x>0 && fixed[mb_xy-1]){ - mv_predictor[pred_count][0]= s->motion_val[mot_index - 2][0]; - mv_predictor[pred_count][1]= s->motion_val[mot_index - 2][1]; + mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - 2][0]; + mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][1]; pred_count++; } if(mb_x+1motion_val[mot_index + 2][0]; - mv_predictor[pred_count][1]= s->motion_val[mot_index + 2][1]; + mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0]; + mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][1]; pred_count++; } if(mb_y>0 && fixed[mb_xy-mb_stride]){ - mv_predictor[pred_count][0]= s->motion_val[mot_index - mot_stride*2][0]; - mv_predictor[pred_count][1]= s->motion_val[mot_index - mot_stride*2][1]; + mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*2][0]; + mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1]; pred_count++; } if(mb_y+1motion_val[mot_index + mot_stride*2][0]; - mv_predictor[pred_count][1]= s->motion_val[mot_index + mot_stride*2][1]; + mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0]; + mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1]; pred_count++; } if(pred_count==0) continue; @@ -467,8 +467,8 @@ int score_sum=0; pred_count++; /* last MV */ - mv_predictor[pred_count][0]= s->motion_val[mot_index][0]; - mv_predictor[pred_count][1]= s->motion_val[mot_index][1]; + mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0]; + mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1]; pred_count++; s->mv_dir = MV_DIR_FORWARD; @@ -485,8 +485,8 @@ int score_sum=0; int score=0; uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize; - s->motion_val[mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0]; - s->motion_val[mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1]; + s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0]; + s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1]; decode_mb(s); @@ -517,9 +517,9 @@ int score_sum=0; } } score_sum+= best_score; -//FIXME no need to set s->motion_val[mot_index][0] explicit - s->motion_val[mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0]; - s->motion_val[mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1]; +//FIXME no need to set s->current_picture.motion_val[0][mot_index][0] explicit + s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0]; + s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1]; decode_mb(s); @@ -671,12 +671,12 @@ void ff_er_frame_end(MpegEncContext *s){ av_log(s->avctx, AV_LOG_INFO, "concealing errors\n"); - if(s->motion_val == NULL){ + if(s->current_picture.motion_val[0] == NULL){ int size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n"); - s->motion_val= av_mallocz(size * 2 * sizeof(int16_t)); + s->current_picture.motion_val[0]= av_mallocz(size * 2 * sizeof(int16_t)); //FIXME } if(s->avctx->debug&FF_DEBUG_ER){ @@ -843,13 +843,13 @@ void ff_er_frame_end(MpegEncContext *s){ int j; s->mv_type = MV_TYPE_8X8; for(j=0; j<4; j++){ - s->mv[0][j][0] = s->motion_val[ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][0]; - s->mv[0][j][1] = s->motion_val[ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][1]; + s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][0]; + s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][1]; } }else{ s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = s->motion_val[ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][0]; - s->mv[0][0][1] = s->motion_val[ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][1]; + s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][0]; + s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][1]; } s->dsp.clear_blocks(s->block[0]); @@ -882,10 +882,10 @@ void ff_er_frame_end(MpegEncContext *s){ int time_pp= s->pp_time; int time_pb= s->pb_time; - s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp; - s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp; - s->mv[1][0][0] = s->motion_val[xy][0]*(time_pb - time_pp)/time_pp; - s->mv[1][0][1] = s->motion_val[xy][1]*(time_pb - time_pp)/time_pp; + s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp; + s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp; + s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp; + s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp; }else{ s->mv[0][0][0]= 0; s->mv[0][0][1]= 0; diff --git a/libavcodec/h263.c b/libavcodec/h263.c index e9da55c..330d572 100644 --- a/libavcodec/h263.c +++ b/libavcodec/h263.c @@ -526,12 +526,12 @@ int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){ s->mv_type = MV_TYPE_8X8; for(i=0; i<4; i++){ xy= s->block_index[i]; - s->mv[0][i][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; - s->mv[0][i][1] = s->motion_val[xy][1]*time_pb/time_pp + my; - s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->motion_val[xy][0] - : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp; - s->mv[1][i][1] = my ? s->mv[0][i][1] - s->motion_val[xy][1] - : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp; + s->mv[0][i][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp + mx; + s->mv[0][i][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp + my; + s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->next_picture.motion_val[0][xy][0] + : s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp; + s->mv[1][i][1] = my ? s->mv[0][i][1] - s->next_picture.motion_val[0][xy][1] + : s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp; } return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1; } else if(IS_INTERLACED(colocated_mb_type)){ @@ -553,12 +553,12 @@ int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){ } return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED; }else{ - s->mv[0][0][0] = s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; - s->mv[0][0][1] = s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->motion_val[xy][1]*time_pb/time_pp + my; - s->mv[1][0][0] = s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0] - : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp; - s->mv[1][0][1] = s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] - : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp; + s->mv[0][0][0] = s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp + mx; + s->mv[0][0][1] = s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp + my; + s->mv[1][0][0] = s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = mx ? s->mv[0][0][0] - s->next_picture.motion_val[0][xy][0] + : s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp; + s->mv[1][0][1] = s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = my ? s->mv[0][0][1] - s->next_picture.motion_val[0][xy][1] + : s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp; if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample) s->mv_type= MV_TYPE_16X16; else @@ -596,14 +596,14 @@ void ff_h263_update_motion_val(MpegEncContext * s){ } /* no update if 8X8 because it has been done during parsing */ - s->motion_val[xy][0] = motion_x; - s->motion_val[xy][1] = motion_y; - s->motion_val[xy + 1][0] = motion_x; - s->motion_val[xy + 1][1] = motion_y; - s->motion_val[xy + wrap][0] = motion_x; - s->motion_val[xy + wrap][1] = motion_y; - s->motion_val[xy + 1 + wrap][0] = motion_x; - s->motion_val[xy + 1 + wrap][1] = motion_y; + s->current_picture.motion_val[0][xy][0] = motion_x; + s->current_picture.motion_val[0][xy][1] = motion_y; + s->current_picture.motion_val[0][xy + 1][0] = motion_x; + s->current_picture.motion_val[0][xy + 1][1] = motion_y; + s->current_picture.motion_val[0][xy + wrap][0] = motion_x; + s->current_picture.motion_val[0][xy + wrap][1] = motion_y; + s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x; + s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y; } if(s->encoding){ //FIXME encoding MUST be cleaned up @@ -951,8 +951,8 @@ void mpeg4_encode_mb(MpegEncContext * s, /* motion vectors: 8x8 mode*/ h263_pred_motion(s, i, &pred_x, &pred_y); - h263_encode_motion(s, s->motion_val[ s->block_index[i] ][0] - pred_x, s->f_code); - h263_encode_motion(s, s->motion_val[ s->block_index[i] ][1] - pred_y, s->f_code); + h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x, s->f_code); + h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code); } } @@ -1124,8 +1124,8 @@ void h263_encode_mb(MpegEncContext * s, /* motion vectors: 8x8 mode*/ h263_pred_motion(s, i, &pred_x, &pred_y); - motion_x= s->motion_val[ s->block_index[i] ][0]; - motion_y= s->motion_val[ s->block_index[i] ][1]; + motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0]; + motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1]; if (!s->umvplus) { h263_encode_motion(s, motion_x - pred_x, 1); h263_encode_motion(s, motion_y - pred_y, 1); @@ -1480,9 +1480,9 @@ int16_t *h263_pred_motion(MpegEncContext * s, int block, wrap = s->block_wrap[0]; xy = s->block_index[block]; - mot_val = s->motion_val[xy]; + mot_val = s->current_picture.motion_val[0][xy]; - A = s->motion_val[xy - 1]; + A = s->current_picture.motion_val[0][xy - 1]; /* special case for first (slice) line */ if (s->first_slice_line && block<3) { // we cant just change some MVs to simulate that as we need them for the B frames (and ME) @@ -1491,7 +1491,7 @@ int16_t *h263_pred_motion(MpegEncContext * s, int block, if(s->mb_x == s->resync_mb_x){ //rare *px= *py = 0; }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare - C = s->motion_val[xy + off[block] - wrap]; + C = s->current_picture.motion_val[0][xy + off[block] - wrap]; if(s->mb_x==0){ *px = C[0]; *py = C[1]; @@ -1505,7 +1505,7 @@ int16_t *h263_pred_motion(MpegEncContext * s, int block, } }else if(block==1){ if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare - C = s->motion_val[xy + off[block] - wrap]; + C = s->current_picture.motion_val[0][xy + off[block] - wrap]; *px = mid_pred(A[0], 0, C[0]); *py = mid_pred(A[1], 0, C[1]); }else{ @@ -1513,8 +1513,8 @@ int16_t *h263_pred_motion(MpegEncContext * s, int block, *py = A[1]; } }else{ /* block==2*/ - B = s->motion_val[xy - wrap]; - C = s->motion_val[xy + off[block] - wrap]; + B = s->current_picture.motion_val[0][xy - wrap]; + C = s->current_picture.motion_val[0][xy + off[block] - wrap]; if(s->mb_x == s->resync_mb_x) //rare A[0]=A[1]=0; @@ -1522,8 +1522,8 @@ int16_t *h263_pred_motion(MpegEncContext * s, int block, *py = mid_pred(A[1], B[1], C[1]); } } else { - B = s->motion_val[xy - wrap]; - C = s->motion_val[xy + off[block] - wrap]; + B = s->current_picture.motion_val[0][xy - wrap]; + C = s->current_picture.motion_val[0][xy + off[block] - wrap]; *px = mid_pred(A[0], B[0], C[0]); *py = mid_pred(A[1], B[1], C[1]); } @@ -1541,7 +1541,7 @@ int16_t *h263_pred_motion2(MpegEncContext * s, int block, int dir, wrap = s->b8_stride; xy = s->mb_x + s->mb_y * wrap; - mot_val = s->current_picture.motion_val[dir] + xy; + mot_val = s->current_picture.motion_val[0][dir] + xy; A = mot_val[ - 1]; /* special case for first (slice) line */ @@ -3271,7 +3271,7 @@ static int mpeg4_decode_partition_a(MpegEncContext *s){ s->pred_dir_table[xy]= dir; }else{ /* P/S_TYPE */ int mx, my, pred_x, pred_y, bits; - int16_t * const mot_val= s->motion_val[s->block_index[0]]; + int16_t * const mot_val= s->current_picture.motion_val[0][s->block_index[0]]; const int stride= s->block_wrap[0]*2; // do{ //FIXME @@ -3529,8 +3529,8 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64]) if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { int i; for(i=0; i<4; i++){ - s->mv[0][i][0] = s->motion_val[ s->block_index[i] ][0]; - s->mv[0][i][1] = s->motion_val[ s->block_index[i] ][1]; + s->mv[0][i][0] = s->current_picture.motion_val[0][ s->block_index[i] ][0]; + s->mv[0][i][1] = s->current_picture.motion_val[0][ s->block_index[i] ][1]; } s->mb_intra = IS_INTRA(mb_type); @@ -3616,7 +3616,7 @@ static void preview_obmc(MpegEncContext *s){ do{ if (get_bits1(&s->gb)) { /* skip mb */ - mot_val = s->motion_val[ s->block_index[0] ]; + mot_val = s->current_picture.motion_val[0][ s->block_index[0] ]; mot_val[0 ]= mot_val[2 ]= mot_val[0+stride]= mot_val[2+stride]= 0; mot_val[1 ]= mot_val[3 ]= diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index 5a74cb2..1a449ce 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -787,16 +787,16 @@ static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4) if(mv4){ int mot_xy= s->block_index[0]; - s->motion_val[mot_xy ][0]= mx; - s->motion_val[mot_xy ][1]= my; - s->motion_val[mot_xy+1][0]= mx; - s->motion_val[mot_xy+1][1]= my; + s->current_picture.motion_val[0][mot_xy ][0]= mx; + s->current_picture.motion_val[0][mot_xy ][1]= my; + s->current_picture.motion_val[0][mot_xy+1][0]= mx; + s->current_picture.motion_val[0][mot_xy+1][1]= my; mot_xy += s->block_wrap[0]; - s->motion_val[mot_xy ][0]= mx; - s->motion_val[mot_xy ][1]= my; - s->motion_val[mot_xy+1][0]= mx; - s->motion_val[mot_xy+1][1]= my; + s->current_picture.motion_val[0][mot_xy ][0]= mx; + s->current_picture.motion_val[0][mot_xy ][1]= my; + s->current_picture.motion_val[0][mot_xy+1][0]= mx; + s->current_picture.motion_val[0][mot_xy+1][1]= my; } } @@ -852,8 +852,8 @@ static inline int h263_mv4_search(MpegEncContext *s, int xmin, int ymin, int xma const int rel_ymin4= ymin - block_y*8; const int rel_ymax4= ymax - block_y*8 + 8; #endif - P_LEFT[0] = s->motion_val[mot_xy - 1][0]; - P_LEFT[1] = s->motion_val[mot_xy - 1][1]; + P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0]; + P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1]; if(P_LEFT[0] > (rel_xmax4<motion_val[mot_xy - mot_stride ][0]; - P_TOP[1] = s->motion_val[mot_xy - mot_stride ][1]; - P_TOPRIGHT[0] = s->motion_val[mot_xy - mot_stride + off[block]][0]; - P_TOPRIGHT[1] = s->motion_val[mot_xy - mot_stride + off[block]][1]; + P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0]; + P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1]; + P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0]; + P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1]; if(P_TOP[1] > (rel_ymax4< (rel_xmax4<motion_val[ s->block_index[block] ][0]= mx4; - s->motion_val[ s->block_index[block] ][1]= my4; + s->current_picture.motion_val[0][ s->block_index[block] ][0]= mx4; + s->current_picture.motion_val[0][ s->block_index[block] ][1]= my4; if(mx4 != mx || my4 != my) same=0; } @@ -1030,16 +1030,16 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, const int mot_stride = s->block_wrap[0]; const int mot_xy = s->block_index[0]; - P_LEFT[0] = s->motion_val[mot_xy - 1][0]; - P_LEFT[1] = s->motion_val[mot_xy - 1][1]; + P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0]; + P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1]; if(P_LEFT[0] > (rel_xmax<motion_val[mot_xy - mot_stride ][0]; - P_TOP[1] = s->motion_val[mot_xy - mot_stride ][1]; - P_TOPRIGHT[0] = s->motion_val[mot_xy - mot_stride + 2][0]; - P_TOPRIGHT[1] = s->motion_val[mot_xy - mot_stride + 2][1]; + P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0]; + P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1]; + P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0]; + P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1]; if(P_TOP[1] > (rel_ymax< (rel_ymax<block_index[i]; int min, max; - s->me.co_located_mv[i][0]= s->motion_val[index][0]; - s->me.co_located_mv[i][1]= s->motion_val[index][1]; + s->me.co_located_mv[i][0]= s->next_picture.motion_val[0][index][0]; + s->me.co_located_mv[i][1]= s->next_picture.motion_val[0][index][1]; s->me.direct_basis_mv[i][0]= s->me.co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3)); s->me.direct_basis_mv[i][1]= s->me.co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3)); // s->me.direct_basis_mv[1][i][0]= s->me.co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3); @@ -1694,8 +1694,8 @@ void ff_fix_long_p_mvs(MpegEncContext * s) int block; for(block=0; block<4; block++){ int off= (block& 1) + (block>>1)*wrap; - int mx= s->motion_val[ xy + off ][0]; - int my= s->motion_val[ xy + off ][1]; + int mx= s->current_picture.motion_val[0][ xy + off ][0]; + int my= s->current_picture.motion_val[0][ xy + off ][1]; if( mx >=range || mx <-range || my >=range || my <-range){ diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index ed81276..2e2a972 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -2131,32 +2131,50 @@ static int mpeg_decode_slice(AVCodecContext *avctx, dprintf("ret=%d\n", ret); if (ret < 0) return -1; - - if(s->motion_val && s->pict_type != B_TYPE){ //note motion_val is normally NULL unless we want to extract the MVs + + if(s->current_picture.motion_val[0]){ //note motion_val is normally NULL unless we want to extract the MVs const int wrap = s->block_wrap[0]; const int xy = s->mb_x*2 + 1 + (s->mb_y*2 +1)*wrap; - int motion_x, motion_y; - + int motion_for_x, motion_for_y, motion_back_x, motion_back_y; if (s->mb_intra) { - motion_x = motion_y = 0; - }else if (s->mv_type == MV_TYPE_16X16) { - motion_x = s->mv[0][0][0]; - motion_y = s->mv[0][0][1]; - } else /*if (s->mv_type == MV_TYPE_FIELD)*/ { - motion_x = s->mv[0][0][0] + s->mv[0][1][0]; - motion_y = s->mv[0][0][1] + s->mv[0][1][1]; - motion_x = (motion_x>>1) | (motion_x&1); + motion_for_x = motion_for_y = motion_back_x = motion_back_y = 0; + }else if (s->mv_type == MV_TYPE_16X16){ + motion_for_x = s->mv[0][0][0]; + motion_for_y = s->mv[0][0][1]; + motion_back_x = s->mv[1][0][0]; + motion_back_y = s->mv[1][0][1]; + } else /*if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8))*/ { + motion_for_x = s->mv[0][0][0] + s->mv[0][1][0]; + motion_for_y = s->mv[0][0][1] + s->mv[0][1][1]; + motion_for_x = (motion_for_x>>1) | (motion_for_x&1); + motion_back_x = s->mv[1][0][0] + s->mv[1][1][0]; + motion_back_y = s->mv[1][0][1] + s->mv[1][1][1]; + motion_back_x = (motion_back_x>>1) | (motion_back_x&1); + } + + s->current_picture.motion_val[0][xy][0] = motion_for_x; + s->current_picture.motion_val[0][xy][1] = motion_for_y; + s->current_picture.motion_val[0][xy + 1][0] = motion_for_x; + s->current_picture.motion_val[0][xy + 1][1] = motion_for_y; + s->current_picture.motion_val[0][xy + wrap][0] = motion_for_x; + s->current_picture.motion_val[0][xy + wrap][1] = motion_for_y; + s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_for_x; + s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_for_y; + + if(s->pict_type != B_TYPE){ + motion_back_x = motion_back_y = 0; } - s->motion_val[xy][0] = motion_x; - s->motion_val[xy][1] = motion_y; - s->motion_val[xy + 1][0] = motion_x; - s->motion_val[xy + 1][1] = motion_y; - s->motion_val[xy + wrap][0] = motion_x; - s->motion_val[xy + wrap][1] = motion_y; - s->motion_val[xy + 1 + wrap][0] = motion_x; - s->motion_val[xy + 1 + wrap][1] = motion_y; + + s->current_picture.motion_val[1][xy][0] = motion_back_x; + s->current_picture.motion_val[1][xy][1] = motion_back_y; + s->current_picture.motion_val[1][xy + 1][0] = motion_back_x; + s->current_picture.motion_val[1][xy + 1][1] = motion_back_y; + s->current_picture.motion_val[1][xy + wrap][0] = motion_back_x; + s->current_picture.motion_val[1][xy + wrap][1] = motion_back_y; + s->current_picture.motion_val[1][xy + 1 + wrap][0] = motion_back_x; + s->current_picture.motion_val[1][xy + 1 + wrap][1] = motion_back_y; } - + s->dest[0] += 16; s->dest[1] += 8; s->dest[2] += 8; diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 1e5e59b..8c84650 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -316,9 +316,9 @@ static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){ pic->motion_val[i]= pic->motion_val_base[i]+1; CHECKED_ALLOCZ(pic->ref_index[i] , b8_array_size * sizeof(uint8_t)) } - }else if(s->out_format == FMT_H263){ + }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&(FF_DEBUG_VIS_MV|FF_DEBUG_MV))){ for(i=0; i<2; i++){ - CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+1) * sizeof(uint16_t)) + CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+1) * sizeof(uint16_t)*2) //FIXME pic->motion_val[i]= pic->motion_val_base[i]+1; } } @@ -489,14 +489,6 @@ int MPV_common_init(MpegEncContext *s) CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t)) - if (s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_VIS_MV)) { - int size; - - /* MV prediction */ - size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); - CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(int16_t)); - } - if(s->codec_id==CODEC_ID_MPEG4){ /* interlaced direct mode decoding tables */ CHECKED_ALLOCZ(s->field_mv_table, mb_array_size*2*2 * sizeof(int16_t)) @@ -581,7 +573,6 @@ void MPV_common_end(MpegEncContext *s) s->b_bidir_back_mv_table= NULL; s->b_direct_mv_table= NULL; - av_freep(&s->motion_val); av_freep(&s->dc_val[0]); av_freep(&s->ac_val[0]); av_freep(&s->coded_block); @@ -1417,8 +1408,8 @@ void ff_print_debug_info(MpegEncContext *s, Picture *pict){ av_log(s->avctx, AV_LOG_DEBUG, "\n"); } } - - if((s->avctx->debug&FF_DEBUG_VIS_MV) && s->motion_val){ + + if((s->avctx->debug&FF_DEBUG_VIS_MV) && pict->motion_val){ const int shift= 1 + s->quarter_sample; int mb_y; uint8_t *ptr= pict->data[0]; @@ -1428,32 +1419,32 @@ void ff_print_debug_info(MpegEncContext *s, Picture *pict){ int mb_x; for(mb_x=0; mb_xmb_width; mb_x++){ const int mb_index= mb_x + mb_y*s->mb_stride; - if(IS_8X8(s->current_picture.mb_type[mb_index])){ + if(IS_8X8(pict->mb_type[mb_index])){ int i; for(i=0; i<4; i++){ int sx= mb_x*16 + 4 + 8*(i&1); int sy= mb_y*16 + 4 + 8*(i>>1); int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2); - int mx= (s->motion_val[xy][0]>>shift) + sx; - int my= (s->motion_val[xy][1]>>shift) + sy; + int mx= (pict->motion_val[0][xy][0]>>shift) + sx; + int my= (pict->motion_val[0][xy][1]>>shift) + sy; draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); } - }else if(IS_16X8(s->current_picture.mb_type[mb_index])){ + }else if(IS_16X8(pict->mb_type[mb_index])){ int i; for(i=0; i<2; i++){ int sx=mb_x*16 + 8; int sy=mb_y*16 + 4 + 8*i; int xy=1 + mb_x*2 + (mb_y*2 + 1 + i)*(s->mb_width*2 + 2); - int mx=(s->motion_val[xy][0]>>shift) + sx; - int my=(s->motion_val[xy][1]>>shift) + sy; + int mx=(pict->motion_val[0][xy][0]>>shift) + sx; + int my=(pict->motion_val[0][xy][1]>>shift) + sy; draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); } }else{ int sx= mb_x*16 + 8; int sy= mb_y*16 + 8; int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); - int mx= (s->motion_val[xy][0]>>shift) + sx; - int my= (s->motion_val[xy][1]>>shift) + sy; + int mx= (pict->motion_val[0][xy][0]>>shift) + sx; + int my= (pict->motion_val[0][xy][1]>>shift) + sy; draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); } s->mbskip_table[mb_index]=0; @@ -2383,30 +2374,30 @@ static inline void MPV_motion(MpegEncContext *s, assert(!s->mb_skiped); - memcpy(mv_cache[1][1], s->motion_val[mot_xy ], sizeof(int16_t)*4); - memcpy(mv_cache[2][1], s->motion_val[mot_xy+mot_stride], sizeof(int16_t)*4); - memcpy(mv_cache[3][1], s->motion_val[mot_xy+mot_stride], sizeof(int16_t)*4); + memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4); + memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); + memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){ memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4); }else{ - memcpy(mv_cache[0][1], s->motion_val[mot_xy-mot_stride], sizeof(int16_t)*4); + memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4); } if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){ *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1]; *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1]; }else{ - *(int32_t*)mv_cache[1][0]= *(int32_t*)s->motion_val[mot_xy-1]; - *(int32_t*)mv_cache[2][0]= *(int32_t*)s->motion_val[mot_xy-1+mot_stride]; + *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1]; + *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride]; } if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){ *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2]; *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2]; }else{ - *(int32_t*)mv_cache[1][3]= *(int32_t*)s->motion_val[mot_xy+2]; - *(int32_t*)mv_cache[2][3]= *(int32_t*)s->motion_val[mot_xy+2+mot_stride]; + *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2]; + *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride]; } mx = 0; @@ -3694,7 +3685,7 @@ static void encode_picture(MpegEncContext *s, int picture_number) }else /* if(s->pict_type == I_TYPE) */{ /* I-Frame */ //FIXME do we need to zero them? - memset(s->motion_val[0], 0, sizeof(int16_t)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); + memset(s->current_picture.motion_val[0][0], 0, sizeof(int16_t)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); memset(s->p_mv_table , 0, sizeof(int16_t)*(s->mb_stride)*s->mb_height*2); memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_stride*s->mb_height); @@ -3998,8 +3989,8 @@ static void encode_picture(MpegEncContext *s, int picture_number) s->mv_type = MV_TYPE_8X8; s->mb_intra= 0; for(i=0; i<4; i++){ - s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; - s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; + s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; + s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; } encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); @@ -4170,8 +4161,8 @@ static void encode_picture(MpegEncContext *s, int picture_number) s->mv_type = MV_TYPE_8X8; s->mb_intra= 0; for(i=0; i<4; i++){ - s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; - s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; + s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; + s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; } motion_x= motion_y= 0; break; diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 865075d..5aa7e14 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -134,35 +134,9 @@ typedef struct Picture{ * halfpel luma planes. */ uint8_t *interpolated[3]; - int16_t (*motion_val_base[2])[2]; - int16_t (*motion_val[2])[2]; ///< motion_val_base+1, so motion_val[][-1] doesnt segfault int8_t *ref_index[2]; uint32_t *mb_type_base; - uint32_t *mb_type; ///< mb_type_base + mb_width + 2, note: only used for decoding currently -#define MB_TYPE_INTRA4x4 0x0001 -#define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific -#define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific -#define MB_TYPE_16x16 0x0008 -#define MB_TYPE_16x8 0x0010 -#define MB_TYPE_8x16 0x0020 -#define MB_TYPE_8x8 0x0040 -#define MB_TYPE_INTERLACED 0x0080 -#define MB_TYPE_DIRECT2 0x0100 //FIXME -#define MB_TYPE_ACPRED 0x0200 -#define MB_TYPE_GMC 0x0400 -#define MB_TYPE_SKIP 0x0800 -#define MB_TYPE_P0L0 0x1000 -#define MB_TYPE_P1L0 0x2000 -#define MB_TYPE_P0L1 0x4000 -#define MB_TYPE_P1L1 0x8000 -#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0) -#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1) -#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1) -#define MB_TYPE_QUANT 0x00010000 -#define MB_TYPE_CBP 0x00020000 -//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...) - #define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4) #define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16) #define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM) @@ -187,7 +161,6 @@ typedef struct Picture{ #define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note doesnt work if subMBs #define HAS_CBP(a) ((a)&MB_TYPE_CBP) - int field_poc[2]; ///< h264 top/bottom POC int poc; ///< h264 frame POC int frame_num; ///< h264 frame_num @@ -376,7 +349,6 @@ typedef struct MpegEncContext { DSPContext dsp; ///< pointers for accelerated dsp fucntions int f_code; ///< forward MV resolution int b_code; ///< backward MV resolution for B Frames (mpeg4) - int16_t (*motion_val)[2]; int16_t (*p_mv_table_base)[2]; int16_t (*b_forw_mv_table_base)[2]; int16_t (*b_back_mv_table_base)[2]; diff --git a/libavcodec/wmv2.c b/libavcodec/wmv2.c index 3ad09f4..130a7f8 100644 --- a/libavcodec/wmv2.c +++ b/libavcodec/wmv2.c @@ -507,11 +507,11 @@ static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){ wrap = s->block_wrap[0]; xy = s->block_index[0]; - mot_val = s->motion_val[xy]; + mot_val = s->current_picture.motion_val[0][xy]; - A = s->motion_val[xy - 1]; - B = s->motion_val[xy - wrap]; - C = s->motion_val[xy + 2 - wrap]; + A = s->current_picture.motion_val[0][xy - 1]; + B = s->current_picture.motion_val[0][xy - wrap]; + C = s->current_picture.motion_val[0][xy + 2 - wrap]; diff= FFMAX(ABS(A[0] - B[0]), ABS(A[1] - B[1])); -- 2.7.4