FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevcdec.c
Date: 2021-09-26 18:22:30
Exec Total Coverage
Lines: 1794 2271 79.0%
Branches: 1287 1717 75.0%

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 "libavutil/attributes.h"
27 #include "libavutil/common.h"
28 #include "libavutil/display.h"
29 #include "libavutil/film_grain_params.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/mastering_display_metadata.h"
32 #include "libavutil/md5.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/stereo3d.h"
36 #include "libavutil/timecode.h"
37
38 #include "bswapdsp.h"
39 #include "bytestream.h"
40 #include "cabac_functions.h"
41 #include "golomb.h"
42 #include "hevc.h"
43 #include "hevc_data.h"
44 #include "hevc_parse.h"
45 #include "hevcdec.h"
46 #include "hwconfig.h"
47 #include "profiles.h"
48
49 const uint8_t ff_hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, [12] = 4, [16] = 5, [24] = 6, [32] = 7, [48] = 8, [64] = 9 };
50
51 /**
52 * NOTE: Each function hls_foo correspond to the function foo in the
53 * specification (HLS stands for High Level Syntax).
54 */
55
56 /**
57 * Section 5.7
58 */
59
60 /* free everything allocated by pic_arrays_init() */
61 743 static void pic_arrays_free(HEVCContext *s)
62 {
63 743 av_freep(&s->sao);
64 743 av_freep(&s->deblock);
65
66 743 av_freep(&s->skip_flag);
67 743 av_freep(&s->tab_ct_depth);
68
69 743 av_freep(&s->tab_ipm);
70 743 av_freep(&s->cbf_luma);
71 743 av_freep(&s->is_pcm);
72
73 743 av_freep(&s->qp_y_tab);
74 743 av_freep(&s->tab_slice_address);
75 743 av_freep(&s->filter_slice_edges);
76
77 743 av_freep(&s->horizontal_bs);
78 743 av_freep(&s->vertical_bs);
79
80 743 av_freep(&s->sh.entry_point_offset);
81 743 av_freep(&s->sh.size);
82 743 av_freep(&s->sh.offset);
83
84 743 av_buffer_pool_uninit(&s->tab_mvf_pool);
85 743 av_buffer_pool_uninit(&s->rpl_tab_pool);
86 743 }
87
88 /* allocate arrays that depend on frame dimensions */
89 372 static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
90 {
91 372 int log2_min_cb_size = sps->log2_min_cb_size;
92 372 int width = sps->width;
93 372 int height = sps->height;
94 372 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
95 372 ((height >> log2_min_cb_size) + 1);
96 372 int ctb_count = sps->ctb_width * sps->ctb_height;
97 372 int min_pu_size = sps->min_pu_width * sps->min_pu_height;
98
99 372 s->bs_width = (width >> 2) + 1;
100 372 s->bs_height = (height >> 2) + 1;
101
102 372 s->sao = av_calloc(ctb_count, sizeof(*s->sao));
103 372 s->deblock = av_calloc(ctb_count, sizeof(*s->deblock));
104
2/4
✓ Branch 0 taken 372 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 372 times.
372 if (!s->sao || !s->deblock)
105 goto fail;
106
107 372 s->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
108 372 s->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
109
2/4
✓ Branch 0 taken 372 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 372 times.
372 if (!s->skip_flag || !s->tab_ct_depth)
110 goto fail;
111
112 372 s->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
113 372 s->tab_ipm = av_mallocz(min_pu_size);
114 372 s->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1);
115
3/6
✓ Branch 0 taken 372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 372 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 372 times.
372 if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)
116 goto fail;
117
118 372 s->filter_slice_edges = av_mallocz(ctb_count);
119 372 s->tab_slice_address = av_malloc_array(pic_size_in_ctb,
120 sizeof(*s->tab_slice_address));
121 372 s->qp_y_tab = av_malloc_array(pic_size_in_ctb,
122 sizeof(*s->qp_y_tab));
123
3/6
✓ Branch 0 taken 372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 372 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 372 times.
372 if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)
124 goto fail;
125
126 372 s->horizontal_bs = av_calloc(s->bs_width, s->bs_height);
127 372 s->vertical_bs = av_calloc(s->bs_width, s->bs_height);
128
2/4
✓ Branch 0 taken 372 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 372 times.
372 if (!s->horizontal_bs || !s->vertical_bs)
129 goto fail;
130
131 372 s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField),
132 av_buffer_allocz);
133 372 s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab),
134 av_buffer_allocz);
135
2/4
✓ Branch 0 taken 372 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 372 times.
372 if (!s->tab_mvf_pool || !s->rpl_tab_pool)
136 goto fail;
137
138 372 return 0;
139
140 fail:
141 pic_arrays_free(s);
142 return AVERROR(ENOMEM);
143 }
144
145 1406 static int pred_weight_table(HEVCContext *s, GetBitContext *gb)
146 {
147 1406 int i = 0;
148 1406 int j = 0;
149 uint8_t luma_weight_l0_flag[16];
150 uint8_t chroma_weight_l0_flag[16];
151 uint8_t luma_weight_l1_flag[16];
152 uint8_t chroma_weight_l1_flag[16];
153 int luma_log2_weight_denom;
154
155 1406 luma_log2_weight_denom = get_ue_golomb_long(gb);
156
2/4
✓ Branch 0 taken 1406 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1406 times.
1406 if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
157 av_log(s->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
158 return AVERROR_INVALIDDATA;
159 }
160 1406 s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
161
1/2
✓ Branch 0 taken 1406 times.
✗ Branch 1 not taken.
1406 if (s->ps.sps->chroma_format_idc != 0) {
162 1406 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
163
2/4
✓ Branch 0 taken 1406 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1406 times.
1406 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
164 av_log(s->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
165 return AVERROR_INVALIDDATA;
166 }
167 1406 s->sh.chroma_log2_weight_denom = chroma_log2_weight_denom;
168 }
169
170
2/2
✓ Branch 0 taken 4356 times.
✓ Branch 1 taken 1406 times.
5762 for (i = 0; i < s->sh.nb_refs[L0]; i++) {
171 4356 luma_weight_l0_flag[i] = get_bits1(gb);
172
2/2
✓ Branch 0 taken 1239 times.
✓ Branch 1 taken 3117 times.
4356 if (!luma_weight_l0_flag[i]) {
173 1239 s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom;
174 1239 s->sh.luma_offset_l0[i] = 0;
175 }
176 }
177
1/2
✓ Branch 0 taken 1406 times.
✗ Branch 1 not taken.
1406 if (s->ps.sps->chroma_format_idc != 0) {
178
2/2
✓ Branch 0 taken 4356 times.
✓ Branch 1 taken 1406 times.
5762 for (i = 0; i < s->sh.nb_refs[L0]; i++)
179 4356 chroma_weight_l0_flag[i] = get_bits1(gb);
180 } else {
181 for (i = 0; i < s->sh.nb_refs[L0]; i++)
182 chroma_weight_l0_flag[i] = 0;
183 }
184
2/2
✓ Branch 0 taken 4356 times.
✓ Branch 1 taken 1406 times.
5762 for (i = 0; i < s->sh.nb_refs[L0]; i++) {
185
2/2
✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1239 times.
4356 if (luma_weight_l0_flag[i]) {
186 3117 int delta_luma_weight_l0 = get_se_golomb(gb);
187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
3117 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
188 return AVERROR_INVALIDDATA;
189 3117 s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l0;
190 3117 s->sh.luma_offset_l0[i] = get_se_golomb(gb);
191 }
192
2/2
✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3225 times.
4356 if (chroma_weight_l0_flag[i]) {
193
2/2
✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
3393 for (j = 0; j < 2; j++) {
194 2262 int delta_chroma_weight_l0 = get_se_golomb(gb);
195 2262 int delta_chroma_offset_l0 = get_se_golomb(gb);
196
197
1/2
✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
2262 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
198
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)) {
199 return AVERROR_INVALIDDATA;
200 }
201
202 2262 s->sh.chroma_weight_l0[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0;
203 2262 s->sh.chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * s->sh.chroma_weight_l0[i][j])
204 2262 >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
205 }
206 } else {
207 3225 s->sh.chroma_weight_l0[i][0] = 1 << s->sh.chroma_log2_weight_denom;
208 3225 s->sh.chroma_offset_l0[i][0] = 0;
209 3225 s->sh.chroma_weight_l0[i][1] = 1 << s->sh.chroma_log2_weight_denom;
210 3225 s->sh.chroma_offset_l0[i][1] = 0;
211 }
212 }
213
2/2
✓ Branch 0 taken 639 times.
✓ Branch 1 taken 767 times.
1406 if (s->sh.slice_type == HEVC_SLICE_B) {
214
2/2
✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 639 times.
1951 for (i = 0; i < s->sh.nb_refs[L1]; i++) {
215 1312 luma_weight_l1_flag[i] = get_bits1(gb);
216
2/2
✓ Branch 0 taken 566 times.
✓ Branch 1 taken 746 times.
1312 if (!luma_weight_l1_flag[i]) {
217 566 s->sh.luma_weight_l1[i] = 1 << s->sh.luma_log2_weight_denom;
218 566 s->sh.luma_offset_l1[i] = 0;
219 }
220 }
221
1/2
✓ Branch 0 taken 639 times.
✗ Branch 1 not taken.
639 if (s->ps.sps->chroma_format_idc != 0) {
222
2/2
✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 639 times.
1951 for (i = 0; i < s->sh.nb_refs[L1]; i++)
223 1312 chroma_weight_l1_flag[i] = get_bits1(gb);
224 } else {
225 for (i = 0; i < s->sh.nb_refs[L1]; i++)
226 chroma_weight_l1_flag[i] = 0;
227 }
228
2/2
✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 639 times.
1951 for (i = 0; i < s->sh.nb_refs[L1]; i++) {
229
2/2
✓ Branch 0 taken 746 times.
✓ Branch 1 taken 566 times.
1312 if (luma_weight_l1_flag[i]) {
230 746 int delta_luma_weight_l1 = get_se_golomb(gb);
231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
746 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
232 return AVERROR_INVALIDDATA;
233 746 s->sh.luma_weight_l1[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l1;
234 746 s->sh.luma_offset_l1[i] = get_se_golomb(gb);
235 }
236
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1076 times.
1312 if (chroma_weight_l1_flag[i]) {
237
2/2
✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
708 for (j = 0; j < 2; j++) {
238 472 int delta_chroma_weight_l1 = get_se_golomb(gb);
239 472 int delta_chroma_offset_l1 = get_se_golomb(gb);
240
241
1/2
✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
472 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
242
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)) {
243 return AVERROR_INVALIDDATA;
244 }
245
246 472 s->sh.chroma_weight_l1[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1;
247 472 s->sh.chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * s->sh.chroma_weight_l1[i][j])
248 472 >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
249 }
250 } else {
251 1076 s->sh.chroma_weight_l1[i][0] = 1 << s->sh.chroma_log2_weight_denom;
252 1076 s->sh.chroma_offset_l1[i][0] = 0;
253 1076 s->sh.chroma_weight_l1[i][1] = 1 << s->sh.chroma_log2_weight_denom;
254 1076 s->sh.chroma_offset_l1[i][1] = 0;
255 }
256 }
257 }
258 1406 return 0;
259 }
260
261 19025 static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
262 {
263 19025 const HEVCSPS *sps = s->ps.sps;
264 19025 int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
265 19025 int prev_delta_msb = 0;
266 19025 unsigned int nb_sps = 0, nb_sh;
267 int i;
268
269 19025 rps->nb_refs = 0;
270
2/2
✓ Branch 0 taken 17991 times.
✓ Branch 1 taken 1034 times.
19025 if (!sps->long_term_ref_pics_present_flag)
271 17991 return 0;
272
273
2/2
✓ Branch 0 taken 499 times.
✓ Branch 1 taken 535 times.
1034 if (sps->num_long_term_ref_pics_sps > 0)
274 499 nb_sps = get_ue_golomb_long(gb);
275 1034 nb_sh = get_ue_golomb_long(gb);
276
277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1034 times.
1034 if (nb_sps > sps->num_long_term_ref_pics_sps)
278 return AVERROR_INVALIDDATA;
279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1034 times.
1034 if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc))
280 return AVERROR_INVALIDDATA;
281
282 1034 rps->nb_refs = nb_sh + nb_sps;
283
284
2/2
✓ Branch 0 taken 1560 times.
✓ Branch 1 taken 1034 times.
2594 for (i = 0; i < rps->nb_refs; i++) {
285
286
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1376 times.
1560 if (i < nb_sps) {
287 184 uint8_t lt_idx_sps = 0;
288
289
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if (sps->num_long_term_ref_pics_sps > 1)
290 184 lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps));
291
292 184 rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
293 184 rps->used[i] = sps->used_by_curr_pic_lt_sps_flag[lt_idx_sps];
294 } else {
295 1376 rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb);
296 1376 rps->used[i] = get_bits1(gb);
297 }
298
299 1560 rps->poc_msb_present[i] = get_bits1(gb);
300
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1512 times.
1560 if (rps->poc_msb_present[i]) {
301 48 int64_t delta = get_ue_golomb_long(gb);
302 int64_t poc;
303
304
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)
305 31 delta += prev_delta_msb;
306
307 48 poc = rps->poc[i] + s->poc - delta * max_poc_lsb - s->sh.pic_order_cnt_lsb;
308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (poc != (int32_t)poc)
309 return AVERROR_INVALIDDATA;
310 48 rps->poc[i] = poc;
311 48 prev_delta_msb = delta;
312 }
313 }
314
315 1034 return 0;
316 }
317
318 550 static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
319 {
320 550 AVCodecContext *avctx = s->avctx;
321 550 const HEVCParamSets *ps = &s->ps;
322 550 const HEVCVPS *vps = (const HEVCVPS*)ps->vps_list[sps->vps_id]->data;
323 550 const HEVCWindow *ow = &sps->output_window;
324 550 unsigned int num = 0, den = 0;
325
326 550 avctx->pix_fmt = sps->pix_fmt;
327 550 avctx->coded_width = sps->width;
328 550 avctx->coded_height = sps->height;
329 550 avctx->width = sps->width - ow->left_offset - ow->right_offset;
330 550 avctx->height = sps->height - ow->top_offset - ow->bottom_offset;
331 550 avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
332 550 avctx->profile = sps->ptl.general_ptl.profile_idc;
333 550 avctx->level = sps->ptl.general_ptl.level_idc;
334
335 550 ff_set_sar(avctx, sps->vui.sar);
336
337
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 536 times.
550 if (sps->vui.video_signal_type_present_flag)
338 14 avctx->color_range = sps->vui.video_full_range_flag ? AVCOL_RANGE_JPEG
339
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 : AVCOL_RANGE_MPEG;
340 else
341 536 avctx->color_range = AVCOL_RANGE_MPEG;
342
343
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 539 times.
550 if (sps->vui.colour_description_present_flag) {
344 11 avctx->color_primaries = sps->vui.colour_primaries;
345 11 avctx->color_trc = sps->vui.transfer_characteristic;
346 11 avctx->colorspace = sps->vui.matrix_coeffs;
347 } else {
348 539 avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
349 539 avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
350 539 avctx->colorspace = AVCOL_SPC_UNSPECIFIED;
351 }
352
353 550 avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
354
2/2
✓ Branch 0 taken 509 times.
✓ Branch 1 taken 41 times.
550 if (sps->chroma_format_idc == 1) {
355
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 505 times.
509 if (sps->vui.chroma_loc_info_present_flag) {
356
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (sps->vui.chroma_sample_loc_type_top_field <= 5)
357 4 avctx->chroma_sample_location = sps->vui.chroma_sample_loc_type_top_field + 1;
358 } else
359 505 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
360 }
361
362
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 527 times.
550 if (vps->vps_timing_info_present_flag) {
363 23 num = vps->vps_num_units_in_tick;
364 23 den = vps->vps_time_scale;
365
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 503 times.
527 } else if (sps->vui.vui_timing_info_present_flag) {
366 24 num = sps->vui.vui_num_units_in_tick;
367 24 den = sps->vui.vui_time_scale;
368 }
369
370
3/4
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 503 times.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
550 if (num != 0 && den != 0)
371 47 av_reduce(&avctx->framerate.den, &avctx->framerate.num,
372 num, den, 1 << 30);
373 550 }
374
375 27770 static int export_stream_params_from_sei(HEVCContext *s)
376 {
377 27770 AVCodecContext *avctx = s->avctx;
378
379
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27770 times.
27770 if (s->sei.a53_caption.buf_ref)
380 s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
381
382
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 27770 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
27770 if (s->sei.alternative_transfer.present &&
383 av_color_transfer_name(s->sei.alternative_transfer.preferred_transfer_characteristics) &&
384 s->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
385 avctx->color_trc = s->sei.alternative_transfer.preferred_transfer_characteristics;
386 }
387
388 27770 return 0;
389 }
390
391 371 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
392 {
393 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
394 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
395 CONFIG_HEVC_NVDEC_HWACCEL + \
396 CONFIG_HEVC_VAAPI_HWACCEL + \
397 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
398 CONFIG_HEVC_VDPAU_HWACCEL)
399 371 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
400
401
6/6
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 2 times.
371 switch (sps->pix_fmt) {
402 319 case AV_PIX_FMT_YUV420P:
403 case AV_PIX_FMT_YUVJ420P:
404 #if CONFIG_HEVC_DXVA2_HWACCEL
405 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
406 #endif
407 #if CONFIG_HEVC_D3D11VA_HWACCEL
408 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
409 *fmt++ = AV_PIX_FMT_D3D11;
410 #endif
411 #if CONFIG_HEVC_VAAPI_HWACCEL
412 319 *fmt++ = AV_PIX_FMT_VAAPI;
413 #endif
414 #if CONFIG_HEVC_VDPAU_HWACCEL
415 319 *fmt++ = AV_PIX_FMT_VDPAU;
416 #endif
417 #if CONFIG_HEVC_NVDEC_HWACCEL
418 *fmt++ = AV_PIX_FMT_CUDA;
419 #endif
420 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
421 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
422 #endif
423 319 break;
424 24 case AV_PIX_FMT_YUV420P10:
425 #if CONFIG_HEVC_DXVA2_HWACCEL
426 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
427 #endif
428 #if CONFIG_HEVC_D3D11VA_HWACCEL
429 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
430 *fmt++ = AV_PIX_FMT_D3D11;
431 #endif
432 #if CONFIG_HEVC_VAAPI_HWACCEL
433 24 *fmt++ = AV_PIX_FMT_VAAPI;
434 #endif
435 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
436 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
437 #endif
438 #if CONFIG_HEVC_VDPAU_HWACCEL
439 24 *fmt++ = AV_PIX_FMT_VDPAU;
440 #endif
441 #if CONFIG_HEVC_NVDEC_HWACCEL
442 *fmt++ = AV_PIX_FMT_CUDA;
443 #endif
444 24 break;
445 4 case AV_PIX_FMT_YUV444P:
446 #if CONFIG_HEVC_VDPAU_HWACCEL
447 4 *fmt++ = AV_PIX_FMT_VDPAU;
448 #endif
449 #if CONFIG_HEVC_NVDEC_HWACCEL
450 *fmt++ = AV_PIX_FMT_CUDA;
451 #endif
452 4 break;
453 12 case AV_PIX_FMT_YUV422P:
454 case AV_PIX_FMT_YUV422P10LE:
455 #if CONFIG_HEVC_VAAPI_HWACCEL
456 12 *fmt++ = AV_PIX_FMT_VAAPI;
457 #endif
458 12 break;
459 10 case AV_PIX_FMT_YUV420P12:
460 case AV_PIX_FMT_YUV444P10:
461 case AV_PIX_FMT_YUV444P12:
462 #if CONFIG_HEVC_VDPAU_HWACCEL
463 10 *fmt++ = AV_PIX_FMT_VDPAU;
464 #endif
465 #if CONFIG_HEVC_NVDEC_HWACCEL
466 *fmt++ = AV_PIX_FMT_CUDA;
467 #endif
468 10 break;
469 }
470
471 371 *fmt++ = sps->pix_fmt;
472 371 *fmt = AV_PIX_FMT_NONE;
473
474 371 return ff_thread_get_format(s->avctx, pix_fmts);
475 }
476
477 372 static int set_sps(HEVCContext *s, const HEVCSPS *sps,
478 enum AVPixelFormat pix_fmt)
479 {
480 int ret, i;
481
482 372 pic_arrays_free(s);
483 372 s->ps.sps = NULL;
484 372 s->ps.vps = NULL;
485
486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372 times.
372 if (!sps)
487 return 0;
488
489 372 ret = pic_arrays_init(s, sps);
490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372 times.
372 if (ret < 0)
491 goto fail;
492
493 372 export_stream_params(s, sps);
494
495 372 s->avctx->pix_fmt = pix_fmt;
496
497 372 ff_hevc_pred_init(&s->hpc, sps->bit_depth);
498 372 ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
499 372 ff_videodsp_init (&s->vdsp, sps->bit_depth);
500
501
2/2
✓ Branch 0 taken 1116 times.
✓ Branch 1 taken 372 times.
1488 for (i = 0; i < 3; i++) {
502 1116 av_freep(&s->sao_pixel_buffer_h[i]);
503 1116 av_freep(&s->sao_pixel_buffer_v[i]);
504 }
505
506
3/4
✓ Branch 0 taken 317 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 317 times.
✗ Branch 3 not taken.
372 if (sps->sao_enabled && !s->avctx->hwaccel) {
507
2/2
✓ Branch 0 taken 315 times.
✓ Branch 1 taken 2 times.
317 int c_count = (sps->chroma_format_idc != 0) ? 3 : 1;
508 int c_idx;
509
510
2/2
✓ Branch 0 taken 947 times.
✓ Branch 1 taken 317 times.
1264 for(c_idx = 0; c_idx < c_count; c_idx++) {
511 947 int w = sps->width >> sps->hshift[c_idx];
512 947 int h = sps->height >> sps->vshift[c_idx];
513 947 s->sao_pixel_buffer_h[c_idx] =
514 947 av_malloc((w * 2 * sps->ctb_height) <<
515 947 sps->pixel_shift);
516 947 s->sao_pixel_buffer_v[c_idx] =
517 947 av_malloc((h * 2 * sps->ctb_width) <<
518 947 sps->pixel_shift);
519
1/2
✓ Branch 0 taken 947 times.
✗ Branch 1 not taken.
947 if (!s->sao_pixel_buffer_h[c_idx] ||
520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 947 times.
947 !s->sao_pixel_buffer_v[c_idx])
521 goto fail;
522 }
523 }
524
525 372 s->ps.sps = sps;
526 372 s->ps.vps = (HEVCVPS*) s->ps.vps_list[s->ps.sps->vps_id]->data;
527
528 372 return 0;
529
530 fail:
531 pic_arrays_free(s);
532 for (i = 0; i < 3; i++) {
533 av_freep(&s->sao_pixel_buffer_h[i]);
534 av_freep(&s->sao_pixel_buffer_v[i]);
535 }
536 s->ps.sps = NULL;
537 return ret;
538 }
539
540 27581 static int hls_slice_header(HEVCContext *s)
541 {
542 27581 GetBitContext *gb = &s->HEVClc->gb;
543 27581 SliceHeader *sh = &s->sh;
544 int i, ret;
545
546 // Coded parameters
547 27581 sh->first_slice_in_pic_flag = get_bits1(gb);
548
4/4
✓ Branch 0 taken 17990 times.
✓ Branch 1 taken 9591 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 17989 times.
27581 if (s->ref && sh->first_slice_in_pic_flag) {
549 1 av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
550 1 return 1; // This slice will be skipped later, do not corrupt state
551 }
552
553
12/12
✓ Branch 0 taken 26677 times.
✓ Branch 1 taken 903 times.
✓ Branch 2 taken 26666 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 26664 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 26657 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 26656 times.
✓ Branch 10 taken 380 times.
✓ Branch 11 taken 544 times.
27580 if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
554 380 s->seq_decode = (s->seq_decode + 1) & 0xff;
555 380 s->max_ra = INT_MAX;
556
4/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 359 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 10 times.
380 if (IS_IDR(s))
557 370 ff_hevc_clear_refs(s);
558 }
559 27580 sh->no_output_of_prior_pics_flag = 0;
560
3/4
✓ Branch 0 taken 1266 times.
✓ Branch 1 taken 26314 times.
✓ Branch 2 taken 1266 times.
✗ Branch 3 not taken.
27580 if (IS_IRAP(s))
561 1266 sh->no_output_of_prior_pics_flag = get_bits1(gb);
562
563 27580 sh->pps_id = get_ue_golomb_long(gb);
564
3/4
✓ Branch 0 taken 27580 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 27558 times.
27580 if (sh->pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[sh->pps_id]) {
565 22 av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id);
566 22 return AVERROR_INVALIDDATA;
567 }
568
2/2
✓ Branch 0 taken 18031 times.
✓ Branch 1 taken 9527 times.
27558 if (!sh->first_slice_in_pic_flag &&
569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18031 times.
18031 s->ps.pps != (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data) {
570 av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
571 return AVERROR_INVALIDDATA;
572 }
573 27558 s->ps.pps = (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data;
574
4/4
✓ Branch 0 taken 342 times.
✓ Branch 1 taken 27216 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 328 times.
27558 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
575 14 sh->no_output_of_prior_pics_flag = 1;
576
577
2/2
✓ Branch 0 taken 371 times.
✓ Branch 1 taken 27187 times.
27558 if (s->ps.sps != (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data) {
578 371 const HEVCSPS *sps = (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data;
579 371 const HEVCSPS *last_sps = s->ps.sps;
580 enum AVPixelFormat pix_fmt;
581
582
5/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 369 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
371 if (last_sps && IS_IRAP(s) && s->nal_unit_type != HEVC_NAL_CRA_NUT) {
583
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (sps->width != last_sps->width || sps->height != last_sps->height ||
584 2 sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering !=
585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 last_sps->temporal_layer[last_sps->max_sub_layers - 1].max_dec_pic_buffering)
586 sh->no_output_of_prior_pics_flag = 0;
587 }
588 371 ff_hevc_clear_refs(s);
589
590 371 ret = set_sps(s, sps, sps->pix_fmt);
591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 371 times.
371 if (ret < 0)
592 return ret;
593
594 371 pix_fmt = get_format(s, sps);
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 371 times.
371 if (pix_fmt < 0)
596 return pix_fmt;
597 371 s->avctx->pix_fmt = pix_fmt;
598
599 371 s->seq_decode = (s->seq_decode + 1) & 0xff;
600 371 s->max_ra = INT_MAX;
601 }
602
603 27558 ret = export_stream_params_from_sei(s);
604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27558 times.
27558 if (ret < 0)
605 return ret;
606
607 27558 sh->dependent_slice_segment_flag = 0;
608
2/2
✓ Branch 0 taken 18031 times.
✓ Branch 1 taken 9527 times.
27558 if (!sh->first_slice_in_pic_flag) {
609 int slice_address_length;
610
611
2/2
✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8939 times.
18031 if (s->ps.pps->dependent_slice_segments_enabled_flag)
612 9092 sh->dependent_slice_segment_flag = get_bits1(gb);
613
614 18031 slice_address_length = av_ceil_log2(s->ps.sps->ctb_width *
615 18031 s->ps.sps->ctb_height);
616 18031 sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18031 times.
18031 if (sh->slice_segment_addr >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) {
618 av_log(s->avctx, AV_LOG_ERROR,
619 "Invalid slice segment address: %u.\n",
620 sh->slice_segment_addr);
621 return AVERROR_INVALIDDATA;
622 }
623
624
2/2
✓ Branch 0 taken 10084 times.
✓ Branch 1 taken 7947 times.
18031 if (!sh->dependent_slice_segment_flag) {
625 10084 sh->slice_addr = sh->slice_segment_addr;
626 10084 s->slice_idx++;
627 }
628 } else {
629 9527 sh->slice_segment_addr = sh->slice_addr = 0;
630 9527 s->slice_idx = 0;
631 9527 s->slice_initialized = 0;
632 }
633
634
2/2
✓ Branch 0 taken 19611 times.
✓ Branch 1 taken 7947 times.
27558 if (!sh->dependent_slice_segment_flag) {
635 19611 s->slice_initialized = 0;
636
637
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 19611 times.
19615 for (i = 0; i < s->ps.pps->num_extra_slice_header_bits; i++)
638 4 skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
639
640 19611 sh->slice_type = get_ue_golomb_long(gb);
641
2/2
✓ Branch 0 taken 18483 times.
✓ Branch 1 taken 1128 times.
19611 if (!(sh->slice_type == HEVC_SLICE_I ||
642
2/2
✓ Branch 0 taken 14743 times.
✓ Branch 1 taken 3740 times.
18483 sh->slice_type == HEVC_SLICE_P ||
643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14743 times.
14743 sh->slice_type == HEVC_SLICE_B)) {
644 av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",
645 sh->slice_type);
646 return AVERROR_INVALIDDATA;
647 }
648
4/6
✓ Branch 0 taken 877 times.
✓ Branch 1 taken 18734 times.
✓ Branch 2 taken 877 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 877 times.
19611 if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I) {
649 av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
650 return AVERROR_INVALIDDATA;
651 }
652
653 // when flag is not present, picture is inferred to be output
654 19611 sh->pic_output_flag = 1;
655
2/2
✓ Branch 0 taken 703 times.
✓ Branch 1 taken 18908 times.
19611 if (s->ps.pps->output_flag_present_flag)
656 703 sh->pic_output_flag = get_bits1(gb);
657
658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19611 times.
19611 if (s->ps.sps->separate_colour_plane_flag)
659 sh->colour_plane_id = get_bits(gb, 2);
660
661
4/4
✓ Branch 0 taken 19036 times.
✓ Branch 1 taken 575 times.
✓ Branch 2 taken 19025 times.
✓ Branch 3 taken 11 times.
38636 if (!IS_IDR(s)) {
662 int poc, pos;
663
664 19025 sh->pic_order_cnt_lsb = get_bits(gb, s->ps.sps->log2_max_poc_lsb);
665 19025 poc = ff_hevc_compute_poc(s->ps.sps, s->pocTid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
666
3/4
✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9157 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
19025 if (!sh->first_slice_in_pic_flag && poc != s->poc) {
667 av_log(s->avctx, AV_LOG_WARNING,
668 "Ignoring POC change between slices: %d -> %d\n", s->poc, poc);
669 if (s->avctx->err_recognition & AV_EF_EXPLODE)
670 return AVERROR_INVALIDDATA;
671 poc = s->poc;
672 }
673 19025 s->poc = poc;
674
675 19025 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
676 19025 pos = get_bits_left(gb);
677
2/2
✓ Branch 0 taken 3213 times.
✓ Branch 1 taken 15812 times.
19025 if (!sh->short_term_ref_pic_set_sps_flag) {
678 3213 ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, s->ps.sps, 1);
679
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3213 times.
3213 if (ret < 0)
680 return ret;
681
682 3213 sh->short_term_rps = &sh->slice_rps;
683 } else {
684 int numbits, rps_idx;
685
686
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15812 times.
15812 if (!s->ps.sps->nb_st_rps) {
687 av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
688 return AVERROR_INVALIDDATA;
689 }
690
691 15812 numbits = av_ceil_log2(s->ps.sps->nb_st_rps);
692
2/2
✓ Branch 0 taken 15784 times.
✓ Branch 1 taken 28 times.
15812 rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
693 15812 sh->short_term_rps = &s->ps.sps->st_rps[rps_idx];
694 }
695 19025 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
696
697 19025 pos = get_bits_left(gb);
698 19025 ret = decode_lt_rps(s, &sh->long_term_rps, gb);
699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19025 times.
19025 if (ret < 0) {
700 av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
701 if (s->avctx->err_recognition & AV_EF_EXPLODE)
702 return AVERROR_INVALIDDATA;
703 }
704 19025 sh->long_term_ref_pic_set_size = pos - get_bits_left(gb);
705
706
2/2
✓ Branch 0 taken 16594 times.
✓ Branch 1 taken 2431 times.
19025 if (s->ps.sps->sps_temporal_mvp_enabled_flag)
707 16594 sh->slice_temporal_mvp_enabled_flag = get_bits1(gb);
708 else
709 2431 sh->slice_temporal_mvp_enabled_flag = 0;
710 } else {
711 586 s->sh.short_term_rps = NULL;
712 586 s->poc = 0;
713 }
714
715 /* 8.3.1 */
716
4/4
✓ Branch 0 taken 9527 times.
✓ Branch 1 taken 10084 times.
✓ Branch 2 taken 9184 times.
✓ Branch 3 taken 343 times.
19611 if (sh->first_slice_in_pic_flag && s->temporal_id == 0 &&
717
2/2
✓ Branch 0 taken 6725 times.
✓ Branch 1 taken 2459 times.
9184 s->nal_unit_type != HEVC_NAL_TRAIL_N &&
718
1/2
✓ Branch 0 taken 6725 times.
✗ Branch 1 not taken.
6725 s->nal_unit_type != HEVC_NAL_TSA_N &&
719
1/2
✓ Branch 0 taken 6725 times.
✗ Branch 1 not taken.
6725 s->nal_unit_type != HEVC_NAL_STSA_N &&
720
2/2
✓ Branch 0 taken 6703 times.
✓ Branch 1 taken 22 times.
6725 s->nal_unit_type != HEVC_NAL_RADL_N &&
721
2/2
✓ Branch 0 taken 6684 times.
✓ Branch 1 taken 19 times.
6703 s->nal_unit_type != HEVC_NAL_RADL_R &&
722
2/2
✓ Branch 0 taken 6327 times.
✓ Branch 1 taken 357 times.
6684 s->nal_unit_type != HEVC_NAL_RASL_N &&
723
2/2
✓ Branch 0 taken 5858 times.
✓ Branch 1 taken 469 times.
6327 s->nal_unit_type != HEVC_NAL_RASL_R)
724 5858 s->pocTid0 = s->poc;
725
726
2/2
✓ Branch 0 taken 16098 times.
✓ Branch 1 taken 3513 times.
19611 if (s->ps.sps->sao_enabled) {
727 16098 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
728
2/2
✓ Branch 0 taken 16096 times.
✓ Branch 1 taken 2 times.
16098 if (s->ps.sps->chroma_format_idc) {
729 16096 sh->slice_sample_adaptive_offset_flag[1] =
730 16096 sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb);
731 }
732 } else {
733 3513 sh->slice_sample_adaptive_offset_flag[0] = 0;
734 3513 sh->slice_sample_adaptive_offset_flag[1] = 0;
735 3513 sh->slice_sample_adaptive_offset_flag[2] = 0;
736 }
737
738 19611 sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
739
4/4
✓ Branch 0 taken 15871 times.
✓ Branch 1 taken 3740 times.
✓ Branch 2 taken 14743 times.
✓ Branch 3 taken 1128 times.
19611 if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
740 int nb_refs;
741
742 18483 sh->nb_refs[L0] = s->ps.pps->num_ref_idx_l0_default_active;
743
2/2
✓ Branch 0 taken 14743 times.
✓ Branch 1 taken 3740 times.
18483 if (sh->slice_type == HEVC_SLICE_B)
744 14743 sh->nb_refs[L1] = s->ps.pps->num_ref_idx_l1_default_active;
745
746
2/2
✓ Branch 1 taken 4860 times.
✓ Branch 2 taken 13623 times.
18483 if (get_bits1(gb)) { // num_ref_idx_active_override_flag
747 4860 sh->nb_refs[L0] = get_ue_golomb_long(gb) + 1;
748
2/2
✓ Branch 0 taken 2699 times.
✓ Branch 1 taken 2161 times.
4860 if (sh->slice_type == HEVC_SLICE_B)
749 2699 sh->nb_refs[L1] = get_ue_golomb_long(gb) + 1;
750 }
751
2/4
✓ Branch 0 taken 18483 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18483 times.
18483 if (sh->nb_refs[L0] > HEVC_MAX_REFS || sh->nb_refs[L1] > HEVC_MAX_REFS) {
752 av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n",
753 sh->nb_refs[L0], sh->nb_refs[L1]);
754 return AVERROR_INVALIDDATA;
755 }
756
757 18483 sh->rpl_modification_flag[0] = 0;
758 18483 sh->rpl_modification_flag[1] = 0;
759 18483 nb_refs = ff_hevc_frame_nb_refs(s);
760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18483 times.
18483 if (!nb_refs) {
761 av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
762 return AVERROR_INVALIDDATA;
763 }
764
765
4/4
✓ Branch 0 taken 1653 times.
✓ Branch 1 taken 16830 times.
✓ Branch 2 taken 1596 times.
✓ Branch 3 taken 57 times.
18483 if (s->ps.pps->lists_modification_present_flag && nb_refs > 1) {
766 1596 sh->rpl_modification_flag[0] = get_bits1(gb);
767
2/2
✓ Branch 0 taken 1176 times.
✓ Branch 1 taken 420 times.
1596 if (sh->rpl_modification_flag[0]) {
768
2/2
✓ Branch 0 taken 2779 times.
✓ Branch 1 taken 1176 times.
3955 for (i = 0; i < sh->nb_refs[L0]; i++)
769 2779 sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs));
770 }
771
772
1/2
✓ Branch 0 taken 1596 times.
✗ Branch 1 not taken.
1596 if (sh->slice_type == HEVC_SLICE_B) {
773 1596 sh->rpl_modification_flag[1] = get_bits1(gb);
774
2/2
✓ Branch 0 taken 652 times.
✓ Branch 1 taken 944 times.
1596 if (sh->rpl_modification_flag[1] == 1)
775
2/2
✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
2207 for (i = 0; i < sh->nb_refs[L1]; i++)
776 1555 sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs));
777 }
778 }
779
780
2/2
✓ Branch 0 taken 14743 times.
✓ Branch 1 taken 3740 times.
18483 if (sh->slice_type == HEVC_SLICE_B)
781 14743 sh->mvd_l1_zero_flag = get_bits1(gb);
782
783
2/2
✓ Branch 0 taken 15792 times.
✓ Branch 1 taken 2691 times.
18483 if (s->ps.pps->cabac_init_present_flag)
784 15792 sh->cabac_init_flag = get_bits1(gb);
785 else
786 2691 sh->cabac_init_flag = 0;
787
788 18483 sh->collocated_ref_idx = 0;
789
2/2
✓ Branch 0 taken 16146 times.
✓ Branch 1 taken 2337 times.
18483 if (sh->slice_temporal_mvp_enabled_flag) {
790 16146 sh->collocated_list = L0;
791
2/2
✓ Branch 0 taken 14241 times.
✓ Branch 1 taken 1905 times.
16146 if (sh->slice_type == HEVC_SLICE_B)
792 14241 sh->collocated_list = !get_bits1(gb);
793
794
2/2
✓ Branch 0 taken 14395 times.
✓ Branch 1 taken 1751 times.
16146 if (sh->nb_refs[sh->collocated_list] > 1) {
795 14395 sh->collocated_ref_idx = get_ue_golomb_long(gb);
796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14395 times.
14395 if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) {
797 av_log(s->avctx, AV_LOG_ERROR,
798 "Invalid collocated_ref_idx: %d.\n",
799 sh->collocated_ref_idx);
800 return AVERROR_INVALIDDATA;
801 }
802 }
803 }
804
805
4/4
✓ Branch 0 taken 1431 times.
✓ Branch 1 taken 17052 times.
✓ Branch 2 taken 664 times.
✓ Branch 3 taken 767 times.
18483 if ((s->ps.pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
806
3/4
✓ Branch 0 taken 639 times.
✓ Branch 1 taken 17077 times.
✓ Branch 2 taken 639 times.
✗ Branch 3 not taken.
17716 (s->ps.pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
807 1406 int ret = pred_weight_table(s, gb);
808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1406 times.
1406 if (ret < 0)
809 return ret;
810 }
811
812 18483 sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
813
2/4
✓ Branch 0 taken 18483 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18483 times.
18483 if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
814 av_log(s->avctx, AV_LOG_ERROR,
815 "Invalid number of merging MVP candidates: %d.\n",
816 sh->max_num_merge_cand);
817 return AVERROR_INVALIDDATA;
818 }
819 }
820
821 19611 sh->slice_qp_delta = get_se_golomb(gb);
822
823
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 19361 times.
19611 if (s->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag) {
824 250 sh->slice_cb_qp_offset = get_se_golomb(gb);
825 250 sh->slice_cr_qp_offset = get_se_golomb(gb);
826
2/4
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 250 times.
✗ Branch 3 not taken.
250 if (sh->slice_cb_qp_offset < -12 || sh->slice_cb_qp_offset > 12 ||
827
2/4
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 250 times.
250 sh->slice_cr_qp_offset < -12 || sh->slice_cr_qp_offset > 12) {
828 av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n");
829 return AVERROR_INVALIDDATA;
830 }
831 } else {
832 19361 sh->slice_cb_qp_offset = 0;
833 19361 sh->slice_cr_qp_offset = 0;
834 }
835
836
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 19568 times.
19611 if (s->ps.pps->chroma_qp_offset_list_enabled_flag)
837 43 sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
838 else
839 19568 sh->cu_chroma_qp_offset_enabled_flag = 0;
840
841
2/2
✓ Branch 0 taken 2897 times.
✓ Branch 1 taken 16714 times.
19611 if (s->ps.pps->deblocking_filter_control_present_flag) {
842 2897 int deblocking_filter_override_flag = 0;
843
844
2/2
✓ Branch 0 taken 673 times.
✓ Branch 1 taken 2224 times.
2897 if (s->ps.pps->deblocking_filter_override_enabled_flag)
845 673 deblocking_filter_override_flag = get_bits1(gb);
846
847
2/2
✓ Branch 0 taken 454 times.
✓ Branch 1 taken 2443 times.
2897 if (deblocking_filter_override_flag) {
848 454 sh->disable_deblocking_filter_flag = get_bits1(gb);
849
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 120 times.
454 if (!sh->disable_deblocking_filter_flag) {
850 334 int beta_offset_div2 = get_se_golomb(gb);
851 334 int tc_offset_div2 = get_se_golomb(gb) ;
852
3/6
✓ Branch 0 taken 334 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 334 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 334 times.
✗ Branch 5 not taken.
334 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334 times.
334 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
854 av_log(s->avctx, AV_LOG_ERROR,
855 "Invalid deblock filter offsets: %d, %d\n",
856 beta_offset_div2, tc_offset_div2);
857 return AVERROR_INVALIDDATA;
858 }
859 334 sh->beta_offset = beta_offset_div2 * 2;
860 334 sh->tc_offset = tc_offset_div2 * 2;
861 }
862 } else {
863 2443 sh->disable_deblocking_filter_flag = s->ps.pps->disable_dbf;
864 2443 sh->beta_offset = s->ps.pps->beta_offset;
865 2443 sh->tc_offset = s->ps.pps->tc_offset;
866 }
867 } else {
868 16714 sh->disable_deblocking_filter_flag = 0;
869 16714 sh->beta_offset = 0;
870 16714 sh->tc_offset = 0;
871 }
872
873
2/2
✓ Branch 0 taken 17078 times.
✓ Branch 1 taken 2533 times.
19611 if (s->ps.pps->seq_loop_filter_across_slices_enabled_flag &&
874
2/2
✓ Branch 0 taken 11467 times.
✓ Branch 1 taken 5611 times.
17078 (sh->slice_sample_adaptive_offset_flag[0] ||
875
2/2
✓ Branch 0 taken 11449 times.
✓ Branch 1 taken 18 times.
11467 sh->slice_sample_adaptive_offset_flag[1] ||
876
2/2
✓ Branch 0 taken 11386 times.
✓ Branch 1 taken 63 times.
11449 !sh->disable_deblocking_filter_flag)) {
877 17015 sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb);
878 } else {
879 2596 sh->slice_loop_filter_across_slices_enabled_flag = s->ps.pps->seq_loop_filter_across_slices_enabled_flag;
880 }
881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
7947 } else if (!s->slice_initialized) {
882 av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
883 return AVERROR_INVALIDDATA;
884 }
885
886 27558 sh->num_entry_point_offsets = 0;
887
4/4
✓ Branch 0 taken 24651 times.
✓ Branch 1 taken 2907 times.
✓ Branch 2 taken 4572 times.
✓ Branch 3 taken 20079 times.
27558 if (s->ps.pps->tiles_enabled_flag || s->ps.pps->entropy_coding_sync_enabled_flag) {
888 7479 unsigned num_entry_point_offsets = get_ue_golomb_long(gb);
889 // It would be possible to bound this tighter but this here is simpler
890
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7479 times.
7479 if (num_entry_point_offsets > get_bits_left(gb)) {
891 av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
892 return AVERROR_INVALIDDATA;
893 }
894
895 7479 sh->num_entry_point_offsets = num_entry_point_offsets;
896
2/2
✓ Branch 0 taken 2009 times.
✓ Branch 1 taken 5470 times.
7479 if (sh->num_entry_point_offsets > 0) {
897 2009 int offset_len = get_ue_golomb_long(gb) + 1;
898
899
2/4
✓ Branch 0 taken 2009 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2009 times.
2009 if (offset_len < 1 || offset_len > 32) {
900 sh->num_entry_point_offsets = 0;
901 av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len);
902 return AVERROR_INVALIDDATA;
903 }
904
905 2009 av_freep(&sh->entry_point_offset);
906 2009 av_freep(&sh->offset);
907 2009 av_freep(&sh->size);
908 2009 sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
909 2009 sh->offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(int));
910 2009 sh->size = av_malloc_array(sh->num_entry_point_offsets, sizeof(int));
911
3/6
✓ Branch 0 taken 2009 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2009 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2009 times.
2009 if (!sh->entry_point_offset || !sh->offset || !sh->size) {
912 sh->num_entry_point_offsets = 0;
913 av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
914 return AVERROR(ENOMEM);
915 }
916
2/2
✓ Branch 0 taken 7772 times.
✓ Branch 1 taken 2009 times.
9781 for (i = 0; i < sh->num_entry_point_offsets; i++) {
917 7772 unsigned val = get_bits_long(gb, offset_len);
918 7772 sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
919 }
920
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2009 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2009 if (s->threads_number > 1 && (s->ps.pps->num_tile_rows > 1 || s->ps.pps->num_tile_columns > 1)) {
921 s->enable_parallel_tiles = 0; // TODO: you can enable tiles in parallel here
922 s->threads_number = 1;
923 } else
924 2009 s->enable_parallel_tiles = 0;
925 } else
926 5470 s->enable_parallel_tiles = 0;
927 }
928
929
2/2
✓ Branch 0 taken 2765 times.
✓ Branch 1 taken 24793 times.
27558 if (s->ps.pps->slice_header_extension_present_flag) {
930 2765 unsigned int length = get_ue_golomb_long(gb);
931
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2765 times.
2765 if (length*8LL > get_bits_left(gb)) {
932 av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n");
933 return AVERROR_INVALIDDATA;
934 }
935
2/2
✓ Branch 0 taken 20264 times.
✓ Branch 1 taken 2765 times.
23029 for (i = 0; i < length; i++)
936 20264 skip_bits(gb, 8); // slice_header_extension_data_byte
937 }
938
939 // Inferred parameters
940 27558 sh->slice_qp = 26U + s->ps.pps->pic_init_qp_minus26 + sh->slice_qp_delta;
941
1/2
✓ Branch 0 taken 27558 times.
✗ Branch 1 not taken.
27558 if (sh->slice_qp > 51 ||
942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27558 times.
27558 sh->slice_qp < -s->ps.sps->qp_bd_offset) {
943 av_log(s->avctx, AV_LOG_ERROR,
944 "The slice_qp %d is outside the valid range "
945 "[%d, 51].\n",
946 sh->slice_qp,
947 -s->ps.sps->qp_bd_offset);
948 return AVERROR_INVALIDDATA;
949 }
950
951 27558 sh->slice_ctb_addr_rs = sh->slice_segment_addr;
952
953
3/4
✓ Branch 0 taken 9527 times.
✓ Branch 1 taken 18031 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9527 times.
27558 if (!s->sh.slice_ctb_addr_rs && s->sh.dependent_slice_segment_flag) {
954 av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
955 return AVERROR_INVALIDDATA;
956 }
957
958
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27558 times.
27558 if (get_bits_left(gb) < 0) {
959 av_log(s->avctx, AV_LOG_ERROR,
960 "Overread slice header by %d bits\n", -get_bits_left(gb));
961 return AVERROR_INVALIDDATA;
962 }
963
964 27558 s->HEVClc->first_qp_group = !s->sh.dependent_slice_segment_flag;
965
966
2/2
✓ Branch 0 taken 22562 times.
✓ Branch 1 taken 4996 times.
27558 if (!s->ps.pps->cu_qp_delta_enabled_flag)
967 22562 s->HEVClc->qp_y = s->sh.slice_qp;
968
969 27558 s->slice_initialized = 1;
970 27558 s->HEVClc->tu.cu_qp_offset_cb = 0;
971 27558 s->HEVClc->tu.cu_qp_offset_cr = 0;
972
973 27558 return 0;
974 }
975
976 #define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)])
977
978 #define SET_SAO(elem, value) \
979 do { \
980 if (!sao_merge_up_flag && !sao_merge_left_flag) \
981 sao->elem = value; \
982 else if (sao_merge_left_flag) \
983 sao->elem = CTB(s->sao, rx-1, ry).elem; \
984 else if (sao_merge_up_flag) \
985 sao->elem = CTB(s->sao, rx, ry-1).elem; \
986 else \
987 sao->elem = 0; \
988 } while (0)
989
990 1395566 static void hls_sao_param(HEVCContext *s, int rx, int ry)
991 {
992 1395566 HEVCLocalContext *lc = s->HEVClc;
993 1395566 int sao_merge_left_flag = 0;
994 1395566 int sao_merge_up_flag = 0;
995 1395566 SAOParams *sao = &CTB(s->sao, rx, ry);
996 int c_idx, i;
997
998
2/2
✓ Branch 0 taken 816170 times.
✓ Branch 1 taken 579396 times.
1395566 if (s->sh.slice_sample_adaptive_offset_flag[0] ||
999
2/2
✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 814526 times.
816170 s->sh.slice_sample_adaptive_offset_flag[1]) {
1000
2/2
✓ Branch 0 taken 550593 times.
✓ Branch 1 taken 30447 times.
581040 if (rx > 0) {
1001
2/2
✓ Branch 0 taken 542104 times.
✓ Branch 1 taken 8489 times.
550593 if (lc->ctb_left_flag)
1002 542104 sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(s);
1003 }
1004
4/4
✓ Branch 0 taken 531489 times.
✓ Branch 1 taken 49551 times.
✓ Branch 2 taken 258964 times.
✓ Branch 3 taken 272525 times.
581040 if (ry > 0 && !sao_merge_left_flag) {
1005
2/2
✓ Branch 0 taken 245616 times.
✓ Branch 1 taken 13348 times.
258964 if (lc->ctb_up_flag)
1006 245616 sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(s);
1007 }
1008 }
1009
1010
4/4
✓ Branch 0 taken 5582072 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4186602 times.
✓ Branch 3 taken 1395566 times.
5582168 for (c_idx = 0; c_idx < (s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) {
1011
2/2
✓ Branch 0 taken 1395566 times.
✓ Branch 1 taken 2791036 times.
4186602 int log2_sao_offset_scale = c_idx == 0 ? s->ps.pps->log2_sao_offset_scale_luma :
1012 2791036 s->ps.pps->log2_sao_offset_scale_chroma;
1013
1014
2/2
✓ Branch 0 taken 2945486 times.
✓ Branch 1 taken 1241116 times.
4186602 if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1015 2945486 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
1016 2945486 continue;
1017 }
1018
1019
2/2
✓ Branch 0 taken 330860 times.
✓ Branch 1 taken 910256 times.
1241116 if (c_idx == 2) {
1020 330860 sao->type_idx[2] = sao->type_idx[1];
1021 330860 sao->eo_class[2] = sao->eo_class[1];
1022 } else {
1023
7/8
✓ Branch 0 taken 788671 times.
✓ Branch 1 taken 121585 times.
✓ Branch 2 taken 354383 times.
✓ Branch 3 taken 434288 times.
✓ Branch 5 taken 434288 times.
✓ Branch 6 taken 121585 times.
✓ Branch 7 taken 121585 times.
✗ Branch 8 not taken.
910256 SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(s));
1024 }
1025
1026
2/2
✓ Branch 0 taken 750144 times.
✓ Branch 1 taken 490972 times.
1241116 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
1027 750144 continue;
1028
1029
2/2
✓ Branch 0 taken 1963888 times.
✓ Branch 1 taken 490972 times.
2454860 for (i = 0; i < 4; i++)
1030
7/8
✓ Branch 0 taken 1621612 times.
✓ Branch 1 taken 342276 times.
✓ Branch 2 taken 864724 times.
✓ Branch 3 taken 756888 times.
✓ Branch 5 taken 756888 times.
✓ Branch 6 taken 342276 times.
✓ Branch 7 taken 342276 times.
✗ Branch 8 not taken.
1963888 SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(s));
1031
1032
2/2
✓ Branch 0 taken 116053 times.
✓ Branch 1 taken 374919 times.
490972 if (sao->type_idx[c_idx] == SAO_BAND) {
1033
2/2
✓ Branch 0 taken 464212 times.
✓ Branch 1 taken 116053 times.
580265 for (i = 0; i < 4; i++) {
1034
2/2
✓ Branch 0 taken 350469 times.
✓ Branch 1 taken 113743 times.
464212 if (sao->offset_abs[c_idx][i]) {
1035
7/8
✓ Branch 0 taken 326635 times.
✓ Branch 1 taken 23834 times.
✓ Branch 2 taken 242504 times.
✓ Branch 3 taken 84131 times.
✓ Branch 5 taken 84131 times.
✓ Branch 6 taken 23834 times.
✓ Branch 7 taken 23834 times.
✗ Branch 8 not taken.
350469 SET_SAO(offset_sign[c_idx][i],
1036 ff_hevc_sao_offset_sign_decode(s));
1037 } else {
1038 113743 sao->offset_sign[c_idx][i] = 0;
1039 }
1040 }
1041
7/8
✓ Branch 0 taken 106461 times.
✓ Branch 1 taken 9592 times.
✓ Branch 2 taken 77629 times.
✓ Branch 3 taken 28832 times.
✓ Branch 5 taken 28832 times.
✓ Branch 6 taken 9592 times.
✓ Branch 7 taken 9592 times.
✗ Branch 8 not taken.
116053 SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(s));
1042
2/2
✓ Branch 0 taken 300225 times.
✓ Branch 1 taken 74694 times.
374919 } else if (c_idx != 2) {
1043
7/8
✓ Branch 0 taken 239326 times.
✓ Branch 1 taken 60899 times.
✓ Branch 2 taken 107851 times.
✓ Branch 3 taken 131475 times.
✓ Branch 5 taken 131475 times.
✓ Branch 6 taken 60899 times.
✓ Branch 7 taken 60899 times.
✗ Branch 8 not taken.
300225 SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(s));
1044 }
1045
1046 // Inferred parameters
1047 490972 sao->offset_val[c_idx][0] = 0;
1048
2/2
✓ Branch 0 taken 1963888 times.
✓ Branch 1 taken 490972 times.
2454860 for (i = 0; i < 4; i++) {
1049 1963888 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
1050
2/2
✓ Branch 0 taken 1499676 times.
✓ Branch 1 taken 464212 times.
1963888 if (sao->type_idx[c_idx] == SAO_EDGE) {
1051
2/2
✓ Branch 0 taken 749838 times.
✓ Branch 1 taken 749838 times.
1499676 if (i > 1)
1052 749838 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1053
2/2
✓ Branch 0 taken 154423 times.
✓ Branch 1 taken 309789 times.
464212 } else if (sao->offset_sign[c_idx][i]) {
1054 154423 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1055 }
1056 1963888 sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale;
1057 }
1058 }
1059 1395566 }
1060
1061 #undef SET_SAO
1062 #undef CTB
1063
1064 384850 static int hls_cross_component_pred(HEVCContext *s, int idx) {
1065 384850 HEVCLocalContext *lc = s->HEVClc;
1066 384850 int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(s, idx);
1067
1068
2/2
✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
384850 if (log2_res_scale_abs_plus1 != 0) {
1069 235843 int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(s, idx);
1070 235843 lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) *
1071 235843 (1 - 2 * res_scale_sign_flag);
1072 } else {
1073 149007 lc->tu.res_scale_val = 0;
1074 }
1075
1076
1077 384850 return 0;
1078 }
1079
1080 15172724 static int hls_transform_unit(HEVCContext *s, int x0, int y0,
1081 int xBase, int yBase, int cb_xBase, int cb_yBase,
1082 int log2_cb_size, int log2_trafo_size,
1083 int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
1084 {
1085 15172724 HEVCLocalContext *lc = s->HEVClc;
1086 15172724 const int log2_trafo_size_c = log2_trafo_size - s->ps.sps->hshift[1];
1087 int i;
1088
1089
2/2
✓ Branch 0 taken 9580799 times.
✓ Branch 1 taken 5591925 times.
15172724 if (lc->cu.pred_mode == MODE_INTRA) {
1090 9580799 int trafo_size = 1 << log2_trafo_size;
1091 9580799 ff_hevc_set_neighbour_available(s, x0, y0, trafo_size, trafo_size);
1092
1093 9580799 s->hpc.intra_pred[log2_trafo_size - 2](s, x0, y0, 0);
1094 }
1095
1096
6/6
✓ Branch 0 taken 5544978 times.
✓ Branch 1 taken 9627746 times.
✓ Branch 2 taken 4920991 times.
✓ Branch 3 taken 623987 times.
✓ Branch 4 taken 4505061 times.
✓ Branch 5 taken 415930 times.
15172724 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1097
6/6
✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4349294 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
15234538 (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1098 10729478 int scan_idx = SCAN_DIAG;
1099 10729478 int scan_idx_c = SCAN_DIAG;
1100
4/4
✓ Branch 0 taken 7170909 times.
✓ Branch 1 taken 3558569 times.
✓ Branch 2 taken 5737534 times.
✓ Branch 3 taken 1433375 times.
16467012 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1101
2/2
✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 5505824 times.
5737534 (s->ps.sps->chroma_format_idc == 2 &&
1102
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]));
1103
1104
4/4
✓ Branch 0 taken 2090082 times.
✓ Branch 1 taken 8639396 times.
✓ Branch 2 taken 579409 times.
✓ Branch 3 taken 1510673 times.
10729478 if (s->ps.pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
1105 579409 lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(s);
1106
2/2
✓ Branch 0 taken 364453 times.
✓ Branch 1 taken 214956 times.
579409 if (lc->tu.cu_qp_delta != 0)
1107
2/2
✓ Branch 1 taken 201451 times.
✓ Branch 2 taken 163002 times.
364453 if (ff_hevc_cu_qp_delta_sign_flag(s) == 1)
1108 201451 lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1109 579409 lc->tu.is_cu_qp_delta_coded = 1;
1110
1111
2/2
✓ Branch 0 taken 579408 times.
✓ Branch 1 taken 1 times.
579409 if (lc->tu.cu_qp_delta < -(26 + s->ps.sps->qp_bd_offset / 2) ||
1112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 579408 times.
579408 lc->tu.cu_qp_delta > (25 + s->ps.sps->qp_bd_offset / 2)) {
1113 1 av_log(s->avctx, AV_LOG_ERROR,
1114 "The cu_qp_delta %d is outside the valid range "
1115 "[%d, %d].\n",
1116 lc->tu.cu_qp_delta,
1117 1 -(26 + s->ps.sps->qp_bd_offset / 2),
1118 1 (25 + s->ps.sps->qp_bd_offset / 2));
1119 1 return AVERROR_INVALIDDATA;
1120 }
1121
1122 579408 ff_hevc_set_qPy(s, cb_xBase, cb_yBase, log2_cb_size);
1123 }
1124
1125
4/4
✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 9837526 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
10729477 if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1126
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) {
1127 266275 int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(s);
1128
2/2
✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
266275 if (cu_chroma_qp_offset_flag) {
1129 48966 int cu_chroma_qp_offset_idx = 0;
1130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
48966 if (s->ps.pps->chroma_qp_offset_list_len_minus1 > 0) {
1131 cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(s);
1132 av_log(s->avctx, AV_LOG_ERROR,
1133 "cu_chroma_qp_offset_idx not yet tested.\n");
1134 }
1135 48966 lc->tu.cu_qp_offset_cb = s->ps.pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
1136 48966 lc->tu.cu_qp_offset_cr = s->ps.pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
1137 } else {
1138 217309 lc->tu.cu_qp_offset_cb = 0;
1139 217309 lc->tu.cu_qp_offset_cr = 0;
1140 }
1141 266275 lc->tu.is_cu_chroma_qp_offset_coded = 1;
1142 }
1143
1144
4/4
✓ Branch 0 taken 7063560 times.
✓ Branch 1 taken 3665917 times.
✓ Branch 2 taken 6203876 times.
✓ Branch 3 taken 859684 times.
10729477 if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1145
2/2
✓ Branch 0 taken 4131022 times.
✓ Branch 1 taken 2072854 times.
6203876 if (lc->tu.intra_pred_mode >= 6 &&
1146
2/2
✓ Branch 0 taken 1495476 times.
✓ Branch 1 taken 2635546 times.
4131022 lc->tu.intra_pred_mode <= 14) {
1147 1495476 scan_idx = SCAN_VERT;
1148
2/2
✓ Branch 0 taken 2032767 times.
✓ Branch 1 taken 2675633 times.
4708400 } else if (lc->tu.intra_pred_mode >= 22 &&
1149
2/2
✓ Branch 0 taken 1707810 times.
✓ Branch 1 taken 324957 times.
2032767 lc->tu.intra_pred_mode <= 30) {
1150 1707810 scan_idx = SCAN_HORIZ;
1151 }
1152
1153
2/2
✓ Branch 0 taken 3703488 times.
✓ Branch 1 taken 2500388 times.
6203876 if (lc->tu.intra_pred_mode_c >= 6 &&
1154
2/2
✓ Branch 0 taken 1406708 times.
✓ Branch 1 taken 2296780 times.
3703488 lc->tu.intra_pred_mode_c <= 14) {
1155 1406708 scan_idx_c = SCAN_VERT;
1156
2/2
✓ Branch 0 taken 1930116 times.
✓ Branch 1 taken 2867052 times.
4797168 } else if (lc->tu.intra_pred_mode_c >= 22 &&
1157
2/2
✓ Branch 0 taken 1615119 times.
✓ Branch 1 taken 314997 times.
1930116 lc->tu.intra_pred_mode_c <= 30) {
1158 1615119 scan_idx_c = SCAN_HORIZ;
1159 }
1160 }
1161
1162 10729477 lc->tu.cross_pf = 0;
1163
1164
2/2
✓ Branch 0 taken 9627745 times.
✓ Branch 1 taken 1101732 times.
10729477 if (cbf_luma)
1165 9627745 ff_hevc_hls_residual_coding(s, x0, y0, log2_trafo_size, scan_idx, 0);
1166
6/6
✓ Branch 0 taken 10729285 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6059301 times.
✓ Branch 3 taken 4669984 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 5849738 times.
15609024 if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) {
1167 4879547 int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]);
1168 4879547 int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
1169
4/4
✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 4542706 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
5097363 lc->tu.cross_pf = (s->ps.pps->cross_component_prediction_enabled_flag && cbf_luma &&
1170
2/2
✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
217816 (lc->cu.pred_mode == MODE_INTER ||
1171
2/2
✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
168873 (lc->tu.chroma_mode_c == 4)));
1172
1173
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4687122 times.
4879547 if (lc->tu.cross_pf) {
1174 192425 hls_cross_component_pred(s, 0);
1175 }
1176
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8852690 times.
✓ Branch 2 taken 5332749 times.
✓ Branch 3 taken 4879547 times.
10212296 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1177
2/2
✓ Branch 0 taken 2955509 times.
✓ Branch 1 taken 2377240 times.
5332749 if (lc->cu.pred_mode == MODE_INTRA) {
1178 2955509 ff_hevc_set_neighbour_available(s, x0, y0 + (i << log2_trafo_size_c), trafo_size_h, trafo_size_v);
1179 2955509 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (i << log2_trafo_size_c), 1);
1180 }
1181
2/2
✓ Branch 0 taken 1487677 times.
✓ Branch 1 taken 3845072 times.
5332749 if (cbf_cb[i])
1182 1487677 ff_hevc_hls_residual_coding(s, x0, y0 + (i << log2_trafo_size_c),
1183 log2_trafo_size_c, scan_idx_c, 1);
1184 else
1185
2/2
✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 3805414 times.
3845072 if (lc->tu.cross_pf) {
1186 39658 ptrdiff_t stride = s->frame->linesize[1];
1187 39658 int hshift = s->ps.sps->hshift[1];
1188 39658 int vshift = s->ps.sps->vshift[1];
1189 39658 int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1190 39658 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1191 39658 int size = 1 << log2_trafo_size_c;
1192
1193 39658 uint8_t *dst = &s->frame->data[1][(y0 >> vshift) * stride +
1194 39658 ((x0 >> hshift) << s->ps.sps->pixel_shift)];
1195
2/2
✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
1871162 for (i = 0; i < (size * size); i++) {
1196 1831504 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1197 }
1198 39658 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1199 }
1200 }
1201
1202
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4687122 times.
4879547 if (lc->tu.cross_pf) {
1203 192425 hls_cross_component_pred(s, 1);
1204 }
1205
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8852690 times.
✓ Branch 2 taken 5332749 times.
✓ Branch 3 taken 4879547 times.
10212296 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1206
2/2
✓ Branch 0 taken 2955509 times.
✓ Branch 1 taken 2377240 times.
5332749 if (lc->cu.pred_mode == MODE_INTRA) {
1207 2955509 ff_hevc_set_neighbour_available(s, x0, y0 + (i << log2_trafo_size_c), trafo_size_h, trafo_size_v);
1208 2955509 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (i << log2_trafo_size_c), 2);
1209 }
1210
2/2
✓ Branch 0 taken 1600461 times.
✓ Branch 1 taken 3732288 times.
5332749 if (cbf_cr[i])
1211 1600461 ff_hevc_hls_residual_coding(s, x0, y0 + (i << log2_trafo_size_c),
1212 log2_trafo_size_c, scan_idx_c, 2);
1213 else
1214
2/2
✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 3656364 times.
3732288 if (lc->tu.cross_pf) {
1215 75924 ptrdiff_t stride = s->frame->linesize[2];
1216 75924 int hshift = s->ps.sps->hshift[2];
1217 75924 int vshift = s->ps.sps->vshift[2];
1218 75924 int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1219 75924 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1220 75924 int size = 1 << log2_trafo_size_c;
1221
1222 75924 uint8_t *dst = &s->frame->data[2][(y0 >> vshift) * stride +
1223 75924 ((x0 >> hshift) << s->ps.sps->pixel_shift)];
1224
2/2
✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
3691476 for (i = 0; i < (size * size); i++) {
1225 3615552 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1226 }
1227 75924 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1228 }
1229 }
1230
4/4
✓ Branch 0 taken 5849738 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1502764 times.
✓ Branch 3 taken 4346974 times.
5849930 } else if (s->ps.sps->chroma_format_idc && blk_idx == 3) {
1231 1502764 int trafo_size_h = 1 << (log2_trafo_size + 1);
1232 1502764 int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]);
1233
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2671790 times.
✓ Branch 2 taken 1669633 times.
✓ Branch 3 taken 1502764 times.
3172397 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1234
2/2
✓ Branch 0 taken 1189546 times.
✓ Branch 1 taken 480087 times.
1669633 if (lc->cu.pred_mode == MODE_INTRA) {
1235 1189546 ff_hevc_set_neighbour_available(s, xBase, yBase + (i << log2_trafo_size),
1236 trafo_size_h, trafo_size_v);
1237 1189546 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (i << log2_trafo_size), 1);
1238 }
1239
2/2
✓ Branch 0 taken 632317 times.
✓ Branch 1 taken 1037316 times.
1669633 if (cbf_cb[i])
1240 632317 ff_hevc_hls_residual_coding(s, xBase, yBase + (i << log2_trafo_size),
1241 log2_trafo_size, scan_idx_c, 1);
1242 }
1243
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2671790 times.
✓ Branch 2 taken 1669633 times.
✓ Branch 3 taken 1502764 times.
3172397 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1244
2/2
✓ Branch 0 taken 1189546 times.
✓ Branch 1 taken 480087 times.
1669633 if (lc->cu.pred_mode == MODE_INTRA) {
1245 1189546 ff_hevc_set_neighbour_available(s, xBase, yBase + (i << log2_trafo_size),
1246 trafo_size_h, trafo_size_v);
1247 1189546 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (i << log2_trafo_size), 2);
1248 }
1249
2/2
✓ Branch 0 taken 713175 times.
✓ Branch 1 taken 956458 times.
1669633 if (cbf_cr[i])
1250 713175 ff_hevc_hls_residual_coding(s, xBase, yBase + (i << log2_trafo_size),
1251 log2_trafo_size, scan_idx_c, 2);
1252 }
1253 }
1254
3/4
✓ Branch 0 taken 4443246 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2517238 times.
✓ Branch 3 taken 1926008 times.
4443246 } else if (s->ps.sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
1255
4/4
✓ Branch 0 taken 1580799 times.
✓ Branch 1 taken 936439 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1520211 times.
3514265 if (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3) {
1256 997027 int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]);
1257 997027 int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
1258 997027 ff_hevc_set_neighbour_available(s, x0, y0, trafo_size_h, trafo_size_v);
1259 997027 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0, 1);
1260 997027 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0, 2);
1261
2/2
✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 984560 times.
997027 if (s->ps.sps->chroma_format_idc == 2) {
1262 12467 ff_hevc_set_neighbour_available(s, x0, y0 + (1 << log2_trafo_size_c),
1263 trafo_size_h, trafo_size_v);
1264 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (1 << log2_trafo_size_c), 1);
1265 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (1 << log2_trafo_size_c), 2);
1266 }
1267
2/2
✓ Branch 0 taken 345067 times.
✓ Branch 1 taken 1175144 times.
1520211 } else if (blk_idx == 3) {
1268 345067 int trafo_size_h = 1 << (log2_trafo_size + 1);
1269 345067 int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]);
1270 345067 ff_hevc_set_neighbour_available(s, xBase, yBase,
1271 trafo_size_h, trafo_size_v);
1272 345067 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase, 1);
1273 345067 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase, 2);
1274
2/2
✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 340871 times.
345067 if (s->ps.sps->chroma_format_idc == 2) {
1275 4196 ff_hevc_set_neighbour_available(s, xBase, yBase + (1 << (log2_trafo_size)),
1276 trafo_size_h, trafo_size_v);
1277 4196 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (1 << (log2_trafo_size)), 1);
1278 4196 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (1 << (log2_trafo_size)), 2);
1279 }
1280 }
1281 }
1282
1283 15172723 return 0;
1284 }
1285
1286 356478 static void set_deblocking_bypass(HEVCContext *s, int x0, int y0, int log2_cb_size)
1287 {
1288 356478 int cb_size = 1 << log2_cb_size;
1289 356478 int log2_min_pu_size = s->ps.sps->log2_min_pu_size;
1290
1291 356478 int min_pu_width = s->ps.sps->min_pu_width;
1292 356478 int x_end = FFMIN(x0 + cb_size, s->ps.sps->width);
1293 356478 int y_end = FFMIN(y0 + cb_size, s->ps.sps->height);
1294 int i, j;
1295
1296
2/2
✓ Branch 0 taken 494908 times.
✓ Branch 1 taken 356478 times.
851386 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1297
2/2
✓ Branch 0 taken 949056 times.
✓ Branch 1 taken 494908 times.
1443964 for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
1298 949056 s->is_pcm[i + j * min_pu_width] = 2;
1299 356478 }
1300
1301 18330889 static int hls_transform_tree(HEVCContext *s, int x0, int y0,
1302 int xBase, int yBase, int cb_xBase, int cb_yBase,
1303 int log2_cb_size, int log2_trafo_size,
1304 int trafo_depth, int blk_idx,
1305 const int *base_cbf_cb, const int *base_cbf_cr)
1306 {
1307 18330889 HEVCLocalContext *lc = s->HEVClc;
1308 uint8_t split_transform_flag;
1309 int cbf_cb[2];
1310 int cbf_cr[2];
1311 int ret;
1312
1313 18330889 cbf_cb[0] = base_cbf_cb[0];
1314 18330889 cbf_cb[1] = base_cbf_cb[1];
1315 18330889 cbf_cr[0] = base_cbf_cr[0];
1316 18330889 cbf_cr[1] = base_cbf_cr[1];
1317
1318
2/2
✓ Branch 0 taken 6291841 times.
✓ Branch 1 taken 12039048 times.
18330889 if (lc->cu.intra_split_flag) {
1319
2/2
✓ Branch 0 taken 4731412 times.
✓ Branch 1 taken 1560429 times.
6291841 if (trafo_depth == 1) {
1320 4731412 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1321
2/2
✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4596008 times.
4731412 if (s->ps.sps->chroma_format_idc == 3) {
1322 135404 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx];
1323 135404 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx];
1324 } else {
1325 4596008 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1326 4596008 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1327 }
1328 }
1329 } else {
1330 12039048 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0];
1331 12039048 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1332 12039048 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1333 }
1334
1335
2/2
✓ Branch 0 taken 18223011 times.
✓ Branch 1 taken 107878 times.
18330889 if (log2_trafo_size <= s->ps.sps->log2_max_trafo_size &&
1336
2/2
✓ Branch 0 taken 9526155 times.
✓ Branch 1 taken 8696856 times.
18223011 log2_trafo_size > s->ps.sps->log2_min_tb_size &&
1337
2/2
✓ Branch 0 taken 7994453 times.
✓ Branch 1 taken 1531702 times.
9526155 trafo_depth < lc->cu.max_trafo_depth &&
1338
4/4
✓ Branch 0 taken 1666078 times.
✓ Branch 1 taken 6328375 times.
✓ Branch 2 taken 490612 times.
✓ Branch 3 taken 1175466 times.
7994453 !(lc->cu.intra_split_flag && trafo_depth == 0)) {
1339 6818987 split_transform_flag = ff_hevc_split_transform_flag_decode(s, log2_trafo_size);
1340 } else {
1341 24610020 int inter_split = s->ps.sps->max_transform_hierarchy_depth_inter == 0 &&
1342
2/2
✓ Branch 0 taken 834875 times.
✓ Branch 1 taken 751341 times.
1586216 lc->cu.pred_mode == MODE_INTER &&
1343
6/6
✓ Branch 0 taken 1586216 times.
✓ Branch 1 taken 9925686 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 159326 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
13098118 lc->cu.part_mode != PART_2Nx2N &&
1344 trafo_depth == 0;
1345
1346 11511902 split_transform_flag = log2_trafo_size > s->ps.sps->log2_max_trafo_size ||
1347
8/8
✓ Branch 0 taken 11404024 times.
✓ Branch 1 taken 107878 times.
✓ Branch 2 taken 5793182 times.
✓ Branch 3 taken 5610842 times.
✓ Branch 4 taken 4617716 times.
✓ Branch 5 taken 1175466 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10109920 times.
11511902 (lc->cu.intra_split_flag && trafo_depth == 0) ||
1348 inter_split;
1349 }
1350
1351
6/6
✓ Branch 0 taken 18330697 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8568776 times.
✓ Branch 3 taken 9761921 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8254360 times.
18330889 if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) {
1352
4/4
✓ Branch 0 taken 4378300 times.
✓ Branch 1 taken 5698037 times.
✓ Branch 2 taken 1219808 times.
✓ Branch 3 taken 3158492 times.
10076337 if (trafo_depth == 0 || cbf_cb[0]) {
1353 6917845 cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1354
6/6
✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 6319579 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
6917845 if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1355 526996 cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1356 }
1357 }
1358
1359
4/4
✓ Branch 0 taken 4378300 times.
✓ Branch 1 taken 5698037 times.
✓ Branch 2 taken 1166360 times.
✓ Branch 3 taken 3211940 times.
10076337 if (trafo_depth == 0 || cbf_cr[0]) {
1360 6864397 cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1361
6/6
✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6119091 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
6864397 if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1362 661961 cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1363 }
1364 }
1365 }
1366
1367
2/2
✓ Branch 0 taken 3158165 times.
✓ Branch 1 taken 15172724 times.
18330889 if (split_transform_flag) {
1368 3158165 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1369 3158165 const int x1 = x0 + trafo_size_split;
1370 3158165 const int y1 = y0 + trafo_size_split;
1371
1372 #define SUBDIVIDE(x, y, idx) \
1373 do { \
1374 ret = hls_transform_tree(s, x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1375 log2_trafo_size - 1, trafo_depth + 1, idx, \
1376 cbf_cb, cbf_cr); \
1377 if (ret < 0) \
1378 return ret; \
1379 } while (0)
1380
1381
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3158165 times.
3158165 SUBDIVIDE(x0, y0, 0);
1382
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3158165 times.
3158165 SUBDIVIDE(x1, y0, 1);
1383
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3158165 times.
3158165 SUBDIVIDE(x0, y1, 2);
1384
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3158165 times.
3158165 SUBDIVIDE(x1, y1, 3);
1385
1386 #undef SUBDIVIDE
1387 } else {
1388 15172724 int min_tu_size = 1 << s->ps.sps->log2_min_tb_size;
1389 15172724 int log2_min_tu_size = s->ps.sps->log2_min_tb_size;
1390 15172724 int min_tu_width = s->ps.sps->min_tb_width;
1391 15172724 int cbf_luma = 1;
1392
1393
4/4
✓ Branch 0 taken 5591925 times.
✓ Branch 1 taken 9580799 times.
✓ Branch 2 taken 976133 times.
✓ Branch 3 taken 4615792 times.
15172724 if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1394
4/4
✓ Branch 0 taken 798105 times.
✓ Branch 1 taken 178028 times.
✓ Branch 2 taken 684251 times.
✓ Branch 3 taken 113854 times.
976133 cbf_cb[0] || cbf_cr[0] ||
1395
6/6
✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 659575 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
684251 (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1396 14501119 cbf_luma = ff_hevc_cbf_luma_decode(s, trafo_depth);
1397 }
1398
1399 15172724 ret = hls_transform_unit(s, x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1400 log2_cb_size, log2_trafo_size,
1401 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1402
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15172723 times.
15172724 if (ret < 0)
1403 1 return ret;
1404 // TODO: store cbf_luma somewhere else
1405
2/2
✓ Branch 0 taken 9627745 times.
✓ Branch 1 taken 5544978 times.
15172723 if (cbf_luma) {
1406 int i, j;
1407
2/2
✓ Branch 0 taken 19554555 times.
✓ Branch 1 taken 9627745 times.
29182300 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1408
2/2
✓ Branch 0 taken 69458731 times.
✓ Branch 1 taken 19554555 times.
89013286 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1409 69458731 int x_tu = (x0 + j) >> log2_min_tu_size;
1410 69458731 int y_tu = (y0 + i) >> log2_min_tu_size;
1411 69458731 s->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1412 }
1413 }
1414
2/2
✓ Branch 0 taken 14639903 times.
✓ Branch 1 taken 532820 times.
15172723 if (!s->sh.disable_deblocking_filter_flag) {
1415 14639903 ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_trafo_size);
1416
2/2
✓ Branch 0 taken 373941 times.
✓ Branch 1 taken 14265962 times.
14639903 if (s->ps.pps->transquant_bypass_enable_flag &&
1417
2/2
✓ Branch 0 taken 275932 times.
✓ Branch 1 taken 98009 times.
373941 lc->cu.cu_transquant_bypass_flag)
1418 275932 set_deblocking_bypass(s, x0, y0, log2_trafo_size);
1419 }
1420 }
1421 18330888 return 0;
1422 }
1423
1424 12433 static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size)
1425 {
1426 12433 HEVCLocalContext *lc = s->HEVClc;
1427 GetBitContext gb;
1428 12433 int cb_size = 1 << log2_cb_size;
1429 12433 ptrdiff_t stride0 = s->frame->linesize[0];
1430 12433 ptrdiff_t stride1 = s->frame->linesize[1];
1431 12433 ptrdiff_t stride2 = s->frame->linesize[2];
1432 12433 uint8_t *dst0 = &s->frame->data[0][y0 * stride0 + (x0 << s->ps.sps->pixel_shift)];
1433 12433 uint8_t *dst1 = &s->frame->data[1][(y0 >> s->ps.sps->vshift[1]) * stride1 + ((x0 >> s->ps.sps->hshift[1]) << s->ps.sps->pixel_shift)];
1434 12433 uint8_t *dst2 = &s->frame->data[2][(y0 >> s->ps.sps->vshift[2]) * stride2 + ((x0 >> s->ps.sps->hshift[2]) << s->ps.sps->pixel_shift)];
1435
1436 12433 int length = cb_size * cb_size * s->ps.sps->pcm.bit_depth +
1437 12433 (((cb_size >> s->ps.sps->hshift[1]) * (cb_size >> s->ps.sps->vshift[1])) +
1438 12433 ((cb_size >> s->ps.sps->hshift[2]) * (cb_size >> s->ps.sps->vshift[2]))) *
1439 12433 s->ps.sps->pcm.bit_depth_chroma;
1440 12433 const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
1441 int ret;
1442
1443
2/2
✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
12433 if (!s->sh.disable_deblocking_filter_flag)
1444 6937 ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
1445
1446 12433 ret = init_get_bits(&gb, pcm, length);
1447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
1448 return ret;
1449
1450 12433 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, s->ps.sps->pcm.bit_depth);
1451
1/2
✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
12433 if (s->ps.sps->chroma_format_idc) {
1452 12433 s->hevcdsp.put_pcm(dst1, stride1,
1453 12433 cb_size >> s->ps.sps->hshift[1],
1454 12433 cb_size >> s->ps.sps->vshift[1],
1455 12433 &gb, s->ps.sps->pcm.bit_depth_chroma);
1456 12433 s->hevcdsp.put_pcm(dst2, stride2,
1457 12433 cb_size >> s->ps.sps->hshift[2],
1458 12433 cb_size >> s->ps.sps->vshift[2],
1459 12433 &gb, s->ps.sps->pcm.bit_depth_chroma);
1460 }
1461
1462 12433 return 0;
1463 }
1464
1465 /**
1466 * 8.5.3.2.2.1 Luma sample unidirectional interpolation process
1467 *
1468 * @param s HEVC decoding context
1469 * @param dst target buffer for block data at block position
1470 * @param dststride stride of the dst buffer
1471 * @param ref reference picture buffer at origin (0, 0)
1472 * @param mv motion vector (relative to block position) to get pixel data from
1473 * @param x_off horizontal position of block from origin (0, 0)
1474 * @param y_off vertical position of block from origin (0, 0)
1475 * @param block_w width of block
1476 * @param block_h height of block
1477 * @param luma_weight weighting factor applied to the luma prediction
1478 * @param luma_offset additive offset applied to the luma prediction value
1479 */
1480
1481 4797591 static void luma_mc_uni(HEVCContext *s, uint8_t *dst, ptrdiff_t dststride,
1482 AVFrame *ref, const Mv *mv, int x_off, int y_off,
1483 int block_w, int block_h, int luma_weight, int luma_offset)
1484 {
1485 4797591 HEVCLocalContext *lc = s->HEVClc;
1486 4797591 uint8_t *src = ref->data[0];
1487 4797591 ptrdiff_t srcstride = ref->linesize[0];
1488 4797591 int pic_width = s->ps.sps->width;
1489 4797591 int pic_height = s->ps.sps->height;
1490 4797591 int mx = mv->x & 3;
1491 4797591 int my = mv->y & 3;
1492
4/4
✓ Branch 0 taken 1954987 times.
✓ Branch 1 taken 2842604 times.
✓ Branch 2 taken 1909330 times.
✓ Branch 3 taken 45657 times.
9549525 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
1493
4/4
✓ Branch 0 taken 2842604 times.
✓ Branch 1 taken 1909330 times.
✓ Branch 2 taken 60281 times.
✓ Branch 3 taken 2782323 times.
4751934 (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
1494 4797591 int idx = ff_hevc_pel_weight[block_w];
1495
1496 4797591 x_off += mv->x >> 2;
1497 4797591 y_off += mv->y >> 2;
1498 4797591 src += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift));
1499
1500
4/4
✓ Branch 0 taken 4742328 times.
✓ Branch 1 taken 55263 times.
✓ Branch 2 taken 4638547 times.
✓ Branch 3 taken 103781 times.
4797591 if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
1501
2/2
✓ Branch 0 taken 4575674 times.
✓ Branch 1 taken 62873 times.
4638547 x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1502
2/2
✓ Branch 0 taken 192203 times.
✓ Branch 1 taken 4383471 times.
4575674 y_off >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1503 414120 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1504 414120 int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1505 414120 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1506
1507 414120 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
1508 edge_emu_stride, srcstride,
1509 block_w + QPEL_EXTRA,
1510 block_h + QPEL_EXTRA,
1511 x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE,
1512 pic_width, pic_height);
1513 414120 src = lc->edge_emu_buffer + buf_offset;
1514 414120 srcstride = edge_emu_stride;
1515 }
1516
1517
2/2
✓ Branch 0 taken 4691653 times.
✓ Branch 1 taken 105938 times.
4797591 if (!weight_flag)
1518 4691653 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride,
1519 block_h, mx, my, block_w);
1520 else
1521 105938 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride,
1522 105938 block_h, s->sh.luma_log2_weight_denom,
1523 luma_weight, luma_offset, mx, my, block_w);
1524 4797591 }
1525
1526 /**
1527 * 8.5.3.2.2.1 Luma sample bidirectional interpolation process
1528 *
1529 * @param s HEVC decoding context
1530 * @param dst target buffer for block data at block position
1531 * @param dststride stride of the dst buffer
1532 * @param ref0 reference picture0 buffer at origin (0, 0)
1533 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1534 * @param x_off horizontal position of block from origin (0, 0)
1535 * @param y_off vertical position of block from origin (0, 0)
1536 * @param block_w width of block
1537 * @param block_h height of block
1538 * @param ref1 reference picture1 buffer at origin (0, 0)
1539 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1540 * @param current_mv current motion vector structure
1541 */
1542 3781449 static void luma_mc_bi(HEVCContext *s, uint8_t *dst, ptrdiff_t dststride,
1543 AVFrame *ref0, const Mv *mv0, int x_off, int y_off,
1544 int block_w, int block_h, AVFrame *ref1, const Mv *mv1, struct MvField *current_mv)
1545 {
1546 3781449 HEVCLocalContext *lc = s->HEVClc;
1547 3781449 ptrdiff_t src0stride = ref0->linesize[0];
1548 3781449 ptrdiff_t src1stride = ref1->linesize[0];
1549 3781449 int pic_width = s->ps.sps->width;
1550 3781449 int pic_height = s->ps.sps->height;
1551 3781449 int mx0 = mv0->x & 3;
1552 3781449 int my0 = mv0->y & 3;
1553 3781449 int mx1 = mv1->x & 3;
1554 3781449 int my1 = mv1->y & 3;
1555
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3781449 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7562898 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
1556
3/4
✓ Branch 0 taken 3781449 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62307 times.
✓ Branch 3 taken 3719142 times.
3781449 (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
1557 3781449 int x_off0 = x_off + (mv0->x >> 2);
1558 3781449 int y_off0 = y_off + (mv0->y >> 2);
1559 3781449 int x_off1 = x_off + (mv1->x >> 2);
1560 3781449 int y_off1 = y_off + (mv1->y >> 2);
1561 3781449 int idx = ff_hevc_pel_weight[block_w];
1562
1563 3781449 uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift);
1564 3781449 uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift);
1565
1566
4/4
✓ Branch 0 taken 3729172 times.
✓ Branch 1 taken 52277 times.
✓ Branch 2 taken 3629676 times.
✓ Branch 3 taken 99496 times.
3781449 if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER ||
1567
2/2
✓ Branch 0 taken 3566623 times.
✓ Branch 1 taken 63053 times.
3629676 x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1568
2/2
✓ Branch 0 taken 200716 times.
✓ Branch 1 taken 3365907 times.
3566623 y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1569 415542 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1570 415542 int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1571 415542 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1572
1573 415542 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset,
1574 edge_emu_stride, src0stride,
1575 block_w + QPEL_EXTRA,
1576 block_h + QPEL_EXTRA,
1577 x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE,
1578 pic_width, pic_height);
1579 415542 src0 = lc->edge_emu_buffer + buf_offset;
1580 415542 src0stride = edge_emu_stride;
1581 }
1582
1583
4/4
✓ Branch 0 taken 3723733 times.
✓ Branch 1 taken 57716 times.
✓ Branch 2 taken 3624885 times.
✓ Branch 3 taken 98848 times.
3781449 if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER ||
1584
2/2
✓ Branch 0 taken 3559536 times.
✓ Branch 1 taken 65349 times.
3624885 x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1585
2/2
✓ Branch 0 taken 204563 times.
✓ Branch 1 taken 3354973 times.
3559536 y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1586 426476 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1587 426476 int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1588 426476 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1589
1590 426476 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset,
1591 edge_emu_stride, src1stride,
1592 block_w + QPEL_EXTRA,
1593 block_h + QPEL_EXTRA,
1594 x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE,
1595 pic_width, pic_height);
1596 426476 src1 = lc->edge_emu_buffer2 + buf_offset;
1597 426476 src1stride = edge_emu_stride;
1598 }
1599
1600 3781449 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride,
1601 block_h, mx0, my0, block_w);
1602
2/2
✓ Branch 0 taken 3719142 times.
✓ Branch 1 taken 62307 times.
3781449 if (!weight_flag)
1603 3719142 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1604 block_h, mx1, my1, block_w);
1605 else
1606 62307 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1607 62307 block_h, s->sh.luma_log2_weight_denom,
1608 62307 s->sh.luma_weight_l0[current_mv->ref_idx[0]],
1609 62307 s->sh.luma_weight_l1[current_mv->ref_idx[1]],
1610 62307 s->sh.luma_offset_l0[current_mv->ref_idx[0]],
1611 62307 s->sh.luma_offset_l1[current_mv->ref_idx[1]],
1612 mx1, my1, block_w);
1613
1614 3781449 }
1615
1616 /**
1617 * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process
1618 *
1619 * @param s HEVC decoding context
1620 * @param dst1 target buffer for block data at block position (U plane)
1621 * @param dst2 target buffer for block data at block position (V plane)
1622 * @param dststride stride of the dst1 and dst2 buffers
1623 * @param ref reference picture buffer at origin (0, 0)
1624 * @param mv motion vector (relative to block position) to get pixel data from
1625 * @param x_off horizontal position of block from origin (0, 0)
1626 * @param y_off vertical position of block from origin (0, 0)
1627 * @param block_w width of block
1628 * @param block_h height of block
1629 * @param chroma_weight weighting factor applied to the chroma prediction
1630 * @param chroma_offset additive offset applied to the chroma prediction value
1631 */
1632
1633 9595182 static void chroma_mc_uni(HEVCContext *s, uint8_t *dst0,
1634 ptrdiff_t dststride, uint8_t *src0, ptrdiff_t srcstride, int reflist,
1635 int x_off, int y_off, int block_w, int block_h, struct MvField *current_mv, int chroma_weight, int chroma_offset)
1636 {
1637 9595182 HEVCLocalContext *lc = s->HEVClc;
1638 9595182 int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1];
1639 9595182 int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1];
1640 9595182 const Mv *mv = &current_mv->mv[reflist];
1641
4/4
✓ Branch 0 taken 3909974 times.
✓ Branch 1 taken 5685208 times.
✓ Branch 2 taken 3818660 times.
✓ Branch 3 taken 91314 times.
19099050 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
1642
4/4
✓ Branch 0 taken 5685208 times.
✓ Branch 1 taken 3818660 times.
✓ Branch 2 taken 120562 times.
✓ Branch 3 taken 5564646 times.
9503868 (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
1643 9595182 int idx = ff_hevc_pel_weight[block_w];
1644 9595182 int hshift = s->ps.sps->hshift[1];
1645 9595182 int vshift = s->ps.sps->vshift[1];
1646 9595182 intptr_t mx = av_mod_uintp2(mv->x, 2 + hshift);
1647 9595182 intptr_t my = av_mod_uintp2(mv->y, 2 + vshift);
1648 9595182 intptr_t _mx = mx << (1 - hshift);
1649 9595182 intptr_t _my = my << (1 - vshift);
1650
1651 9595182 x_off += mv->x >> (2 + hshift);
1652 9595182 y_off += mv->y >> (2 + vshift);
1653 9595182 src0 += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift));
1654
1655
4/4
✓ Branch 0 taken 9494652 times.
✓ Branch 1 taken 100530 times.
✓ Branch 2 taken 9286952 times.
✓ Branch 3 taken 207700 times.
9595182 if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1656
2/2
✓ Branch 0 taken 9161214 times.
✓ Branch 1 taken 125738 times.
9286952 x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1657
2/2
✓ Branch 0 taken 384462 times.
✓ Branch 1 taken 8776752 times.
9161214 y_off >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1658 818430 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1659 818430 int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << s->ps.sps->pixel_shift));
1660 818430 int buf_offset0 = EPEL_EXTRA_BEFORE *
1661 818430 (edge_emu_stride + (1 << s->ps.sps->pixel_shift));
1662 818430 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0,
1663 edge_emu_stride, srcstride,
1664 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1665 x_off - EPEL_EXTRA_BEFORE,
1666 y_off - EPEL_EXTRA_BEFORE,
1667 pic_width, pic_height);
1668
1669 818430 src0 = lc->edge_emu_buffer + buf_offset0;
1670 818430 srcstride = edge_emu_stride;
1671 }
1672
2/2
✓ Branch 0 taken 9383306 times.
✓ Branch 1 taken 211876 times.
9595182 if (!weight_flag)
1673 9383306 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1674 block_h, _mx, _my, block_w);
1675 else
1676 211876 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1677 211876 block_h, s->sh.chroma_log2_weight_denom,
1678 chroma_weight, chroma_offset, _mx, _my, block_w);
1679 9595182 }
1680
1681 /**
1682 * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process
1683 *
1684 * @param s HEVC decoding context
1685 * @param dst target buffer for block data at block position
1686 * @param dststride stride of the dst buffer
1687 * @param ref0 reference picture0 buffer at origin (0, 0)
1688 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1689 * @param x_off horizontal position of block from origin (0, 0)
1690 * @param y_off vertical position of block from origin (0, 0)
1691 * @param block_w width of block
1692 * @param block_h height of block
1693 * @param ref1 reference picture1 buffer at origin (0, 0)
1694 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1695 * @param current_mv current motion vector structure
1696 * @param cidx chroma component(cb, cr)
1697 */
1698 7562898 static void chroma_mc_bi(HEVCContext *s, uint8_t *dst0, ptrdiff_t dststride, AVFrame *ref0, AVFrame *ref1,
1699 int x_off, int y_off, int block_w, int block_h, struct MvField *current_mv, int cidx)
1700 {
1701 7562898 HEVCLocalContext *lc = s->HEVClc;
1702 7562898 uint8_t *src1 = ref0->data[cidx+1];
1703 7562898 uint8_t *src2 = ref1->data[cidx+1];
1704 7562898 ptrdiff_t src1stride = ref0->linesize[cidx+1];
1705 7562898 ptrdiff_t src2stride = ref1->linesize[cidx+1];
1706
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7562898 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15125796 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
1707
3/4
✓ Branch 0 taken 7562898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 124614 times.
✓ Branch 3 taken 7438284 times.
7562898 (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
1708 7562898 int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1];
1709 7562898 int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1];
1710 7562898 Mv *mv0 = &current_mv->mv[0];
1711 7562898 Mv *mv1 = &current_mv->mv[1];
1712 7562898 int hshift = s->ps.sps->hshift[1];
1713 7562898 int vshift = s->ps.sps->vshift[1];
1714
1715 7562898 intptr_t mx0 = av_mod_uintp2(mv0->x, 2 + hshift);
1716 7562898 intptr_t my0 = av_mod_uintp2(mv0->y, 2 + vshift);
1717 7562898 intptr_t mx1 = av_mod_uintp2(mv1->x, 2 + hshift);
1718 7562898 intptr_t my1 = av_mod_uintp2(mv1->y, 2 + vshift);
1719 7562898 intptr_t _mx0 = mx0 << (1 - hshift);
1720 7562898 intptr_t _my0 = my0 << (1 - vshift);
1721 7562898 intptr_t _mx1 = mx1 << (1 - hshift);
1722 7562898 intptr_t _my1 = my1 << (1 - vshift);
1723
1724 7562898 int x_off0 = x_off + (mv0->x >> (2 + hshift));
1725 7562898 int y_off0 = y_off + (mv0->y >> (2 + vshift));
1726 7562898 int x_off1 = x_off + (mv1->x >> (2 + hshift));
1727 7562898 int y_off1 = y_off + (mv1->y >> (2 + vshift));
1728 7562898 int idx = ff_hevc_pel_weight[block_w];
1729 7562898 src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift);
1730 7562898 src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift);
1731
1732
4/4
✓ Branch 0 taken 7463584 times.
✓ Branch 1 taken 99314 times.
✓ Branch 2 taken 7264516 times.
✓ Branch 3 taken 199068 times.
7562898 if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER ||
1733
2/2
✓ Branch 0 taken 7138414 times.
✓ Branch 1 taken 126102 times.
7264516 x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1734
2/2
✓ Branch 0 taken 400782 times.
✓ Branch 1 taken 6737632 times.
7138414 y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1735 825266 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1736 825266 int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << s->ps.sps->pixel_shift));
1737 825266 int buf_offset1 = EPEL_EXTRA_BEFORE *
1738 825266 (edge_emu_stride + (1 << s->ps.sps->pixel_shift));
1739
1740 825266 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1,
1741 edge_emu_stride, src1stride,
1742 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1743 x_off0 - EPEL_EXTRA_BEFORE,
1744 y_off0 - EPEL_EXTRA_BEFORE,
1745 pic_width, pic_height);
1746
1747 825266 src1 = lc->edge_emu_buffer + buf_offset1;
1748 825266 src1stride = edge_emu_stride;
1749 }
1750
1751
4/4
✓ Branch 0 taken 7452390 times.
✓ Branch 1 taken 110508 times.
✓ Branch 2 taken 7254974 times.
✓ Branch 3 taken 197416 times.
7562898 if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER ||
1752
2/2
✓ Branch 0 taken 7124282 times.
✓ Branch 1 taken 130692 times.
7254974 x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1753
2/2
✓ Branch 0 taken 408782 times.
✓ Branch 1 taken 6715500 times.
7124282 y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1754 847398 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1755 847398 int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << s->ps.sps->pixel_shift));
1756 847398 int buf_offset1 = EPEL_EXTRA_BEFORE *
1757 847398 (edge_emu_stride + (1 << s->ps.sps->pixel_shift));
1758
1759 847398 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1,
1760 edge_emu_stride, src2stride,
1761 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1762 x_off1 - EPEL_EXTRA_BEFORE,
1763 y_off1 - EPEL_EXTRA_BEFORE,
1764 pic_width, pic_height);
1765
1766 847398 src2 = lc->edge_emu_buffer2 + buf_offset1;
1767 847398 src2stride = edge_emu_stride;
1768 }
1769
1770 7562898 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride,
1771 block_h, _mx0, _my0, block_w);
1772
2/2
✓ Branch 0 taken 7438284 times.
✓ Branch 1 taken 124614 times.
7562898 if (!weight_flag)
1773 7438284 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->frame->linesize[cidx+1],
1774 7438284 src2, src2stride, lc->tmp,
1775 block_h, _mx1, _my1, block_w);
1776 else
1777 124614 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->frame->linesize[cidx+1],
1778 124614 src2, src2stride, lc->tmp,
1779 block_h,
1780 124614 s->sh.chroma_log2_weight_denom,
1781 124614 s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx],
1782 124614 s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx],
1783 124614 s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx],
1784 124614 s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx],
1785 _mx1, _my1, block_w);
1786 7562898 }
1787
1788 12360489 static void hevc_await_progress(HEVCContext *s, HEVCFrame *ref,
1789 const Mv *mv, int y0, int height)
1790 {
1791
2/2
✓ Branch 0 taken 107575 times.
✓ Branch 1 taken 12252914 times.
12360489 if (s->threads_type == FF_THREAD_FRAME ) {
1792 107575 int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9);
1793
1794 107575 ff_thread_await_progress(&ref->tf, y, 0);
1795 }
1796 12360489 }
1797
1798 2377473 static void hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW,
1799 int nPbH, int log2_cb_size, int part_idx,
1800 int merge_idx, MvField *mv)
1801 {
1802 2377473 HEVCLocalContext *lc = s->HEVClc;
1803 2377473 enum InterPredIdc inter_pred_idc = PRED_L0;
1804 int mvp_flag;
1805
1806 2377473 ff_hevc_set_neighbour_available(s, x0, y0, nPbW, nPbH);
1807 2377473 mv->pred_flag = 0;
1808
2/2
✓ Branch 0 taken 1811353 times.
✓ Branch 1 taken 566120 times.
2377473 if (s->sh.slice_type == HEVC_SLICE_B)
1809 1811353 inter_pred_idc = ff_hevc_inter_pred_idc_decode(s, nPbW, nPbH);
1810
1811
2/2
✓ Branch 0 taken 1993454 times.
✓ Branch 1 taken 384019 times.
2377473 if (inter_pred_idc != PRED_L1) {
1812
1/2
✓ Branch 0 taken 1993454 times.
✗ Branch 1 not taken.
1993454 if (s->sh.nb_refs[L0])
1813 1993454 mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L0]);
1814
1815 1993454 mv->pred_flag = PF_L0;
1816 1993454 ff_hevc_hls_mvd_coding(s, x0, y0, 0);
1817 1993454 mvp_flag = ff_hevc_mvp_lx_flag_decode(s);
1818 1993454 ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1819 part_idx, merge_idx, mv, mvp_flag, 0);
1820 1993454 mv->mv[0].x += lc->pu.mvd.x;
1821 1993454 mv->mv[0].y += lc->pu.mvd.y;
1822 }
1823
1824
2/2
✓ Branch 0 taken 788021 times.
✓ Branch 1 taken 1589452 times.
2377473 if (inter_pred_idc != PRED_L0) {
1825
1/2
✓ Branch 0 taken 788021 times.
✗ Branch 1 not taken.
788021 if (s->sh.nb_refs[L1])
1826 788021 mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L1]);
1827
1828
4/4
✓ Branch 0 taken 187361 times.
✓ Branch 1 taken 600660 times.
✓ Branch 2 taken 157794 times.
✓ Branch 3 taken 29567 times.
788021 if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) {
1829 157794 AV_ZERO32(&lc->pu.mvd);
1830 } else {
1831 630227 ff_hevc_hls_mvd_coding(s, x0, y0, 1);
1832 }
1833
1834 788021 mv->pred_flag += PF_L1;
1835 788021 mvp_flag = ff_hevc_mvp_lx_flag_decode(s);
1836 788021 ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1837 part_idx, merge_idx, mv, mvp_flag, 1);
1838 788021 mv->mv[1].x += lc->pu.mvd.x;
1839 788021 mv->mv[1].y += lc->pu.mvd.y;
1840 }
1841 2377473 }
1842
1843 8579040 static void hls_prediction_unit(HEVCContext *s, int x0, int y0,
1844 int nPbW, int nPbH,
1845 int log2_cb_size, int partIdx, int idx)
1846 {
1847 #define POS(c_idx, x, y) \
1848 &s->frame->data[c_idx][((y) >> s->ps.sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \
1849 (((x) >> s->ps.sps->hshift[c_idx]) << s->ps.sps->pixel_shift)]
1850 8579040 HEVCLocalContext *lc = s->HEVClc;
1851 8579040 int merge_idx = 0;
1852 8579040 struct MvField current_mv = {{{ 0 }}};
1853
1854 8579040 int min_pu_width = s->ps.sps->min_pu_width;
1855
1856 8579040 MvField *tab_mvf = s->ref->tab_mvf;
1857 8579040 RefPicList *refPicList = s->ref->refPicList;
1858 8579040 HEVCFrame *ref0 = NULL, *ref1 = NULL;
1859 8579040 uint8_t *dst0 = POS(0, x0, y0);
1860 8579040 uint8_t *dst1 = POS(1, x0, y0);
1861 8579040 uint8_t *dst2 = POS(2, x0, y0);
1862 8579040 int log2_min_cb_size = s->ps.sps->log2_min_cb_size;
1863 8579040 int min_cb_width = s->ps.sps->min_cb_width;
1864 8579040 int x_cb = x0 >> log2_min_cb_size;
1865 8579040 int y_cb = y0 >> log2_min_cb_size;
1866 int x_pu, y_pu;
1867 int i, j;
1868
1869 8579040 int skip_flag = SAMPLE_CTB(s->skip_flag, x_cb, y_cb);
1870
1871
2/2
✓ Branch 0 taken 4706854 times.
✓ Branch 1 taken 3872186 times.
8579040 if (!skip_flag)
1872 4706854 lc->pu.merge_flag = ff_hevc_merge_flag_decode(s);
1873
1874
4/4
✓ Branch 0 taken 4706854 times.
✓ Branch 1 taken 3872186 times.
✓ Branch 2 taken 2329381 times.
✓ Branch 3 taken 2377473 times.
8579040 if (skip_flag || lc->pu.merge_flag) {
1875
2/2
✓ Branch 0 taken 6124714 times.
✓ Branch 1 taken 76853 times.
6201567 if (s->sh.max_num_merge_cand > 1)
1876 6124714 merge_idx = ff_hevc_merge_idx_decode(s);
1877 else
1878 76853 merge_idx = 0;
1879
1880 6201567 ff_hevc_luma_mv_merge_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1881 partIdx, merge_idx, &current_mv);
1882 } else {
1883 2377473 hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1884 partIdx, merge_idx, &current_mv);
1885 }
1886
1887 8579040 x_pu = x0 >> s->ps.sps->log2_min_pu_size;
1888 8579040 y_pu = y0 >> s->ps.sps->log2_min_pu_size;
1889
1890
2/2
✓ Branch 0 taken 32342572 times.
✓ Branch 1 taken 8579040 times.
40921612 for (j = 0; j < nPbH >> s->ps.sps->log2_min_pu_size; j++)
1891
2/2
✓ Branch 0 taken 205072224 times.
✓ Branch 1 taken 32342572 times.
237414796 for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++)
1892 205072224 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1893
1894
2/2
✓ Branch 0 taken 7818463 times.
✓ Branch 1 taken 760577 times.
8579040 if (current_mv.pred_flag & PF_L0) {
1895 7818463 ref0 = refPicList[0].ref[current_mv.ref_idx[0]];
1896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7818463 times.
7818463 if (!ref0)
1897 return;
1898 7818463 hevc_await_progress(s, ref0, &current_mv.mv[0], y0, nPbH);
1899 }
1900
2/2
✓ Branch 0 taken 4542026 times.
✓ Branch 1 taken 4037014 times.
8579040 if (current_mv.pred_flag & PF_L1) {
1901 4542026 ref1 = refPicList[1].ref[current_mv.ref_idx[1]];
1902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4542026 times.
4542026 if (!ref1)
1903 return;
1904 4542026 hevc_await_progress(s, ref1, &current_mv.mv[1], y0, nPbH);
1905 }
1906
1907
2/2
✓ Branch 0 taken 4037014 times.
✓ Branch 1 taken 4542026 times.
8579040 if (current_mv.pred_flag == PF_L0) {
1908 4037014 int x0_c = x0 >> s->ps.sps->hshift[1];
1909 4037014 int y0_c = y0 >> s->ps.sps->vshift[1];
1910 4037014 int nPbW_c = nPbW >> s->ps.sps->hshift[1];
1911 4037014 int nPbH_c = nPbH >> s->ps.sps->vshift[1];
1912
1913 4037014 luma_mc_uni(s, dst0, s->frame->linesize[0], ref0->frame,
1914 &current_mv.mv[0], x0, y0, nPbW, nPbH,
1915 4037014 s->sh.luma_weight_l0[current_mv.ref_idx[0]],
1916 4037014 s->sh.luma_offset_l0[current_mv.ref_idx[0]]);
1917
1918
1/2
✓ Branch 0 taken 4037014 times.
✗ Branch 1 not taken.
4037014 if (s->ps.sps->chroma_format_idc) {
1919 4037014 chroma_mc_uni(s, dst1, s->frame->linesize[1], ref0->frame->data[1], ref0->frame->linesize[1],
1920 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
1921 4037014 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]);
1922 4037014 chroma_mc_uni(s, dst2, s->frame->linesize[2], ref0->frame->data[2], ref0->frame->linesize[2],
1923 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
1924 4037014 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]);
1925 }
1926
2/2
✓ Branch 0 taken 760577 times.
✓ Branch 1 taken 3781449 times.
4542026 } else if (current_mv.pred_flag == PF_L1) {
1927 760577 int x0_c = x0 >> s->ps.sps->hshift[1];
1928 760577 int y0_c = y0 >> s->ps.sps->vshift[1];
1929 760577 int nPbW_c = nPbW >> s->ps.sps->hshift[1];
1930 760577 int nPbH_c = nPbH >> s->ps.sps->vshift[1];
1931
1932 760577 luma_mc_uni(s, dst0, s->frame->linesize[0], ref1->frame,
1933 &current_mv.mv[1], x0, y0, nPbW, nPbH,
1934 760577 s->sh.luma_weight_l1[current_mv.ref_idx[1]],
1935 760577 s->sh.luma_offset_l1[current_mv.ref_idx[1]]);
1936
1937
1/2
✓ Branch 0 taken 760577 times.
✗ Branch 1 not taken.
760577 if (s->ps.sps->chroma_format_idc) {
1938 760577 chroma_mc_uni(s, dst1, s->frame->linesize[1], ref1->frame->data[1], ref1->frame->linesize[1],
1939 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
1940 760577 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]);
1941
1942 760577 chroma_mc_uni(s, dst2, s->frame->linesize[2], ref1->frame->data[2], ref1->frame->linesize[2],
1943 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
1944 760577 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]);
1945 }
1946
1/2
✓ Branch 0 taken 3781449 times.
✗ Branch 1 not taken.
3781449 } else if (current_mv.pred_flag == PF_BI) {
1947 3781449 int x0_c = x0 >> s->ps.sps->hshift[1];
1948 3781449 int y0_c = y0 >> s->ps.sps->vshift[1];
1949 3781449 int nPbW_c = nPbW >> s->ps.sps->hshift[1];
1950 3781449 int nPbH_c = nPbH >> s->ps.sps->vshift[1];
1951
1952 3781449 luma_mc_bi(s, dst0, s->frame->linesize[0], ref0->frame,
1953 &current_mv.mv[0], x0, y0, nPbW, nPbH,
1954 ref1->frame, &current_mv.mv[1], &current_mv);
1955
1956
1/2
✓ Branch 0 taken 3781449 times.
✗ Branch 1 not taken.
3781449 if (s->ps.sps->chroma_format_idc) {
1957 3781449 chroma_mc_bi(s, dst1, s->frame->linesize[1], ref0->frame, ref1->frame,
1958 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 0);
1959
1960 3781449 chroma_mc_bi(s, dst2, s->frame->linesize[2], ref0->frame, ref1->frame,
1961 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 1);
1962 }
1963 }
1964 }
1965
1966 /**
1967 * 8.4.1
1968 */
1969 7445426 static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size,
1970 int prev_intra_luma_pred_flag)
1971 {
1972 7445426 HEVCLocalContext *lc = s->HEVClc;
1973 7445426 int x_pu = x0 >> s->ps.sps->log2_min_pu_size;
1974 7445426 int y_pu = y0 >> s->ps.sps->log2_min_pu_size;
1975 7445426 int min_pu_width = s->ps.sps->min_pu_width;
1976 7445426 int size_in_pus = pu_size >> s->ps.sps->log2_min_pu_size;
1977 7445426 int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size);
1978 7445426 int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size);
1979
1980
2/2
✓ Branch 0 taken 1046482 times.
✓ Branch 1 taken 119795 times.
1166277 int cand_up = (lc->ctb_up_flag || y0b) ?
1981
2/2
✓ Branch 0 taken 1166277 times.
✓ Branch 1 taken 6279149 times.
8611703 s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
1982
2/2
✓ Branch 0 taken 563471 times.
✓ Branch 1 taken 75439 times.
638910 int cand_left = (lc->ctb_left_flag || x0b) ?
1983
2/2
✓ Branch 0 taken 638910 times.
✓ Branch 1 taken 6806516 times.
8084336 s->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC;
1984
1985 7445426 int y_ctb = (y0 >> (s->ps.sps->log2_ctb_size)) << (s->ps.sps->log2_ctb_size);
1986
1987 7445426 MvField *tab_mvf = s->ref->tab_mvf;
1988 int intra_pred_mode;
1989 int candidate[3];
1990 int i, j;
1991
1992 // intra_pred_mode prediction does not cross vertical CTB boundaries
1993
2/2
✓ Branch 0 taken 939190 times.
✓ Branch 1 taken 6506236 times.
7445426 if ((y0 - 1) < y_ctb)
1994 939190 cand_up = INTRA_DC;
1995
1996
2/2
✓ Branch 0 taken 1562330 times.
✓ Branch 1 taken 5883096 times.
7445426 if (cand_left == cand_up) {
1997
2/2
✓ Branch 0 taken 919421 times.
✓ Branch 1 taken 642909 times.
1562330 if (cand_left < 2) {
1998 919421 candidate[0] = INTRA_PLANAR;
1999 919421 candidate[1] = INTRA_DC;
2000 919421 candidate[2] = INTRA_ANGULAR_26;
2001 } else {
2002 642909 candidate[0] = cand_left;
2003 642909 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2004 642909 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2005 }
2006 } else {
2007 5883096 candidate[0] = cand_left;
2008 5883096 candidate[1] = cand_up;
2009
4/4
✓ Branch 0 taken 4901182 times.
✓ Branch 1 taken 981914 times.
✓ Branch 2 taken 4057636 times.
✓ Branch 3 taken 843546 times.
5883096 if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) {
2010 4057636 candidate[2] = INTRA_PLANAR;
2011
4/4
✓ Branch 0 taken 1597474 times.
✓ Branch 1 taken 227986 times.
✓ Branch 2 taken 1214765 times.
✓ Branch 3 taken 382709 times.
1825460 } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) {
2012 1214765 candidate[2] = INTRA_DC;
2013 } else {
2014 610695 candidate[2] = INTRA_ANGULAR_26;
2015 }
2016 }
2017
2018
2/2
✓ Branch 0 taken 4451594 times.
✓ Branch 1 taken 2993832 times.
7445426 if (prev_intra_luma_pred_flag) {
2019 4451594 intra_pred_mode = candidate[lc->pu.mpm_idx];
2020 } else {
2021
2/2
✓ Branch 0 taken 1433236 times.
✓ Branch 1 taken 1560596 times.
2993832 if (candidate[0] > candidate[1])
2022 1433236 FFSWAP(uint8_t, candidate[0], candidate[1]);
2023
2/2
✓ Branch 0 taken 1787404 times.
✓ Branch 1 taken 1206428 times.
2993832 if (candidate[0] > candidate[2])
2024 1787404 FFSWAP(uint8_t, candidate[0], candidate[2]);
2025
2/2
✓ Branch 0 taken 2234982 times.
✓ Branch 1 taken 758850 times.
2993832 if (candidate[1] > candidate[2])
2026 2234982 FFSWAP(uint8_t, candidate[1], candidate[2]);
2027
2028 2993832 intra_pred_mode = lc->pu.rem_intra_luma_pred_mode;
2029
2/2
✓ Branch 0 taken 8981496 times.
✓ Branch 1 taken 2993832 times.
11975328 for (i = 0; i < 3; i++)
2030
2/2
✓ Branch 0 taken 6544115 times.
✓ Branch 1 taken 2437381 times.
8981496 if (intra_pred_mode >= candidate[i])
2031 6544115 intra_pred_mode++;
2032 }
2033
2034 /* write the intra prediction units into the mv array */
2035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7445426 times.
7445426 if (!size_in_pus)
2036 size_in_pus = 1;
2037
2/2
✓ Branch 0 taken 12939330 times.
✓ Branch 1 taken 7445426 times.
20384756 for (i = 0; i < size_in_pus; i++) {
2038 12939330 memset(&s->tab_ipm[(y_pu + i) * min_pu_width + x_pu],
2039 intra_pred_mode, size_in_pus);
2040
2041
2/2
✓ Branch 0 taken 40127576 times.
✓ Branch 1 taken 12939330 times.
53066906 for (j = 0; j < size_in_pus; j++) {
2042 40127576 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA;
2043 }
2044 }
2045
2046 7445426 return intra_pred_mode;
2047 }
2048
2049 10898564 static av_always_inline void set_ct_depth(HEVCContext *s, int x0, int y0,
2050 int log2_cb_size, int ct_depth)
2051 {
2052 10898564 int length = (1 << log2_cb_size) >> s->ps.sps->log2_min_cb_size;
2053 10898564 int x_cb = x0 >> s->ps.sps->log2_min_cb_size;
2054 10898564 int y_cb = y0 >> s->ps.sps->log2_min_cb_size;
2055 int y;
2056
2057
2/2
✓ Branch 0 taken 19971829 times.
✓ Branch 1 taken 10898564 times.
30870393 for (y = 0; y < length; y++)
2058 19971829 memset(&s->tab_ct_depth[(y_cb + y) * s->ps.sps->min_cb_width + x_cb],
2059 ct_depth, length);
2060 10898564 }
2061
2062 static const uint8_t tab_mode_idx[] = {
2063 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2064 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2065
2066 3896867 static void intra_prediction_unit(HEVCContext *s, int x0, int y0,
2067 int log2_cb_size)
2068 {
2069 3896867 HEVCLocalContext *lc = s->HEVClc;
2070 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2071 uint8_t prev_intra_luma_pred_flag[4];
2072 3896867 int split = lc->cu.part_mode == PART_NxN;
2073 3896867 int pb_size = (1 << log2_cb_size) >> split;
2074 3896867 int side = split + 1;
2075 int chroma_mode;
2076 int i, j;
2077
2078
2/2
✓ Branch 0 taken 5079720 times.
✓ Branch 1 taken 3896867 times.
8976587 for (i = 0; i < side; i++)
2079
2/2
✓ Branch 0 taken 7445426 times.
✓ Branch 1 taken 5079720 times.
12525146 for (j = 0; j < side; j++)
2080 7445426 prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(s);
2081
2082
2/2
✓ Branch 0 taken 5079720 times.
✓ Branch 1 taken 3896867 times.
8976587 for (i = 0; i < side; i++) {
2083
2/2
✓ Branch 0 taken 7445426 times.
✓ Branch 1 taken 5079720 times.
12525146 for (j = 0; j < side; j++) {
2084
2/2
✓ Branch 0 taken 4451594 times.
✓ Branch 1 taken 2993832 times.
7445426 if (prev_intra_luma_pred_flag[2 * i + j])
2085 4451594 lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(s);
2086 else
2087 2993832 lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(s);
2088
2089 7445426 lc->pu.intra_pred_mode[2 * i + j] =
2090 7445426 luma_intra_pred_mode(s, x0 + pb_size * j, y0 + pb_size * i, pb_size,
2091 7445426 prev_intra_luma_pred_flag[2 * i + j]);
2092 }
2093 }
2094
2095
2/2
✓ Branch 0 taken 105006 times.
✓ Branch 1 taken 3791861 times.
3896867 if (s->ps.sps->chroma_format_idc == 3) {
2096
2/2
✓ Branch 0 taken 138857 times.
✓ Branch 1 taken 105006 times.
243863 for (i = 0; i < side; i++) {
2097
2/2
✓ Branch 0 taken 206559 times.
✓ Branch 1 taken 138857 times.
345416 for (j = 0; j < side; j++) {
2098 206559 lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s);
2099
2/2
✓ Branch 0 taken 34248 times.
✓ Branch 1 taken 172311 times.
206559 if (chroma_mode != 4) {
2100
2/2
✓ Branch 0 taken 2343 times.
✓ Branch 1 taken 31905 times.
34248 if (lc->pu.intra_pred_mode[2 * i + j] == intra_chroma_table[chroma_mode])
2101 2343 lc->pu.intra_pred_mode_c[2 * i + j] = 34;
2102 else
2103 31905 lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode];
2104 } else {
2105 172311 lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j];
2106 }
2107 }
2108 }
2109
2/2
✓ Branch 0 taken 247106 times.
✓ Branch 1 taken 3544755 times.
3791861 } else if (s->ps.sps->chroma_format_idc == 2) {
2110 int mode_idx;
2111 247106 lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s);
2112
2/2
✓ Branch 0 taken 73995 times.
✓ Branch 1 taken 173111 times.
247106 if (chroma_mode != 4) {
2113
2/2
✓ Branch 0 taken 3515 times.
✓ Branch 1 taken 70480 times.
73995 if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2114 3515 mode_idx = 34;
2115 else
2116 70480 mode_idx = intra_chroma_table[chroma_mode];
2117 } else {
2118 173111 mode_idx = lc->pu.intra_pred_mode[0];
2119 }
2120 247106 lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx];
2121
2/2
✓ Branch 0 taken 3544563 times.
✓ Branch 1 taken 192 times.
3544755 } else if (s->ps.sps->chroma_format_idc != 0) {
2122 3544563 chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s);
2123
2/2
✓ Branch 0 taken 916359 times.
✓ Branch 1 taken 2628204 times.
3544563 if (chroma_mode != 4) {
2124
2/2
✓ Branch 0 taken 67820 times.
✓ Branch 1 taken 848539 times.
916359 if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2125 67820 lc->pu.intra_pred_mode_c[0] = 34;
2126 else
2127 848539 lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode];
2128 } else {
2129 2628204 lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0];
2130 }
2131 }
2132 3896867 }
2133
2134 7001698 static void intra_prediction_unit_default_value(HEVCContext *s,
2135 int x0, int y0,
2136 int log2_cb_size)
2137 {
2138 7001698 HEVCLocalContext *lc = s->HEVClc;
2139 7001698 int pb_size = 1 << log2_cb_size;
2140 7001698 int size_in_pus = pb_size >> s->ps.sps->log2_min_pu_size;
2141 7001698 int min_pu_width = s->ps.sps->min_pu_width;
2142 7001698 MvField *tab_mvf = s->ref->tab_mvf;
2143 7001698 int x_pu = x0 >> s->ps.sps->log2_min_pu_size;
2144 7001698 int y_pu = y0 >> s->ps.sps->log2_min_pu_size;
2145 int j, k;
2146
2147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7001698 times.
7001698 if (size_in_pus == 0)
2148 size_in_pus = 1;
2149
2/2
✓ Branch 0 taken 29370036 times.
✓ Branch 1 taken 7001698 times.
36371734 for (j = 0; j < size_in_pus; j++)
2150 29370036 memset(&s->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus);
2151
2/2
✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 6989265 times.
7001698 if (lc->cu.pred_mode == MODE_INTRA)
2152
2/2
✓ Branch 0 taken 40908 times.
✓ Branch 1 taken 12433 times.
53341 for (j = 0; j < size_in_pus; j++)
2153
2/2
✓ Branch 0 taken 182512 times.
✓ Branch 1 taken 40908 times.
223420 for (k = 0; k < size_in_pus; k++)
2154 182512 tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA;
2155 7001698 }
2156
2157 10898565 static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
2158 {
2159 10898565 int cb_size = 1 << log2_cb_size;
2160 10898565 HEVCLocalContext *lc = s->HEVClc;
2161 10898565 int log2_min_cb_size = s->ps.sps->log2_min_cb_size;
2162 10898565 int length = cb_size >> log2_min_cb_size;
2163 10898565 int min_cb_width = s->ps.sps->min_cb_width;
2164 10898565 int x_cb = x0 >> log2_min_cb_size;
2165 10898565 int y_cb = y0 >> log2_min_cb_size;
2166 10898565 int idx = log2_cb_size - 2;
2167 10898565 int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2168 int x, y, ret;
2169
2170 10898565 lc->cu.x = x0;
2171 10898565 lc->cu.y = y0;
2172 10898565 lc->cu.pred_mode = MODE_INTRA;
2173 10898565 lc->cu.part_mode = PART_2Nx2N;
2174 10898565 lc->cu.intra_split_flag = 0;
2175
2176 10898565 SAMPLE_CTB(s->skip_flag, x_cb, y_cb) = 0;
2177
2/2
✓ Branch 0 taken 43594260 times.
✓ Branch 1 taken 10898565 times.
54492825 for (x = 0; x < 4; x++)
2178 43594260 lc->pu.intra_pred_mode[x] = 1;
2179
2/2
✓ Branch 0 taken 200139 times.
✓ Branch 1 taken 10698426 times.
10898565 if (s->ps.pps->transquant_bypass_enable_flag) {
2180 200139 lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(s);
2181
2/2
✓ Branch 0 taken 80538 times.
✓ Branch 1 taken 119601 times.
200139 if (lc->cu.cu_transquant_bypass_flag)
2182 80538 set_deblocking_bypass(s, x0, y0, log2_cb_size);
2183 } else
2184 10698426 lc->cu.cu_transquant_bypass_flag = 0;
2185
2186
2/2
✓ Branch 0 taken 8054524 times.
✓ Branch 1 taken 2844041 times.
10898565 if (s->sh.slice_type != HEVC_SLICE_I) {
2187 8054524 uint8_t skip_flag = ff_hevc_skip_flag_decode(s, x0, y0, x_cb, y_cb);
2188
2189 8054524 x = y_cb * min_cb_width + x_cb;
2190
2/2
✓ Branch 0 taken 16260579 times.
✓ Branch 1 taken 8054524 times.
24315103 for (y = 0; y < length; y++) {
2191 16260579 memset(&s->skip_flag[x], skip_flag, length);
2192 16260579 x += min_cb_width;
2193 }
2194
2/2
✓ Branch 0 taken 3872186 times.
✓ Branch 1 taken 4182338 times.
8054524 lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER;
2195 } else {
2196 2844041 x = y_cb * min_cb_width + x_cb;
2197
2/2
✓ Branch 0 taken 3711251 times.
✓ Branch 1 taken 2844041 times.
6555292 for (y = 0; y < length; y++) {
2198 3711251 memset(&s->skip_flag[x], 0, length);
2199 3711251 x += min_cb_width;
2200 }
2201 }
2202
2203
2/2
✓ Branch 0 taken 3872186 times.
✓ Branch 1 taken 7026379 times.
10898565 if (SAMPLE_CTB(s->skip_flag, x_cb, y_cb)) {
2204 3872186 hls_prediction_unit(s, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2205 3872186 intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
2206
2207
2/2
✓ Branch 0 taken 3725673 times.
✓ Branch 1 taken 146513 times.
3872186 if (!s->sh.disable_deblocking_filter_flag)
2208 3725673 ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
2209 } else {
2210 7026379 int pcm_flag = 0;
2211
2212
2/2
✓ Branch 0 taken 4182338 times.
✓ Branch 1 taken 2844041 times.
7026379 if (s->sh.slice_type != HEVC_SLICE_I)
2213 4182338 lc->cu.pred_mode = ff_hevc_pred_mode_decode(s);
2214
2/2
✓ Branch 0 taken 3909300 times.
✓ Branch 1 taken 3117079 times.
7026379 if (lc->cu.pred_mode != MODE_INTRA ||
2215
2/2
✓ Branch 0 taken 3011106 times.
✓ Branch 1 taken 898194 times.
3909300 log2_cb_size == s->ps.sps->log2_min_cb_size) {
2216 6128185 lc->cu.part_mode = ff_hevc_part_mode_decode(s, log2_cb_size);
2217
2/2
✓ Branch 0 taken 1288489 times.
✓ Branch 1 taken 4839696 times.
7416674 lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
2218
2/2
✓ Branch 0 taken 1182853 times.
✓ Branch 1 taken 105636 times.
1288489 lc->cu.pred_mode == MODE_INTRA;
2219 }
2220
2221
2/2
✓ Branch 0 taken 3909300 times.
✓ Branch 1 taken 3117079 times.
7026379 if (lc->cu.pred_mode == MODE_INTRA) {
2222
4/4
✓ Branch 0 taken 2726447 times.
✓ Branch 1 taken 1182853 times.
✓ Branch 2 taken 162684 times.
✓ Branch 3 taken 2563763 times.
3909300 if (lc->cu.part_mode == PART_2Nx2N && s->ps.sps->pcm_enabled_flag &&
2223
2/2
✓ Branch 0 taken 160815 times.
✓ Branch 1 taken 1869 times.
162684 log2_cb_size >= s->ps.sps->pcm.log2_min_pcm_cb_size &&
2224
2/2
✓ Branch 0 taken 153183 times.
✓ Branch 1 taken 7632 times.
160815 log2_cb_size <= s->ps.sps->pcm.log2_max_pcm_cb_size) {
2225 153183 pcm_flag = ff_hevc_pcm_flag_decode(s);
2226 }
2227
2/2
✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 3896867 times.
3909300 if (pcm_flag) {
2228 12433 intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
2229 12433 ret = hls_pcm_sample(s, x0, y0, log2_cb_size);
2230
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12425 times.
12433 if (s->ps.sps->pcm.loop_filter_disable_flag)
2231 8 set_deblocking_bypass(s, x0, y0, log2_cb_size);
2232
2233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
2234 return ret;
2235 } else {
2236 3896867 intra_prediction_unit(s, x0, y0, log2_cb_size);
2237 }
2238 } else {
2239 3117079 intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
2240
8/9
✓ Branch 0 taken 1738576 times.
✓ Branch 1 taken 445726 times.
✓ Branch 2 taken 535018 times.
✓ Branch 3 taken 63734 times.
✓ Branch 4 taken 55171 times.
✓ Branch 5 taken 93167 times.
✓ Branch 6 taken 80051 times.
✓ Branch 7 taken 105636 times.
✗ Branch 8 not taken.
3117079 switch (lc->cu.part_mode) {
2241 1738576 case PART_2Nx2N:
2242 1738576 hls_prediction_unit(s, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2243 1738576 break;
2244 445726 case PART_2NxN:
2245 445726 hls_prediction_unit(s, x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2246 445726 hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2247 445726 break;
2248 535018 case PART_Nx2N:
2249 535018 hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2250 535018 hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2251 535018 break;
2252 63734 case PART_2NxnU:
2253 63734 hls_prediction_unit(s, x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
2254 63734 hls_prediction_unit(s, x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
2255 63734 break;
2256 55171 case PART_2NxnD:
2257 55171 hls_prediction_unit(s, x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
2258 55171 hls_prediction_unit(s, x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
2259 55171 break;
2260 93167 case PART_nLx2N:
2261 93167 hls_prediction_unit(s, x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
2262 93167 hls_prediction_unit(s, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2263 93167 break;
2264 80051 case PART_nRx2N:
2265 80051 hls_prediction_unit(s, x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
2266 80051 hls_prediction_unit(s, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2267 80051 break;
2268 105636 case PART_NxN:
2269 105636 hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
2270 105636 hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2271 105636 hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2272 105636 hls_prediction_unit(s, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2273 105636 break;
2274 }
2275 }
2276
2277
2/2
✓ Branch 0 taken 7013946 times.
✓ Branch 1 taken 12433 times.
7026379 if (!pcm_flag) {
2278 7013946 int rqt_root_cbf = 1;
2279
2280
2/2
✓ Branch 0 taken 3117079 times.
✓ Branch 1 taken 3896867 times.
7013946 if (lc->cu.pred_mode != MODE_INTRA &&
2281
4/4
✓ Branch 0 taken 1738576 times.
✓ Branch 1 taken 1378503 times.
✓ Branch 2 taken 967579 times.
✓ Branch 3 taken 770997 times.
3117079 !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) {
2282 2346082 rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(s);
2283 }
2284
2/2
✓ Branch 0 taken 5698229 times.
✓ Branch 1 taken 1315717 times.
7013946 if (rqt_root_cbf) {
2285 const static int cbf[2] = { 0 };
2286
2/2
✓ Branch 0 taken 3896867 times.
✓ Branch 1 taken 1801362 times.
5698229 lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ?
2287 3896867 s->ps.sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
2288 1801362 s->ps.sps->max_transform_hierarchy_depth_inter;
2289 5698229 ret = hls_transform_tree(s, x0, y0, x0, y0, x0, y0,
2290 log2_cb_size,
2291 log2_cb_size, 0, 0, cbf, cbf);
2292
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5698228 times.
5698229 if (ret < 0)
2293 1 return ret;
2294 } else {
2295
2/2
✓ Branch 0 taken 1259285 times.
✓ Branch 1 taken 56432 times.
1315717 if (!s->sh.disable_deblocking_filter_flag)
2296 1259285 ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
2297 }
2298 }
2299 }
2300
2301
4/4
✓ Branch 0 taken 1872149 times.
✓ Branch 1 taken 9026415 times.
✓ Branch 2 taken 743750 times.
✓ Branch 3 taken 1128399 times.
10898564 if (s->ps.pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
2302 743750 ff_hevc_set_qPy(s, x0, y0, log2_cb_size);
2303
2304 10898564 x = y_cb * min_cb_width + x_cb;
2305
2/2
✓ Branch 0 taken 19971829 times.
✓ Branch 1 taken 10898564 times.
30870393 for (y = 0; y < length; y++) {
2306 19971829 memset(&s->qp_y_tab[x], lc->qp_y, length);
2307 19971829 x += min_cb_width;
2308 }
2309
2310
2/2
✓ Branch 0 taken 3679002 times.
✓ Branch 1 taken 7219562 times.
10898564 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2311
2/2
✓ Branch 0 taken 2134948 times.
✓ Branch 1 taken 1544054 times.
3679002 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2312 2134948 lc->qPy_pred = lc->qp_y;
2313 }
2314
2315 10898564 set_ct_depth(s, x0, y0, log2_cb_size, lc->ct_depth);
2316
2317 10898564 return 0;
2318 }
2319
2320 14222275 static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
2321 int log2_cb_size, int cb_depth)
2322 {
2323 14222275 HEVCLocalContext *lc = s->HEVClc;
2324 14222275 const int cb_size = 1 << log2_cb_size;
2325 int ret;
2326 int split_cu;
2327
2328 14222275 lc->ct_depth = cb_depth;
2329
2/2
✓ Branch 0 taken 14193672 times.
✓ Branch 1 taken 28603 times.
14222275 if (x0 + cb_size <= s->ps.sps->width &&
2330
2/2
✓ Branch 0 taken 13879653 times.
✓ Branch 1 taken 314019 times.
14193672 y0 + cb_size <= s->ps.sps->height &&
2331
2/2
✓ Branch 0 taken 7409067 times.
✓ Branch 1 taken 6470586 times.
13879653 log2_cb_size > s->ps.sps->log2_min_cb_size) {
2332 7409067 split_cu = ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0);
2333 } else {
2334 6813208 split_cu = (log2_cb_size > s->ps.sps->log2_min_cb_size);
2335 }
2336
2/2
✓ Branch 0 taken 2434083 times.
✓ Branch 1 taken 11788192 times.
14222275 if (s->ps.pps->cu_qp_delta_enabled_flag &&
2337
2/2
✓ Branch 0 taken 1370135 times.
✓ Branch 1 taken 1063948 times.
2434083 log2_cb_size >= s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth) {
2338 1370135 lc->tu.is_cu_qp_delta_coded = 0;
2339 1370135 lc->tu.cu_qp_delta = 0;
2340 }
2341
2342
2/2
✓ Branch 0 taken 519326 times.
✓ Branch 1 taken 13702949 times.
14222275 if (s->sh.cu_chroma_qp_offset_enabled_flag &&
2343
1/2
✓ Branch 0 taken 519326 times.
✗ Branch 1 not taken.
519326 log2_cb_size >= s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_chroma_qp_offset_depth) {
2344 519326 lc->tu.is_cu_chroma_qp_offset_coded = 0;
2345 }
2346
2347
2/2
✓ Branch 0 taken 3323710 times.
✓ Branch 1 taken 10898565 times.
14222275 if (split_cu) {
2348 3323710 int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2349 3323710 const int cb_size_split = cb_size >> 1;
2350 3323710 const int x1 = x0 + cb_size_split;
2351 3323710 const int y1 = y0 + cb_size_split;
2352
2353 3323710 int more_data = 0;
2354
2355 3323710 more_data = hls_coding_quadtree(s, x0, y0, log2_cb_size - 1, cb_depth + 1);
2356
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3323708 times.
3323710 if (more_data < 0)
2357 2 return more_data;
2358
2359
4/4
✓ Branch 0 taken 3323699 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3296018 times.
✓ Branch 3 taken 27681 times.
3323708 if (more_data && x1 < s->ps.sps->width) {
2360 3296018 more_data = hls_coding_quadtree(s, x1, y0, log2_cb_size - 1, cb_depth + 1);
2361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3296018 times.
3296018 if (more_data < 0)
2362 return more_data;
2363 }
2364
4/4
✓ Branch 0 taken 3313492 times.
✓ Branch 1 taken 10216 times.
✓ Branch 2 taken 3117331 times.
✓ Branch 3 taken 196161 times.
3323708 if (more_data && y1 < s->ps.sps->height) {
2365 3117331 more_data = hls_coding_quadtree(s, x0, y1, log2_cb_size - 1, cb_depth + 1);
2366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3117331 times.
3117331 if (more_data < 0)
2367 return more_data;
2368 }
2369
4/4
✓ Branch 0 taken 3307407 times.
✓ Branch 1 taken 16301 times.
✓ Branch 2 taken 3285811 times.
✓ Branch 3 taken 21596 times.
3323708 if (more_data && x1 < s->ps.sps->width &&
2370
2/2
✓ Branch 0 taken 3089650 times.
✓ Branch 1 taken 196161 times.
3285811 y1 < s->ps.sps->height) {
2371 3089650 more_data = hls_coding_quadtree(s, x1, y1, log2_cb_size - 1, cb_depth + 1);
2372
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3089649 times.
3089650 if (more_data < 0)
2373 1 return more_data;
2374 }
2375
2376
2/2
✓ Branch 0 taken 1862292 times.
✓ Branch 1 taken 1461415 times.
3323707 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2377
2/2
✓ Branch 0 taken 1384972 times.
✓ Branch 1 taken 477320 times.
1862292 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2378 1384972 lc->qPy_pred = lc->qp_y;
2379
2380
2/2
✓ Branch 0 taken 3288264 times.
✓ Branch 1 taken 35443 times.
3323707 if (more_data)
2381
2/2
✓ Branch 0 taken 90517 times.
✓ Branch 1 taken 3197747 times.
3378781 return ((x1 + cb_size_split) < s->ps.sps->width ||
2382
1/2
✓ Branch 0 taken 90517 times.
✗ Branch 1 not taken.
90517 (y1 + cb_size_split) < s->ps.sps->height);
2383 else
2384 35443 return 0;
2385 } else {
2386 10898565 ret = hls_coding_unit(s, x0, y0, log2_cb_size);
2387
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10898564 times.
10898565 if (ret < 0)
2388 1 return ret;
2389 10898564 if ((!((x0 + cb_size) %
2390
2/2
✓ Branch 0 taken 7966099 times.
✓ Branch 1 taken 2932465 times.
10898564 (1 << (s->ps.sps->log2_ctb_size))) ||
2391
2/2
✓ Branch 0 taken 70697 times.
✓ Branch 1 taken 7895402 times.
7966099 (x0 + cb_size >= s->ps.sps->width)) &&
2392 3003162 (!((y0 + cb_size) %
2393
2/2
✓ Branch 0 taken 1703214 times.
✓ Branch 1 taken 1299948 times.
3003162 (1 << (s->ps.sps->log2_ctb_size))) ||
2394
2/2
✓ Branch 0 taken 95617 times.
✓ Branch 1 taken 1607597 times.
1703214 (y0 + cb_size >= s->ps.sps->height))) {
2395 1395565 int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(s);
2396 1395565 return !end_of_slice_flag;
2397 } else {
2398 9502999 return 1;
2399 }
2400 }
2401
2402 return 0;
2403 }
2404
2405 1395566 static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb,
2406 int ctb_addr_ts)
2407 {
2408 1395566 HEVCLocalContext *lc = s->HEVClc;
2409 1395566 int ctb_size = 1 << s->ps.sps->log2_ctb_size;
2410 1395566 int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2411 1395566 int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
2412
2413 1395566 s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
2414
2415
2/2
✓ Branch 0 taken 93384 times.
✓ Branch 1 taken 1302182 times.
1395566 if (s->ps.pps->entropy_coding_sync_enabled_flag) {
2416
3/4
✓ Branch 0 taken 5334 times.
✓ Branch 1 taken 88050 times.
✓ Branch 2 taken 5334 times.
✗ Branch 3 not taken.
93384 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2417 5334 lc->first_qp_group = 1;
2418 93384 lc->end_of_tiles_x = s->ps.sps->width;
2419
2/2
✓ Branch 0 taken 290050 times.
✓ Branch 1 taken 1012132 times.
1302182 } else if (s->ps.pps->tiles_enabled_flag) {
2420
4/4
✓ Branch 0 taken 289426 times.
✓ Branch 1 taken 624 times.
✓ Branch 2 taken 6285 times.
✓ Branch 3 taken 283141 times.
290050 if (ctb_addr_ts && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) {
2421 6285 int idxX = s->ps.pps->col_idxX[x_ctb >> s->ps.sps->log2_ctb_size];
2422 6285 lc->end_of_tiles_x = x_ctb + (s->ps.pps->column_width[idxX] << s->ps.sps->log2_ctb_size);
2423 6285 lc->first_qp_group = 1;
2424 }
2425 } else {
2426 1012132 lc->end_of_tiles_x = s->ps.sps->width;
2427 }
2428
2429 1395566 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->ps.sps->height);
2430
2431 1395566 lc->boundary_flags = 0;
2432
2/2
✓ Branch 0 taken 290050 times.
✓ Branch 1 taken 1105516 times.
1395566 if (s->ps.pps->tiles_enabled_flag) {
2433
4/4
✓ Branch 0 taken 278142 times.
✓ Branch 1 taken 11908 times.
✓ Branch 2 taken 30707 times.
✓ Branch 3 taken 247435 times.
290050 if (x_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2434 30707 lc->boundary_flags |= BOUNDARY_LEFT_TILE;
2435
4/4
✓ Branch 0 taken 278142 times.
✓ Branch 1 taken 11908 times.
✓ Branch 2 taken 3695 times.
✓ Branch 3 taken 274447 times.
290050 if (x_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - 1])
2436 3695 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2437
4/4
✓ Branch 0 taken 275482 times.
✓ Branch 1 taken 14568 times.
✓ Branch 2 taken 33781 times.
✓ Branch 3 taken 241701 times.
290050 if (y_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->ps.sps->ctb_width]])
2438 33781 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
2439
4/4
✓ Branch 0 taken 275482 times.
✓ Branch 1 taken 14568 times.
✓ Branch 2 taken 14490 times.
✓ Branch 3 taken 260992 times.
290050 if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - s->ps.sps->ctb_width])
2440 14490 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2441 } else {
2442
2/2
✓ Branch 0 taken 17551 times.
✓ Branch 1 taken 1087965 times.
1105516 if (ctb_addr_in_slice <= 0)
2443 17551 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2444
2/2
✓ Branch 0 taken 183824 times.
✓ Branch 1 taken 921692 times.
1105516 if (ctb_addr_in_slice < s->ps.sps->ctb_width)
2445 183824 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2446 }
2447
2448
6/6
✓ Branch 0 taken 1322883 times.
✓ Branch 1 taken 72683 times.
✓ Branch 2 taken 1314996 times.
✓ Branch 3 taken 7887 times.
✓ Branch 4 taken 1285315 times.
✓ Branch 5 taken 29681 times.
1395566 lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
2449
6/6
✓ Branch 0 taken 1277322 times.
✓ Branch 1 taken 118244 times.
✓ Branch 2 taken 1183513 times.
✓ Branch 3 taken 93809 times.
✓ Branch 4 taken 1163393 times.
✓ Branch 5 taken 20120 times.
1395566 lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->ps.sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
2450
6/6
✓ Branch 0 taken 1277322 times.
✓ Branch 1 taken 118244 times.
✓ Branch 2 taken 1186099 times.
✓ Branch 3 taken 91223 times.
✓ Branch 4 taken 1130435 times.
✓ Branch 5 taken 55664 times.
1395566 lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->ps.sps->ctb_width]]));
2451
8/8
✓ Branch 0 taken 1322883 times.
✓ Branch 1 taken 72683 times.
✓ Branch 2 taken 1214123 times.
✓ Branch 3 taken 108760 times.
✓ Branch 4 taken 1125377 times.
✓ Branch 5 taken 88746 times.
✓ Branch 6 taken 1081187 times.
✓ Branch 7 taken 44190 times.
1395566 lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->ps.sps->ctb_width]]));
2452 1395566 }
2453
2454 27473 static int hls_decode_entry(AVCodecContext *avctxt, void *isFilterThread)
2455 {
2456 27473 HEVCContext *s = avctxt->priv_data;
2457 27473 int ctb_size = 1 << s->ps.sps->log2_ctb_size;
2458 27473 int more_data = 1;
2459 27473 int x_ctb = 0;
2460 27473 int y_ctb = 0;
2461 27473 int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
2462 int ret;
2463
2464
3/4
✓ Branch 0 taken 9484 times.
✓ Branch 1 taken 17989 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9484 times.
27473 if (!ctb_addr_ts && s->sh.dependent_slice_segment_flag) {
2465 av_log(s->avctx, AV_LOG_ERROR, "Impossible initial tile.\n");
2466 return AVERROR_INVALIDDATA;
2467 }
2468
2469
2/2
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 19526 times.
27473 if (s->sh.dependent_slice_segment_flag) {
2470 7947 int prev_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
2471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
7947 if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
2472 av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
2473 return AVERROR_INVALIDDATA;
2474 }
2475 }
2476
2477
3/4
✓ Branch 0 taken 1395566 times.
✓ Branch 1 taken 27472 times.
✓ Branch 2 taken 1395566 times.
✗ Branch 3 not taken.
1423038 while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2478 1395566 int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2479
2480 1395566 x_ctb = (ctb_addr_rs % ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;
2481 1395566 y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;
2482 1395566 hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts);
2483
2484 1395566 ret = ff_hevc_cabac_init(s, ctb_addr_ts, 0);
2485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1395566 times.
1395566 if (ret < 0) {
2486 s->tab_slice_address[ctb_addr_rs] = -1;
2487 return ret;
2488 }
2489
2490 1395566 hls_sao_param(s, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size);
2491
2492 1395566 s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2493 1395566 s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2494 1395566 s->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2495
2496 1395566 more_data = hls_coding_quadtree(s, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0);
2497
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1395565 times.
1395566 if (more_data < 0) {
2498 1 s->tab_slice_address[ctb_addr_rs] = -1;
2499 1 return more_data;
2500 }
2501
2502
2503 1395565 ctb_addr_ts++;
2504 1395565 ff_hevc_save_states(s, ctb_addr_ts);
2505 1395565 ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size);
2506 }
2507
2508
2/2
✓ Branch 0 taken 13964 times.
✓ Branch 1 taken 13508 times.
27472 if (x_ctb + ctb_size >= s->ps.sps->width &&
2509
2/2
✓ Branch 0 taken 9483 times.
✓ Branch 1 taken 4481 times.
13964 y_ctb + ctb_size >= s->ps.sps->height)
2510 9483 ff_hevc_hls_filter(s, x_ctb, y_ctb, ctb_size);
2511
2512 27472 return ctb_addr_ts;
2513 }
2514
2515 27473 static int hls_slice_data(HEVCContext *s)
2516 {
2517 int arg[2];
2518 int ret[2];
2519
2520 27473 arg[0] = 0;
2521 27473 arg[1] = 1;
2522
2523 27473 s->avctx->execute(s->avctx, hls_decode_entry, arg, ret , 1, sizeof(int));
2524 27473 return ret[0];
2525 }
2526 static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *input_ctb_row, int job, int self_id)
2527 {
2528 HEVCContext *s1 = avctxt->priv_data, *s;
2529 HEVCLocalContext *lc;
2530 int ctb_size = 1<< s1->ps.sps->log2_ctb_size;
2531 int more_data = 1;
2532 int *ctb_row_p = input_ctb_row;
2533 int ctb_row = ctb_row_p[job];
2534 int ctb_addr_rs = s1->sh.slice_ctb_addr_rs + ctb_row * ((s1->ps.sps->width + ctb_size - 1) >> s1->ps.sps->log2_ctb_size);
2535 int ctb_addr_ts = s1->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2536 int thread = ctb_row % s1->threads_number;
2537 int ret;
2538
2539 s = s1->sList[self_id];
2540 lc = s->HEVClc;
2541
2542 if(ctb_row) {
2543 ret = init_get_bits8(&lc->gb, s->data + s->sh.offset[ctb_row - 1], s->sh.size[ctb_row - 1]);
2544 if (ret < 0)
2545 goto error;
2546 ff_init_cabac_decoder(&lc->cc, s->data + s->sh.offset[(ctb_row)-1], s->sh.size[ctb_row - 1]);
2547 }
2548
2549 while(more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2550 int x_ctb = (ctb_addr_rs % s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size;
2551 int y_ctb = (ctb_addr_rs / s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size;
2552
2553 hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts);
2554
2555 ff_thread_await_progress2(s->avctx, ctb_row, thread, SHIFT_CTB_WPP);
2556
2557 if (atomic_load(&s1->wpp_err)) {
2558 ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP);
2559 return 0;
2560 }
2561
2562 ret = ff_hevc_cabac_init(s, ctb_addr_ts, thread);
2563 if (ret < 0)
2564 goto error;
2565 hls_sao_param(s, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size);
2566 more_data = hls_coding_quadtree(s, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0);
2567
2568 if (more_data < 0) {
2569 ret = more_data;
2570 goto error;
2571 }
2572
2573 ctb_addr_ts++;
2574
2575 ff_hevc_save_states(s, ctb_addr_ts);
2576 ff_thread_report_progress2(s->avctx, ctb_row, thread, 1);
2577 ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size);
2578
2579 if (!more_data && (x_ctb+ctb_size) < s->ps.sps->width && ctb_row != s->sh.num_entry_point_offsets) {
2580 atomic_store(&s1->wpp_err, 1);
2581 ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP);
2582 return 0;
2583 }
2584
2585 if ((x_ctb+ctb_size) >= s->ps.sps->width && (y_ctb+ctb_size) >= s->ps.sps->height ) {
2586 ff_hevc_hls_filter(s, x_ctb, y_ctb, ctb_size);
2587 ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP);
2588 return ctb_addr_ts;
2589 }
2590 ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2591 x_ctb+=ctb_size;
2592
2593 if(x_ctb >= s->ps.sps->width) {
2594 break;
2595 }
2596 }
2597 ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP);
2598
2599 return 0;
2600 error:
2601 s->tab_slice_address[ctb_addr_rs] = -1;
2602 atomic_store(&s1->wpp_err, 1);
2603 ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP);
2604 return ret;
2605 }
2606
2607 static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
2608 {
2609 const uint8_t *data = nal->data;
2610 int length = nal->size;
2611 HEVCLocalContext *lc = s->HEVClc;
2612 int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));
2613 int *arg = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));
2614 int64_t offset;
2615 int64_t startheader, cmpt = 0;
2616 int i, j, res = 0;
2617
2618 if (!ret || !arg) {
2619 av_free(ret);
2620 av_free(arg);
2621 return AVERROR(ENOMEM);
2622 }
2623
2624 if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * s->ps.sps->ctb_width >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) {
2625 av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
2626 s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets,
2627 s->ps.sps->ctb_width, s->ps.sps->ctb_height
2628 );
2629 res = AVERROR_INVALIDDATA;
2630 goto error;
2631 }
2632
2633 ff_alloc_entries(s->avctx, s->sh.num_entry_point_offsets + 1);
2634
2635 for (i = 1; i < s->threads_number; i++) {
2636 if (s->sList[i] && s->HEVClcList[i])
2637 continue;
2638 av_freep(&s->sList[i]);
2639 av_freep(&s->HEVClcList[i]);
2640 s->sList[i] = av_malloc(sizeof(HEVCContext));
2641 s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext));
2642 if (!s->sList[i] || !s->HEVClcList[i]) {
2643 res = AVERROR(ENOMEM);
2644 goto error;
2645 }
2646 memcpy(s->sList[i], s, sizeof(HEVCContext));
2647 s->sList[i]->HEVClc = s->HEVClcList[i];
2648 }
2649
2650 offset = (lc->gb.index >> 3);
2651
2652 for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2653 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2654 startheader--;
2655 cmpt++;
2656 }
2657 }
2658
2659 for (i = 1; i < s->sh.num_entry_point_offsets; i++) {
2660 offset += (s->sh.entry_point_offset[i - 1] - cmpt);
2661 for (j = 0, cmpt = 0, startheader = offset
2662 + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) {
2663 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2664 startheader--;
2665 cmpt++;
2666 }
2667 }
2668 s->sh.size[i - 1] = s->sh.entry_point_offset[i] - cmpt;
2669 s->sh.offset[i - 1] = offset;
2670
2671 }
2672 if (s->sh.num_entry_point_offsets != 0) {
2673 offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt;
2674 if (length < offset) {
2675 av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n");
2676 res = AVERROR_INVALIDDATA;
2677 goto error;
2678 }
2679 s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset;
2680 s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset;
2681
2682 }
2683 s->data = data;
2684
2685 for (i = 1; i < s->threads_number; i++) {
2686 s->sList[i]->HEVClc->first_qp_group = 1;
2687 s->sList[i]->HEVClc->qp_y = s->sList[0]->HEVClc->qp_y;
2688 memcpy(s->sList[i], s, sizeof(HEVCContext));
2689 s->sList[i]->HEVClc = s->HEVClcList[i];
2690 }
2691
2692 atomic_store(&s->wpp_err, 0);
2693 ff_reset_entries(s->avctx);
2694
2695 for (i = 0; i <= s->sh.num_entry_point_offsets; i++) {
2696 arg[i] = i;
2697 ret[i] = 0;
2698 }
2699
2700 if (s->ps.pps->entropy_coding_sync_enabled_flag)
2701 s->avctx->execute2(s->avctx, hls_decode_entry_wpp, arg, ret, s->sh.num_entry_point_offsets + 1);
2702
2703 for (i = 0; i <= s->sh.num_entry_point_offsets; i++)
2704 res += ret[i];
2705 error:
2706 av_free(ret);
2707 av_free(arg);
2708 return res;
2709 }
2710
2711 9484 static int set_side_data(HEVCContext *s)
2712 {
2713 9484 AVFrame *out = s->ref->frame;
2714
2715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9484 times.
9484 if (s->sei.frame_packing.present &&
2716 s->sei.frame_packing.arrangement_type >= 3 &&
2717 s->sei.frame_packing.arrangement_type <= 5 &&
2718 s->sei.frame_packing.content_interpretation_type > 0 &&
2719 s->sei.frame_packing.content_interpretation_type < 3) {
2720 AVStereo3D *stereo = av_stereo3d_create_side_data(out);
2721 if (!stereo)
2722 return AVERROR(ENOMEM);
2723
2724 switch (s->sei.frame_packing.arrangement_type) {
2725 case 3:
2726 if (s->sei.frame_packing.quincunx_subsampling)
2727 stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
2728 else
2729 stereo->type = AV_STEREO3D_SIDEBYSIDE;
2730 break;
2731 case 4:
2732 stereo->type = AV_STEREO3D_TOPBOTTOM;
2733 break;
2734 case 5:
2735 stereo->type = AV_STEREO3D_FRAMESEQUENCE;
2736 break;
2737 }
2738
2739 if (s->sei.frame_packing.content_interpretation_type == 2)
2740 stereo->flags = AV_STEREO3D_FLAG_INVERT;
2741
2742 if (s->sei.frame_packing.arrangement_type == 5) {
2743 if (s->sei.frame_packing.current_frame_is_frame0_flag)
2744 stereo->view = AV_STEREO3D_VIEW_LEFT;
2745 else
2746 stereo->view = AV_STEREO3D_VIEW_RIGHT;
2747 }
2748 }
2749
2750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9484 times.
9484 if (s->sei.display_orientation.present &&
2751 (s->sei.display_orientation.anticlockwise_rotation ||
2752 s->sei.display_orientation.hflip || s->sei.display_orientation.vflip)) {
2753 double angle = s->sei.display_orientation.anticlockwise_rotation * 360 / (double) (1 << 16);
2754 AVFrameSideData *rotation = av_frame_new_side_data(out,
2755 AV_FRAME_DATA_DISPLAYMATRIX,
2756 sizeof(int32_t) * 9);
2757 if (!rotation)
2758 return AVERROR(ENOMEM);
2759
2760 av_display_rotation_set((int32_t *)rotation->data, angle);
2761 av_display_matrix_flip((int32_t *)rotation->data,
2762 s->sei.display_orientation.hflip,
2763 s->sei.display_orientation.vflip);
2764 }
2765
2766 // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1
2767 // so the side data persists for the entire coded video sequence.
2768
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9482 times.
9484 if (s->sei.mastering_display.present > 0 &&
2769
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 IS_IRAP(s) && s->no_rasl_output_flag) {
2770 2 s->sei.mastering_display.present--;
2771 }
2772
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9482 times.
9484 if (s->sei.mastering_display.present) {
2773 // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b
2774 2 const int mapping[3] = {2, 0, 1};
2775 2 const int chroma_den = 50000;
2776 2 const int luma_den = 10000;
2777 int i;
2778 AVMasteringDisplayMetadata *metadata =
2779 2 av_mastering_display_metadata_create_side_data(out);
2780
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!metadata)
2781 return AVERROR(ENOMEM);
2782
2783
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (i = 0; i < 3; i++) {
2784 6 const int j = mapping[i];
2785 6 metadata->display_primaries[i][0].num = s->sei.mastering_display.display_primaries[j][0];
2786 6 metadata->display_primaries[i][0].den = chroma_den;
2787 6 metadata->display_primaries[i][1].num = s->sei.mastering_display.display_primaries[j][1];
2788 6 metadata->display_primaries[i][1].den = chroma_den;
2789 }
2790 2 metadata->white_point[0].num = s->sei.mastering_display.white_point[0];
2791 2 metadata->white_point[0].den = chroma_den;
2792 2 metadata->white_point[1].num = s->sei.mastering_display.white_point[1];
2793 2 metadata->white_point[1].den = chroma_den;
2794
2795 2 metadata->max_luminance.num = s->sei.mastering_display.max_luminance;
2796 2 metadata->max_luminance.den = luma_den;
2797 2 metadata->min_luminance.num = s->sei.mastering_display.min_luminance;
2798 2 metadata->min_luminance.den = luma_den;
2799 2 metadata->has_luminance = 1;
2800 2 metadata->has_primaries = 1;
2801
2802 2 av_log(s->avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
2803 2 av_log(s->avctx, AV_LOG_DEBUG,
2804 "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
2805 av_q2d(metadata->display_primaries[0][0]),
2806 av_q2d(metadata->display_primaries[0][1]),
2807 av_q2d(metadata->display_primaries[1][0]),
2808 av_q2d(metadata->display_primaries[1][1]),
2809 av_q2d(metadata->display_primaries[2][0]),
2810 av_q2d(metadata->display_primaries[2][1]),
2811 av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]));
2812 2 av_log(s->avctx, AV_LOG_DEBUG,
2813 "min_luminance=%f, max_luminance=%f\n",
2814 av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
2815 }
2816 // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1
2817 // so the side data persists for the entire coded video sequence.
2818
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9482 times.
9484 if (s->sei.content_light.present > 0 &&
2819
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 IS_IRAP(s) && s->no_rasl_output_flag) {
2820 2 s->sei.content_light.present--;
2821 }
2822
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9482 times.
9484 if (s->sei.content_light.present) {
2823 AVContentLightMetadata *metadata =
2824 2 av_content_light_metadata_create_side_data(out);
2825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!metadata)
2826 return AVERROR(ENOMEM);
2827 2 metadata->MaxCLL = s->sei.content_light.max_content_light_level;
2828 2 metadata->MaxFALL = s->sei.content_light.max_pic_average_light_level;
2829
2830 2 av_log(s->avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
2831 2 av_log(s->avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
2832 metadata->MaxCLL, metadata->MaxFALL);
2833 }
2834
2835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9484 times.
9484 if (s->sei.a53_caption.buf_ref) {
2836 HEVCSEIA53Caption *a53 = &s->sei.a53_caption;
2837
2838 AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_A53_CC, a53->buf_ref);
2839 if (!sd)
2840 av_buffer_unref(&a53->buf_ref);
2841 a53->buf_ref = NULL;
2842 }
2843
2844
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9484 times.
9490 for (int i = 0; i < s->sei.unregistered.nb_buf_ref; i++) {
2845 6 HEVCSEIUnregistered *unreg = &s->sei.unregistered;
2846
2847
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (unreg->buf_ref[i]) {
2848 6 AVFrameSideData *sd = av_frame_new_side_data_from_buf(out,
2849 AV_FRAME_DATA_SEI_UNREGISTERED,
2850 6 unreg->buf_ref[i]);
2851
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!sd)
2852 av_buffer_unref(&unreg->buf_ref[i]);
2853 6 unreg->buf_ref[i] = NULL;
2854 }
2855 }
2856 9484 s->sei.unregistered.nb_buf_ref = 0;
2857
2858
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9482 times.
9484 if (s->sei.timecode.present) {
2859 uint32_t *tc_sd;
2860 char tcbuf[AV_TIMECODE_STR_SIZE];
2861 2 AVFrameSideData *tcside = av_frame_new_side_data(out, AV_FRAME_DATA_S12M_TIMECODE,
2862 sizeof(uint32_t) * 4);
2863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!tcside)
2864 return AVERROR(ENOMEM);
2865
2866 2 tc_sd = (uint32_t*)tcside->data;
2867 2 tc_sd[0] = s->sei.timecode.num_clock_ts;
2868
2869
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (int i = 0; i < tc_sd[0]; i++) {
2870 2 int drop = s->sei.timecode.cnt_dropped_flag[i];
2871 2 int hh = s->sei.timecode.hours_value[i];
2872 2 int mm = s->sei.timecode.minutes_value[i];
2873 2 int ss = s->sei.timecode.seconds_value[i];
2874 2 int ff = s->sei.timecode.n_frames[i];
2875
2876 2 tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff);
2877 2 av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0);
2878 2 av_dict_set(&out->metadata, "timecode", tcbuf, 0);
2879 }
2880
2881 2 s->sei.timecode.num_clock_ts = 0;
2882 }
2883
2884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9484 times.
9484 if (s->sei.film_grain_characteristics.present &&
2885 (s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN)) {
2886 HEVCSEIFilmGrainCharacteristics *fgc = &s->sei.film_grain_characteristics;
2887 AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(out);
2888 if (!fgp)
2889 return AVERROR(ENOMEM);
2890
2891 fgp->type = AV_FILM_GRAIN_PARAMS_H274;
2892
2893 fgp->codec.h274.model_id = fgc->model_id;
2894 if (fgc->separate_colour_description_present_flag) {
2895 fgp->codec.h274.bit_depth_luma = fgc->bit_depth_luma;
2896 fgp->codec.h274.bit_depth_chroma = fgc->bit_depth_chroma;
2897 fgp->codec.h274.color_range = fgc->full_range + 1;
2898 fgp->codec.h274.color_primaries = fgc->color_primaries;
2899 fgp->codec.h274.color_trc = fgc->transfer_characteristics;
2900 fgp->codec.h274.color_space = fgc->matrix_coeffs;
2901 } else {
2902 const HEVCSPS *sps = s->ps.sps;
2903 const VUI *vui = &sps->vui;
2904 fgp->codec.h274.bit_depth_luma = sps->bit_depth;
2905 fgp->codec.h274.bit_depth_chroma = sps->bit_depth_chroma;
2906 if (vui->video_signal_type_present_flag)
2907 fgp->codec.h274.color_range = vui->video_full_range_flag + 1;
2908 else
2909 fgp->codec.h274.color_range = AVCOL_RANGE_UNSPECIFIED;
2910 if (vui->colour_description_present_flag) {
2911 fgp->codec.h274.color_primaries = vui->colour_primaries;
2912 fgp->codec.h274.color_trc = vui->transfer_characteristic;
2913 fgp->codec.h274.color_space = vui->matrix_coeffs;
2914 } else {
2915 fgp->codec.h274.color_primaries = AVCOL_PRI_UNSPECIFIED;
2916 fgp->codec.h274.color_trc = AVCOL_TRC_UNSPECIFIED;
2917 fgp->codec.h274.color_space = AVCOL_SPC_UNSPECIFIED;
2918 }
2919 }
2920 fgp->codec.h274.blending_mode_id = fgc->blending_mode_id;
2921 fgp->codec.h274.log2_scale_factor = fgc->log2_scale_factor;
2922
2923 memcpy(&fgp->codec.h274.component_model_present, &fgc->comp_model_present_flag,
2924 sizeof(fgp->codec.h274.component_model_present));
2925 memcpy(&fgp->codec.h274.num_intensity_intervals, &fgc->num_intensity_intervals,
2926 sizeof(fgp->codec.h274.num_intensity_intervals));
2927 memcpy(&fgp->codec.h274.num_model_values, &fgc->num_model_values,
2928 sizeof(fgp->codec.h274.num_model_values));
2929 memcpy(&fgp->codec.h274.intensity_interval_lower_bound, &fgc->intensity_interval_lower_bound,
2930 sizeof(fgp->codec.h274.intensity_interval_lower_bound));
2931 memcpy(&fgp->codec.h274.intensity_interval_upper_bound, &fgc->intensity_interval_upper_bound,
2932 sizeof(fgp->codec.h274.intensity_interval_upper_bound));
2933 memcpy(&fgp->codec.h274.comp_model_value, &fgc->comp_model_value,
2934 sizeof(fgp->codec.h274.comp_model_value));
2935
2936 fgc->present = fgc->persistence_flag;
2937 }
2938
2939
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9482 times.
9484 if (s->sei.dynamic_hdr_plus.info) {
2940 2 AVBufferRef *info_ref = av_buffer_ref(s->sei.dynamic_hdr_plus.info);
2941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!info_ref)
2942 return AVERROR(ENOMEM);
2943
2944
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, info_ref)) {
2945 av_buffer_unref(&info_ref);
2946 return AVERROR(ENOMEM);
2947 }
2948 }
2949
2950 9484 return 0;
2951 }
2952
2953 9484 static int hevc_frame_start(HEVCContext *s)
2954 {
2955 9484 HEVCLocalContext *lc = s->HEVClc;
2956 9484 int pic_size_in_ctb = ((s->ps.sps->width >> s->ps.sps->log2_min_cb_size) + 1) *
2957 9484 ((s->ps.sps->height >> s->ps.sps->log2_min_cb_size) + 1);
2958 int ret;
2959
2960 9484 memset(s->horizontal_bs, 0, s->bs_width * s->bs_height);
2961 9484 memset(s->vertical_bs, 0, s->bs_width * s->bs_height);
2962 9484 memset(s->cbf_luma, 0, s->ps.sps->min_tb_width * s->ps.sps->min_tb_height);
2963 9484 memset(s->is_pcm, 0, (s->ps.sps->min_pu_width + 1) * (s->ps.sps->min_pu_height + 1));
2964 9484 memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address));
2965
2966 9484 s->is_decoded = 0;
2967 9484 s->first_nal_type = s->nal_unit_type;
2968
2969
14/14
✓ Branch 0 taken 9125 times.
✓ Branch 1 taken 359 times.
✓ Branch 2 taken 9114 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 9112 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9105 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9104 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 155 times.
✓ Branch 11 taken 8949 times.
✓ Branch 12 taken 8 times.
✓ Branch 13 taken 147 times.
9484 s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos);
2970
2971
2/2
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 8860 times.
9484 if (s->ps.pps->tiles_enabled_flag)
2972 624 lc->end_of_tiles_x = s->ps.pps->column_width[0] << s->ps.sps->log2_ctb_size;
2973
2974 9484 ret = ff_hevc_set_new_ref(s, &s->frame, s->poc);
2975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9484 times.
9484 if (ret < 0)
2976 goto fail;
2977
2978 9484 ret = ff_hevc_frame_rps(s);
2979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9484 times.
9484 if (ret < 0) {
2980 av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n");
2981 goto fail;
2982 }
2983
2984
3/4
✓ Branch 0 taken 535 times.
✓ Branch 1 taken 8949 times.
✓ Branch 2 taken 535 times.
✗ Branch 3 not taken.
9484 s->ref->frame->key_frame = IS_IRAP(s);
2985
2986 9484 ret = set_side_data(s);
2987
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9484 times.
9484 if (ret < 0)
2988 goto fail;
2989
2990 9484 s->frame->pict_type = 3 - s->sh.slice_type;
2991
2992
3/4
✓ Branch 0 taken 535 times.
✓ Branch 1 taken 8949 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 535 times.
9484 if (!IS_IRAP(s))
2993 8949 ff_hevc_bump_frame(s);
2994
2995 9484 av_frame_unref(s->output_frame);
2996 9484 ret = ff_hevc_output_frame(s, s->output_frame, 0);
2997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9484 times.
9484 if (ret < 0)
2998 goto fail;
2999
3000
1/2
✓ Branch 0 taken 9484 times.
✗ Branch 1 not taken.
9484 if (!s->avctx->hwaccel)
3001 9484 ff_thread_finish_setup(s->avctx);
3002
3003 9484 return 0;
3004
3005 fail:
3006 if (s->ref)
3007 ff_hevc_unref_frame(s, s->ref, ~0);
3008 s->ref = NULL;
3009 return ret;
3010 }
3011
3012 37866 static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
3013 {
3014 37866 HEVCLocalContext *lc = s->HEVClc;
3015 37866 GetBitContext *gb = &lc->gb;
3016 int ctb_addr_ts, ret;
3017
3018 37866 *gb = nal->gb;
3019 37866 s->nal_unit_type = nal->type;
3020 37866 s->temporal_id = nal->temporal_id;
3021
3022
7/8
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 397 times.
✓ Branch 2 taken 1355 times.
✓ Branch 3 taken 7490 times.
✓ Branch 4 taken 27581 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 639 times.
✗ Branch 7 not taken.
37866 switch (s->nal_unit_type) {
3023 400 case HEVC_NAL_VPS:
3024
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
400 if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) {
3025 ret = s->avctx->hwaccel->decode_params(s->avctx,
3026 nal->type,
3027 nal->raw_data,
3028 nal->raw_size);
3029 if (ret < 0)
3030 goto fail;
3031 }
3032 400 ret = ff_hevc_decode_nal_vps(gb, s->avctx, &s->ps);
3033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 400 times.
400 if (ret < 0)
3034 goto fail;
3035 400 break;
3036 397 case HEVC_NAL_SPS:
3037
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 397 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
397 if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) {
3038 ret = s->avctx->hwaccel->decode_params(s->avctx,
3039 nal->type,
3040 nal->raw_data,
3041 nal->raw_size);
3042 if (ret < 0)
3043 goto fail;
3044 }
3045 397 ret = ff_hevc_decode_nal_sps(gb, s->avctx, &s->ps,
3046 s->apply_defdispwin);
3047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 397 times.
397 if (ret < 0)
3048 goto fail;
3049 397 break;
3050 1355 case HEVC_NAL_PPS:
3051
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1355 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1355 if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) {
3052 ret = s->avctx->hwaccel->decode_params(s->avctx,
3053 nal->type,
3054 nal->raw_data,
3055 nal->raw_size);
3056 if (ret < 0)
3057 goto fail;
3058 }
3059 1355 ret = ff_hevc_decode_nal_pps(gb, s->avctx, &s->ps);
3060
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1353 times.
1355 if (ret < 0)
3061 2 goto fail;
3062 1353 break;
3063 7490 case HEVC_NAL_SEI_PREFIX:
3064 case HEVC_NAL_SEI_SUFFIX:
3065
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7490 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7490 if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) {
3066 ret = s->avctx->hwaccel->decode_params(s->avctx,
3067 nal->type,
3068 nal->raw_data,
3069 nal->raw_size);
3070 if (ret < 0)
3071 goto fail;
3072 }
3073 7490 ret = ff_hevc_decode_nal_sei(gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type);
3074
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 7444 times.
7490 if (ret < 0)
3075 46 goto fail;
3076 7444 break;
3077 27581 case HEVC_NAL_TRAIL_R:
3078 case HEVC_NAL_TRAIL_N:
3079 case HEVC_NAL_TSA_N:
3080 case HEVC_NAL_TSA_R:
3081 case HEVC_NAL_STSA_N:
3082 case HEVC_NAL_STSA_R:
3083 case HEVC_NAL_BLA_W_LP:
3084 case HEVC_NAL_BLA_W_RADL:
3085 case HEVC_NAL_BLA_N_LP:
3086 case HEVC_NAL_IDR_W_RADL:
3087 case HEVC_NAL_IDR_N_LP:
3088 case HEVC_NAL_CRA_NUT:
3089 case HEVC_NAL_RADL_N:
3090 case HEVC_NAL_RADL_R:
3091 case HEVC_NAL_RASL_N:
3092 case HEVC_NAL_RASL_R:
3093 27581 ret = hls_slice_header(s);
3094
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 27559 times.
27581 if (ret < 0)
3095 22 return ret;
3096
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27558 times.
27559 if (ret == 1) {
3097 1 ret = AVERROR_INVALIDDATA;
3098 1 goto fail;
3099 }
3100
3101
3102 27558 if (
3103
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 27558 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
27558 (s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
3104
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 27558 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
27558 (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
3105
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 27558 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
27558 (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s))) {
3106 break;
3107 }
3108
3109
2/2
✓ Branch 0 taken 9527 times.
✓ Branch 1 taken 18031 times.
27558 if (s->sh.first_slice_in_pic_flag) {
3110
2/2
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 9137 times.
9527 if (s->max_ra == INT_MAX) {
3111
8/8
✓ Branch 0 taken 380 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 378 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 371 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 370 times.
390 if (s->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(s)) {
3112 20 s->max_ra = s->poc;
3113 } else {
3114
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 359 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
370 if (IS_IDR(s))
3115 370 s->max_ra = INT_MIN;
3116 }
3117 }
3118
3119
4/4
✓ Branch 0 taken 9043 times.
✓ Branch 1 taken 484 times.
✓ Branch 2 taken 359 times.
✓ Branch 3 taken 8684 times.
9527 if ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&
3120
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 800 times.
843 s->poc <= s->max_ra) {
3121 43 s->is_decoded = 0;
3122 43 break;
3123 } else {
3124
3/4
✓ Branch 0 taken 463 times.
✓ Branch 1 taken 9021 times.
✓ Branch 2 taken 463 times.
✗ Branch 3 not taken.
9484 if (s->nal_unit_type == HEVC_NAL_RASL_R && s->poc > s->max_ra)
3125 463 s->max_ra = INT_MIN;
3126 }
3127
3128