FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc/hevcdec.c
Date: 2025-06-01 09:29:47
Exec Total Coverage
Lines: 1963 2428 80.8%
Functions: 51 55 92.7%
Branches: 1379 1831 75.3%

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 1384 static void pic_arrays_free(HEVCLayerContext *l)
72 {
73 1384 av_freep(&l->sao);
74 1384 av_freep(&l->deblock);
75
76 1384 av_freep(&l->skip_flag);
77 1384 av_freep(&l->tab_ct_depth);
78
79 1384 av_freep(&l->tab_ipm);
80 1384 av_freep(&l->cbf_luma);
81 1384 av_freep(&l->is_pcm);
82
83 1384 av_freep(&l->qp_y_tab);
84 1384 av_freep(&l->tab_slice_address);
85 1384 av_freep(&l->filter_slice_edges);
86
87 1384 av_freep(&l->horizontal_bs);
88 1384 av_freep(&l->vertical_bs);
89
90
2/2
✓ Branch 0 taken 4152 times.
✓ Branch 1 taken 1384 times.
5536 for (int i = 0; i < 3; i++) {
91 4152 av_freep(&l->sao_pixel_buffer_h[i]);
92 4152 av_freep(&l->sao_pixel_buffer_v[i]);
93 }
94
95 1384 av_refstruct_pool_uninit(&l->tab_mvf_pool);
96 1384 av_refstruct_pool_uninit(&l->rpl_tab_pool);
97 1384 }
98
99 /* allocate arrays that depend on frame dimensions */
100 424 static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps)
101 {
102 424 int log2_min_cb_size = sps->log2_min_cb_size;
103 424 int width = sps->width;
104 424 int height = sps->height;
105 424 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
106 424 ((height >> log2_min_cb_size) + 1);
107 424 int ctb_count = sps->ctb_width * sps->ctb_height;
108 424 int min_pu_size = sps->min_pu_width * sps->min_pu_height;
109
110 424 l->bs_width = (width >> 2) + 1;
111 424 l->bs_height = (height >> 2) + 1;
112
113 424 l->sao = av_calloc(ctb_count, sizeof(*l->sao));
114 424 l->deblock = av_calloc(ctb_count, sizeof(*l->deblock));
115
2/4
✓ Branch 0 taken 424 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 424 times.
424 if (!l->sao || !l->deblock)
116 goto fail;
117
118 424 l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
119 424 l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
120
2/4
✓ Branch 0 taken 424 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 424 times.
424 if (!l->skip_flag || !l->tab_ct_depth)
121 goto fail;
122
123 424 l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
124 424 l->tab_ipm = av_mallocz(min_pu_size);
125 424 l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1);
126
3/6
✓ Branch 0 taken 424 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 424 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 424 times.
424 if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm)
127 goto fail;
128
129 424 l->filter_slice_edges = av_mallocz(ctb_count);
130 424 l->tab_slice_address = av_malloc_array(pic_size_in_ctb,
131 sizeof(*l->tab_slice_address));
132 424 l->qp_y_tab = av_calloc(pic_size_in_ctb,
133 sizeof(*l->qp_y_tab));
134
3/6
✓ Branch 0 taken 424 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 424 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 424 times.
424 if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address)
135 goto fail;
136
137 424 l->horizontal_bs = av_calloc(l->bs_width, l->bs_height);
138 424 l->vertical_bs = av_calloc(l->bs_width, l->bs_height);
139
2/4
✓ Branch 0 taken 424 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 424 times.
424 if (!l->horizontal_bs || !l->vertical_bs)
140 goto fail;
141
142 424 l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
143 424 l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0);
144
2/4
✓ Branch 0 taken 424 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 424 times.
424 if (!l->tab_mvf_pool || !l->rpl_tab_pool)
145 goto fail;
146
147
2/2
✓ Branch 0 taken 369 times.
✓ Branch 1 taken 55 times.
424 if (sps->sao_enabled) {
148
2/2
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 2 times.
369 int c_count = (sps->chroma_format_idc != 0) ? 3 : 1;
149
150
2/2
✓ Branch 0 taken 1103 times.
✓ Branch 1 taken 369 times.
1472 for (int c_idx = 0; c_idx < c_count; c_idx++) {
151 1103 int w = sps->width >> sps->hshift[c_idx];
152 1103 int h = sps->height >> sps->vshift[c_idx];
153 1103 l->sao_pixel_buffer_h[c_idx] =
154 1103 av_malloc((w * 2 * sps->ctb_height) <<
155 1103 sps->pixel_shift);
156 1103 l->sao_pixel_buffer_v[c_idx] =
157 1103 av_malloc((h * 2 * sps->ctb_width) <<
158 1103 sps->pixel_shift);
159
1/2
✓ Branch 0 taken 1103 times.
✗ Branch 1 not taken.
1103 if (!l->sao_pixel_buffer_h[c_idx] ||
160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1103 times.
1103 !l->sao_pixel_buffer_v[c_idx])
161 goto fail;
162 }
163 }
164
165 424 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 int luma_log2_weight_denom;
178 unsigned luma_weight_flags, chroma_weight_flags;
179
180 1443 luma_log2_weight_denom = get_ue_golomb_long(gb);
181
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) {
182 av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
183 return AVERROR_INVALIDDATA;
184 }
185 1443 sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
186
1/2
✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
1443 if (sps->chroma_format_idc != 0) {
187 1443 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
188
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) {
189 av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
190 return AVERROR_INVALIDDATA;
191 }
192 1443 sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
193 }
194
195 1443 luma_weight_flags = get_bits(gb, sh->nb_refs[L0]);
196
1/2
✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
1443 chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L0]) : 0;
197
2/2
✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
5850 for (i = 0; i < sh->nb_refs[L0]; i++) {
198 4407 unsigned flag_bit = 1 << (sh->nb_refs[L0] - 1 - i);
199
200
2/2
✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1290 times.
4407 if (luma_weight_flags & flag_bit) {
201 3117 int delta_luma_weight_l0 = get_se_golomb(gb);
202
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
3117 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
203 return AVERROR_INVALIDDATA;
204 3117 sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
205 3117 sh->luma_offset_l0[i] = get_se_golomb(gb);
206 } else {
207 1290 sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
208 1290 sh->luma_offset_l0[i] = 0;
209 }
210
2/2
✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3276 times.
4407 if (chroma_weight_flags & flag_bit) {
211
2/2
✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
3393 for (j = 0; j < 2; j++) {
212 2262 int delta_chroma_weight_l0 = get_se_golomb(gb);
213 2262 int delta_chroma_offset_l0 = get_se_golomb(gb);
214
215
1/2
✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
2262 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
216
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)) {
217 return AVERROR_INVALIDDATA;
218 }
219
220 2262 sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0;
221 2262 sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j])
222 2262 >> sh->chroma_log2_weight_denom) + 128), -128, 127);
223 }
224 } else {
225 3276 sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom;
226 3276 sh->chroma_offset_l0[i][0] = 0;
227 3276 sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom;
228 3276 sh->chroma_offset_l0[i][1] = 0;
229 }
230 }
231
2/2
✓ Branch 0 taken 668 times.
✓ Branch 1 taken 775 times.
1443 if (sh->slice_type == HEVC_SLICE_B) {
232 668 luma_weight_flags = get_bits(gb, sh->nb_refs[L1]);
233
1/2
✓ Branch 0 taken 668 times.
✗ Branch 1 not taken.
668 chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L1]) : 0;
234
2/2
✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
2015 for (i = 0; i < sh->nb_refs[L1]; i++) {
235 1347 unsigned flag_bit = 1 << (sh->nb_refs[L1] - 1 - i);
236
237
2/2
✓ Branch 0 taken 746 times.
✓ Branch 1 taken 601 times.
1347 if (luma_weight_flags & flag_bit) {
238 746 int delta_luma_weight_l1 = get_se_golomb(gb);
239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
746 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
240 return AVERROR_INVALIDDATA;
241 746 sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
242 746 sh->luma_offset_l1[i] = get_se_golomb(gb);
243 } else {
244 601 sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
245 601 sh->luma_offset_l1[i] = 0;
246 }
247
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1111 times.
1347 if (chroma_weight_flags & flag_bit) {
248
2/2
✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
708 for (j = 0; j < 2; j++) {
249 472 int delta_chroma_weight_l1 = get_se_golomb(gb);
250 472 int delta_chroma_offset_l1 = get_se_golomb(gb);
251
252
1/2
✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
472 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
253
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)) {
254 return AVERROR_INVALIDDATA;
255 }
256
257 472 sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1;
258 472 sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j])
259 472 >> sh->chroma_log2_weight_denom) + 128), -128, 127);
260 }
261 } else {
262 1111 sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom;
263 1111 sh->chroma_offset_l1[i][0] = 0;
264 1111 sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom;
265 1111 sh->chroma_offset_l1[i][1] = 0;
266 }
267 }
268 }
269 1443 return 0;
270 }
271
272 19767 static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps,
273 GetBitContext *gb, int cur_poc, int poc_lsb)
274 {
275 19767 int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
276 19767 int prev_delta_msb = 0;
277 19767 unsigned int nb_sps = 0, nb_sh;
278 int i;
279
280 19767 rps->nb_refs = 0;
281
2/2
✓ Branch 0 taken 18731 times.
✓ Branch 1 taken 1036 times.
19767 if (!sps->long_term_ref_pics_present)
282 18731 return 0;
283
284
2/2
✓ Branch 0 taken 499 times.
✓ Branch 1 taken 537 times.
1036 if (sps->num_long_term_ref_pics_sps > 0)
285 499 nb_sps = get_ue_golomb_long(gb);
286 1036 nb_sh = get_ue_golomb_long(gb);
287
288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
1036 if (nb_sps > sps->num_long_term_ref_pics_sps)
289 return AVERROR_INVALIDDATA;
290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
1036 if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc))
291 return AVERROR_INVALIDDATA;
292
293 1036 rps->nb_refs = nb_sh + nb_sps;
294
295
2/2
✓ Branch 0 taken 1562 times.
✓ Branch 1 taken 1036 times.
2598 for (i = 0; i < rps->nb_refs; i++) {
296
297
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1378 times.
1562 if (i < nb_sps) {
298 184 uint8_t lt_idx_sps = 0;
299
300
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if (sps->num_long_term_ref_pics_sps > 1)
301 184 lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps));
302
303 184 rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
304 184 rps->used[i] = !!(sps->used_by_curr_pic_lt & (1U << lt_idx_sps));
305 } else {
306 1378 rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb);
307 1378 rps->used[i] = get_bits1(gb);
308 }
309
310 1562 rps->poc_msb_present[i] = get_bits1(gb);
311
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1514 times.
1562 if (rps->poc_msb_present[i]) {
312 48 int64_t delta = get_ue_golomb_long(gb);
313 int64_t poc;
314
315
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)
316 31 delta += prev_delta_msb;
317
318 48 poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb;
319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (poc != (int32_t)poc)
320 return AVERROR_INVALIDDATA;
321 48 rps->poc[i] = poc;
322 48 prev_delta_msb = delta;
323 }
324 }
325
326 1036 return 0;
327 }
328
329 682 static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
330 {
331 682 AVCodecContext *avctx = s->avctx;
332 682 const HEVCVPS *vps = sps->vps;
333 682 const HEVCWindow *ow = &sps->output_window;
334 682 unsigned int num = 0, den = 0;
335
336 682 avctx->pix_fmt = sps->pix_fmt;
337 682 avctx->coded_width = sps->width;
338 682 avctx->coded_height = sps->height;
339 682 avctx->width = sps->width - ow->left_offset - ow->right_offset;
340 682 avctx->height = sps->height - ow->top_offset - ow->bottom_offset;
341 682 avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
342 682 avctx->profile = sps->ptl.general_ptl.profile_idc;
343 682 avctx->level = sps->ptl.general_ptl.level_idc;
344
345 682 ff_set_sar(avctx, sps->vui.common.sar);
346
347
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 616 times.
682 if (sps->vui.common.video_signal_type_present_flag)
348 66 avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG
349
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 60 times.
66 : AVCOL_RANGE_MPEG;
350 else
351 616 avctx->color_range = AVCOL_RANGE_MPEG;
352
353
2/2
✓ Branch 0 taken 59 times.
✓ Branch 1 taken 623 times.
682 if (sps->vui.common.colour_description_present_flag) {
354 59 avctx->color_primaries = sps->vui.common.colour_primaries;
355 59 avctx->color_trc = sps->vui.common.transfer_characteristics;
356 59 avctx->colorspace = sps->vui.common.matrix_coeffs;
357 } else {
358 623 avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
359 623 avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
360 623 avctx->colorspace = AVCOL_SPC_UNSPECIFIED;
361 }
362
363 682 avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
364
2/2
✓ Branch 0 taken 641 times.
✓ Branch 1 taken 41 times.
682 if (sps->chroma_format_idc == 1) {
365
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 622 times.
641 if (sps->vui.common.chroma_loc_info_present_flag) {
366
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 if (sps->vui.common.chroma_sample_loc_type_top_field <= 5)
367 19 avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1;
368 } else
369 622 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
370 }
371
372
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 660 times.
682 if (vps->vps_timing_info_present_flag) {
373 22 num = vps->vps_num_units_in_tick;
374 22 den = vps->vps_time_scale;
375
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 604 times.
660 } else if (sps->vui.vui_timing_info_present_flag) {
376 56 num = sps->vui.vui_num_units_in_tick;
377 56 den = sps->vui.vui_time_scale;
378 }
379
380
3/4
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 604 times.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
682 if (num > 0 && den > 0)
381 78 av_reduce(&avctx->framerate.den, &avctx->framerate.num,
382 num, den, 1 << 30);
383 682 }
384
385 10553 static int export_stream_params_from_sei(HEVCContext *s)
386 {
387 10553 AVCodecContext *avctx = s->avctx;
388
389 #if FF_API_CODEC_PROPS
390 FF_DISABLE_DEPRECATION_WARNINGS
391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10553 times.
10553 if (s->sei.common.a53_caption.buf_ref)
392 s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
393 FF_ENABLE_DEPRECATION_WARNINGS
394 #endif
395
396
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10553 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10553 if (s->sei.common.alternative_transfer.present &&
397 av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) &&
398 s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
399 avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics;
400 }
401
402 #if FF_API_CODEC_PROPS
403 FF_DISABLE_DEPRECATION_WARNINGS
404
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10553 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10553 if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) ||
405
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10553 times.
10553 s->sei.common.aom_film_grain.enable)
406 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
407 FF_ENABLE_DEPRECATION_WARNINGS
408 #endif
409
410 10553 return 0;
411 }
412
413 682 static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
414 {
415 682 const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
416
417 682 av_freep(&s->view_ids_available);
418 682 s->nb_view_ids_available = 0;
419 682 av_freep(&s->view_pos_available);
420 682 s->nb_view_pos_available = 0;
421
422 // don't export anything in the trivial case (1 layer, view id=0)
423
3/4
✓ Branch 0 taken 657 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 657 times.
✗ Branch 3 not taken.
682 if (vps->nb_layers < 2 && !vps->view_id[0])
424 657 return 0;
425
426 25 s->view_ids_available = av_calloc(vps->nb_layers, sizeof(*s->view_ids_available));
427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (!s->view_ids_available)
428 return AVERROR(ENOMEM);
429
430
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if (tdrdi->num_ref_displays) {
431 5 s->view_pos_available = av_calloc(vps->nb_layers, sizeof(*s->view_pos_available));
432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!s->view_pos_available)
433 return AVERROR(ENOMEM);
434 }
435
436
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 25 times.
75 for (int i = 0; i < vps->nb_layers; i++) {
437 50 s->view_ids_available[i] = vps->view_id[i];
438
439
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 40 times.
50 if (s->view_pos_available) {
440 10 s->view_pos_available[i] = vps->view_id[i] == tdrdi->left_view_id[0] ?
441
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
15 AV_STEREO3D_VIEW_LEFT :
442
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 vps->view_id[i] == tdrdi->right_view_id[0] ?
443 AV_STEREO3D_VIEW_RIGHT : AV_STEREO3D_VIEW_UNSPEC;
444 }
445 }
446 25 s->nb_view_ids_available = vps->nb_layers;
447
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 s->nb_view_pos_available = s->view_pos_available ? vps->nb_layers : 0;
448
449 25 return 0;
450 }
451
452 11505 int ff_hevc_is_alpha_video(const HEVCContext *s)
453 {
454 11505 const HEVCVPS *vps = s->vps;
455 11505 int ret = 0;
456
457
3/4
✓ Branch 0 taken 1023 times.
✓ Branch 1 taken 10482 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1023 times.
11505 if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1])
458 10482 return 0;
459
460 /* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other
461 * than alpha cannot reach here.
462 */
463 1023 ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY);
464
465
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 870 times.
1023 av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n",
466 ret ? "is" : "not");
467
468 1023 return ret;
469 }
470
471 414 static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
472 {
473 414 unsigned layers_active_output = 0, highest_layer;
474
475 414 s->layers_active_output = 1;
476 414 s->layers_active_decode = 1;
477
478
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 413 times.
414 if (ff_hevc_is_alpha_video(s)) {
479 1 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
480
481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
482 return 0;
483
484 1 s->layers_active_decode = (1 << vps->nb_layers) - 1;
485 1 s->layers_active_output = 1;
486
487 1 return 0;
488 }
489
490 // nothing requested - decode base layer only
491
2/2
✓ Branch 0 taken 403 times.
✓ Branch 1 taken 10 times.
413 if (!s->nb_view_ids)
492 403 return 0;
493
494
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) {
495 layers_active_output = (1 << vps->nb_layers) - 1;
496 } else {
497
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 10 times.
28 for (int i = 0; i < s->nb_view_ids; i++) {
498 18 int view_id = s->view_ids[i];
499 18 int layer_idx = -1;
500
501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (view_id < 0) {
502 av_log(s->avctx, AV_LOG_ERROR,
503 "Invalid view ID requested: %d\n", view_id);
504 return AVERROR(EINVAL);
505 }
506
507
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 for (int j = 0; j < vps->nb_layers; j++) {
508
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
26 if (vps->view_id[j] == view_id) {
509 18 layer_idx = j;
510 18 break;
511 }
512 }
513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (layer_idx < 0) {
514 av_log(s->avctx, AV_LOG_ERROR,
515 "View ID %d not present in VPS\n", view_id);
516 return AVERROR(EINVAL);
517 }
518 18 layers_active_output |= 1 << layer_idx;
519 }
520 }
521
522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!layers_active_output) {
523 av_log(s->avctx, AV_LOG_ERROR, "No layers selected\n");
524 return AVERROR_BUG;
525 }
526
527 10 highest_layer = ff_log2(layers_active_output);
528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (highest_layer >= FF_ARRAY_ELEMS(s->layers)) {
529 av_log(s->avctx, AV_LOG_ERROR,
530 "Too many layers requested: %u\n", layers_active_output);
531 return AVERROR(EINVAL);
532 }
533
534 /* Assume a higher layer depends on all the lower ones.
535 * This is enforced in VPS parsing currently, this logic will need
536 * to be changed if we want to support more complex dependency structures.
537 */
538 10 s->layers_active_decode = (1 << (highest_layer + 1)) - 1;
539 10 s->layers_active_output = layers_active_output;
540
541 10 av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n",
542 s->layers_active_decode, s->layers_active_output);
543
544 10 return 0;
545 }
546
547 1 static enum AVPixelFormat map_to_alpha_format(HEVCContext *s,
548 enum AVPixelFormat pix_fmt)
549 {
550
1/9
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 switch (pix_fmt) {
551 1 case AV_PIX_FMT_YUV420P:
552 case AV_PIX_FMT_YUVJ420P:
553 1 return AV_PIX_FMT_YUVA420P;
554 case AV_PIX_FMT_YUV420P10:
555 return AV_PIX_FMT_YUVA420P10;
556 case AV_PIX_FMT_YUV444P:
557 return AV_PIX_FMT_YUVA444P;
558 case AV_PIX_FMT_YUV422P:
559 return AV_PIX_FMT_YUVA422P;
560 case AV_PIX_FMT_YUV422P10LE:
561 return AV_PIX_FMT_YUVA422P10LE;
562 case AV_PIX_FMT_YUV444P10:
563 return AV_PIX_FMT_YUVA444P10;
564 case AV_PIX_FMT_YUV444P12:
565 return AV_PIX_FMT_YUVA444P12;
566 case AV_PIX_FMT_YUV422P12:
567 return AV_PIX_FMT_YUVA422P12;
568 default:
569 av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n",
570 av_get_pix_fmt_name(pix_fmt));
571 return AV_PIX_FMT_NONE;
572 }
573 }
574
575 414 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
576 {
577 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
578 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
579 CONFIG_HEVC_D3D12VA_HWACCEL + \
580 CONFIG_HEVC_NVDEC_HWACCEL + \
581 CONFIG_HEVC_VAAPI_HWACCEL + \
582 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
583 CONFIG_HEVC_VDPAU_HWACCEL + \
584 CONFIG_HEVC_VULKAN_HWACCEL)
585 414 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts;
586 414 enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE;
587 int ret;
588
589
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 413 times.
414 if (ff_hevc_is_alpha_video(s))
590 1 alpha_fmt = map_to_alpha_format(s, sps->pix_fmt);
591
592
6/7
✓ Branch 0 taken 349 times.
✓ Branch 1 taken 37 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.
414 switch (sps->pix_fmt) {
593 349 case AV_PIX_FMT_YUV420P:
594 case AV_PIX_FMT_YUVJ420P:
595 #if CONFIG_HEVC_DXVA2_HWACCEL
596 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
597 #endif
598 #if CONFIG_HEVC_D3D11VA_HWACCEL
599 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
600 *fmt++ = AV_PIX_FMT_D3D11;
601 #endif
602 #if CONFIG_HEVC_D3D12VA_HWACCEL
603 *fmt++ = AV_PIX_FMT_D3D12;
604 #endif
605 #if CONFIG_HEVC_VAAPI_HWACCEL
606 349 *fmt++ = AV_PIX_FMT_VAAPI;
607 #endif
608 #if CONFIG_HEVC_VDPAU_HWACCEL
609 349 *fmt++ = AV_PIX_FMT_VDPAU;
610 #endif
611 #if CONFIG_HEVC_NVDEC_HWACCEL
612 *fmt++ = AV_PIX_FMT_CUDA;
613 #endif
614 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
615 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
616 #endif
617 #if CONFIG_HEVC_VULKAN_HWACCEL
618 *fmt++ = AV_PIX_FMT_VULKAN;
619 #endif
620 349 break;
621 37 case AV_PIX_FMT_YUV420P10:
622 #if CONFIG_HEVC_DXVA2_HWACCEL
623 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
624 #endif
625 #if CONFIG_HEVC_D3D11VA_HWACCEL
626 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
627 *fmt++ = AV_PIX_FMT_D3D11;
628 #endif
629 #if CONFIG_HEVC_D3D12VA_HWACCEL
630 *fmt++ = AV_PIX_FMT_D3D12;
631 #endif
632 #if CONFIG_HEVC_VAAPI_HWACCEL
633 37 *fmt++ = AV_PIX_FMT_VAAPI;
634 #endif
635 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
636 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
637 #endif
638 #if CONFIG_HEVC_VULKAN_HWACCEL
639 *fmt++ = AV_PIX_FMT_VULKAN;
640 #endif
641 #if CONFIG_HEVC_VDPAU_HWACCEL
642 37 *fmt++ = AV_PIX_FMT_VDPAU;
643 #endif
644 #if CONFIG_HEVC_NVDEC_HWACCEL
645 *fmt++ = AV_PIX_FMT_CUDA;
646 #endif
647 37 break;
648 4 case AV_PIX_FMT_YUV444P:
649 #if CONFIG_HEVC_VAAPI_HWACCEL
650 4 *fmt++ = AV_PIX_FMT_VAAPI;
651 #endif
652 #if CONFIG_HEVC_VDPAU_HWACCEL
653 4 *fmt++ = AV_PIX_FMT_VDPAU;
654 #endif
655 #if CONFIG_HEVC_NVDEC_HWACCEL
656 *fmt++ = AV_PIX_FMT_CUDA;
657 #endif
658 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
659 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
660 #endif
661 #if CONFIG_HEVC_VULKAN_HWACCEL
662 *fmt++ = AV_PIX_FMT_VULKAN;
663 #endif
664 4 break;
665 12 case AV_PIX_FMT_YUV422P:
666 case AV_PIX_FMT_YUV422P10LE:
667 #if CONFIG_HEVC_VAAPI_HWACCEL
668 12 *fmt++ = AV_PIX_FMT_VAAPI;
669 #endif
670 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
671 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
672 #endif
673 #if CONFIG_HEVC_VULKAN_HWACCEL
674 *fmt++ = AV_PIX_FMT_VULKAN;
675 #endif
676 #if CONFIG_HEVC_NVDEC_HWACCEL
677 *fmt++ = AV_PIX_FMT_CUDA;
678 #endif
679 12 break;
680 10 case AV_PIX_FMT_YUV444P10:
681 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
682 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
683 #endif
684 /* NOTE: fallthrough */
685 case AV_PIX_FMT_YUV420P12:
686 case AV_PIX_FMT_YUV444P12:
687 #if CONFIG_HEVC_VAAPI_HWACCEL
688 10 *fmt++ = AV_PIX_FMT_VAAPI;
689 #endif
690 #if CONFIG_HEVC_VDPAU_HWACCEL
691 10 *fmt++ = AV_PIX_FMT_VDPAU;
692 #endif
693 #if CONFIG_HEVC_VULKAN_HWACCEL
694 *fmt++ = AV_PIX_FMT_VULKAN;
695 #endif
696 #if CONFIG_HEVC_NVDEC_HWACCEL
697 *fmt++ = AV_PIX_FMT_CUDA;
698 #endif
699 10 break;
700 case AV_PIX_FMT_YUV422P12:
701 #if CONFIG_HEVC_VAAPI_HWACCEL
702 *fmt++ = AV_PIX_FMT_VAAPI;
703 #endif
704 #if CONFIG_HEVC_VULKAN_HWACCEL
705 *fmt++ = AV_PIX_FMT_VULKAN;
706 #endif
707 #if CONFIG_HEVC_NVDEC_HWACCEL
708 *fmt++ = AV_PIX_FMT_CUDA;
709 #endif
710 break;
711 }
712
713
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 413 times.
414 if (alpha_fmt != AV_PIX_FMT_NONE)
714 1 *fmt++ = alpha_fmt;
715 414 *fmt++ = sps->pix_fmt;
716 414 *fmt = AV_PIX_FMT_NONE;
717
718 // export multilayer information from active VPS to the caller,
719 // so it is available in get_format()
720 414 ret = export_multilayer(s, sps->vps);
721
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
414 if (ret < 0)
722 return ret;
723
724 414 ret = ff_get_format(s->avctx, pix_fmts);
725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
414 if (ret < 0)
726 return ret;
727 414 s->avctx->pix_fmt = ret;
728
729 // set up multilayer decoding, if requested by caller
730 414 ret = setup_multilayer(s, sps->vps);
731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
414 if (ret < 0)
732 return ret;
733
734 414 return 0;
735 }
736
737 424 static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
738 {
739 int ret;
740
741 424 pic_arrays_free(l);
742 424 av_refstruct_unref(&l->sps);
743 424 av_refstruct_unref(&s->vps);
744
745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 424 times.
424 if (!sps)
746 return 0;
747
748 424 ret = pic_arrays_init(l, sps);
749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 424 times.
424 if (ret < 0)
750 goto fail;
751
752 424 ff_hevc_pred_init(&s->hpc, sps->bit_depth);
753 424 ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
754 424 ff_videodsp_init (&s->vdsp, sps->bit_depth);
755
756 424 l->sps = av_refstruct_ref_c(sps);
757 424 s->vps = av_refstruct_ref_c(sps->vps);
758
759 424 return 0;
760
761 fail:
762 pic_arrays_free(l);
763 av_refstruct_unref(&l->sps);
764 return ret;
765 }
766
767 28398 static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb)
768 {
769 const HEVCPPS *pps;
770 const HEVCSPS *sps;
771 const HEVCVPS *vps;
772 unsigned pps_id, layer_idx;
773 int i, ret;
774
775 // Coded parameters
776 28398 sh->first_slice_in_pic_flag = get_bits1(gb);
777
778 28398 sh->no_output_of_prior_pics_flag = 0;
779
3/4
✓ Branch 0 taken 1468 times.
✓ Branch 1 taken 26930 times.
✓ Branch 2 taken 1468 times.
✗ Branch 3 not taken.
28398 if (IS_IRAP(s))
780 1468 sh->no_output_of_prior_pics_flag = get_bits1(gb);
781
782 28398 pps_id = get_ue_golomb_long(gb);
783
3/4
✓ Branch 0 taken 28398 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 28365 times.
28398 if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) {
784 33 av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
785 33 return AVERROR_INVALIDDATA;
786 }
787
3/4
✓ Branch 0 taken 18038 times.
✓ Branch 1 taken 10327 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18038 times.
28365 if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) {
788 av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
789 return AVERROR_INVALIDDATA;
790 }
791 28365 sh->pps_id = pps_id;
792
793 28365 pps = s->ps.pps_list[pps_id];
794 28365 sps = pps->sps;
795 28365 vps = sps->vps;
796 28365 layer_idx = vps->layer_idx[s->nuh_layer_id];
797
798
4/4
✓ Branch 0 taken 479 times.
✓ Branch 1 taken 27886 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 464 times.
28365 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
799 15 sh->no_output_of_prior_pics_flag = 1;
800
801 28365 sh->dependent_slice_segment_flag = 0;
802
2/2
✓ Branch 0 taken 18038 times.
✓ Branch 1 taken 10327 times.
28365 if (!sh->first_slice_in_pic_flag) {
803 int slice_address_length;
804
805
2/2
✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8946 times.
18038 if (pps->dependent_slice_segments_enabled_flag)
806 9092 sh->dependent_slice_segment_flag = get_bits1(gb);
807
3/4
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 10091 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7947 times.
18038 if (sh->dependent_slice_segment_flag && !s->slice_initialized) {
808 av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
809 return AVERROR_INVALIDDATA;
810 }
811
812 18038 slice_address_length = av_ceil_log2(sps->ctb_width *
813 18038 sps->ctb_height);
814 18038 sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18038 times.
18038 if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
816 av_log(s->avctx, AV_LOG_ERROR,
817 "Invalid slice segment address: %u.\n",
818 sh->slice_segment_addr);
819 return AVERROR_INVALIDDATA;
820 }
821
822
2/2
✓ Branch 0 taken 10091 times.
✓ Branch 1 taken 7947 times.
18038 if (!sh->dependent_slice_segment_flag) {
823 10091 sh->slice_addr = sh->slice_segment_addr;
824 }
825 } else {
826 10327 sh->slice_segment_addr = sh->slice_addr = 0;
827 }
828
829
2/2
✓ Branch 0 taken 20418 times.
✓ Branch 1 taken 7947 times.
28365 if (!sh->dependent_slice_segment_flag) {
830
2/2
✓ Branch 0 taken 1078 times.
✓ Branch 1 taken 20418 times.
21496 for (i = 0; i < pps->num_extra_slice_header_bits; i++)
831 1078 skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
832
833 20418 sh->slice_type = get_ue_golomb_long(gb);
834
2/2
✓ Branch 0 taken 19163 times.
✓ Branch 1 taken 1255 times.
20418 if (!(sh->slice_type == HEVC_SLICE_I ||
835
2/2
✓ Branch 0 taken 15233 times.
✓ Branch 1 taken 3930 times.
19163 sh->slice_type == HEVC_SLICE_P ||
836
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15233 times.
15233 sh->slice_type == HEVC_SLICE_B)) {
837 av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",
838 sh->slice_type);
839 return AVERROR_INVALIDDATA;
840 }
841
5/6
✓ Branch 0 taken 1079 times.
✓ Branch 1 taken 19339 times.
✓ Branch 2 taken 1079 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 75 times.
✓ Branch 5 taken 1004 times.
20418 if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
842
1/2
✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
75 !pps->pps_curr_pic_ref_enabled_flag &&
843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
75 s->nuh_layer_id == 0) {
844 av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
845 return AVERROR_INVALIDDATA;
846 }
847
848 // when flag is not present, picture is inferred to be output
849 20418 sh->pic_output_flag = 1;
850
2/2
✓ Branch 0 taken 703 times.
✓ Branch 1 taken 19715 times.
20418 if (pps->output_flag_present_flag)
851 703 sh->pic_output_flag = get_bits1(gb);
852
853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20418 times.
20418 if (sps->separate_colour_plane)
854 sh->colour_plane_id = get_bits(gb, 2);
855
856
4/4
✓ Branch 0 taken 19796 times.
✓ Branch 1 taken 622 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 19767 times.
20418 if (!IS_IDR(s) ||
857
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 639 times.
651 (s->nuh_layer_id > 0 &&
858
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 5 times.
12 !(vps->poc_lsb_not_present & (1 << layer_idx)))) {
859 int poc;
860
861 19774 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
862 19774 poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
863
3/4
✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9906 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
19774 if (!sh->first_slice_in_pic_flag && poc != sh->poc) {
864 av_log(s->avctx, AV_LOG_WARNING,
865 "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc);
866 if (s->avctx->err_recognition & AV_EF_EXPLODE)
867 return AVERROR_INVALIDDATA;
868 poc = sh->poc;
869 }
870 19774 sh->poc = poc;
871 }
872
873
4/4
✓ Branch 0 taken 19796 times.
✓ Branch 1 taken 622 times.
✓ Branch 2 taken 19767 times.
✓ Branch 3 taken 29 times.
40185 if (!IS_IDR(s)) {
874 int pos;
875
876 19767 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
877 19767 pos = get_bits_left(gb);
878
2/2
✓ Branch 0 taken 3499 times.
✓ Branch 1 taken 16268 times.
19767 if (!sh->short_term_ref_pic_set_sps_flag) {
879 3499 ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1);
880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3499 times.
3499 if (ret < 0)
881 return ret;
882
883 3499 sh->short_term_rps = &sh->slice_rps;
884 } else {
885 int numbits, rps_idx;
886
887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16268 times.
16268 if (!sps->nb_st_rps) {
888 av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
889 return AVERROR_INVALIDDATA;
890 }
891
892 16268 numbits = av_ceil_log2(sps->nb_st_rps);
893
2/2
✓ Branch 0 taken 16240 times.
✓ Branch 1 taken 28 times.
16268 rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
894 16268 sh->short_term_rps = &sps->st_rps[rps_idx];
895 }
896 19767 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
897
898 19767 pos = get_bits_left(gb);
899 19767 ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb);
900
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19767 times.
19767 if (ret < 0) {
901 av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
902 if (s->avctx->err_recognition & AV_EF_EXPLODE)
903 return AVERROR_INVALIDDATA;
904 }
905 19767 sh->long_term_ref_pic_set_size = pos - get_bits_left(gb);
906
907
2/2
✓ Branch 0 taken 17336 times.
✓ Branch 1 taken 2431 times.
19767 if (sps->temporal_mvp_enabled)
908 17336 sh->slice_temporal_mvp_enabled_flag = get_bits1(gb);
909 else
910 2431 sh->slice_temporal_mvp_enabled_flag = 0;
911 } else {
912 651 sh->poc = 0;
913 651 sh->pic_order_cnt_lsb = 0;
914 651 sh->short_term_ref_pic_set_sps_flag = 0;
915 651 sh->short_term_ref_pic_set_size = 0;
916 651 sh->short_term_rps = NULL;
917 651 sh->long_term_ref_pic_set_size = 0;
918 651 sh->slice_temporal_mvp_enabled_flag = 0;
919 }
920
921 20418 sh->inter_layer_pred = 0;
922
2/2
✓ Branch 0 taken 327 times.
✓ Branch 1 taken 20091 times.
20418 if (s->nuh_layer_id > 0) {
923 327 int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx];
924
925
2/2
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 98 times.
327 if (vps->default_ref_layers_active)
926 229 sh->inter_layer_pred = !!num_direct_ref_layers;
927
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 50 times.
98 else if (num_direct_ref_layers) {
928 48 sh->inter_layer_pred = get_bits1(gb);
929
930
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) {
931 av_log(s->avctx, AV_LOG_ERROR,
932 "NumDirectRefLayers>1 not supported\n");
933 return AVERROR_PATCHWELCOME;
934 }
935 }
936 }
937
938
2/2
✓ Branch 0 taken 16905 times.
✓ Branch 1 taken 3513 times.
20418 if (sps->sao_enabled) {
939 16905 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
940
2/2
✓ Branch 0 taken 16903 times.
✓ Branch 1 taken 2 times.
16905 if (sps->chroma_format_idc) {
941 16903 sh->slice_sample_adaptive_offset_flag[1] =
942 16903 sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb);
943 }
944 } else {
945 3513 sh->slice_sample_adaptive_offset_flag[0] = 0;
946 3513 sh->slice_sample_adaptive_offset_flag[1] = 0;
947 3513 sh->slice_sample_adaptive_offset_flag[2] = 0;
948 }
949
950 20418 sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
951
4/4
✓ Branch 0 taken 16488 times.
✓ Branch 1 taken 3930 times.
✓ Branch 2 taken 15233 times.
✓ Branch 3 taken 1255 times.
20418 if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
952 int nb_refs;
953
954 19163 sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active;
955
2/2
✓ Branch 0 taken 15233 times.
✓ Branch 1 taken 3930 times.
19163 if (sh->slice_type == HEVC_SLICE_B)
956 15233 sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active;
957
958
2/2
✓ Branch 1 taken 4955 times.
✓ Branch 2 taken 14208 times.
19163 if (get_bits1(gb)) { // num_ref_idx_active_override_flag
959 4955 sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1;
960
2/2
✓ Branch 0 taken 2777 times.
✓ Branch 1 taken 2178 times.
4955 if (sh->slice_type == HEVC_SLICE_B)
961 2777 sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1;
962 }
963
2/4
✓ Branch 0 taken 19163 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19163 times.
19163 if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) {
964 av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n",
965 sh->nb_refs[L0], sh->nb_refs[L1]);
966 return AVERROR_INVALIDDATA;
967 }
968
969 19163 sh->rpl_modification_flag[0] = 0;
970 19163 sh->rpl_modification_flag[1] = 0;
971 19163 nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx);
972
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19163 times.
19163 if (!nb_refs) {
973 av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
974 return AVERROR_INVALIDDATA;
975 }
976
977
4/4
✓ Branch 0 taken 1930 times.
✓ Branch 1 taken 17233 times.
✓ Branch 2 taken 1795 times.
✓ Branch 3 taken 135 times.
19163 if (pps->lists_modification_present_flag && nb_refs > 1) {
978 1795 sh->rpl_modification_flag[0] = get_bits1(gb);
979
2/2
✓ Branch 0 taken 1249 times.
✓ Branch 1 taken 546 times.
1795 if (sh->rpl_modification_flag[0]) {
980
2/2
✓ Branch 0 taken 3000 times.
✓ Branch 1 taken 1249 times.
4249 for (i = 0; i < sh->nb_refs[L0]; i++)
981 3000 sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs));
982 }
983
984
1/2
✓ Branch 0 taken 1795 times.
✗ Branch 1 not taken.
1795 if (sh->slice_type == HEVC_SLICE_B) {
985 1795 sh->rpl_modification_flag[1] = get_bits1(gb);
986
2/2
✓ Branch 0 taken 652 times.
✓ Branch 1 taken 1143 times.
1795 if (sh->rpl_modification_flag[1] == 1)
987
2/2
✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
2207 for (i = 0; i < sh->nb_refs[L1]; i++)
988 1555 sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs));
989 }
990 }
991
992
2/2
✓ Branch 0 taken 15233 times.
✓ Branch 1 taken 3930 times.
19163 if (sh->slice_type == HEVC_SLICE_B)
993 15233 sh->mvd_l1_zero_flag = get_bits1(gb);
994
995
2/2
✓ Branch 0 taken 16314 times.
✓ Branch 1 taken 2849 times.
19163 if (pps->cabac_init_present_flag)
996 16314 sh->cabac_init_flag = get_bits1(gb);
997 else
998 2849 sh->cabac_init_flag = 0;
999
1000 19163 sh->collocated_ref_idx = 0;
1001
2/2
✓ Branch 0 taken 16688 times.
✓ Branch 1 taken 2475 times.
19163 if (sh->slice_temporal_mvp_enabled_flag) {
1002 16688 sh->collocated_list = L0;
1003
2/2
✓ Branch 0 taken 14699 times.
✓ Branch 1 taken 1989 times.
16688 if (sh->slice_type == HEVC_SLICE_B)
1004 14699 sh->collocated_list = !get_bits1(gb);
1005
1006
2/2
✓ Branch 0 taken 14829 times.
✓ Branch 1 taken 1859 times.
16688 if (sh->nb_refs[sh->collocated_list] > 1) {
1007 14829 sh->collocated_ref_idx = get_ue_golomb_long(gb);
1008
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14829 times.
14829 if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) {
1009 av_log(s->avctx, AV_LOG_ERROR,
1010 "Invalid collocated_ref_idx: %d.\n",
1011 sh->collocated_ref_idx);
1012 return AVERROR_INVALIDDATA;
1013 }
1014 }
1015 }
1016
1017
4/4
✓ Branch 0 taken 1468 times.
✓ Branch 1 taken 17695 times.
✓ Branch 2 taken 693 times.
✓ Branch 3 taken 775 times.
19163 if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
1018
3/4
✓ Branch 0 taken 668 times.
✓ Branch 1 taken 17720 times.
✓ Branch 2 taken 668 times.
✗ Branch 3 not taken.
18388 (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
1019 1443 int ret = pred_weight_table(sh, s->avctx, sps, gb);
1020
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1443 times.
1443 if (ret < 0)
1021 return ret;
1022 }
1023
1024 19163 sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
1025
2/4
✓ Branch 0 taken 19163 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19163 times.
19163 if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
1026 av_log(s->avctx, AV_LOG_ERROR,
1027 "Invalid number of merging MVP candidates: %d.\n",
1028 sh->max_num_merge_cand);
1029 return AVERROR_INVALIDDATA;
1030 }
1031
1032 // Syntax in 7.3.6.1
1033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19163 times.
19163 if (sps->motion_vector_resolution_control_idc == 2)
1034 sh->use_integer_mv_flag = get_bits1(gb);
1035 else
1036 // Inferred to be equal to motion_vector_resolution_control_idc if not present
1037 19163 sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc;
1038
1039 }
1040
1041 20418 sh->slice_qp_delta = get_se_golomb(gb);
1042
1043
2/2
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 20147 times.
20418 if (pps->pic_slice_level_chroma_qp_offsets_present_flag) {
1044 271 sh->slice_cb_qp_offset = get_se_golomb(gb);
1045 271 sh->slice_cr_qp_offset = get_se_golomb(gb);
1046
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 ||
1047
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) {
1048 av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n");
1049 return AVERROR_INVALIDDATA;
1050 }
1051 } else {
1052 20147 sh->slice_cb_qp_offset = 0;
1053 20147 sh->slice_cr_qp_offset = 0;
1054 }
1055
1056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20418 times.
20418 if (pps->pps_slice_act_qp_offsets_present_flag) {
1057 sh->slice_act_y_qp_offset = get_se_golomb(gb);
1058 sh->slice_act_cb_qp_offset = get_se_golomb(gb);
1059 sh->slice_act_cr_qp_offset = get_se_golomb(gb);
1060 }
1061
1062
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 20375 times.
20418 if (pps->chroma_qp_offset_list_enabled_flag)
1063 43 sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
1064 else
1065 20375 sh->cu_chroma_qp_offset_enabled_flag = 0;
1066
1067
2/2
✓ Branch 0 taken 3063 times.
✓ Branch 1 taken 17355 times.
20418 if (pps->deblocking_filter_control_present_flag) {
1068 3063 int deblocking_filter_override_flag = 0;
1069
1070
2/2
✓ Branch 0 taken 696 times.
✓ Branch 1 taken 2367 times.
3063 if (pps->deblocking_filter_override_enabled_flag)
1071 696 deblocking_filter_override_flag = get_bits1(gb);
1072
1073
2/2
✓ Branch 0 taken 477 times.
✓ Branch 1 taken 2586 times.
3063 if (deblocking_filter_override_flag) {
1074 477 sh->disable_deblocking_filter_flag = get_bits1(gb);
1075
2/2
✓ Branch 0 taken 357 times.
✓ Branch 1 taken 120 times.
477 if (!sh->disable_deblocking_filter_flag) {
1076 357 int beta_offset_div2 = get_se_golomb(gb);
1077 357 int tc_offset_div2 = get_se_golomb(gb) ;
1078
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 ||
1079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 357 times.
357 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1080 av_log(s->avctx, AV_LOG_ERROR,
1081 "Invalid deblock filter offsets: %d, %d\n",
1082 beta_offset_div2, tc_offset_div2);
1083 return AVERROR_INVALIDDATA;
1084 }
1085 357 sh->beta_offset = beta_offset_div2 * 2;
1086 357 sh->tc_offset = tc_offset_div2 * 2;
1087 }
1088 } else {
1089 2586 sh->disable_deblocking_filter_flag = pps->disable_dbf;
1090 2586 sh->beta_offset = pps->beta_offset;
1091 2586 sh->tc_offset = pps->tc_offset;
1092 }
1093 } else {
1094 17355 sh->disable_deblocking_filter_flag = 0;
1095 17355 sh->beta_offset = 0;
1096 17355 sh->tc_offset = 0;
1097 }
1098
1099
2/2
✓ Branch 0 taken 17750 times.
✓ Branch 1 taken 2668 times.
20418 if (pps->seq_loop_filter_across_slices_enabled_flag &&
1100
2/2
✓ Branch 0 taken 11732 times.
✓ Branch 1 taken 6018 times.
17750 (sh->slice_sample_adaptive_offset_flag[0] ||
1101
2/2
✓ Branch 0 taken 11714 times.
✓ Branch 1 taken 18 times.
11732 sh->slice_sample_adaptive_offset_flag[1] ||
1102
2/2
✓ Branch 0 taken 11651 times.
✓ Branch 1 taken 63 times.
11714 !sh->disable_deblocking_filter_flag)) {
1103 17687 sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb);
1104 } else {
1105 2731 sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag;
1106 }
1107 }
1108
1109 28365 sh->num_entry_point_offsets = 0;
1110
4/4
✓ Branch 0 taken 25450 times.
✓ Branch 1 taken 2915 times.
✓ Branch 2 taken 4737 times.
✓ Branch 3 taken 20713 times.
28365 if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1111 7652 unsigned num_entry_point_offsets = get_ue_golomb_long(gb);
1112 // It would be possible to bound this tighter but this here is simpler
1113
2/4
✓ Branch 1 taken 7652 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 7652 times.
7652 if (num_entry_point_offsets > get_bits_left(gb) || num_entry_point_offsets > UINT16_MAX) {
1114 av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
1115 return AVERROR_INVALIDDATA;
1116 }
1117
1118 7652 sh->num_entry_point_offsets = num_entry_point_offsets;
1119
2/2
✓ Branch 0 taken 2174 times.
✓ Branch 1 taken 5478 times.
7652 if (sh->num_entry_point_offsets > 0) {
1120 2174 int offset_len = get_ue_golomb_long(gb) + 1;
1121
1122
2/4
✓ Branch 0 taken 2174 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2174 times.
2174 if (offset_len < 1 || offset_len > 32) {
1123 sh->num_entry_point_offsets = 0;
1124 av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len);
1125 return AVERROR_INVALIDDATA;
1126 }
1127
1128 2174 av_freep(&sh->entry_point_offset);
1129 2174 av_freep(&sh->offset);
1130 2174 av_freep(&sh->size);
1131 2174 sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
1132 2174 sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1133 2174 sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1134
3/6
✓ Branch 0 taken 2174 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2174 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2174 times.
2174 if (!sh->entry_point_offset || !sh->offset || !sh->size) {
1135 sh->num_entry_point_offsets = 0;
1136 av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
1137 return AVERROR(ENOMEM);
1138 }
1139
2/2
✓ Branch 0 taken 9742 times.
✓ Branch 1 taken 2174 times.
11916 for (i = 0; i < sh->num_entry_point_offsets; i++) {
1140 9742 unsigned val = get_bits_long(gb, offset_len);
1141 9742 sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
1142 }
1143 }
1144 }
1145
1146
2/2
✓ Branch 0 taken 2769 times.
✓ Branch 1 taken 25596 times.
28365 if (pps->slice_header_extension_present_flag) {
1147 2769 unsigned int length = get_ue_golomb_long(gb);
1148
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2769 times.
2769 if (length*8LL > get_bits_left(gb)) {
1149 av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n");
1150 return AVERROR_INVALIDDATA;
1151 }
1152
2/2
✓ Branch 0 taken 20292 times.
✓ Branch 1 taken 2769 times.
23061 for (i = 0; i < length; i++)
1153 20292 skip_bits(gb, 8); // slice_header_extension_data_byte
1154 }
1155
1156 28365 ret = get_bits1(gb);
1157
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28365 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
28365 if (!ret && get_bits_left(gb) >= 0) {
1158 av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n");
1159 return AVERROR_INVALIDDATA;
1160 }
1161 28365 sh->data_offset = align_get_bits(gb) - gb->buffer;
1162
1163
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28365 times.
28365 if (get_bits_left(gb) < 0) {
1164 av_log(s->avctx, AV_LOG_ERROR,
1165 "Overread slice header by %d bits\n", -get_bits_left(gb));
1166 return AVERROR_INVALIDDATA;
1167 }
1168
1169 // Inferred parameters
1170 28365 sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta;
1171
1/2
✓ Branch 0 taken 28365 times.
✗ Branch 1 not taken.
28365 if (sh->slice_qp > 51 ||
1172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28365 times.
28365 sh->slice_qp < -sps->qp_bd_offset) {
1173 av_log(s->avctx, AV_LOG_ERROR,
1174 "The slice_qp %d is outside the valid range "
1175 "[%d, 51].\n",
1176 sh->slice_qp,
1177 -sps->qp_bd_offset);
1178 return AVERROR_INVALIDDATA;
1179 }
1180
1181 28365 sh->slice_ctb_addr_rs = sh->slice_segment_addr;
1182
1183
2/2
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20418 times.
28365 if (sh->dependent_slice_segment_flag &&
1184
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])) {
1185 av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
1186 return AVERROR_INVALIDDATA;
1187 }
1188
1189 28365 return 0;
1190 }
1191
1192 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
1193
1194 #define SET_SAO(elem, value) \
1195 do { \
1196 if (!sao_merge_up_flag && !sao_merge_left_flag) \
1197 sao->elem = value; \
1198 else if (sao_merge_left_flag) \
1199 sao->elem = CTB(l->sao, rx-1, ry).elem; \
1200 else if (sao_merge_up_flag) \
1201 sao->elem = CTB(l->sao, rx, ry-1).elem; \
1202 else \
1203 sao->elem = 0; \
1204 } while (0)
1205
1206 1596780 static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l,
1207 const HEVCPPS *pps, const HEVCSPS *sps,
1208 int rx, int ry)
1209 {
1210 1596780 const HEVCContext *const s = lc->parent;
1211 1596780 int sao_merge_left_flag = 0;
1212 1596780 int sao_merge_up_flag = 0;
1213 1596780 SAOParams *sao = &CTB(l->sao, rx, ry);
1214 int c_idx, i;
1215
1216
2/2
✓ Branch 0 taken 863042 times.
✓ Branch 1 taken 733738 times.
1596780 if (s->sh.slice_sample_adaptive_offset_flag[0] ||
1217
2/2
✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 861398 times.
863042 s->sh.slice_sample_adaptive_offset_flag[1]) {
1218
2/2
✓ Branch 0 taken 698437 times.
✓ Branch 1 taken 36945 times.
735382 if (rx > 0) {
1219
2/2
✓ Branch 0 taken 689856 times.
✓ Branch 1 taken 8581 times.
698437 if (lc->ctb_left_flag)
1220 689856 sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc);
1221 }
1222
4/4
✓ Branch 0 taken 676057 times.
✓ Branch 1 taken 59325 times.
✓ Branch 2 taken 354107 times.
✓ Branch 3 taken 321950 times.
735382 if (ry > 0 && !sao_merge_left_flag) {
1223
2/2
✓ Branch 0 taken 340738 times.
✓ Branch 1 taken 13369 times.
354107 if (lc->ctb_up_flag)
1224 340738 sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc);
1225 }
1226 }
1227
1228
4/4
✓ Branch 0 taken 6386928 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4790244 times.
✓ Branch 3 taken 1596780 times.
6387024 for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) {
1229
2/2
✓ Branch 0 taken 1596780 times.
✓ Branch 1 taken 3193464 times.
4790244 int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma :
1230 3193464 pps->log2_sao_offset_scale_chroma;
1231
1232
2/2
✓ Branch 0 taken 3133126 times.
✓ Branch 1 taken 1657118 times.
4790244 if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1233 3133126 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
1234 3133126 continue;
1235 }
1236
1237
2/2
✓ Branch 0 taken 461690 times.
✓ Branch 1 taken 1195428 times.
1657118 if (c_idx == 2) {
1238 461690 sao->type_idx[2] = sao->type_idx[1];
1239 461690 sao->eo_class[2] = sao->eo_class[1];
1240 } else {
1241
7/8
✓ Branch 0 taken 1053212 times.
✓ Branch 1 taken 142216 times.
✓ Branch 2 taken 520925 times.
✓ Branch 3 taken 532287 times.
✓ Branch 5 taken 532287 times.
✓ Branch 6 taken 142216 times.
✓ Branch 7 taken 142216 times.
✗ Branch 8 not taken.
1195428 SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc));
1242 }
1243
1244
2/2
✓ Branch 0 taken 1110448 times.
✓ Branch 1 taken 546670 times.
1657118 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
1245 1110448 continue;
1246
1247
2/2
✓ Branch 0 taken 2186680 times.
✓ Branch 1 taken 546670 times.
2733350 for (i = 0; i < 4; i++)
1248
7/8
✓ Branch 0 taken 1799848 times.
✓ Branch 1 taken 386832 times.
✓ Branch 2 taken 923876 times.
✓ Branch 3 taken 875972 times.
✓ Branch 5 taken 875972 times.
✓ Branch 6 taken 386832 times.
✓ Branch 7 taken 386832 times.
✗ Branch 8 not taken.
2186680 SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth));
1249
1250
2/2
✓ Branch 0 taken 121010 times.
✓ Branch 1 taken 425660 times.
546670 if (sao->type_idx[c_idx] == SAO_BAND) {
1251
2/2
✓ Branch 0 taken 484040 times.
✓ Branch 1 taken 121010 times.
605050 for (i = 0; i < 4; i++) {
1252
2/2
✓ Branch 0 taken 361637 times.
✓ Branch 1 taken 122403 times.
484040 if (sao->offset_abs[c_idx][i]) {
1253
7/8
✓ Branch 0 taken 335647 times.
✓ Branch 1 taken 25990 times.
✓ Branch 2 taken 247932 times.
✓ Branch 3 taken 87715 times.
✓ Branch 5 taken 87715 times.
✓ Branch 6 taken 25990 times.
✓ Branch 7 taken 25990 times.
✗ Branch 8 not taken.
361637 SET_SAO(offset_sign[c_idx][i],
1254 ff_hevc_sao_offset_sign_decode(lc));
1255 } else {
1256 122403 sao->offset_sign[c_idx][i] = 0;
1257 }
1258 }
1259
7/8
✓ Branch 0 taken 110503 times.
✓ Branch 1 taken 10507 times.
✓ Branch 2 taken 79988 times.
✓ Branch 3 taken 30515 times.
✓ Branch 5 taken 30515 times.
✓ Branch 6 taken 10507 times.
✓ Branch 7 taken 10507 times.
✗ Branch 8 not taken.
121010 SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc));
1260
2/2
✓ Branch 0 taken 342933 times.
✓ Branch 1 taken 82727 times.
425660 } else if (c_idx != 2) {
1261
7/8
✓ Branch 0 taken 273417 times.
✓ Branch 1 taken 69516 times.
✓ Branch 2 taken 117878 times.
✓ Branch 3 taken 155539 times.
✓ Branch 5 taken 155539 times.
✓ Branch 6 taken 69516 times.
✓ Branch 7 taken 69516 times.
✗ Branch 8 not taken.
342933 SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc));
1262 }
1263
1264 // Inferred parameters
1265 546670 sao->offset_val[c_idx][0] = 0;
1266
2/2
✓ Branch 0 taken 2186680 times.
✓ Branch 1 taken 546670 times.
2733350 for (i = 0; i < 4; i++) {
1267 2186680 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
1268
2/2
✓ Branch 0 taken 1702640 times.
✓ Branch 1 taken 484040 times.
2186680 if (sao->type_idx[c_idx] == SAO_EDGE) {
1269
2/2
✓ Branch 0 taken 851320 times.
✓ Branch 1 taken 851320 times.
1702640 if (i > 1)
1270 851320 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1271
2/2
✓ Branch 0 taken 159844 times.
✓ Branch 1 taken 324196 times.
484040 } else if (sao->offset_sign[c_idx][i]) {
1272 159844 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1273 }
1274 2186680 sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale;
1275 }
1276 }
1277 1596780 }
1278
1279 #undef SET_SAO
1280 #undef CTB
1281
1282 384850 static int hls_cross_component_pred(HEVCLocalContext *lc, int idx)
1283 {
1284 384850 int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx);
1285
1286
2/2
✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
384850 if (log2_res_scale_abs_plus1 != 0) {
1287 235843 int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx);
1288 235843 lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) *
1289 235843 (1 - 2 * res_scale_sign_flag);
1290 } else {
1291 149007 lc->tu.res_scale_val = 0;
1292 }
1293
1294
1295 384850 return 0;
1296 }
1297
1298 16526543 static int hls_transform_unit(HEVCLocalContext *lc,
1299 const HEVCLayerContext *l,
1300 const HEVCPPS *pps, const HEVCSPS *sps,
1301 int x0, int y0,
1302 int xBase, int yBase, int cb_xBase, int cb_yBase,
1303 int log2_cb_size, int log2_trafo_size,
1304 int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
1305 {
1306 16526543 const HEVCContext *const s = lc->parent;
1307 16526543 const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1];
1308 int i;
1309
1310
2/2
✓ Branch 0 taken 10532934 times.
✓ Branch 1 taken 5993609 times.
16526543 if (lc->cu.pred_mode == MODE_INTRA) {
1311 10532934 int trafo_size = 1 << log2_trafo_size;
1312 10532934 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size);
1313
1314 10532934 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0);
1315 }
1316
1317
6/6
✓ Branch 0 taken 5973673 times.
✓ Branch 1 taken 10552870 times.
✓ Branch 2 taken 5314021 times.
✓ Branch 3 taken 659652 times.
✓ Branch 4 taken 4862567 times.
✓ Branch 5 taken 451454 times.
16526543 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1318
6/6
✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4706800 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
16588357 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1319 11725791 int scan_idx = SCAN_DIAG;
1320 11725791 int scan_idx_c = SCAN_DIAG;
1321
4/4
✓ Branch 0 taken 7921091 times.
✓ Branch 1 taken 3804700 times.
✓ Branch 2 taken 6336384 times.
✓ Branch 3 taken 1584707 times.
18062175 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1322
2/2
✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 6104674 times.
6336384 (sps->chroma_format_idc == 2 &&
1323
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]));
1324
1325
4/4
✓ Branch 0 taken 2398030 times.
✓ Branch 1 taken 9327761 times.
✓ Branch 2 taken 710974 times.
✓ Branch 3 taken 1687056 times.
11725791 if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
1326 710974 lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc);
1327
2/2
✓ Branch 0 taken 391160 times.
✓ Branch 1 taken 319814 times.
710974 if (lc->tu.cu_qp_delta != 0)
1328
2/2
✓ Branch 1 taken 215797 times.
✓ Branch 2 taken 175363 times.
391160 if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1)
1329 215797 lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1330 710974 lc->tu.is_cu_qp_delta_coded = 1;
1331
1332
2/2
✓ Branch 0 taken 710973 times.
✓ Branch 1 taken 1 times.
710974 if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) ||
1333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 710973 times.
710973 lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) {
1334 1 av_log(s->avctx, AV_LOG_ERROR,
1335 "The cu_qp_delta %d is outside the valid range "
1336 "[%d, %d].\n",
1337 lc->tu.cu_qp_delta,
1338 1 -(26 + sps->qp_bd_offset / 2),
1339 1 (25 + sps->qp_bd_offset / 2));
1340 1 return AVERROR_INVALIDDATA;
1341 }
1342
1343 710973 ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size);
1344 }
1345
1346
4/4
✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 10833839 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
11725790 if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1347
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) {
1348 266275 int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc);
1349
2/2
✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
266275 if (cu_chroma_qp_offset_flag) {
1350 48966 int cu_chroma_qp_offset_idx = 0;
1351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
48966 if (pps->chroma_qp_offset_list_len_minus1 > 0) {
1352 cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1);
1353 av_log(s->avctx, AV_LOG_ERROR,
1354 "cu_chroma_qp_offset_idx not yet tested.\n");
1355 }
1356 48966 lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
1357 48966 lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
1358 } else {
1359 217309 lc->tu.cu_qp_offset_cb = 0;
1360 217309 lc->tu.cu_qp_offset_cr = 0;
1361 }
1362 266275 lc->tu.is_cu_chroma_qp_offset_coded = 1;
1363 }
1364
1365
4/4
✓ Branch 0 taken 7758416 times.
✓ Branch 1 taken 3967374 times.
✓ Branch 2 taken 6742720 times.
✓ Branch 3 taken 1015696 times.
11725790 if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1366
2/2
✓ Branch 0 taken 4480422 times.
✓ Branch 1 taken 2262298 times.
6742720 if (lc->tu.intra_pred_mode >= 6 &&
1367
2/2
✓ Branch 0 taken 1611999 times.
✓ Branch 1 taken 2868423 times.
4480422 lc->tu.intra_pred_mode <= 14) {
1368 1611999 scan_idx = SCAN_VERT;
1369
2/2
✓ Branch 0 taken 2215732 times.
✓ Branch 1 taken 2914989 times.
5130721 } else if (lc->tu.intra_pred_mode >= 22 &&
1370
2/2
✓ Branch 0 taken 1866400 times.
✓ Branch 1 taken 349332 times.
2215732 lc->tu.intra_pred_mode <= 30) {
1371 1866400 scan_idx = SCAN_HORIZ;
1372 }
1373
1374
2/2
✓ Branch 0 taken 4021518 times.
✓ Branch 1 taken 2721202 times.
6742720 if (lc->tu.intra_pred_mode_c >= 6 &&
1375
2/2
✓ Branch 0 taken 1517305 times.
✓ Branch 1 taken 2504213 times.
4021518 lc->tu.intra_pred_mode_c <= 14) {
1376 1517305 scan_idx_c = SCAN_VERT;
1377
2/2
✓ Branch 0 taken 2103790 times.
✓ Branch 1 taken 3121625 times.
5225415 } else if (lc->tu.intra_pred_mode_c >= 22 &&
1378
2/2
✓ Branch 0 taken 1763664 times.
✓ Branch 1 taken 340126 times.
2103790 lc->tu.intra_pred_mode_c <= 30) {
1379 1763664 scan_idx_c = SCAN_HORIZ;
1380 }
1381 }
1382
1383 11725790 lc->tu.cross_pf = 0;
1384
1385
2/2
✓ Branch 0 taken 10552869 times.
✓ Branch 1 taken 1172921 times.
11725790 if (cbf_luma)
1386 10552869 ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0);
1387
6/6
✓ Branch 0 taken 11725598 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6491799 times.
✓ Branch 3 taken 5233799 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 6282236 times.
17169152 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1388 5443362 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1389 5443362 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1390
4/4
✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 5106521 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
5661178 lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma &&
1391
2/2
✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
217816 (lc->cu.pred_mode == MODE_INTER ||
1392
2/2
✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
168873 (lc->tu.chroma_mode_c == 4)));
1393
1394
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5250937 times.
5443362 if (lc->tu.cross_pf) {
1395 192425 hls_cross_component_pred(lc, 0);
1396 }
1397
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9980320 times.
✓ Branch 2 taken 5896564 times.
✓ Branch 3 taken 5443362 times.
11339926 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1398
2/2
✓ Branch 0 taken 3291464 times.
✓ Branch 1 taken 2605100 times.
5896564 if (lc->cu.pred_mode == MODE_INTRA) {
1399 3291464 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1400 3291464 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1401 3291464 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1);
1402 }
1403
2/2
✓ Branch 0 taken 1592416 times.
✓ Branch 1 taken 4304148 times.
5896564 if (cbf_cb[i])
1404 1592416 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1405 log2_trafo_size_c, scan_idx_c, 1);
1406 else
1407
2/2
✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 4264490 times.
4304148 if (lc->tu.cross_pf) {
1408 39658 ptrdiff_t stride = s->cur_frame->f->linesize[1];
1409 39658 int hshift = sps->hshift[1];
1410 39658 int vshift = sps->vshift[1];
1411 39658 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1412 39658 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1413 39658 int size = 1 << log2_trafo_size_c;
1414
1415 39658 uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride +
1416 39658 ((x0 >> hshift) << sps->pixel_shift)];
1417
2/2
✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
1871162 for (i = 0; i < (size * size); i++) {
1418 1831504 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1419 }
1420 39658 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1421 }
1422 }
1423
1424
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5250937 times.
5443362 if (lc->tu.cross_pf) {
1425 192425 hls_cross_component_pred(lc, 1);
1426 }
1427
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9980320 times.
✓ Branch 2 taken 5896564 times.
✓ Branch 3 taken 5443362 times.
11339926 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1428
2/2
✓ Branch 0 taken 3291464 times.
✓ Branch 1 taken 2605100 times.
5896564 if (lc->cu.pred_mode == MODE_INTRA) {
1429 3291464 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1430 3291464 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1431 3291464 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2);
1432 }
1433
2/2
✓ Branch 0 taken 1737170 times.
✓ Branch 1 taken 4159394 times.
5896564 if (cbf_cr[i])
1434 1737170 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1435 log2_trafo_size_c, scan_idx_c, 2);
1436 else
1437
2/2
✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 4083470 times.
4159394 if (lc->tu.cross_pf) {
1438 75924 ptrdiff_t stride = s->cur_frame->f->linesize[2];
1439 75924 int hshift = sps->hshift[2];
1440 75924 int vshift = sps->vshift[2];
1441 75924 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1442 75924 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1443 75924 int size = 1 << log2_trafo_size_c;
1444
1445 75924 uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride +
1446 75924 ((x0 >> hshift) << sps->pixel_shift)];
1447
2/2
✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
3691476 for (i = 0; i < (size * size); i++) {
1448 3615552 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1449 }
1450 75924 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1451 }
1452 }
1453
4/4
✓ Branch 0 taken 6282236 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1616165 times.
✓ Branch 3 taken 4666071 times.
6282428 } else if (sps->chroma_format_idc && blk_idx == 3) {
1454 1616165 int trafo_size_h = 1 << (log2_trafo_size + 1);
1455 1616165 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1456
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2898592 times.
✓ Branch 2 taken 1783034 times.
✓ Branch 3 taken 1616165 times.
3399199 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1457
2/2
✓ Branch 0 taken 1283944 times.
✓ Branch 1 taken 499090 times.
1783034 if (lc->cu.pred_mode == MODE_INTRA) {
1458 1283944 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1459 1283944 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1460 1283944 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1);
1461 }
1462
2/2
✓ Branch 0 taken 667665 times.
✓ Branch 1 taken 1115369 times.
1783034 if (cbf_cb[i])
1463 667665 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1464 log2_trafo_size, scan_idx_c, 1);
1465 }
1466
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2898592 times.
✓ Branch 2 taken 1783034 times.
✓ Branch 3 taken 1616165 times.
3399199 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1467
2/2
✓ Branch 0 taken 1283944 times.
✓ Branch 1 taken 499090 times.
1783034 if (lc->cu.pred_mode == MODE_INTRA) {
1468 1283944 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1469 1283944 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1470 1283944 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2);
1471 }
1472
2/2
✓ Branch 0 taken 756279 times.
✓ Branch 1 taken 1026755 times.
1783034 if (cbf_cr[i])
1473 756279 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1474 log2_trafo_size, scan_idx_c, 2);
1475 }
1476 }
1477
3/4
✓ Branch 0 taken 4800752 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2774517 times.
✓ Branch 3 taken 2026235 times.
4800752 } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
1478
4/4
✓ Branch 0 taken 1700362 times.
✓ Branch 1 taken 1074155 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1639774 times.
3909260 if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) {
1479 1134743 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1480 1134743 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1481 1134743 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
1482 1134743 sps->log2_ctb_size);
1483 1134743 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1);
1484 1134743 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2);
1485
2/2
✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 1122276 times.
1134743 if (sps->chroma_format_idc == 2) {
1486 12467 ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c),
1487 12467 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1488 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1);
1489 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2);
1490 }
1491
2/2
✓ Branch 0 taken 370285 times.
✓ Branch 1 taken 1269489 times.
1639774 } else if (blk_idx == 3) {
1492 370285 int trafo_size_h = 1 << (log2_trafo_size + 1);
1493 370285 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1494 370285 ff_hevc_set_neighbour_available(lc, xBase, yBase,
1495 370285 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1496 370285 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1);
1497 370285 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2);
1498
2/2
✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 366089 times.
370285 if (sps->chroma_format_idc == 2) {
1499 4196 ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size),
1500 4196 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1501 4196 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1);
1502 4196 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2);
1503 }
1504 }
1505 }
1506
1507 16526542 return 0;
1508 }
1509
1510 403332 static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps,
1511 int x0, int y0, int log2_cb_size)
1512 {
1513 403332 int cb_size = 1 << log2_cb_size;
1514 403332 int log2_min_pu_size = sps->log2_min_pu_size;
1515
1516 403332 int min_pu_width = sps->min_pu_width;
1517 403332 int x_end = FFMIN(x0 + cb_size, sps->width);
1518 403332 int y_end = FFMIN(y0 + cb_size, sps->height);
1519 int i, j;
1520
1521
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++)
1522
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++)
1523 1073856 is_pcm[i + j * min_pu_width] = 2;
1524 403332 }
1525
1526 19918575 static int hls_transform_tree(HEVCLocalContext *lc,
1527 const HEVCLayerContext *l,
1528 const HEVCPPS *pps, const HEVCSPS *sps,
1529 int x0, int y0,
1530 int xBase, int yBase, int cb_xBase, int cb_yBase,
1531 int log2_cb_size, int log2_trafo_size,
1532 int trafo_depth, int blk_idx,
1533 const int *base_cbf_cb, const int *base_cbf_cr)
1534 {
1535 19918575 const HEVCContext *const s = lc->parent;
1536 uint8_t split_transform_flag;
1537 int cbf_cb[2];
1538 int cbf_cr[2];
1539 int ret;
1540
1541 19918575 cbf_cb[0] = base_cbf_cb[0];
1542 19918575 cbf_cb[1] = base_cbf_cb[1];
1543 19918575 cbf_cr[0] = base_cbf_cr[0];
1544 19918575 cbf_cr[1] = base_cbf_cr[1];
1545
1546
2/2
✓ Branch 0 taken 6863478 times.
✓ Branch 1 taken 13055097 times.
19918575 if (lc->cu.intra_split_flag) {
1547
2/2
✓ Branch 0 taken 5135160 times.
✓ Branch 1 taken 1728318 times.
6863478 if (trafo_depth == 1) {
1548 5135160 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1549
2/2
✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4999756 times.
5135160 if (sps->chroma_format_idc == 3) {
1550 135404 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx];
1551 135404 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx];
1552 } else {
1553 4999756 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1554 4999756 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1555 }
1556 }
1557 } else {
1558 13055097 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0];
1559 13055097 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1560 13055097 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1561 }
1562
1563
2/2
✓ Branch 0 taken 19794202 times.
✓ Branch 1 taken 124373 times.
19918575 if (log2_trafo_size <= sps->log2_max_trafo_size &&
1564
2/2
✓ Branch 0 taken 10511538 times.
✓ Branch 1 taken 9282664 times.
19794202 log2_trafo_size > sps->log2_min_tb_size &&
1565
2/2
✓ Branch 0 taken 8867536 times.
✓ Branch 1 taken 1644002 times.
10511538 trafo_depth < lc->cu.max_trafo_depth &&
1566
4/4
✓ Branch 0 taken 1860543 times.
✓ Branch 1 taken 7006993 times.
✓ Branch 2 taken 584140 times.
✓ Branch 3 taken 1276403 times.
8867536 !(lc->cu.intra_split_flag && trafo_depth == 0)) {
1567 7591133 split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size);
1568 } else {
1569 26389049 int inter_split = sps->max_transform_hierarchy_depth_inter == 0 &&
1570
2/2
✓ Branch 0 taken 836848 times.
✓ Branch 1 taken 897317 times.
1734165 lc->cu.pred_mode == MODE_INTER &&
1571
6/6
✓ Branch 0 taken 1734165 times.
✓ Branch 1 taken 10593277 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 161299 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
14061607 lc->cu.part_mode != PART_2Nx2N &&
1572 trafo_depth == 0;
1573
1574 12327442 split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size ||
1575
8/8
✓ Branch 0 taken 12203069 times.
✓ Branch 1 taken 124373 times.
✓ Branch 2 taken 6271291 times.
✓ Branch 3 taken 5931778 times.
✓ Branch 4 taken 4994888 times.
✓ Branch 5 taken 1276403 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10808028 times.
12327442 (lc->cu.intra_split_flag && trafo_depth == 0) ||
1576 inter_split;
1577 }
1578
1579
6/6
✓ Branch 0 taken 19918383 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 9154584 times.
✓ Branch 3 taken 10763799 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8840168 times.
19918575 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1580
4/4
✓ Branch 0 taken 4727960 times.
✓ Branch 1 taken 6350255 times.
✓ Branch 2 taken 1300072 times.
✓ Branch 3 taken 3427888 times.
11078215 if (trafo_depth == 0 || cbf_cb[0]) {
1581 7650327 cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1582
6/6
✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 7052061 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
7650327 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1583 526996 cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1584 }
1585 }
1586
1587
4/4
✓ Branch 0 taken 4727960 times.
✓ Branch 1 taken 6350255 times.
✓ Branch 2 taken 1247448 times.
✓ Branch 3 taken 3480512 times.
11078215 if (trafo_depth == 0 || cbf_cr[0]) {
1588 7597703 cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1589
6/6
✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6852397 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
7597703 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1590 661961 cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1591 }
1592 }
1593 }
1594
1595
2/2
✓ Branch 0 taken 3392032 times.
✓ Branch 1 taken 16526543 times.
19918575 if (split_transform_flag) {
1596 3392032 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1597 3392032 const int x1 = x0 + trafo_size_split;
1598 3392032 const int y1 = y0 + trafo_size_split;
1599
1600 #define SUBDIVIDE(x, y, idx) \
1601 do { \
1602 ret = hls_transform_tree(lc, l, pps, sps, \
1603 x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1604 log2_trafo_size - 1, trafo_depth + 1, idx, \
1605 cbf_cb, cbf_cr); \
1606 if (ret < 0) \
1607 return ret; \
1608 } while (0)
1609
1610
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3392032 times.
3392032 SUBDIVIDE(x0, y0, 0);
1611
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3392032 times.
3392032 SUBDIVIDE(x1, y0, 1);
1612
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3392032 times.
3392032 SUBDIVIDE(x0, y1, 2);
1613
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3392032 times.
3392032 SUBDIVIDE(x1, y1, 3);
1614
1615 #undef SUBDIVIDE
1616 } else {
1617 16526543 int min_tu_size = 1 << sps->log2_min_tb_size;
1618 16526543 int log2_min_tu_size = sps->log2_min_tb_size;
1619 16526543 int min_tu_width = sps->min_tb_width;
1620 16526543 int cbf_luma = 1;
1621
1622
4/4
✓ Branch 0 taken 5993609 times.
✓ Branch 1 taken 10532934 times.
✓ Branch 2 taken 1128650 times.
✓ Branch 3 taken 4864959 times.
16526543 if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1623
4/4
✓ Branch 0 taken 927242 times.
✓ Branch 1 taken 201408 times.
✓ Branch 2 taken 793279 times.
✓ Branch 3 taken 133963 times.
1128650 cbf_cb[0] || cbf_cr[0] ||
1624
6/6
✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 768603 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
793279 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1625 15745910 cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth);
1626 }
1627
1628 16526543 ret = hls_transform_unit(lc, l, pps, sps,
1629 x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1630 log2_cb_size, log2_trafo_size,
1631 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1632
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16526542 times.
16526543 if (ret < 0)
1633 1 return ret;
1634 // TODO: store cbf_luma somewhere else
1635
2/2
✓ Branch 0 taken 10552869 times.
✓ Branch 1 taken 5973673 times.
16526542 if (cbf_luma) {
1636 int i, j;
1637
2/2
✓ Branch 0 taken 22263498 times.
✓ Branch 1 taken 10552869 times.
32816367 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1638
2/2
✓ Branch 0 taken 83176764 times.
✓ Branch 1 taken 22263498 times.
105440262 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1639 83176764 int x_tu = (x0 + j) >> log2_min_tu_size;
1640 83176764 int y_tu = (y0 + i) >> log2_min_tu_size;
1641 83176764 l->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1642 }
1643 }
1644
2/2
✓ Branch 0 taken 15993722 times.
✓ Branch 1 taken 532820 times.
16526542 if (!s->sh.disable_deblocking_filter_flag) {
1645 15993722 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size);
1646
2/2
✓ Branch 0 taken 409146 times.
✓ Branch 1 taken 15584576 times.
15993722 if (pps->transquant_bypass_enable_flag &&
1647
2/2
✓ Branch 0 taken 311137 times.
✓ Branch 1 taken 98009 times.
409146 lc->cu.cu_transquant_bypass_flag)
1648 311137 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size);
1649 }
1650 }
1651 19918574 return 0;
1652 }
1653
1654 12433 static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l,
1655 const HEVCPPS *pps, int x0, int y0, int log2_cb_size)
1656 {
1657 12433 const HEVCContext *const s = lc->parent;
1658 12433 const HEVCSPS *const sps = pps->sps;
1659 GetBitContext gb;
1660 12433 int cb_size = 1 << log2_cb_size;
1661 12433 ptrdiff_t stride0 = s->cur_frame->f->linesize[0];
1662 12433 ptrdiff_t stride1 = s->cur_frame->f->linesize[1];
1663 12433 ptrdiff_t stride2 = s->cur_frame->f->linesize[2];
1664 12433 uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)];
1665 12433 uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)];
1666 12433 uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)];
1667
1668 12433 int length = cb_size * cb_size * sps->pcm.bit_depth +
1669 12433 (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) +
1670 12433 ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) *
1671 12433 sps->pcm.bit_depth_chroma;
1672 12433 const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
1673 int ret;
1674
1675
2/2
✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
12433 if (!s->sh.disable_deblocking_filter_flag)
1676 6937 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
1677
1678 12433 ret = init_get_bits(&gb, pcm, length);
1679
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
1680 return ret;
1681
1682 12433 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth);
1683
1/2
✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
12433 if (sps->chroma_format_idc) {
1684 12433 s->hevcdsp.put_pcm(dst1, stride1,
1685 12433 cb_size >> sps->hshift[1],
1686 12433 cb_size >> sps->vshift[1],
1687 12433 &gb, sps->pcm.bit_depth_chroma);
1688 12433 s->hevcdsp.put_pcm(dst2, stride2,
1689 12433 cb_size >> sps->hshift[2],
1690 12433 cb_size >> sps->vshift[2],
1691 12433 &gb, sps->pcm.bit_depth_chroma);
1692 }
1693
1694 12433 return 0;
1695 }
1696
1697 /**
1698 * 8.5.3.2.2.1 Luma sample unidirectional interpolation process
1699 *
1700 * @param s HEVC decoding context
1701 * @param dst target buffer for block data at block position
1702 * @param dststride stride of the dst buffer
1703 * @param ref reference picture buffer at origin (0, 0)
1704 * @param mv motion vector (relative to block position) to get pixel data from
1705 * @param x_off horizontal position of block from origin (0, 0)
1706 * @param y_off vertical position of block from origin (0, 0)
1707 * @param block_w width of block
1708 * @param block_h height of block
1709 * @param luma_weight weighting factor applied to the luma prediction
1710 * @param luma_offset additive offset applied to the luma prediction value
1711 */
1712
1713 5180929 static void luma_mc_uni(HEVCLocalContext *lc,
1714 const HEVCPPS *pps, const HEVCSPS *sps,
1715 uint8_t *dst, ptrdiff_t dststride,
1716 const AVFrame *ref, const Mv *mv, int x_off, int y_off,
1717 int block_w, int block_h, int luma_weight, int luma_offset)
1718 {
1719 5180929 const HEVCContext *const s = lc->parent;
1720 5180929 const uint8_t *src = ref->data[0];
1721 5180929 ptrdiff_t srcstride = ref->linesize[0];
1722 5180929 int pic_width = sps->width;
1723 5180929 int pic_height = sps->height;
1724 5180929 int mx = mv->x & 3;
1725 5180929 int my = mv->y & 3;
1726
4/4
✓ Branch 0 taken 2126467 times.
✓ Branch 1 taken 3054462 times.
✓ Branch 2 taken 2072291 times.
✓ Branch 3 taken 54176 times.
10307682 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1727
4/4
✓ Branch 0 taken 3054462 times.
✓ Branch 1 taken 2072291 times.
✓ Branch 2 taken 70226 times.
✓ Branch 3 taken 2984236 times.
5126753 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1728 5180929 int idx = hevc_pel_weight[block_w];
1729
1730 5180929 x_off += mv->x >> 2;
1731 5180929 y_off += mv->y >> 2;
1732 5180929 src += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1733
1734
4/4
✓ Branch 0 taken 5120805 times.
✓ Branch 1 taken 60124 times.
✓ Branch 2 taken 5012001 times.
✓ Branch 3 taken 108804 times.
5180929 if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
1735
2/2
✓ Branch 0 taken 4945454 times.
✓ Branch 1 taken 66547 times.
5012001 x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1736
2/2
✓ Branch 0 taken 4737754 times.
✓ Branch 1 taken 207700 times.
4945454 y_off >= pic_height - block_h - QPEL_EXTRA_AFTER ||
1737
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4737754 times.
4737754 ref == s->cur_frame->f) {
1738 443175 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1739 443175 int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1740 443175 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1741
1742 443175 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
1743 edge_emu_stride, srcstride,
1744 block_w + QPEL_EXTRA,
1745 block_h + QPEL_EXTRA,
1746 x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE,
1747 pic_width, pic_height);
1748 443175 src = lc->edge_emu_buffer + buf_offset;
1749 443175 srcstride = edge_emu_stride;
1750 }
1751
1752
2/2
✓ Branch 0 taken 5056527 times.
✓ Branch 1 taken 124402 times.
5180929 if (!weight_flag)
1753 5056527 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride,
1754 block_h, mx, my, block_w);
1755 else
1756 124402 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride,
1757 124402 block_h, s->sh.luma_log2_weight_denom,
1758 luma_weight, luma_offset, mx, my, block_w);
1759 5180929 }
1760
1761 /**
1762 * 8.5.3.2.2.1 Luma sample bidirectional interpolation process
1763 *
1764 * @param s HEVC decoding context
1765 * @param dst target buffer for block data at block position
1766 * @param dststride stride of the dst buffer
1767 * @param ref0 reference picture0 buffer at origin (0, 0)
1768 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1769 * @param x_off horizontal position of block from origin (0, 0)
1770 * @param y_off vertical position of block from origin (0, 0)
1771 * @param block_w width of block
1772 * @param block_h height of block
1773 * @param ref1 reference picture1 buffer at origin (0, 0)
1774 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1775 * @param current_mv current motion vector structure
1776 */
1777 3978353 static void luma_mc_bi(HEVCLocalContext *lc,
1778 const HEVCPPS *pps, const HEVCSPS *sps,
1779 uint8_t *dst, ptrdiff_t dststride,
1780 const AVFrame *ref0, const Mv *mv0, int x_off, int y_off,
1781 int block_w, int block_h, const AVFrame *ref1,
1782 const Mv *mv1, struct MvField *current_mv)
1783 {
1784 3978353 const HEVCContext *const s = lc->parent;
1785 3978353 ptrdiff_t src0stride = ref0->linesize[0];
1786 3978353 ptrdiff_t src1stride = ref1->linesize[0];
1787 3978353 int pic_width = sps->width;
1788 3978353 int pic_height = sps->height;
1789 3978353 int mx0 = mv0->x & 3;
1790 3978353 int my0 = mv0->y & 3;
1791 3978353 int mx1 = mv1->x & 3;
1792 3978353 int my1 = mv1->y & 3;
1793
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3978353 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7956706 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1794
3/4
✓ Branch 0 taken 3978353 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68518 times.
✓ Branch 3 taken 3909835 times.
3978353 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1795 3978353 int x_off0 = x_off + (mv0->x >> 2);
1796 3978353 int y_off0 = y_off + (mv0->y >> 2);
1797 3978353 int x_off1 = x_off + (mv1->x >> 2);
1798 3978353 int y_off1 = y_off + (mv1->y >> 2);
1799 3978353 int idx = hevc_pel_weight[block_w];
1800
1801 3978353 const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1802 3978353 const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1803
1804
4/4
✓ Branch 0 taken 3921066 times.
✓ Branch 1 taken 57287 times.
✓ Branch 2 taken 3814596 times.
✓ Branch 3 taken 106470 times.
3978353 if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER ||
1805
2/2
✓ Branch 0 taken 3746394 times.
✓ Branch 1 taken 68202 times.
3814596 x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1806
2/2
✓ Branch 0 taken 208390 times.
✓ Branch 1 taken 3538004 times.
3746394 y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1807 440349 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1808 440349 int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1809 440349 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1810
1811 440349 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset,
1812 edge_emu_stride, src0stride,
1813 block_w + QPEL_EXTRA,
1814 block_h + QPEL_EXTRA,
1815 x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE,
1816 pic_width, pic_height);
1817 440349 src0 = lc->edge_emu_buffer + buf_offset;
1818 440349 src0stride = edge_emu_stride;
1819 }
1820
1821
4/4
✓ Branch 0 taken 3914862 times.
✓ Branch 1 taken 63491 times.
✓ Branch 2 taken 3809053 times.
✓ Branch 3 taken 105809 times.
3978353 if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER ||
1822
2/2
✓ Branch 0 taken 3738943 times.
✓ Branch 1 taken 70110 times.
3809053 x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1823
2/2
✓ Branch 0 taken 211564 times.
✓ Branch 1 taken 3527379 times.
3738943 y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1824 450974 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1825 450974 int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1826 450974 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1827
1828 450974 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset,
1829 edge_emu_stride, src1stride,
1830 block_w + QPEL_EXTRA,
1831 block_h + QPEL_EXTRA,
1832 x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE,
1833 pic_width, pic_height);
1834 450974 src1 = lc->edge_emu_buffer2 + buf_offset;
1835 450974 src1stride = edge_emu_stride;
1836 }
1837
1838 3978353 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride,
1839 block_h, mx0, my0, block_w);
1840
2/2
✓ Branch 0 taken 3909835 times.
✓ Branch 1 taken 68518 times.
3978353 if (!weight_flag)
1841 3909835 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1842 block_h, mx1, my1, block_w);
1843 else
1844 68518 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1845 68518 block_h, s->sh.luma_log2_weight_denom,
1846 68518 s->sh.luma_weight_l0[current_mv->ref_idx[0]],
1847 68518 s->sh.luma_weight_l1[current_mv->ref_idx[1]],
1848 68518 s->sh.luma_offset_l0[current_mv->ref_idx[0]],
1849 68518 s->sh.luma_offset_l1[current_mv->ref_idx[1]],
1850 mx1, my1, block_w);
1851
1852 3978353 }
1853
1854 /**
1855 * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process
1856 *
1857 * @param s HEVC decoding context
1858 * @param dst1 target buffer for block data at block position (U plane)
1859 * @param dst2 target buffer for block data at block position (V plane)
1860 * @param dststride stride of the dst1 and dst2 buffers
1861 * @param ref reference picture buffer at origin (0, 0)
1862 * @param mv motion vector (relative to block position) to get pixel data from
1863 * @param x_off horizontal position of block from origin (0, 0)
1864 * @param y_off vertical position of block from origin (0, 0)
1865 * @param block_w width of block
1866 * @param block_h height of block
1867 * @param chroma_weight weighting factor applied to the chroma prediction
1868 * @param chroma_offset additive offset applied to the chroma prediction value
1869 */
1870
1871 10361858 static void chroma_mc_uni(HEVCLocalContext *lc,
1872 const HEVCPPS *pps, const HEVCSPS *sps,
1873 uint8_t *dst0,
1874 ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist,
1875 int x_off, int y_off, int block_w, int block_h,
1876 const struct MvField *current_mv, int chroma_weight, int chroma_offset)
1877 {
1878 10361858 const HEVCContext *const s = lc->parent;
1879 10361858 int pic_width = sps->width >> sps->hshift[1];
1880 10361858 int pic_height = sps->height >> sps->vshift[1];
1881 10361858 const Mv *mv = &current_mv->mv[reflist];
1882
4/4
✓ Branch 0 taken 4252934 times.
✓ Branch 1 taken 6108924 times.
✓ Branch 2 taken 4144582 times.
✓ Branch 3 taken 108352 times.
20615364 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1883
4/4
✓ Branch 0 taken 6108924 times.
✓ Branch 1 taken 4144582 times.
✓ Branch 2 taken 140452 times.
✓ Branch 3 taken 5968472 times.
10253506 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1884 10361858 int idx = hevc_pel_weight[block_w];
1885 10361858 int hshift = sps->hshift[1];
1886 10361858 int vshift = sps->vshift[1];
1887 10361858 intptr_t mx = av_zero_extend(mv->x, 2 + hshift);
1888 10361858 intptr_t my = av_zero_extend(mv->y, 2 + vshift);
1889 10361858 intptr_t _mx = mx << (1 - hshift);
1890 10361858 intptr_t _my = my << (1 - vshift);
1891
2/4
✓ Branch 0 taken 10361858 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10361858 times.
10361858 int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2];
1892
1893 10361858 x_off += mv->x >> (2 + hshift);
1894 10361858 y_off += mv->y >> (2 + vshift);
1895 10361858 src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1896
1897
4/4
✓ Branch 0 taken 10252206 times.
✓ Branch 1 taken 109652 times.
✓ Branch 2 taken 10034458 times.
✓ Branch 3 taken 217748 times.
10361858 if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1898
2/2
✓ Branch 0 taken 9901372 times.
✓ Branch 1 taken 133086 times.
10034458 x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1899
3/4
✓ Branch 0 taken 9485906 times.
✓ Branch 1 taken 415466 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9485906 times.
9901372 y_off >= pic_height - block_h - EPEL_EXTRA_AFTER ||
1900 emu) {
1901 875952 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1902 875952 int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift));
1903 875952 int buf_offset0 = EPEL_EXTRA_BEFORE *
1904 875952 (edge_emu_stride + (1 << sps->pixel_shift));
1905 875952 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0,
1906 edge_emu_stride, srcstride,
1907 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1908 x_off - EPEL_EXTRA_BEFORE,
1909 y_off - EPEL_EXTRA_BEFORE,
1910 pic_width, pic_height);
1911
1912 875952 src0 = lc->edge_emu_buffer + buf_offset0;
1913 875952 srcstride = edge_emu_stride;
1914 }
1915
2/2
✓ Branch 0 taken 10113054 times.
✓ Branch 1 taken 248804 times.
10361858 if (!weight_flag)
1916 10113054 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1917 block_h, _mx, _my, block_w);
1918 else
1919 248804 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1920 248804 block_h, s->sh.chroma_log2_weight_denom,
1921 chroma_weight, chroma_offset, _mx, _my, block_w);
1922 10361858 }
1923
1924 /**
1925 * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process
1926 *
1927 * @param s HEVC decoding context
1928 * @param dst target buffer for block data at block position
1929 * @param dststride stride of the dst buffer
1930 * @param ref0 reference picture0 buffer at origin (0, 0)
1931 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1932 * @param x_off horizontal position of block from origin (0, 0)
1933 * @param y_off vertical position of block from origin (0, 0)
1934 * @param block_w width of block
1935 * @param block_h height of block
1936 * @param ref1 reference picture1 buffer at origin (0, 0)
1937 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1938 * @param current_mv current motion vector structure
1939 * @param cidx chroma component(cb, cr)
1940 */
1941 7956706 static void chroma_mc_bi(HEVCLocalContext *lc,
1942 const HEVCPPS *pps, const HEVCSPS *sps,
1943 uint8_t *dst0, ptrdiff_t dststride,
1944 const AVFrame *ref0, const AVFrame *ref1,
1945 int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx)
1946 {
1947 7956706 const HEVCContext *const s = lc->parent;
1948 7956706 const uint8_t *src1 = ref0->data[cidx+1];
1949 7956706 const uint8_t *src2 = ref1->data[cidx+1];
1950 7956706 ptrdiff_t src1stride = ref0->linesize[cidx+1];
1951 7956706 ptrdiff_t src2stride = ref1->linesize[cidx+1];
1952
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7956706 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15913412 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1953
3/4
✓ Branch 0 taken 7956706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 137036 times.
✓ Branch 3 taken 7819670 times.
7956706 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1954 7956706 int pic_width = sps->width >> sps->hshift[1];
1955 7956706 int pic_height = sps->height >> sps->vshift[1];
1956 7956706 const Mv *const mv0 = &current_mv->mv[0];
1957 7956706 const Mv *const mv1 = &current_mv->mv[1];
1958 7956706 int hshift = sps->hshift[1];
1959 7956706 int vshift = sps->vshift[1];
1960
1961 7956706 intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift);
1962 7956706 intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift);
1963 7956706 intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift);
1964 7956706 intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift);
1965 7956706 intptr_t _mx0 = mx0 << (1 - hshift);
1966 7956706 intptr_t _my0 = my0 << (1 - vshift);
1967 7956706 intptr_t _mx1 = mx1 << (1 - hshift);
1968 7956706 intptr_t _my1 = my1 << (1 - vshift);
1969
1970 7956706 int x_off0 = x_off + (mv0->x >> (2 + hshift));
1971 7956706 int y_off0 = y_off + (mv0->y >> (2 + vshift));
1972 7956706 int x_off1 = x_off + (mv1->x >> (2 + hshift));
1973 7956706 int y_off1 = y_off + (mv1->y >> (2 + vshift));
1974 7956706 int idx = hevc_pel_weight[block_w];
1975 7956706 src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1976 7956706 src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1977
1978
4/4
✓ Branch 0 taken 7848386 times.
✓ Branch 1 taken 108320 times.
✓ Branch 2 taken 7635334 times.
✓ Branch 3 taken 213052 times.
7956706 if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER ||
1979
2/2
✓ Branch 0 taken 7498934 times.
✓ Branch 1 taken 136400 times.
7635334 x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1980
2/2
✓ Branch 0 taken 416192 times.
✓ Branch 1 taken 7082742 times.
7498934 y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1981 873964 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1982 873964 int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift));
1983 873964 int buf_offset1 = EPEL_EXTRA_BEFORE *
1984 873964 (edge_emu_stride + (1 << sps->pixel_shift));
1985
1986 873964 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1,
1987 edge_emu_stride, src1stride,
1988 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1989 x_off0 - EPEL_EXTRA_BEFORE,
1990 y_off0 - EPEL_EXTRA_BEFORE,
1991 pic_width, pic_height);
1992
1993 873964 src1 = lc->edge_emu_buffer + buf_offset1;
1994 873964 src1stride = edge_emu_stride;
1995 }
1996
1997
4/4
✓ Branch 0 taken 7835120 times.
✓ Branch 1 taken 121586 times.
✓ Branch 2 taken 7623780 times.
✓ Branch 3 taken 211340 times.
7956706 if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER ||
1998
2/2
✓ Branch 0 taken 7483566 times.
✓ Branch 1 taken 140214 times.
7623780 x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1999
2/2
✓ Branch 0 taken 422802 times.
✓ Branch 1 taken 7060764 times.
7483566 y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
2000 895942 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
2001 895942 int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift));
2002 895942 int buf_offset1 = EPEL_EXTRA_BEFORE *
2003 895942 (edge_emu_stride + (1 << sps->pixel_shift));
2004
2005 895942 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1,
2006 edge_emu_stride, src2stride,
2007 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
2008 x_off1 - EPEL_EXTRA_BEFORE,
2009 y_off1 - EPEL_EXTRA_BEFORE,
2010 pic_width, pic_height);
2011
2012 895942 src2 = lc->edge_emu_buffer2 + buf_offset1;
2013 895942 src2stride = edge_emu_stride;
2014 }
2015
2016 7956706 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride,
2017 block_h, _mx0, _my0, block_w);
2018
2/2
✓ Branch 0 taken 7819670 times.
✓ Branch 1 taken 137036 times.
7956706 if (!weight_flag)
2019 7819670 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
2020 7819670 src2, src2stride, lc->tmp,
2021 block_h, _mx1, _my1, block_w);
2022 else
2023 137036 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
2024 137036 src2, src2stride, lc->tmp,
2025 block_h,
2026 137036 s->sh.chroma_log2_weight_denom,
2027 137036 s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx],
2028 137036 s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx],
2029 137036 s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx],
2030 137036 s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx],
2031 _mx1, _my1, block_w);
2032 7956706 }
2033
2034 13137635 static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref,
2035 const Mv *mv, int y0, int height)
2036 {
2037
2/2
✓ Branch 0 taken 111132 times.
✓ Branch 1 taken 13026503 times.
13137635 if (s->avctx->active_thread_type == FF_THREAD_FRAME ) {
2038 111132 int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9);
2039
2040 111132 ff_progress_frame_await(&ref->tf, y);
2041 }
2042 13137635 }
2043
2044 2539966 static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc,
2045 const HEVCPPS *pps, const HEVCSPS *sps,
2046 int x0, int y0, int nPbW,
2047 int nPbH, int log2_cb_size, int part_idx,
2048 int merge_idx, MvField *mv)
2049 {
2050 2539966 const HEVCContext *const s = lc->parent;
2051 2539966 enum InterPredIdc inter_pred_idc = PRED_L0;
2052 int mvp_flag;
2053
2054 2539966 ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size);
2055 2539966 mv->pred_flag = 0;
2056
2/2
✓ Branch 0 taken 1919531 times.
✓ Branch 1 taken 620435 times.
2539966 if (s->sh.slice_type == HEVC_SLICE_B)
2057 1919531 inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH);
2058
2059
2/2
✓ Branch 0 taken 2132157 times.
✓ Branch 1 taken 407809 times.
2539966 if (inter_pred_idc != PRED_L1) {
2060
1/2
✓ Branch 0 taken 2132157 times.
✗ Branch 1 not taken.
2132157 if (s->sh.nb_refs[L0])
2061 2132157 mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]);
2062
2063 2132157 mv->pred_flag = PF_L0;
2064 2132157 ff_hevc_hls_mvd_coding(lc, x0, y0, 0);
2065 2132157 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2066 2132157 ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2067 part_idx, merge_idx, mv, mvp_flag, 0);
2068 2132157 mv->mv[0].x += lc->pu.mvd.x;
2069 2132157 mv->mv[0].y += lc->pu.mvd.y;
2070 }
2071
2072
2/2
✓ Branch 0 taken 832301 times.
✓ Branch 1 taken 1707665 times.
2539966 if (inter_pred_idc != PRED_L0) {
2073
1/2
✓ Branch 0 taken 832301 times.
✗ Branch 1 not taken.
832301 if (s->sh.nb_refs[L1])
2074 832301 mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]);
2075
2076
4/4
✓ Branch 0 taken 193172 times.
✓ Branch 1 taken 639129 times.
✓ Branch 2 taken 163605 times.
✓ Branch 3 taken 29567 times.
832301 if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) {
2077 163605 AV_ZERO32(&lc->pu.mvd);
2078 } else {
2079 668696 ff_hevc_hls_mvd_coding(lc, x0, y0, 1);
2080 }
2081
2082 832301 mv->pred_flag += PF_L1;
2083 832301 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2084 832301 ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2085 part_idx, merge_idx, mv, mvp_flag, 1);
2086 832301 mv->mv[1].x += lc->pu.mvd.x;
2087 832301 mv->mv[1].y += lc->pu.mvd.y;
2088 }
2089 2539966 }
2090
2091 9159282 static void hls_prediction_unit(HEVCLocalContext *lc,
2092 const HEVCLayerContext *l,
2093 const HEVCPPS *pps, const HEVCSPS *sps,
2094 int x0, int y0, int nPbW, int nPbH,
2095 int log2_cb_size, int partIdx, int idx)
2096 {
2097 #define POS(c_idx, x, y) \
2098 &s->cur_frame->f->data[c_idx] ? \
2099 &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \
2100 (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] : NULL
2101 9159282 const HEVCContext *const s = lc->parent;
2102 9159282 int merge_idx = 0;
2103 9159282 struct MvField current_mv = {{{ 0 }}};
2104
2105 9159282 int min_pu_width = sps->min_pu_width;
2106
2107 9159282 MvField *tab_mvf = s->cur_frame->tab_mvf;
2108 9159282 const RefPicList *refPicList = s->cur_frame->refPicList;
2109 9159282 const HEVCFrame *ref0 = NULL, *ref1 = NULL;
2110 9159282 const int *linesize = s->cur_frame->f->linesize;
2111 9159282 uint8_t *dst0 = s->cur_frame->f->data[0] + y0 * linesize[0] + (x0 << sps->pixel_shift);
2112
1/2
✓ Branch 0 taken 9159282 times.
✗ Branch 1 not taken.
9159282 uint8_t *dst1 = POS(1, x0, y0);
2113
1/2
✓ Branch 0 taken 9159282 times.
✗ Branch 1 not taken.
9159282 uint8_t *dst2 = POS(2, x0, y0);
2114 9159282 int log2_min_cb_size = sps->log2_min_cb_size;
2115 9159282 int min_cb_width = sps->min_cb_width;
2116 9159282 int x_cb = x0 >> log2_min_cb_size;
2117 9159282 int y_cb = y0 >> log2_min_cb_size;
2118 int x_pu, y_pu;
2119 int i, j;
2120
2121 9159282 int skip_flag = SAMPLE_CTB(l->skip_flag, x_cb, y_cb);
2122
2123
2/2
✓ Branch 0 taken 5048690 times.
✓ Branch 1 taken 4110592 times.
9159282 if (!skip_flag)
2124 5048690 lc->pu.merge_flag = ff_hevc_merge_flag_decode(lc);
2125
2126
4/4
✓ Branch 0 taken 5048690 times.
✓ Branch 1 taken 4110592 times.
✓ Branch 2 taken 2508724 times.
✓ Branch 3 taken 2539966 times.
9159282 if (skip_flag || lc->pu.merge_flag) {
2127
2/2
✓ Branch 0 taken 6542463 times.
✓ Branch 1 taken 76853 times.
6619316 if (s->sh.max_num_merge_cand > 1)
2128 6542463 merge_idx = ff_hevc_merge_idx_decode(lc);
2129 else
2130 76853 merge_idx = 0;
2131
2132 6619316 ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2133 partIdx, merge_idx, &current_mv);
2134 } else {
2135 2539966 hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size,
2136 partIdx, merge_idx, &current_mv);
2137 }
2138
2139 9159282 x_pu = x0 >> sps->log2_min_pu_size;
2140 9159282 y_pu = y0 >> sps->log2_min_pu_size;
2141
2142
2/2
✓ Branch 0 taken 35665526 times.
✓ Branch 1 taken 9159282 times.
44824808 for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++)
2143
2/2
✓ Branch 0 taken 234082348 times.
✓ Branch 1 taken 35665526 times.
269747874 for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++)
2144 234082348 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
2145
2146
2/2
✓ Branch 0 taken 8344417 times.
✓ Branch 1 taken 814865 times.
9159282 if (current_mv.pred_flag & PF_L0) {
2147 8344417 ref0 = refPicList[0].ref[current_mv.ref_idx[0]];
2148
2/4
✓ Branch 0 taken 8344417 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344417 times.
8344417 if (!ref0 || !ref0->f)
2149 return;
2150 8344417 hevc_await_progress(s, ref0, &current_mv.mv[0], y0, nPbH);
2151 }
2152
2/2
✓ Branch 0 taken 4793218 times.
✓ Branch 1 taken 4366064 times.
9159282 if (current_mv.pred_flag & PF_L1) {
2153 4793218 ref1 = refPicList[1].ref[current_mv.ref_idx[1]];
2154
2/4
✓ Branch 0 taken 4793218 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4793218 times.
4793218 if (!ref1 || !ref1->f)
2155 return;
2156 4793218 hevc_await_progress(s, ref1, &current_mv.mv[1], y0, nPbH);
2157 }
2158
2159
2/2
✓ Branch 0 taken 4366064 times.
✓ Branch 1 taken 4793218 times.
9159282 if (current_mv.pred_flag == PF_L0) {
2160 4366064 int x0_c = x0 >> sps->hshift[1];
2161 4366064 int y0_c = y0 >> sps->vshift[1];
2162 4366064 int nPbW_c = nPbW >> sps->hshift[1];
2163 4366064 int nPbH_c = nPbH >> sps->vshift[1];
2164
2165 4366064 luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f,
2166 &current_mv.mv[0], x0, y0, nPbW, nPbH,
2167 4366064 s->sh.luma_weight_l0[current_mv.ref_idx[0]],
2168 4366064 s->sh.luma_offset_l0[current_mv.ref_idx[0]]);
2169
2170
1/2
✓ Branch 0 taken 4366064 times.
✗ Branch 1 not taken.
4366064 if (sps->chroma_format_idc) {
2171 4366064 chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1],
2172 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2173 4366064 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]);
2174 4366064 chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2],
2175 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2176 4366064 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]);
2177 }
2178
2/2
✓ Branch 0 taken 814865 times.
✓ Branch 1 taken 3978353 times.
4793218 } else if (current_mv.pred_flag == PF_L1) {
2179 814865 int x0_c = x0 >> sps->hshift[1];
2180 814865 int y0_c = y0 >> sps->vshift[1];
2181 814865 int nPbW_c = nPbW >> sps->hshift[1];
2182 814865 int nPbH_c = nPbH >> sps->vshift[1];
2183
2184 814865 luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f,
2185 &current_mv.mv[1], x0, y0, nPbW, nPbH,
2186 814865 s->sh.luma_weight_l1[current_mv.ref_idx[1]],
2187 814865 s->sh.luma_offset_l1[current_mv.ref_idx[1]]);
2188
2189
1/2
✓ Branch 0 taken 814865 times.
✗ Branch 1 not taken.
814865 if (sps->chroma_format_idc) {
2190 814865 chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1],
2191 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2192 814865 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]);
2193
2194 814865 chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2],
2195 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2196 814865 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]);
2197 }
2198
1/2
✓ Branch 0 taken 3978353 times.
✗ Branch 1 not taken.
3978353 } else if (current_mv.pred_flag == PF_BI) {
2199 3978353 int x0_c = x0 >> sps->hshift[1];
2200 3978353 int y0_c = y0 >> sps->vshift[1];
2201 3978353 int nPbW_c = nPbW >> sps->hshift[1];
2202 3978353 int nPbH_c = nPbH >> sps->vshift[1];
2203
2204 3978353 luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f,
2205 &current_mv.mv[0], x0, y0, nPbW, nPbH,
2206 3978353 ref1->f, &current_mv.mv[1], &current_mv);
2207
2208
1/2
✓ Branch 0 taken 3978353 times.
✗ Branch 1 not taken.
3978353 if (sps->chroma_format_idc) {
2209 3978353 chroma_mc_bi(lc, pps, sps, dst1, linesize[1], ref0->f, ref1->f,
2210 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 0);
2211
2212 3978353 chroma_mc_bi(lc, pps, sps, dst2, linesize[2], ref0->f, ref1->f,
2213 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 1);
2214 }
2215 }
2216 }
2217
2218 /**
2219 * 8.4.1
2220 */
2221 8197062 static int luma_intra_pred_mode(HEVCLocalContext *lc, const HEVCLayerContext *l,
2222 const HEVCSPS *sps,
2223 int x0, int y0, int pu_size,
2224 int prev_intra_luma_pred_flag)
2225 {
2226 8197062 const HEVCContext *const s = lc->parent;
2227 8197062 int x_pu = x0 >> sps->log2_min_pu_size;
2228 8197062 int y_pu = y0 >> sps->log2_min_pu_size;
2229 8197062 int min_pu_width = sps->min_pu_width;
2230 8197062 int size_in_pus = pu_size >> sps->log2_min_pu_size;
2231 8197062 int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2232 8197062 int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2233
2234
2/2
✓ Branch 0 taken 1073461 times.
✓ Branch 1 taken 125883 times.
1199344 int cand_up = (lc->ctb_up_flag || y0b) ?
2235
2/2
✓ Branch 0 taken 1199344 times.
✓ Branch 1 taken 6997718 times.
9396406 l->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
2236
2/2
✓ Branch 0 taken 598837 times.
✓ Branch 1 taken 82619 times.
681456 int cand_left = (lc->ctb_left_flag || x0b) ?
2237
2/2
✓ Branch 0 taken 681456 times.
✓ Branch 1 taken 7515606 times.
8878518 l->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC;
2238
2239 8197062 int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size);
2240
2241 8197062 MvField *tab_mvf = s->cur_frame->tab_mvf;
2242 int intra_pred_mode;
2243 int candidate[3];
2244 int i, j;
2245
2246 // intra_pred_mode prediction does not cross vertical CTB boundaries
2247
2/2
✓ Branch 0 taken 1072960 times.
✓ Branch 1 taken 7124102 times.
8197062 if ((y0 - 1) < y_ctb)
2248 1072960 cand_up = INTRA_DC;
2249
2250
2/2
✓ Branch 0 taken 1718796 times.
✓ Branch 1 taken 6478266 times.
8197062 if (cand_left == cand_up) {
2251
2/2
✓ Branch 0 taken 1023198 times.
✓ Branch 1 taken 695598 times.
1718796 if (cand_left < 2) {
2252 1023198 candidate[0] = INTRA_PLANAR;
2253 1023198 candidate[1] = INTRA_DC;
2254 1023198 candidate[2] = INTRA_ANGULAR_26;
2255 } else {
2256 695598 candidate[0] = cand_left;
2257 695598 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2258 695598 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2259 }
2260 } else {
2261 6478266 candidate[0] = cand_left;
2262 6478266 candidate[1] = cand_up;
2263
4/4
✓ Branch 0 taken 5368895 times.
✓ Branch 1 taken 1109371 times.
✓ Branch 2 taken 4428501 times.
✓ Branch 3 taken 940394 times.
6478266 if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) {
2264 4428501 candidate[2] = INTRA_PLANAR;
2265
4/4
✓ Branch 0 taken 1791882 times.
✓ Branch 1 taken 257883 times.
✓ Branch 2 taken 1348268 times.
✓ Branch 3 taken 443614 times.
2049765 } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) {
2266 1348268 candidate[2] = INTRA_DC;
2267 } else {
2268 701497 candidate[2] = INTRA_ANGULAR_26;
2269 }
2270 }
2271
2272
2/2
✓ Branch 0 taken 4921640 times.
✓ Branch 1 taken 3275422 times.
8197062 if (prev_intra_luma_pred_flag) {
2273 4921640 intra_pred_mode = candidate[lc->pu.mpm_idx];
2274 } else {
2275
2/2
✓ Branch 0 taken 1562983 times.
✓ Branch 1 taken 1712439 times.
3275422 if (candidate[0] > candidate[1])
2276 1562983 FFSWAP(uint8_t, candidate[0], candidate[1]);
2277
2/2
✓ Branch 0 taken 1940254 times.
✓ Branch 1 taken 1335168 times.
3275422 if (candidate[0] > candidate[2])
2278 1940254 FFSWAP(uint8_t, candidate[0], candidate[2]);
2279
2/2
✓ Branch 0 taken 2438139 times.
✓ Branch 1 taken 837283 times.
3275422 if (candidate[1] > candidate[2])
2280 2438139 FFSWAP(uint8_t, candidate[1], candidate[2]);
2281
2282 3275422 intra_pred_mode = lc->pu.rem_intra_luma_pred_mode;
2283
2/2
✓ Branch 0 taken 9826266 times.
✓ Branch 1 taken 3275422 times.
13101688 for (i = 0; i < 3; i++)
2284
2/2
✓ Branch 0 taken 7155961 times.
✓ Branch 1 taken 2670305 times.
9826266 if (intra_pred_mode >= candidate[i])
2285 7155961 intra_pred_mode++;
2286 }
2287
2288 /* write the intra prediction units into the mv array */
2289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8197062 times.
8197062 if (!size_in_pus)
2290 size_in_pus = 1;
2291
2/2
✓ Branch 0 taken 14695466 times.
✓ Branch 1 taken 8197062 times.
22892528 for (i = 0; i < size_in_pus; i++) {
2292 14695466 memset(&l->tab_ipm[(y_pu + i) * min_pu_width + x_pu],
2293 intra_pred_mode, size_in_pus);
2294
2295
2/2
✓ Branch 0 taken 48382956 times.
✓ Branch 1 taken 14695466 times.
63078422 for (j = 0; j < size_in_pus; j++) {
2296 48382956 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA;
2297 }
2298 }
2299
2300 8197062 return intra_pred_mode;
2301 }
2302
2303 11854981 static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth,
2304 int x0, int y0,
2305 int log2_cb_size, int ct_depth)
2306 {
2307 11854981 int length = (1 << log2_cb_size) >> sps->log2_min_cb_size;
2308 11854981 int x_cb = x0 >> sps->log2_min_cb_size;
2309 11854981 int y_cb = y0 >> sps->log2_min_cb_size;
2310 int y;
2311
2312
2/2
✓ Branch 0 taken 22291751 times.
✓ Branch 1 taken 11854981 times.
34146732 for (y = 0; y < length; y++)
2313 22291751 memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb],
2314 ct_depth, length);
2315 11854981 }
2316
2317 static const uint8_t tab_mode_idx[] = {
2318 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2319 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2320
2321 4345692 static void intra_prediction_unit(HEVCLocalContext *lc,
2322 const HEVCLayerContext *l, const HEVCSPS *sps,
2323 int x0, int y0,
2324 int log2_cb_size)
2325 {
2326 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2327 uint8_t prev_intra_luma_pred_flag[4];
2328 4345692 int split = lc->cu.part_mode == PART_NxN;
2329 4345692 int pb_size = (1 << log2_cb_size) >> split;
2330 4345692 int side = split + 1;
2331 int chroma_mode;
2332 int i, j;
2333
2334
2/2
✓ Branch 0 taken 5629482 times.
✓ Branch 1 taken 4345692 times.
9975174 for (i = 0; i < side; i++)
2335
2/2
✓ Branch 0 taken 8197062 times.
✓ Branch 1 taken 5629482 times.
13826544 for (j = 0; j < side; j++)
2336 8197062 prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc);
2337
2338
2/2
✓ Branch 0 taken 5629482 times.
✓ Branch 1 taken 4345692 times.
9975174 for (i = 0; i < side; i++) {
2339
2/2
✓ Branch 0 taken 8197062 times.
✓ Branch 1 taken 5629482 times.
13826544 for (j = 0; j < side; j++) {
2340
2/2
✓ Branch 0 taken 4921640 times.
✓ Branch 1 taken 3275422 times.
8197062 if (prev_intra_luma_pred_flag[2 * i + j])
2341 4921640 lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc);
2342 else
2343 3275422 lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc);
2344
2345 8197062 lc->pu.intra_pred_mode[2 * i + j] =
2346 8197062 luma_intra_pred_mode(lc, l, sps,
2347 8197062 x0 + pb_size * j, y0 + pb_size * i, pb_size,
2348 8197062 prev_intra_luma_pred_flag[2 * i + j]);
2349 }
2350 }
2351
2352
2/2
✓ Branch 0 taken 105006 times.
✓ Branch 1 taken 4240686 times.
4345692 if (sps->chroma_format_idc == 3) {
2353
2/2
✓ Branch 0 taken 138857 times.
✓ Branch 1 taken 105006 times.
243863 for (i = 0; i < side; i++) {
2354
2/2
✓ Branch 0 taken 206559 times.
✓ Branch 1 taken 138857 times.
345416 for (j = 0; j < side; j++) {
2355 206559 lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2356
2/2
✓ Branch 0 taken 34248 times.
✓ Branch 1 taken 172311 times.
206559 if (chroma_mode != 4) {
2357
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])
2358 2343 lc->pu.intra_pred_mode_c[2 * i + j] = 34;
2359 else
2360 31905 lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode];
2361 } else {
2362 172311 lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j];
2363 }
2364 }
2365 }
2366
2/2
✓ Branch 0 taken 247106 times.
✓ Branch 1 taken 3993580 times.
4240686 } else if (sps->chroma_format_idc == 2) {
2367 int mode_idx;
2368 247106 lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2369
2/2
✓ Branch 0 taken 73995 times.
✓ Branch 1 taken 173111 times.
247106 if (chroma_mode != 4) {
2370
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])
2371 3515 mode_idx = 34;
2372 else
2373 70480 mode_idx = intra_chroma_table[chroma_mode];
2374 } else {
2375 173111 mode_idx = lc->pu.intra_pred_mode[0];
2376 }
2377 247106 lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx];
2378
2/2
✓ Branch 0 taken 3993388 times.
✓ Branch 1 taken 192 times.
3993580 } else if (sps->chroma_format_idc != 0) {
2379 3993388 chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2380
2/2
✓ Branch 0 taken 995735 times.
✓ Branch 1 taken 2997653 times.
3993388 if (chroma_mode != 4) {
2381
2/2
✓ Branch 0 taken 74030 times.
✓ Branch 1 taken 921705 times.
995735 if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2382 74030 lc->pu.intra_pred_mode_c[0] = 34;
2383 else
2384 921705 lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode];
2385 } else {
2386 2997653 lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0];
2387 }
2388 }
2389 4345692 }
2390
2391 7509290 static void intra_prediction_unit_default_value(HEVCLocalContext *lc,
2392 const HEVCLayerContext *l,
2393 const HEVCSPS *sps,
2394 int x0, int y0,
2395 int log2_cb_size)
2396 {
2397 7509290 const HEVCContext *const s = lc->parent;
2398 7509290 int pb_size = 1 << log2_cb_size;
2399 7509290 int size_in_pus = pb_size >> sps->log2_min_pu_size;
2400 7509290 int min_pu_width = sps->min_pu_width;
2401 7509290 MvField *tab_mvf = s->cur_frame->tab_mvf;
2402 7509290 int x_pu = x0 >> sps->log2_min_pu_size;
2403 7509290 int y_pu = y0 >> sps->log2_min_pu_size;
2404 int j, k;
2405
2406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7509290 times.
7509290 if (size_in_pus == 0)
2407 size_in_pus = 1;
2408
2/2
✓ Branch 0 taken 32455618 times.
✓ Branch 1 taken 7509290 times.
39964908 for (j = 0; j < size_in_pus; j++)
2409 32455618 memset(&l->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus);
2410
2/2
✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 7496857 times.
7509290 if (lc->cu.pred_mode == MODE_INTRA)
2411
2/2
✓ Branch 0 taken 40908 times.
✓ Branch 1 taken 12433 times.
53341 for (j = 0; j < size_in_pus; j++)
2412
2/2
✓ Branch 0 taken 182512 times.
✓ Branch 1 taken 40908 times.
223420 for (k = 0; k < size_in_pus; k++)
2413 182512 tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA;
2414 7509290 }
2415
2416 11854982 static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s,
2417 const HEVCLayerContext *l,
2418 const HEVCPPS *pps, const HEVCSPS *sps,
2419 int x0, int y0, int log2_cb_size)
2420 {
2421 11854982 int cb_size = 1 << log2_cb_size;
2422 11854982 int log2_min_cb_size = sps->log2_min_cb_size;
2423 11854982 int length = cb_size >> log2_min_cb_size;
2424 11854982 int min_cb_width = sps->min_cb_width;
2425 11854982 int x_cb = x0 >> log2_min_cb_size;
2426 11854982 int y_cb = y0 >> log2_min_cb_size;
2427 11854982 int idx = log2_cb_size - 2;
2428 11854982 int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2429 int x, y, ret;
2430
2431 11854982 lc->cu.x = x0;
2432 11854982 lc->cu.y = y0;
2433 11854982 lc->cu.pred_mode = MODE_INTRA;
2434 11854982 lc->cu.part_mode = PART_2Nx2N;
2435 11854982 lc->cu.intra_split_flag = 0;
2436
2437 11854982 SAMPLE_CTB(l->skip_flag, x_cb, y_cb) = 0;
2438
2/2
✓ Branch 0 taken 47419928 times.
✓ Branch 1 taken 11854982 times.
59274910 for (x = 0; x < 4; x++)
2439 47419928 lc->pu.intra_pred_mode[x] = 1;
2440
2/2
✓ Branch 0 taken 211788 times.
✓ Branch 1 taken 11643194 times.
11854982 if (pps->transquant_bypass_enable_flag) {
2441 211788 lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(lc);
2442
2/2
✓ Branch 0 taken 92187 times.
✓ Branch 1 taken 119601 times.
211788 if (lc->cu.cu_transquant_bypass_flag)
2443 92187 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size);
2444 } else
2445 11643194 lc->cu.cu_transquant_bypass_flag = 0;
2446
2447
2/2
✓ Branch 0 taken 8656190 times.
✓ Branch 1 taken 3198792 times.
11854982 if (s->sh.slice_type != HEVC_SLICE_I) {
2448 8656190 const int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2449 8656190 const int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2450 8656190 uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, l->skip_flag,
2451 x0b, y0b, x_cb, y_cb,
2452 min_cb_width);
2453
2454 8656190 x = y_cb * min_cb_width + x_cb;
2455
2/2
✓ Branch 0 taken 17970775 times.
✓ Branch 1 taken 8656190 times.
26626965 for (y = 0; y < length; y++) {
2456 17970775 memset(&l->skip_flag[x], skip_flag, length);
2457 17970775 x += min_cb_width;
2458 }
2459
2/2
✓ Branch 0 taken 4110592 times.
✓ Branch 1 taken 4545598 times.
8656190 lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER;
2460 } else {
2461 3198792 x = y_cb * min_cb_width + x_cb;
2462
2/2
✓ Branch 0 taken 4320977 times.
✓ Branch 1 taken 3198792 times.
7519769 for (y = 0; y < length; y++) {
2463 4320977 memset(&l->skip_flag[x], 0, length);
2464 4320977 x += min_cb_width;
2465 }
2466 }
2467
2468
2/2
✓ Branch 0 taken 4110592 times.
✓ Branch 1 taken 7744390 times.
11854982 if (SAMPLE_CTB(l->skip_flag, x_cb, y_cb)) {
2469 4110592 hls_prediction_unit(lc, l, pps, sps,
2470 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2471 4110592 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2472
2473
2/2
✓ Branch 0 taken 3964079 times.
✓ Branch 1 taken 146513 times.
4110592 if (!s->sh.disable_deblocking_filter_flag)
2474 3964079 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2475 } else {
2476 7744390 int pcm_flag = 0;
2477
2478
2/2
✓ Branch 0 taken 4545598 times.
✓ Branch 1 taken 3198792 times.
7744390 if (s->sh.slice_type != HEVC_SLICE_I)
2479 4545598 lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc);
2480
2/2
✓ Branch 0 taken 4358125 times.
✓ Branch 1 taken 3386265 times.
7744390 if (lc->cu.pred_mode != MODE_INTRA ||
2481
2/2
✓ Branch 0 taken 3293547 times.
✓ Branch 1 taken 1064578 times.
4358125 log2_cb_size == sps->log2_min_cb_size) {
2482 6679812 lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size);
2483
2/2
✓ Branch 0 taken 1391562 times.
✓ Branch 1 taken 5288250 times.
8071374 lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
2484
2/2
✓ Branch 0 taken 1283790 times.
✓ Branch 1 taken 107772 times.
1391562 lc->cu.pred_mode == MODE_INTRA;
2485 }
2486
2487
2/2
✓ Branch 0 taken 4358125 times.
✓ Branch 1 taken 3386265 times.
7744390 if (lc->cu.pred_mode == MODE_INTRA) {
2488
4/4
✓ Branch 0 taken 3074335 times.
✓ Branch 1 taken 1283790 times.
✓ Branch 2 taken 162684 times.
✓ Branch 3 taken 2911651 times.
4358125 if (lc->cu.part_mode == PART_2Nx2N && sps->pcm_enabled &&
2489
2/2
✓ Branch 0 taken 160815 times.
✓ Branch 1 taken 1869 times.
162684 log2_cb_size >= sps->pcm.log2_min_pcm_cb_size &&
2490
2/2
✓ Branch 0 taken 153183 times.
✓ Branch 1 taken 7632 times.
160815 log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) {
2491 153183 pcm_flag = ff_hevc_pcm_flag_decode(lc);
2492 }
2493
2/2
✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 4345692 times.
4358125 if (pcm_flag) {
2494 12433 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2495 12433 ret = hls_pcm_sample(lc, l, pps, x0, y0, log2_cb_size);
2496
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12425 times.
12433 if (sps->pcm_loop_filter_disabled)
2497 8 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size);
2498
2499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
2500 return ret;
2501 } else {
2502 4345692 intra_prediction_unit(lc, l, sps, x0, y0, log2_cb_size);
2503 }
2504 } else {
2505 3386265 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2506
8/9
✓ Branch 0 taken 1939384 times.
✓ Branch 1 taken 462541 times.
✓ Branch 2 taken 565287 times.
✓ Branch 3 taken 67264 times.
✓ Branch 4 taken 58064 times.
✓ Branch 5 taken 100180 times.
✓ Branch 6 taken 85773 times.
✓ Branch 7 taken 107772 times.
✗ Branch 8 not taken.
3386265 switch (lc->cu.part_mode) {
2507 1939384 case PART_2Nx2N:
2508 1939384 hls_prediction_unit(lc, l, pps, sps,
2509 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2510 1939384 break;
2511 462541 case PART_2NxN:
2512 462541 hls_prediction_unit(lc, l, pps, sps,
2513 x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2514 462541 hls_prediction_unit(lc, l, pps, sps,
2515 462541 x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2516 462541 break;
2517 565287 case PART_Nx2N:
2518 565287 hls_prediction_unit(lc, l, pps, sps,
2519 x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2520 565287 hls_prediction_unit(lc, l, pps, sps,
2521 565287 x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2522 565287 break;
2523 67264 case PART_2NxnU:
2524 67264 hls_prediction_unit(lc, l, pps, sps,
2525 x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
2526 67264 hls_prediction_unit(lc, l, pps, sps,
2527 67264 x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
2528 67264 break;
2529 58064 case PART_2NxnD:
2530 58064 hls_prediction_unit(lc, l, pps, sps,
2531 58064 x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
2532 58064 hls_prediction_unit(lc, l, pps, sps,
2533 58064 x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
2534 58064 break;
2535 100180 case PART_nLx2N:
2536 100180 hls_prediction_unit(lc, l, pps, sps,
2537 x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
2538 100180 hls_prediction_unit(lc, l, pps, sps,
2539 100180 x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2540 100180 break;
2541 85773 case PART_nRx2N:
2542 85773 hls_prediction_unit(lc, l, pps, sps,
2543 85773 x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
2544 85773 hls_prediction_unit(lc, l, pps, sps,
2545 85773 x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2546 85773 break;
2547 107772 case PART_NxN:
2548 107772 hls_prediction_unit(lc, l, pps, sps,
2549 x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
2550 107772 hls_prediction_unit(lc, l, pps, sps,
2551 107772 x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2552 107772 hls_prediction_unit(lc, l, pps, sps,
2553 107772 x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2554 107772 hls_prediction_unit(lc, l, pps, sps,
2555 107772 x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2556 107772 break;
2557 }
2558 }
2559
2560
2/2
✓ Branch 0 taken 7731957 times.
✓ Branch 1 taken 12433 times.
7744390 if (!pcm_flag) {
2561 7731957 int rqt_root_cbf = 1;
2562
2563
2/2
✓ Branch 0 taken 3386265 times.
✓ Branch 1 taken 4345692 times.
7731957 if (lc->cu.pred_mode != MODE_INTRA &&
2564
4/4
✓ Branch 0 taken 1939384 times.
✓ Branch 1 taken 1446881 times.
✓ Branch 2 taken 1060770 times.
✓ Branch 3 taken 878614 times.
3386265 !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) {
2565 2507651 rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc);
2566 }
2567
2/2
✓ Branch 0 taken 6350447 times.
✓ Branch 1 taken 1381510 times.
7731957 if (rqt_root_cbf) {
2568 const static int cbf[2] = { 0 };
2569
2/2
✓ Branch 0 taken 4345692 times.
✓ Branch 1 taken 2004755 times.
6350447 lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ?
2570 4345692 sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
2571 2004755 sps->max_transform_hierarchy_depth_inter;
2572 6350447 ret = hls_transform_tree(lc, l, pps, sps, x0, y0, x0, y0, x0, y0,
2573 log2_cb_size,
2574 log2_cb_size, 0, 0, cbf, cbf);
2575
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6350446 times.
6350447 if (ret < 0)
2576 1 return ret;
2577 } else {
2578
2/2
✓ Branch 0 taken 1325078 times.
✓ Branch 1 taken 56432 times.
1381510 if (!s->sh.disable_deblocking_filter_flag)
2579 1325078 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2580 }
2581 }
2582 }
2583
2584
4/4
✓ Branch 0 taken 2148729 times.
✓ Branch 1 taken 9706252 times.
✓ Branch 2 taken 828478 times.
✓ Branch 3 taken 1320251 times.
11854981 if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
2585 828478 ff_hevc_set_qPy(lc, l, pps, x0, y0, log2_cb_size);
2586
2587 11854981 x = y_cb * min_cb_width + x_cb;
2588
2/2
✓ Branch 0 taken 22291751 times.
✓ Branch 1 taken 11854981 times.
34146732 for (y = 0; y < length; y++) {
2589 22291751 memset(&l->qp_y_tab[x], lc->qp_y, length);
2590 22291751 x += min_cb_width;
2591 }
2592
2593
2/2
✓ Branch 0 taken 4118601 times.
✓ Branch 1 taken 7736380 times.
11854981 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2594
2/2
✓ Branch 0 taken 2453275 times.
✓ Branch 1 taken 1665326 times.
4118601 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2595 2453275 lc->qPy_pred = lc->qp_y;
2596 }
2597
2598 11854981 set_ct_depth(sps, l->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth);
2599
2600 11854981 return 0;
2601 }
2602
2603 15435083 static int hls_coding_quadtree(HEVCLocalContext *lc,
2604 const HEVCLayerContext *l,
2605 const HEVCPPS *pps, const HEVCSPS *sps,
2606 int x0, int y0,
2607 int log2_cb_size, int cb_depth)
2608 {
2609 15435083 const HEVCContext *const s = lc->parent;
2610 15435083 const int cb_size = 1 << log2_cb_size;
2611 int ret;
2612 int split_cu;
2613
2614 15435083 lc->ct_depth = cb_depth;
2615
2/2
✓ Branch 0 taken 15406120 times.
✓ Branch 1 taken 28963 times.
15435083 if (x0 + cb_size <= sps->width &&
2616
2/2
✓ Branch 0 taken 15082196 times.
✓ Branch 1 taken 323924 times.
15406120 y0 + cb_size <= sps->height &&
2617
2/2
✓ Branch 0 taken 8165934 times.
✓ Branch 1 taken 6916262 times.
15082196 log2_cb_size > sps->log2_min_cb_size) {
2618 8165934 split_cu = ff_hevc_split_coding_unit_flag_decode(lc, l->tab_ct_depth,
2619 sps, cb_depth, x0, y0);
2620 } else {
2621 7269149 split_cu = (log2_cb_size > sps->log2_min_cb_size);
2622 }
2623
2/2
✓ Branch 0 taken 2779253 times.
✓ Branch 1 taken 12655830 times.
15435083 if (pps->cu_qp_delta_enabled_flag &&
2624
2/2
✓ Branch 0 taken 1613411 times.
✓ Branch 1 taken 1165842 times.
2779253 log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) {
2625 1613411 lc->tu.is_cu_qp_delta_coded = 0;
2626 1613411 lc->tu.cu_qp_delta = 0;
2627 }
2628
2629
2/2
✓ Branch 0 taken 519326 times.
✓ Branch 1 taken 14915757 times.
15435083 if (s->sh.cu_chroma_qp_offset_enabled_flag &&
2630
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) {
2631 519326 lc->tu.is_cu_chroma_qp_offset_coded = 0;
2632 }
2633
2634
2/2
✓ Branch 0 taken 3580101 times.
✓ Branch 1 taken 11854982 times.
15435083 if (split_cu) {
2635 3580101 int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2636 3580101 const int cb_size_split = cb_size >> 1;
2637 3580101 const int x1 = x0 + cb_size_split;
2638 3580101 const int y1 = y0 + cb_size_split;
2639
2640 3580101 int more_data = 0;
2641
2642 3580101 more_data = hls_coding_quadtree(lc, l, pps, sps,
2643 x0, y0, log2_cb_size - 1, cb_depth + 1);
2644
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3580099 times.
3580101 if (more_data < 0)
2645 2 return more_data;
2646
2647
4/4
✓ Branch 0 taken 3580090 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3552149 times.
✓ Branch 3 taken 27941 times.
3580099 if (more_data && x1 < sps->width) {
2648 3552149 more_data = hls_coding_quadtree(lc, l, pps, sps,
2649 x1, y0, log2_cb_size - 1, cb_depth + 1);
2650
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3552149 times.
3552149 if (more_data < 0)
2651 return more_data;
2652 }
2653
4/4
✓ Branch 0 taken 3569678 times.
✓ Branch 1 taken 10421 times.
✓ Branch 2 taken 3366997 times.
✓ Branch 3 taken 202681 times.
3580099 if (more_data && y1 < sps->height) {
2654 3366997 more_data = hls_coding_quadtree(lc, l, pps, sps,
2655 x0, y1, log2_cb_size - 1, cb_depth + 1);
2656
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3366997 times.
3366997 if (more_data < 0)
2657 return more_data;
2658 }
2659
4/4
✓ Branch 0 taken 3563555 times.
✓ Branch 1 taken 16544 times.
✓ Branch 2 taken 3541737 times.
✓ Branch 3 taken 21818 times.
3580099 if (more_data && x1 < sps->width &&
2660
2/2
✓ Branch 0 taken 3339056 times.
✓ Branch 1 taken 202681 times.
3541737 y1 < sps->height) {
2661 3339056 more_data = hls_coding_quadtree(lc, l, pps, sps,
2662 x1, y1, log2_cb_size - 1, cb_depth + 1);
2663
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3339055 times.
3339056 if (more_data < 0)
2664 1 return more_data;
2665 }
2666
2667
2/2
✓ Branch 0 taken 2025951 times.
✓ Branch 1 taken 1554147 times.
3580098 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2668
2/2
✓ Branch 0 taken 1514306 times.
✓ Branch 1 taken 511645 times.
2025951 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2669 1514306 lc->qPy_pred = lc->qp_y;
2670
2671
2/2
✓ Branch 0 taken 3544022 times.
✓ Branch 1 taken 36076 times.
3580098 if (more_data)
2672
2/2
✓ Branch 0 taken 96618 times.
✓ Branch 1 taken 3447404 times.
3640640 return ((x1 + cb_size_split) < sps->width ||
2673
2/2
✓ Branch 0 taken 96617 times.
✓ Branch 1 taken 1 times.
96618 (y1 + cb_size_split) < sps->height);
2674 else
2675 36076 return 0;
2676 } else {
2677 11854982 ret = hls_coding_unit(lc, s, l, pps, sps, x0, y0, log2_cb_size);
2678
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11854981 times.
11854982 if (ret < 0)
2679 1 return ret;
2680 11854981 if ((!((x0 + cb_size) %
2681
2/2
✓ Branch 0 taken 8577259 times.
✓ Branch 1 taken 3277722 times.
11854981 (1 << (sps->log2_ctb_size))) ||
2682
2/2
✓ Branch 0 taken 71449 times.
✓ Branch 1 taken 8505810 times.
8577259 (x0 + cb_size >= sps->width)) &&
2683 3349171 (!((y0 + cb_size) %
2684
2/2
✓ Branch 0 taken 1851434 times.
✓ Branch 1 taken 1497737 times.
3349171 (1 << (sps->log2_ctb_size))) ||
2685
2/2
✓ Branch 0 taken 99042 times.
✓ Branch 1 taken 1752392 times.
1851434 (y0 + cb_size >= sps->height))) {
2686 1596779 int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc);
2687 1596779 return !end_of_slice_flag;
2688 } else {
2689 10258202 return 1;
2690 }
2691 }
2692
2693 return 0;
2694 }
2695
2696 1596780 static void hls_decode_neighbour(HEVCLocalContext *lc,
2697 const HEVCLayerContext *l,
2698 const HEVCPPS *pps, const HEVCSPS *sps,
2699 int x_ctb, int y_ctb, int ctb_addr_ts)
2700 {
2701 1596780 const HEVCContext *const s = lc->parent;
2702 1596780 int ctb_size = 1 << sps->log2_ctb_size;
2703 1596780 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2704 1596780 int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
2705
2706 1596780 l->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
2707
2708
2/2
✓ Branch 0 taken 167314 times.
✓ Branch 1 taken 1429466 times.
1596780 if (pps->entropy_coding_sync_enabled_flag) {
2709
3/4
✓ Branch 0 taken 7469 times.
✓ Branch 1 taken 159845 times.
✓ Branch 2 taken 7469 times.
✗ Branch 3 not taken.
167314 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2710 7469 lc->first_qp_group = 1;
2711 167314 lc->end_of_tiles_x = sps->width;
2712
2/2
✓ Branch 0 taken 293730 times.
✓ Branch 1 taken 1135736 times.
1429466 } else if (pps->tiles_enabled_flag) {
2713
4/4
✓ Branch 0 taken 293102 times.
✓ Branch 1 taken 628 times.
✓ Branch 2 taken 6289 times.
✓ Branch 3 taken 286813 times.
293730 if (ctb_addr_ts && pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
2714 6289 int idxX = pps->col_idxX[x_ctb >> sps->log2_ctb_size];
2715 6289 lc->end_of_tiles_x = x_ctb + (pps->column_width[idxX] << sps->log2_ctb_size);
2716 6289 lc->first_qp_group = 1;
2717 }
2718 } else {
2719 1135736 lc->end_of_tiles_x = sps->width;
2720 }
2721
2722 1596780 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height);
2723
2724 1596780 lc->boundary_flags = 0;
2725
2/2
✓ Branch 0 taken 293730 times.
✓ Branch 1 taken 1303050 times.
1596780 if (pps->tiles_enabled_flag) {
2726
4/4
✓ Branch 0 taken 281730 times.
✓ Branch 1 taken 12000 times.
✓ Branch 2 taken 30799 times.
✓ Branch 3 taken 250931 times.
293730 if (x_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2727 30799 lc->boundary_flags |= BOUNDARY_LEFT_TILE;
2728
4/4
✓ Branch 0 taken 281730 times.
✓ Branch 1 taken 12000 times.
✓ Branch 2 taken 3787 times.
✓ Branch 3 taken 277943 times.
293730 if (x_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - 1])
2729 3787 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2730
4/4
✓ Branch 0 taken 279002 times.
✓ Branch 1 taken 14728 times.
✓ Branch 2 taken 33781 times.
✓ Branch 3 taken 245221 times.
293730 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]])
2731 33781 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
2732
4/4
✓ Branch 0 taken 279002 times.
✓ Branch 1 taken 14728 times.
✓ Branch 2 taken 14490 times.
✓ Branch 3 taken 264512 times.
293730 if (y_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - sps->ctb_width])
2733 14490 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2734 } else {
2735
2/2
✓ Branch 0 taken 18349 times.
✓ Branch 1 taken 1284701 times.
1303050 if (ctb_addr_in_slice <= 0)
2736 18349 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2737
2/2
✓ Branch 0 taken 197532 times.
✓ Branch 1 taken 1105518 times.
1303050 if (ctb_addr_in_slice < sps->ctb_width)
2738 197532 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2739 }
2740
2741
6/6
✓ Branch 0 taken 1514607 times.
✓ Branch 1 taken 82173 times.
✓ Branch 2 taken 1506716 times.
✓ Branch 3 taken 7891 times.
✓ Branch 4 taken 1476947 times.
✓ Branch 5 taken 29769 times.
1596780 lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
2742
6/6
✓ Branch 0 taken 1464689 times.
✓ Branch 1 taken 132091 times.
✓ Branch 2 taken 1370859 times.
✓ Branch 3 taken 93830 times.
✓ Branch 4 taken 1350739 times.
✓ Branch 5 taken 20120 times.
1596780 lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
2743
6/6
✓ Branch 0 taken 1464689 times.
✓ Branch 1 taken 132091 times.
✓ Branch 2 taken 1373448 times.
✓ Branch 3 taken 91241 times.
✓ Branch 4 taken 1317608 times.
✓ Branch 5 taken 55840 times.
1596780 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]]));
2744
8/8
✓ Branch 0 taken 1514607 times.
✓ Branch 1 taken 82173 times.
✓ Branch 2 taken 1392799 times.
✓ Branch 3 taken 121808 times.
✓ Branch 4 taken 1304031 times.
✓ Branch 5 taken 88768 times.
✓ Branch 6 taken 1259757 times.
✓ Branch 7 taken 44274 times.
1596780 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]]));
2745 1596780 }
2746
2747 28279 static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
2748 {
2749 28279 HEVCLocalContext *const lc = &s->local_ctx[0];
2750 28279 const HEVCLayerContext *const l = &s->layers[s->cur_layer];
2751 28279 const HEVCPPS *const pps = s->pps;
2752 28279 const HEVCSPS *const sps = pps->sps;
2753 28279 const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
2754 28279 const size_t slice_size = gb->buffer_end - gb->buffer - s->sh.data_offset;
2755 28279 int ctb_size = 1 << sps->log2_ctb_size;
2756 28279 int more_data = 1;
2757 28279 int x_ctb = 0;
2758 28279 int y_ctb = 0;
2759 28279 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
2760 int ret;
2761
2762
3/4
✓ Branch 0 taken 1596780 times.
✓ Branch 1 taken 28278 times.
✓ Branch 2 taken 1596780 times.
✗ Branch 3 not taken.
1625058 while (more_data && ctb_addr_ts < sps->ctb_size) {
2763 1596780 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2764
2765 1596780 x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2766 1596780 y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2767 1596780 hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
2768
2769 1596780 ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 0);
2770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1596780 times.
1596780 if (ret < 0) {
2771 l->tab_slice_address[ctb_addr_rs] = -1;
2772 return ret;
2773 }
2774
2775 1596780 hls_sao_param(lc, l, pps, sps,
2776 1596780 x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
2777
2778 1596780 l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2779 1596780 l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2780 1596780 l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2781
2782 1596780 more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
2783
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1596779 times.
1596780 if (more_data < 0) {
2784 1 l->tab_slice_address[ctb_addr_rs] = -1;
2785 1 return more_data;
2786 }
2787
2788
2789 1596779 ctb_addr_ts++;
2790 1596779 ff_hevc_save_states(lc, pps, ctb_addr_ts);
2791 1596779 ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size);
2792 }
2793
2794
2/2
✓ Branch 0 taken 14766 times.
✓ Branch 1 taken 13512 times.
28278 if (x_ctb + ctb_size >= sps->width &&
2795
2/2
✓ Branch 0 taken 10282 times.
✓ Branch 1 taken 4484 times.
14766 y_ctb + ctb_size >= sps->height)
2796 10282 ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size);
2797
2798 28278 return ctb_addr_ts;
2799 }
2800
2801 static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist,
2802 int job, int thread)
2803 {
2804 HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread];
2805 const HEVCContext *const s = lc->parent;
2806 const HEVCLayerContext *const l = &s->layers[s->cur_layer];
2807 const HEVCPPS *const pps = s->pps;
2808 const HEVCSPS *const sps = pps->sps;
2809 int ctb_size = 1 << sps->log2_ctb_size;
2810 int more_data = 1;
2811 int ctb_row = job;
2812 int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size);
2813 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2814
2815 const uint8_t *data = s->data + s->sh.offset[ctb_row];
2816 const size_t data_size = s->sh.size[ctb_row];
2817
2818 int progress = 0;
2819
2820 int ret;
2821
2822 if (ctb_row)
2823 ff_init_cabac_decoder(&lc->cc, data, data_size);
2824
2825 while(more_data && ctb_addr_ts < sps->ctb_size) {
2826 int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size;
2827 int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size;
2828
2829 hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
2830
2831 if (ctb_row)
2832 ff_thread_progress_await(&s->wpp_progress[ctb_row - 1],
2833 progress + SHIFT_CTB_WPP + 1);
2834
2835 /* atomic_load's prototype requires a pointer to non-const atomic variable
2836 * (due to implementations via mutexes, where reads involve writes).
2837 * Of course, casting const away here is nevertheless safe. */
2838 if (atomic_load((atomic_int*)&s->wpp_err)) {
2839 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2840 return 0;
2841 }
2842
2843 ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1);
2844 if (ret < 0)
2845 goto error;
2846 hls_sao_param(lc, l, pps, sps,
2847 x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
2848
2849 l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2850 l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2851 l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2852
2853 more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
2854
2855 if (more_data < 0) {
2856 ret = more_data;
2857 goto error;
2858 }
2859
2860 ctb_addr_ts++;
2861
2862 ff_hevc_save_states(lc, pps, ctb_addr_ts);
2863 ff_thread_progress_report(&s->wpp_progress[ctb_row], ++progress);
2864 ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size);
2865
2866 if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) {
2867 /* Casting const away here is safe, because it is an atomic operation. */
2868 atomic_store((atomic_int*)&s->wpp_err, 1);
2869 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2870 return 0;
2871 }
2872
2873 if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) {
2874 ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size);
2875 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2876 return ctb_addr_ts;
2877 }
2878 ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2879 x_ctb+=ctb_size;
2880
2881 if(x_ctb >= sps->width) {
2882 break;
2883 }
2884 }
2885 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2886
2887 return 0;
2888 error:
2889 l->tab_slice_address[ctb_addr_rs] = -1;
2890 /* Casting const away here is safe, because it is an atomic operation. */
2891 atomic_store((atomic_int*)&s->wpp_err, 1);
2892 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2893 return ret;
2894 }
2895
2896 static int wpp_progress_init(HEVCContext *s, unsigned count)
2897 {
2898 if (s->nb_wpp_progress < count) {
2899 void *tmp = av_realloc_array(s->wpp_progress, count,
2900 sizeof(*s->wpp_progress));
2901 if (!tmp)
2902 return AVERROR(ENOMEM);
2903
2904 s->wpp_progress = tmp;
2905 memset(s->wpp_progress + s->nb_wpp_progress, 0,
2906 (count - s->nb_wpp_progress) * sizeof(*s->wpp_progress));
2907
2908 for (int i = s->nb_wpp_progress; i < count; i++) {
2909 int ret = ff_thread_progress_init(&s->wpp_progress[i], 1);
2910 if (ret < 0)
2911 return ret;
2912 s->nb_wpp_progress = i + 1;
2913 }
2914 }
2915
2916 for (int i = 0; i < count; i++)
2917 ff_thread_progress_reset(&s->wpp_progress[i]);
2918
2919 return 0;
2920 }
2921
2922 static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
2923 {
2924 const HEVCPPS *const pps = s->pps;
2925 const HEVCSPS *const sps = pps->sps;
2926 const uint8_t *data = nal->data;
2927 int length = nal->size;
2928 int *ret;
2929 int64_t offset;
2930 int64_t startheader, cmpt = 0;
2931 int i, j, res = 0;
2932
2933 if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * sps->ctb_width >= sps->ctb_width * sps->ctb_height) {
2934 av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
2935 s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets,
2936 sps->ctb_width, sps->ctb_height
2937 );
2938 return AVERROR_INVALIDDATA;
2939 }
2940
2941 if (s->avctx->thread_count > s->nb_local_ctx) {
2942 HEVCLocalContext *tmp = av_malloc_array(s->avctx->thread_count, sizeof(*s->local_ctx));
2943
2944 if (!tmp)
2945 return AVERROR(ENOMEM);
2946
2947 memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx);
2948 av_free(s->local_ctx);
2949 s->local_ctx = tmp;
2950
2951 for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) {
2952 tmp = &s->local_ctx[i];
2953
2954 memset(tmp, 0, sizeof(*tmp));
2955
2956 tmp->logctx = s->avctx;
2957 tmp->parent = s;
2958 tmp->common_cabac_state = &s->cabac;
2959 }
2960
2961 s->nb_local_ctx = s->avctx->thread_count;
2962 }
2963
2964 offset = s->sh.data_offset;
2965
2966 for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2967 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2968 startheader--;
2969 cmpt++;
2970 }
2971 }
2972
2973 for (i = 1; i < s->sh.num_entry_point_offsets; i++) {
2974 offset += (s->sh.entry_point_offset[i - 1] - cmpt);
2975 for (j = 0, cmpt = 0, startheader = offset
2976 + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) {
2977 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2978 startheader--;
2979 cmpt++;
2980 }
2981 }
2982 s->sh.size[i] = s->sh.entry_point_offset[i] - cmpt;
2983 s->sh.offset[i] = offset;
2984
2985 }
2986
2987 offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt;
2988 if (length < offset) {
2989 av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n");
2990 return AVERROR_INVALIDDATA;
2991 }
2992 s->sh.size [s->sh.num_entry_point_offsets] = length - offset;
2993 s->sh.offset[s->sh.num_entry_point_offsets] = offset;
2994
2995 s->sh.offset[0] = s->sh.data_offset;
2996 s->sh.size[0] = s->sh.offset[1] - s->sh.offset[0];
2997
2998 s->data = data;
2999
3000 for (i = 1; i < s->nb_local_ctx; i++) {
3001 s->local_ctx[i].first_qp_group = 1;
3002 s->local_ctx[i].qp_y = s->local_ctx[0].qp_y;
3003 }
3004
3005 atomic_store(&s->wpp_err, 0);
3006 res = wpp_progress_init(s, s->sh.num_entry_point_offsets + 1);
3007 if (res < 0)
3008 return res;
3009
3010 ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret));
3011 if (!ret)
3012 return AVERROR(ENOMEM);
3013
3014 if (pps->entropy_coding_sync_enabled_flag)
3015 s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->local_ctx, ret, s->sh.num_entry_point_offsets + 1);
3016
3017 for (i = 0; i <= s->sh.num_entry_point_offsets; i++)
3018 res += ret[i];
3019
3020 av_free(ret);
3021 return res;
3022 }
3023
3024 28279 static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l,
3025 const H2645NAL *nal, GetBitContext *gb)
3026 {
3027 28279 const HEVCPPS *pps = s->pps;
3028 int ret;
3029
3030
2/2
✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10283 times.
28279 if (!s->sh.first_slice_in_pic_flag)
3031 17996 s->slice_idx += !s->sh.dependent_slice_segment_flag;
3032
3033
4/4
✓ Branch 0 taken 20332 times.
✓ Branch 1 taken 7947 times.
✓ Branch 2 taken 19077 times.
✓ Branch 3 taken 1255 times.
28279 if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) {
3034 19077 ret = ff_hevc_slice_rpl(s);
3035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19077 times.
19077 if (ret < 0) {
3036 av_log(s->avctx, AV_LOG_WARNING,
3037 "Error constructing the reference lists for the current slice.\n");
3038 return ret;
3039 }
3040 }
3041
3042 28279 s->slice_initialized = 1;
3043
3044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28279 times.
28279 if (s->avctx->hwaccel)
3045 return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size);
3046
3047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28279 times.
28279 if (s->avctx->profile == AV_PROFILE_HEVC_SCC) {
3048 av_log(s->avctx, AV_LOG_ERROR,
3049 "SCC profile is not yet implemented in hevc native decoder.\n");
3050 return AVERROR_PATCHWELCOME;
3051 }
3052
3053
2/2
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20332 times.
28279 if (s->sh.dependent_slice_segment_flag) {
3054 7947 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
3055 7947 int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
3056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
7947 if (l->tab_slice_address[prev_rs] != s->sh.slice_addr) {
3057 av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
3058 return AVERROR_INVALIDDATA;
3059 }
3060 }
3061
3062 28279 s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
3063
3064
2/2
✓ Branch 0 taken 23190 times.
✓ Branch 1 taken 5089 times.
28279 if (!pps->cu_qp_delta_enabled_flag)
3065 23190 s->local_ctx[0].qp_y = s->sh.slice_qp;
3066
3067 28279 s->local_ctx[0].tu.cu_qp_offset_cb = 0;
3068 28279 s->local_ctx[0].tu.cu_qp_offset_cr = 0;
3069
3070
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28279 times.
28279 if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
3071 s->sh.num_entry_point_offsets > 0 &&
3072 pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
3073 return hls_slice_data_wpp(s, nal);
3074
3075 28279 return hls_decode_entry(s, gb);
3076 }
3077
3078 10283 static int set_side_data(HEVCContext *s)
3079 {
3080 10283 const HEVCSPS *sps = s->cur_frame->pps->sps;
3081 10283 AVFrame *out = s->cur_frame->f;
3082 int ret;
3083
3084 // Decrement the mastering display and content light level flag when IRAP
3085 // frame has no_rasl_output_flag=1 so the side data persists for the entire
3086 // coded video sequence.
3087
5/6
✓ Branch 0 taken 730 times.
✓ Branch 1 taken 9553 times.
✓ Branch 2 taken 730 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 447 times.
✓ Branch 5 taken 283 times.
10283 if (IS_IRAP(s) && s->no_rasl_output_flag) {
3088
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 437 times.
447 if (s->sei.common.mastering_display.present > 0)
3089 10 s->sei.common.mastering_display.present--;
3090
3091
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 439 times.
447 if (s->sei.common.content_light.present > 0)
3092 8 s->sei.common.content_light.present--;
3093 }
3094
3095 10283 ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx,
3096 &sps->vui.common,
3097 10283 sps->bit_depth, sps->bit_depth_chroma,
3098 10283 s->cur_frame->poc /* no poc_offset in HEVC */);
3099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (ret < 0)
3100 return ret;
3101
3102
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 10260 times.
10283 if (s->sei.timecode.present) {
3103 uint32_t *tc_sd;
3104 char tcbuf[AV_TIMECODE_STR_SIZE];
3105 AVFrameSideData *tcside;
3106 23 ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE,
3107 sizeof(uint32_t) * 4, &tcside);
3108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (ret < 0)
3109 return ret;
3110
3111
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 if (tcside) {
3112 23 tc_sd = (uint32_t*)tcside->data;
3113 23 tc_sd[0] = s->sei.timecode.num_clock_ts;
3114
3115
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 23 times.
46 for (int i = 0; i < tc_sd[0]; i++) {
3116 23 int drop = s->sei.timecode.cnt_dropped_flag[i];
3117 23 int hh = s->sei.timecode.hours_value[i];
3118 23 int mm = s->sei.timecode.minutes_value[i];
3119 23 int ss = s->sei.timecode.seconds_value[i];
3120 23 int ff = s->sei.timecode.n_frames[i];
3121
3122 23 tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff);
3123 23 av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0);
3124 23 av_dict_set(&out->metadata, "timecode", tcbuf, 0);
3125 }
3126 }
3127
3128 23 s->sei.timecode.num_clock_ts = 0;
3129 }
3130
3131
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 10277 times.
10283 if (s->sei.common.dynamic_hdr_plus.info) {
3132 6 AVBufferRef *info_ref = av_buffer_ref(s->sei.common.dynamic_hdr_plus.info);
3133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!info_ref)
3134 return AVERROR(ENOMEM);
3135
3136 6 ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref);
3137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ret < 0)
3138 return ret;
3139 }
3140
3141
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10281 times.
10283 if (s->rpu_buf) {
3142 2 AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf);
3143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!rpu)
3144 return AVERROR(ENOMEM);
3145
3146 2 s->rpu_buf = NULL;
3147 }
3148
3149
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10283 times.
10283 if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0)
3150 return ret;
3151
3152
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10281 times.
10283 if (s->sei.common.dynamic_hdr_vivid.info) {
3153
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,
3154 AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
3155 &s->sei.common.dynamic_hdr_vivid.info,
3156 AV_FRAME_SIDE_DATA_FLAG_NEW_REF))
3157 return AVERROR(ENOMEM);
3158 }
3159
3160 10283 return 0;
3161 }
3162
3163 9956 static int find_finish_setup_nal(const HEVCContext *s)
3164 {
3165 9956 int nal_idx = 0;
3166
3167
2/2
✓ Branch 0 taken 38899 times.
✓ Branch 1 taken 9956 times.
48855 for (int i = nal_idx; i < s->pkt.nb_nals; i++) {
3168 38899 const H2645NAL *nal = &s->pkt.nals[i];
3169 38899 const int layer_id = nal->nuh_layer_id;
3170 38899 GetBitContext gb = nal->gb;
3171
3172
2/4
✓ Branch 0 taken 38899 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38899 times.
✗ Branch 3 not taken.
38899 if (layer_id > HEVC_MAX_NUH_LAYER_ID || s->vps->layer_idx[layer_id] < 0 ||
3173
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 38883 times.
38899 !(s->layers_active_decode & (1 << s->vps->layer_idx[layer_id])))
3174 18012 continue;
3175
3176
3/3
✓ Branch 0 taken 28280 times.
✓ Branch 1 taken 2279 times.
✓ Branch 2 taken 8324 times.
38883 switch (nal->type) {
3177 28280 case HEVC_NAL_TRAIL_R:
3178 case HEVC_NAL_TRAIL_N:
3179 case HEVC_NAL_TSA_N:
3180 case HEVC_NAL_TSA_R:
3181 case HEVC_NAL_STSA_N:
3182 case HEVC_NAL_STSA_R:
3183 case HEVC_NAL_BLA_W_LP:
3184 case HEVC_NAL_BLA_W_RADL:
3185 case HEVC_NAL_BLA_N_LP:
3186 case HEVC_NAL_IDR_W_RADL:
3187 case HEVC_NAL_IDR_N_LP:
3188 case HEVC_NAL_CRA_NUT:
3189 case HEVC_NAL_RADL_N:
3190 case HEVC_NAL_RADL_R:
3191 case HEVC_NAL_RASL_N:
3192 case HEVC_NAL_RASL_R:
3193
2/2
✓ Branch 1 taken 17996 times.
✓ Branch 2 taken 10284 times.
28280 if (!get_bits1(&gb)) // first_slice_segment_in_pic_flag
3194 17996 continue;
3195 case HEVC_NAL_VPS:
3196 case HEVC_NAL_SPS:
3197 case HEVC_NAL_PPS:
3198 12563 nal_idx = i;
3199 12563 break;
3200 }
3201 }
3202
3203 9956 return nal_idx;
3204 }
3205
3206 10283 static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l,
3207 unsigned nal_idx)
3208 {
3209 10283 const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id];
3210 10283 const HEVCSPS *const sps = pps->sps;
3211 10283 int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) *
3212 10283 ((sps->height >> sps->log2_min_cb_size) + 1);
3213
2/2
✓ Branch 0 taken 9956 times.
✓ Branch 1 taken 327 times.
20239 int new_sequence = (l == &s->layers[0]) &&
3214
12/12
✓ Branch 0 taken 9564 times.
✓ Branch 1 taken 392 times.
✓ Branch 2 taken 9540 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 9538 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9531 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9530 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 9 times.
✓ Branch 11 taken 9521 times.
9956 (IS_IDR(s) || IS_BLA(s) || s->last_eos);
3215 10283 int prev_layers_active_decode = s->layers_active_decode;
3216 10283 int prev_layers_active_output = s->layers_active_output;
3217 int ret;
3218
3219
3/4
✓ Branch 0 taken 408 times.
✓ Branch 1 taken 9875 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 408 times.
10283 if (sps->vps != s->vps && l != &s->layers[0]) {
3220 av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n");
3221 set_sps(s, l, NULL);
3222 return AVERROR_INVALIDDATA;
3223 }
3224
3225 10283 av_refstruct_replace(&s->pps, pps);
3226
2/2
✓ Branch 0 taken 423 times.
✓ Branch 1 taken 9860 times.
10283 if (l->sps != sps) {
3227 423 const HEVCSPS *sps_base = s->layers[0].sps;
3228 423 enum AVPixelFormat pix_fmt = sps->pix_fmt;
3229
3230
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 414 times.
423 if (l != &s->layers[0]) {
3231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!sps_base) {
3232 av_log(s->avctx, AV_LOG_ERROR,
3233 "Access unit starts with a non-base layer frame\n");
3234 return AVERROR_INVALIDDATA;
3235 }
3236
3237 // Files produced by Vision Pro lack VPS extension VUI,
3238 // so the secondary layer has no range information.
3239 // This check avoids failing in such a case.
3240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (sps_base->pix_fmt == AV_PIX_FMT_YUVJ420P &&
3241 sps->pix_fmt == AV_PIX_FMT_YUV420P &&
3242 !sps->vui.common.video_signal_type_present_flag)
3243 pix_fmt = sps_base->pix_fmt;
3244
3245 // Ignore range mismatch between base layer and alpha layer
3246
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8 times.
9 if (ff_hevc_is_alpha_video(s) &&
3247
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 sps_base->pix_fmt == AV_PIX_FMT_YUV420P &&
3248 pix_fmt == AV_PIX_FMT_YUVJ420P)
3249 1 pix_fmt = sps_base->pix_fmt;
3250
3251
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (pix_fmt != sps_base->pix_fmt ||
3252
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 sps->width != sps_base->width ||
3253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 sps->height != sps_base->height) {
3254 av_log(s->avctx, AV_LOG_ERROR,
3255 "Base/non-base layer SPS have unsupported parameter combination\n");
3256 return AVERROR(ENOSYS);
3257 }
3258 }
3259
3260 423 ff_hevc_clear_refs(l);
3261
3262 423 ret = set_sps(s, l, sps);
3263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 423 times.
423 if (ret < 0)
3264 return ret;
3265
3266
2/2
✓ Branch 0 taken 414 times.
✓ Branch 1 taken 9 times.
423 if (l == &s->layers[0]) {
3267 414 export_stream_params(s, sps);
3268
3269 414 ret = get_format(s, sps);
3270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
414 if (ret < 0) {
3271 set_sps(s, l, NULL);
3272 return ret;
3273 }
3274
3275 414 new_sequence = 1;
3276 }
3277 }
3278
3279 10283 memset(l->horizontal_bs, 0, l->bs_width * l->bs_height);
3280 10283 memset(l->vertical_bs, 0, l->bs_width * l->bs_height);
3281 10283 memset(l->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height);
3282 10283 memset(l->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1));
3283 10283 memset(l->tab_slice_address, -1, pic_size_in_ctb * sizeof(*l->tab_slice_address));
3284
3285
4/4
✓ Branch 0 taken 9884 times.
✓ Branch 1 taken 399 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 9855 times.
10283 if (IS_IDR(s))
3286 428 ff_hevc_clear_refs(l);
3287
3288 10283 s->slice_idx = 0;
3289 10283 s->first_nal_type = s->nal_unit_type;
3290 10283 s->poc = s->sh.poc;
3291
3292
3/4
✓ Branch 0 taken 730 times.
✓ Branch 1 taken 9553 times.
✓ Branch 2 taken 730 times.
✗ Branch 3 not taken.
10283 if (IS_IRAP(s)) {
3293
10/10
✓ Branch 0 taken 331 times.
✓ Branch 1 taken 399 times.
✓ Branch 2 taken 302 times.
✓ Branch 3 taken 29 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.
1022 s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) ||
3294
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);
3295 730 s->recovery_poc = HEVC_RECOVERY_END;
3296 }
3297
3298
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 10272 times.
10283 if (s->recovery_poc != HEVC_RECOVERY_END &&
3299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 s->sei.recovery_point.has_recovery_poc) {
3300 if (s->recovery_poc == HEVC_RECOVERY_UNSPECIFIED)
3301 s->recovery_poc = s->poc + s->sei.recovery_point.recovery_poc_cnt;
3302 else if (s->poc >= s->recovery_poc)
3303 s->recovery_poc = HEVC_RECOVERY_END;
3304 }
3305
3306 /* 8.3.1 */
3307
2/2
✓ Branch 0 taken 9941 times.
✓ Branch 1 taken 342 times.
10283 if (s->temporal_id == 0 &&
3308
2/2
✓ Branch 0 taken 7270 times.
✓ Branch 1 taken 2671 times.
9941 s->nal_unit_type != HEVC_NAL_TRAIL_N &&
3309
1/2
✓ Branch 0 taken 7270 times.
✗ Branch 1 not taken.
7270 s->nal_unit_type != HEVC_NAL_TSA_N &&
3310
1/2
✓ Branch 0 taken 7270 times.
✗ Branch 1 not taken.
7270 s->nal_unit_type != HEVC_NAL_STSA_N &&
3311
2/2
✓ Branch 0 taken 7244 times.
✓ Branch 1 taken 26 times.
7270 s->nal_unit_type != HEVC_NAL_RADL_N &&
3312
2/2
✓ Branch 0 taken 7222 times.
✓ Branch 1 taken 22 times.
7244 s->nal_unit_type != HEVC_NAL_RADL_R &&
3313
2/2
✓ Branch 0 taken 6852 times.
✓ Branch 1 taken 370 times.
7222 s->nal_unit_type != HEVC_NAL_RASL_N &&
3314
2/2
✓ Branch 0 taken 6378 times.
✓ Branch 1 taken 474 times.
6852 s->nal_unit_type != HEVC_NAL_RASL_R)
3315 6378 s->poc_tid0 = s->poc;
3316
3317
2/2
✓ Branch 0 taken 628 times.
✓ Branch 1 taken 9655 times.
10283 if (pps->tiles_enabled_flag)
3318 628 s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size;
3319
3320
2/2
✓ Branch 0 taken 438 times.
✓ Branch 1 taken 9845 times.
10283 if (new_sequence) {
3321 438 ret = ff_hevc_output_frames(s, prev_layers_active_decode, prev_layers_active_output,
3322 438 0, 0, s->sh.no_output_of_prior_pics_flag);
3323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 438 times.
438 if (ret < 0)
3324 return ret;
3325 }
3326
3327 10283 ret = export_stream_params_from_sei(s);
3328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (ret < 0)
3329 return ret;
3330
3331 10283 ret = ff_hevc_set_new_ref(s, l, s->poc);
3332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (ret < 0)
3333 goto fail;
3334
3335 10283 ret = ff_hevc_frame_rps(s, l);
3336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (ret < 0) {
3337 av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n");
3338 goto fail;
3339 }
3340
3341
3/4
✓ Branch 0 taken 730 times.
✓ Branch 1 taken 9553 times.
✓ Branch 2 taken 730 times.
✗ Branch 3 not taken.
10283 if (IS_IRAP(s))
3342 730 s->cur_frame->f->flags |= AV_FRAME_FLAG_KEY;
3343 else
3344 9553 s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY;
3345
3346 20566 s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics &&
3347 s->sei.common.film_grain_characteristics->present) ||
3348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 s->sei.common.aom_film_grain.enable) &&
3349
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
20566 !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
3350 !s->avctx->hwaccel;
3351
3352 10283 ret = set_side_data(s);
3353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (ret < 0)
3354 goto fail;
3355
3356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (s->cur_frame->needs_fg &&
3357 (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present &&
3358 !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id,
3359 s->cur_frame->f->format) ||
3360 !av_film_grain_params_select(s->cur_frame->f))) {
3361 av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown,
3362 "Unsupported film grain parameters. Ignoring film grain.\n");
3363 s->cur_frame->needs_fg = 0;
3364 }
3365
3366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (s->cur_frame->needs_fg) {
3367 s->cur_frame->frame_grain->format = s->cur_frame->f->format;
3368 s->cur_frame->frame_grain->width = s->cur_frame->f->width;
3369 s->cur_frame->frame_grain->height = s->cur_frame->f->height;
3370 if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0)
3371 goto fail;
3372
3373 ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f);
3374 if (ret < 0)
3375 goto fail;
3376 }
3377
3378 10283 s->cur_frame->f->pict_type = 3 - s->sh.slice_type;
3379
3380 10283 ret = ff_hevc_output_frames(s, s->layers_active_decode, s->layers_active_output,
3381 10283 sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics,
3382 10283 sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0);
3383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (ret < 0)
3384 goto fail;
3385
3386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (s->avctx->hwaccel) {
3387 AVCodecInternal *avci = s->avctx->internal;
3388 AVPacket *avpkt = avci->in_pkt;
3389 ret = FF_HW_CALL(s->avctx, start_frame,
3390 avpkt->buf, NULL, 0);
3391 if (ret < 0)
3392 goto fail;
3393 }
3394
3395 // after starting the base-layer frame we know which layers will be decoded,
3396 // so we can now figure out which NALUs to wait for before we can call
3397 // ff_thread_finish_setup()
3398
2/2
✓ Branch 0 taken 9956 times.
✓ Branch 1 taken 327 times.
10283 if (l == &s->layers[0])
3399 9956 s->finish_setup_nal_idx = find_finish_setup_nal(s);
3400
3401
2/2
✓ Branch 0 taken 9955 times.
✓ Branch 1 taken 328 times.
10283 if (nal_idx >= s->finish_setup_nal_idx)
3402 9955 ff_thread_finish_setup(s->avctx);
3403
3404 10283 return 0;
3405
3406 fail:
3407 if (l->cur_frame)
3408 ff_hevc_unref_frame(l->cur_frame, ~0);
3409 l->cur_frame = NULL;
3410 s->cur_frame = s->collocated_ref = NULL;
3411 s->slice_initialized = 0;
3412 return ret;
3413 }
3414
3415 static int verify_md5(HEVCContext *s, AVFrame *frame)
3416 {
3417 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
3418 char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
3419 int pixel_shift;
3420 int err = 0;
3421 int i, j;
3422
3423 if (!desc)
3424 return AVERROR(EINVAL);
3425
3426 pixel_shift = desc->comp[0].depth > 8;
3427
3428 /* the checksums are LE, so we have to byteswap for >8bpp formats
3429 * on BE arches */
3430 #if HAVE_BIGENDIAN
3431 if (pixel_shift && !s->checksum_buf) {
3432 av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size,
3433 FFMAX3(frame->linesize[0], frame->linesize[1],
3434 frame->linesize[2]));
3435 if (!s->checksum_buf)
3436 return AVERROR(ENOMEM);
3437 }
3438 #endif
3439
3440 msg_buf[0] = '\0';
3441 for (i = 0; frame->data[i]; i++) {
3442 int width = s->avctx->coded_width;
3443 int height = s->avctx->coded_height;
3444 int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width;
3445 int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height;
3446 uint8_t md5[16];
3447
3448 av_md5_init(s->md5_ctx);
3449 for (j = 0; j < h; j++) {
3450 const uint8_t *src = frame->data[i] + j * frame->linesize[i];
3451 #if HAVE_BIGENDIAN
3452 if (pixel_shift) {
3453 s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
3454 (const uint16_t *) src, w);
3455 src = s->checksum_buf;
3456 }
3457 #endif
3458 av_md5_update(s->md5_ctx, src, w << pixel_shift);
3459 }
3460 av_md5_final(s->md5_ctx, md5);
3461
3462 #define MD5_PRI "%016" PRIx64 "%016" PRIx64
3463 #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
3464
3465 if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
3466 av_strlcatf(msg_buf, sizeof(msg_buf),
3467 "plane %d - correct " MD5_PRI "; ",
3468 i, MD5_PRI_ARG(md5));
3469 } else {
3470 av_strlcatf(msg_buf, sizeof(msg_buf),
3471 "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
3472 i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i]));
3473 err = AVERROR_INVALIDDATA;
3474 }
3475 }
3476
3477 av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
3478 "Verifying checksum for frame with POC %d: %s\n",
3479 s->poc, msg_buf);
3480
3481 return err;
3482 }
3483
3484 10283 static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l)
3485 {
3486 10283 HEVCFrame *out = l->cur_frame;
3487 const AVFilmGrainParams *fgp;
3488 av_unused int ret;
3489
3490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (out->needs_fg) {
3491 av_assert0(out->frame_grain->buf[0]);
3492 fgp = av_film_grain_params_select(out->f);
3493 switch (fgp->type) {
3494 case AV_FILM_GRAIN_PARAMS_NONE:
3495 av_assert0(0);
3496 return AVERROR_BUG;
3497 case AV_FILM_GRAIN_PARAMS_H274:
3498 ret = ff_h274_apply_film_grain(out->frame_grain, out->f,
3499 &s->h274db, fgp);
3500 break;
3501 case AV_FILM_GRAIN_PARAMS_AV1:
3502 ret = ff_aom_apply_film_grain(out->frame_grain, out->f, fgp);
3503 break;
3504 }
3505 av_assert1(ret >= 0);
3506 }
3507
3508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (s->avctx->hwaccel) {
3509 ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
3510 if (ret < 0) {
3511 av_log(s->avctx, AV_LOG_ERROR,
3512 "hardware accelerator failed to decode picture\n");
3513 return ret;
3514 }
3515 } else {
3516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
3517 s->sei.picture_hash.is_md5) {
3518 ret = verify_md5(s, out->f);
3519 if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
3520 return ret;
3521 }
3522 }
3523 10283 s->sei.picture_hash.is_md5 = 0;
3524
3525 10283 av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %zu/%d.\n",
3526 10283 l - s->layers, s->poc);
3527
3528 10283 return 0;
3529 }
3530
3531 28403 static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb)
3532 {
3533
2/2
✓ Branch 0 taken 27967 times.
✓ Branch 1 taken 436 times.
28403 const int layer_idx = s->vps ? s->vps->layer_idx[s->nuh_layer_id] : 0;
3534 HEVCLayerContext *l;
3535 int ret;
3536
3537 // skip layers not requested to be decoded
3538 // layers_active_decode can only change while decoding a base-layer frame,
3539 // so we can check it for non-base layers
3540
1/2
✓ Branch 0 taken 28403 times.
✗ Branch 1 not taken.
28403 if (layer_idx < 0 ||
3541
4/4
✓ Branch 0 taken 332 times.
✓ Branch 1 taken 28071 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 327 times.
28403 (s->nuh_layer_id > 0 && !(s->layers_active_decode & (1 << layer_idx))))
3542 5 return 0;
3543
3544 28398 ret = hls_slice_header(&s->sh, s, gb);
3545
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 28365 times.
28398 if (ret < 0) {
3546 // hls_slice_header() does not cleanup on failure thus the state now is inconsistant so we cannot use it on depandant slices
3547 33 s->slice_initialized = 0;
3548 33 return ret;
3549 }
3550
3551
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28365 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
28365 if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
3552
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28365 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
28365 (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
3553
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 28365 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
28365 (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
3554
4/4
✓ Branch 0 taken 27220 times.
✓ Branch 1 taken 1145 times.
✓ Branch 2 taken 1066 times.
✓ Branch 3 taken 26154 times.
28365 ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&
3555
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 2126 times.
2211 s->no_rasl_output_flag)) {
3556 85 return 0;
3557 }
3558
3559 // switching to a new layer, mark previous layer's frame (if any) as done
3560
2/2
✓ Branch 0 taken 646 times.
✓ Branch 1 taken 27634 times.
28280 if (s->cur_layer != layer_idx &&
3561
2/2
✓ Branch 0 taken 327 times.
✓ Branch 1 taken 319 times.
646 s->layers[s->cur_layer].cur_frame &&
3562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 327 times.
327 s->avctx->active_thread_type == FF_THREAD_FRAME)
3563 ff_progress_frame_report(&s->layers[s->cur_layer].cur_frame->tf, INT_MAX);
3564
3565 28280 s->cur_layer = layer_idx;
3566 28280 l = &s->layers[s->cur_layer];
3567
3568
2/2
✓ Branch 0 taken 10284 times.
✓ Branch 1 taken 17996 times.
28280 if (s->sh.first_slice_in_pic_flag) {
3569
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10283 times.
10284 if (l->cur_frame) {
3570 1 av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
3571 1 return AVERROR_INVALIDDATA;
3572 }
3573
3574 10283 ret = hevc_frame_start(s, l, nal_idx);
3575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10283 times.
10283 if (ret < 0)
3576 return ret;
3577
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17996 times.
17996 } else if (!l->cur_frame) {
3578 av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
3579 return AVERROR_INVALIDDATA;
3580 }
3581
3582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28279 times.
28279 if (s->nal_unit_type != s->first_nal_type) {
3583 av_log(s->avctx, AV_LOG_ERROR,
3584 "Non-matching NAL types of the VCL NALUs: %d %d\n",
3585 s->first_nal_type, s->nal_unit_type);
3586 return AVERROR_INVALIDDATA;
3587 }
3588
3589 28279 ret = decode_slice_data(s, l, &s->pkt.nals[nal_idx], gb);
3590
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28278 times.
28279 if (ret < 0)
3591 1 return ret;
3592
3593 28278 return 0;
3594 }
3595
3596 39205 static int decode_nal_unit(HEVCContext *s, unsigned nal_idx)
3597 {
3598 39205 H2645NAL *nal = &s->pkt.nals[nal_idx];
3599 39205 GetBitContext gb = nal->gb;
3600 int ret;
3601
3602 39205 s->nal_unit_type = nal->type;
3603 39205 s->nuh_layer_id = nal->nuh_layer_id;
3604 39205 s->temporal_id = nal->temporal_id;
3605
3606
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 39205 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
39205 if (FF_HW_HAS_CB(s->avctx, decode_params) &&
3607 (s->nal_unit_type == HEVC_NAL_VPS ||
3608 s->nal_unit_type == HEVC_NAL_SPS ||
3609 s->nal_unit_type == HEVC_NAL_PPS ||
3610 s->nal_unit_type == HEVC_NAL_SEI_PREFIX ||
3611 s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) {
3612 ret = FF_HW_CALL(s->avctx, decode_params,
3613 nal->type, nal->raw_data, nal->raw_size);
3614 if (ret < 0)
3615 goto fail;
3616 }
3617
3618
6/7
✓ Branch 0 taken 437 times.
✓ Branch 1 taken 446 times.
✓ Branch 2 taken 1406 times.
✓ Branch 3 taken 7831 times.
✓ Branch 4 taken 28403 times.
✓ Branch 5 taken 682 times.
✗ Branch 6 not taken.
39205 switch (s->nal_unit_type) {
3619 437 case HEVC_NAL_VPS:
3620 437 ret = ff_hevc_decode_nal_vps(&gb, s->avctx, &s->ps);
3621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 437 times.
437 if (ret < 0)
3622 goto fail;
3623 437 break;
3624 446 case HEVC_NAL_SPS:
3625 446 ret = ff_hevc_decode_nal_sps(&gb, s->avctx, &s->ps,
3626 446 nal->nuh_layer_id, s->apply_defdispwin);
3627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 446 times.
446 if (ret < 0)
3628 goto fail;
3629 446 break;
3630 1406 case HEVC_NAL_PPS:
3631 1406 ret = ff_hevc_decode_nal_pps(&gb, s->avctx, &s->ps);
3632
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1404 times.
1406 if (ret < 0)
3633 2 goto fail;
3634 1404 break;
3635 7831 case HEVC_NAL_SEI_PREFIX:
3636 case HEVC_NAL_SEI_SUFFIX:
3637 7831 ret = ff_hevc_decode_nal_sei(&gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type);
3638
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7798 times.
7831 if (ret < 0)
3639 33 goto fail;
3640 7798 break;
3641 28403 case HEVC_NAL_TRAIL_R:
3642 case HEVC_NAL_TRAIL_N:
3643 case HEVC_NAL_TSA_N:
3644 case HEVC_NAL_TSA_R:
3645 case HEVC_NAL_STSA_N:
3646 case HEVC_NAL_STSA_R:
3647 case HEVC_NAL_BLA_W_LP:
3648 case HEVC_NAL_BLA_W_RADL:
3649 case HEVC_NAL_BLA_N_LP:
3650 case HEVC_NAL_IDR_W_RADL:
3651 case HEVC_NAL_IDR_N_LP:
3652 case HEVC_NAL_CRA_NUT:
3653 case HEVC_NAL_RADL_N:
3654 case HEVC_NAL_RADL_R:
3655 case HEVC_NAL_RASL_N:
3656 case HEVC_NAL_RASL_R:
3657 28403 ret = decode_slice(s, nal_idx, &gb);
3658
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 28368 times.
28403 if (ret < 0)
3659 35 goto fail;
3660 28368 break;
3661 682 case HEVC_NAL_EOS_NUT:
3662 case HEVC_NAL_EOB_NUT:
3663 case HEVC_NAL_AUD:
3664 case HEVC_NAL_FD_NUT:
3665 case HEVC_NAL_UNSPEC62:
3666 682 break;
3667 default:
3668 av_log(s->avctx, AV_LOG_INFO,
3669 "Skipping NAL unit %d\n", s->nal_unit_type);
3670 }
3671
3672 39135 return 0;
3673 70 fail:
3674
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 if (ret == AVERROR_INVALIDDATA &&
3675
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 !(s->avctx->err_recognition & AV_EF_EXPLODE)) {
3676 70 av_log(s->avctx, AV_LOG_WARNING,
3677 70 "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type);
3678 70 return 0;
3679 }
3680 return ret;
3681 }
3682
3683 407 static void decode_reset_recovery_point(HEVCContext *s)
3684 {
3685 407 s->recovery_poc = HEVC_RECOVERY_UNSPECIFIED;
3686 407 s->sei.recovery_point.has_recovery_poc = 0;
3687 407 }
3688
3689 10033 static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
3690 {
3691 10033 int i, ret = 0;
3692 10033 int eos_at_start = 1;
3693
2/2
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 9859 times.
10033 int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING;
3694
3695 10033 s->cur_frame = s->collocated_ref = NULL;
3696 10033 s->last_eos = s->eos;
3697 10033 s->eos = 0;
3698 10033 s->slice_initialized = 0;
3699
2/2
✓ Branch 0 taken 403 times.
✓ Branch 1 taken 9630 times.
10033 if (s->last_eos)
3700 403 decode_reset_recovery_point(s);
3701
3702
2/2
✓ Branch 0 taken 20066 times.
✓ Branch 1 taken 10033 times.
30099 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3703 20066 HEVCLayerContext *l = &s->layers[i];
3704 20066 l->cur_frame = NULL;
3705 }
3706
3707 /* split the input packet into NAL units, so we know the upper bound on the
3708 * number of slices in the frame */
3709 10033 ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx,
3710 10033 s->nal_length_size, s->avctx->codec_id, flags);
3711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10033 times.
10033 if (ret < 0) {
3712 av_log(s->avctx, AV_LOG_ERROR,
3713 "Error splitting the input into NAL units.\n");
3714 return ret;
3715 }
3716
3717
2/2
✓ Branch 0 taken 39205 times.
✓ Branch 1 taken 10033 times.
49238 for (i = 0; i < s->pkt.nb_nals; i++) {
3718
2/2
✓ Branch 0 taken 39204 times.
✓ Branch 1 taken 1 times.
39205 if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT ||
3719
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 39201 times.
39204 s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) {
3720
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (eos_at_start) {
3721 4 s->last_eos = 1;
3722 4 decode_reset_recovery_point(s);
3723 } else {
3724 s->eos = 1;
3725 }
3726 } else {
3727 39201 eos_at_start = 0;
3728 }
3729 }
3730
3731 /*
3732 * Check for RPU delimiter.
3733 *
3734 * Dolby Vision RPUs masquerade as unregistered NALs of type 62.
3735 *
3736 * We have to do this check here an create the rpu buffer, since RPUs are appended
3737 * to the end of an AU; they are the last non-EOB/EOS NAL in the AU.
3738 */
3739
4/4
✓ Branch 0 taken 8106 times.
✓ Branch 1 taken 1927 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8104 times.
10033 if (s->pkt.nb_nals > 1 && s->pkt.nals[s->pkt.nb_nals - 1].type == HEVC_NAL_UNSPEC62 &&
3740
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
3741
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 && !s->pkt.nals[s->pkt.nb_nals - 1].temporal_id) {
3742 2 H2645NAL *nal = &s->pkt.nals[s->pkt.nb_nals - 1];
3743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->rpu_buf) {
3744 av_buffer_unref(&s->rpu_buf);
3745 av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n");
3746 }
3747
3748 2 s->rpu_buf = av_buffer_alloc(nal->raw_size - 2);
3749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!s->rpu_buf)
3750 return AVERROR(ENOMEM);
3751 2 memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2);
3752
3753 2 ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2,
3754 2 s->avctx->err_recognition);
3755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0) {
3756 av_buffer_unref(&s->rpu_buf);
3757 av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n");
3758 /* ignore */
3759 }
3760 }
3761
3762 /* decode the NAL units */
3763
2/2
✓ Branch 0 taken 39205 times.
✓ Branch 1 taken 10033 times.
49238 for (i = 0; i < s->pkt.nb_nals; i++) {
3764 39205 H2645NAL *nal = &s->pkt.nals[i];
3765
3766
1/2
✓ Branch 0 taken 39205 times.
✗ Branch 1 not taken.
39205 if (s->avctx->skip_frame >= AVDISCARD_ALL ||
3767
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 39205 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
39205 (s->avctx->skip_frame >= AVDISCARD_NONREF && ff_hevc_nal_is_nonref(nal->type)))
3768 continue;
3769
3770 39205 ret = decode_nal_unit(s, i);
3771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39205 times.
39205 if (ret < 0) {
3772 av_log(s->avctx, AV_LOG_WARNING,
3773 "Error parsing NAL unit #%d.\n", i);
3774 goto fail;
3775 }
3776 }
3777
3778 10033 fail:
3779
2/2
✓ Branch 0 taken 20066 times.
✓ Branch 1 taken 10033 times.
30099 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3780 20066 HEVCLayerContext *l = &s->layers[i];
3781
3782
2/2
✓ Branch 0 taken 9783 times.
✓ Branch 1 taken 10283 times.
20066 if (!l->cur_frame)
3783 9783 continue;
3784
3785
1/2
✓ Branch 0 taken 10283 times.
✗ Branch 1 not taken.
10283 if (ret >= 0)
3786 10283 ret = hevc_frame_end(s, l);
3787
3788
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 10250 times.
10283 if (s->avctx->active_thread_type == FF_THREAD_FRAME)
3789 33 ff_progress_frame_report(&l->cur_frame->tf, INT_MAX);
3790 }
3791
3792 10033 return ret;
3793 }
3794
3795 270 static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first)
3796 {
3797 int ret, i;
3798
3799 270 ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff,
3800 270 &s->nal_length_size, s->avctx->err_recognition,
3801 270 s->apply_defdispwin, s->avctx);
3802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 270 times.
270 if (ret < 0)
3803 return ret;
3804
3805 /* export stream parameters from the first SPS */
3806
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 2 times.
302 for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) {
3807
4/4
✓ Branch 0 taken 284 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 268 times.
✓ Branch 3 taken 16 times.
300 if (first && s->ps.sps_list[i]) {
3808 268 const HEVCSPS *sps = s->ps.sps_list[i];
3809 268 export_stream_params(s, sps);
3810
3811 268 ret = export_multilayer(s, sps->vps);
3812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 268 times.
268 if (ret < 0)
3813 return ret;
3814
3815 268 break;
3816 }
3817 }
3818
3819 /* export stream parameters from SEI */
3820 270 ret = export_stream_params_from_sei(s);
3821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 270 times.
270 if (ret < 0)
3822 return ret;
3823
3824 270 return 0;
3825 }
3826
3827 21244 static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame)
3828 {
3829 21244 HEVCContext *s = avctx->priv_data;
3830 21244 AVCodecInternal *avci = avctx->internal;
3831 21244 AVPacket *avpkt = avci->in_pkt;
3832
3833 int ret;
3834 uint8_t *sd;
3835 size_t sd_size;
3836
3837 21244 s->pkt_dts = AV_NOPTS_VALUE;
3838
3839
2/2
✓ Branch 1 taken 948 times.
✓ Branch 2 taken 20296 times.
21244 if (av_container_fifo_can_read(s->output_fifo))
3840 948 goto do_output;
3841
3842 20296 av_packet_unref(avpkt);
3843 20296 ret = ff_decode_get_packet(avctx, avpkt);
3844
2/2
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 19988 times.
20296 if (ret == AVERROR_EOF) {
3845 308 ret = ff_hevc_output_frames(s, s->layers_active_decode,
3846 s->layers_active_output, 0, 0, 0);
3847
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 308 times.
308 if (ret < 0)
3848 return ret;
3849 308 goto do_output;
3850
2/2
✓ Branch 0 taken 9955 times.
✓ Branch 1 taken 10033 times.
19988 } else if (ret < 0)
3851 9955 return ret;
3852
3853 10033 s->pkt_dts = avpkt->dts;
3854
3855 10033 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size);
3856
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10032 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
10033 if (sd && sd_size > 0) {
3857 1 ret = hevc_decode_extradata(s, sd, sd_size, 0);
3858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
3859 return ret;
3860 }
3861
3862 10033 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size);
3863
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10033 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10033 if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) {
3864 int old = s->dovi_ctx.cfg.dv_profile;
3865 s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd;
3866 if (old)
3867 av_log(avctx, AV_LOG_DEBUG,
3868 "New DOVI configuration record from input packet (profile %d -> %u).\n",
3869 old, s->dovi_ctx.cfg.dv_profile);
3870 }
3871
3872 10033 ret = decode_nal_units(s, avpkt->data, avpkt->size);
3873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10033 times.
10033 if (ret < 0)
3874 return ret;
3875
3876 10033 do_output:
3877
2/2
✓ Branch 1 taken 10063 times.
✓ Branch 2 taken 1226 times.
11289 if (av_container_fifo_read(s->output_fifo, frame, 0) >= 0) {
3878
1/2
✓ Branch 0 taken 10063 times.
✗ Branch 1 not taken.
10063 if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))
3879 10063 av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
3880
3881 10063 return 0;
3882 }
3883
3884
2/2
✓ Branch 0 taken 191 times.
✓ Branch 1 taken 1035 times.
1226 return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN);
3885 }
3886
3887 67 static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
3888 {
3889 int ret;
3890
3891 67 ff_progress_frame_ref(&dst->tf, &src->tf);
3892
3893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (src->needs_fg) {
3894 ret = av_frame_ref(dst->frame_grain, src->frame_grain);
3895 if (ret < 0) {
3896 ff_hevc_unref_frame(dst, ~0);
3897 return ret;
3898 }
3899 dst->needs_fg = 1;
3900 }
3901
3902 67 dst->pps = av_refstruct_ref_c(src->pps);
3903 67 dst->tab_mvf = av_refstruct_ref(src->tab_mvf);
3904 67 dst->rpl_tab = av_refstruct_ref(src->rpl_tab);
3905 67 dst->rpl = av_refstruct_ref(src->rpl);
3906 67 dst->nb_rpl_elems = src->nb_rpl_elems;
3907
3908 67 dst->poc = src->poc;
3909 67 dst->ctb_count = src->ctb_count;
3910 67 dst->flags = src->flags;
3911
3912 67 dst->base_layer_frame = src->base_layer_frame;
3913
3914 67 av_refstruct_replace(&dst->hwaccel_picture_private,
3915 67 src->hwaccel_picture_private);
3916
3917 67 return 0;
3918 }
3919
3920 480 static av_cold int hevc_decode_free(AVCodecContext *avctx)
3921 {
3922 480 HEVCContext *s = avctx->priv_data;
3923
3924
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 480 times.
1440 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3925 960 pic_arrays_free(&s->layers[i]);
3926 960 av_refstruct_unref(&s->layers[i].sps);
3927 }
3928
3929 480 av_refstruct_unref(&s->vps);
3930 480 av_refstruct_unref(&s->pps);
3931
3932 480 ff_dovi_ctx_unref(&s->dovi_ctx);
3933 480 av_buffer_unref(&s->rpu_buf);
3934
3935 480 av_freep(&s->md5_ctx);
3936
3937 480 av_container_fifo_free(&s->output_fifo);
3938
3939
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 480 times.
1440 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
3940 960 HEVCLayerContext *l = &s->layers[layer];
3941
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 960 times.
31680 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
3942 30720 ff_hevc_unref_frame(&l->DPB[i], ~0);
3943 30720 av_frame_free(&l->DPB[i].frame_grain);
3944 }
3945 }
3946
3947 480 ff_hevc_ps_uninit(&s->ps);
3948
3949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 480 times.
480 for (int i = 0; i < s->nb_wpp_progress; i++)
3950 ff_thread_progress_destroy(&s->wpp_progress[i]);
3951 480 av_freep(&s->wpp_progress);
3952
3953 480 av_freep(&s->sh.entry_point_offset);
3954 480 av_freep(&s->sh.offset);
3955 480 av_freep(&s->sh.size);
3956
3957 480 av_freep(&s->local_ctx);
3958
3959 480 ff_h2645_packet_uninit(&s->pkt);
3960
3961 480 ff_hevc_reset_sei(&s->sei);
3962
3963 480 return 0;
3964 }
3965
3966 480 static av_cold int hevc_init_context(AVCodecContext *avctx)
3967 {
3968 480 HEVCContext *s = avctx->priv_data;
3969
3970 480 s->avctx = avctx;
3971
3972 480 s->local_ctx = av_mallocz(sizeof(*s->local_ctx));
3973
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 480 times.
480 if (!s->local_ctx)
3974 return AVERROR(ENOMEM);
3975 480 s->nb_local_ctx = 1;
3976
3977 480 s->local_ctx[0].parent = s;
3978 480 s->local_ctx[0].logctx = avctx;
3979 480 s->local_ctx[0].common_cabac_state = &s->cabac;
3980
3981 480 s->output_fifo = av_container_fifo_alloc_avframe(0);
3982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 480 times.
480 if (!s->output_fifo)
3983 return AVERROR(ENOMEM);
3984
3985
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 480 times.
1440 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
3986 960 HEVCLayerContext *l = &s->layers[layer];
3987
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 960 times.
31680 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
3988 30720 l->DPB[i].frame_grain = av_frame_alloc();
3989
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30720 times.
30720 if (!l->DPB[i].frame_grain)
3990 return AVERROR(ENOMEM);
3991 }
3992 }
3993
3994 480 s->md5_ctx = av_md5_alloc();
3995
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 480 times.
480 if (!s->md5_ctx)
3996 return AVERROR(ENOMEM);
3997
3998 480 ff_bswapdsp_init(&s->bdsp);
3999
4000 480 s->dovi_ctx.logctx = avctx;
4001 480 s->eos = 0;
4002
4003 480 ff_hevc_reset_sei(&s->sei);
4004
4005 480 return 0;
4006 }
4007
4008 #if HAVE_THREADS
4009 32 static int hevc_update_thread_context(AVCodecContext *dst,
4010 const AVCodecContext *src)
4011 {
4012 32 HEVCContext *s = dst->priv_data;
4013 32 HEVCContext *s0 = src->priv_data;
4014 int ret;
4015
4016
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
96 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
4017 64 HEVCLayerContext *l = &s->layers[layer];
4018 64 const HEVCLayerContext *l0 = &s0->layers[layer];
4019
2/2
✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 64 times.
2112 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
4020 2048 ff_hevc_unref_frame(&l->DPB[i], ~0);
4021
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1981 times.
2048 if (l0->DPB[i].f) {
4022 67 ret = hevc_ref_frame(&l->DPB[i], &l0->DPB[i]);
4023
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (ret < 0)
4024 return ret;
4025 }
4026 }
4027
4028
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
64 if (l->sps != l0->sps) {
4029 1 ret = set_sps(s, l, l0->sps);
4030
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
4031 return ret;
4032 }
4033 }
4034
4035
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++)
4036 512 av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]);
4037
4038
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++)
4039 512 av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]);
4040
4041
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++)
4042 2048 av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]);
4043
4044 // PPS do not persist between frames
4045 32 av_refstruct_unref(&s->pps);
4046
4047 32 s->poc_tid0 = s0->poc_tid0;
4048 32 s->eos = s0->eos;
4049 32 s->no_rasl_output_flag = s0->no_rasl_output_flag;
4050
4051 32 s->is_nalff = s0->is_nalff;
4052 32 s->nal_length_size = s0->nal_length_size;
4053 32 s->layers_active_decode = s0->layers_active_decode;
4054 32 s->layers_active_output = s0->layers_active_output;
4055
4056 32 s->film_grain_warning_shown = s0->film_grain_warning_shown;
4057
4058
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (s->nb_view_ids != s0->nb_view_ids ||
4059
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)) {
4060 av_freep(&s->view_ids);
4061 s->nb_view_ids = 0;
4062
4063 if (s0->nb_view_ids) {
4064 s->view_ids = av_memdup(s0->view_ids, s0->nb_view_ids * sizeof(*s0->view_ids));
4065 if (!s->view_ids)
4066 return AVERROR(ENOMEM);
4067 s->nb_view_ids = s0->nb_view_ids;
4068 }
4069 }
4070
4071 32 ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common);
4072
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4073 return ret;
4074
4075 32 ret = av_buffer_replace(&s->sei.common.dynamic_hdr_plus.info,
4076 32 s0->sei.common.dynamic_hdr_plus.info);
4077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4078 return ret;
4079
4080 32 ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf);
4081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4082 return ret;
4083
4084 32 ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx);
4085
4086 32 ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info,
4087 32 s0->sei.common.dynamic_hdr_vivid.info);
4088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4089 return ret;
4090
4091 32 s->sei.common.frame_packing = s0->sei.common.frame_packing;
4092 32 s->sei.common.display_orientation = s0->sei.common.display_orientation;
4093 32 s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer;
4094 32 s->sei.tdrdi = s0->sei.tdrdi;
4095 32 s->sei.recovery_point = s0->sei.recovery_point;
4096 32 s->recovery_poc = s0->recovery_poc;
4097
4098 32 return 0;
4099 }
4100 #endif
4101
4102 480 static av_cold int hevc_decode_init(AVCodecContext *avctx)
4103 {
4104 480 HEVCContext *s = avctx->priv_data;
4105 int ret;
4106
4107 480 ret = hevc_init_context(avctx);
4108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 480 times.
480 if (ret < 0)
4109 return ret;
4110
4111 480 s->sei.picture_timing.picture_struct = 0;
4112 480 s->eos = 1;
4113
4114 480 atomic_init(&s->wpp_err, 0);
4115
4116
2/2
✓ Branch 0 taken 479 times.
✓ Branch 1 taken 1 times.
480 if (!avctx->internal->is_copy) {
4117 const AVPacketSideData *sd;
4118
4119
3/4
✓ Branch 0 taken 269 times.
✓ Branch 1 taken 210 times.
✓ Branch 2 taken 269 times.
✗ Branch 3 not taken.
479 if (avctx->extradata_size > 0 && avctx->extradata) {
4120 269 ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1);
4121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 if (ret < 0) {
4122 return ret;
4123 }
4124
4125 269 ret = ff_h2645_sei_to_context(avctx, &s->sei.common);
4126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 if (ret < 0)
4127 return ret;
4128 }
4129
4130 479 sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF);
4131
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 468 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
479 if (sd && sd->size >= sizeof(s->dovi_ctx.cfg))
4132 11 s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data;
4133 }
4134
4135 480 return 0;
4136 }
4137
4138 9 static void hevc_decode_flush(AVCodecContext *avctx)
4139 {
4140 9 HEVCContext *s = avctx->priv_data;
4141 9 ff_hevc_flush_dpb(s);
4142 9 ff_hevc_reset_sei(&s->sei);
4143 9 ff_dovi_ctx_flush(&s->dovi_ctx);
4144 9 av_buffer_unref(&s->rpu_buf);
4145 9 s->eos = 1;
4146
4147
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
9 if (FF_HW_HAS_CB(avctx, flush))
4148 FF_HW_SIMPLE_CALL(avctx, flush);
4149 9 }
4150
4151 #define OFFSET(x) offsetof(HEVCContext, x)
4152 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
4153
4154 static const AVOption options[] = {
4155 { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin),
4156 AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4157 { "strict-displaywin", "stricly apply default display window size", OFFSET(apply_defdispwin),
4158 AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4159 { "view_ids", "Array of view IDs that should be decoded and output; a single -1 to decode all views",
4160 .offset = OFFSET(view_ids), .type = AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY,
4161 .min = -1, .max = INT_MAX, .flags = PAR },
4162 { "view_ids_available", "Array of available view IDs is exported here",
4163 .offset = OFFSET(view_ids_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4164 .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
4165 { "view_pos_available", "Array of view positions for view_ids_available is exported here, as AVStereo3DView",
4166 .offset = OFFSET(view_pos_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4167 .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY, .unit = "view_pos" },
4168 { "unspecified", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_UNSPEC }, .unit = "view_pos" },
4169 { "left", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_LEFT }, .unit = "view_pos" },
4170 { "right", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_RIGHT }, .unit = "view_pos" },
4171
4172 { NULL },
4173 };
4174
4175 static const AVClass hevc_decoder_class = {
4176 .class_name = "HEVC decoder",
4177 .item_name = av_default_item_name,
4178 .option = options,
4179 .version = LIBAVUTIL_VERSION_INT,
4180 };
4181
4182 const FFCodec ff_hevc_decoder = {
4183 .p.name = "hevc",
4184 CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"),
4185 .p.type = AVMEDIA_TYPE_VIDEO,
4186 .p.id = AV_CODEC_ID_HEVC,
4187 .priv_data_size = sizeof(HEVCContext),
4188 .p.priv_class = &hevc_decoder_class,
4189 .init = hevc_decode_init,
4190 .close = hevc_decode_free,
4191 FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame),
4192 .flush = hevc_decode_flush,
4193 UPDATE_THREAD_CONTEXT(hevc_update_thread_context),
4194 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
4195 AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
4196 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
4197 FF_CODEC_CAP_USES_PROGRESSFRAMES |
4198 FF_CODEC_CAP_INIT_CLEANUP,
4199 .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
4200 .hw_configs = (const AVCodecHWConfigInternal *const []) {
4201 #if CONFIG_HEVC_DXVA2_HWACCEL
4202 HWACCEL_DXVA2(hevc),
4203 #endif
4204 #if CONFIG_HEVC_D3D11VA_HWACCEL
4205 HWACCEL_D3D11VA(hevc),
4206 #endif
4207 #if CONFIG_HEVC_D3D11VA2_HWACCEL
4208 HWACCEL_D3D11VA2(hevc),
4209 #endif
4210 #if CONFIG_HEVC_D3D12VA_HWACCEL
4211 HWACCEL_D3D12VA(hevc),
4212 #endif
4213 #if CONFIG_HEVC_NVDEC_HWACCEL
4214 HWACCEL_NVDEC(hevc),
4215 #endif
4216 #if CONFIG_HEVC_VAAPI_HWACCEL
4217 HWACCEL_VAAPI(hevc),
4218 #endif
4219 #if CONFIG_HEVC_VDPAU_HWACCEL
4220 HWACCEL_VDPAU(hevc),
4221 #endif
4222 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
4223 HWACCEL_VIDEOTOOLBOX(hevc),
4224 #endif
4225 #if CONFIG_HEVC_VULKAN_HWACCEL
4226 HWACCEL_VULKAN(hevc),
4227 #endif
4228 NULL
4229 },
4230 };
4231