#ifdef ALT_BITSTREAM_READER
s->index=0;
#elif defined LIBMPEG2_BITSTREAM_READER
-#ifdef LIBMPEG2_BITSTREAM_HACK
+#ifdef LIBMPEG2_BITSTREAM_READER_HACK
if ((int)buffer&1) {
/* word alignment */
s->cache = (*buffer++)<<24;
#endif
}
+/**
+ * reads 0-32 bits.
+ */
+unsigned int get_bits_long(GetBitContext *s, int n){
+ if(n<=17) return get_bits(s, n);
+ else{
+ int ret= get_bits(s, 16) << (n-16);
+ return ret | get_bits(s, n-16);
+ }
+}
+
+/**
+ * shows 0-32 bits.
+ */
+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;
+ }
+}
+
void align_get_bits(GetBitContext *s)
{
int n= (-get_bits_count(s)) & 7;
# define UPDATE_CACHE(name, gb)\
if(name##_bit_count >= 0){\
- name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr++) << name##_bit_count;\
- name##_buffer_ptr+=2;\
+ name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\
+ ((uint16_t*)name##_buffer_ptr)++;\
name##_bit_count-= 16;\
}\
#endif
-/* add BERO
- if MSB not set it is negative
-*/
+/**
+ * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
+ * if MSB not set it is negative
+ * @param n length in bits
+ * @author BERO
+ */
static inline int get_xbits(GetBitContext *s, int n){
register int tmp;
register int32_t cache;
return tmp;
}
+/**
+ * reads 0-17 bits.
+ * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
+ */
static inline unsigned int get_bits(GetBitContext *s, int n){
register int tmp;
OPEN_READER(re, s)
return tmp;
}
+unsigned int get_bits_long(GetBitContext *s, int n);
+
+/**
+ * shows 0-17 bits.
+ * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
+ */
static inline unsigned int show_bits(GetBitContext *s, int n){
register int tmp;
OPEN_READER(re, s)
return tmp;
}
+unsigned int show_bits_long(GetBitContext *s, int n);
+
static inline void skip_bits(GetBitContext *s, int n){
//Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
OPEN_READER(re, s)
if(s->pict_type==I_TYPE){
int i;
- if(show_bits(&s->gb, 19)==DC_MARKER){
+ if(show_bits_long(&s->gb, 19)==DC_MARKER){
return mb_num-1;
}
s->mb_num_left= mb_num;
if(s->pict_type==I_TYPE){
- if(get_bits(&s->gb, 19)!=DC_MARKER){
+ if(get_bits_long(&s->gb, 19)!=DC_MARKER){
fprintf(stderr, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
int format, width, height;
/* picture start code */
- if (get_bits(&s->gb, 22) != 0x20) {
+ if (get_bits_long(&s->gb, 22) != 0x20) {
fprintf(stderr, "Bad picture start code\n");
return -1;
}
int format;
/* picture header */
- if (get_bits(&s->gb, 22) != 0x20) {
+ if (get_bits_long(&s->gb, 22) != 0x20) {
fprintf(stderr, "Bad picture start code\n");
return -1;
}