FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc/hevcdec.c
Date: 2024-10-04 17:46:48
Exec Total Coverage
Lines: 1935 2365 81.8%
Functions: 48 51 94.1%
Branches: 1365 1786 76.4%

Line Branch Exec Source
1 /*
2 * HEVC video Decoder
3 *
4 * Copyright (C) 2012 - 2013 Guillaume Martres
5 * Copyright (C) 2012 - 2013 Mickael Raulet
6 * Copyright (C) 2012 - 2013 Gildas Cocherel
7 * Copyright (C) 2012 - 2013 Wassim Hamidouche
8 *
9 * This file is part of FFmpeg.
10 *
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #include "config_components.h"
27
28 #include "libavutil/attributes.h"
29 #include "libavutil/avstring.h"
30 #include "libavutil/common.h"
31 #include "libavutil/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/stereo3d.h"
38 #include "libavutil/timecode.h"
39
40 #include "aom_film_grain.h"
41 #include "bswapdsp.h"
42 #include "cabac_functions.h"
43 #include "codec_internal.h"
44 #include "container_fifo.h"
45 #include "decode.h"
46 #include "golomb.h"
47 #include "hevc.h"
48 #include "parse.h"
49 #include "hevcdec.h"
50 #include "hwaccel_internal.h"
51 #include "hwconfig.h"
52 #include "internal.h"
53 #include "profiles.h"
54 #include "progressframe.h"
55 #include "refstruct.h"
56 #include "thread.h"
57
58 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 };
59
60 /**
61 * NOTE: Each function hls_foo correspond to the function foo in the
62 * specification (HLS stands for High Level Syntax).
63 */
64
65 /**
66 * Section 5.7
67 */
68
69 /* free everything allocated by pic_arrays_init() */
70 1326 static void pic_arrays_free(HEVCLayerContext *l)
71 {
72 1326 av_freep(&l->sao);
73 1326 av_freep(&l->deblock);
74
75 1326 av_freep(&l->skip_flag);
76 1326 av_freep(&l->tab_ct_depth);
77
78 1326 av_freep(&l->tab_ipm);
79 1326 av_freep(&l->cbf_luma);
80 1326 av_freep(&l->is_pcm);
81
82 1326 av_freep(&l->qp_y_tab);
83 1326 av_freep(&l->tab_slice_address);
84 1326 av_freep(&l->filter_slice_edges);
85
86 1326 av_freep(&l->horizontal_bs);
87 1326 av_freep(&l->vertical_bs);
88
89
2/2
✓ Branch 0 taken 3978 times.
✓ Branch 1 taken 1326 times.
5304 for (int i = 0; i < 3; i++) {
90 3978 av_freep(&l->sao_pixel_buffer_h[i]);
91 3978 av_freep(&l->sao_pixel_buffer_v[i]);
92 }
93
94 1326 ff_refstruct_pool_uninit(&l->tab_mvf_pool);
95 1326 ff_refstruct_pool_uninit(&l->rpl_tab_pool);
96 1326 }
97
98 /* allocate arrays that depend on frame dimensions */
99 414 static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps)
100 {
101 414 int log2_min_cb_size = sps->log2_min_cb_size;
102 414 int width = sps->width;
103 414 int height = sps->height;
104 414 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
105 414 ((height >> log2_min_cb_size) + 1);
106 414 int ctb_count = sps->ctb_width * sps->ctb_height;
107 414 int min_pu_size = sps->min_pu_width * sps->min_pu_height;
108
109 414 l->bs_width = (width >> 2) + 1;
110 414 l->bs_height = (height >> 2) + 1;
111
112 414 l->sao = av_calloc(ctb_count, sizeof(*l->sao));
113 414 l->deblock = av_calloc(ctb_count, sizeof(*l->deblock));
114
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
414 if (!l->sao || !l->deblock)
115 goto fail;
116
117 414 l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
118 414 l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
119
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
414 if (!l->skip_flag || !l->tab_ct_depth)
120 goto fail;
121
122 414 l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
123 414 l->tab_ipm = av_mallocz(min_pu_size);
124 414 l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1);
125
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 414 times.
414 if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm)
126 goto fail;
127
128 414 l->filter_slice_edges = av_mallocz(ctb_count);
129 414 l->tab_slice_address = av_malloc_array(pic_size_in_ctb,
130 sizeof(*l->tab_slice_address));
131 414 l->qp_y_tab = av_malloc_array(pic_size_in_ctb,
132 sizeof(*l->qp_y_tab));
133
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 414 times.
414 if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address)
134 goto fail;
135
136 414 l->horizontal_bs = av_calloc(l->bs_width, l->bs_height);
137 414 l->vertical_bs = av_calloc(l->bs_width, l->bs_height);
138
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
414 if (!l->horizontal_bs || !l->vertical_bs)
139 goto fail;
140
141 414 l->tab_mvf_pool = ff_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
142 414 l->rpl_tab_pool = ff_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0);
143
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
414 if (!l->tab_mvf_pool || !l->rpl_tab_pool)
144 goto fail;
145
146
2/2
✓ Branch 0 taken 359 times.
✓ Branch 1 taken 55 times.
414 if (sps->sao_enabled) {
147
2/2
✓ Branch 0 taken 357 times.
✓ Branch 1 taken 2 times.
359 int c_count = (sps->chroma_format_idc != 0) ? 3 : 1;
148
149
2/2
✓ Branch 0 taken 1073 times.
✓ Branch 1 taken 359 times.
1432 for (int c_idx = 0; c_idx < c_count; c_idx++) {
150 1073 int w = sps->width >> sps->hshift[c_idx];
151 1073 int h = sps->height >> sps->vshift[c_idx];
152 1073 l->sao_pixel_buffer_h[c_idx] =
153 1073 av_malloc((w * 2 * sps->ctb_height) <<
154 1073 sps->pixel_shift);
155 1073 l->sao_pixel_buffer_v[c_idx] =
156 1073 av_malloc((h * 2 * sps->ctb_width) <<
157 1073 sps->pixel_shift);
158
1/2
✓ Branch 0 taken 1073 times.
✗ Branch 1 not taken.
1073 if (!l->sao_pixel_buffer_h[c_idx] ||
159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1073 times.
1073 !l->sao_pixel_buffer_v[c_idx])
160 goto fail;
161 }
162 }
163
164 414 return 0;
165
166 fail:
167 pic_arrays_free(l);
168 return AVERROR(ENOMEM);
169 }
170
171 1443 static int pred_weight_table(SliceHeader *sh, void *logctx,
172 const HEVCSPS *sps, GetBitContext *gb)
173 {
174 1443 int i = 0;
175 1443 int j = 0;
176 uint8_t luma_weight_l0_flag[16];
177 uint8_t chroma_weight_l0_flag[16];
178 uint8_t luma_weight_l1_flag[16];
179 uint8_t chroma_weight_l1_flag[16];
180 int luma_log2_weight_denom;
181
182 1443 luma_log2_weight_denom = get_ue_golomb_long(gb);
183
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) {
184 av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
185 return AVERROR_INVALIDDATA;
186 }
187 1443 sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
188
1/2
✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
1443 if (sps->chroma_format_idc != 0) {
189 1443 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
190
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) {
191 av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
192 return AVERROR_INVALIDDATA;
193 }
194 1443 sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
195 }
196
197
2/2
✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
5850 for (i = 0; i < sh->nb_refs[L0]; i++) {
198 4407 luma_weight_l0_flag[i] = get_bits1(gb);
199
2/2
✓ Branch 0 taken 1290 times.
✓ Branch 1 taken 3117 times.
4407 if (!luma_weight_l0_flag[i]) {
200 1290 sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
201 1290 sh->luma_offset_l0[i] = 0;
202 }
203 }
204
1/2
✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
1443 if (sps->chroma_format_idc != 0) {
205
2/2
✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
5850 for (i = 0; i < sh->nb_refs[L0]; i++)
206 4407 chroma_weight_l0_flag[i] = get_bits1(gb);
207 } else {
208 for (i = 0; i < sh->nb_refs[L0]; i++)
209 chroma_weight_l0_flag[i] = 0;
210 }
211
2/2
✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
5850 for (i = 0; i < sh->nb_refs[L0]; i++) {
212
2/2
✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1290 times.
4407 if (luma_weight_l0_flag[i]) {
213 3117 int delta_luma_weight_l0 = get_se_golomb(gb);
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
3117 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
215 return AVERROR_INVALIDDATA;
216 3117 sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
217 3117 sh->luma_offset_l0[i] = get_se_golomb(gb);
218 }
219
2/2
✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3276 times.
4407 if (chroma_weight_l0_flag[i]) {
220
2/2
✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
3393 for (j = 0; j < 2; j++) {
221 2262 int delta_chroma_weight_l0 = get_se_golomb(gb);
222 2262 int delta_chroma_offset_l0 = get_se_golomb(gb);
223
224
1/2
✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
2262 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
225
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)) {
226 return AVERROR_INVALIDDATA;
227 }
228
229 2262 sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0;
230 2262 sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j])
231 2262 >> sh->chroma_log2_weight_denom) + 128), -128, 127);
232 }
233 } else {
234 3276 sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom;
235 3276 sh->chroma_offset_l0[i][0] = 0;
236 3276 sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom;
237 3276 sh->chroma_offset_l0[i][1] = 0;
238 }
239 }
240
2/2
✓ Branch 0 taken 668 times.
✓ Branch 1 taken 775 times.
1443 if (sh->slice_type == HEVC_SLICE_B) {
241
2/2
✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
2015 for (i = 0; i < sh->nb_refs[L1]; i++) {
242 1347 luma_weight_l1_flag[i] = get_bits1(gb);
243
2/2
✓ Branch 0 taken 601 times.
✓ Branch 1 taken 746 times.
1347 if (!luma_weight_l1_flag[i]) {
244 601 sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
245 601 sh->luma_offset_l1[i] = 0;
246 }
247 }
248
1/2
✓ Branch 0 taken 668 times.
✗ Branch 1 not taken.
668 if (sps->chroma_format_idc != 0) {
249
2/2
✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
2015 for (i = 0; i < sh->nb_refs[L1]; i++)
250 1347 chroma_weight_l1_flag[i] = get_bits1(gb);
251 } else {
252 for (i = 0; i < sh->nb_refs[L1]; i++)
253 chroma_weight_l1_flag[i] = 0;
254 }
255
2/2
✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
2015 for (i = 0; i < sh->nb_refs[L1]; i++) {
256
2/2
✓ Branch 0 taken 746 times.
✓ Branch 1 taken 601 times.
1347 if (luma_weight_l1_flag[i]) {
257 746 int delta_luma_weight_l1 = get_se_golomb(gb);
258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
746 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
259 return AVERROR_INVALIDDATA;
260 746 sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
261 746 sh->luma_offset_l1[i] = get_se_golomb(gb);
262 }
263
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1111 times.
1347 if (chroma_weight_l1_flag[i]) {
264
2/2
✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
708 for (j = 0; j < 2; j++) {
265 472 int delta_chroma_weight_l1 = get_se_golomb(gb);
266 472 int delta_chroma_offset_l1 = get_se_golomb(gb);
267
268
1/2
✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
472 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
269
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)) {
270 return AVERROR_INVALIDDATA;
271 }
272
273 472 sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1;
274 472 sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j])
275 472 >> sh->chroma_log2_weight_denom) + 128), -128, 127);
276 }
277 } else {
278 1111 sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom;
279 1111 sh->chroma_offset_l1[i][0] = 0;
280 1111 sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom;
281 1111 sh->chroma_offset_l1[i][1] = 0;
282 }
283 }
284 }
285 1443 return 0;
286 }
287
288 19673 static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps,
289 GetBitContext *gb, int cur_poc, int poc_lsb)
290 {
291 19673 int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
292 19673 int prev_delta_msb = 0;
293 19673 unsigned int nb_sps = 0, nb_sh;
294 int i;
295
296 19673 rps->nb_refs = 0;
297
2/2
✓ Branch 0 taken 18637 times.
✓ Branch 1 taken 1036 times.
19673 if (!sps->long_term_ref_pics_present)
298 18637 return 0;
299
300
2/2
✓ Branch 0 taken 499 times.
✓ Branch 1 taken 537 times.
1036 if (sps->num_long_term_ref_pics_sps > 0)
301 499 nb_sps = get_ue_golomb_long(gb);
302 1036 nb_sh = get_ue_golomb_long(gb);
303
304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
1036 if (nb_sps > sps->num_long_term_ref_pics_sps)
305 return AVERROR_INVALIDDATA;
306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
1036 if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc))
307 return AVERROR_INVALIDDATA;
308
309 1036 rps->nb_refs = nb_sh + nb_sps;
310
311
2/2
✓ Branch 0 taken 1562 times.
✓ Branch 1 taken 1036 times.
2598 for (i = 0; i < rps->nb_refs; i++) {
312
313
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1378 times.
1562 if (i < nb_sps) {
314 184 uint8_t lt_idx_sps = 0;
315
316
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if (sps->num_long_term_ref_pics_sps > 1)
317 184 lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps));
318
319 184 rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
320 184 rps->used[i] = !!(sps->used_by_curr_pic_lt & (1U << lt_idx_sps));
321 } else {
322 1378 rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb);
323 1378 rps->used[i] = get_bits1(gb);
324 }
325
326 1562 rps->poc_msb_present[i] = get_bits1(gb);
327
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1514 times.
1562 if (rps->poc_msb_present[i]) {
328 48 int64_t delta = get_ue_golomb_long(gb);
329 int64_t poc;
330
331
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)
332 31 delta += prev_delta_msb;
333
334 48 poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb;
335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (poc != (int32_t)poc)
336 return AVERROR_INVALIDDATA;
337 48 rps->poc[i] = poc;
338 48 prev_delta_msb = delta;
339 }
340 }
341
342 1036 return 0;
343 }
344
345 652 static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
346 {
347 652 AVCodecContext *avctx = s->avctx;
348 652 const HEVCVPS *vps = sps->vps;
349 652 const HEVCWindow *ow = &sps->output_window;
350 652 unsigned int num = 0, den = 0;
351
352 652 avctx->pix_fmt = sps->pix_fmt;
353 652 avctx->coded_width = sps->width;
354 652 avctx->coded_height = sps->height;
355 652 avctx->width = sps->width - ow->left_offset - ow->right_offset;
356 652 avctx->height = sps->height - ow->top_offset - ow->bottom_offset;
357 652 avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
358 652 avctx->profile = sps->ptl.general_ptl.profile_idc;
359 652 avctx->level = sps->ptl.general_ptl.level_idc;
360
361 652 ff_set_sar(avctx, sps->vui.common.sar);
362
363
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 600 times.
652 if (sps->vui.common.video_signal_type_present_flag)
364 52 avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG
365
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 46 times.
52 : AVCOL_RANGE_MPEG;
366 else
367 600 avctx->color_range = AVCOL_RANGE_MPEG;
368
369
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 603 times.
652 if (sps->vui.common.colour_description_present_flag) {
370 49 avctx->color_primaries = sps->vui.common.colour_primaries;
371 49 avctx->color_trc = sps->vui.common.transfer_characteristics;
372 49 avctx->colorspace = sps->vui.common.matrix_coeffs;
373 } else {
374 603 avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
375 603 avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
376 603 avctx->colorspace = AVCOL_SPC_UNSPECIFIED;
377 }
378
379 652 avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
380
2/2
✓ Branch 0 taken 611 times.
✓ Branch 1 taken 41 times.
652 if (sps->chroma_format_idc == 1) {
381
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 596 times.
611 if (sps->vui.common.chroma_loc_info_present_flag) {
382
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (sps->vui.common.chroma_sample_loc_type_top_field <= 5)
383 15 avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1;
384 } else
385 596 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
386 }
387
388
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 630 times.
652 if (vps->vps_timing_info_present_flag) {
389 22 num = vps->vps_num_units_in_tick;
390 22 den = vps->vps_time_scale;
391
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 578 times.
630 } else if (sps->vui.vui_timing_info_present_flag) {
392 52 num = sps->vui.vui_num_units_in_tick;
393 52 den = sps->vui.vui_time_scale;
394 }
395
396
3/4
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 578 times.
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
652 if (num > 0 && den > 0)
397 74 av_reduce(&avctx->framerate.den, &avctx->framerate.num,
398 num, den, 1 << 30);
399 652 }
400
401 10420 static int export_stream_params_from_sei(HEVCContext *s)
402 {
403 10420 AVCodecContext *avctx = s->avctx;
404
405
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10420 times.
10420 if (s->sei.common.a53_caption.buf_ref)
406 s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
407
408
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10420 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10420 if (s->sei.common.alternative_transfer.present &&
409 av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) &&
410 s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
411 avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics;
412 }
413
414
1/2
✓ Branch 0 taken 10420 times.
✗ Branch 1 not taken.
10420 if (s->sei.common.film_grain_characteristics.present ||
415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10420 times.
10420 s->sei.common.aom_film_grain.enable)
416 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
417
418 10420 return 0;
419 }
420
421 652 static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
422 {
423 652 const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
424
425 652 av_freep(&s->view_ids_available);
426 652 s->nb_view_ids_available = 0;
427 652 av_freep(&s->view_pos_available);
428 652 s->nb_view_pos_available = 0;
429
430 // don't export anything in the trivial case (1 layer, view id=0)
431
3/4
✓ Branch 0 taken 630 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 630 times.
✗ Branch 3 not taken.
652 if (vps->nb_layers < 2 && !vps->view_id[0])
432 630 return 0;
433
434 22 s->view_ids_available = av_calloc(vps->nb_layers, sizeof(*s->view_ids_available));
435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (!s->view_ids_available)
436 return AVERROR(ENOMEM);
437
438
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
22 if (tdrdi->num_ref_displays) {
439 5 s->view_pos_available = av_calloc(vps->nb_layers, sizeof(*s->view_pos_available));
440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!s->view_pos_available)
441 return AVERROR(ENOMEM);
442 }
443
444
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 22 times.
66 for (int i = 0; i < vps->nb_layers; i++) {
445 44 s->view_ids_available[i] = vps->view_id[i];
446
447
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 34 times.
44 if (s->view_pos_available) {
448 10 s->view_pos_available[i] = vps->view_id[i] == tdrdi->left_view_id[0] ?
449
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
15 AV_STEREO3D_VIEW_LEFT :
450
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 vps->view_id[i] == tdrdi->right_view_id[0] ?
451 AV_STEREO3D_VIEW_RIGHT : AV_STEREO3D_VIEW_UNSPEC;
452 }
453 }
454 22 s->nb_view_ids_available = vps->nb_layers;
455
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
22 s->nb_view_pos_available = s->view_pos_available ? vps->nb_layers : 0;
456
457 22 return 0;
458 }
459
460 405 static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
461 {
462 405 unsigned layers_active_output = 0, highest_layer;
463
464 405 s->layers_active_output = 1;
465 405 s->layers_active_decode = 1;
466
467 // nothing requested - decode base layer only
468
2/2
✓ Branch 0 taken 395 times.
✓ Branch 1 taken 10 times.
405 if (!s->nb_view_ids)
469 395 return 0;
470
471
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
10 if (s->nb_view_ids == 1 && s->view_ids[0] == -1) {
472 layers_active_output = (1 << vps->nb_layers) - 1;
473 } else {
474
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 10 times.
28 for (int i = 0; i < s->nb_view_ids; i++) {
475 18 int view_id = s->view_ids[i];
476 18 int layer_idx = -1;
477
478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (view_id < 0) {
479 av_log(s->avctx, AV_LOG_ERROR,
480 "Invalid view ID requested: %d\n", view_id);
481 return AVERROR(EINVAL);
482 }
483
484
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 for (int j = 0; j < vps->nb_layers; j++) {
485
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
26 if (vps->view_id[j] == view_id) {
486 18 layer_idx = j;
487 18 break;
488 }
489 }
490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (layer_idx < 0) {
491 av_log(s->avctx, AV_LOG_ERROR,
492 "View ID %d not present in VPS\n", view_id);
493 return AVERROR(EINVAL);
494 }
495 18 layers_active_output |= 1 << layer_idx;
496 }
497 }
498
499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!layers_active_output) {
500 av_log(s->avctx, AV_LOG_ERROR, "No layers selected\n");
501 return AVERROR_BUG;
502 }
503
504 10 highest_layer = ff_log2(layers_active_output);
505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (highest_layer >= FF_ARRAY_ELEMS(s->layers)) {
506 av_log(s->avctx, AV_LOG_ERROR,
507 "Too many layers requested: %u\n", layers_active_output);
508 return AVERROR(EINVAL);
509 }
510
511 /* Assume a higher layer depends on all the lower ones.
512 * This is enforced in VPS parsing currently, this logic will need
513 * to be changed if we want to support more complex dependency structures.
514 */
515 10 s->layers_active_decode = (1 << (highest_layer + 1)) - 1;
516 10 s->layers_active_output = layers_active_output;
517
518 10 av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n",
519 s->layers_active_decode, s->layers_active_output);
520
521 10 return 0;
522 }
523
524 405 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
525 {
526 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
527 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
528 CONFIG_HEVC_D3D12VA_HWACCEL + \
529 CONFIG_HEVC_NVDEC_HWACCEL + \
530 CONFIG_HEVC_VAAPI_HWACCEL + \
531 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
532 CONFIG_HEVC_VDPAU_HWACCEL + \
533 CONFIG_HEVC_VULKAN_HWACCEL)
534 405 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
535 int ret;
536
537
6/7
✓ Branch 0 taken 342 times.
✓ Branch 1 taken 35 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.
405 switch (sps->pix_fmt) {
538 342 case AV_PIX_FMT_YUV420P:
539 case AV_PIX_FMT_YUVJ420P:
540 #if CONFIG_HEVC_DXVA2_HWACCEL
541 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
542 #endif
543 #if CONFIG_HEVC_D3D11VA_HWACCEL
544 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
545 *fmt++ = AV_PIX_FMT_D3D11;
546 #endif
547 #if CONFIG_HEVC_D3D12VA_HWACCEL
548 *fmt++ = AV_PIX_FMT_D3D12;
549 #endif
550 #if CONFIG_HEVC_VAAPI_HWACCEL
551 342 *fmt++ = AV_PIX_FMT_VAAPI;
552 #endif
553 #if CONFIG_HEVC_VDPAU_HWACCEL
554 342 *fmt++ = AV_PIX_FMT_VDPAU;
555 #endif
556 #if CONFIG_HEVC_NVDEC_HWACCEL
557 *fmt++ = AV_PIX_FMT_CUDA;
558 #endif
559 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
560 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
561 #endif
562 #if CONFIG_HEVC_VULKAN_HWACCEL
563 *fmt++ = AV_PIX_FMT_VULKAN;
564 #endif
565 342 break;
566 35 case AV_PIX_FMT_YUV420P10:
567 #if CONFIG_HEVC_DXVA2_HWACCEL
568 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
569 #endif
570 #if CONFIG_HEVC_D3D11VA_HWACCEL
571 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
572 *fmt++ = AV_PIX_FMT_D3D11;
573 #endif
574 #if CONFIG_HEVC_D3D12VA_HWACCEL
575 *fmt++ = AV_PIX_FMT_D3D12;
576 #endif
577 #if CONFIG_HEVC_VAAPI_HWACCEL
578 35 *fmt++ = AV_PIX_FMT_VAAPI;
579 #endif
580 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
581 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
582 #endif
583 #if CONFIG_HEVC_VULKAN_HWACCEL
584 *fmt++ = AV_PIX_FMT_VULKAN;
585 #endif
586 #if CONFIG_HEVC_VDPAU_HWACCEL
587 35 *fmt++ = AV_PIX_FMT_VDPAU;
588 #endif
589 #if CONFIG_HEVC_NVDEC_HWACCEL
590 *fmt++ = AV_PIX_FMT_CUDA;
591 #endif
592 35 break;
593 4 case AV_PIX_FMT_YUV444P:
594 #if CONFIG_HEVC_VAAPI_HWACCEL
595 4 *fmt++ = AV_PIX_FMT_VAAPI;
596 #endif
597 #if CONFIG_HEVC_VDPAU_HWACCEL
598 4 *fmt++ = AV_PIX_FMT_VDPAU;
599 #endif
600 #if CONFIG_HEVC_NVDEC_HWACCEL
601 *fmt++ = AV_PIX_FMT_CUDA;
602 #endif
603 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
604 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
605 #endif
606 #if CONFIG_HEVC_VULKAN_HWACCEL
607 *fmt++ = AV_PIX_FMT_VULKAN;
608 #endif
609 4 break;
610 12 case AV_PIX_FMT_YUV422P:
611 case AV_PIX_FMT_YUV422P10LE:
612 #if CONFIG_HEVC_VAAPI_HWACCEL
613 12 *fmt++ = AV_PIX_FMT_VAAPI;
614 #endif
615 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
616 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
617 #endif
618 #if CONFIG_HEVC_VULKAN_HWACCEL
619 *fmt++ = AV_PIX_FMT_VULKAN;
620 #endif
621 12 break;
622 10 case AV_PIX_FMT_YUV444P10:
623 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
624 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
625 #endif
626 /* NOTE: fallthrough */
627 case AV_PIX_FMT_YUV420P12:
628 case AV_PIX_FMT_YUV444P12:
629 #if CONFIG_HEVC_VAAPI_HWACCEL
630 10 *fmt++ = AV_PIX_FMT_VAAPI;
631 #endif
632 #if CONFIG_HEVC_VDPAU_HWACCEL
633 10 *fmt++ = AV_PIX_FMT_VDPAU;
634 #endif
635 #if CONFIG_HEVC_VULKAN_HWACCEL
636 *fmt++ = AV_PIX_FMT_VULKAN;
637 #endif
638 #if CONFIG_HEVC_NVDEC_HWACCEL
639 *fmt++ = AV_PIX_FMT_CUDA;
640 #endif
641 10 break;
642 case AV_PIX_FMT_YUV422P12:
643 #if CONFIG_HEVC_VAAPI_HWACCEL
644 *fmt++ = AV_PIX_FMT_VAAPI;
645 #endif
646 #if CONFIG_HEVC_VULKAN_HWACCEL
647 *fmt++ = AV_PIX_FMT_VULKAN;
648 #endif
649 break;
650 }
651
652 405 *fmt++ = sps->pix_fmt;
653 405 *fmt = AV_PIX_FMT_NONE;
654
655 // export multilayer information from active VPS to the caller,
656 // so it is available in get_format()
657 405 ret = export_multilayer(s, sps->vps);
658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
405 if (ret < 0)
659 return ret;
660
661 405 ret = ff_get_format(s->avctx, pix_fmts);
662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
405 if (ret < 0)
663 return ret;
664 405 s->avctx->pix_fmt = ret;
665
666 // set up multilayer decoding, if requested by caller
667 405 ret = setup_multilayer(s, sps->vps);
668
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
405 if (ret < 0)
669 return ret;
670
671 405 return 0;
672 }
673
674 414 static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
675 {
676 int ret;
677
678 414 pic_arrays_free(l);
679 414 ff_refstruct_unref(&l->sps);
680 414 ff_refstruct_unref(&s->vps);
681
682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
414 if (!sps)
683 return 0;
684
685 414 ret = pic_arrays_init(l, sps);
686
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
414 if (ret < 0)
687 goto fail;
688
689 414 ff_hevc_pred_init(&s->hpc, sps->bit_depth);
690 414 ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
691 414 ff_videodsp_init (&s->vdsp, sps->bit_depth);
692
693 414 l->sps = ff_refstruct_ref_c(sps);
694 414 s->vps = ff_refstruct_ref_c(sps->vps);
695
696 414 return 0;
697
698 fail:
699 pic_arrays_free(l);
700 ff_refstruct_unref(&l->sps);
701 return ret;
702 }
703
704 28284 static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb)
705 {
706 const HEVCPPS *pps;
707 const HEVCSPS *sps;
708 const HEVCVPS *vps;
709 unsigned pps_id, layer_idx;
710 int i, ret;
711
712 // Coded parameters
713 28284 sh->first_slice_in_pic_flag = get_bits1(gb);
714
715 28284 sh->no_output_of_prior_pics_flag = 0;
716
3/4
✓ Branch 0 taken 1448 times.
✓ Branch 1 taken 26836 times.
✓ Branch 2 taken 1448 times.
✗ Branch 3 not taken.
28284 if (IS_IRAP(s))
717 1448 sh->no_output_of_prior_pics_flag = get_bits1(gb);
718
719 28284 pps_id = get_ue_golomb_long(gb);
720
3/4
✓ Branch 0 taken 28284 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 28251 times.
28284 if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) {
721 33 av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
722 33 return AVERROR_INVALIDDATA;
723 }
724
3/4
✓ Branch 0 taken 18036 times.
✓ Branch 1 taken 10215 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18036 times.
28251 if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) {
725 av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
726 return AVERROR_INVALIDDATA;
727 }
728 28251 sh->pps_id = pps_id;
729
730 28251 pps = s->ps.pps_list[pps_id];
731 28251 sps = pps->sps;
732 28251 vps = sps->vps;
733 28251 layer_idx = vps->layer_idx[s->nuh_layer_id];
734
735
4/4
✓ Branch 0 taken 479 times.
✓ Branch 1 taken 27772 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 464 times.
28251 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
736 15 sh->no_output_of_prior_pics_flag = 1;
737
738 28251 sh->dependent_slice_segment_flag = 0;
739
2/2
✓ Branch 0 taken 18036 times.
✓ Branch 1 taken 10215 times.
28251 if (!sh->first_slice_in_pic_flag) {
740 int slice_address_length;
741
742
2/2
✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8944 times.
18036 if (pps->dependent_slice_segments_enabled_flag)
743 9092 sh->dependent_slice_segment_flag = get_bits1(gb);
744
3/4
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 10089 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7947 times.
18036 if (sh->dependent_slice_segment_flag && !s->slice_initialized) {
745 av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
746 return AVERROR_INVALIDDATA;
747 }
748
749 18036 slice_address_length = av_ceil_log2(sps->ctb_width *
750 18036 sps->ctb_height);
751 18036 sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18036 times.
18036 if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
753 av_log(s->avctx, AV_LOG_ERROR,
754 "Invalid slice segment address: %u.\n",
755 sh->slice_segment_addr);
756 return AVERROR_INVALIDDATA;
757 }
758
759
2/2
✓ Branch 0 taken 10089 times.
✓ Branch 1 taken 7947 times.
18036 if (!sh->dependent_slice_segment_flag) {
760 10089 sh->slice_addr = sh->slice_segment_addr;
761 }
762 } else {
763 10215 sh->slice_segment_addr = sh->slice_addr = 0;
764 }
765
766
2/2
✓ Branch 0 taken 20304 times.
✓ Branch 1 taken 7947 times.
28251 if (!sh->dependent_slice_segment_flag) {
767
2/2
✓ Branch 0 taken 1078 times.
✓ Branch 1 taken 20304 times.
21382 for (i = 0; i < pps->num_extra_slice_header_bits; i++)
768 1078 skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
769
770 20304 sh->slice_type = get_ue_golomb_long(gb);
771
2/2
✓ Branch 0 taken 19069 times.
✓ Branch 1 taken 1235 times.
20304 if (!(sh->slice_type == HEVC_SLICE_I ||
772
2/2
✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3840 times.
19069 sh->slice_type == HEVC_SLICE_P ||
773
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15229 times.
15229 sh->slice_type == HEVC_SLICE_B)) {
774 av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",
775 sh->slice_type);
776 return AVERROR_INVALIDDATA;
777 }
778
5/6
✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 19245 times.
✓ Branch 2 taken 1059 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 75 times.
✓ Branch 5 taken 984 times.
20304 if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
779
1/2
✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
75 !pps->pps_curr_pic_ref_enabled_flag &&
780
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
75 s->nuh_layer_id == 0) {
781 av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
782 return AVERROR_INVALIDDATA;
783 }
784
785 // when flag is not present, picture is inferred to be output
786 20304 sh->pic_output_flag = 1;
787
2/2
✓ Branch 0 taken 703 times.
✓ Branch 1 taken 19601 times.
20304 if (pps->output_flag_present_flag)
788 703 sh->pic_output_flag = get_bits1(gb);
789
790
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20304 times.
20304 if (sps->separate_colour_plane)
791 sh->colour_plane_id = get_bits(gb, 2);
792
793
4/4
✓ Branch 0 taken 19692 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 19673 times.
20304 if (!IS_IDR(s) ||
794
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 624 times.
631 (s->nuh_layer_id > 0 &&
795
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 !(vps->poc_lsb_not_present & (1 << layer_idx)))) {
796 int poc;
797
798 19680 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
799 19680 poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
800
3/4
✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9812 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
19680 if (!sh->first_slice_in_pic_flag && poc != sh->poc) {
801 av_log(s->avctx, AV_LOG_WARNING,
802 "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc);
803 if (s->avctx->err_recognition & AV_EF_EXPLODE)
804 return AVERROR_INVALIDDATA;
805 poc = sh->poc;
806 }
807 19680 sh->poc = poc;
808 }
809
810
4/4
✓ Branch 0 taken 19692 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 19673 times.
✓ Branch 3 taken 19 times.
39977 if (!IS_IDR(s)) {
811 int pos;
812
813 19673 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
814 19673 pos = get_bits_left(gb);
815
2/2
✓ Branch 0 taken 3499 times.
✓ Branch 1 taken 16174 times.
19673 if (!sh->short_term_ref_pic_set_sps_flag) {
816 3499 ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1);
817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3499 times.
3499 if (ret < 0)
818 return ret;
819
820 3499 sh->short_term_rps = &sh->slice_rps;
821 } else {
822 int numbits, rps_idx;
823
824
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16174 times.
16174 if (!sps->nb_st_rps) {
825 av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
826 return AVERROR_INVALIDDATA;
827 }
828
829 16174 numbits = av_ceil_log2(sps->nb_st_rps);
830
2/2
✓ Branch 0 taken 16146 times.
✓ Branch 1 taken 28 times.
16174 rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
831 16174 sh->short_term_rps = &sps->st_rps[rps_idx];
832 }
833 19673 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
834
835 19673 pos = get_bits_left(gb);
836 19673 ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb);
837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19673 times.
19673 if (ret < 0) {
838 av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
839 if (s->avctx->err_recognition & AV_EF_EXPLODE)
840 return AVERROR_INVALIDDATA;
841 }
842 19673 sh->long_term_ref_pic_set_size = pos - get_bits_left(gb);
843
844
2/2
✓ Branch 0 taken 17242 times.
✓ Branch 1 taken 2431 times.
19673 if (sps->temporal_mvp_enabled)
845 17242 sh->slice_temporal_mvp_enabled_flag = get_bits1(gb);
846 else
847 2431 sh->slice_temporal_mvp_enabled_flag = 0;
848 } else {
849 631 sh->poc = 0;
850 631 sh->pic_order_cnt_lsb = 0;
851 631 sh->short_term_ref_pic_set_sps_flag = 0;
852 631 sh->short_term_ref_pic_set_size = 0;
853 631 sh->short_term_rps = NULL;
854 631 sh->long_term_ref_pic_set_size = 0;
855 631 sh->slice_temporal_mvp_enabled_flag = 0;
856 }
857
858 20304 sh->inter_layer_pred = 0;
859
2/2
✓ Branch 0 taken 277 times.
✓ Branch 1 taken 20027 times.
20304 if (s->nuh_layer_id > 0) {
860 277 int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx];
861
862
2/2
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 48 times.
277 if (vps->default_ref_layers_active)
863 229 sh->inter_layer_pred = !!num_direct_ref_layers;
864
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 else if (num_direct_ref_layers) {
865 48 sh->inter_layer_pred = get_bits1(gb);
866
867
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
48 if (sh->inter_layer_pred && num_direct_ref_layers > 1) {
868 av_log(s->avctx, AV_LOG_ERROR,
869 "NumDirectRefLayers>1 not supported\n");
870 return AVERROR_PATCHWELCOME;
871 }
872 }
873 }
874
875
2/2
✓ Branch 0 taken 16791 times.
✓ Branch 1 taken 3513 times.
20304 if (sps->sao_enabled) {
876 16791 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
877
2/2
✓ Branch 0 taken 16789 times.
✓ Branch 1 taken 2 times.
16791 if (sps->chroma_format_idc) {
878 16789 sh->slice_sample_adaptive_offset_flag[1] =
879 16789 sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb);
880 }
881 } else {
882 3513 sh->slice_sample_adaptive_offset_flag[0] = 0;
883 3513 sh->slice_sample_adaptive_offset_flag[1] = 0;
884 3513 sh->slice_sample_adaptive_offset_flag[2] = 0;
885 }
886
887 20304 sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
888
4/4
✓ Branch 0 taken 16464 times.
✓ Branch 1 taken 3840 times.
✓ Branch 2 taken 15229 times.
✓ Branch 3 taken 1235 times.
20304 if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
889 int nb_refs;
890
891 19069 sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active;
892
2/2
✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3840 times.
19069 if (sh->slice_type == HEVC_SLICE_B)
893 15229 sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active;
894
895
2/2
✓ Branch 1 taken 4954 times.
✓ Branch 2 taken 14115 times.
19069 if (get_bits1(gb)) { // num_ref_idx_active_override_flag
896 4954 sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1;
897
2/2
✓ Branch 0 taken 2776 times.
✓ Branch 1 taken 2178 times.
4954 if (sh->slice_type == HEVC_SLICE_B)
898 2776 sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1;
899 }
900
2/4
✓ Branch 0 taken 19069 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19069 times.
19069 if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) {
901 av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n",
902 sh->nb_refs[L0], sh->nb_refs[L1]);
903 return AVERROR_INVALIDDATA;
904 }
905
906 19069 sh->rpl_modification_flag[0] = 0;
907 19069 sh->rpl_modification_flag[1] = 0;
908 19069 nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx);
909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19069 times.
19069 if (!nb_refs) {
910 av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
911 return AVERROR_INVALIDDATA;
912 }
913
914
4/4
✓ Branch 0 taken 1930 times.
✓ Branch 1 taken 17139 times.
✓ Branch 2 taken 1795 times.
✓ Branch 3 taken 135 times.
19069 if (pps->lists_modification_present_flag && nb_refs > 1) {
915 1795 sh->rpl_modification_flag[0] = get_bits1(gb);
916
2/2
✓ Branch 0 taken 1249 times.
✓ Branch 1 taken 546 times.
1795 if (sh->rpl_modification_flag[0]) {
917
2/2
✓ Branch 0 taken 3000 times.
✓ Branch 1 taken 1249 times.
4249 for (i = 0; i < sh->nb_refs[L0]; i++)
918 3000 sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs));
919 }
920
921
1/2
✓ Branch 0 taken 1795 times.
✗ Branch 1 not taken.
1795 if (sh->slice_type == HEVC_SLICE_B) {
922 1795 sh->rpl_modification_flag[1] = get_bits1(gb);
923
2/2
✓ Branch 0 taken 652 times.
✓ Branch 1 taken 1143 times.
1795 if (sh->rpl_modification_flag[1] == 1)
924
2/2
✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
2207 for (i = 0; i < sh->nb_refs[L1]; i++)
925 1555 sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs));
926 }
927 }
928
929
2/2
✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3840 times.
19069 if (sh->slice_type == HEVC_SLICE_B)
930 15229 sh->mvd_l1_zero_flag = get_bits1(gb);
931
932
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 2759 times.
19069 if (pps->cabac_init_present_flag)
933 16310 sh->cabac_init_flag = get_bits1(gb);
934 else
935 2759 sh->cabac_init_flag = 0;
936
937 19069 sh->collocated_ref_idx = 0;
938
2/2
✓ Branch 0 taken 16684 times.
✓ Branch 1 taken 2385 times.
19069 if (sh->slice_temporal_mvp_enabled_flag) {
939 16684 sh->collocated_list = L0;
940
2/2
✓ Branch 0 taken 14695 times.
✓ Branch 1 taken 1989 times.
16684 if (sh->slice_type == HEVC_SLICE_B)
941 14695 sh->collocated_list = !get_bits1(gb);
942
943
2/2
✓ Branch 0 taken 14826 times.
✓ Branch 1 taken 1858 times.
16684 if (sh->nb_refs[sh->collocated_list] > 1) {
944 14826 sh->collocated_ref_idx = get_ue_golomb_long(gb);
945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14826 times.
14826 if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) {
946 av_log(s->avctx, AV_LOG_ERROR,
947 "Invalid collocated_ref_idx: %d.\n",
948 sh->collocated_ref_idx);
949 return AVERROR_INVALIDDATA;
950 }
951 }
952 }
953
954
4/4
✓ Branch 0 taken 1468 times.
✓ Branch 1 taken 17601 times.
✓ Branch 2 taken 693 times.
✓ Branch 3 taken 775 times.
19069 if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
955
3/4
✓ Branch 0 taken 668 times.
✓ Branch 1 taken 17626 times.
✓ Branch 2 taken 668 times.
✗ Branch 3 not taken.
18294 (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
956 1443 int ret = pred_weight_table(sh, s->avctx, sps, gb);
957
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1443 times.
1443 if (ret < 0)
958 return ret;
959 }
960
961 19069 sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
962
2/4
✓ Branch 0 taken 19069 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19069 times.
19069 if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
963 av_log(s->avctx, AV_LOG_ERROR,
964 "Invalid number of merging MVP candidates: %d.\n",
965 sh->max_num_merge_cand);
966 return AVERROR_INVALIDDATA;
967 }
968
969 // Syntax in 7.3.6.1
970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19069 times.
19069 if (sps->motion_vector_resolution_control_idc == 2)
971 sh->use_integer_mv_flag = get_bits1(gb);
972 else
973 // Inferred to be equal to motion_vector_resolution_control_idc if not present
974 19069 sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc;
975
976 }
977
978 20304 sh->slice_qp_delta = get_se_golomb(gb);
979
980
2/2
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 20033 times.
20304 if (pps->pic_slice_level_chroma_qp_offsets_present_flag) {
981 271 sh->slice_cb_qp_offset = get_se_golomb(gb);
982 271 sh->slice_cr_qp_offset = get_se_golomb(gb);
983
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 ||
984
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) {
985 av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n");
986 return AVERROR_INVALIDDATA;
987 }
988 } else {
989 20033 sh->slice_cb_qp_offset = 0;
990 20033 sh->slice_cr_qp_offset = 0;
991 }
992
993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20304 times.
20304 if (pps->pps_slice_act_qp_offsets_present_flag) {
994 sh->slice_act_y_qp_offset = get_se_golomb(gb);
995 sh->slice_act_cb_qp_offset = get_se_golomb(gb);
996 sh->slice_act_cr_qp_offset = get_se_golomb(gb);
997 }
998
999
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 20261 times.
20304 if (pps->chroma_qp_offset_list_enabled_flag)
1000 43 sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
1001 else
1002 20261 sh->cu_chroma_qp_offset_enabled_flag = 0;
1003
1004
2/2
✓ Branch 0 taken 2959 times.
✓ Branch 1 taken 17345 times.
20304 if (pps->deblocking_filter_control_present_flag) {
1005 2959 int deblocking_filter_override_flag = 0;
1006
1007
2/2
✓ Branch 0 taken 696 times.
✓ Branch 1 taken 2263 times.
2959 if (pps->deblocking_filter_override_enabled_flag)
1008 696 deblocking_filter_override_flag = get_bits1(gb);
1009
1010
2/2
✓ Branch 0 taken 477 times.
✓ Branch 1 taken 2482 times.
2959 if (deblocking_filter_override_flag) {
1011 477 sh->disable_deblocking_filter_flag = get_bits1(gb);
1012
2/2
✓ Branch 0 taken 357 times.
✓ Branch 1 taken 120 times.
477 if (!sh->disable_deblocking_filter_flag) {
1013 357 int beta_offset_div2 = get_se_golomb(gb);
1014 357 int tc_offset_div2 = get_se_golomb(gb) ;
1015
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 ||
1016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 357 times.
357 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1017 av_log(s->avctx, AV_LOG_ERROR,
1018 "Invalid deblock filter offsets: %d, %d\n",
1019 beta_offset_div2, tc_offset_div2);
1020 return AVERROR_INVALIDDATA;
1021 }
1022 357 sh->beta_offset = beta_offset_div2 * 2;
1023 357 sh->tc_offset = tc_offset_div2 * 2;
1024 }
1025 } else {
1026 2482 sh->disable_deblocking_filter_flag = pps->disable_dbf;
1027 2482 sh->beta_offset = pps->beta_offset;
1028 2482 sh->tc_offset = pps->tc_offset;
1029 }
1030 } else {
1031 17345 sh->disable_deblocking_filter_flag = 0;
1032 17345 sh->beta_offset = 0;
1033 17345 sh->tc_offset = 0;
1034 }
1035
1036
2/2
✓ Branch 0 taken 17736 times.
✓ Branch 1 taken 2568 times.
20304 if (pps->seq_loop_filter_across_slices_enabled_flag &&
1037
2/2
✓ Branch 0 taken 11732 times.
✓ Branch 1 taken 6004 times.
17736 (sh->slice_sample_adaptive_offset_flag[0] ||
1038
2/2
✓ Branch 0 taken 11714 times.
✓ Branch 1 taken 18 times.
11732 sh->slice_sample_adaptive_offset_flag[1] ||
1039
2/2
✓ Branch 0 taken 11651 times.
✓ Branch 1 taken 63 times.
11714 !sh->disable_deblocking_filter_flag)) {
1040 17673 sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb);
1041 } else {
1042 2631 sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag;
1043 }
1044 }
1045
1046 28251 sh->num_entry_point_offsets = 0;
1047
4/4
✓ Branch 0 taken 25340 times.
✓ Branch 1 taken 2911 times.
✓ Branch 2 taken 4637 times.
✓ Branch 3 taken 20703 times.
28251 if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1048 7548 unsigned num_entry_point_offsets = get_ue_golomb_long(gb);
1049 // It would be possible to bound this tighter but this here is simpler
1050
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7548 times.
7548 if (num_entry_point_offsets > get_bits_left(gb)) {
1051 av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
1052 return AVERROR_INVALIDDATA;
1053 }
1054
1055 7548 sh->num_entry_point_offsets = num_entry_point_offsets;
1056
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 5474 times.
7548 if (sh->num_entry_point_offsets > 0) {
1057 2074 int offset_len = get_ue_golomb_long(gb) + 1;
1058
1059
2/4
✓ Branch 0 taken 2074 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2074 times.
2074 if (offset_len < 1 || offset_len > 32) {
1060 sh->num_entry_point_offsets = 0;
1061 av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len);
1062 return AVERROR_INVALIDDATA;
1063 }
1064
1065 2074 av_freep(&sh->entry_point_offset);
1066 2074 av_freep(&sh->offset);
1067 2074 av_freep(&sh->size);
1068 2074 sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
1069 2074 sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1070 2074 sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
1071
3/6
✓ Branch 0 taken 2074 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2074 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2074 times.
2074 if (!sh->entry_point_offset || !sh->offset || !sh->size) {
1072 sh->num_entry_point_offsets = 0;
1073 av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
1074 return AVERROR(ENOMEM);
1075 }
1076
2/2
✓ Branch 0 taken 8942 times.
✓ Branch 1 taken 2074 times.
11016 for (i = 0; i < sh->num_entry_point_offsets; i++) {
1077 8942 unsigned val = get_bits_long(gb, offset_len);
1078 8942 sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
1079 }
1080 }
1081 }
1082
1083
2/2
✓ Branch 0 taken 2769 times.
✓ Branch 1 taken 25482 times.
28251 if (pps->slice_header_extension_present_flag) {
1084 2769 unsigned int length = get_ue_golomb_long(gb);
1085
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2769 times.
2769 if (length*8LL > get_bits_left(gb)) {
1086 av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n");
1087 return AVERROR_INVALIDDATA;
1088 }
1089
2/2
✓ Branch 0 taken 20292 times.
✓ Branch 1 taken 2769 times.
23061 for (i = 0; i < length; i++)
1090 20292 skip_bits(gb, 8); // slice_header_extension_data_byte
1091 }
1092
1093 28251 ret = get_bits1(gb);
1094
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
28251 if (!ret) {
1095 av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n");
1096 return AVERROR_INVALIDDATA;
1097 }
1098 28251 sh->data_offset = align_get_bits(gb) - gb->buffer;
1099
1100 // Inferred parameters
1101 28251 sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta;
1102
1/2
✓ Branch 0 taken 28251 times.
✗ Branch 1 not taken.
28251 if (sh->slice_qp > 51 ||
1103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
28251 sh->slice_qp < -sps->qp_bd_offset) {
1104 av_log(s->avctx, AV_LOG_ERROR,
1105 "The slice_qp %d is outside the valid range "
1106 "[%d, 51].\n",
1107 sh->slice_qp,
1108 -sps->qp_bd_offset);
1109 return AVERROR_INVALIDDATA;
1110 }
1111
1112 28251 sh->slice_ctb_addr_rs = sh->slice_segment_addr;
1113
1114
2/2
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20304 times.
28251 if (sh->dependent_slice_segment_flag &&
1115
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])) {
1116 av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
1117 return AVERROR_INVALIDDATA;
1118 }
1119
1120
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28251 times.
28251 if (get_bits_left(gb) < 0) {
1121 av_log(s->avctx, AV_LOG_ERROR,
1122 "Overread slice header by %d bits\n", -get_bits_left(gb));
1123 return AVERROR_INVALIDDATA;
1124 }
1125
1126 28251 return 0;
1127 }
1128
1129 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
1130
1131 #define SET_SAO(elem, value) \
1132 do { \
1133 if (!sao_merge_up_flag && !sao_merge_left_flag) \
1134 sao->elem = value; \
1135 else if (sao_merge_left_flag) \
1136 sao->elem = CTB(l->sao, rx-1, ry).elem; \
1137 else if (sao_merge_up_flag) \
1138 sao->elem = CTB(l->sao, rx, ry-1).elem; \
1139 else \
1140 sao->elem = 0; \
1141 } while (0)
1142
1143 1573720 static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l,
1144 const HEVCPPS *pps, const HEVCSPS *sps,
1145 int rx, int ry)
1146 {
1147 1573720 const HEVCContext *const s = lc->parent;
1148 1573720 int sao_merge_left_flag = 0;
1149 1573720 int sao_merge_up_flag = 0;
1150 1573720 SAOParams *sao = &CTB(l->sao, rx, ry);
1151 int c_idx, i;
1152
1153
2/2
✓ Branch 0 taken 863042 times.
✓ Branch 1 taken 710678 times.
1573720 if (s->sh.slice_sample_adaptive_offset_flag[0] ||
1154
2/2
✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 861398 times.
863042 s->sh.slice_sample_adaptive_offset_flag[1]) {
1155
2/2
✓ Branch 0 taken 676534 times.
✓ Branch 1 taken 35788 times.
712322 if (rx > 0) {
1156
2/2
✓ Branch 0 taken 667999 times.
✓ Branch 1 taken 8535 times.
676534 if (lc->ctb_left_flag)
1157 667999 sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc);
1158 }
1159
4/4
✓ Branch 0 taken 654917 times.
✓ Branch 1 taken 57405 times.
✓ Branch 2 taken 342185 times.
✓ Branch 3 taken 312732 times.
712322 if (ry > 0 && !sao_merge_left_flag) {
1160
2/2
✓ Branch 0 taken 328816 times.
✓ Branch 1 taken 13369 times.
342185 if (lc->ctb_up_flag)
1161 328816 sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc);
1162 }
1163 }
1164
1165
4/4
✓ Branch 0 taken 6294688 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4721064 times.
✓ Branch 3 taken 1573720 times.
6294784 for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) {
1166
2/2
✓ Branch 0 taken 1573720 times.
✓ Branch 1 taken 3147344 times.
4721064 int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma :
1167 3147344 pps->log2_sao_offset_scale_chroma;
1168
1169
2/2
✓ Branch 0 taken 3127126 times.
✓ Branch 1 taken 1593938 times.
4721064 if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1170 3127126 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
1171 3127126 continue;
1172 }
1173
1174
2/2
✓ Branch 0 taken 441630 times.
✓ Branch 1 taken 1152308 times.
1593938 if (c_idx == 2) {
1175 441630 sao->type_idx[2] = sao->type_idx[1];
1176 441630 sao->eo_class[2] = sao->eo_class[1];
1177 } else {
1178
7/8
✓ Branch 0 taken 1013958 times.
✓ Branch 1 taken 138350 times.
✓ Branch 2 taken 497980 times.
✓ Branch 3 taken 515978 times.
✓ Branch 5 taken 515978 times.
✓ Branch 6 taken 138350 times.
✓ Branch 7 taken 138350 times.
✗ Branch 8 not taken.
1152308 SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc));
1179 }
1180
1181
2/2
✓ Branch 0 taken 1057774 times.
✓ Branch 1 taken 536164 times.
1593938 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
1182 1057774 continue;
1183
1184
2/2
✓ Branch 0 taken 2144656 times.
✓ Branch 1 taken 536164 times.
2680820 for (i = 0; i < 4; i++)
1185
7/8
✓ Branch 0 taken 1766928 times.
✓ Branch 1 taken 377728 times.
✓ Branch 2 taken 909988 times.
✓ Branch 3 taken 856940 times.
✓ Branch 5 taken 856940 times.
✓ Branch 6 taken 377728 times.
✓ Branch 7 taken 377728 times.
✗ Branch 8 not taken.
2144656 SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth));
1186
1187
2/2
✓ Branch 0 taken 119646 times.
✓ Branch 1 taken 416518 times.
536164 if (sao->type_idx[c_idx] == SAO_BAND) {
1188
2/2
✓ Branch 0 taken 478584 times.
✓ Branch 1 taken 119646 times.
598230 for (i = 0; i < 4; i++) {
1189
2/2
✓ Branch 0 taken 358111 times.
✓ Branch 1 taken 120473 times.
478584 if (sao->offset_abs[c_idx][i]) {
1190
7/8
✓ Branch 0 taken 332770 times.
✓ Branch 1 taken 25341 times.
✓ Branch 2 taken 246136 times.
✓ Branch 3 taken 86634 times.
✓ Branch 5 taken 86634 times.
✓ Branch 6 taken 25341 times.
✓ Branch 7 taken 25341 times.
✗ Branch 8 not taken.
358111 SET_SAO(offset_sign[c_idx][i],
1191 ff_hevc_sao_offset_sign_decode(lc));
1192 } else {
1193 120473 sao->offset_sign[c_idx][i] = 0;
1194 }
1195 }
1196
7/8
✓ Branch 0 taken 109384 times.
✓ Branch 1 taken 10262 times.
✓ Branch 2 taken 79308 times.
✓ Branch 3 taken 30076 times.
✓ Branch 5 taken 30076 times.
✓ Branch 6 taken 10262 times.
✓ Branch 7 taken 10262 times.
✗ Branch 8 not taken.
119646 SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc));
1197
2/2
✓ Branch 0 taken 335144 times.
✓ Branch 1 taken 81374 times.
416518 } else if (c_idx != 2) {
1198
7/8
✓ Branch 0 taken 267336 times.
✓ Branch 1 taken 67808 times.
✓ Branch 2 taken 115628 times.
✓ Branch 3 taken 151708 times.
✓ Branch 5 taken 151708 times.
✓ Branch 6 taken 67808 times.
✓ Branch 7 taken 67808 times.
✗ Branch 8 not taken.
335144 SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc));
1199 }
1200
1201 // Inferred parameters
1202 536164 sao->offset_val[c_idx][0] = 0;
1203
2/2
✓ Branch 0 taken 2144656 times.
✓ Branch 1 taken 536164 times.
2680820 for (i = 0; i < 4; i++) {
1204 2144656 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
1205
2/2
✓ Branch 0 taken 1666072 times.
✓ Branch 1 taken 478584 times.
2144656 if (sao->type_idx[c_idx] == SAO_EDGE) {
1206
2/2
✓ Branch 0 taken 833036 times.
✓ Branch 1 taken 833036 times.
1666072 if (i > 1)
1207 833036 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1208
2/2
✓ Branch 0 taken 158152 times.
✓ Branch 1 taken 320432 times.
478584 } else if (sao->offset_sign[c_idx][i]) {
1209 158152 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1210 }
1211 2144656 sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale;
1212 }
1213 }
1214 1573720 }
1215
1216 #undef SET_SAO
1217 #undef CTB
1218
1219 384850 static int hls_cross_component_pred(HEVCLocalContext *lc, int idx)
1220 {
1221 384850 int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx);
1222
1223
2/2
✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
384850 if (log2_res_scale_abs_plus1 != 0) {
1224 235843 int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx);
1225 235843 lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) *
1226 235843 (1 - 2 * res_scale_sign_flag);
1227 } else {
1228 149007 lc->tu.res_scale_val = 0;
1229 }
1230
1231
1232 384850 return 0;
1233 }
1234
1235 16059232 static int hls_transform_unit(HEVCLocalContext *lc,
1236 const HEVCLayerContext *l,
1237 const HEVCPPS *pps, const HEVCSPS *sps,
1238 int x0, int y0,
1239 int xBase, int yBase, int cb_xBase, int cb_yBase,
1240 int log2_cb_size, int log2_trafo_size,
1241 int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
1242 {
1243 16059232 const HEVCContext *const s = lc->parent;
1244 16059232 const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1];
1245 int i;
1246
1247
2/2
✓ Branch 0 taken 10175157 times.
✓ Branch 1 taken 5884075 times.
16059232 if (lc->cu.pred_mode == MODE_INTRA) {
1248 10175157 int trafo_size = 1 << log2_trafo_size;
1249 10175157 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size);
1250
1251 10175157 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0);
1252 }
1253
1254
6/6
✓ Branch 0 taken 5836378 times.
✓ Branch 1 taken 10222854 times.
✓ Branch 2 taken 5189985 times.
✓ Branch 3 taken 646393 times.
✓ Branch 4 taken 4745748 times.
✓ Branch 5 taken 444237 times.
16059232 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1255
6/6
✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4589981 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
16121046 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1256 11375299 int scan_idx = SCAN_DIAG;
1257 11375299 int scan_idx_c = SCAN_DIAG;
1258
4/4
✓ Branch 0 taken 7663737 times.
✓ Branch 1 taken 3711562 times.
✓ Branch 2 taken 6115356 times.
✓ Branch 3 taken 1548381 times.
17490655 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1259
2/2
✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 5883646 times.
6115356 (sps->chroma_format_idc == 2 &&
1260
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]));
1261
1262
4/4
✓ Branch 0 taken 2273880 times.
✓ Branch 1 taken 9101419 times.
✓ Branch 2 taken 661320 times.
✓ Branch 3 taken 1612560 times.
11375299 if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
1263 661320 lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc);
1264
2/2
✓ Branch 0 taken 374341 times.
✓ Branch 1 taken 286979 times.
661320 if (lc->tu.cu_qp_delta != 0)
1265
2/2
✓ Branch 1 taken 207150 times.
✓ Branch 2 taken 167191 times.
374341 if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1)
1266 207150 lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1267 661320 lc->tu.is_cu_qp_delta_coded = 1;
1268
1269
2/2
✓ Branch 0 taken 661319 times.
✓ Branch 1 taken 1 times.
661320 if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) ||
1270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 661319 times.
661319 lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) {
1271 1 av_log(s->avctx, AV_LOG_ERROR,
1272 "The cu_qp_delta %d is outside the valid range "
1273 "[%d, %d].\n",
1274 lc->tu.cu_qp_delta,
1275 1 -(26 + sps->qp_bd_offset / 2),
1276 1 (25 + sps->qp_bd_offset / 2));
1277 1 return AVERROR_INVALIDDATA;
1278 }
1279
1280 661319 ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size);
1281 }
1282
1283
4/4
✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 10483347 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
11375298 if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1284
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) {
1285 266275 int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc);
1286
2/2
✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
266275 if (cu_chroma_qp_offset_flag) {
1287 48966 int cu_chroma_qp_offset_idx = 0;
1288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
48966 if (pps->chroma_qp_offset_list_len_minus1 > 0) {
1289 cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1);
1290 av_log(s->avctx, AV_LOG_ERROR,
1291 "cu_chroma_qp_offset_idx not yet tested.\n");
1292 }
1293 48966 lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
1294 48966 lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
1295 } else {
1296 217309 lc->tu.cu_qp_offset_cb = 0;
1297 217309 lc->tu.cu_qp_offset_cr = 0;
1298 }
1299 266275 lc->tu.is_cu_chroma_qp_offset_coded = 1;
1300 }
1301
1302
4/4
✓ Branch 0 taken 7486771 times.
✓ Branch 1 taken 3888527 times.
✓ Branch 2 taken 6500521 times.
✓ Branch 3 taken 986250 times.
11375298 if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1303
2/2
✓ Branch 0 taken 4329402 times.
✓ Branch 1 taken 2171119 times.
6500521 if (lc->tu.intra_pred_mode >= 6 &&
1304
2/2
✓ Branch 0 taken 1551675 times.
✓ Branch 1 taken 2777727 times.
4329402 lc->tu.intra_pred_mode <= 14) {
1305 1551675 scan_idx = SCAN_VERT;
1306
2/2
✓ Branch 0 taken 2142003 times.
✓ Branch 1 taken 2806843 times.
4948846 } else if (lc->tu.intra_pred_mode >= 22 &&
1307
2/2
✓ Branch 0 taken 1802346 times.
✓ Branch 1 taken 339657 times.
2142003 lc->tu.intra_pred_mode <= 30) {
1308 1802346 scan_idx = SCAN_HORIZ;
1309 }
1310
1311
2/2
✓ Branch 0 taken 3889316 times.
✓ Branch 1 taken 2611205 times.
6500521 if (lc->tu.intra_pred_mode_c >= 6 &&
1312
2/2
✓ Branch 0 taken 1463056 times.
✓ Branch 1 taken 2426260 times.
3889316 lc->tu.intra_pred_mode_c <= 14) {
1313 1463056 scan_idx_c = SCAN_VERT;
1314
2/2
✓ Branch 0 taken 2034714 times.
✓ Branch 1 taken 3002751 times.
5037465 } else if (lc->tu.intra_pred_mode_c >= 22 &&
1315
2/2
✓ Branch 0 taken 1705423 times.
✓ Branch 1 taken 329291 times.
2034714 lc->tu.intra_pred_mode_c <= 30) {
1316 1705423 scan_idx_c = SCAN_HORIZ;
1317 }
1318 }
1319
1320 11375298 lc->tu.cross_pf = 0;
1321
1322
2/2
✓ Branch 0 taken 10222853 times.
✓ Branch 1 taken 1152445 times.
11375298 if (cbf_luma)
1323 10222853 ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0);
1324
6/6
✓ Branch 0 taken 11375106 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6287255 times.
✓ Branch 3 taken 5087851 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 6077692 times.
16672712 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1325 5297414 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1326 5297414 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1327
4/4
✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 4960573 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
5515230 lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma &&
1328
2/2
✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
217816 (lc->cu.pred_mode == MODE_INTER ||
1329
2/2
✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
168873 (lc->tu.chroma_mode_c == 4)));
1330
1331
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5104989 times.
5297414 if (lc->tu.cross_pf) {
1332 192425 hls_cross_component_pred(lc, 0);
1333 }
1334
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9688424 times.
✓ Branch 2 taken 5750616 times.
✓ Branch 3 taken 5297414 times.
11048030 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1335
2/2
✓ Branch 0 taken 3176481 times.
✓ Branch 1 taken 2574135 times.
5750616 if (lc->cu.pred_mode == MODE_INTRA) {
1336 3176481 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1337 3176481 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1338 3176481 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1);
1339 }
1340
2/2
✓ Branch 0 taken 1560246 times.
✓ Branch 1 taken 4190370 times.
5750616 if (cbf_cb[i])
1341 1560246 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1342 log2_trafo_size_c, scan_idx_c, 1);
1343 else
1344
2/2
✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 4150712 times.
4190370 if (lc->tu.cross_pf) {
1345 39658 ptrdiff_t stride = s->cur_frame->f->linesize[1];
1346 39658 int hshift = sps->hshift[1];
1347 39658 int vshift = sps->vshift[1];
1348 39658 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1349 39658 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1350 39658 int size = 1 << log2_trafo_size_c;
1351
1352 39658 uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride +
1353 39658 ((x0 >> hshift) << sps->pixel_shift)];
1354
2/2
✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
1871162 for (i = 0; i < (size * size); i++) {
1355 1831504 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1356 }
1357 39658 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1358 }
1359 }
1360
1361
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5104989 times.
5297414 if (lc->tu.cross_pf) {
1362 192425 hls_cross_component_pred(lc, 1);
1363 }
1364
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9688424 times.
✓ Branch 2 taken 5750616 times.
✓ Branch 3 taken 5297414 times.
11048030 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1365
2/2
✓ Branch 0 taken 3176481 times.
✓ Branch 1 taken 2574135 times.
5750616 if (lc->cu.pred_mode == MODE_INTRA) {
1366 3176481 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
1367 3176481 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1368 3176481 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2);
1369 }
1370
2/2
✓ Branch 0 taken 1708790 times.
✓ Branch 1 taken 4041826 times.
5750616 if (cbf_cr[i])
1371 1708790 ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
1372 log2_trafo_size_c, scan_idx_c, 2);
1373 else
1374
2/2
✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 3965902 times.
4041826 if (lc->tu.cross_pf) {
1375 75924 ptrdiff_t stride = s->cur_frame->f->linesize[2];
1376 75924 int hshift = sps->hshift[2];
1377 75924 int vshift = sps->vshift[2];
1378 75924 const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1379 75924 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1380 75924 int size = 1 << log2_trafo_size_c;
1381
1382 75924 uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride +
1383 75924 ((x0 >> hshift) << sps->pixel_shift)];
1384
2/2
✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
3691476 for (i = 0; i < (size * size); i++) {
1385 3615552 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1386 }
1387 75924 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1388 }
1389 }
1390
4/4
✓ Branch 0 taken 6077692 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1561978 times.
✓ Branch 3 taken 4515714 times.
6077884 } else if (sps->chroma_format_idc && blk_idx == 3) {
1391 1561978 int trafo_size_h = 1 << (log2_trafo_size + 1);
1392 1561978 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1393
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2790218 times.
✓ Branch 2 taken 1728847 times.
✓ Branch 3 taken 1561978 times.
3290825 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1394
2/2
✓ Branch 0 taken 1242036 times.
✓ Branch 1 taken 486811 times.
1728847 if (lc->cu.pred_mode == MODE_INTRA) {
1395 1242036 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1396 1242036 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1397 1242036 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1);
1398 }
1399
2/2
✓ Branch 0 taken 652423 times.
✓ Branch 1 taken 1076424 times.
1728847 if (cbf_cb[i])
1400 652423 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1401 log2_trafo_size, scan_idx_c, 1);
1402 }
1403
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2790218 times.
✓ Branch 2 taken 1728847 times.
✓ Branch 3 taken 1561978 times.
3290825 for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1404
2/2
✓ Branch 0 taken 1242036 times.
✓ Branch 1 taken 486811 times.
1728847 if (lc->cu.pred_mode == MODE_INTRA) {
1405 1242036 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
1406 1242036 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1407 1242036 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2);
1408 }
1409
2/2
✓ Branch 0 taken 741276 times.
✓ Branch 1 taken 987571 times.
1728847 if (cbf_cr[i])
1410 741276 ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
1411 log2_trafo_size, scan_idx_c, 2);
1412 }
1413 }
1414
3/4
✓ Branch 0 taken 4683933 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2688385 times.
✓ Branch 3 taken 1995548 times.
4683933 } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
1415
4/4
✓ Branch 0 taken 1650024 times.
✓ Branch 1 taken 1038361 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1589436 times.
3787334 if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) {
1416 1098949 int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
1417 1098949 int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
1418 1098949 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
1419 1098949 sps->log2_ctb_size);
1420 1098949 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1);
1421 1098949 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2);
1422
2/2
✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 1086482 times.
1098949 if (sps->chroma_format_idc == 2) {
1423 12467 ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c),
1424 12467 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1425 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1);
1426 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2);
1427 }
1428
2/2
✓ Branch 0 taken 360443 times.
✓ Branch 1 taken 1228993 times.
1589436 } else if (blk_idx == 3) {
1429 360443 int trafo_size_h = 1 << (log2_trafo_size + 1);
1430 360443 int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
1431 360443 ff_hevc_set_neighbour_available(lc, xBase, yBase,
1432 360443 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1433 360443 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1);
1434 360443 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2);
1435
2/2
✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 356247 times.
360443 if (sps->chroma_format_idc == 2) {
1436 4196 ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size),
1437 4196 trafo_size_h, trafo_size_v, sps->log2_ctb_size);
1438 4196 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1);
1439 4196 s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2);
1440 }
1441 }
1442 }
1443
1444 16059231 return 0;
1445 }
1446
1447 403332 static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps,
1448 int x0, int y0, int log2_cb_size)
1449 {
1450 403332 int cb_size = 1 << log2_cb_size;
1451 403332 int log2_min_pu_size = sps->log2_min_pu_size;
1452
1453 403332 int min_pu_width = sps->min_pu_width;
1454 403332 int x_end = FFMIN(x0 + cb_size, sps->width);
1455 403332 int y_end = FFMIN(y0 + cb_size, sps->height);
1456 int i, j;
1457
1458
2/2
✓ Branch 0 taken 562404 times.
✓ Branch 1 taken 403332 times.
965736 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1459
2/2
✓ Branch 0 taken 1073856 times.
✓ Branch 1 taken 562404 times.
1636260 for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
1460 1073856 is_pcm[i + j * min_pu_width] = 2;
1461 403332 }
1462
1463 19346139 static int hls_transform_tree(HEVCLocalContext *lc,
1464 const HEVCLayerContext *l,
1465 const HEVCPPS *pps, const HEVCSPS *sps,
1466 int x0, int y0,
1467 int xBase, int yBase, int cb_xBase, int cb_yBase,
1468 int log2_cb_size, int log2_trafo_size,
1469 int trafo_depth, int blk_idx,
1470 const int *base_cbf_cb, const int *base_cbf_cr)
1471 {
1472 19346139 const HEVCContext *const s = lc->parent;
1473 uint8_t split_transform_flag;
1474 int cbf_cb[2];
1475 int cbf_cr[2];
1476 int ret;
1477
1478 19346139 cbf_cb[0] = base_cbf_cb[0];
1479 19346139 cbf_cb[1] = base_cbf_cb[1];
1480 19346139 cbf_cr[0] = base_cbf_cr[0];
1481 19346139 cbf_cr[1] = base_cbf_cr[1];
1482
1483
2/2
✓ Branch 0 taken 6547826 times.
✓ Branch 1 taken 12798313 times.
19346139 if (lc->cu.intra_split_flag) {
1484
2/2
✓ Branch 0 taken 4936200 times.
✓ Branch 1 taken 1611626 times.
6547826 if (trafo_depth == 1) {
1485 4936200 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1486
2/2
✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4800796 times.
4936200 if (sps->chroma_format_idc == 3) {
1487 135404 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx];
1488 135404 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx];
1489 } else {
1490 4800796 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1491 4800796 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1492 }
1493 }
1494 } else {
1495 12798313 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0];
1496 12798313 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1497 12798313 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1498 }
1499
1500
2/2
✓ Branch 0 taken 19221944 times.
✓ Branch 1 taken 124195 times.
19346139 if (log2_trafo_size <= sps->log2_max_trafo_size &&
1501
2/2
✓ Branch 0 taken 10212060 times.
✓ Branch 1 taken 9009884 times.
19221944 log2_trafo_size > sps->log2_min_tb_size &&
1502
2/2
✓ Branch 0 taken 8594084 times.
✓ Branch 1 taken 1617976 times.
10212060 trafo_depth < lc->cu.max_trafo_depth &&
1503
4/4
✓ Branch 0 taken 1717275 times.
✓ Branch 1 taken 6876809 times.
✓ Branch 2 taken 490612 times.
✓ Branch 3 taken 1226663 times.
8594084 !(lc->cu.intra_split_flag && trafo_depth == 0)) {
1504 7367421 split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size);
1505 } else {
1506 25638351 int inter_split = sps->max_transform_hierarchy_depth_inter == 0 &&
1507
2/2
✓ Branch 0 taken 836848 times.
✓ Branch 1 taken 844067 times.
1680915 lc->cu.pred_mode == MODE_INTER &&
1508
6/6
✓ Branch 0 taken 1680915 times.
✓ Branch 1 taken 10297803 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 161299 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
13659633 lc->cu.part_mode != PART_2Nx2N &&
1509 trafo_depth == 0;
1510
1511 11978718 split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size ||
1512
8/8
✓ Branch 0 taken 11854523 times.
✓ Branch 1 taken 124195 times.
✓ Branch 2 taken 6049167 times.
✓ Branch 3 taken 5805356 times.
✓ Branch 4 taken 4822504 times.
✓ Branch 5 taken 1226663 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10509222 times.
11978718 (lc->cu.intra_split_flag && trafo_depth == 0) ||
1513 inter_split;
1514 }
1515
1516
6/6
✓ Branch 0 taken 19345947 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8881804 times.
✓ Branch 3 taken 10464143 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8567388 times.
19346139 if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
1517
4/4
✓ Branch 0 taken 4580240 times.
✓ Branch 1 taken 6198319 times.
✓ Branch 2 taken 1259672 times.
✓ Branch 3 taken 3320568 times.
10778559 if (trafo_depth == 0 || cbf_cb[0]) {
1518 7457991 cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1519
6/6
✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 6859725 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
7457991 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1520 526996 cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1521 }
1522 }
1523
1524
4/4
✓ Branch 0 taken 4580240 times.
✓ Branch 1 taken 6198319 times.
✓ Branch 2 taken 1221820 times.
✓ Branch 3 taken 3358420 times.
10778559 if (trafo_depth == 0 || cbf_cr[0]) {
1525 7420139 cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1526
6/6
✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6674833 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
7420139 if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1527 661961 cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
1528 }
1529 }
1530 }
1531
1532
2/2
✓ Branch 0 taken 3286907 times.
✓ Branch 1 taken 16059232 times.
19346139 if (split_transform_flag) {
1533 3286907 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1534 3286907 const int x1 = x0 + trafo_size_split;
1535 3286907 const int y1 = y0 + trafo_size_split;
1536
1537 #define SUBDIVIDE(x, y, idx) \
1538 do { \
1539 ret = hls_transform_tree(lc, l, pps, sps, \
1540 x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1541 log2_trafo_size - 1, trafo_depth + 1, idx, \
1542 cbf_cb, cbf_cr); \
1543 if (ret < 0) \
1544 return ret; \
1545 } while (0)
1546
1547
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
3286907 SUBDIVIDE(x0, y0, 0);
1548
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
3286907 SUBDIVIDE(x1, y0, 1);
1549
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
3286907 SUBDIVIDE(x0, y1, 2);
1550
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
3286907 SUBDIVIDE(x1, y1, 3);
1551
1552 #undef SUBDIVIDE
1553 } else {
1554 16059232 int min_tu_size = 1 << sps->log2_min_tb_size;
1555 16059232 int log2_min_tu_size = sps->log2_min_tb_size;
1556 16059232 int min_tu_width = sps->min_tb_width;
1557 16059232 int cbf_luma = 1;
1558
1559
4/4
✓ Branch 0 taken 5884075 times.
✓ Branch 1 taken 10175157 times.
✓ Branch 2 taken 1105689 times.
✓ Branch 3 taken 4778386 times.
16059232 if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1560
4/4
✓ Branch 0 taken 909623 times.
✓ Branch 1 taken 196066 times.
✓ Branch 2 taken 779586 times.
✓ Branch 3 taken 130037 times.
1105689 cbf_cb[0] || cbf_cr[0] ||
1561
6/6
✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 754910 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
779586 (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1562 15292292 cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth);
1563 }
1564
1565 16059232 ret = hls_transform_unit(lc, l, pps, sps,
1566 x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1567 log2_cb_size, log2_trafo_size,
1568 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1569
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16059231 times.
16059232 if (ret < 0)
1570 1 return ret;
1571 // TODO: store cbf_luma somewhere else
1572
2/2
✓ Branch 0 taken 10222853 times.
✓ Branch 1 taken 5836378 times.
16059231 if (cbf_luma) {
1573 int i, j;
1574
2/2
✓ Branch 0 taken 21688627 times.
✓ Branch 1 taken 10222853 times.
31911480 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1575
2/2
✓ Branch 0 taken 81671243 times.
✓ Branch 1 taken 21688627 times.
103359870 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1576 81671243 int x_tu = (x0 + j) >> log2_min_tu_size;
1577 81671243 int y_tu = (y0 + i) >> log2_min_tu_size;
1578 81671243 l->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1579 }
1580 }
1581
2/2
✓ Branch 0 taken 15526411 times.
✓ Branch 1 taken 532820 times.
16059231 if (!s->sh.disable_deblocking_filter_flag) {
1582 15526411 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size);
1583
2/2
✓ Branch 0 taken 409146 times.
✓ Branch 1 taken 15117265 times.
15526411 if (pps->transquant_bypass_enable_flag &&
1584
2/2
✓ Branch 0 taken 311137 times.
✓ Branch 1 taken 98009 times.
409146 lc->cu.cu_transquant_bypass_flag)
1585 311137 set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size);
1586 }
1587 }
1588 19346138 return 0;
1589 }
1590
1591 12433 static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l,
1592 const HEVCPPS *pps, int x0, int y0, int log2_cb_size)
1593 {
1594 12433 const HEVCContext *const s = lc->parent;
1595 12433 const HEVCSPS *const sps = pps->sps;
1596 GetBitContext gb;
1597 12433 int cb_size = 1 << log2_cb_size;
1598 12433 ptrdiff_t stride0 = s->cur_frame->f->linesize[0];
1599 12433 ptrdiff_t stride1 = s->cur_frame->f->linesize[1];
1600 12433 ptrdiff_t stride2 = s->cur_frame->f->linesize[2];
1601 12433 uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)];
1602 12433 uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)];
1603 12433 uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)];
1604
1605 12433 int length = cb_size * cb_size * sps->pcm.bit_depth +
1606 12433 (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) +
1607 12433 ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) *
1608 12433 sps->pcm.bit_depth_chroma;
1609 12433 const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
1610 int ret;
1611
1612
2/2
✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
12433 if (!s->sh.disable_deblocking_filter_flag)
1613 6937 ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size);
1614
1615 12433 ret = init_get_bits(&gb, pcm, length);
1616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
1617 return ret;
1618
1619 12433 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth);
1620
1/2
✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
12433 if (sps->chroma_format_idc) {
1621 12433 s->hevcdsp.put_pcm(dst1, stride1,
1622 12433 cb_size >> sps->hshift[1],
1623 12433 cb_size >> sps->vshift[1],
1624 12433 &gb, sps->pcm.bit_depth_chroma);
1625 12433 s->hevcdsp.put_pcm(dst2, stride2,
1626 12433 cb_size >> sps->hshift[2],
1627 12433 cb_size >> sps->vshift[2],
1628 12433 &gb, sps->pcm.bit_depth_chroma);
1629 }
1630
1631 12433 return 0;
1632 }
1633
1634 /**
1635 * 8.5.3.2.2.1 Luma sample unidirectional interpolation process
1636 *
1637 * @param s HEVC decoding context
1638 * @param dst target buffer for block data at block position
1639 * @param dststride stride of the dst buffer
1640 * @param ref reference picture buffer at origin (0, 0)
1641 * @param mv motion vector (relative to block position) to get pixel data from
1642 * @param x_off horizontal position of block from origin (0, 0)
1643 * @param y_off vertical position of block from origin (0, 0)
1644 * @param block_w width of block
1645 * @param block_h height of block
1646 * @param luma_weight weighting factor applied to the luma prediction
1647 * @param luma_offset additive offset applied to the luma prediction value
1648 */
1649
1650 5095556 static void luma_mc_uni(HEVCLocalContext *lc,
1651 const HEVCPPS *pps, const HEVCSPS *sps,
1652 uint8_t *dst, ptrdiff_t dststride,
1653 const AVFrame *ref, const Mv *mv, int x_off, int y_off,
1654 int block_w, int block_h, int luma_weight, int luma_offset)
1655 {
1656 5095556 const HEVCContext *const s = lc->parent;
1657 5095556 const uint8_t *src = ref->data[0];
1658 5095556 ptrdiff_t srcstride = ref->linesize[0];
1659 5095556 int pic_width = sps->width;
1660 5095556 int pic_height = sps->height;
1661 5095556 int mx = mv->x & 3;
1662 5095556 int my = mv->y & 3;
1663
4/4
✓ Branch 0 taken 2067314 times.
✓ Branch 1 taken 3028242 times.
✓ Branch 2 taken 2013138 times.
✓ Branch 3 taken 54176 times.
10136936 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1664
4/4
✓ Branch 0 taken 3028242 times.
✓ Branch 1 taken 2013138 times.
✓ Branch 2 taken 70226 times.
✓ Branch 3 taken 2958016 times.
5041380 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1665 5095556 int idx = hevc_pel_weight[block_w];
1666
1667 5095556 x_off += mv->x >> 2;
1668 5095556 y_off += mv->y >> 2;
1669 5095556 src += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1670
1671
4/4
✓ Branch 0 taken 5036595 times.
✓ Branch 1 taken 58961 times.
✓ Branch 2 taken 4929898 times.
✓ Branch 3 taken 106697 times.
5095556 if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
1672
2/2
✓ Branch 0 taken 4864534 times.
✓ Branch 1 taken 65364 times.
4929898 x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1673
2/2
✓ Branch 0 taken 4659765 times.
✓ Branch 1 taken 204769 times.
4864534 y_off >= pic_height - block_h - QPEL_EXTRA_AFTER ||
1674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4659765 times.
4659765 ref == s->cur_frame->f) {
1675 435791 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1676 435791 int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1677 435791 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1678
1679 435791 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
1680 edge_emu_stride, srcstride,
1681 block_w + QPEL_EXTRA,
1682 block_h + QPEL_EXTRA,
1683 x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE,
1684 pic_width, pic_height);
1685 435791 src = lc->edge_emu_buffer + buf_offset;
1686 435791 srcstride = edge_emu_stride;
1687 }
1688
1689
2/2
✓ Branch 0 taken 4971154 times.
✓ Branch 1 taken 124402 times.
5095556 if (!weight_flag)
1690 4971154 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride,
1691 block_h, mx, my, block_w);
1692 else
1693 124402 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride,
1694 124402 block_h, s->sh.luma_log2_weight_denom,
1695 luma_weight, luma_offset, mx, my, block_w);
1696 5095556 }
1697
1698 /**
1699 * 8.5.3.2.2.1 Luma sample bidirectional interpolation process
1700 *
1701 * @param s HEVC decoding context
1702 * @param dst target buffer for block data at block position
1703 * @param dststride stride of the dst buffer
1704 * @param ref0 reference picture0 buffer at origin (0, 0)
1705 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1706 * @param x_off horizontal position of block from origin (0, 0)
1707 * @param y_off vertical position of block from origin (0, 0)
1708 * @param block_w width of block
1709 * @param block_h height of block
1710 * @param ref1 reference picture1 buffer at origin (0, 0)
1711 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1712 * @param current_mv current motion vector structure
1713 */
1714 3960193 static void luma_mc_bi(HEVCLocalContext *lc,
1715 const HEVCPPS *pps, const HEVCSPS *sps,
1716 uint8_t *dst, ptrdiff_t dststride,
1717 const AVFrame *ref0, const Mv *mv0, int x_off, int y_off,
1718 int block_w, int block_h, const AVFrame *ref1,
1719 const Mv *mv1, struct MvField *current_mv)
1720 {
1721 3960193 const HEVCContext *const s = lc->parent;
1722 3960193 ptrdiff_t src0stride = ref0->linesize[0];
1723 3960193 ptrdiff_t src1stride = ref1->linesize[0];
1724 3960193 int pic_width = sps->width;
1725 3960193 int pic_height = sps->height;
1726 3960193 int mx0 = mv0->x & 3;
1727 3960193 int my0 = mv0->y & 3;
1728 3960193 int mx1 = mv1->x & 3;
1729 3960193 int my1 = mv1->y & 3;
1730
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3960193 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7920386 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1731
3/4
✓ Branch 0 taken 3960193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68518 times.
✓ Branch 3 taken 3891675 times.
3960193 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1732 3960193 int x_off0 = x_off + (mv0->x >> 2);
1733 3960193 int y_off0 = y_off + (mv0->y >> 2);
1734 3960193 int x_off1 = x_off + (mv1->x >> 2);
1735 3960193 int y_off1 = y_off + (mv1->y >> 2);
1736 3960193 int idx = hevc_pel_weight[block_w];
1737
1738 3960193 const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift);
1739 3960193 const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift);
1740
1741
4/4
✓ Branch 0 taken 3903009 times.
✓ Branch 1 taken 57184 times.
✓ Branch 2 taken 3796710 times.
✓ Branch 3 taken 106299 times.
3960193 if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER ||
1742
2/2
✓ Branch 0 taken 3728624 times.
✓ Branch 1 taken 68086 times.
3796710 x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1743
2/2
✓ Branch 0 taken 208159 times.
✓ Branch 1 taken 3520465 times.
3728624 y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1744 439728 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1745 439728 int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1746 439728 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1747
1748 439728 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset,
1749 edge_emu_stride, src0stride,
1750 block_w + QPEL_EXTRA,
1751 block_h + QPEL_EXTRA,
1752 x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE,
1753 pic_width, pic_height);
1754 439728 src0 = lc->edge_emu_buffer + buf_offset;
1755 439728 src0stride = edge_emu_stride;
1756 }
1757
1758
4/4
✓ Branch 0 taken 3896806 times.
✓ Branch 1 taken 63387 times.
✓ Branch 2 taken 3791189 times.
✓ Branch 3 taken 105617 times.
3960193 if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER ||
1759
2/2
✓ Branch 0 taken 3721188 times.
✓ Branch 1 taken 70001 times.
3791189 x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1760
2/2
✓ Branch 0 taken 211344 times.
✓ Branch 1 taken 3509844 times.
3721188 y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1761 450349 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1762 450349 int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1763 450349 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
1764
1765 450349 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset,
1766 edge_emu_stride, src1stride,
1767 block_w + QPEL_EXTRA,
1768 block_h + QPEL_EXTRA,
1769 x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE,
1770 pic_width, pic_height);
1771 450349 src1 = lc->edge_emu_buffer2 + buf_offset;
1772 450349 src1stride = edge_emu_stride;
1773 }
1774
1775 3960193 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride,
1776 block_h, mx0, my0, block_w);
1777
2/2
✓ Branch 0 taken 3891675 times.
✓ Branch 1 taken 68518 times.
3960193 if (!weight_flag)
1778 3891675 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1779 block_h, mx1, my1, block_w);
1780 else
1781 68518 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1782 68518 block_h, s->sh.luma_log2_weight_denom,
1783 68518 s->sh.luma_weight_l0[current_mv->ref_idx[0]],
1784 68518 s->sh.luma_weight_l1[current_mv->ref_idx[1]],
1785 68518 s->sh.luma_offset_l0[current_mv->ref_idx[0]],
1786 68518 s->sh.luma_offset_l1[current_mv->ref_idx[1]],
1787 mx1, my1, block_w);
1788
1789 3960193 }
1790
1791 /**
1792 * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process
1793 *
1794 * @param s HEVC decoding context
1795 * @param dst1 target buffer for block data at block position (U plane)
1796 * @param dst2 target buffer for block data at block position (V plane)
1797 * @param dststride stride of the dst1 and dst2 buffers
1798 * @param ref reference picture buffer at origin (0, 0)
1799 * @param mv motion vector (relative to block position) to get pixel data from
1800 * @param x_off horizontal position of block from origin (0, 0)
1801 * @param y_off vertical position of block from origin (0, 0)
1802 * @param block_w width of block
1803 * @param block_h height of block
1804 * @param chroma_weight weighting factor applied to the chroma prediction
1805 * @param chroma_offset additive offset applied to the chroma prediction value
1806 */
1807
1808 10191112 static void chroma_mc_uni(HEVCLocalContext *lc,
1809 const HEVCPPS *pps, const HEVCSPS *sps,
1810 uint8_t *dst0,
1811 ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist,
1812 int x_off, int y_off, int block_w, int block_h,
1813 const struct MvField *current_mv, int chroma_weight, int chroma_offset)
1814 {
1815 10191112 const HEVCContext *const s = lc->parent;
1816 10191112 int pic_width = sps->width >> sps->hshift[1];
1817 10191112 int pic_height = sps->height >> sps->vshift[1];
1818 10191112 const Mv *mv = &current_mv->mv[reflist];
1819
4/4
✓ Branch 0 taken 4134628 times.
✓ Branch 1 taken 6056484 times.
✓ Branch 2 taken 4026276 times.
✓ Branch 3 taken 108352 times.
20273872 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1820
4/4
✓ Branch 0 taken 6056484 times.
✓ Branch 1 taken 4026276 times.
✓ Branch 2 taken 140452 times.
✓ Branch 3 taken 5916032 times.
10082760 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1821 10191112 int idx = hevc_pel_weight[block_w];
1822 10191112 int hshift = sps->hshift[1];
1823 10191112 int vshift = sps->vshift[1];
1824 10191112 intptr_t mx = av_zero_extend(mv->x, 2 + hshift);
1825 10191112 intptr_t my = av_zero_extend(mv->y, 2 + vshift);
1826 10191112 intptr_t _mx = mx << (1 - hshift);
1827 10191112 intptr_t _my = my << (1 - vshift);
1828
2/4
✓ Branch 0 taken 10191112 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10191112 times.
10191112 int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2];
1829
1830 10191112 x_off += mv->x >> (2 + hshift);
1831 10191112 y_off += mv->y >> (2 + vshift);
1832 10191112 src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
1833
1834
4/4
✓ Branch 0 taken 10083642 times.
✓ Branch 1 taken 107470 times.
✓ Branch 2 taken 9870108 times.
✓ Branch 3 taken 213534 times.
10191112 if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1835
2/2
✓ Branch 0 taken 9739388 times.
✓ Branch 1 taken 130720 times.
9870108 x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1836
3/4
✓ Branch 0 taken 9329792 times.
✓ Branch 1 taken 409596 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9329792 times.
9739388 y_off >= pic_height - block_h - EPEL_EXTRA_AFTER ||
1837 emu) {
1838 861320 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
1839 861320 int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift));
1840 861320 int buf_offset0 = EPEL_EXTRA_BEFORE *
1841 861320 (edge_emu_stride + (1 << sps->pixel_shift));
1842 861320 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0,
1843 edge_emu_stride, srcstride,
1844 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1845 x_off - EPEL_EXTRA_BEFORE,
1846 y_off - EPEL_EXTRA_BEFORE,
1847 pic_width, pic_height);
1848
1849 861320 src0 = lc->edge_emu_buffer + buf_offset0;
1850 861320 srcstride = edge_emu_stride;
1851 }
1852
2/2
✓ Branch 0 taken 9942308 times.
✓ Branch 1 taken 248804 times.
10191112 if (!weight_flag)
1853 9942308 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1854 block_h, _mx, _my, block_w);
1855 else
1856 248804 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1857 248804 block_h, s->sh.chroma_log2_weight_denom,
1858 chroma_weight, chroma_offset, _mx, _my, block_w);
1859 10191112 }
1860
1861 /**
1862 * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process
1863 *
1864 * @param s HEVC decoding context
1865 * @param dst target buffer for block data at block position
1866 * @param dststride stride of the dst buffer
1867 * @param ref0 reference picture0 buffer at origin (0, 0)
1868 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1869 * @param x_off horizontal position of block from origin (0, 0)
1870 * @param y_off vertical position of block from origin (0, 0)
1871 * @param block_w width of block
1872 * @param block_h height of block
1873 * @param ref1 reference picture1 buffer at origin (0, 0)
1874 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1875 * @param current_mv current motion vector structure
1876 * @param cidx chroma component(cb, cr)
1877 */
1878 7920386 static void chroma_mc_bi(HEVCLocalContext *lc,
1879 const HEVCPPS *pps, const HEVCSPS *sps,
1880 uint8_t *dst0, ptrdiff_t dststride,
1881 const AVFrame *ref0, const AVFrame *ref1,
1882 int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx)
1883 {
1884 7920386 const HEVCContext *const s = lc->parent;
1885 7920386 const uint8_t *src1 = ref0->data[cidx+1];
1886 7920386 const uint8_t *src2 = ref1->data[cidx+1];
1887 7920386 ptrdiff_t src1stride = ref0->linesize[cidx+1];
1888 7920386 ptrdiff_t src2stride = ref1->linesize[cidx+1];
1889
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7920386 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15840772 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
1890
3/4
✓ Branch 0 taken 7920386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 137036 times.
✓ Branch 3 taken 7783350 times.
7920386 (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
1891 7920386 int pic_width = sps->width >> sps->hshift[1];
1892 7920386 int pic_height = sps->height >> sps->vshift[1];
1893 7920386 const Mv *const mv0 = &current_mv->mv[0];
1894 7920386 const Mv *const mv1 = &current_mv->mv[1];
1895 7920386 int hshift = sps->hshift[1];
1896 7920386 int vshift = sps->vshift[1];
1897
1898 7920386 intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift);
1899 7920386 intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift);
1900 7920386 intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift);
1901 7920386 intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift);
1902 7920386 intptr_t _mx0 = mx0 << (1 - hshift);
1903 7920386 intptr_t _my0 = my0 << (1 - vshift);
1904 7920386 intptr_t _mx1 = mx1 << (1 - hshift);