[FFmpeg-devel] Dirac Golomb decoder [PATCH]

Michael Niedermayer michaelni
Wed Aug 15 14:03:24 CEST 2007


Hi

On Wed, Aug 15, 2007 at 11:48:20AM +0200, Marco Gerards wrote:
[...]
> >> Or is there something with the code above?  In that case I do not get
> >> it.  This works very different from svq3 so I will not be able to do
> >> the same.
> >
> > indeed it seems i need some sleep ...
> > one obvious optimization though is:
> >
> > if (ff_interleaved_dirac_golomb_vlc_len[buf] != 9){
> >     ret <<= (ff_interleaved_dirac_golomb_vlc_len[buf] - 1) >> 1;
> >     ret |= ff_interleaved_dirac_golomb_vlc_code[buf];
> >     break;
> > }
> > ret= (ret<<4) | ff_interleaved_dirac_golomb_vlc_code[buf];
> 
> Great suggestion, I made this change.
> 
> Hopefully the new patch is ok.  I stopped using SHOW_UBITS, because it
> would be called after GET_CACHE in that case.  So now I just shift the
> buf and update the cache at the end of the while loop.  Would that be
> ok?

yes

[...]
> @@ -75,7 +76,7 @@
>  
>  static inline int svq3_get_ue_golomb(GetBitContext *gb){
>      uint32_t buf;
> -    int log;
> +    int ret = 1;
>  
>      OPEN_READER(re, gb);
>      UPDATE_CACHE(re, gb);
> @@ -88,21 +89,22 @@
>  
>          return ff_interleaved_ue_golomb_vlc_code[buf];
>      }else{

the int ret = 1; can be moved here, which might avoid an uneeded =1 in the
if() case with some (crappy) compilers


[...]

> @@ -192,6 +194,49 @@
>      }
>  }
>  
> +static inline int dirac_get_se_golomb(GetBitContext *gb){
> +    uint32_t buf;
> +    uint32_t ret = 1;
> +
> +    OPEN_READER(re, gb);
> +    UPDATE_CACHE(re, gb);
> +    buf=GET_CACHE(re, gb);
> +
> +    if(buf&0xAA800000){
> +        buf >>= 32 - 8;
> +        LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
> +        CLOSE_READER(re, gb);
> +
> +        ret = ff_interleaved_ue_golomb_vlc_code[buf];
> +    } else {
> +        while (1) {
> +            buf >>= 32 - 8;
> +            LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));
> +
> +            if (ff_interleaved_golomb_vlc_len[buf] != 9){
> +                ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1;
> +                ret |= ff_interleaved_dirac_golomb_vlc_code[buf];
> +                break;
> +            }
> +            ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf];
> +            UPDATE_CACHE(re, gb);
> +            buf = GET_CACHE(re, gb);
> +        }
> +        ret--;
> +    }

if this part is identical to svq3_get_ue_golomb() then simply calling it
might be worth a try, though it might be a little slower due to the
extra OPEN_READER/UPDATE_CACHE
but it does not seem the se code is used in any speed critical parts of
dirac?


> +
> +    if (ret) {
> +        UPDATE_CACHE(re, gb);

> +        buf = SHOW_UBITS(re, gb, 1);
> +        LAST_SKIP_BITS(re, gb, 1);
> +        if (buf)
> +            ret = -ret;

buf = SHOW_SBITS(re, gb, 1);
LAST_SKIP_BITS(re, gb, 1);
ret = (ret^buf)-buf;

(possibly avoids a conditional branch which is quite slow on moderns CPUs)

with these changes iam fine with the patch, you can commit it 
and if you dont have write access then complain to diego

(you also can commit the changes i suggested seperately if you prefer ...)

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

If you really think that XML is the answer, then you definitly missunderstood
the question -- Attila Kinali
-------------- 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/20070815/899773e1/attachment.pgp>



More information about the ffmpeg-devel mailing list