diff options
Diffstat (limited to 'src/libffmpeg/libavcodec/common.c')
-rw-r--r-- | src/libffmpeg/libavcodec/common.c | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/src/libffmpeg/libavcodec/common.c b/src/libffmpeg/libavcodec/common.c index f7fe2e1d1..571de1afc 100644 --- a/src/libffmpeg/libavcodec/common.c +++ b/src/libffmpeg/libavcodec/common.c @@ -1,25 +1,24 @@ /* * Common bit i/o utils - * Copyright (c) 2000, 2001 Gerard Lantau. + * Copyright (c) 2000, 2001 Fabrice Bellard. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at> */ #include "common.h" -#include <math.h> void init_put_bits(PutBitContext *s, UINT8 *buffer, int buffer_size, @@ -108,6 +107,15 @@ void jflush_put_bits(PutBitContext *s) } #endif +void put_string(PutBitContext * pbc, char *s) +{ + while(*s){ + put_bits(pbc, 8, *s); + s++; + } + put_bits(pbc, 8, 0); +} + /* bit input functions */ void init_get_bits(GetBitContext *s, @@ -166,6 +174,9 @@ unsigned int get_bits_long(GetBitContext *s, int n) (buf_ptr[-2] << 8) | (buf_ptr[-1]); #endif + val |= bit_buf >> (32 + bit_cnt); + bit_buf <<= - bit_cnt; + bit_cnt += 32; } else { buf_ptr -= 4; bit_buf = 0; @@ -177,11 +188,13 @@ unsigned int get_bits_long(GetBitContext *s, int n) bit_buf |= *buf_ptr++ << 8; if (buf_ptr < s->buf_end) bit_buf |= *buf_ptr++; + + val |= bit_buf >> (32 + bit_cnt); + bit_buf <<= - bit_cnt; + bit_cnt += 8*(buf_ptr - s->buf_ptr); + if(bit_cnt<0) bit_cnt=0; } s->buf_ptr = buf_ptr; - val |= bit_buf >> (32 + bit_cnt); - bit_buf <<= - bit_cnt; - bit_cnt += 32; } s->bit_buf = bit_buf; s->bit_cnt = bit_cnt; @@ -349,7 +362,7 @@ static int build_table(VLC *vlc, int table_nb_bits, #endif if (table_bits[j] != 0) { fprintf(stderr, "incorrect codes\n"); - abort(); + exit(1); } table_bits[j] = n; table_codes[j] = i; @@ -435,10 +448,8 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, 0, 0) < 0) { - if (vlc->table_bits) - free(vlc->table_bits); - if (vlc->table_codes) - free(vlc->table_codes); + av_free(vlc->table_bits); + av_free(vlc->table_codes); return -1; } return 0; @@ -447,7 +458,11 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, void free_vlc(VLC *vlc) { - free(vlc->table_bits); - free(vlc->table_codes); + av_free(vlc->table_bits); + av_free(vlc->table_codes); } +int ff_gcd(int a, int b){ + if(b) return ff_gcd(b, a%b); + else return a; +} |