Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * HEVC Parameter Set decoding | ||
3 | * | ||
4 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
5 | * Copyright (C) 2012 - 2013 Mickael Raulet | ||
6 | * Copyright (C) 2012 - 2013 Gildas Cocherel | ||
7 | * Copyright (C) 2013 Vittorio Giovara | ||
8 | * | ||
9 | * This file is part of FFmpeg. | ||
10 | * | ||
11 | * FFmpeg is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU Lesser General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2.1 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * FFmpeg is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * Lesser General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Lesser General Public | ||
22 | * License along with FFmpeg; if not, write to the Free Software | ||
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
24 | */ | ||
25 | |||
26 | #include "libavutil/imgutils.h" | ||
27 | #include "libavutil/mem.h" | ||
28 | #include "golomb.h" | ||
29 | #include "h2645_vui.h" | ||
30 | #include "data.h" | ||
31 | #include "ps.h" | ||
32 | #include "profiles.h" | ||
33 | #include "libavutil/refstruct.h" | ||
34 | |||
35 | static const uint8_t default_scaling_list_intra[] = { | ||
36 | 16, 16, 16, 16, 17, 18, 21, 24, | ||
37 | 16, 16, 16, 16, 17, 19, 22, 25, | ||
38 | 16, 16, 17, 18, 20, 22, 25, 29, | ||
39 | 16, 16, 18, 21, 24, 27, 31, 36, | ||
40 | 17, 17, 20, 24, 30, 35, 41, 47, | ||
41 | 18, 19, 22, 27, 35, 44, 54, 65, | ||
42 | 21, 22, 25, 31, 41, 54, 70, 88, | ||
43 | 24, 25, 29, 36, 47, 65, 88, 115 | ||
44 | }; | ||
45 | |||
46 | static const uint8_t default_scaling_list_inter[] = { | ||
47 | 16, 16, 16, 16, 17, 18, 20, 24, | ||
48 | 16, 16, 16, 17, 18, 20, 24, 25, | ||
49 | 16, 16, 17, 18, 20, 24, 25, 28, | ||
50 | 16, 17, 18, 20, 24, 25, 28, 33, | ||
51 | 17, 18, 20, 24, 25, 28, 33, 41, | ||
52 | 18, 20, 24, 25, 28, 33, 41, 54, | ||
53 | 20, 24, 25, 28, 33, 41, 54, 71, | ||
54 | 24, 25, 28, 33, 41, 54, 71, 91 | ||
55 | }; | ||
56 | |||
57 | static const uint8_t hevc_sub_width_c[] = { | ||
58 | 1, 2, 2, 1 | ||
59 | }; | ||
60 | |||
61 | static const uint8_t hevc_sub_height_c[] = { | ||
62 | 1, 2, 1, 1 | ||
63 | }; | ||
64 | |||
65 | 732 | static void remove_sps(HEVCParamSets *s, int id) | |
66 | { | ||
67 | int i; | ||
68 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 714 times.
|
732 | if (s->sps_list[id]) { |
69 | /* drop all PPS that depend on this SPS */ | ||
70 |
2/2✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
|
1170 | for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) |
71 |
4/4✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1133 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 1 times.
|
1152 | if (s->pps_list[i] && s->pps_list[i]->sps_id == id) |
72 | 18 | av_refstruct_unref(&s->pps_list[i]); | |
73 | |||
74 | 18 | av_refstruct_unref(&s->sps_list[id]); | |
75 | } | ||
76 | 732 | } | |
77 | |||
78 | 689 | static void remove_vps(HEVCParamSets *s, int id) | |
79 | { | ||
80 | int i; | ||
81 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 680 times.
|
689 | if (s->vps_list[id]) { |
82 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 9 times.
|
153 | for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) |
83 |
3/4✓ Branch 0 taken 10 times.
✓ Branch 1 taken 134 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
144 | if (s->sps_list[i] && s->sps_list[i]->vps_id == id) |
84 | 10 | remove_sps(s, i); | |
85 | 9 | av_refstruct_unref(&s->vps_list[id]); | |
86 | } | ||
87 | 689 | } | |
88 | |||
89 | 13499 | int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, | |
90 | ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header) | ||
91 | { | ||
92 | int delta_poc; | ||
93 | 13499 | int k0 = 0; | |
94 | 13499 | int k = 0; | |
95 | int i; | ||
96 | |||
97 | 13499 | rps->used = 0; | |
98 | 13499 | rps->rps_predict = 0; | |
99 | |||
100 |
4/4✓ Branch 0 taken 12487 times.
✓ Branch 1 taken 1012 times.
✓ Branch 2 taken 12163 times.
✓ Branch 3 taken 324 times.
|
13499 | if (rps != sps->st_rps && sps->nb_st_rps) |
101 | 12163 | rps->rps_predict = get_bits1(gb); | |
102 | |||
103 |
2/2✓ Branch 0 taken 8087 times.
✓ Branch 1 taken 5412 times.
|
13499 | if (rps->rps_predict) { |
104 | const ShortTermRPS *rps_ridx; | ||
105 | 8087 | uint8_t used[32] = { 0 }; | |
106 | int delta_rps; | ||
107 | |||
108 |
2/2✓ Branch 0 taken 699 times.
✓ Branch 1 taken 7388 times.
|
8087 | if (is_slice_header) { |
109 | 699 | rps->delta_idx = get_ue_golomb_long(gb) + 1; | |
110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 699 times.
|
699 | if (rps->delta_idx > sps->nb_st_rps) { |
111 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
112 | "Invalid value of delta_idx in slice header RPS: %d > %d.\n", | ||
113 | ✗ | rps->delta_idx, sps->nb_st_rps); | |
114 | ✗ | return AVERROR_INVALIDDATA; | |
115 | } | ||
116 | 699 | rps_ridx = &sps->st_rps[sps->nb_st_rps - rps->delta_idx]; | |
117 | 699 | rps->rps_idx_num_delta_pocs = rps_ridx->num_delta_pocs; | |
118 | } else | ||
119 | 7388 | rps_ridx = &sps->st_rps[rps - sps->st_rps - 1]; | |
120 | |||
121 | 8087 | rps->delta_rps_sign = get_bits1(gb); | |
122 | 8087 | rps->abs_delta_rps = get_ue_golomb_long(gb) + 1; | |
123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8087 times.
|
8087 | if (rps->abs_delta_rps > 32768) { |
124 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
125 | "Invalid value of abs_delta_rps: %d\n", | ||
126 | ✗ | rps->abs_delta_rps); | |
127 | ✗ | return AVERROR_INVALIDDATA; | |
128 | } | ||
129 | 8087 | delta_rps = (1 - (rps->delta_rps_sign << 1)) * rps->abs_delta_rps; | |
130 |
2/2✓ Branch 0 taken 35092 times.
✓ Branch 1 taken 8087 times.
|
43179 | for (i = 0; i <= rps_ridx->num_delta_pocs; i++) { |
131 | 35092 | used[k] = get_bits1(gb); | |
132 | |||
133 | 35092 | rps->use_delta = 0; | |
134 |
2/2✓ Branch 0 taken 6996 times.
✓ Branch 1 taken 28096 times.
|
35092 | if (!used[k]) |
135 | 6996 | rps->use_delta = get_bits1(gb); | |
136 | |||
137 |
4/4✓ Branch 0 taken 6996 times.
✓ Branch 1 taken 28096 times.
✓ Branch 2 taken 50 times.
✓ Branch 3 taken 6946 times.
|
35092 | if (used[k] || rps->use_delta) { |
138 |
2/2✓ Branch 0 taken 22222 times.
✓ Branch 1 taken 5924 times.
|
28146 | if (i < rps_ridx->num_delta_pocs) |
139 | 22222 | delta_poc = delta_rps + rps_ridx->delta_poc[i]; | |
140 | else | ||
141 | 5924 | delta_poc = delta_rps; | |
142 | 28146 | rps->delta_poc[k] = delta_poc; | |
143 |
2/2✓ Branch 0 taken 19284 times.
✓ Branch 1 taken 8862 times.
|
28146 | if (delta_poc < 0) |
144 | 19284 | k0++; | |
145 | 28146 | k++; | |
146 | } | ||
147 | } | ||
148 | |||
149 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8087 times.
|
8087 | if (k >= FF_ARRAY_ELEMS(used)) { |
150 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
151 | "Invalid num_delta_pocs: %d\n", k); | ||
152 | ✗ | return AVERROR_INVALIDDATA; | |
153 | } | ||
154 | |||
155 | 8087 | rps->num_delta_pocs = k; | |
156 | 8087 | rps->num_negative_pics = k0; | |
157 | // sort in increasing order (smallest first) | ||
158 |
1/2✓ Branch 0 taken 8087 times.
✗ Branch 1 not taken.
|
8087 | if (rps->num_delta_pocs != 0) { |
159 | int u, tmp; | ||
160 |
2/2✓ Branch 0 taken 20059 times.
✓ Branch 1 taken 8087 times.
|
28146 | for (i = 1; i < rps->num_delta_pocs; i++) { |
161 | 20059 | delta_poc = rps->delta_poc[i]; | |
162 | 20059 | u = used[i]; | |
163 |
2/2✓ Branch 0 taken 37329 times.
✓ Branch 1 taken 20059 times.
|
57388 | for (k = i - 1; k >= 0; k--) { |
164 | 37329 | tmp = rps->delta_poc[k]; | |
165 |
2/2✓ Branch 0 taken 11761 times.
✓ Branch 1 taken 25568 times.
|
37329 | if (delta_poc < tmp) { |
166 | 11761 | rps->delta_poc[k + 1] = tmp; | |
167 | 11761 | used[k + 1] = used[k]; | |
168 | 11761 | rps->delta_poc[k] = delta_poc; | |
169 | 11761 | used[k] = u; | |
170 | } | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 |
2/2✓ Branch 0 taken 6099 times.
✓ Branch 1 taken 1988 times.
|
8087 | if ((rps->num_negative_pics >> 1) != 0) { |
175 | int u; | ||
176 | 6099 | k = rps->num_negative_pics - 1; | |
177 | // flip the negative values to largest first | ||
178 |
2/2✓ Branch 0 taken 7908 times.
✓ Branch 1 taken 6099 times.
|
14007 | for (i = 0; i < rps->num_negative_pics >> 1; i++) { |
179 | 7908 | delta_poc = rps->delta_poc[i]; | |
180 | 7908 | u = used[i]; | |
181 | 7908 | rps->delta_poc[i] = rps->delta_poc[k]; | |
182 | 7908 | used[i] = used[k]; | |
183 | 7908 | rps->delta_poc[k] = delta_poc; | |
184 | 7908 | used[k] = u; | |
185 | 7908 | k--; | |
186 | } | ||
187 | } | ||
188 | |||
189 |
2/2✓ Branch 0 taken 258784 times.
✓ Branch 1 taken 8087 times.
|
266871 | for (unsigned i = 0; i < FF_ARRAY_ELEMS(used); i++) |
190 | 258784 | rps->used |= (uint32_t)used[i] << i; | |
191 | } else { | ||
192 | unsigned int nb_positive_pics; | ||
193 | |||
194 | 5412 | rps->num_negative_pics = get_ue_golomb_long(gb); | |
195 | 5412 | nb_positive_pics = get_ue_golomb_long(gb); | |
196 | |||
197 |
2/4✓ Branch 0 taken 5412 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5412 times.
|
5412 | if (rps->num_negative_pics >= HEVC_MAX_REFS || |
198 | nb_positive_pics >= HEVC_MAX_REFS) { | ||
199 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many refs in a short term RPS.\n"); | |
200 | ✗ | return AVERROR_INVALIDDATA; | |
201 | } | ||
202 | |||
203 | 5412 | rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics; | |
204 |
2/2✓ Branch 0 taken 4839 times.
✓ Branch 1 taken 573 times.
|
5412 | if (rps->num_delta_pocs) { |
205 | 4839 | int prev = 0; | |
206 | |||
207 |
2/2✓ Branch 0 taken 14365 times.
✓ Branch 1 taken 4839 times.
|
19204 | for (i = 0; i < rps->num_negative_pics; i++) { |
208 | 14365 | delta_poc = get_ue_golomb_long(gb) + 1; | |
209 |
2/4✓ Branch 0 taken 14365 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14365 times.
|
14365 | if (delta_poc < 1 || delta_poc > 32768) { |
210 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
211 | "Invalid value of delta_poc: %d\n", | ||
212 | delta_poc); | ||
213 | ✗ | return AVERROR_INVALIDDATA; | |
214 | } | ||
215 | 14365 | prev -= delta_poc; | |
216 | 14365 | rps->delta_poc[i] = prev; | |
217 | 14365 | rps->used |= get_bits1(gb) * (1 << i); | |
218 | } | ||
219 | 4839 | prev = 0; | |
220 |
2/2✓ Branch 0 taken 1235 times.
✓ Branch 1 taken 4839 times.
|
6074 | for (i = 0; i < nb_positive_pics; i++) { |
221 | 1235 | delta_poc = get_ue_golomb_long(gb) + 1; | |
222 |
2/4✓ Branch 0 taken 1235 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1235 times.
|
1235 | if (delta_poc < 1 || delta_poc > 32768) { |
223 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
224 | "Invalid value of delta_poc: %d\n", | ||
225 | delta_poc); | ||
226 | ✗ | return AVERROR_INVALIDDATA; | |
227 | } | ||
228 | 1235 | prev += delta_poc; | |
229 | 1235 | rps->delta_poc[rps->num_negative_pics + i] = prev; | |
230 | 1235 | rps->used |= get_bits1(gb) * (1 << (rps->num_negative_pics + i)); | |
231 | } | ||
232 | } | ||
233 | } | ||
234 | 13499 | return 0; | |
235 | } | ||
236 | |||
237 | |||
238 | 1900 | static int decode_profile_tier_level(GetBitContext *gb, AVCodecContext *avctx, | |
239 | PTLCommon *ptl) | ||
240 | { | ||
241 | 1900 | const char *profile_name = NULL; | |
242 | int i; | ||
243 | |||
244 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1900 times.
|
1900 | if (get_bits_left(gb) < 2+1+5 + 32 + 4 + 43 + 1) |
245 | ✗ | return -1; | |
246 | |||
247 | 1900 | ptl->profile_space = get_bits(gb, 2); | |
248 | 1900 | ptl->tier_flag = get_bits1(gb); | |
249 | 1900 | ptl->profile_idc = get_bits(gb, 5); | |
250 | |||
251 | #if !CONFIG_SMALL | ||
252 |
2/2✓ Branch 0 taken 2702 times.
✓ Branch 1 taken 40 times.
|
2742 | for (int i = 0; ff_hevc_profiles[i].profile != AV_PROFILE_UNKNOWN; i++) |
253 |
2/2✓ Branch 0 taken 1860 times.
✓ Branch 1 taken 842 times.
|
2702 | if (ff_hevc_profiles[i].profile == ptl->profile_idc) { |
254 | 1860 | profile_name = ff_hevc_profiles[i].name; | |
255 | 1860 | break; | |
256 | } | ||
257 | #endif | ||
258 |
4/4✓ Branch 0 taken 1860 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 1860 times.
✓ Branch 3 taken 40 times.
|
1900 | av_log(avctx, profile_name ? AV_LOG_DEBUG : AV_LOG_WARNING, |
259 | "%s profile bitstream\n", profile_name ? profile_name : "Unknown"); | ||
260 | |||
261 |
2/2✓ Branch 0 taken 60800 times.
✓ Branch 1 taken 1900 times.
|
62700 | for (i = 0; i < 32; i++) { |
262 | 60800 | ptl->profile_compatibility_flag[i] = get_bits1(gb); | |
263 | |||
264 |
6/6✓ Branch 0 taken 96 times.
✓ Branch 1 taken 60704 times.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 32 times.
|
60800 | if (ptl->profile_idc == 0 && i > 0 && ptl->profile_compatibility_flag[i]) |
265 | 32 | ptl->profile_idc = i; | |
266 | } | ||
267 | 1900 | ptl->progressive_source_flag = get_bits1(gb); | |
268 | 1900 | ptl->interlaced_source_flag = get_bits1(gb); | |
269 | 1900 | ptl->non_packed_constraint_flag = get_bits1(gb); | |
270 | 1900 | ptl->frame_only_constraint_flag = get_bits1(gb); | |
271 | |||
272 | #define check_profile_idc(idc) \ | ||
273 | ptl->profile_idc == idc || ptl->profile_compatibility_flag[idc] | ||
274 | |||
275 |
9/12✓ Branch 0 taken 1796 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 1796 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1788 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 1788 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1765 times.
✓ Branch 9 taken 23 times.
✓ Branch 10 taken 1765 times.
✗ Branch 11 not taken.
|
1900 | if (check_profile_idc(4) || check_profile_idc(5) || check_profile_idc(6) || |
276 |
6/12✓ Branch 0 taken 1765 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1765 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1765 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1765 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1765 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1765 times.
✗ Branch 11 not taken.
|
1765 | check_profile_idc(7) || check_profile_idc(8) || check_profile_idc(9) || |
277 |
2/4✓ Branch 0 taken 1765 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1765 times.
|
1765 | check_profile_idc(10)) { |
278 | |||
279 | 135 | ptl->max_12bit_constraint_flag = get_bits1(gb); | |
280 | 135 | ptl->max_10bit_constraint_flag = get_bits1(gb); | |
281 | 135 | ptl->max_8bit_constraint_flag = get_bits1(gb); | |
282 | 135 | ptl->max_422chroma_constraint_flag = get_bits1(gb); | |
283 | 135 | ptl->max_420chroma_constraint_flag = get_bits1(gb); | |
284 | 135 | ptl->max_monochrome_constraint_flag = get_bits1(gb); | |
285 | 135 | ptl->intra_constraint_flag = get_bits1(gb); | |
286 | 135 | ptl->one_picture_only_constraint_flag = get_bits1(gb); | |
287 | 135 | ptl->lower_bit_rate_constraint_flag = get_bits1(gb); | |
288 | |||
289 |
7/12✓ Branch 0 taken 127 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 127 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 127 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 127 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 127 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 127 times.
|
135 | if (check_profile_idc(5) || check_profile_idc(9) || check_profile_idc(10)) { |
290 | 8 | ptl->max_14bit_constraint_flag = get_bits1(gb); | |
291 | 8 | skip_bits_long(gb, 33); // XXX_reserved_zero_33bits[0..32] | |
292 | } else { | ||
293 | 127 | skip_bits_long(gb, 34); // XXX_reserved_zero_34bits[0..33] | |
294 | } | ||
295 |
4/4✓ Branch 0 taken 1549 times.
✓ Branch 1 taken 216 times.
✓ Branch 2 taken 1298 times.
✓ Branch 3 taken 251 times.
|
1765 | } else if (check_profile_idc(2)) { |
296 | 1514 | skip_bits(gb, 7); | |
297 | 1514 | ptl->one_picture_only_constraint_flag = get_bits1(gb); | |
298 | 1514 | skip_bits_long(gb, 35); // XXX_reserved_zero_35bits[0..34] | |
299 | } else { | ||
300 | 251 | skip_bits_long(gb, 43); // XXX_reserved_zero_43bits[0..42] | |
301 | } | ||
302 | |||
303 |
9/12✓ Branch 0 taken 358 times.
✓ Branch 1 taken 1542 times.
✓ Branch 2 taken 351 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 135 times.
✓ Branch 5 taken 216 times.
✓ Branch 6 taken 135 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 135 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 135 times.
✗ Branch 11 not taken.
|
1900 | if (check_profile_idc(1) || check_profile_idc(2) || check_profile_idc(3) || |
304 |
8/12✓ Branch 0 taken 31 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 23 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 23 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 23 times.
|
135 | check_profile_idc(4) || check_profile_idc(5) || check_profile_idc(9)) |
305 | 1877 | ptl->inbld_flag = get_bits1(gb); | |
306 | else | ||
307 | 23 | skip_bits1(gb); | |
308 | #undef check_profile_idc | ||
309 | |||
310 | 1900 | return 0; | |
311 | } | ||
312 | |||
313 | 1883 | static int parse_ptl(GetBitContext *gb, AVCodecContext *avctx, | |
314 | int profile_present, PTL *ptl, int max_num_sub_layers) | ||
315 | { | ||
316 | 1883 | int i, status = 0; | |
317 | |||
318 |
2/2✓ Branch 0 taken 1858 times.
✓ Branch 1 taken 25 times.
|
1883 | if (profile_present) { |
319 | 1858 | status = decode_profile_tier_level(gb, avctx, &ptl->general_ptl); | |
320 | } else { | ||
321 | 25 | memset(&ptl->general_ptl, 0, sizeof(ptl->general_ptl)); | |
322 | } | ||
323 | |||
324 |
4/6✓ Branch 0 taken 1883 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 153 times.
✓ Branch 4 taken 1730 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1883 times.
|
1883 | if (status < 0 || get_bits_left(gb) < 8 + (8*2 * (max_num_sub_layers - 1 > 0))) { |
325 | ✗ | av_log(avctx, AV_LOG_ERROR, "PTL information too short\n"); | |
326 | ✗ | return -1; | |
327 | } | ||
328 | |||
329 | 1883 | ptl->general_ptl.level_idc = get_bits(gb, 8); | |
330 | |||
331 |
2/2✓ Branch 0 taken 303 times.
✓ Branch 1 taken 1883 times.
|
2186 | for (i = 0; i < max_num_sub_layers - 1; i++) { |
332 | 303 | ptl->sub_layer_profile_present_flag[i] = get_bits1(gb); | |
333 | 303 | ptl->sub_layer_level_present_flag[i] = get_bits1(gb); | |
334 | } | ||
335 | |||
336 |
2/2✓ Branch 0 taken 153 times.
✓ Branch 1 taken 1730 times.
|
1883 | if (max_num_sub_layers - 1> 0) |
337 |
2/2✓ Branch 0 taken 921 times.
✓ Branch 1 taken 153 times.
|
1074 | for (i = max_num_sub_layers - 1; i < 8; i++) |
338 | 921 | skip_bits(gb, 2); // reserved_zero_2bits[i] | |
339 |
2/2✓ Branch 0 taken 303 times.
✓ Branch 1 taken 1883 times.
|
2186 | for (i = 0; i < max_num_sub_layers - 1; i++) { |
340 |
3/4✓ Branch 0 taken 42 times.
✓ Branch 1 taken 261 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 42 times.
|
345 | if (ptl->sub_layer_profile_present_flag[i] && |
341 | 42 | decode_profile_tier_level(gb, avctx, &ptl->sub_layer_ptl[i]) < 0) { | |
342 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
343 | "PTL information for sublayer %i too short\n", i); | ||
344 | ✗ | return -1; | |
345 | } | ||
346 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 261 times.
|
303 | if (ptl->sub_layer_level_present_flag[i]) { |
347 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
|
42 | if (get_bits_left(gb) < 8) { |
348 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
349 | "Not enough data for sublayer %i level_idc\n", i); | ||
350 | ✗ | return -1; | |
351 | } else | ||
352 | 42 | ptl->sub_layer_ptl[i].level_idc = get_bits(gb, 8); | |
353 | } | ||
354 | } | ||
355 | |||
356 | 1883 | return 0; | |
357 | } | ||
358 | |||
359 | 106 | static void decode_sublayer_hrd(GetBitContext *gb, unsigned int nb_cpb, | |
360 | HEVCSublayerHdrParams *par, int subpic_params_present) | ||
361 | { | ||
362 | int i; | ||
363 | |||
364 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 106 times.
|
212 | for (i = 0; i < nb_cpb; i++) { |
365 | 106 | par->bit_rate_value_minus1[i] = get_ue_golomb_long(gb); | |
366 | 106 | par->cpb_size_value_minus1[i] = get_ue_golomb_long(gb); | |
367 | |||
368 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 72 times.
|
106 | if (subpic_params_present) { |
369 | 34 | par->cpb_size_du_value_minus1[i] = get_ue_golomb_long(gb); | |
370 | 34 | par->bit_rate_du_value_minus1[i] = get_ue_golomb_long(gb); | |
371 | } | ||
372 | |||
373 | 106 | par->cbr_flag |= get_bits1(gb) << i; | |
374 | } | ||
375 | 106 | } | |
376 | |||
377 | 58 | static int decode_hrd(GetBitContext *gb, int common_inf_present, | |
378 | HEVCHdrParams *hdr, int max_sublayers) | ||
379 | { | ||
380 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | if (common_inf_present) { |
381 | 58 | hdr->nal_hrd_parameters_present_flag = get_bits1(gb); | |
382 | 58 | hdr->vcl_hrd_parameters_present_flag = get_bits1(gb); | |
383 | |||
384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (hdr->nal_hrd_parameters_present_flag || |
385 | ✗ | hdr->vcl_hrd_parameters_present_flag) { | |
386 | 58 | hdr->sub_pic_hrd_params_present_flag = get_bits1(gb); | |
387 | |||
388 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 41 times.
|
58 | if (hdr->sub_pic_hrd_params_present_flag) { |
389 | 17 | hdr->tick_divisor_minus2 = get_bits(gb, 8); | |
390 | 17 | hdr->du_cpb_removal_delay_increment_length_minus1 = get_bits(gb, 5); | |
391 | 17 | hdr->sub_pic_cpb_params_in_pic_timing_sei_flag = get_bits1(gb); | |
392 | 17 | hdr->dpb_output_delay_du_length_minus1 = get_bits(gb, 5); | |
393 | } | ||
394 | |||
395 | 58 | hdr->bit_rate_scale = get_bits(gb, 4); | |
396 | 58 | hdr->cpb_size_scale = get_bits(gb, 4); | |
397 | |||
398 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 41 times.
|
58 | if (hdr->sub_pic_hrd_params_present_flag) |
399 | 17 | hdr->cpb_size_du_scale = get_bits(gb, 4); | |
400 | |||
401 | 58 | hdr->initial_cpb_removal_delay_length_minus1 = get_bits(gb, 5); | |
402 | 58 | hdr->au_cpb_removal_delay_length_minus1 = get_bits(gb, 5); | |
403 | 58 | hdr->dpb_output_delay_length_minus1 = get_bits(gb, 5); | |
404 | } | ||
405 | } | ||
406 | |||
407 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 58 times.
|
116 | for (int i = 0; i < max_sublayers; i++) { |
408 | 58 | unsigned fixed_pic_rate_general_flag = get_bits1(gb); | |
409 | 58 | unsigned fixed_pic_rate_within_cvs_flag = 0; | |
410 | 58 | unsigned low_delay_hrd_flag = 0; | |
411 | 58 | hdr->flags.fixed_pic_rate_general_flag |= fixed_pic_rate_general_flag << i; | |
412 | |||
413 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 35 times.
|
58 | if (!fixed_pic_rate_general_flag) |
414 | 23 | fixed_pic_rate_within_cvs_flag = get_bits1(gb); | |
415 | 58 | hdr->flags.fixed_pic_rate_within_cvs_flag |= fixed_pic_rate_within_cvs_flag << i; | |
416 | |||
417 |
3/4✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 23 times.
|
58 | if (fixed_pic_rate_within_cvs_flag || fixed_pic_rate_general_flag) |
418 | 35 | hdr->elemental_duration_in_tc_minus1[i] = get_ue_golomb_long(gb); | |
419 | else | ||
420 | 23 | low_delay_hrd_flag = get_bits1(gb); | |
421 | 58 | hdr->flags.low_delay_hrd_flag |= low_delay_hrd_flag << i; | |
422 | |||
423 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | if (!low_delay_hrd_flag) { |
424 | 58 | unsigned cpb_cnt_minus1 = get_ue_golomb_long(gb); | |
425 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (cpb_cnt_minus1 > 31) { |
426 | ✗ | av_log(NULL, AV_LOG_ERROR, "nb_cpb %d invalid\n", | |
427 | cpb_cnt_minus1); | ||
428 | ✗ | return AVERROR_INVALIDDATA; | |
429 | } | ||
430 | 58 | hdr->cpb_cnt_minus1[i] = cpb_cnt_minus1; | |
431 | } | ||
432 | |||
433 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | if (hdr->nal_hrd_parameters_present_flag) |
434 | 58 | decode_sublayer_hrd(gb, hdr->cpb_cnt_minus1[i]+1, &hdr->nal_params[i], | |
435 | 58 | hdr->sub_pic_hrd_params_present_flag); | |
436 | |||
437 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 10 times.
|
58 | if (hdr->vcl_hrd_parameters_present_flag) |
438 | 48 | decode_sublayer_hrd(gb, hdr->cpb_cnt_minus1[i]+1, &hdr->vcl_params[i], | |
439 | 48 | hdr->sub_pic_hrd_params_present_flag); | |
440 | } | ||
441 | |||
442 | 58 | return 0; | |
443 | } | ||
444 | |||
445 | 689 | static void hevc_vps_free(AVRefStructOpaque opaque, void *obj) | |
446 | { | ||
447 | 689 | HEVCVPS *vps = obj; | |
448 | |||
449 | 689 | av_freep(&vps->hdr); | |
450 | 689 | av_freep(&vps->data); | |
451 | 689 | } | |
452 | |||
453 | enum DependencyType { | ||
454 | HEVC_DEP_TYPE_SAMPLE = 0, | ||
455 | HEVC_DEP_TYPE_MV = 1, | ||
456 | HEVC_DEP_TYPE_BOTH = 2, | ||
457 | }; | ||
458 | |||
459 | 25 | static int decode_vps_ext(GetBitContext *gb, AVCodecContext *avctx, HEVCVPS *vps, | |
460 | uint64_t layer1_id_included) | ||
461 | { | ||
462 | PTL ptl_dummy; | ||
463 | 25 | uint8_t max_sub_layers[HEVC_MAX_LAYERS] = {1, 1}; | |
464 | 25 | uint8_t dimension_id_len[16] = {0}; | |
465 | 25 | uint8_t dimension_id[16] = {0}; | |
466 | unsigned n; | ||
467 | |||
468 | int splitting_flag, view_id_len, num_add_olss, num_scalability_types, | ||
469 | default_output_layer_idc, direct_dep_type_len, direct_dep_type, | ||
470 | sub_layers_max_present, sub_layer_flag_info_present_flag, nb_ptl; | ||
471 | unsigned non_vui_extension_length; | ||
472 | |||
473 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (vps->vps_max_layers == 1) { |
474 | ✗ | av_log(avctx, AV_LOG_VERBOSE, "Ignoring VPS extensions with a single layer\n"); | |
475 | ✗ | return 0; | |
476 | } | ||
477 | |||
478 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (vps->vps_max_layers > 2) { |
479 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
480 | "VPS has %d layers, only 2 layers are supported\n", | ||
481 | vps->vps_max_layers); | ||
482 | ✗ | return AVERROR_PATCHWELCOME; | |
483 | } | ||
484 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (vps->vps_num_layer_sets > 2) { |
485 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
486 | "VPS has %d layer sets, only 2 layer sets are supported\n", | ||
487 | vps->vps_num_layer_sets); | ||
488 | ✗ | return AVERROR_PATCHWELCOME; | |
489 | } | ||
490 | |||
491 | 25 | align_get_bits(gb); | |
492 | |||
493 | /** | ||
494 | * For stereoscopic MV-HEVC, the following simplifying assumptions are made: | ||
495 | * | ||
496 | * - vps_max_layers = 2 (one base layer, one multiview layer) | ||
497 | * - vps_num_layer_sets = 2 (one output layer set for each view) | ||
498 | * - NumScalabilityTypes = 1 (only HEVC_SCALABILITY_MULTIVIEW) | ||
499 | * - direct_dependency_flag[1][0] = 1 (second layer depends on first) | ||
500 | * - num_add_olss = 0 (no extra output layer sets) | ||
501 | * - default_output_layer_idc = 0 (1:1 mapping between OLSs and layers) | ||
502 | * - layer_id_included_flag[1] = {1, 1} (consequence of layer dependencies) | ||
503 | * - vps_num_rep_formats_minus1 = 0 (all layers have the same size) | ||
504 | * | ||
505 | * Which results in the following derived variables: | ||
506 | * - ViewOrderIdx = {0, 1} | ||
507 | * - NumViews = 2 | ||
508 | * - DependencyFlag[1][0] = 1 | ||
509 | * - NumDirectRefLayers = {0, 1} | ||
510 | * - NumRefLayers = {0, 1} | ||
511 | * - NumPredictedLayers = {1, 0} | ||
512 | * - NumIndependentLayers = 1 | ||
513 | * - NumLayersInTreePartition = {2} | ||
514 | * - NumLayerSets = 2 | ||
515 | * - NumOutputLayerSets = 2 | ||
516 | * - OlsIdxToLsIdx = {0, 1} | ||
517 | * - LayerIdxInVps = {0, 1} | ||
518 | * - NumLayersInIdList = {1, 2} | ||
519 | * - NumNecessaryLayers = {1, 2} | ||
520 | * - NecessaryLayerFlag = {{1, 0}, {1, 1}} | ||
521 | * - NumOutputLayersInOutputLayerSet = {1, 2} | ||
522 | * - OutputLayerFlag = {{1, 0}, {1, 1}} | ||
523 | */ | ||
524 | 25 | vps->nb_layers = 2; | |
525 | |||
526 | /* vps_base_layer_internal_flag is true has been checked before */ | ||
527 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
25 | if (parse_ptl(gb, avctx, 0, &ptl_dummy, vps->vps_max_sub_layers) < 0) |
528 | ✗ | return AVERROR_INVALIDDATA; | |
529 | |||
530 | 25 | splitting_flag = get_bits1(gb); | |
531 | 25 | vps->scalability_mask_flag = get_bits(gb, 16); | |
532 | 25 | num_scalability_types = av_popcount(vps->scalability_mask_flag); | |
533 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (!num_scalability_types) { |
534 | ✗ | av_log(avctx, AV_LOG_ERROR, "Missing scalability mask\n"); | |
535 | ✗ | return AVERROR_INVALIDDATA; | |
536 | } | ||
537 | |||
538 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (!(vps->scalability_mask_flag & |
539 | (HEVC_SCALABILITY_MULTIVIEW | HEVC_SCALABILITY_AUXILIARY))) { | ||
540 | ✗ | av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n", | |
541 | ✗ | 15 - ff_ctz(vps->scalability_mask_flag)); | |
542 | ✗ | return AVERROR_PATCHWELCOME; | |
543 | } | ||
544 | // x265 specify MULTIVIEW when the stream really is alpha video only. | ||
545 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (num_scalability_types > 1) |
546 | ✗ | av_log(avctx, AV_LOG_WARNING, "Multiple scalability types presented\n"); | |
547 | |||
548 | 25 | n = 0; | |
549 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 25 times.
|
50 | for (int i = 0; i < num_scalability_types - splitting_flag; i++) { |
550 | 25 | dimension_id_len[i] = get_bits(gb, 3) + 1; | |
551 | 25 | n += dimension_id_len[i]; | |
552 | } | ||
553 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (splitting_flag) |
554 | ✗ | dimension_id_len[num_scalability_types - 1] = 5 - n; | |
555 | |||
556 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 2 taken 14 times.
|
25 | if (get_bits1(gb)) { /* vps_nuh_layer_id_present_flag */ |
557 | 11 | int layer_id_in_nuh = get_bits(gb, 6); | |
558 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (layer_id_in_nuh >= FF_ARRAY_ELEMS(vps->layer_idx)) { |
559 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid layer_id_in_nuh[1]: %d\n", | |
560 | layer_id_in_nuh); | ||
561 | ✗ | return AVERROR_INVALIDDATA; | |
562 | } | ||
563 | 11 | vps->layer_idx[layer_id_in_nuh] = 1; | |
564 | 11 | vps->layer_id_in_nuh[1] = layer_id_in_nuh; | |
565 | } else { | ||
566 | 14 | vps->layer_idx[1] = 1; | |
567 | 14 | vps->layer_id_in_nuh[1] = 1; | |
568 | } | ||
569 | |||
570 |
1/2✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
|
25 | if (!splitting_flag) { |
571 | 25 | int index = 0; | |
572 | |||
573 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 25 times.
|
50 | for (int i = 0; i < num_scalability_types; i++) |
574 | 25 | dimension_id[i] = get_bits(gb, dimension_id_len[i]); | |
575 | |||
576 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 2 times.
|
25 | if (vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW) |
577 | 23 | index++; | |
578 | |||
579 | /* AuxId 1 is alpha, 2 is depth. Only support alpha */ | ||
580 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 23 times.
|
25 | if (vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY && |
581 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | dimension_id[index] != HEVC_AUX_ALPHA) { |
582 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
583 | "Unsupported dimension_id %d for HEVC_SCALABILITY_AUXILIARY\n", | ||
584 | ✗ | dimension_id[index]); | |
585 | ✗ | return AVERROR_PATCHWELCOME; | |
586 | } | ||
587 | } | ||
588 | |||
589 | 25 | view_id_len = get_bits(gb, 4); | |
590 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 2 times.
|
25 | if (view_id_len) { |
591 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | n = (vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW) ? 2 : 1; |
592 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 23 times.
|
69 | for (int i = 0; i < n; i++) |
593 | 46 | vps->view_id[i] = get_bits(gb, view_id_len); | |
594 | } | ||
595 | |||
596 | /* direct_dependency_flag */ | ||
597 | 25 | vps->num_direct_ref_layers[1] = get_bits1(gb); | |
598 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 23 times.
|
25 | if (!vps->num_direct_ref_layers[1]) { |
599 | 2 | vps->num_add_layer_sets = get_ue_golomb(gb); | |
600 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (vps->num_add_layer_sets > 1) { |
601 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
602 | ✗ | "Unsupported num_add_layer_sets: %d\n", vps->num_add_layer_sets); | |
603 | ✗ | return AVERROR_PATCHWELCOME; | |
604 | } | ||
605 | |||
606 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (vps->num_add_layer_sets) { |
607 | /* highest_layer_idx_plus1 */ | ||
608 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!get_bits1(gb)) |
609 | ✗ | return AVERROR_PATCHWELCOME; | |
610 | } | ||
611 | } | ||
612 | 25 | vps->num_output_layer_sets = vps->vps_num_layer_sets + vps->num_add_layer_sets; | |
613 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (vps->num_output_layer_sets != 2) |
614 | ✗ | return AVERROR_INVALIDDATA; | |
615 | |||
616 | 25 | sub_layers_max_present = get_bits1(gb); // vps_sub_layers_max_minus1_present_flag | |
617 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (sub_layers_max_present) { |
618 | ✗ | for (int i = 0; i < vps->vps_max_layers; i++) | |
619 | ✗ | max_sub_layers[i] = sub_layers_max_present ? get_bits(gb, 3) + 1 : | |
620 | ✗ | vps->vps_max_sub_layers; | |
621 | } | ||
622 | |||
623 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
25 | if (get_bits1(gb) /* max_tid_ref_present_flag */) |
624 | ✗ | skip_bits(gb, 3); // max_tid_il_ref_pics_plus1 | |
625 | |||
626 | 25 | vps->default_ref_layers_active = get_bits1(gb); | |
627 | |||
628 | 25 | nb_ptl = get_ue_golomb(gb) + 1; | |
629 | /* idx [0] is signalled in base VPS, idx [1] is signalled at the | ||
630 | * start of VPS extension, indices 2+ are signalled here; | ||
631 | * we ignore all but the first one anyway */ | ||
632 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 25 times.
|
48 | for (int i = 2; i < nb_ptl; i++) { |
633 | 23 | int profile_present = get_bits1(gb); | |
634 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
|
23 | if (parse_ptl(gb, avctx, profile_present, &ptl_dummy, vps->vps_max_sub_layers) < 0) |
635 | ✗ | return AVERROR_INVALIDDATA; | |
636 | } | ||
637 | |||
638 | 25 | num_add_olss = get_ue_golomb(gb); | |
639 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (num_add_olss != 0) { |
640 | /* Since we don't implement support for independent output layer sets | ||
641 | * and auxiliary layers, this should never nonzero */ | ||
642 | ✗ | av_log(avctx, AV_LOG_ERROR, "Unexpected num_add_olss: %d\n", num_add_olss); | |
643 | ✗ | return AVERROR_PATCHWELCOME; | |
644 | } | ||
645 | |||
646 | 25 | default_output_layer_idc = get_bits(gb, 2); | |
647 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (default_output_layer_idc != 0) { |
648 | ✗ | av_log(avctx, AV_LOG_WARNING, "Unsupported default_output_layer_idc: %d\n", | |
649 | default_output_layer_idc); | ||
650 | ✗ | return AVERROR_PATCHWELCOME; | |
651 | } | ||
652 | |||
653 | /* Consequence of established layer dependencies */ | ||
654 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 2 times.
|
25 | if (layer1_id_included && |
655 | 23 | layer1_id_included != ((1 << vps->layer_id_in_nuh[0]) | | |
656 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | (1 << vps->layer_id_in_nuh[1]))) { |
657 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
658 | "Dependent layer not included in layer ID?\n"); | ||
659 | ✗ | return AVERROR_PATCHWELCOME; | |
660 | } | ||
661 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 23 times.
|
25 | if (!layer1_id_included) |
662 | 2 | vps->ols[1] = 2; | |
663 | else | ||
664 | 23 | vps->ols[1] = 3; | |
665 | |||
666 |
3/4✓ Branch 0 taken 23 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
|
25 | if (vps->vps_num_layer_sets == 1 || default_output_layer_idc == 2) |
667 | 2 | skip_bits1(gb); | |
668 | |||
669 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 25 times.
|
73 | for (int j = 0; j < av_popcount64(vps->ols[1]); j++) { |
670 | 48 | int ptl_idx = get_bits(gb, av_ceil_log2(nb_ptl)); | |
671 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (ptl_idx >= nb_ptl) { |
672 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid PTL index: %d\n", ptl_idx); | |
673 | ✗ | return AVERROR_INVALIDDATA; | |
674 | } | ||
675 | } | ||
676 | |||
677 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
25 | if (get_ue_golomb_31(gb) != 0 /* vps_num_rep_formats_minus1 */) { |
678 | ✗ | av_log(avctx, AV_LOG_ERROR, "Unexpected extra rep formats\n"); | |
679 | ✗ | return AVERROR_INVALIDDATA; | |
680 | } | ||
681 | |||
682 | 25 | vps->rep_format.pic_width_in_luma_samples = get_bits(gb, 16); | |
683 | 25 | vps->rep_format.pic_height_in_luma_samples = get_bits(gb, 16); | |
684 | |||
685 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
25 | if (!get_bits1(gb) /* chroma_and_bit_depth_vps_present_flag */) { |
686 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
687 | "chroma_and_bit_depth_vps_present_flag=0 in first rep_format\n"); | ||
688 | ✗ | return AVERROR_INVALIDDATA; | |
689 | } | ||
690 | 25 | vps->rep_format.chroma_format_idc = get_bits(gb, 2); | |
691 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (vps->rep_format.chroma_format_idc == 3) |
692 | ✗ | vps->rep_format.separate_colour_plane_flag = get_bits1(gb); | |
693 | 25 | vps->rep_format.bit_depth_luma = get_bits(gb, 4) + 8; | |
694 | 25 | vps->rep_format.bit_depth_chroma = get_bits(gb, 4) + 8; | |
695 |
1/2✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
|
25 | if (vps->rep_format.bit_depth_luma > 16 || |
696 |
1/2✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
|
25 | vps->rep_format.bit_depth_chroma > 16 || |
697 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | vps->rep_format.bit_depth_luma != vps->rep_format.bit_depth_chroma) { |
698 | ✗ | av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %"PRIu8" %"PRIu8"\n", | |
699 | ✗ | vps->rep_format.bit_depth_luma, vps->rep_format.bit_depth_chroma); | |
700 | ✗ | return AVERROR_PATCHWELCOME; | |
701 | } | ||
702 | |||
703 |
1/2✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
|
25 | if (get_bits1(gb) /* conformance_window_vps_flag */) { |
704 | 25 | int vert_mult = hevc_sub_height_c[vps->rep_format.chroma_format_idc]; | |
705 | 25 | int horiz_mult = hevc_sub_width_c[vps->rep_format.chroma_format_idc]; | |
706 | 25 | vps->rep_format.conf_win_left_offset = get_ue_golomb(gb) * horiz_mult; | |
707 | 25 | vps->rep_format.conf_win_right_offset = get_ue_golomb(gb) * horiz_mult; | |
708 | 25 | vps->rep_format.conf_win_top_offset = get_ue_golomb(gb) * vert_mult; | |
709 | 25 | vps->rep_format.conf_win_bottom_offset = get_ue_golomb(gb) * vert_mult; | |
710 | } | ||
711 | |||
712 | 25 | vps->max_one_active_ref_layer = get_bits1(gb); | |
713 | 25 | vps->poc_lsb_aligned = get_bits1(gb); | |
714 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 23 times.
|
25 | if (!vps->num_direct_ref_layers[1]) |
715 | 2 | vps->poc_lsb_not_present = get_bits1(gb) << 1; | |
716 | |||
717 | 25 | sub_layer_flag_info_present_flag = get_bits1(gb); | |
718 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 25 times.
|
50 | for (int j = 0; j < FFMAX(max_sub_layers[0], max_sub_layers[1]); j++) { |
719 | 25 | int sub_layer_dpb_info_present_flag = 1; | |
720 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
25 | if (j > 0 && sub_layer_flag_info_present_flag) |
721 | ✗ | sub_layer_dpb_info_present_flag = get_bits1(gb); | |
722 |
1/2✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
|
25 | if (sub_layer_dpb_info_present_flag) { |
723 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 25 times.
|
73 | for (int k = 0; k < av_popcount64(vps->ols[1]); k++) |
724 | 48 | vps->dpb_size.max_dec_pic_buffering = get_ue_golomb_long(gb) + 1; | |
725 | 25 | vps->dpb_size.max_num_reorder_pics = get_ue_golomb_long(gb); | |
726 | 25 | vps->dpb_size.max_latency_increase = get_ue_golomb_long(gb) - 1; | |
727 | } | ||
728 | } | ||
729 | |||
730 | 25 | direct_dep_type_len = get_ue_golomb_31(gb) + 2; | |
731 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (direct_dep_type_len > 32) { |
732 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid direct_dep_type_len: %d\n", | |
733 | direct_dep_type_len); | ||
734 | ✗ | return AVERROR_INVALIDDATA; | |
735 | } | ||
736 | |||
737 | /* direct_depenency_all_layers_flag */ | ||
738 |
2/2✓ Branch 1 taken 23 times.
✓ Branch 2 taken 2 times.
|
25 | if (get_bits1(gb)) { |
739 | 23 | direct_dep_type = get_bits_long(gb, direct_dep_type_len); | |
740 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (direct_dep_type > HEVC_DEP_TYPE_BOTH) { |
741 | ✗ | av_log(avctx, AV_LOG_WARNING, "Unsupported direct_dep_type: %d\n", | |
742 | direct_dep_type); | ||
743 | ✗ | return AVERROR_PATCHWELCOME; | |
744 | } | ||
745 | } | ||
746 | |||
747 | 25 | non_vui_extension_length = get_ue_golomb(gb); | |
748 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (non_vui_extension_length > 4096) { |
749 | ✗ | av_log(avctx, AV_LOG_ERROR, "vps_non_vui_extension_length too large: %u\n", | |
750 | non_vui_extension_length); | ||
751 | ✗ | return AVERROR_INVALIDDATA; | |
752 | } | ||
753 | 25 | skip_bits_long(gb, non_vui_extension_length * 8); | |
754 | |||
755 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
25 | if (get_bits1(gb)) // vps_vui_present_flag |
756 | ✗ | av_log(avctx, AV_LOG_WARNING, "VPS VUI not supported\n"); | |
757 | |||
758 | 25 | return 0; | |
759 | } | ||
760 | |||
761 | 1151 | int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, | |
762 | HEVCParamSets *ps) | ||
763 | { | ||
764 | int i; | ||
765 | 1151 | int vps_id = get_bits(gb, 4); | |
766 | 1151 | ptrdiff_t nal_size = gb->buffer_end - gb->buffer; | |
767 | 1151 | int ret = AVERROR_INVALIDDATA; | |
768 | 1151 | uint64_t layer1_id_included = 0; | |
769 | unsigned vps_base_layer_internal_flag, vps_base_layer_available_flag; | ||
770 | HEVCVPS *vps; | ||
771 | |||
772 |
2/2✓ Branch 0 taken 471 times.
✓ Branch 1 taken 680 times.
|
1151 | if (ps->vps_list[vps_id]) { |
773 | 471 | const HEVCVPS *vps1 = ps->vps_list[vps_id]; | |
774 |
2/2✓ Branch 0 taken 465 times.
✓ Branch 1 taken 6 times.
|
471 | if (vps1->data_size == nal_size && |
775 |
2/2✓ Branch 0 taken 462 times.
✓ Branch 1 taken 3 times.
|
465 | !memcmp(vps1->data, gb->buffer, vps1->data_size)) |
776 | 462 | return 0; | |
777 | } | ||
778 | |||
779 | 689 | vps = av_refstruct_alloc_ext(sizeof(*vps), 0, NULL, hevc_vps_free); | |
780 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 689 times.
|
689 | if (!vps) |
781 | ✗ | return AVERROR(ENOMEM); | |
782 | |||
783 | 689 | av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n"); | |
784 | |||
785 | 689 | vps->data_size = nal_size; | |
786 | 689 | vps->data = av_memdup(gb->buffer, nal_size); | |
787 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 689 times.
|
689 | if (!vps->data) { |
788 | ✗ | ret = AVERROR(ENOMEM); | |
789 | ✗ | goto err; | |
790 | } | ||
791 | 689 | vps->vps_id = vps_id; | |
792 | |||
793 | 689 | vps_base_layer_internal_flag = get_bits1(gb); | |
794 | 689 | vps_base_layer_available_flag = get_bits1(gb); | |
795 |
2/4✓ Branch 0 taken 689 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 689 times.
|
689 | if (!vps_base_layer_internal_flag || !vps_base_layer_available_flag) { |
796 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
797 | "vps_base_layer_internal_flag or vps_base_layer_available_flag not set\n"); | ||
798 | ✗ | ret = AVERROR_PATCHWELCOME; | |
799 | ✗ | goto err; | |
800 | } | ||
801 | |||
802 | 689 | vps->vps_max_layers = get_bits(gb, 6) + 1; | |
803 | 689 | vps->vps_max_sub_layers = get_bits(gb, 3) + 1; | |
804 | 689 | vps->vps_temporal_id_nesting_flag = get_bits1(gb); | |
805 | |||
806 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 689 times.
|
689 | if (get_bits(gb, 16) != 0xffff) { // vps_reserved_ffff_16bits |
807 | ✗ | av_log(avctx, AV_LOG_ERROR, "vps_reserved_ffff_16bits is not 0xffff\n"); | |
808 | ✗ | goto err; | |
809 | } | ||
810 | |||
811 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 689 times.
|
689 | if (vps->vps_max_sub_layers > HEVC_MAX_SUB_LAYERS) { |
812 | ✗ | av_log(avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n", | |
813 | ✗ | vps->vps_max_sub_layers); | |
814 | ✗ | goto err; | |
815 | } | ||
816 | |||
817 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 689 times.
|
689 | if (parse_ptl(gb, avctx, 1, &vps->ptl, vps->vps_max_sub_layers) < 0) |
818 | ✗ | goto err; | |
819 | |||
820 | 689 | vps->vps_sub_layer_ordering_info_present_flag = get_bits1(gb); | |
821 | |||
822 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 609 times.
|
689 | i = vps->vps_sub_layer_ordering_info_present_flag ? 0 : vps->vps_max_sub_layers - 1; |
823 |
2/2✓ Branch 0 taken 747 times.
✓ Branch 1 taken 689 times.
|
1436 | for (; i < vps->vps_max_sub_layers; i++) { |
824 | 747 | vps->vps_max_dec_pic_buffering[i] = get_ue_golomb_long(gb) + 1; | |
825 | 747 | vps->vps_num_reorder_pics[i] = get_ue_golomb_long(gb); | |
826 | 747 | vps->vps_max_latency_increase[i] = get_ue_golomb_long(gb) - 1; | |
827 | |||
828 |
2/4✓ Branch 0 taken 747 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 747 times.
|
747 | if (vps->vps_max_dec_pic_buffering[i] > HEVC_MAX_DPB_SIZE || !vps->vps_max_dec_pic_buffering[i]) { |
829 | ✗ | av_log(avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out of range: %d\n", | |
830 | ✗ | vps->vps_max_dec_pic_buffering[i] - 1); | |
831 | ✗ | goto err; | |
832 | } | ||
833 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
|
747 | if (vps->vps_num_reorder_pics[i] > vps->vps_max_dec_pic_buffering[i] - 1) { |
834 | ✗ | av_log(avctx, AV_LOG_WARNING, "vps_max_num_reorder_pics out of range: %d\n", | |
835 | ✗ | vps->vps_num_reorder_pics[i]); | |
836 | ✗ | if (avctx->err_recognition & AV_EF_EXPLODE) | |
837 | ✗ | goto err; | |
838 | } | ||
839 | } | ||
840 | |||
841 | 689 | vps->vps_max_layer_id = get_bits(gb, 6); | |
842 | 689 | vps->vps_num_layer_sets = get_ue_golomb_long(gb) + 1; | |
843 |
2/4✓ Branch 0 taken 689 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 689 times.
✗ Branch 3 not taken.
|
689 | if (vps->vps_num_layer_sets < 1 || vps->vps_num_layer_sets > 1024 || |
844 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 689 times.
|
689 | (vps->vps_num_layer_sets - 1LL) * (vps->vps_max_layer_id + 1LL) > get_bits_left(gb)) { |
845 | ✗ | av_log(avctx, AV_LOG_ERROR, "too many layer_id_included_flags\n"); | |
846 | ✗ | goto err; | |
847 | } | ||
848 | |||
849 | 689 | vps->num_output_layer_sets = 1; | |
850 | 689 | vps->ols[0] = 1; | |
851 | |||
852 | // we support at most 2 layers, so ignore the others | ||
853 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 666 times.
|
689 | if (vps->vps_num_layer_sets > 1) |
854 | 23 | layer1_id_included = get_bits64(gb, vps->vps_max_layer_id + 1); // layer_id_included_flag | |
855 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 689 times.
|
689 | if (vps->vps_num_layer_sets > 2) |
856 | ✗ | skip_bits_long(gb, (vps->vps_num_layer_sets - 2) * (vps->vps_max_layer_id + 1)); | |
857 | |||
858 | 689 | vps->vps_timing_info_present_flag = get_bits1(gb); | |
859 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 667 times.
|
689 | if (vps->vps_timing_info_present_flag) { |
860 | 22 | vps->vps_num_units_in_tick = get_bits_long(gb, 32); | |
861 | 22 | vps->vps_time_scale = get_bits_long(gb, 32); | |
862 | 22 | vps->vps_poc_proportional_to_timing_flag = get_bits1(gb); | |
863 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | if (vps->vps_poc_proportional_to_timing_flag) |
864 | 22 | vps->vps_num_ticks_poc_diff_one = get_ue_golomb_long(gb) + 1; | |
865 | 22 | vps->vps_num_hrd_parameters = get_ue_golomb_long(gb); | |
866 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | if (vps->vps_num_hrd_parameters > (unsigned)vps->vps_num_layer_sets) { |
867 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
868 | ✗ | "vps_num_hrd_parameters %d is invalid\n", vps->vps_num_hrd_parameters); | |
869 | ✗ | goto err; | |
870 | } | ||
871 | |||
872 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 19 times.
|
22 | if (vps->vps_num_hrd_parameters) { |
873 | 3 | vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); | |
874 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!vps->hdr) |
875 | ✗ | goto err; | |
876 | } | ||
877 | |||
878 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 22 times.
|
25 | for (i = 0; i < vps->vps_num_hrd_parameters; i++) { |
879 | 3 | int common_inf_present = 1; | |
880 | |||
881 | 3 | get_ue_golomb_long(gb); // hrd_layer_set_idx | |
882 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (i) |
883 | ✗ | common_inf_present = get_bits1(gb); | |
884 | 3 | decode_hrd(gb, common_inf_present, &vps->hdr[i], | |
885 | 3 | vps->vps_max_sub_layers); | |
886 | } | ||
887 | } | ||
888 | |||
889 | 689 | vps->nb_layers = 1; | |
890 | 689 | vps->layer_idx[0] = 0; | |
891 |
2/2✓ Branch 0 taken 42718 times.
✓ Branch 1 taken 689 times.
|
43407 | for (int i = 1; i < FF_ARRAY_ELEMS(vps->layer_idx); i++) |
892 | 42718 | vps->layer_idx[i] = -1; | |
893 | |||
894 |
3/4✓ Branch 0 taken 25 times.
✓ Branch 1 taken 664 times.
✓ Branch 3 taken 25 times.
✗ Branch 4 not taken.
|
689 | if (vps->vps_max_layers > 1 && get_bits1(gb)) { /* vps_extension_flag */ |
895 | 25 | int ret = decode_vps_ext(gb, avctx, vps, layer1_id_included); | |
896 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (ret == AVERROR_PATCHWELCOME) { |
897 | ✗ | vps->nb_layers = 1; | |
898 | ✗ | av_log(avctx, AV_LOG_WARNING, "Ignoring unsupported VPS extension\n"); | |
899 | ✗ | ret = 0; | |
900 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | } else if (ret < 0) |
901 | ✗ | goto err; | |
902 | } | ||
903 | |||
904 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 689 times.
|
689 | if (get_bits_left(gb) < 0) { |
905 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
906 | ✗ | "Overread VPS by %d bits\n", -get_bits_left(gb)); | |
907 | ✗ | if (ps->vps_list[vps_id]) | |
908 | ✗ | goto err; | |
909 | } | ||
910 | |||
911 | 689 | remove_vps(ps, vps_id); | |
912 | 689 | ps->vps_list[vps_id] = vps; | |
913 | |||
914 | 689 | return 0; | |
915 | |||
916 | ✗ | err: | |
917 | ✗ | av_refstruct_unref(&vps); | |
918 | ✗ | return ret; | |
919 | } | ||
920 | |||
921 | 308 | static void decode_vui(GetBitContext *gb, AVCodecContext *avctx, | |
922 | int apply_defdispwin, HEVCSPS *sps) | ||
923 | { | ||
924 | 308 | VUI backup_vui, *vui = &sps->vui; | |
925 | GetBitContext backup; | ||
926 | 308 | int alt = 0; | |
927 | |||
928 | 308 | ff_h2645_decode_common_vui_params(gb, &sps->vui.common, avctx); | |
929 | |||
930 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 228 times.
|
308 | if (vui->common.video_signal_type_present_flag) { |
931 |
4/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 68 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 5 times.
|
80 | if (vui->common.video_full_range_flag && sps->pix_fmt == AV_PIX_FMT_YUV420P) |
932 | 7 | sps->pix_fmt = AV_PIX_FMT_YUVJ420P; | |
933 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 12 times.
|
80 | if (vui->common.colour_description_present_flag) { |
934 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
|
68 | if (vui->common.matrix_coeffs == AVCOL_SPC_RGB) { |
935 | ✗ | switch (sps->pix_fmt) { | |
936 | ✗ | case AV_PIX_FMT_YUV444P: | |
937 | ✗ | sps->pix_fmt = AV_PIX_FMT_GBRP; | |
938 | ✗ | break; | |
939 | ✗ | case AV_PIX_FMT_YUV444P10: | |
940 | ✗ | sps->pix_fmt = AV_PIX_FMT_GBRP10; | |
941 | ✗ | break; | |
942 | ✗ | case AV_PIX_FMT_YUV444P12: | |
943 | ✗ | sps->pix_fmt = AV_PIX_FMT_GBRP12; | |
944 | ✗ | break; | |
945 | } | ||
946 | } | ||
947 | } | ||
948 | } | ||
949 | |||
950 | 308 | vui->neutra_chroma_indication_flag = get_bits1(gb); | |
951 | 308 | vui->field_seq_flag = get_bits1(gb); | |
952 | 308 | vui->frame_field_info_present_flag = get_bits1(gb); | |
953 | |||
954 | // Backup context in case an alternate header is detected | ||
955 | 308 | memcpy(&backup, gb, sizeof(backup)); | |
956 | 308 | memcpy(&backup_vui, vui, sizeof(backup_vui)); | |
957 |
3/4✓ Branch 1 taken 117 times.
✓ Branch 2 taken 191 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 117 times.
|
308 | if (get_bits_left(gb) >= 68 && show_bits(gb, 21) == 0x100000) { |
958 | ✗ | vui->default_display_window_flag = 0; | |
959 | ✗ | av_log(avctx, AV_LOG_WARNING, "Invalid default display window\n"); | |
960 | } else | ||
961 | 308 | vui->default_display_window_flag = get_bits1(gb); | |
962 | |||
963 |
2/2✓ Branch 0 taken 194 times.
✓ Branch 1 taken 114 times.
|
308 | if (vui->default_display_window_flag) { |
964 | 114 | int vert_mult = hevc_sub_height_c[sps->chroma_format_idc]; | |
965 | 114 | int horiz_mult = hevc_sub_width_c[sps->chroma_format_idc]; | |
966 | 114 | vui->def_disp_win.left_offset = get_ue_golomb_long(gb) * horiz_mult; | |
967 | 114 | vui->def_disp_win.right_offset = get_ue_golomb_long(gb) * horiz_mult; | |
968 | 114 | vui->def_disp_win.top_offset = get_ue_golomb_long(gb) * vert_mult; | |
969 | 114 | vui->def_disp_win.bottom_offset = get_ue_golomb_long(gb) * vert_mult; | |
970 | |||
971 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 54 times.
|
114 | if (apply_defdispwin && |
972 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | avctx->flags2 & AV_CODEC_FLAG2_IGNORE_CROP) { |
973 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
974 | "discarding vui default display window, " | ||
975 | "original values are l:%u r:%u t:%u b:%u\n", | ||
976 | vui->def_disp_win.left_offset, | ||
977 | vui->def_disp_win.right_offset, | ||
978 | vui->def_disp_win.top_offset, | ||
979 | vui->def_disp_win.bottom_offset); | ||
980 | |||
981 | ✗ | vui->def_disp_win.left_offset = | |
982 | ✗ | vui->def_disp_win.right_offset = | |
983 | ✗ | vui->def_disp_win.top_offset = | |
984 | ✗ | vui->def_disp_win.bottom_offset = 0; | |
985 | } | ||
986 | } | ||
987 | |||
988 | 308 | timing_info: | |
989 | 308 | vui->vui_timing_info_present_flag = get_bits1(gb); | |
990 | |||
991 |
2/2✓ Branch 0 taken 117 times.
✓ Branch 1 taken 191 times.
|
308 | if (vui->vui_timing_info_present_flag) { |
992 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
117 | if( get_bits_left(gb) < 66 && !alt) { |
993 | // The alternate syntax seem to have timing info located | ||
994 | // at where def_disp_win is normally located | ||
995 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
996 | "Strange VUI timing information, retrying...\n"); | ||
997 | ✗ | memcpy(vui, &backup_vui, sizeof(backup_vui)); | |
998 | ✗ | memcpy(gb, &backup, sizeof(backup)); | |
999 | ✗ | alt = 1; | |
1000 | ✗ | goto timing_info; | |
1001 | } | ||
1002 | 117 | vui->vui_num_units_in_tick = get_bits_long(gb, 32); | |
1003 | 117 | vui->vui_time_scale = get_bits_long(gb, 32); | |
1004 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
|
117 | if (alt) { |
1005 | ✗ | av_log(avctx, AV_LOG_INFO, "Retry got %"PRIu32"/%"PRIu32" fps\n", | |
1006 | vui->vui_time_scale, vui->vui_num_units_in_tick); | ||
1007 | } | ||
1008 | 117 | vui->vui_poc_proportional_to_timing_flag = get_bits1(gb); | |
1009 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 79 times.
|
117 | if (vui->vui_poc_proportional_to_timing_flag) |
1010 | 38 | vui->vui_num_ticks_poc_diff_one_minus1 = get_ue_golomb_long(gb); | |
1011 | 117 | vui->vui_hrd_parameters_present_flag = get_bits1(gb); | |
1012 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 62 times.
|
117 | if (vui->vui_hrd_parameters_present_flag) |
1013 | 55 | decode_hrd(gb, 1, &sps->hdr, sps->max_sub_layers); | |
1014 | } | ||
1015 | |||
1016 | 308 | vui->bitstream_restriction_flag = get_bits1(gb); | |
1017 |
2/2✓ Branch 0 taken 116 times.
✓ Branch 1 taken 192 times.
|
308 | if (vui->bitstream_restriction_flag) { |
1018 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
116 | if (get_bits_left(gb) < 8 && !alt) { |
1019 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1020 | "Strange VUI bitstream restriction information, retrying" | ||
1021 | " from timing information...\n"); | ||
1022 | ✗ | memcpy(vui, &backup_vui, sizeof(backup_vui)); | |
1023 | ✗ | memcpy(gb, &backup, sizeof(backup)); | |
1024 | ✗ | alt = 1; | |
1025 | ✗ | goto timing_info; | |
1026 | } | ||
1027 | 116 | vui->tiles_fixed_structure_flag = get_bits1(gb); | |
1028 | 116 | vui->motion_vectors_over_pic_boundaries_flag = get_bits1(gb); | |
1029 | 116 | vui->restricted_ref_pic_lists_flag = get_bits1(gb); | |
1030 | 116 | vui->min_spatial_segmentation_idc = get_ue_golomb_long(gb); | |
1031 | 116 | vui->max_bytes_per_pic_denom = get_ue_golomb_long(gb); | |
1032 | 116 | vui->max_bits_per_min_cu_denom = get_ue_golomb_long(gb); | |
1033 | 116 | vui->log2_max_mv_length_horizontal = get_ue_golomb_long(gb); | |
1034 | 116 | vui->log2_max_mv_length_vertical = get_ue_golomb_long(gb); | |
1035 | } | ||
1036 | |||
1037 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 308 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
308 | if (get_bits_left(gb) < 1 && !alt) { |
1038 | // XXX: Alternate syntax when sps_range_extension_flag != 0? | ||
1039 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1040 | "Overread in VUI, retrying from timing information...\n"); | ||
1041 | ✗ | memcpy(vui, &backup_vui, sizeof(backup_vui)); | |
1042 | ✗ | memcpy(gb, &backup, sizeof(backup)); | |
1043 | ✗ | alt = 1; | |
1044 | ✗ | goto timing_info; | |
1045 | } | ||
1046 | 308 | } | |
1047 | |||
1048 | 172 | static void set_default_scaling_list_data(ScalingList *sl) | |
1049 | { | ||
1050 | int matrixId; | ||
1051 | |||
1052 |
2/2✓ Branch 0 taken 1032 times.
✓ Branch 1 taken 172 times.
|
1204 | for (matrixId = 0; matrixId < 6; matrixId++) { |
1053 | // 4x4 default is 16 | ||
1054 | 1032 | memset(sl->sl[0][matrixId], 16, 16); | |
1055 | 1032 | sl->sl_dc[0][matrixId] = 16; // default for 16x16 | |
1056 | 1032 | sl->sl_dc[1][matrixId] = 16; // default for 32x32 | |
1057 | } | ||
1058 | 172 | memcpy(sl->sl[1][0], default_scaling_list_intra, 64); | |
1059 | 172 | memcpy(sl->sl[1][1], default_scaling_list_intra, 64); | |
1060 | 172 | memcpy(sl->sl[1][2], default_scaling_list_intra, 64); | |
1061 | 172 | memcpy(sl->sl[1][3], default_scaling_list_inter, 64); | |
1062 | 172 | memcpy(sl->sl[1][4], default_scaling_list_inter, 64); | |
1063 | 172 | memcpy(sl->sl[1][5], default_scaling_list_inter, 64); | |
1064 | 172 | memcpy(sl->sl[2][0], default_scaling_list_intra, 64); | |
1065 | 172 | memcpy(sl->sl[2][1], default_scaling_list_intra, 64); | |
1066 | 172 | memcpy(sl->sl[2][2], default_scaling_list_intra, 64); | |
1067 | 172 | memcpy(sl->sl[2][3], default_scaling_list_inter, 64); | |
1068 | 172 | memcpy(sl->sl[2][4], default_scaling_list_inter, 64); | |
1069 | 172 | memcpy(sl->sl[2][5], default_scaling_list_inter, 64); | |
1070 | 172 | memcpy(sl->sl[3][0], default_scaling_list_intra, 64); | |
1071 | 172 | memcpy(sl->sl[3][1], default_scaling_list_intra, 64); | |
1072 | 172 | memcpy(sl->sl[3][2], default_scaling_list_intra, 64); | |
1073 | 172 | memcpy(sl->sl[3][3], default_scaling_list_inter, 64); | |
1074 | 172 | memcpy(sl->sl[3][4], default_scaling_list_inter, 64); | |
1075 | 172 | memcpy(sl->sl[3][5], default_scaling_list_inter, 64); | |
1076 | 172 | } | |
1077 | |||
1078 | 141 | static int scaling_list_data(GetBitContext *gb, AVCodecContext *avctx, | |
1079 | ScalingList *sl, const HEVCSPS *sps) | ||
1080 | { | ||
1081 | uint8_t scaling_list_pred_mode_flag; | ||
1082 | uint8_t scaling_list_dc_coef[2][6]; | ||
1083 | int size_id, matrix_id, pos; | ||
1084 | int i; | ||
1085 | |||
1086 |
2/2✓ Branch 0 taken 564 times.
✓ Branch 1 taken 141 times.
|
705 | for (size_id = 0; size_id < 4; size_id++) |
1087 |
4/4✓ Branch 0 taken 282 times.
✓ Branch 1 taken 2538 times.
✓ Branch 2 taken 2820 times.
✓ Branch 3 taken 564 times.
|
3384 | for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) { |
1088 | 2820 | scaling_list_pred_mode_flag = get_bits1(gb); | |
1089 |
2/2✓ Branch 0 taken 759 times.
✓ Branch 1 taken 2061 times.
|
2820 | if (!scaling_list_pred_mode_flag) { |
1090 | 759 | unsigned int delta = get_ue_golomb_long(gb); | |
1091 | /* Only need to handle non-zero delta. Zero means default, | ||
1092 | * which should already be in the arrays. */ | ||
1093 |
2/2✓ Branch 0 taken 633 times.
✓ Branch 1 taken 126 times.
|
759 | if (delta) { |
1094 | // Copy from previous array. | ||
1095 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 633 times.
|
633 | delta *= (size_id == 3) ? 3 : 1; |
1096 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 633 times.
|
633 | if (matrix_id < delta) { |
1097 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1098 | "Invalid delta in scaling list data: %d.\n", delta); | ||
1099 | ✗ | return AVERROR_INVALIDDATA; | |
1100 | } | ||
1101 | |||
1102 |
2/2✓ Branch 0 taken 400 times.
✓ Branch 1 taken 233 times.
|
633 | memcpy(sl->sl[size_id][matrix_id], |
1103 | 633 | sl->sl[size_id][matrix_id - delta], | |
1104 | size_id > 0 ? 64 : 16); | ||
1105 |
2/2✓ Branch 0 taken 127 times.
✓ Branch 1 taken 506 times.
|
633 | if (size_id > 1) |
1106 | 127 | sl->sl_dc[size_id - 2][matrix_id] = sl->sl_dc[size_id - 2][matrix_id - delta]; | |
1107 | } | ||
1108 | } else { | ||
1109 | int next_coef, coef_num; | ||
1110 | int32_t scaling_list_delta_coef; | ||
1111 | |||
1112 | 2061 | next_coef = 8; | |
1113 | 2061 | coef_num = FFMIN(64, 1 << (4 + (size_id << 1))); | |
1114 |
2/2✓ Branch 0 taken 959 times.
✓ Branch 1 taken 1102 times.
|
2061 | if (size_id > 1) { |
1115 | 959 | int scaling_list_coeff_minus8 = get_se_golomb(gb); | |
1116 |
2/4✓ Branch 0 taken 959 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 959 times.
|
959 | if (scaling_list_coeff_minus8 < -7 || |
1117 | scaling_list_coeff_minus8 > 247) | ||
1118 | ✗ | return AVERROR_INVALIDDATA; | |
1119 | 959 | scaling_list_dc_coef[size_id - 2][matrix_id] = scaling_list_coeff_minus8 + 8; | |
1120 | 959 | next_coef = scaling_list_dc_coef[size_id - 2][matrix_id]; | |
1121 | 959 | sl->sl_dc[size_id - 2][matrix_id] = next_coef; | |
1122 | } | ||
1123 |
2/2✓ Branch 0 taken 103488 times.
✓ Branch 1 taken 2061 times.
|
105549 | for (i = 0; i < coef_num; i++) { |
1124 |
2/2✓ Branch 0 taken 9472 times.
✓ Branch 1 taken 94016 times.
|
103488 | if (size_id == 0) |
1125 | 9472 | pos = 4 * ff_hevc_diag_scan4x4_y[i] + | |
1126 | 9472 | ff_hevc_diag_scan4x4_x[i]; | |
1127 | else | ||
1128 | 94016 | pos = 8 * ff_hevc_diag_scan8x8_y[i] + | |
1129 | 94016 | ff_hevc_diag_scan8x8_x[i]; | |
1130 | |||
1131 | 103488 | scaling_list_delta_coef = get_se_golomb(gb); | |
1132 | 103488 | next_coef = (next_coef + 256U + scaling_list_delta_coef) % 256; | |
1133 | 103488 | sl->sl[size_id][matrix_id][pos] = next_coef; | |
1134 | } | ||
1135 | } | ||
1136 | } | ||
1137 | |||
1138 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 98 times.
|
141 | if (sps->chroma_format_idc == 3) { |
1139 |
2/2✓ Branch 0 taken 2752 times.
✓ Branch 1 taken 43 times.
|
2795 | for (i = 0; i < 64; i++) { |
1140 | 2752 | sl->sl[3][1][i] = sl->sl[2][1][i]; | |
1141 | 2752 | sl->sl[3][2][i] = sl->sl[2][2][i]; | |
1142 | 2752 | sl->sl[3][4][i] = sl->sl[2][4][i]; | |
1143 | 2752 | sl->sl[3][5][i] = sl->sl[2][5][i]; | |
1144 | } | ||
1145 | 43 | sl->sl_dc[1][1] = sl->sl_dc[0][1]; | |
1146 | 43 | sl->sl_dc[1][2] = sl->sl_dc[0][2]; | |
1147 | 43 | sl->sl_dc[1][4] = sl->sl_dc[0][4]; | |
1148 | 43 | sl->sl_dc[1][5] = sl->sl_dc[0][5]; | |
1149 | } | ||
1150 | |||
1151 | |||
1152 | 141 | return 0; | |
1153 | } | ||
1154 | |||
1155 | 1172 | static int map_pixel_format(AVCodecContext *avctx, HEVCSPS *sps) | |
1156 | { | ||
1157 | const AVPixFmtDescriptor *desc; | ||
1158 |
3/5✓ Branch 0 taken 1012 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 137 times.
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
|
1172 | switch (sps->bit_depth) { |
1159 | 1012 | case 8: | |
1160 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1008 times.
|
1012 | if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8; |
1161 |
2/2✓ Branch 0 taken 999 times.
✓ Branch 1 taken 13 times.
|
1012 | if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P; |
1162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1012 times.
|
1012 | if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P; |
1163 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1003 times.
|
1012 | if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P; |
1164 | 1012 | break; | |
1165 | ✗ | case 9: | |
1166 | ✗ | if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY9; | |
1167 | ✗ | if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P9; | |
1168 | ✗ | if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P9; | |
1169 | ✗ | if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P9; | |
1170 | ✗ | break; | |
1171 | 137 | case 10: | |
1172 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 137 times.
|
137 | if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY10; |
1173 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 29 times.
|
137 | if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10; |
1174 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 108 times.
|
137 | if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10; |
1175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 137 times.
|
137 | if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10; |
1176 | 137 | break; | |
1177 | 23 | case 12: | |
1178 |
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; |
1179 |
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; |
1180 |
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; |
1181 |
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; |
1182 | 23 | break; | |
1183 | ✗ | default: | |
1184 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1185 | "The following bit-depths are currently specified: 8, 9, 10 and 12 bits, " | ||
1186 | "chroma_format_idc is %d, depth is %d\n", | ||
1187 | sps->chroma_format_idc, sps->bit_depth); | ||
1188 | ✗ | return AVERROR_INVALIDDATA; | |
1189 | } | ||
1190 | |||
1191 | 1172 | desc = av_pix_fmt_desc_get(sps->pix_fmt); | |
1192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (!desc) |
1193 | ✗ | return AVERROR(EINVAL); | |
1194 | |||
1195 | 1172 | sps->hshift[0] = sps->vshift[0] = 0; | |
1196 | 1172 | sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w; | |
1197 | 1172 | sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h; | |
1198 | |||
1199 | 1172 | sps->pixel_shift = sps->bit_depth > 8; | |
1200 | |||
1201 | 1172 | return 0; | |
1202 | } | ||
1203 | |||
1204 | 1172 | int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, | |
1205 | unsigned nuh_layer_id, int apply_defdispwin, | ||
1206 | const HEVCVPS * const *vps_list, AVCodecContext *avctx) | ||
1207 | { | ||
1208 | HEVCWindow *ow; | ||
1209 | 1172 | int ret = 0; | |
1210 | int bit_depth_chroma, num_comps, multi_layer_ext; | ||
1211 | int vps_max_sub_layers; | ||
1212 | int i; | ||
1213 | |||
1214 | // Coded parameters | ||
1215 | |||
1216 | 1172 | sps->vps_id = get_bits(gb, 4); | |
1217 | |||
1218 |
1/2✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
|
1172 | if (vps_list) { |
1219 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (!vps_list[sps->vps_id]) { |
1220 | ✗ | av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n", | |
1221 | sps->vps_id); | ||
1222 | ✗ | return AVERROR_INVALIDDATA; | |
1223 | } | ||
1224 | 1172 | sps->vps = av_refstruct_ref_c(vps_list[sps->vps_id]); | |
1225 | } | ||
1226 | |||
1227 | 1172 | sps->max_sub_layers = get_bits(gb, 3) + 1; | |
1228 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 1144 times.
|
1200 | multi_layer_ext = nuh_layer_id > 0 && |
1229 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2 times.
|
28 | sps->max_sub_layers == HEVC_MAX_SUB_LAYERS + 1; |
1230 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 1146 times.
|
1172 | if (multi_layer_ext) { |
1231 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!sps->vps) |
1232 | ✗ | return AVERROR(EINVAL); | |
1233 | |||
1234 | 26 | sps->max_sub_layers = sps->vps->vps_max_sub_layers; | |
1235 | } | ||
1236 | 3516 | vps_max_sub_layers = sps->vps ? sps->vps->vps_max_sub_layers | |
1237 |
1/2✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
|
1172 | : FFMIN(sps->max_sub_layers, HEVC_MAX_SUB_LAYERS); |
1238 | |||
1239 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->max_sub_layers > vps_max_sub_layers) { |
1240 | ✗ | av_log(avctx, AV_LOG_ERROR, "sps_max_sub_layers out of range: %d\n", | |
1241 | sps->max_sub_layers); | ||
1242 | ✗ | return AVERROR_INVALIDDATA; | |
1243 | } | ||
1244 | |||
1245 |
2/2✓ Branch 0 taken 1146 times.
✓ Branch 1 taken 26 times.
|
1172 | if (!multi_layer_ext) { |
1246 | 1146 | sps->temporal_id_nesting = get_bits(gb, 1); | |
1247 | |||
1248 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1146 times.
|
1146 | if ((ret = parse_ptl(gb, avctx, 1, &sps->ptl, sps->max_sub_layers)) < 0) |
1249 | ✗ | return ret; | |
1250 | } else { | ||
1251 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | sps->temporal_id_nesting = sps->max_sub_layers > 1 ? |
1252 | ✗ | sps->vps->vps_max_sub_layers : 1; | |
1253 | } | ||
1254 | |||
1255 | 1172 | *sps_id = get_ue_golomb_long(gb); | |
1256 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (*sps_id >= HEVC_MAX_SPS_COUNT) { |
1257 | ✗ | av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", *sps_id); | |
1258 | ✗ | return AVERROR_INVALIDDATA; | |
1259 | } | ||
1260 | |||
1261 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 1146 times.
|
1172 | if (multi_layer_ext) { |
1262 | 26 | const RepFormat *rf = &sps->vps->rep_format; | |
1263 | |||
1264 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (sps->vps->nb_layers == 1) { |
1265 | ✗ | av_log(avctx, AV_LOG_WARNING, "SPS %d references an unsupported VPS extension. Ignoring\n", | |
1266 | *sps_id); | ||
1267 | ✗ | return AVERROR(ENOSYS); | |
1268 | } | ||
1269 | |||
1270 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
26 | if (get_bits1(gb) && // update_rep_format_flag |
1271 | ✗ | get_bits(gb, 8)) { // sps_rep_format_idx | |
1272 | ✗ | av_log(avctx, AV_LOG_ERROR, "sps_rep_format_idx!=0\n"); | |
1273 | ✗ | return AVERROR_PATCHWELCOME; | |
1274 | } | ||
1275 | |||
1276 | 26 | sps->separate_colour_plane = rf->separate_colour_plane_flag; | |
1277 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | sps->chroma_format_idc = sps->separate_colour_plane ? 0 : |
1278 | 26 | rf->chroma_format_idc; | |
1279 | 26 | sps->bit_depth = rf->bit_depth_luma; | |
1280 | 26 | sps->width = rf->pic_width_in_luma_samples; | |
1281 | 26 | sps->height = rf->pic_height_in_luma_samples; | |
1282 | |||
1283 | 26 | sps->pic_conf_win.left_offset = rf->conf_win_left_offset; | |
1284 | 26 | sps->pic_conf_win.right_offset = rf->conf_win_right_offset; | |
1285 | 26 | sps->pic_conf_win.top_offset = rf->conf_win_top_offset; | |
1286 | 26 | sps->pic_conf_win.bottom_offset = rf->conf_win_bottom_offset; | |
1287 | |||
1288 | } else { | ||
1289 | 1146 | sps->chroma_format_idc = get_ue_golomb_long(gb); | |
1290 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1146 times.
|
1146 | if (sps->chroma_format_idc > 3U) { |
1291 | ✗ | av_log(avctx, AV_LOG_ERROR, "chroma_format_idc %d is invalid\n", sps->chroma_format_idc); | |
1292 | ✗ | return AVERROR_INVALIDDATA; | |
1293 | } | ||
1294 | |||
1295 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1114 times.
|
1146 | if (sps->chroma_format_idc == 3) |
1296 | 32 | sps->separate_colour_plane = get_bits1(gb); | |
1297 | |||
1298 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1146 times.
|
1146 | if (sps->separate_colour_plane) |
1299 | ✗ | sps->chroma_format_idc = 0; | |
1300 | |||
1301 | 1146 | sps->width = get_ue_golomb_long(gb); | |
1302 | 1146 | sps->height = get_ue_golomb_long(gb); | |
1303 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1146 times.
|
1146 | if ((ret = av_image_check_size(sps->width, |
1304 | 1146 | sps->height, 0, avctx)) < 0) | |
1305 | ✗ | return ret; | |
1306 | |||
1307 | 1146 | sps->conformance_window = get_bits1(gb); | |
1308 |
2/2✓ Branch 0 taken 943 times.
✓ Branch 1 taken 203 times.
|
1146 | if (sps->conformance_window) { |
1309 | 943 | int vert_mult = hevc_sub_height_c[sps->chroma_format_idc]; | |
1310 | 943 | int horiz_mult = hevc_sub_width_c[sps->chroma_format_idc]; | |
1311 | 943 | sps->pic_conf_win.left_offset = get_ue_golomb_long(gb) * horiz_mult; | |
1312 | 943 | sps->pic_conf_win.right_offset = get_ue_golomb_long(gb) * horiz_mult; | |
1313 | 943 | sps->pic_conf_win.top_offset = get_ue_golomb_long(gb) * vert_mult; | |
1314 | 943 | sps->pic_conf_win.bottom_offset = get_ue_golomb_long(gb) * vert_mult; | |
1315 | |||
1316 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 943 times.
|
943 | if (avctx->flags2 & AV_CODEC_FLAG2_IGNORE_CROP) { |
1317 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
1318 | "discarding sps conformance window, " | ||
1319 | "original values are l:%u r:%u t:%u b:%u\n", | ||
1320 | sps->pic_conf_win.left_offset, | ||
1321 | sps->pic_conf_win.right_offset, | ||
1322 | sps->pic_conf_win.top_offset, | ||
1323 | sps->pic_conf_win.bottom_offset); | ||
1324 | |||
1325 | ✗ | sps->pic_conf_win.left_offset = | |
1326 | ✗ | sps->pic_conf_win.right_offset = | |
1327 | ✗ | sps->pic_conf_win.top_offset = | |
1328 | ✗ | sps->pic_conf_win.bottom_offset = 0; | |
1329 | } | ||
1330 | } | ||
1331 | |||
1332 | 1146 | sps->bit_depth = get_ue_golomb_31(gb) + 8; | |
1333 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1146 times.
|
1146 | if (sps->bit_depth > 16) { |
1334 | ✗ | av_log(avctx, AV_LOG_ERROR, "Luma bit depth (%d) is out of range\n", | |
1335 | sps->bit_depth); | ||
1336 | ✗ | return AVERROR_INVALIDDATA; | |
1337 | } | ||
1338 | 1146 | bit_depth_chroma = get_ue_golomb_31(gb) + 8; | |
1339 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1146 times.
|
1146 | if (bit_depth_chroma > 16) { |
1340 | ✗ | av_log(avctx, AV_LOG_ERROR, "Chroma bit depth (%d) is out of range\n", | |
1341 | bit_depth_chroma); | ||
1342 | ✗ | return AVERROR_INVALIDDATA; | |
1343 | } | ||
1344 |
3/4✓ Branch 0 taken 1142 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1142 times.
|
1146 | if (sps->chroma_format_idc && bit_depth_chroma != sps->bit_depth) { |
1345 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1346 | "Luma bit depth (%d) is different from chroma bit depth (%d), " | ||
1347 | "this is unsupported.\n", | ||
1348 | sps->bit_depth, bit_depth_chroma); | ||
1349 | ✗ | return AVERROR_INVALIDDATA; | |
1350 | } | ||
1351 | 1146 | sps->bit_depth_chroma = bit_depth_chroma; | |
1352 | } | ||
1353 | |||
1354 | 1172 | sps->output_window = sps->pic_conf_win; | |
1355 | |||
1356 | 1172 | ret = map_pixel_format(avctx, sps); | |
1357 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (ret < 0) |
1358 | ✗ | return ret; | |
1359 | |||
1360 | 1172 | sps->log2_max_poc_lsb = get_ue_golomb_long(gb) + 4; | |
1361 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->log2_max_poc_lsb > 16) { |
1362 | ✗ | av_log(avctx, AV_LOG_ERROR, "log2_max_pic_order_cnt_lsb_minus4 out range: %d\n", | |
1363 | ✗ | sps->log2_max_poc_lsb - 4); | |
1364 | ✗ | return AVERROR_INVALIDDATA; | |
1365 | } | ||
1366 | |||
1367 |
2/2✓ Branch 0 taken 1146 times.
✓ Branch 1 taken 26 times.
|
1172 | if (!multi_layer_ext) { |
1368 | int start; | ||
1369 | |||
1370 | 1146 | sps->sublayer_ordering_info = get_bits1(gb); | |
1371 |
2/2✓ Branch 0 taken 158 times.
✓ Branch 1 taken 988 times.
|
1146 | start = sps->sublayer_ordering_info ? 0 : sps->max_sub_layers - 1; |
1372 |
2/2✓ Branch 0 taken 1293 times.
✓ Branch 1 taken 1146 times.
|
2439 | for (i = start; i < sps->max_sub_layers; i++) { |
1373 | 1293 | sps->temporal_layer[i].max_dec_pic_buffering = get_ue_golomb_long(gb) + 1; | |
1374 | 1293 | sps->temporal_layer[i].num_reorder_pics = get_ue_golomb_long(gb); | |
1375 | 1293 | sps->temporal_layer[i].max_latency_increase = get_ue_golomb_long(gb) - 1; | |
1376 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1293 times.
|
1293 | if (sps->temporal_layer[i].max_dec_pic_buffering > (unsigned)HEVC_MAX_DPB_SIZE) { |
1377 | ✗ | av_log(avctx, AV_LOG_ERROR, "sps_max_dec_pic_buffering_minus1 out of range: %d\n", | |
1378 | ✗ | sps->temporal_layer[i].max_dec_pic_buffering - 1U); | |
1379 | ✗ | return AVERROR_INVALIDDATA; | |
1380 | } | ||
1381 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1293 times.
|
1293 | if (sps->temporal_layer[i].num_reorder_pics > sps->temporal_layer[i].max_dec_pic_buffering - 1) { |
1382 | ✗ | av_log(avctx, AV_LOG_WARNING, "sps_max_num_reorder_pics out of range: %d\n", | |
1383 | sps->temporal_layer[i].num_reorder_pics); | ||
1384 | ✗ | if (avctx->err_recognition & AV_EF_EXPLODE || | |
1385 | ✗ | sps->temporal_layer[i].num_reorder_pics > HEVC_MAX_DPB_SIZE - 1) { | |
1386 | ✗ | return AVERROR_INVALIDDATA; | |
1387 | } | ||
1388 | ✗ | sps->temporal_layer[i].max_dec_pic_buffering = sps->temporal_layer[i].num_reorder_pics + 1; | |
1389 | } | ||
1390 | } | ||
1391 | |||
1392 |
2/2✓ Branch 0 taken 158 times.
✓ Branch 1 taken 988 times.
|
1146 | if (!sps->sublayer_ordering_info) { |
1393 |
2/2✓ Branch 0 taken 82 times.
✓ Branch 1 taken 158 times.
|
240 | for (i = 0; i < start; i++) { |
1394 | 82 | sps->temporal_layer[i].max_dec_pic_buffering = sps->temporal_layer[start].max_dec_pic_buffering; | |
1395 | 82 | sps->temporal_layer[i].num_reorder_pics = sps->temporal_layer[start].num_reorder_pics; | |
1396 | 82 | sps->temporal_layer[i].max_latency_increase = sps->temporal_layer[start].max_latency_increase; | |
1397 | } | ||
1398 | } | ||
1399 | } else { | ||
1400 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 26 times.
|
52 | for (int i = 0; i < sps->max_sub_layers; i++) { |
1401 | 26 | sps->temporal_layer[i].max_dec_pic_buffering = sps->vps->dpb_size.max_dec_pic_buffering; | |
1402 | 26 | sps->temporal_layer[i].num_reorder_pics = sps->vps->dpb_size.max_num_reorder_pics; | |
1403 | 26 | sps->temporal_layer[i].max_latency_increase = sps->vps->dpb_size.max_latency_increase; | |
1404 | } | ||
1405 | } | ||
1406 | |||
1407 | 1172 | sps->log2_min_cb_size = get_ue_golomb_long(gb) + 3; | |
1408 | 1172 | sps->log2_diff_max_min_coding_block_size = get_ue_golomb_long(gb); | |
1409 | 1172 | sps->log2_min_tb_size = get_ue_golomb_long(gb) + 2; | |
1410 | 1172 | sps->log2_diff_max_min_transform_block_size = get_ue_golomb_long(gb); | |
1411 | 1172 | sps->log2_max_trafo_size = sps->log2_diff_max_min_transform_block_size + | |
1412 | 1172 | sps->log2_min_tb_size; | |
1413 | |||
1414 |
2/4✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1172 times.
|
1172 | if (sps->log2_min_cb_size < 3 || sps->log2_min_cb_size > 30) { |
1415 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_min_cb_size", sps->log2_min_cb_size); | |
1416 | ✗ | return AVERROR_INVALIDDATA; | |
1417 | } | ||
1418 | |||
1419 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->log2_diff_max_min_coding_block_size > 30) { |
1420 | ✗ | 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); | |
1421 | ✗ | return AVERROR_INVALIDDATA; | |
1422 | } | ||
1423 | |||
1424 |
2/4✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1172 times.
|
1172 | if (sps->log2_min_tb_size >= sps->log2_min_cb_size || sps->log2_min_tb_size < 2) { |
1425 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid value for log2_min_tb_size"); | |
1426 | ✗ | return AVERROR_INVALIDDATA; | |
1427 | } | ||
1428 | |||
1429 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->log2_diff_max_min_transform_block_size > 30) { |
1430 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_transform_block_size", | |
1431 | sps->log2_diff_max_min_transform_block_size); | ||
1432 | ✗ | return AVERROR_INVALIDDATA; | |
1433 | } | ||
1434 | |||
1435 | 1172 | sps->max_transform_hierarchy_depth_inter = get_ue_golomb_long(gb); | |
1436 | 1172 | sps->max_transform_hierarchy_depth_intra = get_ue_golomb_long(gb); | |
1437 | |||
1438 | 1172 | sps->scaling_list_enabled = get_bits1(gb); | |
1439 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 1115 times.
|
1172 | if (sps->scaling_list_enabled) { |
1440 | 57 | set_default_scaling_list_data(&sps->scaling_list); | |
1441 | |||
1442 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 53 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
|
57 | if (multi_layer_ext && get_bits1(gb)) { // sps_infer_scaling_list_flag |
1443 | ✗ | av_log(avctx, AV_LOG_ERROR, "sps_infer_scaling_list_flag=1 not supported\n"); | |
1444 | ✗ | return AVERROR_PATCHWELCOME; | |
1445 | } | ||
1446 | |||
1447 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 2 taken 31 times.
|
57 | if (get_bits1(gb)) { |
1448 | 26 | ret = scaling_list_data(gb, avctx, &sps->scaling_list, sps); | |
1449 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (ret < 0) |
1450 | ✗ | return ret; | |
1451 | } | ||
1452 | } | ||
1453 | |||
1454 | 1172 | sps->amp_enabled = get_bits1(gb); | |
1455 | 1172 | sps->sao_enabled = get_bits1(gb); | |
1456 | |||
1457 | 1172 | sps->pcm_enabled = get_bits1(gb); | |
1458 |
2/2✓ Branch 0 taken 75 times.
✓ Branch 1 taken 1097 times.
|
1172 | if (sps->pcm_enabled) { |
1459 | 75 | sps->pcm.bit_depth = get_bits(gb, 4) + 1; | |
1460 | 75 | sps->pcm.bit_depth_chroma = get_bits(gb, 4) + 1; | |
1461 | 75 | sps->pcm.log2_min_pcm_cb_size = get_ue_golomb_long(gb) + 3; | |
1462 | 150 | sps->pcm.log2_max_pcm_cb_size = sps->pcm.log2_min_pcm_cb_size + | |
1463 | 75 | get_ue_golomb_long(gb); | |
1464 |
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) { |
1465 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1466 | "PCM bit depth (%d, %d) is greater than normal bit depth (%d)\n", | ||
1467 | ✗ | sps->pcm.bit_depth, sps->pcm.bit_depth_chroma, sps->bit_depth); | |
1468 | ✗ | return AVERROR_INVALIDDATA; | |
1469 | } | ||
1470 | |||
1471 | 75 | sps->pcm_loop_filter_disabled = get_bits1(gb); | |
1472 | } | ||
1473 | |||
1474 | 1172 | sps->nb_st_rps = get_ue_golomb_long(gb); | |
1475 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_REF_PIC_SETS) { |
1476 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n", | |
1477 | sps->nb_st_rps); | ||
1478 | ✗ | return AVERROR_INVALIDDATA; | |
1479 | } | ||
1480 |
2/2✓ Branch 0 taken 10000 times.
✓ Branch 1 taken 1172 times.
|
11172 | for (i = 0; i < sps->nb_st_rps; i++) { |
1481 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10000 times.
|
10000 | if ((ret = ff_hevc_decode_short_term_rps(gb, avctx, &sps->st_rps[i], |
1482 | sps, 0)) < 0) | ||
1483 | ✗ | return ret; | |
1484 | } | ||
1485 | |||
1486 | 1172 | sps->long_term_ref_pics_present = get_bits1(gb); | |
1487 |
2/2✓ Branch 0 taken 101 times.
✓ Branch 1 taken 1071 times.
|
1172 | if (sps->long_term_ref_pics_present) { |
1488 | 101 | sps->num_long_term_ref_pics_sps = get_ue_golomb_long(gb); | |
1489 |
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) { |
1490 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many long term ref pics: %d.\n", | |
1491 | ✗ | sps->num_long_term_ref_pics_sps); | |
1492 | ✗ | return AVERROR_INVALIDDATA; | |
1493 | } | ||
1494 | |||
1495 | 101 | sps->used_by_curr_pic_lt = 0; | |
1496 |
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++) { |
1497 | 64 | sps->lt_ref_pic_poc_lsb_sps[i] = get_bits(gb, sps->log2_max_poc_lsb); | |
1498 | 64 | sps->used_by_curr_pic_lt |= get_bits1(gb) << i; | |
1499 | } | ||
1500 | } | ||
1501 | |||
1502 | 1172 | sps->temporal_mvp_enabled = get_bits1(gb); | |
1503 | 1172 | sps->strong_intra_smoothing_enabled = get_bits1(gb); | |
1504 | 1172 | sps->vui.common.sar = (AVRational){0, 1}; | |
1505 | 1172 | sps->vui_present = get_bits1(gb); | |
1506 |
2/2✓ Branch 0 taken 308 times.
✓ Branch 1 taken 864 times.
|
1172 | if (sps->vui_present) |
1507 | 308 | decode_vui(gb, avctx, apply_defdispwin, sps); | |
1508 | |||
1509 | 1172 | sps->extension_present = get_bits1(gb); | |
1510 |
2/2✓ Branch 0 taken 131 times.
✓ Branch 1 taken 1041 times.
|
1172 | if (sps->extension_present) { |
1511 | 131 | sps->range_extension = get_bits1(gb); | |
1512 | 131 | sps->multilayer_extension = get_bits1(gb); | |
1513 | 131 | sps->sps_3d_extension = get_bits1(gb); | |
1514 | 131 | sps->scc_extension = get_bits1(gb); | |
1515 | 131 | skip_bits(gb, 4); // sps_extension_4bits | |
1516 | |||
1517 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 75 times.
|
131 | if (sps->range_extension) { |
1518 | 56 | sps->transform_skip_rotation_enabled = get_bits1(gb); | |
1519 | 56 | sps->transform_skip_context_enabled = get_bits1(gb); | |
1520 | 56 | sps->implicit_rdpcm_enabled = get_bits1(gb); | |
1521 | 56 | sps->explicit_rdpcm_enabled = get_bits1(gb); | |
1522 | |||
1523 | 56 | sps->extended_precision_processing = get_bits1(gb); | |
1524 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (sps->extended_precision_processing) |
1525 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1526 | "extended_precision_processing_flag not yet implemented\n"); | ||
1527 | |||
1528 | 56 | sps->intra_smoothing_disabled = get_bits1(gb); | |
1529 | 56 | sps->high_precision_offsets_enabled = get_bits1(gb); | |
1530 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 18 times.
|
56 | if (sps->high_precision_offsets_enabled) |
1531 | 38 | av_log(avctx, AV_LOG_WARNING, | |
1532 | "high_precision_offsets_enabled_flag not yet implemented\n"); | ||
1533 | |||
1534 | 56 | sps->persistent_rice_adaptation_enabled = get_bits1(gb); | |
1535 | |||
1536 | 56 | sps->cabac_bypass_alignment_enabled = get_bits1(gb); | |
1537 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (sps->cabac_bypass_alignment_enabled) |
1538 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1539 | "cabac_bypass_alignment_enabled_flag not yet implemented\n"); | ||
1540 | } | ||
1541 | |||
1542 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 76 times.
|
131 | if (sps->multilayer_extension) { |
1543 | 55 | skip_bits1(gb); // inter_view_mv_vert_constraint_flag | |
1544 | } | ||
1545 | |||
1546 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 131 times.
|
131 | if (sps->sps_3d_extension) { |
1547 | ✗ | for (i = 0; i <= 1; i++) { | |
1548 | ✗ | skip_bits1(gb); // iv_di_mc_enabled_flag | |
1549 | ✗ | skip_bits1(gb); // iv_mv_scal_enabled_flag | |
1550 | ✗ | if (i == 0) { | |
1551 | ✗ | get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3 | |
1552 | ✗ | skip_bits1(gb); // iv_res_pred_enabled_flag | |
1553 | ✗ | skip_bits1(gb); // depth_ref_enabled_flag | |
1554 | ✗ | skip_bits1(gb); // vsp_mc_enabled_flag | |
1555 | ✗ | skip_bits1(gb); // dbbp_enabled_flag | |
1556 | } else { | ||
1557 | ✗ | skip_bits1(gb); // tex_mc_enabled_flag | |
1558 | ✗ | get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3 | |
1559 | ✗ | skip_bits1(gb); // intra_contour_enabled_flag | |
1560 | ✗ | skip_bits1(gb); // intra_dc_only_wedge_enabled_flag | |
1561 | ✗ | skip_bits1(gb); // cqt_cu_part_pred_enabled_flag | |
1562 | ✗ | skip_bits1(gb); // inter_dc_only_enabled_flag | |
1563 | ✗ | skip_bits1(gb); // skip_intra_enabled_flag | |
1564 | } | ||
1565 | } | ||
1566 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1567 | "sps_3d_extension_flag not yet implemented\n"); | ||
1568 | } | ||
1569 | |||
1570 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 131 times.
|
131 | if (sps->scc_extension) { |
1571 | ✗ | sps->curr_pic_ref_enabled = get_bits1(gb); | |
1572 | ✗ | sps->palette_mode_enabled = get_bits1(gb); | |
1573 | ✗ | if (sps->palette_mode_enabled) { | |
1574 | ✗ | sps->palette_max_size = get_ue_golomb(gb); | |
1575 | ✗ | sps->delta_palette_max_predictor_size = get_ue_golomb(gb); | |
1576 | ✗ | sps->palette_predictor_initializers_present = get_bits1(gb); | |
1577 | |||
1578 | ✗ | if (sps->palette_predictor_initializers_present) { | |
1579 | ✗ | sps->sps_num_palette_predictor_initializers = get_ue_golomb(gb) + 1; | |
1580 | ✗ | if (sps->sps_num_palette_predictor_initializers > HEVC_MAX_PALETTE_PREDICTOR_SIZE) { | |
1581 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1582 | "sps_num_palette_predictor_initializers out of range: %u\n", | ||
1583 | sps->sps_num_palette_predictor_initializers); | ||
1584 | ✗ | return AVERROR_INVALIDDATA; | |
1585 | } | ||
1586 | ✗ | num_comps = !sps->chroma_format_idc ? 1 : 3; | |
1587 | ✗ | for (int comp = 0; comp < num_comps; comp++) { | |
1588 | ✗ | int bit_depth = !comp ? sps->bit_depth : sps->bit_depth_chroma; | |
1589 | ✗ | for (i = 0; i < sps->sps_num_palette_predictor_initializers; i++) | |
1590 | ✗ | sps->sps_palette_predictor_initializer[comp][i] = get_bits(gb, bit_depth); | |
1591 | } | ||
1592 | } | ||
1593 | } | ||
1594 | ✗ | sps->motion_vector_resolution_control_idc = get_bits(gb, 2); | |
1595 | ✗ | sps->intra_boundary_filtering_disabled = get_bits1(gb); | |
1596 | } | ||
1597 | } | ||
1598 |
2/2✓ Branch 0 taken 459 times.
✓ Branch 1 taken 713 times.
|
1172 | if (apply_defdispwin) { |
1599 | 459 | sps->output_window.left_offset += sps->vui.def_disp_win.left_offset; | |
1600 | 459 | sps->output_window.right_offset += sps->vui.def_disp_win.right_offset; | |
1601 | 459 | sps->output_window.top_offset += sps->vui.def_disp_win.top_offset; | |
1602 | 459 | sps->output_window.bottom_offset += sps->vui.def_disp_win.bottom_offset; | |
1603 | } | ||
1604 | |||
1605 | 1172 | ow = &sps->output_window; | |
1606 |
1/2✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
|
1172 | if (ow->left_offset >= INT_MAX - ow->right_offset || |
1607 |
1/2✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
|
1172 | ow->top_offset >= INT_MAX - ow->bottom_offset || |
1608 |
1/2✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
|
1172 | ow->left_offset + ow->right_offset >= sps->width || |
1609 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | ow->top_offset + ow->bottom_offset >= sps->height) { |
1610 | ✗ | av_log(avctx, AV_LOG_WARNING, "Invalid cropping offsets: %u/%u/%u/%u\n", | |
1611 | ow->left_offset, ow->right_offset, ow->top_offset, ow->bottom_offset); | ||
1612 | ✗ | if (avctx->err_recognition & AV_EF_EXPLODE) { | |
1613 | ✗ | return AVERROR_INVALIDDATA; | |
1614 | } | ||
1615 | ✗ | av_log(avctx, AV_LOG_WARNING, | |
1616 | "Displaying the whole video surface.\n"); | ||
1617 | ✗ | memset(ow, 0, sizeof(*ow)); | |
1618 | ✗ | memset(&sps->pic_conf_win, 0, sizeof(sps->pic_conf_win)); | |
1619 | } | ||
1620 | |||
1621 | // Inferred parameters | ||
1622 | 1172 | sps->log2_ctb_size = sps->log2_min_cb_size + | |
1623 | 1172 | sps->log2_diff_max_min_coding_block_size; | |
1624 | 1172 | sps->log2_min_pu_size = sps->log2_min_cb_size - 1; | |
1625 | |||
1626 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->log2_ctb_size > HEVC_MAX_LOG2_CTB_SIZE) { |
1627 | ✗ | av_log(avctx, AV_LOG_ERROR, "CTB size out of range: 2^%d\n", sps->log2_ctb_size); | |
1628 | ✗ | return AVERROR_INVALIDDATA; | |
1629 | } | ||
1630 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->log2_ctb_size < 4) { |
1631 | ✗ | av_log(avctx, | |
1632 | AV_LOG_ERROR, | ||
1633 | "log2_ctb_size %d differs from the bounds of any known profile\n", | ||
1634 | sps->log2_ctb_size); | ||
1635 | ✗ | avpriv_request_sample(avctx, "log2_ctb_size %d", sps->log2_ctb_size); | |
1636 | ✗ | return AVERROR_INVALIDDATA; | |
1637 | } | ||
1638 | |||
1639 | 1172 | sps->ctb_width = (sps->width + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size; | |
1640 | 1172 | sps->ctb_height = (sps->height + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size; | |
1641 | 1172 | sps->ctb_size = sps->ctb_width * sps->ctb_height; | |
1642 | |||
1643 | 1172 | sps->min_cb_width = sps->width >> sps->log2_min_cb_size; | |
1644 | 1172 | sps->min_cb_height = sps->height >> sps->log2_min_cb_size; | |
1645 | 1172 | sps->min_tb_width = sps->width >> sps->log2_min_tb_size; | |
1646 | 1172 | sps->min_tb_height = sps->height >> sps->log2_min_tb_size; | |
1647 | 1172 | sps->min_pu_width = sps->width >> sps->log2_min_pu_size; | |
1648 | 1172 | sps->min_pu_height = sps->height >> sps->log2_min_pu_size; | |
1649 | 1172 | sps->tb_mask = (1 << (sps->log2_ctb_size - sps->log2_min_tb_size)) - 1; | |
1650 | |||
1651 | 1172 | sps->qp_bd_offset = 6 * (sps->bit_depth - 8); | |
1652 | |||
1653 |
1/2✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
|
1172 | if (av_zero_extend(sps->width, sps->log2_min_cb_size) || |
1654 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | av_zero_extend(sps->height, sps->log2_min_cb_size)) { |
1655 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid coded frame dimensions.\n"); | |
1656 | ✗ | return AVERROR_INVALIDDATA; | |
1657 | } | ||
1658 | |||
1659 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->max_transform_hierarchy_depth_inter > sps->log2_ctb_size - sps->log2_min_tb_size) { |
1660 | ✗ | av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_inter out of range: %d\n", | |
1661 | sps->max_transform_hierarchy_depth_inter); | ||
1662 | ✗ | return AVERROR_INVALIDDATA; | |
1663 | } | ||
1664 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->max_transform_hierarchy_depth_intra > sps->log2_ctb_size - sps->log2_min_tb_size) { |
1665 | ✗ | av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_intra out of range: %d\n", | |
1666 | sps->max_transform_hierarchy_depth_intra); | ||
1667 | ✗ | return AVERROR_INVALIDDATA; | |
1668 | } | ||
1669 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (sps->log2_max_trafo_size > FFMIN(sps->log2_ctb_size, 5)) { |
1670 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1671 | "max transform block size out of range: %d\n", | ||
1672 | sps->log2_max_trafo_size); | ||
1673 | ✗ | return AVERROR_INVALIDDATA; | |
1674 | } | ||
1675 | |||
1676 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1172 times.
|
1172 | if (get_bits_left(gb) < 0) { |
1677 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1678 | ✗ | "Overread SPS by %d bits\n", -get_bits_left(gb)); | |
1679 | ✗ | return AVERROR_INVALIDDATA; | |
1680 | } | ||
1681 | |||
1682 | 1172 | return 0; | |
1683 | } | ||
1684 | |||
1685 | 1172 | static void hevc_sps_free(AVRefStructOpaque opaque, void *obj) | |
1686 | { | ||
1687 | 1172 | HEVCSPS *sps = obj; | |
1688 | |||
1689 | 1172 | av_refstruct_unref(&sps->vps); | |
1690 | |||
1691 | 1172 | av_freep(&sps->data); | |
1692 | 1172 | } | |
1693 | |||
1694 | 458 | static int compare_sps(const HEVCSPS *sps1, const HEVCSPS *sps2) | |
1695 | { | ||
1696 |
2/2✓ Branch 0 taken 454 times.
✓ Branch 1 taken 4 times.
|
912 | return sps1->data_size == sps2->data_size && |
1697 |
2/2✓ Branch 0 taken 450 times.
✓ Branch 1 taken 4 times.
|
454 | !memcmp(sps1->data, sps2->data, sps1->data_size); |
1698 | } | ||
1699 | |||
1700 | 1172 | int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, | |
1701 | HEVCParamSets *ps, unsigned nuh_layer_id, | ||
1702 | int apply_defdispwin) | ||
1703 | { | ||
1704 | 1172 | HEVCSPS *sps = av_refstruct_alloc_ext(sizeof(*sps), 0, NULL, hevc_sps_free); | |
1705 | unsigned int sps_id; | ||
1706 | int ret; | ||
1707 | |||
1708 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (!sps) |
1709 | ✗ | return AVERROR(ENOMEM); | |
1710 | |||
1711 | 1172 | av_log(avctx, AV_LOG_DEBUG, "Decoding SPS\n"); | |
1712 | |||
1713 | 1172 | sps->data_size = gb->buffer_end - gb->buffer; | |
1714 | 1172 | sps->data = av_memdup(gb->buffer, sps->data_size); | |
1715 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (!sps->data) { |
1716 | ✗ | ret = AVERROR(ENOMEM); | |
1717 | ✗ | goto err; | |
1718 | } | ||
1719 | |||
1720 | 1172 | ret = ff_hevc_parse_sps(sps, gb, &sps_id, | |
1721 | nuh_layer_id, apply_defdispwin, | ||
1722 | 1172 | ps->vps_list, avctx); | |
1723 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (ret < 0) |
1724 | ✗ | goto err; | |
1725 | |||
1726 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
|
1172 | if (avctx->debug & FF_DEBUG_BITSTREAM) { |
1727 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
1728 | "Parsed SPS: id %d; coded wxh: %dx%d; " | ||
1729 | "cropped wxh: %dx%d; pix_fmt: %s.\n", | ||
1730 | ✗ | sps_id, sps->width, sps->height, | |
1731 | ✗ | sps->width - (sps->output_window.left_offset + sps->output_window.right_offset), | |
1732 | ✗ | sps->height - (sps->output_window.top_offset + sps->output_window.bottom_offset), | |
1733 | ✗ | av_get_pix_fmt_name(sps->pix_fmt)); | |
1734 | } | ||
1735 | |||
1736 | /* check if this is a repeat of an already parsed SPS, then keep the | ||
1737 | * original one. | ||
1738 | * otherwise drop all PPSes that depend on it */ | ||
1739 |
4/4✓ Branch 0 taken 458 times.
✓ Branch 1 taken 714 times.
✓ Branch 2 taken 450 times.
✓ Branch 3 taken 8 times.
|
1630 | if (ps->sps_list[sps_id] && |
1740 | 458 | compare_sps(ps->sps_list[sps_id], sps)) { | |
1741 | 450 | av_refstruct_unref(&sps); | |
1742 | } else { | ||
1743 | 722 | remove_sps(ps, sps_id); | |
1744 | 722 | ps->sps_list[sps_id] = sps; | |
1745 | } | ||
1746 | |||
1747 | 1172 | return 0; | |
1748 | ✗ | err: | |
1749 | ✗ | av_refstruct_unref(&sps); | |
1750 | ✗ | return ret; | |
1751 | } | ||
1752 | |||
1753 | 2176 | static void hevc_pps_free(AVRefStructOpaque unused, void *obj) | |
1754 | { | ||
1755 | 2176 | HEVCPPS *pps = obj; | |
1756 | |||
1757 | 2176 | av_refstruct_unref(&pps->sps); | |
1758 | |||
1759 | 2176 | av_freep(&pps->column_width); | |
1760 | 2176 | av_freep(&pps->row_height); | |
1761 | 2176 | av_freep(&pps->col_bd); | |
1762 | 2176 | av_freep(&pps->row_bd); | |
1763 | 2176 | av_freep(&pps->col_idxX); | |
1764 | 2176 | av_freep(&pps->ctb_addr_rs_to_ts); | |
1765 | 2176 | av_freep(&pps->ctb_addr_ts_to_rs); | |
1766 | 2176 | av_freep(&pps->tile_pos_rs); | |
1767 | 2176 | av_freep(&pps->tile_id); | |
1768 | 2176 | av_freep(&pps->min_tb_addr_zs_tab); | |
1769 | 2176 | av_freep(&pps->data); | |
1770 | 2176 | } | |
1771 | |||
1772 | 3 | static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_depth, | |
1773 | int idx_y, int idx_cb, int idx_cr, int inp_length) | ||
1774 | { | ||
1775 | unsigned int split_octant_flag, part_num_y, coded_res_flag, res_coeff_q, res_coeff_r; | ||
1776 | int cm_res_bits; | ||
1777 | |||
1778 | 3 | part_num_y = 1 << pps->cm_y_part_num_log2; | |
1779 | |||
1780 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | split_octant_flag = inp_depth < pps->cm_octant_depth ? get_bits1(gb) : 0; |
1781 | |||
1782 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (split_octant_flag) |
1783 | ✗ | for (int k = 0; k < 2; k++) | |
1784 | ✗ | for (int m = 0; m < 2; m++) | |
1785 | ✗ | for (int n = 0; n < 2; n++) | |
1786 | ✗ | colour_mapping_octants(gb, pps, inp_depth + 1, | |
1787 | ✗ | idx_y + part_num_y * k * inp_length / 2, | |
1788 | ✗ | idx_cb + m * inp_length / 2, | |
1789 | ✗ | idx_cr + n * inp_length / 2, | |
1790 | inp_length / 2); | ||
1791 | else | ||
1792 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
|
27 | for (int i = 0; i < part_num_y; i++) { |
1793 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 24 times.
|
120 | for (int j = 0; j < 4; j++) { |
1794 | 96 | coded_res_flag = get_bits1(gb); | |
1795 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | if (coded_res_flag) |
1796 | ✗ | for (int c = 0; c < 3; c++) { | |
1797 | ✗ | res_coeff_q = get_ue_golomb_long(gb); | |
1798 | ✗ | cm_res_bits = FFMAX(0, 10 + pps->luma_bit_depth_cm_input - | |
1799 | pps->luma_bit_depth_cm_output - | ||
1800 | pps->cm_res_quant_bits - pps->cm_delta_flc_bits); | ||
1801 | ✗ | res_coeff_r = cm_res_bits ? get_bits(gb, cm_res_bits) : 0; | |
1802 | ✗ | if (res_coeff_q || res_coeff_r) | |
1803 | ✗ | skip_bits1(gb); | |
1804 | } | ||
1805 | } | ||
1806 | } | ||
1807 | 3 | } | |
1808 | |||
1809 | 3 | static int colour_mapping_table(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps) | |
1810 | { | ||
1811 | 3 | pps->num_cm_ref_layers = get_ue_golomb(gb) + 1; | |
1812 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (pps->num_cm_ref_layers > 62) { |
1813 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1814 | "num_cm_ref_layers_minus1 shall be in the range [0, 61].\n"); | ||
1815 | ✗ | return AVERROR_INVALIDDATA; | |
1816 | } | ||
1817 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | for (int i = 0; i < pps->num_cm_ref_layers; i++) |
1818 | 9 | pps->cm_ref_layer_id[i] = get_bits(gb, 6); | |
1819 | |||
1820 | 3 | pps->cm_octant_depth = get_bits(gb, 2); | |
1821 | 3 | pps->cm_y_part_num_log2 = get_bits(gb, 2); | |
1822 | |||
1823 | 3 | pps->luma_bit_depth_cm_input = get_ue_golomb(gb) + 8; | |
1824 | 3 | pps->chroma_bit_depth_cm_input = get_ue_golomb(gb) + 8; | |
1825 | 3 | pps->luma_bit_depth_cm_output = get_ue_golomb(gb) + 8; | |
1826 | 3 | pps->chroma_bit_depth_cm_output = get_ue_golomb(gb) + 8; | |
1827 | |||
1828 | 3 | pps->cm_res_quant_bits = get_bits(gb, 2); | |
1829 | 3 | pps->cm_delta_flc_bits = get_bits(gb, 2) + 1; | |
1830 | |||
1831 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (pps->cm_octant_depth == 1) { |
1832 | ✗ | pps->cm_adapt_threshold_u_delta = get_se_golomb_long(gb); | |
1833 | ✗ | pps->cm_adapt_threshold_v_delta = get_se_golomb_long(gb); | |
1834 | } | ||
1835 | |||
1836 | 3 | colour_mapping_octants(gb, pps, 0, 0, 0, 0, 1 << pps->cm_octant_depth); | |
1837 | |||
1838 | 3 | return 0; | |
1839 | } | ||
1840 | |||
1841 | 43 | static int pps_multilayer_extension(GetBitContext *gb, AVCodecContext *avctx, | |
1842 | HEVCPPS *pps, const HEVCSPS *sps, const HEVCVPS *vps) | ||
1843 | { | ||
1844 | 43 | pps->poc_reset_info_present_flag = get_bits1(gb); | |
1845 | 43 | pps->pps_infer_scaling_list_flag = get_bits1(gb); | |
1846 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if (pps->pps_infer_scaling_list_flag) |
1847 | ✗ | pps->pps_scaling_list_ref_layer_id = get_bits(gb, 6); | |
1848 | |||
1849 | 43 | pps->num_ref_loc_offsets = get_ue_golomb(gb); | |
1850 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if (pps->num_ref_loc_offsets > vps->vps_max_layers - 1) |
1851 | ✗ | return AVERROR_INVALIDDATA; | |
1852 | |||
1853 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | for (int i = 0; i < pps->num_ref_loc_offsets; i++) { |
1854 | ✗ | pps->ref_loc_offset_layer_id[i] = get_bits(gb, 6); | |
1855 | ✗ | pps->scaled_ref_layer_offset_present_flag[i] = get_bits1(gb); | |
1856 | ✗ | if (pps->scaled_ref_layer_offset_present_flag[i]) { | |
1857 | ✗ | pps->scaled_ref_layer_left_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1858 | ✗ | pps->scaled_ref_layer_top_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1859 | ✗ | pps->scaled_ref_layer_right_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1860 | ✗ | pps->scaled_ref_layer_bottom_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1861 | } | ||
1862 | |||
1863 | ✗ | pps->ref_region_offset_present_flag[i] = get_bits1(gb); | |
1864 | ✗ | if (pps->ref_region_offset_present_flag[i]) { | |
1865 | ✗ | pps->ref_region_left_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1866 | ✗ | pps->ref_region_top_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1867 | ✗ | pps->ref_region_right_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1868 | ✗ | pps->ref_region_bottom_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb); | |
1869 | } | ||
1870 | |||
1871 | ✗ | pps->resample_phase_set_present_flag[i] = get_bits1(gb); | |
1872 | ✗ | if (pps->resample_phase_set_present_flag[i]) { | |
1873 | ✗ | pps->phase_hor_luma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb_31(gb); | |
1874 | ✗ | pps->phase_ver_luma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb_31(gb); | |
1875 | ✗ | pps->phase_hor_chroma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb(gb) - 8; | |
1876 | ✗ | pps->phase_ver_chroma[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb(gb) - 8; | |
1877 | } | ||
1878 | } | ||
1879 | |||
1880 | 43 | pps->colour_mapping_enabled_flag = get_bits1(gb); | |
1881 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 40 times.
|
43 | if (pps->colour_mapping_enabled_flag) { |
1882 | 3 | int ret = colour_mapping_table(gb, avctx, pps); | |
1883 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (ret < 0) |
1884 | ✗ | return ret; | |
1885 | } | ||
1886 | |||
1887 | 43 | return 0; | |
1888 | } | ||
1889 | |||
1890 | ✗ | static void delta_dlt(GetBitContext *gb, HEVCPPS *pps) | |
1891 | { | ||
1892 | ✗ | unsigned int num_val_delta_dlt, max_diff = 0; | |
1893 | ✗ | int min_diff_minus1 = -1; | |
1894 | unsigned int len; | ||
1895 | |||
1896 | ✗ | num_val_delta_dlt = get_bits(gb, pps->pps_bit_depth_for_depth_layers_minus8 + 8); | |
1897 | ✗ | if (num_val_delta_dlt) { | |
1898 | ✗ | if (num_val_delta_dlt > 1) | |
1899 | ✗ | max_diff = get_bits(gb, pps->pps_bit_depth_for_depth_layers_minus8 + 8); | |
1900 | ✗ | if (num_val_delta_dlt > 2 && max_diff) { | |
1901 | ✗ | len = av_log2(max_diff) + 1; | |
1902 | ✗ | min_diff_minus1 = get_bits(gb, len); | |
1903 | } | ||
1904 | ✗ | if (max_diff > (min_diff_minus1 + 1)) | |
1905 | ✗ | for (int k = 1; k < num_val_delta_dlt; k++) { | |
1906 | ✗ | len = av_log2(max_diff - (min_diff_minus1 + 1)) + 1; | |
1907 | ✗ | skip_bits(gb, len); // delta_val_diff_minus_min | |
1908 | } | ||
1909 | } | ||
1910 | ✗ | } | |
1911 | |||
1912 | 3 | static int pps_3d_extension(GetBitContext *gb, AVCodecContext *avctx, | |
1913 | HEVCPPS *pps, const HEVCSPS *sps) | ||
1914 | { | ||
1915 | unsigned int pps_depth_layers_minus1; | ||
1916 | |||
1917 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (get_bits1(gb)) { // dlts_present_flag |
1918 | ✗ | pps_depth_layers_minus1 = get_bits(gb, 6); | |
1919 | ✗ | pps->pps_bit_depth_for_depth_layers_minus8 = get_bits(gb, 4); | |
1920 | ✗ | for (int i = 0; i <= pps_depth_layers_minus1; i++) { | |
1921 | ✗ | if (get_bits1(gb)) { // dlt_flag[i] | |
1922 | ✗ | if (!get_bits1(gb)) { // dlt_pred_flag[i] | |
1923 | ✗ | if (get_bits1(gb)) { // dlt_val_flags_present_flag[i] | |
1924 | ✗ | for (int j = 0; j <= ((1 << (pps->pps_bit_depth_for_depth_layers_minus8 + 8)) - 1); j++) | |
1925 | ✗ | skip_bits1(gb); // dlt_value_flag[i][j] | |
1926 | } else | ||
1927 | ✗ | delta_dlt(gb, pps); | |
1928 | } | ||
1929 | } | ||
1930 | } | ||
1931 | } | ||
1932 | |||
1933 | 3 | return 0; | |
1934 | } | ||
1935 | |||
1936 | 63 | static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx, | |
1937 | HEVCPPS *pps, const HEVCSPS *sps) | ||
1938 | { | ||
1939 |
1/2✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
|
63 | if (pps->transform_skip_enabled_flag) { |
1940 | 63 | pps->log2_max_transform_skip_block_size = get_ue_golomb_31(gb) + 2; | |
1941 | } | ||
1942 | 63 | pps->cross_component_prediction_enabled_flag = get_bits1(gb); | |
1943 | 63 | pps->chroma_qp_offset_list_enabled_flag = get_bits1(gb); | |
1944 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 57 times.
|
63 | if (pps->chroma_qp_offset_list_enabled_flag) { |
1945 | 6 | pps->diff_cu_chroma_qp_offset_depth = get_ue_golomb_31(gb); | |
1946 | 6 | pps->chroma_qp_offset_list_len_minus1 = get_ue_golomb_31(gb); | |
1947 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (pps->chroma_qp_offset_list_len_minus1 > 5) { |
1948 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1949 | "chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n"); | ||
1950 | ✗ | return AVERROR_INVALIDDATA; | |
1951 | } | ||
1952 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | for (int i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) { |
1953 | 6 | pps->cb_qp_offset_list[i] = get_se_golomb(gb); | |
1954 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (pps->cb_qp_offset_list[i]) { |
1955 | 6 | av_log(avctx, AV_LOG_WARNING, | |
1956 | "cb_qp_offset_list not tested yet.\n"); | ||
1957 | } | ||
1958 | 6 | pps->cr_qp_offset_list[i] = get_se_golomb(gb); | |
1959 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (pps->cr_qp_offset_list[i]) { |
1960 | 6 | av_log(avctx, AV_LOG_WARNING, | |
1961 | "cb_qp_offset_list not tested yet.\n"); | ||
1962 | } | ||
1963 | } | ||
1964 | } | ||
1965 | 63 | pps->log2_sao_offset_scale_luma = get_ue_golomb_31(gb); | |
1966 | 63 | pps->log2_sao_offset_scale_chroma = get_ue_golomb_31(gb); | |
1967 | |||
1968 |
1/2✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
|
63 | if ( pps->log2_sao_offset_scale_luma > FFMAX(sps->bit_depth - 10, 0) |
1969 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
|
63 | || pps->log2_sao_offset_scale_chroma > FFMAX(sps->bit_depth_chroma - 10, 0) |
1970 | ) | ||
1971 | ✗ | return AVERROR_INVALIDDATA; | |
1972 | |||
1973 | 63 | return(0); | |
1974 | } | ||
1975 | |||
1976 | 3 | static int pps_scc_extension(GetBitContext *gb, AVCodecContext *avctx, | |
1977 | HEVCPPS *pps, const HEVCSPS *sps) | ||
1978 | { | ||
1979 | int num_comps, ret; | ||
1980 | |||
1981 | 3 | pps->pps_curr_pic_ref_enabled_flag = get_bits1(gb); | |
1982 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (pps->residual_adaptive_colour_transform_enabled_flag = get_bits1(gb)) { |
1983 | ✗ | pps->pps_slice_act_qp_offsets_present_flag = get_bits1(gb); | |
1984 | ✗ | pps->pps_act_y_qp_offset = get_se_golomb(gb) - 5; | |
1985 | ✗ | pps->pps_act_cb_qp_offset = get_se_golomb(gb) - 5; | |
1986 | ✗ | pps->pps_act_cr_qp_offset = get_se_golomb(gb) - 3; | |
1987 | |||
1988 | #define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 || \ | ||
1989 | pps->pps_act_ ## name ## _qp_offset >= 12) | ||
1990 | ✗ | ret = CHECK_QP_OFFSET(y) || CHECK_QP_OFFSET(cb) || CHECK_QP_OFFSET(cr); | |
1991 | #undef CHECK_QP_OFFSET | ||
1992 | ✗ | if (ret) { | |
1993 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1994 | "PpsActQpOffsetY/Cb/Cr shall be in the range of [-12, 12].\n"); | ||
1995 | ✗ | return AVERROR_INVALIDDATA; | |
1996 | } | ||
1997 | } | ||
1998 | |||
1999 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (pps->pps_palette_predictor_initializers_present_flag = get_bits1(gb)) { |
2000 | ✗ | pps->pps_num_palette_predictor_initializers = get_ue_golomb(gb); | |
2001 | ✗ | if (pps->pps_num_palette_predictor_initializers > 0) { | |
2002 | ✗ | if (pps->pps_num_palette_predictor_initializers > HEVC_MAX_PALETTE_PREDICTOR_SIZE) { | |
2003 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
2004 | "pps_num_palette_predictor_initializers out of range: %u\n", | ||
2005 | ✗ | pps->pps_num_palette_predictor_initializers); | |
2006 | ✗ | return AVERROR_INVALIDDATA; | |
2007 | } | ||
2008 | ✗ | pps->monochrome_palette_flag = get_bits1(gb); | |
2009 | ✗ | pps->luma_bit_depth_entry = get_ue_golomb_31(gb) + 8; | |
2010 | ✗ | if (pps->luma_bit_depth_entry != sps->bit_depth) | |
2011 | ✗ | return AVERROR_INVALIDDATA; | |
2012 | ✗ | if (!pps->monochrome_palette_flag) { | |
2013 | ✗ | pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8; | |
2014 | ✗ | if (pps->chroma_bit_depth_entry != sps->bit_depth_chroma) | |
2015 | ✗ | return AVERROR_INVALIDDATA; | |
2016 | } | ||
2017 | |||
2018 | ✗ | num_comps = pps->monochrome_palette_flag ? 1 : 3; | |
2019 | ✗ | for (int comp = 0; comp < num_comps; comp++) { | |
2020 | ✗ | int bit_depth = !comp ? pps->luma_bit_depth_entry : pps->chroma_bit_depth_entry; | |
2021 | ✗ | for (int i = 0; i < pps->pps_num_palette_predictor_initializers; i++) | |
2022 | ✗ | pps->pps_palette_predictor_initializer[comp][i] = get_bits(gb, bit_depth); | |
2023 | } | ||
2024 | } | ||
2025 | } | ||
2026 | |||
2027 | 3 | return 0; | |
2028 | } | ||
2029 | |||
2030 | 2172 | static inline int setup_pps(AVCodecContext *avctx, GetBitContext *gb, | |
2031 | HEVCPPS *pps, const HEVCSPS *sps) | ||
2032 | { | ||
2033 | int log2_diff; | ||
2034 | int pic_area_in_ctbs; | ||
2035 | int i, j, x, y, ctb_addr_rs, tile_id; | ||
2036 | |||
2037 | // Inferred parameters | ||
2038 | 2172 | pps->col_bd = av_malloc_array(pps->num_tile_columns + 1, sizeof(*pps->col_bd)); | |
2039 | 2172 | pps->row_bd = av_malloc_array(pps->num_tile_rows + 1, sizeof(*pps->row_bd)); | |
2040 | 2172 | pps->col_idxX = av_malloc_array(sps->ctb_width, sizeof(*pps->col_idxX)); | |
2041 |
3/6✓ Branch 0 taken 2172 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2172 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2172 times.
|
2172 | if (!pps->col_bd || !pps->row_bd || !pps->col_idxX) |
2042 | ✗ | return AVERROR(ENOMEM); | |
2043 | |||
2044 |
2/2✓ Branch 0 taken 1651 times.
✓ Branch 1 taken 521 times.
|
2172 | if (pps->uniform_spacing_flag) { |
2045 |
2/2✓ Branch 0 taken 1425 times.
✓ Branch 1 taken 226 times.
|
1651 | if (!pps->column_width) { |
2046 | 1425 | pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width)); | |
2047 | 1425 | pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height)); | |
2048 | } | ||
2049 |
2/4✓ Branch 0 taken 1651 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1651 times.
|
1651 | if (!pps->column_width || !pps->row_height) |
2050 | ✗ | return AVERROR(ENOMEM); | |
2051 | |||
2052 |
2/2✓ Branch 0 taken 1812 times.
✓ Branch 1 taken 1651 times.
|
3463 | for (i = 0; i < pps->num_tile_columns; i++) { |
2053 | 1812 | pps->column_width[i] = ((i + 1) * sps->ctb_width) / pps->num_tile_columns - | |
2054 | 1812 | (i * sps->ctb_width) / pps->num_tile_columns; | |
2055 | } | ||
2056 | |||
2057 |
2/2✓ Branch 0 taken 1830 times.
✓ Branch 1 taken 1651 times.
|
3481 | for (i = 0; i < pps->num_tile_rows; i++) { |
2058 | 1830 | pps->row_height[i] = ((i + 1) * sps->ctb_height) / pps->num_tile_rows - | |
2059 | 1830 | (i * sps->ctb_height) / pps->num_tile_rows; | |
2060 | } | ||
2061 | } | ||
2062 | |||
2063 | 2172 | pps->col_bd[0] = 0; | |
2064 |
2/2✓ Branch 0 taken 4375 times.
✓ Branch 1 taken 2172 times.
|
6547 | for (i = 0; i < pps->num_tile_columns; i++) |
2065 | 4375 | pps->col_bd[i + 1] = pps->col_bd[i] + pps->column_width[i]; | |
2066 | |||
2067 | 2172 | pps->row_bd[0] = 0; | |
2068 |
2/2✓ Branch 0 taken 4381 times.
✓ Branch 1 taken 2172 times.
|
6553 | for (i = 0; i < pps->num_tile_rows; i++) |
2069 | 4381 | pps->row_bd[i + 1] = pps->row_bd[i] + pps->row_height[i]; | |
2070 | |||
2071 |
2/2✓ Branch 0 taken 42915 times.
✓ Branch 1 taken 2172 times.
|
45087 | for (i = 0, j = 0; i < sps->ctb_width; i++) { |
2072 |
2/2✓ Branch 0 taken 4366 times.
✓ Branch 1 taken 38549 times.
|
42915 | if (i > pps->col_bd[j]) |
2073 | 4366 | j++; | |
2074 | 42915 | pps->col_idxX[i] = j; | |
2075 | } | ||
2076 | |||
2077 | /** | ||
2078 | * 6.5 | ||
2079 | */ | ||
2080 | 2172 | pic_area_in_ctbs = sps->ctb_width * sps->ctb_height; | |
2081 | |||
2082 | 2172 | pps->ctb_addr_rs_to_ts = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_rs_to_ts)); | |
2083 | 2172 | pps->ctb_addr_ts_to_rs = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_ts_to_rs)); | |
2084 | 2172 | pps->tile_id = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->tile_id)); | |
2085 | 2172 | pps->min_tb_addr_zs_tab = av_malloc_array((sps->tb_mask+2) * (sps->tb_mask+2), sizeof(*pps->min_tb_addr_zs_tab)); | |
2086 |
2/4✓ Branch 0 taken 2172 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2172 times.
✗ Branch 3 not taken.
|
2172 | if (!pps->ctb_addr_rs_to_ts || !pps->ctb_addr_ts_to_rs || |
2087 |
2/4✓ Branch 0 taken 2172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2172 times.
|
2172 | !pps->tile_id || !pps->min_tb_addr_zs_tab) { |
2088 | ✗ | return AVERROR(ENOMEM); | |
2089 | } | ||
2090 | |||
2091 |
2/2✓ Branch 0 taken 680883 times.
✓ Branch 1 taken 2172 times.
|
683055 | for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) { |
2092 | 680883 | int tb_x = ctb_addr_rs % sps->ctb_width; | |
2093 | 680883 | int tb_y = ctb_addr_rs / sps->ctb_width; | |
2094 | 680883 | int tile_x = 0; | |
2095 | 680883 | int tile_y = 0; | |
2096 | 680883 | int val = 0; | |
2097 | |||
2098 |
1/2✓ Branch 0 taken 1191435 times.
✗ Branch 1 not taken.
|
1191435 | for (i = 0; i < pps->num_tile_columns; i++) { |
2099 |
2/2✓ Branch 0 taken 680883 times.
✓ Branch 1 taken 510552 times.
|
1191435 | if (tb_x < pps->col_bd[i + 1]) { |
2100 | 680883 | tile_x = i; | |
2101 | 680883 | break; | |
2102 | } | ||
2103 | } | ||
2104 | |||
2105 |
1/2✓ Branch 0 taken 1059281 times.
✗ Branch 1 not taken.
|
1059281 | for (i = 0; i < pps->num_tile_rows; i++) { |
2106 |
2/2✓ Branch 0 taken 680883 times.
✓ Branch 1 taken 378398 times.
|
1059281 | if (tb_y < pps->row_bd[i + 1]) { |
2107 | 680883 | tile_y = i; | |
2108 | 680883 | break; | |
2109 | } | ||
2110 | } | ||
2111 | |||
2112 |
2/2✓ Branch 0 taken 510552 times.
✓ Branch 1 taken 680883 times.
|
1191435 | for (i = 0; i < tile_x; i++) |
2113 | 510552 | val += pps->row_height[tile_y] * pps->column_width[i]; | |
2114 |
2/2✓ Branch 0 taken 378398 times.
✓ Branch 1 taken 680883 times.
|
1059281 | for (i = 0; i < tile_y; i++) |
2115 | 378398 | val += sps->ctb_width * pps->row_height[i]; | |
2116 | |||
2117 | 680883 | val += (tb_y - pps->row_bd[tile_y]) * pps->column_width[tile_x] + | |
2118 | 680883 | tb_x - pps->col_bd[tile_x]; | |
2119 | |||
2120 | 680883 | pps->ctb_addr_rs_to_ts[ctb_addr_rs] = val; | |
2121 | 680883 | pps->ctb_addr_ts_to_rs[val] = ctb_addr_rs; | |
2122 | } | ||
2123 | |||
2124 |
2/2✓ Branch 0 taken 4381 times.
✓ Branch 1 taken 2172 times.
|
6553 | for (j = 0, tile_id = 0; j < pps->num_tile_rows; j++) |
2125 |
2/2✓ Branch 0 taken 14736 times.
✓ Branch 1 taken 4381 times.
|
19117 | for (i = 0; i < pps->num_tile_columns; i++, tile_id++) |
2126 |
2/2✓ Branch 0 taken 65826 times.
✓ Branch 1 taken 14736 times.
|
80562 | for (y = pps->row_bd[j]; y < pps->row_bd[j + 1]; y++) |
2127 |
2/2✓ Branch 0 taken 680883 times.
✓ Branch 1 taken 65826 times.
|
746709 | for (x = pps->col_bd[i]; x < pps->col_bd[i + 1]; x++) |
2128 | 680883 | pps->tile_id[pps->ctb_addr_rs_to_ts[y * sps->ctb_width + x]] = tile_id; | |
2129 | |||
2130 | 2172 | pps->tile_pos_rs = av_malloc_array(tile_id, sizeof(*pps->tile_pos_rs)); | |
2131 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2172 times.
|
2172 | if (!pps->tile_pos_rs) |
2132 | ✗ | return AVERROR(ENOMEM); | |
2133 | |||
2134 |
2/2✓ Branch 0 taken 4381 times.
✓ Branch 1 taken 2172 times.
|
6553 | for (j = 0; j < pps->num_tile_rows; j++) |
2135 |
2/2✓ Branch 0 taken 14736 times.
✓ Branch 1 taken 4381 times.
|
19117 | for (i = 0; i < pps->num_tile_columns; i++) |
2136 | 14736 | pps->tile_pos_rs[j * pps->num_tile_columns + i] = | |
2137 | 14736 | pps->row_bd[j] * sps->ctb_width + pps->col_bd[i]; | |
2138 | |||
2139 | 2172 | log2_diff = sps->log2_ctb_size - sps->log2_min_tb_size; | |
2140 | 2172 | pps->min_tb_addr_zs = &pps->min_tb_addr_zs_tab[1*(sps->tb_mask+2)+1]; | |
2141 |
2/2✓ Branch 0 taken 35888 times.
✓ Branch 1 taken 2172 times.
|
38060 | for (y = 0; y < sps->tb_mask+2; y++) { |
2142 | 35888 | pps->min_tb_addr_zs_tab[y*(sps->tb_mask+2)] = -1; | |
2143 | 35888 | pps->min_tb_addr_zs_tab[y] = -1; | |
2144 | } | ||
2145 |
2/2✓ Branch 0 taken 33716 times.
✓ Branch 1 taken 2172 times.
|
35888 | for (y = 0; y < sps->tb_mask+1; y++) { |
2146 |
2/2✓ Branch 0 taken 532560 times.
✓ Branch 1 taken 33716 times.
|
566276 | for (x = 0; x < sps->tb_mask+1; x++) { |
2147 | 532560 | int tb_x = x >> log2_diff; | |
2148 | 532560 | int tb_y = y >> log2_diff; | |
2149 | 532560 | int rs = sps->ctb_width * tb_y + tb_x; | |
2150 | 532560 | int val = pps->ctb_addr_rs_to_ts[rs] << (log2_diff * 2); | |
2151 |
2/2✓ Branch 0 taken 2123808 times.
✓ Branch 1 taken 532560 times.
|
2656368 | for (i = 0; i < log2_diff; i++) { |
2152 | 2123808 | int m = 1 << i; | |
2153 |
4/4✓ Branch 0 taken 1061904 times.
✓ Branch 1 taken 1061904 times.
✓ Branch 2 taken 1061904 times.
✓ Branch 3 taken 1061904 times.
|
2123808 | val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0); |
2154 | } | ||
2155 | 532560 | pps->min_tb_addr_zs[y * (sps->tb_mask+2) + x] = val; | |
2156 | } | ||
2157 | } | ||
2158 | |||
2159 | 2172 | return 0; | |
2160 | } | ||
2161 | |||
2162 | 3396 | int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, | |
2163 | HEVCParamSets *ps) | ||
2164 | { | ||
2165 | 3396 | const HEVCSPS *sps = NULL; | |
2166 | 3396 | const HEVCVPS *vps = NULL; | |
2167 | 3396 | int i, ret = 0; | |
2168 | 3396 | ptrdiff_t nal_size = gb->buffer_end - gb->buffer; | |
2169 | 3396 | unsigned int pps_id = get_ue_golomb_long(gb); | |
2170 | unsigned log2_parallel_merge_level_minus2; | ||
2171 | HEVCPPS *pps; | ||
2172 | |||
2173 | 3396 | av_log(avctx, AV_LOG_DEBUG, "Decoding PPS\n"); | |
2174 | |||
2175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3396 times.
|
3396 | if (pps_id >= HEVC_MAX_PPS_COUNT) { |
2176 | ✗ | av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); | |
2177 | ✗ | return AVERROR_INVALIDDATA; | |
2178 | } | ||
2179 | |||
2180 |
2/2✓ Branch 0 taken 2425 times.
✓ Branch 1 taken 971 times.
|
3396 | if (ps->pps_list[pps_id]) { |
2181 | 2425 | const HEVCPPS *pps1 = ps->pps_list[pps_id]; | |
2182 |
2/2✓ Branch 0 taken 2045 times.
✓ Branch 1 taken 380 times.
|
2425 | if (pps1->data_size == nal_size && |
2183 |
2/2✓ Branch 0 taken 1220 times.
✓ Branch 1 taken 825 times.
|
2045 | !memcmp(pps1->data, gb->buffer, pps1->data_size)) |
2184 | 1220 | return 0; | |
2185 | } | ||
2186 | |||
2187 | 2176 | pps = av_refstruct_alloc_ext(sizeof(*pps), 0, NULL, hevc_pps_free); | |
2188 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2176 times.
|
2176 | if (!pps) |
2189 | ✗ | return AVERROR(ENOMEM); | |
2190 | |||
2191 | 2176 | pps->data_size = nal_size; | |
2192 | 2176 | pps->data = av_memdup(gb->buffer, nal_size); | |
2193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2176 times.
|
2176 | if (!pps->data) { |
2194 | ✗ | ret = AVERROR_INVALIDDATA; | |
2195 | ✗ | goto err; | |
2196 | } | ||
2197 | |||
2198 | // Default values | ||
2199 | 2176 | pps->loop_filter_across_tiles_enabled_flag = 1; | |
2200 | 2176 | pps->num_tile_columns = 1; | |
2201 | 2176 | pps->num_tile_rows = 1; | |
2202 | 2176 | pps->uniform_spacing_flag = 1; | |
2203 | 2176 | pps->disable_dbf = 0; | |
2204 | 2176 | pps->beta_offset = 0; | |
2205 | 2176 | pps->tc_offset = 0; | |
2206 | 2176 | pps->log2_max_transform_skip_block_size = 2; | |
2207 | |||
2208 | // Coded parameters | ||
2209 | 2176 | pps->pps_id = pps_id; | |
2210 | 2176 | pps->sps_id = get_ue_golomb_long(gb); | |
2211 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2176 times.
|
2176 | if (pps->sps_id >= HEVC_MAX_SPS_COUNT) { |
2212 | ✗ | av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id); | |
2213 | ✗ | ret = AVERROR_INVALIDDATA; | |
2214 | ✗ | goto err; | |
2215 | } | ||
2216 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2172 times.
|
2176 | if (!ps->sps_list[pps->sps_id]) { |
2217 | 4 | av_log(avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id); | |
2218 | 4 | ret = AVERROR_INVALIDDATA; | |
2219 | 4 | goto err; | |
2220 | } | ||
2221 | 2172 | sps = ps->sps_list[pps->sps_id]; | |
2222 | 2172 | vps = ps->vps_list[sps->vps_id]; | |
2223 | |||
2224 | 2172 | pps->sps = av_refstruct_ref_c(sps); | |
2225 | |||
2226 | 2172 | pps->dependent_slice_segments_enabled_flag = get_bits1(gb); | |
2227 | 2172 | pps->output_flag_present_flag = get_bits1(gb); | |
2228 | 2172 | pps->num_extra_slice_header_bits = get_bits(gb, 3); | |
2229 | |||
2230 | 2172 | pps->sign_data_hiding_flag = get_bits1(gb); | |
2231 | |||
2232 | 2172 | pps->cabac_init_present_flag = get_bits1(gb); | |
2233 | |||
2234 | 2172 | pps->num_ref_idx_l0_default_active = get_ue_golomb_31(gb) + 1; | |
2235 | 2172 | pps->num_ref_idx_l1_default_active = get_ue_golomb_31(gb) + 1; | |
2236 |
1/2✓ Branch 0 taken 2172 times.
✗ Branch 1 not taken.
|
2172 | if (pps->num_ref_idx_l0_default_active >= HEVC_MAX_REFS || |
2237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2172 times.
|
2172 | pps->num_ref_idx_l1_default_active >= HEVC_MAX_REFS) { |
2238 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many default refs in PPS: %d/%d.\n", | |
2239 | ✗ | pps->num_ref_idx_l0_default_active, pps->num_ref_idx_l1_default_active); | |
2240 | ✗ | goto err; | |
2241 | } | ||
2242 | |||
2243 | 2172 | pps->pic_init_qp_minus26 = get_se_golomb(gb); | |
2244 | |||
2245 | 2172 | pps->constrained_intra_pred_flag = get_bits1(gb); | |
2246 | 2172 | pps->transform_skip_enabled_flag = get_bits1(gb); | |
2247 | |||
2248 | 2172 | pps->cu_qp_delta_enabled_flag = get_bits1(gb); | |
2249 | 2172 | pps->diff_cu_qp_delta_depth = 0; | |
2250 |
2/2✓ Branch 0 taken 492 times.
✓ Branch 1 taken 1680 times.
|
2172 | if (pps->cu_qp_delta_enabled_flag) |
2251 | 492 | pps->diff_cu_qp_delta_depth = get_ue_golomb_long(gb); | |
2252 | |||
2253 |
1/2✓ Branch 0 taken 2172 times.
✗ Branch 1 not taken.
|
2172 | if (pps->diff_cu_qp_delta_depth < 0 || |
2254 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2172 times.
|
2172 | pps->diff_cu_qp_delta_depth > sps->log2_diff_max_min_coding_block_size) { |
2255 | ✗ | av_log(avctx, AV_LOG_ERROR, "diff_cu_qp_delta_depth %d is invalid\n", | |
2256 | ✗ | pps->diff_cu_qp_delta_depth); | |
2257 | ✗ | ret = AVERROR_INVALIDDATA; | |
2258 | ✗ | goto err; | |
2259 | } | ||
2260 | |||
2261 | 2172 | pps->cb_qp_offset = get_se_golomb(gb); | |
2262 |
2/4✓ Branch 0 taken 2172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2172 times.
|
2172 | if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) { |
2263 | ✗ | av_log(avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n", | |
2264 | ✗ | pps->cb_qp_offset); | |
2265 | ✗ | ret = AVERROR_INVALIDDATA; | |
2266 | ✗ | goto err; | |
2267 | } | ||
2268 | 2172 | pps->cr_qp_offset = get_se_golomb(gb); | |
2269 |
2/4✓ Branch 0 taken 2172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2172 times.
|
2172 | if (pps->cr_qp_offset < -12 || pps->cr_qp_offset > 12) { |
2270 | ✗ | av_log(avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n", | |
2271 | ✗ | pps->cr_qp_offset); | |
2272 | ✗ | ret = AVERROR_INVALIDDATA; | |
2273 | ✗ | goto err; | |
2274 | } | ||
2275 | 2172 | pps->pic_slice_level_chroma_qp_offsets_present_flag = get_bits1(gb); | |
2276 | |||
2277 | 2172 | pps->weighted_pred_flag = get_bits1(gb); | |
2278 | 2172 | pps->weighted_bipred_flag = get_bits1(gb); | |
2279 | |||
2280 | 2172 | pps->transquant_bypass_enable_flag = get_bits1(gb); | |
2281 | 2172 | pps->tiles_enabled_flag = get_bits1(gb); | |
2282 | 2172 | pps->entropy_coding_sync_enabled_flag = get_bits1(gb); | |
2283 | |||
2284 |
2/2✓ Branch 0 taken 747 times.
✓ Branch 1 taken 1425 times.
|
2172 | if (pps->tiles_enabled_flag) { |
2285 | 747 | int num_tile_columns_minus1 = get_ue_golomb(gb); | |
2286 | 747 | int num_tile_rows_minus1 = get_ue_golomb(gb); | |
2287 | |||
2288 |
1/2✓ Branch 0 taken 747 times.
✗ Branch 1 not taken.
|
747 | if (num_tile_columns_minus1 < 0 || |
2289 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
|
747 | num_tile_columns_minus1 >= sps->ctb_width) { |
2290 | ✗ | av_log(avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n", | |
2291 | num_tile_columns_minus1); | ||
2292 | ✗ | ret = num_tile_columns_minus1 < 0 ? num_tile_columns_minus1 : AVERROR_INVALIDDATA; | |
2293 | ✗ | goto err; | |
2294 | } | ||
2295 |
1/2✓ Branch 0 taken 747 times.
✗ Branch 1 not taken.
|
747 | if (num_tile_rows_minus1 < 0 || |
2296 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
|
747 | num_tile_rows_minus1 >= sps->ctb_height) { |
2297 | ✗ | av_log(avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n", | |
2298 | num_tile_rows_minus1); | ||
2299 | ✗ | ret = num_tile_rows_minus1 < 0 ? num_tile_rows_minus1 : AVERROR_INVALIDDATA; | |
2300 | ✗ | goto err; | |
2301 | } | ||
2302 | 747 | pps->num_tile_columns = num_tile_columns_minus1 + 1; | |
2303 | 747 | pps->num_tile_rows = num_tile_rows_minus1 + 1; | |
2304 | |||
2305 | 747 | pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width)); | |
2306 | 747 | pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height)); | |
2307 |
2/4✓ Branch 0 taken 747 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 747 times.
|
747 | if (!pps->column_width || !pps->row_height) { |
2308 | ✗ | ret = AVERROR(ENOMEM); | |
2309 | ✗ | goto err; | |
2310 | } | ||
2311 | |||
2312 | 747 | pps->uniform_spacing_flag = get_bits1(gb); | |
2313 |
2/2✓ Branch 0 taken 521 times.
✓ Branch 1 taken 226 times.
|
747 | if (!pps->uniform_spacing_flag) { |
2314 | 521 | uint64_t sum = 0; | |
2315 |
2/2✓ Branch 0 taken 2042 times.
✓ Branch 1 taken 521 times.
|
2563 | for (i = 0; i < pps->num_tile_columns - 1; i++) { |
2316 | 2042 | pps->column_width[i] = get_ue_golomb_long(gb) + 1; | |
2317 | 2042 | sum += pps->column_width[i]; | |
2318 | } | ||
2319 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 521 times.
|
521 | if (sum >= sps->ctb_width) { |
2320 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid tile widths.\n"); | |
2321 | ✗ | ret = AVERROR_INVALIDDATA; | |
2322 | ✗ | goto err; | |
2323 | } | ||
2324 | 521 | pps->column_width[pps->num_tile_columns - 1] = sps->ctb_width - sum; | |
2325 | |||
2326 | 521 | sum = 0; | |
2327 |
2/2✓ Branch 0 taken 2030 times.
✓ Branch 1 taken 521 times.
|
2551 | for (i = 0; i < pps->num_tile_rows - 1; i++) { |
2328 | 2030 | pps->row_height[i] = get_ue_golomb_long(gb) + 1; | |
2329 | 2030 | sum += pps->row_height[i]; | |
2330 | } | ||
2331 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 521 times.
|
521 | if (sum >= sps->ctb_height) { |
2332 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid tile heights.\n"); | |
2333 | ✗ | ret = AVERROR_INVALIDDATA; | |
2334 | ✗ | goto err; | |
2335 | } | ||
2336 | 521 | pps->row_height[pps->num_tile_rows - 1] = sps->ctb_height - sum; | |
2337 | } | ||
2338 | 747 | pps->loop_filter_across_tiles_enabled_flag = get_bits1(gb); | |
2339 | } | ||
2340 | |||
2341 | 2172 | pps->seq_loop_filter_across_slices_enabled_flag = get_bits1(gb); | |
2342 | |||
2343 | 2172 | pps->deblocking_filter_control_present_flag = get_bits1(gb); | |
2344 |
2/2✓ Branch 0 taken 881 times.
✓ Branch 1 taken 1291 times.
|
2172 | if (pps->deblocking_filter_control_present_flag) { |
2345 | 881 | pps->deblocking_filter_override_enabled_flag = get_bits1(gb); | |
2346 | 881 | pps->disable_dbf = get_bits1(gb); | |
2347 |
2/2✓ Branch 0 taken 755 times.
✓ Branch 1 taken 126 times.
|
881 | if (!pps->disable_dbf) { |
2348 | 755 | int beta_offset_div2 = get_se_golomb(gb); | |
2349 | 755 | int tc_offset_div2 = get_se_golomb(gb) ; | |
2350 |
2/4✓ Branch 0 taken 755 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 755 times.
|
755 | if (beta_offset_div2 < -6 || beta_offset_div2 > 6) { |
2351 | ✗ | av_log(avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n", | |
2352 | beta_offset_div2); | ||
2353 | ✗ | ret = AVERROR_INVALIDDATA; | |
2354 | ✗ | goto err; | |
2355 | } | ||
2356 |
2/4✓ Branch 0 taken 755 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 755 times.
|
755 | if (tc_offset_div2 < -6 || tc_offset_div2 > 6) { |
2357 | ✗ | av_log(avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n", | |
2358 | tc_offset_div2); | ||
2359 | ✗ | ret = AVERROR_INVALIDDATA; | |
2360 | ✗ | goto err; | |
2361 | } | ||
2362 | 755 | pps->beta_offset = 2 * beta_offset_div2; | |
2363 | 755 | pps->tc_offset = 2 * tc_offset_div2; | |
2364 | } | ||
2365 | } | ||
2366 | |||
2367 | 2172 | pps->scaling_list_data_present_flag = get_bits1(gb); | |
2368 |
2/2✓ Branch 0 taken 115 times.
✓ Branch 1 taken 2057 times.
|
2172 | if (pps->scaling_list_data_present_flag) { |
2369 | 115 | set_default_scaling_list_data(&pps->scaling_list); | |
2370 | 115 | ret = scaling_list_data(gb, avctx, &pps->scaling_list, sps); | |
2371 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
|
115 | if (ret < 0) |
2372 | ✗ | goto err; | |
2373 | } | ||
2374 | 2172 | pps->lists_modification_present_flag = get_bits1(gb); | |
2375 | 2172 | log2_parallel_merge_level_minus2 = get_ue_golomb_long(gb); | |
2376 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2172 times.
|
2172 | if (log2_parallel_merge_level_minus2 > sps->log2_ctb_size) { |
2377 | ✗ | av_log(avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n", | |
2378 | log2_parallel_merge_level_minus2); | ||
2379 | ✗ | ret = AVERROR_INVALIDDATA; | |
2380 | ✗ | goto err; | |
2381 | } | ||
2382 | 2172 | pps->log2_parallel_merge_level = log2_parallel_merge_level_minus2 + 2; | |
2383 | |||
2384 | 2172 | pps->slice_header_extension_present_flag = get_bits1(gb); | |
2385 | |||
2386 | 2172 | pps->pps_extension_present_flag = get_bits1(gb); | |
2387 |
2/2✓ Branch 0 taken 109 times.
✓ Branch 1 taken 2063 times.
|
2172 | if (pps->pps_extension_present_flag) { |
2388 | 109 | pps->pps_range_extensions_flag = get_bits1(gb); | |
2389 | 109 | pps->pps_multilayer_extension_flag = get_bits1(gb); | |
2390 | 109 | pps->pps_3d_extension_flag = get_bits1(gb); | |
2391 | 109 | pps->pps_scc_extension_flag = get_bits1(gb); | |
2392 | 109 | skip_bits(gb, 4); // pps_extension_4bits | |
2393 | |||
2394 |
3/4✓ Branch 0 taken 63 times.
✓ Branch 1 taken 46 times.
✓ Branch 2 taken 63 times.
✗ Branch 3 not taken.
|
109 | if (sps->ptl.general_ptl.profile_idc >= AV_PROFILE_HEVC_REXT && pps->pps_range_extensions_flag) { |
2395 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
|
63 | if ((ret = pps_range_extensions(gb, avctx, pps, sps)) < 0) |
2396 | ✗ | goto err; | |
2397 | } | ||
2398 | |||
2399 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 66 times.
|
109 | if (pps->pps_multilayer_extension_flag) { |
2400 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
|
43 | if ((ret = pps_multilayer_extension(gb, avctx, pps, sps, vps)) < 0) |
2401 | ✗ | goto err; | |
2402 | } | ||
2403 | |||
2404 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 106 times.
|
109 | if (pps->pps_3d_extension_flag) { |
2405 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = pps_3d_extension(gb, avctx, pps, sps)) < 0) |
2406 | ✗ | goto err; | |
2407 | } | ||
2408 | |||
2409 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 106 times.
|
109 | if (pps->pps_scc_extension_flag) { |
2410 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = pps_scc_extension(gb, avctx, pps, sps)) < 0) |
2411 | ✗ | goto err; | |
2412 | } | ||
2413 | } | ||
2414 | |||
2415 | 2172 | ret = setup_pps(avctx, gb, pps, sps); | |
2416 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2172 times.
|
2172 | if (ret < 0) |
2417 | ✗ | goto err; | |
2418 | |||
2419 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2169 times.
|
2172 | if (get_bits_left(gb) < 0) { |
2420 | 3 | av_log(avctx, AV_LOG_WARNING, | |
2421 | 3 | "Overread PPS by %d bits\n", -get_bits_left(gb)); | |
2422 | } | ||
2423 | |||
2424 | 2172 | av_refstruct_unref(&ps->pps_list[pps_id]); | |
2425 | 2172 | ps->pps_list[pps_id] = pps; | |
2426 | |||
2427 | 2172 | return 0; | |
2428 | |||
2429 | 4 | err: | |
2430 | 4 | av_refstruct_unref(&pps); | |
2431 | 4 | return ret; | |
2432 | } | ||
2433 | |||
2434 | 721 | void ff_hevc_ps_uninit(HEVCParamSets *ps) | |
2435 | { | ||
2436 | int i; | ||
2437 | |||
2438 |
2/2✓ Branch 0 taken 11536 times.
✓ Branch 1 taken 721 times.
|
12257 | for (i = 0; i < FF_ARRAY_ELEMS(ps->vps_list); i++) |
2439 | 11536 | av_refstruct_unref(&ps->vps_list[i]); | |
2440 |
2/2✓ Branch 0 taken 11536 times.
✓ Branch 1 taken 721 times.
|
12257 | for (i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++) |
2441 | 11536 | av_refstruct_unref(&ps->sps_list[i]); | |
2442 |
2/2✓ Branch 0 taken 46144 times.
✓ Branch 1 taken 721 times.
|
46865 | for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++) |
2443 | 46144 | av_refstruct_unref(&ps->pps_list[i]); | |
2444 | 721 | } | |
2445 | |||
2446 | 31867 | int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type) | |
2447 | { | ||
2448 | 31867 | int max_poc_lsb = 1 << sps->log2_max_poc_lsb; | |
2449 | 31867 | int prev_poc_lsb = pocTid0 % max_poc_lsb; | |
2450 | 31867 | int prev_poc_msb = pocTid0 - prev_poc_lsb; | |
2451 | int poc_msb; | ||
2452 | |||
2453 |
4/4✓ Branch 0 taken 10826 times.
✓ Branch 1 taken 21041 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 10786 times.
|
31867 | if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2) |
2454 | 40 | poc_msb = prev_poc_msb + max_poc_lsb; | |
2455 |
4/4✓ Branch 0 taken 15239 times.
✓ Branch 1 taken 16588 times.
✓ Branch 2 taken 316 times.
✓ Branch 3 taken 14923 times.
|
31827 | else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2) |
2456 | 316 | poc_msb = prev_poc_msb - max_poc_lsb; | |
2457 | else | ||
2458 | 31511 | poc_msb = prev_poc_msb; | |
2459 | |||
2460 | // For BLA picture types, POCmsb is set to 0. | ||
2461 |
4/4✓ Branch 0 taken 31852 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 31846 times.
✓ Branch 3 taken 6 times.
|
31867 | if (nal_unit_type == HEVC_NAL_BLA_W_LP || |
2462 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 31843 times.
|
31846 | nal_unit_type == HEVC_NAL_BLA_W_RADL || |
2463 | nal_unit_type == HEVC_NAL_BLA_N_LP) | ||
2464 | 24 | poc_msb = 0; | |
2465 | |||
2466 | 31867 | return poc_msb + poc_lsb; | |
2467 | } | ||
2468 |