FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc/hevcdec.c
Date: 2026-08-31 11:24:46
Exec Total Coverage
Lines: 1981 2465 80.4%
Functions: 51 56 91.1%
Branches: 1388 1845 75.2%

Line Branch Exec Source
1 /*
2 * HEVC video Decoder
3 *
4 * Copyright (C) 2012 - 2013 Guillaume Martres
5 * Copyright (C) 2012 - 2013 Mickael Raulet
6 * Copyright (C) 2012 - 2013 Gildas Cocherel
7 * Copyright (C) 2012 - 2013 Wassim Hamidouche
8 *
9 * This file is part of FFmpeg.
10 *
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #include "config_components.h"
27
28 #include "libavutil/attributes.h"
29 #include "libavutil/avstring.h"
30 #include "libavutil/common.h"
31 #include "libavutil/container_fifo.h"
32 #include "libavutil/film_grain_params.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/md5.h"
35 #include "libavutil/mem.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/pixdesc.h"
38 #include "libavutil/stereo3d.h"
39 #include "libavutil/tdrdi.h"
40 #include "libavutil/timecode.h"
41 #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 1599 static void pic_arrays_free(HEVCLayerContext *l)
75 {
76 1599 av_freep(&l->sao);
77 1599 av_freep(&l->deblock);
78
79 1599 av_freep(&l->skip_flag);
80 1599 av_freep(&l->tab_ct_depth);
81
82 1599 av_freep(&l->tab_ipm);
83 1599 av_freep(&l->cbf_luma);
84 1599 av_freep(&l->is_pcm);
85
86 1599 av_freep(&l->qp_y_tab);
87 1599 av_freep(&l->tab_slice_address);
88 1599 av_freep(&l->filter_slice_edges);
89
90 1599 av_freep(&l->horizontal_bs);
91 1599 av_freep(&l->vertical_bs);
92
93
2/2
✓ Branch 0 taken 4797 times.
✓ Branch 1 taken 1599 times.
6396 for (int i = 0; i < 3; i++) {
94 4797 av_freep(&l->sao_pixel_buffer_h[i]);
95 4797 av_freep(&l->sao_pixel_buffer_v[i]);
96 }
97
98 1599 av_refstruct_pool_uninit(&l->tab_mvf_pool);
99 1599 av_refstruct_pool_uninit(&l->rpl_tab_pool);
100 1599 }
101
102 /* allocate arrays that depend on frame dimensions */
103 461 static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps)
104 {
105 461 int log2_min_cb_size = sps->log2_min_cb_size;
106 461 int width = sps->width;
107 461 int height = sps->height;
108 461 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
109 461 ((height >> log2_min_cb_size) + 1);
110 461 int ctb_count = sps->ctb_width * sps->ctb_height;
111 461 int min_pu_size = sps->min_pu_width * sps->min_pu_height;
112
113 461 l->bs_width = (width >> 2) + 1;
114 461 l->bs_height = (height >> 2) + 1;
115
116 461 l->sao = av_calloc(ctb_count, sizeof(*l->sao));
117 461 l->deblock = av_calloc(ctb_count, sizeof(*l->deblock));
118
2/4
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 461 times.
461 if (!l->sao || !l->deblock)
119 goto fail;
120
121 461 l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
122 461 l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
123
2/4
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 461 times.
461 if (!l->skip_flag || !l->tab_ct_depth)
124 goto fail;
125
126 461 l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
127 461 l->tab_ipm = av_mallocz(min_pu_size);
128 461 l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1);
129
3/6
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 461 times.
461 if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm)
130 goto fail;
131
132 461 l->filter_slice_edges = av_mallocz(ctb_count);
133 461 l->tab_slice_address = av_malloc_array(pic_size_in_ctb,
134 sizeof(*l->tab_slice_address));
135 461 l->qp_y_tab = av_calloc(pic_size_in_ctb,
136 sizeof(*l->qp_y_tab));
137
3/6
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 461 times.
461 if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address)
138 goto fail;
139
140 461 l->horizontal_bs = av_calloc(l->bs_width, l->bs_height);
141 461 l->vertical_bs = av_calloc(l->bs_width, l->bs_height);
142
2/4
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 461 times.
461 if (!l->horizontal_bs || !l->vertical_bs)
143 goto fail;
144
145 461 l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
146 461 l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0);
147
2/4
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 461 times.
461 if (!l->tab_mvf_pool || !l->rpl_tab_pool)
148 goto fail;
149
150
2/2
✓ Branch 0 taken 402 times.
✓ Branch 1 taken 59 times.
461 if (sps->sao_enabled) {
151
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 2 times.
402 int c_count = (sps->chroma_format_idc != 0) ? 3 : 1;
152
153
2/2
✓ Branch 0 taken 1202 times.
✓ Branch 1 taken 402 times.
1604 for (int c_idx = 0; c_idx < c_count; c_idx++) {
154 1202 int w = sps->width >> sps->hshift[c_idx];
155 1202 int h = sps->height >> sps->vshift[c_idx];
156 1202 l->sao_pixel_buffer_h[c_idx] =
157 1202 av_mallocz((w * 2 * sps->ctb_height) <<
158 1202 sps->pixel_shift);
159 1202 l->sao_pixel_buffer_v[c_idx] =
160 1202 av_mallocz((h * 2 * sps->ctb_width) <<
161 1202 sps->pixel_shift);
162
1/2
✓ Branch 0 taken 1202 times.
✗ Branch 1 not taken.
1202 if (!l->sao_pixel_buffer_h[c_idx] ||
163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1202 times.
1202 !l->sao_pixel_buffer_v[c_idx])
164 goto fail;
165 }
166 }
167
168 461 return 0;
169
170 fail:
171 pic_arrays_free(l);
172 return AVERROR(ENOMEM);
173 }
174
175 1543 static int pred_weight_table(SliceHeader *sh, void *logctx,
176 const HEVCSPS *sps, GetBitContext *gb)
177 {
178 1543 int i = 0;
179 1543 int j = 0;
180 int luma_log2_weight_denom;
181 unsigned luma_weight_flags, chroma_weight_flags;
182
183 1543 luma_log2_weight_denom = get_ue_golomb_long(gb);
184
2/4
✓ Branch 0 taken 1543 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1543 times.
1543 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 1543 sh->luma_log2_weight_denom = luma_log2_weight_denom;
189
1/2
✓ Branch 0 taken 1543 times.
✗ Branch 1 not taken.
1543 if (sps->chroma_format_idc != 0) {
190 1543 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
191
2/4
✓ Branch 0 taken 1543 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1543 times.
1543 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 1543 sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
196 }
197
198 1543 luma_weight_flags = get_bits(gb, sh->nb_refs[L0]);
199
1/2
✓ Branch 0 taken 1543 times.
✗ Branch 1 not taken.
1543 chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L0]) : 0;
200
2/2
✓ Branch 0 taken 4591 times.
✓ Branch 1 taken 1543 times.
6134 for (i = 0; i < sh->nb_refs[L0]; i++) {
201 4591 unsigned flag_bit = 1 << (sh->nb_refs[L0] - 1 - i);
202
203
2/2
✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1474 times.
4591 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 1474 sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
211 1474 sh->luma_offset_l0[i] = 0;
212 }
213
2/2
✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3460 times.
4591 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 3460 sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom;
229 3460 sh->chroma_offset_l0[i][0] = 0;
230 3460 sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom;
231 3460 sh->chroma_offset_l0[i][1] = 0;
232 }
233 }
234
2/2
✓ Branch 0 taken 738 times.
✓ Branch 1 taken 805 times.
1543 if (sh->slice_type == HEVC_SLICE_B) {
235 738 luma_weight_flags = get_bits(gb, sh->nb_refs[L1]);
236
1/2
✓ Branch 0 taken 738 times.
✗ Branch 1 not taken.
738 chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L1]) : 0;
237
2/2
✓ Branch 0 taken 1447 times.
✓ Branch 1 taken 738 times.
2185 for (i = 0; i < sh->nb_refs[L1]; i++) {
238 1447 unsigned flag_bit = 1 << (sh->nb_refs[L1] - 1 - i);
239
240
2/2
✓ Branch 0 taken 746 times.
✓ Branch 1 taken 701 times.
1447 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 701 sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
248 701 sh->luma_offset_l1[i] = 0;
249 }
250
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1211 times.
1447 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 1211 sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom;
266 1211 sh->chroma_offset_l1[i][0] = 0;
267 1211 sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom;
268 1211 sh->chroma_offset_l1[i][1] = 0;
269 }
270 }
271 }
272 1543 return 0;
273 }
274
275 20265 static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps,
276 GetBitContext *gb, int cur_poc, int poc_lsb)
277 {
278 20265 int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
279 20265 int prev_delta_msb = 0;
280 20265 unsigned int nb_sps = 0, nb_sh;
281 int i;
282
283 20265 rps->nb_refs = 0;
284
2/2
✓ Branch 0 taken 18863 times.
✓ Branch 1 taken 1402 times.
20265 if (!sps->long_term_ref_pics_present)
285 18863 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 798 static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
333 {
334 798 AVCodecContext *avctx = s->avctx;
335 798 const HEVCVPS *vps = sps->vps;
336 798 const HEVCWindow *ow = &sps->output_window;
337 798 unsigned int num = 0, den = 0;
338
339 798 avctx->pix_fmt = sps->pix_fmt;
340 798 avctx->coded_width = sps->width;
341 798 avctx->coded_height = sps->height;
342 798 avctx->width = sps->width - ow->left_offset - ow->right_offset;
343 798 avctx->height = sps->height - ow->top_offset - ow->bottom_offset;
344 798 avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
345 798 avctx->profile = sps->ptl.general_ptl.profile_idc;
346 798 avctx->level = sps->ptl.general_ptl.level_idc;
347
348 798 ff_set_sar(avctx, sps->vui.common.sar);
349
350
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 670 times.
798 if (sps->vui.common.video_signal_type_present_flag)
351 128 avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG
352
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 118 times.
128 : AVCOL_RANGE_MPEG;
353 else
354 670 avctx->color_range = AVCOL_RANGE_MPEG;
355
356
2/2
✓ Branch 0 taken 121 times.
✓ Branch 1 taken 677 times.
798 if (sps->vui.common.colour_description_present_flag) {
357 121 avctx->color_primaries = sps->vui.common.colour_primaries;
358 121 avctx->color_trc = sps->vui.common.transfer_characteristics;
359 121 avctx->colorspace = sps->vui.common.matrix_coeffs;
360 } else {
361 677 avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
362 677 avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
363 677 avctx->colorspace = AVCOL_SPC_UNSPECIFIED;
364 }
365
366 798 avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
367
2/2
✓ Branch 0 taken 757 times.
✓ Branch 1 taken 41 times.
798 if (sps->chroma_format_idc == 1) {
368
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 714 times.
757 if (sps->vui.common.chroma_loc_info_present_flag) {
369
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 if (sps->vui.common.chroma_sample_loc_type_top_field <= 5)
370 43 avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1;
371 } else
372 714 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
373 }
374
375
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 752 times.
798 if (vps->vps_timing_info_present_flag) {
376 46 num = vps->vps_num_units_in_tick;
377 46 den = vps->vps_time_scale;
378
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 649 times.
752 } else if (sps->vui.vui_timing_info_present_flag) {
379 103 num = sps->vui.vui_num_units_in_tick;
380 103 den = sps->vui.vui_time_scale;
381 }
382
383
3/4
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 649 times.
✓ Branch 2 taken 149 times.
✗ Branch 3 not taken.
798 if (num > 0 && den > 0)
384 149 av_reduce(&avctx->framerate.den, &avctx->framerate.num,
385 num, den, 1 << 30);
386 798 }
387
388 10916 static int export_stream_params_from_sei(HEVCContext *s)
389 {
390 10916 AVCodecContext *avctx = s->avctx;
391
392
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10916 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10916 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 10916 return 0;
399 }
400
401 798 static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
402 {
403 798 const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
404
405 798 av_freep(&s->view_ids_available);
406 798 s->nb_view_ids_available = 0;
407 798 av_freep(&s->view_pos_available);
408 798 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 770 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 770 times.
✗ Branch 3 not taken.
798 if (vps->nb_layers < 2 && !vps->view_id[0])
412 770 return 0;
413
414 28 s->view_ids_available = av_calloc(vps->nb_layers, sizeof(*s->view_ids_available));
415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if (!s->view_ids_available)
416 return AVERROR(ENOMEM);
417
418
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 23 times.
28 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 56 times.
✓ Branch 1 taken 28 times.
84 for (int i = 0; i < vps->nb_layers; i++) {
425 56 s->view_ids_available[i] = vps->view_id[i];
426
427
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 46 times.
56 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 28 s->nb_view_ids_available = vps->nb_layers;
435
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 23 times.
28 s->nb_view_pos_available = s->view_pos_available ? vps->nb_layers : 0;
436
437 28 return 0;
438 }
439
440 11928 int ff_hevc_is_alpha_video(const HEVCContext *s)
441 {
442 11928 const HEVCVPS *vps = s->vps;
443 11928 int ret = 0;
444
445
3/4
✓ Branch 0 taken 1215 times.
✓ Branch 1 taken 10713 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1215 times.
11928 if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1])
446 10713 return 0;
447
448 /* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other
449 * than alpha cannot reach here.
450 */
451 1215 ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY);
452
453
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 1062 times.
1215 av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n",
454 ret ? "is" : "not");
455
456 1215 return ret;
457 }
458
459 450 static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
460 {
461 450 unsigned layers_active_output = 0, highest_layer;
462
463 450 s->layers_active_output = 1;
464 450 s->layers_active_decode = 1;
465
466
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 449 times.
450 if (ff_hevc_is_alpha_video(s)) {
467 1 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
468
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
470 return 0;
471
472 1 s->layers_active_decode = (1 << vps->nb_layers) - 1;
473 1 s->layers_active_output = 1;
474
475 1 return 0;
476 }
477
478 // nothing requested - decode base layer only
479
2/2
✓ Branch 0 taken 438 times.
✓ Branch 1 taken 11 times.
449 if (!s->nb_view_ids)
480 438 return 0;
481
482
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) {
483 layers_active_output = (1 << vps->nb_layers) - 1;
484 } else {
485
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 11 times.
30 for (int i = 0; i < s->nb_view_ids; i++) {
486 19 int view_id = s->view_ids[i];
487 19 int layer_idx = -1;
488
489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
19 if (view_id < 0) {
490 av_log(s->avctx, AV_LOG_ERROR,
491 "Invalid view ID requested: %d\n", view_id);
492 return AVERROR(EINVAL);
493 }
494
495
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 for (int j = 0; j < vps->nb_layers; j++) {
496
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 9 times.
28 if (vps->view_id[j] == view_id) {
497 19 layer_idx = j;
498 19 break;
499 }
500 }
501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
19 if (layer_idx < 0) {
502 av_log(s->avctx, AV_LOG_ERROR,
503 "View ID %d not present in VPS\n", view_id);
504 return AVERROR(EINVAL);
505 }
506 19 layers_active_output |= 1 << layer_idx;
507 }
508 }
509
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (!layers_active_output) {
511 av_log(s->avctx, AV_LOG_ERROR, "No layers selected\n");
512 return AVERROR_BUG;
513 }
514
515 11 highest_layer = ff_log2(layers_active_output);
516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (highest_layer >= FF_ARRAY_ELEMS(s->layers)) {
517 av_log(s->avctx, AV_LOG_ERROR,
518 "Too many layers requested: %u\n", layers_active_output);
519 return AVERROR(EINVAL);
520 }
521
522 /* Assume a higher layer depends on all the lower ones.
523 * This is enforced in VPS parsing currently, this logic will need
524 * to be changed if we want to support more complex dependency structures.
525 */
526 11 s->layers_active_decode = (1 << (highest_layer + 1)) - 1;
527 11 s->layers_active_output = layers_active_output;
528
529 11 av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n",
530 s->layers_active_decode, s->layers_active_output);
531
532 11 return 0;
533 }
534
535 1 static enum AVPixelFormat map_to_alpha_format(HEVCContext *s,
536 enum AVPixelFormat pix_fmt)
537 {
538
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) {
539 1 case AV_PIX_FMT_YUV420P:
540 case AV_PIX_FMT_YUVJ420P:
541 1 return AV_PIX_FMT_YUVA420P;
542 case AV_PIX_FMT_YUV420P10:
543 return AV_PIX_FMT_YUVA420P10;
544 case AV_PIX_FMT_YUV444P:
545 return AV_PIX_FMT_YUVA444P;
546 case AV_PIX_FMT_YUV422P:
547 return AV_PIX_FMT_YUVA422P;
548 case AV_PIX_FMT_YUV422P10LE:
549 return AV_PIX_FMT_YUVA422P10LE;
550 case AV_PIX_FMT_YUV444P10:
551 return AV_PIX_FMT_YUVA444P10;
552 case AV_PIX_FMT_YUV444P12:
553 return AV_PIX_FMT_YUVA444P12;
554 case AV_PIX_FMT_YUV422P12:
555 return AV_PIX_FMT_YUVA422P12;
556 default:
557 av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n",
558 av_get_pix_fmt_name(pix_fmt));
559 return AV_PIX_FMT_NONE;
560 }
561 }
562
563 450 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
564 {
565 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
566 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
567 CONFIG_HEVC_D3D12VA_HWACCEL + \
568 CONFIG_HEVC_NVDEC_HWACCEL + \
569 CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL + \
570 CONFIG_HEVC_VAAPI_HWACCEL + \
571 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
572 CONFIG_HEVC_VDPAU_HWACCEL + \
573 CONFIG_HEVC_VULKAN_HWACCEL)
574 450 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts;
575 450 enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE;
576 int ret;
577
578
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 449 times.
450 if (ff_hevc_is_alpha_video(s))
579 1 alpha_fmt = map_to_alpha_format(s, sps->pix_fmt);
580
581
6/7
✓ Branch 0 taken 374 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
450 switch (sps->pix_fmt) {
582 374 case AV_PIX_FMT_YUV420P:
583 case AV_PIX_FMT_YUVJ420P:
584 #if CONFIG_HEVC_DXVA2_HWACCEL
585 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
586 #endif
587 #if CONFIG_HEVC_D3D11VA_HWACCEL
588 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
589 *fmt++ = AV_PIX_FMT_D3D11;
590 #endif
591 #if CONFIG_HEVC_D3D12VA_HWACCEL
592 *fmt++ = AV_PIX_FMT_D3D12;
593 #endif
594 #if CONFIG_HEVC_VAAPI_HWACCEL
595 374 *fmt++ = AV_PIX_FMT_VAAPI;
596 #endif
597 #if CONFIG_HEVC_VDPAU_HWACCEL
598 374 *fmt++ = AV_PIX_FMT_VDPAU;
599 #endif
600 #if CONFIG_HEVC_NVDEC_HWACCEL
601 *fmt++ = AV_PIX_FMT_CUDA;
602 #endif
603 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
604 *fmt++ = AV_PIX_FMT_CUARRAY;
605 #endif
606 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
607 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
608 #endif
609 #if CONFIG_HEVC_VULKAN_HWACCEL
610 *fmt++ = AV_PIX_FMT_VULKAN;
611 #endif
612 374 break;
613 48 case AV_PIX_FMT_YUV420P10:
614 #if CONFIG_HEVC_DXVA2_HWACCEL
615 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
616 #endif
617 #if CONFIG_HEVC_D3D11VA_HWACCEL
618 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
619 *fmt++ = AV_PIX_FMT_D3D11;
620 #endif
621 #if CONFIG_HEVC_D3D12VA_HWACCEL
622 *fmt++ = AV_PIX_FMT_D3D12;
623 #endif
624 #if CONFIG_HEVC_VAAPI_HWACCEL
625 48 *fmt++ = AV_PIX_FMT_VAAPI;
626 #endif
627 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
628 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
629 #endif
630 #if CONFIG_HEVC_VULKAN_HWACCEL
631 *fmt++ = AV_PIX_FMT_VULKAN;
632 #endif
633 #if CONFIG_HEVC_VDPAU_HWACCEL
634 48 *fmt++ = AV_PIX_FMT_VDPAU;
635 #endif
636 #if CONFIG_HEVC_NVDEC_HWACCEL
637 *fmt++ = AV_PIX_FMT_CUDA;
638 #endif
639 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
640 *fmt++ = AV_PIX_FMT_CUARRAY;
641 #endif
642 48 break;
643 4 case AV_PIX_FMT_YUV444P:
644 #if CONFIG_HEVC_VAAPI_HWACCEL
645 4 *fmt++ = AV_PIX_FMT_VAAPI;
646 #endif
647 #if CONFIG_HEVC_VDPAU_HWACCEL
648 4 *fmt++ = AV_PIX_FMT_VDPAU;
649 #endif
650 #if CONFIG_HEVC_NVDEC_HWACCEL
651 *fmt++ = AV_PIX_FMT_CUDA;
652 #endif
653 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
654 *fmt++ = AV_PIX_FMT_CUARRAY;
655 #endif
656 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
657 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
658 #endif
659 #if CONFIG_HEVC_VULKAN_HWACCEL
660 *fmt++ = AV_PIX_FMT_VULKAN;
661 #endif
662 4 break;
663 12 case AV_PIX_FMT_YUV422P:
664 case AV_PIX_FMT_YUV422P10LE:
665 #if CONFIG_HEVC_VAAPI_HWACCEL
666 12 *fmt++ = AV_PIX_FMT_VAAPI;
667 #endif
668 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
669 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
670 #endif
671 #if CONFIG_HEVC_VULKAN_HWACCEL
672 *fmt++ = AV_PIX_FMT_VULKAN;
673 #endif
674 #if CONFIG_HEVC_NVDEC_HWACCEL
675 *fmt++ = AV_PIX_FMT_CUDA;
676 #endif
677 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
678 *fmt++ = AV_PIX_FMT_CUARRAY;
679 #endif
680 12 break;
681 10 case AV_PIX_FMT_YUV444P10:
682 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
683 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
684 #endif
685 av_fallthrough;
686 case AV_PIX_FMT_YUV420P12:
687 case AV_PIX_FMT_YUV444P12:
688 #if CONFIG_HEVC_VAAPI_HWACCEL
689 10 *fmt++ = AV_PIX_FMT_VAAPI;
690 #endif
691 #if CONFIG_HEVC_VDPAU_HWACCEL
692 10 *fmt++ = AV_PIX_FMT_VDPAU;
693 #endif
694 #if CONFIG_HEVC_VULKAN_HWACCEL
695 *fmt++ = AV_PIX_FMT_VULKAN;
696 #endif
697 #if CONFIG_HEVC_NVDEC_HWACCEL
698 *fmt++ = AV_PIX_FMT_CUDA;
699 #endif
700 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
701 *fmt++ = AV_PIX_FMT_CUARRAY;
702 #endif
703 10 break;
704 case AV_PIX_FMT_YUV422P12:
705 #if CONFIG_HEVC_VAAPI_HWACCEL
706 *fmt++ = AV_PIX_FMT_VAAPI;
707 #endif
708 #if CONFIG_HEVC_VULKAN_HWACCEL
709 *fmt++ = AV_PIX_FMT_VULKAN;
710 #endif
711 #if CONFIG_HEVC_NVDEC_HWACCEL
712 *fmt++ = AV_PIX_FMT_CUDA;
713 #endif
714 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
715 *fmt++ = AV_PIX_FMT_CUARRAY;
716 #endif
717 break;
718 }
719
720
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 449 times.
450 if (alpha_fmt != AV_PIX_FMT_NONE)
721 1 *fmt++ = alpha_fmt;
722 450 *fmt++ = sps->pix_fmt;
723 450 *fmt = AV_PIX_FMT_NONE;
724
725 // export multilayer information from active VPS to the caller,
726 // so it is available in get_format()
727 450 ret = export_multilayer(s, sps->vps);
728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (ret < 0)
729 return ret;
730
731 450 ret = ff_get_format(s->avctx, pix_fmts);
732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (ret < 0)
733 return ret;
734 450 s->avctx->pix_fmt = ret;
735
736 // set up multilayer decoding, if requested by caller
737 450 ret = setup_multilayer(s, sps->vps);
738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (ret < 0)
739 return ret;
740
741 450 return 0;
742 }
743
744 461 static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
745 {
746 int ret;
747
748 461 pic_arrays_free(l);
749 461 av_refstruct_unref(&l->sps);
750 461 av_refstruct_unref(&s->vps);
751
752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (!sps)
753 return 0;
754
755 461 ret = pic_arrays_init(l, sps);
756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (ret < 0)
757 goto fail;
758
759 461 ff_hevc_pred_init(&s->hpc, sps->bit_depth);
760 461 ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
761 461 ff_videodsp_init (&s->vdsp, sps->bit_depth);
762
763 461 l->sps = av_refstruct_ref_c(sps);
764 461 s->vps = av_refstruct_ref_c(sps->vps);
765
766 461 return 0;
767
768 fail:
769 pic_arrays_free(l);
770 av_refstruct_unref(&l->sps);
771 return ret;
772 }
773
774 28936 static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb)
775 {
776 const HEVCPPS *pps;
777 const HEVCSPS *sps;
778 const HEVCVPS *vps;
779 unsigned pps_id, layer_idx;
780 int i, ret;
781
782 // Coded parameters
783 28936 sh->first_slice_in_pic_flag = get_bits1(gb);
784
785 28936 sh->no_output_of_prior_pics_flag = 0;
786
3/4
✓ Branch 0 taken 1509 times.
✓ Branch 1 taken 27427 times.
✓ Branch 2 taken 1509 times.
✗ Branch 3 not taken.
28936 if (IS_IRAP(s))
787 1509 sh->no_output_of_prior_pics_flag = get_bits1(gb);
788
789 28936 pps_id = get_ue_golomb_long(gb);
790
3/4
✓ Branch 0 taken 28936 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 28903 times.
28936 if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) {
791 33 av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
792 33 return AVERROR_INVALIDDATA;
793 }
794
3/4
✓ Branch 0 taken 18293 times.
✓ Branch 1 taken 10610 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18293 times.
28903 if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) {
795 av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
796 return AVERROR_INVALIDDATA;
797 }
798 28903 sh->pps_id = pps_id;
799
800 28903 pps = s->ps.pps_list[pps_id];
801 28903 sps = pps->sps;
802 28903 vps = sps->vps;
803 28903 layer_idx = vps->layer_idx[s->nuh_layer_id];
804
805
4/4
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 28423 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 464 times.
28903 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
806 16 sh->no_output_of_prior_pics_flag = 1;
807
808 28903 sh->dependent_slice_segment_flag = 0;
809
2/2
✓ Branch 0 taken 18293 times.
✓ Branch 1 taken 10610 times.
28903 if (!sh->first_slice_in_pic_flag) {
810 int slice_address_length;
811
812
2/2
✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 9201 times.
18293 if (pps->dependent_slice_segments_enabled_flag)
813 9092 sh->dependent_slice_segment_flag = get_bits1(gb);
814
3/4
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 10346 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7947 times.
18293 if (sh->dependent_slice_segment_flag && !s->slice_initialized) {
815 av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
816 return AVERROR_INVALIDDATA;
817 }
818
819 18293 slice_address_length = av_ceil_log2(sps->ctb_width *
820 18293 sps->ctb_height);
821 18293 sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18293 times.
18293 if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
823 av_log(s->avctx, AV_LOG_ERROR,
824 "Invalid slice segment address: %u.\n",
825 sh->slice_segment_addr);
826 return AVERROR_INVALIDDATA;
827 }
828
829
2/2
✓ Branch 0 taken 10346 times.
✓ Branch 1 taken 7947 times.
18293 if (!sh->dependent_slice_segment_flag) {
830 10346 sh->slice_addr = sh->slice_segment_addr;
831 }
832 } else {
833 10610 sh->slice_segment_addr = sh->slice_addr = 0;
834 }
835
836
2/2
✓ Branch 0 taken 20956 times.
✓ Branch 1 taken 7947 times.
28903 if (!sh->dependent_slice_segment_flag) {
837
2/2
✓ Branch 0 taken 1834 times.
✓ Branch 1 taken 20956 times.
22790 for (i = 0; i < pps->num_extra_slice_header_bits; i++)
838 1834 skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
839
840 20956 sh->slice_type = get_ue_golomb_long(gb);
841
2/2
✓ Branch 0 taken 19657 times.
✓ Branch 1 taken 1299 times.
20956 if (!(sh->slice_type == HEVC_SLICE_I ||
842
2/2
✓ Branch 0 taken 15325 times.
✓ Branch 1 taken 4332 times.
19657 sh->slice_type == HEVC_SLICE_P ||
843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15325 times.
15325 sh->slice_type == HEVC_SLICE_B)) {
844 av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",
845 sh->slice_type);
846 return AVERROR_INVALIDDATA;
847 }
848
5/6
✓ Branch 0 taken 1120 times.
✓ Branch 1 taken 19836 times.
✓ Branch 2 taken 1120 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 1039 times.
20956 if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
849
1/2
✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
81 !pps->pps_curr_pic_ref_enabled_flag &&
850
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
81 s->nuh_layer_id == 0) {
851 av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
852 return AVERROR_INVALIDDATA;
853 }
854
855 // when flag is not present, picture is inferred to be output
856 20956 sh->pic_output_flag = 1;
857
2/2
✓ Branch 0 taken 703 times.
✓ Branch 1 taken 20253 times.
20956 if (pps->output_flag_present_flag)
858 703 sh->pic_output_flag = get_bits1(gb);
859
860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20956 times.
20956 if (sps->separate_colour_plane)
861 sh->colour_plane_id = get_bits(gb, 2);
862
863
4/4
✓ Branch 0 taken 20313 times.
✓ Branch 1 taken 643 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 20265 times.
20956 if (!IS_IDR(s) ||
864
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 673 times.
691 (s->nuh_layer_id > 0 &&
865
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5 times.
18 !(vps->poc_lsb_not_present & (1 << layer_idx)))) {
866 int poc;
867
868 20278 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
869 20278 poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
870
3/4
✓ Branch 0 taken 10116 times.
✓ Branch 1 taken 10162 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10116 times.
20278 if (!sh->first_slice_in_pic_flag && poc != sh->poc) {
871 av_log(s->avctx, AV_LOG_WARNING,
872 "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc);
873 if (s->avctx->err_recognition & AV_EF_EXPLODE)
874 return AVERROR_INVALIDDATA;
875 poc = sh->poc;
876 }
877 20278 sh->poc = poc;
878 }
879
880
4/4
✓ Branch 0 taken 20313 times.
✓ Branch 1 taken 643 times.
✓ Branch 2 taken 20265 times.
✓ Branch 3 taken 48 times.
41221 if (!IS_IDR(s)) {
881 int pos;
882
883 20265 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
884 20265 pos = get_bits_left(gb);
885
2/2
✓ Branch 0 taken 3987 times.
✓ Branch 1 taken 16278 times.
20265 if (!sh->short_term_ref_pic_set_sps_flag) {
886 3987 ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1);
887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3987 times.
3987 if (ret < 0)
888 return ret;
889
890 3987 sh->short_term_rps = &sh->slice_rps;
891 } else {
892 int numbits, rps_idx;
893
894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16278 times.
16278 if (!sps->nb_st_rps) {
895 av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
896 return AVERROR_INVALIDDATA;
897 }
898
899 16278 numbits = av_ceil_log2(sps->nb_st_rps);
900
2/2
✓ Branch 0 taken 16250 times.
✓ Branch 1 taken 28 times.
16278 rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
901 16278 sh->short_term_rps = &sps->st_rps[rps_idx];
902 }
903 20265 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
904
905 20265 pos = get_bits_left(gb);
906 20265 ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb);
907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20265 times.
20265 if (ret < 0) {
908 av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
909 if (s->avctx->err_recognition & AV_EF_EXPLODE)
910 return AVERROR_INVALIDDATA;
911 }
912 20265 sh->long_term_ref_pic_set_size = pos - get_bits_left(gb);
913
914
2/2
✓ Branch 0 taken 17834 times.
✓ Branch 1 taken 2431 times.
20265 if (sps->temporal_mvp_enabled)
915 17834 sh->slice_temporal_mvp_enabled_flag = get_bits1(gb);
916 else
917 2431 sh->slice_temporal_mvp_enabled_flag = 0;
918 } else {
919 691 sh->poc = 0;
920 691 sh->pic_order_cnt_lsb = 0;
921 691 sh->short_term_ref_pic_set_sps_flag = 0;
922 691 sh->short_term_ref_pic_set_size = 0;
923 691 sh->short_term_rps = NULL;
924 691 sh->long_term_ref_pic_set_size = 0;
925 691 sh->long_term_rps.nb_refs = 0;
926 691 sh->slice_temporal_mvp_enabled_flag = 0;
927 }
928
929 20956 sh->inter_layer_pred = 0;
930
2/2
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 20440 times.
20956 if (s->nuh_layer_id > 0) {
931 516 int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx];
932
933
2/2
✓ Branch 0 taken 418 times.
✓ Branch 1 taken 98 times.
516 if (vps->default_ref_layers_active)
934 418 sh->inter_layer_pred = !!num_direct_ref_layers;
935
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 50 times.
98 else if (num_direct_ref_layers) {
936 48 sh->inter_layer_pred = get_bits1(gb);
937
938
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) {
939 av_log(s->avctx, AV_LOG_ERROR,
940 "NumDirectRefLayers>1 not supported\n");
941 return AVERROR_PATCHWELCOME;
942 }
943 }
944 }
945
946
2/2
✓ Branch 0 taken 17436 times.
✓ Branch 1 taken 3520 times.
20956 if (sps->sao_enabled) {
947 17436 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
948
2/2
✓ Branch 0 taken 17434 times.
✓ Branch 1 taken 2 times.
17436 if (sps->chroma_format_idc) {
949 17434 sh->slice_sample_adaptive_offset_flag[1] =
950 17434 sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb);
951 }
952 } else {
953 3520 sh->slice_sample_adaptive_offset_flag[0] = 0;
954 3520 sh->slice_sample_adaptive_offset_flag[1] = 0;
955 3520 sh->slice_sample_adaptive_offset_flag[2] = 0;
956 }
957
958 20956 sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
959
4/4
✓ Branch 0 taken 16624 times.
✓ Branch 1 taken 4332 times.
✓ Branch 2 taken 15325 times.
✓ Branch 3 taken 1299 times.
20956 if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
960 int nb_refs;
961
962 19657 sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active;
963
2/2
✓ Branch 0 taken 15325 times.
✓ Branch 1 taken 4332 times.
19657 if (sh->slice_type == HEVC_SLICE_B)
964 15325 sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active;
965
966
2/2
✓ Branch 1 taken 5424 times.
✓ Branch 2 taken 14233 times.
19657 if (get_bits1(gb)) { // num_ref_idx_active_override_flag
967 5424 sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1;
968
2/2
✓ Branch 0 taken 2857 times.
✓ Branch 1 taken 2567 times.
5424 if (sh->slice_type == HEVC_SLICE_B)
969 2857 sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1;
970 }
971
2/4
✓ Branch 0 taken 19657 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19657 times.
19657 if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) {
972 av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n",
973 sh->nb_refs[L0], sh->nb_refs[L1]);
974 return AVERROR_INVALIDDATA;
975 }
976
977 19657 sh->rpl_modification_flag[0] = 0;
978 19657 sh->rpl_modification_flag[1] = 0;
979 19657 nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx);
980
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19657 times.
19657 if (!nb_refs) {
981 av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
982 return AVERROR_INVALIDDATA;
983 }
984
985
4/4
✓ Branch 0 taken 2302 times.
✓ Branch 1 taken 17355 times.
✓ Branch 2 taken 1978 times.
✓ Branch 3 taken 324 times.
19657 if (pps->lists_modification_present_flag && nb_refs > 1) {
986 1978 sh->rpl_modification_flag[0] = get_bits1(gb);
987
2/2
✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 546 times.
1978 if (sh->rpl_modification_flag[0]) {
988
2/2
✓ Branch 0 taken 3366 times.
✓ Branch 1 taken 1432 times.
4798 for (i = 0; i < sh->nb_refs[L0]; i++)
989 3366 sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs));
990 }
991
992
2/2
✓ Branch 0 taken 1795 times.
✓ Branch 1 taken 183 times.
1978 if (sh->slice_type == HEVC_SLICE_B) {
993 1795 sh->rpl_modification_flag[1] = get_bits1(gb);
994
2/2
✓ Branch 0 taken 652 times.
✓ Branch 1 taken 1143 times.
1795 if (sh->rpl_modification_flag[1] == 1)
995
2/2
✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
2207 for (i = 0; i < sh->nb_refs[L1]; i++)
996 1555 sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs));
997 }
998 }
999
1000
2/2
✓ Branch 0 taken 15325 times.
✓ Branch 1 taken 4332 times.
19657 if (sh->slice_type == HEVC_SLICE_B)
1001 15325 sh->mvd_l1_zero_flag = get_bits1(gb);
1002
1003
2/2
✓ Branch 0 taken 16687 times.
✓ Branch 1 taken 2970 times.
19657 if (pps->cabac_init_present_flag)
1004 16687 sh->cabac_init_flag = get_bits1(gb);
1005 else
1006 2970 sh->cabac_init_flag = 0;
1007
1008 19657 sh->collocated_ref_idx = 0;
1009
2/2
✓ Branch 0 taken 17176 times.
✓ Branch 1 taken 2481 times.
19657 if (sh->slice_temporal_mvp_enabled_flag) {
1010 17176 sh->collocated_list = L0;
1011
2/2
✓ Branch 0 taken 14791 times.
✓ Branch 1 taken 2385 times.
17176 if (sh->slice_type == HEVC_SLICE_B)
1012 14791 sh->collocated_list = !get_bits1(gb);
1013
1014
2/2
✓ Branch 0 taken 15069 times.
✓ Branch 1 taken 2107 times.
17176 if (sh->nb_refs[sh->collocated_list] > 1) {
1015 15069 sh->collocated_ref_idx = get_ue_golomb_long(gb);
1016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15069 times.
15069 if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) {
1017 av_log(s->avctx, AV_LOG_ERROR,
1018 "Invalid collocated_ref_idx: %d.\n",
1019 sh->collocated_ref_idx);
1020 return AVERROR_INVALIDDATA;
1021 }
1022 }
1023 }
1024
1025
4/4
✓ Branch 0 taken 1589 times.
✓ Branch 1 taken 18068 times.
✓ Branch 2 taken 784 times.
✓ Branch 3 taken 805 times.
19657 if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
1026
3/4
✓ Branch 0 taken 738 times.
✓ Branch 1 taken 18114 times.
✓ Branch 2 taken 738 times.
✗ Branch 3 not taken.
18852 (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
1027 1543 ret = pred_weight_table(sh, s->avctx, sps, gb);
1028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1543 times.
1543 if (ret < 0)
1029 return ret;
1030 }
1031
1032 19657 sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
1033
2/4
✓ Branch 0 taken 19657 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19657 times.
19657 if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
1034 av_log(s->avctx, AV_LOG_ERROR,
1035 "Invalid number of merging MVP candidates: %d.\n",
1036 sh->max_num_merge_cand);
1037 return AVERROR_INVALIDDATA;
1038 }
1039
1040 // Syntax in 7.3.6.1
1041
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19657 times.
19657 if (sps->motion_vector_resolution_control_idc == 2)
1042 sh->use_integer_mv_flag = get_bits1(gb);
1043 else
1044 // Inferred to be equal to motion_vector_resolution_control_idc if not present
1045 19657 sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc;
1046
1047 }
1048
1049 20956 sh->slice_qp_delta = get_se_golomb(gb);
1050
1051
2/2
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 20685 times.
20956 if (pps->pic_slice_level_chroma_qp_offsets_present_flag) {
1052 271 sh->slice_cb_qp_offset = get_se_golomb(gb);
1053 271 sh->slice_cr_qp_offset = get_se_golomb(gb);
1054
2/4
✓ Branch 0 taken 271 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 271 times.
✗ Branch 3 not taken.
271 if (sh->slice_cb_qp_offset < -12 || sh->slice_cb_qp_offset > 12 ||
1055
2/4
✓ Branch 0 taken 271 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 271 times.
271 sh->slice_cr_qp_offset < -12 || sh->slice_cr_qp_offset > 12) {
1056 av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n");
1057 return AVERROR_INVALIDDATA;
1058 }
1059 } else {
1060 20685 sh->slice_cb_qp_offset = 0;
1061 20685 sh->slice_cr_qp_offset = 0;
1062 }
1063
1064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20956 times.
20956 if (pps->pps_slice_act_qp_offsets_present_flag) {
1065 sh->slice_act_y_qp_offset = get_se_golomb(gb);
1066 sh->slice_act_cb_qp_offset = get_se_golomb(gb);
1067 sh->slice_act_cr_qp_offset = get_se_golomb(gb);
1068 }
1069
1070
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 20913 times.
20956 if (pps->chroma_qp_offset_list_enabled_flag)
1071 43 sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
1072 else
1073 20913 sh->cu_chroma_qp_offset_enabled_flag = 0;
1074
1075
2/2
✓ Branch 0 taken 3446 times.
✓ Branch 1 taken 17510 times.
20956 if (pps->deblocking_filter_control_present_flag) {
1076 3446 int deblocking_filter_override_flag = 0;
1077
1078
2/2
✓ Branch 0 taken 1079 times.
✓ Branch 1 taken 2367 times.
3446 if (pps->deblocking_filter_override_enabled_flag)
1079 1079 deblocking_filter_override_flag = get_bits1(gb);
1080
1081
2/2
✓ Branch 0 taken 481 times.
✓ Branch 1 taken 2965 times.
3446 if (deblocking_filter_override_flag) {
1082 481 sh->disable_deblocking_filter_flag = get_bits1(gb);
1083
2/2
✓ Branch 0 taken 361 times.
✓ Branch 1 taken 120 times.
481 if (!sh->disable_deblocking_filter_flag) {
1084 361 int beta_offset_div2 = get_se_golomb(gb);
1085 361 int tc_offset_div2 = get_se_golomb(gb) ;
1086
3/6
✓ Branch 0 taken 361 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 361 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 361 times.
✗ Branch 5 not taken.
361 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
1087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 361 times.
361 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1088 av_log(s->avctx, AV_LOG_ERROR,
1089 "Invalid deblock filter offsets: %d, %d\n",
1090 beta_offset_div2, tc_offset_div2);
1091 return AVERROR_INVALIDDATA;
1092 }
1093 361 sh->beta_offset = beta_offset_div2 * 2;
1094 361 sh->tc_offset = tc_offset_div2 * 2;
1095 }
1096 } else {
1097 2965 sh->disable_deblocking_filter_flag = pps->disable_dbf;
1098 2965 sh->beta_offset = pps->beta_offset;
1099 2965 sh->tc_offset = pps->tc_offset;
1100 }
1101 } else {
1102 17510 sh->disable_deblocking_filter_flag = 0;
1103 17510 sh->beta_offset = 0;
1104 17510 sh->tc_offset = 0;
1105 }
1106
1107
2/2
✓ Branch 0 taken 18288 times.
✓ Branch 1 taken 2668 times.
20956 if (pps->seq_loop_filter_across_slices_enabled_flag &&
1108
2/2
✓ Branch 0 taken 11739 times.
✓ Branch 1 taken 6549 times.
18288 (sh->slice_sample_adaptive_offset_flag[0] ||
1109
2/2
✓ Branch 0 taken 11721 times.
✓ Branch 1 taken 18 times.
11739 sh->slice_sample_adaptive_offset_flag[1] ||
1110
2/2
✓ Branch 0 taken 11658 times.
✓ Branch 1 taken 63 times.
11721 !sh->disable_deblocking_filter_flag)) {
1111 18225 sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb);
1112 } else {
1113 2731 sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag;
1114 }
1115 }
1116
1117 28903 sh->num_entry_point_offsets = 0;
1118
4/4
✓ Branch 0 taken 25610 times.
✓ Branch 1 taken 3293 times.
✓ Branch 2 taken 4871 times.
✓ Branch 3 taken 20739 times.
28903 if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1119 8164 unsigned num_entry_point_offsets = get_ue_golomb_long(gb);
1120 // It would be possible to bound this tighter but this here is simpler
1121
2/4
✓ Branch 1 taken 8164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8164 times.
8164 if (num_entry_point_offsets > get_bits_left(gb) || num_entry_point_offsets > UINT16_MAX) {
1122 av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
1123 return AVERROR_INVALIDDATA;
1124 }
1125
1126 8164 sh->num_entry_point_offsets = num_entry_point_offsets;
1127
2/2
✓ Branch 0 taken 2308 times.
✓ Branch 1 taken 5856 times.
8164 if (sh->num_entry_point_offsets > 0) {
1128 2308 int offset_len = get_ue_golomb_long(gb) + 1;
1129
1130
2/4
✓ Branch 0 taken 2308 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2308 times.
2308 if (offset_len < 1 || offset_len > 32) {
1131 sh->num_entry_point_offsets = 0;
1132 av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len);
1133 return AVERROR_INVALIDDATA;
1134 }
1135
1136 2308 av_freep(&sh->entry_point_offset);
1137 2308 av_freep(&sh->offset);
1138 2308 av_freep(&sh->size);
1139 2308 sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
1140 2308 sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1141 2308 sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1142
3/6
✓ Branch 0 taken 2308 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2308 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2308 times.
2308 if (!sh->entry_point_offset || !sh->offset || !sh->size) {
1143 sh->num_entry_point_offsets = 0;
1144 av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
1145 return AVERROR(ENOMEM);
1146 }
1147
2/2
✓ Branch 0 taken 10312 times.
✓ Branch 1 taken 2308 times.
12620 for (i = 0; i < sh->num_entry_point_offsets; i++) {
1148 10312 unsigned val = get_bits_long(gb, offset_len);
1149 10312 sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
1150 }
1151 }
1152 }
1153
1154
2/2
✓ Branch 0 taken 2769 times.
✓ Branch 1 taken 26134 times.
28903 if (pps->slice_header_extension_present_flag) {
1155 2769 unsigned int length = get_ue_golomb_long(gb);
1156
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2769 times.
2769 if (length*8LL > get_bits_left(gb)) {
1157 av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n");
1158 return AVERROR_INVALIDDATA;
1159 }
1160
2/2
✓ Branch 0 taken 20292 times.
✓ Branch 1 taken 2769 times.
23061 for (i = 0; i < length; i++)
1161 20292 skip_bits(gb, 8); // slice_header_extension_data_byte
1162 }
1163
1164 28903 ret = get_bits1(gb);
1165
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28903 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
28903 if (!ret && get_bits_left(gb) >= 0) {
1166 av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n");
1167 return AVERROR_INVALIDDATA;
1168 }
1169 28903 sh->data_offset = align_get_bits(gb) - gb->buffer;
1170
1171
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28903 times.
28903 if (get_bits_left(gb) < 0) {
1172 av_log(s->avctx, AV_LOG_ERROR,
1173 "Overread slice header by %d bits\n", -get_bits_left(gb));
1174 return AVERROR_INVALIDDATA;
1175 }
1176
1177 // Inferred parameters
1178 28903 sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta;
1179
1/2
✓ Branch 0 taken 28903 times.
✗ Branch 1 not taken.
28903 if (sh->slice_qp > 51 ||
1180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28903 times.
28903 sh->slice_qp < -sps->qp_bd_offset) {
1181 av_log(s->avctx, AV_LOG_ERROR,
1182 "The slice_qp %d is outside the valid range "
1183 "[%d, 51].\n",
1184 sh->slice_qp,
1185 -sps->qp_bd_offset);
1186 return AVERROR_INVALIDDATA;
1187 }
1188
1189 28903 sh->slice_ctb_addr_rs = sh->slice_segment_addr;
1190
1191
2/2
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20956 times.
28903 if (sh->dependent_slice_segment_flag &&
1192
2/4
✓ Branch 0 taken 7947 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7947 times.
7947 (!sh->slice_ctb_addr_rs || !pps->ctb_addr_rs_to_ts[sh->slice_ctb_addr_rs])) {
1193 av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
1194 return AVERROR_INVALIDDATA;
1195 }
1196
1197 28903 return 0;
1198 }
1199
1200 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
1201
1202 #define SET_SAO(elem, value) \
1203 do { \
1204 if (!sao_merge_up_flag && !sao_merge_left_flag) \
1205 sao->elem = value; \
1206 else if (sao_merge_left_flag) \
1207 sao->elem = CTB(l->sao, rx-1, ry).elem; \
1208 else if (sao_merge_up_flag) \
1209 sao->elem = CTB(l->sao, rx, ry-1).elem; \
1210 else \
1211 sao->elem = 0; \
1212 } while (0)
1213
1214 2008936 static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l,
1215 const HEVCPPS *pps, const HEVCSPS *sps,
1216 int rx, int ry)
1217 {
1218 2008936 const HEVCContext *const s = lc->parent;
1219 2008936 int sao_merge_left_flag = 0;
1220 2008936 int sao_merge_up_flag = 0;
1221 2008936 SAOParams *sao = &CTB(l->sao, rx, ry);
1222 int c_idx, i;
1223
1224
2/2
✓ Branch 0 taken 877650 times.
✓ Branch 1 taken 1131286 times.
2008936 if (s->sh.slice_sample_adaptive_offset_flag[0] ||
1225
2/2
✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 876006 times.
877650 s->sh.slice_sample_adaptive_offset_flag[1]) {
1226
2/2
✓ Branch 0 taken 1089046 times.
✓ Branch 1 taken 43884 times.
1132930 if (rx > 0) {
1227
2/2
✓ Branch 0 taken 1068369 times.
✓ Branch 1 taken 20677 times.
1089046 if (lc->ctb_left_flag)
1228 1068369 sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc);
1229 }
1230
4/4
✓ Branch 0 taken 1064004 times.
✓ Branch 1 taken 68926 times.
✓ Branch 2 taken 448363 times.
✓ Branch 3 taken 615641 times.
1132930 if (ry > 0 && !sao_merge_left_flag) {
1231
2/2
✓ Branch 0 taken 434994 times.
✓ Branch 1 taken 13369 times.
448363 if (lc->ctb_up_flag)
1232 434994 sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc);
1233 }
1234 }
1235
1236
4/4
✓ Branch 0 taken 8035552 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 6026712 times.
✓ Branch 3 taken 2008936 times.
8035648 for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) {
1237
2/2
✓ Branch 0 taken 2008936 times.
✓ Branch 1 taken 4017776 times.
6026712 int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma :
1238 4017776 pps->log2_sao_offset_scale_chroma;
1239
1240
2/2
✓ Branch 0 taken 3178950 times.
✓ Branch 1 taken 2847762 times.
6026712 if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1241 3178950 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
1242 3178950 continue;
1243 }
1244
1245
2/2
✓ Branch 0 taken 858238 times.
✓ Branch 1 taken 1989524 times.
2847762 if (c_idx == 2) {
1246 858238 sao->type_idx[2] = sao->type_idx[1];
1247 858238 sao->eo_class[2] = sao->eo_class[1];
1248 } else {
1249
7/8
✓ Branch 0 taken 1732216 times.
✓ Branch 1 taken 257308 times.
✓ Branch 2 taken 599594 times.
✓ Branch 3 taken 1132622 times.
✓ Branch 5 taken 1132622 times.
✓ Branch 6 taken 257308 times.
✓ Branch 7 taken 257308 times.
✗ Branch 8 not taken.
1989524 SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc));
1250 }
1251
1252
2/2
✓ Branch 0 taken 2080235 times.
✓ Branch 1 taken 767527 times.
2847762 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
1253 2080235 continue;
1254
1255
2/2
✓ Branch 0 taken 3070108 times.
✓ Branch 1 taken 767527 times.
3837635 for (i = 0; i < 4; i++)
1256
7/8
✓ Branch 0 taken 2515064 times.
✓ Branch 1 taken 555044 times.
✓ Branch 2 taken 1029260 times.
✓ Branch 3 taken 1485804 times.
✓ Branch 5 taken 1485804 times.
✓ Branch 6 taken 555044 times.
✓ Branch 7 taken 555044 times.
✗ Branch 8 not taken.
3070108 SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth));
1257
1258
2/2
✓ Branch 0 taken 125449 times.
✓ Branch 1 taken 642078 times.
767527 if (sao->type_idx[c_idx] == SAO_BAND) {
1259
2/2
✓ Branch 0 taken 501796 times.
✓ Branch 1 taken 125449 times.
627245 for (i = 0; i < 4; i++) {
1260
2/2
✓ Branch 0 taken 368839 times.
✓ Branch 1 taken 132957 times.
501796 if (sao->offset_abs[c_idx][i]) {
1261
7/8
✓ Branch 0 taken 342280 times.
✓ Branch 1 taken 26559 times.
✓ Branch 2 taken 252778 times.
✓ Branch 3 taken 89502 times.
✓ Branch 5 taken 89502 times.
✓ Branch 6 taken 26559 times.
✓ Branch 7 taken 26559 times.
✗ Branch 8 not taken.
368839 SET_SAO(offset_sign[c_idx][i],
1262 ff_hevc_sao_offset_sign_decode(lc));
1263 } else {
1264 132957 sao->offset_sign[c_idx][i] = 0;
1265 }
1266 }
1267
7/8
✓ Branch 0 taken 114581 times.
✓ Branch 1 taken 10868 times.
✓ Branch 2 taken 82676 times.
✓ Branch 3 taken 31905 times.
✓ Branch 5 taken 31905 times.
✓ Branch 6 taken 10868 times.
✓ Branch 7 taken 10868 times.
✗ Branch 8 not taken.
125449 SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc));
1268
2/2
✓ Branch 0 taken 553978 times.
✓ Branch 1 taken 88100 times.
642078 } else if (c_idx != 2) {
1269
7/8
✓ Branch 0 taken 443805 times.
✓ Branch 1 taken 110173 times.
✓ Branch 2 taken 140248 times.
✓ Branch 3 taken 303557 times.
✓ Branch 5 taken 303557 times.
✓ Branch 6 taken 110173 times.
✓ Branch 7 taken 110173 times.
✗ Branch 8 not taken.
553978 SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc));
1270 }
1271
1272 // Inferred parameters
1273 767527 sao->offset_val[c_idx][0] = 0;
1274
2/2
✓ Branch 0 taken 3070108 times.
✓ Branch 1 taken 767527 times.
3837635 for (i = 0; i < 4; i++) {
1275 3070108 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
1276
2/2
✓ Branch 0 taken 2568312 times.
✓ Branch 1 taken 501796 times.
3070108 if (sao->type_idx[c_idx] == SAO_EDGE) {
1277
2/2
✓ Branch 0 taken 1284156 times.
✓ Branch 1 taken 1284156 times.
2568312 if (i > 1)
1278 1284156 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1279
2/2
✓ Branch 0 taken 163519 times.
✓ Branch 1 taken 338277 times.
501796 } else if (sao->offset_sign[c_idx][i]) {
1280 163519 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1281 }
1282 3070108 sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale;
1283 }
1284 }
1285 2008936 }
1286
1287 #undef SET_SAO
1288 #undef CTB
1289
1290 384850 static int hls_cross_component_pred(HEVCLocalContext *lc, int idx)
1291 {
1292 384850 int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx);
1293
1294
2/2
✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
384850 if (log2_res_scale_abs_plus1 != 0) {
1295 235843 int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx);
1296 235843 lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) *
1297 235843 (1 - 2 * res_scale_sign_flag);
1298 } else {
1299 149007 lc->tu.res_scale_val = 0;
1300 }
1301
1302
1303 384850 return 0;
1304 }
1305
1306 17669638 static int hls_transform_unit(HEVCLocalContext *lc,
1307 const HEVCLayerContext *l,
1308 const HEVCPPS *pps, const HEVCSPS *sps,
1309 int x0, int y0,
1310 int xBase, int yBase, int cb_xBase, int cb_yBase,
1311 int log2_cb_size, int log2_trafo_size,
1312 int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
1313 {
1314 17669638 const HEVCContext *const s = lc->parent;
1315 17669638 const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1];
1316 int i;
1317
1318
2/2
✓ Branch 0 taken 11007473 times.
✓ Branch 1 taken 6662165 times.
17669638 if (lc->cu.pred_mode == MODE_INTRA) {
1319 11007473 int trafo_size = 1 << log2_trafo_size;
1320 11007473 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size);
1321
1322 11007473 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0);
1323 }
1324
1325
6/6
✓ Branch 0 taken 6245802 times.
✓ Branch 1 taken 11423836 times.
✓ Branch 2 taken 5509368 times.
✓ Branch 3 taken 736434 times.
✓ Branch 4 taken 5034226 times.
✓ Branch 5 taken 475142 times.
17669638 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1326
6/6
✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4878459 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
17731452 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1327 12697227 int scan_idx = SCAN_DIAG;
1328 12697227 int scan_idx_c = SCAN_DIAG;
1329
4/4
✓ Branch 0 taken 8613799 times.
✓ Branch 1 taken 4083428 times.
✓ Branch 2 taken 6946886 times.
✓ Branch 3 taken 1666913 times.
19644113 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1330
2/2
✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 6715176 times.
6946886 (sps->chroma_format_idc == 2 &&
1331
4/4
✓ Branch 0 taken 197852 times.
✓ Branch 1 taken 33858 times.
✓ Branch 2 taken 102075 times.
✓ Branch 3 taken 95777 times.
231710 (cbf_cb[1] || cbf_cr[1]));
1332
1333
4/4
✓ Branch 0 taken 3135859 times.
✓ Branch 1 taken 9561368 times.
✓ Branch 2 taken 1021402 times.
✓ Branch 3 taken 2114457 times.
12697227 if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
1334 1021402 lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc);
1335
2/2
✓ Branch 0 taken 529266 times.
✓ Branch 1 taken 492136 times.
1021402 if (lc->tu.cu_qp_delta != 0)
1336
2/2
✓ Branch 1 taken 286140 times.
✓ Branch 2 taken 243126 times.
529266 if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1)
1337 286140 lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1338 1021402 lc->tu.is_cu_qp_delta_coded = 1;
1339
1340
2/2
✓ Branch 0 taken 1021401 times.
✓ Branch 1 taken 1 times.
1021402 if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) ||
1341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1021401 times.
1021401 lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) {
1342 1 av_log(s->avctx, AV_LOG_ERROR,
1343 "The cu_qp_delta %d is outside the valid range "
1344 "[%d, %d].\n",
1345 lc->tu.cu_qp_delta,
1346 1 -(26 + sps->qp_bd_offset / 2),
1347 1 (25 + sps->qp_bd_offset / 2));
1348 1 return AVERROR_INVALIDDATA;
1349 }
1350
1351 1021401 ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size);
1352 }
1353
1354
4/4
✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 11805275 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
12697226 if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1355
3/4
✓ Branch 0 taken 841055 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 266275 times.
✓ Branch 3 taken 574780 times.
841055 !lc->cu.cu_transquant_bypass_flag && !lc->tu.is_cu_chroma_qp_offset_coded) {
1356 266275 int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc);
1357
2/2
✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
266275 if (cu_chroma_qp_offset_flag) {
1358 48966 int cu_chroma_qp_offset_idx = 0;
1359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
48966 if (pps->chroma_qp_offset_list_len_minus1 > 0) {
1360 cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1);
1361 av_log(s->avctx, AV_LOG_ERROR,
1362 "cu_chroma_qp_offset_idx not yet tested.\n");
1363 }
1364 48966 lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
1365 48966 lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
1366 } else {
1367 217309 lc->tu.cu_qp_offset_cb = 0;
1368 217309 lc->tu.cu_qp_offset_cr = 0;
1369 }
1370 266275 lc->tu.is_cu_chroma_qp_offset_coded = 1;
1371 }
1372
1373
4/4
✓ Branch 0 taken 8149426 times.
✓ Branch 1 taken 4547800 times.
✓ Branch 2 taken 7072236 times.
✓ Branch 3 taken 1077190 times.
12697226 if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1374
2/2
✓ Branch 0 taken 4696498 times.
✓ Branch 1 taken 2375738 times.
7072236 if (lc->tu.intra_pred_mode >= 6 &&
1375
2/2
✓ Branch 0 taken 1699891 times.
✓ Branch 1 taken 2996607 times.
4696498 lc->tu.intra_pred_mode <= 14) {
1376 1699891 scan_idx = SCAN_VERT;
1377
2/2
✓ Branch 0 taken 2312666 times.
✓ Branch 1 taken 3059679 times.
5372345 } else if (lc->tu.intra_pred_mode >= 22 &&
1378
2/2
✓ Branch 0 taken 1948318 times.
✓ Branch 1 taken 364348 times.
2312666 lc->tu.intra_pred_mode <= 30) {
1379 1948318 scan_idx = SCAN_HORIZ;
1380 }
1381
1382
2/2
✓ Branch 0 taken 4225329 times.
✓ Branch 1 taken 2846907 times.
7072236 if (lc->tu.intra_pred_mode_c >= 6 &&
1383
2/2
✓ Branch 0 taken 1601848 times.
✓ Branch 1 taken 2623481 times.
4225329 lc->tu.intra_pred_mode_c <= 14) {
1384 1601848 scan_idx_c = SCAN_VERT;
1385
2/2
✓ Branch 0 taken 2200433 times.
✓ Branch 1 taken 3269955 times.
5470388 } else if (lc->tu.intra_pred_mode_c >= 22 &&
1386
2/2
✓ Branch 0 taken 1845986 times.
✓ Branch 1 taken 354447 times.
2200433 lc->tu.intra_pred_mode_c <= 30) {
1387 1845986 scan_idx_c = SCAN_HORIZ;
1388 }
1389 }
1390
1391 12697226 lc->tu.cross_pf = 0;
1392
1393
2/2
✓ Branch 0 taken 11423835 times.
✓ Branch 1 taken 1273391 times.
12697226 if (cbf_luma)
1394 11423835 ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0);
1395
6/6
✓ Branch 0 taken 12697034 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6708335 times.
✓ Branch 3 taken 5988699 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 6498772 times.
18895488 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1396 6198262 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1397 6198262 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1398
4/4
✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 5861421 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
6416078 lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma &&
1399
2/2
✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
217816 (lc->cu.pred_mode == MODE_INTER ||
1400
2/2
✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
168873 (lc->tu.chroma_mode_c == 4)));
1401
1402
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 6005837 times.
6198262 if (lc->tu.cross_pf) {
1403 192425 hls_cross_component_pred(lc, 0);
1404 }
1405
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 11490120 times.
✓ Branch 2 taken 6651464 times.
✓ Branch 3 taken 6198262 times.
12849726 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1406
2/2
✓ Branch 0 taken 3466893 times.
✓ Branch 1 taken 3184571 times.
6651464 if (lc->cu.pred_mode == MODE_INTRA) {
1407 3466893 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1408 3466893 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1409 3466893 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1);
1410 }
1411
2/2
✓ Branch 0 taken 1792804 times.
✓ Branch 1 taken 4858660 times.
6651464 if (cbf_cb[i])
1412 1792804 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1413 log2_trafo_size_c, scan_idx_c, 1);
1414 else
1415
2/2
✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 4819002 times.
4858660 if (lc->tu.cross_pf) {
1416 39658 ptrdiff_t stride = s->cur_frame->f->linesize[1];
1417 39658 int hshift = sps->hshift[1];
1418 39658 int vshift = sps->vshift[1];
1419 39658 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1420 39658 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1421 39658 int size = 1 << log2_trafo_size_c;
1422
1423 39658 uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride +
1424 39658 ((x0 >> hshift) << sps->pixel_shift)];
1425
2/2
✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
1871162 for (i = 0; i < (size * size); i++) {
1426 1831504 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1427 }
1428 39658 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1429 }
1430 }
1431
1432
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 6005837 times.
6198262 if (lc->tu.cross_pf) {
1433 192425 hls_cross_component_pred(lc, 1);
1434 }
1435
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 11490120 times.
✓ Branch 2 taken 6651464 times.
✓ Branch 3 taken 6198262 times.
12849726 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1436
2/2
✓ Branch 0 taken 3466893 times.
✓ Branch 1 taken 3184571 times.
6651464 if (lc->cu.pred_mode == MODE_INTRA) {
1437 3466893 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1438 3466893 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1439 3466893 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2);
1440 }
1441
2/2
✓ Branch 0 taken 1837589 times.
✓ Branch 1 taken 4813875 times.
6651464 if (cbf_cr[i])
1442 1837589 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1443 log2_trafo_size_c, scan_idx_c, 2);
1444 else
1445
2/2
✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 4737951 times.
4813875 if (lc->tu.cross_pf) {
1446 75924 ptrdiff_t stride = s->cur_frame->f->linesize[2];
1447 75924 int hshift = sps->hshift[2];
1448 75924 int vshift = sps->vshift[2];
1449 75924 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1450 75924 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1451 75924 int size = 1 << log2_trafo_size_c;
1452
1453 75924 uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride +
1454 75924 ((x0 >> hshift) << sps->pixel_shift)];
1455
2/2
✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
3691476 for (i = 0; i < (size * size); i++) {
1456 3615552 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1457 }
1458 75924 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1459 }
1460 }
1461
4/4
✓ Branch 0 taken 6498772 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1670620 times.
✓ Branch 3 taken 4828152 times.
6498964 } else if (sps->chroma_format_idc && blk_idx == 3) {
1462 1670620 int trafo_size_h = 1 << (log2_trafo_size + 1);
1463 1670620 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1464
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 3007502 times.
✓ Branch 2 taken 1837489 times.
✓ Branch 3 taken 1670620 times.
3508109 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1465
2/2
✓ Branch 0 taken 1338142 times.
✓ Branch 1 taken 499347 times.
1837489 if (lc->cu.pred_mode == MODE_INTRA) {
1466 1338142 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1467 1338142 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1468 1338142 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1);
1469 }
1470
2/2
✓ Branch 0 taken 687250 times.
✓ Branch 1 taken 1150239 times.
1837489 if (cbf_cb[i])
1471 687250 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1472 log2_trafo_size, scan_idx_c, 1);
1473 }
1474
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 3007502 times.
✓ Branch 2 taken 1837489 times.
✓ Branch 3 taken 1670620 times.
3508109 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1475
2/2
✓ Branch 0 taken 1338142 times.
✓ Branch 1 taken 499347 times.
1837489 if (lc->cu.pred_mode == MODE_INTRA) {
1476 1338142 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1477 1338142 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1478 1338142 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2);
1479 }
1480
2/2
✓ Branch 0 taken 774190 times.
✓ Branch 1 taken 1063299 times.
1837489 if (cbf_cr[i])
1481 774190 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1482 log2_trafo_size, scan_idx_c, 2);
1483 }
1484 }
1485
3/4
✓ Branch 0 taken 4972411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2858046 times.
✓ Branch 3 taken 2114365 times.
4972411 } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
1486
4/4
✓ Branch 0 taken 1723077 times.
✓ Branch 1 taken 1134969 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1662489 times.
4053603 if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) {
1487 1195557 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1488 1195557 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1489 1195557 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
1490 1195557 sps->log2_ctb_size);
1491 1195557 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1);
1492 1195557 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2);
1493
2/2
✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 1183090 times.
1195557 if (sps->chroma_format_idc == 2) {
1494 12467 ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c),
1495 12467 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1496 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1);
1497 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2);
1498 }
1499
2/2
✓ Branch 0 taken 375661 times.
✓ Branch 1 taken 1286828 times.
1662489 } else if (blk_idx == 3) {
1500 375661 int trafo_size_h = 1 << (log2_trafo_size + 1);
1501 375661 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1502 375661 ff_hevc_set_neighbour_available(lc, xBase, yBase,
1503 375661 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1504 375661 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1);
1505 375661 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2);
1506
2/2
✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 371465 times.
375661 if (sps->chroma_format_idc == 2) {
1507 4196 ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size),
1508 4196 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1509 4196 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1);
1510 4196 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2);
1511 }
1512 }
1513 }
1514
1515 17669637 return 0;
1516 }
1517
1518 403332 static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps,
1519 int x0, int y0, int log2_cb_size)
1520 {
1521 403332 int cb_size = 1 << log2_cb_size;
1522 403332 int log2_min_pu_size = sps->log2_min_pu_size;
1523
1524 403332 int min_pu_width = sps->min_pu_width;
1525 403332 int x_end = FFMIN(x0 + cb_size, sps->width);
1526 403332 int y_end = FFMIN(y0 + cb_size, sps->height);
1527 int i, j;
1528
1529
2/2
✓ Branch 0 taken 562404 times.
✓ Branch 1 taken 403332 times.
965736 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1530
2/2
✓ Branch 0 taken 1073856 times.
✓ Branch 1 taken 562404 times.
1636260 for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
1531 1073856 is_pcm[i + j * min_pu_width] = 2;
1532 403332 }
1533
1534 21177588 static int hls_transform_tree(HEVCLocalContext *lc,
1535 const HEVCLayerContext *l,
1536 const HEVCPPS *pps, const HEVCSPS *sps,
1537 int x0, int y0,
1538 int xBase, int yBase, int cb_xBase, int cb_yBase,
1539 int log2_cb_size, int log2_trafo_size,
1540 int trafo_depth, int blk_idx,
1541 const int *base_cbf_cb, const int *base_cbf_cr)
1542 {
1543 21177588 const HEVCContext *const s = lc->parent;
1544 uint8_t split_transform_flag;
1545 int cbf_cb[2];
1546 int cbf_cr[2];
1547 int ret;
1548
1549 21177588 cbf_cb[0] = base_cbf_cb[0];
1550 21177588 cbf_cb[1] = base_cbf_cb[1];
1551 21177588 cbf_cr[0] = base_cbf_cr[0];
1552 21177588 cbf_cr[1] = base_cbf_cr[1];
1553
1554
2/2
✓ Branch 0 taken 7107443 times.
✓ Branch 1 taken 14070145 times.
21177588 if (lc->cu.intra_split_flag) {
1555
2/2
✓ Branch 0 taken 5330300 times.
✓ Branch 1 taken 1777143 times.
7107443 if (trafo_depth == 1) {
1556 5330300 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1557
2/2
✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 5194896 times.
5330300 if (sps->chroma_format_idc == 3) {
1558 135404 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx];
1559 135404 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx];
1560 } else {
1561 5194896 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1562 5194896 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1563 }
1564 }
1565 } else {
1566 14070145 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0];
1567 14070145 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1568 14070145 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1569 }
1570
1571
2/2
✓ Branch 0 taken 21052871 times.
✓ Branch 1 taken 124717 times.
21177588 if (log2_trafo_size <= sps->log2_max_trafo_size &&
1572
2/2
✓ Branch 0 taken 11529867 times.
✓ Branch 1 taken 9523004 times.
21052871 log2_trafo_size > sps->log2_min_tb_size &&
1573
2/2
✓ Branch 0 taken 9026632 times.
✓ Branch 1 taken 2503235 times.
11529867 trafo_depth < lc->cu.max_trafo_depth &&
1574
4/4
✓ Branch 0 taken 1909500 times.
✓ Branch 1 taken 7117132 times.
✓ Branch 2 taken 584312 times.
✓ Branch 3 taken 1325188 times.
9026632 !(lc->cu.intra_split_flag && trafo_depth == 0)) {
1575 7701444 split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size);
1576 } else {
1577 29551486 int inter_split = sps->max_transform_hierarchy_depth_inter == 0 &&
1578
2/2
✓ Branch 0 taken 1552658 times.
✓ Branch 1 taken 1046540 times.
2599198 lc->cu.pred_mode == MODE_INTER &&
1579
6/6
✓ Branch 0 taken 2599198 times.
✓ Branch 1 taken 10876946 times.
✓ Branch 2 taken 930859 times.
✓ Branch 3 taken 621799 times.
✓ Branch 4 taken 184863 times.
✓ Branch 5 taken 745996 times.
16075342 lc->cu.part_mode != PART_2Nx2N &&
1580 trafo_depth == 0;
1581
1582 13476144 split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size ||
1583
8/8
✓ Branch 0 taken 13351427 times.
✓ Branch 1 taken 124717 times.
✓ Branch 2 taken 6515084 times.
✓ Branch 3 taken 6836343 times.
✓ Branch 4 taken 5189896 times.
✓ Branch 5 taken 1325188 times.
✓ Branch 6 taken 169700 times.
✓ Branch 7 taken 11856539 times.
13476144 (lc->cu.intra_split_flag && trafo_depth == 0) ||
1584 inter_split;
1585 }
1586
1587
6/6
✓ Branch 0 taken 21177396 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 9394924 times.
✓ Branch 3 taken 11782472 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 9080508 times.
21177588 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1588
4/4
✓ Branch 0 taken 4951292 times.
✓ Branch 1 taken 7145596 times.
✓ Branch 2 taken 1374000 times.
✓ Branch 3 taken 3577292 times.
12096888 if (trafo_depth == 0 || cbf_cb[0]) {
1589 8519596 cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1590
6/6
✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 7921330 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
8519596 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1591 526996 cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1592 }
1593 }
1594
1595
4/4
✓ Branch 0 taken 4951292 times.
✓ Branch 1 taken 7145596 times.
✓ Branch 2 taken 1282156 times.
✓ Branch 3 taken 3669136 times.
12096888 if (trafo_depth == 0 || cbf_cr[0]) {
1596 8427752 cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1597
6/6
✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 7682446 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
8427752 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1598 661961 cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1599 }
1600 }
1601 }
1602
1603
2/2
✓ Branch 0 taken 3507950 times.
✓ Branch 1 taken 17669638 times.
21177588 if (split_transform_flag) {
1604 3507950 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1605 3507950 const int x1 = x0 + trafo_size_split;
1606 3507950 const int y1 = y0 + trafo_size_split;
1607
1608 #define SUBDIVIDE(x, y, idx) \
1609 do { \
1610 ret = hls_transform_tree(lc, l, pps, sps, \
1611 x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1612 log2_trafo_size - 1, trafo_depth + 1, idx, \
1613 cbf_cb, cbf_cr); \
1614 if (ret < 0) \
1615 return ret; \
1616 } while (0)
1617
1618
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3507950 times.
3507950 SUBDIVIDE(x0, y0, 0);
1619
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3507950 times.
3507950 SUBDIVIDE(x1, y0, 1);
1620
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3507950 times.
3507950 SUBDIVIDE(x0, y1, 2);
1621
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3507950 times.
3507950 SUBDIVIDE(x1, y1, 3);
1622
1623 #undef SUBDIVIDE
1624 } else {
1625 17669638 int min_tu_size = 1 << sps->log2_min_tb_size;
1626 17669638 int log2_min_tu_size = sps->log2_min_tb_size;
1627 17669638 int min_tu_width = sps->min_tb_width;
1628 17669638 int cbf_luma = 1;
1629
1630
4/4
✓ Branch 0 taken 6662165 times.
✓ Branch 1 taken 11007473 times.
✓ Branch 2 taken 1589494 times.
✓ Branch 3 taken 5072671 times.
17669638 if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1631
4/4
✓ Branch 0 taken 1257801 times.
✓ Branch 1 taken 331693 times.
✓ Branch 2 taken 1090362 times.
✓ Branch 3 taken 167439 times.
1589494 cbf_cb[0] || cbf_cr[0] ||
1632
6/6
✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 1065686 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
1090362 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1633 16591922 cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth);
1634 }
1635
1636 17669638 ret = hls_transform_unit(lc, l, pps, sps,
1637 x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1638 log2_cb_size, log2_trafo_size,
1639 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1640
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17669637 times.
17669638 if (ret < 0)
1641 1 return ret;
1642 // TODO: store cbf_luma somewhere else
1643
2/2
✓ Branch 0 taken 11423835 times.
✓ Branch 1 taken 6245802 times.
17669637 if (cbf_luma) {
1644 int i, j;
1645
2/2
✓ Branch 0 taken 24991069 times.
✓ Branch 1 taken 11423835 times.
36414904 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1646
2/2
✓ Branch 0 taken 95811657 times.
✓ Branch 1 taken 24991069 times.
120802726 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1647 95811657 int x_tu = (x0 + j) >> log2_min_tu_size;
1648 95811657 int y_tu = (y0 + i) >> log2_min_tu_size;
1649 95811657 l->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1650 }
1651 }
1652
2/2
✓ Branch 0 taken 17136817 times.
✓ Branch 1 taken 532820 times.
17669637 if (!s->sh.disable_deblocking_filter_flag) {
1653 17136817 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size);
1654
2/2
✓ Branch 0 taken 409146 times.
✓ Branch 1 taken 16727671 times.
17136817 if (pps->transquant_bypass_enable_flag &&
1655
2/2
✓ Branch 0 taken 311137 times.
✓ Branch 1 taken 98009 times.
409146 lc->cu.cu_transquant_bypass_flag)
1656 311137 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size);
1657 }
1658 }
1659 21177587 return 0;
1660 }
1661
1662 12433 static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l,
1663 const HEVCPPS *pps, int x0, int y0, int log2_cb_size)
1664 {
1665 12433 const HEVCContext *const s = lc->parent;
1666 12433 const HEVCSPS *const sps = pps->sps;
1667 GetBitContext gb;
1668 12433 int cb_size = 1 << log2_cb_size;
1669 12433 ptrdiff_t stride0 = s->cur_frame->f->linesize[0];
1670 12433 uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)];
1671
1672 24866 int length = cb_size * cb_size * sps->pcm.bit_depth + (sps->chroma_format_idc != 0 ?
1673 12433 (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) +
1674 12433 ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) *
1675
1/2
✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
12433 sps->pcm.bit_depth_chroma : 0);
1676 12433 const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
1677 int ret;
1678
1679
2/2
✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
12433 if (!s->sh.disable_deblocking_filter_flag)
1680 6937 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
1681
1682 12433 ret = init_get_bits(&gb, pcm, length);
1683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
1684 return ret;
1685
1686 12433 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth);
1687
1/2
✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
12433 if (sps->chroma_format_idc) {
1688 12433 ptrdiff_t stride1 = s->cur_frame->f->linesize[1];
1689 12433 ptrdiff_t stride2 = s->cur_frame->f->linesize[2];
1690 12433 uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)];
1691 12433 uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)];
1692
1693 12433 s->hevcdsp.put_pcm(dst1, stride1,
1694 12433 cb_size >> sps->hshift[1],
1695 12433 cb_size >> sps->vshift[1],
1696 12433 &gb, sps->pcm.bit_depth_chroma);
1697 12433 s->hevcdsp.put_pcm(dst2, stride2,
1698 12433 cb_size >> sps->hshift[2],
1699 12433 cb_size >> sps->vshift[2],
1700 12433 &gb, sps->pcm.bit_depth_chroma);
1701 }
1702
1703 12433 return 0;
1704 }
1705
1706 /**
1707 * 8.5.3.2.2.1 Luma sample unidirectional interpolation process
1708 *
1709 * @param s HEVC decoding context
1710 * @param dst target buffer for block data at block position
1711 * @param dststride stride of the dst buffer
1712 * @param ref reference picture buffer at origin (0, 0)
1713 * @param mv motion vector (relative to block position) to get pixel data from
1714 * @param x_off horizontal position of block from origin (0, 0)
1715 * @param y_off vertical position of block from origin (0, 0)
1716 * @param block_w width of block
1717 * @param block_h height of block
1718 * @param luma_weight weighting factor applied to the luma prediction
1719 * @param luma_offset additive offset applied to the luma prediction value
1720 */
1721
1722 6342554 static void luma_mc_uni(HEVCLocalContext *lc,
1723 const HEVCPPS *pps, const HEVCSPS *sps,
1724 uint8_t *dst, ptrdiff_t dststride,
1725 const AVFrame *ref, const Mv *mv, int x_off, int y_off,
1726 int block_w, int block_h, int luma_weight, int luma_offset)
1727 {
1728 6342554 const HEVCContext *const s = lc->parent;
1729 6342554 const uint8_t *src = ref->data[0];
1730 6342554 ptrdiff_t srcstride = ref->linesize[0];
1731 6342554 int pic_width = sps->width;
1732 6342554 int pic_height = sps->height;
1733 6342554 int mx = mv->x & 3;
1734 6342554 int my = mv->y & 3;
1735
4/4
✓ Branch 0 taken 3280827 times.
✓ Branch 1 taken 3061727 times.
✓ Branch 2 taken 3220239 times.
✓ Branch 3 taken 60588 times.
12624520 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1736
4/4
✓ Branch 0 taken 3061727 times.
✓ Branch 1 taken 3220239 times.
✓ Branch 2 taken 73276 times.
✓ Branch 3 taken 2988451 times.
6281966 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1737 6342554 int idx = hevc_pel_weight[block_w];
1738
1739 6342554 x_off += mv->x >> 2;
1740 6342554 y_off += mv->y >> 2;
1741 6342554 src += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1742
1743
4/4
✓ Branch 0 taken 6274424 times.
✓ Branch 1 taken 68130 times.
✓ Branch 2 taken 6154893 times.
✓ Branch 3 taken 119531 times.
6342554 if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
1744
2/2
✓ Branch 0 taken 6078917 times.
✓ Branch 1 taken 75976 times.
6154893 x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1745
2/2
✓ Branch 0 taken 5860745 times.
✓ Branch 1 taken 218172 times.
6078917 y_off >= pic_height - block_h - QPEL_EXTRA_AFTER ||
1746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5860745 times.
5860745 ref == s->cur_frame->f) {
1747 481809 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1748 481809 int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1749 481809 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1750
1751 481809 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
1752 edge_emu_stride, srcstride,
1753 block_w + QPEL_EXTRA,
1754 block_h + QPEL_EXTRA,
1755 x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE,
1756 pic_width, pic_height);
1757 481809 src = lc->edge_emu_buffer + buf_offset;
1758 481809 srcstride = edge_emu_stride;
1759 }
1760
1761
2/2
✓ Branch 0 taken 6208690 times.
✓ Branch 1 taken 133864 times.
6342554 if (!weight_flag)
1762 6208690 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride,
1763 block_h, mx, my, block_w);
1764 else
1765 133864 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride,
1766 133864 block_h, s->sh.luma_log2_weight_denom,
1767 luma_weight, luma_offset, mx, my, block_w);
1768 6342554 }
1769
1770 /**
1771 * 8.5.3.2.2.1 Luma sample bidirectional interpolation process
1772 *
1773 * @param s HEVC decoding context
1774 * @param dst target buffer for block data at block position
1775 * @param dststride stride of the dst buffer
1776 * @param ref0 reference picture0 buffer at origin (0, 0)
1777 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1778 * @param x_off horizontal position of block from origin (0, 0)
1779 * @param y_off vertical position of block from origin (0, 0)
1780 * @param block_w width of block
1781 * @param block_h height of block
1782 * @param ref1 reference picture1 buffer at origin (0, 0)
1783 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1784 * @param current_mv current motion vector structure
1785 */
1786 3992083 static void luma_mc_bi(HEVCLocalContext *lc,
1787 const HEVCPPS *pps, const HEVCSPS *sps,
1788 uint8_t *dst, ptrdiff_t dststride,
1789 const AVFrame *ref0, const Mv *mv0, int x_off, int y_off,
1790 int block_w, int block_h, const AVFrame *ref1,
1791 const Mv *mv1, struct MvField *current_mv)
1792 {
1793 3992083 const HEVCContext *const s = lc->parent;
1794 3992083 ptrdiff_t src0stride = ref0->linesize[0];
1795 3992083 ptrdiff_t src1stride = ref1->linesize[0];
1796 3992083 int pic_width = sps->width;
1797 3992083 int pic_height = sps->height;
1798 3992083 int mx0 = mv0->x & 3;
1799 3992083 int my0 = mv0->y & 3;
1800 3992083 int mx1 = mv1->x & 3;
1801 3992083 int my1 = mv1->y & 3;
1802
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3992083 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7984166 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1803
3/4
✓ Branch 0 taken 3992083 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 73498 times.
✓ Branch 3 taken 3918585 times.
3992083 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1804 3992083 int x_off0 = x_off + (mv0->x >> 2);
1805 3992083 int y_off0 = y_off + (mv0->y >> 2);
1806 3992083 int x_off1 = x_off + (mv1->x >> 2);
1807 3992083 int y_off1 = y_off + (mv1->y >> 2);
1808 3992083 int idx = hevc_pel_weight[block_w];
1809
1810 3992083 const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1811 3992083 const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1812
1813
4/4
✓ Branch 0 taken 3934283 times.
✓ Branch 1 taken 57800 times.
✓ Branch 2 taken 3826999 times.
✓ Branch 3 taken 107284 times.
3992083 if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER ||
1814
2/2
✓ Branch 0 taken 3757951 times.
✓ Branch 1 taken 69048 times.
3826999 x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1815
2/2
✓ Branch 0 taken 209680 times.
✓ Branch 1 taken 3548271 times.
3757951 y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1816 443812 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1817 443812 int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1818 443812 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1819
1820 443812 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset,
1821 edge_emu_stride, src0stride,
1822 block_w + QPEL_EXTRA,
1823 block_h + QPEL_EXTRA,
1824 x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE,
1825 pic_width, pic_height);
1826 443812 src0 = lc->edge_emu_buffer + buf_offset;
1827 443812 src0stride = edge_emu_stride;
1828 }
1829
1830
4/4
✓ Branch 0 taken 3928081 times.
✓ Branch 1 taken 64002 times.
✓ Branch 2 taken 3821452 times.
✓ Branch 3 taken 106629 times.
3992083 if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER ||
1831
2/2
✓ Branch 0 taken 3750497 times.
✓ Branch 1 taken 70955 times.
3821452 x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1832
2/2
✓ Branch 0 taken 212853 times.
✓ Branch 1 taken 3537644 times.
3750497 y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1833 454439 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1834 454439 int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1835 454439 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1836
1837 454439 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset,
1838 edge_emu_stride, src1stride,
1839 block_w + QPEL_EXTRA,
1840 block_h + QPEL_EXTRA,
1841 x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE,
1842 pic_width, pic_height);
1843 454439 src1 = lc->edge_emu_buffer2 + buf_offset;
1844 454439 src1stride = edge_emu_stride;
1845 }
1846
1847 3992083 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride,
1848 block_h, mx0, my0, block_w);
1849
2/2
✓ Branch 0 taken 3918585 times.
✓ Branch 1 taken 73498 times.
3992083 if (!weight_flag)
1850 3918585 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1851 block_h, mx1, my1, block_w);
1852 else
1853 73498 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1854 73498 block_h, s->sh.luma_log2_weight_denom,
1855 73498 s->sh.luma_weight_l0[current_mv->ref_idx[0]],
1856 73498 s->sh.luma_weight_l1[current_mv->ref_idx[1]],
1857 73498 s->sh.luma_offset_l0[current_mv->ref_idx[0]] +
1858 73498 s->sh.luma_offset_l1[current_mv->ref_idx[1]],
1859 mx1, my1, block_w);
1860
1861 3992083 }
1862
1863 /**
1864 * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process
1865 *
1866 * @param s HEVC decoding context
1867 * @param dst1 target buffer for block data at block position (U plane)
1868 * @param dst2 target buffer for block data at block position (V plane)
1869 * @param dststride stride of the dst1 and dst2 buffers
1870 * @param ref reference picture buffer at origin (0, 0)
1871 * @param mv motion vector (relative to block position) to get pixel data from
1872 * @param x_off horizontal position of block from origin (0, 0)
1873 * @param y_off vertical position of block from origin (0, 0)
1874 * @param block_w width of block
1875 * @param block_h height of block
1876 * @param chroma_weight weighting factor applied to the chroma prediction
1877 * @param chroma_offset additive offset applied to the chroma prediction value
1878 */
1879
1880 12685108 static void chroma_mc_uni(HEVCLocalContext *lc,
1881 const HEVCPPS *pps, const HEVCSPS *sps,
1882 uint8_t *dst0,
1883 ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist,
1884 int x_off, int y_off, int block_w, int block_h,
1885 const struct MvField *current_mv, int chroma_weight, int chroma_offset)
1886 {
1887 12685108 const HEVCContext *const s = lc->parent;
1888 12685108 int pic_width = sps->width >> sps->hshift[1];
1889 12685108 int pic_height = sps->height >> sps->vshift[1];
1890 12685108 const Mv *mv = &current_mv->mv[reflist];
1891
4/4
✓ Branch 0 taken 6561654 times.
✓ Branch 1 taken 6123454 times.
✓ Branch 2 taken 6440478 times.
✓ Branch 3 taken 121176 times.
25249040 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1892
4/4
✓ Branch 0 taken 6123454 times.
✓ Branch 1 taken 6440478 times.
✓ Branch 2 taken 146552 times.
✓ Branch 3 taken 5976902 times.
12563932 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1893 12685108 int idx = hevc_pel_weight[block_w];
1894 12685108 int hshift = sps->hshift[1];
1895 12685108 int vshift = sps->vshift[1];
1896 12685108 intptr_t mx = av_zero_extend(mv->x, 2 + hshift);
1897 12685108 intptr_t my = av_zero_extend(mv->y, 2 + vshift);
1898 12685108 intptr_t _mx = mx << (1 - hshift);
1899 12685108 intptr_t _my = my << (1 - vshift);
1900
2/4
✓ Branch 0 taken 12685108 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12685108 times.
12685108 int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2];
1901
1902 12685108 x_off += mv->x >> (2 + hshift);
1903 12685108 y_off += mv->y >> (2 + vshift);
1904 12685108 src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1905
1906
4/4
✓ Branch 0 taken 12562024 times.
✓ Branch 1 taken 123084 times.
✓ Branch 2 taken 12322816 times.
✓ Branch 3 taken 239208 times.
12685108 if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1907
2/2
✓ Branch 0 taken 12170872 times.
✓ Branch 1 taken 151944 times.
12322816 x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1908
3/4
✓ Branch 0 taken 11734450 times.
✓ Branch 1 taken 436422 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11734450 times.
12170872 y_off >= pic_height - block_h - EPEL_EXTRA_AFTER ||
1909 emu) {
1910 950658 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1911 950658 int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift));
1912 950658 int buf_offset0 = EPEL_EXTRA_BEFORE *
1913 950658 (edge_emu_stride + (1 << sps->pixel_shift));
1914 950658 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0,
1915 edge_emu_stride, srcstride,
1916 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1917 x_off - EPEL_EXTRA_BEFORE,
1918 y_off - EPEL_EXTRA_BEFORE,
1919 pic_width, pic_height);
1920
1921 950658 src0 = lc->edge_emu_buffer + buf_offset0;
1922 950658 srcstride = edge_emu_stride;
1923 }
1924
2/2
✓ Branch 0 taken 12417380 times.
✓ Branch 1 taken 267728 times.
12685108 if (!weight_flag)
1925 12417380 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1926 block_h, _mx, _my, block_w);
1927 else
1928 267728 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1929 267728 block_h, s->sh.chroma_log2_weight_denom,
1930 chroma_weight, chroma_offset, _mx, _my, block_w);
1931 12685108 }
1932
1933 /**
1934 * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process
1935 *
1936 * @param s HEVC decoding context
1937 * @param dst target buffer for block data at block position
1938 * @param dststride stride of the dst buffer
1939 * @param ref0 reference picture0 buffer at origin (0, 0)
1940 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1941 * @param x_off horizontal position of block from origin (0, 0)
1942 * @param y_off vertical position of block from origin (0, 0)
1943 * @param block_w width of block
1944 * @param block_h height of block
1945 * @param ref1 reference picture1 buffer at origin (0, 0)
1946 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1947 * @param current_mv current motion vector structure
1948 * @param cidx chroma component(cb, cr)
1949 */
1950 7984166 static void chroma_mc_bi(HEVCLocalContext *lc,
1951 const HEVCPPS *pps, const HEVCSPS *sps,
1952 uint8_t *dst0, ptrdiff_t dststride,
1953 const AVFrame *ref0, const AVFrame *ref1,
1954 int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx)
1955 {
1956 7984166 const HEVCContext *const s = lc->parent;
1957 7984166 const uint8_t *src1 = ref0->data[cidx+1];
1958 7984166 const uint8_t *src2 = ref1->data[cidx+1];
1959 7984166 ptrdiff_t src1stride = ref0->linesize[cidx+1];
1960 7984166 ptrdiff_t src2stride = ref1->linesize[cidx+1];
1961
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7984166 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15968332 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1962
3/4
✓ Branch 0 taken 7984166 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 146996 times.
✓ Branch 3 taken 7837170 times.
7984166 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1963 7984166 int pic_width = sps->width >> sps->hshift[1];
1964 7984166 int pic_height = sps->height >> sps->vshift[1];
1965 7984166 const Mv *const mv0 = &current_mv->mv[0];
1966 7984166 const Mv *const mv1 = &current_mv->mv[1];
1967 7984166 int hshift = sps->hshift[1];
1968 7984166 int vshift = sps->vshift[1];
1969
1970 7984166 intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift);
1971 7984166 intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift);
1972 7984166 intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift);
1973 7984166 intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift);
1974 7984166 intptr_t _mx0 = mx0 << (1 - hshift);
1975 7984166 intptr_t _my0 = my0 << (1 - vshift);
1976 7984166 intptr_t _mx1 = mx1 << (1 - hshift);
1977 7984166 intptr_t _my1 = my1 << (1 - vshift);
1978
1979 7984166 int x_off0 = x_off + (mv0->x >> (2 + hshift));
1980 7984166 int y_off0 = y_off + (mv0->y >> (2 + vshift));
1981 7984166 int x_off1 = x_off + (mv1->x >> (2 + hshift));
1982 7984166 int y_off1 = y_off + (mv1->y >> (2 + vshift));
1983 7984166 int idx = hevc_pel_weight[block_w];
1984 7984166 src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1985 7984166 src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1986
1987
4/4
✓ Branch 0 taken 7874824 times.
✓ Branch 1 taken 109342 times.
✓ Branch 2 taken 7660144 times.
✓ Branch 3 taken 214680 times.
7984166 if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER ||
1988
2/2
✓ Branch 0 taken 7522052 times.
✓ Branch 1 taken 138092 times.
7660144 x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1989
2/2
✓ Branch 0 taken 418772 times.
✓ Branch 1 taken 7103280 times.
7522052 y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1990 880886 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1991 880886 int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift));
1992 880886 int buf_offset1 = EPEL_EXTRA_BEFORE *
1993 880886 (edge_emu_stride + (1 << sps->pixel_shift));
1994
1995 880886 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1,
1996 edge_emu_stride, src1stride,
1997 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1998 x_off0 - EPEL_EXTRA_BEFORE,
1999 y_off0 - EPEL_EXTRA_BEFORE,
2000 pic_width, pic_height);
2001
2002 880886 src1 = lc->edge_emu_buffer + buf_offset1;
2003 880886 src1stride = edge_emu_stride;
2004 }
2005
2006
4/4
✓ Branch 0 taken 7861558 times.
✓ Branch 1 taken 122608 times.
✓ Branch 2 taken 7648578 times.
✓ Branch 3 taken 212980 times.
7984166 if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER ||
2007
2/2
✓ Branch 0 taken 7506674 times.
✓ Branch 1 taken 141904 times.
7648578 x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
2008
2/2
✓ Branch 0 taken 425380 times.
✓ Branch 1 taken 7081294 times.
7506674 y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
2009 902872 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
2010 902872 int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift));
2011 902872 int buf_offset1 = EPEL_EXTRA_BEFORE *
2012 902872 (edge_emu_stride + (1 << sps->pixel_shift));
2013
2014 902872 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1,
2015 edge_emu_stride, src2stride,
2016 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
2017 x_off1 - EPEL_EXTRA_BEFORE,
2018 y_off1 - EPEL_EXTRA_BEFORE,
2019 pic_width, pic_height);
2020
2021 902872 src2 = lc->edge_emu_buffer2 + buf_offset1;
2022 902872 src2stride = edge_emu_stride;
2023 }
2024
2025 7984166 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride,
2026 block_h, _mx0, _my0, block_w);
2027
2/2
✓ Branch 0 taken 7837170 times.
✓ Branch 1 taken 146996 times.
7984166 if (!weight_flag)
2028 7837170 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
2029 7837170 src2, src2stride, lc->tmp,
2030 block_h, _mx1, _my1, block_w);
2031 else
2032 146996 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
2033 146996 src2, src2stride, lc->tmp,
2034 block_h,
2035 146996 s->sh.chroma_log2_weight_denom,
2036 146996 s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx],
2037 146996 s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx],
2038 146996 s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx] +
2039 146996 s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx],
2040 _mx1, _my1, block_w);
2041 7984166 }
2042
2043 14326720 static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref,
2044 const Mv *mv, int y0, int height)
2045 {
2046
2/2
✓ Branch 0 taken 111132 times.
✓ Branch 1 taken 14215588 times.
14326720 if (s->avctx->active_thread_type == FF_THREAD_FRAME ) {
2047 111132 int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9);
2048
2049 111132 ff_progress_frame_await(&ref->tf, y);
2050 }
2051 14326720 }
2052
2053 2833077 static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc,
2054 const HEVCPPS *pps, const HEVCSPS *sps,
2055 int x0, int y0, int nPbW,
2056 int nPbH, int log2_cb_size, int part_idx,
2057 int merge_idx, MvField *mv)
2058 {
2059 2833077 const HEVCContext *const s = lc->parent;
2060 2833077 enum InterPredIdc inter_pred_idc = PRED_L0;
2061 int mvp_flag;
2062
2063 2833077 ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size);
2064 2833077 mv->pred_flag = 0;
2065
2/2
✓ Branch 0 taken 1922844 times.
✓ Branch 1 taken 910233 times.
2833077 if (s->sh.slice_type == HEVC_SLICE_B)
2066 1922844 inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH);
2067
2068
2/2
✓ Branch 0 taken 2423759 times.
✓ Branch 1 taken 409318 times.
2833077 if (inter_pred_idc != PRED_L1) {
2069
1/2
✓ Branch 0 taken 2423759 times.
✗ Branch 1 not taken.
2423759 if (s->sh.nb_refs[L0])
2070 2423759 mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]);
2071
2072 2423759 mv->pred_flag = PF_L0;
2073 2423759 ff_hevc_hls_mvd_coding(lc, x0, y0, 0);
2074 2423759 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2075 2423759 ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2076 part_idx, merge_idx, mv, mvp_flag, 0);
2077 2423759 mv->mv[0].x += lc->pu.mvd.x;
2078 2423759 mv->mv[0].y += lc->pu.mvd.y;
2079 }
2080
2081
2/2
✓ Branch 0 taken 834243 times.
✓ Branch 1 taken 1998834 times.
2833077 if (inter_pred_idc != PRED_L0) {
2082
1/2
✓ Branch 0 taken 834243 times.
✗ Branch 1 not taken.
834243 if (s->sh.nb_refs[L1])
2083 834243 mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]);
2084
2085
4/4
✓ Branch 0 taken 193172 times.
✓ Branch 1 taken 641071 times.
✓ Branch 2 taken 163605 times.
✓ Branch 3 taken 29567 times.
834243 if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) {
2086 163605 AV_ZERO32(&lc->pu.mvd);
2087 } else {
2088 670638 ff_hevc_hls_mvd_coding(lc, x0, y0, 1);
2089 }
2090
2091 834243 mv->pred_flag += PF_L1;
2092 834243 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
2093 834243 ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2094 part_idx, merge_idx, mv, mvp_flag, 1);
2095 834243 mv->mv[1].x += lc->pu.mvd.x;
2096 834243 mv->mv[1].y += lc->pu.mvd.y;
2097 }
2098 2833077 }
2099
2100 10334637 static void hls_prediction_unit(HEVCLocalContext *lc,
2101 const HEVCLayerContext *l,
2102 const HEVCPPS *pps, const HEVCSPS *sps,
2103 int x0, int y0, int nPbW, int nPbH,
2104 int log2_cb_size, int partIdx, int idx)
2105 {
2106 #define POS(c_idx, x, y) \
2107 s->cur_frame->f->data[c_idx] ? \
2108 &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \
2109 (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] : NULL
2110 10334637 const HEVCContext *const s = lc->parent;
2111 10334637 int merge_idx = 0;
2112 10334637 struct MvField current_mv = {{{ 0 }}};
2113
2114 10334637 int min_pu_width = sps->min_pu_width;
2115
2116 10334637 MvField *tab_mvf = s->cur_frame->tab_mvf;
2117 10334637 const RefPicList *refPicList = s->cur_frame->refPicList;
2118 10334637 const HEVCFrame *ref0 = NULL, *ref1 = NULL;
2119 10334637 const int *linesize = s->cur_frame->f->linesize;
2120 10334637 uint8_t *dst0 = s->cur_frame->f->data[0] + y0 * linesize[0] + (x0 << sps->pixel_shift);
2121
1/2
✓ Branch 0 taken 10334637 times.
✗ Branch 1 not taken.
10334637 uint8_t *dst1 = POS(1, x0, y0);
2122
1/2
✓ Branch 0 taken 10334637 times.
✗ Branch 1 not taken.
10334637 uint8_t *dst2 = POS(2, x0, y0);
2123 10334637 int log2_min_cb_size = sps->log2_min_cb_size;
2124 10334637 int min_cb_width = sps->min_cb_width;
2125 10334637 int x_cb = x0 >> log2_min_cb_size;
2126 10334637 int y_cb = y0 >> log2_min_cb_size;
2127 int x_pu, y_pu;
2128 int i, j;
2129
2130 10334637 int skip_flag = SAMPLE_CTB(l->skip_flag, x_cb, y_cb);
2131
2132
2/2
✓ Branch 0 taken 5769030 times.
✓ Branch 1 taken 4565607 times.
10334637 if (!skip_flag)
2133 5769030 lc->pu.merge_flag = ff_hevc_merge_flag_decode(lc);
2134
2135
4/4
✓ Branch 0 taken 5769030 times.
✓ Branch 1 taken 4565607 times.
✓ Branch 2 taken 2935953 times.
✓ Branch 3 taken 2833077 times.
10334637 if (skip_flag || lc->pu.merge_flag) {
2136
2/2
✓ Branch 0 taken 7424707 times.
✓ Branch 1 taken 76853 times.
7501560 if (s->sh.max_num_merge_cand > 1)
2137 7424707 merge_idx = ff_hevc_merge_idx_decode(lc);
2138 else
2139 76853 merge_idx = 0;
2140
2141 7501560 ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
2142 partIdx, merge_idx, &current_mv);
2143 } else {
2144 2833077 hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size,
2145 partIdx, merge_idx, &current_mv);
2146 }
2147
2148 10334637 x_pu = x0 >> sps->log2_min_pu_size;
2149 10334637 y_pu = y0 >> sps->log2_min_pu_size;
2150
2151
2/2
✓ Branch 0 taken 40422698 times.
✓ Branch 1 taken 10334637 times.
50757335 for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++)
2152
2/2
✓ Branch 0 taken 258353932 times.
✓ Branch 1 taken 40422698 times.
298776630 for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++)
2153 258353932 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
2154
2155
2/2
✓ Branch 0 taken 9515439 times.
✓ Branch 1 taken 819198 times.
10334637 if (current_mv.pred_flag & PF_L0) {
2156 9515439 ref0 = refPicList[0].ref[current_mv.ref_idx[0]];
2157
2/4
✓ Branch 0 taken 9515439 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9515439 times.
9515439 if (!ref0 || !ref0->f)
2158 return;
2159 9515439 hevc_await_progress(s, ref0, &current_mv.mv[0], y0, nPbH);
2160 }
2161
2/2
✓ Branch 0 taken 4811281 times.
✓ Branch 1 taken 5523356 times.
10334637 if (current_mv.pred_flag & PF_L1) {
2162 4811281 ref1 = refPicList[1].ref[current_mv.ref_idx[1]];
2163
2/4
✓ Branch 0 taken 4811281 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4811281 times.
4811281 if (!ref1 || !ref1->f)
2164 return;
2165 4811281 hevc_await_progress(s, ref1, &current_mv.mv[1], y0, nPbH);
2166 }
2167
2168
2/2
✓ Branch 0 taken 5523356 times.
✓ Branch 1 taken 4811281 times.
10334637 if (current_mv.pred_flag == PF_L0) {
2169 5523356 int x0_c = x0 >> sps->hshift[1];
2170 5523356 int y0_c = y0 >> sps->vshift[1];
2171 5523356 int nPbW_c = nPbW >> sps->hshift[1];
2172 5523356 int nPbH_c = nPbH >> sps->vshift[1];
2173
2174 5523356 luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f,
2175 &current_mv.mv[0], x0, y0, nPbW, nPbH,
2176 5523356 s->sh.luma_weight_l0[current_mv.ref_idx[0]],
2177 5523356 s->sh.luma_offset_l0[current_mv.ref_idx[0]]);
2178
2179
1/2
✓ Branch 0 taken 5523356 times.
✗ Branch 1 not taken.
5523356 if (sps->chroma_format_idc) {
2180 5523356 chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1],
2181 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2182 5523356 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]);
2183 5523356 chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2],
2184 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2185 5523356 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]);
2186 }
2187
2/2
✓ Branch 0 taken 819198 times.
✓ Branch 1 taken 3992083 times.
4811281 } else if (current_mv.pred_flag == PF_L1) {
2188 819198 int x0_c = x0 >> sps->hshift[1];
2189 819198 int y0_c = y0 >> sps->vshift[1];
2190 819198 int nPbW_c = nPbW >> sps->hshift[1];
2191 819198 int nPbH_c = nPbH >> sps->vshift[1];
2192
2193 819198 luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f,
2194 &current_mv.mv[1], x0, y0, nPbW, nPbH,
2195 819198 s->sh.luma_weight_l1[current_mv.ref_idx[1]],
2196 819198 s->sh.luma_offset_l1[current_mv.ref_idx[1]]);
2197
2198
1/2
✓ Branch 0 taken 819198 times.
✗ Branch 1 not taken.
819198 if (sps->chroma_format_idc) {
2199 819198 chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1],
2200 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2201 819198 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]);
2202
2203 819198 chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2],
2204 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
2205 819198 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]);
2206 }
2207
1/2
✓ Branch 0 taken 3992083 times.
✗ Branch 1 not taken.
3992083 } else if (current_mv.pred_flag == PF_BI) {
2208 3992083 int x0_c = x0 >> sps->hshift[1];
2209 3992083 int y0_c = y0 >> sps->vshift[1];
2210 3992083 int nPbW_c = nPbW >> sps->hshift[1];
2211 3992083 int nPbH_c = nPbH >> sps->vshift[1];
2212
2213 3992083 luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f,
2214 &current_mv.mv[0], x0, y0, nPbW, nPbH,
2215 3992083 ref1->f, &current_mv.mv[1], &current_mv);
2216
2217
1/2
✓ Branch 0 taken 3992083 times.
✗ Branch 1 not taken.
3992083 if (sps->chroma_format_idc) {
2218 3992083 chroma_mc_bi(lc, pps, sps, dst1, linesize[1], ref0->f, ref1->f,
2219 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 0);
2220
2221 3992083 chroma_mc_bi(lc, pps, sps, dst2, linesize[2], ref0->f, ref1->f,
2222 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 1);
2223 }
2224 }
2225 }
2226
2227 /**
2228 * 8.4.1
2229 */
2230 8626139 static int luma_intra_pred_mode(HEVCLocalContext *lc, const HEVCLayerContext *l,
2231 const HEVCSPS *sps,
2232 int x0, int y0, int pu_size,
2233 int prev_intra_luma_pred_flag)
2234 {
2235 8626139 const HEVCContext *const s = lc->parent;
2236 8626139 int x_pu = x0 >> sps->log2_min_pu_size;
2237 8626139 int y_pu = y0 >> sps->log2_min_pu_size;
2238 8626139 int min_pu_width = sps->min_pu_width;
2239 8626139 int size_in_pus = pu_size >> sps->log2_min_pu_size;
2240 8626139 int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2241 8626139 int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2242
2243
2/2
✓ Branch 0 taken 1091036 times.
✓ Branch 1 taken 129210 times.
1220246 int cand_up = (lc->ctb_up_flag || y0b) ?
2244
2/2
✓ Branch 0 taken 1220246 times.
✓ Branch 1 taken 7405893 times.
9846385 l->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
2245
2/2
✓ Branch 0 taken 613367 times.
✓ Branch 1 taken 85976 times.
699343 int cand_left = (lc->ctb_left_flag || x0b) ?
2246
2/2
✓ Branch 0 taken 699343 times.
✓ Branch 1 taken 7926796 times.
9325482 l->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC;
2247
2248 8626139 int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size);
2249
2250 8626139 MvField *tab_mvf = s->cur_frame->tab_mvf;
2251 int intra_pred_mode;
2252 int candidate[3];
2253 int i, j;
2254
2255 // intra_pred_mode prediction does not cross vertical CTB boundaries
2256
2/2
✓ Branch 0 taken 1161950 times.
✓ Branch 1 taken 7464189 times.
8626139 if ((y0 - 1) < y_ctb)
2257 1161950 cand_up = INTRA_DC;
2258
2259
2/2
✓ Branch 0 taken 1854903 times.
✓ Branch 1 taken 6771236 times.
8626139 if (cand_left == cand_up) {
2260
2/2
✓ Branch 0 taken 1134268 times.
✓ Branch 1 taken 720635 times.
1854903 if (cand_left < 2) {
2261 1134268 candidate[0] = INTRA_PLANAR;
2262 1134268 candidate[1] = INTRA_DC;
2263 1134268 candidate[2] = INTRA_ANGULAR_26;
2264 } else {
2265 720635 candidate[0] = cand_left;
2266 720635 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2267 720635 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2268 }
2269 } else {
2270 6771236 candidate[0] = cand_left;
2271 6771236 candidate[1] = cand_up;
2272
4/4
✓ Branch 0 taken 5606828 times.
✓ Branch 1 taken 1164408 times.
✓ Branch 2 taken 4626709 times.
✓ Branch 3 taken 980119 times.
6771236 if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) {
2273 4626709 candidate[2] = INTRA_PLANAR;
2274
4/4
✓ Branch 0 taken 1875428 times.
✓ Branch 1 taken 269099 times.
✓ Branch 2 taken 1405284 times.
✓ Branch 3 taken 470144 times.
2144527 } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) {
2275 1405284 candidate[2] = INTRA_DC;
2276 } else {
2277 739243 candidate[2] = INTRA_ANGULAR_26;
2278 }
2279 }
2280
2281
2/2
✓ Branch 0 taken 5171549 times.
✓ Branch 1 taken 3454590 times.
8626139 if (prev_intra_luma_pred_flag) {
2282 5171549 intra_pred_mode = candidate[lc->pu.mpm_idx];
2283 } else {
2284
2/2
✓ Branch 0 taken 1633160 times.
✓ Branch 1 taken 1821430 times.
3454590 if (candidate[0] > candidate[1])
2285 1633160 FFSWAP(uint8_t, candidate[0], candidate[1]);
2286
2/2
✓ Branch 0 taken 2026492 times.
✓ Branch 1 taken 1428098 times.
3454590 if (candidate[0] > candidate[2])
2287 2026492 FFSWAP(uint8_t, candidate[0], candidate[2]);
2288
2/2
✓ Branch 0 taken 2547377 times.
✓ Branch 1 taken 907213 times.
3454590 if (candidate[1] > candidate[2])
2289 2547377 FFSWAP(uint8_t, candidate[1], candidate[2]);
2290
2291 3454590 intra_pred_mode = lc->pu.rem_intra_luma_pred_mode;
2292
2/2
✓ Branch 0 taken 10363770 times.
✓ Branch 1 taken 3454590 times.
13818360 for (i = 0; i < 3; i++)
2293
2/2
✓ Branch 0 taken 7548310 times.
✓ Branch 1 taken 2815460 times.
10363770 if (intra_pred_mode >= candidate[i])
2294 7548310 intra_pred_mode++;
2295 }
2296
2297 /* write the intra prediction units into the mv array */
2298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8626139 times.
8626139 if (!size_in_pus)
2299 size_in_pus = 1;
2300
2/2
✓ Branch 0 taken 15589964 times.
✓ Branch 1 taken 8626139 times.
24216103 for (i = 0; i < size_in_pus; i++) {
2301 15589964 memset(&l->tab_ipm[(y_pu + i) * min_pu_width + x_pu],
2302 intra_pred_mode, size_in_pus);
2303
2304
2/2
✓ Branch 0 taken 51408428 times.
✓ Branch 1 taken 15589964 times.
66998392 for (j = 0; j < size_in_pus; j++) {
2305 51408428 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA;
2306 }
2307 }
2308
2309 8626139 return intra_pred_mode;
2310 }
2311
2312 13240260 static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth,
2313 int x0, int y0,
2314 int log2_cb_size, int ct_depth)
2315 {
2316 13240260 int length = (1 << log2_cb_size) >> sps->log2_min_cb_size;
2317 13240260 int x_cb = x0 >> sps->log2_min_cb_size;
2318 13240260 int y_cb = y0 >> sps->log2_min_cb_size;
2319 int y;
2320
2321
2/2
✓ Branch 0 taken 24959179 times.
✓ Branch 1 taken 13240260 times.
38199439 for (y = 0; y < length; y++)
2322 24959179 memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb],
2323 ct_depth, length);
2324 13240260 }
2325
2326 static const uint8_t tab_mode_idx[] = {
2327 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2328 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2329
2330 4628414 static void intra_prediction_unit(HEVCLocalContext *lc,
2331 const HEVCLayerContext *l, const HEVCSPS *sps,
2332 int x0, int y0,
2333 int log2_cb_size)
2334 {
2335 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2336 uint8_t prev_intra_luma_pred_flag[4];
2337 4628414 int split = lc->cu.part_mode == PART_NxN;
2338 4628414 int pb_size = (1 << log2_cb_size) >> split;
2339 4628414 int side = split + 1;
2340 int chroma_mode;
2341 int i, j;
2342
2343
2/2
✓ Branch 0 taken 5960989 times.
✓ Branch 1 taken 4628414 times.
10589403 for (i = 0; i < side; i++)
2344
2/2
✓ Branch 0 taken 8626139 times.
✓ Branch 1 taken 5960989 times.
14587128 for (j = 0; j < side; j++)
2345 8626139 prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc);
2346
2347
2/2
✓ Branch 0 taken 5960989 times.
✓ Branch 1 taken 4628414 times.
10589403 for (i = 0; i < side; i++) {
2348
2/2
✓ Branch 0 taken 8626139 times.
✓ Branch 1 taken 5960989 times.
14587128 for (j = 0; j < side; j++) {
2349
2/2
✓ Branch 0 taken 5171549 times.
✓ Branch 1 taken 3454590 times.
8626139 if (prev_intra_luma_pred_flag[2 * i + j])
2350 5171549 lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc);
2351 else
2352 3454590 lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc);
2353
2354 8626139 lc->pu.intra_pred_mode[2 * i + j] =
2355 8626139 luma_intra_pred_mode(lc, l, sps,
2356 8626139 x0 + pb_size * j, y0 + pb_size * i, pb_size,
2357 8626139 prev_intra_luma_pred_flag[2 * i + j]);
2358 }
2359 }
2360
2361
2/2
✓ Branch 0 taken 105006 times.
✓ Branch 1 taken 4523408 times.
4628414 if (sps->chroma_format_idc == 3) {
2362
2/2
✓ Branch 0 taken 138857 times.
✓ Branch 1 taken 105006 times.
243863 for (i = 0; i < side; i++) {
2363
2/2
✓ Branch 0 taken 206559 times.
✓ Branch 1 taken 138857 times.
345416 for (j = 0; j < side; j++) {
2364 206559 lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2365
2/2
✓ Branch 0 taken 34248 times.
✓ Branch 1 taken 172311 times.
206559 if (chroma_mode != 4) {
2366
2/2
✓ Branch 0 taken 2343 times.
✓ Branch 1 taken 31905 times.
34248 if (lc->pu.intra_pred_mode[2 * i + j] == intra_chroma_table[chroma_mode])
2367 2343 lc->pu.intra_pred_mode_c[2 * i + j] = 34;
2368 else
2369 31905 lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode];
2370 } else {
2371 172311 lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j];
2372 }
2373 }
2374 }
2375
2/2
✓ Branch 0 taken 247106 times.
✓ Branch 1 taken 4276302 times.
4523408 } else if (sps->chroma_format_idc == 2) {
2376 int mode_idx;
2377 247106 lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2378
2/2
✓ Branch 0 taken 73995 times.
✓ Branch 1 taken 173111 times.
247106 if (chroma_mode != 4) {
2379
2/2
✓ Branch 0 taken 3515 times.
✓ Branch 1 taken 70480 times.
73995 if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2380 3515 mode_idx = 34;
2381 else
2382 70480 mode_idx = intra_chroma_table[chroma_mode];
2383 } else {
2384 173111 mode_idx = lc->pu.intra_pred_mode[0];
2385 }
2386 247106 lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx];
2387
2/2
✓ Branch 0 taken 4276110 times.
✓ Branch 1 taken 192 times.
4276302 } else if (sps->chroma_format_idc != 0) {
2388 4276110 chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
2389
2/2
✓ Branch 0 taken 1029007 times.
✓ Branch 1 taken 3247103 times.
4276110 if (chroma_mode != 4) {
2390
2/2
✓ Branch 0 taken 76584 times.
✓ Branch 1 taken 952423 times.
1029007 if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2391 76584 lc->pu.intra_pred_mode_c[0] = 34;
2392 else
2393 952423 lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode];
2394 } else {
2395 3247103 lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0];
2396 }
2397 }
2398 4628414 }
2399
2400 8611847 static void intra_prediction_unit_default_value(HEVCLocalContext *lc,
2401 const HEVCLayerContext *l,
2402 const HEVCSPS *sps,
2403 int x0, int y0,
2404 int log2_cb_size)
2405 {
2406 8611847 const HEVCContext *const s = lc->parent;
2407 8611847 int pb_size = 1 << log2_cb_size;
2408 8611847 int size_in_pus = pb_size >> sps->log2_min_pu_size;
2409 8611847 int min_pu_width = sps->min_pu_width;
2410 8611847 MvField *tab_mvf = s->cur_frame->tab_mvf;
2411 8611847 int x_pu = x0 >> sps->log2_min_pu_size;
2412 8611847 int y_pu = y0 >> sps->log2_min_pu_size;
2413 int j, k;
2414
2415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8611847 times.
8611847 if (size_in_pus == 0)
2416 size_in_pus = 1;
2417
2/2
✓ Branch 0 taken 36993546 times.
✓ Branch 1 taken 8611847 times.
45605393 for (j = 0; j < size_in_pus; j++)
2418 36993546 memset(&l->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus);
2419
2/2
✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 8599414 times.
8611847 if (lc->cu.pred_mode == MODE_INTRA)
2420
2/2
✓ Branch 0 taken 40908 times.
✓ Branch 1 taken 12433 times.
53341 for (j = 0; j < size_in_pus; j++)
2421
2/2
✓ Branch 0 taken 182512 times.
✓ Branch 1 taken 40908 times.
223420 for (k = 0; k < size_in_pus; k++)
2422 182512 tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA;
2423 8611847 }
2424
2425 13240261 static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s,
2426 const HEVCLayerContext *l,
2427 const HEVCPPS *pps, const HEVCSPS *sps,
2428 int x0, int y0, int log2_cb_size)
2429 {
2430 13240261 int cb_size = 1 << log2_cb_size;
2431 13240261 int log2_min_cb_size = sps->log2_min_cb_size;
2432 13240261 int length = cb_size >> log2_min_cb_size;
2433 13240261 int min_cb_width = sps->min_cb_width;
2434 13240261 int x_cb = x0 >> log2_min_cb_size;
2435 13240261 int y_cb = y0 >> log2_min_cb_size;
2436 13240261 int idx = log2_cb_size - 2;
2437 13240261 int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2438 int x, y, ret;
2439
2440 13240261 lc->cu.x = x0;
2441 13240261 lc->cu.y = y0;
2442 13240261 lc->cu.pred_mode = MODE_INTRA;
2443 13240261 lc->cu.part_mode = PART_2Nx2N;
2444 13240261 lc->cu.intra_split_flag = 0;
2445
2446 13240261 SAMPLE_CTB(l->skip_flag, x_cb, y_cb) = 0;
2447
2/2
✓ Branch 0 taken 52961044 times.
✓ Branch 1 taken 13240261 times.
66201305 for (x = 0; x < 4; x++)
2448 52961044 lc->pu.intra_pred_mode[x] = 1;
2449
2/2
✓ Branch 0 taken 211788 times.
✓ Branch 1 taken 13028473 times.
13240261 if (pps->transquant_bypass_enable_flag) {
2450 211788 lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(lc);
2451
2/2
✓ Branch 0 taken 92187 times.
✓ Branch 1 taken 119601 times.
211788 if (lc->cu.cu_transquant_bypass_flag)
2452 92187 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size);
2453 } else
2454 13028473 lc->cu.cu_transquant_bypass_flag = 0;
2455
2456
2/2
✓ Branch 0 taken 9866641 times.
✓ Branch 1 taken 3373620 times.
13240261 if (s->sh.slice_type != HEVC_SLICE_I) {
2457 9866641 const int x0b = av_zero_extend(x0, sps->log2_ctb_size);
2458 9866641 const int y0b = av_zero_extend(y0, sps->log2_ctb_size);
2459 9866641 uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, l->skip_flag,
2460 x0b, y0b, x_cb, y_cb,
2461 min_cb_width);
2462
2463 9866641 x = y_cb * min_cb_width + x_cb;
2464
2/2
✓ Branch 0 taken 20398545 times.
✓ Branch 1 taken 9866641 times.
30265186 for (y = 0; y < length; y++) {
2465 20398545 memset(&l->skip_flag[x], skip_flag, length);
2466 20398545 x += min_cb_width;
2467 }
2468
2/2
✓ Branch 0 taken 4565607 times.
✓ Branch 1 taken 5301034 times.
9866641 lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER;
2469 } else {
2470 3373620 x = y_cb * min_cb_width + x_cb;
2471
2/2
✓ Branch 0 taken 4560635 times.
✓ Branch 1 taken 3373620 times.
7934255 for (y = 0; y < length; y++) {
2472 4560635 memset(&l->skip_flag[x], 0, length);
2473 4560635 x += min_cb_width;
2474 }
2475 }
2476
2477
2/2
✓ Branch 0 taken 4565607 times.
✓ Branch 1 taken 8674654 times.
13240261 if (SAMPLE_CTB(l->skip_flag, x_cb, y_cb)) {
2478 4565607 hls_prediction_unit(lc, l, pps, sps,
2479 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2480 4565607 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2481
2482
2/2
✓ Branch 0 taken 4419094 times.
✓ Branch 1 taken 146513 times.
4565607 if (!s->sh.disable_deblocking_filter_flag)
2483 4419094 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2484 } else {
2485 8674654 int pcm_flag = 0;
2486
2487
2/2
✓ Branch 0 taken 5301034 times.
✓ Branch 1 taken 3373620 times.
8674654 if (s->sh.slice_type != HEVC_SLICE_I)
2488 5301034 lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc);
2489
2/2
✓ Branch 0 taken 4640847 times.
✓ Branch 1 taken 4033807 times.
8674654 if (lc->cu.pred_mode != MODE_INTRA ||
2490
2/2
✓ Branch 0 taken 3501523 times.
✓ Branch 1 taken 1139324 times.
4640847 log2_cb_size == sps->log2_min_cb_size) {
2491 7535330 lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size);
2492
2/2
✓ Branch 0 taken 1440730 times.
✓ Branch 1 taken 6094600 times.
8976060 lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
2493
2/2
✓ Branch 0 taken 1332575 times.
✓ Branch 1 taken 108155 times.
1440730 lc->cu.pred_mode == MODE_INTRA;
2494 }
2495
2496
2/2
✓ Branch 0 taken 4640847 times.
✓ Branch 1 taken 4033807 times.
8674654 if (lc->cu.pred_mode == MODE_INTRA) {
2497
4/4
✓ Branch 0 taken 3308272 times.
✓ Branch 1 taken 1332575 times.
✓ Branch 2 taken 162684 times.
✓ Branch 3 taken 3145588 times.
4640847 if (lc->cu.part_mode == PART_2Nx2N && sps->pcm_enabled &&
2498
2/2
✓ Branch 0 taken 160815 times.
✓ Branch 1 taken 1869 times.
162684 log2_cb_size >= sps->pcm.log2_min_pcm_cb_size &&
2499
2/2
✓ Branch 0 taken 153183 times.
✓ Branch 1 taken 7632 times.
160815 log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) {
2500 153183 pcm_flag = ff_hevc_pcm_flag_decode(lc);
2501 }
2502
2/2
✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 4628414 times.
4640847 if (pcm_flag) {
2503 12433 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2504 12433 ret = hls_pcm_sample(lc, l, pps, x0, y0, log2_cb_size);
2505
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12425 times.
12433 if (sps->pcm_loop_filter_disabled)
2506 8 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size);
2507
2508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
2509 return ret;
2510 } else {
2511 4628414 intra_prediction_unit(lc, l, sps, x0, y0, log2_cb_size);
2512 }
2513 } else {
2514 4033807 intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size);
2515
8/9
✓ Branch 0 taken 2514894 times.
✓ Branch 1 taken 499267 times.
✓ Branch 2 taken 599864 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.
4033807 switch (lc->cu.part_mode) {
2516 2514894 case PART_2Nx2N:
2517 2514894 hls_prediction_unit(lc, l, pps, sps,
2518 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2519 2514894 break;
2520 499267 case PART_2NxN:
2521 499267 hls_prediction_unit(lc, l, pps, sps,
2522 x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2523 499267 hls_prediction_unit(lc, l, pps, sps,
2524 499267 x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2525 499267 break;
2526 599864 case PART_Nx2N:
2527 599864 hls_prediction_unit(lc, l, pps, sps,
2528 x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2529 599864 hls_prediction_unit(lc, l, pps, sps,
2530 599864 x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2531 599864 break;
2532 67350 case PART_2NxnU:
2533 67350 hls_prediction_unit(lc, l, pps, sps,
2534 x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
2535 67350 hls_prediction_unit(lc, l, pps, sps,
2536 67350 x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
2537 67350 break;
2538 58153 case PART_2NxnD:
2539 58153 hls_prediction_unit(lc, l, pps, sps,
2540 58153 x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
2541 58153 hls_prediction_unit(lc, l, pps, sps,
2542 58153 x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
2543 58153 break;
2544 100281 case PART_nLx2N:
2545 100281 hls_prediction_unit(lc, l, pps, sps,
2546 x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
2547 100281 hls_prediction_unit(lc, l, pps, sps,
2548 100281 x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2549 100281 break;
2550 85843 case PART_nRx2N:
2551 85843 hls_prediction_unit(lc, l, pps, sps,
2552 85843 x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
2553 85843 hls_prediction_unit(lc, l, pps, sps,
2554 85843 x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2555 85843 break;
2556 108155 case PART_NxN:
2557 108155 hls_prediction_unit(lc, l, pps, sps,
2558 x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
2559 108155 hls_prediction_unit(lc, l, pps, sps,
2560 108155 x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2561 108155 hls_prediction_unit(lc, l, pps, sps,
2562 108155 x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2563 108155 hls_prediction_unit(lc, l, pps, sps,
2564 108155 x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2565 108155 break;
2566 }
2567 }
2568
2569
2/2
✓ Branch 0 taken 8662221 times.
✓ Branch 1 taken 12433 times.
8674654 if (!pcm_flag) {
2570 8662221 int rqt_root_cbf = 1;
2571
2572
2/2
✓ Branch 0 taken 4033807 times.
✓ Branch 1 taken 4628414 times.
8662221 if (lc->cu.pred_mode != MODE_INTRA &&
2573
4/4
✓ Branch 0 taken 2514894 times.
✓ Branch 1 taken 1518913 times.
✓ Branch 2 taken 1307742 times.
✓ Branch 3 taken 1207152 times.
4033807 !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) {
2574 2826655 rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc);
2575 }
2576
2/2
✓ Branch 0 taken 7145788 times.
✓ Branch 1 taken 1516433 times.
8662221 if (rqt_root_cbf) {
2577 const static int cbf[2] = { 0 };
2578
2/2
✓ Branch 0 taken 4628414 times.
✓ Branch 1 taken 2517374 times.
7145788 lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ?
2579 4628414 sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
2580 2517374 sps->max_transform_hierarchy_depth_inter;
2581 7145788 ret = hls_transform_tree(lc, l, pps, sps, x0, y0, x0, y0, x0, y0,
2582 log2_cb_size,
2583 log2_cb_size, 0, 0, cbf, cbf);
2584
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7145787 times.
7145788 if (ret < 0)
2585 1 return ret;
2586 } else {
2587
2/2
✓ Branch 0 taken 1460001 times.
✓ Branch 1 taken 56432 times.
1516433 if (!s->sh.disable_deblocking_filter_flag)
2588 1460001 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
2589 }
2590 }
2591 }
2592
2593
4/4
✓ Branch 0 taken 3427516 times.
✓ Branch 1 taken 9812744 times.
✓ Branch 2 taken 1190439 times.
✓ Branch 3 taken 2237077 times.
13240260 if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
2594 1190439 ff_hevc_set_qPy(lc, l, pps, x0, y0, log2_cb_size);
2595
2596 13240260 x = y_cb * min_cb_width + x_cb;
2597
2/2
✓ Branch 0 taken 24959179 times.
✓ Branch 1 taken 13240260 times.
38199439 for (y = 0; y < length; y++) {
2598 24959179 memset(&l->qp_y_tab[x], lc->qp_y, length);
2599 24959179 x += min_cb_width;
2600 }
2601
2602
2/2
✓ Branch 0 taken 4770706 times.
✓ Branch 1 taken 8469554 times.
13240260 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2603
2/2
✓ Branch 0 taken 2870433 times.
✓ Branch 1 taken 1900273 times.
4770706 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2604 2870433 lc->qPy_pred = lc->qp_y;
2605 }
2606
2607 13240260 set_ct_depth(sps, l->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth);
2608
2609 13240260 return 0;
2610 }
2611
2612 17146365 static int hls_coding_quadtree(HEVCLocalContext *lc,
2613 const HEVCLayerContext *l,
2614 const HEVCPPS *pps, const HEVCSPS *sps,
2615 int x0, int y0,
2616 int log2_cb_size, int cb_depth)
2617 {
2618 17146365 const HEVCContext *const s = lc->parent;
2619 17146365 const int cb_size = 1 << log2_cb_size;
2620 int ret;
2621 int split_cu;
2622
2623 17146365 lc->ct_depth = cb_depth;
2624
2/2
✓ Branch 0 taken 17115898 times.
✓ Branch 1 taken 30467 times.
17146365 if (x0 + cb_size <= sps->width &&
2625
2/2
✓ Branch 0 taken 16790189 times.
✓ Branch 1 taken 325709 times.
17115898 y0 + cb_size <= sps->height &&
2626
2/2
✓ Branch 0 taken 9259671 times.
✓ Branch 1 taken 7530518 times.
16790189 log2_cb_size > sps->log2_min_cb_size) {
2627 9259671 split_cu = ff_hevc_split_coding_unit_flag_decode(lc, l->tab_ct_depth,
2628 sps, cb_depth, x0, y0);
2629 } else {
2630 7886694 split_cu = (log2_cb_size > sps->log2_min_cb_size);
2631 }
2632
2/2
✓ Branch 0 taken 4349409 times.
✓ Branch 1 taken 12796956 times.
17146365 if (pps->cu_qp_delta_enabled_flag &&
2633
2/2
✓ Branch 0 taken 2030275 times.
✓ Branch 1 taken 2319134 times.
4349409 log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) {
2634 2030275 lc->tu.is_cu_qp_delta_coded = 0;
2635 2030275 lc->tu.cu_qp_delta = 0;
2636 }
2637
2638
2/2
✓ Branch 0 taken 519326 times.
✓ Branch 1 taken 16627039 times.
17146365 if (s->sh.cu_chroma_qp_offset_enabled_flag &&
2639
1/2
✓ Branch 0 taken 519326 times.
✗ Branch 1 not taken.
519326 log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_chroma_qp_offset_depth) {
2640 519326 lc->tu.is_cu_chroma_qp_offset_coded = 0;
2641 }
2642
2643
2/2
✓ Branch 0 taken 3906104 times.
✓ Branch 1 taken 13240261 times.
17146365 if (split_cu) {
2644 3906104 int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
2645 3906104 const int cb_size_split = cb_size >> 1;
2646 3906104 const int x1 = x0 + cb_size_split;
2647 3906104 const int y1 = y0 + cb_size_split;
2648
2649 3906104 int more_data = 0;
2650
2651 3906104 more_data = hls_coding_quadtree(lc, l, pps, sps,
2652 x0, y0, log2_cb_size - 1, cb_depth + 1);
2653
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3906102 times.
3906104 if (more_data < 0)
2654 2 return more_data;
2655
2656
4/4
✓ Branch 0 taken 3906093 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3877148 times.
✓ Branch 3 taken 28945 times.
3906102 if (more_data && x1 < sps->width) {
2657 3877148 more_data = hls_coding_quadtree(lc, l, pps, sps,
2658 x1, y0, log2_cb_size - 1, cb_depth + 1);
2659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3877148 times.
3877148 if (more_data < 0)
2660 return more_data;
2661 }
2662
4/4
✓ Branch 0 taken 3895620 times.
✓ Branch 1 taken 10482 times.
✓ Branch 2 taken 3691561 times.
✓ Branch 3 taken 204059 times.
3906102 if (more_data && y1 < sps->height) {
2663 3691561 more_data = hls_coding_quadtree(lc, l, pps, sps,
2664 x0, y1, log2_cb_size - 1, cb_depth + 1);
2665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3691561 times.
3691561 if (more_data < 0)
2666 return more_data;
2667 }
2668
4/4
✓ Branch 0 taken 3889396 times.
✓ Branch 1 taken 16706 times.
✓ Branch 2 taken 3866675 times.
✓ Branch 3 taken 22721 times.
3906102 if (more_data && x1 < sps->width &&
2669
2/2
✓ Branch 0 taken 3662616 times.
✓ Branch 1 taken 204059 times.
3866675 y1 < sps->height) {
2670 3662616 more_data = hls_coding_quadtree(lc, l, pps, sps,
2671 x1, y1, log2_cb_size - 1, cb_depth + 1);
2672
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3662615 times.
3662616 if (more_data < 0)
2673 1 return more_data;
2674 }
2675
2676
2/2
✓ Branch 0 taken 2264348 times.
✓ Branch 1 taken 1641753 times.
3906101 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2677
2/2
✓ Branch 0 taken 1714634 times.
✓ Branch 1 taken 549714 times.
2264348 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2678 1714634 lc->qPy_pred = lc->qp_y;
2679
2680
2/2
✓ Branch 0 taken 3869614 times.
✓ Branch 1 taken 36487 times.
3906101 if (more_data)
2681
2/2
✓ Branch 0 taken 101435 times.
✓ Branch 1 taken 3768179 times.
3971049 return ((x1 + cb_size_split) < sps->width ||
2682
2/2
✓ Branch 0 taken 101434 times.
✓ Branch 1 taken 1 times.
101435 (y1 + cb_size_split) < sps->height);
2683 else
2684 36487 return 0;
2685 } else {
2686 13240261 ret = hls_coding_unit(lc, s, l, pps, sps, x0, y0, log2_cb_size);
2687
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13240260 times.
13240261 if (ret < 0)
2688 1 return ret;
2689 13240260 if ((!((x0 + cb_size) %
2690
2/2
✓ Branch 0 taken 9315946 times.
✓ Branch 1 taken 3924314 times.
13240260 (1 << (sps->log2_ctb_size))) ||
2691
2/2
✓ Branch 0 taken 73512 times.
✓ Branch 1 taken 9242434 times.
9315946 (x0 + cb_size >= sps->width)) &&
2692 3997826 (!((y0 + cb_size) %
2693
2/2
✓ Branch 0 taken 2088546 times.
✓ Branch 1 taken 1909280 times.
3997826 (1 << (sps->log2_ctb_size))) ||
2694
2/2
✓ Branch 0 taken 99655 times.
✓ Branch 1 taken 1988891 times.
2088546 (y0 + cb_size >= sps->height))) {
2695 2008935 int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc);
2696 2008935 return !end_of_slice_flag;
2697 } else {
2698 11231325 return 1;
2699 }
2700 }
2701
2702 return 0;
2703 }
2704
2705 2008936 static void hls_decode_neighbour(HEVCLocalContext *lc,
2706 const HEVCLayerContext *l,
2707 const HEVCPPS *pps, const HEVCSPS *sps,
2708 int x_ctb, int y_ctb, int ctb_addr_ts)
2709 {
2710 2008936 const HEVCContext *const s = lc->parent;
2711 2008936 int ctb_size = 1 << sps->log2_ctb_size;
2712 2008936 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2713 2008936 int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
2714
2715 2008936 l->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
2716
2717
2/2
✓ Branch 0 taken 173854 times.
✓ Branch 1 taken 1835082 times.
2008936 if (pps->entropy_coding_sync_enabled_flag) {
2718
3/4
✓ Branch 0 taken 8173 times.
✓ Branch 1 taken 165681 times.
✓ Branch 2 taken 8173 times.
✗ Branch 3 not taken.
173854 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2719 8173 lc->first_qp_group = 1;
2720 173854 lc->end_of_tiles_x = sps->width;
2721
2/2
✓ Branch 0 taken 680802 times.
✓ Branch 1 taken 1154280 times.
1835082 } else if (pps->tiles_enabled_flag) {
2722
4/4
✓ Branch 0 taken 680048 times.
✓ Branch 1 taken 754 times.
✓ Branch 2 taken 6541 times.
✓ Branch 3 taken 673507 times.
680802 if (ctb_addr_ts && pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
2723 6541 int idxX = pps->col_idxX[x_ctb >> sps->log2_ctb_size];
2724 6541 lc->end_of_tiles_x = x_ctb + (pps->column_width[idxX] << sps->log2_ctb_size);
2725 6541 lc->first_qp_group = 1;
2726 }
2727 } else {
2728 1154280 lc->end_of_tiles_x = sps->width;
2729 }
2730
2731 2008936 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height);
2732
2733 2008936 lc->boundary_flags = 0;
2734
2/2
✓ Branch 0 taken 680802 times.
✓ Branch 1 taken 1328134 times.
2008936 if (pps->tiles_enabled_flag) {
2735
4/4
✓ Branch 0 taken 662754 times.
✓ Branch 1 taken 18048 times.
✓ Branch 2 taken 42895 times.
✓ Branch 3 taken 619859 times.
680802 if (x_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2736 42895 lc->boundary_flags |= BOUNDARY_LEFT_TILE;
2737
4/4
✓ Branch 0 taken 662754 times.
✓ Branch 1 taken 18048 times.
✓ Branch 2 taken 15883 times.
✓ Branch 3 taken 646871 times.
680802 if (x_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - 1])
2738 15883 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2739
4/4
✓ Branch 0 taken 658010 times.
✓ Branch 1 taken 22792 times.
✓ Branch 2 taken 33781 times.
✓ Branch 3 taken 624229 times.
680802 if (y_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - sps->ctb_width]])
2740 33781 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
2741
4/4
✓ Branch 0 taken 658010 times.
✓ Branch 1 taken 22792 times.
✓ Branch 2 taken 14490 times.
✓ Branch 3 taken 643520 times.
680802 if (y_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - sps->ctb_width])
2742 14490 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2743 } else {
2744
2/2
✓ Branch 0 taken 18509 times.
✓ Branch 1 taken 1309625 times.
1328134 if (ctb_addr_in_slice <= 0)
2745 18509 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2746
2/2
✓ Branch 0 taken 199655 times.
✓ Branch 1 taken 1128479 times.
1328134 if (ctb_addr_in_slice < sps->ctb_width)
2747 199655 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2748 }
2749
2750
6/6
✓ Branch 0 taken 1919668 times.
✓ Branch 1 taken 89268 times.
✓ Branch 2 taken 1911525 times.
✓ Branch 3 taken 8143 times.
✓ Branch 4 taken 1869912 times.
✓ Branch 5 taken 41613 times.
2008936 lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
2751
6/6
✓ Branch 0 taken 1867018 times.
✓ Branch 1 taken 141918 times.
✓ Branch 2 taken 1772828 times.
✓ Branch 3 taken 94190 times.
✓ Branch 4 taken 1752708 times.
✓ Branch 5 taken 20120 times.
2008936 lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
2752
6/6
✓ Branch 0 taken 1867018 times.
✓ Branch 1 taken 141918 times.
✓ Branch 2 taken 1775420 times.
✓ Branch 3 taken 91598 times.
✓ Branch 4 taken 1701814 times.
✓ Branch 5 taken 73606 times.
2008936 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]]));
2753
8/8
✓ Branch 0 taken 1919668 times.
✓ Branch 1 taken 89268 times.
✓ Branch 2 taken 1788316 times.
✓ Branch 3 taken 131352 times.
✓ Branch 4 taken 1698939 times.
✓ Branch 5 taken 89377 times.
✓ Branch 6 taken 1643073 times.
✓ Branch 7 taken 55866 times.
2008936 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]]));
2754 2008936 }
2755
2756 28817 static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
2757 {
2758 28817 HEVCLocalContext *const lc = &s->local_ctx[0];
2759 28817 const HEVCLayerContext *const l = &s->layers[s->cur_layer];
2760 28817 const HEVCPPS *const pps = s->pps;
2761 28817 const HEVCSPS *const sps = pps->sps;
2762 28817 const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
2763 28817 const size_t slice_size = get_bits_bytesize(gb, 1) - s->sh.data_offset;
2764 28817 int ctb_size = 1 << sps->log2_ctb_size;
2765 28817 int more_data = 1;
2766 28817 int x_ctb = 0;
2767 28817 int y_ctb = 0;
2768 28817 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
2769 int ret;
2770
2771
3/4
✓ Branch 0 taken 2008936 times.
✓ Branch 1 taken 28816 times.
✓ Branch 2 taken 2008936 times.
✗ Branch 3 not taken.
2037752 while (more_data && ctb_addr_ts < sps->ctb_size) {
2772 2008936 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2773
2774 2008936 x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2775 2008936 y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
2776 2008936 hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
2777
2778 2008936 ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 0);
2779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2008936 times.
2008936 if (ret < 0) {
2780 l->tab_slice_address[ctb_addr_rs] = -1;
2781 return ret;
2782 }
2783
2784 2008936 hls_sao_param(lc, l, pps, sps,
2785 2008936 x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
2786
2787 2008936 l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2788 2008936 l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2789 2008936 l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2790
2791 2008936 more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
2792
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2008935 times.
2008936 if (more_data < 0) {
2793 1 l->tab_slice_address[ctb_addr_rs] = -1;
2794 1 return more_data;
2795 }
2796
2797
2798 2008935 ctb_addr_ts++;
2799 2008935 ff_hevc_save_states(lc, pps, ctb_addr_ts);
2800 2008935 ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size);
2801 }
2802
2803
2/2
✓ Branch 0 taken 15052 times.
✓ Branch 1 taken 13764 times.
28816 if (x_ctb + ctb_size >= sps->width &&
2804
2/2
✓ Branch 0 taken 10565 times.
✓ Branch 1 taken 4487 times.
15052 y_ctb + ctb_size >= sps->height)
2805 10565 ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size);
2806
2807 28816 return ctb_addr_ts;
2808 }
2809
2810 static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist,
2811 int job, int thread)
2812 {
2813 HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread];
2814 const HEVCContext *const s = lc->parent;
2815 const HEVCLayerContext *const l = &s->layers[s->cur_layer];
2816 const HEVCPPS *const pps = s->pps;
2817 const HEVCSPS *const sps = pps->sps;
2818 int ctb_size = 1 << sps->log2_ctb_size;
2819 int more_data = 1;
2820 int ctb_row = job;
2821 int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size);
2822 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2823
2824 const uint8_t *data = s->data + s->sh.offset[ctb_row];
2825 const size_t data_size = s->sh.size[ctb_row];
2826
2827 int progress = 0;
2828
2829 int ret;
2830
2831 if (ctb_row)
2832 ff_init_cabac_decoder(&lc->cc, data, data_size);
2833
2834 while(more_data && ctb_addr_ts < sps->ctb_size) {
2835 int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size;
2836 int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size;
2837
2838 hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
2839
2840 if (ctb_row)
2841 ff_thread_progress_await(&s->wpp_progress[ctb_row - 1],
2842 progress + SHIFT_CTB_WPP + 1);
2843
2844 /* atomic_load's prototype requires a pointer to non-const atomic variable
2845 * (due to implementations via mutexes, where reads involve writes).
2846 * Of course, casting const away here is nevertheless safe. */
2847 if (atomic_load((atomic_int*)&s->wpp_err)) {
2848 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2849 return 0;
2850 }
2851
2852 ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1);
2853 if (ret < 0)
2854 goto error;
2855 hls_sao_param(lc, l, pps, sps,
2856 x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
2857
2858 l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2859 l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2860 l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2861
2862 more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
2863
2864 if (more_data < 0) {
2865 ret = more_data;
2866 goto error;
2867 }
2868
2869 ctb_addr_ts++;
2870
2871 ff_hevc_save_states(lc, pps, ctb_addr_ts);
2872 ff_thread_progress_report(&s->wpp_progress[ctb_row], ++progress);
2873 ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size);
2874
2875 if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) {
2876 /* Casting const away here is safe, because it is an atomic operation. */
2877 atomic_store((atomic_int*)&s->wpp_err, 1);
2878 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2879 return 0;
2880 }
2881
2882 if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) {
2883 ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size);
2884 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2885 return ctb_addr_ts;
2886 }
2887 ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2888 x_ctb+=ctb_size;
2889
2890 if(x_ctb >= sps->width) {
2891 break;
2892 }
2893 }
2894 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2895
2896 return 0;
2897 error:
2898 l->tab_slice_address[ctb_addr_rs] = -1;
2899 /* Casting const away here is safe, because it is an atomic operation. */
2900 atomic_store((atomic_int*)&s->wpp_err, 1);
2901 ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX);
2902 return ret;
2903 }
2904
2905 static int wpp_progress_init(HEVCContext *s, unsigned count)
2906 {
2907 if (s->nb_wpp_progress < count) {
2908 void *tmp = av_realloc_array(s->wpp_progress, count,
2909 sizeof(*s->wpp_progress));
2910 if (!tmp)
2911 return AVERROR(ENOMEM);
2912
2913 s->wpp_progress = tmp;
2914 memset(s->wpp_progress + s->nb_wpp_progress, 0,
2915 (count - s->nb_wpp_progress) * sizeof(*s->wpp_progress));
2916
2917 for (int i = s->nb_wpp_progress; i < count; i++) {
2918 int ret = ff_thread_progress_init(&s->wpp_progress[i], 1);
2919 if (ret < 0)
2920 return ret;
2921 s->nb_wpp_progress = i + 1;
2922 }
2923 }
2924
2925 for (int i = 0; i < count; i++)
2926 ff_thread_progress_reset(&s->wpp_progress[i]);
2927
2928 return 0;
2929 }
2930
2931 static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
2932 {
2933 const HEVCPPS *const pps = s->pps;
2934 const HEVCSPS *const sps = pps->sps;
2935 const uint8_t *data = nal->data;
2936 int length = nal->size;
2937 int *ret;
2938 int64_t offset;
2939 int64_t startheader, cmpt = 0;
2940 int j, res = 0;
2941
2942 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) {
2943 av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
2944 s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets,
2945 sps->ctb_width, sps->ctb_height
2946 );
2947 return AVERROR_INVALIDDATA;
2948 }
2949
2950 if (s->avctx->thread_count > s->nb_local_ctx) {
2951 HEVCLocalContext *tmp = av_malloc_array(s->avctx->thread_count, sizeof(*s->local_ctx));
2952
2953 if (!tmp)
2954 return AVERROR(ENOMEM);
2955
2956 memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx);
2957 av_free(s->local_ctx);
2958 s->local_ctx = tmp;
2959
2960 for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) {
2961 tmp = &s->local_ctx[i];
2962
2963 memset(tmp, 0, sizeof(*tmp));
2964
2965 tmp->logctx = s->avctx;
2966 tmp->parent = s;
2967 tmp->common_cabac_state = &s->cabac;
2968 }
2969
2970 s->nb_local_ctx = s->avctx->thread_count;
2971 }
2972
2973 offset = s->sh.data_offset;
2974
2975 for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2976 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2977 startheader--;
2978 cmpt++;
2979 }
2980 }
2981
2982 for (int i = 1; i < s->sh.num_entry_point_offsets; i++) {
2983 offset += (s->sh.entry_point_offset[i - 1] - cmpt);
2984 for (j = 0, cmpt = 0, startheader = offset
2985 + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) {
2986 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2987 startheader--;
2988 cmpt++;
2989 }
2990 }
2991 s->sh.size[i] = s->sh.entry_point_offset[i] - cmpt;
2992 s->sh.offset[i] = offset;
2993
2994 }
2995
2996 offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt;
2997 if (length < offset) {
2998 av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n");
2999 return AVERROR_INVALIDDATA;
3000 }
3001 s->sh.size [s->sh.num_entry_point_offsets] = length - offset;
3002 s->sh.offset[s->sh.num_entry_point_offsets] = offset;
3003
3004 s->sh.offset[0] = s->sh.data_offset;
3005 s->sh.size[0] = s->sh.offset[1] - s->sh.offset[0];
3006
3007 s->data = data;
3008
3009 for (unsigned i = 1; i < s->nb_local_ctx; i++) {
3010 s->local_ctx[i].first_qp_group = 1;
3011 s->local_ctx[i].qp_y = s->local_ctx[0].qp_y;
3012 }
3013
3014 atomic_store(&s->wpp_err, 0);
3015 res = wpp_progress_init(s, s->sh.num_entry_point_offsets + 1);
3016 if (res < 0)
3017 return res;
3018
3019 ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret));
3020 if (!ret)
3021 return AVERROR(ENOMEM);
3022
3023 if (pps->entropy_coding_sync_enabled_flag)
3024 s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->local_ctx, ret, s->sh.num_entry_point_offsets + 1);
3025
3026 for (int i = 0; i <= s->sh.num_entry_point_offsets; i++)
3027 res += ret[i];
3028
3029 av_free(ret);
3030 return res;
3031 }
3032
3033 28817 static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l,
3034 const H2645NAL *nal, GetBitContext *gb)
3035 {
3036 28817 const HEVCPPS *pps = s->pps;
3037 int ret;
3038
3039
2/2
✓ Branch 0 taken 18251 times.
✓ Branch 1 taken 10566 times.
28817 if (!s->sh.first_slice_in_pic_flag)
3040 18251 s->slice_idx += !s->sh.dependent_slice_segment_flag;
3041
3042
4/4
✓ Branch 0 taken 20870 times.
✓ Branch 1 taken 7947 times.
✓ Branch 2 taken 19571 times.
✓ Branch 3 taken 1299 times.
28817 if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) {
3043 19571 ret = ff_hevc_slice_rpl(s);
3044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19571 times.
19571 if (ret < 0) {
3045 av_log(s->avctx, AV_LOG_WARNING,
3046 "Error constructing the reference lists for the current slice.\n");
3047 return ret;
3048 }
3049 }
3050
3051 28817 s->slice_initialized = 1;
3052
3053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28817 times.
28817 if (s->avctx->hwaccel)
3054 return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size);
3055
3056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28817 times.
28817 if (s->avctx->profile == AV_PROFILE_HEVC_SCC) {
3057 av_log(s->avctx, AV_LOG_ERROR,
3058 "SCC profile is not yet implemented in hevc native decoder.\n");
3059 return AVERROR_PATCHWELCOME;
3060 }
3061
3062
2/2
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20870 times.
28817 if (s->sh.dependent_slice_segment_flag) {
3063 7947 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
3064 7947 int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
3065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
7947 if (l->tab_slice_address[prev_rs] != s->sh.slice_addr) {
3066 av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
3067 return AVERROR_INVALIDDATA;
3068 }
3069 }
3070
3071 28817 s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
3072
3073
2/2
✓ Branch 0 taken 23206 times.
✓ Branch 1 taken 5611 times.
28817 if (!pps->cu_qp_delta_enabled_flag)
3074 23206 s->local_ctx[0].qp_y = s->sh.slice_qp;
3075
3076 28817 s->local_ctx[0].tu.cu_qp_offset_cb = 0;
3077 28817 s->local_ctx[0].tu.cu_qp_offset_cr = 0;
3078
3079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28817 times.
28817 if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
3080 s->sh.num_entry_point_offsets > 0 &&
3081 pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
3082 return hls_slice_data_wpp(s, nal);
3083
3084 28817 return hls_decode_entry(s, gb);
3085 }
3086
3087 10566 static int set_side_data(HEVCContext *s)
3088 {
3089 10566 const HEVCSPS *sps = s->cur_frame->pps->sps;
3090 10566 AVFrame *out = s->cur_frame->f;
3091 int ret;
3092
3093 // Decrement the mastering display and content light level flag when IRAP
3094 // frame has no_rasl_output_flag=1 so the side data persists for the entire
3095 // coded video sequence.
3096
5/6
✓ Branch 0 taken 760 times.
✓ Branch 1 taken 9806 times.
✓ Branch 2 taken 760 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 477 times.
✓ Branch 5 taken 283 times.
10566 if (IS_IRAP(s) && s->no_rasl_output_flag) {
3097
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 457 times.
477 if (s->sei.common.mastering_display.present > 0)
3098 20 s->sei.common.mastering_display.present--;
3099
3100
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 469 times.
477 if (s->sei.common.content_light.present > 0)
3101 8 s->sei.common.content_light.present--;
3102 }
3103
3104 10566 ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx,
3105 &sps->vui.common,
3106 10566 sps->bit_depth, sps->bit_depth_chroma,
3107 10566 s->cur_frame->poc /* no poc_offset in HEVC */);
3108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (ret < 0)
3109 return ret;
3110
3111
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 10543 times.
10566 if (s->sei.timecode.present) {
3112 uint32_t *tc_sd;
3113 char tcbuf[AV_TIMECODE_STR_SIZE];
3114 AVFrameSideData *tcside;
3115 23 ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE,
3116 sizeof(uint32_t) * 4, &tcside);
3117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (ret < 0)
3118 return ret;
3119
3120
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 if (tcside) {
3121 23 tc_sd = (uint32_t*)tcside->data;
3122 23 tc_sd[0] = s->sei.timecode.num_clock_ts;
3123
3124
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 23 times.
46 for (int i = 0; i < tc_sd[0]; i++) {
3125 23 int drop = s->sei.timecode.cnt_dropped_flag[i];
3126 23 int hh = s->sei.timecode.hours_value[i];
3127 23 int mm = s->sei.timecode.minutes_value[i];
3128 23 int ss = s->sei.timecode.seconds_value[i];
3129 23 int ff = s->sei.timecode.n_frames[i];
3130
3131 23 tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff);
3132 23 av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0);
3133 23 av_dict_set(&out->metadata, "timecode", tcbuf, 0);
3134 }
3135 }
3136
3137 23 s->sei.timecode.num_clock_ts = 0;
3138 }
3139
3140
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 10560 times.
10566 if (s->sei.common.itut_t35.hdr_plus) {
3141 6 AVBufferRef *info_ref = av_buffer_ref(s->sei.common.itut_t35.hdr_plus);
3142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!info_ref)
3143 return AVERROR(ENOMEM);
3144
3145 6 ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref);
3146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ret < 0)
3147 return ret;
3148 }
3149
3150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (s->sei.common.itut_t35.hdr_smpte2094_app5) {
3151 AVBufferRef *info_ref = av_buffer_ref(s->sei.common.itut_t35.hdr_smpte2094_app5);
3152 if (!info_ref)
3153 return AVERROR(ENOMEM);
3154
3155 ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5, &info_ref);
3156 if (ret < 0)
3157 return ret;
3158 }
3159
3160
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10564 times.
10566 if (s->rpu_buf) {
3161 2 AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf);
3162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!rpu)
3163 return AVERROR(ENOMEM);
3164
3165 2 s->rpu_buf = NULL;
3166 }
3167
3168
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10566 times.
10566 if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0)
3169 return ret;
3170
3171
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10564 times.
10566 if (s->sei.common.itut_t35.hdr_vivid) {
3172
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!av_frame_side_data_add(&out->side_data, &out->nb_side_data,
3173 AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
3174 &s->sei.common.itut_t35.hdr_vivid,
3175 AV_FRAME_SIDE_DATA_FLAG_NEW_REF))
3176 return AVERROR(ENOMEM);
3177 }
3178
3179 10566 return 0;
3180 }
3181
3182 10176 static int find_finish_setup_nal(const HEVCContext *s)
3183 {
3184 10176 int nal_idx = 0;
3185
3186
2/2
✓ Branch 0 taken 39566 times.
✓ Branch 1 taken 10176 times.
49742 for (int i = nal_idx; i < s->pkt.nb_nals; i++) {
3187 39566 const H2645NAL *nal = &s->pkt.nals[i];
3188 39566 const int layer_id = nal->nuh_layer_id;
3189 39566 GetBitContext gb = nal->gb;
3190
3191
2/4
✓ Branch 0 taken 39566 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39566 times.
✗ Branch 3 not taken.
39566 if (layer_id > HEVC_MAX_NUH_LAYER_ID || s->vps->layer_idx[layer_id] < 0 ||
3192
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 39550 times.
39566 !(s->layers_active_decode & (1 << s->vps->layer_idx[layer_id])))
3193 18267 continue;
3194
3195
3/3
✓ Branch 0 taken 28818 times.
✓ Branch 1 taken 2316 times.
✓ Branch 2 taken 8416 times.
39550 switch (nal->type) {
3196 28818 case HEVC_NAL_TRAIL_R:
3197 case HEVC_NAL_TRAIL_N:
3198 case HEVC_NAL_TSA_N:
3199 case HEVC_NAL_TSA_R:
3200 case HEVC_NAL_STSA_N:
3201 case HEVC_NAL_STSA_R:
3202 case HEVC_NAL_BLA_W_LP:
3203 case HEVC_NAL_BLA_W_RADL:
3204 case HEVC_NAL_BLA_N_LP:
3205 case HEVC_NAL_IDR_W_RADL:
3206 case HEVC_NAL_IDR_N_LP:
3207 case HEVC_NAL_CRA_NUT:
3208 case HEVC_NAL_RADL_N:
3209 case HEVC_NAL_RADL_R:
3210 case HEVC_NAL_RASL_N:
3211 case HEVC_NAL_RASL_R:
3212
2/2
✓ Branch 1 taken 18251 times.
✓ Branch 2 taken 10567 times.
28818 if (!get_bits1(&gb)) // first_slice_segment_in_pic_flag
3213 18251 continue;
3214 av_fallthrough;
3215 case HEVC_NAL_VPS:
3216 case HEVC_NAL_SPS:
3217 case HEVC_NAL_PPS:
3218 12883 nal_idx = i;
3219 12883 break;
3220 }
3221 }
3222
3223 10176 return nal_idx;
3224 }
3225
3226 10566 static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l,
3227 unsigned nal_idx)
3228 {
3229 10566 const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id];
3230 10566 const HEVCSPS *const sps = pps->sps;
3231 10566 int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) *
3232 10566 ((sps->height >> sps->log2_min_cb_size) + 1);
3233
2/2
✓ Branch 0 taken 10176 times.
✓ Branch 1 taken 390 times.
20742 int new_sequence = (l == &s->layers[0]) &&
3234
12/12
✓ Branch 0 taken 9773 times.
✓ Branch 1 taken 403 times.
✓ Branch 2 taken 9733 times.
✓ Branch 3 taken 40 times.
✓ Branch 4 taken 9731 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9724 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9723 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 19 times.
✓ Branch 11 taken 9704 times.
10176 (IS_IDR(s) || IS_BLA(s) || s->last_eos);
3235 10566 int prev_layers_active_decode = s->layers_active_decode;
3236 10566 int prev_layers_active_output = s->layers_active_output;
3237 int ret;
3238
3239
3/4
✓ Branch 0 taken 444 times.
✓ Branch 1 taken 10122 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 444 times.
10566 if (sps->vps != s->vps && l != &s->layers[0]) {
3240 av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n");
3241 set_sps(s, l, NULL);
3242 return AVERROR_INVALIDDATA;
3243 }
3244
3245 10566 av_refstruct_replace(&s->pps, pps);
3246
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 10106 times.
10566 if (l->sps != sps) {
3247 460 const HEVCSPS *sps_base = s->layers[0].sps;
3248 460 enum AVPixelFormat pix_fmt = sps->pix_fmt;
3249
3250
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 450 times.
460 if (l != &s->layers[0]) {
3251
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!sps_base) {
3252 av_log(s->avctx, AV_LOG_ERROR,
3253 "Access unit starts with a non-base layer frame\n");
3254 return AVERROR_INVALIDDATA;
3255 }
3256
3257 // Files produced by Vision Pro lack VPS extension VUI,
3258 // so the secondary layer has no range information.
3259 // This check avoids failing in such a case.
3260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (sps_base->pix_fmt == AV_PIX_FMT_YUVJ420P &&
3261 sps->pix_fmt == AV_PIX_FMT_YUV420P &&
3262 !sps->vui.common.video_signal_type_present_flag)
3263 pix_fmt = sps_base->pix_fmt;
3264
3265 // Ignore range mismatch between base layer and alpha layer
3266
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
10 if (ff_hevc_is_alpha_video(s) &&
3267
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 &&
3268 pix_fmt == AV_PIX_FMT_YUVJ420P)
3269 1 pix_fmt = sps_base->pix_fmt;
3270
3271
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (pix_fmt != sps_base->pix_fmt ||
3272
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 sps->width != sps_base->width ||
3273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 sps->height != sps_base->height) {
3274 av_log(s->avctx, AV_LOG_ERROR,
3275 "Base/non-base layer SPS have unsupported parameter combination\n");
3276 return AVERROR(ENOSYS);
3277 }
3278 }
3279
3280 460 ff_hevc_clear_refs(l);
3281
3282 460 ret = set_sps(s, l, sps);
3283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if (ret < 0)
3284 return ret;
3285
3286
2/2
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 10 times.
460 if (l == &s->layers[0]) {
3287 450 export_stream_params(s, sps);
3288
3289 450 ret = get_format(s, sps);
3290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (ret < 0) {
3291 set_sps(s, l, NULL);
3292 return ret;
3293 }
3294
3295 450 new_sequence = 1;
3296 }
3297 }
3298
3299 10566 memset(l->horizontal_bs, 0, l->bs_width * l->bs_height);
3300 10566 memset(l->vertical_bs, 0, l->bs_width * l->bs_height);
3301 10566 memset(l->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height);
3302 10566 memset(l->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1));
3303 10566 memset(l->tab_slice_address, -1, pic_size_in_ctb * sizeof(*l->tab_slice_address));
3304
3305
4/4
✓ Branch 0 taken 10154 times.
✓ Branch 1 taken 412 times.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 10109 times.
10566 if (IS_IDR(s))
3306 457 ff_hevc_clear_refs(l);
3307
3308 10566 s->slice_idx = 0;
3309 10566 s->first_nal_type = s->nal_unit_type;
3310 10566 s->poc = s->sh.poc;
3311
3312
3/4
✓ Branch 0 taken 760 times.
✓ Branch 1 taken 9806 times.
✓ Branch 2 taken 760 times.
✗ Branch 3 not taken.
10566 if (IS_IRAP(s)) {
3313
10/10
✓ Branch 0 taken 348 times.
✓ Branch 1 taken 412 times.
✓ Branch 2 taken 303 times.
✓ Branch 3 taken 45 times.
✓ Branch 4 taken 301 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 294 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 293 times.
✓ Branch 9 taken 1 times.
1053 s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) ||
3314
3/4
✓ Branch 0 taken 293 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 283 times.
293 (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos);
3315 760 s->recovery_poc = HEVC_RECOVERY_END;
3316 }
3317
3318
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10546 times.
10566 if (s->recovery_poc != HEVC_RECOVERY_END &&
3319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 s->sei.recovery_point.has_recovery_poc) {
3320 if (s->recovery_poc == HEVC_RECOVERY_UNSPECIFIED)
3321 s->recovery_poc = s->poc + s->sei.recovery_point.recovery_poc_cnt;
3322 else if (s->poc >= s->recovery_poc)
3323 s->recovery_poc = HEVC_RECOVERY_END;
3324 }
3325
3326 /* 8.3.1 */
3327
2/2
✓ Branch 0 taken 10224 times.
✓ Branch 1 taken 342 times.
10566 if (s->temporal_id == 0 &&
3328
2/2
✓ Branch 0 taken 7487 times.
✓ Branch 1 taken 2737 times.
10224 s->nal_unit_type != HEVC_NAL_TRAIL_N &&
3329
1/2
✓ Branch 0 taken 7487 times.
✗ Branch 1 not taken.
7487 s->nal_unit_type != HEVC_NAL_TSA_N &&
3330
1/2
✓ Branch 0 taken 7487 times.
✗ Branch 1 not taken.
7487 s->nal_unit_type != HEVC_NAL_STSA_N &&
3331
2/2
✓ Branch 0 taken 7461 times.
✓ Branch 1 taken 26 times.
7487 s->nal_unit_type != HEVC_NAL_RADL_N &&
3332
2/2
✓ Branch 0 taken 7439 times.
✓ Branch 1 taken 22 times.
7461 s->nal_unit_type != HEVC_NAL_RADL_R &&
3333
2/2
✓ Branch 0 taken 7069 times.
✓ Branch 1 taken 370 times.
7439 s->nal_unit_type != HEVC_NAL_RASL_N &&
3334
2/2
✓ Branch 0 taken 6595 times.
✓ Branch 1 taken 474 times.
7069 s->nal_unit_type != HEVC_NAL_RASL_R)
3335 6595 s->poc_tid0 = s->poc;
3336
3337
2/2
✓ Branch 0 taken 754 times.
✓ Branch 1 taken 9812 times.
10566 if (pps->tiles_enabled_flag)
3338 754 s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size;
3339
3340
2/2
✓ Branch 0 taken 475 times.
✓ Branch 1 taken 10091 times.
10566 if (new_sequence) {
3341 475 ret = ff_hevc_output_frames(s, prev_layers_active_decode, prev_layers_active_output,
3342 475 0, 0, s->sh.no_output_of_prior_pics_flag);
3343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 475 times.
475 if (ret < 0)
3344 return ret;
3345 }
3346
3347 10566 ret = export_stream_params_from_sei(s);
3348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (ret < 0)
3349 return ret;
3350
3351 10566 ret = ff_hevc_set_new_ref(s, l, s->poc);
3352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (ret < 0)
3353 goto fail;
3354
3355 10566 ret = ff_hevc_frame_rps(s, l);
3356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (ret < 0) {
3357 av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n");
3358 goto fail;
3359 }
3360
3361
3/4
✓ Branch 0 taken 760 times.
✓ Branch 1 taken 9806 times.
✓ Branch 2 taken 760 times.
✗ Branch 3 not taken.
10566 if (IS_IRAP(s))
3362 760 s->cur_frame->f->flags |= AV_FRAME_FLAG_KEY;
3363 else
3364 9806 s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY;
3365
3366 21132 s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics &&
3367 s->sei.common.film_grain_characteristics->present) ||
3368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 s->sei.common.itut_t35.aom_film_grain.enable) &&
3369
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
21132 !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
3370 !s->avctx->hwaccel;
3371
3372 10566 ret = set_side_data(s);
3373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (ret < 0)
3374 goto fail;
3375
3376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (s->cur_frame->needs_fg &&
3377 (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present &&
3378 !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id,
3379 s->cur_frame->f->format) ||
3380 !av_film_grain_params_select(s->cur_frame->f))) {
3381 av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown,
3382 "Unsupported film grain parameters. Ignoring film grain.\n");
3383 s->cur_frame->needs_fg = 0;
3384 }
3385
3386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (s->cur_frame->needs_fg) {
3387 s->cur_frame->frame_grain->format = s->cur_frame->f->format;
3388 s->cur_frame->frame_grain->width = s->cur_frame->f->width;
3389 s->cur_frame->frame_grain->height = s->cur_frame->f->height;
3390 if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0)
3391 goto fail;
3392
3393 ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f);
3394 if (ret < 0)
3395 goto fail;
3396 }
3397
3398 10566 s->cur_frame->f->pict_type = 3 - s->sh.slice_type;
3399
3400 10566 ret = ff_hevc_output_frames(s, s->layers_active_decode, s->layers_active_output,
3401 10566 sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics,
3402 10566 sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0);
3403
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (ret < 0)
3404 goto fail;
3405
3406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (s->avctx->hwaccel) {
3407 AVCodecInternal *avci = s->avctx->internal;
3408 AVPacket *avpkt = avci->in_pkt;
3409 ret = FF_HW_CALL(s->avctx, start_frame,
3410 avpkt->buf, NULL, 0);
3411 if (ret < 0)
3412 goto fail;
3413 }
3414
3415 // after starting the base-layer frame we know which layers will be decoded,
3416 // so we can now figure out which NALUs to wait for before we can call
3417 // ff_thread_finish_setup()
3418
2/2
✓ Branch 0 taken 10176 times.
✓ Branch 1 taken 390 times.
10566 if (l == &s->layers[0])
3419 10176 s->finish_setup_nal_idx = find_finish_setup_nal(s);
3420
3421
2/2
✓ Branch 0 taken 10175 times.
✓ Branch 1 taken 391 times.
10566 if (nal_idx >= s->finish_setup_nal_idx)
3422 10175 ff_thread_finish_setup(s->avctx);
3423
3424 10566 return 0;
3425
3426 fail:
3427 if (l->cur_frame)
3428 ff_hevc_unref_frame(l->cur_frame, ~0);
3429 l->cur_frame = NULL;
3430 s->cur_frame = s->collocated_ref = NULL;
3431 return ret;
3432 }
3433
3434 static int verify_md5(HEVCContext *s, AVFrame *frame)
3435 {
3436 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
3437 char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
3438 int pixel_shift;
3439 int err = 0;
3440 int i, j;
3441
3442 if (!desc)
3443 return AVERROR(EINVAL);
3444
3445 pixel_shift = desc->comp[0].depth > 8;
3446
3447 /* the checksums are LE, so we have to byteswap for >8bpp formats
3448 * on BE arches */
3449 #if HAVE_BIGENDIAN
3450 if (pixel_shift && !s->checksum_buf) {
3451 av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size,
3452 FFMAX3(frame->linesize[0], frame->linesize[1],
3453 frame->linesize[2]));
3454 if (!s->checksum_buf)
3455 return AVERROR(ENOMEM);
3456 }
3457 #endif
3458
3459 msg_buf[0] = '\0';
3460 for (i = 0; frame->data[i]; i++) {
3461 int width = s->avctx->coded_width;
3462 int height = s->avctx->coded_height;
3463 int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width;
3464 int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height;
3465 uint8_t md5[16];
3466
3467 av_md5_init(s->md5_ctx);
3468 for (j = 0; j < h; j++) {
3469 const uint8_t *src = frame->data[i] + j * frame->linesize[i];
3470 #if HAVE_BIGENDIAN
3471 if (pixel_shift) {
3472 s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
3473 (const uint16_t *) src, w);
3474 src = s->checksum_buf;
3475 }
3476 #endif
3477 av_md5_update(s->md5_ctx, src, w << pixel_shift);
3478 }
3479 av_md5_final(s->md5_ctx, md5);
3480
3481 #define MD5_PRI "%016" PRIx64 "%016" PRIx64
3482 #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
3483
3484 if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
3485 av_strlcatf(msg_buf, sizeof(msg_buf),
3486 "plane %d - correct " MD5_PRI "; ",
3487 i, MD5_PRI_ARG(md5));
3488 } else {
3489 av_strlcatf(msg_buf, sizeof(msg_buf),
3490 "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
3491 i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i]));
3492 err = AVERROR_INVALIDDATA;
3493 }
3494 }
3495
3496 av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
3497 "Verifying checksum for frame with POC %d: %s\n",
3498 s->poc, msg_buf);
3499
3500 return err;
3501 }
3502
3503 10566 static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l)
3504 {
3505 10566 HEVCFrame *out = l->cur_frame;
3506 const AVFilmGrainParams *fgp;
3507 av_unused int ret;
3508
3509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (out->needs_fg) {
3510 av_assert0(out->frame_grain->buf[0]);
3511 fgp = av_film_grain_params_select(out->f);
3512 switch (fgp->type) {
3513 case AV_FILM_GRAIN_PARAMS_NONE:
3514 av_assert0(0);
3515 return AVERROR_BUG;
3516 case AV_FILM_GRAIN_PARAMS_H274:
3517 ret = ff_h274_apply_film_grain(out->frame_grain, out->f, fgp);
3518 break;
3519 case AV_FILM_GRAIN_PARAMS_AV1:
3520 ret = ff_aom_apply_film_grain(out->frame_grain, out->f, fgp);
3521 break;
3522 }
3523 av_assert1(ret >= 0);
3524 }
3525
3526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (s->avctx->hwaccel) {
3527 ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
3528 if (ret < 0) {
3529 av_log(s->avctx, AV_LOG_ERROR,
3530 "hardware accelerator failed to decode picture\n");
3531 return ret;
3532 }
3533 } else {
3534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
3535 s->sei.picture_hash.is_md5) {
3536 ret = verify_md5(s, out->f);
3537 if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
3538 return ret;
3539 }
3540 }
3541 10566 s->sei.picture_hash.is_md5 = 0;
3542
3543 10566 av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %zu/%d.\n",
3544 10566 l - s->layers, s->poc);
3545
3546 10566 return 0;
3547 }
3548
3549 28941 static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb)
3550 {
3551
2/2
✓ Branch 0 taken 28470 times.
✓ Branch 1 taken 471 times.
28941 const int layer_idx = s->vps ? s->vps->layer_idx[s->nuh_layer_id] : 0;
3552 HEVCLayerContext *l;
3553 int ret;
3554
3555 // skip layers not requested to be decoded
3556 // layers_active_decode can only change while decoding a base-layer frame,
3557 // so we can check it for non-base layers
3558
1/2
✓ Branch 0 taken 28941 times.
✗ Branch 1 not taken.
28941 if (layer_idx < 0 ||
3559
4/4
✓ Branch 0 taken 521 times.
✓ Branch 1 taken 28420 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 516 times.
28941 (s->nuh_layer_id > 0 && !(s->layers_active_decode & (1 << layer_idx))))
3560 5 return 0;
3561
3562 28936 ret = hls_slice_header(&s->sh, s, gb);
3563 // Once hls_slice_header has been called, the context is inconsistent with the slice header
3564 // until the context is reinitialized according to the contents of the new slice header
3565 // at the start of decode_slice_data.
3566 28936 s->slice_initialized = 0;
3567
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 28903 times.
28936 if (ret < 0) {
3568 33 return ret;
3569 }
3570
3571
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28903 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
28903 if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
3572
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28903 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
28903 (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
3573
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 28903 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
28903 (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
3574
4/4
✓ Branch 0 taken 27758 times.
✓ Branch 1 taken 1145 times.
✓ Branch 2 taken 1066 times.
✓ Branch 3 taken 26692 times.
28903 ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&
3575
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 2126 times.
2211 s->no_rasl_output_flag)) {
3576 85 return 0;
3577 }
3578
3579 // switching to a new layer, mark previous layer's frame (if any) as done
3580
2/2
✓ Branch 0 taken 771 times.
✓ Branch 1 taken 28047 times.
28818 if (s->cur_layer != layer_idx &&
3581
2/2
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 381 times.
771 s->layers[s->cur_layer].cur_frame &&
3582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
390 s->avctx->active_thread_type == FF_THREAD_FRAME)
3583 ff_progress_frame_report(&s->layers[s->cur_layer].cur_frame->tf, INT_MAX);
3584
3585 28818 s->cur_layer = layer_idx;
3586 28818 l = &s->layers[s->cur_layer];
3587
3588
2/2
✓ Branch 0 taken 10567 times.
✓ Branch 1 taken 18251 times.
28818 if (s->sh.first_slice_in_pic_flag) {
3589
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10566 times.
10567 if (l->cur_frame) {
3590 1 av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
3591 1 return AVERROR_INVALIDDATA;
3592 }
3593
3594 10566 ret = hevc_frame_start(s, l, nal_idx);
3595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10566 times.
10566 if (ret < 0)
3596 return ret;
3597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18251 times.
18251 } else if (!l->cur_frame) {
3598 av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
3599 return AVERROR_INVALIDDATA;
3600 }
3601
3602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28817 times.
28817 if (s->nal_unit_type != s->first_nal_type) {
3603 av_log(s->avctx, AV_LOG_ERROR,
3604 "Non-matching NAL types of the VCL NALUs: %d %d\n",
3605 s->first_nal_type, s->nal_unit_type);
3606 return AVERROR_INVALIDDATA;
3607 }
3608
3609 28817 ret = decode_slice_data(s, l, &s->pkt.nals[nal_idx], gb);
3610
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28816 times.
28817 if (ret < 0)
3611 1 return ret;
3612
3613 28816 return 0;
3614 }
3615
3616 39872 static int decode_nal_unit(HEVCContext *s, unsigned nal_idx)
3617 {
3618 39872 H2645NAL *nal = &s->pkt.nals[nal_idx];
3619 39872 GetBitContext gb = nal->gb;
3620 int ret;
3621
3622 39872 s->nal_unit_type = nal->type;
3623 39872 s->nuh_layer_id = nal->nuh_layer_id;
3624 39872 s->temporal_id = nal->temporal_id;
3625
3626
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 39872 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
39872 if (FF_HW_HAS_CB(s->avctx, decode_params) &&
3627 (s->nal_unit_type == HEVC_NAL_VPS ||
3628 s->nal_unit_type == HEVC_NAL_SPS ||
3629 s->nal_unit_type == HEVC_NAL_PPS ||
3630 s->nal_unit_type == HEVC_NAL_SEI_PREFIX ||
3631 s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) {
3632 ret = FF_HW_CALL(s->avctx, decode_params,
3633 nal->type, nal->raw_data, nal->raw_size);
3634 if (ret < 0)
3635 goto fail;
3636 }
3637
3638
6/7
✓ Branch 0 taken 449 times.
✓ Branch 1 taken 459 times.
✓ Branch 2 taken 1418 times.
✓ Branch 3 taken 7888 times.
✓ Branch 4 taken 28941 times.
✓ Branch 5 taken 717 times.
✗ Branch 6 not taken.
39872 switch (s->nal_unit_type) {
3639 449 case HEVC_NAL_VPS:
3640 449 ret = ff_hevc_decode_nal_vps(&gb, s->avctx, &s->ps);
3641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 449 times.
449 if (ret < 0)
3642 goto fail;
3643 449 break;
3644 459 case HEVC_NAL_SPS:
3645 459 ret = ff_hevc_decode_nal_sps(&gb, s->avctx, &s->ps,
3646 459 nal->nuh_layer_id, s->apply_defdispwin);
3647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 459 times.
459 if (ret < 0)
3648 goto fail;
3649 459 break;
3650 1418 case HEVC_NAL_PPS:
3651 1418 ret = ff_hevc_decode_nal_pps(&gb, s->avctx, &s->ps);
3652
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1416 times.
1418 if (ret < 0)
3653 2 goto fail;
3654 1416 break;
3655 7888 case HEVC_NAL_SEI_PREFIX:
3656 case HEVC_NAL_SEI_SUFFIX:
3657 7888 ret = ff_hevc_decode_nal_sei(&gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type);
3658
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7855 times.
7888 if (ret < 0)
3659 33 goto fail;
3660 7855 break;
3661 28941 case HEVC_NAL_TRAIL_R:
3662 case HEVC_NAL_TRAIL_N:
3663 case HEVC_NAL_TSA_N:
3664 case HEVC_NAL_TSA_R:
3665 case HEVC_NAL_STSA_N:
3666 case HEVC_NAL_STSA_R:
3667 case HEVC_NAL_BLA_W_LP:
3668 case HEVC_NAL_BLA_W_RADL:
3669 case HEVC_NAL_BLA_N_LP:
3670 case HEVC_NAL_IDR_W_RADL:
3671 case HEVC_NAL_IDR_N_LP:
3672 case HEVC_NAL_CRA_NUT:
3673 case HEVC_NAL_RADL_N:
3674 case HEVC_NAL_RADL_R:
3675 case HEVC_NAL_RASL_N:
3676 case HEVC_NAL_RASL_R:
3677 28941 ret = decode_slice(s, nal_idx, &gb);
3678
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 28906 times.
28941 if (ret < 0)
3679 35 goto fail;
3680 28906 break;
3681 717 case HEVC_NAL_EOS_NUT:
3682 case HEVC_NAL_EOB_NUT:
3683 case HEVC_NAL_AUD:
3684 case HEVC_NAL_FD_NUT:
3685 case HEVC_NAL_UNSPEC62: // Dolby Vision RPU
3686 case HEVC_NAL_UNSPEC63: // Dolby Vision EL
3687 717 break;
3688 default:
3689 av_log(s->avctx, AV_LOG_VERBOSE,
3690 "Skipping NAL unit %d\n", s->nal_unit_type);
3691 }
3692
3693 39802 return 0;
3694 70 fail:
3695
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 if (ret == AVERROR_INVALIDDATA &&
3696
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 !(s->avctx->err_recognition & AV_EF_EXPLODE)) {
3697 70 av_log(s->avctx, AV_LOG_WARNING,
3698 70 "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type);
3699 70 return 0;
3700 }
3701 return ret;
3702 }
3703
3704 442 static void decode_reset_recovery_point(HEVCContext *s)
3705 {
3706 442 s->recovery_poc = HEVC_RECOVERY_UNSPECIFIED;
3707 442 s->sei.recovery_point.has_recovery_poc = 0;
3708 442 }
3709
3710 10253 static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
3711 {
3712 10253 int ret = 0;
3713 10253 int eos_at_start = 1;
3714
2/2
✓ Branch 0 taken 350 times.
✓ Branch 1 taken 9903 times.
10253 int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING;
3715
3716 10253 s->cur_frame = s->collocated_ref = NULL;
3717 10253 s->last_eos = s->eos;
3718 10253 s->eos = 0;
3719 10253 s->slice_initialized = 0;
3720
2/2
✓ Branch 0 taken 438 times.
✓ Branch 1 taken 9815 times.
10253 if (s->last_eos)
3721 438 decode_reset_recovery_point(s);
3722
3723
2/2
✓ Branch 0 taken 20506 times.
✓ Branch 1 taken 10253 times.
30759 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3724 20506 HEVCLayerContext *l = &s->layers[i];
3725 20506 l->cur_frame = NULL;
3726 }
3727
3728 /* split the input packet into NAL units, so we know the upper bound on the
3729 * number of slices in the frame */
3730 10253 ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx,
3731 10253 s->nal_length_size, s->avctx->codec_id, flags);
3732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10253 times.
10253 if (ret < 0) {
3733 av_log(s->avctx, AV_LOG_ERROR,
3734 "Error splitting the input into NAL units.\n");
3735 return ret;
3736 }
3737
3738
2/2
✓ Branch 0 taken 39872 times.
✓ Branch 1 taken 10253 times.
50125 for (int i = 0; i < s->pkt.nb_nals; i++) {
3739
2/2
✓ Branch 0 taken 39871 times.
✓ Branch 1 taken 1 times.
39872 if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT ||
3740
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 39868 times.
39871 s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) {
3741
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (eos_at_start) {
3742 4 s->last_eos = 1;
3743 4 decode_reset_recovery_point(s);
3744 } else {
3745 s->eos = 1;
3746 }
3747 } else {
3748 39868 eos_at_start = 0;
3749 }
3750 }
3751
3752 /*
3753 * Check for RPU delimiter.
3754 *
3755 * Dolby Vision RPUs masquerade as unregistered NALs of type 62.
3756 *
3757 * We have to do this check here an create the rpu buffer, since RPUs are appended
3758 * to the end of an AU; they are normally the last non-EOB/EOS NAL in the AU.
3759 */
3760 10253 H2645NAL *rpu_nal = NULL;
3761
2/2
✓ Branch 0 taken 29618 times.
✓ Branch 1 taken 10251 times.
39869 for (int i = s->pkt.nb_nals - 1; i > 0 ; i--) {
3762
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 29616 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
29618 if (s->pkt.nals[i].type == HEVC_NAL_UNSPEC62 && s->pkt.nals[i].size > 2
3763
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) {
3764 2 rpu_nal = &s->pkt.nals[i];
3765 2 break;
3766 }
3767 }
3768
3769
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10251 times.
10253 if (rpu_nal) {
3770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->rpu_buf) {
3771 av_buffer_unref(&s->rpu_buf);
3772 av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n");
3773 }
3774
3775 2 s->rpu_buf = av_buffer_alloc(rpu_nal->raw_size - 2);
3776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!s->rpu_buf) {
3777 ret = AVERROR(ENOMEM);
3778 goto fail;
3779 }
3780 2 memcpy(s->rpu_buf->data, rpu_nal->raw_data + 2, rpu_nal->raw_size - 2);
3781
3782 2 ret = ff_dovi_rpu_parse(&s->dovi_ctx, rpu_nal->data + 2, rpu_nal->size - 2,
3783 2 s->avctx->err_recognition);
3784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0) {
3785 av_buffer_unref(&s->rpu_buf);
3786 av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n");
3787 /* ignore */
3788 }
3789 }
3790
3791 /* decode the NAL units */
3792
2/2
✓ Branch 0 taken 39872 times.
✓ Branch 1 taken 10253 times.
50125 for (int i = 0; i < s->pkt.nb_nals; i++) {
3793 39872 H2645NAL *nal = &s->pkt.nals[i];
3794
3795
1/2
✓ Branch 0 taken 39872 times.
✗ Branch 1 not taken.
39872 if (s->avctx->skip_frame >= AVDISCARD_ALL ||
3796
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 39872 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
39872 (s->avctx->skip_frame >= AVDISCARD_NONREF && ff_hevc_nal_is_nonref(nal->type)))
3797 continue;
3798
3799 39872 ret = decode_nal_unit(s, i);
3800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39872 times.
39872 if (ret < 0) {
3801 av_log(s->avctx, AV_LOG_WARNING,
3802 "Error parsing NAL unit #%d.\n", i);
3803 goto fail;
3804 }
3805 }
3806
3807 10253 fail:
3808
2/2
✓ Branch 0 taken 20506 times.
✓ Branch 1 taken 10253 times.
30759 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3809 20506 HEVCLayerContext *l = &s->layers[i];
3810
3811
2/2
✓ Branch 0 taken 9940 times.
✓ Branch 1 taken 10566 times.
20506 if (!l->cur_frame)
3812 9940 continue;
3813
3814
1/2
✓ Branch 0 taken 10566 times.
✗ Branch 1 not taken.
10566 if (ret >= 0)
3815 10566 ret = hevc_frame_end(s, l);
3816
3817
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 10533 times.
10566 if (s->avctx->active_thread_type == FF_THREAD_FRAME)
3818 33 ff_progress_frame_report(&l->cur_frame->tf, INT_MAX);
3819 }
3820
3821 10253 return ret;
3822 }
3823
3824 350 static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first)
3825 {
3826 int ret, i;
3827
3828 350 ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff,
3829 350 &s->nal_length_size, s->avctx->err_recognition,
3830 350 s->apply_defdispwin, s->avctx);
3831
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 350 times.
350 if (ret < 0)
3832 return ret;
3833
3834 /* export stream parameters from the first SPS */
3835
2/2
✓ Branch 0 taken 380 times.
✓ Branch 1 taken 2 times.
382 for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) {
3836
4/4
✓ Branch 0 taken 364 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 348 times.
✓ Branch 3 taken 16 times.
380 if (first && s->ps.sps_list[i]) {
3837 348 const HEVCSPS *sps = s->ps.sps_list[i];
3838 348 export_stream_params(s, sps);
3839
3840 348 ret = export_multilayer(s, sps->vps);
3841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
348 if (ret < 0)
3842 return ret;
3843
3844 348 break;
3845 }
3846 }
3847
3848 /* export stream parameters from SEI */
3849 350 ret = export_stream_params_from_sei(s);
3850
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 350 times.
350 if (ret < 0)
3851 return ret;
3852
3853 350 return 0;
3854 }
3855
3856 21735 static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame)
3857 {
3858 21735 HEVCContext *s = avctx->priv_data;
3859 21735 AVCodecInternal *avci = avctx->internal;
3860 21735 AVPacket *avpkt = avci->in_pkt;
3861
3862 int ret;
3863 uint8_t *sd;
3864 size_t sd_size;
3865
3866 21735 s->pkt_dts = AV_NOPTS_VALUE;
3867
3868
2/2
✓ Branch 1 taken 961 times.
✓ Branch 2 taken 20774 times.
21735 if (av_container_fifo_can_read(s->output_fifo))
3869 961 goto do_output;
3870
3871 20774 av_packet_unref(avpkt);
3872 20774 ret = ff_decode_get_packet(avctx, avpkt);
3873
2/2
✓ Branch 0 taken 346 times.
✓ Branch 1 taken 20428 times.
20774 if (ret == AVERROR_EOF) {
3874 346 ret = ff_hevc_output_frames(s, s->layers_active_decode,
3875 s->layers_active_output, 0, 0, 0);
3876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 346 times.
346 if (ret < 0)
3877 return ret;
3878 346 goto do_output;
3879
2/2
✓ Branch 0 taken 10175 times.
✓ Branch 1 taken 10253 times.
20428 } else if (ret < 0)
3880 10175 return ret;
3881
3882 10253 s->pkt_dts = avpkt->dts;
3883
3884 10253 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size);
3885
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10252 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
10253 if (sd && sd_size > 0) {
3886 1 ret = hevc_decode_extradata(s, sd, sd_size, 0);
3887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
3888 return ret;
3889 }
3890
3891 10253 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size);
3892
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10253 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10253 if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) {
3893 int old = s->dovi_ctx.cfg.dv_profile;
3894 s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd;
3895 if (old)
3896 av_log(avctx, AV_LOG_DEBUG,
3897 "New DOVI configuration record from input packet (profile %d -> %u).\n",
3898 old, s->dovi_ctx.cfg.dv_profile);
3899 }
3900
3901 10253 ret = decode_nal_units(s, avpkt->data, avpkt->size);
3902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10253 times.
10253 if (ret < 0)
3903 return ret;
3904
3905 10253 do_output:
3906
2/2
✓ Branch 1 taken 10274 times.
✓ Branch 2 taken 1286 times.
11560 if (av_container_fifo_read(s->output_fifo, frame, 0) >= 0) {
3907
1/2
✓ Branch 0 taken 10274 times.
✗ Branch 1 not taken.
10274 if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))
3908 10274 av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
3909
3910 10274 return 0;
3911 }
3912
3913
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 1069 times.
1286 return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN);
3914 }
3915
3916 67 static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
3917 {
3918 int ret;
3919
3920 67 ff_progress_frame_ref(&dst->tf, &src->tf);
3921
3922
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (src->needs_fg) {
3923 ret = av_frame_ref(dst->frame_grain, src->frame_grain);
3924 if (ret < 0) {
3925 ff_hevc_unref_frame(dst, ~0);
3926 return ret;
3927 }
3928 dst->needs_fg = 1;
3929 }
3930
3931 67 dst->pps = av_refstruct_ref_c(src->pps);
3932 67 dst->tab_mvf = av_refstruct_ref(src->tab_mvf);
3933 67 dst->rpl_tab = av_refstruct_ref(src->rpl_tab);
3934 67 dst->rpl = av_refstruct_ref(src->rpl);
3935 67 dst->nb_rpl_elems = src->nb_rpl_elems;
3936
3937 67 dst->poc = src->poc;
3938 67 dst->ctb_count = src->ctb_count;
3939 67 dst->flags = src->flags;
3940
3941 67 dst->base_layer_frame = src->base_layer_frame;
3942
3943 67 av_refstruct_replace(&dst->hwaccel_picture_private,
3944 67 src->hwaccel_picture_private);
3945
3946 67 return 0;
3947 }
3948
3949 569 static av_cold int hevc_decode_free(AVCodecContext *avctx)
3950 {
3951 569 HEVCContext *s = avctx->priv_data;
3952
3953
2/2
✓ Branch 0 taken 1138 times.
✓ Branch 1 taken 569 times.
1707 for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
3954 1138 pic_arrays_free(&s->layers[i]);
3955 1138 av_refstruct_unref(&s->layers[i].sps);
3956 }
3957
3958 569 av_refstruct_unref(&s->vps);
3959 569 av_refstruct_unref(&s->pps);
3960
3961 569 ff_dovi_ctx_unref(&s->dovi_ctx);
3962 569 av_buffer_unref(&s->rpu_buf);
3963
3964 569 av_freep(&s->md5_ctx);
3965
3966 569 av_container_fifo_free(&s->output_fifo);
3967
3968
2/2
✓ Branch 0 taken 1138 times.
✓ Branch 1 taken 569 times.
1707 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
3969 1138 HEVCLayerContext *l = &s->layers[layer];
3970
2/2
✓ Branch 0 taken 36416 times.
✓ Branch 1 taken 1138 times.
37554 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
3971 36416 ff_hevc_unref_frame(&l->DPB[i], ~0);
3972 36416 av_frame_free(&l->DPB[i].frame_grain);
3973 }
3974 }
3975
3976 569 ff_hevc_ps_uninit(&s->ps);
3977
3978
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 569 times.
569 for (int i = 0; i < s->nb_wpp_progress; i++)
3979 ff_thread_progress_destroy(&s->wpp_progress[i]);
3980 569 av_freep(&s->wpp_progress);
3981
3982 569 av_freep(&s->sh.entry_point_offset);
3983 569 av_freep(&s->sh.offset);
3984 569 av_freep(&s->sh.size);
3985
3986 569 av_freep(&s->local_ctx);
3987
3988 569 ff_h2645_packet_uninit(&s->pkt);
3989
3990 569 ff_hevc_reset_sei(&s->sei);
3991
3992 569 return 0;
3993 }
3994
3995 569 static av_cold int hevc_init_context(AVCodecContext *avctx)
3996 {
3997 569 HEVCContext *s = avctx->priv_data;
3998
3999 569 s->avctx = avctx;
4000
4001 569 s->local_ctx = av_mallocz(sizeof(*s->local_ctx));
4002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 569 times.
569 if (!s->local_ctx)
4003 return AVERROR(ENOMEM);
4004 569 s->nb_local_ctx = 1;
4005
4006 569 s->local_ctx[0].parent = s;
4007 569 s->local_ctx[0].logctx = avctx;
4008 569 s->local_ctx[0].common_cabac_state = &s->cabac;
4009
4010 569 s->output_fifo = av_container_fifo_alloc_avframe(0);
4011
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 569 times.
569 if (!s->output_fifo)
4012 return AVERROR(ENOMEM);
4013
4014
2/2
✓ Branch 0 taken 1138 times.
✓ Branch 1 taken 569 times.
1707 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
4015 1138 HEVCLayerContext *l = &s->layers[layer];
4016
2/2
✓ Branch 0 taken 36416 times.
✓ Branch 1 taken 1138 times.
37554 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
4017 36416 l->DPB[i].frame_grain = av_frame_alloc();
4018
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36416 times.
36416 if (!l->DPB[i].frame_grain)
4019 return AVERROR(ENOMEM);
4020 }
4021 }
4022
4023 569 s->md5_ctx = av_md5_alloc();
4024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 569 times.
569 if (!s->md5_ctx)
4025 return AVERROR(ENOMEM);
4026
4027 569 ff_bswapdsp_init(&s->bdsp);
4028
4029 569 s->dovi_ctx.logctx = avctx;
4030 569 s->eos = 0;
4031
4032 569 ff_hevc_reset_sei(&s->sei);
4033
4034 569 return 0;
4035 }
4036
4037 #if HAVE_THREADS
4038 32 static int hevc_update_thread_context(AVCodecContext *dst,
4039 const AVCodecContext *src)
4040 {
4041 32 HEVCContext *s = dst->priv_data;
4042 32 HEVCContext *s0 = src->priv_data;
4043 int ret;
4044
4045
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
96 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
4046 64 HEVCLayerContext *l = &s->layers[layer];
4047 64 const HEVCLayerContext *l0 = &s0->layers[layer];
4048
2/2
✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 64 times.
2112 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
4049 2048 ff_hevc_unref_frame(&l->DPB[i], ~0);
4050
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1981 times.
2048 if (l0->DPB[i].f) {
4051 67 ret = hevc_ref_frame(&l->DPB[i], &l0->DPB[i]);
4052
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (ret < 0)
4053 return ret;
4054 }
4055 }
4056
4057
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
64 if (l->sps != l0->sps) {
4058 1 ret = set_sps(s, l, l0->sps);
4059
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
4060 return ret;
4061 }
4062 }
4063
4064
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++)
4065 512 av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]);
4066
4067
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++)
4068 512 av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]);
4069
4070
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++)
4071 2048 av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]);
4072
4073 // PPS do not persist between frames
4074 32 av_refstruct_unref(&s->pps);
4075
4076 32 s->poc_tid0 = s0->poc_tid0;
4077 32 s->eos = s0->eos;
4078 32 s->no_rasl_output_flag = s0->no_rasl_output_flag;
4079
4080 32 s->is_nalff = s0->is_nalff;
4081 32 s->nal_length_size = s0->nal_length_size;
4082 32 s->layers_active_decode = s0->layers_active_decode;
4083 32 s->layers_active_output = s0->layers_active_output;
4084
4085 32 s->film_grain_warning_shown = s0->film_grain_warning_shown;
4086
4087
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (s->nb_view_ids != s0->nb_view_ids ||
4088
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)) {
4089 av_freep(&s->view_ids);
4090 s->nb_view_ids = 0;
4091
4092 if (s0->nb_view_ids) {
4093 s->view_ids = av_memdup(s0->view_ids, s0->nb_view_ids * sizeof(*s0->view_ids));
4094 if (!s->view_ids)
4095 return AVERROR(ENOMEM);
4096 s->nb_view_ids = s0->nb_view_ids;
4097 }
4098 }
4099
4100 32 ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common);
4101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4102 return ret;
4103
4104 32 ret = av_buffer_replace(&s->sei.common.itut_t35.hdr_plus,
4105 32 s0->sei.common.itut_t35.hdr_plus);
4106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4107 return ret;
4108
4109 32 ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf);
4110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4111 return ret;
4112
4113 32 ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx);
4114
4115 32 ret = av_buffer_replace(&s->sei.common.itut_t35.hdr_vivid,
4116 32 s0->sei.common.itut_t35.hdr_vivid);
4117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
4118 return ret;
4119
4120 32 s->sei.common.frame_packing = s0->sei.common.frame_packing;
4121 32 s->sei.common.display_orientation = s0->sei.common.display_orientation;
4122 32 s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer;
4123 32 s->sei.tdrdi = s0->sei.tdrdi;
4124 32 s->sei.recovery_point = s0->sei.recovery_point;
4125 32 s->recovery_poc = s0->recovery_poc;
4126
4127 32 return 0;
4128 }
4129 #endif
4130
4131 349 static int hevc_sei_to_context(AVCodecContext *avctx, HEVCSEI *sei)
4132 {
4133 int ret;
4134
4135
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 345 times.
349 if (sei->tdrdi.present) {
4136 AVBufferRef *buf;
4137 size_t size;
4138 4 AV3DReferenceDisplaysInfo *tdrdi = av_tdrdi_alloc(sei->tdrdi.num_ref_displays, &size);
4139
4140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!tdrdi)
4141 return AVERROR(ENOMEM);
4142
4143 4 buf = av_buffer_create((uint8_t *)tdrdi, size, NULL, NULL, 0);
4144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!buf) {
4145 av_free(tdrdi);
4146 return AVERROR(ENOMEM);
4147 }
4148
4149 4 tdrdi->prec_ref_display_width = sei->tdrdi.prec_ref_display_width;
4150 4 tdrdi->ref_viewing_distance_flag = sei->tdrdi.ref_viewing_distance_flag;
4151 4 tdrdi->prec_ref_viewing_dist = sei->tdrdi.prec_ref_viewing_dist;
4152 4 tdrdi->num_ref_displays = sei->tdrdi.num_ref_displays;
4153
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (int i = 0; i < sei->tdrdi.num_ref_displays; i++) {
4154 4 AV3DReferenceDisplay *display = av_tdrdi_get_display(tdrdi, i);
4155
4156 4 display->left_view_id = sei->tdrdi.left_view_id[i];
4157 4 display->right_view_id = sei->tdrdi.right_view_id[i];
4158 4 display->exponent_ref_display_width = sei->tdrdi.exponent_ref_display_width[i];
4159 4 display->mantissa_ref_display_width = sei->tdrdi.mantissa_ref_display_width[i];
4160 4 display->exponent_ref_viewing_distance = sei->tdrdi.exponent_ref_viewing_distance[i];
4161 4 display->mantissa_ref_viewing_distance = sei->tdrdi.mantissa_ref_viewing_distance[i];
4162 4 display->additional_shift_present_flag = sei->tdrdi.additional_shift_present_flag[i];
4163 4 display->num_sample_shift = sei->tdrdi.num_sample_shift[i];
4164 }
4165 4 ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data,
4166 AV_FRAME_DATA_3D_REFERENCE_DISPLAYS, &buf);
4167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0) {
4168 av_buffer_unref(&buf);
4169 return ret;
4170 }
4171 }
4172
4173 349 ret = ff_h2645_sei_to_context(avctx, &sei->common);
4174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 349 times.
349 if (ret < 0)
4175 return ret;
4176
4177 349 return 0;
4178 }
4179
4180 569 static av_cold int hevc_decode_init(AVCodecContext *avctx)
4181 {
4182 569 HEVCContext *s = avctx->priv_data;
4183 int ret;
4184
4185 569 ret = hevc_init_context(avctx);
4186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 569 times.
569 if (ret < 0)
4187 return ret;
4188
4189 569 s->sei.picture_timing.picture_struct = 0;
4190 569 s->eos = 1;
4191
4192 569 atomic_init(&s->wpp_err, 0);
4193
4194
2/2
✓ Branch 0 taken 568 times.
✓ Branch 1 taken 1 times.
569 if (!avctx->internal->is_copy) {
4195 const AVPacketSideData *sd;
4196
4197
3/4
✓ Branch 0 taken 349 times.
✓ Branch 1 taken 219 times.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
568 if (avctx->extradata_size > 0 && avctx->extradata) {
4198 349 ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1);
4199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 349 times.
349 if (ret < 0) {
4200 return ret;
4201 }
4202
4203 349 ret = hevc_sei_to_context(avctx, &s->sei);
4204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 349 times.
349 if (ret < 0)
4205 return ret;
4206 }
4207
4208 568 sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF);
4209
3/4
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 533 times.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
568 if (sd && sd->size >= sizeof(s->dovi_ctx.cfg))
4210 35 s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data;
4211 }
4212
4213 569 return 0;
4214 }
4215
4216 static av_cold void hevc_decode_flush(AVCodecContext *avctx)
4217 {
4218 HEVCContext *s = avctx->priv_data;
4219 ff_hevc_flush_dpb(s);
4220 ff_hevc_reset_sei(&s->sei);
4221 ff_dovi_ctx_flush(&s->dovi_ctx);
4222 av_buffer_unref(&s->rpu_buf);
4223 s->eos = 1;
4224
4225 if (FF_HW_HAS_CB(avctx, flush))
4226 FF_HW_SIMPLE_CALL(avctx, flush);
4227 }
4228
4229 #define OFFSET(x) offsetof(HEVCContext, x)
4230 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
4231
4232 static const AVOption options[] = {
4233 { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin),
4234 AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4235 { "strict-displaywin", "strictly apply default display window size", OFFSET(apply_defdispwin),
4236 AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR },
4237 { "view_ids", "Array of view IDs that should be decoded and output; a single -1 to decode all views",
4238 .offset = OFFSET(view_ids), .type = AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY,
4239 .min = -1, .max = INT_MAX, .flags = PAR },
4240 { "view_ids_available", "Array of available view IDs is exported here",
4241 .offset = OFFSET(view_ids_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4242 .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
4243 { "view_pos_available", "Array of view positions for view_ids_available is exported here, as AVStereo3DView",
4244 .offset = OFFSET(view_pos_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY,
4245 .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY, .unit = "view_pos" },
4246 { "unspecified", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_UNSPEC }, .unit = "view_pos" },
4247 { "left", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_LEFT }, .unit = "view_pos" },
4248 { "right", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_RIGHT }, .unit = "view_pos" },
4249
4250 { NULL },
4251 };
4252
4253 static const AVClass hevc_decoder_class = {
4254 .class_name = "HEVC decoder",
4255 .item_name = av_default_item_name,
4256 .option = options,
4257 .version = LIBAVUTIL_VERSION_INT,
4258 };
4259
4260 const FFCodec ff_hevc_decoder = {
4261 .p.name = "hevc",
4262 CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"),
4263 .p.type = AVMEDIA_TYPE_VIDEO,
4264 .p.id = AV_CODEC_ID_HEVC,
4265 .priv_data_size = sizeof(HEVCContext),
4266 .p.priv_class = &hevc_decoder_class,
4267 .init = hevc_decode_init,
4268 .close = hevc_decode_free,
4269 FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame),
4270 .flush = hevc_decode_flush,
4271 UPDATE_THREAD_CONTEXT(hevc_update_thread_context),
4272 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
4273 AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
4274 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
4275 FF_CODEC_CAP_USES_PROGRESSFRAMES |
4276 FF_CODEC_CAP_INIT_CLEANUP,
4277 .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
4278 .hw_configs = (const AVCodecHWConfigInternal *const []) {
4279 #if CONFIG_HEVC_DXVA2_HWACCEL
4280 HWACCEL_DXVA2(hevc),
4281 #endif
4282 #if CONFIG_HEVC_D3D11VA_HWACCEL
4283 HWACCEL_D3D11VA(hevc),
4284 #endif
4285 #if CONFIG_HEVC_D3D11VA2_HWACCEL
4286 HWACCEL_D3D11VA2(hevc),
4287 #endif
4288 #if CONFIG_HEVC_D3D12VA_HWACCEL
4289 HWACCEL_D3D12VA(hevc),
4290 #endif
4291 #if CONFIG_HEVC_NVDEC_HWACCEL
4292 HWACCEL_NVDEC(hevc),
4293 #endif
4294 #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL
4295 HWACCEL_NVDEC_CUARRAY(hevc),
4296 #endif
4297 #if CONFIG_HEVC_VAAPI_HWACCEL
4298 HWACCEL_VAAPI(hevc),
4299 #endif
4300 #if CONFIG_HEVC_VDPAU_HWACCEL
4301 HWACCEL_VDPAU(hevc),
4302 #endif
4303 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
4304 HWACCEL_VIDEOTOOLBOX(hevc),
4305 #endif
4306 #if CONFIG_HEVC_VULKAN_HWACCEL
4307 HWACCEL_VULKAN(hevc),
4308 #endif
4309 NULL
4310 },
4311 };
4312