Revision 990f213e libavcodec/get_bits.h

View differences:

libavcodec/get_bits.h
39 39
#   define ALT_BITSTREAM_READER
40 40
#endif
41 41

  
42
#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
42
#if !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
43 43
#   if ARCH_ARM && !HAVE_FAST_UNALIGNED
44 44
#       define A32_BITSTREAM_READER
45 45
#   else
46 46
#       define ALT_BITSTREAM_READER
47
//#define LIBMPEG2_BITSTREAM_READER
48 47
//#define A32_BITSTREAM_READER
49 48
#   endif
50 49
#endif
......
55 54
    const uint8_t *buffer, *buffer_end;
56 55
#ifdef ALT_BITSTREAM_READER
57 56
    int index;
58
#elif defined LIBMPEG2_BITSTREAM_READER
59
    uint8_t *buffer_ptr;
60
    uint32_t cache;
61
    int bit_count;
62 57
#elif defined A32_BITSTREAM_READER
63 58
    uint32_t *buffer_ptr;
64 59
    uint32_t cache0;
......
189 184
    s->index += n;
190 185
}
191 186

  
192
#elif defined LIBMPEG2_BITSTREAM_READER
193
//libmpeg2 like reader
194

  
195
#   define MIN_CACHE_BITS 17
196

  
197
#   define OPEN_READER(name, gb)\
198
        int name##_bit_count=(gb)->bit_count;\
199
        int name##_cache= (gb)->cache;\
200
        uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
201

  
202
#   define CLOSE_READER(name, gb)\
203
        (gb)->bit_count= name##_bit_count;\
204
        (gb)->cache= name##_cache;\
205
        (gb)->buffer_ptr= name##_buffer_ptr;\
206

  
207
#   define UPDATE_CACHE(name, gb)\
208
    if(name##_bit_count >= 0){\
209
        name##_cache+= AV_RB16(name##_buffer_ptr) << name##_bit_count; \
210
        name##_buffer_ptr+=2;\
211
        name##_bit_count-= 16;\
212
    }\
213

  
214
#   define SKIP_CACHE(name, gb, num)\
215
        name##_cache <<= (num);\
216

  
217
#   define SKIP_COUNTER(name, gb, num)\
218
        name##_bit_count += (num);\
219

  
220
#   define SKIP_BITS(name, gb, num)\
221
        {\
222
            SKIP_CACHE(name, gb, num)\
223
            SKIP_COUNTER(name, gb, num)\
224
        }\
225

  
226
#   define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
227
#   define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
228

  
229
#   define SHOW_UBITS(name, gb, num)\
230
        NEG_USR32(name##_cache, num)
231

  
232
#   define SHOW_SBITS(name, gb, num)\
233
        NEG_SSR32(name##_cache, num)
234

  
235
#   define GET_CACHE(name, gb)\
236
        ((uint32_t)name##_cache)
237

  
238
static inline int get_bits_count(const GetBitContext *s){
239
    return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
240
}
241

  
242
static inline void skip_bits_long(GetBitContext *s, int n){
243
    OPEN_READER(re, s)
244
    re_bit_count += n;
245
    re_buffer_ptr += 2*(re_bit_count>>4);
246
    re_bit_count &= 15;
247
    re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
248
    UPDATE_CACHE(re, s)
249
    CLOSE_READER(re, s)
250
}
251

  
252 187
#elif defined A32_BITSTREAM_READER
253 188

  
254 189
#   define MIN_CACHE_BITS 32
......
356 291
}
357 292

  
358 293
/**
359
 * reads 1-17 bits.
360
 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
294
 * Read 1-25 bits.
361 295
 */
362 296
static inline unsigned int get_bits(GetBitContext *s, int n){
363 297
    register int tmp;
......
370 304
}
371 305

  
372 306
/**
373
 * shows 1-17 bits.
374
 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
307
 * Shows 1-25 bits.
375 308
 */
376 309
static inline unsigned int show_bits(GetBitContext *s, int n){
377 310
    register int tmp;
......
484 417
    s->buffer_end= buffer + buffer_size;
485 418
#ifdef ALT_BITSTREAM_READER
486 419
    s->index=0;
487
#elif defined LIBMPEG2_BITSTREAM_READER
488
    s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
489
    s->bit_count = 16 + 8*((intptr_t)buffer&1);
490
    skip_bits_long(s, 0);
491 420
#elif defined A32_BITSTREAM_READER
492 421
    s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
493 422
    s->bit_count = 32 + 8*((intptr_t)buffer&3);

Also available in: Unified diff