[FFmpeg-devel] [PATCH] avoid mb_xy recalculation in h264

Michael Niedermayer michaelni
Wed May 7 14:53:06 CEST 2008


On Wed, May 07, 2008 at 03:05:47AM -0400, Alexander Strange wrote:
> This line appears in a lot of h264.c functions:
> const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
>
> It only changes once per MB, so we can add it to the context and only 
> recalculate it in decode_slice().
> I put it at the end of H264Context, but it could be moved up earlier if 
> someone likes it there. The position doesn't seem to affect performance 
> much; it can't be moved next to mb_x/mb_y since that would put it in 
> MpegEncContext, and none of the other codecs use it.
>
> Patches:
> 1- does that, updating it for MBAFF when needed
> 2- removes some newly unused variables
> 3- does the same thing to svq3.c
>
> Before: avg 8.799s max 8.8s min 8.794s
> After: avg 8.645s max 8.651s min 8.641s

Knowing the cpu and compiler would also be usefull.

[...]
> @@ -6790,14 +6790,18 @@
>  
>          for(;;){
>  //START_TIMER
> -            int ret = decode_mb_cabac(h);
> +            int ret;
>              int eos;
> +
> +            h->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
> +            ret = decode_mb_cabac(h);
>  //STOP_TIMER("decode_mb_cabac")
>  
>              if(ret>=0) hl_decode_mb(h);
>  
>              if( ret >= 0 && FRAME_MBAFF ) { //FIXME optimal? or let mb_decode decode 16x32 ?
>                  s->mb_y++;
> +                h->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
>  
>                  if(ret>=0) ret = decode_mb_cabac(h);
>  
> @@ -6830,12 +6834,17 @@
>  
>      } else {
>          for(;;){
> -            int ret = decode_mb_cavlc(h);
> +            int ret;
> +
> +            h->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
> +            ret = decode_mb_cavlc(h);
>  
>              if(ret>=0) hl_decode_mb(h);
>  
>              if(ret>=0 && FRAME_MBAFF){ //FIXME optimal? or let mb_decode decode 16x32 ?
>                  s->mb_y++;
> +                h->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
> +
>                  ret = decode_mb_cavlc(h);

the mb_xy init can be moved into decode_mb_ca*()

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored awnser#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080507/3491085b/attachment.pgp>



More information about the ffmpeg-devel mailing list