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