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