[FFmpeg-soc] [soc]: r484 - in dirac: dirac.c ffmpeg.diff

marco subversion at mplayerhq.hu
Wed Jul 18 20:01:49 CEST 2007


Author: marco
Date: Wed Jul 18 20:01:49 2007
New Revision: 484

Log:
Implemented a more optimal Golomb decoder, properly integrated into golomb.[ch]


Modified:
   dirac/dirac.c
   dirac/ffmpeg.diff

Modified: dirac/dirac.c
==============================================================================
--- dirac/dirac.c	(original)
+++ dirac/dirac.c	Wed Jul 18 20:01:49 2007
@@ -300,26 +300,6 @@ typedef enum {
     subband_hh = 3
 } subband_t;
 
-static int dirac_golomb(GetBitContext *gb) {
-    int val = 1;
-    while (! get_bits (gb, 1)) {
-        val <<= 1;
-        if (get_bits (gb, 1))
-            val++;
-    }
-    val--;
-    return val;
-}
-
-
-static int dirac_golomb_sign(GetBitContext *gb) {
-    int val = dirac_golomb(gb);
-    if (val)
-        if (get_bits(gb, 1))
-            val = -val;
-    return val;
-}
-
 static void dump_sequence_parameters(AVCodecContext *avctx) {
     DiracContext *s = avctx->priv_data;
     struct sequence_parameters *seq = &s->sequence;
@@ -382,13 +362,13 @@ static void parse_sequence_parameters(AV
 
     /* Override the luma dimensions.  */
     if (get_bits(gb, 1)) {
-        s->sequence.luma_width = dirac_golomb(gb);
-        s->sequence.luma_height = dirac_golomb(gb);
+        s->sequence.luma_width = dirac_get_ue_golomb(gb);
+        s->sequence.luma_height = dirac_get_ue_golomb(gb);
     }
 
     /* Override the chroma format.  */
     if (get_bits(gb, 1))
-        s->sequence.chroma_format = dirac_golomb(gb);
+        s->sequence.chroma_format = dirac_get_ue_golomb(gb);
 
     /* Override the chroma dimensions.  */
     switch (s->sequence.chroma_format) {
@@ -413,7 +393,7 @@ static void parse_sequence_parameters(AV
 
     /* Override the video depth.  */
     if (get_bits(gb, 1))
-        s->sequence.video_depth = dirac_golomb(gb);
+        s->sequence.video_depth = dirac_get_ue_golomb(gb);
 }
 
 static void parse_source_parameters(AVCodecContext *avctx) {
@@ -436,10 +416,10 @@ static void parse_source_parameters(AVCo
 
     /* Framerate.  */
     if (get_bits(gb, 1)) {
-        int idx = dirac_golomb(gb);
+        int idx = dirac_get_ue_golomb(gb);
         if (! idx) {
-            s->source.frame_rate.num = dirac_golomb(gb);
-            s->source.frame_rate.den = dirac_golomb(gb);
+            s->source.frame_rate.num = dirac_get_ue_golomb(gb);
+            s->source.frame_rate.den = dirac_get_ue_golomb(gb);
         } else {
             /* Use a pre-set framerate.  */
             s->source.frame_rate = preset_frame_rates[idx - 1];
@@ -448,10 +428,10 @@ static void parse_source_parameters(AVCo
 
     /* Override aspect ratio.  */
     if (get_bits(gb, 1)) {
-        int idx = dirac_golomb(gb);
+        int idx = dirac_get_ue_golomb(gb);
         if (! idx) {
-            s->source.aspect_ratio.num = dirac_golomb(gb);
-            s->source.aspect_ratio.den = dirac_golomb(gb);
+            s->source.aspect_ratio.num = dirac_get_ue_golomb(gb);
+            s->source.aspect_ratio.den = dirac_get_ue_golomb(gb);
         } else {
             /* Use a pre-set aspect ratio.  */
             s->source.aspect_ratio = preset_aspect_ratios[idx - 1];
@@ -460,20 +440,20 @@ static void parse_source_parameters(AVCo
 
     /* Override clean area.  */
     if (get_bits(gb, 1)) {
-        s->source.clean_width = dirac_golomb(gb);
-        s->source.clean_height = dirac_golomb(gb);
-        s->source.clean_left_offset = dirac_golomb(gb);
-        s->source.clean_right_offset = dirac_golomb(gb);
+        s->source.clean_width = dirac_get_ue_golomb(gb);
+        s->source.clean_height = dirac_get_ue_golomb(gb);
+        s->source.clean_left_offset = dirac_get_ue_golomb(gb);
+        s->source.clean_right_offset = dirac_get_ue_golomb(gb);
     }
 
     /* Override signal range.  */
     if (get_bits(gb, 1)) {
-        int idx = dirac_golomb(gb);
+        int idx = dirac_get_ue_golomb(gb);
         if (! idx) {
-            s->source.luma_offset = dirac_golomb(gb);
-            s->source.luma_excursion = dirac_golomb(gb);
-            s->source.chroma_offset = dirac_golomb(gb);
-            s->source.chroma_excursion = dirac_golomb(gb);
+            s->source.luma_offset = dirac_get_ue_golomb(gb);
+            s->source.luma_excursion = dirac_get_ue_golomb(gb);
+            s->source.chroma_offset = dirac_get_ue_golomb(gb);
+            s->source.chroma_excursion = dirac_get_ue_golomb(gb);
         } else {
             /* Use a pre-set signal range.  */
             s->source.luma_offset = preset_luma_offset[idx - 1];
@@ -485,7 +465,7 @@ static void parse_source_parameters(AVCo
 
     /* Color spec.  */
     if (get_bits(gb, 1)) {
-        int idx = dirac_golomb(gb);
+        int idx = dirac_get_ue_golomb(gb);
 
         s->source.color_primaries = preset_primaries[idx];
         s->source.k_r = preset_kr[preset_matrix[idx]];
@@ -497,13 +477,13 @@ static void parse_source_parameters(AVCo
         if (! idx) {
             /* Color primaries.  */
             if (get_bits(gb, 1)) {
-                int primaries_idx = dirac_golomb(gb);
+                int primaries_idx = dirac_get_ue_golomb(gb);
                 s->source.color_primaries = preset_primaries[primaries_idx];
             }
 
             /* Override matrix.  */
             if (get_bits(gb, 1)) {
-                int matrix_idx = dirac_golomb(gb);
+                int matrix_idx = dirac_get_ue_golomb(gb);
 
                 s->source.k_r = preset_kr[preset_matrix[matrix_idx]];
                 s->source.k_b = preset_kb[preset_matrix[matrix_idx]];
@@ -511,7 +491,7 @@ static void parse_source_parameters(AVCo
 
             /* Transfer function.  */
             if (get_bits(gb, 1)) {
-                int transfer_idx = dirac_golomb(gb);
+                int transfer_idx = dirac_get_ue_golomb(gb);
                 s->source.transfer_function = preset_transfer_func[transfer_idx];
             }
         } else {
@@ -531,21 +511,21 @@ static int parse_access_unit_header(AVCo
     /* Parse parameters.  */
     s->next_picture = get_bits_long(gb, 32);
 
-    version_major = dirac_golomb(gb);
-    version_minor = dirac_golomb(gb);
+    version_major = dirac_get_ue_golomb(gb);
+    version_minor = dirac_get_ue_golomb(gb);
     /* XXX: Don't check the version yet, existing encoders do not yet
        set this to a sane value (0.6 at the moment).  */
 
     /* XXX: Not yet documented in the spec.  This is actually the main
        thing that is missing.  */
-    s->profile = dirac_golomb(gb);
-    s->level = dirac_golomb(gb);
+    s->profile = dirac_get_ue_golomb(gb);
+    s->level = dirac_get_ue_golomb(gb);
 
     dprintf (avctx, "Access unit header: Version %d.%d\n",
              version_major, version_minor);
     dprintf (avctx, "Profile: %d, Level: %d\n", s->profile, s->level);
 
-    video_format = dirac_golomb(gb);
+    video_format = dirac_get_ue_golomb(gb);
     dprintf (avctx, "Video format: %d\n", video_format);
 
     /* Fill in defaults for the sequence parameters.  */
@@ -1060,12 +1040,12 @@ static int subband(AVCodecContext *avctx
     int quant;
     int x, y;
 
-    length = dirac_golomb(gb);
+    length = dirac_get_ue_golomb(gb);
     if (! length)
         {
             align_get_bits(gb);
         } else {
-            quant = dirac_golomb(gb);
+            quant = dirac_get_ue_golomb(gb);
 
             arith_init(avctx, gb, length);
 
@@ -1159,10 +1139,10 @@ static int parse_frame(AVCodecContext *a
     s->picture.reference = 0;
 
     picnum = get_bits_long(gb, 32);
-    retire = dirac_golomb(gb);
+    retire = dirac_get_ue_golomb(gb);
 
     for (i = 0; i < retire; i++)
-        dirac_golomb_sign(gb); /* XXX */
+        dirac_get_se_golomb(gb); /* XXX */
 
     dprintf (avctx, "Picture #%d, retire: %d\n", picnum, retire);
 
@@ -1174,7 +1154,7 @@ static int parse_frame(AVCodecContext *a
     /* Override wavelet transform parameters.  */
     if (get_bits(gb, 1)) {
         dprintf (avctx, "Non default filter\n");
-        filter = dirac_golomb(gb);
+        filter = dirac_get_ue_golomb(gb);
     } else {
         dprintf (avctx, "Default filter\n");
         filter = s->frame_decoding.wavelet_idx_intra;
@@ -1190,7 +1170,7 @@ static int parse_frame(AVCodecContext *a
     /* Overrid wavelet depth.  */
     if (get_bits(gb, 1)) {
         dprintf (avctx, "Non default depth\n");
-        s->frame_decoding.wavelet_depth = dirac_golomb(gb);
+        s->frame_decoding.wavelet_depth = dirac_get_ue_golomb(gb);
     }
     dprintf(avctx, "Depth: %d\n", s->frame_decoding.wavelet_depth);
 
@@ -1203,8 +1183,8 @@ static int parse_frame(AVCodecContext *a
         /* Override the default partitioning.  */
         if (get_bits(gb, 1)) {
             for (i = 0; i <= s->frame_decoding.wavelet_depth; i++) {
-                s->codeblocksh[i] = dirac_golomb(gb);
-                s->codeblocksv[i] = dirac_golomb(gb);
+                s->codeblocksh[i] = dirac_get_ue_golomb(gb);
+                s->codeblocksv[i] = dirac_get_ue_golomb(gb);
             }
 
             dprintf (avctx, "Non-default partitioning\n");
@@ -1221,7 +1201,7 @@ static int parse_frame(AVCodecContext *a
             }
         }
 
-        idx = dirac_golomb(gb);
+        idx = dirac_get_ue_golomb(gb);
         dprintf(avctx, "Codeblock mode idx: %d\n", idx);
         /* XXX: Here 0, so single quant.  */
     }

Modified: dirac/ffmpeg.diff
==============================================================================
--- dirac/ffmpeg.diff	(original)
+++ dirac/ffmpeg.diff	Wed Jul 18 20:01:49 2007
@@ -1,6 +1,157 @@
+Index: libavcodec/golomb.c
+===================================================================
+--- libavcodec/golomb.c	(revision 9734)
++++ libavcodec/golomb.c	(working copy)
+@@ -1,6 +1,7 @@
+ /*
+  * exp golomb vlc stuff
+  * Copyright (c) 2003 Michael Niedermayer <michaelni at gmx.at>
++ * Copyright (c) 2007 Marco Gerards <marco at gnu.org>
+  *
+  * This file is part of FFmpeg.
+  *
+@@ -23,7 +24,7 @@
+  * @file golomb.c
+  * @brief
+  *     exp golomb vlc stuff
+- * @author Michael Niedermayer <michaelni at gmx.at>
++ * @author Michael Niedermayer <michaelni at gmx.at> and Marco Gerards <marco at gnu.org>
+  */
+ 
+ #include "common.h"
+@@ -153,3 +154,39 @@
+   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+ };
++
++const uint8_t ff_interleaved_dirac_golomb_vlc_len[256]={
++9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
++9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
++3,3,3,3,3,3,3,3,3,3,3,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, 0, 0, 
++0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
++0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
++0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
++0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
++0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
+Index: libavcodec/golomb.h
+===================================================================
+--- libavcodec/golomb.h	(revision 9734)
++++ libavcodec/golomb.h	(working copy)
+@@ -2,6 +2,7 @@
+  * exp golomb vlc stuff
+  * Copyright (c) 2003 Michael Niedermayer <michaelni at gmx.at>
+  * Copyright (c) 2004 Alex Beregszaszi
++ * Copyright (c) 2007 Marco Gerards <marco at gnu.org>
+  *
+  * This file is part of FFmpeg.
+  *
+@@ -24,7 +25,7 @@
+  * @file golomb.h
+  * @brief
+  *     exp golomb vlc stuff
+- * @author Michael Niedermayer <michaelni at gmx.at> and Alex Beregszaszi
++ * @author Michael Niedermayer <michaelni at gmx.at>, Alex Beregszaszi and Marco Gerards
+  */
+ 
+ #ifndef AVCODEC_GOLOMB_H
+@@ -43,6 +44,8 @@
+ extern const uint8_t ff_interleaved_golomb_vlc_len[256];
+ extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256];
+ extern const  int8_t ff_interleaved_se_golomb_vlc_code[256];
++extern const uint8_t ff_interleaved_dirac_golomb_vlc_len[256];
++extern const uint8_t ff_interleaved_dirac_golomb_vlc_code[256];
+ 
+ 
+  /**
+@@ -106,6 +109,59 @@
+     }
+ }
+ 
++static inline int dirac_get_ue_golomb(GetBitContext *gb){
++    uint32_t buf;
++    uint32_t ret = 1;
++
++    OPEN_READER(re, gb);
++    while (1) {
++        UPDATE_CACHE(re, gb);
++        buf = GET_CACHE(re, gb);
++
++        buf >>= 32 - 8;
++        LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_dirac_golomb_vlc_len[buf], 8));
++
++        ret <<= (ff_interleaved_dirac_golomb_vlc_len[buf] - 1) >> 1;
++        ret |= ff_interleaved_dirac_golomb_vlc_code[buf];
++        if (ff_interleaved_dirac_golomb_vlc_len[buf] != 9)
++            break;
++    }
++    CLOSE_READER(re, gb);
++
++    return ret - 1;
++}
++
++static inline int dirac_get_se_golomb(GetBitContext *gb){
++    uint32_t buf;
++    uint32_t ret = 1;
++
++    OPEN_READER(re, gb);
++    while (1) {
++        UPDATE_CACHE(re, gb);
++
++        buf = GET_CACHE(re, gb);
++        buf >>= 32 - 8;
++        LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_dirac_golomb_vlc_len[buf], 8));
++
++        ret <<= (ff_interleaved_dirac_golomb_vlc_len[buf] - 1) >> 1;
++        ret |= ff_interleaved_dirac_golomb_vlc_code[buf];
++        if (ff_interleaved_dirac_golomb_vlc_len[buf] != 9)
++            break;
++    }
++    ret--;
++
++    buf = GET_CACHE(re, gb);
++    if (ret) {
++        LAST_SKIP_BITS(re, gb, 1);
++        if (buf & 0x80000000)
++            ret = -ret;
++    }
++
++    CLOSE_READER(re, gb);
++
++    return ret;
++}
++
+ /**
+  * read unsigned truncated exp golomb code.
+  */
 Index: libavcodec/Makefile
 ===================================================================
---- libavcodec/Makefile	(revision 9599)
+--- libavcodec/Makefile	(revision 9734)
 +++ libavcodec/Makefile	(working copy)
 @@ -52,6 +52,7 @@
  OBJS-$(CONFIG_CSCD_DECODER)            += cscd.o
@@ -10,7 +161,7 @@ Index: libavcodec/Makefile
  OBJS-$(CONFIG_DNXHD_DECODER)           += dnxhddec.o
  OBJS-$(CONFIG_DSICINVIDEO_DECODER)     += dsicinav.o
  OBJS-$(CONFIG_DSICINAUDIO_DECODER)     += dsicinav.o
-@@ -304,6 +305,7 @@
+@@ -305,6 +306,7 @@
  OBJS-$(CONFIG_AC3_PARSER)              += ac3_parser.o ac3tab.o aac_ac3_parser.o
  OBJS-$(CONFIG_CAVSVIDEO_PARSER)        += cavs_parser.o
  OBJS-$(CONFIG_DCA_PARSER)              += dca_parser.o
@@ -20,7 +171,7 @@ Index: libavcodec/Makefile
  OBJS-$(CONFIG_H261_PARSER)             += h261_parser.o
 Index: libavcodec/allcodecs.c
 ===================================================================
---- libavcodec/allcodecs.c	(revision 9599)
+--- libavcodec/allcodecs.c	(revision 9734)
 +++ libavcodec/allcodecs.c	(working copy)
 @@ -68,6 +68,7 @@
      REGISTER_DECODER(CLJR, cljr);
@@ -40,7 +191,7 @@ Index: libavcodec/allcodecs.c
      REGISTER_PARSER (H261, h261);
 Index: libavcodec/allcodecs.h
 ===================================================================
---- libavcodec/allcodecs.h	(revision 9599)
+--- libavcodec/allcodecs.h	(revision 9734)
 +++ libavcodec/allcodecs.h	(working copy)
 @@ -92,6 +92,7 @@
  extern AVCodec cscd_decoder;
@@ -52,7 +203,7 @@ Index: libavcodec/allcodecs.h
  extern AVCodec dsicinvideo_decoder;
 Index: libavcodec/avcodec.h
 ===================================================================
---- libavcodec/avcodec.h	(revision 9599)
+--- libavcodec/avcodec.h	(revision 9734)
 +++ libavcodec/avcodec.h	(working copy)
 @@ -166,6 +166,7 @@
      CODEC_ID_BETHSOFTVID,
@@ -72,7 +223,7 @@ Index: libavcodec/avcodec.h
  extern AVCodecParser h261_parser;
 Index: libavformat/Makefile
 ===================================================================
---- libavformat/Makefile	(revision 9599)
+--- libavformat/Makefile	(revision 9734)
 +++ libavformat/Makefile	(working copy)
 @@ -36,6 +36,7 @@
  OBJS-$(CONFIG_CRC_MUXER)                 += crc.o
@@ -84,7 +235,7 @@ Index: libavformat/Makefile
  OBJS-$(CONFIG_DV_DEMUXER)                += dv.o
 Index: libavformat/raw.c
 ===================================================================
---- libavformat/raw.c	(revision 9599)
+--- libavformat/raw.c	(revision 9734)
 +++ libavformat/raw.c	(working copy)
 @@ -316,6 +316,7 @@
          av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
@@ -130,7 +281,7 @@ Index: libavformat/raw.c
      "raw dts",
 Index: libavformat/allformats.c
 ===================================================================
---- libavformat/allformats.c	(revision 9599)
+--- libavformat/allformats.c	(revision 9734)
 +++ libavformat/allformats.c	(working copy)
 @@ -66,6 +66,7 @@
      REGISTER_MUXER   (CRC, crc);
@@ -142,7 +293,7 @@ Index: libavformat/allformats.c
      REGISTER_MUXDEMUX(DV, dv);
 Index: libavformat/allformats.h
 ===================================================================
---- libavformat/allformats.h	(revision 9599)
+--- libavformat/allformats.h	(revision 9734)
 +++ libavformat/allformats.h	(working copy)
 @@ -39,6 +39,7 @@
  extern AVInputFormat c93_demuxer;



More information about the FFmpeg-soc mailing list