~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/bitstream.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc, Andrew Starr-Bochicchio, Lionel Le Folgoc
  • Date: 2008-12-26 00:10:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081226001006-2040ls9680bd1blt
Tags: 1.1.7-0.2ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian-multimedia (LP: #298547), Ubuntu Changes:
 - For ffmpeg-related build-deps, fix versionized dependencies
   as the ubuntu versioning is different than debian-multimedia's.

[ Lionel Le Folgoc ]
* LP: #311412 is fixed since the 1.1.7~rc1-0.1 revision.
* debian/patches/03_ffmpeg.diff: updated to fix FTBFS due to libswscale API
  change (cherry-pick from Gentoo #234383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * Copyright (c) 2000, 2001 Fabrice Bellard.
4
4
 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5
5
 *
 
6
 * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
 
7
 *
6
8
 * This file is part of FFmpeg.
7
9
 *
8
10
 * FFmpeg is free software; you can redistribute it and/or
18
20
 * You should have received a copy of the GNU Lesser General Public
19
21
 * License along with FFmpeg; if not, write to the Free Software
20
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 
 *
22
 
 * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
23
23
 */
24
24
 
25
25
/**
36
36
 * @param[in] ptr The block of memory to reallocate.
37
37
 * @param[in] size The requested size.
38
38
 * @return Block of memory of requested size.
 
39
 * @deprecated. Code which uses ff_realloc_static is broken/misdesigned
 
40
 * and should correctly use static arrays
39
41
 */
 
42
attribute_deprecated av_alloc_size(2)
40
43
void *ff_realloc_static(void *ptr, unsigned int size);
41
44
 
42
45
void align_put_bits(PutBitContext *s)
48
51
#endif
49
52
}
50
53
 
51
 
void ff_put_string(PutBitContext * pbc, char *s, int put_zero)
 
54
void ff_put_string(PutBitContext * pbc, const char *s, int put_zero)
52
55
{
53
56
    while(*s){
54
57
        put_bits(pbc, 8, *s);
58
61
        put_bits(pbc, 8, 0);
59
62
}
60
63
 
 
64
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
 
65
{
 
66
    const uint16_t *srcw= (const uint16_t*)src;
 
67
    int words= length>>4;
 
68
    int bits= length&15;
 
69
    int i;
 
70
 
 
71
    if(length==0) return;
 
72
 
 
73
    if(ENABLE_SMALL || words < 16 || put_bits_count(pb)&7){
 
74
        for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i]));
 
75
    }else{
 
76
        for(i=0; put_bits_count(pb)&31; i++)
 
77
            put_bits(pb, 8, src[i]);
 
78
        flush_put_bits(pb);
 
79
        memcpy(pbBufPtr(pb), src+i, 2*words-i);
 
80
        skip_put_bytes(pb, 2*words-i);
 
81
    }
 
82
 
 
83
    put_bits(pb, bits, be2me_16(srcw[words])>>(16-bits));
 
84
}
 
85
 
61
86
/* VLC decoding */
62
87
 
63
88
//#define DEBUG_VLC
102
127
                       int nb_codes,
103
128
                       const void *bits, int bits_wrap, int bits_size,
104
129
                       const void *codes, int codes_wrap, int codes_size,
 
130
                       const void *symbols, int symbols_wrap, int symbols_size,
105
131
                       uint32_t code_prefix, int n_prefix, int flags)
106
132
{
107
 
    int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2;
 
133
    int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol;
108
134
    uint32_t code;
109
135
    VLC_TYPE (*table)[2];
110
136
 
111
137
    table_size = 1 << table_nb_bits;
112
138
    table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_STATIC);
113
139
#ifdef DEBUG_VLC
114
 
    printf("new table index=%d size=%d code_prefix=%x n=%d\n",
 
140
    av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n",
115
141
           table_index, table_size, code_prefix, n_prefix);
116
142
#endif
117
143
    if (table_index < 0)
130
156
        /* we accept tables with holes */
131
157
        if (n <= 0)
132
158
            continue;
 
159
        if (!symbols)
 
160
            symbol = i;
 
161
        else
 
162
            GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size);
133
163
#if defined(DEBUG_VLC) && 0
134
 
        printf("i=%d n=%d code=0x%x\n", i, n, code);
 
164
        av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code);
135
165
#endif
136
166
        /* if code matches the prefix, it is in the table */
137
167
        n -= n_prefix;
156
186
                        return -1;
157
187
                    }
158
188
                    table[j][1] = n; //bits
159
 
                    table[j][0] = i; //code
 
189
                    table[j][0] = symbol;
160
190
                    j++;
161
191
                }
162
192
            } else {
163
193
                n -= table_nb_bits;
164
194
                j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
165
195
#ifdef DEBUG_VLC
166
 
                printf("%4x: n=%d (subtable)\n",
 
196
                av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n",
167
197
                       j, n);
168
198
#endif
169
199
                /* compute table size */
187
217
            index = build_table(vlc, n, nb_codes,
188
218
                                bits, bits_wrap, bits_size,
189
219
                                codes, codes_wrap, codes_size,
 
220
                                symbols, symbols_wrap, symbols_size,
190
221
                                (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i),
191
222
                                n_prefix + table_nb_bits, flags);
192
223
            if (index < 0)
212
243
 
213
244
   'codes' : table which gives the bit pattern of of each vlc code.
214
245
 
 
246
   'symbols' : table which gives the values to be returned from get_vlc().
 
247
 
215
248
   'xxx_wrap' : give the number of bytes between each entry of the
216
249
   'bits' or 'codes' tables.
217
250
 
219
252
   or 'codes' tables.
220
253
 
221
254
   'wrap' and 'size' allows to use any memory configuration and types
222
 
   (byte/word/long) to store the 'bits' and 'codes' tables.
 
255
   (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
223
256
 
224
257
   'use_static' should be set to 1 for tables, which should be freed
225
258
   with av_free_static(), 0 if free_vlc() will be used.
226
259
*/
227
 
int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
 
260
int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
228
261
             const void *bits, int bits_wrap, int bits_size,
229
262
             const void *codes, int codes_wrap, int codes_size,
230
 
             int use_static)
 
263
             const void *symbols, int symbols_wrap, int symbols_size,
 
264
             int flags)
231
265
{
232
266
    vlc->bits = nb_bits;
233
 
    if(!use_static) {
 
267
    if(!(flags & INIT_VLC_USE_STATIC)) {
234
268
        vlc->table = NULL;
235
269
        vlc->table_allocated = 0;
236
270
        vlc->table_size = 0;
242
276
    }
243
277
 
244
278
#ifdef DEBUG_VLC
245
 
    printf("build table nb_codes=%d\n", nb_codes);
 
279
    av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes);
246
280
#endif
247
281
 
248
282
    if (build_table(vlc, nb_bits, nb_codes,
249
283
                    bits, bits_wrap, bits_size,
250
284
                    codes, codes_wrap, codes_size,
251
 
                    0, 0, use_static) < 0) {
252
 
        av_free(vlc->table);
 
285
                    symbols, symbols_wrap, symbols_size,
 
286
                    0, 0, flags) < 0) {
 
287
        av_freep(&vlc->table);
253
288
        return -1;
254
289
    }
255
290
    return 0;
258
293
 
259
294
void free_vlc(VLC *vlc)
260
295
{
261
 
    av_free(vlc->table);
 
296
    av_freep(&vlc->table);
262
297
}
263
298