changeset 7260:3ec34b551aae libavcodec

bitstream: move put_sbits() from flacenc.c to bitstream.h and use it throughout libavcodec.
author ramiro
date Sun, 13 Jul 2008 14:27:48 +0000
parents 9de4bc7d4938
children 032a49f033e8
files adpcm.c asv1.c bitstream.h flacenc.c golomb.h h261enc.c h263.c mjpegenc.c mpeg12enc.c msmpeg4.c rv10.c
diffstat 11 files changed, 34 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/adpcm.c	Sun Jul 13 14:25:31 2008 +0000
+++ b/adpcm.c	Sun Jul 13 14:27:48 2008 +0000
@@ -563,7 +563,7 @@
         //Init the encoder state
         for(i=0; i<avctx->channels; i++){
             c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63); // clip step so it fits 6 bits
-            put_bits(&pb, 16, samples[i] & 0xFFFF);
+            put_sbits(&pb, 16, samples[i]);
             put_bits(&pb, 6, c->status[i].step_index);
             c->status[i].prev_sample = (signed short)samples[i];
         }
--- a/asv1.c	Sun Jul 13 14:25:31 2008 +0000
+++ b/asv1.c	Sun Jul 13 14:27:48 2008 +0000
@@ -166,7 +166,7 @@
     if(index <= 6) put_bits(pb, level_tab[index][1], level_tab[index][0]);
     else{
         put_bits(pb, level_tab[3][1], level_tab[3][0]);
-        put_bits(pb, 8, level&0xFF);
+        put_sbits(pb, 8, level);
     }
 }
 
--- a/bitstream.h	Sun Jul 13 14:25:31 2008 +0000
+++ b/bitstream.h	Sun Jul 13 14:27:48 2008 +0000
@@ -315,6 +315,13 @@
 }
 #endif
 
+static inline void put_sbits(PutBitContext *pb, int bits, int32_t val)
+{
+    assert(bits >= 0 && bits <= 31);
+
+    put_bits(pb, bits, val & ((1<<bits)-1));
+}
+
 
 static inline uint8_t* pbBufPtr(PutBitContext *s)
 {
--- a/flacenc.c	Sun Jul 13 14:25:31 2008 +0000
+++ b/flacenc.c	Sun Jul 13 14:27:48 2008 +0000
@@ -1236,13 +1236,6 @@
     }
 }
 
-static void put_sbits(PutBitContext *pb, int bits, int32_t val)
-{
-    assert(bits >= 0 && bits <= 31);
-
-    put_bits(pb, bits, val & ((1<<bits)-1));
-}
-
 static void write_utf8(PutBitContext *pb, uint32_t val)
 {
     uint8_t tmp;
--- a/golomb.h	Sun Jul 13 14:25:31 2008 +0000
+++ b/golomb.h	Sun Jul 13 14:27:48 2008 +0000
@@ -469,7 +469,7 @@
         }
         put_bits(pb, e, 1);
         if(k)
-            put_bits(pb, k, i&((1<<k)-1));
+            put_sbits(pb, k, i);
     }else{
         while(limit > 31) {
             put_bits(pb, 31, 0);
--- a/h261enc.c	Sun Jul 13 14:25:31 2008 +0000
+++ b/h261enc.c	Sun Jul 13 14:27:48 2008 +0000
@@ -61,7 +61,7 @@
 
     temp_ref= s->picture_number * (int64_t)30000 * s->avctx->time_base.num /
                          (1001 * (int64_t)s->avctx->time_base.den); //FIXME maybe this should use a timestamp
-    put_bits(&s->pb, 5, temp_ref & 0x1f); /* TemporalReference */
+    put_sbits(&s->pb, 5, temp_ref); /* TemporalReference */
 
     put_bits(&s->pb, 1, 0); /* split screen off */
     put_bits(&s->pb, 1, 0); /* camera  off */
@@ -309,7 +309,7 @@
                 put_bits(&s->pb, 6, run);
                 assert(slevel != 0);
                 assert(level <= 127);
-                put_bits(&s->pb, 8, slevel & 0xff);
+                put_sbits(&s->pb, 8, slevel);
             } else {
                 put_bits(&s->pb, 1, sign);
             }
--- a/h263.c	Sun Jul 13 14:25:31 2008 +0000
+++ b/h263.c	Sun Jul 13 14:27:48 2008 +0000
@@ -249,7 +249,7 @@
     put_bits(&s->pb, 22, 0x20); /* PSC */
     temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->time_base.num / //FIXME use timestamp
                          (coded_frame_rate_base * (int64_t)s->avctx->time_base.den);
-    put_bits(&s->pb, 8, temp_ref & 0xff); /* TemporalReference */
+    put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */
 
     put_bits(&s->pb, 1, 1);     /* marker */
     put_bits(&s->pb, 1, 0);     /* h263 id */
@@ -326,7 +326,7 @@
                 put_bits(&s->pb, 1, best_clock_code);
                 put_bits(&s->pb, 7, best_divisor);
             }
-            put_bits(&s->pb, 2, (temp_ref>>8)&3);
+            put_sbits(&s->pb, 2, temp_ref>>8);
         }
 
         /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
@@ -2224,11 +2224,11 @@
                 assert(slevel != 0);
 
                 if(level < 128)
-                    put_bits(&s->pb, 8, slevel & 0xff);
+                    put_sbits(&s->pb, 8, slevel);
                 else{
                     put_bits(&s->pb, 8, 128);
-                    put_bits(&s->pb, 5, slevel & 0x1f);
-                    put_bits(&s->pb, 6, (slevel>>5)&0x3f);
+                    put_sbits(&s->pb, 5, slevel);
+                    put_sbits(&s->pb, 6, slevel>>5);
                 }
               }else{
                 if(level < 64) { // 7-bit level
@@ -2236,14 +2236,14 @@
                         put_bits(&s->pb, 1, last);
                         put_bits(&s->pb, 6, run);
 
-                        put_bits(&s->pb, 7, slevel & 0x7f);
+                        put_sbits(&s->pb, 7, slevel);
                     } else {
                         /* 11-bit level */
                         put_bits(&s->pb, 1, 1);
                         put_bits(&s->pb, 1, last);
                         put_bits(&s->pb, 6, run);
 
-                        put_bits(&s->pb, 11, slevel & 0x7ff);
+                        put_sbits(&s->pb, 11, slevel);
                     }
               }
             } else {
@@ -2804,7 +2804,7 @@
                         put_bits(ac_pb, 1, last);
                         put_bits(ac_pb, 6, run);
                         put_bits(ac_pb, 1, 1);
-                        put_bits(ac_pb, 12, slevel & 0xfff);
+                        put_sbits(ac_pb, 12, slevel);
                         put_bits(ac_pb, 1, 1);
                     } else {
                         /* second escape */
--- a/mjpegenc.c	Sun Jul 13 14:25:31 2008 +0000
+++ b/mjpegenc.c	Sun Jul 13 14:27:48 2008 +0000
@@ -369,7 +369,7 @@
 
         put_bits(&s->pb, huff_size[nbits], huff_code[nbits]);
 
-        put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
+        put_sbits(&s->pb, nbits, mant);
     }
 }
 
@@ -421,7 +421,7 @@
 
             put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]);
 
-            put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
+            put_sbits(&s->pb, nbits, mant);
             run = 0;
         }
     }
--- a/mpeg12enc.c	Sun Jul 13 14:25:31 2008 +0000
+++ b/mpeg12enc.c	Sun Jul 13 14:27:48 2008 +0000
@@ -184,7 +184,7 @@
 {
     align_put_bits(&s->pb);
     put_bits(&s->pb, 16, header>>16);
-    put_bits(&s->pb, 16, header&0xFFFF);
+    put_sbits(&s->pb, 16, header);
 }
 
 /* put sequence header if needed */
@@ -206,8 +206,8 @@
             /* mpeg1 header repeated every gop */
             put_header(s, SEQ_START_CODE);
 
-            put_bits(&s->pb, 12, s->width  & 0xFFF);
-            put_bits(&s->pb, 12, s->height & 0xFFF);
+            put_sbits(&s->pb, 12, s->width );
+            put_sbits(&s->pb, 12, s->height);
 
             for(i=1; i<15; i++){
                 float error= aspect_ratio;
@@ -242,9 +242,9 @@
                 vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024;
             vbv_buffer_size= (vbv_buffer_size + 16383) / 16384;
 
-            put_bits(&s->pb, 18, v & 0x3FFFF);
+            put_sbits(&s->pb, 18, v);
             put_bits(&s->pb, 1, 1); /* marker */
-            put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF);
+            put_sbits(&s->pb, 10, vbv_buffer_size);
 
             constraint_parameter_flag=
                 s->width <= 768 && s->height <= 576 &&
@@ -557,7 +557,7 @@
                     put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp][1], ff_mpeg12_mbPatTable[cbp][0]);
                 } else {
                     put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp>>2][1], ff_mpeg12_mbPatTable[cbp>>2][0]);
-                    put_bits(&s->pb, 2, cbp & 3);
+                    put_sbits(&s->pb, 2, cbp);
                 }
             }
             s->f_count++;
@@ -640,7 +640,7 @@
                     put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp][1], ff_mpeg12_mbPatTable[cbp][0]);
                 } else {
                     put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp>>2][1], ff_mpeg12_mbPatTable[cbp>>2][0]);
-                    put_bits(&s->pb, 2, cbp & 3);
+                    put_sbits(&s->pb, 2, cbp);
                 }
             }
         }
@@ -908,16 +908,16 @@
                 put_bits(&s->pb, 6, run);
                 if(s->codec_id == CODEC_ID_MPEG1VIDEO){
                     if (alevel < 128) {
-                        put_bits(&s->pb, 8, level & 0xff);
+                        put_sbits(&s->pb, 8, level);
                     } else {
                         if (level < 0) {
                             put_bits(&s->pb, 16, 0x8001 + level + 255);
                         } else {
-                            put_bits(&s->pb, 16, level & 0xffff);
+                            put_sbits(&s->pb, 16, level);
                         }
                     }
                 }else{
-                    put_bits(&s->pb, 12, level & 0xfff);
+                    put_sbits(&s->pb, 12, level);
                 }
             }
             last_non_zero = i;
--- a/msmpeg4.c	Sun Jul 13 14:25:31 2008 +0000
+++ b/msmpeg4.c	Sun Jul 13 14:27:48 2008 +0000
@@ -957,7 +957,7 @@
                             put_bits(&s->pb, s->esc3_level_length, level);
                         }else{
                             put_bits(&s->pb, 6, run);
-                            put_bits(&s->pb, 8, slevel & 0xff);
+                            put_sbits(&s->pb, 8, slevel);
                         }
                     } else {
                         /* second escape */
--- a/rv10.c	Sun Jul 13 14:25:31 2008 +0000
+++ b/rv10.c	Sun Jul 13 14:27:48 2008 +0000
@@ -265,7 +265,7 @@
     put_bits(&s->pb, 1, 0);     /* unknown bit */
     put_bits(&s->pb, 5, s->qscale);
 
-    put_bits(&s->pb, 8, picture_number&0xFF); //FIXME wrong, but correct is not known
+    put_sbits(&s->pb, 8, picture_number); //FIXME wrong, but correct is not known
     s->mb_x= s->mb_y= 0;
     ff_h263_encode_mba(s);