FFmpeg coverage


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