changeset 1257:6defe392d5d2 libavcodec

libmpeg2 style bitstream reader fixes
author michaelni
date Wed, 14 May 2003 10:55:59 +0000
parents b8e1c17b8d7d
children 802614404398
files common.c common.h h263.c
diffstat 3 files changed, 49 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/common.c	Wed May 14 10:54:25 2003 +0000
+++ b/common.c	Wed May 14 10:55:59 2003 +0000
@@ -140,7 +140,7 @@
 #ifdef ALT_BITSTREAM_READER
     s->index=0;
 #elif defined LIBMPEG2_BITSTREAM_READER
-#ifdef LIBMPEG2_BITSTREAM_HACK
+#ifdef LIBMPEG2_BITSTREAM_READER_HACK
   if ((int)buffer&1) {
      /* word alignment */
     s->cache = (*buffer++)<<24;
@@ -170,6 +170,30 @@
 #endif
 }
 
+/** 
+ * reads 0-32 bits.
+ */
+unsigned int get_bits_long(GetBitContext *s, int n){
+    if(n<=17) return get_bits(s, n);
+    else{
+        int ret= get_bits(s, 16) << (n-16);
+        return ret | get_bits(s, n-16);
+    }
+}
+
+/** 
+ * shows 0-32 bits.
+ */
+unsigned int show_bits_long(GetBitContext *s, int n){
+    if(n<=17) return show_bits(s, n);
+    else{
+        GetBitContext gb= *s;
+        int ret= get_bits_long(s, n);
+        *s= gb;
+        return ret;
+    }
+}
+
 void align_get_bits(GetBitContext *s)
 {
     int n= (-get_bits_count(s)) & 7;
--- a/common.h	Wed May 14 10:54:25 2003 +0000
+++ b/common.h	Wed May 14 10:55:59 2003 +0000
@@ -543,8 +543,8 @@
 
 #   define UPDATE_CACHE(name, gb)\
     if(name##_bit_count >= 0){\
-        name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr++) << name##_bit_count;\
-        name##_buffer_ptr+=2;\
+        name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\
+        ((uint16_t*)name##_buffer_ptr)++;\
         name##_bit_count-= 16;\
     }\
 
@@ -654,9 +654,12 @@
 
 #endif
 
-/* add BERO
-   if MSB not set it is negative 
-*/
+/**
+ * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
+ * if MSB not set it is negative 
+ * @param n length in bits
+ * @author BERO  
+ */
 static inline int get_xbits(GetBitContext *s, int n){
     register int tmp;
     register int32_t cache;
@@ -685,6 +688,10 @@
     return tmp;
 }
 
+/**
+ * reads 0-17 bits.
+ * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
+ */
 static inline unsigned int get_bits(GetBitContext *s, int n){
     register int tmp;
     OPEN_READER(re, s)
@@ -695,6 +702,12 @@
     return tmp;
 }
 
+unsigned int get_bits_long(GetBitContext *s, int n);
+
+/**
+ * shows 0-17 bits.
+ * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
+ */
 static inline unsigned int show_bits(GetBitContext *s, int n){
     register int tmp;
     OPEN_READER(re, s)
@@ -704,6 +717,8 @@
     return tmp;
 }
 
+unsigned int show_bits_long(GetBitContext *s, int n);
+
 static inline void skip_bits(GetBitContext *s, int n){
  //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
     OPEN_READER(re, s)
--- a/h263.c	Wed May 14 10:54:25 2003 +0000
+++ b/h263.c	Wed May 14 10:55:59 2003 +0000
@@ -2708,7 +2708,7 @@
             if(s->pict_type==I_TYPE){
                 int i;
 
-                if(show_bits(&s->gb, 19)==DC_MARKER){
+                if(show_bits_long(&s->gb, 19)==DC_MARKER){
                     return mb_num-1;
                 }
 
@@ -2956,7 +2956,7 @@
     s->mb_num_left= mb_num;
         
     if(s->pict_type==I_TYPE){
-        if(get_bits(&s->gb, 19)!=DC_MARKER){
+        if(get_bits_long(&s->gb, 19)!=DC_MARKER){
             fprintf(stderr, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y);
             return -1;
         }
@@ -3885,7 +3885,7 @@
     int format, width, height;
 
     /* picture start code */
-    if (get_bits(&s->gb, 22) != 0x20) {
+    if (get_bits_long(&s->gb, 22) != 0x20) {
         fprintf(stderr, "Bad picture start code\n");
         return -1;
     }
@@ -4878,7 +4878,7 @@
     int format;
 
     /* picture header */
-    if (get_bits(&s->gb, 22) != 0x20) {
+    if (get_bits_long(&s->gb, 22) != 0x20) {
         fprintf(stderr, "Bad picture start code\n");
         return -1;
     }