43 while (root * 2 + 1 < size) {
44 int child = root * 2 + 1;
45 if (child < size - 1 && h[child].
val > h[child+1].
val)
47 if (h[root].
val > h[child].
val) {
58 int *up =
av_malloc(
sizeof(*up) * 2 * size);
63 if (!h || !up || !len) {
68 for (offset = 1; ; offset <<= 1) {
69 for (i=0; i <
size; i++) {
71 h[i].
val = (stats[i] << 14) + offset;
73 for (i = size / 2 - 1; i >= 0; i--)
76 for (next = size; next < size * 2 - 1; next++) {
78 uint64_t min1v = h[0].
val;
88 len[2 * size - 2] = 0;
89 for (i = 2 * size - 3; i >=
size; i--)
90 len[i] = len[up[i]] + 1;
91 for (i = 0; i <
size; i++) {
92 dst[i] = len[up[i]] + 1;
93 if (dst[i] >= 32)
break;
105 Node *nodes,
int node,
106 uint32_t pfx,
int pl,
int *pos,
int no_zero_count)
111 if (s !=
HNODE || (no_zero_count && !nodes[node].
count)) {
122 get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0 + 1, pfx, pl,
136 &pos, no_zero_count);
137 return ff_init_vlc_sparse(vlc, nb_bits, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0);
152 for (i = 0; i < nb_codes; i++) {
155 sum += nodes[i].
count;
160 "Too high symbol frequencies. "
161 "Tree construction is not possible\n");
164 qsort(nodes, nb_codes,
sizeof(
Node), cmp);
166 nodes[nb_codes*2-1].
count = 0;
167 for (i = 0; i < nb_codes * 2 - 1; i += 2) {
168 uint32_t cur_count = nodes[i].
count + nodes[i+1].
count;
171 for(j = cur_node; j > i + 2; j--){
172 if(cur_count > nodes[j-1].
count ||
173 (cur_count == nodes[j-1].
count &&
176 nodes[j] = nodes[j - 1];
179 nodes[j].
count = cur_count;
183 if (
build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags, nb_bits) < 0) {