From 66370d3fca1ce0628d83ff34f47e11515ff7eb9f Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 12 Sep 2002 12:26:09 +0000 Subject: [PATCH] statistics for forw & back p-MBs instead of just one counter for both Originally committed as revision 925 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/h263.c | 27 +++++++++++++++++---------- libavcodec/mpegvideo.c | 11 +++++++---- libavcodec/mpegvideo.h | 3 ++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/libavcodec/h263.c b/libavcodec/h263.c index 05c0f6a567..a7c6e723ae 100644 --- a/libavcodec/h263.c +++ b/libavcodec/h263.c @@ -18,7 +18,9 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * ac prediction encoding & b-frame support by Michael Niedermayer + * ac prediction encoding, b-frame support, error resilience, optimizations, + * qpel decoding, gmc decoding, interlaced decoding, + * by Michael Niedermayer */ //#define DEBUG @@ -363,6 +365,8 @@ void mpeg4_encode_mb(MpegEncContext * s, case 0: /* direct */ h263_encode_motion(s, motion_x, 1); h263_encode_motion(s, motion_y, 1); + s->b_count++; + s->f_count++; break; case 1: /* bidir */ h263_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code); @@ -373,18 +377,22 @@ void mpeg4_encode_mb(MpegEncContext * s, s->last_mv[0][0][1]= s->mv[0][0][1]; s->last_mv[1][0][0]= s->mv[1][0][0]; s->last_mv[1][0][1]= s->mv[1][0][1]; + s->b_count++; + s->f_count++; break; case 2: /* backward */ h263_encode_motion(s, motion_x - s->last_mv[1][0][0], s->b_code); h263_encode_motion(s, motion_y - s->last_mv[1][0][1], s->b_code); s->last_mv[1][0][0]= motion_x; s->last_mv[1][0][1]= motion_y; + s->b_count++; break; case 3: /* forward */ h263_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); h263_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); s->last_mv[0][0][0]= motion_x; s->last_mv[0][0][1]= motion_y; + s->f_count++; break; default: printf("unknown mb type\n"); @@ -515,7 +523,7 @@ void mpeg4_encode_mb(MpegEncContext * s, s->p_tex_bits+= bits - s->last_bits; s->last_bits=bits; } - s->p_count++; + s->f_count++; } } else { int cbp; @@ -2851,9 +2859,9 @@ int h263_decode_mb(MpegEncContext *s, s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp + my; s->mv[1][0][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0] - : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp + mx; + : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp; s->mv[1][0][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] - : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp + my; + : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp; if(s->non_b_mv4_table[xy]){ int i; s->mv_type = MV_TYPE_8X8; @@ -2862,9 +2870,9 @@ int h263_decode_mb(MpegEncContext *s, 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 + mx; + : 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 + my; + : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp; } PRINT_MB_TYPE("4"); }else{ @@ -2970,7 +2978,7 @@ intra: static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) { - int code, val, sign, shift, l, m; + int code, val, sign, shift, l; code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); if (code < 0) @@ -2991,11 +2999,10 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) /* modulo decoding */ if (!s->h263_long_vectors) { l = (1 << (f_code - 1)) * 32; - m = 2 * l; if (val < -l) { - val += m; + val += l<<1; } else if (val >= l) { - val -= m; + val -= l<<1; } } else { /* horrible h263 long vector mode */ diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 619cf509fe..7be76e0371 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -879,7 +879,7 @@ int MPV_encode_picture(AVCodecContext *avctx, avctx->i_tex_bits = s->i_tex_bits; avctx->p_tex_bits = s->p_tex_bits; avctx->i_count = s->i_count; - avctx->p_count = s->p_count; + avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx avctx->skip_count = s->skip_count; MPV_frame_end(s); @@ -1894,7 +1894,8 @@ static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext d->i_tex_bits= s->i_tex_bits; d->p_tex_bits= s->p_tex_bits; d->i_count= s->i_count; - d->p_count= s->p_count; + d->f_count= s->f_count; + d->b_count= s->b_count; d->skip_count= s->skip_count; d->misc_bits= s->misc_bits; d->last_bits= 0; @@ -1918,7 +1919,8 @@ static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext * d->i_tex_bits= s->i_tex_bits; d->p_tex_bits= s->p_tex_bits; d->i_count= s->i_count; - d->p_count= s->p_count; + d->f_count= s->f_count; + d->b_count= s->b_count; d->skip_count= s->skip_count; d->misc_bits= s->misc_bits; @@ -2118,7 +2120,8 @@ static void encode_picture(MpegEncContext *s, int picture_number) s->i_tex_bits=0; s->p_tex_bits=0; s->i_count=0; - s->p_count=0; + s->f_count=0; + s->b_count=0; s->skip_count=0; /* init last dc values */ diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 611671bf65..7d62e4fc2b 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -301,7 +301,8 @@ typedef struct MpegEncContext { int i_tex_bits; int p_tex_bits; int i_count; - int p_count; + int f_count; + int b_count; int skip_count; int misc_bits; // cbp, mb_type int last_bits; //temp var used for calculating the above vars