[Ffmpeg-devel] [PATCH] H264 cabac vlc reading code

Michael Niedermayer michaelni
Fri Oct 13 15:43:46 CEST 2006


Hi

the attached patch contains some generic "non binary"/"vlc" cabac 
reading code, sadly its slower, thats why i post it here instead of
commiting it ;)

maybe its usefull for someone or someone has an idea how to make it
faster

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is
-------------- next part --------------
Index: libavcodec/h264.c
===================================================================
--- libavcodec/h264.c	(revision 6675)
+++ libavcodec/h264.c	(working copy)
@@ -5636,10 +5636,38 @@
     return get_cabac_noinline( &h->cabac, &h->cabac_state[70 + ctx] );
 }
 
+static const CABACVLC intra_mb_type_i_vlc[]={
+    {1,-24},
+    {2,-8},
+    {4,-4},{5,-2},{0, 1},{0, 2},{5,-2},{0, 3},{0, 4},
+    {3,-8},
+    {4,-4},{5,-2},{0, 5},{0, 6},{5,-2},{0, 7},{0, 8},
+    {4,-4},{5,-2},{0, 9},{0,10},{5,-2},{0,11},{0,12},
+    {2,-8},
+    {4,-4},{5,-2},{0,13},{0,14},{5,-2},{0,15},{0,16},
+    {3,-8},
+    {4,-4},{5,-2},{0,17},{0,18},{5,-2},{0,19},{0,20},
+    {4,-4},{5,-2},{0,21},{0,22},{5,-2},{0,23},{0,24},
+};
+
+static const CABACVLC intra_mb_type_p_vlc[]={
+    {1,-24},
+    {2,-8},
+    {3,-4},{3,-2},{0, 1},{0, 2},{3,-2},{0, 3},{0, 4},
+    {2,-8},
+    {3,-4},{3,-2},{0, 5},{0, 6},{3,-2},{0, 7},{0, 8},
+    {3,-4},{3,-2},{0, 9},{0,10},{3,-2},{0,11},{0,12},
+    {2,-8},
+    {3,-4},{3,-2},{0,13},{0,14},{3,-2},{0,15},{0,16},
+    {2,-8},
+    {3,-4},{3,-2},{0,17},{0,18},{3,-2},{0,19},{0,20},
+    {3,-4},{3,-2},{0,21},{0,22},{3,-2},{0,23},{0,24},
+};
+
 static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) {
     uint8_t *state= &h->cabac_state[ctx_base];
     int mb_type;
-
+START_TIMER
     if(intra_slice){
         MpegEncContext * const s = &h->s;
         const int mba_xy = h->left_mb_xy[0];
@@ -5659,13 +5687,20 @@
 
     if( get_cabac_terminate( &h->cabac ) )
         return 25;  /* PCM */
-
+#if 1
+    if(intra_slice)
+        mb_type=get_cabac_vlc(&h->cabac, state, intra_mb_type_i_vlc);
+    else
+        mb_type=get_cabac_vlc(&h->cabac, state, intra_mb_type_p_vlc);
+#else
     mb_type = 1; /* I16x16 */
     mb_type += 12 * get_cabac_noinline( &h->cabac, &state[1] ); /* cbp_luma != 0 */
     if( get_cabac_noinline( &h->cabac, &state[2] ) ) /* cbp_chroma */
         mb_type += 4 + 4 * get_cabac_noinline( &h->cabac, &state[2+intra_slice] );
     mb_type += 2 * get_cabac_noinline( &h->cabac, &state[3+intra_slice] );
     mb_type += 1 * get_cabac_noinline( &h->cabac, &state[3+2*intra_slice] );
+#endif
+STOP_TIMER("decode_cabac_intra_mb_type")
     return mb_type;
 }
 
 
===================================================================
--- libavcodec/cabac.h	(revision 6679)
+++ libavcodec/cabac.h	(working copy)
@@ -571,6 +572,19 @@
     return get_cabac_inline(c,state);
 }
 
+typedef struct CABACVLC{
+    int8_t idx;
+    int8_t val;
+}CABACVLC;
+
+static int __attribute((noinline)) get_cabac_vlc(CABACContext *c, uint8_t * state, CABACVLC *tree){
+    do{
+        int v= get_cabac_inline(c, state + tree->idx) - 1;
+        tree -= v | tree->val;
+    }while(tree->val < 0);
+    return tree->val;
+}
+
 static int get_cabac_bypass(CABACContext *c){
     c->low += c->low;
 



More information about the ffmpeg-devel mailing list