changeset 12365:7c54834209f6 libavcodec

VP5/6/8: eliminate CABAC dependency Create a custom table for VP5/6/8's renorm to avoid depending on H.264's. Saves one instruction in the arithmetic decoder as well.
author darkshikari
date Wed, 04 Aug 2010 23:04:05 +0000
parents 2e96cab6ecde
children 09a31ef6ed58
files Makefile vp5.c vp56.h vp56rac.c vp6.c vp8.c
diffstat 6 files changed, 60 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Aug 04 06:56:55 2010 +0000
+++ b/Makefile	Wed Aug 04 23:04:05 2010 +0000
@@ -376,10 +376,10 @@
                                           vorbis_data.o
 OBJS-$(CONFIG_VP3_DECODER)             += vp3.o vp3dsp.o
 OBJS-$(CONFIG_VP5_DECODER)             += vp5.o vp56.o vp56data.o vp56dsp.o \
-                                          vp3dsp.o cabac.o
+                                          vp3dsp.o vp56rac.o
 OBJS-$(CONFIG_VP6_DECODER)             += vp6.o vp56.o vp56data.o vp56dsp.o \
-                                          vp3dsp.o vp6dsp.o huffman.o cabac.o
-OBJS-$(CONFIG_VP8_DECODER)             += vp8.o vp8dsp.o cabac.o
+                                          vp3dsp.o vp6dsp.o huffman.o vp56rac.o
+OBJS-$(CONFIG_VP8_DECODER)             += vp8.o vp8dsp.o vp56rac.o
 OBJS-$(CONFIG_VQA_DECODER)             += vqavideo.o
 OBJS-$(CONFIG_WAVPACK_DECODER)         += wavpack.o
 OBJS-$(CONFIG_WMAPRO_DECODER)          += wmaprodec.o wma.o
--- a/vp5.c	Wed Aug 04 06:56:55 2010 +0000
+++ b/vp5.c	Wed Aug 04 23:04:05 2010 +0000
@@ -39,7 +39,7 @@
     VP56RangeCoder *c = &s->c;
     int rows, cols;
 
-    vp56_init_range_decoder(&s->c, buf, buf_size);
+    ff_vp56_init_range_decoder(&s->c, buf, buf_size);
     s->framep[VP56_FRAME_CURRENT]->key_frame = !vp56_rac_get(c);
     vp56_rac_get(c);
     ff_vp56_init_dequant(s, vp56_rac_gets(c, 6));
--- a/vp56.h	Wed Aug 04 06:56:55 2010 +0000
+++ b/vp56.h	Wed Aug 04 23:04:05 2010 +0000
@@ -181,19 +181,12 @@
  * vp56 specific range coder implementation
  */
 
-static inline void vp56_init_range_decoder(VP56RangeCoder *c,
-                                           const uint8_t *buf, int buf_size)
-{
-    c->high = 255;
-    c->bits = -8;
-    c->buffer = buf;
-    c->end = buf + buf_size;
-    c->code_word = bytestream_get_be16(&c->buffer);
-}
+extern const uint8_t ff_vp56_norm_shift[256];
+void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size);
 
 static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c)
 {
-    int shift = ff_h264_norm_shift[c->high] - 1;
+    int shift = ff_vp56_norm_shift[c->high];
     int bits = c->bits;
     unsigned int code_word = c->code_word;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vp56rac.c	Wed Aug 04 23:04:05 2010 +0000
@@ -0,0 +1,47 @@
+/*
+ * VP5/6/8 decoder
+ * Copyright (c) 2010 Jason Garrett-Glaser <darkshikari@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/common.h"
+#include "vp56.h"
+
+const uint8_t ff_vp56_norm_shift[256]= {
+ 8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,
+ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 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,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,
+};
+
+void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
+{
+    c->high = 255;
+    c->bits = -8;
+    c->buffer = buf;
+    c->end = buf + buf_size;
+    c->code_word = bytestream_get_be16(&c->buffer);
+}
--- a/vp6.c	Wed Aug 04 06:56:55 2010 +0000
+++ b/vp6.c	Wed Aug 04 23:04:05 2010 +0000
@@ -87,7 +87,7 @@
             res = 2;
         }
 
-        vp56_init_range_decoder(c, buf+6, buf_size-6);
+        ff_vp56_init_range_decoder(c, buf+6, buf_size-6);
         vp56_rac_gets(c, 2);
 
         parse_filter_info = s->filter_header;
@@ -103,7 +103,7 @@
             buf += 2;
             buf_size -= 2;
         }
-        vp56_init_range_decoder(c, buf+1, buf_size-1);
+        ff_vp56_init_range_decoder(c, buf+1, buf_size-1);
 
         *golden_frame = vp56_rac_get(c);
         if (s->filter_header) {
@@ -143,7 +143,7 @@
             s->parse_coeff = vp6_parse_coeff_huffman;
             init_get_bits(&s->gb, buf, buf_size<<3);
         } else {
-            vp56_init_range_decoder(&s->cc, buf, buf_size);
+            ff_vp56_init_range_decoder(&s->cc, buf, buf_size);
             s->ccp = &s->cc;
         }
     } else {
--- a/vp8.c	Wed Aug 04 06:56:55 2010 +0000
+++ b/vp8.c	Wed Aug 04 23:04:05 2010 +0000
@@ -305,11 +305,11 @@
         if (buf_size - size < 0)
             return -1;
 
-        vp56_init_range_decoder(&s->coeff_partition[i], buf, size);
+        ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, size);
         buf      += size;
         buf_size -= size;
     }
-    vp56_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
+    ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
 
     return 0;
 }
@@ -445,7 +445,7 @@
             return ret;
     }
 
-    vp56_init_range_decoder(c, buf, header_size);
+    ff_vp56_init_range_decoder(c, buf, header_size);
     buf      += header_size;
     buf_size -= header_size;