FFmpeg coverage


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