FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc/hevcdec.c
Date: 2026-05-18 19:05:09
Exec Total Coverage
Lines: 1980 2460 80.5%
Functions: 51 56 91.1%
Branches: 1388 1845 75.2%

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 1492 static void pic_arrays_free(HEVCLayerContext *l)
74 {
75 1492 av_freep(&l->sao);
76 1492 av_freep(&l->deblock);
77
78 1492 av_freep(&l->skip_flag);
79 1492 av_freep(&l->tab_ct_depth);
80
81 1492 av_freep(&l->tab_ipm);
82 1492 av_freep(&l->cbf_luma);
83 1492 av_freep(&l->is_pcm);
84
85 1492 av_freep(&l->qp_y_tab);
86 1492 av_freep(&l->tab_slice_address);
87 1492 av_freep(&l->filter_slice_edges);
88
89 1492 av_freep(&l->horizontal_bs);
90 1492 av_freep(&l->vertical_bs);
91
92
2/2
✓ Branch 0 taken 4476 times.
✓ Branch 1 taken 1492 times.
5968 for (int i = 0; i < 3; i++) {
93 4476 av_freep(&l->sao_pixel_buffer_h[i]);
94 4476 av_freep(&l->sao_pixel_buffer_v[i]);
95 }
96
97 1492 av_refstruct_pool_uninit(&l->tab_mvf_pool);
98 1492 av_refstruct_pool_uninit(&l->rpl_tab_pool);
99 1492 }
100
101 /* allocate arrays that depend on frame dimensions */
102 448 static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps)
103 {
104 448 int log2_min_cb_size = sps->log2_min_cb_size;
105 448 int width = sps->width;
106 448 int height = sps->height;
107 448 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
108 448 ((height >> log2_min_cb_size) + 1);
109 448 int ctb_count = sps->ctb_width * sps->ctb_height;
110 448 int min_pu_size = sps->min_pu_width * sps->min_pu_height;
111
112 448 l->bs_width = (width >> 2) + 1;
113 448 l->bs_height = (height >> 2) + 1;
114
115 448 l->sao = av_calloc(ctb_count, sizeof(*l->sao));
116 448 l->deblock = av_calloc(ctb_count, sizeof(*l->deblock));
117
2/4
✓ Branch 0 taken 448 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 448 times.
448 if (!l->sao || !l->deblock)
118 goto fail;
119
120 448 l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
121 448 l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
122
2/4
✓ Branch 0 taken 448 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 448 times.
448 if (!l->skip_flag || !l->tab_ct_depth)
123 goto fail;
124
125 448 l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
126 448 l->tab_ipm = av_mallocz(min_pu_size);
127 448 l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1);
128
3/6
✓ Branch 0 taken 448 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 448 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 448 times.
448 if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm)
129 goto fail;
130
131 448 l->filter_slice_edges = av_mallocz(ctb_count);
132 448 l->tab_slice_address = av_malloc_array(pic_size_in_ctb,
133 sizeof(*l->tab_slice_address));
134 448 l->qp_y_tab = av_calloc(pic_size_in_ctb,
135 sizeof(*l->qp_y_tab));
136
3/6
✓ Branch 0 taken 448 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 448 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 448 times.
448 if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address)
137 goto fail;
138
139 448 l->horizontal_bs = av_calloc(l->bs_width, l->bs_height);
140 448 l->vertical_bs = av_calloc(l->bs_width, l->bs_height);
141
2/4
✓ Branch 0 taken 448 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 448 times.
448 if (!l->horizontal_bs || !l->vertical_bs)
142 goto fail;
143
144 448 l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
145 448 l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0);
146
2/4
✓ Branch 0 taken 448 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 448 times.
448 if (!l->tab_mvf_pool || !l->rpl_tab_pool)
147 goto fail;
148
149
2/2
✓ Branch 0 taken 389 times.
✓ Branch 1 taken 59 times.
448 if (sps->sao_enabled) {
150
2/2
✓ Branch 0 taken 387 times.
✓ Branch 1 taken 2 times.
389 int c_count = (sps->chroma_format_idc != 0) ? 3 : 1;
151
152
2/2
✓ Branch 0 taken 1163 times.
✓ Branch 1 taken 389 times.
1552 for (int c_idx = 0; c_idx < c_count; c_idx++) {
153 1163 int w = sps->width >> sps->hshift[c_idx];
154 1163 int h = sps->height >> sps->vshift[c_idx];
155 1163 l->sao_pixel_buffer_h[c_idx] =
156 1163 av_mallocz((w * 2 * sps->ctb_height) <<
157 1163 sps->pixel_shift);
158 1163 l->sao_pixel_buffer_v[c_idx] =
159 1163 av_mallocz((h * 2 * sps->ctb_width) <<
160 1163 sps->pixel_shift);
161
1/2
✓ Branch 0 taken 1163 times.
✗ Branch 1 not taken.
1163 if (!l->sao_pixel_buffer_h[c_idx] ||
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1163 times.
1163 !l->sao_pixel_buffer_v[c_idx])
163 goto fail;
164 }
165 }
166
167 448 return 0;
168
169 fail:
170 pic_arrays_free(l);
171 return AVERROR(ENOMEM);
172 }
173
174 1451 static int pred_weight_table(SliceHeader *sh, void *logctx,
175 const HEVCSPS *sps, GetBitContext *gb)
176 {
177 1451 int i = 0;
178 1451 int j = 0;
179 int luma_log2_weight_denom;
180 unsigned luma_weight_flags, chroma_weight_flags;
181
182 1451 luma_log2_weight_denom = get_ue_golomb_long(gb);
183
2/4
✓ Branch 0 taken 1451 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1451 times.
1451 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 1451 sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
188
1/2
✓ Branch 0 taken 1451 times.
✗ Branch 1 not taken.
1451 if (sps->chroma_format_idc != 0) {
189 1451 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
190
2/4
✓ Branch 0 taken 1451 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1451 times.
1451 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 1451 sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
195 }
196
197 1451 luma_weight_flags = get_bits(gb, sh->nb_refs[L0]);
198
1/2
✓ Branch 0 taken 1451 times.
✗ Branch 1 not taken.
1451 chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L0]) : 0;
199
2/2
✓ Branch 0 taken 4429 times.
✓ Branch 1 taken 1451 times.
5880 for (i = 0; i < sh->nb_refs[L0]; i++) {
200 4429 unsigned flag_bit = 1 << (sh->nb_refs[L0] - 1 - i);
201
202
2/2
✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1312 times.
4429 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 1312 sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
210 1312 sh->luma_offset_l0[i] = 0;
211 }
212
2/2
✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3298 times.
4429 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 3298 sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom;
228 3298 sh->chroma_offset_l0[i][0] = 0;
229 3298 sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom;
230 3298 sh->chroma_offset_l0[i][1] = 0;
231 }
232 }
233
2/2
✓ Branch 0 taken 668 times.
✓ Branch 1 taken 783 times.
1451 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 1451 return 0;
272 }
273
274 20173 static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps,
275 GetBitContext *gb, int cur_poc, int poc_lsb)
276 {
277 20173 int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
278 20173 int prev_delta_msb = 0;
279 20173 unsigned int nb_sps = 0, nb_sh;
280 int i;
281
282 20173 rps->nb_refs = 0;
283
2/2
✓ Branch 0 taken 18771 times.
✓ Branch 1 taken 1402 times.
20173 if (!sps->long_term_ref_pics_present)
284 18771 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 739 static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
332 {
333 739 AVCodecContext *avctx = s->avctx;
334 739 const HEVCVPS *vps = sps->vps;
335 739 const HEVCWindow *ow = &sps->output_window;
336 739 unsigned int num = 0, den = 0;
337
338 739 avctx->pix_fmt = sps->pix_fmt;
339 739 avctx->coded_width = sps->width;
340 739 avctx->coded_height = sps->height;
341 739 avctx->width = sps->width - ow->left_offset - ow->right_offset;
342 739 avctx->height = sps->height - ow->top_offset - ow->bottom_offset;
343 739 avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
344 739 avctx->profile = sps->ptl.general_ptl.profile_idc;
345 739 avctx->level = sps->ptl.general_ptl.level_idc;
346
347 739 ff_set_sar(avctx, sps->vui.common.sar);
348
349
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 665 times.
739 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 665 avctx->color_range = AVCOL_RANGE_MPEG;
354
355
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 672 times.
739 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 672 avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
361 672 avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
362 672 avctx->colorspace = AVCOL_SPC_UNSPECIFIED;
363 }
364
365 739 avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
366
2/2
✓ Branch 0 taken 698 times.
✓ Branch 1 taken 41 times.
739 if (sps->chroma_format_idc == 1) {
367
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 679 times.
698 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 679 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
372 }
373
374
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 717 times.
739 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 68 times.
✓ Branch 1 taken 649 times.
717 } else if (sps->vui.vui_timing_info_present_flag) {
378 68 num = sps->vui.vui_num_units_in_tick;
379 68 den = sps->vui.vui_time_scale;
380 }
381
382
3/4
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 649 times.
✓ Branch 2 taken 90 times.
✗ Branch 3 not taken.
739 if (num > 0 && den > 0)
383 90 av_reduce(&avctx->framerate.den, &avctx->framerate.num,
384 num, den, 1 << 30);
385 739 }
386
387 10765 static int export_stream_params_from_sei(HEVCContext *s)
388 {
389 10765 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 10765 times.
10765 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 10765 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10765 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 10765 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10765 if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) ||
407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10765 times.
10765 s->sei.common.aom_film_grain.enable)
408 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
409 FF_ENABLE_DEPRECATION_WARNINGS
410 #endif
411
412 10765 return 0;
413 }
414
415 739 static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
416 {
417 739 const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
418
419 739 av_freep(&s->view_ids_available);
420 739 s->nb_view_ids_available = 0;
421 739 av_freep(&s->view_pos_available);
422 739 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 711 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 711 times.
✗ Branch 3 not taken.
739 if (vps->nb_layers < 2 && !vps->view_id[0])
426 711 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 11797 int ff_hevc_is_alpha_video(const HEVCContext *s)
455 {
456 11797 const HEVCVPS *vps = s->vps;
457 11797 int ret = 0;
458
459
3/4
✓ Branch 0 taken 1215 times.
✓ Branch 1 taken 10582 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1215 times.
11797 if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1])
460 10582 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 437 static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
474 {
475 437 unsigned layers_active_output = 0, highest_layer;
476
477 437 s->layers_active_output = 1;
478 437 s->layers_active_decode = 1;
479
480
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 436 times.
437 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 425 times.
✓ Branch 1 taken 11 times.
436 if (!s->nb_view_ids)
494 425 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 437 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 437 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts;
588 437 enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE;
589 int ret;
590
591
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 436 times.
437 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 371 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.
437 switch (sps->pix_fmt) {
595 371 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 371 *fmt++ = AV_PIX_FMT_VAAPI;
609 #endif
610 #if CONFIG_HEVC_VDPAU_HWACCEL
611 371 *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 371 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 av_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 436 times.
437 if (alpha_fmt != AV_PIX_FMT_NONE)
716 1 *fmt++ = alpha_fmt;
717 437 *fmt++ = sps->pix_fmt;
718 437 *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 437 ret = export_multilayer(s, sps->vps);
723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 437 times.
437 if (ret < 0)
724 return ret;
725
726 437 ret = ff_get_format(s->avctx, pix_fmts);
727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 437 times.
437 if (ret < 0)
728 return ret;
729 437 s->avctx->pix_fmt = ret;
730
731 // set up multilayer decoding, if requested by caller
732 437 ret = setup_multilayer(s, sps->vps);
733
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 437 times.
437 if (ret < 0)
734 return ret;
735
736 437 return 0;
737 }
738
739 448 static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
740 {
741 int ret;
742
743 448 pic_arrays_free(l);
744 448 av_refstruct_unref(&l->sps);
745 448 av_refstruct_unref(&s->vps);
746
747
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 448 times.
448 if (!sps)
748 return 0;
749
750 448 ret = pic_arrays_init(l, sps);
751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 448 times.
448 if (ret < 0)
752 goto fail;
753
754 448 ff_hevc_pred_init(&s->hpc, sps->bit_depth);
755 448 ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
756 448 ff_videodsp_init (&s->vdsp, sps->bit_depth);
757
758 448 l->sps = av_refstruct_ref_c(sps);
759 448 s->vps = av_refstruct_ref_c(sps->vps);
760
761 448 return 0;
762
763 fail:
764 pic_arrays_free(l);
765 av_refstruct_unref(&l->sps);
766 return ret;
767 }
768
769 28831 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 28831 sh->first_slice_in_pic_flag = get_bits1(gb);
779
780 28831 sh->no_output_of_prior_pics_flag = 0;
781
3/4
✓ Branch 0 taken 1496 times.
✓ Branch 1 taken 27335 times.
✓ Branch 2 taken 1496 times.
✗ Branch 3 not taken.
28831 if (IS_IRAP(s))
782 1496 sh->no_output_of_prior_pics_flag = get_bits1(gb);
783
784 28831 pps_id = get_ue_golomb_long(gb);
785
3/4
✓ Branch 0 taken 28831 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 28798 times.
28831 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 10505 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18293 times.
28798 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 28798 sh->pps_id = pps_id;
794
795 28798 pps = s->ps.pps_list[pps_id];
796 28798 sps = pps->sps;
797 28798 vps = sps->vps;
798 28798 layer_idx = vps->layer_idx[s->nuh_layer_id];
799
800
4/4
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 28318 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 464 times.
28798 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 28798 sh->dependent_slice_segment_flag = 0;
804
2/2
✓ Branch 0 taken 18293 times.
✓ Branch 1 taken 10505 times.
28798 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 10505 sh->slice_segment_addr = sh->slice_addr = 0;
829 }
830
831
2/2
✓ Branch 0 taken 20851 times.
✓ Branch 1 taken 7947 times.
28798 if (!sh->dependent_slice_segment_flag) {
832
2/2
✓ Branch 0 taken 1834 times.
✓ Branch 1 taken 20851 times.
22685 for (i = 0; i < pps->num_extra_slice_header_bits; i++)
833 1834 skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
834
835 20851 sh->slice_type = get_ue_golomb_long(gb);
836
2/2
✓ Branch 0 taken 19565 times.
✓ Branch 1 taken 1286 times.
20851 if (!(sh->slice_type == HEVC_SLICE_I ||
837
2/2
✓ Branch 0 taken 15255 times.
✓ Branch 1 taken 4310 times.
19565 sh->slice_type == HEVC_SLICE_P ||
838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15255 times.
15255 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 1107 times.
✓ Branch 1 taken 19744 times.
✓ Branch 2 taken 1107 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 1026 times.
20851 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 20851 sh->pic_output_flag = 1;
852
2/2
✓ Branch 0 taken 703 times.
✓ Branch 1 taken 20148 times.
20851 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 20851 times.
20851 if (sps->separate_colour_plane)
856 sh->colour_plane_id = get_bits(gb, 2);
857
858
4/4
✓ Branch 0 taken 20211 times.
✓ Branch 1 taken 640 times.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 20173 times.
20851 if (!IS_IDR(s) ||
859
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 660 times.
678 (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 20186 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
864 20186 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 10070 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10116 times.
20186 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 20186 sh->poc = poc;
873 }
874
875
4/4
✓ Branch 0 taken 20211 times.
✓ Branch 1 taken 640 times.
✓ Branch 2 taken 20173 times.
✓ Branch 3 taken 38 times.
41024 if (!IS_IDR(s)) {
876 int pos;
877
878 20173 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
879 20173 pos = get_bits_left(gb);
880
2/2
✓ Branch 0 taken 3895 times.
✓ Branch 1 taken 16278 times.
20173 if (!sh->short_term_ref_pic_set_sps_flag) {
881 3895 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 3895 times.
3895 if (ret < 0)
883 return ret;
884
885 3895 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 20173 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
899
900 20173 pos = get_bits_left(gb);
901 20173 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 20173 times.
20173 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 20173 sh->long_term_ref_pic_set_size = pos - get_bits_left(gb);
908
909
2/2
✓ Branch 0 taken 17742 times.
✓ Branch 1 taken 2431 times.
20173 if (sps->temporal_mvp_enabled)
910 17742 sh->slice_temporal_mvp_enabled_flag = get_bits1(gb);
911 else
912 2431 sh->slice_temporal_mvp_enabled_flag = 0;
913 } else {
914 678 sh->poc = 0;
915 678 sh->pic_order_cnt_lsb = 0;
916 678 sh->short_term_ref_pic_set_sps_flag = 0;
917 678 sh->short_term_ref_pic_set_size = 0;
918 678 sh->short_term_rps = NULL;
919 678 sh->long_term_ref_pic_set_size = 0;
920 678 sh->long_term_rps.nb_refs = 0;
921 678 sh->slice_temporal_mvp_enabled_flag = 0;
922 }
923
924 20851 sh->inter_layer_pred = 0;
925
2/2
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 20335 times.
20851 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 17331 times.
✓ Branch 1 taken 3520 times.
20851 if (sps->sao_enabled) {
942 17331 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
943
2/2
✓ Branch 0 taken 17329 times.
✓ Branch 1 taken 2 times.
17331 if (sps->chroma_format_idc) {
944 17329 sh->slice_sample_adaptive_offset_flag[1] =
945 17329 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 20851 sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
954
4/4
✓ Branch 0 taken 16541 times.
✓ Branch 1 taken 4310 times.
✓ Branch 2 taken 15255 times.
✓ Branch 3 taken 1286 times.
20851 if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
955 int nb_refs;
956
957 19565 sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active;
958
2/2
✓ Branch 0 taken 15255 times.
✓ Branch 1 taken 4310 times.
19565 if (sh->slice_type == HEVC_SLICE_B)
959 15255 sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active;
960
961
2/2
✓ Branch 1 taken 5354 times.
✓ Branch 2 taken 14211 times.
19565 if (get_bits1(gb)) { // num_ref_idx_active_override_flag
962 5354 sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1;
963
2/2
✓ Branch 0 taken 2797 times.
✓ Branch 1 taken 2557 times.
5354 if (sh->slice_type == HEVC_SLICE_B)
964 2797 sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1;
965 }
966
2/4
✓ Branch 0 taken 19565 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19565 times.
19565 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 19565 sh->rpl_modification_flag[0] = 0;
973 19565 sh->rpl_modification_flag[1] = 0;
974 19565 nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx);
975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19565 times.
19565 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 17263 times.
✓ Branch 2 taken 1978 times.
✓ Branch 3 taken 324 times.
19565 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 15255 times.
✓ Branch 1 taken 4310 times.
19565 if (sh->slice_type == HEVC_SLICE_B)
996 15255 sh->mvd_l1_zero_flag = get_bits1(gb);
997
998
2/2
✓ Branch 0 taken 16687 times.
✓ Branch 1 taken 2878 times.
19565 if (pps->cabac_init_present_flag)
999 16687 sh->cabac_init_flag = get_bits1(gb);
1000 else
1001 2878 sh->cabac_init_flag = 0;
1002
1003 19565 sh->collocated_ref_idx = 0;
1004
2/2
✓ Branch 0 taken 17084 times.
✓ Branch 1 taken 2481 times.
19565 if (sh->slice_temporal_mvp_enabled_flag) {
1005 17084 sh->collocated_list = L0;
1006
2/2
✓ Branch 0 taken 14721 times.
✓ Branch 1 taken 2363 times.
17084 if (sh->slice_type == HEVC_SLICE_B)
1007 14721 sh->collocated_list = !get_bits1(gb);
1008
1009
2/2
✓ Branch 0 taken 15029 times.
✓ Branch 1 taken 2055 times.
17084 if (sh->nb_refs[sh->collocated_list] > 1) {
1010 15029 sh->collocated_ref_idx = get_ue_golomb_long(gb);
1011
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15029 times.
15029 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 1497 times.
✓ Branch 1 taken 18068 times.
✓ Branch 2 taken 714 times.
✓ Branch 3 taken 783 times.
19565 if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
1021
3/4
✓ Branch 0 taken 668 times.
✓ Branch 1 taken 18114 times.
✓ Branch 2 taken 668 times.
✗ Branch 3 not taken.
18782 (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
1022 1451 ret = pred_weight_table(sh, s->avctx, sps, gb);
1023
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1451 times.
1451 if (ret < 0)
1024 return ret;
1025 }
1026
1027 19565 sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
1028
2/4
✓ Branch 0 taken 19565 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19565 times.
19565 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 19565 times.
19565 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 19565 sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc;
1041
1042 }
1043
1044 20851 sh->slice_qp_delta = get_se_golomb(gb);
1045
1046
2/2
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 20580 times.
20851 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 20580 sh->slice_cb_qp_offset = 0;
1056 20580 sh->slice_cr_qp_offset = 0;
1057 }
1058
1059
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20851 times.
20851 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 20808 times.
20851 if (pps->chroma_qp_offset_list_enabled_flag)
1066 43 sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
1067 else
1068 20808 sh->cu_chroma_qp_offset_enabled_flag = 0;
1069
1070
2/2
✓ Branch 0 taken 3446 times.
✓ Branch 1 taken 17405 times.
20851 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 17405 sh->disable_deblocking_filter_flag = 0;
1098 17405 sh->beta_offset = 0;
1099 17405 sh->tc_offset = 0;
1100 }
1101
1102
2/2
✓ Branch 0 taken 18183 times.
✓ Branch 1 taken 2668 times.
20851 if (pps->seq_loop_filter_across_slices_enabled_flag &&
1103
2/2
✓ Branch 0 taken 11739 times.
✓ Branch 1 taken 6444 times.
18183 (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 18120 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 28798 sh->num_entry_point_offsets = 0;
1113
4/4
✓ Branch 0 taken 25505 times.
✓ Branch 1 taken 3293 times.
✓ Branch 2 taken 4771 times.
✓ Branch 3 taken 20734 times.
28798 if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1114 8064 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 8064 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8064 times.
8064 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 8064 sh->num_entry_point_offsets = num_entry_point_offsets;
1122
2/2
✓ Branch 0 taken 2208 times.
✓ Branch 1 taken 5856 times.
8064 if (sh->num_entry_point_offsets > 0) {
1123 2208 int offset_len = get_ue_golomb_long(gb) + 1;
1124
1125
2/4
✓ Branch 0 taken 2208 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2208 times.
2208 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 2208 av_freep(&sh->entry_point_offset);
1132 2208 av_freep(&sh->offset);
1133 2208 av_freep(&sh->size);
1134 2208 sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
1135 2208 sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1136 2208 sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1137
3/6
✓ Branch 0 taken 2208 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2208 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2208 times.
2208 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 9912 times.
✓ Branch 1 taken 2208 times.
12120 for (i = 0; i < sh->num_entry_point_offsets; i++) {
1143 9912 unsigned val = get_bits_long(gb, offset_len);
1144 9912 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 26029 times.
28798 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 28798 ret = get_bits1(gb);
1160
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28798 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
28798 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 28798 sh->data_offset = align_get_bits(gb) - gb->buffer;
1165
1166
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28798 times.
28798 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 28798 sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta;
1174
1/2
✓ Branch 0 taken 28798 times.
✗ Branch 1 not taken.
28798 if (sh->slice_qp > 51 ||
1175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28798 times.
28798 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 28798 sh->slice_ctb_addr_rs = sh->slice_segment_addr;
1185
1186
2/2
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20851 times.
28798 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 28798 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 2004408 static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l,
1210 const HEVCPPS *pps, const HEVCSPS *sps,
1211 int rx, int ry)
1212 {
1213 2004408 const HEVCContext *const s = lc->parent;
1214 2004408 int sao_merge_left_flag = 0;
1215 2004408 int sao_merge_up_flag = 0;
1216 2004408 SAOParams *sao = &CTB(l->sao, rx, ry);
1217 int c_idx, i;
1218
1219
2/2
✓ Branch 0 taken 877650 times.
✓ Branch 1 taken 1126758 times.
2004408 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 1085032 times.
✓ Branch 1 taken 43370 times.
1128402 if (rx > 0) {
1222
2/2
✓ Branch 0 taken 1064355 times.
✓ Branch 1 taken 20677 times.
1085032 if (lc->ctb_left_flag)
1223 1064355 sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc);
1224 }
1225
4/4
✓ Branch 0 taken 1060386 times.
✓ Branch 1 taken 68016 times.
✓ Branch 2 taken 445333 times.
✓ Branch 3 taken 615053 times.
1128402 if (ry > 0 && !sao_merge_left_flag) {
1226
2/2
✓ Branch 0 taken 431964 times.
✓ Branch 1 taken 13369 times.
445333 if (lc->ctb_up_flag)
1227 431964 sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc);
1228 }
1229 }
1230
1231
4/4
✓ Branch 0 taken 8017440 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 6013128 times.
✓ Branch 3 taken 2004408 times.
8017536 for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) {
1232
2/2
✓ Branch 0 taken 2004408 times.
✓ Branch 1 taken 4008720 times.
6013128 int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma :
1233 4008720 pps->log2_sao_offset_scale_chroma;
1234
1235
2/2
✓ Branch 0 taken 3178950 times.
✓ Branch 1 taken 2834178 times.
6013128 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 853710 times.
✓ Branch 1 taken 1980468 times.
2834178 if (c_idx == 2) {
1241 853710 sao->type_idx[2] = sao->type_idx[1];
1242 853710 sao->eo_class[2] = sao->eo_class[1];
1243 } else {
1244
7/8
✓ Branch 0 taken 1723630 times.
✓ Branch 1 taken 256838 times.
✓ Branch 2 taken 592548 times.
✓ Branch 3 taken 1131082 times.
✓ Branch 5 taken 1131082 times.
✓ Branch 6 taken 256838 times.
✓ Branch 7 taken 256838 times.
✗ Branch 8 not taken.
1980468 SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc));
1245 }
1246
1247
2/2
✓ Branch 0 taken 2068020 times.
✓ Branch 1 taken 766158 times.
2834178 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
1248 2068020 continue;
1249
1250
2/2
✓ Branch 0 taken 3064632 times.
✓ Branch 1 taken 766158 times.
3830790 for (i = 0; i < 4; i++)
1251
7/8
✓ Branch 0 taken 2510652 times.
✓ Branch 1 taken 553980 times.
✓ Branch 2 taken 1026592 times.
✓ Branch 3 taken 1484060 times.
✓ Branch 5 taken 1484060 times.
✓ Branch 6 taken 553980 times.
✓ Branch 7 taken 553980 times.
✗ Branch 8 not taken.
3064632 SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth));
1252
1253
2/2
✓ Branch 0 taken 125290 times.
✓ Branch 1 taken 640868 times.
766158 if (sao->type_idx[c_idx] == SAO_BAND) {
1254
2/2
✓ Branch 0 taken 501160 times.
✓ Branch 1 taken 125290 times.
626450 for (i = 0; i < 4; i++) {
1255
2/2
✓ Branch 0 taken 368607 times.
✓ Branch 1 taken 132553 times.
501160 if (sao->offset_abs[c_idx][i]) {
1256
7/8
✓ Branch 0 taken 342048 times.
✓ Branch 1 taken 26559 times.
✓ Branch 2 taken 252618 times.
✓ Branch 3 taken 89430 times.
✓ Branch 5 taken 89430 times.
✓ Branch 6 taken 26559 times.
✓ Branch 7 taken 26559 times.
✗ Branch 8 not taken.
368607 SET_SAO(offset_sign[c_idx][i],
1257 ff_hevc_sao_offset_sign_decode(lc));
1258 } else {
1259 132553 sao->offset_sign[c_idx][i] = 0;
1260 }
1261 }
1262
7/8
✓ Branch 0 taken 114422 times.
✓ Branch 1 taken 10868 times.
✓ Branch 2 taken 82581 times.
✓ Branch 3 taken 31841 times.
✓ Branch 5 taken 31841 times.
✓ Branch 6 taken 10868 times.
✓ Branch 7 taken 10868 times.
✗ Branch 8 not taken.
125290 SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc));
1263
2/2
✓ Branch 0 taken 553012 times.
✓ Branch 1 taken 87856 times.
640868 } else if (c_idx != 2) {
1264
7/8
✓ Branch 0 taken 443044 times.
✓ Branch 1 taken 109968 times.
✓ Branch 2 taken 139807 times.
✓ Branch 3 taken 303237 times.
✓ Branch 5 taken 303237 times.
✓ Branch 6 taken 109968 times.
✓ Branch 7 taken 109968 times.
✗ Branch 8 not taken.
553012 SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc));
1265 }
1266
1267 // Inferred parameters
1268 766158 sao->offset_val[c_idx][0] = 0;
1269
2/2
✓ Branch 0 taken 3064632 times.
✓ Branch 1 taken 766158 times.
3830790 for (i = 0; i < 4; i++) {
1270 3064632 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
1271
2/2
✓ Branch 0 taken 2563472 times.
✓ Branch 1 taken 501160 times.
3064632 if (sao->type_idx[c_idx] == SAO_EDGE) {
1272
2/2
✓ Branch 0 taken 1281736 times.
✓ Branch 1 taken 1281736 times.
2563472 if (i > 1)
1273 1281736 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1274
2/2
✓ Branch 0 taken 163404 times.
✓ Branch 1 taken 337756 times.
501160 } else if (sao->offset_sign[c_idx][i]) {
1275 163404 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1276 }
1277 3064632 sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale;
1278 }
1279 }
1280 2004408 }
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 17638554 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 17638554 const HEVCContext *const s = lc->parent;
1310 17638554 const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1];
1311 int i;
1312
1313
2/2
✓ Branch 0 taken 10977659 times.
✓ Branch 1 taken 6660895 times.
17638554 if (lc->cu.pred_mode == MODE_INTRA) {
1314 10977659 int trafo_size = 1 << log2_trafo_size;
1315 10977659 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size);
1316
1317 10977659 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0);
1318 }
1319
1320
6/6
✓ Branch 0 taken 6235086 times.
✓ Branch 1 taken 11403468 times.
✓ Branch 2 taken 5501791 times.
✓ Branch 3 taken 733295 times.
✓ Branch 4 taken 5027702 times.
✓ Branch 5 taken 474089 times.
17638554 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1321
6/6
✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4871935 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
17700368 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1322 12672667 int scan_idx = SCAN_DIAG;
1323 12672667 int scan_idx_c = SCAN_DIAG;
1324
4/4
✓ Branch 0 taken 8601505 times.
✓ Branch 1 taken 4071162 times.
✓ Branch 2 taken 6938557 times.
✓ Branch 3 taken 1662948 times.
19611224 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1325
2/2
✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 6706847 times.
6938557 (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 3111299 times.
✓ Branch 1 taken 9561368 times.
✓ Branch 2 taken 1019084 times.
✓ Branch 3 taken 2092215 times.
12672667 if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
1329 1019084 lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc);
1330
2/2
✓ Branch 0 taken 527625 times.
✓ Branch 1 taken 491459 times.
1019084 if (lc->tu.cu_qp_delta != 0)
1331
2/2
✓ Branch 1 taken 285205 times.
✓ Branch 2 taken 242420 times.
527625 if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1)
1332 285205 lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1333 1019084 lc->tu.is_cu_qp_delta_coded = 1;
1334
1335
2/2
✓ Branch 0 taken 1019083 times.
✓ Branch 1 taken 1 times.
1019084 if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) ||
1336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1019083 times.
1019083 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 1019083 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 11780715 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
12672666 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 8125646 times.
✓ Branch 1 taken 4547020 times.
✓ Branch 2 taken 7050293 times.
✓ Branch 3 taken 1075353 times.
12672666 if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1369
2/2
✓ Branch 0 taken 4679826 times.
✓ Branch 1 taken 2370467 times.
7050293 if (lc->tu.intra_pred_mode >= 6 &&
1370
2/2
✓ Branch 0 taken 1691135 times.
✓ Branch 1 taken 2988691 times.
4679826 lc->tu.intra_pred_mode <= 14) {
1371 1691135 scan_idx = SCAN_VERT;
1372
2/2
✓ Branch 0 taken 2307777 times.
✓ Branch 1 taken 3051381 times.
5359158 } else if (lc->tu.intra_pred_mode >= 22 &&
1373
2/2
✓ Branch 0 taken 1944581 times.
✓ Branch 1 taken 363196 times.
2307777 lc->tu.intra_pred_mode <= 30) {
1374 1944581 scan_idx = SCAN_HORIZ;
1375 }
1376
1377
2/2
✓ Branch 0 taken 4210196 times.
✓ Branch 1 taken 2840097 times.
7050293 if (lc->tu.intra_pred_mode_c >= 6 &&
1378
2/2
✓ Branch 0 taken 1593393 times.
✓ Branch 1 taken 2616803 times.
4210196 lc->tu.intra_pred_mode_c <= 14) {
1379 1593393 scan_idx_c = SCAN_VERT;
1380
2/2
✓ Branch 0 taken 2196082 times.
✓ Branch 1 taken 3260818 times.
5456900 } else if (lc->tu.intra_pred_mode_c >= 22 &&
1381
2/2
✓ Branch 0 taken 1842546 times.
✓ Branch 1 taken 353536 times.
2196082 lc->tu.intra_pred_mode_c <= 30) {
1382 1842546 scan_idx_c = SCAN_HORIZ;
1383 }
1384 }
1385
1386 12672666 lc->tu.cross_pf = 0;
1387
1388
2/2
✓ Branch 0 taken 11403467 times.
✓ Branch 1 taken 1269199 times.
12672666 if (cbf_luma)
1389 11403467 ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0);
1390
6/6
✓ Branch 0 taken 12672474 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6689406 times.
✓ Branch 3 taken 5983068 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 6479843 times.
18865297 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1391 6192631 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1392 6192631 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1393
4/4
✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 5855790 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
6410447 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 6000206 times.
6192631 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 11478858 times.
✓ Branch 2 taken 6645833 times.
✓ Branch 3 taken 6192631 times.
12838464 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1401
2/2
✓ Branch 0 taken 3462042 times.
✓ Branch 1 taken 3183791 times.
6645833 if (lc->cu.pred_mode == MODE_INTRA) {
1402 3462042 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1403 3462042 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1404 3462042 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 1790902 times.
✓ Branch 1 taken 4854931 times.
6645833 if (cbf_cb[i])
1407 1790902 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 4815273 times.
4854931 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 6000206 times.
6192631 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 11478858 times.
✓ Branch 2 taken 6645833 times.
✓ Branch 3 taken 6192631 times.
12838464 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1431
2/2
✓ Branch 0 taken 3462042 times.
✓ Branch 1 taken 3183791 times.
6645833 if (lc->cu.pred_mode == MODE_INTRA) {
1432 3462042 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1433 3462042 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1434 3462042 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 1835951 times.
✓ Branch 1 taken 4809882 times.
6645833 if (cbf_cr[i])
1437 1835951 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 4733958 times.
4809882 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 6479843 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1665932 times.
✓ Branch 3 taken 4813911 times.
6480035 } else if (sps->chroma_format_idc && blk_idx == 3) {
1457 1665932 int trafo_size_h = 1 << (log2_trafo_size + 1);
1458 1665932 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1459
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2998126 times.
✓ Branch 2 taken 1832801 times.
✓ Branch 3 taken 1665932 times.
3498733 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1460
2/2
✓ Branch 0 taken 1333454 times.
✓ Branch 1 taken 499347 times.
1832801 if (lc->cu.pred_mode == MODE_INTRA) {
1461 1333454 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1462 1333454 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1463 1333454 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1);
1464 }
1465
2/2
✓ Branch 0 taken 684659 times.
✓ Branch 1 taken 1148142 times.
1832801 if (cbf_cb[i])
1466 684659 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 2998126 times.
✓ Branch 2 taken 1832801 times.
✓ Branch 3 taken 1665932 times.
3498733 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1470
2/2
✓ Branch 0 taken 1333454 times.
✓ Branch 1 taken 499347 times.
1832801 if (lc->cu.pred_mode == MODE_INTRA) {
1471 1333454 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1472 1333454 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1473 1333454 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2);
1474 }
1475
2/2
✓ Branch 0 taken 771899 times.
✓ Branch 1 taken 1060902 times.
1832801 if (cbf_cr[i])
1476 771899 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 4965887 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2852012 times.
✓ Branch 3 taken 2113875 times.
4965887 } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
1481
4/4
✓ Branch 0 taken 1719062 times.
✓ Branch 1 taken 1132950 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1658474 times.
4045550 if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) {
1482 1193538 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1483 1193538 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1484 1193538 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
1485 1193538 sps->log2_ctb_size);
1486 1193538 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1);
1487 1193538 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 1181071 times.
1193538 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 374613 times.
✓ Branch 1 taken 1283861 times.
1658474 } else if (blk_idx == 3) {
1495 374613 int trafo_size_h = 1 << (log2_trafo_size + 1);
1496 374613 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1497 374613 ff_hevc_set_neighbour_available(lc, xBase, yBase,
1498 374613 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1499 374613 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1);
1500 374613 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2);
1501
2/2
✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 370417 times.
374613 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 17638553 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 21140348 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 21140348 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 21140348 cbf_cb[0] = base_cbf_cb[0];
1545 21140348 cbf_cb[1] = base_cbf_cb[1];
1546 21140348 cbf_cr[0] = base_cbf_cr[0];
1547 21140348 cbf_cr[1] = base_cbf_cr[1];
1548
1549
2/2
✓ Branch 0 taken 7085213 times.
✓ Branch 1 taken 14055135 times.
21140348 if (lc->cu.intra_split_flag) {
1550
2/2
✓ Branch 0 taken 5312516 times.
✓ Branch 1 taken 1772697 times.
7085213 if (trafo_depth == 1) {
1551 5312516 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1552
2/2
✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 5177112 times.
5312516 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 5177112 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1557 5177112 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1558 }
1559 }
1560 } else {
1561 14055135 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0];
1562 14055135 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1563 14055135 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1564 }
1565
1566
2/2
✓ Branch 0 taken 21015831 times.
✓ Branch 1 taken 124517 times.
21140348 if (log2_trafo_size <= sps->log2_max_trafo_size &&
1567
2/2
✓ Branch 0 taken 11515771 times.
✓ Branch 1 taken 9500060 times.
21015831 log2_trafo_size > sps->log2_min_tb_size &&
1568
2/2
✓ Branch 0 taken 9014606 times.
✓ Branch 1 taken 2501165 times.
11515771 trafo_depth < lc->cu.max_trafo_depth &&
1569
4/4
✓ Branch 0 taken 1905054 times.
✓ Branch 1 taken 7109552 times.
✓ Branch 2 taken 584312 times.
✓ Branch 3 taken 1320742 times.
9014606 !(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 29491246 int inter_split = sps->max_transform_hierarchy_depth_inter == 0 &&
1573
2/2
✓ Branch 0 taken 1552658 times.
✓ Branch 1 taken 1045620 times.
2598278 lc->cu.pred_mode == MODE_INTER &&
1574
6/6
✓ Branch 0 taken 2598278 times.
✓ Branch 1 taken 10848206 times.
✓ Branch 2 taken 930859 times.
✓ Branch 3 taken 621799 times.
✓ Branch 4 taken 184863 times.
✓ Branch 5 taken 745996 times.
16044762 lc->cu.part_mode != PART_2Nx2N &&
1575 trafo_depth == 0;
1576
1577 13446484 split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size ||
1578
8/8
✓ Branch 0 taken 13321967 times.
✓ Branch 1 taken 124517 times.
✓ Branch 2 taken 6492854 times.
✓ Branch 3 taken 6829113 times.
✓ Branch 4 taken 5172112 times.
✓ Branch 5 taken 1320742 times.
✓ Branch 6 taken 169700 times.
✓ Branch 7 taken 11831525 times.
13446484 (lc->cu.intra_split_flag && trafo_depth == 0) ||
1579 inter_split;
1580 }
1581
1582
6/6
✓ Branch 0 taken 21140156 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 9371980 times.
✓ Branch 3 taken 11768176 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 9057564 times.
21140348 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1583
4/4
✓ Branch 0 taken 4949612 times.
✓ Branch 1 taken 7132980 times.
✓ Branch 2 taken 1373400 times.
✓ Branch 3 taken 3576212 times.
12082592 if (trafo_depth == 0 || cbf_cb[0]) {
1584 8506380 cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1585
6/6
✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 7908114 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
8506380 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 4949612 times.
✓ Branch 1 taken 7132980 times.
✓ Branch 2 taken 1281636 times.
✓ Branch 3 taken 3667976 times.
12082592 if (trafo_depth == 0 || cbf_cr[0]) {
1591 8414616 cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1592
6/6
✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 7669310 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
8414616 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 3501794 times.
✓ Branch 1 taken 17638554 times.
21140348 if (split_transform_flag) {
1599 3501794 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1600 3501794 const int x1 = x0 + trafo_size_split;
1601 3501794 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 3501794 times.
3501794 SUBDIVIDE(x0, y0, 0);
1614
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3501794 times.
3501794 SUBDIVIDE(x1, y0, 1);
1615
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3501794 times.
3501794 SUBDIVIDE(x0, y1, 2);
1616
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3501794 times.
3501794 SUBDIVIDE(x1, y1, 3);
1617
1618 #undef SUBDIVIDE
1619 } else {
1620 17638554 int min_tu_size = 1 << sps->log2_min_tb_size;
1621 17638554 int log2_min_tu_size = sps->log2_min_tb_size;
1622 17638554 int min_tu_width = sps->min_tb_width;
1623 17638554 int cbf_luma = 1;
1624
1625
4/4
✓ Branch 0 taken 6660895 times.
✓ Branch 1 taken 10977659 times.
✓ Branch 2 taken 1589264 times.
✓ Branch 3 taken 5071631 times.
17638554 if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1626
4/4
✓ Branch 0 taken 1257601 times.
✓ Branch 1 taken 331663 times.
✓ Branch 2 taken 1090182 times.
✓ Branch 3 taken 167419 times.
1589264 cbf_cb[0] || cbf_cr[0] ||
1627
6/6
✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 1065506 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
1090182 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1628 16561018 cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth);
1629 }
1630
1631 17638554 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 17638553 times.
17638554 if (ret < 0)
1636 1 return ret;
1637 // TODO: store cbf_luma somewhere else
1638
2/2
✓ Branch 0 taken 11403467 times.
✓ Branch 1 taken 6235086 times.
17638553 if (cbf_luma) {
1639 int i, j;
1640
2/2
✓ Branch 0 taken 24954913 times.
✓ Branch 1 taken 11403467 times.
36358380 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1641
2/2
✓ Branch 0 taken 95678879 times.
✓ Branch 1 taken 24954913 times.
120633792 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1642 95678879 int x_tu = (x0 + j) >> log2_min_tu_size;
1643 95678879 int y_tu = (y0 + i) >> log2_min_tu_size;
1644 95678879 l->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1645 }
1646 }
1647
2/2
✓ Branch 0 taken 17105733 times.
✓ Branch 1 taken 532820 times.
17638553 if (!s->sh.disable_deblocking_filter_flag) {
1648 17105733 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size);
1649
2/2
✓ Branch 0 taken 409146 times.
✓ Branch 1 taken 16696587 times.
17105733 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 21140347 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 6336779 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 6336779 const HEVCContext *const s = lc->parent;
1724 6336779 const uint8_t *src = ref->data[0];
1725 6336779 ptrdiff_t srcstride = ref->linesize[0];
1726 6336779 int pic_width = sps->width;
1727 6336779 int pic_height = sps->height;
1728 6336779 int mx = mv->x & 3;
1729 6336779 int my = mv->y & 3;
1730
4/4
✓ Branch 0 taken 3278102 times.
✓ Branch 1 taken 3058677 times.
✓ Branch 2 taken 3220239 times.
✓ Branch 3 taken 57863 times.
12615695 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1731
4/4
✓ Branch 0 taken 3058677 times.
✓ Branch 1 taken 3220239 times.
✓ Branch 2 taken 70226 times.
✓ Branch 3 taken 2988451 times.
6278916 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1732 6336779 int idx = hevc_pel_weight[block_w];
1733
1734 6336779 x_off += mv->x >> 2;
1735 6336779 y_off += mv->y >> 2;
1736 6336779 src += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1737
1738
4/4
✓ Branch 0 taken 6268873 times.
✓ Branch 1 taken 67906 times.
✓ Branch 2 taken 6149769 times.
✓ Branch 3 taken 119104 times.
6336779 if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
1739
2/2
✓ Branch 0 taken 6074852 times.
✓ Branch 1 taken 74917 times.
6149769 x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1740
2/2
✓ Branch 0 taken 5857387 times.
✓ Branch 1 taken 217465 times.
6074852 y_off >= pic_height - block_h - QPEL_EXTRA_AFTER ||
1741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5857387 times.
5857387 ref == s->cur_frame->f) {
1742 479392 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1743 479392 int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1744 479392 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1745
1746 479392 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 479392 src = lc->edge_emu_buffer + buf_offset;
1753 479392 srcstride = edge_emu_stride;
1754 }
1755
1756
2/2
✓ Branch 0 taken 6208690 times.
✓ Branch 1 taken 128089 times.
6336779 if (!weight_flag)
1757 6208690 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride,
1758 block_h, mx, my, block_w);
1759 else
1760 128089 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride,
1761 128089 block_h, s->sh.luma_log2_weight_denom,
1762 luma_weight, luma_offset, mx, my, block_w);
1763 6336779 }
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 3987103 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 3987103 const HEVCContext *const s = lc->parent;
1789 3987103 ptrdiff_t src0stride = ref0->linesize[0];
1790 3987103 ptrdiff_t src1stride = ref1->linesize[0];
1791 3987103 int pic_width = sps->width;
1792 3987103 int pic_height = sps->height;
1793 3987103 int mx0 = mv0->x & 3;
1794 3987103 int my0 = mv0->y & 3;
1795 3987103 int mx1 = mv1->x & 3;
1796 3987103 int my1 = mv1->y & 3;
1797
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3987103 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7974206 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1798
3/4
✓ Branch 0 taken 3987103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68518 times.
✓ Branch 3 taken 3918585 times.
3987103 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1799 3987103 int x_off0 = x_off + (mv0->x >> 2);
1800 3987103 int y_off0 = y_off + (mv0->y >> 2);
1801 3987103 int x_off1 = x_off + (mv1->x >> 2);
1802 3987103 int y_off1 = y_off + (mv1->y >> 2);
1803 3987103 int idx = hevc_pel_weight[block_w];
1804
1805 3987103 const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1806 3987103 const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1807
1808
4/4
✓ Branch 0 taken 3929643 times.
✓ Branch 1 taken 57460 times.
✓ Branch 2 taken 3822909 times.
✓ Branch 3 taken 106734 times.
3987103 if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER ||
1809
2/2
✓ Branch 0 taken 3754531 times.
✓ Branch 1 taken 68378 times.
3822909 x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1810
2/2
✓ Branch 0 taken 209020 times.
✓ Branch 1 taken 3545511 times.
3754531 y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1811 441592 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1812 441592 int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1813 441592 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1814
1815 441592 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 441592 src0 = lc->edge_emu_buffer + buf_offset;
1822 441592 src0stride = edge_emu_stride;
1823 }
1824
1825
4/4
✓ Branch 0 taken 3923441 times.
✓ Branch 1 taken 63662 times.
✓ Branch 2 taken 3817362 times.
✓ Branch 3 taken 106079 times.
3987103 if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER ||
1826
2/2
✓ Branch 0 taken 3747077 times.
✓ Branch 1 taken 70285 times.
3817362 x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1827
2/2
✓ Branch 0 taken 212193 times.
✓ Branch 1 taken 3534884 times.
3747077 y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1828 452219 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1829 452219 int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1830 452219 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1831
1832 452219 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 452219 src1 = lc->edge_emu_buffer2 + buf_offset;
1839 452219 src1stride = edge_emu_stride;
1840 }
1841
1842 3987103 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 3918585 times.
✓ Branch 1 taken 68518 times.
3987103 if (!weight_flag)
1845 3918585 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 3987103 }
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 12673558 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 12673558 const HEVCContext *const s = lc->parent;
1883 12673558 int pic_width = sps->width >> sps->hshift[1];
1884 12673558 int pic_height = sps->height >> sps->vshift[1];
1885 12673558 const Mv *mv = &current_mv->mv[reflist];
1886
4/4
✓ Branch 0 taken 6556204 times.
✓ Branch 1 taken 6117354 times.
✓ Branch 2 taken 6440478 times.
✓ Branch 3 taken 115726 times.
25231390 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1887
4/4
✓ Branch 0 taken 6117354 times.
✓ Branch 1 taken 6440478 times.
✓ Branch 2 taken 140452 times.
✓ Branch 3 taken 5976902 times.
12557832 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1888 12673558 int idx = hevc_pel_weight[block_w];
1889 12673558 int hshift = sps->hshift[1];
1890 12673558 int vshift = sps->vshift[1];
1891 12673558 intptr_t mx = av_zero_extend(mv->x, 2 + hshift);
1892 12673558 intptr_t my = av_zero_extend(mv->y, 2 + vshift);
1893 12673558 intptr_t _mx = mx << (1 - hshift);
1894 12673558 intptr_t _my = my << (1 - vshift);
1895
2/4
✓ Branch 0 taken 12673558 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12673558 times.
12673558 int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2];
1896
1897 12673558 x_off += mv->x >> (2 + hshift);
1898 12673558 y_off += mv->y >> (2 + vshift);
1899 12673558 src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1900
1901
4/4
✓ Branch 0 taken 12550922 times.
✓ Branch 1 taken 122636 times.
✓ Branch 2 taken 12312568 times.
✓ Branch 3 taken 238354 times.
12673558 if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1902
2/2
✓ Branch 0 taken 12162742 times.
✓ Branch 1 taken 149826 times.
12312568 x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1903
3/4
✓ Branch 0 taken 11727734 times.
✓ Branch 1 taken 435008 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11727734 times.
12162742 y_off >= pic_height - block_h - EPEL_EXTRA_AFTER ||
1904 emu) {
1905 945824 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1906 945824 int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift));
1907 945824 int buf_offset0 = EPEL_EXTRA_BEFORE *
1908 945824 (edge_emu_stride + (1 << sps->pixel_shift));
1909 945824 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 945824 src0 = lc->edge_emu_buffer + buf_offset0;
1917 945824 srcstride = edge_emu_stride;
1918 }
1919
2/2
✓ Branch 0 taken 12417380 times.
✓ Branch 1 taken 256178 times.
12673558 if (!weight_flag)
1920 12417380 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1921 block_h, _mx, _my, block_w);
1922 else
1923 256178 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1924 256178 block_h, s->sh.chroma_log2_weight_denom,
1925 chroma_weight, chroma_offset, _mx, _my, block_w);
1926 12673558 }
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 7974206 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 7974206 const HEVCContext *const s = lc->parent;
1952 7974206 const uint8_t *src1 = ref0->data[cidx+1];
1953 7974206 const uint8_t *src2 = ref1->data[cidx+1];
1954 7974206 ptrdiff_t src1stride = ref0->linesize[cidx+1];
1955 7974206 ptrdiff_t src2stride = ref1->linesize[cidx+1];
1956
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7974206 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15948412 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1957
3/4
✓ Branch 0 taken 7974206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 137036 times.
✓ Branch 3 taken 7837170 times.
7974206 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1958 7974206 int pic_width = sps->width >> sps->hshift[1];
1959 7974206 int pic_height = sps->height >> sps->vshift[1];
1960 7974206 const Mv *const mv0 = &current_mv->mv[0];
1961 7974206 const Mv *const mv1 = &current_mv->mv[1];
1962 7974206 int hshift = sps->hshift[1];
1963 7974206 int vshift = sps->vshift[1];
1964
1965 7974206 intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift);
1966 7974206 intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift);
1967 7974206 intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift);
1968 7974206 intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift);
1969 7974206 intptr_t _mx0 = mx0 << (1 - hshift);
1970 7974206 intptr_t _my0 = my0 << (1 - vshift);
1971 7974206 intptr_t _mx1 = mx1 << (1 - hshift);
1972 7974206 intptr_t _my1 = my1 << (1 - vshift);
1973
1974 7974206 int x_off0 = x_off + (mv0->x >> (2 + hshift));
1975 7974206 int y_off0 = y_off + (mv0->y >> (2 + vshift));
1976 7974206 int x_off1 = x_off + (mv1->x >> (2 + hshift));
1977 7974206 int y_off1 = y_off + (mv1->y >> (2 + vshift));
1978 7974206 int idx = hevc_pel_weight[block_w];
1979 7974206 src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1980 7974206 src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1981
1982
4/4
✓ Branch 0 taken 7865544 times.
✓ Branch 1 taken 108662 times.
✓ Branch 2 taken 7651964 times.
✓ Branch 3 taken 213580 times.
7974206 if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER ||
1983
2/2
✓ Branch 0 taken 7515212 times.
✓ Branch 1 taken 136752 times.
7651964 x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1984
2/2
✓ Branch 0 taken 417452 times.
✓ Branch 1 taken 7097760 times.
7515212 y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1985 876446 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1986 876446 int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift));
1987 876446 int buf_offset1 = EPEL_EXTRA_BEFORE *
1988 876446 (edge_emu_stride + (1 << sps->pixel_shift));
1989
1990 876446 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 876446 src1 = lc->edge_emu_buffer + buf_offset1;
1998 876446 src1stride = edge_emu_stride;
1999 }
2000
2001
4/4
✓ Branch 0 taken 7852278 times.
✓ Branch 1 taken 121928 times.
✓ Branch 2 taken 7640398 times.
✓ Branch 3 taken 211880 times.
7974206 if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER ||
2002
2/2
✓ Branch 0 taken 7499834 times.
✓ Branch 1 taken 140564 times.
7640398 x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
2003
2/2
✓ Branch 0 taken 424060 times.
✓ Branch 1 taken 7075774 times.
7499834 y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
2004 898432 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
2005 898432 int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift));
2006 898432 int buf_offset1 = EPEL_EXTRA_BEFORE *
2007 898432 (edge_emu_stride + (1 << sps->pixel_shift));
2008
2009 898432 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 898432 src2 = lc->edge_emu_buffer2 + buf_offset1;
2017 898432 src2stride = edge_emu_stride;
2018 }
2019
2020 7974206 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 7837170 times.
✓ Branch 1 taken 137036 times.
7974206 if (!weight_flag)
2023 7837170 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
2024 7837170 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 7974206 }
2037
2038 14310985 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 14199853 times.
14310985 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 14310985 }
2047
2048 2832183 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 2832183 const HEVCContext *const s = lc->parent;
2055 2832183 enum InterPredIdc inter_pred_idc = PRED_L0;
2056 int mvp_flag;
2057
2058 2832183 ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size);
2059 2832183 mv->pred_flag = 0;
2060
2/2
✓ Branch 0 taken 1922264 times.
✓ Branch 1 taken 909919 times.
2832183 if (s->sh.slice_type == HEVC_SLICE_B)
2061 1922264 inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH);
2062
2063
2/2
✓ Branch 0 taken 2423165 times.
✓ Branch 1 taken 409018 times.
2832183 if (inter_pred_idc != PRED_L1) {
2064
1/2
✓ Branch 0 taken 2423165 times.
✗ Branch 1 not taken.
2423165 if (s->sh.nb_refs[L0])
2065 2423165 mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]);
2066
2067 2423165 mv->pred_flag = PF_L0;
2068 2423165 ff_hevc_hls_mvd_coding(lc, x0, y0, 0);
2069 2423165 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2070 2423165 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 2423165 mv->mv[0].x += lc->pu.mvd.x;
2073 2423165 mv->mv[0].y += lc->pu.mvd.y;
2074 }
2075
2076
2/2
✓ Branch 0 taken 833873 times.
✓ Branch 1 taken 1998310 times.
2832183 if (inter_pred_idc != PRED_L0) {
2077
1/2
✓ Branch 0 taken 833873 times.
✗ Branch 1 not taken.
833873 if (s->sh.nb_refs[L1])
2078 833873 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 640701 times.
✓ Branch 2 taken 163605 times.
✓ Branch 3 taken 29567 times.
833873 if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) {
2081 163605 AV_ZERO32(&lc->pu.mvd);
2082 } else {
2083 670268 ff_hevc_hls_mvd_coding(lc, x0, y0, 1);
2084 }
2085
2086 833873 mv->pred_flag += PF_L1;
2087 833873 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2088 833873 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 833873 mv->mv[1].x += lc->pu.mvd.x;
2091 833873 mv->mv[1].y += lc->pu.mvd.y;
2092 }
2093 2832183 }
2094
2095 10323882 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 10323882 const HEVCContext *const s = lc->parent;
2106 10323882 int merge_idx = 0;
2107 10323882 struct MvField current_mv = {{{ 0 }}};
2108
2109 10323882 int min_pu_width = sps->min_pu_width;
2110
2111 10323882 MvField *tab_mvf = s->cur_frame->tab_mvf;
2112 10323882 const RefPicList *refPicList = s->cur_frame->refPicList;
2113 10323882 const HEVCFrame *ref0 = NULL, *ref1 = NULL;
2114 10323882 const int *linesize = s->cur_frame->f->linesize;
2115 10323882 uint8_t *dst0 = s->cur_frame->f->data[0] + y0 * linesize[0] + (x0 << sps->pixel_shift);
2116
1/2
✓ Branch 0 taken 10323882 times.
✗ Branch 1 not taken.
10323882 uint8_t *dst1 = POS(1, x0, y0);
2117
1/2
✓ Branch 0 taken 10323882 times.
✗ Branch 1 not taken.
10323882 uint8_t *dst2 = POS(2, x0, y0);
2118 10323882 int log2_min_cb_size = sps->log2_min_cb_size;
2119 10323882 int min_cb_width = sps->min_cb_width;
2120 10323882 int x_cb = x0 >> log2_min_cb_size;
2121 10323882 int y_cb = y0 >> log2_min_cb_size;
2122 int x_pu, y_pu;
2123 int i, j;
2124
2125 10323882 int skip_flag = SAMPLE_CTB(l->skip_flag, x_cb, y_cb);
2126
2127
2/2
✓ Branch 0 taken 5767266 times.
✓ Branch 1 taken 4556616 times.
10323882 if (!skip_flag)
2128 5767266 lc->pu.merge_flag = ff_hevc_merge_flag_decode(lc);
2129
2130
4/4
✓ Branch 0 taken 5767266 times.
✓ Branch 1 taken 4556616 times.
✓ Branch 2 taken 2935083 times.
✓ Branch 3 taken 2832183 times.
10323882 if (skip_flag || lc->pu.merge_flag) {
2131
2/2
✓ Branch 0 taken 7414846 times.
✓ Branch 1 taken 76853 times.
7491699 if (s->sh.max_num_merge_cand > 1)
2132 7414846 merge_idx = ff_hevc_merge_idx_decode(lc);
2133 else
2134 76853 merge_idx = 0;
2135
2136 7491699 ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2137 partIdx, merge_idx, &current_mv);
2138 } else {
2139 2832183 hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size,
2140 partIdx, merge_idx, &current_mv);
2141 }
2142
2143 10323882 x_pu = x0 >> sps->log2_min_pu_size;
2144 10323882 y_pu = y0 >> sps->log2_min_pu_size;
2145
2146
2/2
✓ Branch 0 taken 40327770 times.
✓ Branch 1 taken 10323882 times.
50651652 for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++)
2147
2/2
✓ Branch 0 taken 257343500 times.
✓ Branch 1 taken 40327770 times.
297671270 for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++)
2148 257343500 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
2149
2150
2/2
✓ Branch 0 taken 9506734 times.
✓ Branch 1 taken 817148 times.
10323882 if (current_mv.pred_flag & PF_L0) {
2151 9506734 ref0 = refPicList[0].ref[current_mv.ref_idx[0]];
2152
2/4
✓ Branch 0 taken 9506734 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9506734 times.
9506734 if (!ref0 || !ref0->f)
2153 return;
2154 9506734 hevc_await_progress(s, ref0, &current_mv.mv[0], y0, nPbH);
2155 }
2156
2/2
✓ Branch 0 taken 4804251 times.
✓ Branch 1 taken 5519631 times.
10323882 if (current_mv.pred_flag & PF_L1) {
2157 4804251 ref1 = refPicList[1].ref[current_mv.ref_idx[1]];
2158
2/4
✓ Branch 0 taken 4804251 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4804251 times.
4804251 if (!ref1 || !ref1->f)
2159 return;
2160 4804251 hevc_await_progress(s, ref1, &current_mv.mv[1], y0, nPbH);
2161 }
2162
2163
2/2
✓ Branch 0 taken 5519631 times.
✓ Branch 1 taken 4804251 times.
10323882 if (current_mv.pred_flag == PF_L0) {
2164 5519631 int x0_c = x0 >> sps->hshift[1];
2165 5519631 int y0_c = y0 >> sps->vshift[1];
2166 5519631 int nPbW_c = nPbW >> sps->hshift[1];
2167 5519631 int nPbH_c = nPbH >> sps->vshift[1];
2168
2169 5519631 luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f,
2170 &current_mv.mv[0], x0, y0, nPbW, nPbH,
2171 5519631 s->sh.luma_weight_l0[current_mv.ref_idx[0]],
2172 5519631 s->sh.luma_offset_l0[current_mv.ref_idx[0]]);
2173
2174
1/2
✓ Branch 0 taken 5519631 times.
✗ Branch 1 not taken.
5519631 if (sps->chroma_format_idc) {
2175 5519631 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 5519631 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]);
2178 5519631 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 5519631 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 817148 times.
✓ Branch 1 taken 3987103 times.
4804251 } else if (current_mv.pred_flag == PF_L1) {
2183 817148 int x0_c = x0 >> sps->hshift[1];
2184 817148 int y0_c = y0 >> sps->vshift[1];
2185 817148 int nPbW_c = nPbW >> sps->hshift[1];
2186 817148 int nPbH_c = nPbH >> sps->vshift[1];
2187
2188 817148 luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f,
2189 &current_mv.mv[1], x0, y0, nPbW, nPbH,
2190 817148 s->sh.luma_weight_l1[current_mv.ref_idx[1]],
2191 817148 s->sh.luma_offset_l1[current_mv.ref_idx[1]]);
2192
2193
1/2
✓ Branch 0 taken 817148 times.
✗ Branch 1 not taken.
817148 if (sps->chroma_format_idc) {
2194 817148 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 817148 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]);
2197
2198 817148 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 817148 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 3987103 times.
✗ Branch 1 not taken.
3987103 } else if (current_mv.pred_flag == PF_BI) {
2203 3987103 int x0_c = x0 >> sps->hshift[1];
2204 3987103 int y0_c = y0 >> sps->vshift[1];
2205 3987103 int nPbW_c = nPbW >> sps->hshift[1];
2206 3987103 int nPbH_c = nPbH >> sps->vshift[1];
2207
2208 3987103 luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f,
2209 &current_mv.mv[0], x0, y0, nPbW, nPbH,
2210 3987103 ref1->f, &current_mv.mv[1], &current_mv);
2211
2212
1/2
✓ Branch 0 taken 3987103 times.
✗ Branch 1 not taken.
3987103 if (sps->chroma_format_idc) {
2213 3987103 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 3987103 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 8600675 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 8600675 const HEVCContext *const s = lc->parent;
2231 8600675 int x_pu = x0 >> sps->log2_min_pu_size;
2232 8600675 int y_pu = y0 >> sps->log2_min_pu_size;
2233 8600675 int min_pu_width = sps->min_pu_width;
2234 8600675 int size_in_pus = pu_size >> sps->log2_min_pu_size;
2235 8600675 int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2236 8600675 int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2237
2238
2/2
✓ Branch 0 taken 1088336 times.
✓ Branch 1 taken 128938 times.
1217274 int cand_up = (lc->ctb_up_flag || y0b) ?
2239
2/2
✓ Branch 0 taken 1217274 times.
✓ Branch 1 taken 7383401 times.
9817949 l->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
2240
2/2
✓ Branch 0 taken 612794 times.
✓ Branch 1 taken 85816 times.
698610 int cand_left = (lc->ctb_left_flag || x0b) ?
2241
2/2
✓ Branch 0 taken 698610 times.
✓ Branch 1 taken 7902065 times.
9299285 l->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC;
2242
2243 8600675 int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size);
2244
2245 8600675 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 1159511 times.
✓ Branch 1 taken 7441164 times.
8600675 if ((y0 - 1) < y_ctb)
2252 1159511 cand_up = INTRA_DC;
2253
2254
2/2
✓ Branch 0 taken 1851082 times.
✓ Branch 1 taken 6749593 times.
8600675 if (cand_left == cand_up) {
2255
2/2
✓ Branch 0 taken 1133316 times.
✓ Branch 1 taken 717766 times.
1851082 if (cand_left < 2) {
2256 1133316 candidate[0] = INTRA_PLANAR;
2257 1133316 candidate[1] = INTRA_DC;
2258 1133316 candidate[2] = INTRA_ANGULAR_26;
2259 } else {
2260 717766 candidate[0] = cand_left;
2261 717766 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2262 717766 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2263 }
2264 } else {
2265 6749593 candidate[0] = cand_left;
2266 6749593 candidate[1] = cand_up;
2267
4/4
✓ Branch 0 taken 5588591 times.
✓ Branch 1 taken 1161002 times.
✓ Branch 2 taken 4611636 times.
✓ Branch 3 taken 976955 times.
6749593 if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) {
2268 4611636 candidate[2] = INTRA_PLANAR;
2269
4/4
✓ Branch 0 taken 1869152 times.
✓ Branch 1 taken 268805 times.
✓ Branch 2 taken 1399786 times.
✓ Branch 3 taken 469366 times.
2137957 } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) {
2270 1399786 candidate[2] = INTRA_DC;
2271 } else {
2272 738171 candidate[2] = INTRA_ANGULAR_26;
2273 }
2274 }
2275
2276
2/2
✓ Branch 0 taken 5156639 times.
✓ Branch 1 taken 3444036 times.
8600675 if (prev_intra_luma_pred_flag) {
2277 5156639 intra_pred_mode = candidate[lc->pu.mpm_idx];
2278 } else {
2279
2/2
✓ Branch 0 taken 1627711 times.
✓ Branch 1 taken 1816325 times.
3444036 if (candidate[0] > candidate[1])
2280 1627711 FFSWAP(uint8_t, candidate[0], candidate[1]);
2281
2/2
✓ Branch 0 taken 2020031 times.
✓ Branch 1 taken 1424005 times.
3444036 if (candidate[0] > candidate[2])
2282 2020031 FFSWAP(uint8_t, candidate[0], candidate[2]);
2283
2/2
✓ Branch 0 taken 2538529 times.
✓ Branch 1 taken 905507 times.
3444036 if (candidate[1] > candidate[2])
2284 2538529 FFSWAP(uint8_t, candidate[1], candidate[2]);
2285
2286 3444036 intra_pred_mode = lc->pu.rem_intra_luma_pred_mode;
2287
2/2
✓ Branch 0 taken 10332108 times.
✓ Branch 1 taken 3444036 times.
13776144 for (i = 0; i < 3; i++)
2288
2/2
✓ Branch 0 taken 7526216 times.
✓ Branch 1 taken 2805892 times.
10332108 if (intra_pred_mode >= candidate[i])
2289 7526216 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 8600675 times.
8600675 if (!size_in_pus)
2294 size_in_pus = 1;
2295
2/2
✓ Branch 0 taken 15548940 times.
✓ Branch 1 taken 8600675 times.
24149615 for (i = 0; i < size_in_pus; i++) {
2296 15548940 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 51291692 times.
✓ Branch 1 taken 15548940 times.
66840632 for (j = 0; j < size_in_pus; j++) {
2300 51291692 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA;
2301 }
2302 }
2303
2304 8600675 return intra_pred_mode;
2305 }
2306
2307 13217779 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 13217779 int length = (1 << log2_cb_size) >> sps->log2_min_cb_size;
2312 13217779 int x_cb = x0 >> sps->log2_min_cb_size;
2313 13217779 int y_cb = y0 >> sps->log2_min_cb_size;
2314 int y;
2315
2316
2/2
✓ Branch 0 taken 24896529 times.
✓ Branch 1 taken 13217779 times.
38114308 for (y = 0; y < length; y++)
2317 24896529 memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb],
2318 ct_depth, length);
2319 13217779 }
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 4616288 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 4616288 int split = lc->cu.part_mode == PART_NxN;
2333 4616288 int pb_size = (1 << log2_cb_size) >> split;
2334 4616288 int side = split + 1;
2335 int chroma_mode;
2336 int i, j;
2337
2338
2/2
✓ Branch 0 taken 5944417 times.
✓ Branch 1 taken 4616288 times.
10560705 for (i = 0; i < side; i++)
2339
2/2
✓ Branch 0 taken 8600675 times.
✓ Branch 1 taken 5944417 times.
14545092 for (j = 0; j < side; j++)
2340 8600675 prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc);
2341
2342
2/2
✓ Branch 0 taken 5944417 times.
✓ Branch 1 taken 4616288 times.
10560705 for (i = 0; i < side; i++) {
2343
2/2
✓ Branch 0 taken 8600675 times.
✓ Branch 1 taken 5944417 times.
14545092 for (j = 0; j < side; j++) {
2344
2/2
✓ Branch 0 taken 5156639 times.
✓ Branch 1 taken 3444036 times.
8600675 if (prev_intra_luma_pred_flag[2 * i + j])
2345 5156639 lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc);
2346 else
2347 3444036 lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc);
2348
2349 8600675 lc->pu.intra_pred_mode[2 * i + j] =
2350 8600675 luma_intra_pred_mode(lc, l, sps,
2351 8600675 x0 + pb_size * j, y0 + pb_size * i, pb_size,
2352 8600675 prev_intra_luma_pred_flag[2 * i + j]);
2353 }
2354 }
2355
2356
2/2
✓ Branch 0 taken 105006 times.
✓ Branch 1 taken 4511282 times.
4616288 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 4264176 times.
4511282 } 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 4263984 times.
✓ Branch 1 taken 192 times.
4264176 } else if (sps->chroma_format_idc != 0) {
2383 4263984 chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2384
2/2
✓ Branch 0 taken 1026603 times.
✓ Branch 1 taken 3237381 times.
4263984 if (chroma_mode != 4) {
2385
2/2
✓ Branch 0 taken 76400 times.
✓ Branch 1 taken 950203 times.
1026603 if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2386 76400 lc->pu.intra_pred_mode_c[0] = 34;
2387 else
2388 950203 lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode];
2389 } else {
2390 3237381 lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0];
2391 }
2392 }
2393 4616288 }
2394
2395 8601492 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 8601492 const HEVCContext *const s = lc->parent;
2402 8601492 int pb_size = 1 << log2_cb_size;
2403 8601492 int size_in_pus = pb_size >> sps->log2_min_pu_size;
2404 8601492 int min_pu_width = sps->min_pu_width;
2405 8601492 MvField *tab_mvf = s->cur_frame->tab_mvf;
2406 8601492 int x_pu = x0 >> sps->log2_min_pu_size;
2407 8601492 int y_pu = y0 >> sps->log2_min_pu_size;
2408 int j, k;
2409
2410
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8601492 times.
8601492 if (size_in_pus == 0)
2411 size_in_pus = 1;
2412
2/2
✓ Branch 0 taken 36900378 times.
✓ Branch 1 taken 8601492 times.
45501870 for (j = 0; j < size_in_pus; j++)
2413 36900378 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 8589059 times.
8601492 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 8601492 }
2419
2420 13217780 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 13217780 int cb_size = 1 << log2_cb_size;
2426 13217780 int log2_min_cb_size = sps->log2_min_cb_size;
2427 13217780 int length = cb_size >> log2_min_cb_size;
2428 13217780 int min_cb_width = sps->min_cb_width;
2429 13217780 int x_cb = x0 >> log2_min_cb_size;
2430 13217780 int y_cb = y0 >> log2_min_cb_size;
2431 13217780 int idx = log2_cb_size - 2;
2432 13217780 int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2433 int x, y, ret;
2434
2435 13217780 lc->cu.x = x0;
2436 13217780 lc->cu.y = y0;
2437 13217780 lc->cu.pred_mode = MODE_INTRA;
2438 13217780 lc->cu.part_mode = PART_2Nx2N;
2439 13217780 lc->cu.intra_split_flag = 0;
2440
2441 13217780 SAMPLE_CTB(l->skip_flag, x_cb, y_cb) = 0;
2442
2/2
✓ Branch 0 taken 52871120 times.
✓ Branch 1 taken 13217780 times.
66088900 for (x = 0; x < 4; x++)
2443 52871120 lc->pu.intra_pred_mode[x] = 1;
2444
2/2
✓ Branch 0 taken 211788 times.
✓ Branch 1 taken 13005992 times.
13217780 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 13005992 lc->cu.cu_transquant_bypass_flag = 0;
2450
2451
2/2
✓ Branch 0 taken 9856276 times.
✓ Branch 1 taken 3361504 times.
13217780 if (s->sh.slice_type != HEVC_SLICE_I) {
2452 9856276 const int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2453 9856276 const int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2454 9856276 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 9856276 x = y_cb * min_cb_width + x_cb;
2459
2/2
✓ Branch 0 taken 20351921 times.
✓ Branch 1 taken 9856276 times.
30208197 for (y = 0; y < length; y++) {
2460 20351921 memset(&l->skip_flag[x], skip_flag, length);
2461 20351921 x += min_cb_width;
2462 }
2463
2/2
✓ Branch 0 taken 4556616 times.
✓ Branch 1 taken 5299660 times.
9856276 lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER;
2464 } else {
2465 3361504 x = y_cb * min_cb_width + x_cb;
2466
2/2
✓ Branch 0 taken 4544609 times.
✓ Branch 1 taken 3361504 times.
7906113 for (y = 0; y < length; y++) {
2467 4544609 memset(&l->skip_flag[x], 0, length);
2468 4544609 x += min_cb_width;
2469 }
2470 }
2471
2472
2/2
✓ Branch 0 taken 4556616 times.
✓ Branch 1 taken 8661164 times.
13217780 if (SAMPLE_CTB(l->skip_flag, x_cb, y_cb)) {
2473 4556616 hls_prediction_unit(lc, l, pps, sps,
2474 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2475 4556616 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2476
2477
2/2
✓ Branch 0 taken 4410103 times.
✓ Branch 1 taken 146513 times.
4556616 if (!s->sh.disable_deblocking_filter_flag)
2478 4410103 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2479 } else {
2480 8661164 int pcm_flag = 0;
2481
2482
2/2
✓ Branch 0 taken 5299660 times.
✓ Branch 1 taken 3361504 times.
8661164 if (s->sh.slice_type != HEVC_SLICE_I)
2483 5299660 lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc);
2484
2/2
✓ Branch 0 taken 4628721 times.
✓ Branch 1 taken 4032443 times.
8661164 if (lc->cu.pred_mode != MODE_INTRA ||
2485
2/2
✓ Branch 0 taken 3491591 times.
✓ Branch 1 taken 1137130 times.
4628721 log2_cb_size == sps->log2_min_cb_size) {
2486 7524034 lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size);
2487
2/2
✓ Branch 0 taken 1436284 times.
✓ Branch 1 taken 6087750 times.
8960318 lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
2488
2/2
✓ Branch 0 taken 1328129 times.
✓ Branch 1 taken 108155 times.
1436284 lc->cu.pred_mode == MODE_INTRA;
2489 }
2490
2491
2/2
✓ Branch 0 taken 4628721 times.
✓ Branch 1 taken 4032443 times.
8661164 if (lc->cu.pred_mode == MODE_INTRA) {
2492
4/4
✓ Branch 0 taken 3300592 times.
✓ Branch 1 taken 1328129 times.
✓ Branch 2 taken 162684 times.
✓ Branch 3 taken 3137908 times.
4628721 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 4616288 times.
4628721 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 4616288 intra_prediction_unit(lc, l, sps, x0, y0, log2_cb_size);
2507 }
2508 } else {
2509 4032443 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2510
8/9
✓ Branch 0 taken 2513930 times.
✓ Branch 1 taken 499137 times.
✓ Branch 2 taken 599704 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.
4032443 switch (lc->cu.part_mode) {
2511 2513930 case PART_2Nx2N:
2512 2513930 hls_prediction_unit(lc, l, pps, sps,
2513 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2514 2513930 break;
2515 499137 case PART_2NxN:
2516 499137 hls_prediction_unit(lc, l, pps, sps,
2517 x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2518 499137 hls_prediction_unit(lc, l, pps, sps,
2519 499137 x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2520 499137 break;
2521 599704 case PART_Nx2N:
2522 599704 hls_prediction_unit(lc, l, pps, sps,
2523 x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2524 599704 hls_prediction_unit(lc, l, pps, sps,
2525 599704 x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2526 599704 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 8648731 times.
✓ Branch 1 taken 12433 times.
8661164 if (!pcm_flag) {
2565 8648731 int rqt_root_cbf = 1;
2566
2567
2/2
✓ Branch 0 taken 4032443 times.
✓ Branch 1 taken 4616288 times.
8648731 if (lc->cu.pred_mode != MODE_INTRA &&
2568
4/4
✓ Branch 0 taken 2513930 times.
✓ Branch 1 taken 1518513 times.
✓ Branch 2 taken 1307108 times.
✓ Branch 3 taken 1206822 times.
4032443 !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) {
2569 2825621 rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc);
2570 }
2571
2/2
✓ Branch 0 taken 7133172 times.
✓ Branch 1 taken 1515559 times.
8648731 if (rqt_root_cbf) {
2572 const static int cbf[2] = { 0 };
2573
2/2
✓ Branch 0 taken 4616288 times.
✓ Branch 1 taken 2516884 times.
7133172 lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ?
2574 4616288 sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
2575 2516884 sps->max_transform_hierarchy_depth_inter;
2576 7133172 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 7133171 times.
7133172 if (ret < 0)
2580 1 return ret;
2581 } else {
2582
2/2
✓ Branch 0 taken 1459127 times.
✓ Branch 1 taken 56432 times.
1515559 if (!s->sh.disable_deblocking_filter_flag)
2583 1459127 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2584 }
2585 }
2586 }
2587
2588
4/4
✓ Branch 0 taken 3405035 times.
✓ Branch 1 taken 9812744 times.
✓ Branch 2 taken 1180207 times.
✓ Branch 3 taken 2224828 times.
13217779 if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
2589 1180207 ff_hevc_set_qPy(lc, l, pps, x0, y0, log2_cb_size);
2590
2591 13217779 x = y_cb * min_cb_width + x_cb;
2592
2/2
✓ Branch 0 taken 24896529 times.
✓ Branch 1 taken 13217779 times.
38114308 for (y = 0; y < length; y++) {
2593 24896529 memset(&l->qp_y_tab[x], lc->qp_y, length);
2594 24896529 x += min_cb_width;
2595 }
2596
2597
2/2
✓ Branch 0 taken 4758392 times.
✓ Branch 1 taken 8459387 times.
13217779 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2598
2/2
✓ Branch 0 taken 2860287 times.
✓ Branch 1 taken 1898105 times.
4758392 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2599 2860287 lc->qPy_pred = lc->qp_y;
2600 }
2601
2602 13217779 set_ct_depth(sps, l->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth);
2603
2604 13217779 return 0;
2605 }
2606
2607 17117233 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 17117233 const HEVCContext *const s = lc->parent;
2614 17117233 const int cb_size = 1 << log2_cb_size;
2615 int ret;
2616 int split_cu;
2617
2618 17117233 lc->ct_depth = cb_depth;
2619
2/2
✓ Branch 0 taken 17088266 times.
✓ Branch 1 taken 28967 times.
17117233 if (x0 + cb_size <= sps->width &&
2620
2/2
✓ Branch 0 taken 16762557 times.
✓ Branch 1 taken 325709 times.
17088266 y0 + cb_size <= sps->height &&
2621
2/2
✓ Branch 0 taken 9242043 times.
✓ Branch 1 taken 7520514 times.
16762557 log2_cb_size > sps->log2_min_cb_size) {
2622 9242043 split_cu = ff_hevc_split_coding_unit_flag_decode(lc, l->tab_ct_depth,
2623 sps, cb_depth, x0, y0);
2624 } else {
2625 7875190 split_cu = (log2_cb_size > sps->log2_min_cb_size);
2626 }
2627
2/2
✓ Branch 0 taken 4320277 times.
✓ Branch 1 taken 12796956 times.
17117233 if (pps->cu_qp_delta_enabled_flag &&
2628
2/2
✓ Branch 0 taken 2016923 times.
✓ Branch 1 taken 2303354 times.
4320277 log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) {
2629 2016923 lc->tu.is_cu_qp_delta_coded = 0;
2630 2016923 lc->tu.cu_qp_delta = 0;
2631 }
2632
2633
2/2
✓ Branch 0 taken 519326 times.
✓ Branch 1 taken 16597907 times.
17117233 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 3899453 times.
✓ Branch 1 taken 13217780 times.
17117233 if (split_cu) {
2639 3899453 int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2640 3899453 const int cb_size_split = cb_size >> 1;
2641 3899453 const int x1 = x0 + cb_size_split;
2642 3899453 const int y1 = y0 + cb_size_split;
2643
2644 3899453 int more_data = 0;
2645
2646 3899453 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 3899451 times.
3899453 if (more_data < 0)
2649 2 return more_data;
2650
2651
4/4
✓ Branch 0 taken 3899442 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3871497 times.
✓ Branch 3 taken 27945 times.
3899451 if (more_data && x1 < sps->width) {
2652 3871497 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 3871497 times.
3871497 if (more_data < 0)
2655 return more_data;
2656 }
2657
4/4
✓ Branch 0 taken 3888969 times.
✓ Branch 1 taken 10482 times.
✓ Branch 2 taken 3684910 times.
✓ Branch 3 taken 204059 times.
3899451 if (more_data && y1 < sps->height) {
2658 3684910 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 3684910 times.
3684910 if (more_data < 0)
2661 return more_data;
2662 }
2663
4/4
✓ Branch 0 taken 3882845 times.
✓ Branch 1 taken 16606 times.
✓ Branch 2 taken 3861024 times.
✓ Branch 3 taken 21821 times.
3899451 if (more_data && x1 < sps->width &&
2664
2/2
✓ Branch 0 taken 3656965 times.
✓ Branch 1 taken 204059 times.
3861024 y1 < sps->height) {
2665 3656965 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 3656964 times.
3656965 if (more_data < 0)
2668 1 return more_data;
2669 }
2670
2671
2/2
✓ Branch 0 taken 2258974 times.
✓ Branch 1 taken 1640476 times.
3899450 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2672
2/2
✓ Branch 0 taken 1709859 times.
✓ Branch 1 taken 549115 times.
2258974 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2673 1709859 lc->qPy_pred = lc->qp_y;
2674
2675
2/2
✓ Branch 0 taken 3863186 times.
✓ Branch 1 taken 36264 times.
3899450 if (more_data)
2676
2/2
✓ Branch 0 taken 100066 times.
✓ Branch 1 taken 3763120 times.
3963252 return ((x1 + cb_size_split) < sps->width ||
2677
2/2
✓ Branch 0 taken 100065 times.
✓ Branch 1 taken 1 times.
100066 (y1 + cb_size_split) < sps->height);
2678 else
2679 36264 return 0;
2680 } else {
2681 13217780 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 13217779 times.
13217780 if (ret < 0)
2683 1 return ret;
2684 13217779 if ((!((x0 + cb_size) %
2685
2/2
✓ Branch 0 taken 9300266 times.
✓ Branch 1 taken 3917513 times.
13217779 (1 << (sps->log2_ctb_size))) ||
2686
2/2
✓ Branch 0 taken 71472 times.
✓ Branch 1 taken 9228794 times.
9300266 (x0 + cb_size >= sps->width)) &&
2687 3988985 (!((y0 + cb_size) %
2688
2/2
✓ Branch 0 taken 2084233 times.
✓ Branch 1 taken 1904752 times.
3988985 (1 << (sps->log2_ctb_size))) ||
2689
2/2
✓ Branch 0 taken 99655 times.
✓ Branch 1 taken 1984578 times.
2084233 (y0 + cb_size >= sps->height))) {
2690 2004407 int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc);
2691 2004407 return !end_of_slice_flag;
2692 } else {
2693 11213372 return 1;
2694 }
2695 }
2696
2697 return 0;
2698 }
2699
2700 2004408 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 2004408 const HEVCContext *const s = lc->parent;
2706 2004408 int ctb_size = 1 << sps->log2_ctb_size;
2707 2004408 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2708 2004408 int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
2709
2710 2004408 l->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
2711
2712
2/2
✓ Branch 0 taken 169354 times.
✓ Branch 1 taken 1835054 times.
2004408 if (pps->entropy_coding_sync_enabled_flag) {
2713
3/4
✓ Branch 0 taken 7673 times.
✓ Branch 1 taken 161681 times.
✓ Branch 2 taken 7673 times.
✗ Branch 3 not taken.
169354 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2714 7673 lc->first_qp_group = 1;
2715 169354 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 2004408 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height);
2727
2728 2004408 lc->boundary_flags = 0;
2729
2/2
✓ Branch 0 taken 680802 times.
✓ Branch 1 taken 1323606 times.
2004408 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 18404 times.
✓ Branch 1 taken 1305202 times.
1323606 if (ctb_addr_in_slice <= 0)
2740 18404 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2741
2/2
✓ Branch 0 taken 198745 times.
✓ Branch 1 taken 1124861 times.
1323606 if (ctb_addr_in_slice < sps->ctb_width)
2742 198745 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2743 }
2744
2745
6/6
✓ Branch 0 taken 1915654 times.
✓ Branch 1 taken 88754 times.
✓ Branch 2 taken 1907511 times.
✓ Branch 3 taken 8143 times.
✓ Branch 4 taken 1865898 times.
✓ Branch 5 taken 41613 times.
2004408 lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
2746
6/6
✓ Branch 0 taken 1863400 times.
✓ Branch 1 taken 141008 times.
✓ Branch 2 taken 1769210 times.
✓ Branch 3 taken 94190 times.
✓ Branch 4 taken 1749090 times.
✓ Branch 5 taken 20120 times.
2004408 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 1863400 times.
✓ Branch 1 taken 141008 times.
✓ Branch 2 taken 1771802 times.
✓ Branch 3 taken 91598 times.
✓ Branch 4 taken 1698196 times.
✓ Branch 5 taken 73606 times.
2004408 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 1915654 times.
✓ Branch 1 taken 88754 times.
✓ Branch 2 taken 1785107 times.
✓ Branch 3 taken 130547 times.
✓ Branch 4 taken 1695730 times.
✓ Branch 5 taken 89377 times.
✓ Branch 6 taken 1639864 times.
✓ Branch 7 taken 55866 times.
2004408 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 2004408 }
2750
2751 28712 static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
2752 {
2753 28712 HEVCLocalContext *const lc = &s->local_ctx[0];
2754 28712 const HEVCLayerContext *const l = &s->layers[s->cur_layer];
2755 28712 const HEVCPPS *const pps = s->pps;
2756 28712 const HEVCSPS *const sps = pps->sps;
2757 28712 const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
2758 28712 const size_t slice_size = get_bits_bytesize(gb, 1) - s->sh.data_offset;
2759 28712 int ctb_size = 1 << sps->log2_ctb_size;
2760 28712 int more_data = 1;
2761 28712 int x_ctb = 0;
2762 28712 int y_ctb = 0;
2763 28712 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 2004408 times.
✓ Branch 1 taken 28711 times.
✓ Branch 2 taken 2004408 times.
✗ Branch 3 not taken.
2033119 while (more_data && ctb_addr_ts < sps->ctb_size) {
2767 2004408 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2768
2769 2004408 x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2770 2004408 y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2771 2004408 hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
2772
2773 2004408 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 2004408 times.
2004408 if (ret < 0) {
2775 l->tab_slice_address[ctb_addr_rs] = -1;
2776 return ret;
2777 }
2778
2779 2004408 hls_sao_param(lc, l, pps, sps,
2780 2004408 x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
2781
2782 2004408 l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2783 2004408 l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2784 2004408 l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2785
2786 2004408 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 2004407 times.
2004408 if (more_data < 0) {
2788 1 l->tab_slice_address[ctb_addr_rs] = -1;
2789 1 return more_data;
2790 }
2791
2792
2793 2004407 ctb_addr_ts++;
2794 2004407 ff_hevc_save_states(lc, pps, ctb_addr_ts);
2795 2004407 ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size);
2796 }
2797
2798
2/2
✓ Branch 0 taken 14947 times.
✓ Branch 1 taken 13764 times.
28711 if (x_ctb + ctb_size >= sps->width &&
2799
2/2
✓ Branch 0 taken 10460 times.
✓ Branch 1 taken 4487 times.
14947 y_ctb + ctb_size >= sps->height)
2800 10460 ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size);
2801
2802 28711 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 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 (int 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 (unsigned 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 (int 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 28712 static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l,
3029 const H2645NAL *nal, GetBitContext *gb)
3030 {
3031 28712 const HEVCPPS *pps = s->pps;
3032 int ret;
3033
3034
2/2
✓ Branch 0 taken 18251 times.
✓ Branch 1 taken 10461 times.
28712 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 20765 times.
✓ Branch 1 taken 7947 times.
✓ Branch 2 taken 19479 times.
✓ Branch 3 taken 1286 times.
28712 if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) {
3038 19479 ret = ff_hevc_slice_rpl(s);
3039
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19479 times.
19479 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 28712 s->slice_initialized = 1;
3047
3048
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28712 times.
28712 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 28712 times.
28712 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 20765 times.
28712 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 28712 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 5506 times.
28712 if (!pps->cu_qp_delta_enabled_flag)
3069 23206 s->local_ctx[0].qp_y = s->sh.slice_qp;
3070
3071 28712 s->local_ctx[0].tu.cu_qp_offset_cb = 0;
3072 28712 s->local_ctx[0].tu.cu_qp_offset_cr = 0;
3073
3074
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28712 times.
28712 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 28712 return hls_decode_entry(s, gb);
3080 }
3081
3082 10461 static int set_side_data(HEVCContext *s)
3083 {
3084 10461 const HEVCSPS *sps = s->cur_frame->pps->sps;
3085 10461 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 747 times.
✓ Branch 1 taken 9714 times.
✓ Branch 2 taken 747 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 464 times.
✓ Branch 5 taken 283 times.
10461 if (IS_IRAP(s) && s->no_rasl_output_flag) {
3092
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 454 times.
464 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 456 times.
464 if (s->sei.common.content_light.present > 0)
3096 8 s->sei.common.content_light.present--;
3097 }
3098
3099 10461 ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx,
3100 &sps->vui.common,
3101 10461 sps->bit_depth, sps->bit_depth_chroma,
3102 10461 s->cur_frame->poc /* no poc_offset in HEVC */);
3103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (ret < 0)
3104 return ret;
3105
3106
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 10438 times.
10461 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 10455 times.
10461 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 10459 times.
10461 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 10461 times.
10461 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 10459 times.
10461 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 10461 return 0;
3165 }
3166
3167 10071 static int find_finish_setup_nal(const HEVCContext *s)
3168 {
3169 10071 int nal_idx = 0;
3170
3171
2/2
✓ Branch 0 taken 39439 times.
✓ Branch 1 taken 10071 times.
49510 for (int i = nal_idx; i < s->pkt.nb_nals; i++) {
3172 39439 const H2645NAL *nal = &s->pkt.nals[i];
3173 39439 const int layer_id = nal->nuh_layer_id;
3174 39439 GetBitContext gb = nal->gb;
3175
3176
2/4
✓ Branch 0 taken 39439 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39439 times.
✗ Branch 3 not taken.
39439 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 39423 times.
39439 !(s->layers_active_decode & (1 << s->vps->layer_idx[layer_id])))
3178 18267 continue;
3179
3180
3/3
✓ Branch 0 taken 28713 times.
✓ Branch 1 taken 2307 times.
✓ Branch 2 taken 8403 times.
39423 switch (nal->type) {
3181 28713 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 10462 times.
28713 if (!get_bits1(&gb)) // first_slice_segment_in_pic_flag
3198 18251 continue;
3199 av_fallthrough;
3200 case HEVC_NAL_VPS:
3201 case HEVC_NAL_SPS:
3202 case HEVC_NAL_PPS:
3203 12769 nal_idx = i;
3204 12769 break;
3205 }
3206 }
3207
3208 10071 return nal_idx;
3209 }
3210
3211 10461 static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l,
3212 unsigned nal_idx)
3213 {
3214 10461 const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id];
3215 10461 const HEVCSPS *const sps = pps->sps;
3216 10461 int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) *
3217 10461 ((sps->height >> sps->log2_min_cb_size) + 1);
3218
2/2
✓ Branch 0 taken 10071 times.
✓ Branch 1 taken 390 times.
20532 int new_sequence = (l == &s->layers[0]) &&
3219
12/12
✓ Branch 0 taken 9671 times.
✓ Branch 1 taken 400 times.
✓ Branch 2 taken 9641 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 9639 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9632 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9631 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 19 times.
✓ Branch 11 taken 9612 times.
10071 (IS_IDR(s) || IS_BLA(s) || s->last_eos);
3220 10461 int prev_layers_active_decode = s->layers_active_decode;
3221 10461 int prev_layers_active_output = s->layers_active_output;
3222 int ret;
3223
3224
3/4
✓ Branch 0 taken 431 times.
✓ Branch 1 taken 10030 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 431 times.
10461 if (sps->vps != s->vps && l != &s->layers[0]) {
3225 av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n");
3226 set_sps(s, l, NULL);
3227 return AVERROR_INVALIDDATA;
3228 }
3229
3230 10461 av_refstruct_replace(&s->pps, pps);
3231
2/2
✓ Branch 0 taken 447 times.
✓ Branch 1 taken 10014 times.
10461 if (l->sps != sps) {
3232 447 const HEVCSPS *sps_base = s->layers[0].sps;
3233 447 enum AVPixelFormat pix_fmt = sps->pix_fmt;
3234
3235
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 437 times.
447 if (l != &s->layers[0]) {
3236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!sps_base) {
3237 av_log(s->avctx, AV_LOG_ERROR,
3238 "Access unit starts with a non-base layer frame\n");
3239 return AVERROR_INVALIDDATA;
3240 }
3241
3242 // Files produced by Vision Pro lack VPS extension VUI,
3243 // so the secondary layer has no range information.
3244 // This check avoids failing in such a case.
3245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (sps_base->pix_fmt == AV_PIX_FMT_YUVJ420P &&
3246 sps->pix_fmt == AV_PIX_FMT_YUV420P &&
3247 !sps->vui.common.video_signal_type_present_flag)
3248 pix_fmt = sps_base->pix_fmt;
3249
3250 // Ignore range mismatch between base layer and alpha layer
3251
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
10 if (ff_hevc_is_alpha_video(s) &&
3252
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 &&
3253 pix_fmt == AV_PIX_FMT_YUVJ420P)
3254 1 pix_fmt = sps_base->pix_fmt;
3255
3256
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (pix_fmt != sps_base->pix_fmt ||
3257
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 sps->width != sps_base->width ||
3258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 sps->height != sps_base->height) {
3259 av_log(s->avctx, AV_LOG_ERROR,
3260 "Base/non-base layer SPS have unsupported parameter combination\n");
3261 return AVERROR(ENOSYS);
3262 }
3263 }
3264
3265 447 ff_hevc_clear_refs(l);
3266
3267 447 ret = set_sps(s, l, sps);
3268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 447 times.
447 if (ret < 0)
3269 return ret;
3270
3271
2/2
✓ Branch 0 taken 437 times.
✓ Branch 1 taken 10 times.
447 if (l == &s->layers[0]) {
3272 437 export_stream_params(s, sps);
3273
3274 437 ret = get_format(s, sps);
3275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 437 times.
437 if (ret < 0) {
3276 set_sps(s, l, NULL);
3277 return ret;
3278 }
3279
3280 437 new_sequence = 1;
3281 }
3282 }
3283
3284 10461 memset(l->horizontal_bs, 0, l->bs_width * l->bs_height);
3285 10461 memset(l->vertical_bs, 0, l->bs_width * l->bs_height);
3286 10461 memset(l->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height);
3287 10461 memset(l->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1));
3288 10461 memset(l->tab_slice_address, -1, pic_size_in_ctb * sizeof(*l->tab_slice_address));
3289
3290
4/4
✓ Branch 0 taken 10052 times.
✓ Branch 1 taken 409 times.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 10017 times.
10461 if (IS_IDR(s))
3291 444 ff_hevc_clear_refs(l);
3292
3293 10461 s->slice_idx = 0;
3294 10461 s->first_nal_type = s->nal_unit_type;
3295 10461 s->poc = s->sh.poc;
3296
3297
3/4
✓ Branch 0 taken 747 times.
✓ Branch 1 taken 9714 times.
✓ Branch 2 taken 747 times.
✗ Branch 3 not taken.
10461 if (IS_IRAP(s)) {
3298
10/10
✓ Branch 0 taken 338 times.
✓ Branch 1 taken 409 times.
✓ Branch 2 taken 303 times.
✓ Branch 3 taken 35 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.
1040 s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) ||
3299
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);
3300 747 s->recovery_poc = HEVC_RECOVERY_END;
3301 }
3302
3303
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10441 times.
10461 if (s->recovery_poc != HEVC_RECOVERY_END &&
3304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 s->sei.recovery_point.has_recovery_poc) {
3305 if (s->recovery_poc == HEVC_RECOVERY_UNSPECIFIED)
3306 s->recovery_poc = s->poc + s->sei.recovery_point.recovery_poc_cnt;
3307 else if (s->poc >= s->recovery_poc)
3308 s->recovery_poc = HEVC_RECOVERY_END;
3309 }
3310
3311 /* 8.3.1 */
3312
2/2
✓ Branch 0 taken 10119 times.
✓ Branch 1 taken 342 times.
10461 if (s->temporal_id == 0 &&
3313
2/2
✓ Branch 0 taken 7432 times.
✓ Branch 1 taken 2687 times.
10119 s->nal_unit_type != HEVC_NAL_TRAIL_N &&
3314
1/2
✓ Branch 0 taken 7432 times.
✗ Branch 1 not taken.
7432 s->nal_unit_type != HEVC_NAL_TSA_N &&
3315
1/2
✓ Branch 0 taken 7432 times.
✗ Branch 1 not taken.
7432 s->nal_unit_type != HEVC_NAL_STSA_N &&
3316
2/2
✓ Branch 0 taken 7406 times.
✓ Branch 1 taken 26 times.
7432 s->nal_unit_type != HEVC_NAL_RADL_N &&
3317
2/2
✓ Branch 0 taken 7384 times.
✓ Branch 1 taken 22 times.
7406 s->nal_unit_type != HEVC_NAL_RADL_R &&
3318
2/2
✓ Branch 0 taken 7014 times.
✓ Branch 1 taken 370 times.
7384 s->nal_unit_type != HEVC_NAL_RASL_N &&
3319
2/2
✓ Branch 0 taken 6540 times.
✓ Branch 1 taken 474 times.
7014 s->nal_unit_type != HEVC_NAL_RASL_R)
3320 6540 s->poc_tid0 = s->poc;
3321
3322
2/2
✓ Branch 0 taken 754 times.
✓ Branch 1 taken 9707 times.
10461 if (pps->tiles_enabled_flag)
3323 754 s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size;
3324
3325
2/2
✓ Branch 0 taken 462 times.
✓ Branch 1 taken 9999 times.
10461 if (new_sequence) {
3326 462 ret = ff_hevc_output_frames(s, prev_layers_active_decode, prev_layers_active_output,
3327 462 0, 0, s->sh.no_output_of_prior_pics_flag);
3328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 462 times.
462 if (ret < 0)
3329 return ret;
3330 }
3331
3332 10461 ret = export_stream_params_from_sei(s);
3333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (ret < 0)
3334 return ret;
3335
3336 10461 ret = ff_hevc_set_new_ref(s, l, s->poc);
3337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (ret < 0)
3338 goto fail;
3339
3340 10461 ret = ff_hevc_frame_rps(s, l);
3341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (ret < 0) {
3342 av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n");
3343 goto fail;
3344 }
3345
3346
3/4
✓ Branch 0 taken 747 times.
✓ Branch 1 taken 9714 times.
✓ Branch 2 taken 747 times.
✗ Branch 3 not taken.
10461 if (IS_IRAP(s))
3347 747 s->cur_frame->f->flags |= AV_FRAME_FLAG_KEY;
3348 else
3349 9714 s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY;
3350
3351 20922 s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics &&
3352 s->sei.common.film_grain_characteristics->present) ||
3353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 s->sei.common.aom_film_grain.enable) &&
3354
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
20922 !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
3355 !s->avctx->hwaccel;
3356
3357 10461 ret = set_side_data(s);
3358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (ret < 0)
3359 goto fail;
3360
3361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (s->cur_frame->needs_fg &&
3362 (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present &&
3363 !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id,
3364 s->cur_frame->f->format) ||
3365 !av_film_grain_params_select(s->cur_frame->f))) {
3366 av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown,
3367 "Unsupported film grain parameters. Ignoring film grain.\n");
3368 s->cur_frame->needs_fg = 0;
3369 }
3370
3371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (s->cur_frame->needs_fg) {
3372 s->cur_frame->frame_grain->format = s->cur_frame->f->format;
3373 s->cur_frame->frame_grain->width = s->cur_frame->f->width;
3374 s->cur_frame->frame_grain->height = s->cur_frame->f->height;
3375 if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0)
3376 goto fail;
3377
3378 ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f);
3379 if (ret < 0)
3380 goto fail;
3381 }
3382
3383 10461 s->cur_frame->f->pict_type = 3 - s->sh.slice_type;
3384
3385 10461 ret = ff_hevc_output_frames(s, s->layers_active_decode, s->layers_active_output,
3386 10461 sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics,
3387 10461 sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0);
3388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (ret < 0)
3389 goto fail;
3390
3391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (s->avctx->hwaccel) {
3392 AVCodecInternal *avci = s->avctx->internal;
3393 AVPacket *avpkt = avci->in_pkt;
3394 ret = FF_HW_CALL(s->avctx, start_frame,
3395 avpkt->buf, NULL, 0);
3396 if (ret < 0)
3397 goto fail;
3398 }
3399
3400 // after starting the base-layer frame we know which layers will be decoded,
3401 // so we can now figure out which NALUs to wait for before we can call
3402 // ff_thread_finish_setup()
3403
2/2
✓ Branch 0 taken 10071 times.
✓ Branch 1 taken 390 times.
10461 if (l == &s->layers[0])
3404 10071 s->finish_setup_nal_idx = find_finish_setup_nal(s);
3405
3406
2/2
✓ Branch 0 taken 10070 times.
✓ Branch 1 taken 391 times.
10461 if (nal_idx >= s->finish_setup_nal_idx)
3407 10070 ff_thread_finish_setup(s->avctx);
3408
3409 10461 return 0;
3410
3411 fail:
3412 if (l->cur_frame)
3413 ff_hevc_unref_frame(l->cur_frame, ~0);
3414 l->cur_frame = NULL;
3415 s->cur_frame = s->collocated_ref = NULL;
3416 return ret;
3417 }
3418
3419 static int verify_md5(HEVCContext *s, AVFrame *frame)
3420 {
3421 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
3422 char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
3423 int pixel_shift;
3424 int err = 0;
3425 int i, j;
3426
3427 if (!desc)
3428 return AVERROR(EINVAL);
3429
3430 pixel_shift = desc->comp[0].depth > 8;
3431
3432 /* the checksums are LE, so we have to byteswap for >8bpp formats
3433 * on BE arches */
3434 #if HAVE_BIGENDIAN
3435 if (pixel_shift && !s->checksum_buf) {
3436 av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size,
3437 FFMAX3(frame->linesize[0], frame->linesize[1],
3438 frame->linesize[2]));
3439 if (!s->checksum_buf)
3440 return AVERROR(ENOMEM);
3441 }
3442 #endif
3443
3444 msg_buf[0] = '\0';
3445 for (i = 0; frame->data[i]; i++) {
3446 int width = s->avctx->coded_width;
3447 int height = s->avctx->coded_height;
3448 int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width;
3449 int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height;
3450 uint8_t md5[16];
3451
3452 av_md5_init(s->md5_ctx);
3453 for (j = 0; j < h; j++) {
3454 const uint8_t *src = frame->data[i] + j * frame->linesize[i];
3455 #if HAVE_BIGENDIAN
3456 if (pixel_shift) {
3457 s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
3458 (const uint16_t *) src, w);
3459 src = s->checksum_buf;
3460 }
3461 #endif
3462 av_md5_update(s->md5_ctx, src, w << pixel_shift);
3463 }
3464 av_md5_final(s->md5_ctx, md5);
3465
3466 #define MD5_PRI "%016" PRIx64 "%016" PRIx64
3467 #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
3468
3469 if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
3470 av_strlcatf(msg_buf, sizeof(msg_buf),
3471 "plane %d - correct " MD5_PRI "; ",
3472 i, MD5_PRI_ARG(md5));
3473 } else {
3474 av_strlcatf(msg_buf, sizeof(msg_buf),
3475 "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
3476 i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i]));
3477 err = AVERROR_INVALIDDATA;
3478 }
3479 }
3480
3481 av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
3482 "Verifying checksum for frame with POC %d: %s\n",
3483 s->poc, msg_buf);
3484
3485 return err;
3486 }
3487
3488 10461 static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l)
3489 {
3490 10461 HEVCFrame *out = l->cur_frame;
3491 const AVFilmGrainParams *fgp;
3492 av_unused int ret;
3493
3494
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (out->needs_fg) {
3495 av_assert0(out->frame_grain->buf[0]);
3496 fgp = av_film_grain_params_select(out->f);
3497 switch (fgp->type) {
3498 case AV_FILM_GRAIN_PARAMS_NONE:
3499 av_assert0(0);
3500 return AVERROR_BUG;
3501 case AV_FILM_GRAIN_PARAMS_H274:
3502 ret = ff_h274_apply_film_grain(out->frame_grain, out->f, fgp);
3503 break;
3504 case AV_FILM_GRAIN_PARAMS_AV1:
3505 ret = ff_aom_apply_film_grain(out->frame_grain, out->f, fgp);
3506 break;
3507 }
3508 av_assert1(ret >= 0);
3509 }
3510
3511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (s->avctx->hwaccel) {
3512 ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
3513 if (ret < 0) {
3514 av_log(s->avctx, AV_LOG_ERROR,
3515 "hardware accelerator failed to decode picture\n");
3516 return ret;
3517 }
3518 } else {
3519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
3520 s->sei.picture_hash.is_md5) {
3521 ret = verify_md5(s, out->f);
3522 if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
3523 return ret;
3524 }
3525 }
3526 10461 s->sei.picture_hash.is_md5 = 0;
3527
3528 10461 av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %zu/%d.\n",
3529 10461 l - s->layers, s->poc);
3530
3531 10461 return 0;
3532 }
3533
3534 28836 static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb)
3535 {
3536
2/2
✓ Branch 0 taken 28377 times.
✓ Branch 1 taken 459 times.
28836 const int layer_idx = s->vps ? s->vps->layer_idx[s->nuh_layer_id] : 0;
3537 HEVCLayerContext *l;
3538 int ret;
3539
3540 // skip layers not requested to be decoded
3541 // layers_active_decode can only change while decoding a base-layer frame,
3542 // so we can check it for non-base layers
3543
1/2
✓ Branch 0 taken 28836 times.
✗ Branch 1 not taken.
28836 if (layer_idx < 0 ||
3544
4/4
✓ Branch 0 taken 521 times.
✓ Branch 1 taken 28315 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 516 times.
28836 (s->nuh_layer_id > 0 && !(s->layers_active_decode & (1 << layer_idx))))
3545 5 return 0;
3546
3547 28831 ret = hls_slice_header(&s->sh, s, gb);
3548 // Once hls_slice_header has been called, the context is inconsistent with the slice header
3549 // until the context is reinitialized according to the contents of the new slice header
3550 // at the start of decode_slice_data.
3551 28831 s->slice_initialized = 0;
3552
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 28798 times.
28831 if (ret < 0) {
3553 33 return ret;
3554 }
3555
3556
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28798 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
28798 if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
3557
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28798 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
28798 (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
3558
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 28798 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
28798 (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
3559
4/4
✓ Branch 0 taken 27653 times.
✓ Branch 1 taken 1145 times.
✓ Branch 2 taken 1066 times.
✓ Branch 3 taken 26587 times.
28798 ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&
3560
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 2126 times.
2211 s->no_rasl_output_flag)) {
3561 85 return 0;
3562 }
3563
3564 // switching to a new layer, mark previous layer's frame (if any) as done
3565
2/2
✓ Branch 0 taken 771 times.
✓ Branch 1 taken 27942 times.
28713 if (s->cur_layer != layer_idx &&
3566
2/2
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 381 times.
771 s->layers[s->cur_layer].cur_frame &&
3567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
390 s->avctx->active_thread_type == FF_THREAD_FRAME)
3568 ff_progress_frame_report(&s->layers[s->cur_layer].cur_frame->tf, INT_MAX);
3569
3570 28713 s->cur_layer = layer_idx;
3571 28713 l = &s->layers[s->cur_layer];
3572
3573
2/2
✓ Branch 0 taken 10462 times.
✓ Branch 1 taken 18251 times.
28713 if (s->sh.first_slice_in_pic_flag) {
3574
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10461 times.
10462 if (l->cur_frame) {
3575 1 av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
3576 1 return AVERROR_INVALIDDATA;
3577 }
3578
3579 10461 ret = hevc_frame_start(s, l, nal_idx);
3580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10461 times.
10461 if (ret < 0)
3581 return ret;
3582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18251 times.
18251 } else if (!l->cur_frame) {
3583 av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
3584 return AVERROR_INVALIDDATA;
3585 }
3586
3587
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28712 times.
28712 if (s->nal_unit_type != s->first_nal_type) {
3588 av_log(s->avctx, AV_LOG_ERROR,
3589 "Non-matching NAL types of the VCL NALUs: %d %d\n",
3590 s->first_nal_type, s->nal_unit_type);
3591 return AVERROR_INVALIDDATA;
3592 }
3593
3594 28712 ret = decode_slice_data(s, l, &s->pkt.nals[nal_idx], gb);
3595
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28711 times.
28712 if (ret < 0)
3596 1 return ret;
3597
3598 28711 return 0;
3599 }
3600
3601 39745 static int decode_nal_unit(HEVCContext *s, unsigned nal_idx)
3602 {
3603 39745 H2645NAL *nal = &s->pkt.nals[nal_idx];
3604 39745 GetBitContext gb = nal->gb;
3605 int ret;
3606
3607 39745 s->nal_unit_type = nal->type;
3608 39745 s->nuh_layer_id = nal->nuh_layer_id;
3609 39745 s->temporal_id = nal->temporal_id;
3610
3611
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 39745 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
39745 if (FF_HW_HAS_CB(s->avctx, decode_params) &&
3612 (s->nal_unit_type == HEVC_NAL_VPS ||
3613 s->nal_unit_type == HEVC_NAL_SPS ||
3614 s->nal_unit_type == HEVC_NAL_PPS ||
3615 s->nal_unit_type == HEVC_NAL_SEI_PREFIX ||
3616 s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) {
3617 ret = FF_HW_CALL(s->avctx, decode_params,
3618 nal->type, nal->raw_data, nal->raw_size);
3619 if (ret < 0)
3620 goto fail;
3621 }
3622
3623
6/7
✓ Branch 0 taken 446 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 1415 times.
✓ Branch 3 taken 7875 times.
✓ Branch 4 taken 28836 times.
✓ Branch 5 taken 717 times.
✗ Branch 6 not taken.
39745 switch (s->nal_unit_type) {
3624 446 case HEVC_NAL_VPS:
3625 446 ret = ff_hevc_decode_nal_vps(&gb, s->avctx, &s->ps);
3626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 446 times.
446 if (ret < 0)
3627 goto fail;
3628 446 break;
3629 456 case HEVC_NAL_SPS:
3630 456 ret = ff_hevc_decode_nal_sps(&gb, s->avctx, &s->ps,
3631 456 nal->nuh_layer_id, s->apply_defdispwin);
3632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 456 times.
456 if (ret < 0)
3633 goto fail;
3634 456 break;
3635 1415 case HEVC_NAL_PPS:
3636 1415 ret = ff_hevc_decode_nal_pps(&gb, s->avctx, &s->ps);
3637
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1413 times.
1415 if (ret < 0)
3638 2 goto fail;
3639 1413 break;
3640 7875 case HEVC_NAL_SEI_PREFIX:
3641 case HEVC_NAL_SEI_SUFFIX:
3642 7875 ret = ff_hevc_decode_nal_sei(&gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type);
3643
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7842 times.
7875 if (ret < 0)
3644 33 goto fail;
3645 7842 break;
3646 28836 case HEVC_NAL_TRAIL_R:
3647 case HEVC_NAL_TRAIL_N:
3648 case HEVC_NAL_TSA_N:
3649 case HEVC_NAL_TSA_R:
3650 case HEVC_NAL_STSA_N:
3651 case HEVC_NAL_STSA_R:
3652 case HEVC_NAL_BLA_W_LP:
3653 case HEVC_NAL_BLA_W_RADL:
3654 case HEVC_NAL_BLA_N_LP:
3655 case HEVC_NAL_IDR_W_RADL:
3656 case HEVC_NAL_IDR_N_LP:
3657 case HEVC_NAL_CRA_NUT:
3658 case HEVC_NAL_RADL_N:
3659 case HEVC_NAL_RADL_R:
3660 case HEVC_NAL_RASL_N:
3661 case HEVC_NAL_RASL_R:
3662 28836 ret = decode_slice(s, nal_idx, &gb);
3663
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 28801 times.
28836 if (ret < 0)
3664 35 goto fail;
3665 28801 break;
3666 717 case HEVC_NAL_EOS_NUT:
3667 case HEVC_NAL_EOB_NUT:
3668 case HEVC_NAL_AUD:
3669 case HEVC_NAL_FD_NUT:
3670 case HEVC_NAL_UNSPEC62: // Dolby Vision RPU
3671 case HEVC_NAL_UNSPEC63: // Dolby Vision EL
3672 717 break;
3673 default:
3674 av_log(s->avctx, AV_LOG_VERBOSE,
3675 "Skipping NAL unit %d\n", s->nal_unit_type);
3676 }
3677
3678 39675 return 0;
3679 70 fail:
3680
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 if (ret == AVERROR_INVALIDDATA &&
3681
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 !(s->avctx->err_recognition & AV_EF_EXPLODE)) {
3682 70 av_log(s->avctx, AV_LOG_WARNING,
3683 70 "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type);
3684 70 return 0;
3685 }
3686 return ret;
3687 }
3688
3689 430 static void decode_reset_recovery_point(HEVCContext *s)
3690 {
3691 430 s->recovery_poc = HEVC_RECOVERY_UNSPECIFIED;
3692 430 s->sei.recovery_point.has_recovery_poc = 0;
3693 430 }
3694
3695 10148 static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
3696 {
3697 10148 int ret = 0;
3698 10148 int eos_at_start = 1;
3699
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 9898 times.
10148 int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING;
3700
3701 10148 s->cur_frame = s->collocated_ref = NULL;
3702 10148 s->last_eos = s->eos;
3703 10148 s->eos = 0;
3704 10148 s->slice_initialized = 0;
3705
2/2
✓ Branch 0 taken 426 times.
✓ Branch 1 taken 9722 times.
10148 if (s->last_eos)
3706 426 decode_reset_recovery_point(s);
3707
3708
2/2
✓ Branch 0 taken 20296 times.
✓ Branch 1 taken 10148 times.
30444 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3709 20296 HEVCLayerContext *l = &s->layers[i];
3710 20296 l->cur_frame = NULL;
3711 }
3712
3713 /* split the input packet into NAL units, so we know the upper bound on the
3714 * number of slices in the frame */
3715 10148 ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx,
3716 10148 s->nal_length_size, s->avctx->codec_id, flags);
3717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10148 times.
10148 if (ret < 0) {
3718 av_log(s->avctx, AV_LOG_ERROR,
3719 "Error splitting the input into NAL units.\n");
3720 return ret;
3721 }
3722
3723
2/2
✓ Branch 0 taken 39745 times.
✓ Branch 1 taken 10148 times.
49893 for (int i = 0; i < s->pkt.nb_nals; i++) {
3724
2/2
✓ Branch 0 taken 39744 times.
✓ Branch 1 taken 1 times.
39745 if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT ||
3725
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 39741 times.
39744 s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) {
3726
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (eos_at_start) {
3727 4 s->last_eos = 1;
3728 4 decode_reset_recovery_point(s);
3729 } else {
3730 s->eos = 1;
3731 }
3732 } else {
3733 39741 eos_at_start = 0;
3734 }
3735 }
3736
3737 /*
3738 * Check for RPU delimiter.
3739 *
3740 * Dolby Vision RPUs masquerade as unregistered NALs of type 62.
3741 *
3742 * We have to do this check here an create the rpu buffer, since RPUs are appended
3743 * to the end of an AU; they are the last non-EOB/EOS NAL in the AU.
3744 */
3745
4/4
✓ Branch 0 taken 8208 times.
✓ Branch 1 taken 1940 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8206 times.
10148 if (s->pkt.nb_nals > 1 && s->pkt.nals[s->pkt.nb_nals - 1].type == HEVC_NAL_UNSPEC62 &&
3746
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
3747
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 && !s->pkt.nals[s->pkt.nb_nals - 1].temporal_id) {
3748 2 H2645NAL *nal = &s->pkt.nals[s->pkt.nb_nals - 1];
3749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->rpu_buf) {
3750 av_buffer_unref(&s->rpu_buf);
3751 av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n");
3752 }
3753
3754 2 s->rpu_buf = av_buffer_alloc(nal->raw_size - 2);
3755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!s->rpu_buf) {
3756 ret = AVERROR(ENOMEM);
3757 goto fail;
3758 }
3759 2 memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2);
3760
3761 2 ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2,
3762 2 s->avctx->err_recognition);
3763
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0) {
3764 av_buffer_unref(&s->rpu_buf);
3765 av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n");
3766 /* ignore */
3767 }
3768 }
3769
3770 /* decode the NAL units */
3771
2/2
✓ Branch 0 taken 39745 times.
✓ Branch 1 taken 10148 times.
49893 for (int i = 0; i < s->pkt.nb_nals; i++) {
3772 39745 H2645NAL *nal = &s->pkt.nals[i];
3773
3774
1/2
✓ Branch 0 taken 39745 times.
✗ Branch 1 not taken.
39745 if (s->avctx->skip_frame >= AVDISCARD_ALL ||
3775
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 39745 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
39745 (s->avctx->skip_frame >= AVDISCARD_NONREF && ff_hevc_nal_is_nonref(nal->type)))
3776 continue;
3777
3778 39745 ret = decode_nal_unit(s, i);
3779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39745 times.
39745 if (ret < 0) {
3780 av_log(s->avctx, AV_LOG_WARNING,
3781 "Error parsing NAL unit #%d.\n", i);
3782 goto fail;
3783 }
3784 }
3785
3786 10148 fail:
3787
2/2
✓ Branch 0 taken 20296 times.
✓ Branch 1 taken 10148 times.
30444 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3788 20296 HEVCLayerContext *l = &s->layers[i];
3789
3790
2/2
✓ Branch 0 taken 9835 times.
✓ Branch 1 taken 10461 times.
20296 if (!l->cur_frame)
3791 9835 continue;
3792
3793
1/2
✓ Branch 0 taken 10461 times.
✗ Branch 1 not taken.
10461 if (ret >= 0)
3794 10461 ret = hevc_frame_end(s, l);
3795
3796
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 10428 times.
10461 if (s->avctx->active_thread_type == FF_THREAD_FRAME)
3797 33 ff_progress_frame_report(&l->cur_frame->tf, INT_MAX);
3798 }
3799
3800 10148 return ret;
3801 }
3802
3803 304 static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first)
3804 {
3805 int ret, i;
3806
3807 304 ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff,
3808 304 &s->nal_length_size, s->avctx->err_recognition,
3809 304 s->apply_defdispwin, s->avctx);
3810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
304 if (ret < 0)
3811 return ret;
3812
3813 /* export stream parameters from the first SPS */
3814
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 2 times.
336 for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) {
3815
4/4
✓ Branch 0 taken 318 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 302 times.
✓ Branch 3 taken 16 times.
334 if (first && s->ps.sps_list[i]) {
3816 302 const HEVCSPS *sps = s->ps.sps_list[i];
3817 302 export_stream_params(s, sps);
3818
3819 302 ret = export_multilayer(s, sps->vps);
3820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (ret < 0)
3821 return ret;
3822
3823 302 break;
3824 }
3825 }
3826
3827 /* export stream parameters from SEI */
3828 304 ret = export_stream_params_from_sei(s);
3829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
304 if (ret < 0)
3830 return ret;
3831
3832 304 return 0;
3833 }
3834
3835 21491 static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame)
3836 {
3837 21491 HEVCContext *s = avctx->priv_data;
3838 21491 AVCodecInternal *avci = avctx->internal;
3839 21491 AVPacket *avpkt = avci->in_pkt;
3840
3841 int ret;
3842 uint8_t *sd;
3843 size_t sd_size;
3844
3845 21491 s->pkt_dts = AV_NOPTS_VALUE;
3846
3847
2/2
✓ Branch 1 taken 949 times.
✓ Branch 2 taken 20542 times.
21491 if (av_container_fifo_can_read(s->output_fifo))
3848 949 goto do_output;
3849
3850 20542 av_packet_unref(avpkt);
3851 20542 ret = ff_decode_get_packet(avctx, avpkt);
3852
2/2
✓ Branch 0 taken 324 times.
✓ Branch 1 taken 20218 times.
20542 if (ret == AVERROR_EOF) {
3853 324 ret = ff_hevc_output_frames(s, s->layers_active_decode,
3854 s->layers_active_output, 0, 0, 0);
3855
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 324 times.
324 if (ret < 0)
3856 return ret;
3857 324 goto do_output;
3858
2/2
✓ Branch 0 taken 10070 times.
✓ Branch 1 taken 10148 times.
20218 } else if (ret < 0)
3859 10070 return ret;
3860
3861 10148 s->pkt_dts = avpkt->dts;
3862
3863 10148 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size);
3864
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10147 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
10148 if (sd && sd_size > 0) {
3865 1 ret = hevc_decode_extradata(s, sd, sd_size, 0);
3866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
3867 return ret;
3868 }
3869
3870 10148 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size);
3871
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10148 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10148 if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) {
3872 int old = s->dovi_ctx.cfg.dv_profile;
3873 s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd;
3874 if (old)
3875 av_log(avctx, AV_LOG_DEBUG,
3876 "New DOVI configuration record from input packet (profile %d -> %u).\n",
3877 old, s->dovi_ctx.cfg.dv_profile);
3878 }
3879
3880 10148 ret = decode_nal_units(s, avpkt->data, avpkt->size);
3881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10148 times.
10148 if (ret < 0)
3882 return ret;
3883
3884 10148 do_output:
3885
2/2
✓ Branch 1 taken 10170 times.
✓ Branch 2 taken 1251 times.
11421 if (av_container_fifo_read(s->output_fifo, frame, 0) >= 0) {
3886
1/2
✓ Branch 0 taken 10170 times.
✗ Branch 1 not taken.
10170 if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))
3887 10170 av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
3888
3889 10170 return 0;
3890 }
3891
3892
2/2
✓ Branch 0 taken 206 times.
✓ Branch 1 taken 1045 times.
1251 return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN);
3893 }
3894
3895 67 static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
3896 {
3897 int ret;
3898
3899 67 ff_progress_frame_ref(&dst->tf, &src->tf);
3900
3901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (src->needs_fg) {
3902 ret = av_frame_ref(dst->frame_grain, src->frame_grain);
3903 if (ret < 0) {
3904 ff_hevc_unref_frame(dst, ~0);
3905 return ret;
3906 }
3907 dst->needs_fg = 1;
3908 }
3909
3910 67 dst->pps = av_refstruct_ref_c(src->pps);
3911 67 dst->tab_mvf = av_refstruct_ref(src->tab_mvf);
3912 67 dst->rpl_tab = av_refstruct_ref(src->rpl_tab);
3913 67 dst->rpl = av_refstruct_ref(src->rpl);
3914 67 dst->nb_rpl_elems = src->nb_rpl_elems;
3915
3916 67 dst->poc = src->poc;
3917 67 dst->ctb_count = src->ctb_count;
3918 67 dst->flags = src->flags;
3919
3920 67 dst->base_layer_frame = src->base_layer_frame;
3921
3922 67 av_refstruct_replace(&dst->hwaccel_picture_private,
3923 67 src->hwaccel_picture_private);
3924
3925 67 return 0;
3926 }
3927
3928 522 static av_cold int hevc_decode_free(AVCodecContext *avctx)
3929 {
3930 522 HEVCContext *s = avctx->priv_data;
3931
3932
2/2
✓ Branch 0 taken 1044 times.
✓ Branch 1 taken 522 times.
1566 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3933 1044 pic_arrays_free(&s->layers[i]);
3934 1044 av_refstruct_unref(&s->layers[i].sps);
3935 }
3936
3937 522 av_refstruct_unref(&s->vps);
3938 522 av_refstruct_unref(&s->pps);
3939
3940 522 ff_dovi_ctx_unref(&s->dovi_ctx);
3941 522 av_buffer_unref(&s->rpu_buf);
3942
3943 522 av_freep(&s->md5_ctx);
3944
3945 522 av_container_fifo_free(&s->output_fifo);
3946
3947
2/2
✓ Branch 0 taken 1044 times.
✓ Branch 1 taken 522 times.
1566 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
3948 1044 HEVCLayerContext *l = &s->layers[layer];
3949
2/2
✓ Branch 0 taken 33408 times.
✓ Branch 1 taken 1044 times.
34452 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
3950 33408 ff_hevc_unref_frame(&l->DPB[i], ~0);
3951 33408 av_frame_free(&l->DPB[i].frame_grain);
3952 }
3953 }
3954
3955 522 ff_hevc_ps_uninit(&s->ps);
3956
3957
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 522 times.
522 for (int i = 0; i < s->nb_wpp_progress; i++)
3958 ff_thread_progress_destroy(&s->wpp_progress[i]);
3959 522 av_freep(&s->wpp_progress);
3960
3961 522 av_freep(&s->sh.entry_point_offset);
3962 522 av_freep(&s->sh.offset);
3963 522 av_freep(&s->sh.size);
3964
3965 522 av_freep(&s->local_ctx);
3966
3967 522 ff_h2645_packet_uninit(&s->pkt);
3968
3969 522 ff_hevc_reset_sei(&s->sei);
3970
3971 522 return 0;
3972 }
3973
3974 522 static av_cold int hevc_init_context(AVCodecContext *avctx)
3975 {
3976 522 HEVCContext *s = avctx->priv_data;
3977
3978 522 s->avctx = avctx;
3979
3980 522 s->local_ctx = av_mallocz(sizeof(*s->local_ctx));
3981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 522 times.
522 if (!s->local_ctx)
3982 return AVERROR(ENOMEM);
3983 522 s->nb_local_ctx = 1;
3984
3985 522 s->local_ctx[0].parent = s;
3986 522 s->local_ctx[0].logctx = avctx;
3987 522 s->local_ctx[0].common_cabac_state = &s->cabac;
3988
3989 522 s->output_fifo = av_container_fifo_alloc_avframe(0);
3990
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 522 times.
522 if (!s->output_fifo)
3991 return AVERROR(ENOMEM);
3992
3993
2/2
✓ Branch 0 taken 1044 times.
✓ Branch 1 taken 522 times.
1566 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
3994 1044 HEVCLayerContext *l = &s->layers[layer];
3995
2/2
✓ Branch 0 taken 33408 times.
✓ Branch 1 taken 1044 times.
34452 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
3996 33408 l->DPB[i].frame_grain = av_frame_alloc();
3997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33408 times.
33408 if (!l->DPB[i].frame_grain)
3998 return AVERROR(ENOMEM);
3999 }
4000 }
4001
4002 522 s->md5_ctx = av_md5_alloc();
4003
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 522 times.
522 if (!s->md5_ctx)
4004 return AVERROR(ENOMEM);
4005
4006 522 ff_bswapdsp_init(&s->bdsp);
4007
4008 522 s->dovi_ctx.logctx = avctx;
4009 522 s->eos = 0;
4010
4011 522 ff_hevc_reset_sei(&s->sei);
4012
4013 522 return 0;
4014 }
4015
4016 #if HAVE_THREADS
4017 32 static int hevc_update_thread_context(AVCodecContext *dst,
4018 const AVCodecContext *src)
4019 {
4020 32 HEVCContext *s = dst->priv_data;
4021 32 HEVCContext *s0 = src->priv_data;
4022 int ret;
4023
4024
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
96 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
4025 64 HEVCLayerContext *l = &s->layers[layer];
4026 64 const HEVCLayerContext *l0 = &s0->layers[layer];
4027
2/2
✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 64 times.
2112 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
4028 2048 ff_hevc_unref_frame(&l->DPB[i], ~0);
4029
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1981 times.
2048 if (l0->DPB[i].f) {
4030 67 ret = hevc_ref_frame(&l->DPB[i], &l0->DPB[i]);
4031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (ret < 0)
4032 return ret;
4033 }
4034 }
4035
4036
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
64 if (l->sps != l0->sps) {
4037 1 ret = set_sps(s, l, l0->sps);
4038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
4039 return ret;
4040 }
4041 }
4042
4043
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++)
4044 512 av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]);
4045
4046
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++)
4047 512 av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]);
4048
4049
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++)
4050 2048 av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]);
4051
4052 // PPS do not persist between frames
4053 32 av_refstruct_unref(&s->pps);
4054
4055 32 s->poc_tid0 = s0->poc_tid0;
4056 32 s->eos = s0->eos;
4057 32 s->no_rasl_output_flag = s0->no_rasl_output_flag;
4058
4059 32 s->is_nalff = s0->is_nalff;
4060 32 s->nal_length_size = s0->nal_length_size;
4061 32 s->layers_active_decode = s0->layers_active_decode;
4062 32 s->layers_active_output = s0->layers_active_output;
4063
4064 32 s->film_grain_warning_shown = s0->film_grain_warning_shown;
4065
4066
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (s->nb_view_ids != s0->nb_view_ids ||
4067
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)) {
4068 av_freep(&s->view_ids);
4069 s->nb_view_ids = 0;
4070
4071 if (s0->nb_view_ids) {
4072 s->view_ids = av_memdup(s0->view_ids, s0->nb_view_ids * sizeof(*s0->view_ids));
4073 if (!s->view_ids)
4074 return AVERROR(ENOMEM);
4075 s->nb_view_ids = s0->nb_view_ids;
4076 }
4077 }
4078
4079 32 ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common);
4080
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4081 return ret;
4082
4083 32 ret = av_buffer_replace(&s->sei.common.dynamic_hdr_plus.info,
4084 32 s0->sei.common.dynamic_hdr_plus.info);
4085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4086 return ret;
4087
4088 32 ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf);
4089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4090 return ret;
4091
4092 32 ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx);
4093
4094 32 ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info,
4095 32 s0->sei.common.dynamic_hdr_vivid.info);
4096
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4097 return ret;
4098
4099 32 s->sei.common.frame_packing = s0->sei.common.frame_packing;
4100 32 s->sei.common.display_orientation = s0->sei.common.display_orientation;
4101 32 s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer;
4102 32 s->sei.tdrdi = s0->sei.tdrdi;
4103 32 s->sei.recovery_point = s0->sei.recovery_point;
4104 32 s->recovery_poc = s0->recovery_poc;
4105
4106 32 return 0;
4107 }
4108 #endif
4109
4110 303 static int hevc_sei_to_context(AVCodecContext *avctx, HEVCSEI *sei)
4111 {
4112 int ret;
4113
4114
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 299 times.
303 if (sei->tdrdi.present) {
4115 AVBufferRef *buf;
4116 size_t size;
4117 4 AV3DReferenceDisplaysInfo *tdrdi = av_tdrdi_alloc(sei->tdrdi.num_ref_displays, &size);
4118
4119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!tdrdi)
4120 return AVERROR(ENOMEM);
4121
4122 4 buf = av_buffer_create((uint8_t *)tdrdi, size, NULL, NULL, 0);
4123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!buf) {
4124 av_free(tdrdi);
4125 return AVERROR(ENOMEM);
4126 }
4127
4128 4 tdrdi->prec_ref_display_width = sei->tdrdi.prec_ref_display_width;
4129 4 tdrdi->ref_viewing_distance_flag = sei->tdrdi.ref_viewing_distance_flag;
4130 4 tdrdi->prec_ref_viewing_dist = sei->tdrdi.prec_ref_viewing_dist;
4131 4 tdrdi->num_ref_displays = sei->tdrdi.num_ref_displays;
4132
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (int i = 0; i < sei->tdrdi.num_ref_displays; i++) {
4133 4 AV3DReferenceDisplay *display = av_tdrdi_get_display(tdrdi, i);
4134
4135 4 display->left_view_id = sei->tdrdi.left_view_id[i];
4136 4 display->right_view_id = sei->tdrdi.right_view_id[i];
4137 4 display->exponent_ref_display_width = sei->tdrdi.exponent_ref_display_width[i];
4138 4 display->mantissa_ref_display_width = sei->tdrdi.mantissa_ref_display_width[i];
4139 4 display->exponent_ref_viewing_distance = sei->tdrdi.exponent_ref_viewing_distance[i];
4140 4 display->mantissa_ref_viewing_distance = sei->tdrdi.mantissa_ref_viewing_distance[i];
4141 4 display->additional_shift_present_flag = sei->tdrdi.additional_shift_present_flag[i];
4142 4 display->num_sample_shift = sei->tdrdi.num_sample_shift[i];
4143 }
4144 4 ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data,
4145 AV_FRAME_DATA_3D_REFERENCE_DISPLAYS, &buf);
4146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0) {
4147 av_buffer_unref(&buf);
4148 return ret;
4149 }
4150 }
4151
4152 303 ret = ff_h2645_sei_to_context(avctx, &sei->common);
4153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 303 times.
303 if (ret < 0)
4154 return ret;
4155
4156 303 return 0;
4157 }
4158
4159 522 static av_cold int hevc_decode_init(AVCodecContext *avctx)
4160 {
4161 522 HEVCContext *s = avctx->priv_data;
4162 int ret;
4163
4164 522 ret = hevc_init_context(avctx);
4165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 522 times.
522 if (ret < 0)
4166 return ret;
4167
4168 522 s->sei.picture_timing.picture_struct = 0;
4169 522 s->eos = 1;
4170
4171 522 atomic_init(&s->wpp_err, 0);
4172
4173
2/2
✓ Branch 0 taken 521 times.
✓ Branch 1 taken 1 times.
522 if (!avctx->internal->is_copy) {
4174 const AVPacketSideData *sd;
4175
4176
3/4
✓ Branch 0 taken 303 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 303 times.
✗ Branch 3 not taken.
521 if (avctx->extradata_size > 0 && avctx->extradata) {
4177 303 ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1);
4178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 303 times.
303 if (ret < 0) {
4179 return ret;
4180 }
4181
4182 303 ret = hevc_sei_to_context(avctx, &s->sei);
4183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 303 times.
303 if (ret < 0)
4184 return ret;
4185 }
4186
4187 521 sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF);
4188
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 510 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
521 if (sd && sd->size >= sizeof(s->dovi_ctx.cfg))
4189 11 s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data;
4190 }
4191
4192 522 return 0;
4193 }
4194
4195 static av_cold void hevc_decode_flush(AVCodecContext *avctx)
4196 {
4197 HEVCContext *s = avctx->priv_data;
4198 ff_hevc_flush_dpb(s);
4199 ff_hevc_reset_sei(&s->sei);
4200 ff_dovi_ctx_flush(&s->dovi_ctx);
4201 av_buffer_unref(&s->rpu_buf);
4202 s->eos = 1;
4203
4204 if (FF_HW_HAS_CB(avctx, flush))
4205 FF_HW_SIMPLE_CALL(avctx, flush);
4206 }
4207
4208 #define OFFSET(x) offsetof(HEVCContext, x)
4209 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
4210
4211 static const AVOption options[] = {
4212 { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin),
4213 AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4214 { "strict-displaywin", "strictly apply default display window size", OFFSET(apply_defdispwin),
4215 AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4216 { "view_ids", "Array of view IDs that should be decoded and output; a single -1 to decode all views",
4217 .offset = OFFSET(view_ids), .type = AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY,
4218 .min = -1, .max = INT_MAX, .flags = PAR },
4219 { "view_ids_available", "Array of available view IDs is exported here",
4220 .offset = OFFSET(view_ids_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4221 .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
4222 { "view_pos_available", "Array of view positions for view_ids_available is exported here, as AVStereo3DView",
4223 .offset = OFFSET(view_pos_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4224 .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY, .unit = "view_pos" },
4225 { "unspecified", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_UNSPEC }, .unit = "view_pos" },
4226 { "left", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_LEFT }, .unit = "view_pos" },
4227 { "right", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_RIGHT }, .unit = "view_pos" },
4228
4229 { NULL },
4230 };
4231
4232 static const AVClass hevc_decoder_class = {
4233 .class_name = "HEVC decoder",
4234 .item_name = av_default_item_name,
4235 .option = options,
4236 .version = LIBAVUTIL_VERSION_INT,
4237 };
4238
4239 const FFCodec ff_hevc_decoder = {
4240 .p.name = "hevc",
4241 CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"),
4242 .p.type = AVMEDIA_TYPE_VIDEO,
4243 .p.id = AV_CODEC_ID_HEVC,
4244 .priv_data_size = sizeof(HEVCContext),
4245 .p.priv_class = &hevc_decoder_class,
4246 .init = hevc_decode_init,
4247 .close = hevc_decode_free,
4248 FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame),
4249 .flush = hevc_decode_flush,
4250 UPDATE_THREAD_CONTEXT(hevc_update_thread_context),
4251 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
4252 AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
4253 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
4254 FF_CODEC_CAP_USES_PROGRESSFRAMES |
4255 FF_CODEC_CAP_INIT_CLEANUP,
4256 .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
4257 .hw_configs = (const AVCodecHWConfigInternal *const []) {
4258 #if CONFIG_HEVC_DXVA2_HWACCEL
4259 HWACCEL_DXVA2(hevc),
4260 #endif
4261 #if CONFIG_HEVC_D3D11VA_HWACCEL
4262 HWACCEL_D3D11VA(hevc),
4263 #endif
4264 #if CONFIG_HEVC_D3D11VA2_HWACCEL
4265 HWACCEL_D3D11VA2(hevc),
4266 #endif
4267 #if CONFIG_HEVC_D3D12VA_HWACCEL
4268 HWACCEL_D3D12VA(hevc),
4269 #endif
4270 #if CONFIG_HEVC_NVDEC_HWACCEL
4271 HWACCEL_NVDEC(hevc),
4272 #endif
4273 #if CONFIG_HEVC_VAAPI_HWACCEL
4274 HWACCEL_VAAPI(hevc),
4275 #endif
4276 #if CONFIG_HEVC_VDPAU_HWACCEL
4277 HWACCEL_VDPAU(hevc),
4278 #endif
4279 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
4280 HWACCEL_VIDEOTOOLBOX(hevc),
4281 #endif
4282 #if CONFIG_HEVC_VULKAN_HWACCEL
4283 HWACCEL_VULKAN(hevc),
4284 #endif
4285 NULL
4286 },
4287 };
4288