Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * HEVC video Decoder | ||
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) 2012 - 2013 Wassim Hamidouche | ||
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 "config_components.h" | ||
27 | |||
28 | #include "libavutil/attributes.h" | ||
29 | #include "libavutil/avstring.h" | ||
30 | #include "libavutil/common.h" | ||
31 | #include "libavutil/container_fifo.h" | ||
32 | #include "libavutil/film_grain_params.h" | ||
33 | #include "libavutil/internal.h" | ||
34 | #include "libavutil/md5.h" | ||
35 | #include "libavutil/mem.h" | ||
36 | #include "libavutil/opt.h" | ||
37 | #include "libavutil/pixdesc.h" | ||
38 | #include "libavutil/stereo3d.h" | ||
39 | #include "libavutil/timecode.h" | ||
40 | |||
41 | #include "aom_film_grain.h" | ||
42 | #include "bswapdsp.h" | ||
43 | #include "cabac_functions.h" | ||
44 | #include "codec_internal.h" | ||
45 | #include "decode.h" | ||
46 | #include "golomb.h" | ||
47 | #include "hevc.h" | ||
48 | #include "parse.h" | ||
49 | #include "hevcdec.h" | ||
50 | #include "hwaccel_internal.h" | ||
51 | #include "hwconfig.h" | ||
52 | #include "internal.h" | ||
53 | #include "profiles.h" | ||
54 | #include "progressframe.h" | ||
55 | #include "libavutil/refstruct.h" | ||
56 | #include "thread.h" | ||
57 | #include "threadprogress.h" | ||
58 | |||
59 | static const uint8_t hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, [12] = 4, [16] = 5, [24] = 6, [32] = 7, [48] = 8, [64] = 9 }; | ||
60 | |||
61 | /** | ||
62 | * NOTE: Each function hls_foo correspond to the function foo in the | ||
63 | * specification (HLS stands for High Level Syntax). | ||
64 | */ | ||
65 | |||
66 | /** | ||
67 | * Section 5.7 | ||
68 | */ | ||
69 | |||
70 | /* free everything allocated by pic_arrays_init() */ | ||
71 | 1334 | static void pic_arrays_free(HEVCLayerContext *l) | |
72 | { | ||
73 | 1334 | av_freep(&l->sao); | |
74 | 1334 | av_freep(&l->deblock); | |
75 | |||
76 | 1334 | av_freep(&l->skip_flag); | |
77 | 1334 | av_freep(&l->tab_ct_depth); | |
78 | |||
79 | 1334 | av_freep(&l->tab_ipm); | |
80 | 1334 | av_freep(&l->cbf_luma); | |
81 | 1334 | av_freep(&l->is_pcm); | |
82 | |||
83 | 1334 | av_freep(&l->qp_y_tab); | |
84 | 1334 | av_freep(&l->tab_slice_address); | |
85 | 1334 | av_freep(&l->filter_slice_edges); | |
86 | |||
87 | 1334 | av_freep(&l->horizontal_bs); | |
88 | 1334 | av_freep(&l->vertical_bs); | |
89 | |||
90 |
2/2✓ Branch 0 taken 4002 times.
✓ Branch 1 taken 1334 times.
|
5336 | for (int i = 0; i < 3; i++) { |
91 | 4002 | av_freep(&l->sao_pixel_buffer_h[i]); | |
92 | 4002 | av_freep(&l->sao_pixel_buffer_v[i]); | |
93 | } | ||
94 | |||
95 | 1334 | av_refstruct_pool_uninit(&l->tab_mvf_pool); | |
96 | 1334 | av_refstruct_pool_uninit(&l->rpl_tab_pool); | |
97 | 1334 | } | |
98 | |||
99 | /* allocate arrays that depend on frame dimensions */ | ||
100 | 414 | static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps) | |
101 | { | ||
102 | 414 | int log2_min_cb_size = sps->log2_min_cb_size; | |
103 | 414 | int width = sps->width; | |
104 | 414 | int height = sps->height; | |
105 | 414 | int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) * | |
106 | 414 | ((height >> log2_min_cb_size) + 1); | |
107 | 414 | int ctb_count = sps->ctb_width * sps->ctb_height; | |
108 | 414 | int min_pu_size = sps->min_pu_width * sps->min_pu_height; | |
109 | |||
110 | 414 | l->bs_width = (width >> 2) + 1; | |
111 | 414 | l->bs_height = (height >> 2) + 1; | |
112 | |||
113 | 414 | l->sao = av_calloc(ctb_count, sizeof(*l->sao)); | |
114 | 414 | l->deblock = av_calloc(ctb_count, sizeof(*l->deblock)); | |
115 |
2/4✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
|
414 | if (!l->sao || !l->deblock) |
116 | ✗ | goto fail; | |
117 | |||
118 | 414 | l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
119 | 414 | l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
120 |
2/4✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
|
414 | if (!l->skip_flag || !l->tab_ct_depth) |
121 | ✗ | goto fail; | |
122 | |||
123 | 414 | l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height); | |
124 | 414 | l->tab_ipm = av_mallocz(min_pu_size); | |
125 | 414 | l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1); | |
126 |
3/6✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 414 times.
|
414 | if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm) |
127 | ✗ | goto fail; | |
128 | |||
129 | 414 | l->filter_slice_edges = av_mallocz(ctb_count); | |
130 | 414 | l->tab_slice_address = av_malloc_array(pic_size_in_ctb, | |
131 | sizeof(*l->tab_slice_address)); | ||
132 | 414 | l->qp_y_tab = av_calloc(pic_size_in_ctb, | |
133 | sizeof(*l->qp_y_tab)); | ||
134 |
3/6✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 414 times.
|
414 | if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address) |
135 | ✗ | goto fail; | |
136 | |||
137 | 414 | l->horizontal_bs = av_calloc(l->bs_width, l->bs_height); | |
138 | 414 | l->vertical_bs = av_calloc(l->bs_width, l->bs_height); | |
139 |
2/4✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
|
414 | if (!l->horizontal_bs || !l->vertical_bs) |
140 | ✗ | goto fail; | |
141 | |||
142 | 414 | l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0); | |
143 | 414 | l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0); | |
144 |
2/4✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
|
414 | if (!l->tab_mvf_pool || !l->rpl_tab_pool) |
145 | ✗ | goto fail; | |
146 | |||
147 |
2/2✓ Branch 0 taken 359 times.
✓ Branch 1 taken 55 times.
|
414 | if (sps->sao_enabled) { |
148 |
2/2✓ Branch 0 taken 357 times.
✓ Branch 1 taken 2 times.
|
359 | int c_count = (sps->chroma_format_idc != 0) ? 3 : 1; |
149 | |||
150 |
2/2✓ Branch 0 taken 1073 times.
✓ Branch 1 taken 359 times.
|
1432 | for (int c_idx = 0; c_idx < c_count; c_idx++) { |
151 | 1073 | int w = sps->width >> sps->hshift[c_idx]; | |
152 | 1073 | int h = sps->height >> sps->vshift[c_idx]; | |
153 | 1073 | l->sao_pixel_buffer_h[c_idx] = | |
154 | 1073 | av_malloc((w * 2 * sps->ctb_height) << | |
155 | 1073 | sps->pixel_shift); | |
156 | 1073 | l->sao_pixel_buffer_v[c_idx] = | |
157 | 1073 | av_malloc((h * 2 * sps->ctb_width) << | |
158 | 1073 | sps->pixel_shift); | |
159 |
1/2✓ Branch 0 taken 1073 times.
✗ Branch 1 not taken.
|
1073 | if (!l->sao_pixel_buffer_h[c_idx] || |
160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1073 times.
|
1073 | !l->sao_pixel_buffer_v[c_idx]) |
161 | ✗ | goto fail; | |
162 | } | ||
163 | } | ||
164 | |||
165 | 414 | return 0; | |
166 | |||
167 | ✗ | fail: | |
168 | ✗ | pic_arrays_free(l); | |
169 | ✗ | return AVERROR(ENOMEM); | |
170 | } | ||
171 | |||
172 | 1443 | static int pred_weight_table(SliceHeader *sh, void *logctx, | |
173 | const HEVCSPS *sps, GetBitContext *gb) | ||
174 | { | ||
175 | 1443 | int i = 0; | |
176 | 1443 | int j = 0; | |
177 | uint8_t luma_weight_l0_flag[16]; | ||
178 | uint8_t chroma_weight_l0_flag[16]; | ||
179 | uint8_t luma_weight_l1_flag[16]; | ||
180 | uint8_t chroma_weight_l1_flag[16]; | ||
181 | int luma_log2_weight_denom; | ||
182 | |||
183 | 1443 | luma_log2_weight_denom = get_ue_golomb_long(gb); | |
184 |
2/4✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1443 times.
|
1443 | if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) { |
185 | ✗ | av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom); | |
186 | ✗ | return AVERROR_INVALIDDATA; | |
187 | } | ||
188 | 1443 | sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3); | |
189 |
1/2✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
|
1443 | if (sps->chroma_format_idc != 0) { |
190 | 1443 | int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb); | |
191 |
2/4✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1443 times.
|
1443 | if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) { |
192 | ✗ | av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom); | |
193 | ✗ | return AVERROR_INVALIDDATA; | |
194 | } | ||
195 | 1443 | sh->chroma_log2_weight_denom = chroma_log2_weight_denom; | |
196 | } | ||
197 | |||
198 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < sh->nb_refs[L0]; i++) { |
199 | 4407 | luma_weight_l0_flag[i] = get_bits1(gb); | |
200 |
2/2✓ Branch 0 taken 1290 times.
✓ Branch 1 taken 3117 times.
|
4407 | if (!luma_weight_l0_flag[i]) { |
201 | 1290 | sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom; | |
202 | 1290 | sh->luma_offset_l0[i] = 0; | |
203 | } | ||
204 | } | ||
205 |
1/2✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
|
1443 | if (sps->chroma_format_idc != 0) { |
206 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < sh->nb_refs[L0]; i++) |
207 | 4407 | chroma_weight_l0_flag[i] = get_bits1(gb); | |
208 | } else { | ||
209 | ✗ | for (i = 0; i < sh->nb_refs[L0]; i++) | |
210 | ✗ | chroma_weight_l0_flag[i] = 0; | |
211 | } | ||
212 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < sh->nb_refs[L0]; i++) { |
213 |
2/2✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1290 times.
|
4407 | if (luma_weight_l0_flag[i]) { |
214 | 3117 | int delta_luma_weight_l0 = get_se_golomb(gb); | |
215 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
|
3117 | if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0) |
216 | ✗ | return AVERROR_INVALIDDATA; | |
217 | 3117 | sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0; | |
218 | 3117 | sh->luma_offset_l0[i] = get_se_golomb(gb); | |
219 | } | ||
220 |
2/2✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3276 times.
|
4407 | if (chroma_weight_l0_flag[i]) { |
221 |
2/2✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
|
3393 | for (j = 0; j < 2; j++) { |
222 | 2262 | int delta_chroma_weight_l0 = get_se_golomb(gb); | |
223 | 2262 | int delta_chroma_offset_l0 = get_se_golomb(gb); | |
224 | |||
225 |
1/2✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
|
2262 | if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0 |
226 |
2/4✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2262 times.
|
2262 | || delta_chroma_offset_l0 < -(1<<17) || delta_chroma_offset_l0 > (1<<17)) { |
227 | ✗ | return AVERROR_INVALIDDATA; | |
228 | } | ||
229 | |||
230 | 2262 | sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0; | |
231 | 2262 | sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j]) | |
232 | 2262 | >> sh->chroma_log2_weight_denom) + 128), -128, 127); | |
233 | } | ||
234 | } else { | ||
235 | 3276 | sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom; | |
236 | 3276 | sh->chroma_offset_l0[i][0] = 0; | |
237 | 3276 | sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom; | |
238 | 3276 | sh->chroma_offset_l0[i][1] = 0; | |
239 | } | ||
240 | } | ||
241 |
2/2✓ Branch 0 taken 668 times.
✓ Branch 1 taken 775 times.
|
1443 | if (sh->slice_type == HEVC_SLICE_B) { |
242 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < sh->nb_refs[L1]; i++) { |
243 | 1347 | luma_weight_l1_flag[i] = get_bits1(gb); | |
244 |
2/2✓ Branch 0 taken 601 times.
✓ Branch 1 taken 746 times.
|
1347 | if (!luma_weight_l1_flag[i]) { |
245 | 601 | sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom; | |
246 | 601 | sh->luma_offset_l1[i] = 0; | |
247 | } | ||
248 | } | ||
249 |
1/2✓ Branch 0 taken 668 times.
✗ Branch 1 not taken.
|
668 | if (sps->chroma_format_idc != 0) { |
250 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < sh->nb_refs[L1]; i++) |
251 | 1347 | chroma_weight_l1_flag[i] = get_bits1(gb); | |
252 | } else { | ||
253 | ✗ | for (i = 0; i < sh->nb_refs[L1]; i++) | |
254 | ✗ | chroma_weight_l1_flag[i] = 0; | |
255 | } | ||
256 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < sh->nb_refs[L1]; i++) { |
257 |
2/2✓ Branch 0 taken 746 times.
✓ Branch 1 taken 601 times.
|
1347 | if (luma_weight_l1_flag[i]) { |
258 | 746 | int delta_luma_weight_l1 = get_se_golomb(gb); | |
259 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
|
746 | if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1) |
260 | ✗ | return AVERROR_INVALIDDATA; | |
261 | 746 | sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1; | |
262 | 746 | sh->luma_offset_l1[i] = get_se_golomb(gb); | |
263 | } | ||
264 |
2/2✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1111 times.
|
1347 | if (chroma_weight_l1_flag[i]) { |
265 |
2/2✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
|
708 | for (j = 0; j < 2; j++) { |
266 | 472 | int delta_chroma_weight_l1 = get_se_golomb(gb); | |
267 | 472 | int delta_chroma_offset_l1 = get_se_golomb(gb); | |
268 | |||
269 |
1/2✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
|
472 | if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1 |
270 |
2/4✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 472 times.
|
472 | || delta_chroma_offset_l1 < -(1<<17) || delta_chroma_offset_l1 > (1<<17)) { |
271 | ✗ | return AVERROR_INVALIDDATA; | |
272 | } | ||
273 | |||
274 | 472 | sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1; | |
275 | 472 | sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j]) | |
276 | 472 | >> sh->chroma_log2_weight_denom) + 128), -128, 127); | |
277 | } | ||
278 | } else { | ||
279 | 1111 | sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom; | |
280 | 1111 | sh->chroma_offset_l1[i][0] = 0; | |
281 | 1111 | sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom; | |
282 | 1111 | sh->chroma_offset_l1[i][1] = 0; | |
283 | } | ||
284 | } | ||
285 | } | ||
286 | 1443 | return 0; | |
287 | } | ||
288 | |||
289 | 19673 | static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps, | |
290 | GetBitContext *gb, int cur_poc, int poc_lsb) | ||
291 | { | ||
292 | 19673 | int max_poc_lsb = 1 << sps->log2_max_poc_lsb; | |
293 | 19673 | int prev_delta_msb = 0; | |
294 | 19673 | unsigned int nb_sps = 0, nb_sh; | |
295 | int i; | ||
296 | |||
297 | 19673 | rps->nb_refs = 0; | |
298 |
2/2✓ Branch 0 taken 18637 times.
✓ Branch 1 taken 1036 times.
|
19673 | if (!sps->long_term_ref_pics_present) |
299 | 18637 | return 0; | |
300 | |||
301 |
2/2✓ Branch 0 taken 499 times.
✓ Branch 1 taken 537 times.
|
1036 | if (sps->num_long_term_ref_pics_sps > 0) |
302 | 499 | nb_sps = get_ue_golomb_long(gb); | |
303 | 1036 | nb_sh = get_ue_golomb_long(gb); | |
304 | |||
305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
|
1036 | if (nb_sps > sps->num_long_term_ref_pics_sps) |
306 | ✗ | return AVERROR_INVALIDDATA; | |
307 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
|
1036 | if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc)) |
308 | ✗ | return AVERROR_INVALIDDATA; | |
309 | |||
310 | 1036 | rps->nb_refs = nb_sh + nb_sps; | |
311 | |||
312 |
2/2✓ Branch 0 taken 1562 times.
✓ Branch 1 taken 1036 times.
|
2598 | for (i = 0; i < rps->nb_refs; i++) { |
313 | |||
314 |
2/2✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1378 times.
|
1562 | if (i < nb_sps) { |
315 | 184 | uint8_t lt_idx_sps = 0; | |
316 | |||
317 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (sps->num_long_term_ref_pics_sps > 1) |
318 | 184 | lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps)); | |
319 | |||
320 | 184 | rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps]; | |
321 | 184 | rps->used[i] = !!(sps->used_by_curr_pic_lt & (1U << lt_idx_sps)); | |
322 | } else { | ||
323 | 1378 | rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb); | |
324 | 1378 | rps->used[i] = get_bits1(gb); | |
325 | } | ||
326 | |||
327 | 1562 | rps->poc_msb_present[i] = get_bits1(gb); | |
328 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1514 times.
|
1562 | if (rps->poc_msb_present[i]) { |
329 | 48 | int64_t delta = get_ue_golomb_long(gb); | |
330 | int64_t poc; | ||
331 | |||
332 |
3/4✓ Branch 0 taken 31 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
|
48 | if (i && i != nb_sps) |
333 | 31 | delta += prev_delta_msb; | |
334 | |||
335 | 48 | poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb; | |
336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (poc != (int32_t)poc) |
337 | ✗ | return AVERROR_INVALIDDATA; | |
338 | 48 | rps->poc[i] = poc; | |
339 | 48 | prev_delta_msb = delta; | |
340 | } | ||
341 | } | ||
342 | |||
343 | 1036 | return 0; | |
344 | } | ||
345 | |||
346 | 656 | static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) | |
347 | { | ||
348 | 656 | AVCodecContext *avctx = s->avctx; | |
349 | 656 | const HEVCVPS *vps = sps->vps; | |
350 | 656 | const HEVCWindow *ow = &sps->output_window; | |
351 | 656 | unsigned int num = 0, den = 0; | |
352 | |||
353 | 656 | avctx->pix_fmt = sps->pix_fmt; | |
354 | 656 | avctx->coded_width = sps->width; | |
355 | 656 | avctx->coded_height = sps->height; | |
356 | 656 | avctx->width = sps->width - ow->left_offset - ow->right_offset; | |
357 | 656 | avctx->height = sps->height - ow->top_offset - ow->bottom_offset; | |
358 | 656 | avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics; | |
359 | 656 | avctx->profile = sps->ptl.general_ptl.profile_idc; | |
360 | 656 | avctx->level = sps->ptl.general_ptl.level_idc; | |
361 | |||
362 | 656 | ff_set_sar(avctx, sps->vui.common.sar); | |
363 | |||
364 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 600 times.
|
656 | if (sps->vui.common.video_signal_type_present_flag) |
365 | 56 | avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG | |
366 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 50 times.
|
56 | : AVCOL_RANGE_MPEG; |
367 | else | ||
368 | 600 | avctx->color_range = AVCOL_RANGE_MPEG; | |
369 | |||
370 |
2/2✓ Branch 0 taken 49 times.
✓ Branch 1 taken 607 times.
|
656 | if (sps->vui.common.colour_description_present_flag) { |
371 | 49 | avctx->color_primaries = sps->vui.common.colour_primaries; | |
372 | 49 | avctx->color_trc = sps->vui.common.transfer_characteristics; | |
373 | 49 | avctx->colorspace = sps->vui.common.matrix_coeffs; | |
374 | } else { | ||
375 | 607 | avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; | |
376 | 607 | avctx->color_trc = AVCOL_TRC_UNSPECIFIED; | |
377 | 607 | avctx->colorspace = AVCOL_SPC_UNSPECIFIED; | |
378 | } | ||
379 | |||
380 | 656 | avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED; | |
381 |
2/2✓ Branch 0 taken 615 times.
✓ Branch 1 taken 41 times.
|
656 | if (sps->chroma_format_idc == 1) { |
382 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 596 times.
|
615 | if (sps->vui.common.chroma_loc_info_present_flag) { |
383 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | if (sps->vui.common.chroma_sample_loc_type_top_field <= 5) |
384 | 19 | avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1; | |
385 | } else | ||
386 | 596 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; | |
387 | } | ||
388 | |||
389 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 634 times.
|
656 | if (vps->vps_timing_info_present_flag) { |
390 | 22 | num = vps->vps_num_units_in_tick; | |
391 | 22 | den = vps->vps_time_scale; | |
392 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 578 times.
|
634 | } else if (sps->vui.vui_timing_info_present_flag) { |
393 | 56 | num = sps->vui.vui_num_units_in_tick; | |
394 | 56 | den = sps->vui.vui_time_scale; | |
395 | } | ||
396 | |||
397 |
3/4✓ Branch 0 taken 78 times.
✓ Branch 1 taken 578 times.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
|
656 | if (num > 0 && den > 0) |
398 | 78 | av_reduce(&avctx->framerate.den, &avctx->framerate.num, | |
399 | num, den, 1 << 30); | ||
400 | 656 | } | |
401 | |||
402 | 10424 | static int export_stream_params_from_sei(HEVCContext *s) | |
403 | { | ||
404 | 10424 | AVCodecContext *avctx = s->avctx; | |
405 | |||
406 | #if FF_API_CODEC_PROPS | ||
407 | FF_DISABLE_DEPRECATION_WARNINGS | ||
408 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10424 times.
|
10424 | if (s->sei.common.a53_caption.buf_ref) |
409 | ✗ | s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; | |
410 | FF_ENABLE_DEPRECATION_WARNINGS | ||
411 | #endif | ||
412 | |||
413 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10424 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10424 | if (s->sei.common.alternative_transfer.present && |
414 | ✗ | av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) && | |
415 | ✗ | s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) { | |
416 | ✗ | avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics; | |
417 | } | ||
418 | |||
419 | #if FF_API_CODEC_PROPS | ||
420 | FF_DISABLE_DEPRECATION_WARNINGS | ||
421 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10424 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10424 | if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) || |
422 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10424 times.
|
10424 | s->sei.common.aom_film_grain.enable) |
423 | ✗ | avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; | |
424 | FF_ENABLE_DEPRECATION_WARNINGS | ||
425 | #endif | ||
426 | |||
427 | 10424 | return 0; | |
428 | } | ||
429 | |||
430 | 656 | static int export_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
431 | { | ||
432 | 656 | const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi; | |
433 | |||
434 | 656 | av_freep(&s->view_ids_available); | |
435 | 656 | s->nb_view_ids_available = 0; | |
436 | 656 | av_freep(&s->view_pos_available); | |
437 | 656 | s->nb_view_pos_available = 0; | |
438 | |||
439 | // don't export anything in the trivial case (1 layer, view id=0) | ||
440 |
3/4✓ Branch 0 taken 634 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 634 times.
✗ Branch 3 not taken.
|
656 | if (vps->nb_layers < 2 && !vps->view_id[0]) |
441 | 634 | return 0; | |
442 | |||
443 | 22 | s->view_ids_available = av_calloc(vps->nb_layers, sizeof(*s->view_ids_available)); | |
444 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | if (!s->view_ids_available) |
445 | ✗ | return AVERROR(ENOMEM); | |
446 | |||
447 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
|
22 | if (tdrdi->num_ref_displays) { |
448 | 5 | s->view_pos_available = av_calloc(vps->nb_layers, sizeof(*s->view_pos_available)); | |
449 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!s->view_pos_available) |
450 | ✗ | return AVERROR(ENOMEM); | |
451 | } | ||
452 | |||
453 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 22 times.
|
66 | for (int i = 0; i < vps->nb_layers; i++) { |
454 | 44 | s->view_ids_available[i] = vps->view_id[i]; | |
455 | |||
456 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 34 times.
|
44 | if (s->view_pos_available) { |
457 | 10 | s->view_pos_available[i] = vps->view_id[i] == tdrdi->left_view_id[0] ? | |
458 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
15 | AV_STEREO3D_VIEW_LEFT : |
459 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | vps->view_id[i] == tdrdi->right_view_id[0] ? |
460 | AV_STEREO3D_VIEW_RIGHT : AV_STEREO3D_VIEW_UNSPEC; | ||
461 | } | ||
462 | } | ||
463 | 22 | s->nb_view_ids_available = vps->nb_layers; | |
464 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
|
22 | s->nb_view_pos_available = s->view_pos_available ? vps->nb_layers : 0; |
465 | |||
466 | 22 | return 0; | |
467 | } | ||
468 | |||
469 | 405 | static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
470 | { | ||
471 | 405 | unsigned layers_active_output = 0, highest_layer; | |
472 | |||
473 | 405 | s->layers_active_output = 1; | |
474 | 405 | s->layers_active_decode = 1; | |
475 | |||
476 | // nothing requested - decode base layer only | ||
477 |
2/2✓ Branch 0 taken 395 times.
✓ Branch 1 taken 10 times.
|
405 | if (!s->nb_view_ids) |
478 | 395 | return 0; | |
479 | |||
480 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
10 | if (s->nb_view_ids == 1 && s->view_ids[0] == -1) { |
481 | ✗ | layers_active_output = (1 << vps->nb_layers) - 1; | |
482 | } else { | ||
483 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 10 times.
|
28 | for (int i = 0; i < s->nb_view_ids; i++) { |
484 | 18 | int view_id = s->view_ids[i]; | |
485 | 18 | int layer_idx = -1; | |
486 | |||
487 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (view_id < 0) { |
488 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
489 | "Invalid view ID requested: %d\n", view_id); | ||
490 | ✗ | return AVERROR(EINVAL); | |
491 | } | ||
492 | |||
493 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | for (int j = 0; j < vps->nb_layers; j++) { |
494 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
|
26 | if (vps->view_id[j] == view_id) { |
495 | 18 | layer_idx = j; | |
496 | 18 | break; | |
497 | } | ||
498 | } | ||
499 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (layer_idx < 0) { |
500 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
501 | "View ID %d not present in VPS\n", view_id); | ||
502 | ✗ | return AVERROR(EINVAL); | |
503 | } | ||
504 | 18 | layers_active_output |= 1 << layer_idx; | |
505 | } | ||
506 | } | ||
507 | |||
508 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (!layers_active_output) { |
509 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No layers selected\n"); | |
510 | ✗ | return AVERROR_BUG; | |
511 | } | ||
512 | |||
513 | 10 | highest_layer = ff_log2(layers_active_output); | |
514 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (highest_layer >= FF_ARRAY_ELEMS(s->layers)) { |
515 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
516 | "Too many layers requested: %u\n", layers_active_output); | ||
517 | ✗ | return AVERROR(EINVAL); | |
518 | } | ||
519 | |||
520 | /* Assume a higher layer depends on all the lower ones. | ||
521 | * This is enforced in VPS parsing currently, this logic will need | ||
522 | * to be changed if we want to support more complex dependency structures. | ||
523 | */ | ||
524 | 10 | s->layers_active_decode = (1 << (highest_layer + 1)) - 1; | |
525 | 10 | s->layers_active_output = layers_active_output; | |
526 | |||
527 | 10 | av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n", | |
528 | s->layers_active_decode, s->layers_active_output); | ||
529 | |||
530 | 10 | return 0; | |
531 | } | ||
532 | |||
533 | 405 | static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) | |
534 | { | ||
535 | #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \ | ||
536 | CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \ | ||
537 | CONFIG_HEVC_D3D12VA_HWACCEL + \ | ||
538 | CONFIG_HEVC_NVDEC_HWACCEL + \ | ||
539 | CONFIG_HEVC_VAAPI_HWACCEL + \ | ||
540 | CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \ | ||
541 | CONFIG_HEVC_VDPAU_HWACCEL + \ | ||
542 | CONFIG_HEVC_VULKAN_HWACCEL) | ||
543 | 405 | enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts; | |
544 | int ret; | ||
545 | |||
546 |
6/7✓ Branch 0 taken 342 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
|
405 | switch (sps->pix_fmt) { |
547 | 342 | case AV_PIX_FMT_YUV420P: | |
548 | case AV_PIX_FMT_YUVJ420P: | ||
549 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
550 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
551 | #endif | ||
552 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
553 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
554 | *fmt++ = AV_PIX_FMT_D3D11; | ||
555 | #endif | ||
556 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
557 | *fmt++ = AV_PIX_FMT_D3D12; | ||
558 | #endif | ||
559 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
560 | 342 | *fmt++ = AV_PIX_FMT_VAAPI; | |
561 | #endif | ||
562 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
563 | 342 | *fmt++ = AV_PIX_FMT_VDPAU; | |
564 | #endif | ||
565 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
566 | *fmt++ = AV_PIX_FMT_CUDA; | ||
567 | #endif | ||
568 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
569 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
570 | #endif | ||
571 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
572 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
573 | #endif | ||
574 | 342 | break; | |
575 | 35 | case AV_PIX_FMT_YUV420P10: | |
576 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
577 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
578 | #endif | ||
579 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
580 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
581 | *fmt++ = AV_PIX_FMT_D3D11; | ||
582 | #endif | ||
583 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
584 | *fmt++ = AV_PIX_FMT_D3D12; | ||
585 | #endif | ||
586 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
587 | 35 | *fmt++ = AV_PIX_FMT_VAAPI; | |
588 | #endif | ||
589 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
590 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
591 | #endif | ||
592 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
593 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
594 | #endif | ||
595 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
596 | 35 | *fmt++ = AV_PIX_FMT_VDPAU; | |
597 | #endif | ||
598 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
599 | *fmt++ = AV_PIX_FMT_CUDA; | ||
600 | #endif | ||
601 | 35 | break; | |
602 | 4 | case AV_PIX_FMT_YUV444P: | |
603 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
604 | 4 | *fmt++ = AV_PIX_FMT_VAAPI; | |
605 | #endif | ||
606 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
607 | 4 | *fmt++ = AV_PIX_FMT_VDPAU; | |
608 | #endif | ||
609 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
610 | *fmt++ = AV_PIX_FMT_CUDA; | ||
611 | #endif | ||
612 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
613 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
614 | #endif | ||
615 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
616 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
617 | #endif | ||
618 | 4 | break; | |
619 | 12 | case AV_PIX_FMT_YUV422P: | |
620 | case AV_PIX_FMT_YUV422P10LE: | ||
621 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
622 | 12 | *fmt++ = AV_PIX_FMT_VAAPI; | |
623 | #endif | ||
624 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
625 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
626 | #endif | ||
627 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
628 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
629 | #endif | ||
630 | 12 | break; | |
631 | 10 | case AV_PIX_FMT_YUV444P10: | |
632 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
633 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
634 | #endif | ||
635 | /* NOTE: fallthrough */ | ||
636 | case AV_PIX_FMT_YUV420P12: | ||
637 | case AV_PIX_FMT_YUV444P12: | ||
638 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
639 | 10 | *fmt++ = AV_PIX_FMT_VAAPI; | |
640 | #endif | ||
641 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
642 | 10 | *fmt++ = AV_PIX_FMT_VDPAU; | |
643 | #endif | ||
644 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
645 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
646 | #endif | ||
647 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
648 | *fmt++ = AV_PIX_FMT_CUDA; | ||
649 | #endif | ||
650 | 10 | break; | |
651 | ✗ | case AV_PIX_FMT_YUV422P12: | |
652 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
653 | ✗ | *fmt++ = AV_PIX_FMT_VAAPI; | |
654 | #endif | ||
655 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
656 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
657 | #endif | ||
658 | ✗ | break; | |
659 | } | ||
660 | |||
661 | 405 | *fmt++ = sps->pix_fmt; | |
662 | 405 | *fmt = AV_PIX_FMT_NONE; | |
663 | |||
664 | // export multilayer information from active VPS to the caller, | ||
665 | // so it is available in get_format() | ||
666 | 405 | ret = export_multilayer(s, sps->vps); | |
667 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
|
405 | if (ret < 0) |
668 | ✗ | return ret; | |
669 | |||
670 | 405 | ret = ff_get_format(s->avctx, pix_fmts); | |
671 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
|
405 | if (ret < 0) |
672 | ✗ | return ret; | |
673 | 405 | s->avctx->pix_fmt = ret; | |
674 | |||
675 | // set up multilayer decoding, if requested by caller | ||
676 | 405 | ret = setup_multilayer(s, sps->vps); | |
677 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
|
405 | if (ret < 0) |
678 | ✗ | return ret; | |
679 | |||
680 | 405 | return 0; | |
681 | } | ||
682 | |||
683 | 414 | static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) | |
684 | { | ||
685 | int ret; | ||
686 | |||
687 | 414 | pic_arrays_free(l); | |
688 | 414 | av_refstruct_unref(&l->sps); | |
689 | 414 | av_refstruct_unref(&s->vps); | |
690 | |||
691 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
|
414 | if (!sps) |
692 | ✗ | return 0; | |
693 | |||
694 | 414 | ret = pic_arrays_init(l, sps); | |
695 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
|
414 | if (ret < 0) |
696 | ✗ | goto fail; | |
697 | |||
698 | 414 | ff_hevc_pred_init(&s->hpc, sps->bit_depth); | |
699 | 414 | ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); | |
700 | 414 | ff_videodsp_init (&s->vdsp, sps->bit_depth); | |
701 | |||
702 | 414 | l->sps = av_refstruct_ref_c(sps); | |
703 | 414 | s->vps = av_refstruct_ref_c(sps->vps); | |
704 | |||
705 | 414 | return 0; | |
706 | |||
707 | ✗ | fail: | |
708 | ✗ | pic_arrays_free(l); | |
709 | ✗ | av_refstruct_unref(&l->sps); | |
710 | ✗ | return ret; | |
711 | } | ||
712 | |||
713 | 28284 | static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb) | |
714 | { | ||
715 | const HEVCPPS *pps; | ||
716 | const HEVCSPS *sps; | ||
717 | const HEVCVPS *vps; | ||
718 | unsigned pps_id, layer_idx; | ||
719 | int i, ret; | ||
720 | |||
721 | // Coded parameters | ||
722 | 28284 | sh->first_slice_in_pic_flag = get_bits1(gb); | |
723 | |||
724 | 28284 | sh->no_output_of_prior_pics_flag = 0; | |
725 |
3/4✓ Branch 0 taken 1448 times.
✓ Branch 1 taken 26836 times.
✓ Branch 2 taken 1448 times.
✗ Branch 3 not taken.
|
28284 | if (IS_IRAP(s)) |
726 | 1448 | sh->no_output_of_prior_pics_flag = get_bits1(gb); | |
727 | |||
728 | 28284 | pps_id = get_ue_golomb_long(gb); | |
729 |
3/4✓ Branch 0 taken 28284 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 28251 times.
|
28284 | if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) { |
730 | 33 | av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); | |
731 | 33 | return AVERROR_INVALIDDATA; | |
732 | } | ||
733 |
3/4✓ Branch 0 taken 18036 times.
✓ Branch 1 taken 10215 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18036 times.
|
28251 | if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) { |
734 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); | |
735 | ✗ | return AVERROR_INVALIDDATA; | |
736 | } | ||
737 | 28251 | sh->pps_id = pps_id; | |
738 | |||
739 | 28251 | pps = s->ps.pps_list[pps_id]; | |
740 | 28251 | sps = pps->sps; | |
741 | 28251 | vps = sps->vps; | |
742 | 28251 | layer_idx = vps->layer_idx[s->nuh_layer_id]; | |
743 | |||
744 |
4/4✓ Branch 0 taken 479 times.
✓ Branch 1 taken 27772 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 464 times.
|
28251 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) |
745 | 15 | sh->no_output_of_prior_pics_flag = 1; | |
746 | |||
747 | 28251 | sh->dependent_slice_segment_flag = 0; | |
748 |
2/2✓ Branch 0 taken 18036 times.
✓ Branch 1 taken 10215 times.
|
28251 | if (!sh->first_slice_in_pic_flag) { |
749 | int slice_address_length; | ||
750 | |||
751 |
2/2✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8944 times.
|
18036 | if (pps->dependent_slice_segments_enabled_flag) |
752 | 9092 | sh->dependent_slice_segment_flag = get_bits1(gb); | |
753 |
3/4✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 10089 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7947 times.
|
18036 | if (sh->dependent_slice_segment_flag && !s->slice_initialized) { |
754 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); | |
755 | ✗ | return AVERROR_INVALIDDATA; | |
756 | } | ||
757 | |||
758 | 18036 | slice_address_length = av_ceil_log2(sps->ctb_width * | |
759 | 18036 | sps->ctb_height); | |
760 | 18036 | sh->slice_segment_addr = get_bitsz(gb, slice_address_length); | |
761 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18036 times.
|
18036 | if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) { |
762 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
763 | "Invalid slice segment address: %u.\n", | ||
764 | sh->slice_segment_addr); | ||
765 | ✗ | return AVERROR_INVALIDDATA; | |
766 | } | ||
767 | |||
768 |
2/2✓ Branch 0 taken 10089 times.
✓ Branch 1 taken 7947 times.
|
18036 | if (!sh->dependent_slice_segment_flag) { |
769 | 10089 | sh->slice_addr = sh->slice_segment_addr; | |
770 | } | ||
771 | } else { | ||
772 | 10215 | sh->slice_segment_addr = sh->slice_addr = 0; | |
773 | } | ||
774 | |||
775 |
2/2✓ Branch 0 taken 20304 times.
✓ Branch 1 taken 7947 times.
|
28251 | if (!sh->dependent_slice_segment_flag) { |
776 |
2/2✓ Branch 0 taken 1078 times.
✓ Branch 1 taken 20304 times.
|
21382 | for (i = 0; i < pps->num_extra_slice_header_bits; i++) |
777 | 1078 | skip_bits(gb, 1); // slice_reserved_undetermined_flag[] | |
778 | |||
779 | 20304 | sh->slice_type = get_ue_golomb_long(gb); | |
780 |
2/2✓ Branch 0 taken 19069 times.
✓ Branch 1 taken 1235 times.
|
20304 | if (!(sh->slice_type == HEVC_SLICE_I || |
781 |
2/2✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3840 times.
|
19069 | sh->slice_type == HEVC_SLICE_P || |
782 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15229 times.
|
15229 | sh->slice_type == HEVC_SLICE_B)) { |
783 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", | |
784 | ✗ | sh->slice_type); | |
785 | ✗ | return AVERROR_INVALIDDATA; | |
786 | } | ||
787 |
5/6✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 19245 times.
✓ Branch 2 taken 1059 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 75 times.
✓ Branch 5 taken 984 times.
|
20304 | if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I && |
788 |
1/2✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
|
75 | !pps->pps_curr_pic_ref_enabled_flag && |
789 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
|
75 | s->nuh_layer_id == 0) { |
790 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); | |
791 | ✗ | return AVERROR_INVALIDDATA; | |
792 | } | ||
793 | |||
794 | // when flag is not present, picture is inferred to be output | ||
795 | 20304 | sh->pic_output_flag = 1; | |
796 |
2/2✓ Branch 0 taken 703 times.
✓ Branch 1 taken 19601 times.
|
20304 | if (pps->output_flag_present_flag) |
797 | 703 | sh->pic_output_flag = get_bits1(gb); | |
798 | |||
799 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20304 times.
|
20304 | if (sps->separate_colour_plane) |
800 | ✗ | sh->colour_plane_id = get_bits(gb, 2); | |
801 | |||
802 |
4/4✓ Branch 0 taken 19692 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 19673 times.
|
20304 | if (!IS_IDR(s) || |
803 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 624 times.
|
631 | (s->nuh_layer_id > 0 && |
804 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | !(vps->poc_lsb_not_present & (1 << layer_idx)))) { |
805 | int poc; | ||
806 | |||
807 | 19680 | sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb); | |
808 | 19680 | poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type); | |
809 |
3/4✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9812 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
|
19680 | if (!sh->first_slice_in_pic_flag && poc != sh->poc) { |
810 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
811 | "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc); | ||
812 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
813 | ✗ | return AVERROR_INVALIDDATA; | |
814 | ✗ | poc = sh->poc; | |
815 | } | ||
816 | 19680 | sh->poc = poc; | |
817 | } | ||
818 | |||
819 |
4/4✓ Branch 0 taken 19692 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 19673 times.
✓ Branch 3 taken 19 times.
|
39977 | if (!IS_IDR(s)) { |
820 | int pos; | ||
821 | |||
822 | 19673 | sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); | |
823 | 19673 | pos = get_bits_left(gb); | |
824 |
2/2✓ Branch 0 taken 3499 times.
✓ Branch 1 taken 16174 times.
|
19673 | if (!sh->short_term_ref_pic_set_sps_flag) { |
825 | 3499 | ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1); | |
826 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3499 times.
|
3499 | if (ret < 0) |
827 | ✗ | return ret; | |
828 | |||
829 | 3499 | sh->short_term_rps = &sh->slice_rps; | |
830 | } else { | ||
831 | int numbits, rps_idx; | ||
832 | |||
833 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16174 times.
|
16174 | if (!sps->nb_st_rps) { |
834 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); | |
835 | ✗ | return AVERROR_INVALIDDATA; | |
836 | } | ||
837 | |||
838 | 16174 | numbits = av_ceil_log2(sps->nb_st_rps); | |
839 |
2/2✓ Branch 0 taken 16146 times.
✓ Branch 1 taken 28 times.
|
16174 | rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; |
840 | 16174 | sh->short_term_rps = &sps->st_rps[rps_idx]; | |
841 | } | ||
842 | 19673 | sh->short_term_ref_pic_set_size = pos - get_bits_left(gb); | |
843 | |||
844 | 19673 | pos = get_bits_left(gb); | |
845 | 19673 | ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb); | |
846 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19673 times.
|
19673 | if (ret < 0) { |
847 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n"); | |
848 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
849 | ✗ | return AVERROR_INVALIDDATA; | |
850 | } | ||
851 | 19673 | sh->long_term_ref_pic_set_size = pos - get_bits_left(gb); | |
852 | |||
853 |
2/2✓ Branch 0 taken 17242 times.
✓ Branch 1 taken 2431 times.
|
19673 | if (sps->temporal_mvp_enabled) |
854 | 17242 | sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); | |
855 | else | ||
856 | 2431 | sh->slice_temporal_mvp_enabled_flag = 0; | |
857 | } else { | ||
858 | 631 | sh->poc = 0; | |
859 | 631 | sh->pic_order_cnt_lsb = 0; | |
860 | 631 | sh->short_term_ref_pic_set_sps_flag = 0; | |
861 | 631 | sh->short_term_ref_pic_set_size = 0; | |
862 | 631 | sh->short_term_rps = NULL; | |
863 | 631 | sh->long_term_ref_pic_set_size = 0; | |
864 | 631 | sh->slice_temporal_mvp_enabled_flag = 0; | |
865 | } | ||
866 | |||
867 | 20304 | sh->inter_layer_pred = 0; | |
868 |
2/2✓ Branch 0 taken 277 times.
✓ Branch 1 taken 20027 times.
|
20304 | if (s->nuh_layer_id > 0) { |
869 | 277 | int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx]; | |
870 | |||
871 |
2/2✓ Branch 0 taken 229 times.
✓ Branch 1 taken 48 times.
|
277 | if (vps->default_ref_layers_active) |
872 | 229 | sh->inter_layer_pred = !!num_direct_ref_layers; | |
873 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | else if (num_direct_ref_layers) { |
874 | 48 | sh->inter_layer_pred = get_bits1(gb); | |
875 | |||
876 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
48 | if (sh->inter_layer_pred && num_direct_ref_layers > 1) { |
877 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
878 | "NumDirectRefLayers>1 not supported\n"); | ||
879 | ✗ | return AVERROR_PATCHWELCOME; | |
880 | } | ||
881 | } | ||
882 | } | ||
883 | |||
884 |
2/2✓ Branch 0 taken 16791 times.
✓ Branch 1 taken 3513 times.
|
20304 | if (sps->sao_enabled) { |
885 | 16791 | sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); | |
886 |
2/2✓ Branch 0 taken 16789 times.
✓ Branch 1 taken 2 times.
|
16791 | if (sps->chroma_format_idc) { |
887 | 16789 | sh->slice_sample_adaptive_offset_flag[1] = | |
888 | 16789 | sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); | |
889 | } | ||
890 | } else { | ||
891 | 3513 | sh->slice_sample_adaptive_offset_flag[0] = 0; | |
892 | 3513 | sh->slice_sample_adaptive_offset_flag[1] = 0; | |
893 | 3513 | sh->slice_sample_adaptive_offset_flag[2] = 0; | |
894 | } | ||
895 | |||
896 | 20304 | sh->nb_refs[L0] = sh->nb_refs[L1] = 0; | |
897 |
4/4✓ Branch 0 taken 16464 times.
✓ Branch 1 taken 3840 times.
✓ Branch 2 taken 15229 times.
✓ Branch 3 taken 1235 times.
|
20304 | if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) { |
898 | int nb_refs; | ||
899 | |||
900 | 19069 | sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active; | |
901 |
2/2✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3840 times.
|
19069 | if (sh->slice_type == HEVC_SLICE_B) |
902 | 15229 | sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active; | |
903 | |||
904 |
2/2✓ Branch 1 taken 4954 times.
✓ Branch 2 taken 14115 times.
|
19069 | if (get_bits1(gb)) { // num_ref_idx_active_override_flag |
905 | 4954 | sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1; | |
906 |
2/2✓ Branch 0 taken 2776 times.
✓ Branch 1 taken 2178 times.
|
4954 | if (sh->slice_type == HEVC_SLICE_B) |
907 | 2776 | sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1; | |
908 | } | ||
909 |
2/4✓ Branch 0 taken 19069 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19069 times.
|
19069 | if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) { |
910 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n", | |
911 | sh->nb_refs[L0], sh->nb_refs[L1]); | ||
912 | ✗ | return AVERROR_INVALIDDATA; | |
913 | } | ||
914 | |||
915 | 19069 | sh->rpl_modification_flag[0] = 0; | |
916 | 19069 | sh->rpl_modification_flag[1] = 0; | |
917 | 19069 | nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx); | |
918 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19069 times.
|
19069 | if (!nb_refs) { |
919 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); | |
920 | ✗ | return AVERROR_INVALIDDATA; | |
921 | } | ||
922 | |||
923 |
4/4✓ Branch 0 taken 1930 times.
✓ Branch 1 taken 17139 times.
✓ Branch 2 taken 1795 times.
✓ Branch 3 taken 135 times.
|
19069 | if (pps->lists_modification_present_flag && nb_refs > 1) { |
924 | 1795 | sh->rpl_modification_flag[0] = get_bits1(gb); | |
925 |
2/2✓ Branch 0 taken 1249 times.
✓ Branch 1 taken 546 times.
|
1795 | if (sh->rpl_modification_flag[0]) { |
926 |
2/2✓ Branch 0 taken 3000 times.
✓ Branch 1 taken 1249 times.
|
4249 | for (i = 0; i < sh->nb_refs[L0]; i++) |
927 | 3000 | sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
928 | } | ||
929 | |||
930 |
1/2✓ Branch 0 taken 1795 times.
✗ Branch 1 not taken.
|
1795 | if (sh->slice_type == HEVC_SLICE_B) { |
931 | 1795 | sh->rpl_modification_flag[1] = get_bits1(gb); | |
932 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 1143 times.
|
1795 | if (sh->rpl_modification_flag[1] == 1) |
933 |
2/2✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
|
2207 | for (i = 0; i < sh->nb_refs[L1]; i++) |
934 | 1555 | sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
935 | } | ||
936 | } | ||
937 | |||
938 |
2/2✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3840 times.
|
19069 | if (sh->slice_type == HEVC_SLICE_B) |
939 | 15229 | sh->mvd_l1_zero_flag = get_bits1(gb); | |
940 | |||
941 |
2/2✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 2759 times.
|
19069 | if (pps->cabac_init_present_flag) |
942 | 16310 | sh->cabac_init_flag = get_bits1(gb); | |
943 | else | ||
944 | 2759 | sh->cabac_init_flag = 0; | |
945 | |||
946 | 19069 | sh->collocated_ref_idx = 0; | |
947 |
2/2✓ Branch 0 taken 16684 times.
✓ Branch 1 taken 2385 times.
|
19069 | if (sh->slice_temporal_mvp_enabled_flag) { |
948 | 16684 | sh->collocated_list = L0; | |
949 |
2/2✓ Branch 0 taken 14695 times.
✓ Branch 1 taken 1989 times.
|
16684 | if (sh->slice_type == HEVC_SLICE_B) |
950 | 14695 | sh->collocated_list = !get_bits1(gb); | |
951 | |||
952 |
2/2✓ Branch 0 taken 14826 times.
✓ Branch 1 taken 1858 times.
|
16684 | if (sh->nb_refs[sh->collocated_list] > 1) { |
953 | 14826 | sh->collocated_ref_idx = get_ue_golomb_long(gb); | |
954 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14826 times.
|
14826 | if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { |
955 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
956 | "Invalid collocated_ref_idx: %d.\n", | ||
957 | sh->collocated_ref_idx); | ||
958 | ✗ | return AVERROR_INVALIDDATA; | |
959 | } | ||
960 | } | ||
961 | } | ||
962 | |||
963 |
4/4✓ Branch 0 taken 1468 times.
✓ Branch 1 taken 17601 times.
✓ Branch 2 taken 693 times.
✓ Branch 3 taken 775 times.
|
19069 | if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) || |
964 |
3/4✓ Branch 0 taken 668 times.
✓ Branch 1 taken 17626 times.
✓ Branch 2 taken 668 times.
✗ Branch 3 not taken.
|
18294 | (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) { |
965 | 1443 | int ret = pred_weight_table(sh, s->avctx, sps, gb); | |
966 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1443 times.
|
1443 | if (ret < 0) |
967 | ✗ | return ret; | |
968 | } | ||
969 | |||
970 | 19069 | sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb); | |
971 |
2/4✓ Branch 0 taken 19069 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19069 times.
|
19069 | if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) { |
972 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
973 | "Invalid number of merging MVP candidates: %d.\n", | ||
974 | ✗ | sh->max_num_merge_cand); | |
975 | ✗ | return AVERROR_INVALIDDATA; | |
976 | } | ||
977 | |||
978 | // Syntax in 7.3.6.1 | ||
979 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19069 times.
|
19069 | if (sps->motion_vector_resolution_control_idc == 2) |
980 | ✗ | sh->use_integer_mv_flag = get_bits1(gb); | |
981 | else | ||
982 | // Inferred to be equal to motion_vector_resolution_control_idc if not present | ||
983 | 19069 | sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc; | |
984 | |||
985 | } | ||
986 | |||
987 | 20304 | sh->slice_qp_delta = get_se_golomb(gb); | |
988 | |||
989 |
2/2✓ Branch 0 taken 271 times.
✓ Branch 1 taken 20033 times.
|
20304 | if (pps->pic_slice_level_chroma_qp_offsets_present_flag) { |
990 | 271 | sh->slice_cb_qp_offset = get_se_golomb(gb); | |
991 | 271 | sh->slice_cr_qp_offset = get_se_golomb(gb); | |
992 |
2/4✓ Branch 0 taken 271 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 271 times.
✗ Branch 3 not taken.
|
271 | if (sh->slice_cb_qp_offset < -12 || sh->slice_cb_qp_offset > 12 || |
993 |
2/4✓ Branch 0 taken 271 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 271 times.
|
271 | sh->slice_cr_qp_offset < -12 || sh->slice_cr_qp_offset > 12) { |
994 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n"); | |
995 | ✗ | return AVERROR_INVALIDDATA; | |
996 | } | ||
997 | } else { | ||
998 | 20033 | sh->slice_cb_qp_offset = 0; | |
999 | 20033 | sh->slice_cr_qp_offset = 0; | |
1000 | } | ||
1001 | |||
1002 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20304 times.
|
20304 | if (pps->pps_slice_act_qp_offsets_present_flag) { |
1003 | ✗ | sh->slice_act_y_qp_offset = get_se_golomb(gb); | |
1004 | ✗ | sh->slice_act_cb_qp_offset = get_se_golomb(gb); | |
1005 | ✗ | sh->slice_act_cr_qp_offset = get_se_golomb(gb); | |
1006 | } | ||
1007 | |||
1008 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 20261 times.
|
20304 | if (pps->chroma_qp_offset_list_enabled_flag) |
1009 | 43 | sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb); | |
1010 | else | ||
1011 | 20261 | sh->cu_chroma_qp_offset_enabled_flag = 0; | |
1012 | |||
1013 |
2/2✓ Branch 0 taken 2959 times.
✓ Branch 1 taken 17345 times.
|
20304 | if (pps->deblocking_filter_control_present_flag) { |
1014 | 2959 | int deblocking_filter_override_flag = 0; | |
1015 | |||
1016 |
2/2✓ Branch 0 taken 696 times.
✓ Branch 1 taken 2263 times.
|
2959 | if (pps->deblocking_filter_override_enabled_flag) |
1017 | 696 | deblocking_filter_override_flag = get_bits1(gb); | |
1018 | |||
1019 |
2/2✓ Branch 0 taken 477 times.
✓ Branch 1 taken 2482 times.
|
2959 | if (deblocking_filter_override_flag) { |
1020 | 477 | sh->disable_deblocking_filter_flag = get_bits1(gb); | |
1021 |
2/2✓ Branch 0 taken 357 times.
✓ Branch 1 taken 120 times.
|
477 | if (!sh->disable_deblocking_filter_flag) { |
1022 | 357 | int beta_offset_div2 = get_se_golomb(gb); | |
1023 | 357 | int tc_offset_div2 = get_se_golomb(gb) ; | |
1024 |
3/6✓ Branch 0 taken 357 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 357 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 357 times.
✗ Branch 5 not taken.
|
357 | if (beta_offset_div2 < -6 || beta_offset_div2 > 6 || |
1025 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 357 times.
|
357 | tc_offset_div2 < -6 || tc_offset_div2 > 6) { |
1026 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1027 | "Invalid deblock filter offsets: %d, %d\n", | ||
1028 | beta_offset_div2, tc_offset_div2); | ||
1029 | ✗ | return AVERROR_INVALIDDATA; | |
1030 | } | ||
1031 | 357 | sh->beta_offset = beta_offset_div2 * 2; | |
1032 | 357 | sh->tc_offset = tc_offset_div2 * 2; | |
1033 | } | ||
1034 | } else { | ||
1035 | 2482 | sh->disable_deblocking_filter_flag = pps->disable_dbf; | |
1036 | 2482 | sh->beta_offset = pps->beta_offset; | |
1037 | 2482 | sh->tc_offset = pps->tc_offset; | |
1038 | } | ||
1039 | } else { | ||
1040 | 17345 | sh->disable_deblocking_filter_flag = 0; | |
1041 | 17345 | sh->beta_offset = 0; | |
1042 | 17345 | sh->tc_offset = 0; | |
1043 | } | ||
1044 | |||
1045 |
2/2✓ Branch 0 taken 17736 times.
✓ Branch 1 taken 2568 times.
|
20304 | if (pps->seq_loop_filter_across_slices_enabled_flag && |
1046 |
2/2✓ Branch 0 taken 11732 times.
✓ Branch 1 taken 6004 times.
|
17736 | (sh->slice_sample_adaptive_offset_flag[0] || |
1047 |
2/2✓ Branch 0 taken 11714 times.
✓ Branch 1 taken 18 times.
|
11732 | sh->slice_sample_adaptive_offset_flag[1] || |
1048 |
2/2✓ Branch 0 taken 11651 times.
✓ Branch 1 taken 63 times.
|
11714 | !sh->disable_deblocking_filter_flag)) { |
1049 | 17673 | sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); | |
1050 | } else { | ||
1051 | 2631 | sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag; | |
1052 | } | ||
1053 | } | ||
1054 | |||
1055 | 28251 | sh->num_entry_point_offsets = 0; | |
1056 |
4/4✓ Branch 0 taken 25340 times.
✓ Branch 1 taken 2911 times.
✓ Branch 2 taken 4637 times.
✓ Branch 3 taken 20703 times.
|
28251 | if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) { |
1057 | 7548 | unsigned num_entry_point_offsets = get_ue_golomb_long(gb); | |
1058 | // It would be possible to bound this tighter but this here is simpler | ||
1059 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7548 times.
|
7548 | if (num_entry_point_offsets > get_bits_left(gb)) { |
1060 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets); | |
1061 | ✗ | return AVERROR_INVALIDDATA; | |
1062 | } | ||
1063 | |||
1064 | 7548 | sh->num_entry_point_offsets = num_entry_point_offsets; | |
1065 |
2/2✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 5474 times.
|
7548 | if (sh->num_entry_point_offsets > 0) { |
1066 | 2074 | int offset_len = get_ue_golomb_long(gb) + 1; | |
1067 | |||
1068 |
2/4✓ Branch 0 taken 2074 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2074 times.
|
2074 | if (offset_len < 1 || offset_len > 32) { |
1069 | ✗ | sh->num_entry_point_offsets = 0; | |
1070 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len); | |
1071 | ✗ | return AVERROR_INVALIDDATA; | |
1072 | } | ||
1073 | |||
1074 | 2074 | av_freep(&sh->entry_point_offset); | |
1075 | 2074 | av_freep(&sh->offset); | |
1076 | 2074 | av_freep(&sh->size); | |
1077 | 2074 | sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned)); | |
1078 | 2074 | sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
1079 | 2074 | sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
1080 |
3/6✓ Branch 0 taken 2074 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2074 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2074 times.
|
2074 | if (!sh->entry_point_offset || !sh->offset || !sh->size) { |
1081 | ✗ | sh->num_entry_point_offsets = 0; | |
1082 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n"); | |
1083 | ✗ | return AVERROR(ENOMEM); | |
1084 | } | ||
1085 |
2/2✓ Branch 0 taken 8942 times.
✓ Branch 1 taken 2074 times.
|
11016 | for (i = 0; i < sh->num_entry_point_offsets; i++) { |
1086 | 8942 | unsigned val = get_bits_long(gb, offset_len); | |
1087 | 8942 | sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size | |
1088 | } | ||
1089 | } | ||
1090 | } | ||
1091 | |||
1092 |
2/2✓ Branch 0 taken 2769 times.
✓ Branch 1 taken 25482 times.
|
28251 | if (pps->slice_header_extension_present_flag) { |
1093 | 2769 | unsigned int length = get_ue_golomb_long(gb); | |
1094 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2769 times.
|
2769 | if (length*8LL > get_bits_left(gb)) { |
1095 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n"); | |
1096 | ✗ | return AVERROR_INVALIDDATA; | |
1097 | } | ||
1098 |
2/2✓ Branch 0 taken 20292 times.
✓ Branch 1 taken 2769 times.
|
23061 | for (i = 0; i < length; i++) |
1099 | 20292 | skip_bits(gb, 8); // slice_header_extension_data_byte | |
1100 | } | ||
1101 | |||
1102 | 28251 | ret = get_bits1(gb); | |
1103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
|
28251 | if (!ret) { |
1104 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n"); | |
1105 | ✗ | return AVERROR_INVALIDDATA; | |
1106 | } | ||
1107 | 28251 | sh->data_offset = align_get_bits(gb) - gb->buffer; | |
1108 | |||
1109 | // Inferred parameters | ||
1110 | 28251 | sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta; | |
1111 |
1/2✓ Branch 0 taken 28251 times.
✗ Branch 1 not taken.
|
28251 | if (sh->slice_qp > 51 || |
1112 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
|
28251 | sh->slice_qp < -sps->qp_bd_offset) { |
1113 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1114 | "The slice_qp %d is outside the valid range " | ||
1115 | "[%d, 51].\n", | ||
1116 | ✗ | sh->slice_qp, | |
1117 | ✗ | -sps->qp_bd_offset); | |
1118 | ✗ | return AVERROR_INVALIDDATA; | |
1119 | } | ||
1120 | |||
1121 | 28251 | sh->slice_ctb_addr_rs = sh->slice_segment_addr; | |
1122 | |||
1123 |
2/2✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20304 times.
|
28251 | if (sh->dependent_slice_segment_flag && |
1124 |
2/4✓ Branch 0 taken 7947 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7947 times.
|
7947 | (!sh->slice_ctb_addr_rs || !pps->ctb_addr_rs_to_ts[sh->slice_ctb_addr_rs])) { |
1125 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n"); | |
1126 | ✗ | return AVERROR_INVALIDDATA; | |
1127 | } | ||
1128 | |||
1129 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28251 times.
|
28251 | if (get_bits_left(gb) < 0) { |
1130 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1131 | ✗ | "Overread slice header by %d bits\n", -get_bits_left(gb)); | |
1132 | ✗ | return AVERROR_INVALIDDATA; | |
1133 | } | ||
1134 | |||
1135 | 28251 | return 0; | |
1136 | } | ||
1137 | |||
1138 | #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)]) | ||
1139 | |||
1140 | #define SET_SAO(elem, value) \ | ||
1141 | do { \ | ||
1142 | if (!sao_merge_up_flag && !sao_merge_left_flag) \ | ||
1143 | sao->elem = value; \ | ||
1144 | else if (sao_merge_left_flag) \ | ||
1145 | sao->elem = CTB(l->sao, rx-1, ry).elem; \ | ||
1146 | else if (sao_merge_up_flag) \ | ||
1147 | sao->elem = CTB(l->sao, rx, ry-1).elem; \ | ||
1148 | else \ | ||
1149 | sao->elem = 0; \ | ||
1150 | } while (0) | ||
1151 | |||
1152 | 1573720 | static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
1153 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1154 | int rx, int ry) | ||
1155 | { | ||
1156 | 1573720 | const HEVCContext *const s = lc->parent; | |
1157 | 1573720 | int sao_merge_left_flag = 0; | |
1158 | 1573720 | int sao_merge_up_flag = 0; | |
1159 | 1573720 | SAOParams *sao = &CTB(l->sao, rx, ry); | |
1160 | int c_idx, i; | ||
1161 | |||
1162 |
2/2✓ Branch 0 taken 863042 times.
✓ Branch 1 taken 710678 times.
|
1573720 | if (s->sh.slice_sample_adaptive_offset_flag[0] || |
1163 |
2/2✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 861398 times.
|
863042 | s->sh.slice_sample_adaptive_offset_flag[1]) { |
1164 |
2/2✓ Branch 0 taken 676534 times.
✓ Branch 1 taken 35788 times.
|
712322 | if (rx > 0) { |
1165 |
2/2✓ Branch 0 taken 667999 times.
✓ Branch 1 taken 8535 times.
|
676534 | if (lc->ctb_left_flag) |
1166 | 667999 | sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc); | |
1167 | } | ||
1168 |
4/4✓ Branch 0 taken 654917 times.
✓ Branch 1 taken 57405 times.
✓ Branch 2 taken 342185 times.
✓ Branch 3 taken 312732 times.
|
712322 | if (ry > 0 && !sao_merge_left_flag) { |
1169 |
2/2✓ Branch 0 taken 328816 times.
✓ Branch 1 taken 13369 times.
|
342185 | if (lc->ctb_up_flag) |
1170 | 328816 | sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc); | |
1171 | } | ||
1172 | } | ||
1173 | |||
1174 |
4/4✓ Branch 0 taken 6294688 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4721064 times.
✓ Branch 3 taken 1573720 times.
|
6294784 | for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) { |
1175 |
2/2✓ Branch 0 taken 1573720 times.
✓ Branch 1 taken 3147344 times.
|
4721064 | int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma : |
1176 | 3147344 | pps->log2_sao_offset_scale_chroma; | |
1177 | |||
1178 |
2/2✓ Branch 0 taken 3127126 times.
✓ Branch 1 taken 1593938 times.
|
4721064 | if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) { |
1179 | 3127126 | sao->type_idx[c_idx] = SAO_NOT_APPLIED; | |
1180 | 3127126 | continue; | |
1181 | } | ||
1182 | |||
1183 |
2/2✓ Branch 0 taken 441630 times.
✓ Branch 1 taken 1152308 times.
|
1593938 | if (c_idx == 2) { |
1184 | 441630 | sao->type_idx[2] = sao->type_idx[1]; | |
1185 | 441630 | sao->eo_class[2] = sao->eo_class[1]; | |
1186 | } else { | ||
1187 |
7/8✓ Branch 0 taken 1013958 times.
✓ Branch 1 taken 138350 times.
✓ Branch 2 taken 497980 times.
✓ Branch 3 taken 515978 times.
✓ Branch 5 taken 515978 times.
✓ Branch 6 taken 138350 times.
✓ Branch 7 taken 138350 times.
✗ Branch 8 not taken.
|
1152308 | SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc)); |
1188 | } | ||
1189 | |||
1190 |
2/2✓ Branch 0 taken 1057774 times.
✓ Branch 1 taken 536164 times.
|
1593938 | if (sao->type_idx[c_idx] == SAO_NOT_APPLIED) |
1191 | 1057774 | continue; | |
1192 | |||
1193 |
2/2✓ Branch 0 taken 2144656 times.
✓ Branch 1 taken 536164 times.
|
2680820 | for (i = 0; i < 4; i++) |
1194 |
7/8✓ Branch 0 taken 1766928 times.
✓ Branch 1 taken 377728 times.
✓ Branch 2 taken 909988 times.
✓ Branch 3 taken 856940 times.
✓ Branch 5 taken 856940 times.
✓ Branch 6 taken 377728 times.
✓ Branch 7 taken 377728 times.
✗ Branch 8 not taken.
|
2144656 | SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth)); |
1195 | |||
1196 |
2/2✓ Branch 0 taken 119646 times.
✓ Branch 1 taken 416518 times.
|
536164 | if (sao->type_idx[c_idx] == SAO_BAND) { |
1197 |
2/2✓ Branch 0 taken 478584 times.
✓ Branch 1 taken 119646 times.
|
598230 | for (i = 0; i < 4; i++) { |
1198 |
2/2✓ Branch 0 taken 358111 times.
✓ Branch 1 taken 120473 times.
|
478584 | if (sao->offset_abs[c_idx][i]) { |
1199 |
7/8✓ Branch 0 taken 332770 times.
✓ Branch 1 taken 25341 times.
✓ Branch 2 taken 246136 times.
✓ Branch 3 taken 86634 times.
✓ Branch 5 taken 86634 times.
✓ Branch 6 taken 25341 times.
✓ Branch 7 taken 25341 times.
✗ Branch 8 not taken.
|
358111 | SET_SAO(offset_sign[c_idx][i], |
1200 | ff_hevc_sao_offset_sign_decode(lc)); | ||
1201 | } else { | ||
1202 | 120473 | sao->offset_sign[c_idx][i] = 0; | |
1203 | } | ||
1204 | } | ||
1205 |
7/8✓ Branch 0 taken 109384 times.
✓ Branch 1 taken 10262 times.
✓ Branch 2 taken 79308 times.
✓ Branch 3 taken 30076 times.
✓ Branch 5 taken 30076 times.
✓ Branch 6 taken 10262 times.
✓ Branch 7 taken 10262 times.
✗ Branch 8 not taken.
|
119646 | SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc)); |
1206 |
2/2✓ Branch 0 taken 335144 times.
✓ Branch 1 taken 81374 times.
|
416518 | } else if (c_idx != 2) { |
1207 |
7/8✓ Branch 0 taken 267336 times.
✓ Branch 1 taken 67808 times.
✓ Branch 2 taken 115628 times.
✓ Branch 3 taken 151708 times.
✓ Branch 5 taken 151708 times.
✓ Branch 6 taken 67808 times.
✓ Branch 7 taken 67808 times.
✗ Branch 8 not taken.
|
335144 | SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc)); |
1208 | } | ||
1209 | |||
1210 | // Inferred parameters | ||
1211 | 536164 | sao->offset_val[c_idx][0] = 0; | |
1212 |
2/2✓ Branch 0 taken 2144656 times.
✓ Branch 1 taken 536164 times.
|
2680820 | for (i = 0; i < 4; i++) { |
1213 | 2144656 | sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i]; | |
1214 |
2/2✓ Branch 0 taken 1666072 times.
✓ Branch 1 taken 478584 times.
|
2144656 | if (sao->type_idx[c_idx] == SAO_EDGE) { |
1215 |
2/2✓ Branch 0 taken 833036 times.
✓ Branch 1 taken 833036 times.
|
1666072 | if (i > 1) |
1216 | 833036 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1217 |
2/2✓ Branch 0 taken 158152 times.
✓ Branch 1 taken 320432 times.
|
478584 | } else if (sao->offset_sign[c_idx][i]) { |
1218 | 158152 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1219 | } | ||
1220 | 2144656 | sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale; | |
1221 | } | ||
1222 | } | ||
1223 | 1573720 | } | |
1224 | |||
1225 | #undef SET_SAO | ||
1226 | #undef CTB | ||
1227 | |||
1228 | 384850 | static int hls_cross_component_pred(HEVCLocalContext *lc, int idx) | |
1229 | { | ||
1230 | 384850 | int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx); | |
1231 | |||
1232 |
2/2✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
|
384850 | if (log2_res_scale_abs_plus1 != 0) { |
1233 | 235843 | int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx); | |
1234 | 235843 | lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) * | |
1235 | 235843 | (1 - 2 * res_scale_sign_flag); | |
1236 | } else { | ||
1237 | 149007 | lc->tu.res_scale_val = 0; | |
1238 | } | ||
1239 | |||
1240 | |||
1241 | 384850 | return 0; | |
1242 | } | ||
1243 | |||
1244 | 16059232 | static int hls_transform_unit(HEVCLocalContext *lc, | |
1245 | const HEVCLayerContext *l, | ||
1246 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1247 | int x0, int y0, | ||
1248 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1249 | int log2_cb_size, int log2_trafo_size, | ||
1250 | int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr) | ||
1251 | { | ||
1252 | 16059232 | const HEVCContext *const s = lc->parent; | |
1253 | 16059232 | const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1]; | |
1254 | int i; | ||
1255 | |||
1256 |
2/2✓ Branch 0 taken 10175157 times.
✓ Branch 1 taken 5884075 times.
|
16059232 | if (lc->cu.pred_mode == MODE_INTRA) { |
1257 | 10175157 | int trafo_size = 1 << log2_trafo_size; | |
1258 | 10175157 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size); | |
1259 | |||
1260 | 10175157 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0); | |
1261 | } | ||
1262 | |||
1263 |
6/6✓ Branch 0 taken 5836378 times.
✓ Branch 1 taken 10222854 times.
✓ Branch 2 taken 5189985 times.
✓ Branch 3 taken 646393 times.
✓ Branch 4 taken 4745748 times.
✓ Branch 5 taken 444237 times.
|
16059232 | if (cbf_luma || cbf_cb[0] || cbf_cr[0] || |
1264 |
6/6✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4589981 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
|
16121046 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1265 | 11375299 | int scan_idx = SCAN_DIAG; | |
1266 | 11375299 | int scan_idx_c = SCAN_DIAG; | |
1267 |
4/4✓ Branch 0 taken 7663737 times.
✓ Branch 1 taken 3711562 times.
✓ Branch 2 taken 6115356 times.
✓ Branch 3 taken 1548381 times.
|
17490655 | int cbf_chroma = cbf_cb[0] || cbf_cr[0] || |
1268 |
2/2✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 5883646 times.
|
6115356 | (sps->chroma_format_idc == 2 && |
1269 |
4/4✓ Branch 0 taken 197852 times.
✓ Branch 1 taken 33858 times.
✓ Branch 2 taken 102075 times.
✓ Branch 3 taken 95777 times.
|
231710 | (cbf_cb[1] || cbf_cr[1])); |
1270 | |||
1271 |
4/4✓ Branch 0 taken 2273880 times.
✓ Branch 1 taken 9101419 times.
✓ Branch 2 taken 661320 times.
✓ Branch 3 taken 1612560 times.
|
11375299 | if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) { |
1272 | 661320 | lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc); | |
1273 |
2/2✓ Branch 0 taken 374341 times.
✓ Branch 1 taken 286979 times.
|
661320 | if (lc->tu.cu_qp_delta != 0) |
1274 |
2/2✓ Branch 1 taken 207150 times.
✓ Branch 2 taken 167191 times.
|
374341 | if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1) |
1275 | 207150 | lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta; | |
1276 | 661320 | lc->tu.is_cu_qp_delta_coded = 1; | |
1277 | |||
1278 |
2/2✓ Branch 0 taken 661319 times.
✓ Branch 1 taken 1 times.
|
661320 | if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) || |
1279 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 661319 times.
|
661319 | lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) { |
1280 | 1 | av_log(s->avctx, AV_LOG_ERROR, | |
1281 | "The cu_qp_delta %d is outside the valid range " | ||
1282 | "[%d, %d].\n", | ||
1283 | lc->tu.cu_qp_delta, | ||
1284 | 1 | -(26 + sps->qp_bd_offset / 2), | |
1285 | 1 | (25 + sps->qp_bd_offset / 2)); | |
1286 | 1 | return AVERROR_INVALIDDATA; | |
1287 | } | ||
1288 | |||
1289 | 661319 | ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size); | |
1290 | } | ||
1291 | |||
1292 |
4/4✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 10483347 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
|
11375298 | if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma && |
1293 |
3/4✓ Branch 0 taken 841055 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 266275 times.
✓ Branch 3 taken 574780 times.
|
841055 | !lc->cu.cu_transquant_bypass_flag && !lc->tu.is_cu_chroma_qp_offset_coded) { |
1294 | 266275 | int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc); | |
1295 |
2/2✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
|
266275 | if (cu_chroma_qp_offset_flag) { |
1296 | 48966 | int cu_chroma_qp_offset_idx = 0; | |
1297 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
|
48966 | if (pps->chroma_qp_offset_list_len_minus1 > 0) { |
1298 | ✗ | cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1); | |
1299 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1300 | "cu_chroma_qp_offset_idx not yet tested.\n"); | ||
1301 | } | ||
1302 | 48966 | lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1303 | 48966 | lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1304 | } else { | ||
1305 | 217309 | lc->tu.cu_qp_offset_cb = 0; | |
1306 | 217309 | lc->tu.cu_qp_offset_cr = 0; | |
1307 | } | ||
1308 | 266275 | lc->tu.is_cu_chroma_qp_offset_coded = 1; | |
1309 | } | ||
1310 | |||
1311 |
4/4✓ Branch 0 taken 7486771 times.
✓ Branch 1 taken 3888527 times.
✓ Branch 2 taken 6500521 times.
✓ Branch 3 taken 986250 times.
|
11375298 | if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) { |
1312 |
2/2✓ Branch 0 taken 4329402 times.
✓ Branch 1 taken 2171119 times.
|
6500521 | if (lc->tu.intra_pred_mode >= 6 && |
1313 |
2/2✓ Branch 0 taken 1551675 times.
✓ Branch 1 taken 2777727 times.
|
4329402 | lc->tu.intra_pred_mode <= 14) { |
1314 | 1551675 | scan_idx = SCAN_VERT; | |
1315 |
2/2✓ Branch 0 taken 2142003 times.
✓ Branch 1 taken 2806843 times.
|
4948846 | } else if (lc->tu.intra_pred_mode >= 22 && |
1316 |
2/2✓ Branch 0 taken 1802346 times.
✓ Branch 1 taken 339657 times.
|
2142003 | lc->tu.intra_pred_mode <= 30) { |
1317 | 1802346 | scan_idx = SCAN_HORIZ; | |
1318 | } | ||
1319 | |||
1320 |
2/2✓ Branch 0 taken 3889316 times.
✓ Branch 1 taken 2611205 times.
|
6500521 | if (lc->tu.intra_pred_mode_c >= 6 && |
1321 |
2/2✓ Branch 0 taken 1463056 times.
✓ Branch 1 taken 2426260 times.
|
3889316 | lc->tu.intra_pred_mode_c <= 14) { |
1322 | 1463056 | scan_idx_c = SCAN_VERT; | |
1323 |
2/2✓ Branch 0 taken 2034714 times.
✓ Branch 1 taken 3002751 times.
|
5037465 | } else if (lc->tu.intra_pred_mode_c >= 22 && |
1324 |
2/2✓ Branch 0 taken 1705423 times.
✓ Branch 1 taken 329291 times.
|
2034714 | lc->tu.intra_pred_mode_c <= 30) { |
1325 | 1705423 | scan_idx_c = SCAN_HORIZ; | |
1326 | } | ||
1327 | } | ||
1328 | |||
1329 | 11375298 | lc->tu.cross_pf = 0; | |
1330 | |||
1331 |
2/2✓ Branch 0 taken 10222853 times.
✓ Branch 1 taken 1152445 times.
|
11375298 | if (cbf_luma) |
1332 | 10222853 | ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0); | |
1333 |
6/6✓ Branch 0 taken 11375106 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6287255 times.
✓ Branch 3 taken 5087851 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 6077692 times.
|
16672712 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
1334 | 5297414 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
1335 | 5297414 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
1336 |
4/4✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 4960573 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
|
5515230 | lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma && |
1337 |
2/2✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
|
217816 | (lc->cu.pred_mode == MODE_INTER || |
1338 |
2/2✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
|
168873 | (lc->tu.chroma_mode_c == 4))); |
1339 | |||
1340 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5104989 times.
|
5297414 | if (lc->tu.cross_pf) { |
1341 | 192425 | hls_cross_component_pred(lc, 0); | |
1342 | } | ||
1343 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9688424 times.
✓ Branch 2 taken 5750616 times.
✓ Branch 3 taken 5297414 times.
|
11048030 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1344 |
2/2✓ Branch 0 taken 3176481 times.
✓ Branch 1 taken 2574135 times.
|
5750616 | if (lc->cu.pred_mode == MODE_INTRA) { |
1345 | 3176481 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
1346 | 3176481 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1347 | 3176481 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1); | |
1348 | } | ||
1349 |
2/2✓ Branch 0 taken 1560246 times.
✓ Branch 1 taken 4190370 times.
|
5750616 | if (cbf_cb[i]) |
1350 | 1560246 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
1351 | log2_trafo_size_c, scan_idx_c, 1); | ||
1352 | else | ||
1353 |
2/2✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 4150712 times.
|
4190370 | if (lc->tu.cross_pf) { |
1354 | 39658 | ptrdiff_t stride = s->cur_frame->f->linesize[1]; | |
1355 | 39658 | int hshift = sps->hshift[1]; | |
1356 | 39658 | int vshift = sps->vshift[1]; | |
1357 | 39658 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1358 | 39658 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1359 | 39658 | int size = 1 << log2_trafo_size_c; | |
1360 | |||
1361 | 39658 | uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride + | |
1362 | 39658 | ((x0 >> hshift) << sps->pixel_shift)]; | |
1363 |
2/2✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
|
1871162 | for (i = 0; i < (size * size); i++) { |
1364 | 1831504 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1365 | } | ||
1366 | 39658 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1367 | } | ||
1368 | } | ||
1369 | |||
1370 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5104989 times.
|
5297414 | if (lc->tu.cross_pf) { |
1371 | 192425 | hls_cross_component_pred(lc, 1); | |
1372 | } | ||
1373 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9688424 times.
✓ Branch 2 taken 5750616 times.
✓ Branch 3 taken 5297414 times.
|
11048030 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1374 |
2/2✓ Branch 0 taken 3176481 times.
✓ Branch 1 taken 2574135 times.
|
5750616 | if (lc->cu.pred_mode == MODE_INTRA) { |
1375 | 3176481 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
1376 | 3176481 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1377 | 3176481 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2); | |
1378 | } | ||
1379 |
2/2✓ Branch 0 taken 1708790 times.
✓ Branch 1 taken 4041826 times.
|
5750616 | if (cbf_cr[i]) |
1380 | 1708790 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
1381 | log2_trafo_size_c, scan_idx_c, 2); | ||
1382 | else | ||
1383 |
2/2✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 3965902 times.
|
4041826 | if (lc->tu.cross_pf) { |
1384 | 75924 | ptrdiff_t stride = s->cur_frame->f->linesize[2]; | |
1385 | 75924 | int hshift = sps->hshift[2]; | |
1386 | 75924 | int vshift = sps->vshift[2]; | |
1387 | 75924 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1388 | 75924 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1389 | 75924 | int size = 1 << log2_trafo_size_c; | |
1390 | |||
1391 | 75924 | uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride + | |
1392 | 75924 | ((x0 >> hshift) << sps->pixel_shift)]; | |
1393 |
2/2✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
|
3691476 | for (i = 0; i < (size * size); i++) { |
1394 | 3615552 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1395 | } | ||
1396 | 75924 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1397 | } | ||
1398 | } | ||
1399 |
4/4✓ Branch 0 taken 6077692 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1561978 times.
✓ Branch 3 taken 4515714 times.
|
6077884 | } else if (sps->chroma_format_idc && blk_idx == 3) { |
1400 | 1561978 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1401 | 1561978 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
1402 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2790218 times.
✓ Branch 2 taken 1728847 times.
✓ Branch 3 taken 1561978 times.
|
3290825 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1403 |
2/2✓ Branch 0 taken 1242036 times.
✓ Branch 1 taken 486811 times.
|
1728847 | if (lc->cu.pred_mode == MODE_INTRA) { |
1404 | 1242036 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
1405 | 1242036 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1406 | 1242036 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1); | |
1407 | } | ||
1408 |
2/2✓ Branch 0 taken 652423 times.
✓ Branch 1 taken 1076424 times.
|
1728847 | if (cbf_cb[i]) |
1409 | 652423 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
1410 | log2_trafo_size, scan_idx_c, 1); | ||
1411 | } | ||
1412 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2790218 times.
✓ Branch 2 taken 1728847 times.
✓ Branch 3 taken 1561978 times.
|
3290825 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1413 |
2/2✓ Branch 0 taken 1242036 times.
✓ Branch 1 taken 486811 times.
|
1728847 | if (lc->cu.pred_mode == MODE_INTRA) { |
1414 | 1242036 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
1415 | 1242036 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1416 | 1242036 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2); | |
1417 | } | ||
1418 |
2/2✓ Branch 0 taken 741276 times.
✓ Branch 1 taken 987571 times.
|
1728847 | if (cbf_cr[i]) |
1419 | 741276 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
1420 | log2_trafo_size, scan_idx_c, 2); | ||
1421 | } | ||
1422 | } | ||
1423 |
3/4✓ Branch 0 taken 4683933 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2688385 times.
✓ Branch 3 taken 1995548 times.
|
4683933 | } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) { |
1424 |
4/4✓ Branch 0 taken 1650024 times.
✓ Branch 1 taken 1038361 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1589436 times.
|
3787334 | if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) { |
1425 | 1098949 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
1426 | 1098949 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
1427 | 1098949 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v, | |
1428 | 1098949 | sps->log2_ctb_size); | |
1429 | 1098949 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1); | |
1430 | 1098949 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2); | |
1431 |
2/2✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 1086482 times.
|
1098949 | if (sps->chroma_format_idc == 2) { |
1432 | 12467 | ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c), | |
1433 | 12467 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1434 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1); | |
1435 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2); | |
1436 | } | ||
1437 |
2/2✓ Branch 0 taken 360443 times.
✓ Branch 1 taken 1228993 times.
|
1589436 | } else if (blk_idx == 3) { |
1438 | 360443 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1439 | 360443 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
1440 | 360443 | ff_hevc_set_neighbour_available(lc, xBase, yBase, | |
1441 | 360443 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1442 | 360443 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1); | |
1443 | 360443 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2); | |
1444 |
2/2✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 356247 times.
|
360443 | if (sps->chroma_format_idc == 2) { |
1445 | 4196 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size), | |
1446 | 4196 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1447 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1); | |
1448 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2); | |
1449 | } | ||
1450 | } | ||
1451 | } | ||
1452 | |||
1453 | 16059231 | return 0; | |
1454 | } | ||
1455 | |||
1456 | 403332 | static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps, | |
1457 | int x0, int y0, int log2_cb_size) | ||
1458 | { | ||
1459 | 403332 | int cb_size = 1 << log2_cb_size; | |
1460 | 403332 | int log2_min_pu_size = sps->log2_min_pu_size; | |
1461 | |||
1462 | 403332 | int min_pu_width = sps->min_pu_width; | |
1463 | 403332 | int x_end = FFMIN(x0 + cb_size, sps->width); | |
1464 | 403332 | int y_end = FFMIN(y0 + cb_size, sps->height); | |
1465 | int i, j; | ||
1466 | |||
1467 |
2/2✓ Branch 0 taken 562404 times.
✓ Branch 1 taken 403332 times.
|
965736 | for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++) |
1468 |
2/2✓ Branch 0 taken 1073856 times.
✓ Branch 1 taken 562404 times.
|
1636260 | for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++) |
1469 | 1073856 | is_pcm[i + j * min_pu_width] = 2; | |
1470 | 403332 | } | |
1471 | |||
1472 | 19346139 | static int hls_transform_tree(HEVCLocalContext *lc, | |
1473 | const HEVCLayerContext *l, | ||
1474 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1475 | int x0, int y0, | ||
1476 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1477 | int log2_cb_size, int log2_trafo_size, | ||
1478 | int trafo_depth, int blk_idx, | ||
1479 | const int *base_cbf_cb, const int *base_cbf_cr) | ||
1480 | { | ||
1481 | 19346139 | const HEVCContext *const s = lc->parent; | |
1482 | uint8_t split_transform_flag; | ||
1483 | int cbf_cb[2]; | ||
1484 | int cbf_cr[2]; | ||
1485 | int ret; | ||
1486 | |||
1487 | 19346139 | cbf_cb[0] = base_cbf_cb[0]; | |
1488 | 19346139 | cbf_cb[1] = base_cbf_cb[1]; | |
1489 | 19346139 | cbf_cr[0] = base_cbf_cr[0]; | |
1490 | 19346139 | cbf_cr[1] = base_cbf_cr[1]; | |
1491 | |||
1492 |
2/2✓ Branch 0 taken 6547826 times.
✓ Branch 1 taken 12798313 times.
|
19346139 | if (lc->cu.intra_split_flag) { |
1493 |
2/2✓ Branch 0 taken 4936200 times.
✓ Branch 1 taken 1611626 times.
|
6547826 | if (trafo_depth == 1) { |
1494 | 4936200 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx]; | |
1495 |
2/2✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4800796 times.
|
4936200 | if (sps->chroma_format_idc == 3) { |
1496 | 135404 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx]; | |
1497 | 135404 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx]; | |
1498 | } else { | ||
1499 | 4800796 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1500 | 4800796 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1501 | } | ||
1502 | } | ||
1503 | } else { | ||
1504 | 12798313 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0]; | |
1505 | 12798313 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1506 | 12798313 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1507 | } | ||
1508 | |||
1509 |
2/2✓ Branch 0 taken 19221944 times.
✓ Branch 1 taken 124195 times.
|
19346139 | if (log2_trafo_size <= sps->log2_max_trafo_size && |
1510 |
2/2✓ Branch 0 taken 10212060 times.
✓ Branch 1 taken 9009884 times.
|
19221944 | log2_trafo_size > sps->log2_min_tb_size && |
1511 |
2/2✓ Branch 0 taken 8594084 times.
✓ Branch 1 taken 1617976 times.
|
10212060 | trafo_depth < lc->cu.max_trafo_depth && |
1512 |
4/4✓ Branch 0 taken 1717275 times.
✓ Branch 1 taken 6876809 times.
✓ Branch 2 taken 490612 times.
✓ Branch 3 taken 1226663 times.
|
8594084 | !(lc->cu.intra_split_flag && trafo_depth == 0)) { |
1513 | 7367421 | split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size); | |
1514 | } else { | ||
1515 | 25638351 | int inter_split = sps->max_transform_hierarchy_depth_inter == 0 && | |
1516 |
2/2✓ Branch 0 taken 836848 times.
✓ Branch 1 taken 844067 times.
|
1680915 | lc->cu.pred_mode == MODE_INTER && |
1517 |
6/6✓ Branch 0 taken 1680915 times.
✓ Branch 1 taken 10297803 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 161299 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
|
13659633 | lc->cu.part_mode != PART_2Nx2N && |
1518 | trafo_depth == 0; | ||
1519 | |||
1520 | 11978718 | split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size || | |
1521 |
8/8✓ Branch 0 taken 11854523 times.
✓ Branch 1 taken 124195 times.
✓ Branch 2 taken 6049167 times.
✓ Branch 3 taken 5805356 times.
✓ Branch 4 taken 4822504 times.
✓ Branch 5 taken 1226663 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10509222 times.
|
11978718 | (lc->cu.intra_split_flag && trafo_depth == 0) || |
1522 | inter_split; | ||
1523 | } | ||
1524 | |||
1525 |
6/6✓ Branch 0 taken 19345947 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8881804 times.
✓ Branch 3 taken 10464143 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8567388 times.
|
19346139 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
1526 |
4/4✓ Branch 0 taken 4580240 times.
✓ Branch 1 taken 6198319 times.
✓ Branch 2 taken 1259672 times.
✓ Branch 3 taken 3320568 times.
|
10778559 | if (trafo_depth == 0 || cbf_cb[0]) { |
1527 | 7457991 | cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1528 |
6/6✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 6859725 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
|
7457991 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1529 | 526996 | cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1530 | } | ||
1531 | } | ||
1532 | |||
1533 |
4/4✓ Branch 0 taken 4580240 times.
✓ Branch 1 taken 6198319 times.
✓ Branch 2 taken 1221820 times.
✓ Branch 3 taken 3358420 times.
|
10778559 | if (trafo_depth == 0 || cbf_cr[0]) { |
1534 | 7420139 | cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1535 |
6/6✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6674833 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
|
7420139 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1536 | 661961 | cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1537 | } | ||
1538 | } | ||
1539 | } | ||
1540 | |||
1541 |
2/2✓ Branch 0 taken 3286907 times.
✓ Branch 1 taken 16059232 times.
|
19346139 | if (split_transform_flag) { |
1542 | 3286907 | const int trafo_size_split = 1 << (log2_trafo_size - 1); | |
1543 | 3286907 | const int x1 = x0 + trafo_size_split; | |
1544 | 3286907 | const int y1 = y0 + trafo_size_split; | |
1545 | |||
1546 | #define SUBDIVIDE(x, y, idx) \ | ||
1547 | do { \ | ||
1548 | ret = hls_transform_tree(lc, l, pps, sps, \ | ||
1549 | x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \ | ||
1550 | log2_trafo_size - 1, trafo_depth + 1, idx, \ | ||
1551 | cbf_cb, cbf_cr); \ | ||
1552 | if (ret < 0) \ | ||
1553 | return ret; \ | ||
1554 | } while (0) | ||
1555 | |||
1556 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
|
3286907 | SUBDIVIDE(x0, y0, 0); |
1557 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
|
3286907 | SUBDIVIDE(x1, y0, 1); |
1558 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
|
3286907 | SUBDIVIDE(x0, y1, 2); |
1559 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
|
3286907 | SUBDIVIDE(x1, y1, 3); |
1560 | |||
1561 | #undef SUBDIVIDE | ||
1562 | } else { | ||
1563 | 16059232 | int min_tu_size = 1 << sps->log2_min_tb_size; | |
1564 | 16059232 | int log2_min_tu_size = sps->log2_min_tb_size; | |
1565 | 16059232 | int min_tu_width = sps->min_tb_width; | |
1566 | 16059232 | int cbf_luma = 1; | |
1567 | |||
1568 |
4/4✓ Branch 0 taken 5884075 times.
✓ Branch 1 taken 10175157 times.
✓ Branch 2 taken 1105689 times.
✓ Branch 3 taken 4778386 times.
|
16059232 | if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 || |
1569 |
4/4✓ Branch 0 taken 909623 times.
✓ Branch 1 taken 196066 times.
✓ Branch 2 taken 779586 times.
✓ Branch 3 taken 130037 times.
|
1105689 | cbf_cb[0] || cbf_cr[0] || |
1570 |
6/6✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 754910 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
|
779586 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1571 | 15292292 | cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth); | |
1572 | } | ||
1573 | |||
1574 | 16059232 | ret = hls_transform_unit(lc, l, pps, sps, | |
1575 | x0, y0, xBase, yBase, cb_xBase, cb_yBase, | ||
1576 | log2_cb_size, log2_trafo_size, | ||
1577 | blk_idx, cbf_luma, cbf_cb, cbf_cr); | ||
1578 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16059231 times.
|
16059232 | if (ret < 0) |
1579 | 1 | return ret; | |
1580 | // TODO: store cbf_luma somewhere else | ||
1581 |
2/2✓ Branch 0 taken 10222853 times.
✓ Branch 1 taken 5836378 times.
|
16059231 | if (cbf_luma) { |
1582 | int i, j; | ||
1583 |
2/2✓ Branch 0 taken 21688627 times.
✓ Branch 1 taken 10222853 times.
|
31911480 | for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size) |
1584 |
2/2✓ Branch 0 taken 81671243 times.
✓ Branch 1 taken 21688627 times.
|
103359870 | for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) { |
1585 | 81671243 | int x_tu = (x0 + j) >> log2_min_tu_size; | |
1586 | 81671243 | int y_tu = (y0 + i) >> log2_min_tu_size; | |
1587 | 81671243 | l->cbf_luma[y_tu * min_tu_width + x_tu] = 1; | |
1588 | } | ||
1589 | } | ||
1590 |
2/2✓ Branch 0 taken 15526411 times.
✓ Branch 1 taken 532820 times.
|
16059231 | if (!s->sh.disable_deblocking_filter_flag) { |
1591 | 15526411 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size); | |
1592 |
2/2✓ Branch 0 taken 409146 times.
✓ Branch 1 taken 15117265 times.
|
15526411 | if (pps->transquant_bypass_enable_flag && |
1593 |
2/2✓ Branch 0 taken 311137 times.
✓ Branch 1 taken 98009 times.
|
409146 | lc->cu.cu_transquant_bypass_flag) |
1594 | 311137 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size); | |
1595 | } | ||
1596 | } | ||
1597 | 19346138 | return 0; | |
1598 | } | ||
1599 | |||
1600 | 12433 | static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
1601 | const HEVCPPS *pps, int x0, int y0, int log2_cb_size) | ||
1602 | { | ||
1603 | 12433 | const HEVCContext *const s = lc->parent; | |
1604 | 12433 | const HEVCSPS *const sps = pps->sps; | |
1605 | GetBitContext gb; | ||
1606 | 12433 | int cb_size = 1 << log2_cb_size; | |
1607 | 12433 | ptrdiff_t stride0 = s->cur_frame->f->linesize[0]; | |
1608 | 12433 | ptrdiff_t stride1 = s->cur_frame->f->linesize[1]; | |
1609 | 12433 | ptrdiff_t stride2 = s->cur_frame->f->linesize[2]; | |
1610 | 12433 | uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)]; | |
1611 | 12433 | uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)]; | |
1612 | 12433 | uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)]; | |
1613 | |||
1614 | 12433 | int length = cb_size * cb_size * sps->pcm.bit_depth + | |
1615 | 12433 | (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) + | |
1616 | 12433 | ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) * | |
1617 | 12433 | sps->pcm.bit_depth_chroma; | |
1618 | 12433 | const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3); | |
1619 | int ret; | ||
1620 | |||
1621 |
2/2✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
|
12433 | if (!s->sh.disable_deblocking_filter_flag) |
1622 | 6937 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
1623 | |||
1624 | 12433 | ret = init_get_bits(&gb, pcm, length); | |
1625 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
|
12433 | if (ret < 0) |
1626 | ✗ | return ret; | |
1627 | |||
1628 | 12433 | s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth); | |
1629 |
1/2✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
|
12433 | if (sps->chroma_format_idc) { |
1630 | 12433 | s->hevcdsp.put_pcm(dst1, stride1, | |
1631 | 12433 | cb_size >> sps->hshift[1], | |
1632 | 12433 | cb_size >> sps->vshift[1], | |
1633 | 12433 | &gb, sps->pcm.bit_depth_chroma); | |
1634 | 12433 | s->hevcdsp.put_pcm(dst2, stride2, | |
1635 | 12433 | cb_size >> sps->hshift[2], | |
1636 | 12433 | cb_size >> sps->vshift[2], | |
1637 | 12433 | &gb, sps->pcm.bit_depth_chroma); | |
1638 | } | ||
1639 | |||
1640 | 12433 | return 0; | |
1641 | } | ||
1642 | |||
1643 | /** | ||
1644 | * 8.5.3.2.2.1 Luma sample unidirectional interpolation process | ||
1645 | * | ||
1646 | * @param s HEVC decoding context | ||
1647 | * @param dst target buffer for block data at block position | ||
1648 | * @param dststride stride of the dst buffer | ||
1649 | * @param ref reference picture buffer at origin (0, 0) | ||
1650 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1651 | * @param x_off horizontal position of block from origin (0, 0) | ||
1652 | * @param y_off vertical position of block from origin (0, 0) | ||
1653 | * @param block_w width of block | ||
1654 | * @param block_h height of block | ||
1655 | * @param luma_weight weighting factor applied to the luma prediction | ||
1656 | * @param luma_offset additive offset applied to the luma prediction value | ||
1657 | */ | ||
1658 | |||
1659 | 5095556 | static void luma_mc_uni(HEVCLocalContext *lc, | |
1660 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1661 | uint8_t *dst, ptrdiff_t dststride, | ||
1662 | const AVFrame *ref, const Mv *mv, int x_off, int y_off, | ||
1663 | int block_w, int block_h, int luma_weight, int luma_offset) | ||
1664 | { | ||
1665 | 5095556 | const HEVCContext *const s = lc->parent; | |
1666 | 5095556 | const uint8_t *src = ref->data[0]; | |
1667 | 5095556 | ptrdiff_t srcstride = ref->linesize[0]; | |
1668 | 5095556 | int pic_width = sps->width; | |
1669 | 5095556 | int pic_height = sps->height; | |
1670 | 5095556 | int mx = mv->x & 3; | |
1671 | 5095556 | int my = mv->y & 3; | |
1672 |
4/4✓ Branch 0 taken 2067314 times.
✓ Branch 1 taken 3028242 times.
✓ Branch 2 taken 2013138 times.
✓ Branch 3 taken 54176 times.
|
10136936 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1673 |
4/4✓ Branch 0 taken 3028242 times.
✓ Branch 1 taken 2013138 times.
✓ Branch 2 taken 70226 times.
✓ Branch 3 taken 2958016 times.
|
5041380 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1674 | 5095556 | int idx = hevc_pel_weight[block_w]; | |
1675 | |||
1676 | 5095556 | x_off += mv->x >> 2; | |
1677 | 5095556 | y_off += mv->y >> 2; | |
1678 | 5095556 | src += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
1679 | |||
1680 |
4/4✓ Branch 0 taken 5036595 times.
✓ Branch 1 taken 58961 times.
✓ Branch 2 taken 4929898 times.
✓ Branch 3 taken 106697 times.
|
5095556 | if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER || |
1681 |
2/2✓ Branch 0 taken 4864534 times.
✓ Branch 1 taken 65364 times.
|
4929898 | x_off >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1682 |
2/2✓ Branch 0 taken 4659765 times.
✓ Branch 1 taken 204769 times.
|
4864534 | y_off >= pic_height - block_h - QPEL_EXTRA_AFTER || |
1683 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4659765 times.
|
4659765 | ref == s->cur_frame->f) { |
1684 | 435791 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1685 | 435791 | int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1686 | 435791 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1687 | |||
1688 | 435791 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset, | |
1689 | edge_emu_stride, srcstride, | ||
1690 | block_w + QPEL_EXTRA, | ||
1691 | block_h + QPEL_EXTRA, | ||
1692 | x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE, | ||
1693 | pic_width, pic_height); | ||
1694 | 435791 | src = lc->edge_emu_buffer + buf_offset; | |
1695 | 435791 | srcstride = edge_emu_stride; | |
1696 | } | ||
1697 | |||
1698 |
2/2✓ Branch 0 taken 4971154 times.
✓ Branch 1 taken 124402 times.
|
5095556 | if (!weight_flag) |
1699 | 4971154 | s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1700 | block_h, mx, my, block_w); | ||
1701 | else | ||
1702 | 124402 | s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1703 | 124402 | block_h, s->sh.luma_log2_weight_denom, | |
1704 | luma_weight, luma_offset, mx, my, block_w); | ||
1705 | 5095556 | } | |
1706 | |||
1707 | /** | ||
1708 | * 8.5.3.2.2.1 Luma sample bidirectional interpolation process | ||
1709 | * | ||
1710 | * @param s HEVC decoding context | ||
1711 | * @param dst target buffer for block data at block position | ||
1712 | * @param dststride stride of the dst buffer | ||
1713 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1714 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1715 | * @param x_off horizontal position of block from origin (0, 0) | ||
1716 | * @param y_off vertical position of block from origin (0, 0) | ||
1717 | * @param block_w width of block | ||
1718 | * @param block_h height of block | ||
1719 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1720 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1721 | * @param current_mv current motion vector structure | ||
1722 | */ | ||
1723 | 3960193 | static void luma_mc_bi(HEVCLocalContext *lc, | |
1724 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1725 | uint8_t *dst, ptrdiff_t dststride, | ||
1726 | const AVFrame *ref0, const Mv *mv0, int x_off, int y_off, | ||
1727 | int block_w, int block_h, const AVFrame *ref1, | ||
1728 | const Mv *mv1, struct MvField *current_mv) | ||
1729 | { | ||
1730 | 3960193 | const HEVCContext *const s = lc->parent; | |
1731 | 3960193 | ptrdiff_t src0stride = ref0->linesize[0]; | |
1732 | 3960193 | ptrdiff_t src1stride = ref1->linesize[0]; | |
1733 | 3960193 | int pic_width = sps->width; | |
1734 | 3960193 | int pic_height = sps->height; | |
1735 | 3960193 | int mx0 = mv0->x & 3; | |
1736 | 3960193 | int my0 = mv0->y & 3; | |
1737 | 3960193 | int mx1 = mv1->x & 3; | |
1738 | 3960193 | int my1 = mv1->y & 3; | |
1739 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3960193 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7920386 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1740 |
3/4✓ Branch 0 taken 3960193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68518 times.
✓ Branch 3 taken 3891675 times.
|
3960193 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1741 | 3960193 | int x_off0 = x_off + (mv0->x >> 2); | |
1742 | 3960193 | int y_off0 = y_off + (mv0->y >> 2); | |
1743 | 3960193 | int x_off1 = x_off + (mv1->x >> 2); | |
1744 | 3960193 | int y_off1 = y_off + (mv1->y >> 2); | |
1745 | 3960193 | int idx = hevc_pel_weight[block_w]; | |
1746 | |||
1747 | 3960193 | const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift); | |
1748 | 3960193 | const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift); | |
1749 | |||
1750 |
4/4✓ Branch 0 taken 3903009 times.
✓ Branch 1 taken 57184 times.
✓ Branch 2 taken 3796710 times.
✓ Branch 3 taken 106299 times.
|
3960193 | if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER || |
1751 |
2/2✓ Branch 0 taken 3728624 times.
✓ Branch 1 taken 68086 times.
|
3796710 | x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1752 |
2/2✓ Branch 0 taken 208159 times.
✓ Branch 1 taken 3520465 times.
|
3728624 | y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1753 | 439728 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1754 | 439728 | int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1755 | 439728 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1756 | |||
1757 | 439728 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset, | |
1758 | edge_emu_stride, src0stride, | ||
1759 | block_w + QPEL_EXTRA, | ||
1760 | block_h + QPEL_EXTRA, | ||
1761 | x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE, | ||
1762 | pic_width, pic_height); | ||
1763 | 439728 | src0 = lc->edge_emu_buffer + buf_offset; | |
1764 | 439728 | src0stride = edge_emu_stride; | |
1765 | } | ||
1766 | |||
1767 |
4/4✓ Branch 0 taken 3896806 times.
✓ Branch 1 taken 63387 times.
✓ Branch 2 taken 3791189 times.
✓ Branch 3 taken 105617 times.
|
3960193 | if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER || |
1768 |
2/2✓ Branch 0 taken 3721188 times.
✓ Branch 1 taken 70001 times.
|
3791189 | x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1769 |
2/2✓ Branch 0 taken 211344 times.
✓ Branch 1 taken 3509844 times.
|
3721188 | y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1770 | 450349 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1771 | 450349 | int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1772 | 450349 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1773 | |||
1774 | 450349 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset, | |
1775 | edge_emu_stride, src1stride, | ||
1776 | block_w + QPEL_EXTRA, | ||
1777 | block_h + QPEL_EXTRA, | ||
1778 | x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE, | ||
1779 | pic_width, pic_height); | ||
1780 | 450349 | src1 = lc->edge_emu_buffer2 + buf_offset; | |
1781 | 450349 | src1stride = edge_emu_stride; | |
1782 | } | ||
1783 | |||
1784 | 3960193 | s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride, | |
1785 | block_h, mx0, my0, block_w); | ||
1786 |
2/2✓ Branch 0 taken 3891675 times.
✓ Branch 1 taken 68518 times.
|
3960193 | if (!weight_flag) |
1787 | 3891675 | s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1788 | block_h, mx1, my1, block_w); | ||
1789 | else | ||
1790 | 68518 | s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1791 | 68518 | block_h, s->sh.luma_log2_weight_denom, | |
1792 | 68518 | s->sh.luma_weight_l0[current_mv->ref_idx[0]], | |
1793 | 68518 | s->sh.luma_weight_l1[current_mv->ref_idx[1]], | |
1794 | 68518 | s->sh.luma_offset_l0[current_mv->ref_idx[0]], | |
1795 | 68518 | s->sh.luma_offset_l1[current_mv->ref_idx[1]], | |
1796 | mx1, my1, block_w); | ||
1797 | |||
1798 | 3960193 | } | |
1799 | |||
1800 | /** | ||
1801 | * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process | ||
1802 | * | ||
1803 | * @param s HEVC decoding context | ||
1804 | * @param dst1 target buffer for block data at block position (U plane) | ||
1805 | * @param dst2 target buffer for block data at block position (V plane) | ||
1806 | * @param dststride stride of the dst1 and dst2 buffers | ||
1807 | * @param ref reference picture buffer at origin (0, 0) | ||
1808 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1809 | * @param x_off horizontal position of block from origin (0, 0) | ||
1810 | * @param y_off vertical position of block from origin (0, 0) | ||
1811 | * @param block_w width of block | ||
1812 | * @param block_h height of block | ||
1813 | * @param chroma_weight weighting factor applied to the chroma prediction | ||
1814 | * @param chroma_offset additive offset applied to the chroma prediction value | ||
1815 | */ | ||
1816 | |||
1817 | 10191112 | static void chroma_mc_uni(HEVCLocalContext *lc, | |
1818 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1819 | uint8_t *dst0, | ||
1820 | ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist, | ||
1821 | int x_off, int y_off, int block_w, int block_h, | ||
1822 | const struct MvField *current_mv, int chroma_weight, int chroma_offset) | ||
1823 | { | ||
1824 | 10191112 | const HEVCContext *const s = lc->parent; | |
1825 | 10191112 | int pic_width = sps->width >> sps->hshift[1]; | |
1826 | 10191112 | int pic_height = sps->height >> sps->vshift[1]; | |
1827 | 10191112 | const Mv *mv = ¤t_mv->mv[reflist]; | |
1828 |
4/4✓ Branch 0 taken 4134628 times.
✓ Branch 1 taken 6056484 times.
✓ Branch 2 taken 4026276 times.
✓ Branch 3 taken 108352 times.
|
20273872 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1829 |
4/4✓ Branch 0 taken 6056484 times.
✓ Branch 1 taken 4026276 times.
✓ Branch 2 taken 140452 times.
✓ Branch 3 taken 5916032 times.
|
10082760 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1830 | 10191112 | int idx = hevc_pel_weight[block_w]; | |
1831 | 10191112 | int hshift = sps->hshift[1]; | |
1832 | 10191112 | int vshift = sps->vshift[1]; | |
1833 | 10191112 | intptr_t mx = av_zero_extend(mv->x, 2 + hshift); | |
1834 | 10191112 | intptr_t my = av_zero_extend(mv->y, 2 + vshift); | |
1835 | 10191112 | intptr_t _mx = mx << (1 - hshift); | |
1836 | 10191112 | intptr_t _my = my << (1 - vshift); | |
1837 |
2/4✓ Branch 0 taken 10191112 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10191112 times.
|
10191112 | int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2]; |
1838 | |||
1839 | 10191112 | x_off += mv->x >> (2 + hshift); | |
1840 | 10191112 | y_off += mv->y >> (2 + vshift); | |
1841 | 10191112 | src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
1842 | |||
1843 |
4/4✓ Branch 0 taken 10083642 times.
✓ Branch 1 taken 107470 times.
✓ Branch 2 taken 9870108 times.
✓ Branch 3 taken 213534 times.
|
10191112 | if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER || |
1844 |
2/2✓ Branch 0 taken 9739388 times.
✓ Branch 1 taken 130720 times.
|
9870108 | x_off >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1845 |
3/4✓ Branch 0 taken 9329792 times.
✓ Branch 1 taken 409596 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9329792 times.
|
9739388 | y_off >= pic_height - block_h - EPEL_EXTRA_AFTER || |
1846 | emu) { | ||
1847 | 861320 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1848 | 861320 | int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift)); | |
1849 | 861320 | int buf_offset0 = EPEL_EXTRA_BEFORE * | |
1850 | 861320 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
1851 | 861320 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0, | |
1852 | edge_emu_stride, srcstride, | ||
1853 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1854 | x_off - EPEL_EXTRA_BEFORE, | ||
1855 | y_off - EPEL_EXTRA_BEFORE, | ||
1856 | pic_width, pic_height); | ||
1857 | |||
1858 | 861320 | src0 = lc->edge_emu_buffer + buf_offset0; | |
1859 | 861320 | srcstride = edge_emu_stride; | |
1860 | } | ||
1861 |
2/2✓ Branch 0 taken 9942308 times.
✓ Branch 1 taken 248804 times.
|
10191112 | if (!weight_flag) |
1862 | 9942308 | s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1863 | block_h, _mx, _my, block_w); | ||
1864 | else | ||
1865 | 248804 | s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1866 | 248804 | block_h, s->sh.chroma_log2_weight_denom, | |
1867 | chroma_weight, chroma_offset, _mx, _my, block_w); | ||
1868 | 10191112 | } | |
1869 | |||
1870 | /** | ||
1871 | * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process | ||
1872 | * | ||
1873 | * @param s HEVC decoding context | ||
1874 | * @param dst target buffer for block data at block position | ||
1875 | * @param dststride stride of the dst buffer | ||
1876 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1877 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1878 | * @param x_off horizontal position of block from origin (0, 0) | ||
1879 | * @param y_off vertical position of block from origin (0, 0) | ||
1880 | * @param block_w width of block | ||
1881 | * @param block_h height of block | ||
1882 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1883 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1884 | * @param current_mv current motion vector structure | ||
1885 | * @param cidx chroma component(cb, cr) | ||
1886 | */ | ||
1887 | 7920386 | static void chroma_mc_bi(HEVCLocalContext *lc, | |
1888 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1889 | uint8_t *dst0, ptrdiff_t dststride, | ||
1890 | const AVFrame *ref0, const AVFrame *ref1, | ||
1891 | int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx) | ||
1892 | { | ||
1893 | 7920386 | const HEVCContext *const s = lc->parent; | |
1894 | 7920386 | const uint8_t *src1 = ref0->data[cidx+1]; | |
1895 | 7920386 | const uint8_t *src2 = ref1->data[cidx+1]; | |
1896 | 7920386 | ptrdiff_t src1stride = ref0->linesize[cidx+1]; | |
1897 | 7920386 | ptrdiff_t src2stride = ref1->linesize[cidx+1]; | |
1898 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7920386 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
15840772 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1899 |
3/4✓ Branch 0 taken 7920386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 137036 times.
✓ Branch 3 taken 7783350 times.
|
7920386 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1900 | 7920386 | int pic_width = sps->width >> sps->hshift[1]; | |
1901 | 7920386 | int pic_height = sps->height >> sps->vshift[1]; | |
1902 | 7920386 | const Mv *const mv0 = ¤t_mv->mv[0]; | |
1903 | 7920386 | const Mv *const mv1 = ¤t_mv->mv[1]; | |
1904 | 7920386 | int hshift = sps->hshift[1]; | |
1905 | 7920386 | int vshift = sps->vshift[1]; | |
1906 | |||
1907 | 7920386 | intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift); | |
1908 | 7920386 | intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift); | |
1909 | 7920386 | intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift); | |
1910 | 7920386 | intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift); | |
1911 | 7920386 | intptr_t _mx0 = mx0 << (1 - hshift); | |
1912 | 7920386 | intptr_t _my0 = my0 << (1 - vshift); | |
1913 | 7920386 | intptr_t _mx1 = mx1 << (1 - hshift); | |
1914 | 7920386 | intptr_t _my1 = my1 << (1 - vshift); | |
1915 | |||
1916 | 7920386 | int x_off0 = x_off + (mv0->x >> (2 + hshift)); | |
1917 | 7920386 | int y_off0 = y_off + (mv0->y >> (2 + vshift)); | |
1918 | 7920386 | int x_off1 = x_off + (mv1->x >> (2 + hshift)); | |
1919 | 7920386 | int y_off1 = y_off + (mv1->y >> (2 + vshift)); | |
1920 | 7920386 | int idx = hevc_pel_weight[block_w]; | |
1921 | 7920386 | src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift); | |
1922 | 7920386 | src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift); | |
1923 | |||
1924 |
4/4✓ Branch 0 taken 7812248 times.
✓ Branch 1 taken 108138 times.
✓ Branch 2 taken 7599538 times.
✓ Branch 3 taken 212710 times.
|
7920386 | if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER || |
1925 |
2/2✓ Branch 0 taken 7463370 times.
✓ Branch 1 taken 136168 times.
|
7599538 | x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1926 |
2/2✓ Branch 0 taken 415730 times.
✓ Branch 1 taken 7047640 times.
|
7463370 | y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
1927 | 872746 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1928 | 872746 | int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift)); | |
1929 | 872746 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
1930 | 872746 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
1931 | |||
1932 | 872746 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1, | |
1933 | edge_emu_stride, src1stride, | ||
1934 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1935 | x_off0 - EPEL_EXTRA_BEFORE, | ||
1936 | y_off0 - EPEL_EXTRA_BEFORE, | ||
1937 | pic_width, pic_height); | ||
1938 | |||
1939 | 872746 | src1 = lc->edge_emu_buffer + buf_offset1; | |
1940 | 872746 | src1stride = edge_emu_stride; | |
1941 | } | ||
1942 | |||
1943 |
4/4✓ Branch 0 taken 7799008 times.
✓ Branch 1 taken 121378 times.
✓ Branch 2 taken 7588052 times.
✓ Branch 3 taken 210956 times.
|
7920386 | if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER || |
1944 |
2/2✓ Branch 0 taken 7448056 times.
✓ Branch 1 taken 139996 times.
|
7588052 | x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1945 |
2/2✓ Branch 0 taken 422362 times.
✓ Branch 1 taken 7025694 times.
|
7448056 | y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
1946 | 894692 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1947 | 894692 | int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift)); | |
1948 | 894692 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
1949 | 894692 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
1950 | |||
1951 | 894692 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1, | |
1952 | edge_emu_stride, src2stride, | ||
1953 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1954 | x_off1 - EPEL_EXTRA_BEFORE, | ||
1955 | y_off1 - EPEL_EXTRA_BEFORE, | ||
1956 | pic_width, pic_height); | ||
1957 | |||
1958 | 894692 | src2 = lc->edge_emu_buffer2 + buf_offset1; | |
1959 | 894692 | src2stride = edge_emu_stride; | |
1960 | } | ||
1961 | |||
1962 | 7920386 | s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride, | |
1963 | block_h, _mx0, _my0, block_w); | ||
1964 |
2/2✓ Branch 0 taken 7783350 times.
✓ Branch 1 taken 137036 times.
|
7920386 | if (!weight_flag) |
1965 | 7783350 | s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1], | |
1966 | 7783350 | src2, src2stride, lc->tmp, | |
1967 | block_h, _mx1, _my1, block_w); | ||
1968 | else | ||
1969 | 137036 | s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1], | |
1970 | 137036 | src2, src2stride, lc->tmp, | |
1971 | block_h, | ||
1972 | 137036 | s->sh.chroma_log2_weight_denom, | |
1973 | 137036 | s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx], | |
1974 | 137036 | s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx], | |
1975 | 137036 | s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx], | |
1976 | 137036 | s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx], | |
1977 | _mx1, _my1, block_w); | ||
1978 | 7920386 | } | |
1979 | |||
1980 | 13015942 | static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref, | |
1981 | const Mv *mv, int y0, int height) | ||
1982 | { | ||
1983 |
2/2✓ Branch 0 taken 111132 times.
✓ Branch 1 taken 12904810 times.
|
13015942 | if (s->avctx->active_thread_type == FF_THREAD_FRAME ) { |
1984 | 111132 | int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9); | |
1985 | |||
1986 | 111132 | ff_progress_frame_await(&ref->tf, y); | |
1987 | } | ||
1988 | 13015942 | } | |
1989 | |||
1990 | 2498802 | static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, | |
1991 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1992 | int x0, int y0, int nPbW, | ||
1993 | int nPbH, int log2_cb_size, int part_idx, | ||
1994 | int merge_idx, MvField *mv) | ||
1995 | { | ||
1996 | 2498802 | const HEVCContext *const s = lc->parent; | |
1997 | 2498802 | enum InterPredIdc inter_pred_idc = PRED_L0; | |
1998 | int mvp_flag; | ||
1999 | |||
2000 | 2498802 | ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size); | |
2001 | 2498802 | mv->pred_flag = 0; | |
2002 |
2/2✓ Branch 0 taken 1900740 times.
✓ Branch 1 taken 598062 times.
|
2498802 | if (s->sh.slice_type == HEVC_SLICE_B) |
2003 | 1900740 | inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH); | |
2004 | |||
2005 |
2/2✓ Branch 0 taken 2091484 times.
✓ Branch 1 taken 407318 times.
|
2498802 | if (inter_pred_idc != PRED_L1) { |
2006 |
1/2✓ Branch 0 taken 2091484 times.
✗ Branch 1 not taken.
|
2091484 | if (s->sh.nb_refs[L0]) |
2007 | 2091484 | mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]); | |
2008 | |||
2009 | 2091484 | mv->pred_flag = PF_L0; | |
2010 | 2091484 | ff_hevc_hls_mvd_coding(lc, x0, y0, 0); | |
2011 | 2091484 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
2012 | 2091484 | ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
2013 | part_idx, merge_idx, mv, mvp_flag, 0); | ||
2014 | 2091484 | mv->mv[0].x += lc->pu.mvd.x; | |
2015 | 2091484 | mv->mv[0].y += lc->pu.mvd.y; | |
2016 | } | ||
2017 | |||
2018 |
2/2✓ Branch 0 taken 829430 times.
✓ Branch 1 taken 1669372 times.
|
2498802 | if (inter_pred_idc != PRED_L0) { |
2019 |
1/2✓ Branch 0 taken 829430 times.
✗ Branch 1 not taken.
|
829430 | if (s->sh.nb_refs[L1]) |
2020 | 829430 | mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]); | |
2021 | |||
2022 |
4/4✓ Branch 0 taken 192341 times.
✓ Branch 1 taken 637089 times.
✓ Branch 2 taken 162774 times.
✓ Branch 3 taken 29567 times.
|
829430 | if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) { |
2023 | 162774 | AV_ZERO32(&lc->pu.mvd); | |
2024 | } else { | ||
2025 | 666656 | ff_hevc_hls_mvd_coding(lc, x0, y0, 1); | |
2026 | } | ||
2027 | |||
2028 | 829430 | mv->pred_flag += PF_L1; | |
2029 | 829430 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
2030 | 829430 | ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
2031 | part_idx, merge_idx, mv, mvp_flag, 1); | ||
2032 | 829430 | mv->mv[1].x += lc->pu.mvd.x; | |
2033 | 829430 | mv->mv[1].y += lc->pu.mvd.y; | |
2034 | } | ||
2035 | 2498802 | } | |
2036 | |||
2037 | 9055749 | static void hls_prediction_unit(HEVCLocalContext *lc, | |
2038 | const HEVCLayerContext *l, | ||
2039 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
2040 | int x0, int y0, int nPbW, int nPbH, | ||
2041 | int log2_cb_size, int partIdx, int idx) | ||
2042 | { | ||
2043 | #define POS(c_idx, x, y) \ | ||
2044 | &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \ | ||
2045 | (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] | ||
2046 | 9055749 | const HEVCContext *const s = lc->parent; | |
2047 | 9055749 | int merge_idx = 0; | |
2048 | 9055749 | struct MvField current_mv = {{{ 0 }}}; | |
2049 | |||
2050 | 9055749 | int min_pu_width = sps->min_pu_width; | |
2051 | |||
2052 | 9055749 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
2053 | 9055749 | const RefPicList *refPicList = s->cur_frame->refPicList; | |
2054 | 9055749 | const HEVCFrame *ref0 = NULL, *ref1 = NULL; | |
2055 | 9055749 | const int *linesize = s->cur_frame->f->linesize; | |
2056 | 9055749 | uint8_t *dst0 = POS(0, x0, y0); | |
2057 | 9055749 | uint8_t *dst1 = POS(1, x0, y0); | |
2058 | 9055749 | uint8_t *dst2 = POS(2, x0, y0); | |
2059 | 9055749 | int log2_min_cb_size = sps->log2_min_cb_size; | |
2060 | 9055749 | int min_cb_width = sps->min_cb_width; | |
2061 | 9055749 | int x_cb = x0 >> log2_min_cb_size; | |
2062 | 9055749 | int y_cb = y0 >> log2_min_cb_size; | |
2063 | int x_pu, y_pu; | ||
2064 | int i, j; | ||
2065 | |||
2066 | 9055749 | int skip_flag = SAMPLE_CTB(l->skip_flag, x_cb, y_cb); | |
2067 | |||
2068 |
2/2✓ Branch 0 taken 4973963 times.
✓ Branch 1 taken 4081786 times.
|
9055749 | if (!skip_flag) |
2069 | 4973963 | lc->pu.merge_flag = ff_hevc_merge_flag_decode(lc); | |
2070 | |||
2071 |
4/4✓ Branch 0 taken 4973963 times.
✓ Branch 1 taken 4081786 times.
✓ Branch 2 taken 2475161 times.
✓ Branch 3 taken 2498802 times.
|
9055749 | if (skip_flag || lc->pu.merge_flag) { |
2072 |
2/2✓ Branch 0 taken 6480094 times.
✓ Branch 1 taken 76853 times.
|
6556947 | if (s->sh.max_num_merge_cand > 1) |
2073 | 6480094 | merge_idx = ff_hevc_merge_idx_decode(lc); | |
2074 | else | ||
2075 | 76853 | merge_idx = 0; | |
2076 | |||
2077 | 6556947 | ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
2078 | partIdx, merge_idx, ¤t_mv); | ||
2079 | } else { | ||
2080 | 2498802 | hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size, | |
2081 | partIdx, merge_idx, ¤t_mv); | ||
2082 | } | ||
2083 | |||
2084 | 9055749 | x_pu = x0 >> sps->log2_min_pu_size; | |
2085 | 9055749 | y_pu = y0 >> sps->log2_min_pu_size; | |
2086 | |||
2087 |
2/2✓ Branch 0 taken 35407858 times.
✓ Branch 1 taken 9055749 times.
|
44463607 | for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++) |
2088 |
2/2✓ Branch 0 taken 233212748 times.
✓ Branch 1 taken 35407858 times.
|
268620606 | for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++) |
2089 | 233212748 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; | |
2090 | |||
2091 |
2/2✓ Branch 0 taken 8241622 times.
✓ Branch 1 taken 814127 times.
|
9055749 | if (current_mv.pred_flag & PF_L0) { |
2092 | 8241622 | ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; | |
2093 |
2/4✓ Branch 0 taken 8241622 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8241622 times.
|
8241622 | if (!ref0 || !ref0->f) |
2094 | ✗ | return; | |
2095 | 8241622 | hevc_await_progress(s, ref0, ¤t_mv.mv[0], y0, nPbH); | |
2096 | } | ||
2097 |
2/2✓ Branch 0 taken 4774320 times.
✓ Branch 1 taken 4281429 times.
|
9055749 | if (current_mv.pred_flag & PF_L1) { |
2098 | 4774320 | ref1 = refPicList[1].ref[current_mv.ref_idx[1]]; | |
2099 |
2/4✓ Branch 0 taken 4774320 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4774320 times.
|
4774320 | if (!ref1 || !ref1->f) |
2100 | ✗ | return; | |
2101 | 4774320 | hevc_await_progress(s, ref1, ¤t_mv.mv[1], y0, nPbH); | |
2102 | } | ||
2103 | |||
2104 |
2/2✓ Branch 0 taken 4281429 times.
✓ Branch 1 taken 4774320 times.
|
9055749 | if (current_mv.pred_flag == PF_L0) { |
2105 | 4281429 | int x0_c = x0 >> sps->hshift[1]; | |
2106 | 4281429 | int y0_c = y0 >> sps->vshift[1]; | |
2107 | 4281429 | int nPbW_c = nPbW >> sps->hshift[1]; | |
2108 | 4281429 | int nPbH_c = nPbH >> sps->vshift[1]; | |
2109 | |||
2110 | 4281429 | luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f, | |
2111 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
2112 | 4281429 | s->sh.luma_weight_l0[current_mv.ref_idx[0]], | |
2113 | 4281429 | s->sh.luma_offset_l0[current_mv.ref_idx[0]]); | |
2114 | |||
2115 |
1/2✓ Branch 0 taken 4281429 times.
✗ Branch 1 not taken.
|
4281429 | if (sps->chroma_format_idc) { |
2116 | 4281429 | chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1], | |
2117 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2118 | 4281429 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]); | |
2119 | 4281429 | chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2], | |
2120 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2121 | 4281429 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]); | |
2122 | } | ||
2123 |
2/2✓ Branch 0 taken 814127 times.
✓ Branch 1 taken 3960193 times.
|
4774320 | } else if (current_mv.pred_flag == PF_L1) { |
2124 | 814127 | int x0_c = x0 >> sps->hshift[1]; | |
2125 | 814127 | int y0_c = y0 >> sps->vshift[1]; | |
2126 | 814127 | int nPbW_c = nPbW >> sps->hshift[1]; | |
2127 | 814127 | int nPbH_c = nPbH >> sps->vshift[1]; | |
2128 | |||
2129 | 814127 | luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f, | |
2130 | ¤t_mv.mv[1], x0, y0, nPbW, nPbH, | ||
2131 | 814127 | s->sh.luma_weight_l1[current_mv.ref_idx[1]], | |
2132 | 814127 | s->sh.luma_offset_l1[current_mv.ref_idx[1]]); | |
2133 | |||
2134 |
1/2✓ Branch 0 taken 814127 times.
✗ Branch 1 not taken.
|
814127 | if (sps->chroma_format_idc) { |
2135 | 814127 | chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1], | |
2136 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2137 | 814127 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]); | |
2138 | |||
2139 | 814127 | chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2], | |
2140 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2141 | 814127 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]); | |
2142 | } | ||
2143 |
1/2✓ Branch 0 taken 3960193 times.
✗ Branch 1 not taken.
|
3960193 | } else if (current_mv.pred_flag == PF_BI) { |
2144 | 3960193 | int x0_c = x0 >> sps->hshift[1]; | |
2145 | 3960193 | int y0_c = y0 >> sps->vshift[1]; | |
2146 | 3960193 | int nPbW_c = nPbW >> sps->hshift[1]; | |
2147 | 3960193 | int nPbH_c = nPbH >> sps->vshift[1]; | |
2148 | |||
2149 | 3960193 | luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f, | |
2150 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
2151 | 3960193 | ref1->f, ¤t_mv.mv[1], ¤t_mv); | |
2152 | |||
2153 |
1/2✓ Branch 0 taken 3960193 times.
✗ Branch 1 not taken.
|
3960193 | if (sps->chroma_format_idc) { |
2154 | 3960193 | chroma_mc_bi(lc, pps, sps, dst1, linesize[1], ref0->f, ref1->f, | |
2155 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0); | ||
2156 | |||
2157 | 3960193 | chroma_mc_bi(lc, pps, sps, dst2, linesize[2], ref0->f, ref1->f, | |
2158 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1); | ||
2159 | } | ||
2160 | } | ||
2161 | } | ||
2162 | |||
2163 | /** | ||
2164 | * 8.4.1 | ||
2165 | */ | ||
2166 | 7937817 | static int luma_intra_pred_mode(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
2167 | const HEVCSPS *sps, | ||
2168 | int x0, int y0, int pu_size, | ||
2169 | int prev_intra_luma_pred_flag) | ||
2170 | { | ||
2171 | 7937817 | const HEVCContext *const s = lc->parent; | |
2172 | 7937817 | int x_pu = x0 >> sps->log2_min_pu_size; | |
2173 | 7937817 | int y_pu = y0 >> sps->log2_min_pu_size; | |
2174 | 7937817 | int min_pu_width = sps->min_pu_width; | |
2175 | 7937817 | int size_in_pus = pu_size >> sps->log2_min_pu_size; | |
2176 | 7937817 | int x0b = av_zero_extend(x0, sps->log2_ctb_size); | |
2177 | 7937817 | int y0b = av_zero_extend(y0, sps->log2_ctb_size); | |
2178 | |||
2179 |
2/2✓ Branch 0 taken 1064812 times.
✓ Branch 1 taken 124209 times.
|
1189021 | int cand_up = (lc->ctb_up_flag || y0b) ? |
2180 |
2/2✓ Branch 0 taken 1189021 times.
✓ Branch 1 taken 6748796 times.
|
9126838 | l->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC; |
2181 |
2/2✓ Branch 0 taken 589762 times.
✓ Branch 1 taken 80835 times.
|
670597 | int cand_left = (lc->ctb_left_flag || x0b) ? |
2182 |
2/2✓ Branch 0 taken 670597 times.
✓ Branch 1 taken 7267220 times.
|
8608414 | l->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC; |
2183 | |||
2184 | 7937817 | int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size); | |
2185 | |||
2186 | 7937817 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
2187 | int intra_pred_mode; | ||
2188 | int candidate[3]; | ||
2189 | int i, j; | ||
2190 | |||
2191 | // intra_pred_mode prediction does not cross vertical CTB boundaries | ||
2192 |
2/2✓ Branch 0 taken 1033091 times.
✓ Branch 1 taken 6904726 times.
|
7937817 | if ((y0 - 1) < y_ctb) |
2193 | 1033091 | cand_up = INTRA_DC; | |
2194 | |||
2195 |
2/2✓ Branch 0 taken 1672482 times.
✓ Branch 1 taken 6265335 times.
|
7937817 | if (cand_left == cand_up) { |
2196 |
2/2✓ Branch 0 taken 990780 times.
✓ Branch 1 taken 681702 times.
|
1672482 | if (cand_left < 2) { |
2197 | 990780 | candidate[0] = INTRA_PLANAR; | |
2198 | 990780 | candidate[1] = INTRA_DC; | |
2199 | 990780 | candidate[2] = INTRA_ANGULAR_26; | |
2200 | } else { | ||
2201 | 681702 | candidate[0] = cand_left; | |
2202 | 681702 | candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31); | |
2203 | 681702 | candidate[2] = 2 + ((cand_left - 2 + 1) & 31); | |
2204 | } | ||
2205 | } else { | ||
2206 | 6265335 | candidate[0] = cand_left; | |
2207 | 6265335 | candidate[1] = cand_up; | |
2208 |
4/4✓ Branch 0 taken 5196254 times.
✓ Branch 1 taken 1069081 times.
✓ Branch 2 taken 4288799 times.
✓ Branch 3 taken 907455 times.
|
6265335 | if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) { |
2209 | 4288799 | candidate[2] = INTRA_PLANAR; | |
2210 |
4/4✓ Branch 0 taken 1727771 times.
✓ Branch 1 taken 248765 times.
✓ Branch 2 taken 1301443 times.
✓ Branch 3 taken 426328 times.
|
1976536 | } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) { |
2211 | 1301443 | candidate[2] = INTRA_DC; | |
2212 | } else { | ||
2213 | 675093 | candidate[2] = INTRA_ANGULAR_26; | |
2214 | } | ||
2215 | } | ||
2216 | |||
2217 |
2/2✓ Branch 0 taken 4775607 times.
✓ Branch 1 taken 3162210 times.
|
7937817 | if (prev_intra_luma_pred_flag) { |
2218 | 4775607 | intra_pred_mode = candidate[lc->pu.mpm_idx]; | |
2219 | } else { | ||
2220 |
2/2✓ Branch 0 taken 1508646 times.
✓ Branch 1 taken 1653564 times.
|
3162210 | if (candidate[0] > candidate[1]) |
2221 | 1508646 | FFSWAP(uint8_t, candidate[0], candidate[1]); | |
2222 |
2/2✓ Branch 0 taken 1875221 times.
✓ Branch 1 taken 1286989 times.
|
3162210 | if (candidate[0] > candidate[2]) |
2223 | 1875221 | FFSWAP(uint8_t, candidate[0], candidate[2]); | |
2224 |
2/2✓ Branch 0 taken 2353015 times.
✓ Branch 1 taken 809195 times.
|
3162210 | if (candidate[1] > candidate[2]) |
2225 | 2353015 | FFSWAP(uint8_t, candidate[1], candidate[2]); | |
2226 | |||
2227 | 3162210 | intra_pred_mode = lc->pu.rem_intra_luma_pred_mode; | |
2228 |
2/2✓ Branch 0 taken 9486630 times.
✓ Branch 1 taken 3162210 times.
|
12648840 | for (i = 0; i < 3; i++) |
2229 |
2/2✓ Branch 0 taken 6910867 times.
✓ Branch 1 taken 2575763 times.
|
9486630 | if (intra_pred_mode >= candidate[i]) |
2230 | 6910867 | intra_pred_mode++; | |
2231 | } | ||
2232 | |||
2233 | /* write the intra prediction units into the mv array */ | ||
2234 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7937817 times.
|
7937817 | if (!size_in_pus) |
2235 | ✗ | size_in_pus = 1; | |
2236 |
2/2✓ Branch 0 taken 14343066 times.
✓ Branch 1 taken 7937817 times.
|
22280883 | for (i = 0; i < size_in_pus; i++) { |
2237 | 14343066 | memset(&l->tab_ipm[(y_pu + i) * min_pu_width + x_pu], | |
2238 | intra_pred_mode, size_in_pus); | ||
2239 | |||
2240 |
2/2✓ Branch 0 taken 47697996 times.
✓ Branch 1 taken 14343066 times.
|
62041062 | for (j = 0; j < size_in_pus; j++) { |
2241 | 47697996 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA; | |
2242 | } | ||
2243 | } | ||
2244 | |||
2245 | 7937817 | return intra_pred_mode; | |
2246 | } | ||
2247 | |||
2248 | 11662466 | static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth, | |
2249 | int x0, int y0, | ||
2250 | int log2_cb_size, int ct_depth) | ||
2251 | { | ||
2252 | 11662466 | int length = (1 << log2_cb_size) >> sps->log2_min_cb_size; | |
2253 | 11662466 | int x_cb = x0 >> sps->log2_min_cb_size; | |
2254 | 11662466 | int y_cb = y0 >> sps->log2_min_cb_size; | |
2255 | int y; | ||
2256 | |||
2257 |
2/2✓ Branch 0 taken 22049211 times.
✓ Branch 1 taken 11662466 times.
|
33711677 | for (y = 0; y < length; y++) |
2258 | 22049211 | memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb], | |
2259 | ct_depth, length); | ||
2260 | 11662466 | } | |
2261 | |||
2262 | static const uint8_t tab_mode_idx[] = { | ||
2263 | 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, | ||
2264 | 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31}; | ||
2265 | |||
2266 | 4235667 | static void intra_prediction_unit(HEVCLocalContext *lc, | |
2267 | const HEVCLayerContext *l, const HEVCSPS *sps, | ||
2268 | int x0, int y0, | ||
2269 | int log2_cb_size) | ||
2270 | { | ||
2271 | static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 }; | ||
2272 | uint8_t prev_intra_luma_pred_flag[4]; | ||
2273 | 4235667 | int split = lc->cu.part_mode == PART_NxN; | |
2274 | 4235667 | int pb_size = (1 << log2_cb_size) >> split; | |
2275 | 4235667 | int side = split + 1; | |
2276 | int chroma_mode; | ||
2277 | int i, j; | ||
2278 | |||
2279 |
2/2✓ Branch 0 taken 5469717 times.
✓ Branch 1 taken 4235667 times.
|
9705384 | for (i = 0; i < side; i++) |
2280 |
2/2✓ Branch 0 taken 7937817 times.
✓ Branch 1 taken 5469717 times.
|
13407534 | for (j = 0; j < side; j++) |
2281 | 7937817 | prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc); | |
2282 | |||
2283 |
2/2✓ Branch 0 taken 5469717 times.
✓ Branch 1 taken 4235667 times.
|
9705384 | for (i = 0; i < side; i++) { |
2284 |
2/2✓ Branch 0 taken 7937817 times.
✓ Branch 1 taken 5469717 times.
|
13407534 | for (j = 0; j < side; j++) { |
2285 |
2/2✓ Branch 0 taken 4775607 times.
✓ Branch 1 taken 3162210 times.
|
7937817 | if (prev_intra_luma_pred_flag[2 * i + j]) |
2286 | 4775607 | lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc); | |
2287 | else | ||
2288 | 3162210 | lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc); | |
2289 | |||
2290 | 7937817 | lc->pu.intra_pred_mode[2 * i + j] = | |
2291 | 7937817 | luma_intra_pred_mode(lc, l, sps, | |
2292 | 7937817 | x0 + pb_size * j, y0 + pb_size * i, pb_size, | |
2293 | 7937817 | prev_intra_luma_pred_flag[2 * i + j]); | |
2294 | } | ||
2295 | } | ||
2296 | |||
2297 |
2/2✓ Branch 0 taken 105006 times.
✓ Branch 1 taken 4130661 times.
|
4235667 | if (sps->chroma_format_idc == 3) { |
2298 |
2/2✓ Branch 0 taken 138857 times.
✓ Branch 1 taken 105006 times.
|
243863 | for (i = 0; i < side; i++) { |
2299 |
2/2✓ Branch 0 taken 206559 times.
✓ Branch 1 taken 138857 times.
|
345416 | for (j = 0; j < side; j++) { |
2300 | 206559 | lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
2301 |
2/2✓ Branch 0 taken 34248 times.
✓ Branch 1 taken 172311 times.
|
206559 | if (chroma_mode != 4) { |
2302 |
2/2✓ Branch 0 taken 2343 times.
✓ Branch 1 taken 31905 times.
|
34248 | if (lc->pu.intra_pred_mode[2 * i + j] == intra_chroma_table[chroma_mode]) |
2303 | 2343 | lc->pu.intra_pred_mode_c[2 * i + j] = 34; | |
2304 | else | ||
2305 | 31905 | lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode]; | |
2306 | } else { | ||
2307 | 172311 | lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j]; | |
2308 | } | ||
2309 | } | ||
2310 | } | ||
2311 |
2/2✓ Branch 0 taken 247106 times.
✓ Branch 1 taken 3883555 times.
|
4130661 | } else if (sps->chroma_format_idc == 2) { |
2312 | int mode_idx; | ||
2313 | 247106 | lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
2314 |
2/2✓ Branch 0 taken 73995 times.
✓ Branch 1 taken 173111 times.
|
247106 | if (chroma_mode != 4) { |
2315 |
2/2✓ Branch 0 taken 3515 times.
✓ Branch 1 taken 70480 times.
|
73995 | if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode]) |
2316 | 3515 | mode_idx = 34; | |
2317 | else | ||
2318 | 70480 | mode_idx = intra_chroma_table[chroma_mode]; | |
2319 | } else { | ||
2320 | 173111 | mode_idx = lc->pu.intra_pred_mode[0]; | |
2321 | } | ||
2322 | 247106 | lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx]; | |
2323 |
2/2✓ Branch 0 taken 3883363 times.
✓ Branch 1 taken 192 times.
|
3883555 | } else if (sps->chroma_format_idc != 0) { |
2324 | 3883363 | chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
2325 |
2/2✓ Branch 0 taken 964565 times.
✓ Branch 1 taken 2918798 times.
|
3883363 | if (chroma_mode != 4) { |
2326 |
2/2✓ Branch 0 taken 71726 times.
✓ Branch 1 taken 892839 times.
|
964565 | if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode]) |
2327 | 71726 | lc->pu.intra_pred_mode_c[0] = 34; | |
2328 | else | ||
2329 | 892839 | lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode]; | |
2330 | } else { | ||
2331 | 2918798 | lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0]; | |
2332 | } | ||
2333 | } | ||
2334 | 4235667 | } | |
2335 | |||
2336 | 7426800 | static void intra_prediction_unit_default_value(HEVCLocalContext *lc, | |
2337 | const HEVCLayerContext *l, | ||
2338 | const HEVCSPS *sps, | ||
2339 | int x0, int y0, | ||
2340 | int log2_cb_size) | ||
2341 | { | ||
2342 | 7426800 | const HEVCContext *const s = lc->parent; | |
2343 | 7426800 | int pb_size = 1 << log2_cb_size; | |
2344 | 7426800 | int size_in_pus = pb_size >> sps->log2_min_pu_size; | |
2345 | 7426800 | int min_pu_width = sps->min_pu_width; | |
2346 | 7426800 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
2347 | 7426800 | int x_pu = x0 >> sps->log2_min_pu_size; | |
2348 | 7426800 | int y_pu = y0 >> sps->log2_min_pu_size; | |
2349 | int j, k; | ||
2350 | |||
2351 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7426800 times.
|
7426800 | if (size_in_pus == 0) |
2352 | ✗ | size_in_pus = 1; | |
2353 |
2/2✓ Branch 0 taken 32223458 times.
✓ Branch 1 taken 7426800 times.
|
39650258 | for (j = 0; j < size_in_pus; j++) |
2354 | 32223458 | memset(&l->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus); | |
2355 |
2/2✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 7414367 times.
|
7426800 | if (lc->cu.pred_mode == MODE_INTRA) |
2356 |
2/2✓ Branch 0 taken 40908 times.
✓ Branch 1 taken 12433 times.
|
53341 | for (j = 0; j < size_in_pus; j++) |
2357 |
2/2✓ Branch 0 taken 182512 times.
✓ Branch 1 taken 40908 times.
|
223420 | for (k = 0; k < size_in_pus; k++) |
2358 | 182512 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA; | |
2359 | 7426800 | } | |
2360 | |||
2361 | 11662467 | static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, | |
2362 | const HEVCLayerContext *l, | ||
2363 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
2364 | int x0, int y0, int log2_cb_size) | ||
2365 | { | ||
2366 | 11662467 | int cb_size = 1 << log2_cb_size; | |
2367 | 11662467 | int log2_min_cb_size = sps->log2_min_cb_size; | |
2368 | 11662467 | int length = cb_size >> log2_min_cb_size; | |
2369 | 11662467 | int min_cb_width = sps->min_cb_width; | |
2370 | 11662467 | int x_cb = x0 >> log2_min_cb_size; | |
2371 | 11662467 | int y_cb = y0 >> log2_min_cb_size; | |
2372 | 11662467 | int idx = log2_cb_size - 2; | |
2373 | 11662467 | int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1; | |
2374 | int x, y, ret; | ||
2375 | |||
2376 | 11662467 | lc->cu.x = x0; | |
2377 | 11662467 | lc->cu.y = y0; | |
2378 | 11662467 | lc->cu.pred_mode = MODE_INTRA; | |
2379 | 11662467 | lc->cu.part_mode = PART_2Nx2N; | |
2380 | 11662467 | lc->cu.intra_split_flag = 0; | |
2381 | |||
2382 | 11662467 | SAMPLE_CTB(l->skip_flag, x_cb, y_cb) = 0; | |
2383 |
2/2✓ Branch 0 taken 46649868 times.
✓ Branch 1 taken 11662467 times.
|
58312335 | for (x = 0; x < 4; x++) |
2384 | 46649868 | lc->pu.intra_pred_mode[x] = 1; | |
2385 |
2/2✓ Branch 0 taken 211788 times.
✓ Branch 1 taken 11450679 times.
|
11662467 | if (pps->transquant_bypass_enable_flag) { |
2386 | 211788 | lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(lc); | |
2387 |
2/2✓ Branch 0 taken 92187 times.
✓ Branch 1 taken 119601 times.
|
211788 | if (lc->cu.cu_transquant_bypass_flag) |
2388 | 92187 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size); | |
2389 | } else | ||
2390 | 11450679 | lc->cu.cu_transquant_bypass_flag = 0; | |
2391 | |||
2392 |
2/2✓ Branch 0 taken 8550547 times.
✓ Branch 1 taken 3111920 times.
|
11662467 | if (s->sh.slice_type != HEVC_SLICE_I) { |
2393 | 8550547 | const int x0b = av_zero_extend(x0, sps->log2_ctb_size); | |
2394 | 8550547 | const int y0b = av_zero_extend(y0, sps->log2_ctb_size); | |
2395 | 8550547 | uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, l->skip_flag, | |
2396 | x0b, y0b, x_cb, y_cb, | ||
2397 | min_cb_width); | ||
2398 | |||
2399 | 8550547 | x = y_cb * min_cb_width + x_cb; | |
2400 |
2/2✓ Branch 0 taken 17829469 times.
✓ Branch 1 taken 8550547 times.
|
26380016 | for (y = 0; y < length; y++) { |
2401 | 17829469 | memset(&l->skip_flag[x], skip_flag, length); | |
2402 | 17829469 | x += min_cb_width; | |
2403 | } | ||
2404 |
2/2✓ Branch 0 taken 4081786 times.
✓ Branch 1 taken 4468761 times.
|
8550547 | lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER; |
2405 | } else { | ||
2406 | 3111920 | x = y_cb * min_cb_width + x_cb; | |
2407 |
2/2✓ Branch 0 taken 4219743 times.
✓ Branch 1 taken 3111920 times.
|
7331663 | for (y = 0; y < length; y++) { |
2408 | 4219743 | memset(&l->skip_flag[x], 0, length); | |
2409 | 4219743 | x += min_cb_width; | |
2410 | } | ||
2411 | } | ||
2412 | |||
2413 |
2/2✓ Branch 0 taken 4081786 times.
✓ Branch 1 taken 7580681 times.
|
11662467 | if (SAMPLE_CTB(l->skip_flag, x_cb, y_cb)) { |
2414 | 4081786 | hls_prediction_unit(lc, l, pps, sps, | |
2415 | x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | ||
2416 | 4081786 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
2417 | |||
2418 |
2/2✓ Branch 0 taken 3935273 times.
✓ Branch 1 taken 146513 times.
|
4081786 | if (!s->sh.disable_deblocking_filter_flag) |
2419 | 3935273 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
2420 | } else { | ||
2421 | 7580681 | int pcm_flag = 0; | |
2422 | |||
2423 |
2/2✓ Branch 0 taken 4468761 times.
✓ Branch 1 taken 3111920 times.
|
7580681 | if (s->sh.slice_type != HEVC_SLICE_I) |
2424 | 4468761 | lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc); | |
2425 |
2/2✓ Branch 0 taken 4248100 times.
✓ Branch 1 taken 3332581 times.
|
7580681 | if (lc->cu.pred_mode != MODE_INTRA || |
2426 |
2/2✓ Branch 0 taken 3196179 times.
✓ Branch 1 taken 1051921 times.
|
4248100 | log2_cb_size == sps->log2_min_cb_size) { |
2427 | 6528760 | lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size); | |
2428 |
2/2✓ Branch 0 taken 1339686 times.
✓ Branch 1 taken 5189074 times.
|
7868446 | lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN && |
2429 |
2/2✓ Branch 0 taken 1234050 times.
✓ Branch 1 taken 105636 times.
|
1339686 | lc->cu.pred_mode == MODE_INTRA; |
2430 | } | ||
2431 | |||
2432 |
2/2✓ Branch 0 taken 4248100 times.
✓ Branch 1 taken 3332581 times.
|
7580681 | if (lc->cu.pred_mode == MODE_INTRA) { |
2433 |
4/4✓ Branch 0 taken 3014050 times.
✓ Branch 1 taken 1234050 times.
✓ Branch 2 taken 162684 times.
✓ Branch 3 taken 2851366 times.
|
4248100 | if (lc->cu.part_mode == PART_2Nx2N && sps->pcm_enabled && |
2434 |
2/2✓ Branch 0 taken 160815 times.
✓ Branch 1 taken 1869 times.
|
162684 | log2_cb_size >= sps->pcm.log2_min_pcm_cb_size && |
2435 |
2/2✓ Branch 0 taken 153183 times.
✓ Branch 1 taken 7632 times.
|
160815 | log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) { |
2436 | 153183 | pcm_flag = ff_hevc_pcm_flag_decode(lc); | |
2437 | } | ||
2438 |
2/2✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 4235667 times.
|
4248100 | if (pcm_flag) { |
2439 | 12433 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
2440 | 12433 | ret = hls_pcm_sample(lc, l, pps, x0, y0, log2_cb_size); | |
2441 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12425 times.
|
12433 | if (sps->pcm_loop_filter_disabled) |
2442 | 8 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size); | |
2443 | |||
2444 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
|
12433 | if (ret < 0) |
2445 | ✗ | return ret; | |
2446 | } else { | ||
2447 | 4235667 | intra_prediction_unit(lc, l, sps, x0, y0, log2_cb_size); | |
2448 | } | ||
2449 | } else { | ||
2450 | 3332581 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
2451 |
8/9✓ Branch 0 taken 1902471 times.
✓ Branch 1 taken 456818 times.
✓ Branch 2 taken 557201 times.
✓ Branch 3 taken 67005 times.
✓ Branch 4 taken 57888 times.
✓ Branch 5 taken 99971 times.
✓ Branch 6 taken 85591 times.
✓ Branch 7 taken 105636 times.
✗ Branch 8 not taken.
|
3332581 | switch (lc->cu.part_mode) { |
2452 | 1902471 | case PART_2Nx2N: | |
2453 | 1902471 | hls_prediction_unit(lc, l, pps, sps, | |
2454 | x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | ||
2455 | 1902471 | break; | |
2456 | 456818 | case PART_2NxN: | |
2457 | 456818 | hls_prediction_unit(lc, l, pps, sps, | |
2458 | x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx); | ||
2459 | 456818 | hls_prediction_unit(lc, l, pps, sps, | |
2460 | 456818 | x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx); | |
2461 | 456818 | break; | |
2462 | 557201 | case PART_Nx2N: | |
2463 | 557201 | hls_prediction_unit(lc, l, pps, sps, | |
2464 | x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1); | ||
2465 | 557201 | hls_prediction_unit(lc, l, pps, sps, | |
2466 | 557201 | x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1); | |
2467 | 557201 | break; | |
2468 | 67005 | case PART_2NxnU: | |
2469 | 67005 | hls_prediction_unit(lc, l, pps, sps, | |
2470 | x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx); | ||
2471 | 67005 | hls_prediction_unit(lc, l, pps, sps, | |
2472 | 67005 | x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx); | |
2473 | 67005 | break; | |
2474 | 57888 | case PART_2NxnD: | |
2475 | 57888 | hls_prediction_unit(lc, l, pps, sps, | |
2476 | 57888 | x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx); | |
2477 | 57888 | hls_prediction_unit(lc, l, pps, sps, | |
2478 | 57888 | x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx); | |
2479 | 57888 | break; | |
2480 | 99971 | case PART_nLx2N: | |
2481 | 99971 | hls_prediction_unit(lc, l, pps, sps, | |
2482 | x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2); | ||
2483 | 99971 | hls_prediction_unit(lc, l, pps, sps, | |
2484 | 99971 | x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2); | |
2485 | 99971 | break; | |
2486 | 85591 | case PART_nRx2N: | |
2487 | 85591 | hls_prediction_unit(lc, l, pps, sps, | |
2488 | 85591 | x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2); | |
2489 | 85591 | hls_prediction_unit(lc, l, pps, sps, | |
2490 | 85591 | x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2); | |
2491 | 85591 | break; | |
2492 | 105636 | case PART_NxN: | |
2493 | 105636 | hls_prediction_unit(lc, l, pps, sps, | |
2494 | x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1); | ||
2495 | 105636 | hls_prediction_unit(lc, l, pps, sps, | |
2496 | 105636 | x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1); | |
2497 | 105636 | hls_prediction_unit(lc, l, pps, sps, | |
2498 | 105636 | x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1); | |
2499 | 105636 | hls_prediction_unit(lc, l, pps, sps, | |
2500 | 105636 | x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1); | |
2501 | 105636 | break; | |
2502 | } | ||
2503 | } | ||
2504 | |||
2505 |
2/2✓ Branch 0 taken 7568248 times.
✓ Branch 1 taken 12433 times.
|
7580681 | if (!pcm_flag) { |
2506 | 7568248 | int rqt_root_cbf = 1; | |
2507 | |||
2508 |
2/2✓ Branch 0 taken 3332581 times.
✓ Branch 1 taken 4235667 times.
|
7568248 | if (lc->cu.pred_mode != MODE_INTRA && |
2509 |
4/4✓ Branch 0 taken 1902471 times.
✓ Branch 1 taken 1430110 times.
✓ Branch 2 taken 1040595 times.
✓ Branch 3 taken 861876 times.
|
3332581 | !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) { |
2510 | 2470705 | rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc); | |
2511 | } | ||
2512 |
2/2✓ Branch 0 taken 6198511 times.
✓ Branch 1 taken 1369737 times.
|
7568248 | if (rqt_root_cbf) { |
2513 | const static int cbf[2] = { 0 }; | ||
2514 |
2/2✓ Branch 0 taken 4235667 times.
✓ Branch 1 taken 1962844 times.
|
6198511 | lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ? |
2515 | 4235667 | sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag : | |
2516 | 1962844 | sps->max_transform_hierarchy_depth_inter; | |
2517 | 6198511 | ret = hls_transform_tree(lc, l, pps, sps, x0, y0, x0, y0, x0, y0, | |
2518 | log2_cb_size, | ||
2519 | log2_cb_size, 0, 0, cbf, cbf); | ||
2520 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6198510 times.
|
6198511 | if (ret < 0) |
2521 | 1 | return ret; | |
2522 | } else { | ||
2523 |
2/2✓ Branch 0 taken 1313305 times.
✓ Branch 1 taken 56432 times.
|
1369737 | if (!s->sh.disable_deblocking_filter_flag) |
2524 | 1313305 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
2525 | } | ||
2526 | } | ||
2527 | } | ||
2528 | |||
2529 |
4/4✓ Branch 0 taken 2077208 times.
✓ Branch 1 taken 9585258 times.
✓ Branch 2 taken 818343 times.
✓ Branch 3 taken 1258865 times.
|
11662466 | if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0) |
2530 | 818343 | ff_hevc_set_qPy(lc, l, pps, x0, y0, log2_cb_size); | |
2531 | |||
2532 | 11662466 | x = y_cb * min_cb_width + x_cb; | |
2533 |
2/2✓ Branch 0 taken 22049211 times.
✓ Branch 1 taken 11662466 times.
|
33711677 | for (y = 0; y < length; y++) { |
2534 | 22049211 | memset(&l->qp_y_tab[x], lc->qp_y, length); | |
2535 | 22049211 | x += min_cb_width; | |
2536 | } | ||
2537 | |||
2538 |
2/2✓ Branch 0 taken 4021512 times.
✓ Branch 1 taken 7640954 times.
|
11662466 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
2539 |
2/2✓ Branch 0 taken 2380064 times.
✓ Branch 1 taken 1641448 times.
|
4021512 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) { |
2540 | 2380064 | lc->qPy_pred = lc->qp_y; | |
2541 | } | ||
2542 | |||
2543 | 11662466 | set_ct_depth(sps, l->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth); | |
2544 | |||
2545 | 11662466 | return 0; | |
2546 | } | ||
2547 | |||
2548 | 15184963 | static int hls_coding_quadtree(HEVCLocalContext *lc, | |
2549 | const HEVCLayerContext *l, | ||
2550 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
2551 | int x0, int y0, | ||
2552 | int log2_cb_size, int cb_depth) | ||
2553 | { | ||
2554 | 15184963 | const HEVCContext *const s = lc->parent; | |
2555 | 15184963 | const int cb_size = 1 << log2_cb_size; | |
2556 | int ret; | ||
2557 | int split_cu; | ||
2558 | |||
2559 | 15184963 | lc->ct_depth = cb_depth; | |
2560 |
2/2✓ Branch 0 taken 15156000 times.
✓ Branch 1 taken 28963 times.
|
15184963 | if (x0 + cb_size <= sps->width && |
2561 |
2/2✓ Branch 0 taken 14833756 times.
✓ Branch 1 taken 322244 times.
|
15156000 | y0 + cb_size <= sps->height && |
2562 |
2/2✓ Branch 0 taken 8075142 times.
✓ Branch 1 taken 6758614 times.
|
14833756 | log2_cb_size > sps->log2_min_cb_size) { |
2563 | 8075142 | split_cu = ff_hevc_split_coding_unit_flag_decode(lc, l->tab_ct_depth, | |
2564 | sps, cb_depth, x0, y0); | ||
2565 | } else { | ||
2566 | 7109821 | split_cu = (log2_cb_size > sps->log2_min_cb_size); | |
2567 | } | ||
2568 |
2/2✓ Branch 0 taken 2686255 times.
✓ Branch 1 taken 12498708 times.
|
15184963 | if (pps->cu_qp_delta_enabled_flag && |
2569 |
2/2✓ Branch 0 taken 1536373 times.
✓ Branch 1 taken 1149882 times.
|
2686255 | log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) { |
2570 | 1536373 | lc->tu.is_cu_qp_delta_coded = 0; | |
2571 | 1536373 | lc->tu.cu_qp_delta = 0; | |
2572 | } | ||
2573 | |||
2574 |
2/2✓ Branch 0 taken 519326 times.
✓ Branch 1 taken 14665637 times.
|
15184963 | if (s->sh.cu_chroma_qp_offset_enabled_flag && |
2575 |
1/2✓ Branch 0 taken 519326 times.
✗ Branch 1 not taken.
|
519326 | log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_chroma_qp_offset_depth) { |
2576 | 519326 | lc->tu.is_cu_chroma_qp_offset_coded = 0; | |
2577 | } | ||
2578 | |||
2579 |
2/2✓ Branch 0 taken 3522496 times.
✓ Branch 1 taken 11662467 times.
|
15184963 | if (split_cu) { |
2580 | 3522496 | int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1; | |
2581 | 3522496 | const int cb_size_split = cb_size >> 1; | |
2582 | 3522496 | const int x1 = x0 + cb_size_split; | |
2583 | 3522496 | const int y1 = y0 + cb_size_split; | |
2584 | |||
2585 | 3522496 | int more_data = 0; | |
2586 | |||
2587 | 3522496 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
2588 | x0, y0, log2_cb_size - 1, cb_depth + 1); | ||
2589 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3522494 times.
|
3522496 | if (more_data < 0) |
2590 | 2 | return more_data; | |
2591 | |||
2592 |
4/4✓ Branch 0 taken 3522485 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3494544 times.
✓ Branch 3 taken 27941 times.
|
3522494 | if (more_data && x1 < sps->width) { |
2593 | 3494544 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
2594 | x1, y0, log2_cb_size - 1, cb_depth + 1); | ||
2595 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3494544 times.
|
3494544 | if (more_data < 0) |
2596 | ✗ | return more_data; | |
2597 | } | ||
2598 |
4/4✓ Branch 0 taken 3512179 times.
✓ Branch 1 taken 10315 times.
✓ Branch 2 taken 3311072 times.
✓ Branch 3 taken 201107 times.
|
3522494 | if (more_data && y1 < sps->height) { |
2599 | 3311072 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
2600 | x0, y1, log2_cb_size - 1, cb_depth + 1); | ||
2601 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3311072 times.
|
3311072 | if (more_data < 0) |
2602 | ✗ | return more_data; | |
2603 | } | ||
2604 |
4/4✓ Branch 0 taken 3506056 times.
✓ Branch 1 taken 16438 times.
✓ Branch 2 taken 3484238 times.
✓ Branch 3 taken 21818 times.
|
3522494 | if (more_data && x1 < sps->width && |
2605 |
2/2✓ Branch 0 taken 3283131 times.
✓ Branch 1 taken 201107 times.
|
3484238 | y1 < sps->height) { |
2606 | 3283131 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
2607 | x1, y1, log2_cb_size - 1, cb_depth + 1); | ||
2608 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3283130 times.
|
3283131 | if (more_data < 0) |
2609 | 1 | return more_data; | |
2610 | } | ||
2611 | |||
2612 |
2/2✓ Branch 0 taken 1984526 times.
✓ Branch 1 taken 1537967 times.
|
3522493 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
2613 |
2/2✓ Branch 0 taken 1480040 times.
✓ Branch 1 taken 504486 times.
|
1984526 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) |
2614 | 1480040 | lc->qPy_pred = lc->qp_y; | |
2615 | |||
2616 |
2/2✓ Branch 0 taken 3486566 times.
✓ Branch 1 taken 35927 times.
|
3522493 | if (more_data) |
2617 |
2/2✓ Branch 0 taken 95186 times.
✓ Branch 1 taken 3391380 times.
|
3581752 | return ((x1 + cb_size_split) < sps->width || |
2618 |
2/2✓ Branch 0 taken 95185 times.
✓ Branch 1 taken 1 times.
|
95186 | (y1 + cb_size_split) < sps->height); |
2619 | else | ||
2620 | 35927 | return 0; | |
2621 | } else { | ||
2622 | 11662467 | ret = hls_coding_unit(lc, s, l, pps, sps, x0, y0, log2_cb_size); | |
2623 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11662466 times.
|
11662467 | if (ret < 0) |
2624 | 1 | return ret; | |
2625 | 11662466 | if ((!((x0 + cb_size) % | |
2626 |
2/2✓ Branch 0 taken 8441724 times.
✓ Branch 1 taken 3220742 times.
|
11662466 | (1 << (sps->log2_ctb_size))) || |
2627 |
2/2✓ Branch 0 taken 71449 times.
✓ Branch 1 taken 8370275 times.
|
8441724 | (x0 + cb_size >= sps->width)) && |
2628 | 3292191 | (!((y0 + cb_size) % | |
2629 |
2/2✓ Branch 0 taken 1815954 times.
✓ Branch 1 taken 1476237 times.
|
3292191 | (1 << (sps->log2_ctb_size))) || |
2630 |
2/2✓ Branch 0 taken 97482 times.
✓ Branch 1 taken 1718472 times.
|
1815954 | (y0 + cb_size >= sps->height))) { |
2631 | 1573719 | int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc); | |
2632 | 1573719 | return !end_of_slice_flag; | |
2633 | } else { | ||
2634 | 10088747 | return 1; | |
2635 | } | ||
2636 | } | ||
2637 | |||
2638 | return 0; | ||
2639 | } | ||
2640 | |||
2641 | 1573720 | static void hls_decode_neighbour(HEVCLocalContext *lc, | |
2642 | const HEVCLayerContext *l, | ||
2643 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
2644 | int x_ctb, int y_ctb, int ctb_addr_ts) | ||
2645 | { | ||
2646 | 1573720 | const HEVCContext *const s = lc->parent; | |
2647 | 1573720 | int ctb_size = 1 << sps->log2_ctb_size; | |
2648 | 1573720 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2649 | 1573720 | int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr; | |
2650 | |||
2651 | 1573720 | l->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr; | |
2652 | |||
2653 |
2/2✓ Branch 0 taken 153814 times.
✓ Branch 1 taken 1419906 times.
|
1573720 | if (pps->entropy_coding_sync_enabled_flag) { |
2654 |
3/4✓ Branch 0 taken 6569 times.
✓ Branch 1 taken 147245 times.
✓ Branch 2 taken 6569 times.
✗ Branch 3 not taken.
|
153814 | if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0) |
2655 | 6569 | lc->first_qp_group = 1; | |
2656 | 153814 | lc->end_of_tiles_x = sps->width; | |
2657 |
2/2✓ Branch 0 taken 291890 times.
✓ Branch 1 taken 1128016 times.
|
1419906 | } else if (pps->tiles_enabled_flag) { |
2658 |
4/4✓ Branch 0 taken 291264 times.
✓ Branch 1 taken 626 times.
✓ Branch 2 taken 6287 times.
✓ Branch 3 taken 284977 times.
|
291890 | if (ctb_addr_ts && pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) { |
2659 | 6287 | int idxX = pps->col_idxX[x_ctb >> sps->log2_ctb_size]; | |
2660 | 6287 | lc->end_of_tiles_x = x_ctb + (pps->column_width[idxX] << sps->log2_ctb_size); | |
2661 | 6287 | lc->first_qp_group = 1; | |
2662 | } | ||
2663 | } else { | ||
2664 | 1128016 | lc->end_of_tiles_x = sps->width; | |
2665 | } | ||
2666 | |||
2667 | 1573720 | lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height); | |
2668 | |||
2669 | 1573720 | lc->boundary_flags = 0; | |
2670 |
2/2✓ Branch 0 taken 291890 times.
✓ Branch 1 taken 1281830 times.
|
1573720 | if (pps->tiles_enabled_flag) { |
2671 |
4/4✓ Branch 0 taken 279936 times.
✓ Branch 1 taken 11954 times.
✓ Branch 2 taken 30753 times.
✓ Branch 3 taken 249183 times.
|
291890 | if (x_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]]) |
2672 | 30753 | lc->boundary_flags |= BOUNDARY_LEFT_TILE; | |
2673 |
4/4✓ Branch 0 taken 279936 times.
✓ Branch 1 taken 11954 times.
✓ Branch 2 taken 3741 times.
✓ Branch 3 taken 276195 times.
|
291890 | if (x_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - 1]) |
2674 | 3741 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
2675 |
4/4✓ Branch 0 taken 277242 times.
✓ Branch 1 taken 14648 times.
✓ Branch 2 taken 33781 times.
✓ Branch 3 taken 243461 times.
|
291890 | if (y_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - sps->ctb_width]]) |
2676 | 33781 | lc->boundary_flags |= BOUNDARY_UPPER_TILE; | |
2677 |
4/4✓ Branch 0 taken 277242 times.
✓ Branch 1 taken 14648 times.
✓ Branch 2 taken 14490 times.
✓ Branch 3 taken 262752 times.
|
291890 | if (y_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - sps->ctb_width]) |
2678 | 14490 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
2679 | } else { | ||
2680 |
2/2✓ Branch 0 taken 18239 times.
✓ Branch 1 taken 1263591 times.
|
1281830 | if (ctb_addr_in_slice <= 0) |
2681 | 18239 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
2682 |
2/2✓ Branch 0 taken 195692 times.
✓ Branch 1 taken 1086138 times.
|
1281830 | if (ctb_addr_in_slice < sps->ctb_width) |
2683 | 195692 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
2684 | } | ||
2685 | |||
2686 |
6/6✓ Branch 0 taken 1492704 times.
✓ Branch 1 taken 81016 times.
✓ Branch 2 taken 1484815 times.
✓ Branch 3 taken 7889 times.
✓ Branch 4 taken 1455090 times.
✓ Branch 5 taken 29725 times.
|
1573720 | lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE)); |
2687 |
6/6✓ Branch 0 taken 1443549 times.
✓ Branch 1 taken 130171 times.
✓ Branch 2 taken 1349719 times.
✓ Branch 3 taken 93830 times.
✓ Branch 4 taken 1329599 times.
✓ Branch 5 taken 20120 times.
|
1573720 | lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE)); |
2688 |
6/6✓ Branch 0 taken 1443549 times.
✓ Branch 1 taken 130171 times.
✓ Branch 2 taken 1352308 times.
✓ Branch 3 taken 91241 times.
✓ Branch 4 taken 1296556 times.
✓ Branch 5 taken 55752 times.
|
1573720 | lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= sps->ctb_width) && (pps->tile_id[ctb_addr_ts] == pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - sps->ctb_width]])); |
2689 |
8/8✓ Branch 0 taken 1492704 times.
✓ Branch 1 taken 81016 times.
✓ Branch 2 taken 1372704 times.
✓ Branch 3 taken 120000 times.
✓ Branch 4 taken 1283938 times.
✓ Branch 5 taken 88766 times.
✓ Branch 6 taken 1239706 times.
✓ Branch 7 taken 44232 times.
|
1573720 | lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= sps->ctb_width) && (pps->tile_id[ctb_addr_ts] == pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - sps->ctb_width]])); |
2690 | 1573720 | } | |
2691 | |||
2692 | 28165 | static int hls_decode_entry(HEVCContext *s, GetBitContext *gb) | |
2693 | { | ||
2694 | 28165 | HEVCLocalContext *const lc = &s->local_ctx[0]; | |
2695 | 28165 | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
2696 | 28165 | const HEVCPPS *const pps = s->pps; | |
2697 | 28165 | const HEVCSPS *const sps = pps->sps; | |
2698 | 28165 | const uint8_t *slice_data = gb->buffer + s->sh.data_offset; | |
2699 | 28165 | const size_t slice_size = gb->buffer_end - gb->buffer - s->sh.data_offset; | |
2700 | 28165 | int ctb_size = 1 << sps->log2_ctb_size; | |
2701 | 28165 | int more_data = 1; | |
2702 | 28165 | int x_ctb = 0; | |
2703 | 28165 | int y_ctb = 0; | |
2704 | 28165 | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
2705 | int ret; | ||
2706 | |||
2707 |
3/4✓ Branch 0 taken 1573720 times.
✓ Branch 1 taken 28164 times.
✓ Branch 2 taken 1573720 times.
✗ Branch 3 not taken.
|
1601884 | while (more_data && ctb_addr_ts < sps->ctb_size) { |
2708 | 1573720 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2709 | |||
2710 | 1573720 | x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size; | |
2711 | 1573720 | y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size; | |
2712 | 1573720 | hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
2713 | |||
2714 | 1573720 | ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 0); | |
2715 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1573720 times.
|
1573720 | if (ret < 0) { |
2716 | ✗ | l->tab_slice_address[ctb_addr_rs] = -1; | |
2717 | ✗ | return ret; | |
2718 | } | ||
2719 | |||
2720 | 1573720 | hls_sao_param(lc, l, pps, sps, | |
2721 | 1573720 | x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); | |
2722 | |||
2723 | 1573720 | l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
2724 | 1573720 | l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
2725 | 1573720 | l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
2726 | |||
2727 | 1573720 | more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); | |
2728 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1573719 times.
|
1573720 | if (more_data < 0) { |
2729 | 1 | l->tab_slice_address[ctb_addr_rs] = -1; | |
2730 | 1 | return more_data; | |
2731 | } | ||
2732 | |||
2733 | |||
2734 | 1573719 | ctb_addr_ts++; | |
2735 | 1573719 | ff_hevc_save_states(lc, pps, ctb_addr_ts); | |
2736 | 1573719 | ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
2737 | } | ||
2738 | |||
2739 |
2/2✓ Branch 0 taken 14654 times.
✓ Branch 1 taken 13510 times.
|
28164 | if (x_ctb + ctb_size >= sps->width && |
2740 |
2/2✓ Branch 0 taken 10170 times.
✓ Branch 1 taken 4484 times.
|
14654 | y_ctb + ctb_size >= sps->height) |
2741 | 10170 | ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
2742 | |||
2743 | 28164 | return ctb_addr_ts; | |
2744 | } | ||
2745 | |||
2746 | ✗ | static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, | |
2747 | int job, int thread) | ||
2748 | { | ||
2749 | ✗ | HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread]; | |
2750 | ✗ | const HEVCContext *const s = lc->parent; | |
2751 | ✗ | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
2752 | ✗ | const HEVCPPS *const pps = s->pps; | |
2753 | ✗ | const HEVCSPS *const sps = pps->sps; | |
2754 | ✗ | int ctb_size = 1 << sps->log2_ctb_size; | |
2755 | ✗ | int more_data = 1; | |
2756 | ✗ | int ctb_row = job; | |
2757 | ✗ | int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size); | |
2758 | ✗ | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs]; | |
2759 | |||
2760 | ✗ | const uint8_t *data = s->data + s->sh.offset[ctb_row]; | |
2761 | ✗ | const size_t data_size = s->sh.size[ctb_row]; | |
2762 | |||
2763 | ✗ | int progress = 0; | |
2764 | |||
2765 | int ret; | ||
2766 | |||
2767 | ✗ | if (ctb_row) | |
2768 | ✗ | ff_init_cabac_decoder(&lc->cc, data, data_size); | |
2769 | |||
2770 | ✗ | while(more_data && ctb_addr_ts < sps->ctb_size) { | |
2771 | ✗ | int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size; | |
2772 | ✗ | int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size; | |
2773 | |||
2774 | ✗ | hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
2775 | |||
2776 | ✗ | if (ctb_row) | |
2777 | ✗ | ff_thread_progress_await(&s->wpp_progress[ctb_row - 1], | |
2778 | progress + SHIFT_CTB_WPP + 1); | ||
2779 | |||
2780 | /* atomic_load's prototype requires a pointer to non-const atomic variable | ||
2781 | * (due to implementations via mutexes, where reads involve writes). | ||
2782 | * Of course, casting const away here is nevertheless safe. */ | ||
2783 | ✗ | if (atomic_load((atomic_int*)&s->wpp_err)) { | |
2784 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2785 | ✗ | return 0; | |
2786 | } | ||
2787 | |||
2788 | ✗ | ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1); | |
2789 | ✗ | if (ret < 0) | |
2790 | ✗ | goto error; | |
2791 | ✗ | hls_sao_param(lc, l, pps, sps, | |
2792 | ✗ | x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); | |
2793 | |||
2794 | ✗ | l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
2795 | ✗ | l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
2796 | ✗ | l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
2797 | |||
2798 | ✗ | more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); | |
2799 | |||
2800 | ✗ | if (more_data < 0) { | |
2801 | ✗ | ret = more_data; | |
2802 | ✗ | goto error; | |
2803 | } | ||
2804 | |||
2805 | ✗ | ctb_addr_ts++; | |
2806 | |||
2807 | ✗ | ff_hevc_save_states(lc, pps, ctb_addr_ts); | |
2808 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], ++progress); | |
2809 | ✗ | ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
2810 | |||
2811 | ✗ | if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) { | |
2812 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
2813 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
2814 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2815 | ✗ | return 0; | |
2816 | } | ||
2817 | |||
2818 | ✗ | if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) { | |
2819 | ✗ | ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
2820 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2821 | ✗ | return ctb_addr_ts; | |
2822 | } | ||
2823 | ✗ | ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2824 | ✗ | x_ctb+=ctb_size; | |
2825 | |||
2826 | ✗ | if(x_ctb >= sps->width) { | |
2827 | ✗ | break; | |
2828 | } | ||
2829 | } | ||
2830 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2831 | |||
2832 | ✗ | return 0; | |
2833 | ✗ | error: | |
2834 | ✗ | l->tab_slice_address[ctb_addr_rs] = -1; | |
2835 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
2836 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
2837 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2838 | ✗ | return ret; | |
2839 | } | ||
2840 | |||
2841 | ✗ | static int wpp_progress_init(HEVCContext *s, unsigned count) | |
2842 | { | ||
2843 | ✗ | if (s->nb_wpp_progress < count) { | |
2844 | ✗ | void *tmp = av_realloc_array(s->wpp_progress, count, | |
2845 | sizeof(*s->wpp_progress)); | ||
2846 | ✗ | if (!tmp) | |
2847 | ✗ | return AVERROR(ENOMEM); | |
2848 | |||
2849 | ✗ | s->wpp_progress = tmp; | |
2850 | ✗ | memset(s->wpp_progress + s->nb_wpp_progress, 0, | |
2851 | ✗ | (count - s->nb_wpp_progress) * sizeof(*s->wpp_progress)); | |
2852 | |||
2853 | ✗ | for (int i = s->nb_wpp_progress; i < count; i++) { | |
2854 | ✗ | int ret = ff_thread_progress_init(&s->wpp_progress[i], 1); | |
2855 | ✗ | if (ret < 0) | |
2856 | ✗ | return ret; | |
2857 | ✗ | s->nb_wpp_progress = i + 1; | |
2858 | } | ||
2859 | } | ||
2860 | |||
2861 | ✗ | for (int i = 0; i < count; i++) | |
2862 | ✗ | ff_thread_progress_reset(&s->wpp_progress[i]); | |
2863 | |||
2864 | ✗ | return 0; | |
2865 | } | ||
2866 | |||
2867 | ✗ | static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) | |
2868 | { | ||
2869 | ✗ | const HEVCPPS *const pps = s->pps; | |
2870 | ✗ | const HEVCSPS *const sps = pps->sps; | |
2871 | ✗ | const uint8_t *data = nal->data; | |
2872 | ✗ | int length = nal->size; | |
2873 | int *ret; | ||
2874 | int64_t offset; | ||
2875 | ✗ | int64_t startheader, cmpt = 0; | |
2876 | ✗ | int i, j, res = 0; | |
2877 | |||
2878 | ✗ | if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * sps->ctb_width >= sps->ctb_width * sps->ctb_height) { | |
2879 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n", | |
2880 | s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets, | ||
2881 | ✗ | sps->ctb_width, sps->ctb_height | |
2882 | ); | ||
2883 | ✗ | return AVERROR_INVALIDDATA; | |
2884 | } | ||
2885 | |||
2886 | ✗ | if (s->avctx->thread_count > s->nb_local_ctx) { | |
2887 | ✗ | HEVCLocalContext *tmp = av_malloc_array(s->avctx->thread_count, sizeof(*s->local_ctx)); | |
2888 | |||
2889 | ✗ | if (!tmp) | |
2890 | ✗ | return AVERROR(ENOMEM); | |
2891 | |||
2892 | ✗ | memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx); | |
2893 | ✗ | av_free(s->local_ctx); | |
2894 | ✗ | s->local_ctx = tmp; | |
2895 | |||
2896 | ✗ | for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) { | |
2897 | ✗ | tmp = &s->local_ctx[i]; | |
2898 | |||
2899 | ✗ | memset(tmp, 0, sizeof(*tmp)); | |
2900 | |||
2901 | ✗ | tmp->logctx = s->avctx; | |
2902 | ✗ | tmp->parent = s; | |
2903 | ✗ | tmp->common_cabac_state = &s->cabac; | |
2904 | } | ||
2905 | |||
2906 | ✗ | s->nb_local_ctx = s->avctx->thread_count; | |
2907 | } | ||
2908 | |||
2909 | ✗ | offset = s->sh.data_offset; | |
2910 | |||
2911 | ✗ | for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) { | |
2912 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
2913 | ✗ | startheader--; | |
2914 | ✗ | cmpt++; | |
2915 | } | ||
2916 | } | ||
2917 | |||
2918 | ✗ | for (i = 1; i < s->sh.num_entry_point_offsets; i++) { | |
2919 | ✗ | offset += (s->sh.entry_point_offset[i - 1] - cmpt); | |
2920 | ✗ | for (j = 0, cmpt = 0, startheader = offset | |
2921 | ✗ | + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) { | |
2922 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
2923 | ✗ | startheader--; | |
2924 | ✗ | cmpt++; | |
2925 | } | ||
2926 | } | ||
2927 | ✗ | s->sh.size[i] = s->sh.entry_point_offset[i] - cmpt; | |
2928 | ✗ | s->sh.offset[i] = offset; | |
2929 | |||
2930 | } | ||
2931 | |||
2932 | ✗ | offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt; | |
2933 | ✗ | if (length < offset) { | |
2934 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n"); | |
2935 | ✗ | return AVERROR_INVALIDDATA; | |
2936 | } | ||
2937 | ✗ | s->sh.size [s->sh.num_entry_point_offsets] = length - offset; | |
2938 | ✗ | s->sh.offset[s->sh.num_entry_point_offsets] = offset; | |
2939 | |||
2940 | ✗ | s->sh.offset[0] = s->sh.data_offset; | |
2941 | ✗ | s->sh.size[0] = s->sh.offset[1] - s->sh.offset[0]; | |
2942 | |||
2943 | ✗ | s->data = data; | |
2944 | |||
2945 | ✗ | for (i = 1; i < s->nb_local_ctx; i++) { | |
2946 | ✗ | s->local_ctx[i].first_qp_group = 1; | |
2947 | ✗ | s->local_ctx[i].qp_y = s->local_ctx[0].qp_y; | |
2948 | } | ||
2949 | |||
2950 | ✗ | atomic_store(&s->wpp_err, 0); | |
2951 | ✗ | res = wpp_progress_init(s, s->sh.num_entry_point_offsets + 1); | |
2952 | ✗ | if (res < 0) | |
2953 | ✗ | return res; | |
2954 | |||
2955 | ✗ | ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret)); | |
2956 | ✗ | if (!ret) | |
2957 | ✗ | return AVERROR(ENOMEM); | |
2958 | |||
2959 | ✗ | if (pps->entropy_coding_sync_enabled_flag) | |
2960 | ✗ | s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->local_ctx, ret, s->sh.num_entry_point_offsets + 1); | |
2961 | |||
2962 | ✗ | for (i = 0; i <= s->sh.num_entry_point_offsets; i++) | |
2963 | ✗ | res += ret[i]; | |
2964 | |||
2965 | ✗ | av_free(ret); | |
2966 | ✗ | return res; | |
2967 | } | ||
2968 | |||
2969 | 28165 | static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l, | |
2970 | const H2645NAL *nal, GetBitContext *gb) | ||
2971 | { | ||
2972 | 28165 | const HEVCPPS *pps = s->pps; | |
2973 | int ret; | ||
2974 | |||
2975 |
2/2✓ Branch 0 taken 17994 times.
✓ Branch 1 taken 10171 times.
|
28165 | if (!s->sh.first_slice_in_pic_flag) |
2976 | 17994 | s->slice_idx += !s->sh.dependent_slice_segment_flag; | |
2977 | |||
2978 |
4/4✓ Branch 0 taken 20218 times.
✓ Branch 1 taken 7947 times.
✓ Branch 2 taken 18983 times.
✓ Branch 3 taken 1235 times.
|
28165 | if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) { |
2979 | 18983 | ret = ff_hevc_slice_rpl(s); | |
2980 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18983 times.
|
18983 | if (ret < 0) { |
2981 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
2982 | "Error constructing the reference lists for the current slice.\n"); | ||
2983 | ✗ | return ret; | |
2984 | } | ||
2985 | } | ||
2986 | |||
2987 | 28165 | s->slice_initialized = 1; | |
2988 | |||
2989 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28165 times.
|
28165 | if (s->avctx->hwaccel) |
2990 | ✗ | return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size); | |
2991 | |||
2992 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28165 times.
|
28165 | if (s->avctx->profile == AV_PROFILE_HEVC_SCC) { |
2993 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
2994 | "SCC profile is not yet implemented in hevc native decoder.\n"); | ||
2995 | ✗ | return AVERROR_PATCHWELCOME; | |
2996 | } | ||
2997 | |||
2998 |
2/2✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20218 times.
|
28165 | if (s->sh.dependent_slice_segment_flag) { |
2999 | 7947 | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
3000 | 7947 | int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1]; | |
3001 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
|
7947 | if (l->tab_slice_address[prev_rs] != s->sh.slice_addr) { |
3002 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n"); | |
3003 | ✗ | return AVERROR_INVALIDDATA; | |
3004 | } | ||
3005 | } | ||
3006 | |||
3007 | 28165 | s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag; | |
3008 | |||
3009 |
2/2✓ Branch 0 taken 23130 times.
✓ Branch 1 taken 5035 times.
|
28165 | if (!pps->cu_qp_delta_enabled_flag) |
3010 | 23130 | s->local_ctx[0].qp_y = s->sh.slice_qp; | |
3011 | |||
3012 | 28165 | s->local_ctx[0].tu.cu_qp_offset_cb = 0; | |
3013 | 28165 | s->local_ctx[0].tu.cu_qp_offset_cr = 0; | |
3014 | |||
3015 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28165 times.
|
28165 | if (s->avctx->active_thread_type == FF_THREAD_SLICE && |
3016 | ✗ | s->sh.num_entry_point_offsets > 0 && | |
3017 | ✗ | pps->num_tile_rows == 1 && pps->num_tile_columns == 1) | |
3018 | ✗ | return hls_slice_data_wpp(s, nal); | |
3019 | |||
3020 | 28165 | return hls_decode_entry(s, gb); | |
3021 | } | ||
3022 | |||
3023 | 10171 | static int set_side_data(HEVCContext *s) | |
3024 | { | ||
3025 | 10171 | const HEVCSPS *sps = s->cur_frame->pps->sps; | |
3026 | 10171 | AVFrame *out = s->cur_frame->f; | |
3027 | int ret; | ||
3028 | |||
3029 | // Decrement the mastering display and content light level flag when IRAP | ||
3030 | // frame has no_rasl_output_flag=1 so the side data persists for the entire | ||
3031 | // coded video sequence. | ||
3032 |
5/6✓ Branch 0 taken 712 times.
✓ Branch 1 taken 9459 times.
✓ Branch 2 taken 712 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✓ Branch 5 taken 283 times.
|
10171 | if (IS_IRAP(s) && s->no_rasl_output_flag) { |
3033 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 421 times.
|
429 | if (s->sei.common.mastering_display.present > 0) |
3034 | 8 | s->sei.common.mastering_display.present--; | |
3035 | |||
3036 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 423 times.
|
429 | if (s->sei.common.content_light.present > 0) |
3037 | 6 | s->sei.common.content_light.present--; | |
3038 | } | ||
3039 | |||
3040 | 10171 | ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx, | |
3041 | &sps->vui.common, | ||
3042 | 10171 | sps->bit_depth, sps->bit_depth_chroma, | |
3043 | 10171 | s->cur_frame->poc /* no poc_offset in HEVC */); | |
3044 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (ret < 0) |
3045 | ✗ | return ret; | |
3046 | |||
3047 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 10148 times.
|
10171 | if (s->sei.timecode.present) { |
3048 | uint32_t *tc_sd; | ||
3049 | char tcbuf[AV_TIMECODE_STR_SIZE]; | ||
3050 | AVFrameSideData *tcside; | ||
3051 | 23 | ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE, | |
3052 | sizeof(uint32_t) * 4, &tcside); | ||
3053 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (ret < 0) |
3054 | ✗ | return ret; | |
3055 | |||
3056 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | if (tcside) { |
3057 | 23 | tc_sd = (uint32_t*)tcside->data; | |
3058 | 23 | tc_sd[0] = s->sei.timecode.num_clock_ts; | |
3059 | |||
3060 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 23 times.
|
46 | for (int i = 0; i < tc_sd[0]; i++) { |
3061 | 23 | int drop = s->sei.timecode.cnt_dropped_flag[i]; | |
3062 | 23 | int hh = s->sei.timecode.hours_value[i]; | |
3063 | 23 | int mm = s->sei.timecode.minutes_value[i]; | |
3064 | 23 | int ss = s->sei.timecode.seconds_value[i]; | |
3065 | 23 | int ff = s->sei.timecode.n_frames[i]; | |
3066 | |||
3067 | 23 | tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff); | |
3068 | 23 | av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0); | |
3069 | 23 | av_dict_set(&out->metadata, "timecode", tcbuf, 0); | |
3070 | } | ||
3071 | } | ||
3072 | |||
3073 | 23 | s->sei.timecode.num_clock_ts = 0; | |
3074 | } | ||
3075 | |||
3076 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10167 times.
|
10171 | if (s->sei.common.dynamic_hdr_plus.info) { |
3077 | 4 | AVBufferRef *info_ref = av_buffer_ref(s->sei.common.dynamic_hdr_plus.info); | |
3078 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!info_ref) |
3079 | ✗ | return AVERROR(ENOMEM); | |
3080 | |||
3081 | 4 | ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref); | |
3082 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ret < 0) |
3083 | ✗ | return ret; | |
3084 | } | ||
3085 | |||
3086 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10169 times.
|
10171 | if (s->rpu_buf) { |
3087 | 2 | AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf); | |
3088 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!rpu) |
3089 | ✗ | return AVERROR(ENOMEM); | |
3090 | |||
3091 | 2 | s->rpu_buf = NULL; | |
3092 | } | ||
3093 | |||
3094 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10171 times.
|
10171 | if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0) |
3095 | ✗ | return ret; | |
3096 | |||
3097 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10169 times.
|
10171 | if (s->sei.common.dynamic_hdr_vivid.info) { |
3098 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!av_frame_side_data_add(&out->side_data, &out->nb_side_data, |
3099 | AV_FRAME_DATA_DYNAMIC_HDR_VIVID, | ||
3100 | &s->sei.common.dynamic_hdr_vivid.info, | ||
3101 | AV_FRAME_SIDE_DATA_FLAG_NEW_REF)) | ||
3102 | ✗ | return AVERROR(ENOMEM); | |
3103 | } | ||
3104 | |||
3105 | 10171 | return 0; | |
3106 | } | ||
3107 | |||
3108 | 9894 | static int find_finish_setup_nal(const HEVCContext *s) | |
3109 | { | ||
3110 | 9894 | int nal_idx = 0; | |
3111 | |||
3112 |
2/2✓ Branch 0 taken 38764 times.
✓ Branch 1 taken 9894 times.
|
48658 | for (int i = nal_idx; i < s->pkt.nb_nals; i++) { |
3113 | 38764 | const H2645NAL *nal = &s->pkt.nals[i]; | |
3114 | 38764 | const int layer_id = nal->nuh_layer_id; | |
3115 | 38764 | GetBitContext gb = nal->gb; | |
3116 | |||
3117 |
2/4✓ Branch 0 taken 38764 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38764 times.
✗ Branch 3 not taken.
|
38764 | if (layer_id > HEVC_MAX_NUH_LAYER_ID || s->vps->layer_idx[layer_id] < 0 || |
3118 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 38748 times.
|
38764 | !(s->layers_active_decode & (1 << s->vps->layer_idx[layer_id]))) |
3119 | 18010 | continue; | |
3120 | |||
3121 |
3/3✓ Branch 0 taken 28166 times.
✓ Branch 1 taken 2264 times.
✓ Branch 2 taken 8318 times.
|
38748 | switch (nal->type) { |
3122 | 28166 | case HEVC_NAL_TRAIL_R: | |
3123 | case HEVC_NAL_TRAIL_N: | ||
3124 | case HEVC_NAL_TSA_N: | ||
3125 | case HEVC_NAL_TSA_R: | ||
3126 | case HEVC_NAL_STSA_N: | ||
3127 | case HEVC_NAL_STSA_R: | ||
3128 | case HEVC_NAL_BLA_W_LP: | ||
3129 | case HEVC_NAL_BLA_W_RADL: | ||
3130 | case HEVC_NAL_BLA_N_LP: | ||
3131 | case HEVC_NAL_IDR_W_RADL: | ||
3132 | case HEVC_NAL_IDR_N_LP: | ||
3133 | case HEVC_NAL_CRA_NUT: | ||
3134 | case HEVC_NAL_RADL_N: | ||
3135 | case HEVC_NAL_RADL_R: | ||
3136 | case HEVC_NAL_RASL_N: | ||
3137 | case HEVC_NAL_RASL_R: | ||
3138 |
2/2✓ Branch 1 taken 17994 times.
✓ Branch 2 taken 10172 times.
|
28166 | if (!get_bits1(&gb)) // first_slice_segment_in_pic_flag |
3139 | 17994 | continue; | |
3140 | case HEVC_NAL_VPS: | ||
3141 | case HEVC_NAL_SPS: | ||
3142 | case HEVC_NAL_PPS: | ||
3143 | 12436 | nal_idx = i; | |
3144 | 12436 | break; | |
3145 | } | ||
3146 | } | ||
3147 | |||
3148 | 9894 | return nal_idx; | |
3149 | } | ||
3150 | |||
3151 | 10171 | static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, | |
3152 | unsigned nal_idx) | ||
3153 | { | ||
3154 | 10171 | const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id]; | |
3155 | 10171 | const HEVCSPS *const sps = pps->sps; | |
3156 | 10171 | int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) * | |
3157 | 10171 | ((sps->height >> sps->log2_min_cb_size) + 1); | |
3158 |
2/2✓ Branch 0 taken 9894 times.
✓ Branch 1 taken 277 times.
|
20065 | int new_sequence = (l == &s->layers[0]) && |
3159 |
12/12✓ Branch 0 taken 9510 times.
✓ Branch 1 taken 384 times.
✓ Branch 2 taken 9491 times.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 9489 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9482 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9481 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 9 times.
✓ Branch 11 taken 9472 times.
|
9894 | (IS_IDR(s) || IS_BLA(s) || s->last_eos); |
3160 | 10171 | int prev_layers_active_decode = s->layers_active_decode; | |
3161 | 10171 | int prev_layers_active_output = s->layers_active_output; | |
3162 | int ret; | ||
3163 | |||
3164 |
3/4✓ Branch 0 taken 399 times.
✓ Branch 1 taken 9772 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 399 times.
|
10171 | if (sps->vps != s->vps && l != &s->layers[0]) { |
3165 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n"); | |
3166 | ✗ | set_sps(s, l, NULL); | |
3167 | ✗ | return AVERROR_INVALIDDATA; | |
3168 | } | ||
3169 | |||
3170 | 10171 | av_refstruct_replace(&s->pps, pps); | |
3171 |
2/2✓ Branch 0 taken 413 times.
✓ Branch 1 taken 9758 times.
|
10171 | if (l->sps != sps) { |
3172 | 413 | const HEVCSPS *sps_base = s->layers[0].sps; | |
3173 | 413 | enum AVPixelFormat pix_fmt = sps->pix_fmt; | |
3174 | |||
3175 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 405 times.
|
413 | if (l != &s->layers[0]) { |
3176 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (!sps_base) { |
3177 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3178 | "Access unit starts with a non-base layer frame\n"); | ||
3179 | ✗ | return AVERROR_INVALIDDATA; | |
3180 | } | ||
3181 | |||
3182 | // Files produced by Vision Pro lack VPS extension VUI, | ||
3183 | // so the secondary layer has no range information. | ||
3184 | // This check avoids failing in such a case. | ||
3185 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (sps_base->pix_fmt == AV_PIX_FMT_YUVJ420P && |
3186 | ✗ | sps->pix_fmt == AV_PIX_FMT_YUV420P && | |
3187 | ✗ | !sps->vui.common.video_signal_type_present_flag) | |
3188 | ✗ | pix_fmt = sps_base->pix_fmt; | |
3189 | |||
3190 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (pix_fmt != sps_base->pix_fmt || |
3191 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | sps->width != sps_base->width || |
3192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | sps->height != sps_base->height) { |
3193 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3194 | "Base/non-base layer SPS have unsupported parameter combination\n"); | ||
3195 | ✗ | return AVERROR(ENOSYS); | |
3196 | } | ||
3197 | } | ||
3198 | |||
3199 | 413 | ff_hevc_clear_refs(l); | |
3200 | |||
3201 | 413 | ret = set_sps(s, l, sps); | |
3202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 413 times.
|
413 | if (ret < 0) |
3203 | ✗ | return ret; | |
3204 | |||
3205 |
2/2✓ Branch 0 taken 405 times.
✓ Branch 1 taken 8 times.
|
413 | if (l == &s->layers[0]) { |
3206 | 405 | export_stream_params(s, sps); | |
3207 | |||
3208 | 405 | ret = get_format(s, sps); | |
3209 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
|
405 | if (ret < 0) { |
3210 | ✗ | set_sps(s, l, NULL); | |
3211 | ✗ | return ret; | |
3212 | } | ||
3213 | |||
3214 | 405 | new_sequence = 1; | |
3215 | } | ||
3216 | } | ||
3217 | |||
3218 | 10171 | memset(l->horizontal_bs, 0, l->bs_width * l->bs_height); | |
3219 | 10171 | memset(l->vertical_bs, 0, l->bs_width * l->bs_height); | |
3220 | 10171 | memset(l->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height); | |
3221 | 10171 | memset(l->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1)); | |
3222 | 10171 | memset(l->tab_slice_address, -1, pic_size_in_ctb * sizeof(*l->tab_slice_address)); | |
3223 | |||
3224 |
4/4✓ Branch 0 taken 9780 times.
✓ Branch 1 taken 391 times.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 9761 times.
|
10171 | if (IS_IDR(s)) |
3225 | 410 | ff_hevc_clear_refs(l); | |
3226 | |||
3227 | 10171 | s->slice_idx = 0; | |
3228 | 10171 | s->first_nal_type = s->nal_unit_type; | |
3229 | 10171 | s->poc = s->sh.poc; | |
3230 | |||
3231 |
3/4✓ Branch 0 taken 712 times.
✓ Branch 1 taken 9459 times.
✓ Branch 2 taken 712 times.
✗ Branch 3 not taken.
|
10171 | if (IS_IRAP(s)) |
3232 |
10/10✓ Branch 0 taken 321 times.
✓ Branch 1 taken 391 times.
✓ Branch 2 taken 302 times.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 300 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 293 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 292 times.
✓ Branch 9 taken 1 times.
|
1004 | s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || |
3233 |
3/4✓ Branch 0 taken 292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 283 times.
|
292 | (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos); |
3234 | |||
3235 | /* 8.3.1 */ | ||
3236 |
2/2✓ Branch 0 taken 9829 times.
✓ Branch 1 taken 342 times.
|
10171 | if (s->temporal_id == 0 && |
3237 |
2/2✓ Branch 0 taken 7159 times.
✓ Branch 1 taken 2670 times.
|
9829 | s->nal_unit_type != HEVC_NAL_TRAIL_N && |
3238 |
1/2✓ Branch 0 taken 7159 times.
✗ Branch 1 not taken.
|
7159 | s->nal_unit_type != HEVC_NAL_TSA_N && |
3239 |
1/2✓ Branch 0 taken 7159 times.
✗ Branch 1 not taken.
|
7159 | s->nal_unit_type != HEVC_NAL_STSA_N && |
3240 |
2/2✓ Branch 0 taken 7133 times.
✓ Branch 1 taken 26 times.
|
7159 | s->nal_unit_type != HEVC_NAL_RADL_N && |
3241 |
2/2✓ Branch 0 taken 7111 times.
✓ Branch 1 taken 22 times.
|
7133 | s->nal_unit_type != HEVC_NAL_RADL_R && |
3242 |
2/2✓ Branch 0 taken 6741 times.
✓ Branch 1 taken 370 times.
|
7111 | s->nal_unit_type != HEVC_NAL_RASL_N && |
3243 |
2/2✓ Branch 0 taken 6267 times.
✓ Branch 1 taken 474 times.
|
6741 | s->nal_unit_type != HEVC_NAL_RASL_R) |
3244 | 6267 | s->poc_tid0 = s->poc; | |
3245 | |||
3246 |
2/2✓ Branch 0 taken 626 times.
✓ Branch 1 taken 9545 times.
|
10171 | if (pps->tiles_enabled_flag) |
3247 | 626 | s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size; | |
3248 | |||
3249 |
2/2✓ Branch 0 taken 425 times.
✓ Branch 1 taken 9746 times.
|
10171 | if (new_sequence) { |
3250 | 425 | ret = ff_hevc_output_frames(s, prev_layers_active_decode, prev_layers_active_output, | |
3251 | 425 | 0, 0, s->sh.no_output_of_prior_pics_flag); | |
3252 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 425 times.
|
425 | if (ret < 0) |
3253 | ✗ | return ret; | |
3254 | } | ||
3255 | |||
3256 | 10171 | ret = export_stream_params_from_sei(s); | |
3257 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (ret < 0) |
3258 | ✗ | return ret; | |
3259 | |||
3260 | 10171 | ret = ff_hevc_set_new_ref(s, l, s->poc); | |
3261 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (ret < 0) |
3262 | ✗ | goto fail; | |
3263 | |||
3264 | 10171 | ret = ff_hevc_frame_rps(s, l); | |
3265 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (ret < 0) { |
3266 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n"); | |
3267 | ✗ | goto fail; | |
3268 | } | ||
3269 | |||
3270 |
3/4✓ Branch 0 taken 712 times.
✓ Branch 1 taken 9459 times.
✓ Branch 2 taken 712 times.
✗ Branch 3 not taken.
|
10171 | if (IS_IRAP(s)) |
3271 | 712 | s->cur_frame->f->flags |= AV_FRAME_FLAG_KEY; | |
3272 | else | ||
3273 | 9459 | s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY; | |
3274 | |||
3275 | 20342 | s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics && | |
3276 | ✗ | s->sei.common.film_grain_characteristics->present) || | |
3277 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | s->sei.common.aom_film_grain.enable) && |
3278 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
20342 | !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && |
3279 | ✗ | !s->avctx->hwaccel; | |
3280 | |||
3281 | 10171 | ret = set_side_data(s); | |
3282 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (ret < 0) |
3283 | ✗ | goto fail; | |
3284 | |||
3285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (s->cur_frame->needs_fg && |
3286 | ✗ | (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present && | |
3287 | ✗ | !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id, | |
3288 | ✗ | s->cur_frame->f->format) || | |
3289 | ✗ | !av_film_grain_params_select(s->cur_frame->f))) { | |
3290 | ✗ | av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown, | |
3291 | "Unsupported film grain parameters. Ignoring film grain.\n"); | ||
3292 | ✗ | s->cur_frame->needs_fg = 0; | |
3293 | } | ||
3294 | |||
3295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (s->cur_frame->needs_fg) { |
3296 | ✗ | s->cur_frame->frame_grain->format = s->cur_frame->f->format; | |
3297 | ✗ | s->cur_frame->frame_grain->width = s->cur_frame->f->width; | |
3298 | ✗ | s->cur_frame->frame_grain->height = s->cur_frame->f->height; | |
3299 | ✗ | if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0) | |
3300 | ✗ | goto fail; | |
3301 | |||
3302 | ✗ | ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f); | |
3303 | ✗ | if (ret < 0) | |
3304 | ✗ | goto fail; | |
3305 | } | ||
3306 | |||
3307 | 10171 | s->cur_frame->f->pict_type = 3 - s->sh.slice_type; | |
3308 | |||
3309 | 10171 | ret = ff_hevc_output_frames(s, s->layers_active_decode, s->layers_active_output, | |
3310 | 10171 | sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics, | |
3311 | 10171 | sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0); | |
3312 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (ret < 0) |
3313 | ✗ | goto fail; | |
3314 | |||
3315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (s->avctx->hwaccel) { |
3316 | ✗ | ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0); | |
3317 | ✗ | if (ret < 0) | |
3318 | ✗ | goto fail; | |
3319 | } | ||
3320 | |||
3321 | // after starting the base-layer frame we know which layers will be decoded, | ||
3322 | // so we can now figure out which NALUs to wait for before we can call | ||
3323 | // ff_thread_finish_setup() | ||
3324 |
2/2✓ Branch 0 taken 9894 times.
✓ Branch 1 taken 277 times.
|
10171 | if (l == &s->layers[0]) |
3325 | 9894 | s->finish_setup_nal_idx = find_finish_setup_nal(s); | |
3326 | |||
3327 |
2/2✓ Branch 0 taken 9893 times.
✓ Branch 1 taken 278 times.
|
10171 | if (nal_idx >= s->finish_setup_nal_idx) |
3328 | 9893 | ff_thread_finish_setup(s->avctx); | |
3329 | |||
3330 | 10171 | return 0; | |
3331 | |||
3332 | ✗ | fail: | |
3333 | ✗ | if (l->cur_frame) | |
3334 | ✗ | ff_hevc_unref_frame(l->cur_frame, ~0); | |
3335 | ✗ | l->cur_frame = NULL; | |
3336 | ✗ | s->cur_frame = s->collocated_ref = NULL; | |
3337 | ✗ | s->slice_initialized = 0; | |
3338 | ✗ | return ret; | |
3339 | } | ||
3340 | |||
3341 | ✗ | static int verify_md5(HEVCContext *s, AVFrame *frame) | |
3342 | { | ||
3343 | ✗ | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); | |
3344 | char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)]; | ||
3345 | int pixel_shift; | ||
3346 | ✗ | int err = 0; | |
3347 | int i, j; | ||
3348 | |||
3349 | ✗ | if (!desc) | |
3350 | ✗ | return AVERROR(EINVAL); | |
3351 | |||
3352 | ✗ | pixel_shift = desc->comp[0].depth > 8; | |
3353 | |||
3354 | /* the checksums are LE, so we have to byteswap for >8bpp formats | ||
3355 | * on BE arches */ | ||
3356 | #if HAVE_BIGENDIAN | ||
3357 | if (pixel_shift && !s->checksum_buf) { | ||
3358 | av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size, | ||
3359 | FFMAX3(frame->linesize[0], frame->linesize[1], | ||
3360 | frame->linesize[2])); | ||
3361 | if (!s->checksum_buf) | ||
3362 | return AVERROR(ENOMEM); | ||
3363 | } | ||
3364 | #endif | ||
3365 | |||
3366 | ✗ | msg_buf[0] = '\0'; | |
3367 | ✗ | for (i = 0; frame->data[i]; i++) { | |
3368 | ✗ | int width = s->avctx->coded_width; | |
3369 | ✗ | int height = s->avctx->coded_height; | |
3370 | ✗ | int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width; | |
3371 | ✗ | int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height; | |
3372 | uint8_t md5[16]; | ||
3373 | |||
3374 | ✗ | av_md5_init(s->md5_ctx); | |
3375 | ✗ | for (j = 0; j < h; j++) { | |
3376 | ✗ | const uint8_t *src = frame->data[i] + j * frame->linesize[i]; | |
3377 | #if HAVE_BIGENDIAN | ||
3378 | if (pixel_shift) { | ||
3379 | s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf, | ||
3380 | (const uint16_t *) src, w); | ||
3381 | src = s->checksum_buf; | ||
3382 | } | ||
3383 | #endif | ||
3384 | ✗ | av_md5_update(s->md5_ctx, src, w << pixel_shift); | |
3385 | } | ||
3386 | ✗ | av_md5_final(s->md5_ctx, md5); | |
3387 | |||
3388 | #define MD5_PRI "%016" PRIx64 "%016" PRIx64 | ||
3389 | #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8) | ||
3390 | |||
3391 | ✗ | if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) { | |
3392 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
3393 | "plane %d - correct " MD5_PRI "; ", | ||
3394 | ✗ | i, MD5_PRI_ARG(md5)); | |
3395 | } else { | ||
3396 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
3397 | "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ", | ||
3398 | ✗ | i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i])); | |
3399 | ✗ | err = AVERROR_INVALIDDATA; | |
3400 | } | ||
3401 | } | ||
3402 | |||
3403 | ✗ | av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG, | |
3404 | "Verifying checksum for frame with POC %d: %s\n", | ||
3405 | s->poc, msg_buf); | ||
3406 | |||
3407 | ✗ | return err; | |
3408 | } | ||
3409 | |||
3410 | 10171 | static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l) | |
3411 | { | ||
3412 | 10171 | HEVCFrame *out = l->cur_frame; | |
3413 | const AVFilmGrainParams *fgp; | ||
3414 | av_unused int ret; | ||
3415 | |||
3416 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (out->needs_fg) { |
3417 | ✗ | av_assert0(out->frame_grain->buf[0]); | |
3418 | ✗ | fgp = av_film_grain_params_select(out->f); | |
3419 | ✗ | switch (fgp->type) { | |
3420 | ✗ | case AV_FILM_GRAIN_PARAMS_NONE: | |
3421 | ✗ | av_assert0(0); | |
3422 | return AVERROR_BUG; | ||
3423 | ✗ | case AV_FILM_GRAIN_PARAMS_H274: | |
3424 | ✗ | ret = ff_h274_apply_film_grain(out->frame_grain, out->f, | |
3425 | &s->h274db, fgp); | ||
3426 | ✗ | break; | |
3427 | ✗ | case AV_FILM_GRAIN_PARAMS_AV1: | |
3428 | ✗ | ret = ff_aom_apply_film_grain(out->frame_grain, out->f, fgp); | |
3429 | ✗ | break; | |
3430 | } | ||
3431 | av_assert1(ret >= 0); | ||
3432 | } | ||
3433 | |||
3434 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (s->avctx->hwaccel) { |
3435 | ✗ | ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame); | |
3436 | ✗ | if (ret < 0) { | |
3437 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3438 | "hardware accelerator failed to decode picture\n"); | ||
3439 | ✗ | return ret; | |
3440 | } | ||
3441 | } else { | ||
3442 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (s->avctx->err_recognition & AV_EF_CRCCHECK && |
3443 | ✗ | s->sei.picture_hash.is_md5) { | |
3444 | ✗ | ret = verify_md5(s, out->f); | |
3445 | ✗ | if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) | |
3446 | ✗ | return ret; | |
3447 | } | ||
3448 | } | ||
3449 | 10171 | s->sei.picture_hash.is_md5 = 0; | |
3450 | |||
3451 | 10171 | av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %zu/%d.\n", | |
3452 | 10171 | l - s->layers, s->poc); | |
3453 | |||
3454 | 10171 | return 0; | |
3455 | } | ||
3456 | |||
3457 | 28289 | static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb) | |
3458 | { | ||
3459 |
2/2✓ Branch 0 taken 27862 times.
✓ Branch 1 taken 427 times.
|
28289 | const int layer_idx = s->vps ? s->vps->layer_idx[s->nuh_layer_id] : 0; |
3460 | HEVCLayerContext *l; | ||
3461 | int ret; | ||
3462 | |||
3463 | // skip layers not requested to be decoded | ||
3464 | // layers_active_decode can only change while decoding a base-layer frame, | ||
3465 | // so we can check it for non-base layers | ||
3466 |
1/2✓ Branch 0 taken 28289 times.
✗ Branch 1 not taken.
|
28289 | if (layer_idx < 0 || |
3467 |
4/4✓ Branch 0 taken 282 times.
✓ Branch 1 taken 28007 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 277 times.
|
28289 | (s->nuh_layer_id > 0 && !(s->layers_active_decode & (1 << layer_idx)))) |
3468 | 5 | return 0; | |
3469 | |||
3470 | 28284 | ret = hls_slice_header(&s->sh, s, gb); | |
3471 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 28251 times.
|
28284 | if (ret < 0) { |
3472 | // hls_slice_header() does not cleanup on failure thus the state now is inconsistant so we cannot use it on depandant slices | ||
3473 | 33 | s->slice_initialized = 0; | |
3474 | 33 | return ret; | |
3475 | } | ||
3476 | |||
3477 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
28251 | if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) || |
3478 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
28251 | (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) || |
3479 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
28251 | (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) || |
3480 |
4/4✓ Branch 0 taken 27106 times.
✓ Branch 1 taken 1145 times.
✓ Branch 2 taken 1066 times.
✓ Branch 3 taken 26040 times.
|
28251 | ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) && |
3481 |
2/2✓ Branch 0 taken 85 times.
✓ Branch 1 taken 2126 times.
|
2211 | s->no_rasl_output_flag)) { |
3482 | 85 | return 0; | |
3483 | } | ||
3484 | |||
3485 | // switching to a new layer, mark previous layer's frame (if any) as done | ||
3486 |
2/2✓ Branch 0 taken 547 times.
✓ Branch 1 taken 27619 times.
|
28166 | if (s->cur_layer != layer_idx && |
3487 |
2/2✓ Branch 0 taken 277 times.
✓ Branch 1 taken 270 times.
|
547 | s->layers[s->cur_layer].cur_frame && |
3488 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 277 times.
|
277 | s->avctx->active_thread_type == FF_THREAD_FRAME) |
3489 | ✗ | ff_progress_frame_report(&s->layers[s->cur_layer].cur_frame->tf, INT_MAX); | |
3490 | |||
3491 | 28166 | s->cur_layer = layer_idx; | |
3492 | 28166 | l = &s->layers[s->cur_layer]; | |
3493 | |||
3494 |
2/2✓ Branch 0 taken 10172 times.
✓ Branch 1 taken 17994 times.
|
28166 | if (s->sh.first_slice_in_pic_flag) { |
3495 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10171 times.
|
10172 | if (l->cur_frame) { |
3496 | 1 | av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n"); | |
3497 | 1 | return AVERROR_INVALIDDATA; | |
3498 | } | ||
3499 | |||
3500 | 10171 | ret = hevc_frame_start(s, l, nal_idx); | |
3501 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10171 times.
|
10171 | if (ret < 0) |
3502 | ✗ | return ret; | |
3503 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17994 times.
|
17994 | } else if (!l->cur_frame) { |
3504 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n"); | |
3505 | ✗ | return AVERROR_INVALIDDATA; | |
3506 | } | ||
3507 | |||
3508 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28165 times.
|
28165 | if (s->nal_unit_type != s->first_nal_type) { |
3509 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3510 | "Non-matching NAL types of the VCL NALUs: %d %d\n", | ||
3511 | ✗ | s->first_nal_type, s->nal_unit_type); | |
3512 | ✗ | return AVERROR_INVALIDDATA; | |
3513 | } | ||
3514 | |||
3515 | 28165 | ret = decode_slice_data(s, l, &s->pkt.nals[nal_idx], gb); | |
3516 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28164 times.
|
28165 | if (ret < 0) |
3517 | 1 | return ret; | |
3518 | |||
3519 | 28164 | return 0; | |
3520 | } | ||
3521 | |||
3522 | 39070 | static int decode_nal_unit(HEVCContext *s, unsigned nal_idx) | |
3523 | { | ||
3524 | 39070 | H2645NAL *nal = &s->pkt.nals[nal_idx]; | |
3525 | 39070 | GetBitContext gb = nal->gb; | |
3526 | int ret; | ||
3527 | |||
3528 | 39070 | s->nal_unit_type = nal->type; | |
3529 | 39070 | s->nuh_layer_id = nal->nuh_layer_id; | |
3530 | 39070 | s->temporal_id = nal->temporal_id; | |
3531 | |||
3532 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 39070 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
39070 | if (FF_HW_HAS_CB(s->avctx, decode_params) && |
3533 | ✗ | (s->nal_unit_type == HEVC_NAL_VPS || | |
3534 | ✗ | s->nal_unit_type == HEVC_NAL_SPS || | |
3535 | ✗ | s->nal_unit_type == HEVC_NAL_PPS || | |
3536 | ✗ | s->nal_unit_type == HEVC_NAL_SEI_PREFIX || | |
3537 | ✗ | s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) { | |
3538 | ✗ | ret = FF_HW_CALL(s->avctx, decode_params, | |
3539 | nal->type, nal->raw_data, nal->raw_size); | ||
3540 | ✗ | if (ret < 0) | |
3541 | ✗ | goto fail; | |
3542 | } | ||
3543 | |||
3544 |
6/7✓ Branch 0 taken 432 times.
✓ Branch 1 taken 441 times.
✓ Branch 2 taken 1401 times.
✓ Branch 3 taken 7825 times.
✓ Branch 4 taken 28289 times.
✓ Branch 5 taken 682 times.
✗ Branch 6 not taken.
|
39070 | switch (s->nal_unit_type) { |
3545 | 432 | case HEVC_NAL_VPS: | |
3546 | 432 | ret = ff_hevc_decode_nal_vps(&gb, s->avctx, &s->ps); | |
3547 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 432 times.
|
432 | if (ret < 0) |
3548 | ✗ | goto fail; | |
3549 | 432 | break; | |
3550 | 441 | case HEVC_NAL_SPS: | |
3551 | 441 | ret = ff_hevc_decode_nal_sps(&gb, s->avctx, &s->ps, | |
3552 | 441 | nal->nuh_layer_id, s->apply_defdispwin); | |
3553 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 441 times.
|
441 | if (ret < 0) |
3554 | ✗ | goto fail; | |
3555 | 441 | break; | |
3556 | 1401 | case HEVC_NAL_PPS: | |
3557 | 1401 | ret = ff_hevc_decode_nal_pps(&gb, s->avctx, &s->ps); | |
3558 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1399 times.
|
1401 | if (ret < 0) |
3559 | 2 | goto fail; | |
3560 | 1399 | break; | |
3561 | 7825 | case HEVC_NAL_SEI_PREFIX: | |
3562 | case HEVC_NAL_SEI_SUFFIX: | ||
3563 | 7825 | ret = ff_hevc_decode_nal_sei(&gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type); | |
3564 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7792 times.
|
7825 | if (ret < 0) |
3565 | 33 | goto fail; | |
3566 | 7792 | break; | |
3567 | 28289 | case HEVC_NAL_TRAIL_R: | |
3568 | case HEVC_NAL_TRAIL_N: | ||
3569 | case HEVC_NAL_TSA_N: | ||
3570 | case HEVC_NAL_TSA_R: | ||
3571 | case HEVC_NAL_STSA_N: | ||
3572 | case HEVC_NAL_STSA_R: | ||
3573 | case HEVC_NAL_BLA_W_LP: | ||
3574 | case HEVC_NAL_BLA_W_RADL: | ||
3575 | case HEVC_NAL_BLA_N_LP: | ||
3576 | case HEVC_NAL_IDR_W_RADL: | ||
3577 | case HEVC_NAL_IDR_N_LP: | ||
3578 | case HEVC_NAL_CRA_NUT: | ||
3579 | case HEVC_NAL_RADL_N: | ||
3580 | case HEVC_NAL_RADL_R: | ||
3581 | case HEVC_NAL_RASL_N: | ||
3582 | case HEVC_NAL_RASL_R: | ||
3583 | 28289 | ret = decode_slice(s, nal_idx, &gb); | |
3584 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 28254 times.
|
28289 | if (ret < 0) |
3585 | 35 | goto fail; | |
3586 | 28254 | break; | |
3587 | 682 | case HEVC_NAL_EOS_NUT: | |
3588 | case HEVC_NAL_EOB_NUT: | ||
3589 | case HEVC_NAL_AUD: | ||
3590 | case HEVC_NAL_FD_NUT: | ||
3591 | case HEVC_NAL_UNSPEC62: | ||
3592 | 682 | break; | |
3593 | ✗ | default: | |
3594 | ✗ | av_log(s->avctx, AV_LOG_INFO, | |
3595 | ✗ | "Skipping NAL unit %d\n", s->nal_unit_type); | |
3596 | } | ||
3597 | |||
3598 | 39000 | return 0; | |
3599 | 70 | fail: | |
3600 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | if (ret == AVERROR_INVALIDDATA && |
3601 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | !(s->avctx->err_recognition & AV_EF_EXPLODE)) { |
3602 | 70 | av_log(s->avctx, AV_LOG_WARNING, | |
3603 | 70 | "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type); | |
3604 | 70 | return 0; | |
3605 | } | ||
3606 | ✗ | return ret; | |
3607 | } | ||
3608 | |||
3609 | 9971 | static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) | |
3610 | { | ||
3611 | 9971 | int i, ret = 0; | |
3612 | 9971 | int eos_at_start = 1; | |
3613 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 9851 times.
|
9971 | int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING; |
3614 | |||
3615 | 9971 | s->cur_frame = s->collocated_ref = NULL; | |
3616 | 9971 | s->last_eos = s->eos; | |
3617 | 9971 | s->eos = 0; | |
3618 | 9971 | s->slice_initialized = 0; | |
3619 | |||
3620 |
2/2✓ Branch 0 taken 19942 times.
✓ Branch 1 taken 9971 times.
|
29913 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
3621 | 19942 | HEVCLayerContext *l = &s->layers[i]; | |
3622 | 19942 | l->cur_frame = NULL; | |
3623 | } | ||
3624 | |||
3625 | /* split the input packet into NAL units, so we know the upper bound on the | ||
3626 | * number of slices in the frame */ | ||
3627 | 9971 | ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx, | |
3628 | 9971 | s->nal_length_size, s->avctx->codec_id, flags); | |
3629 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9971 times.
|
9971 | if (ret < 0) { |
3630 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3631 | "Error splitting the input into NAL units.\n"); | ||
3632 | ✗ | return ret; | |
3633 | } | ||
3634 | |||
3635 |
2/2✓ Branch 0 taken 39070 times.
✓ Branch 1 taken 9971 times.
|
49041 | for (i = 0; i < s->pkt.nb_nals; i++) { |
3636 |
2/2✓ Branch 0 taken 39069 times.
✓ Branch 1 taken 1 times.
|
39070 | if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT || |
3637 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 39066 times.
|
39069 | s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) { |
3638 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (eos_at_start) { |
3639 | 4 | s->last_eos = 1; | |
3640 | } else { | ||
3641 | ✗ | s->eos = 1; | |
3642 | } | ||
3643 | } else { | ||
3644 | 39066 | eos_at_start = 0; | |
3645 | } | ||
3646 | } | ||
3647 | |||
3648 | /* | ||
3649 | * Check for RPU delimiter. | ||
3650 | * | ||
3651 | * Dolby Vision RPUs masquerade as unregistered NALs of type 62. | ||
3652 | * | ||
3653 | * We have to do this check here an create the rpu buffer, since RPUs are appended | ||
3654 | * to the end of an AU; they are the last non-EOB/EOS NAL in the AU. | ||
3655 | */ | ||
3656 |
4/4✓ Branch 0 taken 8051 times.
✓ Branch 1 taken 1920 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8049 times.
|
9971 | if (s->pkt.nb_nals > 1 && s->pkt.nals[s->pkt.nb_nals - 1].type == HEVC_NAL_UNSPEC62 && |
3657 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | s->pkt.nals[s->pkt.nb_nals - 1].size > 2 && !s->pkt.nals[s->pkt.nb_nals - 1].nuh_layer_id |
3658 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | && !s->pkt.nals[s->pkt.nb_nals - 1].temporal_id) { |
3659 | 2 | H2645NAL *nal = &s->pkt.nals[s->pkt.nb_nals - 1]; | |
3660 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (s->rpu_buf) { |
3661 | ✗ | av_buffer_unref(&s->rpu_buf); | |
3662 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n"); | |
3663 | } | ||
3664 | |||
3665 | 2 | s->rpu_buf = av_buffer_alloc(nal->raw_size - 2); | |
3666 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!s->rpu_buf) |
3667 | ✗ | return AVERROR(ENOMEM); | |
3668 | 2 | memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2); | |
3669 | |||
3670 | 2 | ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2, | |
3671 | 2 | s->avctx->err_recognition); | |
3672 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ret < 0) { |
3673 | ✗ | av_buffer_unref(&s->rpu_buf); | |
3674 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n"); | |
3675 | /* ignore */ | ||
3676 | } | ||
3677 | } | ||
3678 | |||
3679 | /* decode the NAL units */ | ||
3680 |
2/2✓ Branch 0 taken 39070 times.
✓ Branch 1 taken 9971 times.
|
49041 | for (i = 0; i < s->pkt.nb_nals; i++) { |
3681 | 39070 | H2645NAL *nal = &s->pkt.nals[i]; | |
3682 | |||
3683 |
1/2✓ Branch 0 taken 39070 times.
✗ Branch 1 not taken.
|
39070 | if (s->avctx->skip_frame >= AVDISCARD_ALL || |
3684 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 39070 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
39070 | (s->avctx->skip_frame >= AVDISCARD_NONREF && ff_hevc_nal_is_nonref(nal->type))) |
3685 | ✗ | continue; | |
3686 | |||
3687 | 39070 | ret = decode_nal_unit(s, i); | |
3688 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39070 times.
|
39070 | if (ret < 0) { |
3689 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
3690 | "Error parsing NAL unit #%d.\n", i); | ||
3691 | ✗ | goto fail; | |
3692 | } | ||
3693 | } | ||
3694 | |||
3695 | 9971 | fail: | |
3696 |
2/2✓ Branch 0 taken 19942 times.
✓ Branch 1 taken 9971 times.
|
29913 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
3697 | 19942 | HEVCLayerContext *l = &s->layers[i]; | |
3698 | |||
3699 |
2/2✓ Branch 0 taken 9771 times.
✓ Branch 1 taken 10171 times.
|
19942 | if (!l->cur_frame) |
3700 | 9771 | continue; | |
3701 | |||
3702 |
1/2✓ Branch 0 taken 10171 times.
✗ Branch 1 not taken.
|
10171 | if (ret >= 0) |
3703 | 10171 | ret = hevc_frame_end(s, l); | |
3704 | |||
3705 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 10138 times.
|
10171 | if (s->avctx->active_thread_type == FF_THREAD_FRAME) |
3706 | 33 | ff_progress_frame_report(&l->cur_frame->tf, INT_MAX); | |
3707 | } | ||
3708 | |||
3709 | 9971 | return ret; | |
3710 | } | ||
3711 | |||
3712 | 253 | static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first) | |
3713 | { | ||
3714 | int ret, i; | ||
3715 | |||
3716 | 253 | ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff, | |
3717 | 253 | &s->nal_length_size, s->avctx->err_recognition, | |
3718 | 253 | s->apply_defdispwin, s->avctx); | |
3719 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 253 times.
|
253 | if (ret < 0) |
3720 | ✗ | return ret; | |
3721 | |||
3722 | /* export stream parameters from the first SPS */ | ||
3723 |
2/2✓ Branch 0 taken 283 times.
✓ Branch 1 taken 2 times.
|
285 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { |
3724 |
4/4✓ Branch 0 taken 267 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 251 times.
✓ Branch 3 taken 16 times.
|
283 | if (first && s->ps.sps_list[i]) { |
3725 | 251 | const HEVCSPS *sps = s->ps.sps_list[i]; | |
3726 | 251 | export_stream_params(s, sps); | |
3727 | |||
3728 | 251 | ret = export_multilayer(s, sps->vps); | |
3729 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 251 times.
|
251 | if (ret < 0) |
3730 | ✗ | return ret; | |
3731 | |||
3732 | 251 | break; | |
3733 | } | ||
3734 | } | ||
3735 | |||
3736 | /* export stream parameters from SEI */ | ||
3737 | 253 | ret = export_stream_params_from_sei(s); | |
3738 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 253 times.
|
253 | if (ret < 0) |
3739 | ✗ | return ret; | |
3740 | |||
3741 | 253 | return 0; | |
3742 | } | ||
3743 | |||
3744 | 21117 | static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) | |
3745 | { | ||
3746 | 21117 | HEVCContext *s = avctx->priv_data; | |
3747 | 21117 | AVCodecInternal *avci = avctx->internal; | |
3748 | 21117 | AVPacket *avpkt = avci->in_pkt; | |
3749 | |||
3750 | int ret; | ||
3751 | uint8_t *sd; | ||
3752 | size_t sd_size; | ||
3753 | |||
3754 | 21117 | s->pkt_dts = AV_NOPTS_VALUE; | |
3755 | |||
3756 |
2/2✓ Branch 1 taken 948 times.
✓ Branch 2 taken 20169 times.
|
21117 | if (av_container_fifo_can_read(s->output_fifo)) |
3757 | 948 | goto do_output; | |
3758 | |||
3759 | 20169 | av_packet_unref(avpkt); | |
3760 | 20169 | ret = ff_decode_get_packet(avctx, avpkt); | |
3761 |
2/2✓ Branch 0 taken 303 times.
✓ Branch 1 taken 19866 times.
|
20169 | if (ret == AVERROR_EOF) { |
3762 | 303 | ret = ff_hevc_output_frames(s, s->layers_active_decode, | |
3763 | s->layers_active_output, 0, 0, 0); | ||
3764 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 303 times.
|
303 | if (ret < 0) |
3765 | ✗ | return ret; | |
3766 | 303 | goto do_output; | |
3767 |
2/2✓ Branch 0 taken 9895 times.
✓ Branch 1 taken 9971 times.
|
19866 | } else if (ret < 0) |
3768 | 9895 | return ret; | |
3769 | |||
3770 | 9971 | s->pkt_dts = avpkt->dts; | |
3771 | |||
3772 | 9971 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size); | |
3773 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9970 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
9971 | if (sd && sd_size > 0) { |
3774 | 1 | ret = hevc_decode_extradata(s, sd, sd_size, 0); | |
3775 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
3776 | ✗ | return ret; | |
3777 | } | ||
3778 | |||
3779 | 9971 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size); | |
3780 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 9971 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
9971 | if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) { |
3781 | ✗ | int old = s->dovi_ctx.cfg.dv_profile; | |
3782 | ✗ | s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd; | |
3783 | ✗ | if (old) | |
3784 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
3785 | "New DOVI configuration record from input packet (profile %d -> %u).\n", | ||
3786 | ✗ | old, s->dovi_ctx.cfg.dv_profile); | |
3787 | } | ||
3788 | |||
3789 | 9971 | ret = decode_nal_units(s, avpkt->data, avpkt->size); | |
3790 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9971 times.
|
9971 | if (ret < 0) |
3791 | ✗ | return ret; | |
3792 | |||
3793 | 9971 | do_output: | |
3794 |
2/2✓ Branch 1 taken 10006 times.
✓ Branch 2 taken 1216 times.
|
11222 | if (av_container_fifo_read(s->output_fifo, frame, 0) >= 0) { |
3795 |
1/2✓ Branch 0 taken 10006 times.
✗ Branch 1 not taken.
|
10006 | if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN)) |
3796 | 10006 | av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS); | |
3797 | |||
3798 | 10006 | return 0; | |
3799 | } | ||
3800 | |||
3801 |
2/2✓ Branch 0 taken 186 times.
✓ Branch 1 taken 1030 times.
|
1216 | return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN); |
3802 | } | ||
3803 | |||
3804 | 67 | static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src) | |
3805 | { | ||
3806 | int ret; | ||
3807 | |||
3808 | 67 | ff_progress_frame_ref(&dst->tf, &src->tf); | |
3809 | |||
3810 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (src->needs_fg) { |
3811 | ✗ | ret = av_frame_ref(dst->frame_grain, src->frame_grain); | |
3812 | ✗ | if (ret < 0) { | |
3813 | ✗ | ff_hevc_unref_frame(dst, ~0); | |
3814 | ✗ | return ret; | |
3815 | } | ||
3816 | ✗ | dst->needs_fg = 1; | |
3817 | } | ||
3818 | |||
3819 | 67 | dst->pps = av_refstruct_ref_c(src->pps); | |
3820 | 67 | dst->tab_mvf = av_refstruct_ref(src->tab_mvf); | |
3821 | 67 | dst->rpl_tab = av_refstruct_ref(src->rpl_tab); | |
3822 | 67 | dst->rpl = av_refstruct_ref(src->rpl); | |
3823 | 67 | dst->nb_rpl_elems = src->nb_rpl_elems; | |
3824 | |||
3825 | 67 | dst->poc = src->poc; | |
3826 | 67 | dst->ctb_count = src->ctb_count; | |
3827 | 67 | dst->flags = src->flags; | |
3828 | |||
3829 | 67 | dst->base_layer_frame = src->base_layer_frame; | |
3830 | |||
3831 | 67 | av_refstruct_replace(&dst->hwaccel_picture_private, | |
3832 | 67 | src->hwaccel_picture_private); | |
3833 | |||
3834 | 67 | return 0; | |
3835 | } | ||
3836 | |||
3837 | 460 | static av_cold int hevc_decode_free(AVCodecContext *avctx) | |
3838 | { | ||
3839 | 460 | HEVCContext *s = avctx->priv_data; | |
3840 | |||
3841 |
2/2✓ Branch 0 taken 920 times.
✓ Branch 1 taken 460 times.
|
1380 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
3842 | 920 | pic_arrays_free(&s->layers[i]); | |
3843 | 920 | av_refstruct_unref(&s->layers[i].sps); | |
3844 | } | ||
3845 | |||
3846 | 460 | av_refstruct_unref(&s->vps); | |
3847 | 460 | av_refstruct_unref(&s->pps); | |
3848 | |||
3849 | 460 | ff_dovi_ctx_unref(&s->dovi_ctx); | |
3850 | 460 | av_buffer_unref(&s->rpu_buf); | |
3851 | |||
3852 | 460 | av_freep(&s->md5_ctx); | |
3853 | |||
3854 | 460 | av_container_fifo_free(&s->output_fifo); | |
3855 | |||
3856 |
2/2✓ Branch 0 taken 920 times.
✓ Branch 1 taken 460 times.
|
1380 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
3857 | 920 | HEVCLayerContext *l = &s->layers[layer]; | |
3858 |
2/2✓ Branch 0 taken 29440 times.
✓ Branch 1 taken 920 times.
|
30360 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
3859 | 29440 | ff_hevc_unref_frame(&l->DPB[i], ~0); | |
3860 | 29440 | av_frame_free(&l->DPB[i].frame_grain); | |
3861 | } | ||
3862 | } | ||
3863 | |||
3864 | 460 | ff_hevc_ps_uninit(&s->ps); | |
3865 | |||
3866 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
|
460 | for (int i = 0; i < s->nb_wpp_progress; i++) |
3867 | ✗ | ff_thread_progress_destroy(&s->wpp_progress[i]); | |
3868 | 460 | av_freep(&s->wpp_progress); | |
3869 | |||
3870 | 460 | av_freep(&s->sh.entry_point_offset); | |
3871 | 460 | av_freep(&s->sh.offset); | |
3872 | 460 | av_freep(&s->sh.size); | |
3873 | |||
3874 | 460 | av_freep(&s->local_ctx); | |
3875 | |||
3876 | 460 | ff_h2645_packet_uninit(&s->pkt); | |
3877 | |||
3878 | 460 | ff_hevc_reset_sei(&s->sei); | |
3879 | |||
3880 | 460 | return 0; | |
3881 | } | ||
3882 | |||
3883 | 460 | static av_cold int hevc_init_context(AVCodecContext *avctx) | |
3884 | { | ||
3885 | 460 | HEVCContext *s = avctx->priv_data; | |
3886 | |||
3887 | 460 | s->avctx = avctx; | |
3888 | |||
3889 | 460 | s->local_ctx = av_mallocz(sizeof(*s->local_ctx)); | |
3890 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
|
460 | if (!s->local_ctx) |
3891 | ✗ | return AVERROR(ENOMEM); | |
3892 | 460 | s->nb_local_ctx = 1; | |
3893 | |||
3894 | 460 | s->local_ctx[0].parent = s; | |
3895 | 460 | s->local_ctx[0].logctx = avctx; | |
3896 | 460 | s->local_ctx[0].common_cabac_state = &s->cabac; | |
3897 | |||
3898 | 460 | s->output_fifo = av_container_fifo_alloc_avframe(0); | |
3899 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
|
460 | if (!s->output_fifo) |
3900 | ✗ | return AVERROR(ENOMEM); | |
3901 | |||
3902 |
2/2✓ Branch 0 taken 920 times.
✓ Branch 1 taken 460 times.
|
1380 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
3903 | 920 | HEVCLayerContext *l = &s->layers[layer]; | |
3904 |
2/2✓ Branch 0 taken 29440 times.
✓ Branch 1 taken 920 times.
|
30360 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
3905 | 29440 | l->DPB[i].frame_grain = av_frame_alloc(); | |
3906 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29440 times.
|
29440 | if (!l->DPB[i].frame_grain) |
3907 | ✗ | return AVERROR(ENOMEM); | |
3908 | } | ||
3909 | } | ||
3910 | |||
3911 | 460 | s->md5_ctx = av_md5_alloc(); | |
3912 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
|
460 | if (!s->md5_ctx) |
3913 | ✗ | return AVERROR(ENOMEM); | |
3914 | |||
3915 | 460 | ff_bswapdsp_init(&s->bdsp); | |
3916 | |||
3917 | 460 | s->dovi_ctx.logctx = avctx; | |
3918 | 460 | s->eos = 0; | |
3919 | |||
3920 | 460 | ff_hevc_reset_sei(&s->sei); | |
3921 | |||
3922 | 460 | return 0; | |
3923 | } | ||
3924 | |||
3925 | #if HAVE_THREADS | ||
3926 | 32 | static int hevc_update_thread_context(AVCodecContext *dst, | |
3927 | const AVCodecContext *src) | ||
3928 | { | ||
3929 | 32 | HEVCContext *s = dst->priv_data; | |
3930 | 32 | HEVCContext *s0 = src->priv_data; | |
3931 | int ret; | ||
3932 | |||
3933 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
|
96 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
3934 | 64 | HEVCLayerContext *l = &s->layers[layer]; | |
3935 | 64 | const HEVCLayerContext *l0 = &s0->layers[layer]; | |
3936 |
2/2✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 64 times.
|
2112 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
3937 | 2048 | ff_hevc_unref_frame(&l->DPB[i], ~0); | |
3938 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1981 times.
|
2048 | if (l0->DPB[i].f) { |
3939 | 67 | ret = hevc_ref_frame(&l->DPB[i], &l0->DPB[i]); | |
3940 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (ret < 0) |
3941 | ✗ | return ret; | |
3942 | } | ||
3943 | } | ||
3944 | |||
3945 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
|
64 | if (l->sps != l0->sps) { |
3946 | 1 | ret = set_sps(s, l, l0->sps); | |
3947 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
3948 | ✗ | return ret; | |
3949 | } | ||
3950 | } | ||
3951 | |||
3952 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 32 times.
|
544 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) |
3953 | 512 | av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); | |
3954 | |||
3955 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 32 times.
|
544 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) |
3956 | 512 | av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); | |
3957 | |||
3958 |
2/2✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 32 times.
|
2080 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) |
3959 | 2048 | av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); | |
3960 | |||
3961 | // PPS do not persist between frames | ||
3962 | 32 | av_refstruct_unref(&s->pps); | |
3963 | |||
3964 | 32 | s->poc_tid0 = s0->poc_tid0; | |
3965 | 32 | s->eos = s0->eos; | |
3966 | 32 | s->no_rasl_output_flag = s0->no_rasl_output_flag; | |
3967 | |||
3968 | 32 | s->is_nalff = s0->is_nalff; | |
3969 | 32 | s->nal_length_size = s0->nal_length_size; | |
3970 | 32 | s->layers_active_decode = s0->layers_active_decode; | |
3971 | 32 | s->layers_active_output = s0->layers_active_output; | |
3972 | |||
3973 | 32 | s->film_grain_warning_shown = s0->film_grain_warning_shown; | |
3974 | |||
3975 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | if (s->nb_view_ids != s0->nb_view_ids || |
3976 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | memcmp(s->view_ids, s0->view_ids, sizeof(*s->view_ids) * s->nb_view_ids)) { |
3977 | ✗ | av_freep(&s->view_ids); | |
3978 | ✗ | s->nb_view_ids = 0; | |
3979 | |||
3980 | ✗ | if (s0->nb_view_ids) { | |
3981 | ✗ | s->view_ids = av_memdup(s0->view_ids, s0->nb_view_ids * sizeof(*s0->view_ids)); | |
3982 | ✗ | if (!s->view_ids) | |
3983 | ✗ | return AVERROR(ENOMEM); | |
3984 | ✗ | s->nb_view_ids = s0->nb_view_ids; | |
3985 | } | ||
3986 | } | ||
3987 | |||
3988 | 32 | ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common); | |
3989 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
3990 | ✗ | return ret; | |
3991 | |||
3992 | 32 | ret = av_buffer_replace(&s->sei.common.dynamic_hdr_plus.info, | |
3993 | 32 | s0->sei.common.dynamic_hdr_plus.info); | |
3994 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
3995 | ✗ | return ret; | |
3996 | |||
3997 | 32 | ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf); | |
3998 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
3999 | ✗ | return ret; | |
4000 | |||
4001 | 32 | ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx); | |
4002 | |||
4003 | 32 | ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info, | |
4004 | 32 | s0->sei.common.dynamic_hdr_vivid.info); | |
4005 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
4006 | ✗ | return ret; | |
4007 | |||
4008 | 32 | s->sei.common.frame_packing = s0->sei.common.frame_packing; | |
4009 | 32 | s->sei.common.display_orientation = s0->sei.common.display_orientation; | |
4010 | 32 | s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer; | |
4011 | 32 | s->sei.tdrdi = s0->sei.tdrdi; | |
4012 | |||
4013 | 32 | return 0; | |
4014 | } | ||
4015 | #endif | ||
4016 | |||
4017 | 460 | static av_cold int hevc_decode_init(AVCodecContext *avctx) | |
4018 | { | ||
4019 | 460 | HEVCContext *s = avctx->priv_data; | |
4020 | int ret; | ||
4021 | |||
4022 | 460 | ret = hevc_init_context(avctx); | |
4023 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
|
460 | if (ret < 0) |
4024 | ✗ | return ret; | |
4025 | |||
4026 | 460 | s->sei.picture_timing.picture_struct = 0; | |
4027 | 460 | s->eos = 1; | |
4028 | |||
4029 | 460 | atomic_init(&s->wpp_err, 0); | |
4030 | |||
4031 |
2/2✓ Branch 0 taken 459 times.
✓ Branch 1 taken 1 times.
|
460 | if (!avctx->internal->is_copy) { |
4032 | const AVPacketSideData *sd; | ||
4033 | |||
4034 |
3/4✓ Branch 0 taken 252 times.
✓ Branch 1 taken 207 times.
✓ Branch 2 taken 252 times.
✗ Branch 3 not taken.
|
459 | if (avctx->extradata_size > 0 && avctx->extradata) { |
4035 | 252 | ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1); | |
4036 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
|
252 | if (ret < 0) { |
4037 | ✗ | return ret; | |
4038 | } | ||
4039 | |||
4040 | 252 | ret = ff_h2645_sei_to_context(avctx, &s->sei.common); | |
4041 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
|
252 | if (ret < 0) |
4042 | ✗ | return ret; | |
4043 | } | ||
4044 | |||
4045 | 459 | sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF); | |
4046 |
3/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 448 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
459 | if (sd && sd->size >= sizeof(s->dovi_ctx.cfg)) |
4047 | 11 | s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data; | |
4048 | } | ||
4049 | |||
4050 | 460 | return 0; | |
4051 | } | ||
4052 | |||
4053 | 8 | static void hevc_decode_flush(AVCodecContext *avctx) | |
4054 | { | ||
4055 | 8 | HEVCContext *s = avctx->priv_data; | |
4056 | 8 | ff_hevc_flush_dpb(s); | |
4057 | 8 | ff_hevc_reset_sei(&s->sei); | |
4058 | 8 | ff_dovi_ctx_flush(&s->dovi_ctx); | |
4059 | 8 | av_buffer_unref(&s->rpu_buf); | |
4060 | 8 | s->eos = 1; | |
4061 | |||
4062 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
8 | if (FF_HW_HAS_CB(avctx, flush)) |
4063 | ✗ | FF_HW_SIMPLE_CALL(avctx, flush); | |
4064 | 8 | } | |
4065 | |||
4066 | #define OFFSET(x) offsetof(HEVCContext, x) | ||
4067 | #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) | ||
4068 | |||
4069 | static const AVOption options[] = { | ||
4070 | { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin), | ||
4071 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
4072 | { "strict-displaywin", "stricly apply default display window size", OFFSET(apply_defdispwin), | ||
4073 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
4074 | { "view_ids", "Array of view IDs that should be decoded and output; a single -1 to decode all views", | ||
4075 | .offset = OFFSET(view_ids), .type = AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, | ||
4076 | .min = -1, .max = INT_MAX, .flags = PAR }, | ||
4077 | { "view_ids_available", "Array of available view IDs is exported here", | ||
4078 | .offset = OFFSET(view_ids_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY, | ||
4079 | .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY }, | ||
4080 | { "view_pos_available", "Array of view positions for view_ids_available is exported here, as AVStereo3DView", | ||
4081 | .offset = OFFSET(view_pos_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY, | ||
4082 | .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY, .unit = "view_pos" }, | ||
4083 | { "unspecified", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_UNSPEC }, .unit = "view_pos" }, | ||
4084 | { "left", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_LEFT }, .unit = "view_pos" }, | ||
4085 | { "right", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_RIGHT }, .unit = "view_pos" }, | ||
4086 | |||
4087 | { NULL }, | ||
4088 | }; | ||
4089 | |||
4090 | static const AVClass hevc_decoder_class = { | ||
4091 | .class_name = "HEVC decoder", | ||
4092 | .item_name = av_default_item_name, | ||
4093 | .option = options, | ||
4094 | .version = LIBAVUTIL_VERSION_INT, | ||
4095 | }; | ||
4096 | |||
4097 | const FFCodec ff_hevc_decoder = { | ||
4098 | .p.name = "hevc", | ||
4099 | CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"), | ||
4100 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
4101 | .p.id = AV_CODEC_ID_HEVC, | ||
4102 | .priv_data_size = sizeof(HEVCContext), | ||
4103 | .p.priv_class = &hevc_decoder_class, | ||
4104 | .init = hevc_decode_init, | ||
4105 | .close = hevc_decode_free, | ||
4106 | FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame), | ||
4107 | .flush = hevc_decode_flush, | ||
4108 | UPDATE_THREAD_CONTEXT(hevc_update_thread_context), | ||
4109 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | | ||
4110 | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, | ||
4111 | .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | | ||
4112 | FF_CODEC_CAP_USES_PROGRESSFRAMES | | ||
4113 | FF_CODEC_CAP_INIT_CLEANUP, | ||
4114 | .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles), | ||
4115 | .hw_configs = (const AVCodecHWConfigInternal *const []) { | ||
4116 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
4117 | HWACCEL_DXVA2(hevc), | ||
4118 | #endif | ||
4119 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
4120 | HWACCEL_D3D11VA(hevc), | ||
4121 | #endif | ||
4122 | #if CONFIG_HEVC_D3D11VA2_HWACCEL | ||
4123 | HWACCEL_D3D11VA2(hevc), | ||
4124 | #endif | ||
4125 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
4126 | HWACCEL_D3D12VA(hevc), | ||
4127 | #endif | ||
4128 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
4129 | HWACCEL_NVDEC(hevc), | ||
4130 | #endif | ||
4131 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
4132 | HWACCEL_VAAPI(hevc), | ||
4133 | #endif | ||
4134 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
4135 | HWACCEL_VDPAU(hevc), | ||
4136 | #endif | ||
4137 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
4138 | HWACCEL_VIDEOTOOLBOX(hevc), | ||
4139 | #endif | ||
4140 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
4141 | HWACCEL_VULKAN(hevc), | ||
4142 | #endif | ||
4143 | NULL | ||
4144 | }, | ||
4145 | }; | ||
4146 |