FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc/hevcdec.c
Date: 2025-04-25 22:50:00
Exec Total Coverage
Lines: 1963 2428 80.8%
Functions: 51 55 92.7%
Branches: 1378 1827 75.4%

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