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