45 while (root * 2 + 1 < size) {
46 int child = root * 2 + 1;
47 if (child < size - 1 && h[child].
val > h[child+1].
val)
49 if (h[root].
val > h[child].
val) {
65 for (offset = 1; ; offset <<= 1) {
66 for (i=0; i <
size; i++) {
68 h[i].
val = (stats[i] << 8) + offset;
70 for (i = size / 2 - 1; i >= 0; i--)
73 for (next = size; next < size * 2 - 1; next++) {
75 uint64_t min1v = h[0].
val;
85 len[2 * size - 2] = 0;
86 for (i = 2 * size - 3; i >=
size; i--)
87 len[i] = len[up[i]] + 1;
88 for (i = 0; i <
size; i++) {
89 dst[i] = len[up[i]] + 1;
90 if (dst[i] >= 32)
break;
97 Node *nodes,
int node,
98 uint32_t pfx,
int pl,
int *pos,
int no_zero_count)
103 if (s !=
HNODE || (no_zero_count && !nodes[node].count)) {
114 get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0 + 1, pfx, pl,
128 &pos, no_zero_count);
129 return ff_init_vlc_sparse(vlc, nb_bits, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0);
144 for (i = 0; i < nb_codes; i++) {
147 sum += nodes[i].
count;
152 "Too high symbol frequencies. " 153 "Tree construction is not possible\n");
156 qsort(nodes, nb_codes,
sizeof(
Node), cmp);
158 nodes[nb_codes*2-1].
count = 0;
159 for (i = 0; i < nb_codes * 2 - 1; i += 2) {
162 nodes[cur_node].
n0 = i;
163 for (j = cur_node; j > 0; j--) {
164 if (nodes[j].count > nodes[j - 1].count ||
165 (nodes[j].count == nodes[j - 1].count &&
167 nodes[j].n0 == j - 1 || nodes[j].n0 == j - 2 ||
168 (nodes[j].sym!=
HNODE && nodes[j-1].sym!=
HNODE))))
174 if (
build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags, nb_bits) < 0) {
#define FF_HUFFMAN_FLAG_HNODE_FIRST
static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t *xlat, Node *nodes, int node, uint32_t pfx, int pl, int *pos, int no_zero_count)
int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes, int nb_bits, Node *nodes, HuffCmp cmp, int flags)
nodes size must be 2*nb_codes first nb_codes nodes.count must be set
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
void ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats)
static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits)
int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
static void heap_sift(HeapElem *h, int root, int size)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_HUFFMAN_FLAG_ZERO_COUNT
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
Libavcodec external API header.
main external API structure.
huffman tree builder and VLC generator
common internal and external API header
#define FFSWAP(type, a, b)
int(* HuffCmp)(const void *va, const void *vb)