Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * HEVC Parameter Set decoding | ||
3 | * | ||
4 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
5 | * Copyright (C) 2012 - 2013 Mickael Raulet | ||
6 | * Copyright (C) 2012 - 2013 Gildas Cocherel | ||
7 | * Copyright (C) 2013 Vittorio Giovara | ||
8 | * | ||
9 | * This file is part of FFmpeg. | ||
10 | * | ||
11 | * FFmpeg is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU Lesser General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2.1 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * FFmpeg is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * Lesser General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Lesser General Public | ||
22 | * License along with FFmpeg; if not, write to the Free Software | ||
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
24 | */ | ||
25 | |||
26 | #include "libavutil/imgutils.h" | ||
27 | #include "libavutil/mem.h" | ||
28 | #include "golomb.h" | ||
29 | #include "h2645_vui.h" | ||
30 | #include "data.h" | ||
31 | #include "ps.h" | ||
32 | #include "profiles.h" | ||
33 | #include "refstruct.h" | ||
34 | |||
35 | static const uint8_t default_scaling_list_intra[] = { | ||
36 | 16, 16, 16, 16, 17, 18, 21, 24, | ||
37 | 16, 16, 16, 16, 17, 19, 22, 25, | ||
38 | 16, 16, 17, 18, 20, 22, 25, 29, | ||
39 | 16, 16, 18, 21, 24, 27, 31, 36, | ||
40 | 17, 17, 20, 24, 30, 35, 41, 47, | ||
41 | 18, 19, 22, 27, 35, 44, 54, 65, | ||
42 | 21, 22, 25, 31, 41, 54, 70, 88, | ||
43 | 24, 25, 29, 36, 47, 65, 88, 115 | ||
44 | }; | ||
45 | |||
46 | static const uint8_t default_scaling_list_inter[] = { | ||
47 | 16, 16, 16, 16, 17, 18, 20, 24, | ||
48 | 16, 16, 16, 17, 18, 20, 24, 25, | ||
49 | 16, 16, 17, 18, 20, 24, 25, 28, | ||
50 | 16, 17, 18, 20, 24, 25, 28, 33, | ||
51 | 17, 18, 20, 24, 25, 28, 33, 41, | ||
52 | 18, 20, 24, 25, 28, 33, 41, 54, | ||
53 | 20, 24, 25, 28, 33, 41, 54, 71, | ||
54 | 24, 25, 28, 33, 41, 54, 71, 91 | ||
55 | }; | ||
56 | |||
57 | static const uint8_t hevc_sub_width_c[] = { | ||
58 | 1, 2, 2, 1 | ||
59 | }; | ||
60 | |||
61 | static const uint8_t hevc_sub_height_c[] = { | ||
62 | 1, 2, 1, 1 | ||
63 | }; | ||
64 | |||
65 | 658 | static void remove_sps(HEVCParamSets *s, int id) | |
66 | { | ||
67 | int i; | ||
68 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 647 times.
|
658 | if (s->sps_list[id]) { |
69 | /* drop all PPS that depend on this SPS */ | ||
70 |
2/2✓ Branch 0 taken 704 times.
✓ Branch 1 taken 11 times.
|
715 | for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) |
71 |
3/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 693 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
704 | if (s->pps_list[i] && s->pps_list[i]->sps_id == id) |
72 | 11 | ff_refstruct_unref(&s->pps_list[i]); | |
73 | |||
74 | 11 | ff_refstruct_unref(&s->sps_list[id]); | |
75 | } | ||
76 | 658 | } | |
77 | |||
78 | 645 | static void remove_vps(HEVCParamSets *s, int id) | |
79 | { | ||
80 | int i; | ||
81 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 642 times.
|
645 | if (s->vps_list[id]) { |
82 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 3 times.
|
51 | for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) |
83 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
48 | if (s->sps_list[i] && s->sps_list[i]->vps_id == id) |
84 | 3 | remove_sps(s, i); | |
85 | 3 | ff_refstruct_unref(&s->vps_list[id]); | |
86 | } | ||
87 | 645 | } | |
88 | |||
89 | 12606 | int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, | |
90 | ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header) | ||
91 | { | ||
92 | int delta_poc; | ||
93 | 12606 | int k0 = 0; | |
94 | 12606 | int k = 0; | |
95 | int i; | ||
96 | |||
97 | 12606 | rps->used = 0; | |
98 | 12606 | rps->rps_predict = 0; | |
99 | |||
100 |
4/4✓ Branch 0 taken 11667 times.
✓ Branch 1 taken 939 times.
✓ Branch 2 taken 11364 times.
✓ Branch 3 taken 303 times.
|
12606 | if (rps != sps->st_rps && sps->nb_st_rps) |
101 | 11364 | rps->rps_predict = get_bits1(gb); | |
102 | |||
103 |
2/2✓ Branch 0 taken 7566 times.
✓ Branch 1 taken 5040 times.
|
12606 | if (rps->rps_predict) { |
104 | const ShortTermRPS *rps_ridx; | ||
105 | 7566 | uint8_t used[32] = { 0 }; | |
106 | int delta_rps; | ||
107 | |||
108 |
2/2✓ Branch 0 taken 619 times.
✓ Branch 1 taken 6947 times.
|
7566 | if (is_slice_header) { |
109 | 619 | rps->delta_idx = get_ue_golomb_long(gb) + 1; | |
110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 619 times.
|
619 | if (rps->delta_idx > sps->nb_st_rps) { |
111 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
112 | "Invalid value of delta_idx in slice header RPS: %d > %d.\n", | ||
113 | ✗ | rps->delta_idx, sps->nb_st_rps); | |
114 | ✗ | return AVERROR_INVALIDDATA; | |
115 | } | ||
116 | 619 | rps_ridx = &sps->st_rps[sps->nb_st_rps - rps->delta_idx]; | |
117 | 619 | rps->rps_idx_num_delta_pocs = rps_ridx->num_delta_pocs; | |
118 | } else | ||
119 | 6947 | rps_ridx = &sps->st_rps[rps - sps->st_rps - 1]; | |
120 | |||
121 | 7566 | rps->delta_rps_sign = get_bits1(gb); | |
122 | 7566 | rps->abs_delta_rps = get_ue_golomb_long(gb) + 1; | |
123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7566 times.
|
7566 | if (rps->abs_delta_rps > 32768) { |
124 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
125 | "Invalid value of abs_delta_rps: %d\n", | ||
126 | ✗ | rps->abs_delta_rps); | |
127 | ✗ | return AVERROR_INVALIDDATA; | |
128 | } | ||
129 | 7566 | delta_rps = (1 - (rps->delta_rps_sign << 1)) * rps->abs_delta_rps; | |
130 |
2/2✓ Branch 0 taken 32810 times.
✓ Branch 1 taken 7566 times.
|
40376 | for (i = 0; i <= rps_ridx->num_delta_pocs; i++) { |
131 | 32810 | used[k] = get_bits1(gb); | |
132 | |||
133 | 32810 | rps->use_delta = 0; | |
134 |
2/2✓ Branch 0 taken 6497 times.
✓ Branch 1 taken 26313 times.
|
32810 | if (!used[k]) |
135 | 6497 | rps->use_delta = get_bits1(gb); | |
136 | |||
137 |
4/4✓ Branch 0 taken 6497 times.
✓ Branch 1 taken 26313 times.
✓ Branch 2 taken 50 times.
✓ Branch 3 taken 6447 times.
|
32810 | if (used[k] || rps->use_delta) { |
138 |
2/2✓ Branch 0 taken 20769 times.
✓ Branch 1 taken 5594 times.
|
26363 | if (i < rps_ridx->num_delta_pocs) |
139 | 20769 | delta_poc = delta_rps + rps_ridx->delta_poc[i]; | |
140 | else | ||
141 | 5594 | delta_poc = delta_rps; | |
142 | 26363 | rps->delta_poc[k] = delta_poc; | |
143 |
2/2✓ Branch 0 taken 18304 times.
✓ Branch 1 taken 8059 times.
|
26363 | if (delta_poc < 0) |
144 | 18304 | k0++; | |
145 | 26363 | k++; | |
146 | } | ||
147 | } | ||
148 | |||
149 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7566 times.
|
7566 | if (k >= FF_ARRAY_ELEMS(used)) { |
150 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
151 | "Invalid num_delta_pocs: %d\n", k); | ||
152 | ✗ | return AVERROR_INVALIDDATA; | |
153 | } | ||
154 | |||
155 | 7566 | rps->num_delta_pocs = k; | |
156 | 7566 | rps->num_negative_pics = k0; | |
157 | // sort in increasing order (smallest first) | ||
158 |
1/2✓ Branch 0 taken 7566 times.
✗ Branch 1 not taken.
|
7566 | if (rps->num_delta_pocs != 0) { |
159 | int u, tmp; | ||
160 |
2/2✓ Branch 0 taken 18797 times.
✓ Branch 1 taken 7566 times.
|
26363 | for (i = 1; i < rps->num_delta_pocs; i++) { |
161 | 18797 | delta_poc = rps->delta_poc[i]; | |
162 | 18797 | u = used[i]; | |
163 |
2/2✓ Branch 0 taken 35026 times.
✓ Branch 1 taken 18797 times.
|
53823 | for (k = i - 1; k >= 0; k--) { |
164 | 35026 | tmp = rps->delta_poc[k]; | |
165 |
2/2✓ Branch 0 taken 11215 times.
✓ Branch 1 taken 23811 times.
|
35026 | if (delta_poc < tmp) { |
166 | 11215 | rps->delta_poc[k + 1] = tmp; | |
167 | 11215 | used[k + 1] = used[k]; | |
168 | 11215 | rps->delta_poc[k] = delta_poc; | |
169 | 11215 | used[k] = u; | |
170 | } | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 |
2/2✓ Branch 0 taken 5751 times.
✓ Branch 1 taken 1815 times.
|
7566 | if ((rps->num_negative_pics >> 1) != 0) { |
175 | int u; | ||
176 | 5751 | k = rps->num_negative_pics - 1; | |
177 | // flip the negative values to largest first | ||
178 |
2/2✓ Branch 0 taken 7560 times.
✓ Branch 1 taken 5751 times.
|
13311 | for (i = 0; i < rps->num_negative_pics >> 1; i++) { |
179 | 7560 | delta_poc = rps->delta_poc[i]; | |
180 | 7560 | u = used[i]; | |
181 | 7560 | rps->delta_poc[i] = rps->delta_poc[k]; | |
182 | 7560 | used[i] = used[k]; | |
183 | 7560 | rps->delta_poc[k] = delta_poc; | |
184 | 7560 | used[k] = u; | |
185 | 7560 | k--; | |
186 | } | ||
187 | } | ||
188 | |||
189 |
2/2✓ Branch 0 taken 242112 times.
✓ Branch 1 taken 7566 times.
|
249678 | for (unsigned i = 0; i < FF_ARRAY_ELEMS(used); i++) |
190 | 242112 | rps->used |= (uint32_t)used[i] << i; | |
191 | } else { | ||
192 | unsigned int nb_positive_pics; | ||
193 | |||
194 | 5040 | rps->num_negative_pics = get_ue_golomb_long(gb); | |
195 | 5040 | nb_positive_pics = get_ue_golomb_long(gb); | |
196 | |||
197 |
2/4✓ Branch 0 taken 5040 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5040 times.
|
5040 | if (rps->num_negative_pics >= HEVC_MAX_REFS || |
198 | nb_positive_pics >= HEVC_MAX_REFS) { | ||
199 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many refs in a short term RPS.\n"); | |
200 | ✗ | return AVERROR_INVALIDDATA; | |
201 | } | ||
202 | |||
203 | 5040 | rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics; | |
204 |
2/2✓ Branch 0 taken 4668 times.
✓ Branch 1 taken 372 times.
|
5040 | if (rps->num_delta_pocs) { |
205 | 4668 | int prev = 0; | |
206 | |||
207 |
2/2✓ Branch 0 taken 13993 times.
✓ Branch 1 taken 4668 times.
|
18661 | for (i = 0; i < rps->num_negative_pics; i++) { |
208 | 13993 | delta_poc = get_ue_golomb_long(gb) + 1; | |
209 |
2/4✓ Branch 0 taken 13993 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13993 times.
|
13993 | if (delta_poc < 1 || delta_poc > 32768) { |
210 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
211 | "Invalid value of delta_poc: %d\n", | ||
212 | delta_poc); | ||
213 | ✗ | return AVERROR_INVALIDDATA; | |
214 | } | ||
215 | 13993 | prev -= delta_poc; | |
216 | 13993 | rps->delta_poc[i] = prev; | |
217 | 13993 | rps->used |= get_bits1(gb) * (1 << i); | |
218 | } | ||
219 | 4668 | prev = 0; | |
220 |
2/2✓ Branch 0 taken 1217 times.
✓ Branch 1 taken 4668 times.
|
5885 | for (i = 0; i < nb_positive_pics; i++) { |
221 | 1217 | delta_poc = get_ue_golomb_long(gb) + 1; | |
222 |
2/4✓ Branch 0 taken 1217 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1217 times.
|
1217 | if (delta_poc < 1 || delta_poc > 32768) { |
223 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
224 | "Invalid value of delta_poc: %d\n", | ||
225 | delta_poc); | ||
226 | ✗ | return AVERROR_INVALIDDATA; | |
227 | } | ||
228 | 1217 | prev += delta_poc; | |
229 | 1217 | rps->delta_poc[rps->num_negative_pics + i] = prev; | |
230 | 1217 | rps->used |= get_bits1(gb) * (1 << (rps->num_negative_pics + i)); | |
231 | } | ||
232 | } | ||
233 | } | ||
234 | 12606 | return 0; | |
235 | } | ||
236 | |||
237 | |||
238 | 1773 | static int decode_profile_tier_level(GetBitContext *gb, AVCodecContext *avctx, | |
239 | PTLCommon *ptl) | ||
240 | { | ||
241 | 1773 | const char *profile_name = NULL; | |
242 | int i; | ||
243 | |||
244 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1773 times.
|
1773 | if (get_bits_left(gb) < 2+1+5 + 32 + 4 + 43 + 1) |
245 | ✗ | return -1; | |
246 | |||
247 | 1773 | ptl->profile_space = get_bits(gb, 2); | |
248 | 1773 | ptl->tier_flag = get_bits1(gb); | |
249 | 1773 | ptl->profile_idc = get_bits(gb, 5); | |
250 | |||
251 | #if !CONFIG_SMALL | ||
252 |
2/2✓ Branch 0 taken 2483 times.
✓ Branch 1 taken 40 times.
|
2523 | for (int i = 0; ff_hevc_profiles[i].profile != AV_PROFILE_UNKNOWN; i++) |
253 |
2/2✓ Branch 0 taken 1733 times.
✓ Branch 1 taken 750 times.
|
2483 | if (ff_hevc_profiles[i].profile == ptl->profile_idc) { |
254 | 1733 | profile_name = ff_hevc_profiles[i].name; | |
255 | 1733 | break; | |
256 | } | ||
257 | #endif | ||
258 |
4/4✓ Branch 0 taken 1733 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 1733 times.
✓ Branch 3 taken 40 times.
|
1773 | av_log(avctx, profile_name ? AV_LOG_DEBUG : AV_LOG_WARNING, |
259 | "%s profile bitstream\n", profile_name ? profile_name : "Unknown"); | ||
260 | |||
261 |
2/2✓ Branch 0 taken 56736 times.
✓ Branch 1 taken 1773 times.
|
58509 | for (i = 0; i < 32; i++) { |
262 | 56736 | ptl->profile_compatibility_flag[i] = get_bits1(gb); | |
263 | |||
264 |
6/6✓ Branch 0 taken 96 times.
✓ Branch 1 taken 56640 times.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 32 times.
|
56736 | if (ptl->profile_idc == 0 && i > 0 && ptl->profile_compatibility_flag[i]) |
265 | 32 | ptl->profile_idc = i; | |
266 | } | ||
267 | 1773 | ptl->progressive_source_flag = get_bits1(gb); | |
268 | 1773 | ptl->interlaced_source_flag = get_bits1(gb); | |
269 | 1773 | ptl->non_packed_constraint_flag = get_bits1(gb); | |
270 | 1773 | ptl->frame_only_constraint_flag = get_bits1(gb); | |
271 | |||
272 | #define check_profile_idc(idc) \ | ||
273 | ptl->profile_idc == idc || ptl->profile_compatibility_flag[idc] | ||
274 | |||
275 |
8/12✓ Branch 0 taken 1669 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 1669 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1661 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 1661 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1661 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1661 times.
✗ Branch 11 not taken.
|
1773 | if (check_profile_idc(4) || check_profile_idc(5) || check_profile_idc(6) || |
276 |
6/12✓ Branch 0 taken 1661 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1661 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1661 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1661 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1661 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1661 times.
✗ Branch 11 not taken.
|
1661 | check_profile_idc(7) || check_profile_idc(8) || check_profile_idc(9) || |
277 |
2/4✓ Branch 0 taken 1661 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1661 times.
|
1661 | check_profile_idc(10)) { |
278 | |||
279 | 112 | ptl->max_12bit_constraint_flag = get_bits1(gb); | |
280 | 112 | ptl->max_10bit_constraint_flag = get_bits1(gb); | |
281 | 112 | ptl->max_8bit_constraint_flag = get_bits1(gb); | |
282 | 112 | ptl->max_422chroma_constraint_flag = get_bits1(gb); | |
283 | 112 | ptl->max_420chroma_constraint_flag = get_bits1(gb); | |
284 | 112 | ptl->max_monochrome_constraint_flag = get_bits1(gb); | |
285 | 112 | ptl->intra_constraint_flag = get_bits1(gb); | |
286 | 112 | ptl->one_picture_only_constraint_flag = get_bits1(gb); | |
287 | 112 | ptl->lower_bit_rate_constraint_flag = get_bits1(gb); | |
288 | |||
289 |
7/12✓ Branch 0 taken 104 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 104 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 104 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 104 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 104 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 104 times.
|
112 | if (check_profile_idc(5) || check_profile_idc(9) || check_profile_idc(10)) { |
290 | 8 | ptl->max_14bit_constraint_flag = get_bits1(gb); | |
291 | 8 | skip_bits_long(gb, 33); // XXX_reserved_zero_33bits[0..32] | |
292 | } else { | ||
293 | 104 | skip_bits_long(gb, 34); // XXX_reserved_zero_34bits[0..33] | |
294 | } | ||
295 |
4/4✓ Branch 0 taken 1445 times.
✓ Branch 1 taken 216 times.
✓ Branch 2 taken 1194 times.
✓ Branch 3 taken 251 times.
|
1661 | } else if (check_profile_idc(2)) { |
296 | 1410 | skip_bits(gb, 7); | |
297 | 1410 | ptl->one_picture_only_constraint_flag = get_bits1(gb); | |
298 | 1410 | skip_bits_long(gb, 35); // XXX_reserved_zero_35bits[0..34] | |
299 | } else { | ||
300 | 251 | skip_bits_long(gb, 43); // XXX_reserved_zero_43bits[0..42] | |
301 | } | ||
302 | |||
303 |
9/12✓ Branch 0 taken 335 times.
✓ Branch 1 taken 1438 times.
✓ Branch 2 taken 328 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 112 times.
✓ Branch 5 taken 216 times.
✓ Branch 6 taken 112 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 112 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 112 times.
✗ Branch 11 not taken.
|
1773 | if (check_profile_idc(1) || check_profile_idc(2) || check_profile_idc(3) || |
304 |
4/12✓ Branch 0 taken 8 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
112 | check_profile_idc(4) || check_profile_idc(5) || check_profile_idc(9)) |
305 | 1773 | ptl->inbld_flag = get_bits1(gb); | |
306 | else | ||
307 | ✗ | skip_bits1(gb); | |
308 | #undef check_profile_idc | ||
309 | |||
310 | 1773 | return 0; | |
311 | } | ||
312 | |||
313 | 1731 | static int parse_ptl(GetBitContext *gb, AVCodecContext *avctx, | |
314 | PTL *ptl, int max_num_sub_layers) | ||
315 | { | ||
316 | int i; | ||
317 |
2/4✓ Branch 1 taken 1731 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1731 times.
|
3462 | if (decode_profile_tier_level(gb, avctx, &ptl->general_ptl) < 0 || |
318 |
2/2✓ Branch 1 taken 153 times.
✓ Branch 2 taken 1578 times.
|
1731 | get_bits_left(gb) < 8 + (8*2 * (max_num_sub_layers - 1 > 0))) { |
319 | ✗ | av_log(avctx, AV_LOG_ERROR, "PTL information too short\n"); | |
320 | ✗ | return -1; | |
321 | } | ||
322 | |||
323 | 1731 | ptl->general_ptl.level_idc = get_bits(gb, 8); | |
324 | |||
325 |
2/2✓ Branch 0 taken 303 times.
✓ Branch 1 taken 1731 times.
|
2034 | for (i = 0; i < max_num_sub_layers - 1; i++) { |
326 | 303 | ptl->sub_layer_profile_present_flag[i] = get_bits1(gb); | |
327 | 303 | ptl->sub_layer_level_present_flag[i] = get_bits1(gb); | |
328 | } | ||
329 | |||
330 |
2/2✓ Branch 0 taken 153 times.
✓ Branch 1 taken 1578 times.
|
1731 | if (max_num_sub_layers - 1> 0) |
331 |
2/2✓ Branch 0 taken 921 times.
✓ Branch 1 taken 153 times.
|
1074 | for (i = max_num_sub_layers - 1; i < 8; i++) |
332 | 921 | skip_bits(gb, 2); // reserved_zero_2bits[i] | |
333 |
2/2✓ Branch 0 taken 303 times.
✓ Branch 1 taken 1731 times.
|
2034 | for (i = 0; i < max_num_sub_layers - 1; i++) { |
334 |
3/4✓ Branch 0 taken 42 times.
✓ Branch 1 taken 261 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 42 times.
|
345 | if (ptl->sub_layer_profile_present_flag[i] && |
335 | 42 | decode_profile_tier_level(gb, avctx, &ptl->sub_layer_ptl[i]) < 0) { | |
336 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
337 | "PTL information for sublayer %i too short\n", i); | ||
338 | ✗ | return -1; | |
339 | } | ||
340 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 261 times.
|
303 | if (ptl->sub_layer_level_present_flag[i]) { |
341 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
|
42 | if (get_bits_left(gb) < 8) { |
342 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
343 | "Not enough data for sublayer %i level_idc\n", i); | ||
344 | ✗ | return -1; | |
345 | } else | ||
346 | 42 | ptl->sub_layer_ptl[i].level_idc = get_bits(gb, 8); | |
347 | } | ||
348 | } | ||
349 | |||
350 | 1731 | return 0; | |
351 | } | ||
352 | |||
353 | 101 | static void decode_sublayer_hrd(GetBitContext *gb, unsigned int nb_cpb, | |
354 | HEVCSublayerHdrParams *par, int subpic_params_present) | ||
355 | { | ||
356 | int i; | ||
357 | |||
358 |
2/2✓ Branch 0 taken 101 times.
✓ Branch 1 taken 101 times.
|
202 | for (i = 0; i < nb_cpb; i++) { |
359 | 101 | par->bit_rate_value_minus1[i] = get_ue_golomb_long(gb); | |
360 | 101 | par->cpb_size_value_minus1[i] = get_ue_golomb_long(gb); | |
361 | |||
362 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 67 times.
|
101 | if (subpic_params_present) { |
363 | 34 | par->cpb_size_du_value_minus1[i] = get_ue_golomb_long(gb); | |
364 | 34 | par->bit_rate_du_value_minus1[i] = get_ue_golomb_long(gb); | |
365 | } | ||
366 | |||
367 | 101 | par->cbr_flag |= get_bits1(gb) << i; | |
368 | } | ||
369 | 101 | } | |
370 | |||
371 | 53 | static int decode_hrd(GetBitContext *gb, int common_inf_present, | |
372 | HEVCHdrParams *hdr, int max_sublayers) | ||
373 | { | ||
374 |
1/2✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
|
53 | if (common_inf_present) { |
375 | 53 | hdr->nal_hrd_parameters_present_flag = get_bits1(gb); | |
376 | 53 | hdr->vcl_hrd_parameters_present_flag = get_bits1(gb); | |
377 | |||
378 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
|
53 | if (hdr->nal_hrd_parameters_present_flag || |
379 | ✗ | hdr->vcl_hrd_parameters_present_flag) { | |
380 | 53 | hdr->sub_pic_hrd_params_present_flag = get_bits1(gb); | |
381 | |||
382 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 36 times.
|
53 | if (hdr->sub_pic_hrd_params_present_flag) { |
383 | 17 | hdr->tick_divisor_minus2 = get_bits(gb, 8); | |
384 | 17 | hdr->du_cpb_removal_delay_increment_length_minus1 = get_bits(gb, 5); | |
385 | 17 | hdr->sub_pic_cpb_params_in_pic_timing_sei_flag = get_bits1(gb); | |
386 | 17 | hdr->dpb_output_delay_du_length_minus1 = get_bits(gb, 5); | |
387 | } | ||
388 | |||
389 | 53 | hdr->bit_rate_scale = get_bits(gb, 4); | |
390 | 53 | hdr->cpb_size_scale = get_bits(gb, 4); | |
391 | |||
392 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 36 times.
|
53 | if (hdr->sub_pic_hrd_params_present_flag) |
393 | 17 | hdr->cpb_size_du_scale = get_bits(gb, 4); | |
394 | |||
395 | 53 | hdr->initial_cpb_removal_delay_length_minus1 = get_bits(gb, 5); | |
396 | 53 | hdr->au_cpb_removal_delay_length_minus1 = get_bits(gb, 5); | |
397 | 53 | hdr->dpb_output_delay_length_minus1 = get_bits(gb, 5); | |
398 | } | ||
399 | } | ||
400 | |||
401 |
2/2✓ Branch 0 taken 53 times.
✓ Branch 1 taken 53 times.
|
106 | for (int i = 0; i < max_sublayers; i++) { |
402 | 53 | unsigned fixed_pic_rate_general_flag = get_bits1(gb); | |
403 | 53 | unsigned fixed_pic_rate_within_cvs_flag = 0; | |
404 | 53 | unsigned low_delay_hrd_flag = 0; | |
405 | 53 | hdr->flags.fixed_pic_rate_general_flag |= fixed_pic_rate_general_flag << i; | |
406 | |||
407 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 30 times.
|
53 | if (!fixed_pic_rate_general_flag) |
408 | 23 | fixed_pic_rate_within_cvs_flag = get_bits1(gb); | |
409 | 53 | hdr->flags.fixed_pic_rate_within_cvs_flag |= fixed_pic_rate_within_cvs_flag << i; | |
410 | |||
411 |
3/4✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 23 times.
|
53 | if (fixed_pic_rate_within_cvs_flag || fixed_pic_rate_general_flag) |
412 | 30 | hdr->elemental_duration_in_tc_minus1[i] = get_ue_golomb_long(gb); | |
413 | else | ||
414 | 23 | low_delay_hrd_flag = get_bits1(gb); | |
415 | 53 | hdr->flags.low_delay_hrd_flag |= low_delay_hrd_flag << i; | |
416 | |||
417 |
1/2✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
|
53 | if (!low_delay_hrd_flag) { |
418 | 53 | unsigned cpb_cnt_minus1 = get_ue_golomb_long(gb); | |
419 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
|
53 | if (cpb_cnt_minus1 > 31) { |
420 | ✗ | av_log(NULL, AV_LOG_ERROR, "nb_cpb %d invalid\n", | |
421 | cpb_cnt_minus1); | ||
422 | ✗ | return AVERROR_INVALIDDATA; | |
423 | } | ||
424 | 53 | hdr->cpb_cnt_minus1[i] = cpb_cnt_minus1; | |
425 | } | ||
426 | |||
427 |
1/2✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
|
53 | if (hdr->nal_hrd_parameters_present_flag) |
428 | 53 | decode_sublayer_hrd(gb, hdr->cpb_cnt_minus1[i]+1, &hdr->nal_params[i], | |
429 | 53 | hdr->sub_pic_hrd_params_present_flag); | |
430 | |||
431 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 5 times.
|
53 | if (hdr->vcl_hrd_parameters_present_flag) |
432 | 48 | decode_sublayer_hrd(gb, hdr->cpb_cnt_minus1[i]+1, &hdr->vcl_params[i], | |
433 | 48 | hdr->sub_pic_hrd_params_present_flag); | |
434 | } | ||
435 | |||
436 | 53 | return 0; | |
437 | } | ||
438 | |||
439 | 645 | static void hevc_vps_free(FFRefStructOpaque opaque, void *obj) | |
440 | { | ||
441 | 645 | HEVCVPS *vps = obj; | |
442 | |||
443 | 645 | av_freep(&vps->hdr); | |
444 | 645 | av_freep(&vps->data); | |
445 | 645 | } | |
446 | |||
447 | 1093 | int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, | |
448 | HEVCParamSets *ps) | ||
449 | { | ||
450 | int i,j; | ||
451 | 1093 | int vps_id = get_bits(gb, 4); | |
452 | 1093 | ptrdiff_t nal_size = gb->buffer_end - gb->buffer; | |
453 | 1093 | int ret = AVERROR_INVALIDDATA; | |
454 | HEVCVPS *vps; | ||
455 | |||
456 |
2/2✓ Branch 0 taken 451 times.
✓ Branch 1 taken 642 times.
|
1093 | if (ps->vps_list[vps_id]) { |
457 | 451 | const HEVCVPS *vps1 = ps->vps_list[vps_id]; | |
458 |
1/2✓ Branch 0 taken 451 times.
✗ Branch 1 not taken.
|
451 | if (vps1->data_size == nal_size && |
459 |
2/2✓ Branch 0 taken 448 times.
✓ Branch 1 taken 3 times.
|
451 | !memcmp(vps1->data, gb->buffer, vps1->data_size)) |
460 | 448 | return 0; | |
461 | } | ||
462 | |||
463 | 645 | vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL, hevc_vps_free); | |
464 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 645 times.
|
645 | if (!vps) |
465 | ✗ | return AVERROR(ENOMEM); | |
466 | |||
467 | 645 | av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n"); | |
468 | |||
469 | 645 | vps->data_size = nal_size; | |
470 | 645 | vps->data = av_memdup(gb->buffer, nal_size); | |
471 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 645 times.
|
645 | if (!vps->data) { |
472 | ✗ | ret = AVERROR(ENOMEM); | |
473 | ✗ | goto err; | |
474 | } | ||
475 | 645 | vps->vps_id = vps_id; | |
476 | |||
477 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 645 times.
|
645 | if (get_bits(gb, 2) != 3) { // vps_reserved_three_2bits |
478 | ✗ | av_log(avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n"); | |
479 | ✗ | goto err; | |
480 | } | ||
481 | |||
482 | 645 | vps->vps_max_layers = get_bits(gb, 6) + 1; | |
483 | 645 | vps->vps_max_sub_layers = get_bits(gb, 3) + 1; | |
484 | 645 | vps->vps_temporal_id_nesting_flag = get_bits1(gb); | |
485 | |||
486 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 645 times.
|
645 | if (get_bits(gb, 16) != 0xffff) { // vps_reserved_ffff_16bits |
487 | ✗ | av_log(avctx, AV_LOG_ERROR, "vps_reserved_ffff_16bits is not 0xffff\n"); | |
488 | ✗ | goto err; | |
489 | } | ||
490 | |||
491 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 645 times.
|
645 | if (vps->vps_max_sub_layers > HEVC_MAX_SUB_LAYERS) { |
492 | ✗ | av_log(avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n", | |
493 | ✗ | vps->vps_max_sub_layers); | |
494 | ✗ | goto err; | |
495 | } | ||
496 | |||
497 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 645 times.
|
645 | if (parse_ptl(gb, avctx, &vps->ptl, vps->vps_max_sub_layers) < 0) |
498 | ✗ | goto err; | |
499 | |||
500 | 645 | vps->vps_sub_layer_ordering_info_present_flag = get_bits1(gb); | |
501 | |||
502 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 569 times.
|
645 | i = vps->vps_sub_layer_ordering_info_present_flag ? 0 : vps->vps_max_sub_layers - 1; |
503 |
2/2✓ Branch 0 taken 703 times.
✓ Branch 1 taken 645 times.
|
1348 | for (; i < vps->vps_max_sub_layers; i++) { |
504 | 703 | vps->vps_max_dec_pic_buffering[i] = get_ue_golomb_long(gb) + 1; | |
505 | 703 | vps->vps_num_reorder_pics[i] = get_ue_golomb_long(gb); | |
506 | 703 | vps->vps_max_latency_increase[i] = get_ue_golomb_long(gb) - 1; | |
507 | |||
508 |
2/4✓ Branch 0 taken 703 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 703 times.
|
703 | if (vps->vps_max_dec_pic_buffering[i] > HEVC_MAX_DPB_SIZE || !vps->vps_max_dec_pic_buffering[i]) { |
509 | ✗ | av_log(avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out of range: %d\n", | |
510 | ✗ | vps->vps_max_dec_pic_buffering[i] - 1); | |
511 | ✗ | goto err; | |
512 | } | ||
513 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 703 times.
|
703 | if (vps->vps_num_reorder_pics[i] > vps->vps_max_dec_pic_buffering[i] - 1) { |
514 | ✗ | av_log(avctx, AV_LOG_WARNING, "vps_max_num_reorder_pics out of range: %d\n", | |
515 | ✗ | vps->vps_num_reorder_pics[i]); | |
516 | ✗ | if (avctx->err_recognition & AV_EF_EXPLODE) | |
517 | ✗ | goto err; | |
518 | } | ||
519 | } | ||
520 | |||
521 | 645 | vps->vps_max_layer_id = get_bits(gb, 6); | |
522 | 645 | vps->vps_num_layer_sets = get_ue_golomb_long(gb) + 1; | |
523 |
2/4✓ Branch 0 taken 645 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 645 times.
✗ Branch 3 not taken.
|
645 | if (vps->vps_num_layer_sets < 1 || vps->vps_num_layer_sets > 1024 || |
524 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 645 times.
|
645 | (vps->vps_num_layer_sets - 1LL) * (vps->vps_max_layer_id + 1LL) > get_bits_left(gb)) { |
525 | ✗ | av_log(avctx, AV_LOG_ERROR, "too many layer_id_included_flags\n"); | |
526 | ✗ | goto err; | |
527 | } | ||
528 | |||
529 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 645 times.
|
647 | for (i = 1; i < vps->vps_num_layer_sets; i++) |
530 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | for (j = 0; j <= vps->vps_max_layer_id; j++) |
531 | 4 | skip_bits(gb, 1); // layer_id_included_flag[i][j] | |
532 | |||
533 | 645 | vps->vps_timing_info_present_flag = get_bits1(gb); | |
534 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 623 times.
|
645 | if (vps->vps_timing_info_present_flag) { |
535 | 22 | vps->vps_num_units_in_tick = get_bits_long(gb, 32); | |
536 | 22 | vps->vps_time_scale = get_bits_long(gb, 32); | |
537 | 22 | vps->vps_poc_proportional_to_timing_flag = get_bits1(gb); | |
538 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | if (vps->vps_poc_proportional_to_timing_flag) |
539 | 22 | vps->vps_num_ticks_poc_diff_one = get_ue_golomb_long(gb) + 1; | |
540 | 22 | vps->vps_num_hrd_parameters = get_ue_golomb_long(gb); | |
541 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | if (vps->vps_num_hrd_parameters > (unsigned)vps->vps_num_layer_sets) { |
542 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
543 | ✗ | "vps_num_hrd_parameters %d is invalid\n", vps->vps_num_hrd_parameters); | |
544 | ✗ | goto err; | |
545 | } | ||
546 | |||
547 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 19 times.
|
22 | if (vps->vps_num_hrd_parameters) { |
548 | 3 | vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); | |
549 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!vps->hdr) |
550 | ✗ | goto err; | |
551 | } | ||
552 | |||
553 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 22 times.
|
25 | for (i = 0; i < vps->vps_num_hrd_parameters; i++) { |
554 | 3 | int common_inf_present = 1; | |
555 | |||
556 | 3 | get_ue_golomb_long(gb); // hrd_layer_set_idx | |
557 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (i) |
558 | ✗ | common_inf_present = get_bits1(gb); | |
559 | 3 | decode_hrd(gb, common_inf_present, &vps->hdr[i], | |
560 | 3 | vps->vps_max_sub_layers); | |
561 | } | ||
562 | } | ||
563 | 645 | get_bits1(gb); /* vps_extension_flag */ | |
564 | |||
565 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 645 times.
|
645 | if (get_bits_left(gb) < 0) { |
566 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
567 | ✗ | "Overread VPS by %d bits\n", -get_bits_left(gb)); | |
568 | ✗ | if (ps->vps_list[vps_id]) | |
569 | ✗ | goto err; | |
570 | } | ||
571 | |||
572 | 645 | remove_vps(ps, vps_id); | |
573 | 645 | ps->vps_list[vps_id] = vps; | |
574 | |||
575 | 645 | return 0; | |
576 | |||
577 | ✗ | err: | |
578 | ✗ | ff_refstruct_unref(&vps); | |
579 | ✗ | return ret; | |
580 | } | ||
581 | |||
582 | 286 | static void decode_vui(GetBitContext *gb, AVCodecContext *avctx, | |
583 | int apply_defdispwin, HEVCSPS *sps) | ||
584 | { | ||
585 | 286 | VUI backup_vui, *vui = &sps->vui; | |
586 | GetBitContext backup; | ||
587 | 286 | int alt = 0; | |
588 | |||
589 | 286 | ff_h2645_decode_common_vui_params(gb, &sps->vui.common, avctx); | |
590 | |||
591 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 219 times.
|
286 | if (vui->common.video_signal_type_present_flag) { |
592 |
4/4✓ Branch 0 taken 10 times.
✓ Branch 1 taken 57 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 5 times.
|
67 | if (vui->common.video_full_range_flag && sps->pix_fmt == AV_PIX_FMT_YUV420P) |
593 | 5 | sps->pix_fmt = AV_PIX_FMT_YUVJ420P; | |
594 |
2/2✓ Branch 0 taken 62 times.
✓ Branch 1 taken 5 times.
|
67 | if (vui->common.colour_description_present_flag) { |
595 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | if (vui->common.matrix_coeffs == AVCOL_SPC_RGB) { |
596 | ✗ | switch (sps->pix_fmt) { | |
597 | ✗ | case AV_PIX_FMT_YUV444P: | |
598 | ✗ | sps->pix_fmt = AV_PIX_FMT_GBRP; | |
599 | ✗ | break; | |
600 | ✗ | case AV_PIX_FMT_YUV444P10: | |
601 | ✗ | sps->pix_fmt = AV_PIX_FMT_GBRP10; | |
602 | ✗ | break; | |
603 | ✗ | case AV_PIX_FMT_YUV444P12: | |
604 | ✗ | sps->pix_fmt = AV_PIX_FMT_GBRP12; | |
605 | ✗ | break; | |
606 | } | ||
607 | } | ||
608 | } | ||
609 | } | ||
610 | |||
611 | 286 | vui->neutra_chroma_indication_flag = get_bits1(gb); | |
612 | 286 | vui->field_seq_flag = get_bits1(gb); | |
613 | 286 | vui->frame_field_info_present_flag = get_bits1(gb); | |
614 | |||
615 | // Backup context in case an alternate header is detected | ||
616 | 286 | memcpy(&backup, gb, sizeof(backup)); | |
617 | 286 | memcpy(&backup_vui, vui, sizeof(backup_vui)); | |
618 |
3/4✓ Branch 1 taken 105 times.
✓ Branch 2 taken 181 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 105 times.
|
286 | if (get_bits_left(gb) >= 68 && show_bits(gb, 21) == 0x100000) { |
619 | ✗ | vui->default_display_window_flag = 0; | |
620 | ✗ | av_log(avctx, AV_LOG_WARNING, "Invalid default display window\n"); | |
621 | } else | ||
622 | 286 | vui->default_display_window_flag = get_bits1(gb); | |
623 | |||
624 |
2/2✓ Branch 0 taken 172 times.
✓ Branch 1 taken 114 times.
|
286 | if (vui->default_display_window_flag) { |
625 | 114 | int vert_mult = hevc_sub_height_c[sps->chroma_format_idc]; | |
626 | 114 | int horiz_mult = hevc_sub_width_c[sps->chroma_format_idc]; | |
627 | 114 | vui->def_disp_win.left_offset = get_ue_golomb_long(gb) * horiz_mult; | |
628 | 114 | vui->def_disp_win.right_offset = get_ue_golomb_long(gb) * horiz_mult; | |
629 | 114 | vui->def_disp_win.top_offset = get_ue_golomb_long(gb) * vert_mult; | |
630 | 114 | vui->def_disp_win.bottom_offset = get_ue_golomb_long(gb) * vert_mult; | |
631 | |||
632 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 54 times.
|
114 | if (apply_defdispwin && |
633 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | avctx->flags2 & AV_CODEC_FLAG2_IGNORE_CROP) { |
634 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
635 | "discarding vui default display window, " | ||
636 | "original values are l:%u r:%u t:%u b:%u\n", | ||
637 | vui->def_disp_win.left_offset, | ||
638 | vui->def_disp_win.right_offset, | ||
639 | vui->def_disp_win.top_offset, | ||
640 | vui->def_disp_win.bottom_offset); | ||
641 | |||
642 | ✗ | vui->def_disp_win.left_offset = | |
643 | ✗ | vui->def_disp_win.right_offset = | |
644 | ✗ | vui->def_disp_win.top_offset = | |
645 | ✗ | vui->def_disp_win.bottom_offset = 0; | |
646 | } | ||
647 | } | ||
648 | |||
649 | 286 | timing_info: | |
650 | 286 | vui->vui_timing_info_present_flag = get_bits1(gb); | |
651 | |||
652 |
2/2✓ Branch 0 taken 105 times.
✓ Branch 1 taken 181 times.
|
286 | if (vui->vui_timing_info_present_flag) { |
653 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 105 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
105 | if( get_bits_left(gb) < 66 && !alt) { |
654 | // The alternate syntax seem to have timing info located | ||
655 | // at where def_disp_win is normally located | ||
656 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
657 | "Strange VUI timing information, retrying...\n"); | ||
658 | ✗ | memcpy(vui, &backup_vui, sizeof(backup_vui)); | |
659 | ✗ | memcpy(gb, &backup, sizeof(backup)); | |
660 | ✗ | alt = 1; | |
661 | ✗ | goto timing_info; | |
662 | } | ||
663 | 105 | vui->vui_num_units_in_tick = get_bits_long(gb, 32); | |
664 | 105 | vui->vui_time_scale = get_bits_long(gb, 32); | |
665 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 105 times.
|
105 | if (alt) { |
666 | ✗ | av_log(avctx, AV_LOG_INFO, "Retry got %"PRIu32"/%"PRIu32" fps\n", | |
667 | vui->vui_time_scale, vui->vui_num_units_in_tick); | ||
668 | } | ||
669 | 105 | vui->vui_poc_proportional_to_timing_flag = get_bits1(gb); | |
670 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 67 times.
|
105 | if (vui->vui_poc_proportional_to_timing_flag) |
671 | 38 | vui->vui_num_ticks_poc_diff_one_minus1 = get_ue_golomb_long(gb); | |
672 | 105 | vui->vui_hrd_parameters_present_flag = get_bits1(gb); | |
673 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 55 times.
|
105 | if (vui->vui_hrd_parameters_present_flag) |
674 | 50 | decode_hrd(gb, 1, &sps->hdr, sps->max_sub_layers); | |
675 | } | ||
676 | |||
677 | 286 | vui->bitstream_restriction_flag = get_bits1(gb); | |
678 |
2/2✓ Branch 0 taken 116 times.
✓ Branch 1 taken 170 times.
|
286 | if (vui->bitstream_restriction_flag) { |
679 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
116 | if (get_bits_left(gb) < 8 && !alt) { |
680 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
681 | "Strange VUI bitstream restriction information, retrying" | ||
682 | " from timing information...\n"); | ||
683 | ✗ | memcpy(vui, &backup_vui, sizeof(backup_vui)); | |
684 | ✗ | memcpy(gb, &backup, sizeof(backup)); | |
685 | ✗ | alt = 1; | |
686 | ✗ | goto timing_info; | |
687 | } | ||
688 | 116 | vui->tiles_fixed_structure_flag = get_bits1(gb); | |
689 | 116 | vui->motion_vectors_over_pic_boundaries_flag = get_bits1(gb); | |
690 | 116 | vui->restricted_ref_pic_lists_flag = get_bits1(gb); | |
691 | 116 | vui->min_spatial_segmentation_idc = get_ue_golomb_long(gb); | |
692 | 116 | vui->max_bytes_per_pic_denom = get_ue_golomb_long(gb); | |
693 | 116 | vui->max_bits_per_min_cu_denom = get_ue_golomb_long(gb); | |
694 | 116 | vui->log2_max_mv_length_horizontal = get_ue_golomb_long(gb); | |
695 | 116 | vui->log2_max_mv_length_vertical = get_ue_golomb_long(gb); | |
696 | } | ||
697 | |||
698 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 286 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
286 | if (get_bits_left(gb) < 1 && !alt) { |
699 | // XXX: Alternate syntax when sps_range_extension_flag != 0? | ||
700 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
701 | "Overread in VUI, retrying from timing information...\n"); | ||
702 | ✗ | memcpy(vui, &backup_vui, sizeof(backup_vui)); | |
703 | ✗ | memcpy(gb, &backup, sizeof(backup)); | |
704 | ✗ | alt = 1; | |
705 | ✗ | goto timing_info; | |
706 | } | ||
707 | 286 | } | |
708 | |||
709 | 162 | static void set_default_scaling_list_data(ScalingList *sl) | |
710 | { | ||
711 | int matrixId; | ||
712 | |||
713 |
2/2✓ Branch 0 taken 972 times.
✓ Branch 1 taken 162 times.
|
1134 | for (matrixId = 0; matrixId < 6; matrixId++) { |
714 | // 4x4 default is 16 | ||
715 | 972 | memset(sl->sl[0][matrixId], 16, 16); | |
716 | 972 | sl->sl_dc[0][matrixId] = 16; // default for 16x16 | |
717 | 972 | sl->sl_dc[1][matrixId] = 16; // default for 32x32 | |
718 | } | ||
719 | 162 | memcpy(sl->sl[1][0], default_scaling_list_intra, 64); | |
720 | 162 | memcpy(sl->sl[1][1], default_scaling_list_intra, 64); | |
721 | 162 | memcpy(sl->sl[1][2], default_scaling_list_intra, 64); | |
722 | 162 | memcpy(sl->sl[1][3], default_scaling_list_inter, 64); | |
723 | 162 | memcpy(sl->sl[1][4], default_scaling_list_inter, 64); | |
724 | 162 | memcpy(sl->sl[1][5], default_scaling_list_inter, 64); | |
725 | 162 | memcpy(sl->sl[2][0], default_scaling_list_intra, 64); | |
726 | 162 | memcpy(sl->sl[2][1], default_scaling_list_intra, 64); | |
727 | 162 | memcpy(sl->sl[2][2], default_scaling_list_intra, 64); | |
728 | 162 | memcpy(sl->sl[2][3], default_scaling_list_inter, 64); | |
729 | 162 | memcpy(sl->sl[2][4], default_scaling_list_inter, 64); | |
730 | 162 | memcpy(sl->sl[2][5], default_scaling_list_inter, 64); | |
731 | 162 | memcpy(sl->sl[3][0], default_scaling_list_intra, 64); | |
732 | 162 | memcpy(sl->sl[3][1], default_scaling_list_intra, 64); | |
733 | 162 | memcpy(sl->sl[3][2], default_scaling_list_intra, 64); | |
734 | 162 | memcpy(sl->sl[3][3], default_scaling_list_inter, 64); | |
735 | 162 | memcpy(sl->sl[3][4], default_scaling_list_inter, 64); | |
736 | 162 | memcpy(sl->sl[3][5], default_scaling_list_inter, 64); | |
737 | 162 | } | |
738 | |||
739 | 141 | static int scaling_list_data(GetBitContext *gb, AVCodecContext *avctx, | |
740 | ScalingList *sl, const HEVCSPS *sps) | ||
741 | { | ||
742 | uint8_t scaling_list_pred_mode_flag; | ||
743 | uint8_t scaling_list_dc_coef[2][6]; | ||
744 | int size_id, matrix_id, pos; | ||
745 | int i; | ||
746 | |||
747 |
2/2✓ Branch 0 taken 564 times.
✓ Branch 1 taken 141 times.
|
705 | for (size_id = 0; size_id < 4; size_id++) |
748 |
4/4✓ Branch 0 taken 282 times.
✓ Branch 1 taken 2538 times.
✓ Branch 2 taken 2820 times.
✓ Branch 3 taken 564 times.
|
3384 | for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) { |
749 | 2820 | scaling_list_pred_mode_flag = get_bits1(gb); | |
750 |
2/2✓ Branch 0 taken 759 times.
✓ Branch 1 taken 2061 times.
|
2820 | if (!scaling_list_pred_mode_flag) { |
751 | 759 | unsigned int delta = get_ue_golomb_long(gb); | |
752 | /* Only need to handle non-zero delta. Zero means default, | ||
753 | * which should already be in the arrays. */ | ||
754 |
2/2✓ Branch 0 taken 633 times.
✓ Branch 1 taken 126 times.
|
759 | if (delta) { |
755 | // Copy from previous array. | ||
756 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 633 times.
|
633 | delta *= (size_id == 3) ? 3 : 1; |
757 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 633 times.
|
633 | if (matrix_id < delta) { |
758 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
759 | "Invalid delta in scaling list data: %d.\n", delta); | ||
760 | ✗ | return AVERROR_INVALIDDATA; | |
761 | } | ||
762 | |||
763 |
2/2✓ Branch 0 taken 400 times.
✓ Branch 1 taken 233 times.
|
633 | memcpy(sl->sl[size_id][matrix_id], |
764 | 633 | sl->sl[size_id][matrix_id - delta], | |
765 | size_id > 0 ? 64 : 16); | ||
766 |
2/2✓ Branch 0 taken 127 times.
✓ Branch 1 taken 506 times.
|
633 | if (size_id > 1) |
767 | 127 | sl->sl_dc[size_id - 2][matrix_id] = sl->sl_dc[size_id - 2][matrix_id - delta]; | |
768 | } | ||
769 | } else { | ||
770 | int next_coef, coef_num; | ||
771 | int32_t scaling_list_delta_coef; | ||
772 | |||
773 | 2061 | next_coef = 8; | |
774 | 2061 | coef_num = FFMIN(64, 1 << (4 + (size_id << 1))); | |
775 |
2/2✓ Branch 0 taken 959 times.
✓ Branch 1 taken 1102 times.
|
2061 | if (size_id > 1) { |
776 | 959 | int scaling_list_coeff_minus8 = get_se_golomb(gb); | |
777 |
2/4✓ Branch 0 taken 959 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 959 times.
|
959 | if (scaling_list_coeff_minus8 < -7 || |
778 | scaling_list_coeff_minus8 > 247) | ||
779 | ✗ | return AVERROR_INVALIDDATA; | |
780 | 959 | scaling_list_dc_coef[size_id - 2][matrix_id] = scaling_list_coeff_minus8 + 8; | |
781 | 959 | next_coef = scaling_list_dc_coef[size_id - 2][matrix_id]; | |
782 | 959 | sl->sl_dc[size_id - 2][matrix_id] = next_coef; | |
783 | } | ||
784 |
2/2✓ Branch 0 taken 103488 times.
✓ Branch 1 taken 2061 times.
|
105549 | for (i = 0; i < coef_num; i++) { |
785 |
2/2✓ Branch 0 taken 9472 times.
✓ Branch 1 taken 94016 times.
|
103488 | if (size_id == 0) |
786 | 9472 | pos = 4 * ff_hevc_diag_scan4x4_y[i] + | |
787 | 9472 | ff_hevc_diag_scan4x4_x[i]; | |
788 | else | ||
789 | 94016 | pos = 8 * ff_hevc_diag_scan8x8_y[i] + | |
790 | 94016 | ff_hevc_diag_scan8x8_x[i]; | |
791 | |||
792 | 103488 | scaling_list_delta_coef = get_se_golomb(gb); | |
793 | 103488 | next_coef = (next_coef + 256U + scaling_list_delta_coef) % 256; | |
794 | 103488 | sl->sl[size_id][matrix_id][pos] = next_coef; | |
795 | } | ||
796 | } | ||
797 | } | ||
798 | |||
799 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 98 times.
|
141 | if (sps->chroma_format_idc == 3) { |
800 |
2/2✓ Branch 0 taken 2752 times.
✓ Branch 1 taken 43 times.
|
2795 | for (i = 0; i < 64; i++) { |
801 | 2752 | sl->sl[3][1][i] = sl->sl[2][1][i]; | |
802 | 2752 | sl->sl[3][2][i] = sl->sl[2][2][i]; | |
803 | 2752 | sl->sl[3][4][i] = sl->sl[2][4][i]; | |
804 | 2752 | sl->sl[3][5][i] = sl->sl[2][5][i]; | |
805 | } | ||
806 | 43 | sl->sl_dc[1][1] = sl->sl_dc[0][1]; | |
807 | 43 | sl->sl_dc[1][2] = sl->sl_dc[0][2]; | |
808 | 43 | sl->sl_dc[1][4] = sl->sl_dc[0][4]; | |
809 | 43 | sl->sl_dc[1][5] = sl->sl_dc[0][5]; | |
810 | } | ||
811 | |||
812 | |||
813 | 141 | return 0; | |
814 | } | ||
815 | |||
816 | 1086 | static int map_pixel_format(AVCodecContext *avctx, HEVCSPS *sps) | |
817 | { | ||
818 | const AVPixFmtDescriptor *desc; | ||
819 |
3/5✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 137 times.
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
|
1086 | switch (sps->bit_depth) { |
820 | 926 | case 8: | |
821 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 922 times.
|
926 | if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8; |
822 |
2/2✓ Branch 0 taken 913 times.
✓ Branch 1 taken 13 times.
|
926 | if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P; |
823 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 926 times.
|
926 | if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P; |
824 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 917 times.
|
926 | if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P; |
825 | 926 | break; | |
826 | ✗ | case 9: | |
827 | ✗ | if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY9; | |
828 | ✗ | if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P9; | |
829 | ✗ | if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P9; | |
830 | ✗ | if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P9; | |
831 | ✗ | break; | |
832 | 137 | case 10: | |
833 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 137 times.
|
137 | if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY10; |
834 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 29 times.
|
137 | if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10; |
835 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 108 times.
|
137 | if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10; |
836 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 137 times.
|
137 | if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10; |
837 | 137 | break; | |
838 | 23 | case 12: | |
839 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY12; |
840 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12; |
841 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12; |
842 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12; |
843 | 23 | break; | |
844 | ✗ | default: | |
845 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
846 | "The following bit-depths are currently specified: 8, 9, 10 and 12 bits, " | ||
847 | "chroma_format_idc is %d, depth is %d\n", | ||
848 | sps->chroma_format_idc, sps->bit_depth); | ||
849 | ✗ | return AVERROR_INVALIDDATA; | |
850 | } | ||
851 | |||
852 | 1086 | desc = av_pix_fmt_desc_get(sps->pix_fmt); | |
853 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (!desc) |
854 | ✗ | return AVERROR(EINVAL); | |
855 | |||
856 | 1086 | sps->hshift[0] = sps->vshift[0] = 0; | |
857 | 1086 | sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w; | |
858 | 1086 | sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h; | |
859 | |||
860 | 1086 | sps->pixel_shift = sps->bit_depth > 8; | |
861 | |||
862 | 1086 | return 0; | |
863 | } | ||
864 | |||
865 | 1086 | int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, | |
866 | int apply_defdispwin, const HEVCVPS * const *vps_list, | ||
867 | AVCodecContext *avctx) | ||
868 | { | ||
869 | HEVCWindow *ow; | ||
870 | 1086 | int ret = 0; | |
871 | int bit_depth_chroma, start, num_comps; | ||
872 | int i; | ||
873 | |||
874 | // Coded parameters | ||
875 | |||
876 | 1086 | sps->vps_id = get_bits(gb, 4); | |
877 | |||
878 |
1/2✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
|
1086 | if (vps_list) { |
879 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (!vps_list[sps->vps_id]) { |
880 | ✗ | av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n", | |
881 | sps->vps_id); | ||
882 | ✗ | return AVERROR_INVALIDDATA; | |
883 | } | ||
884 | 1086 | sps->vps = ff_refstruct_ref_c(vps_list[sps->vps_id]); | |
885 | } | ||
886 | |||
887 | 1086 | sps->max_sub_layers = get_bits(gb, 3) + 1; | |
888 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->max_sub_layers > HEVC_MAX_SUB_LAYERS) { |
889 | ✗ | av_log(avctx, AV_LOG_ERROR, "sps_max_sub_layers out of range: %d\n", | |
890 | sps->max_sub_layers); | ||
891 | ✗ | return AVERROR_INVALIDDATA; | |
892 | } | ||
893 | |||
894 | 1086 | sps->temporal_id_nesting = get_bits(gb, 1); | |
895 | |||
896 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1086 times.
|
1086 | if ((ret = parse_ptl(gb, avctx, &sps->ptl, sps->max_sub_layers)) < 0) |
897 | ✗ | return ret; | |
898 | |||
899 | 1086 | *sps_id = get_ue_golomb_long(gb); | |
900 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (*sps_id >= HEVC_MAX_SPS_COUNT) { |
901 | ✗ | av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", *sps_id); | |
902 | ✗ | return AVERROR_INVALIDDATA; | |
903 | } | ||
904 | |||
905 | 1086 | sps->chroma_format_idc = get_ue_golomb_long(gb); | |
906 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->chroma_format_idc > 3U) { |
907 | ✗ | av_log(avctx, AV_LOG_ERROR, "chroma_format_idc %d is invalid\n", sps->chroma_format_idc); | |
908 | ✗ | return AVERROR_INVALIDDATA; | |
909 | } | ||
910 | |||
911 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1054 times.
|
1086 | if (sps->chroma_format_idc == 3) |
912 | 32 | sps->separate_colour_plane = get_bits1(gb); | |
913 | |||
914 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->separate_colour_plane) |
915 | ✗ | sps->chroma_format_idc = 0; | |
916 | |||
917 | 1086 | sps->width = get_ue_golomb_long(gb); | |
918 | 1086 | sps->height = get_ue_golomb_long(gb); | |
919 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if ((ret = av_image_check_size(sps->width, |
920 | 1086 | sps->height, 0, avctx)) < 0) | |
921 | ✗ | return ret; | |
922 | |||
923 | 1086 | sps->conformance_window = get_bits1(gb); | |
924 |
2/2✓ Branch 0 taken 895 times.
✓ Branch 1 taken 191 times.
|
1086 | if (sps->conformance_window) { |
925 | 895 | int vert_mult = hevc_sub_height_c[sps->chroma_format_idc]; | |
926 | 895 | int horiz_mult = hevc_sub_width_c[sps->chroma_format_idc]; | |
927 | 895 | sps->pic_conf_win.left_offset = get_ue_golomb_long(gb) * horiz_mult; | |
928 | 895 | sps->pic_conf_win.right_offset = get_ue_golomb_long(gb) * horiz_mult; | |
929 | 895 | sps->pic_conf_win.top_offset = get_ue_golomb_long(gb) * vert_mult; | |
930 | 895 | sps->pic_conf_win.bottom_offset = get_ue_golomb_long(gb) * vert_mult; | |
931 | |||
932 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 895 times.
|
895 | if (avctx->flags2 & AV_CODEC_FLAG2_IGNORE_CROP) { |
933 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
934 | "discarding sps conformance window, " | ||
935 | "original values are l:%u r:%u t:%u b:%u\n", | ||
936 | sps->pic_conf_win.left_offset, | ||
937 | sps->pic_conf_win.right_offset, | ||
938 | sps->pic_conf_win.top_offset, | ||
939 | sps->pic_conf_win.bottom_offset); | ||
940 | |||
941 | ✗ | sps->pic_conf_win.left_offset = | |
942 | ✗ | sps->pic_conf_win.right_offset = | |
943 | ✗ | sps->pic_conf_win.top_offset = | |
944 | ✗ | sps->pic_conf_win.bottom_offset = 0; | |
945 | } | ||
946 | 895 | sps->output_window = sps->pic_conf_win; | |
947 | } | ||
948 | |||
949 | 1086 | sps->bit_depth = get_ue_golomb_31(gb) + 8; | |
950 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->bit_depth > 16) { |
951 | ✗ | av_log(avctx, AV_LOG_ERROR, "Luma bit depth (%d) is out of range\n", | |
952 | sps->bit_depth); | ||
953 | ✗ | return AVERROR_INVALIDDATA; | |
954 | } | ||
955 | 1086 | bit_depth_chroma = get_ue_golomb_31(gb) + 8; | |
956 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (bit_depth_chroma > 16) { |
957 | ✗ | av_log(avctx, AV_LOG_ERROR, "Chroma bit depth (%d) is out of range\n", | |
958 | bit_depth_chroma); | ||
959 | ✗ | return AVERROR_INVALIDDATA; | |
960 | } | ||
961 |
3/4✓ Branch 0 taken 1082 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1082 times.
|
1086 | if (sps->chroma_format_idc && bit_depth_chroma != sps->bit_depth) { |
962 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
963 | "Luma bit depth (%d) is different from chroma bit depth (%d), " | ||
964 | "this is unsupported.\n", | ||
965 | sps->bit_depth, bit_depth_chroma); | ||
966 | ✗ | return AVERROR_INVALIDDATA; | |
967 | } | ||
968 | 1086 | sps->bit_depth_chroma = bit_depth_chroma; | |
969 | |||
970 | 1086 | ret = map_pixel_format(avctx, sps); | |
971 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (ret < 0) |
972 | ✗ | return ret; | |
973 | |||
974 | 1086 | sps->log2_max_poc_lsb = get_ue_golomb_long(gb) + 4; | |
975 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->log2_max_poc_lsb > 16) { |
976 | ✗ | av_log(avctx, AV_LOG_ERROR, "log2_max_pic_order_cnt_lsb_minus4 out range: %d\n", | |
977 | ✗ | sps->log2_max_poc_lsb - 4); | |
978 | ✗ | return AVERROR_INVALIDDATA; | |
979 | } | ||
980 | |||
981 | 1086 | sps->sublayer_ordering_info = get_bits1(gb); | |
982 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 934 times.
|
1086 | start = sps->sublayer_ordering_info ? 0 : sps->max_sub_layers - 1; |
983 |
2/2✓ Branch 0 taken 1233 times.
✓ Branch 1 taken 1086 times.
|
2319 | for (i = start; i < sps->max_sub_layers; i++) { |
984 | 1233 | sps->temporal_layer[i].max_dec_pic_buffering = get_ue_golomb_long(gb) + 1; | |
985 | 1233 | sps->temporal_layer[i].num_reorder_pics = get_ue_golomb_long(gb); | |
986 | 1233 | sps->temporal_layer[i].max_latency_increase = get_ue_golomb_long(gb) - 1; | |
987 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1233 times.
|
1233 | if (sps->temporal_layer[i].max_dec_pic_buffering > (unsigned)HEVC_MAX_DPB_SIZE) { |
988 | ✗ | av_log(avctx, AV_LOG_ERROR, "sps_max_dec_pic_buffering_minus1 out of range: %d\n", | |
989 | ✗ | sps->temporal_layer[i].max_dec_pic_buffering - 1U); | |
990 | ✗ | return AVERROR_INVALIDDATA; | |
991 | } | ||
992 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1233 times.
|
1233 | if (sps->temporal_layer[i].num_reorder_pics > sps->temporal_layer[i].max_dec_pic_buffering - 1) { |
993 | ✗ | av_log(avctx, AV_LOG_WARNING, "sps_max_num_reorder_pics out of range: %d\n", | |
994 | sps->temporal_layer[i].num_reorder_pics); | ||
995 | ✗ | if (avctx->err_recognition & AV_EF_EXPLODE || | |
996 | ✗ | sps->temporal_layer[i].num_reorder_pics > HEVC_MAX_DPB_SIZE - 1) { | |
997 | ✗ | return AVERROR_INVALIDDATA; | |
998 | } | ||
999 | ✗ | sps->temporal_layer[i].max_dec_pic_buffering = sps->temporal_layer[i].num_reorder_pics + 1; | |
1000 | } | ||
1001 | } | ||
1002 | |||
1003 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 934 times.
|
1086 | if (!sps->sublayer_ordering_info) { |
1004 |
2/2✓ Branch 0 taken 82 times.
✓ Branch 1 taken 152 times.
|
234 | for (i = 0; i < start; i++) { |
1005 | 82 | sps->temporal_layer[i].max_dec_pic_buffering = sps->temporal_layer[start].max_dec_pic_buffering; | |
1006 | 82 | sps->temporal_layer[i].num_reorder_pics = sps->temporal_layer[start].num_reorder_pics; | |
1007 | 82 | sps->temporal_layer[i].max_latency_increase = sps->temporal_layer[start].max_latency_increase; | |
1008 | } | ||
1009 | } | ||
1010 | |||
1011 | 1086 | sps->log2_min_cb_size = get_ue_golomb_long(gb) + 3; | |
1012 | 1086 | sps->log2_diff_max_min_coding_block_size = get_ue_golomb_long(gb); | |
1013 | 1086 | sps->log2_min_tb_size = get_ue_golomb_long(gb) + 2; | |
1014 | 1086 | sps->log2_diff_max_min_transform_block_size = get_ue_golomb_long(gb); | |
1015 | 1086 | sps->log2_max_trafo_size = sps->log2_diff_max_min_transform_block_size + | |
1016 | 1086 | sps->log2_min_tb_size; | |
1017 | |||
1018 |
2/4✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1086 times.
|
1086 | if (sps->log2_min_cb_size < 3 || sps->log2_min_cb_size > 30) { |
1019 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_min_cb_size", sps->log2_min_cb_size); | |
1020 | ✗ | return AVERROR_INVALIDDATA; | |
1021 | } | ||
1022 | |||
1023 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->log2_diff_max_min_coding_block_size > 30) { |
1024 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_coding_block_size", sps->log2_diff_max_min_coding_block_size); | |
1025 | ✗ | return AVERROR_INVALIDDATA; | |
1026 | } | ||
1027 | |||
1028 |
2/4✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1086 times.
|
1086 | if (sps->log2_min_tb_size >= sps->log2_min_cb_size || sps->log2_min_tb_size < 2) { |
1029 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid value for log2_min_tb_size"); | |
1030 | ✗ | return AVERROR_INVALIDDATA; | |
1031 | } | ||
1032 | |||
1033 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->log2_diff_max_min_transform_block_size > 30) { |
1034 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_transform_block_size", | |
1035 | sps->log2_diff_max_min_transform_block_size); | ||
1036 | ✗ | return AVERROR_INVALIDDATA; | |
1037 | } | ||
1038 | |||
1039 | 1086 | sps->max_transform_hierarchy_depth_inter = get_ue_golomb_long(gb); | |
1040 | 1086 | sps->max_transform_hierarchy_depth_intra = get_ue_golomb_long(gb); | |
1041 | |||
1042 | 1086 | sps->scaling_list_enabled = get_bits1(gb); | |
1043 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 1039 times.
|
1086 | if (sps->scaling_list_enabled) { |
1044 | 47 | set_default_scaling_list_data(&sps->scaling_list); | |
1045 | |||
1046 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 2 taken 21 times.
|
47 | if (get_bits1(gb)) { |
1047 | 26 | ret = scaling_list_data(gb, avctx, &sps->scaling_list, sps); | |
1048 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (ret < 0) |
1049 | ✗ | return ret; | |
1050 | } | ||
1051 | } | ||
1052 | |||
1053 | 1086 | sps->amp_enabled = get_bits1(gb); | |
1054 | 1086 | sps->sao_enabled = get_bits1(gb); | |
1055 | |||
1056 | 1086 | sps->pcm_enabled = get_bits1(gb); | |
1057 |
2/2✓ Branch 0 taken 75 times.
✓ Branch 1 taken 1011 times.
|
1086 | if (sps->pcm_enabled) { |
1058 | 75 | sps->pcm.bit_depth = get_bits(gb, 4) + 1; | |
1059 | 75 | sps->pcm.bit_depth_chroma = get_bits(gb, 4) + 1; | |
1060 | 75 | sps->pcm.log2_min_pcm_cb_size = get_ue_golomb_long(gb) + 3; | |
1061 | 150 | sps->pcm.log2_max_pcm_cb_size = sps->pcm.log2_min_pcm_cb_size + | |
1062 | 75 | get_ue_golomb_long(gb); | |
1063 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
|
75 | if (FFMAX(sps->pcm.bit_depth, sps->pcm.bit_depth_chroma) > sps->bit_depth) { |
1064 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1065 | "PCM bit depth (%d, %d) is greater than normal bit depth (%d)\n", | ||
1066 | ✗ | sps->pcm.bit_depth, sps->pcm.bit_depth_chroma, sps->bit_depth); | |
1067 | ✗ | return AVERROR_INVALIDDATA; | |
1068 | } | ||
1069 | |||
1070 | 75 | sps->pcm_loop_filter_disabled = get_bits1(gb); | |
1071 | } | ||
1072 | |||
1073 | 1086 | sps->nb_st_rps = get_ue_golomb_long(gb); | |
1074 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_REF_PIC_SETS) { |
1075 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n", | |
1076 | sps->nb_st_rps); | ||
1077 | ✗ | return AVERROR_INVALIDDATA; | |
1078 | } | ||
1079 |
2/2✓ Branch 0 taken 9351 times.
✓ Branch 1 taken 1086 times.
|
10437 | for (i = 0; i < sps->nb_st_rps; i++) { |
1080 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9351 times.
|
9351 | if ((ret = ff_hevc_decode_short_term_rps(gb, avctx, &sps->st_rps[i], |
1081 | sps, 0)) < 0) | ||
1082 | ✗ | return ret; | |
1083 | } | ||
1084 | |||
1085 | 1086 | sps->long_term_ref_pics_present = get_bits1(gb); | |
1086 |
2/2✓ Branch 0 taken 101 times.
✓ Branch 1 taken 985 times.
|
1086 | if (sps->long_term_ref_pics_present) { |
1087 | 101 | sps->num_long_term_ref_pics_sps = get_ue_golomb_long(gb); | |
1088 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 101 times.
|
101 | if (sps->num_long_term_ref_pics_sps > HEVC_MAX_LONG_TERM_REF_PICS) { |
1089 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many long term ref pics: %d.\n", | |
1090 | ✗ | sps->num_long_term_ref_pics_sps); | |
1091 | ✗ | return AVERROR_INVALIDDATA; | |
1092 | } | ||
1093 | |||
1094 | 101 | sps->used_by_curr_pic_lt = 0; | |
1095 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 101 times.
|
165 | for (i = 0; i < sps->num_long_term_ref_pics_sps; i++) { |
1096 | 64 | sps->lt_ref_pic_poc_lsb_sps[i] = get_bits(gb, sps->log2_max_poc_lsb); | |
1097 | 64 | sps->used_by_curr_pic_lt |= get_bits1(gb) << i; | |
1098 | } | ||
1099 | } | ||
1100 | |||
1101 | 1086 | sps->temporal_mvp_enabled = get_bits1(gb); | |
1102 | 1086 | sps->strong_intra_smoothing_enabled = get_bits1(gb); | |
1103 | 1086 | sps->vui.common.sar = (AVRational){0, 1}; | |
1104 | 1086 | sps->vui_present = get_bits1(gb); | |
1105 |
2/2✓ Branch 0 taken 286 times.
✓ Branch 1 taken 800 times.
|
1086 | if (sps->vui_present) |
1106 | 286 | decode_vui(gb, avctx, apply_defdispwin, sps); | |
1107 | |||
1108 | 1086 | sps->extension_present = get_bits1(gb); | |
1109 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 1010 times.
|
1086 | if (sps->extension_present) { |
1110 | 76 | sps->range_extension = get_bits1(gb); | |
1111 | 76 | sps->multilayer_extension = get_bits1(gb); | |
1112 | 76 | sps->sps_3d_extension = get_bits1(gb); | |
1113 | 76 | sps->scc_extension = get_bits1(gb); | |
1114 | 76 | skip_bits(gb, 4); // sps_extension_4bits | |
1115 | |||
1116 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 20 times.
|
76 | if (sps->range_extension) { |
1117 | 56 | sps->transform_skip_rotation_enabled = get_bits1(gb); | |
1118 | 56 | sps->transform_skip_context_enabled = get_bits1(gb); | |
1119 | 56 | sps->implicit_rdpcm_enabled = get_bits1(gb); | |
1120 | 56 | sps->explicit_rdpcm_enabled = get_bits1(gb); | |
1121 | |||
1122 | 56 | sps->extended_precision_processing = get_bits1(gb); | |
1123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (sps->extended_precision_processing) |
1124 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1125 | "extended_precision_processing_flag not yet implemented\n"); | ||
1126 | |||
1127 | 56 | sps->intra_smoothing_disabled = get_bits1(gb); | |
1128 | 56 | sps->high_precision_offsets_enabled = get_bits1(gb); | |
1129 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 18 times.
|
56 | if (sps->high_precision_offsets_enabled) |
1130 | 38 | av_log(avctx, AV_LOG_WARNING, | |
1131 | "high_precision_offsets_enabled_flag not yet implemented\n"); | ||
1132 | |||
1133 | 56 | sps->persistent_rice_adaptation_enabled = get_bits1(gb); | |
1134 | |||
1135 | 56 | sps->cabac_bypass_alignment_enabled = get_bits1(gb); | |
1136 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (sps->cabac_bypass_alignment_enabled) |
1137 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1138 | "cabac_bypass_alignment_enabled_flag not yet implemented\n"); | ||
1139 | } | ||
1140 | |||
1141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | if (sps->multilayer_extension) { |
1142 | ✗ | skip_bits1(gb); // inter_view_mv_vert_constraint_flag | |
1143 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1144 | "sps_multilayer_extension_flag not yet implemented\n"); | ||
1145 | } | ||
1146 | |||
1147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | if (sps->sps_3d_extension) { |
1148 | ✗ | for (i = 0; i <= 1; i++) { | |
1149 | ✗ | skip_bits1(gb); // iv_di_mc_enabled_flag | |
1150 | ✗ | skip_bits1(gb); // iv_mv_scal_enabled_flag | |
1151 | ✗ | if (i == 0) { | |
1152 | ✗ | get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3 | |
1153 | ✗ | skip_bits1(gb); // iv_res_pred_enabled_flag | |
1154 | ✗ | skip_bits1(gb); // depth_ref_enabled_flag | |
1155 | ✗ | skip_bits1(gb); // vsp_mc_enabled_flag | |
1156 | ✗ | skip_bits1(gb); // dbbp_enabled_flag | |
1157 | } else { | ||
1158 | ✗ | skip_bits1(gb); // tex_mc_enabled_flag | |
1159 | ✗ | get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3 | |
1160 | ✗ | skip_bits1(gb); // intra_contour_enabled_flag | |
1161 | ✗ | skip_bits1(gb); // intra_dc_only_wedge_enabled_flag | |
1162 | ✗ | skip_bits1(gb); // cqt_cu_part_pred_enabled_flag | |
1163 | ✗ | skip_bits1(gb); // inter_dc_only_enabled_flag | |
1164 | ✗ | skip_bits1(gb); // skip_intra_enabled_flag | |
1165 | } | ||
1166 | } | ||
1167 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1168 | "sps_3d_extension_flag not yet implemented\n"); | ||
1169 | } | ||
1170 | |||
1171 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | if (sps->scc_extension) { |
1172 | ✗ | sps->curr_pic_ref_enabled = get_bits1(gb); | |
1173 | ✗ | sps->palette_mode_enabled = get_bits1(gb); | |
1174 | ✗ | if (sps->palette_mode_enabled) { | |
1175 | ✗ | sps->palette_max_size = get_ue_golomb(gb); | |
1176 | ✗ | sps->delta_palette_max_predictor_size = get_ue_golomb(gb); | |
1177 | ✗ | sps->palette_predictor_initializers_present = get_bits1(gb); | |
1178 | |||
1179 | ✗ | if (sps->palette_predictor_initializers_present) { | |
1180 | ✗ | sps->sps_num_palette_predictor_initializers = get_ue_golomb(gb) + 1; | |
1181 | ✗ | if (sps->sps_num_palette_predictor_initializers > HEVC_MAX_PALETTE_PREDICTOR_SIZE) { | |
1182 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1183 | "sps_num_palette_predictor_initializers out of range: %u\n", | ||
1184 | sps->sps_num_palette_predictor_initializers); | ||
1185 | ✗ | return AVERROR_INVALIDDATA; | |
1186 | } | ||
1187 | ✗ | num_comps = !sps->chroma_format_idc ? 1 : 3; | |
1188 | ✗ | for (int comp = 0; comp < num_comps; comp++) { | |
1189 | ✗ | int bit_depth = !comp ? sps->bit_depth : sps->bit_depth_chroma; | |
1190 | ✗ | for (i = 0; i < sps->sps_num_palette_predictor_initializers; i++) | |
1191 | ✗ | sps->sps_palette_predictor_initializer[comp][i] = get_bits(gb, bit_depth); | |
1192 | } | ||
1193 | } | ||
1194 | } | ||
1195 | ✗ | sps->motion_vector_resolution_control_idc = get_bits(gb, 2); | |
1196 | ✗ | sps->intra_boundary_filtering_disabled = get_bits1(gb); | |
1197 | } | ||
1198 | } | ||
1199 |
2/2✓ Branch 0 taken 434 times.
✓ Branch 1 taken 652 times.
|
1086 | if (apply_defdispwin) { |
1200 | 434 | sps->output_window.left_offset += sps->vui.def_disp_win.left_offset; | |
1201 | 434 | sps->output_window.right_offset += sps->vui.def_disp_win.right_offset; | |
1202 | 434 | sps->output_window.top_offset += sps->vui.def_disp_win.top_offset; | |
1203 | 434 | sps->output_window.bottom_offset += sps->vui.def_disp_win.bottom_offset; | |
1204 | } | ||
1205 | |||
1206 | 1086 | ow = &sps->output_window; | |
1207 |
1/2✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
|
1086 | if (ow->left_offset >= INT_MAX - ow->right_offset || |
1208 |
1/2✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
|
1086 | ow->top_offset >= INT_MAX - ow->bottom_offset || |
1209 |
1/2✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
|
1086 | ow->left_offset + ow->right_offset >= sps->width || |
1210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | ow->top_offset + ow->bottom_offset >= sps->height) { |
1211 | ✗ | av_log(avctx, AV_LOG_WARNING, "Invalid cropping offsets: %u/%u/%u/%u\n", | |
1212 | ow->left_offset, ow->right_offset, ow->top_offset, ow->bottom_offset); | ||
1213 | ✗ | if (avctx->err_recognition & AV_EF_EXPLODE) { | |
1214 | ✗ | return AVERROR_INVALIDDATA; | |
1215 | } | ||
1216 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1217 | "Displaying the whole video surface.\n"); | ||
1218 | ✗ | memset(ow, 0, sizeof(*ow)); | |
1219 | ✗ | memset(&sps->pic_conf_win, 0, sizeof(sps->pic_conf_win)); | |
1220 | } | ||
1221 | |||
1222 | // Inferred parameters | ||
1223 | 1086 | sps->log2_ctb_size = sps->log2_min_cb_size + | |
1224 | 1086 | sps->log2_diff_max_min_coding_block_size; | |
1225 | 1086 | sps->log2_min_pu_size = sps->log2_min_cb_size - 1; | |
1226 | |||
1227 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->log2_ctb_size > HEVC_MAX_LOG2_CTB_SIZE) { |
1228 | ✗ | av_log(avctx, AV_LOG_ERROR, "CTB size out of range: 2^%d\n", sps->log2_ctb_size); | |
1229 | ✗ | return AVERROR_INVALIDDATA; | |
1230 | } | ||
1231 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->log2_ctb_size < 4) { |
1232 | ✗ | av_log(avctx, | |
1233 | AV_LOG_ERROR, | ||
1234 | "log2_ctb_size %d differs from the bounds of any known profile\n", | ||
1235 | sps->log2_ctb_size); | ||
1236 | ✗ | avpriv_request_sample(avctx, "log2_ctb_size %d", sps->log2_ctb_size); | |
1237 | ✗ | return AVERROR_INVALIDDATA; | |
1238 | } | ||
1239 | |||
1240 | 1086 | sps->ctb_width = (sps->width + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size; | |
1241 | 1086 | sps->ctb_height = (sps->height + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size; | |
1242 | 1086 | sps->ctb_size = sps->ctb_width * sps->ctb_height; | |
1243 | |||
1244 | 1086 | sps->min_cb_width = sps->width >> sps->log2_min_cb_size; | |
1245 | 1086 | sps->min_cb_height = sps->height >> sps->log2_min_cb_size; | |
1246 | 1086 | sps->min_tb_width = sps->width >> sps->log2_min_tb_size; | |
1247 | 1086 | sps->min_tb_height = sps->height >> sps->log2_min_tb_size; | |
1248 | 1086 | sps->min_pu_width = sps->width >> sps->log2_min_pu_size; | |
1249 | 1086 | sps->min_pu_height = sps->height >> sps->log2_min_pu_size; | |
1250 | 1086 | sps->tb_mask = (1 << (sps->log2_ctb_size - sps->log2_min_tb_size)) - 1; | |
1251 | |||
1252 | 1086 | sps->qp_bd_offset = 6 * (sps->bit_depth - 8); | |
1253 | |||
1254 |
1/2✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
|
1086 | if (av_zero_extend(sps->width, sps->log2_min_cb_size) || |
1255 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | av_zero_extend(sps->height, sps->log2_min_cb_size)) { |
1256 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid coded frame dimensions.\n"); | |
1257 | ✗ | return AVERROR_INVALIDDATA; | |
1258 | } | ||
1259 | |||
1260 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->max_transform_hierarchy_depth_inter > sps->log2_ctb_size - sps->log2_min_tb_size) { |
1261 | ✗ | av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_inter out of range: %d\n", | |
1262 | sps->max_transform_hierarchy_depth_inter); | ||
1263 | ✗ | return AVERROR_INVALIDDATA; | |
1264 | } | ||
1265 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->max_transform_hierarchy_depth_intra > sps->log2_ctb_size - sps->log2_min_tb_size) { |
1266 | ✗ | av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_intra out of range: %d\n", | |
1267 | sps->max_transform_hierarchy_depth_intra); | ||
1268 | ✗ | return AVERROR_INVALIDDATA; | |
1269 | } | ||
1270 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (sps->log2_max_trafo_size > FFMIN(sps->log2_ctb_size, 5)) { |
1271 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1272 | "max transform block size out of range: %d\n", | ||
1273 | sps->log2_max_trafo_size); | ||
1274 | ✗ | return AVERROR_INVALIDDATA; | |
1275 | } | ||
1276 | |||
1277 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1086 times.
|
1086 | if (get_bits_left(gb) < 0) { |
1278 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1279 | ✗ | "Overread SPS by %d bits\n", -get_bits_left(gb)); | |
1280 | ✗ | return AVERROR_INVALIDDATA; | |
1281 | } | ||
1282 | |||
1283 | 1086 | return 0; | |
1284 | } | ||
1285 | |||
1286 | 1086 | static void hevc_sps_free(FFRefStructOpaque opaque, void *obj) | |
1287 | { | ||
1288 | 1086 | HEVCSPS *sps = obj; | |
1289 | |||
1290 | 1086 | ff_refstruct_unref(&sps->vps); | |
1291 | |||
1292 | 1086 | av_freep(&sps->data); | |
1293 | 1086 | } | |
1294 | |||
1295 | 439 | static int compare_sps(const HEVCSPS *sps1, const HEVCSPS *sps2) | |
1296 | { | ||
1297 |
2/2✓ Branch 0 taken 435 times.
✓ Branch 1 taken 4 times.
|
874 | return sps1->data_size == sps2->data_size && |
1298 |
2/2✓ Branch 0 taken 431 times.
✓ Branch 1 taken 4 times.
|
435 | !memcmp(sps1->data, sps2->data, sps1->data_size); |
1299 | } | ||
1300 | |||
1301 | 1086 | int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, | |
1302 | HEVCParamSets *ps, int apply_defdispwin) | ||
1303 | { | ||
1304 | 1086 | HEVCSPS *sps = ff_refstruct_alloc_ext(sizeof(*sps), 0, NULL, hevc_sps_free); | |
1305 | unsigned int sps_id; | ||
1306 | int ret; | ||
1307 | |||
1308 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (!sps) |
1309 | ✗ | return AVERROR(ENOMEM); | |
1310 | |||
1311 | 1086 | av_log(avctx, AV_LOG_DEBUG, "Decoding SPS\n"); | |
1312 | |||
1313 | 1086 | sps->data_size = gb->buffer_end - gb->buffer; | |
1314 | 1086 | sps->data = av_memdup(gb->buffer, sps->data_size); | |
1315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (!sps->data) { |
1316 | ✗ | ret = AVERROR(ENOMEM); | |
1317 | ✗ | goto err; | |
1318 | } | ||
1319 | |||
1320 | 1086 | ret = ff_hevc_parse_sps(sps, gb, &sps_id, | |
1321 | apply_defdispwin, | ||
1322 | 1086 | ps->vps_list, avctx); | |
1323 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (ret < 0) |
1324 | ✗ | goto err; | |
1325 | |||
1326 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (avctx->debug & FF_DEBUG_BITSTREAM) { |
1327 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
1328 | "Parsed SPS: id %d; coded wxh: %dx%d; " | ||
1329 | "cropped wxh: %dx%d; pix_fmt: %s.\n", | ||
1330 | ✗ | sps_id, sps->width, sps->height, | |
1331 | ✗ | sps->width - (sps->output_window.left_offset + sps->output_window.right_offset), | |
1332 | ✗ | sps->height - (sps->output_window.top_offset + sps->output_window.bottom_offset), | |
1333 | ✗ | av_get_pix_fmt_name(sps->pix_fmt)); | |
1334 | } | ||
1335 | |||
1336 | /* check if this is a repeat of an already parsed SPS, then keep the | ||
1337 | * original one. | ||
1338 | * otherwise drop all PPSes that depend on it */ | ||
1339 |
4/4✓ Branch 0 taken 439 times.
✓ Branch 1 taken 647 times.
✓ Branch 2 taken 431 times.
✓ Branch 3 taken 8 times.
|
1525 | if (ps->sps_list[sps_id] && |
1340 | 439 | compare_sps(ps->sps_list[sps_id], sps)) { | |
1341 | 431 | ff_refstruct_unref(&sps); | |
1342 | } else { | ||
1343 | 655 | remove_sps(ps, sps_id); | |
1344 | 655 | ps->sps_list[sps_id] = sps; | |
1345 | } | ||
1346 | |||
1347 | 1086 | return 0; | |
1348 | ✗ | err: | |
1349 | ✗ | ff_refstruct_unref(&sps); | |
1350 | ✗ | return ret; | |
1351 | } | ||
1352 | |||
1353 | 2109 | static void hevc_pps_free(FFRefStructOpaque unused, void *obj) | |
1354 | { | ||
1355 | 2109 | HEVCPPS *pps = obj; | |
1356 | |||
1357 | 2109 | ff_refstruct_unref(&pps->sps); | |
1358 | |||
1359 | 2109 | av_freep(&pps->column_width); | |
1360 | 2109 | av_freep(&pps->row_height); | |
1361 | 2109 | av_freep(&pps->col_bd); | |
1362 | 2109 | av_freep(&pps->row_bd); | |
1363 | 2109 | av_freep(&pps->col_idxX); | |
1364 | 2109 | av_freep(&pps->ctb_addr_rs_to_ts); | |
1365 | 2109 | av_freep(&pps->ctb_addr_ts_to_rs); | |
1366 | 2109 | av_freep(&pps->tile_pos_rs); | |
1367 | 2109 | av_freep(&pps->tile_id); | |
1368 | 2109 | av_freep(&pps->min_tb_addr_zs_tab); | |
1369 | 2109 | av_freep(&pps->data); | |
1370 | 2109 | } | |
1371 | |||
1372 | 3 | static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_depth, | |
1373 | int idx_y, int idx_cb, int idx_cr, int inp_length) | ||
1374 | { | ||
1375 | unsigned int split_octant_flag, part_num_y, coded_res_flag, res_coeff_q, res_coeff_r; | ||
1376 | int cm_res_bits; | ||
1377 | |||
1378 | 3 | part_num_y = 1 << pps->cm_y_part_num_log2; | |
1379 | |||
1380 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | split_octant_flag = inp_depth < pps->cm_octant_depth ? get_bits1(gb) : 0; |
1381 | |||
1382 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (split_octant_flag) |
1383 | ✗ | for (int k = 0; k < 2; k++) | |
1384 | ✗ | for (int m = 0; m < 2; m++) | |
1385 | ✗ | for (int n = 0; n < 2; n++) | |
1386 | ✗ | colour_mapping_octants(gb, pps, inp_depth + 1, | |
1387 | ✗ | idx_y + part_num_y * k * inp_length / 2, | |
1388 | ✗ | idx_cb + m * inp_length / 2, | |
1389 | ✗ | idx_cr + n * inp_length / 2, | |
1390 | inp_length / 2); | ||
1391 | else | ||
1392 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
|
27 | for (int i = 0; i < part_num_y; i++) { |
1393 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 24 times.
|
120 | for (int j = 0; j < 4; j++) { |
1394 | 96 | coded_res_flag = get_bits1(gb); | |
1395 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | if (coded_res_flag) |
1396 | ✗ | for (int c = 0; c < 3; c++) { | |
1397 | ✗ | res_coeff_q = get_ue_golomb_long(gb); | |
1398 | ✗ | cm_res_bits = FFMAX(0, 10 + pps->luma_bit_depth_cm_input - | |
1399 | pps->luma_bit_depth_cm_output - | ||
1400 | pps->cm_res_quant_bits - pps->cm_delta_flc_bits); | ||
1401 | ✗ | res_coeff_r = cm_res_bits ? get_bits(gb, cm_res_bits) : 0; | |
1402 | ✗ | if (res_coeff_q || res_coeff_r) | |
1403 | ✗ | skip_bits1(gb); | |
1404 | } | ||
1405 | } | ||
1406 | } | ||
1407 | 3 | } | |
1408 | |||
1409 | 3 | static int colour_mapping_table(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps) | |
1410 | { | ||
1411 | 3 | pps->num_cm_ref_layers = get_ue_golomb(gb) + 1; | |
1412 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (pps->num_cm_ref_layers > 62) { |
1413 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1414 | "num_cm_ref_layers_minus1 shall be in the range [0, 61].\n"); | ||
1415 | ✗ | return AVERROR_INVALIDDATA; | |
1416 | } | ||
1417 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | for (int i = 0; i < pps->num_cm_ref_layers; i++) |
1418 | 9 | pps->cm_ref_layer_id[i] = get_bits(gb, 6); | |
1419 | |||
1420 | 3 | pps->cm_octant_depth = get_bits(gb, 2); | |
1421 | 3 | pps->cm_y_part_num_log2 = get_bits(gb, 2); | |
1422 | |||
1423 | 3 | pps->luma_bit_depth_cm_input = get_ue_golomb(gb) + 8; | |
1424 | 3 | pps->chroma_bit_depth_cm_input = get_ue_golomb(gb) + 8; | |
1425 | 3 | pps->luma_bit_depth_cm_output = get_ue_golomb(gb) + 8; | |
1426 | 3 | pps->chroma_bit_depth_cm_output = get_ue_golomb(gb) + 8; | |
1427 | |||
1428 | 3 | pps->cm_res_quant_bits = get_bits(gb, 2); | |
1429 | 3 | pps->cm_delta_flc_bits = get_bits(gb, 2) + 1; | |
1430 | |||
1431 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (pps->cm_octant_depth == 1) { |
1432 | ✗ | pps->cm_adapt_threshold_u_delta = get_se_golomb_long(gb); | |
1433 | ✗ | pps->cm_adapt_threshold_v_delta = get_se_golomb_long(gb); | |
1434 | } | ||
1435 | |||
1436 | 3 | colour_mapping_octants(gb, pps, 0, 0, 0, 0, 1 << pps->cm_octant_depth); | |
1437 | |||
1438 | 3 | return 0; | |
1439 | } | ||
1440 | |||
1441 | 3 | static int pps_multilayer_extension(GetBitContext *gb, AVCodecContext *avctx, | |
1442 | HEVCPPS *pps, const HEVCSPS *sps, const HEVCVPS *vps) | ||
1443 | { | ||
1444 | 3 | pps->poc_reset_info_present_flag = get_bits1(gb); | |
1445 | 3 | pps->pps_infer_scaling_list_flag = get_bits1(gb); | |
1446 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (pps->pps_infer_scaling_list_flag) |
1447 | ✗ | pps->pps_scaling_list_ref_layer_id = get_bits(gb, 6); | |
1448 | |||
1449 | 3 | pps->num_ref_loc_offsets = get_ue_golomb(gb); | |
1450 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (pps->num_ref_loc_offsets > vps->vps_max_layers - 1) |
1451 | ✗ | return AVERROR_INVALIDDATA; | |
1452 | |||
1453 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | for (int i = 0; i < pps->num_ref_loc_offsets; i++) { |
1454 | ✗ | pps->ref_loc_offset_layer_id[i] = get_bits(gb, 6); | |
1455 | ✗ | pps->scaled_ref_layer_offset_present_flag[i] = get_bits1(gb); | |
1456 | ✗ | if (pps->scaled_ref_layer_offset_present_flag[i]) { | |
1457 | ✗ | pps->scaled_ref_layer_left_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1458 | ✗ | pps->scaled_ref_layer_top_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1459 | ✗ | pps->scaled_ref_layer_right_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1460 | ✗ | pps->scaled_ref_layer_bottom_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1461 | } | ||
1462 | |||
1463 | ✗ | pps->ref_region_offset_present_flag[i] = get_bits1(gb); | |
1464 | ✗ | if (pps->ref_region_offset_present_flag[i]) { | |
1465 | ✗ | pps->ref_region_left_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1466 | ✗ | pps->ref_region_top_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1467 | ✗ | pps->ref_region_right_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1468 | ✗ | pps->ref_region_bottom_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1469 | } | ||
1470 | |||
1471 | ✗ | pps->resample_phase_set_present_flag[i] = get_bits1(gb); | |
1472 | ✗ | if (pps->resample_phase_set_present_flag[i]) { | |
1473 | ✗ | pps->phase_hor_luma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb_31(gb); | |
1474 | ✗ | pps->phase_ver_luma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb_31(gb); | |
1475 | ✗ | pps->phase_hor_chroma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb(gb) - 8; | |
1476 | ✗ | pps->phase_ver_chroma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb(gb) - 8; | |
1477 | } | ||
1478 | } | ||
1479 | |||
1480 | 3 | pps->colour_mapping_enabled_flag = get_bits1(gb); | |
1481 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (pps->colour_mapping_enabled_flag) { |
1482 | 3 | int ret = colour_mapping_table(gb, avctx, pps); | |
1483 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (ret < 0) |
1484 | ✗ | return ret; | |
1485 | } | ||
1486 | |||
1487 | 3 | return 0; | |
1488 | } | ||
1489 | |||
1490 | ✗ | static void delta_dlt(GetBitContext *gb, HEVCPPS *pps) | |
1491 | { | ||
1492 | ✗ | unsigned int num_val_delta_dlt, max_diff = 0; | |
1493 | ✗ | int min_diff_minus1 = -1; | |
1494 | unsigned int len; | ||
1495 | |||
1496 | ✗ | num_val_delta_dlt = get_bits(gb, pps->pps_bit_depth_for_depth_layers_minus8 + 8); | |
1497 | ✗ | if (num_val_delta_dlt) { | |
1498 | ✗ | if (num_val_delta_dlt > 1) | |
1499 | ✗ | max_diff = get_bits(gb, pps->pps_bit_depth_for_depth_layers_minus8 + 8); | |
1500 | ✗ | if (num_val_delta_dlt > 2 && max_diff) { | |
1501 | ✗ | len = av_log2(max_diff) + 1; | |
1502 | ✗ | min_diff_minus1 = get_bits(gb, len); | |
1503 | } | ||
1504 | ✗ | if (max_diff > (min_diff_minus1 + 1)) | |
1505 | ✗ | for (int k = 1; k < num_val_delta_dlt; k++) { | |
1506 | ✗ | len = av_log2(max_diff - (min_diff_minus1 + 1)) + 1; | |
1507 | ✗ | skip_bits(gb, len); // delta_val_diff_minus_min | |
1508 | } | ||
1509 | } | ||
1510 | ✗ | } | |
1511 | |||
1512 | 3 | static int pps_3d_extension(GetBitContext *gb, AVCodecContext *avctx, | |
1513 | HEVCPPS *pps, const HEVCSPS *sps) | ||
1514 | { | ||
1515 | unsigned int pps_depth_layers_minus1; | ||
1516 | |||
1517 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (get_bits1(gb)) { // dlts_present_flag |
1518 | ✗ | pps_depth_layers_minus1 = get_bits(gb, 6); | |
1519 | ✗ | pps->pps_bit_depth_for_depth_layers_minus8 = get_bits(gb, 4); | |
1520 | ✗ | for (int i = 0; i <= pps_depth_layers_minus1; i++) { | |
1521 | ✗ | if (get_bits1(gb)) { // dlt_flag[i] | |
1522 | ✗ | if (!get_bits1(gb)) { // dlt_pred_flag[i] | |
1523 | ✗ | if (get_bits1(gb)) { // dlt_val_flags_present_flag[i] | |
1524 | ✗ | for (int j = 0; j <= ((1 << (pps->pps_bit_depth_for_depth_layers_minus8 + 8)) - 1); j++) | |
1525 | ✗ | skip_bits1(gb); // dlt_value_flag[i][j] | |
1526 | } else | ||
1527 | ✗ | delta_dlt(gb, pps); | |
1528 | } | ||
1529 | } | ||
1530 | } | ||
1531 | } | ||
1532 | |||
1533 | 3 | return 0; | |
1534 | } | ||
1535 | |||
1536 | 63 | static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx, | |
1537 | HEVCPPS *pps, const HEVCSPS *sps) | ||
1538 | { | ||
1539 |
1/2✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
|
63 | if (pps->transform_skip_enabled_flag) { |
1540 | 63 | pps->log2_max_transform_skip_block_size = get_ue_golomb_31(gb) + 2; | |
1541 | } | ||
1542 | 63 | pps->cross_component_prediction_enabled_flag = get_bits1(gb); | |
1543 | 63 | pps->chroma_qp_offset_list_enabled_flag = get_bits1(gb); | |
1544 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 57 times.
|
63 | if (pps->chroma_qp_offset_list_enabled_flag) { |
1545 | 6 | pps->diff_cu_chroma_qp_offset_depth = get_ue_golomb_31(gb); | |
1546 | 6 | pps->chroma_qp_offset_list_len_minus1 = get_ue_golomb_31(gb); | |
1547 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (pps->chroma_qp_offset_list_len_minus1 > 5) { |
1548 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1549 | "chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n"); | ||
1550 | ✗ | return AVERROR_INVALIDDATA; | |
1551 | } | ||
1552 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | for (int i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) { |
1553 | 6 | pps->cb_qp_offset_list[i] = get_se_golomb(gb); | |
1554 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (pps->cb_qp_offset_list[i]) { |
1555 | 6 | av_log(avctx, AV_LOG_WARNING, | |
1556 | "cb_qp_offset_list not tested yet.\n"); | ||
1557 | } | ||
1558 | 6 | pps->cr_qp_offset_list[i] = get_se_golomb(gb); | |
1559 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (pps->cr_qp_offset_list[i]) { |
1560 | 6 | av_log(avctx, AV_LOG_WARNING, | |
1561 | "cb_qp_offset_list not tested yet.\n"); | ||
1562 | } | ||
1563 | } | ||
1564 | } | ||
1565 | 63 | pps->log2_sao_offset_scale_luma = get_ue_golomb_31(gb); | |
1566 | 63 | pps->log2_sao_offset_scale_chroma = get_ue_golomb_31(gb); | |
1567 | |||
1568 |
1/2✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
|
63 | if ( pps->log2_sao_offset_scale_luma > FFMAX(sps->bit_depth - 10, 0) |
1569 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
|
63 | || pps->log2_sao_offset_scale_chroma > FFMAX(sps->bit_depth_chroma - 10, 0) |
1570 | ) | ||
1571 | ✗ | return AVERROR_INVALIDDATA; | |
1572 | |||
1573 | 63 | return(0); | |
1574 | } | ||
1575 | |||
1576 | 3 | static int pps_scc_extension(GetBitContext *gb, AVCodecContext *avctx, | |
1577 | HEVCPPS *pps, const HEVCSPS *sps) | ||
1578 | { | ||
1579 | int num_comps, ret; | ||
1580 | |||
1581 | 3 | pps->pps_curr_pic_ref_enabled_flag = get_bits1(gb); | |
1582 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (pps->residual_adaptive_colour_transform_enabled_flag = get_bits1(gb)) { |
1583 | ✗ | pps->pps_slice_act_qp_offsets_present_flag = get_bits1(gb); | |
1584 | ✗ | pps->pps_act_y_qp_offset = get_se_golomb(gb) - 5; | |
1585 | ✗ | pps->pps_act_cb_qp_offset = get_se_golomb(gb) - 5; | |
1586 | ✗ | pps->pps_act_cr_qp_offset = get_se_golomb(gb) - 3; | |
1587 | |||
1588 | #define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 || \ | ||
1589 | pps->pps_act_ ## name ## _qp_offset >= 12) | ||
1590 | ✗ | ret = CHECK_QP_OFFSET(y) || CHECK_QP_OFFSET(cb) || CHECK_QP_OFFSET(cr); | |
1591 | #undef CHECK_QP_OFFSET | ||
1592 | ✗ | if (ret) { | |
1593 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1594 | "PpsActQpOffsetY/Cb/Cr shall be in the range of [-12, 12].\n"); | ||
1595 | ✗ | return AVERROR_INVALIDDATA; | |
1596 | } | ||
1597 | } | ||
1598 | |||
1599 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (pps->pps_palette_predictor_initializers_present_flag = get_bits1(gb)) { |
1600 | ✗ | pps->pps_num_palette_predictor_initializers = get_ue_golomb(gb); | |
1601 | ✗ | if (pps->pps_num_palette_predictor_initializers > 0) { | |
1602 | ✗ | if (pps->pps_num_palette_predictor_initializers > HEVC_MAX_PALETTE_PREDICTOR_SIZE) { | |
1603 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1604 | "pps_num_palette_predictor_initializers out of range: %u\n", | ||
1605 | ✗ | pps->pps_num_palette_predictor_initializers); | |
1606 | ✗ | return AVERROR_INVALIDDATA; | |
1607 | } | ||
1608 | ✗ | pps->monochrome_palette_flag = get_bits1(gb); | |
1609 | ✗ | pps->luma_bit_depth_entry = get_ue_golomb_31(gb) + 8; | |
1610 | ✗ | if (pps->luma_bit_depth_entry != sps->bit_depth) | |
1611 | ✗ | return AVERROR_INVALIDDATA; | |
1612 | ✗ | if (!pps->monochrome_palette_flag) { | |
1613 | ✗ | pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8; | |
1614 | ✗ | if (pps->chroma_bit_depth_entry != sps->bit_depth_chroma) | |
1615 | ✗ | return AVERROR_INVALIDDATA; | |
1616 | } | ||
1617 | |||
1618 | ✗ | num_comps = pps->monochrome_palette_flag ? 1 : 3; | |
1619 | ✗ | for (int comp = 0; comp < num_comps; comp++) { | |
1620 | ✗ | int bit_depth = !comp ? pps->luma_bit_depth_entry : pps->chroma_bit_depth_entry; | |
1621 | ✗ | for (int i = 0; i < pps->pps_num_palette_predictor_initializers; i++) | |
1622 | ✗ | pps->pps_palette_predictor_initializer[comp][i] = get_bits(gb, bit_depth); | |
1623 | } | ||
1624 | } | ||
1625 | } | ||
1626 | |||
1627 | 3 | return 0; | |
1628 | } | ||
1629 | |||
1630 | 2105 | static inline int setup_pps(AVCodecContext *avctx, GetBitContext *gb, | |
1631 | HEVCPPS *pps, const HEVCSPS *sps) | ||
1632 | { | ||
1633 | int log2_diff; | ||
1634 | int pic_area_in_ctbs; | ||
1635 | int i, j, x, y, ctb_addr_rs, tile_id; | ||
1636 | |||
1637 | // Inferred parameters | ||
1638 | 2105 | pps->col_bd = av_malloc_array(pps->num_tile_columns + 1, sizeof(*pps->col_bd)); | |
1639 | 2105 | pps->row_bd = av_malloc_array(pps->num_tile_rows + 1, sizeof(*pps->row_bd)); | |
1640 | 2105 | pps->col_idxX = av_malloc_array(sps->ctb_width, sizeof(*pps->col_idxX)); | |
1641 |
3/6✓ Branch 0 taken 2105 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2105 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2105 times.
|
2105 | if (!pps->col_bd || !pps->row_bd || !pps->col_idxX) |
1642 | ✗ | return AVERROR(ENOMEM); | |
1643 | |||
1644 |
2/2✓ Branch 0 taken 1584 times.
✓ Branch 1 taken 521 times.
|
2105 | if (pps->uniform_spacing_flag) { |
1645 |
2/2✓ Branch 0 taken 1358 times.
✓ Branch 1 taken 226 times.
|
1584 | if (!pps->column_width) { |
1646 | 1358 | pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width)); | |
1647 | 1358 | pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height)); | |
1648 | } | ||
1649 |
2/4✓ Branch 0 taken 1584 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1584 times.
|
1584 | if (!pps->column_width || !pps->row_height) |
1650 | ✗ | return AVERROR(ENOMEM); | |
1651 | |||
1652 |
2/2✓ Branch 0 taken 1745 times.
✓ Branch 1 taken 1584 times.
|
3329 | for (i = 0; i < pps->num_tile_columns; i++) { |
1653 | 1745 | pps->column_width[i] = ((i + 1) * sps->ctb_width) / pps->num_tile_columns - | |
1654 | 1745 | (i * sps->ctb_width) / pps->num_tile_columns; | |
1655 | } | ||
1656 | |||
1657 |
2/2✓ Branch 0 taken 1763 times.
✓ Branch 1 taken 1584 times.
|
3347 | for (i = 0; i < pps->num_tile_rows; i++) { |
1658 | 1763 | pps->row_height[i] = ((i + 1) * sps->ctb_height) / pps->num_tile_rows - | |
1659 | 1763 | (i * sps->ctb_height) / pps->num_tile_rows; | |
1660 | } | ||
1661 | } | ||
1662 | |||
1663 | 2105 | pps->col_bd[0] = 0; | |
1664 |
2/2✓ Branch 0 taken 4308 times.
✓ Branch 1 taken 2105 times.
|
6413 | for (i = 0; i < pps->num_tile_columns; i++) |
1665 | 4308 | pps->col_bd[i + 1] = pps->col_bd[i] + pps->column_width[i]; | |
1666 | |||
1667 | 2105 | pps->row_bd[0] = 0; | |
1668 |
2/2✓ Branch 0 taken 4314 times.
✓ Branch 1 taken 2105 times.
|
6419 | for (i = 0; i < pps->num_tile_rows; i++) |
1669 | 4314 | pps->row_bd[i + 1] = pps->row_bd[i] + pps->row_height[i]; | |
1670 | |||
1671 |
2/2✓ Branch 0 taken 41632 times.
✓ Branch 1 taken 2105 times.
|
43737 | for (i = 0, j = 0; i < sps->ctb_width; i++) { |
1672 |
2/2✓ Branch 0 taken 4299 times.
✓ Branch 1 taken 37333 times.
|
41632 | if (i > pps->col_bd[j]) |
1673 | 4299 | j++; | |
1674 | 41632 | pps->col_idxX[i] = j; | |
1675 | } | ||
1676 | |||
1677 | /** | ||
1678 | * 6.5 | ||
1679 | */ | ||
1680 | 2105 | pic_area_in_ctbs = sps->ctb_width * sps->ctb_height; | |
1681 | |||
1682 | 2105 | pps->ctb_addr_rs_to_ts = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_rs_to_ts)); | |
1683 | 2105 | pps->ctb_addr_ts_to_rs = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_ts_to_rs)); | |
1684 | 2105 | pps->tile_id = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->tile_id)); | |
1685 | 2105 | pps->min_tb_addr_zs_tab = av_malloc_array((sps->tb_mask+2) * (sps->tb_mask+2), sizeof(*pps->min_tb_addr_zs_tab)); | |
1686 |
2/4✓ Branch 0 taken 2105 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2105 times.
✗ Branch 3 not taken.
|
2105 | if (!pps->ctb_addr_rs_to_ts || !pps->ctb_addr_ts_to_rs || |
1687 |
2/4✓ Branch 0 taken 2105 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2105 times.
|
2105 | !pps->tile_id || !pps->min_tb_addr_zs_tab) { |
1688 | ✗ | return AVERROR(ENOMEM); | |
1689 | } | ||
1690 | |||
1691 |
2/2✓ Branch 0 taken 656759 times.
✓ Branch 1 taken 2105 times.
|
658864 | for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) { |
1692 | 656759 | int tb_x = ctb_addr_rs % sps->ctb_width; | |
1693 | 656759 | int tb_y = ctb_addr_rs / sps->ctb_width; | |
1694 | 656759 | int tile_x = 0; | |
1695 | 656759 | int tile_y = 0; | |
1696 | 656759 | int val = 0; | |
1697 | |||
1698 |
1/2✓ Branch 0 taken 1167311 times.
✗ Branch 1 not taken.
|
1167311 | for (i = 0; i < pps->num_tile_columns; i++) { |
1699 |
2/2✓ Branch 0 taken 656759 times.
✓ Branch 1 taken 510552 times.
|
1167311 | if (tb_x < pps->col_bd[i + 1]) { |
1700 | 656759 | tile_x = i; | |
1701 | 656759 | break; | |
1702 | } | ||
1703 | } | ||
1704 | |||
1705 |
1/2✓ Branch 0 taken 1035157 times.
✗ Branch 1 not taken.
|
1035157 | for (i = 0; i < pps->num_tile_rows; i++) { |
1706 |
2/2✓ Branch 0 taken 656759 times.
✓ Branch 1 taken 378398 times.
|
1035157 | if (tb_y < pps->row_bd[i + 1]) { |
1707 | 656759 | tile_y = i; | |
1708 | 656759 | break; | |
1709 | } | ||
1710 | } | ||
1711 | |||
1712 |
2/2✓ Branch 0 taken 510552 times.
✓ Branch 1 taken 656759 times.
|
1167311 | for (i = 0; i < tile_x; i++) |
1713 | 510552 | val += pps->row_height[tile_y] * pps->column_width[i]; | |
1714 |
2/2✓ Branch 0 taken 378398 times.
✓ Branch 1 taken 656759 times.
|
1035157 | for (i = 0; i < tile_y; i++) |
1715 | 378398 | val += sps->ctb_width * pps->row_height[i]; | |
1716 | |||
1717 | 656759 | val += (tb_y - pps->row_bd[tile_y]) * pps->column_width[tile_x] + | |
1718 | 656759 | tb_x - pps->col_bd[tile_x]; | |
1719 | |||
1720 | 656759 | pps->ctb_addr_rs_to_ts[ctb_addr_rs] = val; | |
1721 | 656759 | pps->ctb_addr_ts_to_rs[val] = ctb_addr_rs; | |
1722 | } | ||
1723 | |||
1724 |
2/2✓ Branch 0 taken 4314 times.
✓ Branch 1 taken 2105 times.
|
6419 | for (j = 0, tile_id = 0; j < pps->num_tile_rows; j++) |
1725 |
2/2✓ Branch 0 taken 14669 times.
✓ Branch 1 taken 4314 times.
|
18983 | for (i = 0; i < pps->num_tile_columns; i++, tile_id++) |
1726 |
2/2✓ Branch 0 taken 65004 times.
✓ Branch 1 taken 14669 times.
|
79673 | for (y = pps->row_bd[j]; y < pps->row_bd[j + 1]; y++) |
1727 |
2/2✓ Branch 0 taken 656759 times.
✓ Branch 1 taken 65004 times.
|
721763 | for (x = pps->col_bd[i]; x < pps->col_bd[i + 1]; x++) |
1728 | 656759 | pps->tile_id[pps->ctb_addr_rs_to_ts[y * sps->ctb_width + x]] = tile_id; | |
1729 | |||
1730 | 2105 | pps->tile_pos_rs = av_malloc_array(tile_id, sizeof(*pps->tile_pos_rs)); | |
1731 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2105 times.
|
2105 | if (!pps->tile_pos_rs) |
1732 | ✗ | return AVERROR(ENOMEM); | |
1733 | |||
1734 |
2/2✓ Branch 0 taken 4314 times.
✓ Branch 1 taken 2105 times.
|
6419 | for (j = 0; j < pps->num_tile_rows; j++) |
1735 |
2/2✓ Branch 0 taken 14669 times.
✓ Branch 1 taken 4314 times.
|
18983 | for (i = 0; i < pps->num_tile_columns; i++) |
1736 | 14669 | pps->tile_pos_rs[j * pps->num_tile_columns + i] = | |
1737 | 14669 | pps->row_bd[j] * sps->ctb_width + pps->col_bd[i]; | |
1738 | |||
1739 | 2105 | log2_diff = sps->log2_ctb_size - sps->log2_min_tb_size; | |
1740 | 2105 | pps->min_tb_addr_zs = &pps->min_tb_addr_zs_tab[1*(sps->tb_mask+2)+1]; | |
1741 |
2/2✓ Branch 0 taken 34829 times.
✓ Branch 1 taken 2105 times.
|
36934 | for (y = 0; y < sps->tb_mask+2; y++) { |
1742 | 34829 | pps->min_tb_addr_zs_tab[y*(sps->tb_mask+2)] = -1; | |
1743 | 34829 | pps->min_tb_addr_zs_tab[y] = -1; | |
1744 | } | ||
1745 |
2/2✓ Branch 0 taken 32724 times.
✓ Branch 1 taken 2105 times.
|
34829 | for (y = 0; y < sps->tb_mask+1; y++) { |
1746 |
2/2✓ Branch 0 taken 517328 times.
✓ Branch 1 taken 32724 times.
|
550052 | for (x = 0; x < sps->tb_mask+1; x++) { |
1747 | 517328 | int tb_x = x >> log2_diff; | |
1748 | 517328 | int tb_y = y >> log2_diff; | |
1749 | 517328 | int rs = sps->ctb_width * tb_y + tb_x; | |
1750 | 517328 | int val = pps->ctb_addr_rs_to_ts[rs] << (log2_diff * 2); | |
1751 |
2/2✓ Branch 0 taken 2063520 times.
✓ Branch 1 taken 517328 times.
|
2580848 | for (i = 0; i < log2_diff; i++) { |
1752 | 2063520 | int m = 1 << i; | |
1753 |
4/4✓ Branch 0 taken 1031760 times.
✓ Branch 1 taken 1031760 times.
✓ Branch 2 taken 1031760 times.
✓ Branch 3 taken 1031760 times.
|
2063520 | val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0); |
1754 | } | ||
1755 | 517328 | pps->min_tb_addr_zs[y * (sps->tb_mask+2) + x] = val; | |
1756 | } | ||
1757 | } | ||
1758 | |||
1759 | 2105 | return 0; | |
1760 | } | ||
1761 | |||
1762 | 3310 | int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, | |
1763 | HEVCParamSets *ps) | ||
1764 | { | ||
1765 | 3310 | const HEVCSPS *sps = NULL; | |
1766 | 3310 | const HEVCVPS *vps = NULL; | |
1767 | 3310 | int i, ret = 0; | |
1768 | 3310 | ptrdiff_t nal_size = gb->buffer_end - gb->buffer; | |
1769 | 3310 | unsigned int pps_id = get_ue_golomb_long(gb); | |
1770 | unsigned log2_parallel_merge_level_minus2; | ||
1771 | HEVCPPS *pps; | ||
1772 | |||
1773 | 3310 | av_log(avctx, AV_LOG_DEBUG, "Decoding PPS\n"); | |
1774 | |||
1775 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3310 times.
|
3310 | if (pps_id >= HEVC_MAX_PPS_COUNT) { |
1776 | ✗ | av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); | |
1777 | ✗ | return AVERROR_INVALIDDATA; | |
1778 | } | ||
1779 | |||
1780 |
2/2✓ Branch 0 taken 2406 times.
✓ Branch 1 taken 904 times.
|
3310 | if (ps->pps_list[pps_id]) { |
1781 | 2406 | const HEVCPPS *pps1 = ps->pps_list[pps_id]; | |
1782 |
2/2✓ Branch 0 taken 2026 times.
✓ Branch 1 taken 380 times.
|
2406 | if (pps1->data_size == nal_size && |
1783 |
2/2✓ Branch 0 taken 1201 times.
✓ Branch 1 taken 825 times.
|
2026 | !memcmp(pps1->data, gb->buffer, pps1->data_size)) |
1784 | 1201 | return 0; | |
1785 | } | ||
1786 | |||
1787 | 2109 | pps = ff_refstruct_alloc_ext(sizeof(*pps), 0, NULL, hevc_pps_free); | |
1788 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2109 times.
|
2109 | if (!pps) |
1789 | ✗ | return AVERROR(ENOMEM); | |
1790 | |||
1791 | 2109 | pps->data_size = nal_size; | |
1792 | 2109 | pps->data = av_memdup(gb->buffer, nal_size); | |
1793 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2109 times.
|
2109 | if (!pps->data) { |
1794 | ✗ | ret = AVERROR_INVALIDDATA; | |
1795 | ✗ | goto err; | |
1796 | } | ||
1797 | |||
1798 | // Default values | ||
1799 | 2109 | pps->loop_filter_across_tiles_enabled_flag = 1; | |
1800 | 2109 | pps->num_tile_columns = 1; | |
1801 | 2109 | pps->num_tile_rows = 1; | |
1802 | 2109 | pps->uniform_spacing_flag = 1; | |
1803 | 2109 | pps->disable_dbf = 0; | |
1804 | 2109 | pps->beta_offset = 0; | |
1805 | 2109 | pps->tc_offset = 0; | |
1806 | 2109 | pps->log2_max_transform_skip_block_size = 2; | |
1807 | |||
1808 | // Coded parameters | ||
1809 | 2109 | pps->pps_id = pps_id; | |
1810 | 2109 | pps->sps_id = get_ue_golomb_long(gb); | |
1811 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2109 times.
|
2109 | if (pps->sps_id >= HEVC_MAX_SPS_COUNT) { |
1812 | ✗ | av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id); | |
1813 | ✗ | ret = AVERROR_INVALIDDATA; | |
1814 | ✗ | goto err; | |
1815 | } | ||
1816 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2105 times.
|
2109 | if (!ps->sps_list[pps->sps_id]) { |
1817 | 4 | av_log(avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id); | |
1818 | 4 | ret = AVERROR_INVALIDDATA; | |
1819 | 4 | goto err; | |
1820 | } | ||
1821 | 2105 | sps = ps->sps_list[pps->sps_id]; | |
1822 | 2105 | vps = ps->vps_list[sps->vps_id]; | |
1823 | |||
1824 | 2105 | pps->sps = ff_refstruct_ref_c(sps); | |
1825 | |||
1826 | 2105 | pps->dependent_slice_segments_enabled_flag = get_bits1(gb); | |
1827 | 2105 | pps->output_flag_present_flag = get_bits1(gb); | |
1828 | 2105 | pps->num_extra_slice_header_bits = get_bits(gb, 3); | |
1829 | |||
1830 | 2105 | pps->sign_data_hiding_flag = get_bits1(gb); | |
1831 | |||
1832 | 2105 | pps->cabac_init_present_flag = get_bits1(gb); | |
1833 | |||
1834 | 2105 | pps->num_ref_idx_l0_default_active = get_ue_golomb_31(gb) + 1; | |
1835 | 2105 | pps->num_ref_idx_l1_default_active = get_ue_golomb_31(gb) + 1; | |
1836 |
1/2✓ Branch 0 taken 2105 times.
✗ Branch 1 not taken.
|
2105 | if (pps->num_ref_idx_l0_default_active >= HEVC_MAX_REFS || |
1837 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2105 times.
|
2105 | pps->num_ref_idx_l1_default_active >= HEVC_MAX_REFS) { |
1838 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many default refs in PPS: %d/%d.\n", | |
1839 | ✗ | pps->num_ref_idx_l0_default_active, pps->num_ref_idx_l1_default_active); | |
1840 | ✗ | goto err; | |
1841 | } | ||
1842 | |||
1843 | 2105 | pps->pic_init_qp_minus26 = get_se_golomb(gb); | |
1844 | |||
1845 | 2105 | pps->constrained_intra_pred_flag = get_bits1(gb); | |
1846 | 2105 | pps->transform_skip_enabled_flag = get_bits1(gb); | |
1847 | |||
1848 | 2105 | pps->cu_qp_delta_enabled_flag = get_bits1(gb); | |
1849 | 2105 | pps->diff_cu_qp_delta_depth = 0; | |
1850 |
2/2✓ Branch 0 taken 471 times.
✓ Branch 1 taken 1634 times.
|
2105 | if (pps->cu_qp_delta_enabled_flag) |
1851 | 471 | pps->diff_cu_qp_delta_depth = get_ue_golomb_long(gb); | |
1852 | |||
1853 |
1/2✓ Branch 0 taken 2105 times.
✗ Branch 1 not taken.
|
2105 | if (pps->diff_cu_qp_delta_depth < 0 || |
1854 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2105 times.
|
2105 | pps->diff_cu_qp_delta_depth > sps->log2_diff_max_min_coding_block_size) { |
1855 | ✗ | av_log(avctx, AV_LOG_ERROR, "diff_cu_qp_delta_depth %d is invalid\n", | |
1856 | ✗ | pps->diff_cu_qp_delta_depth); | |
1857 | ✗ | ret = AVERROR_INVALIDDATA; | |
1858 | ✗ | goto err; | |
1859 | } | ||
1860 | |||
1861 | 2105 | pps->cb_qp_offset = get_se_golomb(gb); | |
1862 |
2/4✓ Branch 0 taken 2105 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2105 times.
|
2105 | if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) { |
1863 | ✗ | av_log(avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n", | |
1864 | ✗ | pps->cb_qp_offset); | |
1865 | ✗ | ret = AVERROR_INVALIDDATA; | |
1866 | ✗ | goto err; | |
1867 | } | ||
1868 | 2105 | pps->cr_qp_offset = get_se_golomb(gb); | |
1869 |
2/4✓ Branch 0 taken 2105 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2105 times.
|
2105 | if (pps->cr_qp_offset < -12 || pps->cr_qp_offset > 12) { |
1870 | ✗ | av_log(avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n", | |
1871 | ✗ | pps->cr_qp_offset); | |
1872 | ✗ | ret = AVERROR_INVALIDDATA; | |
1873 | ✗ | goto err; | |
1874 | } | ||
1875 | 2105 | pps->pic_slice_level_chroma_qp_offsets_present_flag = get_bits1(gb); | |
1876 | |||
1877 | 2105 | pps->weighted_pred_flag = get_bits1(gb); | |
1878 | 2105 | pps->weighted_bipred_flag = get_bits1(gb); | |
1879 | |||
1880 | 2105 | pps->transquant_bypass_enable_flag = get_bits1(gb); | |
1881 | 2105 | pps->tiles_enabled_flag = get_bits1(gb); | |
1882 | 2105 | pps->entropy_coding_sync_enabled_flag = get_bits1(gb); | |
1883 | |||
1884 |
2/2✓ Branch 0 taken 747 times.
✓ Branch 1 taken 1358 times.
|
2105 | if (pps->tiles_enabled_flag) { |
1885 | 747 | int num_tile_columns_minus1 = get_ue_golomb(gb); | |
1886 | 747 | int num_tile_rows_minus1 = get_ue_golomb(gb); | |
1887 | |||
1888 |
1/2✓ Branch 0 taken 747 times.
✗ Branch 1 not taken.
|
747 | if (num_tile_columns_minus1 < 0 || |
1889 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
|
747 | num_tile_columns_minus1 >= sps->ctb_width) { |
1890 | ✗ | av_log(avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n", | |
1891 | num_tile_columns_minus1); | ||
1892 | ✗ | ret = num_tile_columns_minus1 < 0 ? num_tile_columns_minus1 : AVERROR_INVALIDDATA; | |
1893 | ✗ | goto err; | |
1894 | } | ||
1895 |
1/2✓ Branch 0 taken 747 times.
✗ Branch 1 not taken.
|
747 | if (num_tile_rows_minus1 < 0 || |
1896 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
|
747 | num_tile_rows_minus1 >= sps->ctb_height) { |
1897 | ✗ | av_log(avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n", | |
1898 | num_tile_rows_minus1); | ||
1899 | ✗ | ret = num_tile_rows_minus1 < 0 ? num_tile_rows_minus1 : AVERROR_INVALIDDATA; | |
1900 | ✗ | goto err; | |
1901 | } | ||
1902 | 747 | pps->num_tile_columns = num_tile_columns_minus1 + 1; | |
1903 | 747 | pps->num_tile_rows = num_tile_rows_minus1 + 1; | |
1904 | |||
1905 | 747 | pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width)); | |
1906 | 747 | pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height)); | |
1907 |
2/4✓ Branch 0 taken 747 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 747 times.
|
747 | if (!pps->column_width || !pps->row_height) { |
1908 | ✗ | ret = AVERROR(ENOMEM); | |
1909 | ✗ | goto err; | |
1910 | } | ||
1911 | |||
1912 | 747 | pps->uniform_spacing_flag = get_bits1(gb); | |
1913 |
2/2✓ Branch 0 taken 521 times.
✓ Branch 1 taken 226 times.
|
747 | if (!pps->uniform_spacing_flag) { |
1914 | 521 | uint64_t sum = 0; | |
1915 |
2/2✓ Branch 0 taken 2042 times.
✓ Branch 1 taken 521 times.
|
2563 | for (i = 0; i < pps->num_tile_columns - 1; i++) { |
1916 | 2042 | pps->column_width[i] = get_ue_golomb_long(gb) + 1; | |
1917 | 2042 | sum += pps->column_width[i]; | |
1918 | } | ||
1919 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 521 times.
|
521 | if (sum >= sps->ctb_width) { |
1920 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid tile widths.\n"); | |
1921 | ✗ | ret = AVERROR_INVALIDDATA; | |
1922 | ✗ | goto err; | |
1923 | } | ||
1924 | 521 | pps->column_width[pps->num_tile_columns - 1] = sps->ctb_width - sum; | |
1925 | |||
1926 | 521 | sum = 0; | |
1927 |
2/2✓ Branch 0 taken 2030 times.
✓ Branch 1 taken 521 times.
|
2551 | for (i = 0; i < pps->num_tile_rows - 1; i++) { |
1928 | 2030 | pps->row_height[i] = get_ue_golomb_long(gb) + 1; | |
1929 | 2030 | sum += pps->row_height[i]; | |
1930 | } | ||
1931 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 521 times.
|
521 | if (sum >= sps->ctb_height) { |
1932 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid tile heights.\n"); | |
1933 | ✗ | ret = AVERROR_INVALIDDATA; | |
1934 | ✗ | goto err; | |
1935 | } | ||
1936 | 521 | pps->row_height[pps->num_tile_rows - 1] = sps->ctb_height - sum; | |
1937 | } | ||
1938 | 747 | pps->loop_filter_across_tiles_enabled_flag = get_bits1(gb); | |
1939 | } | ||
1940 | |||
1941 | 2105 | pps->seq_loop_filter_across_slices_enabled_flag = get_bits1(gb); | |
1942 | |||
1943 | 2105 | pps->deblocking_filter_control_present_flag = get_bits1(gb); | |
1944 |
2/2✓ Branch 0 taken 868 times.
✓ Branch 1 taken 1237 times.
|
2105 | if (pps->deblocking_filter_control_present_flag) { |
1945 | 868 | pps->deblocking_filter_override_enabled_flag = get_bits1(gb); | |
1946 | 868 | pps->disable_dbf = get_bits1(gb); | |
1947 |
2/2✓ Branch 0 taken 742 times.
✓ Branch 1 taken 126 times.
|
868 | if (!pps->disable_dbf) { |
1948 | 742 | int beta_offset_div2 = get_se_golomb(gb); | |
1949 | 742 | int tc_offset_div2 = get_se_golomb(gb) ; | |
1950 |
2/4✓ Branch 0 taken 742 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 742 times.
|
742 | if (beta_offset_div2 < -6 || beta_offset_div2 > 6) { |
1951 | ✗ | av_log(avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n", | |
1952 | beta_offset_div2); | ||
1953 | ✗ | ret = AVERROR_INVALIDDATA; | |
1954 | ✗ | goto err; | |
1955 | } | ||
1956 |
2/4✓ Branch 0 taken 742 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 742 times.
|
742 | if (tc_offset_div2 < -6 || tc_offset_div2 > 6) { |
1957 | ✗ | av_log(avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n", | |
1958 | tc_offset_div2); | ||
1959 | ✗ | ret = AVERROR_INVALIDDATA; | |
1960 | ✗ | goto err; | |
1961 | } | ||
1962 | 742 | pps->beta_offset = 2 * beta_offset_div2; | |
1963 | 742 | pps->tc_offset = 2 * tc_offset_div2; | |
1964 | } | ||
1965 | } | ||
1966 | |||
1967 | 2105 | pps->scaling_list_data_present_flag = get_bits1(gb); | |
1968 |
2/2✓ Branch 0 taken 115 times.
✓ Branch 1 taken 1990 times.
|
2105 | if (pps->scaling_list_data_present_flag) { |
1969 | 115 | set_default_scaling_list_data(&pps->scaling_list); | |
1970 | 115 | ret = scaling_list_data(gb, avctx, &pps->scaling_list, sps); | |
1971 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
|
115 | if (ret < 0) |
1972 | ✗ | goto err; | |
1973 | } | ||
1974 | 2105 | pps->lists_modification_present_flag = get_bits1(gb); | |
1975 | 2105 | log2_parallel_merge_level_minus2 = get_ue_golomb_long(gb); | |
1976 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2105 times.
|
2105 | if (log2_parallel_merge_level_minus2 > sps->log2_ctb_size) { |
1977 | ✗ | av_log(avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n", | |
1978 | log2_parallel_merge_level_minus2); | ||
1979 | ✗ | ret = AVERROR_INVALIDDATA; | |
1980 | ✗ | goto err; | |
1981 | } | ||
1982 | 2105 | pps->log2_parallel_merge_level = log2_parallel_merge_level_minus2 + 2; | |
1983 | |||
1984 | 2105 | pps->slice_header_extension_present_flag = get_bits1(gb); | |
1985 | |||
1986 | 2105 | pps->pps_extension_present_flag = get_bits1(gb); | |
1987 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 2036 times.
|
2105 | if (pps->pps_extension_present_flag) { |
1988 | 69 | pps->pps_range_extensions_flag = get_bits1(gb); | |
1989 | 69 | pps->pps_multilayer_extension_flag = get_bits1(gb); | |
1990 | 69 | pps->pps_3d_extension_flag = get_bits1(gb); | |
1991 | 69 | pps->pps_scc_extension_flag = get_bits1(gb); | |
1992 | 69 | skip_bits(gb, 4); // pps_extension_4bits | |
1993 | |||
1994 |
3/4✓ Branch 0 taken 63 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 63 times.
✗ Branch 3 not taken.
|
69 | if (sps->ptl.general_ptl.profile_idc >= AV_PROFILE_HEVC_REXT && pps->pps_range_extensions_flag) { |
1995 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
|
63 | if ((ret = pps_range_extensions(gb, avctx, pps, sps)) < 0) |
1996 | ✗ | goto err; | |
1997 | } | ||
1998 | |||
1999 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 66 times.
|
69 | if (pps->pps_multilayer_extension_flag) { |
2000 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = pps_multilayer_extension(gb, avctx, pps, sps, vps)) < 0) |
2001 | ✗ | goto err; | |
2002 | } | ||
2003 | |||
2004 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 66 times.
|
69 | if (pps->pps_3d_extension_flag) { |
2005 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = pps_3d_extension(gb, avctx, pps, sps)) < 0) |
2006 | ✗ | goto err; | |
2007 | } | ||
2008 | |||
2009 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 66 times.
|
69 | if (pps->pps_scc_extension_flag) { |
2010 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = pps_scc_extension(gb, avctx, pps, sps)) < 0) |
2011 | ✗ | goto err; | |
2012 | } | ||
2013 | } | ||
2014 | |||
2015 | 2105 | ret = setup_pps(avctx, gb, pps, sps); | |
2016 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2105 times.
|
2105 | if (ret < 0) |
2017 | ✗ | goto err; | |
2018 | |||
2019 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2102 times.
|
2105 | if (get_bits_left(gb) < 0) { |
2020 | 3 | av_log(avctx, AV_LOG_WARNING, | |
2021 | 3 | "Overread PPS by %d bits\n", -get_bits_left(gb)); | |
2022 | } | ||
2023 | |||
2024 | 2105 | ff_refstruct_unref(&ps->pps_list[pps_id]); | |
2025 | 2105 | ps->pps_list[pps_id] = pps; | |
2026 | |||
2027 | 2105 | return 0; | |
2028 | |||
2029 | 4 | err: | |
2030 | 4 | ff_refstruct_unref(&pps); | |
2031 | 4 | return ret; | |
2032 | } | ||
2033 | |||
2034 | 677 | void ff_hevc_ps_uninit(HEVCParamSets *ps) | |
2035 | { | ||
2036 | int i; | ||
2037 | |||
2038 |
2/2✓ Branch 0 taken 10832 times.
✓ Branch 1 taken 677 times.
|
11509 | for (i = 0; i < FF_ARRAY_ELEMS(ps->vps_list); i++) |
2039 | 10832 | ff_refstruct_unref(&ps->vps_list[i]); | |
2040 |
2/2✓ Branch 0 taken 10832 times.
✓ Branch 1 taken 677 times.
|
11509 | for (i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++) |
2041 | 10832 | ff_refstruct_unref(&ps->sps_list[i]); | |
2042 |
2/2✓ Branch 0 taken 43328 times.
✓ Branch 1 taken 677 times.
|
44005 | for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++) |
2043 | 43328 | ff_refstruct_unref(&ps->pps_list[i]); | |
2044 | 677 | } | |
2045 | |||
2046 | 30737 | int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type) | |
2047 | { | ||
2048 | 30737 | int max_poc_lsb = 1 << sps->log2_max_poc_lsb; | |
2049 | 30737 | int prev_poc_lsb = pocTid0 % max_poc_lsb; | |
2050 | 30737 | int prev_poc_msb = pocTid0 - prev_poc_lsb; | |
2051 | int poc_msb; | ||
2052 | |||
2053 |
4/4✓ Branch 0 taken 10430 times.
✓ Branch 1 taken 20307 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 10390 times.
|
30737 | if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2) |
2054 | 40 | poc_msb = prev_poc_msb + max_poc_lsb; | |
2055 |
4/4✓ Branch 0 taken 14715 times.
✓ Branch 1 taken 15982 times.
✓ Branch 2 taken 302 times.
✓ Branch 3 taken 14413 times.
|
30697 | else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2) |
2056 | 302 | poc_msb = prev_poc_msb - max_poc_lsb; | |
2057 | else | ||
2058 | 30395 | poc_msb = prev_poc_msb; | |
2059 | |||
2060 | // For BLA picture types, POCmsb is set to 0. | ||
2061 |
4/4✓ Branch 0 taken 30722 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 30716 times.
✓ Branch 3 taken 6 times.
|
30737 | if (nal_unit_type == HEVC_NAL_BLA_W_LP || |
2062 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 30713 times.
|
30716 | nal_unit_type == HEVC_NAL_BLA_W_RADL || |
2063 | nal_unit_type == HEVC_NAL_BLA_N_LP) | ||
2064 | 24 | poc_msb = 0; | |
2065 | |||
2066 | 30737 | return poc_msb + poc_lsb; | |
2067 | } | ||
2068 |