Avoids having to create the codes ourselves.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -115,40 +115,36 @@ end: · 114 unmodified lines | ||
| 115 | 115 | return ret; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | −static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t *xlat, | |
| 119 | − Node *nodes, int node, | |
| 120 | − uint32_t pfx, int pl, int *pos, int no_zero_count) | |
| 118 | +static void get_tree_codes(int8_t *lens, uint8_t *xlat, | |
| 119 | + Node *nodes, int node, int pl, int *pos, int no_zero_count) | |
| 121 | 120 | { |
| 122 | 121 | int s; |
| 123 | 122 | |
| 124 | 123 | s = nodes[node].sym; |
| 125 | 124 | if (s != HNODE || (no_zero_count && !nodes[node].count)) { |
| 126 | − bits[*pos] = pfx; | |
| 127 | 125 | lens[*pos] = pl; |
| 128 | 126 | xlat[*pos] = s; |
| 129 | 127 | (*pos)++; |
| 130 | 128 | } else { |
| 131 | − pfx <<= 1; | |
| 132 | 129 | pl++; |
| 133 | − get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0, pfx, pl, | |
| 130 | + get_tree_codes(lens, xlat, nodes, nodes[node].n0, pl, | |
| 134 | 131 | pos, no_zero_count); |
| 135 | − pfx |= 1; | |
| 136 | − get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0 + 1, pfx, pl, | |
| 132 | + get_tree_codes(lens, xlat, nodes, nodes[node].n0 + 1, pl, | |
| 137 | 133 | pos, no_zero_count); |
| 138 | 134 | } |
| 139 | 135 | } |
| 140 | 136 | |
| 141 | −static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits) | |
| 137 | +static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits, void *logctx) | |
| 142 | 138 | { |
| 143 | 139 | int no_zero_count = !(flags & FF_HUFFMAN_FLAG_ZERO_COUNT); |
| 144 | − uint32_t bits[256]; | |
| 145 | − int16_t lens[256]; | |
| 140 | + int8_t lens[256]; | |
| 146 | 141 | uint8_t xlat[256]; |
| 147 | 142 | int pos = 0; |
| 148 | 143 | |
| 149 | − get_tree_codes(bits, lens, xlat, nodes, head, 0, 0, | |
| 144 | + get_tree_codes(lens, xlat, nodes, head, 0, | |
| 150 | 145 | &pos, no_zero_count); |
| 151 | − return ff_vlc_init_sparse(vlc, nb_bits, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0); | |
| 146 | + return ff_vlc_init_from_lengths(vlc, nb_bits, pos, lens, 1, | |
| 147 | + xlat, 1, 1, 0, 0, logctx); | |
| 152 | 148 | } |
| 153 | 149 | |
| 154 | 150 | |
| @@ -194,7 +190,7 @@ int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits, · 39 unmodified lines | ||
| 194 | 190 | nodes[j].n0 = i; |
| 195 | 191 | cur_node++; |
| 196 | 192 | } |
| 197 | − if (build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags, nb_bits) < 0) { | |
| 193 | + if (build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags, nb_bits, logctx) < 0) { | |
| 198 | 194 | av_log(logctx, AV_LOG_ERROR, "Error building tree\n"); |
| 199 | 195 | return -1; |
| 200 | 196 | } |