FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc/hevcdec.c
Date: 2026-10-29 07:45:57
Exec Total Coverage
Lines: 2153 2629 81.9%
Functions: 57 62 91.9%
Branches: 1501 1965 76.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/tdrdi.h"
40 #include "libavutil/timecode.h"
41 #include "libavutil/refstruct.h"
42
43 #include "libavcodec/aom_film_grain.h"
44 #include "libavcodec/bswapdsp.h"
45 #include "libavcodec/cabac_functions.h"
46 #include "libavcodec/codec_internal.h"
47 #include "libavcodec/decode.h"
48 #include "libavcodec/golomb.h"
49 #include "libavcodec/h274.h"
50 #include "libavcodec/hwaccel_internal.h"
51 #include "libavcodec/hwconfig.h"
52 #include "libavcodec/internal.h"
53 #include "libavcodec/profiles.h"
54 #include "libavcodec/progressframe.h"
55 #include "libavcodec/thread.h"
56 #include "libavcodec/threadprogress.h"
57
58 #include "hevc.h"
59 #include "parse.h"
60 #include "hevcdec.h"
61
62 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 };
63
64 /**
65 * NOTE: Each function hls_foo correspond to the function foo in the
66 * specification (HLS stands for High Level Syntax).
67 */
68
69 /**
70 * Section 5.7
71 */
72
73 /* free everything allocated by pic_arrays_init() */
74 1759 static void pic_arrays_free(HEVCLayerContext *l)
75 {
76 1759 av_freep(&l->sao);
77 1759 av_freep(&l->deblock);
78
79 1759 av_freep(&l->skip_flag);
80 1759 av_freep(&l->tab_ct_depth);
81
82 1759 av_freep(&l->tab_ipm);
83 1759 av_freep(&l->cbf_luma);
84 1759 av_freep(&l->is_pcm);
85
86 1759 av_freep(&l->qp_y_tab);
87 1759 av_freep(&l->tab_slice_address);
88 1759 av_freep(&l->filter_slice_edges);
89
90 1759 av_freep(&l->horizontal_bs);
91 1759 av_freep(&l->vertical_bs);
92
93
2/2
✓ Branch 0 taken 5277 times.
✓ Branch 1 taken 1759 times.
7036 for (int i = 0; i < 3; i++) {
94 5277 av_freep(&l->sao_pixel_buffer_h[i]);
95 5277 av_freep(&l->sao_pixel_buffer_v[i]);
96 }
97
98 1759 av_refstruct_pool_uninit(&l->tab_mvf_pool);
99 1759 av_refstruct_pool_uninit(&l->rpl_tab_pool);
100 1759 }
101
102 /* allocate arrays that depend on frame dimensions */
103 263 static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps)
104 {
105 263 int log2_min_cb_size = sps->log2_min_cb_size;
106 263 int width = sps->width;
107 263 int height = sps->height;
108 263 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
109 263 ((height >> log2_min_cb_size) + 1);
110 263 int ctb_count = sps->ctb_width * sps->ctb_height;
111 263 int min_pu_size = sps->min_pu_width * sps->min_pu_height;
112
113 263 l->bs_width = (width >> 2) + 1;
114 263 l->bs_height = (height >> 2) + 1;
115
116 263 l->sao = av_calloc(ctb_count, sizeof(*l->sao));
117 263 l->deblock = av_calloc(ctb_count, sizeof(*l->deblock));
118
2/4
✓ Branch 0 taken 263 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 263 times.
263 if (!l->sao || !l->deblock)
119 ✗ goto fail;
120
121 263 l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
122 263 l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
123
2/4
✓ Branch 0 taken 263 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 263 times.
263 if (!l->skip_flag || !l->tab_ct_depth)
124 ✗ goto fail;
125
126 263 l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
127 263 l->tab_ipm = av_mallocz(min_pu_size);
128 263 l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1);
129
3/6
✓ Branch 0 taken 263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 263 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 263 times.
263 if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm)
130 ✗ goto fail;
131
132 263 l->filter_slice_edges = av_mallocz(ctb_count);
133 263 l->tab_slice_address = av_malloc_array(pic_size_in_ctb,
134 sizeof(*l->tab_slice_address));
135 263 l->qp_y_tab = av_calloc(pic_size_in_ctb,
136 sizeof(*l->qp_y_tab));
137
3/6
✓ Branch 0 taken 263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 263 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 263 times.
263 if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address)
138 ✗ goto fail;
139
140 263 l->horizontal_bs = av_calloc(l->bs_width, l->bs_height);
141 263 l->vertical_bs = av_calloc(l->bs_width, l->bs_height);
142
2/4
✓ Branch 0 taken 263 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 263 times.
263 if (!l->horizontal_bs || !l->vertical_bs)
143 ✗ goto fail;
144
145 263 l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
146 263 l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0);
147
2/4
✓ Branch 0 taken 263 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 263 times.
263 if (!l->tab_mvf_pool || !l->rpl_tab_pool)
148 ✗ goto fail;
149
150
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 44 times.
263 if (sps->sao_enabled) {
151
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 2 times.
219 int c_count = (sps->chroma_format_idc != 0) ? 3 : 1;
152
153
2/2
✓ Branch 0 taken 653 times.
✓ Branch 1 taken 219 times.
872 for (int c_idx = 0; c_idx < c_count; c_idx++) {
154 653 int w = sps->width >> sps->hshift[c_idx];
155 653 int h = sps->height >> sps->vshift[c_idx];
156 653 l->sao_pixel_buffer_h[c_idx] =
157 653 av_mallocz((w * 2 * sps->ctb_height) <<
158 653 sps->pixel_shift);
159 653 l->sao_pixel_buffer_v[c_idx] =
160 653 av_mallocz((h * 2 * sps->ctb_width) <<
161 653 sps->pixel_shift);
162
1/2
✓ Branch 0 taken 653 times.
✗ Branch 1 not taken.
653 if (!l->sao_pixel_buffer_h[c_idx] ||
163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 653 times.
653 !l->sao_pixel_buffer_v[c_idx])
164 ✗ goto fail;
165 }
166 }
167
168 263 return 0;
169
170 ✗ fail:
171 ✗ pic_arrays_free(l);
172 ✗ return AVERROR(ENOMEM);
173 }
174
175 1501 static int pred_weight_table(SliceHeader *sh, void *logctx,
176 const HEVCSPS *sps, GetBitContext *gb)
177 {
178 1501 int i = 0;
179 1501 int j = 0;
180 int luma_log2_weight_denom;
181 unsigned luma_weight_flags, chroma_weight_flags;
182
183 1501 luma_log2_weight_denom = get_ue_golomb_long(gb);
184
2/4
✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1501 times.
1501 if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
185 ✗ av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
186 ✗ return AVERROR_INVALIDDATA;
187 }
188 1501 sh->luma_log2_weight_denom = luma_log2_weight_denom;
189
1/2
✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
1501 if (sps->chroma_format_idc != 0) {
190 1501 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
191
2/4
✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1501 times.
1501 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
192 ✗ av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
193 ✗ return AVERROR_INVALIDDATA;
194 }
195 1501 sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
196 }
197
198 1501 luma_weight_flags = get_bits(gb, sh->nb_refs[L0]);
199
1/2
✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
1501 chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L0]) : 0;
200
2/2
✓ Branch 0 taken 4549 times.
✓ Branch 1 taken 1501 times.
6050 for (i = 0; i < sh->nb_refs[L0]; i++) {
201 4549 unsigned flag_bit = 1 << (sh->nb_refs[L0] - 1 - i);
202
203
2/2
✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1432 times.
4549 if (luma_weight_flags & flag_bit) {
204 3117 int delta_luma_weight_l0 = get_se_golomb(gb);
205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
3117 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
206 ✗ return AVERROR_INVALIDDATA;
207 3117 sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
208 3117 sh->luma_offset_l0[i] = get_se_golomb(gb);
209 } else {
210 1432 sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
211 1432 sh->luma_offset_l0[i] = 0;
212 }
213
2/2
✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3418 times.
4549 if (chroma_weight_flags & flag_bit) {
214
2/2
✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
3393 for (j = 0; j < 2; j++) {
215 2262 int delta_chroma_weight_l0 = get_se_golomb(gb);
216 2262 int delta_chroma_offset_l0 = get_se_golomb(gb);
217
218
1/2
✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
2262 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
219
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)) {
220 ✗ return AVERROR_INVALIDDATA;
221 }
222
223 2262 sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0;
224 2262 sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j])
225 2262 >> sh->chroma_log2_weight_denom) + 128), -128, 127);
226 }
227 } else {
228 3418 sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom;
229 3418 sh->chroma_offset_l0[i][0] = 0;
230 3418 sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom;
231 3418 sh->chroma_offset_l0[i][1] = 0;
232 }
233 }
234
2/2
✓ Branch 0 taken 696 times.
✓ Branch 1 taken 805 times.
1501 if (sh->slice_type == HEVC_SLICE_B) {
235 696 luma_weight_flags = get_bits(gb, sh->nb_refs[L1]);
236
1/2
✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
696 chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L1]) : 0;
237
2/2
✓ Branch 0 taken 1405 times.
✓ Branch 1 taken 696 times.
2101 for (i = 0; i < sh->nb_refs[L1]; i++) {
238 1405 unsigned flag_bit = 1 << (sh->nb_refs[L1] - 1 - i);
239
240
2/2
✓ Branch 0 taken 746 times.
✓ Branch 1 taken 659 times.
1405 if (luma_weight_flags & flag_bit) {
241 746 int delta_luma_weight_l1 = get_se_golomb(gb);
242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
746 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
243 ✗ return AVERROR_INVALIDDATA;
244 746 sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
245 746 sh->luma_offset_l1[i] = get_se_golomb(gb);
246 } else {
247 659 sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
248 659 sh->luma_offset_l1[i] = 0;
249 }
250
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1169 times.
1405 if (chroma_weight_flags & flag_bit) {
251
2/2
✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
708 for (j = 0; j < 2; j++) {
252 472 int delta_chroma_weight_l1 = get_se_golomb(gb);
253 472 int delta_chroma_offset_l1 = get_se_golomb(gb);
254
255
1/2
✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
472 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
256
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)) {
257 ✗ return AVERROR_INVALIDDATA;
258 }
259
260 472 sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1;
261 472 sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j])
262 472 >> sh->chroma_log2_weight_denom) + 128), -128, 127);
263 }
264 } else {
265 1169 sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom;
266 1169 sh->chroma_offset_l1[i][0] = 0;
267 1169 sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom;
268 1169 sh->chroma_offset_l1[i][1] = 0;
269 }
270 }
271 }
272 1501 return 0;
273 }
274
275 20478 static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps,
276 GetBitContext *gb, int cur_poc, int poc_lsb)
277 {
278 20478 int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
279 20478 int prev_delta_msb = 0;
280 20478 unsigned int nb_sps = 0, nb_sh;
281 int i;
282
283 20478 rps->nb_refs = 0;
284
2/2
✓ Branch 0 taken 19076 times.
✓ Branch 1 taken 1402 times.
20478 if (!sps->long_term_ref_pics_present)
285 19076 return 0;
286
287
2/2
✓ Branch 0 taken 499 times.
✓ Branch 1 taken 903 times.
1402 if (sps->num_long_term_ref_pics_sps > 0)
288 499 nb_sps = get_ue_golomb_long(gb);
289 1402 nb_sh = get_ue_golomb_long(gb);
290
291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1402 times.
1402 if (nb_sps > sps->num_long_term_ref_pics_sps)
292 ✗ return AVERROR_INVALIDDATA;
293
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1402 times.
1402 if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc))
294 ✗ return AVERROR_INVALIDDATA;
295
296 1402 rps->nb_refs = nb_sh + nb_sps;
297
298
2/2
✓ Branch 0 taken 1928 times.
✓ Branch 1 taken 1402 times.
3330 for (i = 0; i < rps->nb_refs; i++) {
299
300
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1744 times.
1928 if (i < nb_sps) {
301 184 uint8_t lt_idx_sps = 0;
302
303
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if (sps->num_long_term_ref_pics_sps > 1)
304 184 lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps));
305
306 184 rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
307 184 rps->used[i] = !!(sps->used_by_curr_pic_lt & (1U << lt_idx_sps));
308 } else {
309 1744 rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb);
310 1744 rps->used[i] = get_bits1(gb);
311 }
312
313 1928 rps->poc_msb_present[i] = get_bits1(gb);
314
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1880 times.
1928 if (rps->poc_msb_present[i]) {
315 48 int64_t delta = get_ue_golomb_long(gb);
316 int64_t poc;
317
318
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)
319 31 delta += prev_delta_msb;
320
321 48 poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb;
322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (poc != (int32_t)poc)
323 ✗ return AVERROR_INVALIDDATA;
324 48 rps->poc[i] = poc;
325 48 prev_delta_msb = delta;
326 }
327 }
328
329 1402 return 0;
330 }
331
332 862 static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
333 {
334 862 AVCodecContext *avctx = s->avctx;
335 862 const HEVCVPS *vps = sps->vps;
336 862 const HEVCWindow *ow = &sps->output_window;
337 862 unsigned int num = 0, den = 0;
338
339 862 avctx->pix_fmt = sps->pix_fmt;
340 862 avctx->coded_width = sps->width;
341 862 avctx->coded_height = sps->height;
342 862 avctx->width = sps->width - ow->left_offset - ow->right_offset;
343 862 avctx->height = sps->height - ow->top_offset - ow->bottom_offset;
344 862 avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
345 862 avctx->profile = sps->ptl.general_ptl.profile_idc;
346 862 avctx->level = sps->ptl.general_ptl.level_idc;
347
348 862 ff_set_sar(avctx, sps->vui.common.sar);
349
350
2/2
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 707 times.
862 if (sps->vui.common.video_signal_type_present_flag)
351 155 avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG
352
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 124 times.
155 : AVCOL_RANGE_MPEG;
353 else
354 707 avctx->color_range = AVCOL_RANGE_MPEG;
355
356
2/2
✓ Branch 0 taken 145 times.
✓ Branch 1 taken 717 times.
862 if (sps->vui.common.colour_description_present_flag) {
357 145 avctx->color_primaries = sps->vui.common.colour_primaries;
358 145 avctx->color_trc = sps->vui.common.transfer_characteristics;
359 145 avctx->colorspace = sps->vui.common.matrix_coeffs;
360 } else {
361 717 avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
362 717 avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
363 717 avctx->colorspace = AVCOL_SPC_UNSPECIFIED;
364 }
365
366 862 avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
367
2/2
✓ Branch 0 taken 812 times.
✓ Branch 1 taken 50 times.
862 if (sps->chroma_format_idc == 1) {
368
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 763 times.
812 if (sps->vui.common.chroma_loc_info_present_flag) {
369
1/2
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
49 if (sps->vui.common.chroma_sample_loc_type_top_field <= 5)
370 49 avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1;
371 } else
372 763 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
373 }
374
375
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 813 times.
862 if (vps->vps_timing_info_present_flag) {
376 49 num = vps->vps_num_units_in_tick;
377 49 den = vps->vps_time_scale;
378
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 680 times.
813 } else if (sps->vui.vui_timing_info_present_flag) {
379 133 num = sps->vui.vui_num_units_in_tick;
380 133 den = sps->vui.vui_time_scale;
381 }
382
383
3/4
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 680 times.
✓ Branch 2 taken 182 times.
✗ Branch 3 not taken.
862 if (num > 0 && den > 0)
384 182 av_reduce(&avctx->framerate.den, &avctx->framerate.num,
385 num, den, 1 << 30);
386 862 }
387
388 11201 static int export_stream_params_from_sei(HEVCContext *s)
389 {
390 11201 AVCodecContext *avctx = s->avctx;
391
392
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11201 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11201 if (s->sei.common.alternative_transfer.present &&
393 ✗ av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) &&
394 ✗ s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
395 ✗ avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics;
396 }
397
398 11201 return 0;
399 }
400
401 633 static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
402 {
403 633 const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
404
405 633 av_freep(&s->view_ids_available);
406 633 s->nb_view_ids_available = 0;
407 633 av_freep(&s->view_pos_available);
408 633 s->nb_view_pos_available = 0;
409
410 // don't export anything in the trivial case (1 layer, view id=0)
411
3/4
✓ Branch 0 taken 610 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 610 times.
✗ Branch 3 not taken.
633 if (vps->nb_layers < 2 && !vps->view_id[0])
412 610 return 0;
413
414 23 s->view_ids_available = av_calloc(vps->nb_layers, sizeof(*s->view_ids_available));
415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (!s->view_ids_available)
416 ✗ return AVERROR(ENOMEM);
417
418
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 18 times.
23 if (tdrdi->num_ref_displays) {
419 5 s->view_pos_available = av_calloc(vps->nb_layers, sizeof(*s->view_pos_available));
420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!s->view_pos_available)
421 ✗ return AVERROR(ENOMEM);
422 }
423
424
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 23 times.
69 for (int i = 0; i < vps->nb_layers; i++) {
425 46 s->view_ids_available[i] = vps->view_id[i];
426
427
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 36 times.
46 if (s->view_pos_available) {
428 10 s->view_pos_available[i] = vps->view_id[i] == tdrdi->left_view_id[0] ?
429
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
15 AV_STEREO3D_VIEW_LEFT :
430
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 vps->view_id[i] == tdrdi->right_view_id[0] ?
431 AV_STEREO3D_VIEW_RIGHT : AV_STEREO3D_VIEW_UNSPEC;
432 }
433 }
434 23 s->nb_view_ids_available = vps->nb_layers;
435
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 18 times.
23 s->nb_view_pos_available = s->view_pos_available ? vps->nb_layers : 0;
436
437 23 return 0;
438 }
439
440 11938 int ff_hevc_is_alpha_video(const HEVCContext *s)
441 {
442 11938 const HEVCVPS *vps = s->vps;
443 11938 int ret = 0;
444
445
3/4
✓ Branch 0 taken 1590 times.
✓ Branch 1 taken 10348 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1590 times.
11938 if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1])
446 10348 return 0;
447
448 /* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other
449 * than alpha cannot reach here.
450 */
451 1590 ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY);
452
453
2/2
✓ Branch 0 taken 203 times.
✓ Branch 1 taken 1387 times.
1590 av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n",
454 ret ? "is" : "not");
455
456 1590 return ret;
457 }
458
459 251 int ff_hevc_requested_layers(const HEVCContext *s, const HEVCVPS *vps,
460 unsigned *active_output)
461 {
462 251 unsigned layers_active_output = 0, highest_layer;
463
464 // nothing requested - decode base layer only
465
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 11 times.
251 if (!s->nb_view_ids) {
466 240 *active_output = 1;
467 240 return 1;
468 }
469
470
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
11 if (s->nb_view_ids == 1 && s->view_ids[0] == -1) {
471 ✗ layers_active_output = (1 << vps->nb_layers) - 1;
472 } else {
473
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 11 times.
30 for (int i = 0; i < s->nb_view_ids; i++) {
474 19 int view_id = s->view_ids[i];
475 19 int layer_idx = -1;
476
477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
19 if (view_id < 0) {
478 ✗ av_log(s->avctx, AV_LOG_ERROR,
479 "Invalid view ID requested: %d\n", view_id);
480 ✗ return AVERROR(EINVAL);
481 }
482
483
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 for (int j = 0; j < vps->nb_layers; j++) {
484
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 9 times.
28 if (vps->view_id[j] == view_id) {
485 19 layer_idx = j;
486 19 break;
487 }
488 }
489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
19 if (layer_idx < 0) {
490 ✗ av_log(s->avctx, AV_LOG_ERROR,
491 "View ID %d not present in VPS\n", view_id);
492 ✗ return AVERROR(EINVAL);
493 }
494 19 layers_active_output |= 1 << layer_idx;
495 }
496 }
497
498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (!layers_active_output) {
499 ✗ av_log(s->avctx, AV_LOG_ERROR, "No layers selected\n");
500 ✗ return AVERROR_BUG;
501 }
502
503 11 highest_layer = ff_log2(layers_active_output);
504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (highest_layer >= FF_ARRAY_ELEMS(s->layers)) {
505 ✗ av_log(s->avctx, AV_LOG_ERROR,
506 "Too many layers requested: %u\n", layers_active_output);
507 ✗ return AVERROR(EINVAL);
508 }
509
510 11 *active_output = layers_active_output;
511
512 /* Assume a higher layer depends on all the lower ones.
513 * This is enforced in VPS parsing currently, this logic will need
514 * to be changed if we want to support more complex dependency structures.
515 */
516 11 return highest_layer + 1;
517 }
518
519 252 static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
520 {
521 unsigned layers_active_output;
522 int nb_decode_layers;
523
524 252 s->layers_active_output = 1;
525 252 s->layers_active_decode = 1;
526
527
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 251 times.
252 if (ff_hevc_is_alpha_video(s)) {
528 1 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
529
530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
531 ✗ return 0;
532
533 1 s->layers_active_decode = (1 << vps->nb_layers) - 1;
534 1 s->layers_active_output = 1;
535
536 1 return 0;
537 }
538
539 251 nb_decode_layers = ff_hevc_requested_layers(s, vps, &layers_active_output);
540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 251 times.
251 if (nb_decode_layers < 0)
541 ✗ return nb_decode_layers;
542
543 251 s->layers_active_decode = (1 << nb_decode_layers) - 1;
544 251 s->layers_active_output = layers_active_output;
545
546 251 av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n",
547 s->layers_active_decode, s->layers_active_output);
548
549 251 return 0;
550 }
551
552 1 static enum AVPixelFormat map_to_alpha_format(HEVCContext *s,
553 enum AVPixelFormat pix_fmt)
554 {
555
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) {
556 1 case AV_PIX_FMT_YUV420P:
557 case AV_PIX_FMT_YUVJ420P:
558 1 return AV_PIX_FMT_YUVA420P;
559 ✗ case AV_PIX_FMT_YUV420P10:
560 ✗ return AV_PIX_FMT_YUVA420P10;
561 ✗ case AV_PIX_FMT_YUV444P:
562 ✗ return AV_PIX_FMT_YUVA444P;
563 ✗ case AV_PIX_FMT_YUV422P:
564 ✗ return AV_PIX_FMT_YUVA422P;
565 ✗ case AV_PIX_FMT_YUV422P10LE:
566 ✗ return AV_PIX_FMT_YUVA422P10LE;
567 ✗ case AV_PIX_FMT_YUV444P10:
568 ✗ return AV_PIX_FMT_YUVA444P10;
569 ✗ case AV_PIX_FMT_YUV444P12:
570 ✗ return AV_PIX_FMT_YUVA444P12;
571 ✗ case AV_PIX_FMT_YUV422P12:
572 ✗ return AV_PIX_FMT_YUVA422P12;
573 ✗ default:
574 ✗ av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n",
575 av_get_pix_fmt_name(pix_fmt));
576 ✗ return AV_PIX_FMT_NONE;
577 }
578 }
579
580 252 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
581 {
582 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
583 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
584 CONFIG_HEVC_D3D12VA_HWACCEL + \
585 CONFIG_HEVC_NVDEC_HWACCEL + \
586 CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL + \
587 CONFIG_HEVC_VAAPI_HWACCEL + \
588 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
589 CONFIG_HEVC_VDPAU_HWACCEL + \
590 CONFIG_HEVC_VULKAN_HWACCEL)
591 252 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts;
592 252 enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE;
593 int ret;
594
595
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 251 times.
252 if (ff_hevc_is_alpha_video(s))
596 1 alpha_fmt = map_to_alpha_format(s, sps->pix_fmt);
597
598
6/7
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
252 switch (sps->pix_fmt) {
599 205 case AV_PIX_FMT_YUV420P:
600 case AV_PIX_FMT_YUVJ420P:
601 #if CONFIG_HEVC_DXVA2_HWACCEL
602 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
603 #endif
604 #if CONFIG_HEVC_D3D11VA_HWACCEL
605 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
606 *fmt++ = AV_PIX_FMT_D3D11;
607 #endif
608 #if CONFIG_HEVC_D3D12VA_HWACCEL
609 *fmt++ = AV_PIX_FMT_D3D12;
610 #endif
611 #if CONFIG_HEVC_VAAPI_HWACCEL
612 205 *fmt++ = AV_PIX_FMT_VAAPI;
613 #endif
614 #if CONFIG_HEVC_VDPAU_HWACCEL
615 205 *fmt++ = AV_PIX_FMT_VDPAU;
616 #endif
617 #if CONFIG_HEVC_NVDEC_HWACCEL
618 *fmt++ = AV_PIX_FMT_CUDA;
619 #endif
620 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
621 *fmt++ = AV_PIX_FMT_CUARRAY;
622 #endif
623 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
624 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
625 #endif
626 #if CONFIG_HEVC_VULKAN_HWACCEL
627 *fmt++ = AV_PIX_FMT_VULKAN;
628 #endif
629 205 break;
630 29 case AV_PIX_FMT_YUV420P10:
631 #if CONFIG_HEVC_DXVA2_HWACCEL
632 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
633 #endif
634 #if CONFIG_HEVC_D3D11VA_HWACCEL
635 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
636 *fmt++ = AV_PIX_FMT_D3D11;
637 #endif
638 #if CONFIG_HEVC_D3D12VA_HWACCEL
639 *fmt++ = AV_PIX_FMT_D3D12;
640 #endif
641 #if CONFIG_HEVC_VAAPI_HWACCEL
642 29 *fmt++ = AV_PIX_FMT_VAAPI;
643 #endif
644 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
645 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
646 #endif
647 #if CONFIG_HEVC_VULKAN_HWACCEL
648 *fmt++ = AV_PIX_FMT_VULKAN;
649 #endif
650 #if CONFIG_HEVC_VDPAU_HWACCEL
651 29 *fmt++ = AV_PIX_FMT_VDPAU;
652 #endif
653 #if CONFIG_HEVC_NVDEC_HWACCEL
654 *fmt++ = AV_PIX_FMT_CUDA;
655 #endif
656 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
657 *fmt++ = AV_PIX_FMT_CUARRAY;
658 #endif
659 29 break;
660 2 case AV_PIX_FMT_YUV444P:
661 #if CONFIG_HEVC_VAAPI_HWACCEL
662 2 *fmt++ = AV_PIX_FMT_VAAPI;
663 #endif
664 #if CONFIG_HEVC_VDPAU_HWACCEL
665 2 *fmt++ = AV_PIX_FMT_VDPAU;
666 #endif
667 #if CONFIG_HEVC_NVDEC_HWACCEL
668 *fmt++ = AV_PIX_FMT_CUDA;
669 #endif
670 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
671 *fmt++ = AV_PIX_FMT_CUARRAY;
672 #endif
673 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
674 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
675 #endif
676 #if CONFIG_HEVC_VULKAN_HWACCEL
677 *fmt++ = AV_PIX_FMT_VULKAN;
678 #endif
679 2 break;
680 7 case AV_PIX_FMT_YUV422P:
681 case AV_PIX_FMT_YUV422P10LE:
682 #if CONFIG_HEVC_VAAPI_HWACCEL
683 7 *fmt++ = AV_PIX_FMT_VAAPI;
684 #endif
685 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
686 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
687 #endif
688 #if CONFIG_HEVC_VULKAN_HWACCEL
689 *fmt++ = AV_PIX_FMT_VULKAN;
690 #endif
691 #if CONFIG_HEVC_NVDEC_HWACCEL
692 *fmt++ = AV_PIX_FMT_CUDA;
693 #endif
694 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
695 *fmt++ = AV_PIX_FMT_CUARRAY;
696 #endif
697 7 break;
698 6 case AV_PIX_FMT_YUV444P10:
699 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
700 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
701 #endif
702 av_fallthrough;
703 case AV_PIX_FMT_YUV420P12:
704 case AV_PIX_FMT_YUV444P12:
705 #if CONFIG_HEVC_VAAPI_HWACCEL
706 6 *fmt++ = AV_PIX_FMT_VAAPI;
707 #endif
708 #if CONFIG_HEVC_VDPAU_HWACCEL
709 6 *fmt++ = AV_PIX_FMT_VDPAU;
710 #endif
711 #if CONFIG_HEVC_VULKAN_HWACCEL
712 *fmt++ = AV_PIX_FMT_VULKAN;
713 #endif
714 #if CONFIG_HEVC_NVDEC_HWACCEL
715 *fmt++ = AV_PIX_FMT_CUDA;
716 #endif
717 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
718 *fmt++ = AV_PIX_FMT_CUARRAY;
719 #endif
720 6 break;
721 ✗ case AV_PIX_FMT_YUV422P12:
722 #if CONFIG_HEVC_VAAPI_HWACCEL
723 ✗ *fmt++ = AV_PIX_FMT_VAAPI;
724 #endif
725 #if CONFIG_HEVC_VULKAN_HWACCEL
726 *fmt++ = AV_PIX_FMT_VULKAN;
727 #endif
728 #if CONFIG_HEVC_NVDEC_HWACCEL
729 *fmt++ = AV_PIX_FMT_CUDA;
730 #endif
731 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
732 *fmt++ = AV_PIX_FMT_CUARRAY;
733 #endif
734 ✗ break;
735 }
736
737
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 251 times.
252 if (alpha_fmt != AV_PIX_FMT_NONE)
738 1 *fmt++ = alpha_fmt;
739 252 *fmt++ = sps->pix_fmt;
740 252 *fmt = AV_PIX_FMT_NONE;
741
742 // export multilayer information from active VPS to the caller,
743 // so it is available in get_format()
744 252 ret = export_multilayer(s, sps->vps);
745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if (ret < 0)
746 ✗ return ret;
747
748 252 ret = ff_get_format(s->avctx, pix_fmts);
749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if (ret < 0)
750 ✗ return ret;
751 252 s->avctx->pix_fmt = ret;
752
753 // set up multilayer decoding, if requested by caller
754 252 ret = setup_multilayer(s, sps->vps);
755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if (ret < 0)
756 ✗ return ret;
757
758 252 return 0;
759 }
760
761 515 static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
762 {
763 int ret;
764
765 515 pic_arrays_free(l);
766 515 av_refstruct_unref(&l->sps);
767
768
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 263 times.
515 if (!sps)
769 252 return 0;
770
771 263 av_refstruct_unref(&s->vps);
772
773 263 ret = pic_arrays_init(l, sps);
774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 263 times.
263 if (ret < 0)
775 ✗ goto fail;
776
777 263 av_refstruct_unref(&s->vps);
778
779 263 ff_hevc_pred_init(&s->hpc, sps->bit_depth);
780 263 ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
781 263 ff_videodsp_init (&s->vdsp, sps->bit_depth);
782
783 263 l->sps = av_refstruct_ref_c(sps);
784 263 s->vps = av_refstruct_ref_c(sps->vps);
785
786 263 return 0;
787
788 ✗ fail:
789 ✗ pic_arrays_free(l);
790 ✗ av_refstruct_unref(&l->sps);
791 ✗ return ret;
792 }
793
794 28669 static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb)
795 {
796 const HEVCPPS *pps;
797 const HEVCSPS *sps;
798 const HEVCVPS *vps;
799 unsigned pps_id;
800 int i, ret, layer_idx;
801
802 // Coded parameters
803 28669 sh->first_slice_in_pic_flag = get_bits1(gb);
804
805 28669 sh->no_output_of_prior_pics_flag = 0;
806
3/4
✓ Branch 0 taken 1070 times.
✓ Branch 1 taken 27599 times.
✓ Branch 2 taken 1070 times.
✗ Branch 3 not taken.
28669 if (IS_IRAP(s))
807 1070 sh->no_output_of_prior_pics_flag = get_bits1(gb);
808
809 28669 pps_id = get_ue_golomb_long(gb);
810
2/4
✓ Branch 0 taken 28669 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 28669 times.
28669 if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) {
811 ✗ av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
812 ✗ return AVERROR_INVALIDDATA;
813 }
814
3/4
✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10673 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17996 times.
28669 if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) {
815 ✗ av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
816 ✗ return AVERROR_INVALIDDATA;
817 }
818 28669 sh->pps_id = pps_id;
819
820 28669 pps = s->ps.pps_list[pps_id];
821 28669 sps = pps->sps;
822 28669 vps = sps->vps;
823 28669 layer_idx = vps->layer_idx[s->nuh_layer_id];
824
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28669 times.
28669 if (layer_idx < 0) {
825 ✗ av_log(s->avctx, AV_LOG_ERROR, "Layer %d is not in the VPS\n", s->nuh_layer_id);
826 ✗ return AVERROR_INVALIDDATA;
827 }
828
829
4/4
✓ Branch 0 taken 502 times.
✓ Branch 1 taken 28167 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 491 times.
28669 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
830 11 sh->no_output_of_prior_pics_flag = 1;
831
832 28669 sh->dependent_slice_segment_flag = 0;
833
2/2
✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10673 times.
28669 if (!sh->first_slice_in_pic_flag) {
834 int slice_address_length;
835
836
2/2
✓ Branch 0 taken 8936 times.
✓ Branch 1 taken 9060 times.
17996 if (pps->dependent_slice_segments_enabled_flag)
837 8936 sh->dependent_slice_segment_flag = get_bits1(gb);
838
3/4
✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 10202 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7794 times.
17996 if (sh->dependent_slice_segment_flag && !s->slice_initialized) {
839 ✗ av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
840 ✗ return AVERROR_INVALIDDATA;
841 }
842
843 17996 slice_address_length = av_ceil_log2(sps->ctb_width *
844 17996 sps->ctb_height);
845 17996 sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17996 times.
17996 if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
847 ✗ av_log(s->avctx, AV_LOG_ERROR,
848 "Invalid slice segment address: %u.\n",
849 sh->slice_segment_addr);
850 ✗ return AVERROR_INVALIDDATA;
851 }
852
853
2/2
✓ Branch 0 taken 10202 times.
✓ Branch 1 taken 7794 times.
17996 if (!sh->dependent_slice_segment_flag) {
854 10202 sh->slice_addr = sh->slice_segment_addr;
855 }
856 } else {
857 10673 sh->slice_segment_addr = sh->slice_addr = 0;
858 }
859
860
2/2
✓ Branch 0 taken 20875 times.
✓ Branch 1 taken 7794 times.
28669 if (!sh->dependent_slice_segment_flag) {
861
2/2
✓ Branch 0 taken 1823 times.
✓ Branch 1 taken 20875 times.
22698 for (i = 0; i < pps->num_extra_slice_header_bits; i++)
862 1823 skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
863
864 20875 sh->slice_type = get_ue_golomb_long(gb);
865
2/2
✓ Branch 0 taken 19862 times.
✓ Branch 1 taken 1013 times.
20875 if (!(sh->slice_type == HEVC_SLICE_I ||
866
2/2
✓ Branch 0 taken 15427 times.
✓ Branch 1 taken 4435 times.
19862 sh->slice_type == HEVC_SLICE_P ||
867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15427 times.
15427 sh->slice_type == HEVC_SLICE_B)) {
868 ✗ av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",
869 ✗ sh->slice_type);
870 ✗ return AVERROR_INVALIDDATA;
871 }
872
5/6
✓ Branch 0 taken 834 times.
✓ Branch 1 taken 20041 times.
✓ Branch 2 taken 834 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 753 times.
20875 if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
873
1/2
✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
81 !pps->pps_curr_pic_ref_enabled_flag &&
874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
81 s->nuh_layer_id == 0) {
875 ✗ av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
876 ✗ return AVERROR_INVALIDDATA;
877 }
878
879 // when flag is not present, picture is inferred to be output
880 20875 sh->pic_output_flag = 1;
881
2/2
✓ Branch 0 taken 700 times.
✓ Branch 1 taken 20175 times.
20875 if (pps->output_flag_present_flag)
882 700 sh->pic_output_flag = get_bits1(gb);
883
884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20875 times.
20875 if (sps->separate_colour_plane)
885 ✗ sh->colour_plane_id = get_bits(gb, 2);
886
887
4/4
✓ Branch 0 taken 20526 times.
✓ Branch 1 taken 349 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 20478 times.
20875 if (!IS_IDR(s) ||
888
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 379 times.
397 (s->nuh_layer_id > 0 &&
889
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5 times.
18 !(vps->poc_lsb_not_present & (1 << layer_idx)))) {
890 int poc;
891
892 20491 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
893 20491 poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
894
3/4
✓ Branch 0 taken 10073 times.
✓ Branch 1 taken 10418 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10073 times.
20491 if (!sh->first_slice_in_pic_flag && poc != sh->poc) {
895 ✗ av_log(s->avctx, AV_LOG_WARNING,
896 "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc);
897 ✗ if (s->avctx->err_recognition & AV_EF_EXPLODE)
898 ✗ return AVERROR_INVALIDDATA;
899 ✗ poc = sh->poc;
900 }
901 20491 sh->poc = poc;
902 }
903
904
4/4
✓ Branch 0 taken 20526 times.
✓ Branch 1 taken 349 times.
✓ Branch 2 taken 20478 times.
✓ Branch 3 taken 48 times.
41353 if (!IS_IDR(s)) {
905 int pos;
906
907 20478 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
908 20478 pos = get_bits_left(gb);
909
2/2
✓ Branch 0 taken 4095 times.
✓ Branch 1 taken 16383 times.
20478 if (!sh->short_term_ref_pic_set_sps_flag) {
910 4095 ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1);
911
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4095 times.
4095 if (ret < 0)
912 ✗ return ret;
913
914 4095 sh->short_term_rps = &sh->slice_rps;
915 } else {
916 int numbits, rps_idx;
917
918
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16383 times.
16383 if (!sps->nb_st_rps) {
919 ✗ av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
920 ✗ return AVERROR_INVALIDDATA;
921 }
922
923 16383 numbits = av_ceil_log2(sps->nb_st_rps);
924
2/2
✓ Branch 0 taken 16355 times.
✓ Branch 1 taken 28 times.
16383 rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
925 16383 sh->short_term_rps = &sps->st_rps[rps_idx];
926 }
927 20478 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
928
929 20478 pos = get_bits_left(gb);
930 20478 ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb);
931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20478 times.
20478 if (ret < 0) {
932 ✗ av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
933 ✗ if (s->avctx->err_recognition & AV_EF_EXPLODE)
934 ✗ return AVERROR_INVALIDDATA;
935 }
936 20478 sh->long_term_ref_pic_set_size = pos - get_bits_left(gb);
937
938
2/2
✓ Branch 0 taken 17921 times.
✓ Branch 1 taken 2557 times.
20478 if (sps->temporal_mvp_enabled)
939 17921 sh->slice_temporal_mvp_enabled_flag = get_bits1(gb);
940 else
941 2557 sh->slice_temporal_mvp_enabled_flag = 0;
942 } else {
943 397 sh->poc = 0;
944 397 sh->pic_order_cnt_lsb = 0;
945 397 sh->short_term_ref_pic_set_sps_flag = 0;
946 397 sh->short_term_ref_pic_set_size = 0;
947 397 sh->short_term_rps = NULL;
948 397 sh->long_term_ref_pic_set_size = 0;
949 397 sh->long_term_rps.nb_refs = 0;
950 397 sh->slice_temporal_mvp_enabled_flag = 0;
951 }
952
953 20875 sh->inter_layer_pred = 0;
954
2/2
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 20359 times.
20875 if (s->nuh_layer_id > 0) {
955 516 int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx];
956
957
2/2
✓ Branch 0 taken 418 times.
✓ Branch 1 taken 98 times.
516 if (vps->default_ref_layers_active)
958 418 sh->inter_layer_pred = !!num_direct_ref_layers;
959
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 50 times.
98 else if (num_direct_ref_layers) {
960 48 sh->inter_layer_pred = get_bits1(gb);
961
962
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) {
963 ✗ av_log(s->avctx, AV_LOG_ERROR,
964 "NumDirectRefLayers>1 not supported\n");
965 ✗ return AVERROR_PATCHWELCOME;
966 }
967 }
968 }
969
970
2/2
✓ Branch 0 taken 17309 times.
✓ Branch 1 taken 3566 times.
20875 if (sps->sao_enabled) {
971 17309 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
972
2/2
✓ Branch 0 taken 17307 times.
✓ Branch 1 taken 2 times.
17309 if (sps->chroma_format_idc) {
973 17307 sh->slice_sample_adaptive_offset_flag[1] =
974 17307 sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb);
975 }
976 } else {
977 3566 sh->slice_sample_adaptive_offset_flag[0] = 0;
978 3566 sh->slice_sample_adaptive_offset_flag[1] = 0;
979 3566 sh->slice_sample_adaptive_offset_flag[2] = 0;
980 }
981
982 20875 sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
983
4/4
✓ Branch 0 taken 16440 times.
✓ Branch 1 taken 4435 times.
✓ Branch 2 taken 15427 times.
✓ Branch 3 taken 1013 times.
20875 if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
984 int nb_refs;
985
986 19862 sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active;
987
2/2
✓ Branch 0 taken 15427 times.
✓ Branch 1 taken 4435 times.
19862 if (sh->slice_type == HEVC_SLICE_B)
988 15427 sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active;
989
990
2/2
✓ Branch 1 taken 5551 times.
✓ Branch 2 taken 14311 times.
19862 if (get_bits1(gb)) { // num_ref_idx_active_override_flag
991 5551 sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1;
992
2/2
✓ Branch 0 taken 2881 times.
✓ Branch 1 taken 2670 times.
5551 if (sh->slice_type == HEVC_SLICE_B)
993 2881 sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1;
994 }
995
2/4
✓ Branch 0 taken 19862 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19862 times.
19862 if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) {
996 ✗ av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n",
997 sh->nb_refs[L0], sh->nb_refs[L1]);
998 ✗ return AVERROR_INVALIDDATA;
999 }
1000
1001 19862 sh->rpl_modification_flag[0] = 0;
1002 19862 sh->rpl_modification_flag[1] = 0;
1003 19862 nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx);
1004
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19862 times.
19862 if (!nb_refs) {
1005 ✗ av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
1006 ✗ return AVERROR_INVALIDDATA;
1007 }
1008
1009
4/4
✓ Branch 0 taken 2311 times.
✓ Branch 1 taken 17551 times.
✓ Branch 2 taken 1986 times.
✓ Branch 3 taken 325 times.
19862 if (pps->lists_modification_present_flag && nb_refs > 1) {
1010 1986 sh->rpl_modification_flag[0] = get_bits1(gb);
1011
2/2
✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 554 times.
1986 if (sh->rpl_modification_flag[0]) {
1012
2/2
✓ Branch 0 taken 3366 times.
✓ Branch 1 taken 1432 times.
4798 for (i = 0; i < sh->nb_refs[L0]; i++)
1013 3366 sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs));
1014 }
1015
1016
2/2
✓ Branch 0 taken 1803 times.
✓ Branch 1 taken 183 times.
1986 if (sh->slice_type == HEVC_SLICE_B) {
1017 1803 sh->rpl_modification_flag[1] = get_bits1(gb);
1018
2/2
✓ Branch 0 taken 655 times.
✓ Branch 1 taken 1148 times.
1803 if (sh->rpl_modification_flag[1] == 1)
1019
2/2
✓ Branch 0 taken 1558 times.
✓ Branch 1 taken 655 times.
2213 for (i = 0; i < sh->nb_refs[L1]; i++)
1020 1558 sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs));
1021 }
1022 }
1023
1024
2/2
✓ Branch 0 taken 15427 times.
✓ Branch 1 taken 4435 times.
19862 if (sh->slice_type == HEVC_SLICE_B)
1025 15427 sh->mvd_l1_zero_flag = get_bits1(gb);
1026
1027
2/2
✓ Branch 0 taken 16800 times.
✓ Branch 1 taken 3062 times.
19862 if (pps->cabac_init_present_flag)
1028 16800 sh->cabac_init_flag = get_bits1(gb);
1029 else
1030 3062 sh->cabac_init_flag = 0;
1031
1032 19862 sh->collocated_ref_idx = 0;
1033
2/2
✓ Branch 0 taken 17255 times.
✓ Branch 1 taken 2607 times.
19862 if (sh->slice_temporal_mvp_enabled_flag) {
1034 17255 sh->collocated_list = L0;
1035
2/2
✓ Branch 0 taken 14870 times.
✓ Branch 1 taken 2385 times.
17255 if (sh->slice_type == HEVC_SLICE_B)
1036 14870 sh->collocated_list = !get_bits1(gb);
1037
1038
2/2
✓ Branch 0 taken 15172 times.
✓ Branch 1 taken 2083 times.
17255 if (sh->nb_refs[sh->collocated_list] > 1) {
1039 15172 sh->collocated_ref_idx = get_ue_golomb_long(gb);
1040
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15172 times.
15172 if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) {
1041 ✗ av_log(s->avctx, AV_LOG_ERROR,
1042 "Invalid collocated_ref_idx: %d.\n",
1043 sh->collocated_ref_idx);
1044 ✗ return AVERROR_INVALIDDATA;
1045 }
1046 }
1047 }
1048
1049
4/4
✓ Branch 0 taken 1559 times.
✓ Branch 1 taken 18303 times.
✓ Branch 2 taken 754 times.
✓ Branch 3 taken 805 times.
19862 if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
1050
3/4
✓ Branch 0 taken 696 times.
✓ Branch 1 taken 18361 times.
✓ Branch 2 taken 696 times.
✗ Branch 3 not taken.
19057 (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
1051 1501 ret = pred_weight_table(sh, s->avctx, sps, gb);
1052
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1501 times.
1501 if (ret < 0)
1053 ✗ return ret;
1054 }
1055
1056 19862 sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
1057
2/4
✓ Branch 0 taken 19862 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19862 times.
19862 if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
1058 ✗ av_log(s->avctx, AV_LOG_ERROR,
1059 "Invalid number of merging MVP candidates: %d.\n",
1060 ✗ sh->max_num_merge_cand);
1061 ✗ return AVERROR_INVALIDDATA;
1062 }
1063
1064 // Syntax in 7.3.6.1
1065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19862 times.
19862 if (sps->motion_vector_resolution_control_idc == 2)
1066 ✗ sh->use_integer_mv_flag = get_bits1(gb);
1067 else
1068 // Inferred to be equal to motion_vector_resolution_control_idc if not present
1069 19862 sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc;
1070
1071 }
1072
1073 20875 sh->slice_qp_delta = get_se_golomb(gb);
1074
1075
2/2
✓ Branch 0 taken 260 times.
✓ Branch 1 taken 20615 times.
20875 if (pps->pic_slice_level_chroma_qp_offsets_present_flag) {
1076 260 sh->slice_cb_qp_offset = get_se_golomb(gb);
1077 260 sh->slice_cr_qp_offset = get_se_golomb(gb);
1078
2/4
✓ Branch 0 taken 260 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 260 times.
✗ Branch 3 not taken.
260 if (sh->slice_cb_qp_offset < -12 || sh->slice_cb_qp_offset > 12 ||
1079
2/4
✓ Branch 0 taken 260 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 260 times.
260 sh->slice_cr_qp_offset < -12 || sh->slice_cr_qp_offset > 12) {
1080 ✗ av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n");
1081 ✗ return AVERROR_INVALIDDATA;
1082 }
1083 } else {
1084 20615 sh->slice_cb_qp_offset = 0;
1085 20615 sh->slice_cr_qp_offset = 0;
1086 }
1087
1088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20875 times.
20875 if (pps->pps_slice_act_qp_offsets_present_flag) {
1089 ✗ sh->slice_act_y_qp_offset = get_se_golomb(gb);
1090 ✗ sh->slice_act_cb_qp_offset = get_se_golomb(gb);
1091 ✗ sh->slice_act_cr_qp_offset = get_se_golomb(gb);
1092 }
1093
1094
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 20834 times.
20875 if (pps->chroma_qp_offset_list_enabled_flag)
1095 41 sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
1096 else
1097 20834 sh->cu_chroma_qp_offset_enabled_flag = 0;
1098
1099
2/2
✓ Branch 0 taken 3512 times.
✓ Branch 1 taken 17363 times.
20875 if (pps->deblocking_filter_control_present_flag) {
1100 3512 int deblocking_filter_override_flag = 0;
1101
1102
2/2
✓ Branch 0 taken 1097 times.
✓ Branch 1 taken 2415 times.
3512 if (pps->deblocking_filter_override_enabled_flag)
1103 1097 deblocking_filter_override_flag = get_bits1(gb);
1104
1105
2/2
✓ Branch 0 taken 506 times.
✓ Branch 1 taken 3006 times.
3512 if (deblocking_filter_override_flag) {
1106 506 sh->disable_deblocking_filter_flag = get_bits1(gb);
1107
2/2
✓ Branch 0 taken 349 times.
✓ Branch 1 taken 157 times.
506 if (!sh->disable_deblocking_filter_flag) {
1108 349 int beta_offset_div2 = get_se_golomb(gb);
1109 349 int tc_offset_div2 = get_se_golomb(gb) ;
1110
3/6
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
349 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
1111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 349 times.
349 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1112 ✗ av_log(s->avctx, AV_LOG_ERROR,
1113 "Invalid deblock filter offsets: %d, %d\n",
1114 beta_offset_div2, tc_offset_div2);
1115 ✗ return AVERROR_INVALIDDATA;
1116 }
1117 349 sh->beta_offset = beta_offset_div2 * 2;
1118 349 sh->tc_offset = tc_offset_div2 * 2;
1119 }
1120 } else {
1121 3006 sh->disable_deblocking_filter_flag = pps->disable_dbf;
1122 3006 sh->beta_offset = pps->beta_offset;
1123 3006 sh->tc_offset = pps->tc_offset;
1124 }
1125 } else {
1126 17363 sh->disable_deblocking_filter_flag = 0;
1127 17363 sh->beta_offset = 0;
1128 17363 sh->tc_offset = 0;
1129 }
1130
1131
2/2
✓ Branch 0 taken 18268 times.
✓ Branch 1 taken 2607 times.
20875 if (pps->seq_loop_filter_across_slices_enabled_flag &&
1132
2/2
✓ Branch 0 taken 11868 times.
✓ Branch 1 taken 6400 times.
18268 (sh->slice_sample_adaptive_offset_flag[0] ||
1133
2/2
✓ Branch 0 taken 11851 times.
✓ Branch 1 taken 17 times.
11868 sh->slice_sample_adaptive_offset_flag[1] ||
1134
2/2
✓ Branch 0 taken 11751 times.
✓ Branch 1 taken 100 times.
11851 !sh->disable_deblocking_filter_flag)) {
1135 18168 sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb);
1136 } else {
1137 2707 sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag;
1138 }
1139 }
1140
1141 28669 sh->num_entry_point_offsets = 0;
1142
4/4
✓ Branch 0 taken 25411 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 4834 times.
✓ Branch 3 taken 20577 times.
28669 if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1143 8092 unsigned num_entry_point_offsets = get_ue_golomb_long(gb);
1144 // It would be possible to bound this tighter but this here is simpler
1145
2/4
✓ Branch 1 taken 8092 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8092 times.
8092 if (num_entry_point_offsets > get_bits_left(gb) || num_entry_point_offsets > UINT16_MAX) {
1146 ✗ av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
1147 ✗ return AVERROR_INVALIDDATA;
1148 }
1149
1150 8092 sh->num_entry_point_offsets = num_entry_point_offsets;
1151
2/2
✓ Branch 0 taken 2341 times.
✓ Branch 1 taken 5751 times.
8092 if (sh->num_entry_point_offsets > 0) {
1152 2341 int offset_len = get_ue_golomb_long(gb) + 1;
1153
1154
2/4
✓ Branch 0 taken 2341 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2341 times.
2341 if (offset_len < 1 || offset_len > 32) {
1155 ✗ sh->num_entry_point_offsets = 0;
1156 ✗ av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len);
1157 ✗ return AVERROR_INVALIDDATA;
1158 }
1159
1160 2341 av_freep(&sh->entry_point_offset);
1161 2341 av_freep(&sh->offset);
1162 2341 av_freep(&sh->size);
1163 2341 sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
1164 2341 sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1165 2341 sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1166
3/6
✓ Branch 0 taken 2341 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2341 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2341 times.
2341 if (!sh->entry_point_offset || !sh->offset || !sh->size) {
1167 ✗ sh->num_entry_point_offsets = 0;
1168 ✗ av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
1169 ✗ return AVERROR(ENOMEM);
1170 }
1171
2/2
✓ Branch 0 taken 12499 times.
✓ Branch 1 taken 2341 times.
14840 for (i = 0; i < sh->num_entry_point_offsets; i++) {
1172 12499 unsigned val = get_bits_long(gb, offset_len);
1173 12499 sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
1174 }
1175 }
1176 }
1177
1178
2/2
✓ Branch 0 taken 2749 times.
✓ Branch 1 taken 25920 times.
28669 if (pps->slice_header_extension_present_flag) {
1179 2749 unsigned int length = get_ue_golomb_long(gb);
1180
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2749 times.
2749 if (length*8LL > get_bits_left(gb)) {
1181 ✗ av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n");
1182 ✗ return AVERROR_INVALIDDATA;
1183 }
1184
2/2
✓ Branch 0 taken 19903 times.
✓ Branch 1 taken 2749 times.
22652 for (i = 0; i < length; i++)
1185 19903 skip_bits(gb, 8); // slice_header_extension_data_byte
1186 }
1187
1188 28669 ret = get_bits1(gb);
1189
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28669 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
28669 if (!ret && get_bits_left(gb) >= 0) {
1190 ✗ av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n");
1191 ✗ return AVERROR_INVALIDDATA;
1192 }
1193 28669 sh->data_offset = align_get_bits(gb) - gb->buffer;
1194
1195
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28669 times.
28669 if (get_bits_left(gb) < 0) {
1196 ✗ av_log(s->avctx, AV_LOG_ERROR,
1197 ✗ "Overread slice header by %d bits\n", -get_bits_left(gb));
1198 ✗ return AVERROR_INVALIDDATA;
1199 }
1200
1201 // Inferred parameters
1202 28669 sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta;
1203
1/2
✓ Branch 0 taken 28669 times.
✗ Branch 1 not taken.
28669 if (sh->slice_qp > 51 ||
1204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28669 times.
28669 sh->slice_qp < -sps->qp_bd_offset) {
1205 ✗ av_log(s->avctx, AV_LOG_ERROR,
1206 "The slice_qp %d is outside the valid range "
1207 "[%d, 51].\n",
1208 ✗ sh->slice_qp,
1209 ✗ -sps->qp_bd_offset);
1210 ✗ return AVERROR_INVALIDDATA;
1211 }
1212
1213 28669 sh->slice_ctb_addr_rs = sh->slice_segment_addr;
1214
1215
2/2
✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 20875 times.
28669 if (sh->dependent_slice_segment_flag &&
1216
2/4
✓ Branch 0 taken 7794 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7794 times.
7794 (!sh->slice_ctb_addr_rs || !pps->ctb_addr_rs_to_ts[sh->slice_ctb_addr_rs])) {
1217 ✗ av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
1218 ✗ return AVERROR_INVALIDDATA;
1219 }
1220
1221 28669 return 0;
1222 }
1223
1224 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
1225
1226 #define SET_SAO(elem, value) \
1227 do { \
1228 if (!sao_merge_up_flag && !sao_merge_left_flag) \
1229 sao->elem = value; \
1230 else if (sao_merge_left_flag) \
1231 sao->elem = CTB(l->sao, rx-1, ry).elem; \
1232 else if (sao_merge_up_flag) \
1233 sao->elem = CTB(l->sao, rx, ry-1).elem; \
1234 else \
1235 sao->elem = 0; \
1236 } while (0)
1237
1238 1993962 static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l,
1239 const HEVCPPS *pps, const HEVCSPS *sps,
1240 int rx, int ry)
1241 {
1242 1993962 const HEVCContext *const s = lc->parent;
1243 1993962 int sao_merge_left_flag = 0;
1244 1993962 int sao_merge_up_flag = 0;
1245 1993962 SAOParams *sao = &CTB(l->sao, rx, ry);
1246 int c_idx, i;
1247
1248
2/2
✓ Branch 0 taken 913244 times.
✓ Branch 1 taken 1080718 times.
1993962 if (s->sh.slice_sample_adaptive_offset_flag[0] ||
1249
2/2
✓ Branch 0 taken 1540 times.
✓ Branch 1 taken 911704 times.
913244 s->sh.slice_sample_adaptive_offset_flag[1]) {
1250
2/2
✓ Branch 0 taken 1040486 times.
✓ Branch 1 taken 41772 times.
1082258 if (rx > 0) {
1251
2/2
✓ Branch 0 taken 1021467 times.
✓ Branch 1 taken 19019 times.
1040486 if (lc->ctb_left_flag)
1252 1021467 sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc);
1253 }
1254
4/4
✓ Branch 0 taken 1016395 times.
✓ Branch 1 taken 65863 times.
✓ Branch 2 taken 421770 times.
✓ Branch 3 taken 594625 times.
1082258 if (ry > 0 && !sao_merge_left_flag) {
1255
2/2
✓ Branch 0 taken 408763 times.
✓ Branch 1 taken 13007 times.
421770 if (lc->ctb_up_flag)
1256 408763 sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc);
1257 }
1258 }
1259
1260
4/4
✓ Branch 0 taken 7975736 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 5981830 times.
✓ Branch 3 taken 1993962 times.
7975792 for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) {
1261
2/2
✓ Branch 0 taken 1993962 times.
✓ Branch 1 taken 3987868 times.
5981830 int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma :
1262 3987868 pps->log2_sao_offset_scale_chroma;
1263
1264
2/2
✓ Branch 0 taken 3285548 times.
✓ Branch 1 taken 2696282 times.
5981830 if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1265 3285548 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
1266 3285548 continue;
1267 }
1268
1269
2/2
✓ Branch 0 taken 807782 times.
✓ Branch 1 taken 1888500 times.
2696282 if (c_idx == 2) {
1270 807782 sao->type_idx[2] = sao->type_idx[1];
1271 807782 sao->eo_class[2] = sao->eo_class[1];
1272 } else {
1273
7/8
✓ Branch 0 taken 1649055 times.
✓ Branch 1 taken 239445 times.
✓ Branch 2 taken 561217 times.
✓ Branch 3 taken 1087838 times.
✓ Branch 5 taken 1087838 times.
✓ Branch 6 taken 239445 times.
✓ Branch 7 taken 239445 times.
✗ Branch 8 not taken.
1888500 SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc));
1274 }
1275
1276
2/2
✓ Branch 0 taken 2009642 times.
✓ Branch 1 taken 686640 times.
2696282 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
1277 2009642 continue;
1278
1279
2/2
✓ Branch 0 taken 2746560 times.
✓ Branch 1 taken 686640 times.
3433200 for (i = 0; i < 4; i++)
1280
7/8
✓ Branch 0 taken 2251500 times.
✓ Branch 1 taken 495060 times.
✓ Branch 2 taken 875640 times.
✓ Branch 3 taken 1375860 times.
✓ Branch 5 taken 1375860 times.
✓ Branch 6 taken 495060 times.
✓ Branch 7 taken 495060 times.
✗ Branch 8 not taken.
2746560 SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth));
1281
1282
2/2
✓ Branch 0 taken 108424 times.
✓ Branch 1 taken 578216 times.
686640 if (sao->type_idx[c_idx] == SAO_BAND) {
1283
2/2
✓ Branch 0 taken 433696 times.
✓ Branch 1 taken 108424 times.
542120 for (i = 0; i < 4; i++) {
1284
2/2
✓ Branch 0 taken 323582 times.
✓ Branch 1 taken 110114 times.
433696 if (sao->offset_abs[c_idx][i]) {
1285
7/8
✓ Branch 0 taken 300849 times.
✓ Branch 1 taken 22733 times.
✓ Branch 2 taken 223920 times.
✓ Branch 3 taken 76929 times.
✓ Branch 5 taken 76929 times.
✓ Branch 6 taken 22733 times.
✓ Branch 7 taken 22733 times.
✗ Branch 8 not taken.
323582 SET_SAO(offset_sign[c_idx][i],
1286 ff_hevc_sao_offset_sign_decode(lc));
1287 } else {
1288 110114 sao->offset_sign[c_idx][i] = 0;
1289 }
1290 }
1291
7/8
✓ Branch 0 taken 99262 times.
✓ Branch 1 taken 9162 times.
✓ Branch 2 taken 72036 times.
✓ Branch 3 taken 27226 times.
✓ Branch 5 taken 27226 times.
✓ Branch 6 taken 9162 times.
✓ Branch 7 taken 9162 times.
✗ Branch 8 not taken.
108424 SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc));
1292
2/2
✓ Branch 0 taken 506073 times.
✓ Branch 1 taken 72143 times.
578216 } else if (c_idx != 2) {
1293
7/8
✓ Branch 0 taken 405950 times.
✓ Branch 1 taken 100123 times.
✓ Branch 2 taken 119922 times.
✓ Branch 3 taken 286028 times.
✓ Branch 5 taken 286028 times.
✓ Branch 6 taken 100123 times.
✓ Branch 7 taken 100123 times.
✗ Branch 8 not taken.
506073 SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc));
1294 }
1295
1296 // Inferred parameters
1297 686640 sao->offset_val[c_idx][0] = 0;
1298
2/2
✓ Branch 0 taken 2746560 times.
✓ Branch 1 taken 686640 times.
3433200 for (i = 0; i < 4; i++) {
1299 2746560 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
1300
2/2
✓ Branch 0 taken 2312864 times.
✓ Branch 1 taken 433696 times.
2746560 if (sao->type_idx[c_idx] == SAO_EDGE) {
1301
2/2
✓ Branch 0 taken 1156432 times.
✓ Branch 1 taken 1156432 times.
2312864 if (i > 1)
1302 1156432 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1303
2/2
✓ Branch 0 taken 144543 times.
✓ Branch 1 taken 289153 times.
433696 } else if (sao->offset_sign[c_idx][i]) {
1304 144543 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1305 }
1306 2746560 sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale;
1307 }
1308 }
1309 1993962 }
1310
1311 #undef SET_SAO
1312 #undef CTB
1313
1314 251428 static int hls_cross_component_pred(HEVCLocalContext *lc, int idx)
1315 {
1316 251428 int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx);
1317
1318
2/2
✓ Branch 0 taken 142161 times.
✓ Branch 1 taken 109267 times.
251428 if (log2_res_scale_abs_plus1 != 0) {
1319 142161 int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx);
1320 142161 lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) *
1321 142161 (1 - 2 * res_scale_sign_flag);
1322 } else {
1323 109267 lc->tu.res_scale_val = 0;
1324 }
1325
1326
1327 251428 return 0;
1328 }
1329
1330 15620723 static int hls_transform_unit(HEVCLocalContext *lc,
1331 const HEVCLayerContext *l,
1332 const HEVCPPS *pps, const HEVCSPS *sps,
1333 int x0, int y0,
1334 int xBase, int yBase, int cb_xBase, int cb_yBase,
1335 int log2_cb_size, int log2_trafo_size,
1336 int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
1337 {
1338 15620723 const HEVCContext *const s = lc->parent;
1339 15620723 const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1];
1340 int i;
1341
1342
2/2
✓ Branch 0 taken 8787187 times.
✓ Branch 1 taken 6833536 times.
15620723 if (lc->cu.pred_mode == MODE_INTRA) {
1343 8787187 int trafo_size = 1 << log2_trafo_size;
1344 8787187 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size);
1345
1346 8787187 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0);
1347 }
1348
1349
6/6
✓ Branch 0 taken 5743586 times.
✓ Branch 1 taken 9877137 times.
✓ Branch 2 taken 5096236 times.
✓ Branch 3 taken 647350 times.
✓ Branch 4 taken 4662290 times.
✓ Branch 5 taken 433946 times.
15620723 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1350
6/6
✓ Branch 0 taken 140838 times.
✓ Branch 1 taken 4521452 times.
✓ Branch 2 taken 133247 times.
✓ Branch 3 taken 7591 times.
✓ Branch 4 taken 51975 times.
✓ Branch 5 taken 81272 times.
15680288 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1351 11017999 int scan_idx = SCAN_DIAG;
1352 11017999 int scan_idx_c = SCAN_DIAG;
1353
4/4
✓ Branch 0 taken 7732736 times.
✓ Branch 1 taken 3285263 times.
✓ Branch 2 taken 6273473 times.
✓ Branch 3 taken 1459263 times.
17291472 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1354
2/2
✓ Branch 0 taken 196699 times.
✓ Branch 1 taken 6076774 times.
6273473 (sps->chroma_format_idc == 2 &&
1355
4/4
✓ Branch 0 taken 170962 times.
✓ Branch 1 taken 25737 times.
✓ Branch 2 taken 97068 times.
✓ Branch 3 taken 73894 times.
196699 (cbf_cb[1] || cbf_cr[1]));
1356
1357
4/4
✓ Branch 0 taken 2714358 times.
✓ Branch 1 taken 8303641 times.
✓ Branch 2 taken 920252 times.
✓ Branch 3 taken 1794106 times.
11017999 if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
1358 920252 lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc);
1359
2/2
✓ Branch 0 taken 485048 times.
✓ Branch 1 taken 435204 times.
920252 if (lc->tu.cu_qp_delta != 0)
1360
2/2
✓ Branch 1 taken 262087 times.
✓ Branch 2 taken 222961 times.
485048 if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1)
1361 262087 lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1362 920252 lc->tu.is_cu_qp_delta_coded = 1;
1363
1364
2/2
✓ Branch 0 taken 920251 times.
✓ Branch 1 taken 1 times.
920252 if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) ||
1365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 920251 times.
920251 lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) {
1366 1 av_log(s->avctx, AV_LOG_ERROR,
1367 "The cu_qp_delta %d is outside the valid range "
1368 "[%d, %d].\n",
1369 lc->tu.cu_qp_delta,
1370 1 -(26 + sps->qp_bd_offset / 2),
1371 1 (25 + sps->qp_bd_offset / 2));
1372 1 return AVERROR_INVALIDDATA;
1373 }
1374
1375 920251 ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size);
1376 }
1377
1378
4/4
✓ Branch 0 taken 779607 times.
✓ Branch 1 taken 10238391 times.
✓ Branch 2 taken 730220 times.
✓ Branch 3 taken 49387 times.
11017998 if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1379
3/4
✓ Branch 0 taken 730220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 228078 times.
✓ Branch 3 taken 502142 times.
730220 !lc->cu.cu_transquant_bypass_flag && !lc->tu.is_cu_chroma_qp_offset_coded) {
1380 228078 int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc);
1381
2/2
✓ Branch 0 taken 35811 times.
✓ Branch 1 taken 192267 times.
228078 if (cu_chroma_qp_offset_flag) {
1382 35811 int cu_chroma_qp_offset_idx = 0;
1383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35811 times.
35811 if (pps->chroma_qp_offset_list_len_minus1 > 0) {
1384 ✗ cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1);
1385 ✗ av_log(s->avctx, AV_LOG_ERROR,
1386 "cu_chroma_qp_offset_idx not yet tested.\n");
1387 }
1388 35811 lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
1389 35811 lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
1390 } else {
1391 192267 lc->tu.cu_qp_offset_cb = 0;
1392 192267 lc->tu.cu_qp_offset_cr = 0;
1393 }
1394 228078 lc->tu.is_cu_chroma_qp_offset_coded = 1;
1395 }
1396
1397
4/4
✓ Branch 0 taken 6374631 times.
✓ Branch 1 taken 4643367 times.
✓ Branch 2 taken 5522579 times.
✓ Branch 3 taken 852052 times.
11017998 if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1398
2/2
✓ Branch 0 taken 3669420 times.
✓ Branch 1 taken 1853159 times.
5522579 if (lc->tu.intra_pred_mode >= 6 &&
1399
2/2
✓ Branch 0 taken 1275324 times.
✓ Branch 1 taken 2394096 times.
3669420 lc->tu.intra_pred_mode <= 14) {
1400 1275324 scan_idx = SCAN_VERT;
1401
2/2
✓ Branch 0 taken 1854401 times.
✓ Branch 1 taken 2392854 times.
4247255 } else if (lc->tu.intra_pred_mode >= 22 &&
1402
2/2
✓ Branch 0 taken 1565685 times.
✓ Branch 1 taken 288716 times.
1854401 lc->tu.intra_pred_mode <= 30) {
1403 1565685 scan_idx = SCAN_HORIZ;
1404 }
1405
1406
2/2
✓ Branch 0 taken 3325836 times.
✓ Branch 1 taken 2196743 times.
5522579 if (lc->tu.intra_pred_mode_c >= 6 &&
1407
2/2
✓ Branch 0 taken 1224263 times.
✓ Branch 1 taken 2101573 times.
3325836 lc->tu.intra_pred_mode_c <= 14) {
1408 1224263 scan_idx_c = SCAN_VERT;
1409
2/2
✓ Branch 0 taken 1765017 times.
✓ Branch 1 taken 2533299 times.
4298316 } else if (lc->tu.intra_pred_mode_c >= 22 &&
1410
2/2
✓ Branch 0 taken 1484116 times.
✓ Branch 1 taken 280901 times.
1765017 lc->tu.intra_pred_mode_c <= 30) {
1411 1484116 scan_idx_c = SCAN_HORIZ;
1412 }
1413 }
1414
1415 11017998 lc->tu.cross_pf = 0;
1416
1417
2/2
✓ Branch 0 taken 9877136 times.
✓ Branch 1 taken 1140862 times.
11017998 if (cbf_luma)
1418 9877136 ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0);
1419
6/6
✓ Branch 0 taken 11017484 times.
✓ Branch 1 taken 514 times.
✓ Branch 2 taken 5617996 times.
✓ Branch 3 taken 5399488 times.
✓ Branch 4 taken 149809 times.
✓ Branch 5 taken 5468187 times.
16567295 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1420 5549297 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1421 5549297 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1422
4/4
✓ Branch 0 taken 246342 times.
✓ Branch 1 taken 5302955 times.
✓ Branch 2 taken 140024 times.
✓ Branch 3 taken 106318 times.
5689321 lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma &&
1423
2/2
✓ Branch 0 taken 91081 times.
✓ Branch 1 taken 48943 times.
140024 (lc->cu.pred_mode == MODE_INTER ||
1424
2/2
✓ Branch 0 taken 76771 times.
✓ Branch 1 taken 14310 times.
91081 (lc->tu.chroma_mode_c == 4)));
1425
1426
2/2
✓ Branch 0 taken 125714 times.
✓ Branch 1 taken 5423583 times.
5549297 if (lc->tu.cross_pf) {
1427 125714 hls_cross_component_pred(lc, 0);
1428 }
1429
4/4
✓ Branch 0 taken 1078236 times.
✓ Branch 1 taken 10379770 times.
✓ Branch 2 taken 5908709 times.
✓ Branch 3 taken 5549297 times.
11458006 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1430
2/2
✓ Branch 0 taken 2644910 times.
✓ Branch 1 taken 3263799 times.
5908709 if (lc->cu.pred_mode == MODE_INTRA) {
1431 2644910 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1432 2644910 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1433 2644910 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1);
1434 }
1435
2/2
✓ Branch 0 taken 1451201 times.
✓ Branch 1 taken 4457508 times.
5908709 if (cbf_cb[i])
1436 1451201 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1437 log2_trafo_size_c, scan_idx_c, 1);
1438 else
1439
2/2
✓ Branch 0 taken 27018 times.
✓ Branch 1 taken 4430490 times.
4457508 if (lc->tu.cross_pf) {
1440 27018 ptrdiff_t stride = s->cur_frame->f->linesize[1];
1441 27018 int hshift = sps->hshift[1];
1442 27018 int vshift = sps->vshift[1];
1443 27018 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1444 27018 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1445 27018 int size = 1 << log2_trafo_size_c;
1446
1447 27018 uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride +
1448 27018 ((x0 >> hshift) << sps->pixel_shift)];
1449
2/2
✓ Branch 0 taken 1473408 times.
✓ Branch 1 taken 27018 times.
1500426 for (i = 0; i < (size * size); i++) {
1450 1473408 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1451 }
1452 27018 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1453 }
1454 }
1455
1456
2/2
✓ Branch 0 taken 125714 times.
✓ Branch 1 taken 5423583 times.
5549297 if (lc->tu.cross_pf) {
1457 125714 hls_cross_component_pred(lc, 1);
1458 }
1459
4/4
✓ Branch 0 taken 1078236 times.
✓ Branch 1 taken 10379770 times.
✓ Branch 2 taken 5908709 times.
✓ Branch 3 taken 5549297 times.
11458006 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1460
2/2
✓ Branch 0 taken 2644910 times.
✓ Branch 1 taken 3263799 times.
5908709 if (lc->cu.pred_mode == MODE_INTRA) {
1461 2644910 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1462 2644910 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1463 2644910 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2);
1464 }
1465
2/2
✓ Branch 0 taken 1521492 times.
✓ Branch 1 taken 4387217 times.
5908709 if (cbf_cr[i])
1466 1521492 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1467 log2_trafo_size_c, scan_idx_c, 2);
1468 else
1469
2/2
✓ Branch 0 taken 52981 times.
✓ Branch 1 taken 4334236 times.
4387217 if (lc->tu.cross_pf) {
1470 52981 ptrdiff_t stride = s->cur_frame->f->linesize[2];
1471 52981 int hshift = sps->hshift[2];
1472 52981 int vshift = sps->vshift[2];
1473 52981 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1474 52981 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1475 52981 int size = 1 << log2_trafo_size_c;
1476
1477 52981 uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride +
1478 52981 ((x0 >> hshift) << sps->pixel_shift)];
1479
2/2
✓ Branch 0 taken 2927920 times.
✓ Branch 1 taken 52981 times.
2980901 for (i = 0; i < (size * size); i++) {
1480 2927920 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1481 }
1482 52981 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1483 }
1484 }
1485
4/4
✓ Branch 0 taken 5468187 times.
✓ Branch 1 taken 514 times.
✓ Branch 2 taken 1405734 times.
✓ Branch 3 taken 4062453 times.
5468701 } else if (sps->chroma_format_idc && blk_idx == 3) {
1486 1405734 int trafo_size_h = 1 << (log2_trafo_size + 1);
1487 1405734 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1488
4/4
✓ Branch 0 taken 412647 times.
✓ Branch 1 taken 2536370 times.
✓ Branch 2 taken 1543283 times.
✓ Branch 3 taken 1405734 times.
2949017 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1489
2/2
✓ Branch 0 taken 1040057 times.
✓ Branch 1 taken 503226 times.
1543283 if (lc->cu.pred_mode == MODE_INTRA) {
1490 1040057 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1491 1040057 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1492 1040057 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1);
1493 }
1494
2/2
✓ Branch 0 taken 537411 times.
✓ Branch 1 taken 1005872 times.
1543283 if (cbf_cb[i])
1495 537411 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1496 log2_trafo_size, scan_idx_c, 1);
1497 }
1498
4/4
✓ Branch 0 taken 412647 times.
✓ Branch 1 taken 2536370 times.
✓ Branch 2 taken 1543283 times.
✓ Branch 3 taken 1405734 times.
2949017 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1499
2/2
✓ Branch 0 taken 1040057 times.
✓ Branch 1 taken 503226 times.
1543283 if (lc->cu.pred_mode == MODE_INTRA) {
1500 1040057 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1501 1040057 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1502 1040057 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2);
1503 }
1504
2/2
✓ Branch 0 taken 625006 times.
✓ Branch 1 taken 918277 times.
1543283 if (cbf_cr[i])
1505 625006 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1506 log2_trafo_size, scan_idx_c, 2);
1507 }
1508 }
1509
4/4
✓ Branch 0 taken 4602691 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 2412522 times.
✓ Branch 3 taken 2190169 times.
4602724 } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
1510
4/4
✓ Branch 0 taken 1458459 times.
✓ Branch 1 taken 954063 times.
✓ Branch 2 taken 46806 times.
✓ Branch 3 taken 1411653 times.
3413391 if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) {
1511 1000869 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1512 1000869 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1513 1000869 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
1514 1000869 sps->log2_ctb_size);
1515 1000869 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1);
1516 1000869 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2);
1517
2/2
✓ Branch 0 taken 7467 times.
✓ Branch 1 taken 993402 times.
1000869 if (sps->chroma_format_idc == 2) {
1518 7467 ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c),
1519 7467 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1520 7467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1);
1521 7467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2);
1522 }
1523
2/2
✓ Branch 0 taken 319986 times.
✓ Branch 1 taken 1091667 times.
1411653 } else if (blk_idx == 3) {
1524 319986 int trafo_size_h = 1 << (log2_trafo_size + 1);
1525 319986 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1526 319986 ff_hevc_set_neighbour_available(lc, xBase, yBase,
1527 319986 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1528 319986 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1);
1529 319986 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2);
1530
2/2
✓ Branch 0 taken 2373 times.
✓ Branch 1 taken 317613 times.
319986 if (sps->chroma_format_idc == 2) {
1531 2373 ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size),
1532 2373 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1533 2373 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1);
1534 2373 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2);
1535 }
1536 }
1537 }
1538
1539 15620722 return 0;
1540 }
1541
1542 341674 static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps,
1543 int x0, int y0, int log2_cb_size)
1544 {
1545 341674 int cb_size = 1 << log2_cb_size;
1546 341674 int log2_min_pu_size = sps->log2_min_pu_size;
1547
1548 341674 int min_pu_width = sps->min_pu_width;
1549 341674 int x_end = FFMIN(x0 + cb_size, sps->width);
1550 341674 int y_end = FFMIN(y0 + cb_size, sps->height);
1551 int i, j;
1552
1553
2/2
✓ Branch 0 taken 487722 times.
✓ Branch 1 taken 341674 times.
829396 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1554
2/2
✓ Branch 0 taken 968596 times.
✓ Branch 1 taken 487722 times.
1456318 for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
1555 968596 is_pcm[i + j * min_pu_width] = 2;
1556 341674 }
1557
1558 18752828 static int hls_transform_tree(HEVCLocalContext *lc,
1559 const HEVCLayerContext *l,
1560 const HEVCPPS *pps, const HEVCSPS *sps,
1561 int x0, int y0,
1562 int xBase, int yBase, int cb_xBase, int cb_yBase,
1563 int log2_cb_size, int log2_trafo_size,
1564 int trafo_depth, int blk_idx,
1565 const int *base_cbf_cb, const int *base_cbf_cr)
1566 {
1567 18752828 const HEVCContext *const s = lc->parent;
1568 uint8_t split_transform_flag;
1569 int cbf_cb[2];
1570 int cbf_cr[2];
1571 int ret;
1572
1573 18752828 cbf_cb[0] = base_cbf_cb[0];
1574 18752828 cbf_cb[1] = base_cbf_cb[1];
1575 18752828 cbf_cr[0] = base_cbf_cr[0];
1576 18752828 cbf_cr[1] = base_cbf_cr[1];
1577
1578
2/2
✓ Branch 0 taken 5601706 times.
✓ Branch 1 taken 13151122 times.
18752828 if (lc->cu.intra_split_flag) {
1579
2/2
✓ Branch 0 taken 4199400 times.
✓ Branch 1 taken 1402306 times.
5601706 if (trafo_depth == 1) {
1580 4199400 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1581
2/2
✓ Branch 0 taken 75392 times.
✓ Branch 1 taken 4124008 times.
4199400 if (sps->chroma_format_idc == 3) {
1582 75392 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx];
1583 75392 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx];
1584 } else {
1585 4124008 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1586 4124008 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1587 }
1588 }
1589 } else {
1590 13151122 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0];
1591 13151122 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1592 13151122 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1593 }
1594
1595
2/2
✓ Branch 0 taken 18633656 times.
✓ Branch 1 taken 119172 times.
18752828 if (log2_trafo_size <= sps->log2_max_trafo_size &&
1596
2/2
✓ Branch 0 taken 10485584 times.
✓ Branch 1 taken 8148072 times.
18633656 log2_trafo_size > sps->log2_min_tb_size &&
1597
2/2
✓ Branch 0 taken 7973979 times.
✓ Branch 1 taken 2511605 times.
10485584 trafo_depth < lc->cu.max_trafo_depth &&
1598
4/4
✓ Branch 0 taken 1514655 times.
✓ Branch 1 taken 6459324 times.
✓ Branch 2 taken 469616 times.
✓ Branch 3 taken 1045039 times.
7973979 !(lc->cu.intra_split_flag && trafo_depth == 0)) {
1599 6928940 split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size);
1600 } else {
1601 26000069 int inter_split = sps->max_transform_hierarchy_depth_inter == 0 &&
1602
2/2
✓ Branch 0 taken 1554001 times.
✓ Branch 1 taken 798292 times.
2352293 lc->cu.pred_mode == MODE_INTER &&
1603
6/6
✓ Branch 0 taken 2352293 times.
✓ Branch 1 taken 9471595 times.
✓ Branch 2 taken 930859 times.
✓ Branch 3 taken 623142 times.
✓ Branch 4 taken 184863 times.
✓ Branch 5 taken 745996 times.
14176181 lc->cu.part_mode != PART_2Nx2N &&
1604 trafo_depth == 0;
1605
1606 11823888 split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size ||
1607
8/8
✓ Branch 0 taken 11704716 times.
✓ Branch 1 taken 119172 times.
✓ Branch 2 taken 5126887 times.
✓ Branch 3 taken 6577829 times.
✓ Branch 4 taken 4081848 times.
✓ Branch 5 taken 1045039 times.
✓ Branch 6 taken 169700 times.
✓ Branch 7 taken 10489977 times.
11823888 (lc->cu.intra_split_flag && trafo_depth == 0) ||
1608 inter_split;
1609 }
1610
1611
6/6
✓ Branch 0 taken 18752189 times.
✓ Branch 1 taken 639 times.
✓ Branch 2 taken 8061236 times.
✓ Branch 3 taken 10690953 times.
✓ Branch 4 taken 240880 times.
✓ Branch 5 taken 7820356 times.
18752828 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1612
4/4
✓ Branch 0 taken 4707696 times.
✓ Branch 1 taken 6224137 times.
✓ Branch 2 taken 1174724 times.
✓ Branch 3 taken 3532972 times.
10931833 if (trafo_depth == 0 || cbf_cb[0]) {
1613 7398861 cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1614
6/6
✓ Branch 0 taken 458668 times.
✓ Branch 1 taken 6940193 times.
✓ Branch 2 taken 170236 times.
✓ Branch 3 taken 288432 times.
✓ Branch 4 taken 108956 times.
✓ Branch 5 taken 61280 times.
7398861 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1615 397388 cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1616 }
1617 }
1618
1619
4/4
✓ Branch 0 taken 4707696 times.
✓ Branch 1 taken 6224137 times.
✓ Branch 2 taken 1103740 times.
✓ Branch 3 taken 3603956 times.
10931833 if (trafo_depth == 0 || cbf_cr[0]) {
1620 7327877 cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1621
6/6
✓ Branch 0 taken 605644 times.
✓ Branch 1 taken 6722233 times.
✓ Branch 2 taken 217952 times.
✓ Branch 3 taken 387692 times.
✓ Branch 4 taken 144600 times.
✓ Branch 5 taken 73352 times.
7327877 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1622 532292 cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1623 }
1624 }
1625 }
1626
1627
2/2
✓ Branch 0 taken 3132105 times.
✓ Branch 1 taken 15620723 times.
18752828 if (split_transform_flag) {
1628 3132105 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1629 3132105 const int x1 = x0 + trafo_size_split;
1630 3132105 const int y1 = y0 + trafo_size_split;
1631
1632 #define SUBDIVIDE(x, y, idx) \
1633 do { \
1634 ret = hls_transform_tree(lc, l, pps, sps, \
1635 x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1636 log2_trafo_size - 1, trafo_depth + 1, idx, \
1637 cbf_cb, cbf_cr); \
1638 if (ret < 0) \
1639 return ret; \
1640 } while (0)
1641
1642
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3132105 times.
3132105 SUBDIVIDE(x0, y0, 0);
1643
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3132105 times.
3132105 SUBDIVIDE(x1, y0, 1);
1644
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3132105 times.
3132105 SUBDIVIDE(x0, y1, 2);
1645
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3132105 times.
3132105 SUBDIVIDE(x1, y1, 3);
1646
1647 #undef SUBDIVIDE
1648 } else {
1649 15620723 int min_tu_size = 1 << sps->log2_min_tb_size;
1650 15620723 int log2_min_tu_size = sps->log2_min_tb_size;
1651 15620723 int min_tu_width = sps->min_tb_width;
1652 15620723 int cbf_luma = 1;
1653
1654
4/4
✓ Branch 0 taken 6833536 times.
✓ Branch 1 taken 8787187 times.
✓ Branch 2 taken 1601800 times.
✓ Branch 3 taken 5231736 times.
15620723 if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1655
4/4
✓ Branch 0 taken 1268507 times.
✓ Branch 1 taken 333293 times.
✓ Branch 2 taken 1100833 times.
✓ Branch 3 taken 167674 times.
1601800 cbf_cb[0] || cbf_cr[0] ||
1656
6/6
✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 1076157 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
1100833 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1657 14532536 cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth);
1658 }
1659
1660 15620723 ret = hls_transform_unit(lc, l, pps, sps,
1661 x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1662 log2_cb_size, log2_trafo_size,
1663 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1664
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15620722 times.
15620723 if (ret < 0)
1665 1 return ret;
1666 // TODO: store cbf_luma somewhere else
1667
2/2
✓ Branch 0 taken 9877136 times.
✓ Branch 1 taken 5743586 times.
15620722 if (cbf_luma) {
1668 int i, j;
1669
2/2
✓ Branch 0 taken 22375064 times.
✓ Branch 1 taken 9877136 times.
32252200 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1670
2/2
✓ Branch 0 taken 88258802 times.
✓ Branch 1 taken 22375064 times.
110633866 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1671 88258802 int x_tu = (x0 + j) >> log2_min_tu_size;
1672 88258802 int y_tu = (y0 + i) >> log2_min_tu_size;
1673 88258802 l->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1674 }
1675 }
1676
2/2
✓ Branch 0 taken 15117158 times.
✓ Branch 1 taken 503564 times.
15620722 if (!s->sh.disable_deblocking_filter_flag) {
1677 15117158 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size);
1678
2/2
✓ Branch 0 taken 321201 times.
✓ Branch 1 taken 14795957 times.
15117158 if (pps->transquant_bypass_enable_flag &&
1679
2/2
✓ Branch 0 taken 261529 times.
✓ Branch 1 taken 59672 times.
321201 lc->cu.cu_transquant_bypass_flag)
1680 261529 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size);
1681 }
1682 }
1683 18752827 return 0;
1684 }
1685
1686 11207 static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l,
1687 const HEVCPPS *pps, int x0, int y0, int log2_cb_size)
1688 {
1689 11207 const HEVCContext *const s = lc->parent;
1690 11207 const HEVCSPS *const sps = pps->sps;
1691 GetBitContext gb;
1692 11207 int cb_size = 1 << log2_cb_size;
1693 11207 ptrdiff_t stride0 = s->cur_frame->f->linesize[0];
1694 11207 uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)];
1695
1696 22414 int length = cb_size * cb_size * sps->pcm.bit_depth + (sps->chroma_format_idc != 0 ?
1697 11207 (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) +
1698 11207 ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) *
1699
1/2
✓ Branch 0 taken 11207 times.
✗ Branch 1 not taken.
11207 sps->pcm.bit_depth_chroma : 0);
1700 11207 const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
1701 int ret;
1702
1703
2/2
✓ Branch 0 taken 6041 times.
✓ Branch 1 taken 5166 times.
11207 if (!s->sh.disable_deblocking_filter_flag)
1704 6041 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
1705
1706 11207 ret = init_get_bits(&gb, pcm, length);
1707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11207 times.
11207 if (ret < 0)
1708 ✗ return ret;
1709
1710 11207 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth);
1711
1/2
✓ Branch 0 taken 11207 times.
✗ Branch 1 not taken.
11207 if (sps->chroma_format_idc) {
1712 11207 ptrdiff_t stride1 = s->cur_frame->f->linesize[1];
1713 11207 ptrdiff_t stride2 = s->cur_frame->f->linesize[2];
1714 11207 uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)];
1715 11207 uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)];
1716
1717 11207 s->hevcdsp.put_pcm(dst1, stride1,
1718 11207 cb_size >> sps->hshift[1],
1719 11207 cb_size >> sps->vshift[1],
1720 11207 &gb, sps->pcm.bit_depth_chroma);
1721 11207 s->hevcdsp.put_pcm(dst2, stride2,
1722 11207 cb_size >> sps->hshift[2],
1723 11207 cb_size >> sps->vshift[2],
1724 11207 &gb, sps->pcm.bit_depth_chroma);
1725 }
1726
1727 11207 return 0;
1728 }
1729
1730 /**
1731 * 8.5.3.2.2.1 Luma sample unidirectional interpolation process
1732 *
1733 * @param s HEVC decoding context
1734 * @param dst target buffer for block data at block position
1735 * @param dststride stride of the dst buffer
1736 * @param ref reference picture buffer at origin (0, 0)
1737 * @param mv motion vector (relative to block position) to get pixel data from
1738 * @param x_off horizontal position of block from origin (0, 0)
1739 * @param y_off vertical position of block from origin (0, 0)
1740 * @param block_w width of block
1741 * @param block_h height of block
1742 * @param luma_weight weighting factor applied to the luma prediction
1743 * @param luma_offset additive offset applied to the luma prediction value
1744 */
1745
1746 6593619 static void luma_mc_uni(HEVCLocalContext *lc,
1747 const HEVCPPS *pps, const HEVCSPS *sps,
1748 uint8_t *dst, ptrdiff_t dststride,
1749 const AVFrame *ref, const Mv *mv, int x_off, int y_off,
1750 int block_w, int block_h, int luma_weight, int luma_offset)
1751 {
1752 6593619 const HEVCContext *const s = lc->parent;
1753 6593619 const uint8_t *src = ref->data[0];
1754 6593619 ptrdiff_t srcstride = ref->linesize[0];
1755 6593619 int pic_width = sps->width;
1756 6593619 int pic_height = sps->height;
1757 6593619 int mx = mv->x & 3;
1758 6593619 int my = mv->y & 3;
1759
4/4
✓ Branch 0 taken 3530684 times.
✓ Branch 1 taken 3062935 times.
✓ Branch 2 taken 3470096 times.
✓ Branch 3 taken 60588 times.
13126650 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1760
4/4
✓ Branch 0 taken 3062935 times.
✓ Branch 1 taken 3470096 times.
✓ Branch 2 taken 73276 times.
✓ Branch 3 taken 2989659 times.
6533031 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1761 6593619 int idx = hevc_pel_weight[block_w];
1762
1763 6593619 x_off += mv->x >> 2;
1764 6593619 y_off += mv->y >> 2;
1765 6593619 src += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1766
1767
4/4
✓ Branch 0 taken 6523554 times.
✓ Branch 1 taken 70065 times.
✓ Branch 2 taken 6399302 times.
✓ Branch 3 taken 124252 times.
6593619 if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
1768
2/2
✓ Branch 0 taken 6320486 times.
✓ Branch 1 taken 78816 times.
6399302 x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1769
2/2
✓ Branch 0 taken 6078959 times.
✓ Branch 1 taken 241527 times.
6320486 y_off >= pic_height - block_h - QPEL_EXTRA_AFTER ||
1770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6078959 times.
6078959 ref == s->cur_frame->f) {
1771 514660 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1772 514660 int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1773 514660 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1774
1775 514660 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
1776 edge_emu_stride, srcstride,
1777 block_w + QPEL_EXTRA,
1778 block_h + QPEL_EXTRA,
1779 x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE,
1780 pic_width, pic_height);
1781 514660 src = lc->edge_emu_buffer + buf_offset;
1782 514660 srcstride = edge_emu_stride;
1783 }
1784
1785
2/2
✓ Branch 0 taken 6459755 times.
✓ Branch 1 taken 133864 times.
6593619 if (!weight_flag)
1786 6459755 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride,
1787 block_h, mx, my, block_w);
1788 else
1789 133864 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride,
1790 133864 block_h, s->sh.luma_log2_weight_denom,
1791 luma_weight, luma_offset, mx, my, block_w);
1792 6593619 }
1793
1794 /**
1795 * 8.5.3.2.2.1 Luma sample bidirectional interpolation process
1796 *
1797 * @param s HEVC decoding context
1798 * @param dst target buffer for block data at block position
1799 * @param dststride stride of the dst buffer
1800 * @param ref0 reference picture0 buffer at origin (0, 0)
1801 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1802 * @param x_off horizontal position of block from origin (0, 0)
1803 * @param y_off vertical position of block from origin (0, 0)
1804 * @param block_w width of block
1805 * @param block_h height of block
1806 * @param ref1 reference picture1 buffer at origin (0, 0)
1807 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1808 * @param current_mv current motion vector structure
1809 */
1810 3992260 static void luma_mc_bi(HEVCLocalContext *lc,
1811 const HEVCPPS *pps, const HEVCSPS *sps,
1812 uint8_t *dst, ptrdiff_t dststride,
1813 const AVFrame *ref0, const Mv *mv0, int x_off, int y_off,
1814 int block_w, int block_h, const AVFrame *ref1,
1815 const Mv *mv1, struct MvField *current_mv)
1816 {
1817 3992260 const HEVCContext *const s = lc->parent;
1818 3992260 ptrdiff_t src0stride = ref0->linesize[0];
1819 3992260 ptrdiff_t src1stride = ref1->linesize[0];
1820 3992260 int pic_width = sps->width;
1821 3992260 int pic_height = sps->height;
1822 3992260 int mx0 = mv0->x & 3;
1823 3992260 int my0 = mv0->y & 3;
1824 3992260 int mx1 = mv1->x & 3;
1825 3992260 int my1 = mv1->y & 3;
1826
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3992260 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7984520 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1827
3/4
✓ Branch 0 taken 3992260 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 73498 times.
✓ Branch 3 taken 3918762 times.
3992260 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1828 3992260 int x_off0 = x_off + (mv0->x >> 2);
1829 3992260 int y_off0 = y_off + (mv0->y >> 2);
1830 3992260 int x_off1 = x_off + (mv1->x >> 2);
1831 3992260 int y_off1 = y_off + (mv1->y >> 2);
1832 3992260 int idx = hevc_pel_weight[block_w];
1833
1834 3992260 const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1835 3992260 const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1836
1837
4/4
✓ Branch 0 taken 3934452 times.
✓ Branch 1 taken 57808 times.
✓ Branch 2 taken 3827160 times.
✓ Branch 3 taken 107292 times.
3992260 if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER ||
1838
2/2
✓ Branch 0 taken 3758110 times.
✓ Branch 1 taken 69050 times.
3827160 x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1839
2/2
✓ Branch 0 taken 209692 times.
✓ Branch 1 taken 3548418 times.
3758110 y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1840 443842 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1841 443842 int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1842 443842 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1843
1844 443842 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset,
1845 edge_emu_stride, src0stride,
1846 block_w + QPEL_EXTRA,
1847 block_h + QPEL_EXTRA,
1848 x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE,
1849 pic_width, pic_height);
1850 443842 src0 = lc->edge_emu_buffer + buf_offset;
1851 443842 src0stride = edge_emu_stride;
1852 }
1853
1854
4/4
✓ Branch 0 taken 3928250 times.
✓ Branch 1 taken 64010 times.
✓ Branch 2 taken 3821613 times.
✓ Branch 3 taken 106637 times.
3992260 if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER ||
1855
2/2
✓ Branch 0 taken 3750656 times.
✓ Branch 1 taken 70957 times.
3821613 x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1856
2/2
✓ Branch 0 taken 212865 times.
✓ Branch 1 taken 3537791 times.
3750656 y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1857 454469 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1858 454469 int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1859 454469 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1860
1861 454469 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset,
1862 edge_emu_stride, src1stride,
1863 block_w + QPEL_EXTRA,
1864 block_h + QPEL_EXTRA,
1865 x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE,
1866 pic_width, pic_height);
1867 454469 src1 = lc->edge_emu_buffer2 + buf_offset;
1868 454469 src1stride = edge_emu_stride;
1869 }
1870
1871 3992260 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride,
1872 block_h, mx0, my0, block_w);
1873
2/2
✓ Branch 0 taken 3918762 times.
✓ Branch 1 taken 73498 times.
3992260 if (!weight_flag)
1874 3918762 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1875 block_h, mx1, my1, block_w);
1876 else
1877 73498 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1878 73498 block_h, s->sh.luma_log2_weight_denom,
1879 73498 s->sh.luma_weight_l0[current_mv->ref_idx[0]],
1880 73498 s->sh.luma_weight_l1[current_mv->ref_idx[1]],
1881 73498 s->sh.luma_offset_l0[current_mv->ref_idx[0]] +
1882 73498 s->sh.luma_offset_l1[current_mv->ref_idx[1]],
1883 mx1, my1, block_w);
1884
1885 3992260 }
1886
1887 /**
1888 * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process
1889 *
1890 * @param s HEVC decoding context
1891 * @param dst1 target buffer for block data at block position (U plane)
1892 * @param dst2 target buffer for block data at block position (V plane)
1893 * @param dststride stride of the dst1 and dst2 buffers
1894 * @param ref reference picture buffer at origin (0, 0)
1895 * @param mv motion vector (relative to block position) to get pixel data from
1896 * @param x_off horizontal position of block from origin (0, 0)
1897 * @param y_off vertical position of block from origin (0, 0)
1898 * @param block_w width of block
1899 * @param block_h height of block
1900 * @param chroma_weight weighting factor applied to the chroma prediction
1901 * @param chroma_offset additive offset applied to the chroma prediction value
1902 */
1903
1904 13187238 static void chroma_mc_uni(HEVCLocalContext *lc,
1905 const HEVCPPS *pps, const HEVCSPS *sps,
1906 uint8_t *dst0,
1907 ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist,
1908 int x_off, int y_off, int block_w, int block_h,
1909 const struct MvField *current_mv, int chroma_weight, int chroma_offset)
1910 {
1911 13187238 const HEVCContext *const s = lc->parent;
1912 13187238 int pic_width = sps->width >> sps->hshift[1];
1913 13187238 int pic_height = sps->height >> sps->vshift[1];
1914 13187238 const Mv *mv = &current_mv->mv[reflist];
1915
4/4
✓ Branch 0 taken 7061368 times.
✓ Branch 1 taken 6125870 times.
✓ Branch 2 taken 6940192 times.
✓ Branch 3 taken 121176 times.
26253300 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1916
4/4
✓ Branch 0 taken 6125870 times.
✓ Branch 1 taken 6940192 times.
✓ Branch 2 taken 146552 times.
✓ Branch 3 taken 5979318 times.
13066062 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1917 13187238 int idx = hevc_pel_weight[block_w];
1918 13187238 int hshift = sps->hshift[1];
1919 13187238 int vshift = sps->vshift[1];
1920 13187238 intptr_t mx = av_zero_extend(mv->x, 2 + hshift);
1921 13187238 intptr_t my = av_zero_extend(mv->y, 2 + vshift);
1922 13187238 intptr_t _mx = mx << (1 - hshift);
1923 13187238 intptr_t _my = my << (1 - vshift);
1924
2/4
✓ Branch 0 taken 13187238 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13187238 times.
13187238 int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2];
1925
1926 13187238 x_off += mv->x >> (2 + hshift);
1927 13187238 y_off += mv->y >> (2 + vshift);
1928 13187238 src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1929
1930
4/4
✓ Branch 0 taken 13061514 times.
✓ Branch 1 taken 125724 times.
✓ Branch 2 taken 12812810 times.
✓ Branch 3 taken 248704 times.
13187238 if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1931
2/2
✓ Branch 0 taken 12655186 times.
✓ Branch 1 taken 157624 times.
12812810 x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1932
3/4
✓ Branch 0 taken 12172004 times.
✓ Branch 1 taken 483182 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12172004 times.
12655186 y_off >= pic_height - block_h - EPEL_EXTRA_AFTER ||
1933 emu) {
1934 1015234 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1935 1015234 int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift));
1936 1015234 int buf_offset0 = EPEL_EXTRA_BEFORE *
1937 1015234 (edge_emu_stride + (1 << sps->pixel_shift));
1938 1015234 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0,
1939 edge_emu_stride, srcstride,
1940 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1941 x_off - EPEL_EXTRA_BEFORE,
1942 y_off - EPEL_EXTRA_BEFORE,
1943 pic_width, pic_height);
1944
1945 1015234 src0 = lc->edge_emu_buffer + buf_offset0;
1946 1015234 srcstride = edge_emu_stride;
1947 }
1948
2/2
✓ Branch 0 taken 12919510 times.
✓ Branch 1 taken 267728 times.
13187238 if (!weight_flag)
1949 12919510 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1950 block_h, _mx, _my, block_w);
1951 else
1952 267728 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1953 267728 block_h, s->sh.chroma_log2_weight_denom,
1954 chroma_weight, chroma_offset, _mx, _my, block_w);
1955 13187238 }
1956
1957 /**
1958 * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process
1959 *
1960 * @param s HEVC decoding context
1961 * @param dst target buffer for block data at block position
1962 * @param dststride stride of the dst buffer
1963 * @param ref0 reference picture0 buffer at origin (0, 0)
1964 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1965 * @param x_off horizontal position of block from origin (0, 0)
1966 * @param y_off vertical position of block from origin (0, 0)
1967 * @param block_w width of block
1968 * @param block_h height of block
1969 * @param ref1 reference picture1 buffer at origin (0, 0)
1970 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1971 * @param current_mv current motion vector structure
1972 * @param cidx chroma component(cb, cr)
1973 */
1974 7984520 static void chroma_mc_bi(HEVCLocalContext *lc,
1975 const HEVCPPS *pps, const HEVCSPS *sps,
1976 uint8_t *dst0, ptrdiff_t dststride,
1977 const AVFrame *ref0, const AVFrame *ref1,
1978 int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx)
1979 {
1980 7984520 const HEVCContext *const s = lc->parent;
1981 7984520 const uint8_t *src1 = ref0->data[cidx+1];
1982 7984520 const uint8_t *src2 = ref1->data[cidx+1];
1983 7984520 ptrdiff_t src1stride = ref0->linesize[cidx+1];
1984 7984520 ptrdiff_t src2stride = ref1->linesize[cidx+1];
1985
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7984520 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15969040 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1986
3/4
✓ Branch 0 taken 7984520 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 146996 times.
✓ Branch 3 taken 7837524 times.
7984520 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1987 7984520 int pic_width = sps->width >> sps->hshift[1];
1988 7984520 int pic_height = sps->height >> sps->vshift[1];
1989 7984520 const Mv *const mv0 = &current_mv->mv[0];
1990 7984520 const Mv *const mv1 = &current_mv->mv[1];
1991 7984520 int hshift = sps->hshift[1];
1992 7984520 int vshift = sps->vshift[1];
1993
1994 7984520 intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift);
1995 7984520 intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift);
1996 7984520 intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift);
1997 7984520 intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift);
1998 7984520 intptr_t _mx0 = mx0 << (1 - hshift);
1999 7984520 intptr_t _my0 = my0 << (1 - vshift);
2000 7984520 intptr_t _mx1 = mx1 << (1 - hshift);
2001 7984520 intptr_t _my1 = my1 << (1 - vshift);
2002
2003 7984520 int x_off0 = x_off + (mv0->x >> (2 + hshift));
2004 7984520 int y_off0 = y_off + (mv0->y >> (2 + vshift));
2005 7984520 int x_off1 = x_off + (mv1->x >> (2 + hshift));
2006 7984520 int y_off1 = y_off + (mv1->y >> (2 + vshift));
2007 7984520 int idx = hevc_pel_weight[block_w];
2008 7984520 src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift);
2009 7984520 src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift);
2010
2011
4/4
✓ Branch 0 taken 7875162 times.
✓ Branch 1 taken 109358 times.
✓ Branch 2 taken 7660466 times.
✓ Branch 3 taken 214696 times.
7984520 if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER ||
2012
2/2
✓ Branch 0 taken 7522370 times.
✓ Branch 1 taken 138096 times.
7660466 x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
2013
2/2
✓ Branch 0 taken 418796 times.
✓ Branch 1 taken 7103574 times.
7522370 y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
2014 880946 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
2015 880946 int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift));
2016 880946 int buf_offset1 = EPEL_EXTRA_BEFORE *
2017 880946 (edge_emu_stride + (1 << sps->pixel_shift));
2018
2019 880946 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1,
2020 edge_emu_stride, src1stride,
2021 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
2022 x_off0 - EPEL_EXTRA_BEFORE,
2023 y_off0 - EPEL_EXTRA_BEFORE,
2024 pic_width, pic_height);
2025
2026 880946 src1 = lc->edge_emu_buffer + buf_offset1;
2027 880946 src1stride = edge_emu_stride;
2028 }
2029
2030
4/4
✓ Branch 0 taken 7861896 times.
✓ Branch 1 taken 122624 times.
✓ Branch 2 taken 7648900 times.
✓ Branch 3 taken 212996 times.
7984520 if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER ||
2031
2/2
✓ Branch 0 taken 7506992 times.
✓ Branch 1 taken 141908 times.
7648900 x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
2032
2/2
✓ Branch 0 taken 425404 times.
✓ Branch 1 taken 7081588 times.
7506992 y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
2033 902932 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
2034 902932 int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift));
2035 902932 int buf_offset1 = EPEL_EXTRA_BEFORE *
2036 902932 (edge_emu_stride + (1 << sps->pixel_shift));
2037
2038 902932 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1,
2039 edge_emu_stride, src2stride,
2040 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
2041 x_off1 - EPEL_EXTRA_BEFORE,
2042 y_off1 - EPEL_EXTRA_BEFORE,
2043 pic_width, pic_height);
2044
2045 902932 src2 = lc->edge_emu_buffer2 + buf_offset1;
2046 902932 src2stride = edge_emu_stride;
2047 }
2048
2049 7984520 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride,
2050 block_h, _mx0, _my0, block_w);
2051
2/2
✓ Branch 0 taken 7837524 times.
✓ Branch 1 taken 146996 times.
7984520 if (!weight_flag)
2052 7837524 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
2053 7837524 src2, src2stride, lc->tmp,
2054 block_h, _mx1, _my1, block_w);
2055 else
2056 146996 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
2057 146996 src2, src2stride, lc->tmp,
2058 block_h,
2059 146996 s->sh.chroma_log2_weight_denom,
2060 146996 s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx],
2061 146996 s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx],
2062 146996 s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx] +
2063 146996 s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx],
2064 _mx1, _my1, block_w);
2065 7984520 }
2066
2067 14578139 static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref,
2068 const Mv *mv, int y0, int height)
2069 {
2070
2/2
✓ Branch 0 taken 111132 times.
✓ Branch 1 taken 14467007 times.
14578139 if (s->avctx->active_thread_type == FF_THREAD_FRAME ) {
2071 111132 int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9);
2072
2073 111132 ff_progress_frame_await(&ref->tf, y);
2074 }
2075 14578139 }
2076
2077 2924907 static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc,
2078 const HEVCPPS *pps, const HEVCSPS *sps,
2079 int x0, int y0, int nPbW,
2080 int nPbH, int log2_cb_size, int part_idx,
2081 int merge_idx, MvField *mv)
2082 {
2083 2924907 const HEVCContext *const s = lc->parent;
2084 2924907 enum InterPredIdc inter_pred_idc = PRED_L0;
2085 int mvp_flag;
2086
2087 2924907 ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size);
2088 2924907 mv->pred_flag = 0;
2089
2/2
✓ Branch 0 taken 1923220 times.
✓ Branch 1 taken 1001687 times.
2924907 if (s->sh.slice_type == HEVC_SLICE_B)
2090 1923220 inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH);
2091
2092
2/2
✓ Branch 0 taken 2515419 times.
✓ Branch 1 taken 409488 times.
2924907 if (inter_pred_idc != PRED_L1) {
2093
1/2
✓ Branch 0 taken 2515419 times.
✗ Branch 1 not taken.
2515419 if (s->sh.nb_refs[L0])
2094 2515419 mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]);
2095
2096 2515419 mv->pred_flag = PF_L0;
2097 2515419 ff_hevc_hls_mvd_coding(lc, x0, y0, 0);
2098 2515419 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2099 2515419 ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2100 part_idx, merge_idx, mv, mvp_flag, 0);
2101 2515419 mv->mv[0].x += lc->pu.mvd.x;
2102 2515419 mv->mv[0].y += lc->pu.mvd.y;
2103 }
2104
2105
2/2
✓ Branch 0 taken 834466 times.
✓ Branch 1 taken 2090441 times.
2924907 if (inter_pred_idc != PRED_L0) {
2106
1/2
✓ Branch 0 taken 834466 times.
✗ Branch 1 not taken.
834466 if (s->sh.nb_refs[L1])
2107 834466 mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]);
2108
2109
4/4
✓ Branch 0 taken 193172 times.
✓ Branch 1 taken 641294 times.
✓ Branch 2 taken 163605 times.
✓ Branch 3 taken 29567 times.
834466 if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) {
2110 163605 AV_ZERO32(&lc->pu.mvd);
2111 } else {
2112 670861 ff_hevc_hls_mvd_coding(lc, x0, y0, 1);
2113 }
2114
2115 834466 mv->pred_flag += PF_L1;
2116 834466 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2117 834466 ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2118 part_idx, merge_idx, mv, mvp_flag, 1);
2119 834466 mv->mv[1].x += lc->pu.mvd.x;
2120 834466 mv->mv[1].y += lc->pu.mvd.y;
2121 }
2122 2924907 }
2123
2124 10585879 static void hls_prediction_unit(HEVCLocalContext *lc,
2125 const HEVCLayerContext *l,
2126 const HEVCPPS *pps, const HEVCSPS *sps,
2127 int x0, int y0, int nPbW, int nPbH,
2128 int log2_cb_size, int partIdx, int idx)
2129 {
2130 #define POS(c_idx, x, y) \
2131 s->cur_frame->f->data[c_idx] ? \
2132 &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \
2133 (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] : NULL
2134 10585879 const HEVCContext *const s = lc->parent;
2135 10585879 int merge_idx = 0;
2136 10585879 struct MvField current_mv = {{{ 0 }}};
2137
2138 10585879 int min_pu_width = sps->min_pu_width;
2139
2140 10585879 MvField *tab_mvf = s->cur_frame->tab_mvf;
2141 10585879 const RefPicList *refPicList = s->cur_frame->refPicList;
2142 10585879 const HEVCFrame *ref0 = NULL, *ref1 = NULL;
2143 10585879 const int *linesize = s->cur_frame->f->linesize;
2144 10585879 uint8_t *dst0 = s->cur_frame->f->data[0] + y0 * linesize[0] + (x0 << sps->pixel_shift);
2145
1/2
✓ Branch 0 taken 10585879 times.
✗ Branch 1 not taken.
10585879 uint8_t *dst1 = POS(1, x0, y0);
2146
1/2
✓ Branch 0 taken 10585879 times.
✗ Branch 1 not taken.
10585879 uint8_t *dst2 = POS(2, x0, y0);
2147 10585879 int log2_min_cb_size = sps->log2_min_cb_size;
2148 10585879 int min_cb_width = sps->min_cb_width;
2149 10585879 int x_cb = x0 >> log2_min_cb_size;
2150 10585879 int y_cb = y0 >> log2_min_cb_size;
2151 int x_pu, y_pu;
2152 int i, j;
2153
2154 10585879 int skip_flag = SAMPLE_CTB(l->skip_flag, x_cb, y_cb);
2155
2156
2/2
✓ Branch 0 taken 5861787 times.
✓ Branch 1 taken 4724092 times.
10585879 if (!skip_flag)
2157 5861787 lc->pu.merge_flag = ff_hevc_merge_flag_decode(lc);
2158
2159
4/4
✓ Branch 0 taken 5861787 times.
✓ Branch 1 taken 4724092 times.
✓ Branch 2 taken 2936880 times.
✓ Branch 3 taken 2924907 times.
10585879 if (skip_flag || lc->pu.merge_flag) {
2160
2/2
✓ Branch 0 taken 7584119 times.
✓ Branch 1 taken 76853 times.
7660972 if (s->sh.max_num_merge_cand > 1)
2161 7584119 merge_idx = ff_hevc_merge_idx_decode(lc);
2162 else
2163 76853 merge_idx = 0;
2164
2165 7660972 ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2166 partIdx, merge_idx, &current_mv);
2167 } else {
2168 2924907 hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size,
2169 partIdx, merge_idx, &current_mv);
2170 }
2171
2172 10585879 x_pu = x0 >> sps->log2_min_pu_size;
2173 10585879 y_pu = y0 >> sps->log2_min_pu_size;
2174
2175
2/2
✓ Branch 0 taken 41855258 times.
✓ Branch 1 taken 10585879 times.
52441137 for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++)
2176
2/2
✓ Branch 0 taken 271172596 times.
✓ Branch 1 taken 41855258 times.
313027854 for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++)
2177 271172596 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
2178
2179
2/2
✓ Branch 0 taken 9766042 times.
✓ Branch 1 taken 819837 times.
10585879 if (current_mv.pred_flag & PF_L0) {
2180 9766042 ref0 = refPicList[0].ref[current_mv.ref_idx[0]];
2181
2/4
✓ Branch 0 taken 9766042 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9766042 times.
9766042 if (!ref0 || !ref0->f)
2182 ✗ return;
2183 9766042 hevc_await_progress(s, ref0, &current_mv.mv[0], y0, nPbH);
2184 }
2185
2/2
✓ Branch 0 taken 4812097 times.
✓ Branch 1 taken 5773782 times.
10585879 if (current_mv.pred_flag & PF_L1) {
2186 4812097 ref1 = refPicList[1].ref[current_mv.ref_idx[1]];
2187
2/4
✓ Branch 0 taken 4812097 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4812097 times.
4812097 if (!ref1 || !ref1->f)
2188 ✗ return;
2189 4812097 hevc_await_progress(s, ref1, &current_mv.mv[1], y0, nPbH);
2190 }
2191
2192
2/2
✓ Branch 0 taken 5773782 times.
✓ Branch 1 taken 4812097 times.
10585879 if (current_mv.pred_flag == PF_L0) {
2193 5773782 int x0_c = x0 >> sps->hshift[1];
2194 5773782 int y0_c = y0 >> sps->vshift[1];
2195 5773782 int nPbW_c = nPbW >> sps->hshift[1];
2196 5773782 int nPbH_c = nPbH >> sps->vshift[1];
2197
2198 5773782 luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f,
2199 &current_mv.mv[0], x0, y0, nPbW, nPbH,
2200 5773782 s->sh.luma_weight_l0[current_mv.ref_idx[0]],
2201 5773782 s->sh.luma_offset_l0[current_mv.ref_idx[0]]);
2202
2203
1/2
✓ Branch 0 taken 5773782 times.
✗ Branch 1 not taken.
5773782 if (sps->chroma_format_idc) {
2204 5773782 chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1],
2205 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2206 5773782 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]);
2207 5773782 chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2],
2208 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2209 5773782 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]);
2210 }
2211
2/2
✓ Branch 0 taken 819837 times.
✓ Branch 1 taken 3992260 times.
4812097 } else if (current_mv.pred_flag == PF_L1) {
2212 819837 int x0_c = x0 >> sps->hshift[1];
2213 819837 int y0_c = y0 >> sps->vshift[1];
2214 819837 int nPbW_c = nPbW >> sps->hshift[1];
2215 819837 int nPbH_c = nPbH >> sps->vshift[1];
2216
2217 819837 luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f,
2218 &current_mv.mv[1], x0, y0, nPbW, nPbH,
2219 819837 s->sh.luma_weight_l1[current_mv.ref_idx[1]],
2220 819837 s->sh.luma_offset_l1[current_mv.ref_idx[1]]);
2221
2222
1/2
✓ Branch 0 taken 819837 times.
✗ Branch 1 not taken.
819837 if (sps->chroma_format_idc) {
2223 819837 chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1],
2224 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2225 819837 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]);
2226
2227 819837 chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2],
2228 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2229 819837 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]);
2230 }
2231
1/2
✓ Branch 0 taken 3992260 times.
✗ Branch 1 not taken.
3992260 } else if (current_mv.pred_flag == PF_BI) {
2232 3992260 int x0_c = x0 >> sps->hshift[1];
2233 3992260 int y0_c = y0 >> sps->vshift[1];
2234 3992260 int nPbW_c = nPbW >> sps->hshift[1];
2235 3992260 int nPbH_c = nPbH >> sps->vshift[1];
2236
2237 3992260 luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f,
2238 &current_mv.mv[0], x0, y0, nPbW, nPbH,
2239 3992260 ref1->f, &current_mv.mv[1], &current_mv);
2240
2241
1/2
✓ Branch 0 taken 3992260 times.
✗ Branch 1 not taken.
3992260 if (sps->chroma_format_idc) {
2242 3992260 chroma_mc_bi(lc, pps, sps, dst1, linesize[1], ref0->f, ref1->f,
2243 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 0);
2244
2245 3992260 chroma_mc_bi(lc, pps, sps, dst2, linesize[2], ref0->f, ref1->f,
2246 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 1);
2247 }
2248 }
2249 }
2250
2251 /**
2252 * 8.4.1
2253 */
2254 6823027 static int luma_intra_pred_mode(HEVCLocalContext *lc, const HEVCLayerContext *l,
2255 const HEVCSPS *sps,
2256 int x0, int y0, int pu_size,
2257 int prev_intra_luma_pred_flag)
2258 {
2259 6823027 const HEVCContext *const s = lc->parent;
2260 6823027 int x_pu = x0 >> sps->log2_min_pu_size;
2261 6823027 int y_pu = y0 >> sps->log2_min_pu_size;
2262 6823027 int min_pu_width = sps->min_pu_width;
2263 6823027 int size_in_pus = pu_size >> sps->log2_min_pu_size;
2264 6823027 int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2265 6823027 int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2266
2267
2/2
✓ Branch 0 taken 914768 times.
✓ Branch 1 taken 107942 times.
1022710 int cand_up = (lc->ctb_up_flag || y0b) ?
2268
2/2
✓ Branch 0 taken 1022710 times.
✓ Branch 1 taken 5800317 times.
7845737 l->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
2269
2/2
✓ Branch 0 taken 495722 times.
✓ Branch 1 taken 69617 times.
565339 int cand_left = (lc->ctb_left_flag || x0b) ?
2270
2/2
✓ Branch 0 taken 565339 times.
✓ Branch 1 taken 6257688 times.
7388366 l->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC;
2271
2272 6823027 int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size);
2273
2274 6823027 MvField *tab_mvf = s->cur_frame->tab_mvf;
2275 int intra_pred_mode;
2276 int candidate[3];
2277 int i, j;
2278
2279 // intra_pred_mode prediction does not cross vertical CTB boundaries
2280
2/2
✓ Branch 0 taken 914617 times.
✓ Branch 1 taken 5908410 times.
6823027 if ((y0 - 1) < y_ctb)
2281 914617 cand_up = INTRA_DC;
2282
2283
2/2
✓ Branch 0 taken 1528536 times.
✓ Branch 1 taken 5294491 times.
6823027 if (cand_left == cand_up) {
2284
2/2
✓ Branch 0 taken 980738 times.
✓ Branch 1 taken 547798 times.
1528536 if (cand_left < 2) {
2285 980738 candidate[0] = INTRA_PLANAR;
2286 980738 candidate[1] = INTRA_DC;
2287 980738 candidate[2] = INTRA_ANGULAR_26;
2288 } else {
2289 547798 candidate[0] = cand_left;
2290 547798 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2291 547798 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2292 }
2293 } else {
2294 5294491 candidate[0] = cand_left;
2295 5294491 candidate[1] = cand_up;
2296
4/4
✓ Branch 0 taken 4393216 times.
✓ Branch 1 taken 901275 times.
✓ Branch 2 taken 3630602 times.
✓ Branch 3 taken 762614 times.
5294491 if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) {
2297 3630602 candidate[2] = INTRA_PLANAR;
2298
4/4
✓ Branch 0 taken 1445949 times.
✓ Branch 1 taken 217940 times.
✓ Branch 2 taken 1077783 times.
✓ Branch 3 taken 368166 times.
1663889 } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) {
2299 1077783 candidate[2] = INTRA_DC;
2300 } else {
2301 586106 candidate[2] = INTRA_ANGULAR_26;
2302 }
2303 }
2304
2305
2/2
✓ Branch 0 taken 4052829 times.
✓ Branch 1 taken 2770198 times.
6823027 if (prev_intra_luma_pred_flag) {
2306 4052829 intra_pred_mode = candidate[lc->pu.mpm_idx];
2307 } else {
2308
2/2
✓ Branch 0 taken 1272412 times.
✓ Branch 1 taken 1497786 times.
2770198 if (candidate[0] > candidate[1])
2309 1272412 FFSWAP(uint8_t, candidate[0], candidate[1]);
2310
2/2
✓ Branch 0 taken 1598153 times.
✓ Branch 1 taken 1172045 times.
2770198 if (candidate[0] > candidate[2])
2311 1598153 FFSWAP(uint8_t, candidate[0], candidate[2]);
2312
2/2
✓ Branch 0 taken 1996614 times.
✓ Branch 1 taken 773584 times.
2770198 if (candidate[1] > candidate[2])
2313 1996614 FFSWAP(uint8_t, candidate[1], candidate[2]);
2314
2315 2770198 intra_pred_mode = lc->pu.rem_intra_luma_pred_mode;
2316
2/2
✓ Branch 0 taken 8310594 times.
✓ Branch 1 taken 2770198 times.
11080792 for (i = 0; i < 3; i++)
2317
2/2
✓ Branch 0 taken 6061418 times.
✓ Branch 1 taken 2249176 times.
8310594 if (intra_pred_mode >= candidate[i])
2318 6061418 intra_pred_mode++;
2319 }
2320
2321 /* write the intra prediction units into the mv array */
2322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6823027 times.
6823027 if (!size_in_pus)
2323 ✗ size_in_pus = 1;
2324
2/2
✓ Branch 0 taken 12424116 times.
✓ Branch 1 taken 6823027 times.
19247143 for (i = 0; i < size_in_pus; i++) {
2325 12424116 memset(&l->tab_ipm[(y_pu + i) * min_pu_width + x_pu],
2326 intra_pred_mode, size_in_pus);
2327
2328
2/2
✓ Branch 0 taken 41756248 times.
✓ Branch 1 taken 12424116 times.
54180364 for (j = 0; j < size_in_pus; j++) {
2329 41756248 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA;
2330 }
2331 }
2332
2333 6823027 return intra_pred_mode;
2334 }
2335
2336 12518427 static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth,
2337 int x0, int y0,
2338 int log2_cb_size, int ct_depth)
2339 {
2340 12518427 int length = (1 << log2_cb_size) >> sps->log2_min_cb_size;
2341 12518427 int x_cb = x0 >> sps->log2_min_cb_size;
2342 12518427 int y_cb = y0 >> sps->log2_min_cb_size;
2343 int y;
2344
2345
2/2
✓ Branch 0 taken 24343656 times.
✓ Branch 1 taken 12518427 times.
36862083 for (y = 0; y < length; y++)
2346 24343656 memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb],
2347 ct_depth, length);
2348 12518427 }
2349
2350 static const uint8_t tab_mode_idx[] = {
2351 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2352 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2353
2354 3673477 static void intra_prediction_unit(HEVCLocalContext *lc,
2355 const HEVCLayerContext *l, const HEVCSPS *sps,
2356 int x0, int y0,
2357 int log2_cb_size)
2358 {
2359 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2360 uint8_t prev_intra_luma_pred_flag[4];
2361 3673477 int split = lc->cu.part_mode == PART_NxN;
2362 3673477 int pb_size = (1 << log2_cb_size) >> split;
2363 3673477 int side = split + 1;
2364 int chroma_mode;
2365 int i, j;
2366
2367
2/2
✓ Branch 0 taken 4723327 times.
✓ Branch 1 taken 3673477 times.
8396804 for (i = 0; i < side; i++)
2368
2/2
✓ Branch 0 taken 6823027 times.
✓ Branch 1 taken 4723327 times.
11546354 for (j = 0; j < side; j++)
2369 6823027 prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc);
2370
2371
2/2
✓ Branch 0 taken 4723327 times.
✓ Branch 1 taken 3673477 times.
8396804 for (i = 0; i < side; i++) {
2372
2/2
✓ Branch 0 taken 6823027 times.
✓ Branch 1 taken 4723327 times.
11546354 for (j = 0; j < side; j++) {
2373
2/2
✓ Branch 0 taken 4052829 times.
✓ Branch 1 taken 2770198 times.
6823027 if (prev_intra_luma_pred_flag[2 * i + j])
2374 4052829 lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc);
2375 else
2376 2770198 lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc);
2377
2378 6823027 lc->pu.intra_pred_mode[2 * i + j] =
2379 6823027 luma_intra_pred_mode(lc, l, sps,
2380 6823027 x0 + pb_size * j, y0 + pb_size * i, pb_size,
2381 6823027 prev_intra_luma_pred_flag[2 * i + j]);
2382 }
2383 }
2384
2385
2/2
✓ Branch 0 taken 59592 times.
✓ Branch 1 taken 3613885 times.
3673477 if (sps->chroma_format_idc == 3) {
2386
2/2
✓ Branch 0 taken 78440 times.
✓ Branch 1 taken 59592 times.
138032 for (i = 0; i < side; i++) {
2387
2/2
✓ Branch 0 taken 116136 times.
✓ Branch 1 taken 78440 times.
194576 for (j = 0; j < side; j++) {
2388 116136 lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2389
2/2
✓ Branch 0 taken 19818 times.
✓ Branch 1 taken 96318 times.
116136 if (chroma_mode != 4) {
2390
2/2
✓ Branch 0 taken 1494 times.
✓ Branch 1 taken 18324 times.
19818 if (lc->pu.intra_pred_mode[2 * i + j] == intra_chroma_table[chroma_mode])
2391 1494 lc->pu.intra_pred_mode_c[2 * i + j] = 34;
2392 else
2393 18324 lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode];
2394 } else {
2395 96318 lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j];
2396 }
2397 }
2398 }
2399
2/2
✓ Branch 0 taken 147152 times.
✓ Branch 1 taken 3466733 times.
3613885 } else if (sps->chroma_format_idc == 2) {
2400 int mode_idx;
2401 147152 lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2402
2/2
✓ Branch 0 taken 46479 times.
✓ Branch 1 taken 100673 times.
147152 if (chroma_mode != 4) {
2403
2/2
✓ Branch 0 taken 2238 times.
✓ Branch 1 taken 44241 times.
46479 if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2404 2238 mode_idx = 34;
2405 else
2406 44241 mode_idx = intra_chroma_table[chroma_mode];
2407 } else {
2408 100673 mode_idx = lc->pu.intra_pred_mode[0];
2409 }
2410 147152 lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx];
2411
2/2
✓ Branch 0 taken 3466462 times.
✓ Branch 1 taken 271 times.
3466733 } else if (sps->chroma_format_idc != 0) {
2412 3466462 chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2413
2/2
✓ Branch 0 taken 822901 times.
✓ Branch 1 taken 2643561 times.
3466462 if (chroma_mode != 4) {
2414
2/2
✓ Branch 0 taken 61006 times.
✓ Branch 1 taken 761895 times.
822901 if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2415 61006 lc->pu.intra_pred_mode_c[0] = 34;
2416 else
2417 761895 lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode];
2418 } else {
2419 2643561 lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0];
2420 }
2421 }
2422 3673477 }
2423
2424 8844951 static void intra_prediction_unit_default_value(HEVCLocalContext *lc,
2425 const HEVCLayerContext *l,
2426 const HEVCSPS *sps,
2427 int x0, int y0,
2428 int log2_cb_size)
2429 {
2430 8844951 const HEVCContext *const s = lc->parent;
2431 8844951 int pb_size = 1 << log2_cb_size;
2432 8844951 int size_in_pus = pb_size >> sps->log2_min_pu_size;
2433 8844951 int min_pu_width = sps->min_pu_width;
2434 8844951 MvField *tab_mvf = s->cur_frame->tab_mvf;
2435 8844951 int x_pu = x0 >> sps->log2_min_pu_size;
2436 8844951 int y_pu = y0 >> sps->log2_min_pu_size;
2437 int j, k;
2438
2439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8844951 times.
8844951 if (size_in_pus == 0)
2440 ✗ size_in_pus = 1;
2441
2/2
✓ Branch 0 taken 38362898 times.
✓ Branch 1 taken 8844951 times.
47207849 for (j = 0; j < size_in_pus; j++)
2442 38362898 memset(&l->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus);
2443
2/2
✓ Branch 0 taken 11207 times.
✓ Branch 1 taken 8833744 times.
8844951 if (lc->cu.pred_mode == MODE_INTRA)
2444
2/2
✓ Branch 0 taken 37756 times.
✓ Branch 1 taken 11207 times.
48963 for (j = 0; j < size_in_pus; j++)
2445
2/2
✓ Branch 0 taken 172544 times.
✓ Branch 1 taken 37756 times.
210300 for (k = 0; k < size_in_pus; k++)
2446 172544 tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA;
2447 8844951 }
2448
2449 12518428 static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s,
2450 const HEVCLayerContext *l,
2451 const HEVCPPS *pps, const HEVCSPS *sps,
2452 int x0, int y0, int log2_cb_size)
2453 {
2454 12518428 int cb_size = 1 << log2_cb_size;
2455 12518428 int log2_min_cb_size = sps->log2_min_cb_size;
2456 12518428 int length = cb_size >> log2_min_cb_size;
2457 12518428 int min_cb_width = sps->min_cb_width;
2458 12518428 int x_cb = x0 >> log2_min_cb_size;
2459 12518428 int y_cb = y0 >> log2_min_cb_size;
2460 12518428 int idx = log2_cb_size - 2;
2461 12518428 int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2462 int x, y, ret;
2463
2464 12518428 lc->cu.x = x0;
2465 12518428 lc->cu.y = y0;
2466 12518428 lc->cu.pred_mode = MODE_INTRA;
2467 12518428 lc->cu.part_mode = PART_2Nx2N;
2468 12518428 lc->cu.intra_split_flag = 0;
2469
2470 12518428 SAMPLE_CTB(l->skip_flag, x_cb, y_cb) = 0;
2471
2/2
✓ Branch 0 taken 50073712 times.
✓ Branch 1 taken 12518428 times.
62592140 for (x = 0; x < 4; x++)
2472 50073712 lc->pu.intra_pred_mode[x] = 1;
2473
2/2
✓ Branch 0 taken 180080 times.
✓ Branch 1 taken 12338348 times.
12518428 if (pps->transquant_bypass_enable_flag) {
2474 180080 lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(lc);
2475
2/2
✓ Branch 0 taken 80141 times.
✓ Branch 1 taken 99939 times.
180080 if (lc->cu.cu_transquant_bypass_flag)
2476 80141 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size);
2477 } else
2478 12338348 lc->cu.cu_transquant_bypass_flag = 0;
2479
2480
2/2
✓ Branch 0 taken 10114738 times.
✓ Branch 1 taken 2403690 times.
12518428 if (s->sh.slice_type != HEVC_SLICE_I) {
2481 10114738 const int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2482 10114738 const int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2483 10114738 uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, l->skip_flag,
2484 x0b, y0b, x_cb, y_cb,
2485 min_cb_width);
2486
2487 10114738 x = y_cb * min_cb_width + x_cb;
2488
2/2
✓ Branch 0 taken 21113041 times.
✓ Branch 1 taken 10114738 times.
31227779 for (y = 0; y < length; y++) {
2489 21113041 memset(&l->skip_flag[x], skip_flag, length);
2490 21113041 x += min_cb_width;
2491 }
2492
2/2
✓ Branch 0 taken 4724092 times.
✓ Branch 1 taken 5390646 times.
10114738 lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER;
2493 } else {
2494 2403690 x = y_cb * min_cb_width + x_cb;
2495
2/2
✓ Branch 0 taken 3230616 times.
✓ Branch 1 taken 2403690 times.
5634306 for (y = 0; y < length; y++) {
2496 3230616 memset(&l->skip_flag[x], 0, length);
2497 3230616 x += min_cb_width;
2498 }
2499 }
2500
2501
2/2
✓ Branch 0 taken 4724092 times.
✓ Branch 1 taken 7794336 times.
12518428 if (SAMPLE_CTB(l->skip_flag, x_cb, y_cb)) {
2502 4724092 hls_prediction_unit(lc, l, pps, sps,
2503 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2504 4724092 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2505
2506
2/2
✓ Branch 0 taken 4577464 times.
✓ Branch 1 taken 146628 times.
4724092 if (!s->sh.disable_deblocking_filter_flag)
2507 4577464 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2508 } else {
2509 7794336 int pcm_flag = 0;
2510
2511
2/2
✓ Branch 0 taken 5390646 times.
✓ Branch 1 taken 2403690 times.
7794336 if (s->sh.slice_type != HEVC_SLICE_I)
2512 5390646 lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc);
2513
2/2
✓ Branch 0 taken 3684684 times.
✓ Branch 1 taken 4109652 times.
7794336 if (lc->cu.pred_mode != MODE_INTRA ||
2514
2/2
✓ Branch 0 taken 2768038 times.
✓ Branch 1 taken 916646 times.
3684684 log2_cb_size == sps->log2_min_cb_size) {
2515 6877690 lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size);
2516
2/2
✓ Branch 0 taken 1158005 times.
✓ Branch 1 taken 5719685 times.
8035695 lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
2517
2/2
✓ Branch 0 taken 1049850 times.
✓ Branch 1 taken 108155 times.
1158005 lc->cu.pred_mode == MODE_INTRA;
2518 }
2519
2520
2/2
✓ Branch 0 taken 3684684 times.
✓ Branch 1 taken 4109652 times.
7794336 if (lc->cu.pred_mode == MODE_INTRA) {
2521
4/4
✓ Branch 0 taken 2634834 times.
✓ Branch 1 taken 1049850 times.
✓ Branch 2 taken 134413 times.
✓ Branch 3 taken 2500421 times.
3684684 if (lc->cu.part_mode == PART_2Nx2N && sps->pcm_enabled &&
2522
2/2
✓ Branch 0 taken 133790 times.
✓ Branch 1 taken 623 times.
134413 log2_cb_size >= sps->pcm.log2_min_pcm_cb_size &&
2523
2/2
✓ Branch 0 taken 126478 times.
✓ Branch 1 taken 7312 times.
133790 log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) {
2524 126478 pcm_flag = ff_hevc_pcm_flag_decode(lc);
2525 }
2526
2/2
✓ Branch 0 taken 11207 times.
✓ Branch 1 taken 3673477 times.
3684684 if (pcm_flag) {
2527 11207 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2528 11207 ret = hls_pcm_sample(lc, l, pps, x0, y0, log2_cb_size);
2529
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11203 times.
11207 if (sps->pcm_loop_filter_disabled)
2530 4 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size);
2531
2532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11207 times.
11207 if (ret < 0)
2533 ✗ return ret;
2534 } else {
2535 3673477 intra_prediction_unit(lc, l, sps, x0, y0, log2_cb_size);
2536 }
2537 } else {
2538 4109652 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2539
8/9
✓ Branch 0 taken 2573827 times.
✓ Branch 1 taken 508582 times.
✓ Branch 2 taken 607461 times.
✓ Branch 3 taken 67350 times.
✓ Branch 4 taken 58153 times.
✓ Branch 5 taken 100281 times.
✓ Branch 6 taken 85843 times.
✓ Branch 7 taken 108155 times.
✗ Branch 8 not taken.
4109652 switch (lc->cu.part_mode) {
2540 2573827 case PART_2Nx2N:
2541 2573827 hls_prediction_unit(lc, l, pps, sps,
2542 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2543 2573827 break;
2544 508582 case PART_2NxN:
2545 508582 hls_prediction_unit(lc, l, pps, sps,
2546 x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2547 508582 hls_prediction_unit(lc, l, pps, sps,
2548 508582 x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2549 508582 break;
2550 607461 case PART_Nx2N:
2551 607461 hls_prediction_unit(lc, l, pps, sps,
2552 x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2553 607461 hls_prediction_unit(lc, l, pps, sps,
2554 607461 x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2555 607461 break;
2556 67350 case PART_2NxnU:
2557 67350 hls_prediction_unit(lc, l, pps, sps,
2558 x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
2559 67350 hls_prediction_unit(lc, l, pps, sps,
2560 67350 x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
2561 67350 break;
2562 58153 case PART_2NxnD:
2563 58153 hls_prediction_unit(lc, l, pps, sps,
2564 58153 x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
2565 58153 hls_prediction_unit(lc, l, pps, sps,
2566 58153 x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
2567 58153 break;
2568 100281 case PART_nLx2N:
2569 100281 hls_prediction_unit(lc, l, pps, sps,
2570 x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
2571 100281 hls_prediction_unit(lc, l, pps, sps,
2572 100281 x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2573 100281 break;
2574 85843 case PART_nRx2N:
2575 85843 hls_prediction_unit(lc, l, pps, sps,
2576 85843 x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
2577 85843 hls_prediction_unit(lc, l, pps, sps,
2578 85843 x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2579 85843 break;
2580 108155 case PART_NxN:
2581 108155 hls_prediction_unit(lc, l, pps, sps,
2582 x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
2583 108155 hls_prediction_unit(lc, l, pps, sps,
2584 108155 x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2585 108155 hls_prediction_unit(lc, l, pps, sps,
2586 108155 x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2587 108155 hls_prediction_unit(lc, l, pps, sps,
2588 108155 x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2589 108155 break;
2590 }
2591 }
2592
2593
2/2
✓ Branch 0 taken 7783129 times.
✓ Branch 1 taken 11207 times.
7794336 if (!pcm_flag) {
2594 7783129 int rqt_root_cbf = 1;
2595
2596
2/2
✓ Branch 0 taken 4109652 times.
✓ Branch 1 taken 3673477 times.
7783129 if (lc->cu.pred_mode != MODE_INTRA &&
2597
4/4
✓ Branch 0 taken 2573827 times.
✓ Branch 1 taken 1535825 times.
✓ Branch 2 taken 1365748 times.
✓ Branch 3 taken 1208079 times.
4109652 !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) {
2598 2901573 rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc);
2599 }
2600
2/2
✓ Branch 0 taken 6224408 times.
✓ Branch 1 taken 1558721 times.
7783129 if (rqt_root_cbf) {
2601 const static int cbf[2] = { 0 };
2602
2/2
✓ Branch 0 taken 3673477 times.
✓ Branch 1 taken 2550931 times.
6224408 lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ?
2603 3673477 sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
2604 2550931 sps->max_transform_hierarchy_depth_inter;
2605 6224408 ret = hls_transform_tree(lc, l, pps, sps, x0, y0, x0, y0, x0, y0,
2606 log2_cb_size,
2607 log2_cb_size, 0, 0, cbf, cbf);
2608
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6224407 times.
6224408 if (ret < 0)
2609 1 return ret;
2610 } else {
2611
2/2
✓ Branch 0 taken 1502270 times.
✓ Branch 1 taken 56451 times.
1558721 if (!s->sh.disable_deblocking_filter_flag)
2612 1502270 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2613 }
2614 }
2615 }
2616
2617
4/4
✓ Branch 0 taken 3206812 times.
✓ Branch 1 taken 9311615 times.
✓ Branch 2 taken 1172355 times.
✓ Branch 3 taken 2034457 times.
12518427 if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
2618 1172355 ff_hevc_set_qPy(lc, l, pps, x0, y0, log2_cb_size);
2619
2620 12518427 x = y_cb * min_cb_width + x_cb;
2621
2/2
✓ Branch 0 taken 24343656 times.
✓ Branch 1 taken 12518427 times.
36862083 for (y = 0; y < length; y++) {
2622 24343656 memset(&l->qp_y_tab[x], lc->qp_y, length);
2623 24343656 x += min_cb_width;
2624 }
2625
2626
2/2
✓ Branch 0 taken 4588449 times.
✓ Branch 1 taken 7929978 times.
12518427 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2627
2/2
✓ Branch 0 taken 2769909 times.
✓ Branch 1 taken 1818540 times.
4588449 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2628 2769909 lc->qPy_pred = lc->qp_y;
2629 }
2630
2631 12518427 set_ct_depth(sps, l->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth);
2632
2633 12518427 return 0;
2634 }
2635
2636 16192568 static int hls_coding_quadtree(HEVCLocalContext *lc,
2637 const HEVCLayerContext *l,
2638 const HEVCPPS *pps, const HEVCSPS *sps,
2639 int x0, int y0,
2640 int log2_cb_size, int cb_depth)
2641 {
2642 16192568 const HEVCContext *const s = lc->parent;
2643 16192568 const int cb_size = 1 << log2_cb_size;
2644 int ret;
2645 int split_cu;
2646
2647 16192568 lc->ct_depth = cb_depth;
2648
2/2
✓ Branch 0 taken 16163370 times.
✓ Branch 1 taken 29198 times.
16192568 if (x0 + cb_size <= sps->width &&
2649
2/2
✓ Branch 0 taken 15824718 times.
✓ Branch 1 taken 338652 times.
16163370 y0 + cb_size <= sps->height &&
2650
2/2
✓ Branch 0 taken 8950751 times.
✓ Branch 1 taken 6873967 times.
15824718 log2_cb_size > sps->log2_min_cb_size) {
2651 8950751 split_cu = ff_hevc_split_coding_unit_flag_decode(lc, l->tab_ct_depth,
2652 sps, cb_depth, x0, y0);
2653 } else {
2654 7241817 split_cu = (log2_cb_size > sps->log2_min_cb_size);
2655 }
2656
2/2
✓ Branch 0 taken 4063549 times.
✓ Branch 1 taken 12129019 times.
16192568 if (pps->cu_qp_delta_enabled_flag &&
2657
2/2
✓ Branch 0 taken 1887230 times.
✓ Branch 1 taken 2176319 times.
4063549 log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) {
2658 1887230 lc->tu.is_cu_qp_delta_coded = 0;
2659 1887230 lc->tu.cu_qp_delta = 0;
2660 }
2661
2662
2/2
✓ Branch 0 taken 467556 times.
✓ Branch 1 taken 15725012 times.
16192568 if (s->sh.cu_chroma_qp_offset_enabled_flag &&
2663
1/2
✓ Branch 0 taken 467556 times.
✗ Branch 1 not taken.
467556 log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_chroma_qp_offset_depth) {
2664 467556 lc->tu.is_cu_chroma_qp_offset_coded = 0;
2665 }
2666
2667
2/2
✓ Branch 0 taken 3674140 times.
✓ Branch 1 taken 12518428 times.
16192568 if (split_cu) {
2668 3674140 int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2669 3674140 const int cb_size_split = cb_size >> 1;
2670 3674140 const int x1 = x0 + cb_size_split;
2671 3674140 const int y1 = y0 + cb_size_split;
2672
2673 3674140 int more_data = 0;
2674
2675 3674140 more_data = hls_coding_quadtree(lc, l, pps, sps,
2676 x0, y0, log2_cb_size - 1, cb_depth + 1);
2677
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3674138 times.
3674140 if (more_data < 0)
2678 2 return more_data;
2679
2680
4/4
✓ Branch 0 taken 3674130 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 3646324 times.
✓ Branch 3 taken 27806 times.
3674138 if (more_data && x1 < sps->width) {
2681 3646324 more_data = hls_coding_quadtree(lc, l, pps, sps,
2682 x1, y0, log2_cb_size - 1, cb_depth + 1);
2683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3646324 times.
3646324 if (more_data < 0)
2684 ✗ return more_data;
2685 }
2686
4/4
✓ Branch 0 taken 3663749 times.
✓ Branch 1 taken 10389 times.
✓ Branch 2 taken 3452974 times.
✓ Branch 3 taken 210775 times.
3674138 if (more_data && y1 < sps->height) {
2687 3452974 more_data = hls_coding_quadtree(lc, l, pps, sps,
2688 x0, y1, log2_cb_size - 1, cb_depth + 1);
2689
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3452974 times.
3452974 if (more_data < 0)
2690 ✗ return more_data;
2691 }
2692
4/4
✓ Branch 0 taken 3657634 times.
✓ Branch 1 taken 16504 times.
✓ Branch 2 taken 3635943 times.
✓ Branch 3 taken 21691 times.
3674138 if (more_data && x1 < sps->width &&
2693
2/2
✓ Branch 0 taken 3425168 times.
✓ Branch 1 taken 210775 times.
3635943 y1 < sps->height) {
2694 3425168 more_data = hls_coding_quadtree(lc, l, pps, sps,
2695 x1, y1, log2_cb_size - 1, cb_depth + 1);
2696
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3425167 times.
3425168 if (more_data < 0)
2697 1 return more_data;
2698 }
2699
2700
2/2
✓ Branch 0 taken 2152394 times.
✓ Branch 1 taken 1521743 times.
3674137 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2701
2/2
✓ Branch 0 taken 1644120 times.
✓ Branch 1 taken 508274 times.
2152394 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2702 1644120 lc->qPy_pred = lc->qp_y;
2703
2704
2/2
✓ Branch 0 taken 3638327 times.
✓ Branch 1 taken 35810 times.
3674137 if (more_data)
2705
2/2
✓ Branch 0 taken 96022 times.
✓ Branch 1 taken 3542305 times.
3734349 return ((x1 + cb_size_split) < sps->width ||
2706
2/2
✓ Branch 0 taken 96021 times.
✓ Branch 1 taken 1 times.
96022 (y1 + cb_size_split) < sps->height);
2707 else
2708 35810 return 0;
2709 } else {
2710 12518428 ret = hls_coding_unit(lc, s, l, pps, sps, x0, y0, log2_cb_size);
2711
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 12518427 times.
12518428 if (ret < 0)
2712 1 return ret;
2713 12518427 if ((!((x0 + cb_size) %
2714
2/2
✓ Branch 0 taken 8705326 times.
✓ Branch 1 taken 3813101 times.
12518427 (1 << (sps->log2_ctb_size))) ||
2715
2/2
✓ Branch 0 taken 69669 times.
✓ Branch 1 taken 8635657 times.
8705326 (x0 + cb_size >= sps->width)) &&
2716 3882770 (!((y0 + cb_size) %
2717
2/2
✓ Branch 0 taken 1988991 times.
✓ Branch 1 taken 1893779 times.
3882770 (1 << (sps->log2_ctb_size))) ||
2718
2/2
✓ Branch 0 taken 100182 times.
✓ Branch 1 taken 1888809 times.
1988991 (y0 + cb_size >= sps->height))) {
2719 1993961 int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc);
2720 1993961 return !end_of_slice_flag;
2721 } else {
2722 10524466 return 1;
2723 }
2724 }
2725
2726 return 0;
2727 }
2728
2729 2074572 static void hls_decode_neighbour(HEVCLocalContext *lc,
2730 const HEVCLayerContext *l,
2731 const HEVCPPS *pps, const HEVCSPS *sps,
2732 int x_ctb, int y_ctb, int ctb_addr_ts)
2733 {
2734 2074572 const HEVCContext *const s = lc->parent;
2735 2074572 int ctb_size = 1 << sps->log2_ctb_size;
2736 2074572 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2737 2074572 int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
2738
2739 /* the tile-parallel path pre-fills this serially, workers only read it */
2740
2/2
✓ Branch 0 taken 2022012 times.
✓ Branch 1 taken 52560 times.
2074572 if (!lc->tile_bs_defer)
2741 2022012 l->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
2742
2743
2/2
✓ Branch 0 taken 168556 times.
✓ Branch 1 taken 1906016 times.
2074572 if (pps->entropy_coding_sync_enabled_flag) {
2744
3/4
✓ Branch 0 taken 7942 times.
✓ Branch 1 taken 160614 times.
✓ Branch 2 taken 7942 times.
✗ Branch 3 not taken.
168556 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2745 7942 lc->first_qp_group = 1;
2746 168556 lc->end_of_tiles_x = sps->width;
2747
2/2
✓ Branch 0 taken 788466 times.
✓ Branch 1 taken 1117550 times.
1906016 } else if (pps->tiles_enabled_flag) {
2748
4/4
✓ Branch 0 taken 787450 times.
✓ Branch 1 taken 1016 times.
✓ Branch 2 taken 12741 times.
✓ Branch 3 taken 774709 times.
788466 if (ctb_addr_ts && pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
2749 12741 int idxX = pps->col_idxX[x_ctb >> sps->log2_ctb_size];
2750 12741 lc->end_of_tiles_x = x_ctb + (pps->column_width[idxX] << sps->log2_ctb_size);
2751 12741 lc->first_qp_group = 1;
2752 }
2753 } else {
2754 1117550 lc->end_of_tiles_x = sps->width;
2755 }
2756
2757 2074572 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height);
2758
2759 2074572 lc->boundary_flags = 0;
2760
2/2
✓ Branch 0 taken 788466 times.
✓ Branch 1 taken 1286106 times.
2074572 if (pps->tiles_enabled_flag) {
2761
4/4
✓ Branch 0 taken 766676 times.
✓ Branch 1 taken 21790 times.
✓ Branch 2 taken 58661 times.
✓ Branch 3 taken 708015 times.
788466 if (x_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2762 58661 lc->boundary_flags |= BOUNDARY_LEFT_TILE;
2763
4/4
✓ Branch 0 taken 766676 times.
✓ Branch 1 taken 21790 times.
✓ Branch 2 taken 15689 times.
✓ Branch 3 taken 750987 times.
788466 if (x_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - 1])
2764 15689 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2765
4/4
✓ Branch 0 taken 758339 times.
✓ Branch 1 taken 30127 times.
✓ Branch 2 taken 63962 times.
✓ Branch 3 taken 694377 times.
788466 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]])
2766 63962 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
2767
4/4
✓ Branch 0 taken 758339 times.
✓ Branch 1 taken 30127 times.
✓ Branch 2 taken 13570 times.
✓ Branch 3 taken 744769 times.
788466 if (y_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - sps->ctb_width])
2768 13570 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2769 } else {
2770
2/2
✓ Branch 0 taken 18279 times.
✓ Branch 1 taken 1267827 times.
1286106 if (ctb_addr_in_slice <= 0)
2771 18279 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2772
2/2
✓ Branch 0 taken 196276 times.
✓ Branch 1 taken 1089830 times.
1286106 if (ctb_addr_in_slice < sps->ctb_width)
2773 196276 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2774 }
2775
2776
6/6
✓ Branch 0 taken 1983170 times.
✓ Branch 1 taken 91402 times.
✓ Branch 2 taken 1975081 times.
✓ Branch 3 taken 8089 times.
✓ Branch 4 taken 1917666 times.
✓ Branch 5 taken 57415 times.
2074572 lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
2777
6/6
✓ Branch 0 taken 1928246 times.
✓ Branch 1 taken 146326 times.
✓ Branch 2 taken 1835420 times.
✓ Branch 3 taken 92826 times.
✓ Branch 4 taken 1784207 times.
✓ Branch 5 taken 51213 times.
2074572 lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
2778
6/6
✓ Branch 0 taken 1928246 times.
✓ Branch 1 taken 146326 times.
✓ Branch 2 taken 1837967 times.
✓ Branch 3 taken 90279 times.
✓ Branch 4 taken 1720231 times.
✓ Branch 5 taken 117736 times.
2074572 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]]));
2779
8/8
✓ Branch 0 taken 1983170 times.
✓ Branch 1 taken 91402 times.
✓ Branch 2 taken 1847491 times.
✓ Branch 3 taken 135679 times.
✓ Branch 4 taken 1759453 times.
✓ Branch 5 taken 88038 times.
✓ Branch 6 taken 1662915 times.
✓ Branch 7 taken 96538 times.
2074572 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]]));
2780 2074572 }
2781
2782 28358 static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
2783 {
2784 28358 HEVCLocalContext *const lc = &s->local_ctx[0];
2785 28358 const HEVCLayerContext *const l = &s->layers[s->cur_layer];
2786 28358 const HEVCPPS *const pps = s->pps;
2787 28358 const HEVCSPS *const sps = pps->sps;
2788 28358 const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
2789 28358 const size_t slice_size = get_bits_bytesize(gb, 1) - s->sh.data_offset;
2790 28358 int ctb_size = 1 << sps->log2_ctb_size;
2791 28358 int more_data = 1;
2792 28358 int x_ctb = 0;
2793 28358 int y_ctb = 0;
2794 28358 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
2795 int ret;
2796
2797
3/4
✓ Branch 0 taken 1941402 times.
✓ Branch 1 taken 28357 times.
✓ Branch 2 taken 1941402 times.
✗ Branch 3 not taken.
1969759 while (more_data && ctb_addr_ts < sps->ctb_size) {
2798 1941402 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2799
2800 1941402 x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2801 1941402 y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2802 1941402 hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
2803
2804 1941402 ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 0);
2805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1941402 times.
1941402 if (ret < 0) {
2806 ✗ l->tab_slice_address[ctb_addr_rs] = -1;
2807 ✗ return ret;
2808 }
2809
2810 1941402 hls_sao_param(lc, l, pps, sps,
2811 1941402 x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
2812
2813 1941402 l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2814 1941402 l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2815 1941402 l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2816
2817 1941402 more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
2818
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1941401 times.
1941402 if (more_data < 0) {
2819 1 l->tab_slice_address[ctb_addr_rs] = -1;
2820 1 return more_data;
2821 }
2822
2823
2824 1941401 ctb_addr_ts++;
2825 1941401 ff_hevc_save_states(lc, pps, ctb_addr_ts);
2826 1941401 ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size);
2827 }
2828
2829
2/2
✓ Branch 0 taken 14788 times.
✓ Branch 1 taken 13569 times.
28357 if (x_ctb + ctb_size >= sps->width &&
2830
2/2
✓ Branch 0 taken 10361 times.
✓ Branch 1 taken 4427 times.
14788 y_ctb + ctb_size >= sps->height)
2831 10361 ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size);
2832
2833 28357 return ctb_addr_ts;
2834 }
2835
2836 ✗ static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist,
2837 int job, int thread)
2838 {
2839 ✗ HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread];
2840 ✗ const HEVCContext *const s = lc->parent;
2841 ✗ const HEVCLayerContext *const l = &s->layers[s->cur_layer];
2842 ✗ const HEVCPPS *const pps = s->pps;
2843 ✗ const HEVCSPS *const sps = pps->sps;
2844 ✗ int ctb_size = 1 << sps->log2_ctb_size;
2845 ✗ int more_data = 1;
2846 ✗ int ctb_row = job;
2847 ✗ int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size);
2848 ✗ int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2849
2850 ✗ const uint8_t *data = s->data + s->sh.offset[ctb_row];
2851 ✗ const size_t data_size = s->sh.size[ctb_row];
2852
2853 ✗ int progress = 0;
2854
2855 int ret;
2856
2857 ✗ if (ctb_row)
2858 ✗ ff_init_cabac_decoder(&lc->cc, data, data_size);
2859
2860 ✗ while(more_data && ctb_addr_ts < sps->ctb_size) {
2861 ✗ int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size;
2862 ✗ int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size;
2863
2864 ✗ hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
2865
2866 ✗ if (ctb_row)
2867 ✗ ff_thread_progress_await(&s->wpp_progress[ctb_row - 1],
2868 progress + SHIFT_CTB_WPP + 1);
2869
2870 /* atomic_load's prototype requires a pointer to non-const atomic variable
2871 * (due to implementations via mutexes, where reads involve writes).
2872 * Of course, casting const away here is nevertheless safe. */
2873 ✗ if (atomic_load((atomic_int*)&s->wpp_err)) {
2874 ✗ ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2875 ✗ return 0;
2876 }
2877
2878 ✗ ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1);
2879 ✗ if (ret < 0)
2880 ✗ goto error;
2881 ✗ hls_sao_param(lc, l, pps, sps,
2882 ✗ x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
2883
2884 ✗ l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2885 ✗ l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2886 ✗ l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2887
2888 ✗ more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
2889
2890 ✗ if (more_data < 0) {
2891 ✗ ret = more_data;
2892 ✗ goto error;
2893 }
2894
2895 ✗ ctb_addr_ts++;
2896
2897 ✗ ff_hevc_save_states(lc, pps, ctb_addr_ts);
2898 ✗ ff_thread_progress_report(&s->wpp_progress[ctb_row], ++progress);
2899 ✗ ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size);
2900
2901 ✗ if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) {
2902 /* Casting const away here is safe, because it is an atomic operation. */
2903 ✗ atomic_store((atomic_int*)&s->wpp_err, 1);
2904 ✗ ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2905 ✗ return 0;
2906 }
2907
2908 ✗ if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) {
2909 ✗ ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size);
2910 ✗ ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2911 ✗ return ctb_addr_ts;
2912 }
2913 ✗ ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2914 ✗ x_ctb+=ctb_size;
2915
2916 ✗ if(x_ctb >= sps->width) {
2917 ✗ break;
2918 }
2919 }
2920 ✗ ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2921
2922 ✗ return 0;
2923 ✗ error:
2924 ✗ l->tab_slice_address[ctb_addr_rs] = -1;
2925 /* Casting const away here is safe, because it is an atomic operation. */
2926 ✗ atomic_store((atomic_int*)&s->wpp_err, 1);
2927 ✗ ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2928 ✗ return ret;
2929 }
2930
2931 ✗ static int wpp_progress_init(HEVCContext *s, unsigned count)
2932 {
2933 ✗ if (s->nb_wpp_progress < count) {
2934 ✗ void *tmp = av_realloc_array(s->wpp_progress, count,
2935 sizeof(*s->wpp_progress));
2936 ✗ if (!tmp)
2937 ✗ return AVERROR(ENOMEM);
2938
2939 ✗ s->wpp_progress = tmp;
2940 ✗ memset(s->wpp_progress + s->nb_wpp_progress, 0,
2941 ✗ (count - s->nb_wpp_progress) * sizeof(*s->wpp_progress));
2942
2943 ✗ for (int i = s->nb_wpp_progress; i < count; i++) {
2944 ✗ int ret = ff_thread_progress_init(&s->wpp_progress[i], 1);
2945 ✗ if (ret < 0)
2946 ✗ return ret;
2947 ✗ s->nb_wpp_progress = i + 1;
2948 }
2949 }
2950
2951 ✗ for (int i = 0; i < count; i++)
2952 ✗ ff_thread_progress_reset(&s->wpp_progress[i]);
2953
2954 ✗ return 0;
2955 }
2956
2957 115 static int alloc_local_ctxs(HEVCContext *s)
2958 {
2959 HEVCLocalContext *tmp;
2960
2961
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 2 times.
115 if (s->avctx->thread_count <= s->nb_local_ctx)
2962 113 return 0;
2963
2964 2 tmp = av_malloc_array(s->avctx->thread_count, sizeof(*s->local_ctx));
2965
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!tmp)
2966 ✗ return AVERROR(ENOMEM);
2967
2968 2 memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx);
2969 2 av_free(s->local_ctx);
2970 2 s->local_ctx = tmp;
2971
2972
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) {
2973 6 tmp = &s->local_ctx[i];
2974
2975 6 memset(tmp, 0, sizeof(*tmp));
2976
2977 6 tmp->logctx = s->avctx;
2978 6 tmp->parent = s;
2979 6 tmp->common_cabac_state = &s->cabac;
2980 }
2981
2982 2 s->nb_local_ctx = s->avctx->thread_count;
2983
2984 2 return 0;
2985 }
2986
2987 115 static int slice_substreams_init(HEVCContext *s, const H2645NAL *nal)
2988 {
2989 115 int64_t offset, startheader, cmpt = 0;
2990 int j;
2991
2992 115 offset = s->sh.data_offset;
2993
2994
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 115 times.
126 for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2995
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2996 ✗ startheader--;
2997 ✗ cmpt++;
2998 }
2999 }
3000
3001
2/2
✓ Branch 0 taken 2405 times.
✓ Branch 1 taken 115 times.
2520 for (int i = 1; i < s->sh.num_entry_point_offsets; i++) {
3002 2405 offset += (s->sh.entry_point_offset[i - 1] - cmpt);
3003 2405 for (j = 0, cmpt = 0, startheader = offset
3004
2/2
✓ Branch 0 taken 253 times.
✓ Branch 1 taken 2405 times.
2658 + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) {
3005
4/4
✓ Branch 0 taken 59 times.
✓ Branch 1 taken 194 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 48 times.
253 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
3006 11 startheader--;
3007 11 cmpt++;
3008 }
3009 }
3010 2405 s->sh.size[i] = s->sh.entry_point_offset[i] - cmpt;
3011 2405 s->sh.offset[i] = offset;
3012
3013 }
3014
3015 115 offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt;
3016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (nal->size < offset) {
3017 ✗ av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n");
3018 ✗ return AVERROR_INVALIDDATA;
3019 }
3020 115 s->sh.size [s->sh.num_entry_point_offsets] = nal->size - offset;
3021 115 s->sh.offset[s->sh.num_entry_point_offsets] = offset;
3022
3023 115 s->sh.offset[0] = s->sh.data_offset;
3024 115 s->sh.size[0] = s->sh.offset[1] - s->sh.offset[0];
3025
3026 115 s->data = nal->data;
3027
3028 115 return 0;
3029 }
3030
3031 ✗ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
3032 {
3033 ✗ const HEVCPPS *const pps = s->pps;
3034 ✗ const HEVCSPS *const sps = pps->sps;
3035 int *ret;
3036 ✗ int res = 0;
3037
3038 ✗ if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * (int64_t)sps->ctb_width >= sps->ctb_width * (int64_t)sps->ctb_height) {
3039 ✗ av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
3040 s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets,
3041 ✗ sps->ctb_width, sps->ctb_height
3042 );
3043 ✗ return AVERROR_INVALIDDATA;
3044 }
3045
3046 ✗ res = alloc_local_ctxs(s);
3047 ✗ if (res < 0)
3048 ✗ return res;
3049
3050 ✗ res = slice_substreams_init(s, nal);
3051 ✗ if (res < 0)
3052 ✗ return res;
3053
3054 ✗ for (unsigned i = 1; i < s->nb_local_ctx; i++) {
3055 ✗ s->local_ctx[i].first_qp_group = 1;
3056 ✗ s->local_ctx[i].qp_y = s->local_ctx[0].qp_y;
3057 }
3058
3059 ✗ atomic_store(&s->wpp_err, 0);
3060 ✗ res = wpp_progress_init(s, s->sh.num_entry_point_offsets + 1);
3061 ✗ if (res < 0)
3062 ✗ return res;
3063
3064 ✗ ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret));
3065 ✗ if (!ret)
3066 ✗ return AVERROR(ENOMEM);
3067
3068 ✗ if (pps->entropy_coding_sync_enabled_flag)
3069 ✗ s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->local_ctx, ret, s->sh.num_entry_point_offsets + 1);
3070
3071 ✗ for (int i = 0; i <= s->sh.num_entry_point_offsets; i++)
3072 ✗ res += ret[i];
3073
3074 ✗ av_free(ret);
3075 ✗ return res;
3076 }
3077
3078 2635 static int hls_decode_entry_tile(AVCodecContext *avctx, void *hevc_lclist,
3079 int job, int thread)
3080 {
3081 2635 HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread];
3082 2635 const HEVCContext *const s = lc->parent;
3083 2635 const HEVCLayerContext *const l = &s->layers[s->cur_layer];
3084 2635 const HEVCPPS *const pps = s->pps;
3085 2635 const HEVCSPS *const sps = pps->sps;
3086 2635 const uint8_t *data = s->data + s->sh.offset[job];
3087 2635 const size_t data_size = s->sh.size[job];
3088 /* the slice covers every tile, so job and tile are the same index */
3089 2635 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[pps->row_bd[job / pps->num_tile_columns] * sps->ctb_width +
3090 2635 pps->col_bd[job % pps->num_tile_columns]];
3091 2635 int more_data = 1, ret;
3092
3093 2635 lc->tile_bs_defer = 1;
3094 2635 lc->tu.cu_qp_offset_cb = 0;
3095 2635 lc->tu.cu_qp_offset_cr = 0;
3096 /* hls_decode_neighbour() skips this for the first CTB of the picture */
3097 2635 lc->end_of_tiles_x = pps->col_bd[job % pps->num_tile_columns + 1] << sps->log2_ctb_size;
3098
3099
3/4
✓ Branch 0 taken 55080 times.
✓ Branch 1 taken 115 times.
✓ Branch 2 taken 55080 times.
✗ Branch 3 not taken.
55195 while (more_data && ctb_addr_ts < sps->ctb_size &&
3100
2/2
✓ Branch 0 taken 52560 times.
✓ Branch 1 taken 2520 times.
55080 pps->tile_id[ctb_addr_ts] == job) {
3101 52560 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
3102 52560 int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size;
3103 52560 int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size;
3104
3105 52560 hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
3106
3107 52560 ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1);
3108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52560 times.
52560 if (ret < 0)
3109 ✗ return ret;
3110
3111 52560 hls_sao_param(lc, l, pps, sps,
3112 52560 x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
3113
3114 52560 l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
3115 52560 l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
3116 52560 l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
3117
3118 52560 more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
3119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52560 times.
52560 if (more_data < 0)
3120 ✗ return more_data;
3121 52560 ctb_addr_ts++;
3122 }
3123 2635 return ctb_addr_ts;
3124 }
3125
3126 115 static int hls_slice_data_tiles(HEVCContext *s, const H2645NAL *nal)
3127 {
3128 115 const HEVCPPS *const pps = s->pps;
3129 115 const HEVCSPS *const sps = pps->sps;
3130 115 const HEVCLayerContext *const l = &s->layers[s->cur_layer];
3131 115 const int ctb_size = 1 << sps->log2_ctb_size;
3132 115 const int nb_tiles = s->sh.num_entry_point_offsets + 1;
3133 115 const int start_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
3134 115 int res = 0, ctb_addr_ts, x_ctb = 0, y_ctb = 0;
3135 int *ret;
3136
3137 115 res = alloc_local_ctxs(s);
3138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (res < 0)
3139 ✗ return res;
3140
3141 115 res = slice_substreams_init(s, nal);
3142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (res < 0)
3143 ✗ return res;
3144
3145
2/2
✓ Branch 0 taken 345 times.
✓ Branch 1 taken 115 times.
460 for (unsigned i = 1; i < s->nb_local_ctx; i++) {
3146 345 s->local_ctx[i].first_qp_group = 1;
3147 345 s->local_ctx[i].qp_y = s->local_ctx[0].qp_y;
3148 }
3149
3150
2/2
✓ Branch 0 taken 52560 times.
✓ Branch 1 taken 115 times.
52675 for (ctb_addr_ts = start_ts; ctb_addr_ts < sps->ctb_size; ctb_addr_ts++)
3151 52560 l->tab_slice_address[pps->ctb_addr_ts_to_rs[ctb_addr_ts]] = s->sh.slice_addr;
3152
3153 115 ret = av_calloc(nb_tiles, sizeof(*ret));
3154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (!ret)
3155 ✗ return AVERROR(ENOMEM);
3156 115 s->avctx->execute2(s->avctx, hls_decode_entry_tile, s->local_ctx, ret, nb_tiles);
3157
2/2
✓ Branch 0 taken 2635 times.
✓ Branch 1 taken 115 times.
2750 for (int i = 0; i < nb_tiles; i++)
3158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2635 times.
2635 if (ret[i] < 0)
3159 ✗ res = ret[i];
3160 115 av_free(ret);
3161
3162
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 115 times.
575 for (unsigned i = 0; i < s->nb_local_ctx; i++)
3163 460 s->local_ctx[i].tile_bs_defer = 0;
3164
3165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (res < 0)
3166 ✗ return res;
3167
3168
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 45 times.
115 if (pps->loop_filter_across_tiles_enabled_flag &&
3169
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 15 times.
70 !s->sh.disable_deblocking_filter_flag) {
3170
2/2
✓ Branch 0 taken 28050 times.
✓ Branch 1 taken 55 times.
28105 for (ctb_addr_ts = start_ts; ctb_addr_ts < sps->ctb_size; ctb_addr_ts++) {
3171 28050 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
3172 28050 x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size;
3173 28050 y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size;
3174 28050 hls_decode_neighbour(&s->local_ctx[0], l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
3175
2/2
✓ Branch 0 taken 9460 times.
✓ Branch 1 taken 18590 times.
28050 if (s->local_ctx[0].boundary_flags & (BOUNDARY_LEFT_TILE | BOUNDARY_UPPER_TILE))
3176 9460 ff_hevc_tile_boundary_bs(&s->local_ctx[0], l, pps, x_ctb, y_ctb);
3177 }
3178 }
3179
3180
2/2
✓ Branch 0 taken 52560 times.
✓ Branch 1 taken 115 times.
52675 for (ctb_addr_ts = start_ts; ctb_addr_ts < sps->ctb_size; ctb_addr_ts++) {
3181 52560 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
3182 52560 x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size;
3183 52560 y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size;
3184 52560 hls_decode_neighbour(&s->local_ctx[0], l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
3185 52560 ff_hevc_hls_filters(&s->local_ctx[0], l, pps, x_ctb, y_ctb, ctb_size);
3186 }
3187
2/4
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115 times.
✗ Branch 3 not taken.
115 if (x_ctb + ctb_size >= sps->width && y_ctb + ctb_size >= sps->height)
3188 115 ff_hevc_hls_filter(&s->local_ctx[0], l, pps, x_ctb, y_ctb, ctb_size);
3189
3190 115 return sps->ctb_size;
3191 }
3192
3193 28585 static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l,
3194 const H2645NAL *nal, GetBitContext *gb)
3195 {
3196 28585 const HEVCPPS *pps = s->pps;
3197 int ret;
3198
3199
2/2
✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10589 times.
28585 if (!s->sh.first_slice_in_pic_flag)
3200 17996 s->slice_idx += !s->sh.dependent_slice_segment_flag;
3201
3202
4/4
✓ Branch 0 taken 20791 times.
✓ Branch 1 taken 7794 times.
✓ Branch 2 taken 19778 times.
✓ Branch 3 taken 1013 times.
28585 if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) {
3203 19778 ret = ff_hevc_slice_rpl(s);
3204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19778 times.
19778 if (ret < 0) {
3205 ✗ av_log(s->avctx, AV_LOG_WARNING,
3206 "Error constructing the reference lists for the current slice.\n");
3207 ✗ return ret;
3208 }
3209 }
3210
3211 28585 s->slice_initialized = 1;
3212
3213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28585 times.
28585 if (s->avctx->hwaccel)
3214 ✗ return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size);
3215
3216
2/2
✓ Branch 1 taken 112 times.
✓ Branch 2 taken 28473 times.
28585 if (ff_decode_skip_all_pixels(s->avctx))
3217 112 return 0;
3218
3219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28473 times.
28473 if (s->avctx->profile == AV_PROFILE_HEVC_SCC) {
3220 ✗ av_log(s->avctx, AV_LOG_ERROR,
3221 "SCC profile is not yet implemented in hevc native decoder.\n");
3222 ✗ return AVERROR_PATCHWELCOME;
3223 }
3224
3225
2/2
✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 20679 times.
28473 if (s->sh.dependent_slice_segment_flag) {
3226 7794 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
3227 7794 int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
3228
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7794 times.
7794 if (l->tab_slice_address[prev_rs] != s->sh.slice_addr) {
3229 ✗ av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
3230 ✗ return AVERROR_INVALIDDATA;
3231 }
3232 }
3233
3234 28473 s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
3235
3236
2/2
✓ Branch 0 taken 22964 times.
✓ Branch 1 taken 5509 times.
28473 if (!pps->cu_qp_delta_enabled_flag)
3237 22964 s->local_ctx[0].qp_y = s->sh.slice_qp;
3238
3239 28473 s->local_ctx[0].tu.cu_qp_offset_cb = 0;
3240 28473 s->local_ctx[0].tu.cu_qp_offset_cr = 0;
3241
3242
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 28358 times.
28473 if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
3243
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 s->sh.num_entry_point_offsets > 0 &&
3244
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
115 pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
3245 ✗ return hls_slice_data_wpp(s, nal);
3246
3247
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 28358 times.
28473 if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
3248
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 s->sh.num_entry_point_offsets > 0 &&
3249
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 pps->tiles_enabled_flag &&
3250
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 !pps->entropy_coding_sync_enabled_flag &&
3251
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 s->sh.first_slice_in_pic_flag &&
3252
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 s->sh.num_entry_point_offsets + 1 == pps->num_tile_rows * pps->num_tile_columns)
3253 115 return hls_slice_data_tiles(s, nal);
3254
3255 28358 return hls_decode_entry(s, gb);
3256 }
3257
3258 10589 static int set_side_data(HEVCContext *s)
3259 {
3260 10589 const HEVCSPS *sps = s->cur_frame->pps->sps;
3261 10589 AVFrame *out = s->cur_frame->f;
3262 int ret;
3263
3264 // Decrement the mastering display and content light level flag when IRAP
3265 // frame has no_rasl_output_flag=1 so the side data persists for the entire
3266 // coded video sequence.
3267
5/6
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 10013 times.
✓ Branch 2 taken 576 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 282 times.
✓ Branch 5 taken 294 times.
10589 if (IS_IRAP(s) && s->no_rasl_output_flag) {
3268
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 266 times.
282 if (s->sei.common.mastering_display.present > 0)
3269 16 s->sei.common.mastering_display.present--;
3270
3271
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 278 times.
282 if (s->sei.common.content_light.present > 0)
3272 4 s->sei.common.content_light.present--;
3273 }
3274
3275 10589 ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx,
3276 &sps->vui.common,
3277 10589 sps->bit_depth, sps->bit_depth_chroma,
3278 10589 s->cur_frame->poc /* no poc_offset in HEVC */);
3279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (ret < 0)
3280 ✗ return ret;
3281
3282
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10569 times.
10589 if (s->sei.timecode.present) {
3283 uint32_t *tc_sd;
3284 char tcbuf[AV_TIMECODE_STR_SIZE];
3285 AVFrameSideData *tcside;
3286 20 ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE,
3287 sizeof(uint32_t) * 4, &tcside);
3288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0)
3289 ✗ return ret;
3290
3291
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if (tcside) {
3292 20 tc_sd = (uint32_t*)tcside->data;
3293 20 tc_sd[0] = s->sei.timecode.num_clock_ts;
3294
3295
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 for (int i = 0; i < tc_sd[0]; i++) {
3296 20 int drop = s->sei.timecode.cnt_dropped_flag[i];
3297 20 int hh = s->sei.timecode.hours_value[i];
3298 20 int mm = s->sei.timecode.minutes_value[i];
3299 20 int ss = s->sei.timecode.seconds_value[i];
3300 20 int ff = s->sei.timecode.n_frames[i];
3301
3302 20 tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff);
3303 20 av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0);
3304 20 av_dict_set(&out->metadata, "timecode", tcbuf, 0);
3305 }
3306 }
3307
3308 20 s->sei.timecode.num_clock_ts = 0;
3309 }
3310
3311
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10586 times.
10589 if (s->sei.common.itut_t35.hdr_plus) {
3312 3 AVBufferRef *info_ref = av_buffer_ref(s->sei.common.itut_t35.hdr_plus);
3313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!info_ref)
3314 ✗ return AVERROR(ENOMEM);
3315
3316 3 ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref);
3317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
3318 ✗ return ret;
3319 }
3320
3321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (s->sei.common.itut_t35.hdr_smpte2094_app5) {
3322 ✗ AVBufferRef *info_ref = av_buffer_ref(s->sei.common.itut_t35.hdr_smpte2094_app5);
3323 ✗ if (!info_ref)
3324 ✗ return AVERROR(ENOMEM);
3325
3326 ✗ ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5, &info_ref);
3327 ✗ if (ret < 0)
3328 ✗ return ret;
3329 }
3330
3331
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10587 times.
10589 if (s->rpu_buf) {
3332 2 AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf);
3333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!rpu)
3334 ✗ return AVERROR(ENOMEM);
3335
3336 2 s->rpu_buf = NULL;
3337 }
3338
3339
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10589 times.
10589 if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0)
3340 ✗ return ret;
3341
3342
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10588 times.
10589 if (s->sei.common.itut_t35.hdr_vivid) {
3343
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!av_frame_side_data_add(&out->side_data, &out->nb_side_data,
3344 AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
3345 &s->sei.common.itut_t35.hdr_vivid,
3346 AV_FRAME_SIDE_DATA_FLAG_NEW_REF))
3347 ✗ return AVERROR(ENOMEM);
3348 }
3349
3350 10589 return 0;
3351 }
3352
3353 10199 static int find_finish_setup_nal(const HEVCContext *s)
3354 {
3355 10199 int nal_idx = 0;
3356
3357
2/2
✓ Branch 0 taken 38642 times.
✓ Branch 1 taken 10199 times.
48841 for (int i = nal_idx; i < s->pkt.nb_nals; i++) {
3358 38642 const H2645NAL *nal = &s->pkt.nals[i];
3359 38642 const int layer_id = nal->nuh_layer_id;
3360 38642 GetBitContext gb = nal->gb;
3361
3362
2/4
✓ Branch 0 taken 38642 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38642 times.
✗ Branch 3 not taken.
38642 if (layer_id > HEVC_MAX_NUH_LAYER_ID || s->vps->layer_idx[layer_id] < 0 ||
3363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38642 times.
38642 !(s->layers_active_decode & (1 << s->vps->layer_idx[layer_id])))
3364 17996 continue;
3365
3366
3/3
✓ Branch 0 taken 28586 times.
✓ Branch 1 taken 1761 times.
✓ Branch 2 taken 8295 times.
38642 switch (nal->type) {
3367 28586 case HEVC_NAL_TRAIL_R:
3368 case HEVC_NAL_TRAIL_N:
3369 case HEVC_NAL_TSA_N:
3370 case HEVC_NAL_TSA_R:
3371 case HEVC_NAL_STSA_N:
3372 case HEVC_NAL_STSA_R:
3373 case HEVC_NAL_BLA_W_LP:
3374 case HEVC_NAL_BLA_W_RADL:
3375 case HEVC_NAL_BLA_N_LP:
3376 case HEVC_NAL_IDR_W_RADL:
3377 case HEVC_NAL_IDR_N_LP:
3378 case HEVC_NAL_CRA_NUT:
3379 case HEVC_NAL_RADL_N:
3380 case HEVC_NAL_RADL_R:
3381 case HEVC_NAL_RASL_N:
3382 case HEVC_NAL_RASL_R:
3383
2/2
✓ Branch 1 taken 17996 times.
✓ Branch 2 taken 10590 times.
28586 if (!get_bits1(&gb)) // first_slice_segment_in_pic_flag
3384 17996 continue;
3385 av_fallthrough;
3386 case HEVC_NAL_VPS:
3387 case HEVC_NAL_SPS:
3388 case HEVC_NAL_PPS:
3389 12351 nal_idx = i;
3390 12351 break;
3391 }
3392 }
3393
3394 10199 return nal_idx;
3395 }
3396
3397 10589 static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l,
3398 unsigned nal_idx)
3399 {
3400 10589 const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id];
3401 10589 const HEVCSPS *const sps = pps->sps;
3402 10589 int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) *
3403 10589 ((sps->height >> sps->log2_min_cb_size) + 1);
3404
2/2
✓ Branch 0 taken 10199 times.
✓ Branch 1 taken 390 times.
20788 int new_sequence = (l == &s->layers[0]) &&
3405
12/12
✓ Branch 0 taken 9989 times.
✓ Branch 1 taken 210 times.
✓ Branch 2 taken 9949 times.
✓ Branch 3 taken 40 times.
✓ Branch 4 taken 9947 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9940 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9939 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 17 times.
✓ Branch 11 taken 9922 times.
10199 (IS_IDR(s) || IS_BLA(s) || s->last_eos);
3406 10589 int prev_layers_active_decode = s->layers_active_decode;
3407 10589 int prev_layers_active_output = s->layers_active_output;
3408 int ret;
3409
3410
3/4
✓ Branch 0 taken 244 times.
✓ Branch 1 taken 10345 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 244 times.
10589 if (sps->vps != s->vps && l != &s->layers[0]) {
3411 ✗ av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n");
3412 ✗ set_sps(s, l, NULL);
3413 ✗ return AVERROR_INVALIDDATA;
3414 }
3415
3416
5/6
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 10199 times.
✓ Branch 3 taken 50 times.
✓ Branch 4 taken 340 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 50 times.
10589 if (l != &s->layers[0] && ff_hevc_is_alpha_video(s) && !s->layers[0].cur_frame) {
3417 ✗ av_log(s->avctx, AV_LOG_ERROR, "Alpha layer frame without a base layer frame\n");
3418 ✗ return AVERROR_INVALIDDATA;
3419 }
3420
3421 10589 av_refstruct_replace(&s->pps, pps);
3422
2/2
✓ Branch 0 taken 262 times.
✓ Branch 1 taken 10327 times.
10589 if (l->sps != sps) {
3423 262 const HEVCSPS *sps_base = s->layers[0].sps;
3424 262 enum AVPixelFormat pix_fmt = sps->pix_fmt;
3425
3426
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 252 times.
262 if (l != &s->layers[0]) {
3427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!sps_base) {
3428 ✗ av_log(s->avctx, AV_LOG_ERROR,
3429 "Access unit starts with a non-base layer frame\n");
3430 ✗ return AVERROR_INVALIDDATA;
3431 }
3432
3433 // Files produced by Vision Pro lack VPS extension VUI,
3434 // so the secondary layer has no range information.
3435 // This check avoids failing in such a case.
3436
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (sps_base->pix_fmt == AV_PIX_FMT_YUVJ420P &&
3437 ✗ sps->pix_fmt == AV_PIX_FMT_YUV420P &&
3438 ✗ !sps->vui.common.video_signal_type_present_flag)
3439 ✗ pix_fmt = sps_base->pix_fmt;
3440
3441 // Ignore range mismatch between base layer and alpha layer
3442
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
10 if (ff_hevc_is_alpha_video(s) &&
3443
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 &&
3444 pix_fmt == AV_PIX_FMT_YUVJ420P)
3445 1 pix_fmt = sps_base->pix_fmt;
3446
3447
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (pix_fmt != sps_base->pix_fmt ||
3448
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 sps->width != sps_base->width ||
3449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 sps->height != sps_base->height) {
3450 ✗ av_log(s->avctx, AV_LOG_ERROR,
3451 "Base/non-base layer SPS have unsupported parameter combination\n");
3452 ✗ return AVERROR(ENOSYS);
3453 }
3454 } else {
3455
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 for (int i = 1; i < FF_ARRAY_ELEMS(s->layers); i++)
3456 252 set_sps(s, &s->layers[i], NULL);
3457 }
3458
3459 262 ff_hevc_clear_refs(l);
3460
3461 262 ret = set_sps(s, l, sps);
3462
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 262 times.
262 if (ret < 0)
3463 ✗ return ret;
3464
3465
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 10 times.
262 if (l == &s->layers[0]) {
3466 252 export_stream_params(s, sps);
3467
3468 252 ret = get_format(s, sps);
3469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if (ret < 0) {
3470 ✗ set_sps(s, l, NULL);
3471 ✗ return ret;
3472 }
3473
3474 252 new_sequence = 1;
3475 }
3476 }
3477
3478 10589 memset(l->horizontal_bs, 0, l->bs_width * l->bs_height);
3479 10589 memset(l->vertical_bs, 0, l->bs_width * l->bs_height);
3480 10589 memset(l->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height);
3481 10589 memset(l->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1));
3482 10589 memset(l->tab_slice_address, -1, pic_size_in_ctb * sizeof(*l->tab_slice_address));
3483
3484
4/4
✓ Branch 0 taken 10370 times.
✓ Branch 1 taken 219 times.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 10325 times.
10589 if (IS_IDR(s))
3485 264 ff_hevc_clear_refs(l);
3486
3487 10589 s->slice_idx = 0;
3488 10589 s->first_nal_type = s->nal_unit_type;
3489 10589 s->poc = s->sh.poc;
3490
3491
3/4
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 10013 times.
✓ Branch 2 taken 576 times.
✗ Branch 3 not taken.
10589 if (IS_IRAP(s)) {
3492
10/10
✓ Branch 0 taken 357 times.
✓ Branch 1 taken 219 times.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 45 times.
✓ Branch 4 taken 310 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 303 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 302 times.
✓ Branch 9 taken 1 times.
878 s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) ||
3493
3/4
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 294 times.
302 (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos);
3494 576 s->recovery_poc = HEVC_RECOVERY_END;
3495 }
3496
3497
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10569 times.
10589 if (s->recovery_poc != HEVC_RECOVERY_END &&
3498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 s->sei.recovery_point.has_recovery_poc) {
3499 ✗ if (s->recovery_poc == HEVC_RECOVERY_UNSPECIFIED)
3500 ✗ s->recovery_poc = s->poc + s->sei.recovery_point.recovery_poc_cnt;
3501 ✗ else if (s->poc >= s->recovery_poc)
3502 ✗ s->recovery_poc = HEVC_RECOVERY_END;
3503 }
3504
3505 /* 8.3.1 */
3506
2/2
✓ Branch 0 taken 10247 times.
✓ Branch 1 taken 342 times.
10589 if (s->temporal_id == 0 &&
3507
2/2
✓ Branch 0 taken 7474 times.
✓ Branch 1 taken 2773 times.
10247 s->nal_unit_type != HEVC_NAL_TRAIL_N &&
3508
1/2
✓ Branch 0 taken 7474 times.
✗ Branch 1 not taken.
7474 s->nal_unit_type != HEVC_NAL_TSA_N &&
3509
1/2
✓ Branch 0 taken 7474 times.
✗ Branch 1 not taken.
7474 s->nal_unit_type != HEVC_NAL_STSA_N &&
3510
2/2
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 26 times.
7474 s->nal_unit_type != HEVC_NAL_RADL_N &&
3511
2/2
✓ Branch 0 taken 7426 times.
✓ Branch 1 taken 22 times.
7448 s->nal_unit_type != HEVC_NAL_RADL_R &&
3512
2/2
✓ Branch 0 taken 7040 times.
✓ Branch 1 taken 386 times.
7426 s->nal_unit_type != HEVC_NAL_RASL_N &&
3513
2/2
✓ Branch 0 taken 6563 times.
✓ Branch 1 taken 477 times.
7040 s->nal_unit_type != HEVC_NAL_RASL_R)
3514 6563 s->poc_tid0 = s->poc;
3515
3516
2/2
✓ Branch 0 taken 846 times.
✓ Branch 1 taken 9743 times.
10589 if (pps->tiles_enabled_flag)
3517 846 s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size;
3518
3519
2/2
✓ Branch 0 taken 277 times.
✓ Branch 1 taken 10312 times.
10589 if (new_sequence) {
3520 277 ret = ff_hevc_output_frames(s, prev_layers_active_decode, prev_layers_active_output,
3521 277 0, 0, s->sh.no_output_of_prior_pics_flag);
3522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 277 times.
277 if (ret < 0)
3523 ✗ return ret;
3524 }
3525
3526 10589 ret = export_stream_params_from_sei(s);
3527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (ret < 0)
3528 ✗ return ret;
3529
3530 10589 ret = ff_hevc_set_new_ref(s, l, s->poc);
3531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (ret < 0)
3532 ✗ goto fail;
3533
3534 10589 ret = ff_hevc_frame_rps(s, l);
3535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (ret < 0) {
3536 ✗ av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n");
3537 ✗ goto fail;
3538 }
3539
3540
3/4
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 10013 times.
✓ Branch 2 taken 576 times.
✗ Branch 3 not taken.
10589 if (IS_IRAP(s))
3541 576 s->cur_frame->f->flags |= AV_FRAME_FLAG_KEY;
3542 else
3543 10013 s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY;
3544
3545 21178 s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics &&
3546 ✗ s->sei.common.film_grain_characteristics->present) ||
3547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 s->sei.common.itut_t35.aom_film_grain.enable) &&
3548 ✗ !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
3549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
21178 !ff_decode_skip_all_pixels(s->avctx) &&
3550 ✗ !s->avctx->hwaccel;
3551
3552 10589 ret = set_side_data(s);
3553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (ret < 0)
3554 ✗ goto fail;
3555
3556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (s->cur_frame->needs_fg &&
3557 ✗ (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present &&
3558 ✗ !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id,
3559 ✗ s->cur_frame->f->format) ||
3560 ✗ !av_film_grain_params_select(s->cur_frame->f))) {
3561 ✗ av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown,
3562 "Unsupported film grain parameters. Ignoring film grain.\n");
3563 ✗ s->cur_frame->needs_fg = 0;
3564 }
3565
3566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (s->cur_frame->needs_fg) {
3567 ✗ s->cur_frame->frame_grain->format = s->cur_frame->f->format;
3568 ✗ s->cur_frame->frame_grain->width = s->cur_frame->f->width;
3569 ✗ s->cur_frame->frame_grain->height = s->cur_frame->f->height;
3570 ✗ if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0)
3571 ✗ goto fail;
3572
3573 ✗ ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f);
3574 ✗ if (ret < 0)
3575 ✗ goto fail;
3576 }
3577
3578 10589 s->cur_frame->f->pict_type = 3 - s->sh.slice_type;
3579
3580 10589 ret = ff_hevc_output_frames(s, s->layers_active_decode, s->layers_active_output,
3581 10589 sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics,
3582 10589 sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0);
3583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (ret < 0)
3584 ✗ goto fail;
3585
3586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (s->avctx->hwaccel) {
3587 ✗ AVCodecInternal *avci = s->avctx->internal;
3588 ✗ AVPacket *avpkt = avci->in_pkt;
3589 ✗ ret = FF_HW_CALL(s->avctx, start_frame,
3590 avpkt->buf, NULL, 0);
3591 ✗ if (ret < 0)
3592 ✗ goto fail;
3593 }
3594
3595 // after starting the base-layer frame we know which layers will be decoded,
3596 // so we can now figure out which NALUs to wait for before we can call
3597 // ff_thread_finish_setup()
3598
2/2
✓ Branch 0 taken 10199 times.
✓ Branch 1 taken 390 times.
10589 if (l == &s->layers[0])
3599 10199 s->finish_setup_nal_idx = find_finish_setup_nal(s);
3600
3601
2/2
✓ Branch 0 taken 10198 times.
✓ Branch 1 taken 391 times.
10589 if (nal_idx >= s->finish_setup_nal_idx)
3602 10198 ff_thread_finish_setup(s->avctx);
3603
3604 10589 return 0;
3605
3606 ✗ fail:
3607 ✗ if (l->cur_frame)
3608 ✗ ff_hevc_unref_frame(l->cur_frame, ~0);
3609 ✗ l->cur_frame = NULL;
3610 ✗ s->cur_frame = s->collocated_ref = NULL;
3611 ✗ return ret;
3612 }
3613
3614 ✗ static int verify_md5(HEVCContext *s, AVFrame *frame)
3615 {
3616 ✗ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
3617 char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
3618 int pixel_shift;
3619 ✗ int err = 0;
3620 int i, j;
3621
3622 ✗ if (!desc)
3623 ✗ return AVERROR(EINVAL);
3624
3625 ✗ pixel_shift = desc->comp[0].depth > 8;
3626
3627 /* the checksums are LE, so we have to byteswap for >8bpp formats
3628 * on BE arches */
3629 #if HAVE_BIGENDIAN
3630 if (pixel_shift && !s->checksum_buf) {
3631 av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size,
3632 FFMAX3(frame->linesize[0], frame->linesize[1],
3633 frame->linesize[2]));
3634 if (!s->checksum_buf)
3635 return AVERROR(ENOMEM);
3636 }
3637 #endif
3638
3639 ✗ msg_buf[0] = '\0';
3640 ✗ for (i = 0; frame->data[i]; i++) {
3641 ✗ int width = s->avctx->coded_width;
3642 ✗ int height = s->avctx->coded_height;
3643 ✗ int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width;
3644 ✗ int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height;
3645 uint8_t md5[16];
3646
3647 ✗ av_md5_init(s->md5_ctx);
3648 ✗ for (j = 0; j < h; j++) {
3649 ✗ const uint8_t *src = frame->data[i] + j * frame->linesize[i];
3650 #if HAVE_BIGENDIAN
3651 if (pixel_shift) {
3652 s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
3653 (const uint16_t *) src, w);
3654 src = s->checksum_buf;
3655 }
3656 #endif
3657 ✗ av_md5_update(s->md5_ctx, src, w << pixel_shift);
3658 }
3659 ✗ av_md5_final(s->md5_ctx, md5);
3660
3661 #define MD5_PRI "%016" PRIx64 "%016" PRIx64
3662 #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
3663
3664 ✗ if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
3665 ✗ av_strlcatf(msg_buf, sizeof(msg_buf),
3666 "plane %d - correct " MD5_PRI "; ",
3667 ✗ i, MD5_PRI_ARG(md5));
3668 } else {
3669 ✗ av_strlcatf(msg_buf, sizeof(msg_buf),
3670 "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
3671 ✗ i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i]));
3672 ✗ err = AVERROR_INVALIDDATA;
3673 }
3674 }
3675
3676 ✗ av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
3677 "Verifying checksum for frame with POC %d: %s\n",
3678 s->poc, msg_buf);
3679
3680 ✗ return err;
3681 }
3682
3683 10589 static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l)
3684 {
3685 10589 HEVCFrame *out = l->cur_frame;
3686 const AVFilmGrainParams *fgp;
3687 int ret;
3688
3689
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (out->needs_fg) {
3690 ✗ av_assert0(out->frame_grain->buf[0]);
3691 ✗ fgp = av_film_grain_params_select(out->f);
3692 ✗ switch (fgp->type) {
3693 ✗ case AV_FILM_GRAIN_PARAMS_NONE:
3694 ✗ av_assert0(0);
3695 return AVERROR_BUG;
3696 ✗ case AV_FILM_GRAIN_PARAMS_H274:
3697 ✗ ret = ff_h274_apply_film_grain(out->frame_grain, out->f, fgp);
3698 ✗ break;
3699 ✗ case AV_FILM_GRAIN_PARAMS_AV1:
3700 ✗ ret = ff_aom_apply_film_grain(out->frame_grain, out->f, fgp);
3701 ✗ break;
3702 }
3703 ✗ if (ret < 0) {
3704 ✗ out->needs_fg = 0;
3705 ✗ return ret;
3706 }
3707 }
3708
3709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (s->avctx->hwaccel) {
3710 ✗ ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
3711 ✗ if (ret < 0) {
3712 ✗ av_log(s->avctx, AV_LOG_ERROR,
3713 "hardware accelerator failed to decode picture\n");
3714 ✗ return ret;
3715 }
3716 } else {
3717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
3718 ✗ s->sei.picture_hash.is_md5) {
3719 ✗ ret = verify_md5(s, out->f);
3720 ✗ if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
3721 ✗ return ret;
3722 }
3723 }
3724 10589 s->sei.picture_hash.is_md5 = 0;
3725
3726 10589 av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %zu/%d.\n",
3727 10589 l - s->layers, s->poc);
3728
3729 10589 return 0;
3730 }
3731
3732 29155 static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb)
3733 {
3734
2/2
✓ Branch 0 taken 28917 times.
✓ Branch 1 taken 238 times.
29155 const int layer_idx = s->vps ? s->vps->layer_idx[s->nuh_layer_id] : 0;
3735 HEVCLayerContext *l;
3736 int ret;
3737
3738 // skip layers not requested to be decoded
3739 // layers_active_decode can only change while decoding a base-layer frame,
3740 // so we can check it for non-base layers
3741
1/2
✓ Branch 0 taken 29155 times.
✗ Branch 1 not taken.
29155 if (layer_idx < 0 ||
3742
3/4
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 28639 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 516 times.
29155 (s->nuh_layer_id > 0 && !(s->layers_active_decode & (1 << layer_idx))))
3743 ✗ return 0;
3744
3745 // the first slice of this picture was skipped, so drop the remaining
3746 // slices before parsing, the context is stale for them
3747
4/4
✓ Branch 0 taken 566 times.
✓ Branch 1 taken 28589 times.
✓ Branch 3 taken 486 times.
✓ Branch 4 taken 80 times.
29155 if (s->skipping_frame && !show_bits1(gb))
3748 486 return 0;
3749
3750 28669 ret = hls_slice_header(&s->sh, s, gb);
3751 // Once hls_slice_header has been called, the context is inconsistent with the slice header
3752 // until the context is reinitialized according to the contents of the new slice header
3753 // at the start of decode_slice_data.
3754 28669 s->slice_initialized = 0;
3755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28669 times.
28669 if (ret < 0) {
3756 ✗ return ret;
3757 }
3758
3759
4/4
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 28588 times.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 26 times.
28669 if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
3760
4/4
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 28588 times.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 1 times.
28643 (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
3761
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 28642 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
28642 (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
3762
4/4
✓ Branch 0 taken 27508 times.
✓ Branch 1 taken 1134 times.
✓ Branch 2 taken 1067 times.
✓ Branch 3 taken 26441 times.
28642 ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&
3763
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 2145 times.
2201 s->no_rasl_output_flag)) {
3764
1/2
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
83 if (s->sh.first_slice_in_pic_flag)
3765 83 s->skipping_frame = 1;
3766 83 return 0;
3767 }
3768
2/2
✓ Branch 0 taken 10590 times.
✓ Branch 1 taken 17996 times.
28586 if (s->sh.first_slice_in_pic_flag)
3769 10590 s->skipping_frame = 0;
3770
3771 // switching to a new layer, mark previous layer's frame (if any) as done
3772
2/2
✓ Branch 0 taken 771 times.
✓ Branch 1 taken 27815 times.
28586 if (s->cur_layer != layer_idx &&
3773
2/2
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 381 times.
771 s->layers[s->cur_layer].cur_frame &&
3774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
390 s->avctx->active_thread_type == FF_THREAD_FRAME)
3775 ✗ ff_progress_frame_report(&s->layers[s->cur_layer].cur_frame->tf, INT_MAX);
3776
3777 28586 s->cur_layer = layer_idx;
3778 28586 l = &s->layers[s->cur_layer];
3779
3780
2/2
✓ Branch 0 taken 10590 times.
✓ Branch 1 taken 17996 times.
28586 if (s->sh.first_slice_in_pic_flag) {
3781
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10589 times.
10590 if (l->cur_frame) {
3782 1 av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
3783 1 return AVERROR_INVALIDDATA;
3784 }
3785
3786 10589 ret = hevc_frame_start(s, l, nal_idx);
3787
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10589 times.
10589 if (ret < 0)
3788 ✗ return ret;
3789
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17996 times.
17996 } else if (!l->cur_frame) {
3790 ✗ av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
3791 ✗ return AVERROR_INVALIDDATA;
3792 }
3793
3794
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28585 times.
28585 if (s->nal_unit_type != s->first_nal_type) {
3795 ✗ av_log(s->avctx, AV_LOG_ERROR,
3796 "Non-matching NAL types of the VCL NALUs: %d %d\n",
3797 ✗ s->first_nal_type, s->nal_unit_type);
3798 ✗ return AVERROR_INVALIDDATA;
3799 }
3800
3801 28585 ret = decode_slice_data(s, l, &s->pkt.nals[nal_idx], gb);
3802
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28584 times.
28585 if (ret < 0)
3803 1 return ret;
3804
3805 28584 return 0;
3806 }
3807
3808 40568 static int decode_nal_unit(HEVCContext *s, unsigned nal_idx)
3809 {
3810 40568 H2645NAL *nal = &s->pkt.nals[nal_idx];
3811 40568 GetBitContext gb = nal->gb;
3812 int ret;
3813
3814 40568 s->nal_unit_type = nal->type;
3815 40568 s->nuh_layer_id = nal->nuh_layer_id;
3816 40568 s->temporal_id = nal->temporal_id;
3817
3818
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 40568 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
40568 if (FF_HW_HAS_CB(s->avctx, decode_params) &&
3819 ✗ (s->nal_unit_type == HEVC_NAL_VPS ||
3820 ✗ s->nal_unit_type == HEVC_NAL_SPS ||
3821 ✗ s->nal_unit_type == HEVC_NAL_PPS ||
3822 ✗ s->nal_unit_type == HEVC_NAL_SEI_PREFIX ||
3823 ✗ s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) {
3824 ✗ ret = FF_HW_CALL(s->avctx, decode_params,
3825 nal->type, nal->raw_data, nal->raw_size);
3826 ✗ if (ret < 0)
3827 ✗ goto fail;
3828 }
3829
3830
6/7
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 492 times.
✓ Branch 2 taken 1582 times.
✓ Branch 3 taken 8185 times.
✓ Branch 4 taken 29155 times.
✓ Branch 5 taken 674 times.
✗ Branch 6 not taken.
40568 switch (s->nal_unit_type) {
3831 480 case HEVC_NAL_VPS:
3832 480 ret = ff_hevc_decode_nal_vps(&gb, s->avctx, &s->ps);
3833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 480 times.
480 if (ret < 0)
3834 ✗ goto fail;
3835 480 break;
3836 492 case HEVC_NAL_SPS:
3837 492 ret = ff_hevc_decode_nal_sps(&gb, s->avctx, &s->ps,
3838 492 nal->nuh_layer_id, s->apply_defdispwin);
3839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 492 times.
492 if (ret < 0)
3840 ✗ goto fail;
3841 492 break;
3842 1582 case HEVC_NAL_PPS:
3843 1582 ret = ff_hevc_decode_nal_pps(&gb, s->avctx, &s->ps);
3844
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1580 times.
1582 if (ret < 0)
3845 2 goto fail;
3846 1580 break;
3847 8185 case HEVC_NAL_SEI_PREFIX:
3848 case HEVC_NAL_SEI_SUFFIX:
3849 8185 ret = ff_hevc_decode_nal_sei(&gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type);
3850
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 8119 times.
8185 if (ret < 0)
3851 66 goto fail;
3852 8119 break;
3853 29155 case HEVC_NAL_TRAIL_R:
3854 case HEVC_NAL_TRAIL_N:
3855 case HEVC_NAL_TSA_N:
3856 case HEVC_NAL_TSA_R:
3857 case HEVC_NAL_STSA_N:
3858 case HEVC_NAL_STSA_R:
3859 case HEVC_NAL_BLA_W_LP:
3860 case HEVC_NAL_BLA_W_RADL:
3861 case HEVC_NAL_BLA_N_LP:
3862 case HEVC_NAL_IDR_W_RADL:
3863 case HEVC_NAL_IDR_N_LP:
3864 case HEVC_NAL_CRA_NUT:
3865 case HEVC_NAL_RADL_N:
3866 case HEVC_NAL_RADL_R:
3867 case HEVC_NAL_RASL_N:
3868 case HEVC_NAL_RASL_R:
3869 29155 ret = decode_slice(s, nal_idx, &gb);
3870
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 29153 times.
29155 if (ret < 0)
3871 2 goto fail;
3872 29153 break;
3873 674 case HEVC_NAL_EOS_NUT:
3874 case HEVC_NAL_EOB_NUT:
3875 case HEVC_NAL_AUD:
3876 case HEVC_NAL_FD_NUT:
3877 case HEVC_NAL_UNSPEC62: // Dolby Vision RPU
3878 case HEVC_NAL_UNSPEC63: // Dolby Vision EL
3879 674 break;
3880 ✗ default:
3881 ✗ av_log(s->avctx, AV_LOG_VERBOSE,
3882 ✗ "Skipping NAL unit %d\n", s->nal_unit_type);
3883 }
3884
3885 40498 return 0;
3886 70 fail:
3887
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 if (ret == AVERROR_INVALIDDATA &&
3888
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 !(s->avctx->err_recognition & AV_EF_EXPLODE)) {
3889 70 av_log(s->avctx, AV_LOG_WARNING,
3890 70 "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type);
3891 70 return 0;
3892 }
3893 ✗ return ret;
3894 }
3895
3896 472 static void decode_reset_recovery_point(HEVCContext *s)
3897 {
3898 472 s->recovery_poc = HEVC_RECOVERY_UNSPECIFIED;
3899 472 s->sei.recovery_point.has_recovery_poc = 0;
3900 472 }
3901
3902 385 static int export_stream_params_from_slice(HEVCContext *s, const H2645NAL *nal)
3903 {
3904 385 GetBitContext gb = nal->gb;
3905 const HEVCSPS *sps;
3906 const HEVCVPS *vps;
3907 unsigned pps_id;
3908
3909
2/2
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 66 times.
704 int is_slice = nal->type <= HEVC_NAL_RASL_R ||
3910
1/2
✓ Branch 0 taken 319 times.
✗ Branch 1 not taken.
319 (nal->type >= HEVC_NAL_BLA_W_LP &&
3911
2/2
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 90 times.
319 nal->type <= HEVC_NAL_CRA_NUT);
3912
3913
3/4
✓ Branch 0 taken 295 times.
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 295 times.
385 if (!is_slice || nal->nuh_layer_id)
3914 90 return 0;
3915
3916 295 skip_bits1(&gb); // first_slice_segment_in_pic_flag
3917
2/2
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 66 times.
295 if (nal->type >= HEVC_NAL_BLA_W_LP)
3918 229 skip_bits1(&gb); // no_output_of_prior_pics_flag
3919 295 pps_id = get_ue_golomb_long(&gb);
3920
3/4
✓ Branch 0 taken 295 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 229 times.
295 if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id])
3921 66 return 0;
3922 229 sps = s->ps.pps_list[pps_id]->sps;
3923 229 vps = sps->vps;
3924
3925 229 export_stream_params(s, sps);
3926
3927
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 224 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
229 if (vps->nb_layers == 2 && vps->layer_id_in_nuh[1] &&
3928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY) {
3929 ✗ enum AVPixelFormat alpha_fmt = map_to_alpha_format(s, sps->pix_fmt);
3930
3931 ✗ if (alpha_fmt != AV_PIX_FMT_NONE)
3932 ✗ s->avctx->pix_fmt = alpha_fmt;
3933 }
3934
3935 229 return 1;
3936 }
3937
3938 10607 static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
3939 {
3940 10607 int ret = 0;
3941 10607 int eos_at_start = 1;
3942 10607 int params_exported = 0;
3943
2/2
✓ Branch 0 taken 377 times.
✓ Branch 1 taken 10230 times.
10607 int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING;
3944
3945 10607 s->cur_frame = s->collocated_ref = NULL;
3946 10607 s->last_eos = s->eos;
3947 10607 s->eos = 0;
3948 10607 s->slice_initialized = 0;
3949
2/2
✓ Branch 0 taken 467 times.
✓ Branch 1 taken 10140 times.
10607 if (s->last_eos)
3950 467 decode_reset_recovery_point(s);
3951
3952
2/2
✓ Branch 0 taken 21214 times.
✓ Branch 1 taken 10607 times.
31821 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3953 21214 HEVCLayerContext *l = &s->layers[i];
3954 21214 l->cur_frame = NULL;
3955 }
3956
3957 /* split the input packet into NAL units, so we know the upper bound on the
3958 * number of slices in the frame */
3959 10607 ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx,
3960 10607 s->nal_length_size, s->avctx->codec_id, flags);
3961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10607 times.
10607 if (ret < 0) {
3962 ✗ av_log(s->avctx, AV_LOG_ERROR,
3963 "Error splitting the input into NAL units.\n");
3964 ✗ return ret;
3965 }
3966
3967
2/2
✓ Branch 0 taken 41805 times.
✓ Branch 1 taken 10607 times.
52412 for (int i = 0; i < s->pkt.nb_nals; i++) {
3968
2/2
✓ Branch 0 taken 41804 times.
✓ Branch 1 taken 1 times.
41805 if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT ||
3969
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 41800 times.
41804 s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) {
3970
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (eos_at_start) {
3971 5 s->last_eos = 1;
3972 5 decode_reset_recovery_point(s);
3973 } else {
3974 ✗ s->eos = 1;
3975 }
3976 } else {
3977 41800 eos_at_start = 0;
3978 }
3979 }
3980
3981 /*
3982 * Check for RPU delimiter.
3983 *
3984 * Dolby Vision RPUs masquerade as unregistered NALs of type 62.
3985 *
3986 * We have to do this check here an create the rpu buffer, since RPUs are appended
3987 * to the end of an AU; they are normally the last non-EOB/EOS NAL in the AU.
3988 */
3989 10607 H2645NAL *rpu_nal = NULL;
3990
2/2
✓ Branch 0 taken 31197 times.
✓ Branch 1 taken 10605 times.
41802 for (int i = s->pkt.nb_nals - 1; i > 0 ; i--) {
3991
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 31195 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
31197 if (s->pkt.nals[i].type == HEVC_NAL_UNSPEC62 && s->pkt.nals[i].size > 2
3992
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 && !s->pkt.nals[i].nuh_layer_id && !s->pkt.nals[i].temporal_id) {
3993 2 rpu_nal = &s->pkt.nals[i];
3994 2 break;
3995 }
3996 }
3997
3998
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10605 times.
10607 if (rpu_nal) {
3999
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->rpu_buf) {
4000 ✗ av_buffer_unref(&s->rpu_buf);
4001 ✗ av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n");
4002 }
4003
4004 2 s->rpu_buf = av_buffer_alloc(rpu_nal->raw_size - 2);
4005
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!s->rpu_buf) {
4006 ✗ ret = AVERROR(ENOMEM);
4007 ✗ goto fail;
4008 }
4009 2 memcpy(s->rpu_buf->data, rpu_nal->raw_data + 2, rpu_nal->raw_size - 2);
4010
4011 2 ret = ff_dovi_rpu_parse(&s->dovi_ctx, rpu_nal->data + 2, rpu_nal->size - 2,
4012 2 s->avctx->err_recognition);
4013
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0) {
4014 ✗ av_buffer_unref(&s->rpu_buf);
4015 ✗ av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n");
4016 /* ignore */
4017 }
4018 }
4019
4020 /* decode the NAL units */
4021
2/2
✓ Branch 0 taken 41805 times.
✓ Branch 1 taken 10607 times.
52412 for (int i = 0; i < s->pkt.nb_nals; i++) {
4022 41805 H2645NAL *nal = &s->pkt.nals[i];
4023
4024
2/2
✓ Branch 0 taken 1958 times.
✓ Branch 1 taken 39847 times.
41805 if (s->avctx->skip_frame >= AVDISCARD_ALL) {
4025
2/2
✓ Branch 0 taken 1226 times.
✓ Branch 1 taken 732 times.
1958 switch (nal->type) {
4026 1226 case HEVC_NAL_VPS:
4027 case HEVC_NAL_SPS:
4028 case HEVC_NAL_PPS:
4029 case HEVC_NAL_SEI_PREFIX:
4030 case HEVC_NAL_SEI_SUFFIX:
4031 1226 break;
4032 732 default:
4033
3/4
✓ Branch 0 taken 732 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 385 times.
✓ Branch 3 taken 347 times.
732 if (!s->layers[0].sps && !params_exported)
4034 385 params_exported = export_stream_params_from_slice(s, nal);
4035 732 continue;
4036 }
4037
4/4
✓ Branch 0 taken 1095 times.
✓ Branch 1 taken 38752 times.
✓ Branch 2 taken 505 times.
✓ Branch 3 taken 590 times.
40942 } else if (s->avctx->skip_frame >= AVDISCARD_NONREF &&
4038 1095 ff_hevc_nal_is_nonref(nal->type))
4039 505 continue;
4040
4041 40568 ret = decode_nal_unit(s, i);
4042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40568 times.
40568 if (ret < 0) {
4043 ✗ av_log(s->avctx, AV_LOG_WARNING,
4044 "Error parsing NAL unit #%d.\n", i);
4045 ✗ goto fail;
4046 }
4047 }
4048
4049
2/2
✓ Branch 0 taken 10378 times.
✓ Branch 1 taken 229 times.
10607 if (params_exported) {
4050 229 ret = export_stream_params_from_sei(s);
4051
1/2
✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
229 if (ret < 0)
4052 ✗ goto fail;
4053 }
4054
4055 10607 fail:
4056
2/2
✓ Branch 0 taken 21214 times.
✓ Branch 1 taken 10607 times.
31821 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
4057 21214 HEVCLayerContext *l = &s->layers[i];
4058
4059
2/2
✓ Branch 0 taken 10625 times.
✓ Branch 1 taken 10589 times.
21214 if (!l->cur_frame)
4060 10625 continue;
4061
4062
1/2
✓ Branch 0 taken 10589 times.
✗ Branch 1 not taken.
10589 if (ret >= 0)
4063 10589 ret = hevc_frame_end(s, l);
4064
4065
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 10556 times.
10589 if (s->avctx->active_thread_type == FF_THREAD_FRAME)
4066 33 ff_progress_frame_report(&l->cur_frame->tf, INT_MAX);
4067 }
4068
4069 10607 return ret;
4070 }
4071
4072 383 static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first)
4073 {
4074 int ret, i;
4075
4076 383 ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff,
4077 383 &s->nal_length_size, s->avctx->err_recognition,
4078 383 s->apply_defdispwin, s->avctx);
4079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 383 times.
383 if (ret < 0)
4080 ✗ return ret;
4081
4082 /* export stream parameters from the first SPS */
4083
2/2
✓ Branch 0 taken 413 times.
✓ Branch 1 taken 2 times.
415 for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) {
4084
4/4
✓ Branch 0 taken 397 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 381 times.
✓ Branch 3 taken 16 times.
413 if (first && s->ps.sps_list[i]) {
4085 381 const HEVCSPS *sps = s->ps.sps_list[i];
4086 381 export_stream_params(s, sps);
4087
4088 381 ret = export_multilayer(s, sps->vps);
4089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 381 times.
381 if (ret < 0)
4090 ✗ return ret;
4091
4092 381 break;
4093 }
4094 }
4095
4096 /* export stream parameters from SEI */
4097 383 ret = export_stream_params_from_sei(s);
4098
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 383 times.
383 if (ret < 0)
4099 ✗ return ret;
4100
4101 383 return 0;
4102 }
4103
4104 22575 static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame)
4105 {
4106 22575 HEVCContext *s = avctx->priv_data;
4107 22575 AVCodecInternal *avci = avctx->internal;
4108 22575 AVPacket *avpkt = avci->in_pkt;
4109
4110 int ret;
4111 uint8_t *sd;
4112 size_t sd_size;
4113
4114 22575 s->pkt_dts = AV_NOPTS_VALUE;
4115
4116
2/2
✓ Branch 1 taken 980 times.
✓ Branch 2 taken 21595 times.
22575 if (av_container_fifo_can_read(s->output_fifo))
4117 980 goto do_output;
4118
4119 21595 av_packet_unref(avpkt);
4120 21595 ret = ff_decode_get_packet(avctx, avpkt);
4121
2/2
✓ Branch 0 taken 381 times.
✓ Branch 1 taken 21214 times.
21595 if (ret == AVERROR_EOF) {
4122 381 ret = ff_hevc_output_frames(s, s->layers_active_decode,
4123 s->layers_active_output, 0, 0, 0);
4124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 381 times.
381 if (ret < 0)
4125 ✗ return ret;
4126 381 goto do_output;
4127
2/2
✓ Branch 0 taken 10607 times.
✓ Branch 1 taken 10607 times.
21214 } else if (ret < 0)
4128 10607 return ret;
4129
4130 10607 s->pkt_dts = avpkt->dts;
4131
4132 10607 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size);
4133
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10606 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
10607 if (sd && sd_size > 0) {
4134 1 ret = hevc_decode_extradata(s, sd, sd_size, 0);
4135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
4136 ✗ return ret;
4137 }
4138
4139 10607 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size);
4140
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10607 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10607 if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) {
4141 ✗ int old = s->dovi_ctx.cfg.dv_profile;
4142 ✗ s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd;
4143 ✗ if (old)
4144 ✗ av_log(avctx, AV_LOG_DEBUG,
4145 "New DOVI configuration record from input packet (profile %d -> %u).\n",
4146 ✗ old, s->dovi_ctx.cfg.dv_profile);
4147 }
4148
4149 10607 ret = decode_nal_units(s, avpkt->data, avpkt->size);
4150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10607 times.
10607 if (ret < 0)
4151 ✗ return ret;
4152
4153 10607 do_output:
4154
2/2
✓ Branch 1 taken 10435 times.
✓ Branch 2 taken 1533 times.
11968 if (av_container_fifo_read(s->output_fifo, frame, 0) >= 0) {
4155
1/2
✓ Branch 0 taken 10435 times.
✗ Branch 1 not taken.
10435 if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))
4156 10435 av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
4157
4158 10435 return 0;
4159 }
4160
4161
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1297 times.
1533 return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN);
4162 }
4163
4164 67 static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
4165 {
4166 int ret;
4167
4168 67 ff_progress_frame_ref(&dst->tf, &src->tf);
4169
4170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (src->needs_fg) {
4171 ✗ ret = av_frame_ref(dst->frame_grain, src->frame_grain);
4172 ✗ if (ret < 0) {
4173 ✗ ff_hevc_unref_frame(dst, ~0);
4174 ✗ return ret;
4175 }
4176 ✗ dst->needs_fg = 1;
4177 }
4178
4179 67 dst->pps = av_refstruct_ref_c(src->pps);
4180 67 dst->tab_mvf = av_refstruct_ref(src->tab_mvf);
4181 67 dst->rpl_tab = av_refstruct_ref(src->rpl_tab);
4182 67 dst->rpl = av_refstruct_ref(src->rpl);
4183 67 dst->nb_rpl_elems = src->nb_rpl_elems;
4184
4185 67 dst->poc = src->poc;
4186 67 dst->ctb_count = src->ctb_count;
4187 67 dst->flags = src->flags;
4188
4189 67 dst->base_layer_frame = src->base_layer_frame;
4190
4191 67 av_refstruct_replace(&dst->hwaccel_picture_private,
4192 67 src->hwaccel_picture_private);
4193
4194 67 return 0;
4195 }
4196
4197 622 static av_cold int hevc_decode_free(AVCodecContext *avctx)
4198 {
4199 622 HEVCContext *s = avctx->priv_data;
4200
4201
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 622 times.
1866 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
4202 1244 pic_arrays_free(&s->layers[i]);
4203 1244 av_refstruct_unref(&s->layers[i].sps);
4204 }
4205
4206 622 av_refstruct_unref(&s->vps);
4207 622 av_refstruct_unref(&s->pps);
4208
4209 622 ff_dovi_ctx_unref(&s->dovi_ctx);
4210 622 av_buffer_unref(&s->rpu_buf);
4211
4212 622 av_freep(&s->md5_ctx);
4213
4214 622 av_container_fifo_free(&s->output_fifo);
4215
4216
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 622 times.
1866 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
4217 1244 HEVCLayerContext *l = &s->layers[layer];
4218
2/2
✓ Branch 0 taken 39808 times.
✓ Branch 1 taken 1244 times.
41052 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
4219 39808 ff_hevc_unref_frame(&l->DPB[i], ~0);
4220 39808 av_frame_free(&l->DPB[i].frame_grain);
4221 }
4222 }
4223
4224 622 ff_hevc_ps_uninit(&s->ps);
4225
4226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 622 times.
622 for (int i = 0; i < s->nb_wpp_progress; i++)
4227 ✗ ff_thread_progress_destroy(&s->wpp_progress[i]);
4228 622 av_freep(&s->wpp_progress);
4229
4230 622 av_freep(&s->sh.entry_point_offset);
4231 622 av_freep(&s->sh.offset);
4232 622 av_freep(&s->sh.size);
4233
4234 622 av_freep(&s->local_ctx);
4235
4236 622 ff_h2645_packet_uninit(&s->pkt);
4237
4238 622 ff_hevc_reset_sei(&s->sei);
4239
4240 622 return 0;
4241 }
4242
4243 622 static av_cold int hevc_init_context(AVCodecContext *avctx)
4244 {
4245 622 HEVCContext *s = avctx->priv_data;
4246
4247 622 s->avctx = avctx;
4248
4249 622 s->local_ctx = av_mallocz(sizeof(*s->local_ctx));
4250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 622 times.
622 if (!s->local_ctx)
4251 ✗ return AVERROR(ENOMEM);
4252 622 s->nb_local_ctx = 1;
4253
4254 622 s->local_ctx[0].parent = s;
4255 622 s->local_ctx[0].logctx = avctx;
4256 622 s->local_ctx[0].common_cabac_state = &s->cabac;
4257
4258 622 s->output_fifo = av_container_fifo_alloc_avframe(0);
4259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 622 times.
622 if (!s->output_fifo)
4260 ✗ return AVERROR(ENOMEM);
4261
4262
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 622 times.
1866 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
4263 1244 HEVCLayerContext *l = &s->layers[layer];
4264
2/2
✓ Branch 0 taken 39808 times.
✓ Branch 1 taken 1244 times.
41052 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
4265 39808 l->DPB[i].frame_grain = av_frame_alloc();
4266
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39808 times.
39808 if (!l->DPB[i].frame_grain)
4267 ✗ return AVERROR(ENOMEM);
4268 }
4269 }
4270
4271 622 s->md5_ctx = av_md5_alloc();
4272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 622 times.
622 if (!s->md5_ctx)
4273 ✗ return AVERROR(ENOMEM);
4274
4275 622 ff_bswapdsp_init(&s->bdsp);
4276
4277 622 s->dovi_ctx.logctx = avctx;
4278 622 s->eos = 0;
4279
4280 622 ff_hevc_reset_sei(&s->sei);
4281
4282 622 return 0;
4283 }
4284
4285 #if HAVE_THREADS
4286 32 static int hevc_update_thread_context(AVCodecContext *dst,
4287 const AVCodecContext *src)
4288 {
4289 32 HEVCContext *s = dst->priv_data;
4290 32 HEVCContext *s0 = src->priv_data;
4291 int ret;
4292
4293
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
96 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
4294 64 HEVCLayerContext *l = &s->layers[layer];
4295 64 const HEVCLayerContext *l0 = &s0->layers[layer];
4296
2/2
✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 64 times.
2112 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
4297 2048 ff_hevc_unref_frame(&l->DPB[i], ~0);
4298
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1981 times.
2048 if (l0->DPB[i].f) {
4299 67 ret = hevc_ref_frame(&l->DPB[i], &l0->DPB[i]);
4300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (ret < 0)
4301 ✗ return ret;
4302 }
4303 }
4304
4305
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
64 if (l->sps != l0->sps) {
4306 1 ret = set_sps(s, l, l0->sps);
4307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
4308 ✗ return ret;
4309 }
4310 }
4311
4312
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++)
4313 512 av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]);
4314
4315
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++)
4316 512 av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]);
4317
4318
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++)
4319 2048 av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]);
4320
4321 // PPS do not persist between frames
4322 32 av_refstruct_unref(&s->pps);
4323
4324 32 s->poc_tid0 = s0->poc_tid0;
4325 32 s->eos = s0->eos;
4326 32 s->no_rasl_output_flag = s0->no_rasl_output_flag;
4327 32 s->skipping_frame = s0->skipping_frame;
4328
4329 32 s->is_nalff = s0->is_nalff;
4330 32 s->nal_length_size = s0->nal_length_size;
4331 32 s->layers_active_decode = s0->layers_active_decode;
4332 32 s->layers_active_output = s0->layers_active_output;
4333
4334 32 s->film_grain_warning_shown = s0->film_grain_warning_shown;
4335
4336
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (s->nb_view_ids != s0->nb_view_ids ||
4337
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)) {
4338 ✗ av_freep(&s->view_ids);
4339 ✗ s->nb_view_ids = 0;
4340
4341 ✗ if (s0->nb_view_ids) {
4342 ✗ s->view_ids = av_memdup(s0->view_ids, s0->nb_view_ids * sizeof(*s0->view_ids));
4343 ✗ if (!s->view_ids)
4344 ✗ return AVERROR(ENOMEM);
4345 ✗ s->nb_view_ids = s0->nb_view_ids;
4346 }
4347 }
4348
4349 32 ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common);
4350
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4351 ✗ return ret;
4352
4353 32 ret = av_buffer_replace(&s->sei.common.itut_t35.hdr_plus,
4354 32 s0->sei.common.itut_t35.hdr_plus);
4355
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4356 ✗ return ret;
4357
4358 32 ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf);
4359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4360 ✗ return ret;
4361
4362 32 ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx);
4363
4364 32 ret = av_buffer_replace(&s->sei.common.itut_t35.hdr_vivid,
4365 32 s0->sei.common.itut_t35.hdr_vivid);
4366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4367 ✗ return ret;
4368
4369 32 s->sei.common.frame_packing = s0->sei.common.frame_packing;
4370 32 s->sei.common.display_orientation = s0->sei.common.display_orientation;
4371 32 s->sei.tdrdi = s0->sei.tdrdi;
4372 32 s->sei.recovery_point = s0->sei.recovery_point;
4373 32 s->recovery_poc = s0->recovery_poc;
4374
4375 32 return 0;
4376 }
4377 #endif
4378
4379 382 static int hevc_sei_to_context(AVCodecContext *avctx, HEVCSEI *sei)
4380 {
4381 int ret;
4382
4383
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 378 times.
382 if (sei->tdrdi.present) {
4384 AVBufferRef *buf;
4385 size_t size;
4386 4 AV3DReferenceDisplaysInfo *tdrdi = av_tdrdi_alloc(sei->tdrdi.num_ref_displays, &size);
4387
4388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!tdrdi)
4389 ✗ return AVERROR(ENOMEM);
4390
4391 4 buf = av_buffer_create((uint8_t *)tdrdi, size, NULL, NULL, 0);
4392
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!buf) {
4393 ✗ av_free(tdrdi);
4394 ✗ return AVERROR(ENOMEM);
4395 }
4396
4397 4 tdrdi->prec_ref_display_width = sei->tdrdi.prec_ref_display_width;
4398 4 tdrdi->ref_viewing_distance_flag = sei->tdrdi.ref_viewing_distance_flag;
4399 4 tdrdi->prec_ref_viewing_dist = sei->tdrdi.prec_ref_viewing_dist;
4400 4 tdrdi->num_ref_displays = sei->tdrdi.num_ref_displays;
4401
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (int i = 0; i < sei->tdrdi.num_ref_displays; i++) {
4402 4 AV3DReferenceDisplay *display = av_tdrdi_get_display(tdrdi, i);
4403
4404 4 display->left_view_id = sei->tdrdi.left_view_id[i];
4405 4 display->right_view_id = sei->tdrdi.right_view_id[i];
4406 4 display->exponent_ref_display_width = sei->tdrdi.exponent_ref_display_width[i];
4407 4 display->mantissa_ref_display_width = sei->tdrdi.mantissa_ref_display_width[i];
4408 4 display->exponent_ref_viewing_distance = sei->tdrdi.exponent_ref_viewing_distance[i];
4409 4 display->mantissa_ref_viewing_distance = sei->tdrdi.mantissa_ref_viewing_distance[i];
4410 4 display->additional_shift_present_flag = sei->tdrdi.additional_shift_present_flag[i];
4411 4 display->num_sample_shift = sei->tdrdi.num_sample_shift[i];
4412 }
4413 4 ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data,
4414 AV_FRAME_DATA_3D_REFERENCE_DISPLAYS, &buf);
4415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0) {
4416 ✗ av_buffer_unref(&buf);
4417 ✗ return ret;
4418 }
4419 }
4420
4421 382 ret = ff_h2645_sei_to_context(avctx, &sei->common);
4422
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382 times.
382 if (ret < 0)
4423 ✗ return ret;
4424
4425 382 return 0;
4426 }
4427
4428 622 static av_cold int hevc_decode_init(AVCodecContext *avctx)
4429 {
4430 622 HEVCContext *s = avctx->priv_data;
4431 int ret;
4432
4433 622 ret = hevc_init_context(avctx);
4434
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 622 times.
622 if (ret < 0)
4435 ✗ return ret;
4436
4437 622 s->sei.picture_timing.picture_struct = 0;
4438 622 s->eos = 1;
4439
4440 622 atomic_init(&s->wpp_err, 0);
4441
4442
2/2
✓ Branch 0 taken 621 times.
✓ Branch 1 taken 1 times.
622 if (!avctx->internal->is_copy) {
4443 const AVPacketSideData *sd;
4444
4445
3/4
✓ Branch 0 taken 382 times.
✓ Branch 1 taken 239 times.
✓ Branch 2 taken 382 times.
✗ Branch 3 not taken.
621 if (avctx->extradata_size > 0 && avctx->extradata) {
4446 382 ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1);
4447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382 times.
382 if (ret < 0) {
4448 ✗ return ret;
4449 }
4450
4451 382 ret = hevc_sei_to_context(avctx, &s->sei);
4452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382 times.
382 if (ret < 0)
4453 ✗ return ret;
4454 }
4455
4456 621 sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF);
4457
3/4
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 586 times.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
621 if (sd && sd->size >= sizeof(s->dovi_ctx.cfg))
4458 35 s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data;
4459 }
4460
4461 622 return 0;
4462 }
4463
4464 ✗ static av_cold void hevc_decode_flush(AVCodecContext *avctx)
4465 {
4466 ✗ HEVCContext *s = avctx->priv_data;
4467 ✗ ff_hevc_flush_dpb(s);
4468 ✗ ff_hevc_reset_sei(&s->sei);
4469 ✗ ff_dovi_ctx_flush(&s->dovi_ctx);
4470 ✗ av_buffer_unref(&s->rpu_buf);
4471 ✗ s->eos = 1;
4472 ✗ s->skipping_frame = 0;
4473
4474 ✗ if (FF_HW_HAS_CB(avctx, flush))
4475 ✗ FF_HW_SIMPLE_CALL(avctx, flush);
4476 ✗ }
4477
4478 #define OFFSET(x) offsetof(HEVCContext, x)
4479 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
4480
4481 static const AVOption options[] = {
4482 { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin),
4483 AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4484 { "strict-displaywin", "strictly apply default display window size", OFFSET(apply_defdispwin),
4485 AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4486 { "view_ids", "Array of view IDs that should be decoded and output; a single -1 to decode all views",
4487 .offset = OFFSET(view_ids), .type = AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY,
4488 .min = -1, .max = INT_MAX, .flags = PAR },
4489 { "view_ids_available", "Array of available view IDs is exported here",
4490 .offset = OFFSET(view_ids_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4491 .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
4492 { "view_pos_available", "Array of view positions for view_ids_available is exported here, as AVStereo3DView",
4493 .offset = OFFSET(view_pos_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4494 .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY, .unit = "view_pos" },
4495 { "unspecified", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_UNSPEC }, .unit = "view_pos" },
4496 { "left", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_LEFT }, .unit = "view_pos" },
4497 { "right", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_RIGHT }, .unit = "view_pos" },
4498
4499 { NULL },
4500 };
4501
4502 static const AVClass hevc_decoder_class = {
4503 .class_name = "HEVC decoder",
4504 .item_name = av_default_item_name,
4505 .option = options,
4506 .version = LIBAVUTIL_VERSION_INT,
4507 };
4508
4509 const FFCodec ff_hevc_decoder = {
4510 .p.name = "hevc",
4511 CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"),
4512 .p.type = AVMEDIA_TYPE_VIDEO,
4513 .p.id = AV_CODEC_ID_HEVC,
4514 .priv_data_size = sizeof(HEVCContext),
4515 .p.priv_class = &hevc_decoder_class,
4516 .init = hevc_decode_init,
4517 .close = hevc_decode_free,
4518 FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame),
4519 .flush = hevc_decode_flush,
4520 UPDATE_THREAD_CONTEXT(hevc_update_thread_context),
4521 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
4522 AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
4523 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
4524 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
4525 FF_CODEC_CAP_USES_PROGRESSFRAMES |
4526 FF_CODEC_CAP_INIT_CLEANUP,
4527 .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
4528 .hw_configs = (const AVCodecHWConfigInternal *const []) {
4529 #if CONFIG_HEVC_DXVA2_HWACCEL
4530 HWACCEL_DXVA2(hevc),
4531 #endif
4532 #if CONFIG_HEVC_D3D11VA_HWACCEL
4533 HWACCEL_D3D11VA(hevc),
4534 #endif
4535 #if CONFIG_HEVC_D3D11VA2_HWACCEL
4536 HWACCEL_D3D11VA2(hevc),
4537 #endif
4538 #if CONFIG_HEVC_D3D12VA_HWACCEL
4539 HWACCEL_D3D12VA(hevc),
4540 #endif
4541 #if CONFIG_HEVC_NVDEC_HWACCEL
4542 HWACCEL_NVDEC(hevc),
4543 #endif
4544 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
4545 HWACCEL_NVDEC_CUARRAY(hevc),
4546 #endif
4547 #if CONFIG_HEVC_VAAPI_HWACCEL
4548 HWACCEL_VAAPI(hevc),
4549 #endif
4550 #if CONFIG_HEVC_VDPAU_HWACCEL
4551 HWACCEL_VDPAU(hevc),
4552 #endif
4553 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
4554 HWACCEL_VIDEOTOOLBOX(hevc),
4555 #endif
4556 #if CONFIG_HEVC_VULKAN_HWACCEL
4557 HWACCEL_VULKAN(hevc),
4558 #endif
4559 NULL
4560 },
4561 };
4562