]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/bitstream.h
Add av_shrink_packet function for use in av_get_packet that reduces pkt->size
[ffmpeg] / libavcodec / bitstream.h
index e1ec934b28203a4fe0ca0b5254f01dafd9117a2c..263fe9aa5a869db79decb916ed038cf5d9b0d835 100644 (file)
@@ -33,6 +33,7 @@
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/log.h"
+#include "mathops.h"
 
 #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
 #   define ALT_BITSTREAM_READER
@@ -336,6 +337,7 @@ static inline void skip_put_bytes(PutBitContext *s, int n){
 /**
  * Skips the given number of bits.
  * Must only be used if the actual values in the bitstream do not matter.
+ * If \p n is 0 the behavior is undefined.
  */
 static inline void skip_put_bits(PutBitContext *s, int n){
 #ifdef ALT_BITSTREAM_WRITER
@@ -706,6 +708,13 @@ static inline unsigned int get_bits_long(GetBitContext *s, int n){
     }
 }
 
+/**
+ * reads 0-32 bits as a signed integer.
+ */
+static inline int get_sbits_long(GetBitContext *s, int n) {
+    return sign_extend(get_bits_long(s, n), n);
+}
+
 /**
  * shows 0-32 bits.
  */
@@ -713,9 +722,7 @@ static inline 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;
+        return get_bits_long(&gb, n);
     }
 }