Revision d8cf5aea libavcodec/common.h

View differences:

libavcodec/common.h
168 168
    int index;
169 169
#else
170 170
    UINT32 bit_buf;
171
    int bit_cnt;
171
    int bit_left;
172 172
    UINT8 *buf, *buf_ptr, *buf_end;
173
    void *opaque;
174
    WriteDataFunc write_data;
175 173
#endif
176 174
    INT64 data_out_size; /* in bytes */
177 175
} PutBitContext;
......
181 179
                   void *opaque,
182 180
                   void (*write_data)(void *, UINT8 *, int));
183 181

  
184
#ifndef ALT_BITSTREAM_WRITER
185
void put_bits(PutBitContext *s, int n, unsigned int value);
186
#endif
187

  
188 182
INT64 get_bit_count(PutBitContext *s); /* XXX: change function name */
189 183
void align_put_bits(PutBitContext *s);
190 184
void flush_put_bits(PutBitContext *s);
191 185

  
192 186
/* jpeg specific put_bits */
193
#ifndef ALT_BITSTREAM_WRITER
194
void jput_bits(PutBitContext *s, int n, unsigned int value);
195
#endif
196 187
void jflush_put_bits(PutBitContext *s);
197 188

  
198 189
/* bit input */
......
238 229
#endif
239 230
#endif //!ARCH_X86
240 231

  
232
#ifndef ALT_BITSTREAM_WRITER
233
static inline void put_bits(PutBitContext *s, int n, unsigned int value)
234
{
235
    unsigned int bit_buf;
236
    int bit_left;
237

  
238
#ifdef STATS
239
    st_out_bit_counts[st_current_index] += n;
240
#endif
241
    //    printf("put_bits=%d %x\n", n, value);
242
    assert(n == 32 || value < (1U << n));
243

  
244
    bit_buf = s->bit_buf;
245
    bit_left = s->bit_left;
246

  
247
    //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
248
    /* XXX: optimize */
249
    if (n < bit_left) {
250
        bit_buf = (bit_buf<<n) | value;
251
        bit_left-=n;
252
    } else {
253
	bit_buf<<=bit_left;
254
        bit_buf |= value >> (n - bit_left);
255
        *(UINT32 *)s->buf_ptr = be2me_32(bit_buf);
256
        //printf("bitbuf = %08x\n", bit_buf);
257
        s->buf_ptr+=4;
258
	bit_left+=32 - n;
259
        bit_buf = value;
260
    }
261

  
262
    s->bit_buf = bit_buf;
263
    s->bit_left = bit_left;
264
}
265
#endif
266

  
267

  
241 268
#ifdef ALT_BITSTREAM_WRITER
242 269
static inline void put_bits(PutBitContext *s, int n, unsigned int value)
243 270
{
......
304 331
}
305 332
#endif
306 333

  
334
#ifndef ALT_BITSTREAM_WRITER
335
/* for jpeg : escape 0xff with 0x00 after it */
336
static inline void jput_bits(PutBitContext *s, int n, unsigned int value)
337
{
338
    unsigned int bit_buf, b;
339
    int bit_left, i;
340
    
341
    assert(n == 32 || value < (1U << n));
342

  
343
    bit_buf = s->bit_buf;
344
    bit_left = s->bit_left;
345

  
346
    //printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
347
    /* XXX: optimize */
348
    if (n < bit_left) {
349
        bit_buf = (bit_buf<<n) | value;
350
        bit_left-=n;
351
    } else {
352
	bit_buf<<=bit_left;
353
        bit_buf |= value >> (n - bit_left);
354
        /* handle escape */
355
        for(i=0;i<4;i++) {
356
            b = (bit_buf >> 24);
357
            *(s->buf_ptr++) = b;
358
            if (b == 0xff)
359
                *(s->buf_ptr++) = 0;
360
            bit_buf <<= 8;
361
        }
362

  
363
	bit_left+= 32 - n;
364
        bit_buf = value;
365
    }
366
    
367
    s->bit_buf = bit_buf;
368
    s->bit_left = bit_left;
369
}
370
#endif
371

  
372

  
307 373
#ifdef ALT_BITSTREAM_WRITER
308 374
static inline void jput_bits(PutBitContext *s, int n, int value)
309 375
{

Also available in: Unified diff