FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc/hevcdec.c
Date: 2024-07-16 12:46:59
Exec Total Coverage
Lines: 1794 2184 82.1%
Functions: 45 48 93.8%
Branches: 1254 1640 76.5%

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/film_grain_params.h"
32 #include "libavutil/internal.h"
33 #include "libavutil/md5.h"
34 #include "libavutil/mem.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/pixdesc.h"
37 #include "libavutil/timecode.h"
38
39 #include "aom_film_grain.h"
40 #include "bswapdsp.h"
41 #include "cabac_functions.h"
42 #include "codec_internal.h"
43 #include "decode.h"
44 #include "golomb.h"
45 #include "hevc.h"
46 #include "parse.h"
47 #include "hevcdec.h"
48 #include "hwaccel_internal.h"
49 #include "hwconfig.h"
50 #include "internal.h"
51 #include "profiles.h"
52 #include "progressframe.h"
53 #include "refstruct.h"
54 #include "thread.h"
55
56 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 };
57
58 /**
59 * NOTE: Each function hls_foo correspond to the function foo in the
60 * specification (HLS stands for High Level Syntax).
61 */
62
63 /**
64 * Section 5.7
65 */
66
67 /* free everything allocated by pic_arrays_init() */
68 818 static void pic_arrays_free(HEVCContext *s)
69 {
70 818 av_freep(&s->sao);
71 818 av_freep(&s->deblock);
72
73 818 av_freep(&s->skip_flag);
74 818 av_freep(&s->tab_ct_depth);
75
76 818 av_freep(&s->tab_ipm);
77 818 av_freep(&s->cbf_luma);
78 818 av_freep(&s->is_pcm);
79
80 818 av_freep(&s->qp_y_tab);
81 818 av_freep(&s->tab_slice_address);
82 818 av_freep(&s->filter_slice_edges);
83
84 818 av_freep(&s->horizontal_bs);
85 818 av_freep(&s->vertical_bs);
86
87 818 ff_refstruct_pool_uninit(&s->tab_mvf_pool);
88 818 ff_refstruct_pool_uninit(&s->rpl_tab_pool);
89 818 }
90
91 /* allocate arrays that depend on frame dimensions */
92 386 static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
93 {
94 386 int log2_min_cb_size = sps->log2_min_cb_size;
95 386 int width = sps->width;
96 386 int height = sps->height;
97 386 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
98 386 ((height >> log2_min_cb_size) + 1);
99 386 int ctb_count = sps->ctb_width * sps->ctb_height;
100 386 int min_pu_size = sps->min_pu_width * sps->min_pu_height;
101
102 386 s->bs_width = (width >> 2) + 1;
103 386 s->bs_height = (height >> 2) + 1;
104
105 386 s->sao = av_calloc(ctb_count, sizeof(*s->sao));
106 386 s->deblock = av_calloc(ctb_count, sizeof(*s->deblock));
107
2/4
✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 386 times.
386 if (!s->sao || !s->deblock)
108 goto fail;
109
110 386 s->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
111 386 s->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
112
2/4
✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 386 times.
386 if (!s->skip_flag || !s->tab_ct_depth)
113 goto fail;
114
115 386 s->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
116 386 s->tab_ipm = av_mallocz(min_pu_size);
117 386 s->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1);
118
3/6
✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 386 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 386 times.
386 if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)
119 goto fail;
120
121 386 s->filter_slice_edges = av_mallocz(ctb_count);
122 386 s->tab_slice_address = av_malloc_array(pic_size_in_ctb,
123 sizeof(*s->tab_slice_address));
124 386 s->qp_y_tab = av_malloc_array(pic_size_in_ctb,
125 sizeof(*s->qp_y_tab));
126
3/6
✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 386 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 386 times.
386 if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)
127 goto fail;
128
129 386 s->horizontal_bs = av_calloc(s->bs_width, s->bs_height);
130 386 s->vertical_bs = av_calloc(s->bs_width, s->bs_height);
131
2/4
✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 386 times.
386 if (!s->horizontal_bs || !s->vertical_bs)
132 goto fail;
133
134 386 s->tab_mvf_pool = ff_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
135 386 s->rpl_tab_pool = ff_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0);
136
2/4
✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 386 times.
386 if (!s->tab_mvf_pool || !s->rpl_tab_pool)
137 goto fail;
138
139 386 return 0;
140
141 fail:
142 pic_arrays_free(s);
143 return AVERROR(ENOMEM);
144 }
145
146 1443 static int pred_weight_table(SliceHeader *sh, void *logctx,
147 const HEVCSPS *sps, GetBitContext *gb)
148 {
149 1443 int i = 0;
150 1443 int j = 0;
151 uint8_t luma_weight_l0_flag[16];
152 uint8_t chroma_weight_l0_flag[16];
153 uint8_t luma_weight_l1_flag[16];
154 uint8_t chroma_weight_l1_flag[16];
155 int luma_log2_weight_denom;
156
157 1443 luma_log2_weight_denom = get_ue_golomb_long(gb);
158
2/4
✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1443 times.
1443 if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
159 av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
160 return AVERROR_INVALIDDATA;
161 }
162 1443 sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
163
1/2
✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
1443 if (sps->chroma_format_idc != 0) {
164 1443 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
165
2/4
✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1443 times.
1443 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
166 av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
167 return AVERROR_INVALIDDATA;
168 }
169 1443 sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
170 }
171
172
2/2
✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
5850 for (i = 0; i < sh->nb_refs[L0]; i++) {
173 4407 luma_weight_l0_flag[i] = get_bits1(gb);
174
2/2
✓ Branch 0 taken 1290 times.
✓ Branch 1 taken 3117 times.
4407 if (!luma_weight_l0_flag[i]) {
175 1290 sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
176 1290 sh->luma_offset_l0[i] = 0;
177 }
178 }
179
1/2
✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
1443 if (sps->chroma_format_idc != 0) {
180
2/2
✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
5850 for (i = 0; i < sh->nb_refs[L0]; i++)
181 4407 chroma_weight_l0_flag[i] = get_bits1(gb);
182 } else {
183 for (i = 0; i < sh->nb_refs[L0]; i++)
184 chroma_weight_l0_flag[i] = 0;
185 }
186
2/2
✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
5850 for (i = 0; i < sh->nb_refs[L0]; i++) {
187
2/2
✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1290 times.
4407 if (luma_weight_l0_flag[i]) {
188 3117 int delta_luma_weight_l0 = get_se_golomb(gb);
189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
3117 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
190 return AVERROR_INVALIDDATA;
191 3117 sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
192 3117 sh->luma_offset_l0[i] = get_se_golomb(gb);
193 }
194
2/2
✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3276 times.
4407 if (chroma_weight_l0_flag[i]) {
195
2/2
✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
3393 for (j = 0; j < 2; j++) {
196 2262 int delta_chroma_weight_l0 = get_se_golomb(gb);
197 2262 int delta_chroma_offset_l0 = get_se_golomb(gb);
198
199
1/2
✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
2262 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
200
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)) {
201 return AVERROR_INVALIDDATA;
202 }
203
204 2262 sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0;
205 2262 sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j])
206 2262 >> sh->chroma_log2_weight_denom) + 128), -128, 127);
207 }
208 } else {
209 3276 sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom;
210 3276 sh->chroma_offset_l0[i][0] = 0;
211 3276 sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom;
212 3276 sh->chroma_offset_l0[i][1] = 0;
213 }
214 }
215
2/2
✓ Branch 0 taken 668 times.
✓ Branch 1 taken 775 times.
1443 if (sh->slice_type == HEVC_SLICE_B) {
216
2/2
✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
2015 for (i = 0; i < sh->nb_refs[L1]; i++) {
217 1347 luma_weight_l1_flag[i] = get_bits1(gb);
218
2/2
✓ Branch 0 taken 601 times.
✓ Branch 1 taken 746 times.
1347 if (!luma_weight_l1_flag[i]) {
219 601 sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
220 601 sh->luma_offset_l1[i] = 0;
221 }
222 }
223
1/2
✓ Branch 0 taken 668 times.
✗ Branch 1 not taken.
668 if (sps->chroma_format_idc != 0) {
224
2/2
✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
2015 for (i = 0; i < sh->nb_refs[L1]; i++)
225 1347 chroma_weight_l1_flag[i] = get_bits1(gb);
226 } else {
227 for (i = 0; i < sh->nb_refs[L1]; i++)
228 chroma_weight_l1_flag[i] = 0;
229 }
230
2/2
✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
2015 for (i = 0; i < sh->nb_refs[L1]; i++) {
231
2/2
✓ Branch 0 taken 746 times.
✓ Branch 1 taken 601 times.
1347 if (luma_weight_l1_flag[i]) {
232 746 int delta_luma_weight_l1 = get_se_golomb(gb);
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
746 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
234 return AVERROR_INVALIDDATA;
235 746 sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
236 746 sh->luma_offset_l1[i] = get_se_golomb(gb);
237 }
238
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1111 times.
1347 if (chroma_weight_l1_flag[i]) {
239
2/2
✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
708 for (j = 0; j < 2; j++) {
240 472 int delta_chroma_weight_l1 = get_se_golomb(gb);
241 472 int delta_chroma_offset_l1 = get_se_golomb(gb);
242
243
1/2
✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
472 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
244
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)) {
245 return AVERROR_INVALIDDATA;
246 }
247
248 472 sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1;
249 472 sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j])
250 472 >> sh->chroma_log2_weight_denom) + 128), -128, 127);
251 }
252 } else {
253 1111 sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom;
254 1111 sh->chroma_offset_l1[i][0] = 0;
255 1111 sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom;
256 1111 sh->chroma_offset_l1[i][1] = 0;
257 }
258 }
259 }
260 1443 return 0;
261 }
262
263 19069 static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps,
264 GetBitContext *gb, int cur_poc, int poc_lsb)
265 {
266 19069 int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
267 19069 int prev_delta_msb = 0;
268 19069 unsigned int nb_sps = 0, nb_sh;
269 int i;
270
271 19069 rps->nb_refs = 0;
272
2/2
✓ Branch 0 taken 18033 times.
✓ Branch 1 taken 1036 times.
19069 if (!sps->long_term_ref_pics_present)
273 18033 return 0;
274
275
2/2
✓ Branch 0 taken 499 times.
✓ Branch 1 taken 537 times.
1036 if (sps->num_long_term_ref_pics_sps > 0)
276 499 nb_sps = get_ue_golomb_long(gb);
277 1036 nb_sh = get_ue_golomb_long(gb);
278
279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
1036 if (nb_sps > sps->num_long_term_ref_pics_sps)
280 return AVERROR_INVALIDDATA;
281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
1036 if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc))
282 return AVERROR_INVALIDDATA;
283
284 1036 rps->nb_refs = nb_sh + nb_sps;
285
286
2/2
✓ Branch 0 taken 1562 times.
✓ Branch 1 taken 1036 times.
2598 for (i = 0; i < rps->nb_refs; i++) {
287
288
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1378 times.
1562 if (i < nb_sps) {
289 184 uint8_t lt_idx_sps = 0;
290
291
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if (sps->num_long_term_ref_pics_sps > 1)
292 184 lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps));
293
294 184 rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
295 184 rps->used[i] = !!(sps->used_by_curr_pic_lt & (1 << lt_idx_sps));
296 } else {
297 1378 rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb);
298 1378 rps->used[i] = get_bits1(gb);
299 }
300
301 1562 rps->poc_msb_present[i] = get_bits1(gb);
302
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1514 times.
1562 if (rps->poc_msb_present[i]) {
303 48 int64_t delta = get_ue_golomb_long(gb);
304 int64_t poc;
305
306
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)
307 31 delta += prev_delta_msb;
308
309 48 poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb;
310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (poc != (int32_t)poc)
311 return AVERROR_INVALIDDATA;
312 48 rps->poc[i] = poc;
313 48 prev_delta_msb = delta;
314 }
315 }
316
317 1036 return 0;
318 }
319
320 616 static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
321 {
322 616 AVCodecContext *avctx = s->avctx;
323 616 const HEVCVPS *vps = sps->vps;
324 616 const HEVCWindow *ow = &sps->output_window;
325 616 unsigned int num = 0, den = 0;
326
327 616 avctx->pix_fmt = sps->pix_fmt;
328 616 avctx->coded_width = sps->width;
329 616 avctx->coded_height = sps->height;
330 616 avctx->width = sps->width - ow->left_offset - ow->right_offset;
331 616 avctx->height = sps->height - ow->top_offset - ow->bottom_offset;
332 616 avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
333 616 avctx->profile = sps->ptl.general_ptl.profile_idc;
334 616 avctx->level = sps->ptl.general_ptl.level_idc;
335
336 616 ff_set_sar(avctx, sps->vui.common.sar);
337
338
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 570 times.
616 if (sps->vui.common.video_signal_type_present_flag)
339 46 avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG
340
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 40 times.
46 : AVCOL_RANGE_MPEG;
341 else
342 570 avctx->color_range = AVCOL_RANGE_MPEG;
343
344
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 573 times.
616 if (sps->vui.common.colour_description_present_flag) {
345 43 avctx->color_primaries = sps->vui.common.colour_primaries;
346 43 avctx->color_trc = sps->vui.common.transfer_characteristics;
347 43 avctx->colorspace = sps->vui.common.matrix_coeffs;
348 } else {
349 573 avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
350 573 avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
351 573 avctx->colorspace = AVCOL_SPC_UNSPECIFIED;
352 }
353
354 616 avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
355
2/2
✓ Branch 0 taken 575 times.
✓ Branch 1 taken 41 times.
616 if (sps->chroma_format_idc == 1) {
356
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 560 times.
575 if (sps->vui.common.chroma_loc_info_present_flag) {
357
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (sps->vui.common.chroma_sample_loc_type_top_field <= 5)
358 15 avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1;
359 } else
360 560 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
361 }
362
363
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 594 times.
616 if (vps->vps_timing_info_present_flag) {
364 22 num = vps->vps_num_units_in_tick;
365 22 den = vps->vps_time_scale;
366
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 545 times.
594 } else if (sps->vui.vui_timing_info_present_flag) {
367 49 num = sps->vui.vui_num_units_in_tick;
368 49 den = sps->vui.vui_time_scale;
369 }
370
371
3/4
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 545 times.
✓ Branch 2 taken 71 times.
✗ Branch 3 not taken.
616 if (num != 0 && den != 0)
372 71 av_reduce(&avctx->framerate.den, &avctx->framerate.num,
373 num, den, 1 << 30);
374 616 }
375
376 9772 static int export_stream_params_from_sei(HEVCContext *s)
377 {
378 9772 AVCodecContext *avctx = s->avctx;
379
380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9772 times.
9772 if (s->sei.common.a53_caption.buf_ref)
381 s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
382
383
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9772 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9772 if (s->sei.common.alternative_transfer.present &&
384 av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) &&
385 s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
386 avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics;
387 }
388
389
1/2
✓ Branch 0 taken 9772 times.
✗ Branch 1 not taken.
9772 if (s->sei.common.film_grain_characteristics.present ||
390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9772 times.
9772 s->sei.common.aom_film_grain.enable)
391 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
392
393 9772 return 0;
394 }
395
396 385 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
397 {
398 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
399 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
400 CONFIG_HEVC_D3D12VA_HWACCEL + \
401 CONFIG_HEVC_NVDEC_HWACCEL + \
402 CONFIG_HEVC_VAAPI_HWACCEL + \
403 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
404 CONFIG_HEVC_VDPAU_HWACCEL + \
405 CONFIG_HEVC_VULKAN_HWACCEL)
406 385 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
407
408
6/7
✓ Branch 0 taken 324 times.
✓ Branch 1 taken 33 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.
385 switch (sps->pix_fmt) {
409 324 case AV_PIX_FMT_YUV420P:
410 case AV_PIX_FMT_YUVJ420P:
411 #if CONFIG_HEVC_DXVA2_HWACCEL
412 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
413 #endif
414 #if CONFIG_HEVC_D3D11VA_HWACCEL
415 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
416 *fmt++ = AV_PIX_FMT_D3D11;
417 #endif
418 #if CONFIG_HEVC_D3D12VA_HWACCEL
419 *fmt++ = AV_PIX_FMT_D3D12;
420 #endif
421 #if CONFIG_HEVC_VAAPI_HWACCEL
422 324 *fmt++ = AV_PIX_FMT_VAAPI;
423 #endif
424 #if CONFIG_HEVC_VDPAU_HWACCEL
425 324 *fmt++ = AV_PIX_FMT_VDPAU;
426 #endif
427 #if CONFIG_HEVC_NVDEC_HWACCEL
428 *fmt++ = AV_PIX_FMT_CUDA;
429 #endif
430 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
431 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
432 #endif
433 #if CONFIG_HEVC_VULKAN_HWACCEL
434 *fmt++ = AV_PIX_FMT_VULKAN;
435 #endif
436 324 break;
437 33 case AV_PIX_FMT_YUV420P10:
438 #if CONFIG_HEVC_DXVA2_HWACCEL
439 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
440 #endif
441 #if CONFIG_HEVC_D3D11VA_HWACCEL
442 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
443 *fmt++ = AV_PIX_FMT_D3D11;
444 #endif
445 #if CONFIG_HEVC_D3D12VA_HWACCEL
446 *fmt++ = AV_PIX_FMT_D3D12;
447 #endif
448 #if CONFIG_HEVC_VAAPI_HWACCEL
449 33 *fmt++ = AV_PIX_FMT_VAAPI;
450 #endif
451 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
452 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
453 #endif
454 #if CONFIG_HEVC_VULKAN_HWACCEL
455 *fmt++ = AV_PIX_FMT_VULKAN;
456 #endif
457 #if CONFIG_HEVC_VDPAU_HWACCEL
458 33 *fmt++ = AV_PIX_FMT_VDPAU;
459 #endif
460 #if CONFIG_HEVC_NVDEC_HWACCEL
461 *fmt++ = AV_PIX_FMT_CUDA;
462 #endif
463 33 break;
464 4 case AV_PIX_FMT_YUV444P:
465 #if CONFIG_HEVC_VAAPI_HWACCEL
466 4 *fmt++ = AV_PIX_FMT_VAAPI;
467 #endif
468 #if CONFIG_HEVC_VDPAU_HWACCEL
469 4 *fmt++ = AV_PIX_FMT_VDPAU;
470 #endif
471 #if CONFIG_HEVC_NVDEC_HWACCEL
472 *fmt++ = AV_PIX_FMT_CUDA;
473 #endif
474 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
475 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
476 #endif
477 #if CONFIG_HEVC_VULKAN_HWACCEL
478 *fmt++ = AV_PIX_FMT_VULKAN;
479 #endif
480 4 break;
481 12 case AV_PIX_FMT_YUV422P:
482 case AV_PIX_FMT_YUV422P10LE:
483 #if CONFIG_HEVC_VAAPI_HWACCEL
484 12 *fmt++ = AV_PIX_FMT_VAAPI;
485 #endif
486 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
487 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
488 #endif
489 #if CONFIG_HEVC_VULKAN_HWACCEL
490 *fmt++ = AV_PIX_FMT_VULKAN;
491 #endif
492 12 break;
493 10 case AV_PIX_FMT_YUV444P10:
494 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
495 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
496 #endif
497 /* NOTE: fallthrough */
498 case AV_PIX_FMT_YUV420P12:
499 case AV_PIX_FMT_YUV444P12:
500 #if CONFIG_HEVC_VAAPI_HWACCEL
501 10 *fmt++ = AV_PIX_FMT_VAAPI;
502 #endif
503 #if CONFIG_HEVC_VDPAU_HWACCEL
504 10 *fmt++ = AV_PIX_FMT_VDPAU;
505 #endif
506 #if CONFIG_HEVC_VULKAN_HWACCEL
507 *fmt++ = AV_PIX_FMT_VULKAN;
508 #endif
509 #if CONFIG_HEVC_NVDEC_HWACCEL
510 *fmt++ = AV_PIX_FMT_CUDA;
511 #endif
512 10 break;
513 case AV_PIX_FMT_YUV422P12:
514 #if CONFIG_HEVC_VAAPI_HWACCEL
515 *fmt++ = AV_PIX_FMT_VAAPI;
516 #endif
517 #if CONFIG_HEVC_VULKAN_HWACCEL
518 *fmt++ = AV_PIX_FMT_VULKAN;
519 #endif
520 break;
521 }
522
523 385 *fmt++ = sps->pix_fmt;
524 385 *fmt = AV_PIX_FMT_NONE;
525
526 385 return ff_get_format(s->avctx, pix_fmts);
527 }
528
529 386 static int set_sps(HEVCContext *s, const HEVCSPS *sps)
530 {
531 int ret, i;
532
533 386 pic_arrays_free(s);
534 386 s->ps.sps = NULL;
535 386 s->ps.vps = NULL;
536
537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 386 times.
386 if (!sps)
538 return 0;
539
540 386 ret = pic_arrays_init(s, sps);
541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 386 times.
386 if (ret < 0)
542 goto fail;
543
544 386 ff_hevc_pred_init(&s->hpc, sps->bit_depth);
545 386 ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
546 386 ff_videodsp_init (&s->vdsp, sps->bit_depth);
547
548
2/2
✓ Branch 0 taken 1158 times.
✓ Branch 1 taken 386 times.
1544 for (i = 0; i < 3; i++) {
549 1158 av_freep(&s->sao_pixel_buffer_h[i]);
550 1158 av_freep(&s->sao_pixel_buffer_v[i]);
551 }
552
553
3/4
✓ Branch 0 taken 331 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 331 times.
✗ Branch 3 not taken.
386 if (sps->sao_enabled && !s->avctx->hwaccel) {
554
2/2
✓ Branch 0 taken 329 times.
✓ Branch 1 taken 2 times.
331 int c_count = (sps->chroma_format_idc != 0) ? 3 : 1;
555 int c_idx;
556
557
2/2
✓ Branch 0 taken 989 times.
✓ Branch 1 taken 331 times.
1320 for(c_idx = 0; c_idx < c_count; c_idx++) {
558 989 int w = sps->width >> sps->hshift[c_idx];
559 989 int h = sps->height >> sps->vshift[c_idx];
560 989 s->sao_pixel_buffer_h[c_idx] =
561 989 av_malloc((w * 2 * sps->ctb_height) <<
562 989 sps->pixel_shift);
563 989 s->sao_pixel_buffer_v[c_idx] =
564 989 av_malloc((h * 2 * sps->ctb_width) <<
565 989 sps->pixel_shift);
566
1/2
✓ Branch 0 taken 989 times.
✗ Branch 1 not taken.
989 if (!s->sao_pixel_buffer_h[c_idx] ||
567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 989 times.
989 !s->sao_pixel_buffer_v[c_idx])
568 goto fail;
569 }
570 }
571
572 386 s->ps.sps = sps;
573 386 s->ps.vps = sps->vps;
574
575 386 return 0;
576
577 fail:
578 pic_arrays_free(s);
579 for (i = 0; i < 3; i++) {
580 av_freep(&s->sao_pixel_buffer_h[i]);
581 av_freep(&s->sao_pixel_buffer_v[i]);
582 }
583 s->ps.sps = NULL;
584 return ret;
585 }
586
587 27617 static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb)
588 {
589 const HEVCPPS *pps;
590 const HEVCSPS *sps;
591 unsigned pps_id;
592 int i, ret;
593
594 // Coded parameters
595 27617 sh->first_slice_in_pic_flag = get_bits1(gb);
596
597 27617 sh->no_output_of_prior_pics_flag = 0;
598
3/4
✓ Branch 0 taken 1283 times.
✓ Branch 1 taken 26334 times.
✓ Branch 2 taken 1283 times.
✗ Branch 3 not taken.
27617 if (IS_IRAP(s))
599 1283 sh->no_output_of_prior_pics_flag = get_bits1(gb);
600
601 27617 pps_id = get_ue_golomb_long(gb);
602
2/4
✓ Branch 0 taken 27617 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27617 times.
27617 if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) {
603 av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
604 return AVERROR_INVALIDDATA;
605 }
606
3/4
✓ Branch 0 taken 18034 times.
✓ Branch 1 taken 9583 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18034 times.
27617 if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) {
607 av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
608 return AVERROR_INVALIDDATA;
609 }
610 27617 sh->pps_id = pps_id;
611
612 27617 pps = s->ps.pps_list[pps_id];
613 27617 sps = pps->sps;
614
615
4/4
✓ Branch 0 taken 344 times.
✓ Branch 1 taken 27273 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 330 times.
27617 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
616 14 sh->no_output_of_prior_pics_flag = 1;
617
618 27617 sh->dependent_slice_segment_flag = 0;
619
2/2
✓ Branch 0 taken 18034 times.
✓ Branch 1 taken 9583 times.
27617 if (!sh->first_slice_in_pic_flag) {
620 int slice_address_length;
621
622
2/2
✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8942 times.
18034 if (pps->dependent_slice_segments_enabled_flag)
623 9092 sh->dependent_slice_segment_flag = get_bits1(gb);
624
625 18034 slice_address_length = av_ceil_log2(sps->ctb_width *
626 18034 sps->ctb_height);
627 18034 sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18034 times.
18034 if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
629 av_log(s->avctx, AV_LOG_ERROR,
630 "Invalid slice segment address: %u.\n",
631 sh->slice_segment_addr);
632 return AVERROR_INVALIDDATA;
633 }
634
635
2/2
✓ Branch 0 taken 10087 times.
✓ Branch 1 taken 7947 times.
18034 if (!sh->dependent_slice_segment_flag) {
636 10087 sh->slice_addr = sh->slice_segment_addr;
637 }
638 } else {
639 9583 sh->slice_segment_addr = sh->slice_addr = 0;
640 }
641
642
2/2
✓ Branch 0 taken 19670 times.
✓ Branch 1 taken 7947 times.
27617 if (!sh->dependent_slice_segment_flag) {
643
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 19670 times.
19674 for (i = 0; i < pps->num_extra_slice_header_bits; i++)
644 4 skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
645
646 19670 sh->slice_type = get_ue_golomb_long(gb);
647
2/2
✓ Branch 0 taken 18525 times.
✓ Branch 1 taken 1145 times.
19670 if (!(sh->slice_type == HEVC_SLICE_I ||
648
2/2
✓ Branch 0 taken 14772 times.
✓ Branch 1 taken 3753 times.
18525 sh->slice_type == HEVC_SLICE_P ||
649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14772 times.
14772 sh->slice_type == HEVC_SLICE_B)) {
650 av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",
651 sh->slice_type);
652 return AVERROR_INVALIDDATA;
653 }
654
4/6
✓ Branch 0 taken 894 times.
✓ Branch 1 taken 18776 times.
✓ Branch 2 taken 894 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 894 times.
19670 if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
655 !pps->pps_curr_pic_ref_enabled_flag) {
656 av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
657 return AVERROR_INVALIDDATA;
658 }
659
660 // when flag is not present, picture is inferred to be output
661 19670 sh->pic_output_flag = 1;
662
2/2
✓ Branch 0 taken 703 times.
✓ Branch 1 taken 18967 times.
19670 if (pps->output_flag_present_flag)
663 703 sh->pic_output_flag = get_bits1(gb);
664
665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19670 times.
19670 if (sps->separate_colour_plane)
666 sh->colour_plane_id = get_bits(gb, 2);
667
668
4/4
✓ Branch 0 taken 19085 times.
✓ Branch 1 taken 585 times.
✓ Branch 2 taken 19069 times.
✓ Branch 3 taken 16 times.
38739 if (!IS_IDR(s)) {
669 int poc, pos;
670
671 19069 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
672 19069 poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
673
3/4
✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9201 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
19069 if (!sh->first_slice_in_pic_flag && poc != sh->poc) {
674 av_log(s->avctx, AV_LOG_WARNING,
675 "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc);
676 if (s->avctx->err_recognition & AV_EF_EXPLODE)
677 return AVERROR_INVALIDDATA;
678 poc = sh->poc;
679 }
680 19069 sh->poc = poc;
681
682 19069 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
683 19069 pos = get_bits_left(gb);
684
2/2
✓ Branch 0 taken 3255 times.
✓ Branch 1 taken 15814 times.
19069 if (!sh->short_term_ref_pic_set_sps_flag) {
685 3255 ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1);
686
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3255 times.
3255 if (ret < 0)
687 return ret;
688
689 3255 sh->short_term_rps = &sh->slice_rps;
690 } else {
691 int numbits, rps_idx;
692
693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15814 times.
15814 if (!sps->nb_st_rps) {
694 av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
695 return AVERROR_INVALIDDATA;
696 }
697
698 15814 numbits = av_ceil_log2(sps->nb_st_rps);
699
2/2
✓ Branch 0 taken 15786 times.
✓ Branch 1 taken 28 times.
15814 rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
700 15814 sh->short_term_rps = &sps->st_rps[rps_idx];
701 }
702 19069 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
703
704 19069 pos = get_bits_left(gb);
705 19069 ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb);
706
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19069 times.
19069 if (ret < 0) {
707 av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
708 if (s->avctx->err_recognition & AV_EF_EXPLODE)
709 return AVERROR_INVALIDDATA;
710 }
711 19069 sh->long_term_ref_pic_set_size = pos - get_bits_left(gb);
712
713
2/2
✓ Branch 0 taken 16638 times.
✓ Branch 1 taken 2431 times.
19069 if (sps->temporal_mvp_enabled)
714 16638 sh->slice_temporal_mvp_enabled_flag = get_bits1(gb);
715 else
716 2431 sh->slice_temporal_mvp_enabled_flag = 0;
717 } else {
718 601 sh->poc = 0;
719 601 sh->pic_order_cnt_lsb = 0;
720 601 sh->short_term_ref_pic_set_sps_flag = 0;
721 601 sh->short_term_ref_pic_set_size = 0;
722 601 sh->short_term_rps = NULL;
723 601 sh->long_term_ref_pic_set_size = 0;
724 601 sh->slice_temporal_mvp_enabled_flag = 0;
725 }
726
727
2/2
✓ Branch 0 taken 16157 times.
✓ Branch 1 taken 3513 times.
19670 if (sps->sao_enabled) {
728 16157 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
729
2/2
✓ Branch 0 taken 16155 times.
✓ Branch 1 taken 2 times.
16157 if (sps->chroma_format_idc) {
730 16155 sh->slice_sample_adaptive_offset_flag[1] =
731 16155 sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb);
732 }
733 } else {
734 3513 sh->slice_sample_adaptive_offset_flag[0] = 0;
735 3513 sh->slice_sample_adaptive_offset_flag[1] = 0;
736 3513 sh->slice_sample_adaptive_offset_flag[2] = 0;
737 }
738
739 19670 sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
740
4/4
✓ Branch 0 taken 15917 times.
✓ Branch 1 taken 3753 times.
✓ Branch 2 taken 14772 times.
✓ Branch 3 taken 1145 times.
19670 if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
741 int nb_refs;
742
743 18525 sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active;
744
2/2
✓ Branch 0 taken 14772 times.
✓ Branch 1 taken 3753 times.
18525 if (sh->slice_type == HEVC_SLICE_B)
745 14772 sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active;
746
747
2/2
✓ Branch 1 taken 4877 times.
✓ Branch 2 taken 13648 times.
18525 if (get_bits1(gb)) { // num_ref_idx_active_override_flag
748 4877 sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1;
749
2/2
✓ Branch 0 taken 2711 times.
✓ Branch 1 taken 2166 times.
4877 if (sh->slice_type == HEVC_SLICE_B)
750 2711 sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1;
751 }
752
2/4
✓ Branch 0 taken 18525 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18525 times.
18525 if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) {
753 av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n",
754 sh->nb_refs[L0], sh->nb_refs[L1]);
755 return AVERROR_INVALIDDATA;
756 }
757
758 18525 sh->rpl_modification_flag[0] = 0;
759 18525 sh->rpl_modification_flag[1] = 0;
760 18525 nb_refs = ff_hevc_frame_nb_refs(sh, pps);
761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18525 times.
18525 if (!nb_refs) {
762 av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
763 return AVERROR_INVALIDDATA;
764 }
765
766
4/4
✓ Branch 0 taken 1653 times.
✓ Branch 1 taken 16872 times.
✓ Branch 2 taken 1596 times.
✓ Branch 3 taken 57 times.
18525 if (pps->lists_modification_present_flag && nb_refs > 1) {
767 1596 sh->rpl_modification_flag[0] = get_bits1(gb);
768
2/2
✓ Branch 0 taken 1176 times.
✓ Branch 1 taken 420 times.
1596 if (sh->rpl_modification_flag[0]) {
769
2/2
✓ Branch 0 taken 2779 times.
✓ Branch 1 taken 1176 times.
3955 for (i = 0; i < sh->nb_refs[L0]; i++)
770 2779 sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs));
771 }
772
773
1/2
✓ Branch 0 taken 1596 times.
✗ Branch 1 not taken.
1596 if (sh->slice_type == HEVC_SLICE_B) {
774 1596 sh->rpl_modification_flag[1] = get_bits1(gb);
775
2/2
✓ Branch 0 taken 652 times.
✓ Branch 1 taken 944 times.
1596 if (sh->rpl_modification_flag[1] == 1)
776
2/2
✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
2207 for (i = 0; i < sh->nb_refs[L1]; i++)
777 1555 sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs));
778 }
779 }
780
781
2/2
✓ Branch 0 taken 14772 times.
✓ Branch 1 taken 3753 times.
18525 if (sh->slice_type == HEVC_SLICE_B)
782 14772 sh->mvd_l1_zero_flag = get_bits1(gb);
783
784
2/2
✓ Branch 0 taken 15796 times.
✓ Branch 1 taken 2729 times.
18525 if (pps->cabac_init_present_flag)
785 15796 sh->cabac_init_flag = get_bits1(gb);
786 else
787 2729 sh->cabac_init_flag = 0;
788
789 18525 sh->collocated_ref_idx = 0;
790
2/2
✓ Branch 0 taken 16168 times.
✓ Branch 1 taken 2357 times.
18525 if (sh->slice_temporal_mvp_enabled_flag) {
791 16168 sh->collocated_list = L0;
792
2/2
✓ Branch 0 taken 14255 times.
✓ Branch 1 taken 1913 times.
16168 if (sh->slice_type == HEVC_SLICE_B)
793 14255 sh->collocated_list = !get_bits1(gb);
794
795
2/2
✓ Branch 0 taken 14404 times.
✓ Branch 1 taken 1764 times.
16168 if (sh->nb_refs[sh->collocated_list] > 1) {
796 14404 sh->collocated_ref_idx = get_ue_golomb_long(gb);
797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14404 times.
14404 if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) {
798 av_log(s->avctx, AV_LOG_ERROR,
799 "Invalid collocated_ref_idx: %d.\n",
800 sh->collocated_ref_idx);
801 return AVERROR_INVALIDDATA;
802 }
803 }
804 }
805
806
4/4
✓ Branch 0 taken 1468 times.
✓ Branch 1 taken 17057 times.
✓ Branch 2 taken 693 times.
✓ Branch 3 taken 775 times.
18525 if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
807
3/4
✓ Branch 0 taken 668 times.
✓ Branch 1 taken 17082 times.
✓ Branch 2 taken 668 times.
✗ Branch 3 not taken.
17750 (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
808 1443 int ret = pred_weight_table(sh, s->avctx, sps, gb);
809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1443 times.
1443 if (ret < 0)
810 return ret;
811 }
812
813 18525 sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
814
2/4
✓ Branch 0 taken 18525 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18525 times.
18525 if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
815 av_log(s->avctx, AV_LOG_ERROR,
816 "Invalid number of merging MVP candidates: %d.\n",
817 sh->max_num_merge_cand);
818 return AVERROR_INVALIDDATA;
819 }
820
821 // Syntax in 7.3.6.1
822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18525 times.
18525 if (sps->motion_vector_resolution_control_idc == 2)
823 sh->use_integer_mv_flag = get_bits1(gb);
824 else
825 // Inferred to be equal to motion_vector_resolution_control_idc if not present
826 18525 sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc;
827
828 }
829
830 19670 sh->slice_qp_delta = get_se_golomb(gb);
831
832
2/2
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 19399 times.
19670 if (pps->pic_slice_level_chroma_qp_offsets_present_flag) {
833 271 sh->slice_cb_qp_offset = get_se_golomb(gb);
834 271 sh->slice_cr_qp_offset = get_se_golomb(gb);
835
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 ||
836
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) {
837 av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n");
838 return AVERROR_INVALIDDATA;
839 }
840 } else {
841 19399 sh->slice_cb_qp_offset = 0;
842 19399 sh->slice_cr_qp_offset = 0;
843 }
844
845
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19670 times.
19670 if (pps->pps_slice_act_qp_offsets_present_flag) {
846 sh->slice_act_y_qp_offset = get_se_golomb(gb);
847 sh->slice_act_cb_qp_offset = get_se_golomb(gb);
848 sh->slice_act_cr_qp_offset = get_se_golomb(gb);
849 }
850
851
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 19627 times.
19670 if (pps->chroma_qp_offset_list_enabled_flag)
852 43 sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
853 else
854 19627 sh->cu_chroma_qp_offset_enabled_flag = 0;
855
856
2/2
✓ Branch 0 taken 2922 times.
✓ Branch 1 taken 16748 times.
19670 if (pps->deblocking_filter_control_present_flag) {
857 2922 int deblocking_filter_override_flag = 0;
858
859
2/2
✓ Branch 0 taken 696 times.
✓ Branch 1 taken 2226 times.
2922 if (pps->deblocking_filter_override_enabled_flag)
860 696 deblocking_filter_override_flag = get_bits1(gb);
861
862
2/2
✓ Branch 0 taken 477 times.
✓ Branch 1 taken 2445 times.
2922 if (deblocking_filter_override_flag) {
863 477 sh->disable_deblocking_filter_flag = get_bits1(gb);
864
2/2
✓ Branch 0 taken 357 times.
✓ Branch 1 taken 120 times.
477 if (!sh->disable_deblocking_filter_flag) {
865 357 int beta_offset_div2 = get_se_golomb(gb);
866 357 int tc_offset_div2 = get_se_golomb(gb) ;
867
3/6
✓ Branch 0 taken 357 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 357 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 357 times.
✗ Branch 5 not taken.
357 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
868
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 357 times.
357 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
869 av_log(s->avctx, AV_LOG_ERROR,
870 "Invalid deblock filter offsets: %d, %d\n",
871 beta_offset_div2, tc_offset_div2);
872 return AVERROR_INVALIDDATA;
873 }
874 357 sh->beta_offset = beta_offset_div2 * 2;
875 357 sh->tc_offset = tc_offset_div2 * 2;
876 }
877 } else {
878 2445 sh->disable_deblocking_filter_flag = pps->disable_dbf;
879 2445 sh->beta_offset = pps->beta_offset;
880 2445 sh->tc_offset = pps->tc_offset;
881 }
882 } else {
883 16748 sh->disable_deblocking_filter_flag = 0;
884 16748 sh->beta_offset = 0;
885 16748 sh->tc_offset = 0;
886 }
887
888
2/2
✓ Branch 0 taken 17135 times.
✓ Branch 1 taken 2535 times.
19670 if (pps->seq_loop_filter_across_slices_enabled_flag &&
889
2/2
✓ Branch 0 taken 11467 times.
✓ Branch 1 taken 5668 times.
17135 (sh->slice_sample_adaptive_offset_flag[0] ||
890
2/2
✓ Branch 0 taken 11449 times.
✓ Branch 1 taken 18 times.
11467 sh->slice_sample_adaptive_offset_flag[1] ||
891
2/2
✓ Branch 0 taken 11386 times.
✓ Branch 1 taken 63 times.
11449 !sh->disable_deblocking_filter_flag)) {
892 17072 sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb);
893 } else {
894 2598 sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag;
895 }
896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
7947 } else if (!s->slice_initialized) {
897 av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
898 return AVERROR_INVALIDDATA;
899 }
900
901 27617 sh->num_entry_point_offsets = 0;
902
4/4
✓ Branch 0 taken 24710 times.
✓ Branch 1 taken 2907 times.
✓ Branch 2 taken 4604 times.
✓ Branch 3 taken 20106 times.
27617 if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
903 7511 unsigned num_entry_point_offsets = get_ue_golomb_long(gb);
904 // It would be possible to bound this tighter but this here is simpler
905
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7511 times.
7511 if (num_entry_point_offsets > get_bits_left(gb)) {
906 av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
907 return AVERROR_INVALIDDATA;
908 }
909
910 7511 sh->num_entry_point_offsets = num_entry_point_offsets;
911
2/2
✓ Branch 0 taken 2041 times.
✓ Branch 1 taken 5470 times.
7511 if (sh->num_entry_point_offsets > 0) {
912 2041 int offset_len = get_ue_golomb_long(gb) + 1;
913
914
2/4
✓ Branch 0 taken 2041 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2041 times.
2041 if (offset_len < 1 || offset_len > 32) {
915 sh->num_entry_point_offsets = 0;
916 av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len);
917 return AVERROR_INVALIDDATA;
918 }
919
920 2041 av_freep(&sh->entry_point_offset);
921 2041 av_freep(&sh->offset);
922 2041 av_freep(&sh->size);
923 2041 sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
924 2041 sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
925 2041 sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
926
3/6
✓ Branch 0 taken 2041 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2041 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2041 times.
2041 if (!sh->entry_point_offset || !sh->offset || !sh->size) {
927 sh->num_entry_point_offsets = 0;
928 av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
929 return AVERROR(ENOMEM);
930 }
931
2/2
✓ Branch 0 taken 8040 times.
✓ Branch 1 taken 2041 times.
10081 for (i = 0; i < sh->num_entry_point_offsets; i++) {
932 8040 unsigned val = get_bits_long(gb, offset_len);
933 8040 sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
934 }
935 }
936 }
937
938
2/2
✓ Branch 0 taken 2769 times.
✓ Branch 1 taken 24848 times.
27617 if (pps->slice_header_extension_present_flag) {
939 2769 unsigned int length = get_ue_golomb_long(gb);
940
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2769 times.
2769 if (length*8LL > get_bits_left(gb)) {
941 av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n");
942 return AVERROR_INVALIDDATA;
943 }
944
2/2
✓ Branch 0 taken 20292 times.
✓ Branch 1 taken 2769 times.
23061 for (i = 0; i < length; i++)
945 20292 skip_bits(gb, 8); // slice_header_extension_data_byte
946 }
947
948 27617 ret = get_bits1(gb);
949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27617 times.
27617 if (!ret) {
950 av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n");
951 return AVERROR_INVALIDDATA;
952 }
953 27617 sh->data_offset = align_get_bits(gb) - gb->buffer;
954
955 // Inferred parameters
956 27617 sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta;
957
1/2
✓ Branch 0 taken 27617 times.
✗ Branch 1 not taken.
27617 if (sh->slice_qp > 51 ||
958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27617 times.
27617 sh->slice_qp < -sps->qp_bd_offset) {
959 av_log(s->avctx, AV_LOG_ERROR,
960 "The slice_qp %d is outside the valid range "
961 "[%d, 51].\n",
962 sh->slice_qp,
963 -sps->qp_bd_offset);
964 return AVERROR_INVALIDDATA;
965 }
966
967 27617 sh->slice_ctb_addr_rs = sh->slice_segment_addr;
968
969
2/2
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 19670 times.
27617 if (sh->dependent_slice_segment_flag &&
970
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])) {
971 av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
972 return AVERROR_INVALIDDATA;
973 }
974
975
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27617 times.
27617 if (get_bits_left(gb) < 0) {
976 av_log(s->avctx, AV_LOG_ERROR,
977 "Overread slice header by %d bits\n", -get_bits_left(gb));
978 return AVERROR_INVALIDDATA;
979 }
980
981 27617 return 0;
982 }
983
984 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
985
986 #define SET_SAO(elem, value) \
987 do { \
988 if (!sao_merge_up_flag && !sao_merge_left_flag) \
989 sao->elem = value; \
990 else if (sao_merge_left_flag) \
991 sao->elem = CTB(s->sao, rx-1, ry).elem; \
992 else if (sao_merge_up_flag) \
993 sao->elem = CTB(s->sao, rx, ry-1).elem; \
994 else \
995 sao->elem = 0; \
996 } while (0)
997
998 1416754 static void hls_sao_param(HEVCLocalContext *lc,
999 const HEVCPPS *pps, const HEVCSPS *sps,
1000 int rx, int ry)
1001 {
1002 1416754 const HEVCContext *const s = lc->parent;
1003 1416754 int sao_merge_left_flag = 0;
1004 1416754 int sao_merge_up_flag = 0;
1005 1416754 SAOParams *sao = &CTB(s->sao, rx, ry);
1006 int c_idx, i;
1007
1008
2/2
✓ Branch 0 taken 816170 times.
✓ Branch 1 taken 600584 times.
1416754 if (s->sh.slice_sample_adaptive_offset_flag[0] ||
1009
2/2
✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 814526 times.
816170 s->sh.slice_sample_adaptive_offset_flag[1]) {
1010
2/2
✓ Branch 0 taken 571103 times.
✓ Branch 1 taken 31125 times.
602228 if (rx > 0) {
1011
2/2
✓ Branch 0 taken 562614 times.
✓ Branch 1 taken 8489 times.
571103 if (lc->ctb_left_flag)
1012 562614 sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc);
1013 }
1014
4/4
✓ Branch 0 taken 551498 times.
✓ Branch 1 taken 50730 times.
✓ Branch 2 taken 271724 times.
✓ Branch 3 taken 279774 times.
602228 if (ry > 0 && !sao_merge_left_flag) {
1015
2/2
✓ Branch 0 taken 258355 times.
✓ Branch 1 taken 13369 times.
271724 if (lc->ctb_up_flag)
1016 258355 sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc);
1017 }
1018 }
1019
1020
4/4
✓ Branch 0 taken 5666824 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4250166 times.
✓ Branch 3 taken 1416754 times.
5666920 for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) {
1021
2/2
✓ Branch 0 taken 1416754 times.
✓ Branch 1 taken 2833412 times.
4250166 int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma :
1022 2833412 pps->log2_sao_offset_scale_chroma;
1023
1024
2/2
✓ Branch 0 taken 2945486 times.
✓ Branch 1 taken 1304680 times.
4250166 if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1025 2945486 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
1026 2945486 continue;
1027 }
1028
1029
2/2
✓ Branch 0 taken 352048 times.
✓ Branch 1 taken 952632 times.
1304680 if (c_idx == 2) {
1030 352048 sao->type_idx[2] = sao->type_idx[1];
1031 352048 sao->eo_class[2] = sao->eo_class[1];
1032 } else {
1033
7/8
✓ Branch 0 taken 828413 times.
✓ Branch 1 taken 124219 times.
✓ Branch 2 taken 378861 times.
✓ Branch 3 taken 449552 times.
✓ Branch 5 taken 449552 times.
✓ Branch 6 taken 124219 times.
✓ Branch 7 taken 124219 times.
✗ Branch 8 not taken.
952632 SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc));
1034 }
1035
1036
2/2
✓ Branch 0 taken 806073 times.
✓ Branch 1 taken 498607 times.
1304680 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
1037 806073 continue;
1038
1039
2/2
✓ Branch 0 taken 1994428 times.
✓ Branch 1 taken 498607 times.
2493035 for (i = 0; i < 4; i++)
1040
7/8
✓ Branch 0 taken 1645912 times.
✓ Branch 1 taken 348516 times.
✓ Branch 2 taken 871500 times.
✓ Branch 3 taken 774412 times.
✓ Branch 5 taken 774412 times.
✓ Branch 6 taken 348516 times.
✓ Branch 7 taken 348516 times.
✗ Branch 8 not taken.
1994428 SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth));
1041
1042
2/2
✓ Branch 0 taken 116810 times.
✓ Branch 1 taken 381797 times.
498607 if (sao->type_idx[c_idx] == SAO_BAND) {
1043
2/2
✓ Branch 0 taken 467240 times.
✓ Branch 1 taken 116810 times.
584050 for (i = 0; i < 4; i++) {
1044
2/2
✓ Branch 0 taken 351904 times.
✓ Branch 1 taken 115336 times.
467240 if (sao->offset_abs[c_idx][i]) {
1045
7/8
✓ Branch 0 taken 327850 times.
✓ Branch 1 taken 24054 times.
✓ Branch 2 taken 243189 times.
✓ Branch 3 taken 84661 times.
✓ Branch 5 taken 84661 times.
✓ Branch 6 taken 24054 times.
✓ Branch 7 taken 24054 times.
✗ Branch 8 not taken.
351904 SET_SAO(offset_sign[c_idx][i],
1046 ff_hevc_sao_offset_sign_decode(lc));
1047 } else {
1048 115336 sao->offset_sign[c_idx][i] = 0;
1049 }
1050 }
1051
7/8
✓ Branch 0 taken 107120 times.
✓ Branch 1 taken 9690 times.
✓ Branch 2 taken 77975 times.
✓ Branch 3 taken 29145 times.
✓ Branch 5 taken 29145 times.
✓ Branch 6 taken 9690 times.
✓ Branch 7 taken 9690 times.
✗ Branch 8 not taken.
116810 SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc));
1052
2/2
✓ Branch 0 taken 305331 times.
✓ Branch 1 taken 76466 times.
381797 } else if (c_idx != 2) {
1053
7/8
✓ Branch 0 taken 243309 times.
✓ Branch 1 taken 62022 times.
✓ Branch 2 taken 108883 times.
✓ Branch 3 taken 134426 times.
✓ Branch 5 taken 134426 times.
✓ Branch 6 taken 62022 times.
✓ Branch 7 taken 62022 times.
✗ Branch 8 not taken.
305331 SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc));
1054 }
1055
1056 // Inferred parameters
1057 498607 sao->offset_val[c_idx][0] = 0;
1058
2/2
✓ Branch 0 taken 1994428 times.
✓ Branch 1 taken 498607 times.
2493035 for (i = 0; i < 4; i++) {
1059 1994428 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
1060
2/2
✓ Branch 0 taken 1527188 times.
✓ Branch 1 taken 467240 times.
1994428 if (sao->type_idx[c_idx] == SAO_EDGE) {
1061
2/2
✓ Branch 0 taken 763594 times.
✓ Branch 1 taken 763594 times.
1527188 if (i > 1)
1062 763594 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1063
2/2
✓ Branch 0 taken 155063 times.
✓ Branch 1 taken 312177 times.
467240 } else if (sao->offset_sign[c_idx][i]) {
1064 155063 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1065 }
1066 1994428 sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale;
1067 }
1068 }
1069 1416754 }
1070
1071 #undef SET_SAO
1072 #undef CTB
1073
1074 384850 static int hls_cross_component_pred(HEVCLocalContext *lc, int idx)
1075 {
1076 384850 int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx);
1077
1078
2/2
✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
384850 if (log2_res_scale_abs_plus1 != 0) {
1079 235843 int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx);
1080 235843 lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) *
1081 235843 (1 - 2 * res_scale_sign_flag);
1082 } else {
1083 149007 lc->tu.res_scale_val = 0;
1084 }
1085
1086
1087 384850 return 0;
1088 }
1089
1090 15298000 static int hls_transform_unit(HEVCLocalContext *lc,
1091 const HEVCPPS *pps, const HEVCSPS *sps,
1092 int x0, int y0,
1093 int xBase, int yBase, int cb_xBase, int cb_yBase,
1094 int log2_cb_size, int log2_trafo_size,
1095 int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
1096 {
1097 15298000 const HEVCContext *const s = lc->parent;
1098 15298000 const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1];
1099 int i;
1100
1101
2/2
✓ Branch 0 taken 9692268 times.
✓ Branch 1 taken 5605732 times.
15298000 if (lc->cu.pred_mode == MODE_INTRA) {
1102 9692268 int trafo_size = 1 << log2_trafo_size;
1103 9692268 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size);
1104
1105 9692268 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0);
1106 }
1107
1108
6/6
✓ Branch 0 taken 5595180 times.
✓ Branch 1 taken 9702820 times.
✓ Branch 2 taken 4967417 times.
✓ Branch 3 taken 627763 times.
✓ Branch 4 taken 4549170 times.
✓ Branch 5 taken 418247 times.
15298000 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1109
6/6
✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4393403 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
15359814 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1110 10810645 int scan_idx = SCAN_DIAG;
1111 10810645 int scan_idx_c = SCAN_DIAG;
1112
4/4
✓ Branch 0 taken 7230564 times.
✓ Branch 1 taken 3580081 times.
✓ Branch 2 taken 5786727 times.
✓ Branch 3 taken 1443837 times.
16597372 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1113
2/2
✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 5555017 times.
5786727 (sps->chroma_format_idc == 2 &&
1114
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]));
1115
1116
4/4
✓ Branch 0 taken 2147874 times.
✓ Branch 1 taken 8662771 times.
✓ Branch 2 taken 610611 times.
✓ Branch 3 taken 1537263 times.
10810645 if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
1117 610611 lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc);
1118
2/2
✓ Branch 0 taken 370940 times.
✓ Branch 1 taken 239671 times.
610611 if (lc->tu.cu_qp_delta != 0)
1119
2/2
✓ Branch 1 taken 204969 times.
✓ Branch 2 taken 165971 times.
370940 if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1)
1120 204969 lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1121 610611 lc->tu.is_cu_qp_delta_coded = 1;
1122
1123
2/2
✓ Branch 0 taken 610610 times.
✓ Branch 1 taken 1 times.
610611 if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) ||
1124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 610610 times.
610610 lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) {
1125 1 av_log(s->avctx, AV_LOG_ERROR,
1126 "The cu_qp_delta %d is outside the valid range "
1127 "[%d, %d].\n",
1128 lc->tu.cu_qp_delta,
1129 1 -(26 + sps->qp_bd_offset / 2),
1130 1 (25 + sps->qp_bd_offset / 2));
1131 1 return AVERROR_INVALIDDATA;
1132 }
1133
1134 610610 ff_hevc_set_qPy(lc, pps, cb_xBase, cb_yBase, log2_cb_size);
1135 }
1136
1137
4/4
✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 9918693 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
10810644 if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1138
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) {
1139 266275 int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc);
1140
2/2
✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
266275 if (cu_chroma_qp_offset_flag) {
1141 48966 int cu_chroma_qp_offset_idx = 0;
1142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
48966 if (pps->chroma_qp_offset_list_len_minus1 > 0) {
1143 cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1);
1144 av_log(s->avctx, AV_LOG_ERROR,
1145 "cu_chroma_qp_offset_idx not yet tested.\n");
1146 }
1147 48966 lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
1148 48966 lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
1149 } else {
1150 217309 lc->tu.cu_qp_offset_cb = 0;
1151 217309 lc->tu.cu_qp_offset_cr = 0;
1152 }
1153 266275 lc->tu.is_cu_chroma_qp_offset_coded = 1;
1154 }
1155
1156
4/4
✓ Branch 0 taken 7135127 times.
✓ Branch 1 taken 3675517 times.
✓ Branch 2 taken 6259657 times.
✓ Branch 3 taken 875470 times.
10810644 if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1157
2/2
✓ Branch 0 taken 4172978 times.
✓ Branch 1 taken 2086679 times.
6259657 if (lc->tu.intra_pred_mode >= 6 &&
1158
2/2
✓ Branch 0 taken 1511262 times.
✓ Branch 1 taken 2661716 times.
4172978 lc->tu.intra_pred_mode <= 14) {
1159 1511262 scan_idx = SCAN_VERT;
1160
2/2
✓ Branch 0 taken 2052700 times.
✓ Branch 1 taken 2695695 times.
4748395 } else if (lc->tu.intra_pred_mode >= 22 &&
1161
2/2
✓ Branch 0 taken 1724499 times.
✓ Branch 1 taken 328201 times.
2052700 lc->tu.intra_pred_mode <= 30) {
1162 1724499 scan_idx = SCAN_HORIZ;
1163 }
1164
1165
2/2
✓ Branch 0 taken 3741433 times.
✓ Branch 1 taken 2518224 times.
6259657 if (lc->tu.intra_pred_mode_c >= 6 &&
1166
2/2
✓ Branch 0 taken 1421959 times.
✓ Branch 1 taken 2319474 times.
3741433 lc->tu.intra_pred_mode_c <= 14) {
1167 1421959 scan_idx_c = SCAN_VERT;
1168
2/2
✓ Branch 0 taken 1948395 times.
✓ Branch 1 taken 2889303 times.
4837698 } else if (lc->tu.intra_pred_mode_c >= 22 &&
1169
2/2
✓ Branch 0 taken 1630633 times.
✓ Branch 1 taken 317762 times.
1948395 lc->tu.intra_pred_mode_c <= 30) {
1170 1630633 scan_idx_c = SCAN_HORIZ;
1171 }
1172 }
1173
1174 10810644 lc->tu.cross_pf = 0;
1175
1176
2/2
✓ Branch 0 taken 9702819 times.
✓ Branch 1 taken 1107825 times.
10810644 if (cbf_luma)
1177 9702819 ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0);
1178
6/6
✓ Branch 0 taken 10810452 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6105417 times.
✓ Branch 3 taken 4705035 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 5895854 times.
15725242 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1179 4914598 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1180 4914598 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1181
4/4
✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 4577757 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
5132414 lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma &&
1182
2/2
✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
217816 (lc->cu.pred_mode == MODE_INTER ||
1183
2/2
✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
168873 (lc->tu.chroma_mode_c == 4)));
1184
1185
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4722173 times.
4914598 if (lc->tu.cross_pf) {
1186 192425 hls_cross_component_pred(lc, 0);
1187 }
1188
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8922792 times.
✓ Branch 2 taken 5367800 times.
✓ Branch 3 taken 4914598 times.
10282398 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1189
2/2
✓ Branch 0 taken 2982711 times.
✓ Branch 1 taken 2385089 times.
5367800 if (lc->cu.pred_mode == MODE_INTRA) {
1190 2982711 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1191 2982711 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1192 2982711 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1);
1193 }
1194
2/2
✓ Branch 0 taken 1493885 times.
✓ Branch 1 taken 3873915 times.
5367800 if (cbf_cb[i])
1195 1493885 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1196 log2_trafo_size_c, scan_idx_c, 1);
1197 else
1198
2/2
✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 3834257 times.
3873915 if (lc->tu.cross_pf) {
1199 39658 ptrdiff_t stride = s->cur_frame->f->linesize[1];
1200 39658 int hshift = sps->hshift[1];
1201 39658 int vshift = sps->vshift[1];
1202 39658 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1203 39658 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1204 39658 int size = 1 << log2_trafo_size_c;
1205
1206 39658 uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride +
1207 39658 ((x0 >> hshift) << sps->pixel_shift)];
1208
2/2
✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
1871162 for (i = 0; i < (size * size); i++) {
1209 1831504 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1210 }
1211 39658 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1212 }
1213 }
1214
1215
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4722173 times.
4914598 if (lc->tu.cross_pf) {
1216 192425 hls_cross_component_pred(lc, 1);
1217 }
1218
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8922792 times.
✓ Branch 2 taken 5367800 times.
✓ Branch 3 taken 4914598 times.
10282398 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1219
2/2
✓ Branch 0 taken 2982711 times.
✓ Branch 1 taken 2385089 times.
5367800 if (lc->cu.pred_mode == MODE_INTRA) {
1220 2982711 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1221 2982711 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1222 2982711 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2);
1223 }
1224
2/2
✓ Branch 0 taken 1607817 times.
✓ Branch 1 taken 3759983 times.
5367800 if (cbf_cr[i])
1225 1607817 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1226 log2_trafo_size_c, scan_idx_c, 2);
1227 else
1228
2/2
✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 3684059 times.
3759983 if (lc->tu.cross_pf) {
1229 75924 ptrdiff_t stride = s->cur_frame->f->linesize[2];
1230 75924 int hshift = sps->hshift[2];
1231 75924 int vshift = sps->vshift[2];
1232 75924 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1233 75924 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1234 75924 int size = 1 << log2_trafo_size_c;
1235
1236 75924 uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride +
1237 75924 ((x0 >> hshift) << sps->pixel_shift)];
1238
2/2
✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
3691476 for (i = 0; i < (size * size); i++) {
1239 3615552 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1240 }
1241 75924 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1242 }
1243 }
1244
4/4
✓ Branch 0 taken 5895854 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1514383 times.
✓ Branch 3 taken 4381471 times.
5896046 } else if (sps->chroma_format_idc && blk_idx == 3) {
1245 1514383 int trafo_size_h = 1 << (log2_trafo_size + 1);
1246 1514383 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1247
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2695028 times.
✓ Branch 2 taken 1681252 times.
✓ Branch 3 taken 1514383 times.
3195635 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1248
2/2
✓ Branch 0 taken 1200706 times.
✓ Branch 1 taken 480546 times.
1681252 if (lc->cu.pred_mode == MODE_INTRA) {
1249 1200706 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1250 1200706 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1251 1200706 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1);
1252 }
1253
2/2
✓ Branch 0 taken 636143 times.
✓ Branch 1 taken 1045109 times.
1681252 if (cbf_cb[i])
1254 636143 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1255 log2_trafo_size, scan_idx_c, 1);
1256 }
1257
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2695028 times.
✓ Branch 2 taken 1681252 times.
✓ Branch 3 taken 1514383 times.
3195635 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1258
2/2
✓ Branch 0 taken 1200706 times.
✓ Branch 1 taken 480546 times.
1681252 if (lc->cu.pred_mode == MODE_INTRA) {
1259 1200706 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1260 1200706 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1261 1200706 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2);
1262 }
1263
2/2
✓ Branch 0 taken 717416 times.
✓ Branch 1 taken 963836 times.
1681252 if (cbf_cr[i])
1264 717416 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1265 log2_trafo_size, scan_idx_c, 2);
1266 }
1267 }
1268
3/4
✓ Branch 0 taken 4487355 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2557140 times.
✓ Branch 3 taken 1930215 times.
4487355 } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
1269
4/4
✓ Branch 0 taken 1593070 times.
✓ Branch 1 taken 964070 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1532482 times.
3581798 if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) {
1270 1024658 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1271 1024658 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1272 1024658 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
1273 1024658 sps->log2_ctb_size);
1274 1024658 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1);
1275 1024658 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2);
1276
2/2
✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 1012191 times.
1024658 if (sps->chroma_format_idc == 2) {
1277 12467 ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c),
1278 12467 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1279 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1);
1280 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2);
1281 }
1282
2/2
✓ Branch 0 taken 348066 times.
✓ Branch 1 taken 1184416 times.
1532482 } else if (blk_idx == 3) {
1283 348066 int trafo_size_h = 1 << (log2_trafo_size + 1);
1284 348066 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1285 348066 ff_hevc_set_neighbour_available(lc, xBase, yBase,
1286 348066 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1287 348066 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1);
1288 348066 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2);
1289
2/2
✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 343870 times.
348066 if (sps->chroma_format_idc == 2) {
1290 4196 ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size),
1291 4196 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1292 4196 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1);
1293 4196 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2);
1294 }
1295 }
1296 }
1297
1298 15297999 return 0;
1299 }
1300
1301 356478 static void set_deblocking_bypass(const HEVCContext *s, const HEVCSPS *sps,
1302 int x0, int y0, int log2_cb_size)
1303 {
1304 356478 int cb_size = 1 << log2_cb_size;
1305 356478 int log2_min_pu_size = sps->log2_min_pu_size;
1306
1307 356478 int min_pu_width = sps->min_pu_width;
1308 356478 int x_end = FFMIN(x0 + cb_size, sps->width);
1309 356478 int y_end = FFMIN(y0 + cb_size, sps->height);
1310 int i, j;
1311
1312
2/2
✓ Branch 0 taken 494908 times.
✓ Branch 1 taken 356478 times.
851386 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1313
2/2
✓ Branch 0 taken 949056 times.
✓ Branch 1 taken 494908 times.
1443964 for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
1314 949056 s->is_pcm[i + j * min_pu_width] = 2;
1315 356478 }
1316
1317 18472604 static int hls_transform_tree(HEVCLocalContext *lc,
1318 const HEVCPPS *pps, const HEVCSPS *sps,
1319 int x0, int y0,
1320 int xBase, int yBase, int cb_xBase, int cb_yBase,
1321 int log2_cb_size, int log2_trafo_size,
1322 int trafo_depth, int blk_idx,
1323 const int *base_cbf_cb, const int *base_cbf_cr)
1324 {
1325 18472604 const HEVCContext *const s = lc->parent;
1326 uint8_t split_transform_flag;
1327 int cbf_cb[2];
1328 int cbf_cr[2];
1329 int ret;
1330
1331 18472604 cbf_cb[0] = base_cbf_cb[0];
1332 18472604 cbf_cb[1] = base_cbf_cb[1];
1333 18472604 cbf_cr[0] = base_cbf_cr[0];
1334 18472604 cbf_cr[1] = base_cbf_cr[1];
1335
1336
2/2
✓ Branch 0 taken 6358411 times.
✓ Branch 1 taken 12114193 times.
18472604 if (lc->cu.intra_split_flag) {
1337
2/2
✓ Branch 0 taken 4784668 times.
✓ Branch 1 taken 1573743 times.
6358411 if (trafo_depth == 1) {
1338 4784668 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1339
2/2
✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4649264 times.
4784668 if (sps->chroma_format_idc == 3) {
1340 135404 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx];
1341 135404 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx];
1342 } else {
1343 4649264 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1344 4649264 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1345 }
1346 }
1347 } else {
1348 12114193 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0];
1349 12114193 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1350 12114193 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1351 }
1352
1353
2/2
✓ Branch 0 taken 18363798 times.
✓ Branch 1 taken 108806 times.
18472604 if (log2_trafo_size <= sps->log2_max_trafo_size &&
1354
2/2
✓ Branch 0 taken 9606754 times.
✓ Branch 1 taken 8757044 times.
18363798 log2_trafo_size > sps->log2_min_tb_size &&
1355
2/2
✓ Branch 0 taken 8046513 times.
✓ Branch 1 taken 1560241 times.
9606754 trafo_depth < lc->cu.max_trafo_depth &&
1356
4/4
✓ Branch 0 taken 1679392 times.
✓ Branch 1 taken 6367121 times.
✓ Branch 2 taken 490612 times.
✓ Branch 3 taken 1188780 times.
8046513 !(lc->cu.intra_split_flag && trafo_depth == 0)) {
1357 6857733 split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size);
1358 } else {
1359 24857407 int inter_split = sps->max_transform_hierarchy_depth_inter == 0 &&
1360
2/2
✓ Branch 0 taken 836848 times.
✓ Branch 1 taken 790817 times.
1627665 lc->cu.pred_mode == MODE_INTER &&
1361
6/6
✓ Branch 0 taken 1627665 times.
✓ Branch 1 taken 9987206 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 161299 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
13242536 lc->cu.part_mode != PART_2Nx2N &&
1362 trafo_depth == 0;
1363
1364 11614871 split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size ||
1365
8/8
✓ Branch 0 taken 11506065 times.
✓ Branch 1 taken 108806 times.
✓ Branch 2 taken 5859752 times.
✓ Branch 3 taken 5646313 times.
✓ Branch 4 taken 4670972 times.
✓ Branch 5 taken 1188780 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10198647 times.
11614871 (lc->cu.intra_split_flag && trafo_depth == 0) ||
1366 inter_split;
1367 }
1368
1369
6/6
✓ Branch 0 taken 18472412 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8628964 times.
✓ Branch 3 taken 9843448 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8314548 times.
18472604 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1370
4/4
✓ Branch 0 taken 4383868 times.
✓ Branch 1 taken 5773996 times.
✓ Branch 2 taken 1221632 times.
✓ Branch 3 taken 3162236 times.
10157864 if (trafo_depth == 0 || cbf_cb[0]) {
1371 6995628 cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1372
6/6
✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 6397362 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
6995628 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1373 526996 cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1374 }
1375 }
1376
1377
4/4
✓ Branch 0 taken 4383868 times.
✓ Branch 1 taken 5773996 times.
✓ Branch 2 taken 1166936 times.
✓ Branch 3 taken 3216932 times.
10157864 if (trafo_depth == 0 || cbf_cr[0]) {
1378 6940932 cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1379
6/6
✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6195626 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
6940932 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1380 661961 cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1381 }
1382 }
1383 }
1384
1385
2/2
✓ Branch 0 taken 3174604 times.
✓ Branch 1 taken 15298000 times.
18472604 if (split_transform_flag) {
1386 3174604 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1387 3174604 const int x1 = x0 + trafo_size_split;
1388 3174604 const int y1 = y0 + trafo_size_split;
1389
1390 #define SUBDIVIDE(x, y, idx) \
1391 do { \
1392 ret = hls_transform_tree(lc, pps, sps, \
1393 x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1394 log2_trafo_size - 1, trafo_depth + 1, idx, \
1395 cbf_cb, cbf_cr); \
1396 if (ret < 0) \
1397 return ret; \
1398 } while (0)
1399
1400
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3174604 times.
3174604 SUBDIVIDE(x0, y0, 0);
1401
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3174604 times.
3174604 SUBDIVIDE(x1, y0, 1);
1402
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3174604 times.
3174604 SUBDIVIDE(x0, y1, 2);
1403
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3174604 times.
3174604 SUBDIVIDE(x1, y1, 3);
1404
1405 #undef SUBDIVIDE
1406 } else {
1407 15298000 int min_tu_size = 1 << sps->log2_min_tb_size;
1408 15298000 int log2_min_tu_size = sps->log2_min_tb_size;
1409 15298000 int min_tu_width = sps->min_tb_width;
1410 15298000 int cbf_luma = 1;
1411
1412
4/4
✓ Branch 0 taken 5605732 times.
✓ Branch 1 taken 9692268 times.
✓ Branch 2 taken 982499 times.
✓ Branch 3 taken 4623233 times.
15298000 if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1413
4/4
✓ Branch 0 taken 804066 times.
✓ Branch 1 taken 178433 times.
✓ Branch 2 taken 689084 times.
✓ Branch 3 taken 114982 times.
982499 cbf_cb[0] || cbf_cr[0] ||
1414
6/6
✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 664408 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
689084 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1415 14621562 cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth);
1416 }
1417
1418 15298000 ret = hls_transform_unit(lc, pps, sps,
1419 x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1420 log2_cb_size, log2_trafo_size,
1421 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1422
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15297999 times.
15298000 if (ret < 0)
1423 1 return ret;
1424 // TODO: store cbf_luma somewhere else
1425
2/2
✓ Branch 0 taken 9702819 times.
✓ Branch 1 taken 5595180 times.
15297999 if (cbf_luma) {
1426 int i, j;
1427
2/2
✓ Branch 0 taken 19743620 times.
✓ Branch 1 taken 9702819 times.
29446439 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1428
2/2
✓ Branch 0 taken 70339182 times.
✓ Branch 1 taken 19743620 times.
90082802 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1429 70339182 int x_tu = (x0 + j) >> log2_min_tu_size;
1430 70339182 int y_tu = (y0 + i) >> log2_min_tu_size;
1431 70339182 s->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1432 }
1433 }
1434
2/2
✓ Branch 0 taken 14765179 times.
✓ Branch 1 taken 532820 times.
15297999 if (!s->sh.disable_deblocking_filter_flag) {
1435 14765179 ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_trafo_size);
1436
2/2
✓ Branch 0 taken 373941 times.
✓ Branch 1 taken 14391238 times.
14765179 if (pps->transquant_bypass_enable_flag &&
1437
2/2
✓ Branch 0 taken 275932 times.
✓ Branch 1 taken 98009 times.
373941 lc->cu.cu_transquant_bypass_flag)
1438 275932 set_deblocking_bypass(s, sps, x0, y0, log2_trafo_size);
1439 }
1440 }
1441 18472603 return 0;
1442 }
1443
1444 12433 static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCPPS *pps,
1445 int x0, int y0, int log2_cb_size)
1446 {
1447 12433 const HEVCContext *const s = lc->parent;
1448 12433 const HEVCSPS *const sps = pps->sps;
1449 GetBitContext gb;
1450 12433 int cb_size = 1 << log2_cb_size;
1451 12433 ptrdiff_t stride0 = s->cur_frame->f->linesize[0];
1452 12433 ptrdiff_t stride1 = s->cur_frame->f->linesize[1];
1453 12433 ptrdiff_t stride2 = s->cur_frame->f->linesize[2];
1454 12433 uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)];
1455 12433 uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)];
1456 12433 uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)];
1457
1458 12433 int length = cb_size * cb_size * sps->pcm.bit_depth +
1459 12433 (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) +
1460 12433 ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) *
1461 12433 sps->pcm.bit_depth_chroma;
1462 12433 const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
1463 int ret;
1464
1465
2/2
✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
12433 if (!s->sh.disable_deblocking_filter_flag)
1466 6937 ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_cb_size);
1467
1468 12433 ret = init_get_bits(&gb, pcm, length);
1469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
1470 return ret;
1471
1472 12433 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth);
1473
1/2
✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
12433 if (sps->chroma_format_idc) {
1474 12433 s->hevcdsp.put_pcm(dst1, stride1,
1475 12433 cb_size >> sps->hshift[1],
1476 12433 cb_size >> sps->vshift[1],
1477 12433 &gb, sps->pcm.bit_depth_chroma);
1478 12433 s->hevcdsp.put_pcm(dst2, stride2,
1479 12433 cb_size >> sps->hshift[2],
1480 12433 cb_size >> sps->vshift[2],
1481 12433 &gb, sps->pcm.bit_depth_chroma);
1482 }
1483
1484 12433 return 0;
1485 }
1486
1487 /**
1488 * 8.5.3.2.2.1 Luma sample unidirectional interpolation process
1489 *
1490 * @param s HEVC decoding context
1491 * @param dst target buffer for block data at block position
1492 * @param dststride stride of the dst buffer
1493 * @param ref reference picture buffer at origin (0, 0)
1494 * @param mv motion vector (relative to block position) to get pixel data from
1495 * @param x_off horizontal position of block from origin (0, 0)
1496 * @param y_off vertical position of block from origin (0, 0)
1497 * @param block_w width of block
1498 * @param block_h height of block
1499 * @param luma_weight weighting factor applied to the luma prediction
1500 * @param luma_offset additive offset applied to the luma prediction value
1501 */
1502
1503 4828407 static void luma_mc_uni(HEVCLocalContext *lc,
1504 const HEVCPPS *pps, const HEVCSPS *sps,
1505 uint8_t *dst, ptrdiff_t dststride,
1506 const AVFrame *ref, const Mv *mv, int x_off, int y_off,
1507 int block_w, int block_h, int luma_weight, int luma_offset)
1508 {
1509 4828407 const HEVCContext *const s = lc->parent;
1510 4828407 const uint8_t *src = ref->data[0];
1511 4828407 ptrdiff_t srcstride = ref->linesize[0];
1512 4828407 int pic_width = sps->width;
1513 4828407 int pic_height = sps->height;
1514 4828407 int mx = mv->x & 3;
1515 4828407 int my = mv->y & 3;
1516
4/4
✓ Branch 0 taken 1975858 times.
✓ Branch 1 taken 2852549 times.
✓ Branch 2 taken 1921682 times.
✓ Branch 3 taken 54176 times.
9602638 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1517
4/4
✓ Branch 0 taken 2852549 times.
✓ Branch 1 taken 1921682 times.
✓ Branch 2 taken 70226 times.
✓ Branch 3 taken 2782323 times.
4774231 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1518 4828407 int idx = hevc_pel_weight[block_w];
1519
1520 4828407 x_off += mv->x >> 2;
1521 4828407 y_off += mv->y >> 2;
1522 4828407 src += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1523
1524
4/4
✓ Branch 0 taken 4772734 times.
✓ Branch 1 taken 55673 times.
✓ Branch 2 taken 4668338 times.
✓ Branch 3 taken 104396 times.
4828407 if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
1525
2/2
✓ Branch 0 taken 4604874 times.
✓ Branch 1 taken 63464 times.
4668338 x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1526
2/2
✓ Branch 0 taken 4408446 times.
✓ Branch 1 taken 196428 times.
4604874 y_off >= pic_height - block_h - QPEL_EXTRA_AFTER ||
1527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4408446 times.
4408446 ref == s->cur_frame->f) {
1528 419961 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1529 419961 int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1530 419961 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1531
1532 419961 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
1533 edge_emu_stride, srcstride,
1534 block_w + QPEL_EXTRA,
1535 block_h + QPEL_EXTRA,
1536 x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE,
1537 pic_width, pic_height);
1538 419961 src = lc->edge_emu_buffer + buf_offset;
1539 419961 srcstride = edge_emu_stride;
1540 }
1541
1542
2/2
✓ Branch 0 taken 4704005 times.
✓ Branch 1 taken 124402 times.
4828407 if (!weight_flag)
1543 4704005 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride,
1544 block_h, mx, my, block_w);
1545 else
1546 124402 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride,
1547 124402 block_h, s->sh.luma_log2_weight_denom,
1548 luma_weight, luma_offset, mx, my, block_w);
1549 4828407 }
1550
1551 /**
1552 * 8.5.3.2.2.1 Luma sample bidirectional interpolation process
1553 *
1554 * @param s HEVC decoding context
1555 * @param dst target buffer for block data at block position
1556 * @param dststride stride of the dst buffer
1557 * @param ref0 reference picture0 buffer at origin (0, 0)
1558 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1559 * @param x_off horizontal position of block from origin (0, 0)
1560 * @param y_off vertical position of block from origin (0, 0)
1561 * @param block_w width of block
1562 * @param block_h height of block
1563 * @param ref1 reference picture1 buffer at origin (0, 0)
1564 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1565 * @param current_mv current motion vector structure
1566 */
1567 3787660 static void luma_mc_bi(HEVCLocalContext *lc,
1568 const HEVCPPS *pps, const HEVCSPS *sps,
1569 uint8_t *dst, ptrdiff_t dststride,
1570 const AVFrame *ref0, const Mv *mv0, int x_off, int y_off,
1571 int block_w, int block_h, const AVFrame *ref1,
1572 const Mv *mv1, struct MvField *current_mv)
1573 {
1574 3787660 const HEVCContext *const s = lc->parent;
1575 3787660 ptrdiff_t src0stride = ref0->linesize[0];
1576 3787660 ptrdiff_t src1stride = ref1->linesize[0];
1577 3787660 int pic_width = sps->width;
1578 3787660 int pic_height = sps->height;
1579 3787660 int mx0 = mv0->x & 3;
1580 3787660 int my0 = mv0->y & 3;
1581 3787660 int mx1 = mv1->x & 3;
1582 3787660 int my1 = mv1->y & 3;
1583
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3787660 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7575320 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1584
3/4
✓ Branch 0 taken 3787660 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68518 times.
✓ Branch 3 taken 3719142 times.
3787660 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1585 3787660 int x_off0 = x_off + (mv0->x >> 2);
1586 3787660 int y_off0 = y_off + (mv0->y >> 2);
1587 3787660 int x_off1 = x_off + (mv1->x >> 2);
1588 3787660 int y_off1 = y_off + (mv1->y >> 2);
1589 3787660 int idx = hevc_pel_weight[block_w];
1590
1591 3787660 const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1592 3787660 const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1593
1594
4/4
✓ Branch 0 taken 3735171 times.
✓ Branch 1 taken 52489 times.
✓ Branch 2 taken 3635300 times.
✓ Branch 3 taken 99871 times.
3787660 if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER ||
1595
2/2
✓ Branch 0 taken 3571997 times.
✓ Branch 1 taken 63303 times.
3635300 x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1596
2/2
✓ Branch 0 taken 201868 times.
✓ Branch 1 taken 3370129 times.
3571997 y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1597 417531 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1598 417531 int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1599 417531 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1600
1601 417531 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset,
1602 edge_emu_stride, src0stride,
1603 block_w + QPEL_EXTRA,
1604 block_h + QPEL_EXTRA,
1605 x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE,
1606 pic_width, pic_height);
1607 417531 src0 = lc->edge_emu_buffer + buf_offset;
1608 417531 src0stride = edge_emu_stride;
1609 }
1610
1611
4/4
✓ Branch 0 taken 3729732 times.
✓ Branch 1 taken 57928 times.
✓ Branch 2 taken 3630497 times.
✓ Branch 3 taken 99235 times.
3787660 if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER ||
1612
2/2
✓ Branch 0 taken 3564899 times.
✓ Branch 1 taken 65598 times.
3630497 x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1613
2/2
✓ Branch 0 taken 205510 times.
✓ Branch 1 taken 3359389 times.
3564899 y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1614 428271 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1615 428271 int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1616 428271 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1617
1618 428271 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset,
1619 edge_emu_stride, src1stride,
1620 block_w + QPEL_EXTRA,
1621 block_h + QPEL_EXTRA,
1622 x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE,
1623 pic_width, pic_height);
1624 428271 src1 = lc->edge_emu_buffer2 + buf_offset;
1625 428271 src1stride = edge_emu_stride;
1626 }
1627
1628 3787660 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride,
1629 block_h, mx0, my0, block_w);
1630
2/2
✓ Branch 0 taken 3719142 times.
✓ Branch 1 taken 68518 times.
3787660 if (!weight_flag)
1631 3719142 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1632 block_h, mx1, my1, block_w);
1633 else
1634 68518 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1635 68518 block_h, s->sh.luma_log2_weight_denom,
1636 68518 s->sh.luma_weight_l0[current_mv->ref_idx[0]],
1637 68518 s->sh.luma_weight_l1[current_mv->ref_idx[1]],
1638 68518 s->sh.luma_offset_l0[current_mv->ref_idx[0]],
1639 68518 s->sh.luma_offset_l1[current_mv->ref_idx[1]],
1640 mx1, my1, block_w);
1641
1642 3787660 }
1643
1644 /**
1645 * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process
1646 *
1647 * @param s HEVC decoding context
1648 * @param dst1 target buffer for block data at block position (U plane)
1649 * @param dst2 target buffer for block data at block position (V plane)
1650 * @param dststride stride of the dst1 and dst2 buffers
1651 * @param ref reference picture buffer at origin (0, 0)
1652 * @param mv motion vector (relative to block position) to get pixel data from
1653 * @param x_off horizontal position of block from origin (0, 0)
1654 * @param y_off vertical position of block from origin (0, 0)
1655 * @param block_w width of block
1656 * @param block_h height of block
1657 * @param chroma_weight weighting factor applied to the chroma prediction
1658 * @param chroma_offset additive offset applied to the chroma prediction value
1659 */
1660
1661 9656814 static void chroma_mc_uni(HEVCLocalContext *lc,
1662 const HEVCPPS *pps, const HEVCSPS *sps,
1663 uint8_t *dst0,
1664 ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist,
1665 int x_off, int y_off, int block_w, int block_h,
1666 const struct MvField *current_mv, int chroma_weight, int chroma_offset)
1667 {
1668 9656814 const HEVCContext *const s = lc->parent;
1669 9656814 int pic_width = sps->width >> sps->hshift[1];
1670 9656814 int pic_height = sps->height >> sps->vshift[1];
1671 9656814 const Mv *mv = &current_mv->mv[reflist];
1672
4/4
✓ Branch 0 taken 3951716 times.
✓ Branch 1 taken 5705098 times.
✓ Branch 2 taken 3843364 times.
✓ Branch 3 taken 108352 times.
19205276 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1673
4/4
✓ Branch 0 taken 5705098 times.
✓ Branch 1 taken 3843364 times.
✓ Branch 2 taken 140452 times.
✓ Branch 3 taken 5564646 times.
9548462 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1674 9656814 int idx = hevc_pel_weight[block_w];
1675 9656814 int hshift = sps->hshift[1];
1676 9656814 int vshift = sps->vshift[1];
1677 9656814 intptr_t mx = av_zero_extend(mv->x, 2 + hshift);
1678 9656814 intptr_t my = av_zero_extend(mv->y, 2 + vshift);
1679 9656814 intptr_t _mx = mx << (1 - hshift);
1680 9656814 intptr_t _my = my << (1 - vshift);
1681
2/4
✓ Branch 0 taken 9656814 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9656814 times.
9656814 int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2];
1682
1683 9656814 x_off += mv->x >> (2 + hshift);
1684 9656814 y_off += mv->y >> (2 + vshift);
1685 9656814 src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1686
1687
4/4
✓ Branch 0 taken 9555468 times.
✓ Branch 1 taken 101346 times.
✓ Branch 2 taken 9346538 times.
✓ Branch 3 taken 208930 times.
9656814 if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1688
2/2
✓ Branch 0 taken 9219618 times.
✓ Branch 1 taken 126920 times.
9346538 x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1689
3/4
✓ Branch 0 taken 8826706 times.
✓ Branch 1 taken 392912 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8826706 times.
9219618 y_off >= pic_height - block_h - EPEL_EXTRA_AFTER ||
1690 emu) {
1691 830108 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1692 830108 int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift));
1693 830108 int buf_offset0 = EPEL_EXTRA_BEFORE *
1694 830108 (edge_emu_stride + (1 << sps->pixel_shift));
1695 830108 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0,
1696 edge_emu_stride, srcstride,
1697 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1698 x_off - EPEL_EXTRA_BEFORE,
1699 y_off - EPEL_EXTRA_BEFORE,
1700 pic_width, pic_height);
1701
1702 830108 src0 = lc->edge_emu_buffer + buf_offset0;
1703 830108 srcstride = edge_emu_stride;
1704 }
1705
2/2
✓ Branch 0 taken 9408010 times.
✓ Branch 1 taken 248804 times.
9656814 if (!weight_flag)
1706 9408010 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1707 block_h, _mx, _my, block_w);
1708 else
1709 248804 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1710 248804 block_h, s->sh.chroma_log2_weight_denom,
1711 chroma_weight, chroma_offset, _mx, _my, block_w);
1712 9656814 }
1713
1714 /**
1715 * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process
1716 *
1717 * @param s HEVC decoding context
1718 * @param dst target buffer for block data at block position
1719 * @param dststride stride of the dst buffer
1720 * @param ref0 reference picture0 buffer at origin (0, 0)
1721 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1722 * @param x_off horizontal position of block from origin (0, 0)
1723 * @param y_off vertical position of block from origin (0, 0)
1724 * @param block_w width of block
1725 * @param block_h height of block
1726 * @param ref1 reference picture1 buffer at origin (0, 0)
1727 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1728 * @param current_mv current motion vector structure
1729 * @param cidx chroma component(cb, cr)
1730 */
1731 7575320 static void chroma_mc_bi(HEVCLocalContext *lc,
1732 const HEVCPPS *pps, const HEVCSPS *sps,
1733 uint8_t *dst0, ptrdiff_t dststride,
1734 const AVFrame *ref0, const AVFrame *ref1,
1735 int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx)
1736 {
1737 7575320 const HEVCContext *const s = lc->parent;
1738 7575320 const uint8_t *src1 = ref0->data[cidx+1];
1739 7575320 const uint8_t *src2 = ref1->data[cidx+1];
1740 7575320 ptrdiff_t src1stride = ref0->linesize[cidx+1];
1741 7575320 ptrdiff_t src2stride = ref1->linesize[cidx+1];
1742
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7575320 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15150640 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1743
3/4
✓ Branch 0 taken 7575320 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 137036 times.
✓ Branch 3 taken 7438284 times.
7575320 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1744 7575320 int pic_width = sps->width >> sps->hshift[1];
1745 7575320 int pic_height = sps->height >> sps->vshift[1];
1746 7575320 const Mv *const mv0 = &current_mv->mv[0];
1747 7575320 const Mv *const mv1 = &current_mv->mv[1];
1748 7575320 int hshift = sps->hshift[1];
1749 7575320 int vshift = sps->vshift[1];
1750
1751 7575320 intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift);
1752 7575320 intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift);
1753 7575320 intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift);
1754 7575320 intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift);
1755 7575320 intptr_t _mx0 = mx0 << (1 - hshift);
1756 7575320 intptr_t _my0 = my0 << (1 - vshift);
1757 7575320 intptr_t _mx1 = mx1 << (1 - hshift);
1758 7575320 intptr_t _my1 = my1 << (1 - vshift);
1759
1760 7575320 int x_off0 = x_off + (mv0->x >> (2 + hshift));
1761 7575320 int y_off0 = y_off + (mv0->y >> (2 + vshift));
1762 7575320 int x_off1 = x_off + (mv1->x >> (2 + hshift));
1763 7575320 int y_off1 = y_off + (mv1->y >> (2 + vshift));
1764 7575320 int idx = hevc_pel_weight[block_w];
1765 7575320 src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1766 7575320 src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1767
1768
4/4
✓ Branch 0 taken 7475582 times.
✓ Branch 1 taken 99738 times.
✓ Branch 2 taken 7275764 times.
✓ Branch 3 taken 199818 times.
7575320 if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER ||
1769
2/2
✓ Branch 0 taken 7149162 times.
✓ Branch 1 taken 126602 times.
7275764 x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1770
2/2
✓ Branch 0 taken 403086 times.
✓ Branch 1 taken 6746076 times.
7149162 y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1771 829244 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1772 829244 int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift));
1773 829244 int buf_offset1 = EPEL_EXTRA_BEFORE *
1774 829244 (edge_emu_stride + (1 << sps->pixel_shift));
1775
1776 829244 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1,
1777 edge_emu_stride, src1stride,
1778 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1779 x_off0 - EPEL_EXTRA_BEFORE,
1780 y_off0 - EPEL_EXTRA_BEFORE,
1781 pic_width, pic_height);
1782
1783 829244 src1 = lc->edge_emu_buffer + buf_offset1;
1784 829244 src1stride = edge_emu_stride;
1785 }
1786
1787
4/4
✓ Branch 0 taken 7464388 times.
✓ Branch 1 taken 110932 times.
✓ Branch 2 taken 7266198 times.
✓ Branch 3 taken 198190 times.
7575320 if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER ||
1788
2/2
✓ Branch 0 taken 7135008 times.
✓ Branch 1 taken 131190 times.
7266198 x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1789
2/2
✓ Branch 0 taken 410676 times.
✓ Branch 1 taken 6724332 times.
7135008 y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1790 850988 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1791 850988 int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift));
1792 850988 int buf_offset1 = EPEL_EXTRA_BEFORE *
1793 850988 (edge_emu_stride + (1 << sps->pixel_shift));
1794
1795 850988 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1,
1796 edge_emu_stride, src2stride,
1797 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1798 x_off1 - EPEL_EXTRA_BEFORE,
1799 y_off1 - EPEL_EXTRA_BEFORE,
1800 pic_width, pic_height);
1801
1802 850988 src2 = lc->edge_emu_buffer2 + buf_offset1;
1803 850988 src2stride = edge_emu_stride;
1804 }
1805
1806 7575320 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride,
1807 block_h, _mx0, _my0, block_w);
1808
2/2
✓ Branch 0 taken 7438284 times.
✓ Branch 1 taken 137036 times.
7575320 if (!weight_flag)
1809 7438284 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
1810 7438284 src2, src2stride, lc->tmp,
1811 block_h, _mx1, _my1, block_w);
1812 else
1813 137036 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1],
1814 137036 src2, src2stride, lc->tmp,
1815 block_h,
1816 137036 s->sh.chroma_log2_weight_denom,
1817 137036 s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx],
1818 137036 s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx],
1819 137036 s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx],
1820 137036 s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx],
1821 _mx1, _my1, block_w);
1822 7575320 }
1823
1824 12403727 static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref,
1825 const Mv *mv, int y0, int height)
1826 {
1827
2/2
✓ Branch 0 taken 111132 times.
✓ Branch 1 taken 12292595 times.
12403727 if (s->avctx->active_thread_type == FF_THREAD_FRAME ) {
1828 111132 int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9);
1829
1830 111132 ff_progress_frame_await(&ref->tf, y);
1831 }
1832 12403727 }
1833
1834 2383767 static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc,
1835 const HEVCPPS *pps, const HEVCSPS *sps,
1836 int x0, int y0, int nPbW,
1837 int nPbH, int log2_cb_size, int part_idx,
1838 int merge_idx, MvField *mv)
1839 {
1840 2383767 const HEVCContext *const s = lc->parent;
1841 2383767 enum InterPredIdc inter_pred_idc = PRED_L0;
1842 int mvp_flag;
1843
1844 2383767 ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size);
1845 2383767 mv->pred_flag = 0;
1846
2/2
✓ Branch 0 taken 1811994 times.
✓ Branch 1 taken 571773 times.
2383767 if (s->sh.slice_type == HEVC_SLICE_B)
1847 1811994 inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH);
1848
1849
2/2
✓ Branch 0 taken 1999583 times.
✓ Branch 1 taken 384184 times.
2383767 if (inter_pred_idc != PRED_L1) {
1850
1/2
✓ Branch 0 taken 1999583 times.
✗ Branch 1 not taken.
1999583 if (s->sh.nb_refs[L0])
1851 1999583 mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]);
1852
1853 1999583 mv->pred_flag = PF_L0;
1854 1999583 ff_hevc_hls_mvd_coding(lc, x0, y0, 0);
1855 1999583 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
1856 1999583 ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
1857 part_idx, merge_idx, mv, mvp_flag, 0);
1858 1999583 mv->mv[0].x += lc->pu.mvd.x;
1859 1999583 mv->mv[0].y += lc->pu.mvd.y;
1860 }
1861
1862
2/2
✓ Branch 0 taken 788395 times.
✓ Branch 1 taken 1595372 times.
2383767 if (inter_pred_idc != PRED_L0) {
1863
1/2
✓ Branch 0 taken 788395 times.
✗ Branch 1 not taken.
788395 if (s->sh.nb_refs[L1])
1864 788395 mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]);
1865
1866
4/4
✓ Branch 0 taken 187361 times.
✓ Branch 1 taken 601034 times.
✓ Branch 2 taken 157794 times.
✓ Branch 3 taken 29567 times.
788395 if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) {
1867 157794 AV_ZERO32(&lc->pu.mvd);
1868 } else {
1869 630601 ff_hevc_hls_mvd_coding(lc, x0, y0, 1);
1870 }
1871
1872 788395 mv->pred_flag += PF_L1;
1873 788395 mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
1874 788395 ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
1875 part_idx, merge_idx, mv, mvp_flag, 1);
1876 788395 mv->mv[1].x += lc->pu.mvd.x;
1877 788395 mv->mv[1].y += lc->pu.mvd.y;
1878 }
1879 2383767 }
1880
1881 8616067 static void hls_prediction_unit(HEVCLocalContext *lc,
1882 const HEVCPPS *pps, const HEVCSPS *sps,
1883 int x0, int y0, int nPbW, int nPbH,
1884 int log2_cb_size, int partIdx, int idx)
1885 {
1886 #define POS(c_idx, x, y) \