bitstream: move put_sbits() from flacenc.c to bitstream.h and use it

throughout libavcodec.

Originally committed as revision 14204 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Ramiro Polla 2008-07-13 14:27:48 +00:00
parent f9bd305694
commit 6647ab80e3
11 changed files with 34 additions and 34 deletions

View File

@ -563,7 +563,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx,
//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];
}

View File

@ -166,7 +166,7 @@ static inline void asv1_put_level(PutBitContext *pb, int level){
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);
}
}

View File

@ -315,6 +315,13 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
}
#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)
{

View File

@ -1236,13 +1236,6 @@ static void channel_decorrelation(FlacEncodeContext *ctx)
}
}
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;

View File

@ -469,7 +469,7 @@ static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k, int lim
}
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);

View File

@ -61,7 +61,7 @@ void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){
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 @@ static void h261_encode_block(H261Context * h, DCTELEM * block, int n){
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);
}

View File

@ -249,7 +249,7 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number)
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 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number)
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 @@ static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
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 @@ static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
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 @@ static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n
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 */

View File

@ -369,7 +369,7 @@ void ff_mjpeg_encode_dc(MpegEncContext *s, int val,
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 @@ static void encode_block(MpegEncContext *s, DCTELEM *block, int n)
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;
}
}

View File

@ -184,7 +184,7 @@ static void put_header(MpegEncContext *s, int header)
{
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 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
/* 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 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
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 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
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 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
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 @@ static void mpeg1_encode_block(MpegEncContext *s,
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;

View File

@ -957,7 +957,7 @@ else
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 */

View File

@ -265,7 +265,7 @@ void rv20_encode_picture_header(MpegEncContext *s, int picture_number){
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);