*/
#include "avcodec.h"
+#include "internal.h"
#include "mathops.h"
#include "get_bits.h"
#include "put_bits.h"
vlc->table_size += size;
if (vlc->table_size > vlc->table_allocated) {
+ int err;
if (use_static)
return AVERROR_BUG;
vlc->table_allocated += (1 << vlc->bits);
- vlc->table = av_realloc(vlc->table, sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
- if (!vlc->table)
- return AVERROR(ENOMEM);
+ if ((err = av_reallocp(&vlc->table,
+ sizeof(VLC_TYPE) * 2 *
+ vlc->table_allocated)) < 0) {
+ vlc->table_allocated = 0;
+ vlc->table_size = 0;
+ return err;
+ }
}
return index;
}
(uint32_t)ff_reverse[ x >> 24];
}
-typedef struct {
+typedef struct VLCcode {
uint8_t bits;
uint16_t symbol;
/** codeword, with the first bit-to-be-read in the msb
table_size = 1 << table_nb_bits;
table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);
- av_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);
+ ff_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);
if (table_index < 0)
return table_index;
table = &vlc->table[table_index];
n = codes[i].bits;
code = codes[i].code;
symbol = codes[i].symbol;
- av_dlog(NULL, "i=%d n=%d code=0x%x\n", i, n, code);
+ ff_dlog(NULL, "i=%d n=%d code=0x%x\n", i, n, code);
if (n <= table_nb_bits) {
/* no need to add another table */
j = code >> (32 - table_nb_bits);
inc = 1 << n;
}
for (k = 0; k < nb; k++) {
- av_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n);
+ ff_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n);
if (table[j][1] /*bits*/ != 0) {
av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
return AVERROR_INVALIDDATA;
subtable_bits = FFMIN(subtable_bits, table_nb_bits);
j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;
table[j][1] = -subtable_bits;
- av_dlog(NULL, "%4x: n=%d (subtable)\n",
+ ff_dlog(NULL, "%4x: n=%d (subtable)\n",
j, codes[i].bits + table_nb_bits);
index = build_table(vlc, subtable_bits, k-i, codes+i, flags);
if (index < 0)
vlc->table_size = 0;
}
- av_dlog(NULL, "build table nb_codes=%d\n", nb_codes);
+ ff_dlog(NULL, "build table nb_codes=%d\n", nb_codes);
buf = av_malloc((nb_codes + 1) * sizeof(VLCcode));
+ if (!buf)
+ return AVERROR(ENOMEM);
assert(symbols_size <= 2 || !symbols);
j = 0;