[Ffmpeg-devel] [PATCH] fix get_bits_long with ALT_BITSTREAM_READER_LE

Reimar Döffinger Reimar.Doeffinger
Mon Sep 25 23:41:22 CEST 2006


Hello,
get_bits_long (and thus tta.c) is currently completely broken for
ALT_BITSTREAM_READER_LE, because it reassembles the two get_bits parts
in a way that works only with big-endian.
Before it was moved to bitstream.h it "worked" (more or less) because it
used the big-endian get_bits and returned a big-endian thing.
The attached patch should fix this properly and removes the
get_bits_long_le hack from vorbis.c.
Okay to apply?

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavcodec/tta.c
===================================================================
--- libavcodec/tta.c	(revision 6328)
+++ libavcodec/tta.c	(working copy)
@@ -198,12 +198,12 @@
 // shamelessly copied from shorten.c
 static int inline get_le16(GetBitContext *gb)
 {
-    return bswap_16(get_bits_long(gb, 16));
+    return get_bits_long(gb, 16);
 }
 
 static int inline get_le32(GetBitContext *gb)
 {
-    return bswap_32(get_bits_long(gb, 32));
+    return get_bits_long(gb, 32);
 }
 
 static int tta_decode_init(AVCodecContext * avctx)
@@ -218,7 +218,7 @@
         return -1;
 
     init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size);
-    if (show_bits_long(&s->gb, 32) == bswap_32(ff_get_fourcc("TTA1")))
+    if (show_bits_long(&s->gb, 32) == ff_get_fourcc("TTA1"))
     {
         /* signature */
         skip_bits(&s->gb, 32);
Index: libavcodec/bitstream.h
===================================================================
--- libavcodec/bitstream.h	(revision 6328)
+++ libavcodec/bitstream.h	(working copy)
@@ -725,8 +725,13 @@
 static inline unsigned int get_bits_long(GetBitContext *s, int n){
     if(n<=17) return get_bits(s, n);
     else{
+#ifdef ALT_BITSTREAM_READER_LE
+        int ret= get_bits(s, 16);
+        return ret | (get_bits(s, n-16) << 16);
+#else
         int ret= get_bits(s, 16) << (n-16);
         return ret | get_bits(s, n-16);
+#endif
     }
 }
 
Index: libavcodec/vorbis.c
===================================================================
--- libavcodec/vorbis.c	(revision 6328)
+++ libavcodec/vorbis.c	(working copy)
@@ -45,17 +45,6 @@
 
 /* Helper functions */
 
-/**
- *  reads 0-32 bits when using the ALT_BITSTREAM_READER_LE bitstream reader
- */
-static unsigned int get_bits_long_le(GetBitContext *s, int n){
-    if(n<=17) return get_bits(s, n);
-    else{
-        int ret= get_bits(s, 16);
-        return ret | (get_bits(s, n-16) << 16);
-    }
-}
-
 #define ilog(i) av_log2(2*(i))
 
 #define BARK(x) \
@@ -311,8 +300,8 @@
             uint_fast16_t codebook_lookup_values=nth_root(entries, codebook_setup->dimensions);
             uint_fast16_t codebook_multiplicands[codebook_lookup_values];
 
-            float codebook_minimum_value=vorbisfloat2float(get_bits_long_le(gb, 32));
-            float codebook_delta_value=vorbisfloat2float(get_bits_long_le(gb, 32));
+            float codebook_minimum_value=vorbisfloat2float(get_bits_long(gb, 32));
+            float codebook_delta_value=vorbisfloat2float(get_bits_long(gb, 32));
             uint_fast8_t codebook_value_bits=get_bits(gb, 4)+1;
             uint_fast8_t codebook_sequence_p=get_bits1(gb);
 
@@ -869,12 +858,12 @@
         return 1;
     }
 
-    vc->version=get_bits_long_le(gb, 32);    //FIXME check 0
+    vc->version=get_bits_long(gb, 32);    //FIXME check 0
     vc->audio_channels=get_bits(gb, 8);   //FIXME check >0
-    vc->audio_samplerate=get_bits_long_le(gb, 32);   //FIXME check >0
-    vc->bitrate_maximum=get_bits_long_le(gb, 32);
-    vc->bitrate_nominal=get_bits_long_le(gb, 32);
-    vc->bitrate_minimum=get_bits_long_le(gb, 32);
+    vc->audio_samplerate=get_bits_long(gb, 32);   //FIXME check >0
+    vc->bitrate_maximum=get_bits_long(gb, 32);
+    vc->bitrate_nominal=get_bits_long(gb, 32);
+    vc->bitrate_minimum=get_bits_long(gb, 32);
     bl0=get_bits(gb, 4);
     bl1=get_bits(gb, 4);
     vc->blocksize[0]=(1<<bl0);



More information about the ffmpeg-devel mailing list