FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevcdec.c
Date: 2022-01-28 07:56:06
Exec Total Coverage
Lines: 1833 2345 78.2%
Branches: 1311 1777 73.8%

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 758 static void pic_arrays_free(HEVCContext *s)
62 {
63 758 av_freep(&s->sao);
64 758 av_freep(&s->deblock);
65
66 758 av_freep(&s->skip_flag);
67 758 av_freep(&s->tab_ct_depth);
68
69 758 av_freep(&s->tab_ipm);
70 758 av_freep(&s->cbf_luma);
71 758 av_freep(&s->is_pcm);
72
73 758 av_freep(&s->qp_y_tab);
74 758 av_freep(&s->tab_slice_address);
75 758 av_freep(&s->filter_slice_edges);
76
77 758 av_freep(&s->horizontal_bs);
78 758 av_freep(&s->vertical_bs);
79
80 758 av_freep(&s->sh.entry_point_offset);
81 758 av_freep(&s->sh.size);
82 758 av_freep(&s->sh.offset);
83
84 758 av_buffer_pool_uninit(&s->tab_mvf_pool);
85 758 av_buffer_pool_uninit(&s->rpl_tab_pool);
86 758 }
87
88 /* allocate arrays that depend on frame dimensions */
89 373 static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
90 {
91 373 int log2_min_cb_size = sps->log2_min_cb_size;
92 373 int width = sps->width;
93 373 int height = sps->height;
94 373 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
95 373 ((height >> log2_min_cb_size) + 1);
96 373 int ctb_count = sps->ctb_width * sps->ctb_height;
97 373 int min_pu_size = sps->min_pu_width * sps->min_pu_height;
98
99 373 s->bs_width = (width >> 2) + 1;
100 373 s->bs_height = (height >> 2) + 1;
101
102 373 s->sao = av_calloc(ctb_count, sizeof(*s->sao));
103 373 s->deblock = av_calloc(ctb_count, sizeof(*s->deblock));
104
2/4
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 373 times.
373 if (!s->sao || !s->deblock)
105 goto fail;
106
107 373 s->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
108 373 s->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
109
2/4
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 373 times.
373 if (!s->skip_flag || !s->tab_ct_depth)
110 goto fail;
111
112 373 s->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
113 373 s->tab_ipm = av_mallocz(min_pu_size);
114 373 s->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1);
115
3/6
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 373 times.
373 if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)
116 goto fail;
117
118 373 s->filter_slice_edges = av_mallocz(ctb_count);
119 373 s->tab_slice_address = av_malloc_array(pic_size_in_ctb,
120 sizeof(*s->tab_slice_address));
121 373 s->qp_y_tab = av_malloc_array(pic_size_in_ctb,
122 sizeof(*s->qp_y_tab));
123
3/6
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 373 times.
373 if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)
124 goto fail;
125
126 373 s->horizontal_bs = av_calloc(s->bs_width, s->bs_height);
127 373 s->vertical_bs = av_calloc(s->bs_width, s->bs_height);
128
2/4
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 373 times.
373 if (!s->horizontal_bs || !s->vertical_bs)
129 goto fail;
130
131 373 s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField),
132 av_buffer_allocz);
133 373 s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab),
134 av_buffer_allocz);
135
2/4
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 373 times.
373 if (!s->tab_mvf_pool || !s->rpl_tab_pool)
136 goto fail;
137
138 373 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 19026 static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
262 {
263 19026 const HEVCSPS *sps = s->ps.sps;
264 19026 int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
265 19026 int prev_delta_msb = 0;
266 19026 unsigned int nb_sps = 0, nb_sh;
267 int i;
268
269 19026 rps->nb_refs = 0;
270
2/2
✓ Branch 0 taken 17992 times.
✓ Branch 1 taken 1034 times.
19026 if (!sps->long_term_ref_pics_present_flag)
271 17992 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 565 static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
319 {
320 565 AVCodecContext *avctx = s->avctx;
321 565 const HEVCParamSets *ps = &s->ps;
322 565 const HEVCVPS *vps = (const HEVCVPS*)ps->vps_list[sps->vps_id]->data;
323 565 const HEVCWindow *ow = &sps->output_window;
324 565 unsigned int num = 0, den = 0;
325
326 565 avctx->pix_fmt = sps->pix_fmt;
327 565 avctx->coded_width = sps->width;
328 565 avctx->coded_height = sps->height;
329 565 avctx->width = sps->width - ow->left_offset - ow->right_offset;
330 565 avctx->height = sps->height - ow->top_offset - ow->bottom_offset;
331 565 avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
332 565 avctx->profile = sps->ptl.general_ptl.profile_idc;
333 565 avctx->level = sps->ptl.general_ptl.level_idc;
334
335 565 ff_set_sar(avctx, sps->vui.sar);
336
337
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 536 times.
565 if (sps->vui.video_signal_type_present_flag)
338 29 avctx->color_range = sps->vui.video_full_range_flag ? AVCOL_RANGE_JPEG
339
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 22 times.
29 : AVCOL_RANGE_MPEG;
340 else
341 536 avctx->color_range = AVCOL_RANGE_MPEG;
342
343
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 539 times.
565 if (sps->vui.colour_description_present_flag) {
344 26 avctx->color_primaries = sps->vui.colour_primaries;
345 26 avctx->color_trc = sps->vui.transfer_characteristic;
346 26 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 565 avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
354
2/2
✓ Branch 0 taken 524 times.
✓ Branch 1 taken 41 times.
565 if (sps->chroma_format_idc == 1) {
355
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 512 times.
524 if (sps->vui.chroma_loc_info_present_flag) {
356
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (sps->vui.chroma_sample_loc_type_top_field <= 5)
357 12 avctx->chroma_sample_location = sps->vui.chroma_sample_loc_type_top_field + 1;
358 } else
359 512 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
360 }
361
362
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 542 times.
565 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 32 times.
✓ Branch 1 taken 510 times.
542 } else if (sps->vui.vui_timing_info_present_flag) {
366 32 num = sps->vui.vui_num_units_in_tick;
367 32 den = sps->vui.vui_time_scale;
368 }
369
370
3/4
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 510 times.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
565 if (num != 0 && den != 0)
371 55 av_reduce(&avctx->framerate.den, &avctx->framerate.num,
372 num, den, 1 << 30);
373 565 }
374
375 27786 static int export_stream_params_from_sei(HEVCContext *s)
376 {
377 27786 AVCodecContext *avctx = s->avctx;
378
379
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27786 times.
27786 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 27786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
27786 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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27786 times.
27786 if (s->sei.film_grain_characteristics.present)
389 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
390
391 27786 return 0;
392 }
393
394 372 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
395 {
396 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
397 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
398 CONFIG_HEVC_NVDEC_HWACCEL + \
399 CONFIG_HEVC_VAAPI_HWACCEL + \
400 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
401 CONFIG_HEVC_VDPAU_HWACCEL)
402 372 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
403
404
6/6
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 2 times.
372 switch (sps->pix_fmt) {
405 319 case AV_PIX_FMT_YUV420P:
406 case AV_PIX_FMT_YUVJ420P:
407 #if CONFIG_HEVC_DXVA2_HWACCEL
408 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
409 #endif
410 #if CONFIG_HEVC_D3D11VA_HWACCEL
411 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
412 *fmt++ = AV_PIX_FMT_D3D11;
413 #endif
414 #if CONFIG_HEVC_VAAPI_HWACCEL
415 319 *fmt++ = AV_PIX_FMT_VAAPI;
416 #endif
417 #if CONFIG_HEVC_VDPAU_HWACCEL
418 319 *fmt++ = AV_PIX_FMT_VDPAU;
419 #endif
420 #if CONFIG_HEVC_NVDEC_HWACCEL
421 *fmt++ = AV_PIX_FMT_CUDA;
422 #endif
423 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
424 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
425 #endif
426 319 break;
427 25 case AV_PIX_FMT_YUV420P10:
428 #if CONFIG_HEVC_DXVA2_HWACCEL
429 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
430 #endif
431 #if CONFIG_HEVC_D3D11VA_HWACCEL
432 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
433 *fmt++ = AV_PIX_FMT_D3D11;
434 #endif
435 #if CONFIG_HEVC_VAAPI_HWACCEL
436 25 *fmt++ = AV_PIX_FMT_VAAPI;
437 #endif
438 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
439 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
440 #endif
441 #if CONFIG_HEVC_VDPAU_HWACCEL
442 25 *fmt++ = AV_PIX_FMT_VDPAU;
443 #endif
444 #if CONFIG_HEVC_NVDEC_HWACCEL
445 *fmt++ = AV_PIX_FMT_CUDA;
446 #endif
447 25 break;
448 4 case AV_PIX_FMT_YUV444P:
449 #if CONFIG_HEVC_VDPAU_HWACCEL
450 4 *fmt++ = AV_PIX_FMT_VDPAU;
451 #endif
452 #if CONFIG_HEVC_NVDEC_HWACCEL
453 *fmt++ = AV_PIX_FMT_CUDA;
454 #endif
455 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
456 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
457 #endif
458 4 break;
459 12 case AV_PIX_FMT_YUV422P:
460 case AV_PIX_FMT_YUV422P10LE:
461 #if CONFIG_HEVC_VAAPI_HWACCEL
462 12 *fmt++ = AV_PIX_FMT_VAAPI;
463 #endif
464 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
465 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
466 #endif
467 12 break;
468 10 case AV_PIX_FMT_YUV444P10:
469 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
470 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
471 #endif
472 case AV_PIX_FMT_YUV420P12:
473 case AV_PIX_FMT_YUV444P12:
474 #if CONFIG_HEVC_VDPAU_HWACCEL
475 10 *fmt++ = AV_PIX_FMT_VDPAU;
476 #endif
477 #if CONFIG_HEVC_NVDEC_HWACCEL
478 *fmt++ = AV_PIX_FMT_CUDA;
479 #endif
480 10 break;
481 }
482
483 372 *fmt++ = sps->pix_fmt;
484 372 *fmt = AV_PIX_FMT_NONE;
485
486 372 return ff_thread_get_format(s->avctx, pix_fmts);
487 }
488
489 373 static int set_sps(HEVCContext *s, const HEVCSPS *sps,
490 enum AVPixelFormat pix_fmt)
491 {
492 int ret, i;
493
494 373 pic_arrays_free(s);
495 373 s->ps.sps = NULL;
496 373 s->ps.vps = NULL;
497
498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 373 times.
373 if (!sps)
499 return 0;
500
501 373 ret = pic_arrays_init(s, sps);
502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 373 times.
373 if (ret < 0)
503 goto fail;
504
505 373 export_stream_params(s, sps);
506
507 373 s->avctx->pix_fmt = pix_fmt;
508
509 373 ff_hevc_pred_init(&s->hpc, sps->bit_depth);
510 373 ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
511 373 ff_videodsp_init (&s->vdsp, sps->bit_depth);
512
513
2/2
✓ Branch 0 taken 1119 times.
✓ Branch 1 taken 373 times.
1492 for (i = 0; i < 3; i++) {
514 1119 av_freep(&s->sao_pixel_buffer_h[i]);
515 1119 av_freep(&s->sao_pixel_buffer_v[i]);
516 }
517
518
3/4
✓ Branch 0 taken 318 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 318 times.
✗ Branch 3 not taken.
373 if (sps->sao_enabled && !s->avctx->hwaccel) {
519
2/2
✓ Branch 0 taken 316 times.
✓ Branch 1 taken 2 times.
318 int c_count = (sps->chroma_format_idc != 0) ? 3 : 1;
520 int c_idx;
521
522
2/2
✓ Branch 0 taken 950 times.
✓ Branch 1 taken 318 times.
1268 for(c_idx = 0; c_idx < c_count; c_idx++) {
523 950 int w = sps->width >> sps->hshift[c_idx];
524 950 int h = sps->height >> sps->vshift[c_idx];
525 950 s->sao_pixel_buffer_h[c_idx] =
526 950 av_malloc((w * 2 * sps->ctb_height) <<
527 950 sps->pixel_shift);
528 950 s->sao_pixel_buffer_v[c_idx] =
529 950 av_malloc((h * 2 * sps->ctb_width) <<
530 950 sps->pixel_shift);
531
1/2
✓ Branch 0 taken 950 times.
✗ Branch 1 not taken.
950 if (!s->sao_pixel_buffer_h[c_idx] ||
532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 950 times.
950 !s->sao_pixel_buffer_v[c_idx])
533 goto fail;
534 }
535 }
536
537 373 s->ps.sps = sps;
538 373 s->ps.vps = (HEVCVPS*) s->ps.vps_list[s->ps.sps->vps_id]->data;
539
540 373 return 0;
541
542 fail:
543 pic_arrays_free(s);
544 for (i = 0; i < 3; i++) {
545 av_freep(&s->sao_pixel_buffer_h[i]);
546 av_freep(&s->sao_pixel_buffer_v[i]);
547 }
548 s->ps.sps = NULL;
549 return ret;
550 }
551
552 27583 static int hls_slice_header(HEVCContext *s)
553 {
554 27583 GetBitContext *gb = &s->HEVClc->gb;
555 27583 SliceHeader *sh = &s->sh;
556 int i, ret;
557
558 // Coded parameters
559 27583 sh->first_slice_in_pic_flag = get_bits1(gb);
560
4/4
✓ Branch 0 taken 17990 times.
✓ Branch 1 taken 9593 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 17989 times.
27583 if (s->ref && sh->first_slice_in_pic_flag) {
561 1 av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
562 1 return 1; // This slice will be skipped later, do not corrupt state
563 }
564
565
12/12
✓ Branch 0 taken 26679 times.
✓ Branch 1 taken 903 times.
✓ Branch 2 taken 26667 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 26665 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 26658 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 26657 times.
✓ Branch 10 taken 381 times.
✓ Branch 11 taken 544 times.
27582 if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
566 381 s->seq_decode = (s->seq_decode + 1) & 0xff;
567 381 s->max_ra = INT_MAX;
568
4/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 359 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 10 times.
381 if (IS_IDR(s))
569 371 ff_hevc_clear_refs(s);
570 }
571 27582 sh->no_output_of_prior_pics_flag = 0;
572
3/4
✓ Branch 0 taken 1267 times.
✓ Branch 1 taken 26315 times.
✓ Branch 2 taken 1267 times.
✗ Branch 3 not taken.
27582 if (IS_IRAP(s))
573 1267 sh->no_output_of_prior_pics_flag = get_bits1(gb);
574
575 27582 sh->pps_id = get_ue_golomb_long(gb);
576
3/4
✓ Branch 0 taken 27582 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 27560 times.
27582 if (sh->pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[sh->pps_id]) {
577 22 av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id);
578 22 return AVERROR_INVALIDDATA;
579 }
580
2/2
✓ Branch 0 taken 18031 times.
✓ Branch 1 taken 9529 times.
27560 if (!sh->first_slice_in_pic_flag &&
581
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18031 times.
18031 s->ps.pps != (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data) {
582 av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
583 return AVERROR_INVALIDDATA;
584 }
585 27560 s->ps.pps = (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data;
586
4/4
✓ Branch 0 taken 342 times.
✓ Branch 1 taken 27218 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 328 times.
27560 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
587 14 sh->no_output_of_prior_pics_flag = 1;
588
589
2/2
✓ Branch 0 taken 372 times.
✓ Branch 1 taken 27188 times.
27560 if (s->ps.sps != (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data) {
590 372 const HEVCSPS *sps = (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data;
591 372 const HEVCSPS *last_sps = s->ps.sps;
592 enum AVPixelFormat pix_fmt;
593
594
5/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 370 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.
372 if (last_sps && IS_IRAP(s) && s->nal_unit_type != HEVC_NAL_CRA_NUT) {
595
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 ||
596 2 sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering !=
597
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)
598 sh->no_output_of_prior_pics_flag = 0;
599 }
600 372 ff_hevc_clear_refs(s);
601
602 372 ret = set_sps(s, sps, sps->pix_fmt);
603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372 times.
372 if (ret < 0)
604 return ret;
605
606 372 pix_fmt = get_format(s, sps);
607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372 times.
372 if (pix_fmt < 0)
608 return pix_fmt;
609 372 s->avctx->pix_fmt = pix_fmt;
610
611 372 s->seq_decode = (s->seq_decode + 1) & 0xff;
612 372 s->max_ra = INT_MAX;
613 }
614
615 27560 ret = export_stream_params_from_sei(s);
616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27560 times.
27560 if (ret < 0)
617 return ret;
618
619 27560 sh->dependent_slice_segment_flag = 0;
620
2/2
✓ Branch 0 taken 18031 times.
✓ Branch 1 taken 9529 times.
27560 if (!sh->first_slice_in_pic_flag) {
621 int slice_address_length;
622
623
2/2
✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8939 times.
18031 if (s->ps.pps->dependent_slice_segments_enabled_flag)
624 9092 sh->dependent_slice_segment_flag = get_bits1(gb);
625
626 18031 slice_address_length = av_ceil_log2(s->ps.sps->ctb_width *
627 18031 s->ps.sps->ctb_height);
628 18031 sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
629
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) {
630 av_log(s->avctx, AV_LOG_ERROR,
631 "Invalid slice segment address: %u.\n",
632 sh->slice_segment_addr);
633 return AVERROR_INVALIDDATA;
634 }
635
636
2/2
✓ Branch 0 taken 10084 times.
✓ Branch 1 taken 7947 times.
18031 if (!sh->dependent_slice_segment_flag) {
637 10084 sh->slice_addr = sh->slice_segment_addr;
638 10084 s->slice_idx++;
639 }
640 } else {
641 9529 sh->slice_segment_addr = sh->slice_addr = 0;
642 9529 s->slice_idx = 0;
643 9529 s->slice_initialized = 0;
644 }
645
646
2/2
✓ Branch 0 taken 19613 times.
✓ Branch 1 taken 7947 times.
27560 if (!sh->dependent_slice_segment_flag) {
647 19613 s->slice_initialized = 0;
648
649
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 19613 times.
19617 for (i = 0; i < s->ps.pps->num_extra_slice_header_bits; i++)
650 4 skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
651
652 19613 sh->slice_type = get_ue_golomb_long(gb);
653
2/2
✓ Branch 0 taken 18484 times.
✓ Branch 1 taken 1129 times.
19613 if (!(sh->slice_type == HEVC_SLICE_I ||
654
2/2
✓ Branch 0 taken 14743 times.
✓ Branch 1 taken 3741 times.
18484 sh->slice_type == HEVC_SLICE_P ||
655
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14743 times.
14743 sh->slice_type == HEVC_SLICE_B)) {
656 av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",
657 sh->slice_type);
658 return AVERROR_INVALIDDATA;
659 }
660
4/6
✓ Branch 0 taken 878 times.
✓ Branch 1 taken 18735 times.
✓ Branch 2 taken 878 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 878 times.
19613 if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I) {
661 av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
662 return AVERROR_INVALIDDATA;
663 }
664
665 // when flag is not present, picture is inferred to be output
666 19613 sh->pic_output_flag = 1;
667
2/2
✓ Branch 0 taken 703 times.
✓ Branch 1 taken 18910 times.
19613 if (s->ps.pps->output_flag_present_flag)
668 703 sh->pic_output_flag = get_bits1(gb);
669
670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19613 times.
19613 if (s->ps.sps->separate_colour_plane_flag)
671 sh->colour_plane_id = get_bits(gb, 2);
672
673
4/4
✓ Branch 0 taken 19038 times.
✓ Branch 1 taken 575 times.
✓ Branch 2 taken 19026 times.
✓ Branch 3 taken 12 times.
38639 if (!IS_IDR(s)) {
674 int poc, pos;
675
676 19026 sh->pic_order_cnt_lsb = get_bits(gb, s->ps.sps->log2_max_poc_lsb);
677 19026 poc = ff_hevc_compute_poc(s->ps.sps, s->pocTid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
678
3/4
✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9158 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
19026 if (!sh->first_slice_in_pic_flag && poc != s->poc) {
679 av_log(s->avctx, AV_LOG_WARNING,
680 "Ignoring POC change between slices: %d -> %d\n", s->poc, poc);
681 if (s->avctx->err_recognition & AV_EF_EXPLODE)
682 return AVERROR_INVALIDDATA;
683 poc = s->poc;
684 }
685 19026 s->poc = poc;
686
687 19026 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
688 19026 pos = get_bits_left(gb);
689
2/2
✓ Branch 0 taken 3214 times.
✓ Branch 1 taken 15812 times.
19026 if (!sh->short_term_ref_pic_set_sps_flag) {
690 3214 ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, s->ps.sps, 1);
691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3214 times.
3214 if (ret < 0)
692 return ret;
693
694 3214 sh->short_term_rps = &sh->slice_rps;
695 } else {
696 int numbits, rps_idx;
697
698
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15812 times.
15812 if (!s->ps.sps->nb_st_rps) {
699 av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
700 return AVERROR_INVALIDDATA;
701 }
702
703 15812 numbits = av_ceil_log2(s->ps.sps->nb_st_rps);
704
2/2
✓ Branch 0 taken 15784 times.
✓ Branch 1 taken 28 times.
15812 rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
705 15812 sh->short_term_rps = &s->ps.sps->st_rps[rps_idx];
706 }
707 19026 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
708
709 19026 pos = get_bits_left(gb);
710 19026 ret = decode_lt_rps(s, &sh->long_term_rps, gb);
711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19026 times.
19026 if (ret < 0) {
712 av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
713 if (s->avctx->err_recognition & AV_EF_EXPLODE)
714 return AVERROR_INVALIDDATA;
715 }
716 19026 sh->long_term_ref_pic_set_size = pos - get_bits_left(gb);
717
718
2/2
✓ Branch 0 taken 16595 times.
✓ Branch 1 taken 2431 times.
19026 if (s->ps.sps->sps_temporal_mvp_enabled_flag)
719 16595 sh->slice_temporal_mvp_enabled_flag = get_bits1(gb);
720 else
721 2431 sh->slice_temporal_mvp_enabled_flag = 0;
722 } else {
723 587 s->sh.short_term_rps = NULL;
724 587 s->poc = 0;
725 }
726
727 /* 8.3.1 */
728
4/4
✓ Branch 0 taken 9529 times.
✓ Branch 1 taken 10084 times.
✓ Branch 2 taken 9186 times.
✓ Branch 3 taken 343 times.
19613 if (sh->first_slice_in_pic_flag && s->temporal_id == 0 &&
729
2/2
✓ Branch 0 taken 6727 times.
✓ Branch 1 taken 2459 times.
9186 s->nal_unit_type != HEVC_NAL_TRAIL_N &&
730
1/2
✓ Branch 0 taken 6727 times.
✗ Branch 1 not taken.
6727 s->nal_unit_type != HEVC_NAL_TSA_N &&
731
1/2
✓ Branch 0 taken 6727 times.
✗ Branch 1 not taken.
6727 s->nal_unit_type != HEVC_NAL_STSA_N &&
732
2/2
✓ Branch 0 taken 6705 times.
✓ Branch 1 taken 22 times.
6727 s->nal_unit_type != HEVC_NAL_RADL_N &&
733
2/2
✓ Branch 0 taken 6686 times.
✓ Branch 1 taken 19 times.
6705 s->nal_unit_type != HEVC_NAL_RADL_R &&
734
2/2
✓ Branch 0 taken 6329 times.
✓ Branch 1 taken 357 times.
6686 s->nal_unit_type != HEVC_NAL_RASL_N &&
735
2/2
✓ Branch 0 taken 5860 times.
✓ Branch 1 taken 469 times.
6329 s->nal_unit_type != HEVC_NAL_RASL_R)
736 5860 s->pocTid0 = s->poc;
737
738
2/2
✓ Branch 0 taken 16100 times.
✓ Branch 1 taken 3513 times.
19613 if (s->ps.sps->sao_enabled) {
739 16100 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
740
2/2
✓ Branch 0 taken 16098 times.
✓ Branch 1 taken 2 times.
16100 if (s->ps.sps->chroma_format_idc) {
741 16098 sh->slice_sample_adaptive_offset_flag[1] =
742 16098 sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb);
743 }
744 } else {
745 3513 sh->slice_sample_adaptive_offset_flag[0] = 0;
746 3513 sh->slice_sample_adaptive_offset_flag[1] = 0;
747 3513 sh->slice_sample_adaptive_offset_flag[2] = 0;
748 }
749
750 19613 sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
751
4/4
✓ Branch 0 taken 15872 times.
✓ Branch 1 taken 3741 times.
✓ Branch 2 taken 14743 times.
✓ Branch 3 taken 1129 times.
19613 if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
752 int nb_refs;
753
754 18484 sh->nb_refs[L0] = s->ps.pps->num_ref_idx_l0_default_active;
755
2/2
✓ Branch 0 taken 14743 times.
✓ Branch 1 taken 3741 times.
18484 if (sh->slice_type == HEVC_SLICE_B)
756 14743 sh->nb_refs[L1] = s->ps.pps->num_ref_idx_l1_default_active;
757
758
2/2
✓ Branch 1 taken 4861 times.
✓ Branch 2 taken 13623 times.
18484 if (get_bits1(gb)) { // num_ref_idx_active_override_flag
759 4861 sh->nb_refs[L0] = get_ue_golomb_long(gb) + 1;
760
2/2
✓ Branch 0 taken 2699 times.
✓ Branch 1 taken 2162 times.
4861 if (sh->slice_type == HEVC_SLICE_B)
761 2699 sh->nb_refs[L1] = get_ue_golomb_long(gb) + 1;
762 }
763
2/4
✓ Branch 0 taken 18484 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18484 times.
18484 if (sh->nb_refs[L0] > HEVC_MAX_REFS || sh->nb_refs[L1] > HEVC_MAX_REFS) {
764 av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n",
765 sh->nb_refs[L0], sh->nb_refs[L1]);
766 return AVERROR_INVALIDDATA;
767 }
768
769 18484 sh->rpl_modification_flag[0] = 0;
770 18484 sh->rpl_modification_flag[1] = 0;
771 18484 nb_refs = ff_hevc_frame_nb_refs(s);
772
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18484 times.
18484 if (!nb_refs) {
773 av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
774 return AVERROR_INVALIDDATA;
775 }
776
777
4/4
✓ Branch 0 taken 1653 times.
✓ Branch 1 taken 16831 times.
✓ Branch 2 taken 1596 times.
✓ Branch 3 taken 57 times.
18484 if (s->ps.pps->lists_modification_present_flag && nb_refs > 1) {
778 1596 sh->rpl_modification_flag[0] = get_bits1(gb);
779
2/2
✓ Branch 0 taken 1176 times.
✓ Branch 1 taken 420 times.
1596 if (sh->rpl_modification_flag[0]) {
780
2/2
✓ Branch 0 taken 2779 times.
✓ Branch 1 taken 1176 times.
3955 for (i = 0; i < sh->nb_refs[L0]; i++)
781 2779 sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs));
782 }
783
784
1/2
✓ Branch 0 taken 1596 times.
✗ Branch 1 not taken.
1596 if (sh->slice_type == HEVC_SLICE_B) {
785 1596 sh->rpl_modification_flag[1] = get_bits1(gb);
786
2/2
✓ Branch 0 taken 652 times.
✓ Branch 1 taken 944 times.
1596 if (sh->rpl_modification_flag[1] == 1)
787
2/2
✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
2207 for (i = 0; i < sh->nb_refs[L1]; i++)
788 1555 sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs));
789 }
790 }
791
792
2/2
✓ Branch 0 taken 14743 times.
✓ Branch 1 taken 3741 times.
18484 if (sh->slice_type == HEVC_SLICE_B)
793 14743 sh->mvd_l1_zero_flag = get_bits1(gb);
794
795
2/2
✓ Branch 0 taken 15792 times.
✓ Branch 1 taken 2692 times.
18484 if (s->ps.pps->cabac_init_present_flag)
796 15792 sh->cabac_init_flag = get_bits1(gb);
797 else
798 2692 sh->cabac_init_flag = 0;
799
800 18484 sh->collocated_ref_idx = 0;
801
2/2
✓ Branch 0 taken 16146 times.
✓ Branch 1 taken 2338 times.
18484 if (sh->slice_temporal_mvp_enabled_flag) {
802 16146 sh->collocated_list = L0;
803
2/2
✓ Branch 0 taken 14241 times.
✓ Branch 1 taken 1905 times.
16146 if (sh->slice_type == HEVC_SLICE_B)
804 14241 sh->collocated_list = !get_bits1(gb);
805
806
2/2
✓ Branch 0 taken 14395 times.
✓ Branch 1 taken 1751 times.
16146 if (sh->nb_refs[sh->collocated_list] > 1) {
807 14395 sh->collocated_ref_idx = get_ue_golomb_long(gb);
808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14395 times.
14395 if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) {
809 av_log(s->avctx, AV_LOG_ERROR,
810 "Invalid collocated_ref_idx: %d.\n",
811 sh->collocated_ref_idx);
812 return AVERROR_INVALIDDATA;
813 }
814 }
815 }
816
817
4/4
✓ Branch 0 taken 1431 times.
✓ Branch 1 taken 17053 times.
✓ Branch 2 taken 664 times.
✓ Branch 3 taken 767 times.
18484 if ((s->ps.pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
818
3/4
✓ Branch 0 taken 639 times.
✓ Branch 1 taken 17078 times.
✓ Branch 2 taken 639 times.
✗ Branch 3 not taken.
17717 (s->ps.pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
819 1406 int ret = pred_weight_table(s, gb);
820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1406 times.
1406 if (ret < 0)
821 return ret;
822 }
823
824 18484 sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
825
2/4
✓ Branch 0 taken 18484 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18484 times.
18484 if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
826 av_log(s->avctx, AV_LOG_ERROR,
827 "Invalid number of merging MVP candidates: %d.\n",
828 sh->max_num_merge_cand);
829 return AVERROR_INVALIDDATA;
830 }
831 }
832
833 19613 sh->slice_qp_delta = get_se_golomb(gb);
834
835
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 19363 times.
19613 if (s->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag) {
836 250 sh->slice_cb_qp_offset = get_se_golomb(gb);
837 250 sh->slice_cr_qp_offset = get_se_golomb(gb);
838
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 ||
839
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) {
840 av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n");
841 return AVERROR_INVALIDDATA;
842 }
843 } else {
844 19363 sh->slice_cb_qp_offset = 0;
845 19363 sh->slice_cr_qp_offset = 0;
846 }
847
848
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 19570 times.
19613 if (s->ps.pps->chroma_qp_offset_list_enabled_flag)
849 43 sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
850 else
851 19570 sh->cu_chroma_qp_offset_enabled_flag = 0;
852
853
2/2
✓ Branch 0 taken 2899 times.
✓ Branch 1 taken 16714 times.
19613 if (s->ps.pps->deblocking_filter_control_present_flag) {
854 2899 int deblocking_filter_override_flag = 0;
855
856
2/2
✓ Branch 0 taken 673 times.
✓ Branch 1 taken 2226 times.
2899 if (s->ps.pps->deblocking_filter_override_enabled_flag)
857 673 deblocking_filter_override_flag = get_bits1(gb);
858
859
2/2
✓ Branch 0 taken 454 times.
✓ Branch 1 taken 2445 times.
2899 if (deblocking_filter_override_flag) {
860 454 sh->disable_deblocking_filter_flag = get_bits1(gb);
861
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 120 times.
454 if (!sh->disable_deblocking_filter_flag) {
862 334 int beta_offset_div2 = get_se_golomb(gb);
863 334 int tc_offset_div2 = get_se_golomb(gb) ;
864
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 ||
865
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334 times.
334 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
866 av_log(s->avctx, AV_LOG_ERROR,
867 "Invalid deblock filter offsets: %d, %d\n",
868 beta_offset_div2, tc_offset_div2);
869 return AVERROR_INVALIDDATA;
870 }
871 334 sh->beta_offset = beta_offset_div2 * 2;
872 334 sh->tc_offset = tc_offset_div2 * 2;
873 }
874 } else {
875 2445 sh->disable_deblocking_filter_flag = s->ps.pps->disable_dbf;
876 2445 sh->beta_offset = s->ps.pps->beta_offset;
877 2445 sh->tc_offset = s->ps.pps->tc_offset;
878 }
879 } else {
880 16714 sh->disable_deblocking_filter_flag = 0;
881 16714 sh->beta_offset = 0;
882 16714 sh->tc_offset = 0;
883 }
884
885
2/2
✓ Branch 0 taken 17078 times.
✓ Branch 1 taken 2535 times.
19613 if (s->ps.pps->seq_loop_filter_across_slices_enabled_flag &&
886
2/2
✓ Branch 0 taken 11467 times.
✓ Branch 1 taken 5611 times.
17078 (sh->slice_sample_adaptive_offset_flag[0] ||
887
2/2
✓ Branch 0 taken 11449 times.
✓ Branch 1 taken 18 times.
11467 sh->slice_sample_adaptive_offset_flag[1] ||
888
2/2
✓ Branch 0 taken 11386 times.
✓ Branch 1 taken 63 times.
11449 !sh->disable_deblocking_filter_flag)) {
889 17015 sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb);
890 } else {
891 2598 sh->slice_loop_filter_across_slices_enabled_flag = s->ps.pps->seq_loop_filter_across_slices_enabled_flag;
892 }
893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
7947 } else if (!s->slice_initialized) {
894 av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
895 return AVERROR_INVALIDDATA;
896 }
897
898 27560 sh->num_entry_point_offsets = 0;
899
4/4
✓ Branch 0 taken 24653 times.
✓ Branch 1 taken 2907 times.
✓ Branch 2 taken 4574 times.
✓ Branch 3 taken 20079 times.
27560 if (s->ps.pps->tiles_enabled_flag || s->ps.pps->entropy_coding_sync_enabled_flag) {
900 7481 unsigned num_entry_point_offsets = get_ue_golomb_long(gb);
901 // It would be possible to bound this tighter but this here is simpler
902
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7481 times.
7481 if (num_entry_point_offsets > get_bits_left(gb)) {
903 av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
904 return AVERROR_INVALIDDATA;
905 }
906
907 7481 sh->num_entry_point_offsets = num_entry_point_offsets;
908
2/2
✓ Branch 0 taken 2011 times.
✓ Branch 1 taken 5470 times.
7481 if (sh->num_entry_point_offsets > 0) {
909 2011 int offset_len = get_ue_golomb_long(gb) + 1;
910
911
2/4
✓ Branch 0 taken 2011 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2011 times.
2011 if (offset_len < 1 || offset_len > 32) {
912 sh->num_entry_point_offsets = 0;
913 av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len);
914 return AVERROR_INVALIDDATA;
915 }
916
917 2011 av_freep(&sh->entry_point_offset);
918 2011 av_freep(&sh->offset);
919 2011 av_freep(&sh->size);
920 2011 sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
921 2011 sh->offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(int));
922 2011 sh->size = av_malloc_array(sh->num_entry_point_offsets, sizeof(int));
923
3/6
✓ Branch 0 taken 2011 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2011 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2011 times.
2011 if (!sh->entry_point_offset || !sh->offset || !sh->size) {
924 sh->num_entry_point_offsets = 0;
925 av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
926 return AVERROR(ENOMEM);
927 }
928
2/2
✓ Branch 0 taken 7838 times.
✓ Branch 1 taken 2011 times.
9849 for (i = 0; i < sh->num_entry_point_offsets; i++) {
929 7838 unsigned val = get_bits_long(gb, offset_len);
930 7838 sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
931 }
932
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2011 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2011 if (s->threads_number > 1 && (s->ps.pps->num_tile_rows > 1 || s->ps.pps->num_tile_columns > 1)) {
933 s->enable_parallel_tiles = 0; // TODO: you can enable tiles in parallel here
934 s->threads_number = 1;
935 } else
936 2011 s->enable_parallel_tiles = 0;
937 } else
938 5470 s->enable_parallel_tiles = 0;
939 }
940
941
2/2
✓ Branch 0 taken 2765 times.
✓ Branch 1 taken 24795 times.
27560 if (s->ps.pps->slice_header_extension_present_flag) {
942 2765 unsigned int length = get_ue_golomb_long(gb);
943
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2765 times.
2765 if (length*8LL > get_bits_left(gb)) {
944 av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n");
945 return AVERROR_INVALIDDATA;
946 }
947
2/2
✓ Branch 0 taken 20264 times.
✓ Branch 1 taken 2765 times.
23029 for (i = 0; i < length; i++)
948 20264 skip_bits(gb, 8); // slice_header_extension_data_byte
949 }
950
951 // Inferred parameters
952 27560 sh->slice_qp = 26U + s->ps.pps->pic_init_qp_minus26 + sh->slice_qp_delta;
953
1/2
✓ Branch 0 taken 27560 times.
✗ Branch 1 not taken.
27560 if (sh->slice_qp > 51 ||
954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27560 times.
27560 sh->slice_qp < -s->ps.sps->qp_bd_offset) {
955 av_log(s->avctx, AV_LOG_ERROR,
956 "The slice_qp %d is outside the valid range "
957 "[%d, 51].\n",
958 sh->slice_qp,
959 -s->ps.sps->qp_bd_offset);
960 return AVERROR_INVALIDDATA;
961 }
962
963 27560 sh->slice_ctb_addr_rs = sh->slice_segment_addr;
964
965
3/4
✓ Branch 0 taken 9529 times.
✓ Branch 1 taken 18031 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9529 times.
27560 if (!s->sh.slice_ctb_addr_rs && s->sh.dependent_slice_segment_flag) {
966 av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
967 return AVERROR_INVALIDDATA;
968 }
969
970
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27560 times.
27560 if (get_bits_left(gb) < 0) {
971 av_log(s->avctx, AV_LOG_ERROR,
972 "Overread slice header by %d bits\n", -get_bits_left(gb));
973 return AVERROR_INVALIDDATA;
974 }
975
976 27560 s->HEVClc->first_qp_group = !s->sh.dependent_slice_segment_flag;
977
978
2/2
✓ Branch 0 taken 22562 times.
✓ Branch 1 taken 4998 times.
27560 if (!s->ps.pps->cu_qp_delta_enabled_flag)
979 22562 s->HEVClc->qp_y = s->sh.slice_qp;
980
981 27560 s->slice_initialized = 1;
982 27560 s->HEVClc->tu.cu_qp_offset_cb = 0;
983 27560 s->HEVClc->tu.cu_qp_offset_cr = 0;
984
985 27560 return 0;
986 }
987
988 #define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)])
989
990 #define SET_SAO(elem, value) \
991 do { \
992 if (!sao_merge_up_flag && !sao_merge_left_flag) \
993 sao->elem = value; \
994 else if (sao_merge_left_flag) \
995 sao->elem = CTB(s->sao, rx-1, ry).elem; \
996 else if (sao_merge_up_flag) \
997 sao->elem = CTB(s->sao, rx, ry-1).elem; \
998 else \
999 sao->elem = 0; \
1000 } while (0)
1001
1002 1399646 static void hls_sao_param(HEVCContext *s, int rx, int ry)
1003 {
1004 1399646 HEVCLocalContext *lc = s->HEVClc;
1005 1399646 int sao_merge_left_flag = 0;
1006 1399646 int sao_merge_up_flag = 0;
1007 1399646 SAOParams *sao = &CTB(s->sao, rx, ry);
1008 int c_idx, i;
1009
1010
2/2
✓ Branch 0 taken 816170 times.
✓ Branch 1 taken 583476 times.
1399646 if (s->sh.slice_sample_adaptive_offset_flag[0] ||
1011
2/2
✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 814526 times.
816170 s->sh.slice_sample_adaptive_offset_flag[1]) {
1012
2/2
✓ Branch 0 taken 554605 times.
✓ Branch 1 taken 30515 times.
585120 if (rx > 0) {
1013
2/2
✓ Branch 0 taken 546116 times.
✓ Branch 1 taken 8489 times.
554605 if (lc->ctb_left_flag)
1014 546116 sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(s);
1015 }
1016
4/4
✓ Branch 0 taken 535449 times.
✓ Branch 1 taken 49671 times.
✓ Branch 2 taken 262255 times.
✓ Branch 3 taken 273194 times.
585120 if (ry > 0 && !sao_merge_left_flag) {
1017
2/2
✓ Branch 0 taken 248907 times.
✓ Branch 1 taken 13348 times.
262255 if (lc->ctb_up_flag)
1018 248907 sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(s);
1019 }
1020 }
1021
1022
4/4
✓ Branch 0 taken 5598392 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4198842 times.
✓ Branch 3 taken 1399646 times.
5598488 for (c_idx = 0; c_idx < (s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) {
1023
2/2
✓ Branch 0 taken 1399646 times.
✓ Branch 1 taken 2799196 times.
4198842 int log2_sao_offset_scale = c_idx == 0 ? s->ps.pps->log2_sao_offset_scale_luma :
1024 2799196 s->ps.pps->log2_sao_offset_scale_chroma;
1025
1026
2/2
✓ Branch 0 taken 2945486 times.
✓ Branch 1 taken 1253356 times.
4198842 if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1027 2945486 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
1028 2945486 continue;
1029 }
1030
1031
2/2
✓ Branch 0 taken 334940 times.
✓ Branch 1 taken 918416 times.
1253356 if (c_idx == 2) {
1032 334940 sao->type_idx[2] = sao->type_idx[1];
1033 334940 sao->eo_class[2] = sao->eo_class[1];
1034 } else {
1035
7/8
✓ Branch 0 taken 796295 times.
✓ Branch 1 taken 122121 times.
✓ Branch 2 taken 360669 times.
✓ Branch 3 taken 435626 times.
✓ Branch 5 taken 435626 times.
✓ Branch 6 taken 122121 times.
✓ Branch 7 taken 122121 times.
✗ Branch 8 not taken.
918416 SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(s));
1036 }
1037
1038
2/2
✓ Branch 0 taken 761625 times.
✓ Branch 1 taken 491731 times.
1253356 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
1039 761625 continue;
1040
1041
2/2
✓ Branch 0 taken 1966924 times.
✓ Branch 1 taken 491731 times.
2458655 for (i = 0; i < 4; i++)
1042
7/8
✓ Branch 0 taken 1623756 times.
✓ Branch 1 taken 343168 times.
✓ Branch 2 taken 865536 times.
✓ Branch 3 taken 758220 times.
✓ Branch 5 taken 758220 times.
✓ Branch 6 taken 343168 times.
✓ Branch 7 taken 343168 times.
✗ Branch 8 not taken.
1966924 SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(s));
1043
1044
2/2
✓ Branch 0 taken 116053 times.
✓ Branch 1 taken 375678 times.
491731 if (sao->type_idx[c_idx] == SAO_BAND) {
1045
2/2
✓ Branch 0 taken 464212 times.
✓ Branch 1 taken 116053 times.
580265 for (i = 0; i < 4; i++) {
1046
2/2
✓ Branch 0 taken 350469 times.
✓ Branch 1 taken 113743 times.
464212 if (sao->offset_abs[c_idx][i]) {
1047
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],
1048 ff_hevc_sao_offset_sign_decode(s));
1049 } else {
1050 113743 sao->offset_sign[c_idx][i] = 0;
1051 }
1052 }
1053
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));
1054
2/2
✓ Branch 0 taken 300964 times.
✓ Branch 1 taken 74714 times.
375678 } else if (c_idx != 2) {
1055
7/8
✓ Branch 0 taken 239847 times.
✓ Branch 1 taken 61117 times.
✓ Branch 2 taken 108049 times.
✓ Branch 3 taken 131798 times.
✓ Branch 5 taken 131798 times.
✓ Branch 6 taken 61117 times.
✓ Branch 7 taken 61117 times.
✗ Branch 8 not taken.
300964 SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(s));
1056 }
1057
1058 // Inferred parameters
1059 491731 sao->offset_val[c_idx][0] = 0;
1060
2/2
✓ Branch 0 taken 1966924 times.
✓ Branch 1 taken 491731 times.
2458655 for (i = 0; i < 4; i++) {
1061 1966924 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
1062
2/2
✓ Branch 0 taken 1502712 times.
✓ Branch 1 taken 464212 times.
1966924 if (sao->type_idx[c_idx] == SAO_EDGE) {
1063
2/2
✓ Branch 0 taken 751356 times.
✓ Branch 1 taken 751356 times.
1502712 if (i > 1)
1064 751356 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1065
2/2
✓ Branch 0 taken 154423 times.
✓ Branch 1 taken 309789 times.
464212 } else if (sao->offset_sign[c_idx][i]) {
1066 154423 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
1067 }
1068 1966924 sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale;
1069 }
1070 }
1071 1399646 }
1072
1073 #undef SET_SAO
1074 #undef CTB
1075
1076 384850 static int hls_cross_component_pred(HEVCContext *s, int idx) {
1077 384850 HEVCLocalContext *lc = s->HEVClc;
1078 384850 int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(s, idx);
1079
1080
2/2
✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
384850 if (log2_res_scale_abs_plus1 != 0) {
1081 235843 int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(s, idx);
1082 235843 lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) *
1083 235843 (1 - 2 * res_scale_sign_flag);
1084 } else {
1085 149007 lc->tu.res_scale_val = 0;
1086 }
1087
1088
1089 384850 return 0;
1090 }
1091
1092 15183513 static int hls_transform_unit(HEVCContext *s, int x0, int y0,
1093 int xBase, int yBase, int cb_xBase, int cb_yBase,
1094 int log2_cb_size, int log2_trafo_size,
1095 int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
1096 {
1097 15183513 HEVCLocalContext *lc = s->HEVClc;
1098 15183513 const int log2_trafo_size_c = log2_trafo_size - s->ps.sps->hshift[1];
1099 int i;
1100
1101
2/2
✓ Branch 0 taken 9587951 times.
✓ Branch 1 taken 5595562 times.
15183513 if (lc->cu.pred_mode == MODE_INTRA) {
1102 9587951 int trafo_size = 1 << log2_trafo_size;
1103 9587951 ff_hevc_set_neighbour_available(s, x0, y0, trafo_size, trafo_size);
1104
1105 9587951 s->hpc.intra_pred[log2_trafo_size - 2](s, x0, y0, 0);
1106 }
1107
1108
6/6
✓ Branch 0 taken 5547330 times.
✓ Branch 1 taken 9636183 times.
✓ Branch 2 taken 4923313 times.
✓ Branch 3 taken 624017 times.
✓ Branch 4 taken 4506894 times.
✓ Branch 5 taken 416419 times.
15183513 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1109
6/6
✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4351127 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
15245327 (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1110 10738434 int scan_idx = SCAN_DIAG;
1111 10738434 int scan_idx_c = SCAN_DIAG;
1112
4/4
✓ Branch 0 taken 7179166 times.
✓ Branch 1 taken 3559268 times.
✓ Branch 2 taken 5743001 times.
✓ Branch 3 taken 1436165 times.
16481435 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1113
2/2
✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 5511291 times.
5743001 (s->ps.sps->chroma_format_idc == 2 &&
1114
4/4
✓ Branch 0 taken 197852 times.
✓ Branch 1 taken 33858 times.
✓ Branch 2 taken 102075 times.
✓ Branch 3 taken 95777 times.
231710 (cbf_cb[1] || cbf_cr[1]));
1115
1116
4/4
✓ Branch 0 taken 2099038 times.
✓ Branch 1 taken 8639396 times.
✓ Branch 2 taken 587289 times.
✓ Branch 3 taken 1511749 times.
10738434 if (s->ps.pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
1117 587289 lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(s);
1118
2/2
✓ Branch 0 taken 368174 times.
✓ Branch 1 taken 219115 times.
587289 if (lc->tu.cu_qp_delta != 0)
1119
2/2
✓ Branch 1 taken 203431 times.
✓ Branch 2 taken 164743 times.
368174 if (ff_hevc_cu_qp_delta_sign_flag(s) == 1)
1120 203431 lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1121 587289 lc->tu.is_cu_qp_delta_coded = 1;
1122
1123
2/2
✓ Branch 0 taken 587288 times.
✓ Branch 1 taken 1 times.
587289 if (lc->tu.cu_qp_delta < -(26 + s->ps.sps->qp_bd_offset / 2) ||
1124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 587288 times.
587288 lc->tu.cu_qp_delta > (25 + s->ps.sps->qp_bd_offset / 2)) {
1125 1 av_log(s->avctx, AV_LOG_ERROR,
1126 "The cu_qp_delta %d is outside the valid range "
1127 "[%d, %d].\n",
1128 lc->tu.cu_qp_delta,
1129 1 -(26 + s->ps.sps->qp_bd_offset / 2),
1130 1 (25 + s->ps.sps->qp_bd_offset / 2));
1131 1 return AVERROR_INVALIDDATA;
1132 }
1133
1134 587288 ff_hevc_set_qPy(s, cb_xBase, cb_yBase, log2_cb_size);
1135 }
1136
1137
4/4
✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 9846482 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
10738433 if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1138
3/4
✓ Branch 0 taken 841055 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 266275 times.
✓ Branch 3 taken 574780 times.
841055 !lc->cu.cu_transquant_bypass_flag && !lc->tu.is_cu_chroma_qp_offset_coded) {
1139 266275 int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(s);
1140
2/2
✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
266275 if (cu_chroma_qp_offset_flag) {
1141 48966 int cu_chroma_qp_offset_idx = 0;
1142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
48966 if (s->ps.pps->chroma_qp_offset_list_len_minus1 > 0) {
1143 cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(s);
1144 av_log(s->avctx, AV_LOG_ERROR,
1145 "cu_chroma_qp_offset_idx not yet tested.\n");
1146 }
1147 48966 lc->tu.cu_qp_offset_cb = s->ps.pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
1148 48966 lc->tu.cu_qp_offset_cr = s->ps.pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
1149 } else {
1150 217309 lc->tu.cu_qp_offset_cb = 0;
1151 217309 lc->tu.cu_qp_offset_cr = 0;
1152 }
1153 266275 lc->tu.is_cu_chroma_qp_offset_coded = 1;
1154 }
1155
1156
4/4
✓ Branch 0 taken 7069217 times.
✓ Branch 1 taken 3669216 times.
✓ Branch 2 taken 6206232 times.
✓ Branch 3 taken 862985 times.
10738433 if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1157
2/2
✓ Branch 0 taken 4132694 times.
✓ Branch 1 taken 2073538 times.
6206232 if (lc->tu.intra_pred_mode >= 6 &&
1158
2/2
✓ Branch 0 taken 1495612 times.
✓ Branch 1 taken 2637082 times.
4132694 lc->tu.intra_pred_mode <= 14) {
1159 1495612 scan_idx = SCAN_VERT;
1160
2/2
✓ Branch 0 taken 2034069 times.
✓ Branch 1 taken 2676551 times.
4710620 } else if (lc->tu.intra_pred_mode >= 22 &&
1161
2/2
✓ Branch 0 taken 1708967 times.
✓ Branch 1 taken 325102 times.
2034069 lc->tu.intra_pred_mode <= 30) {
1162 1708967 scan_idx = SCAN_HORIZ;
1163 }
1164
1165
2/2
✓ Branch 0 taken 3704991 times.
✓ Branch 1 taken 2501241 times.
6206232 if (lc->tu.intra_pred_mode_c >= 6 &&
1166
2/2
✓ Branch 0 taken 1406816 times.
✓ Branch 1 taken 2298175 times.
3704991 lc->tu.intra_pred_mode_c <= 14) {
1167 1406816 scan_idx_c = SCAN_VERT;
1168
2/2
✓ Branch 0 taken 1931373 times.
✓ Branch 1 taken 2868043 times.
4799416 } else if (lc->tu.intra_pred_mode_c >= 22 &&
1169
2/2
✓ Branch 0 taken 1616251 times.
✓ Branch 1 taken 315122 times.
1931373 lc->tu.intra_pred_mode_c <= 30) {
1170 1616251 scan_idx_c = SCAN_HORIZ;
1171 }
1172 }
1173
1174 10738433 lc->tu.cross_pf = 0;
1175
1176
2/2
✓ Branch 0 taken 9636182 times.
✓ Branch 1 taken 1102251 times.
10738433 if (cbf_luma)
1177 9636182 ff_hevc_hls_residual_coding(s, x0, y0, log2_trafo_size, scan_idx, 0);
1178
6/6
✓ Branch 0 taken 10738241 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6061005 times.
✓ Branch 3 taken 4677236 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 5851442 times.
15625232 if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) {
1179 4886799 int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]);
1180 4886799 int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
1181
4/4
✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 4549958 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
5104615 lc->tu.cross_pf = (s->ps.pps->cross_component_prediction_enabled_flag && cbf_luma &&
1182
2/2
✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
217816 (lc->cu.pred_mode == MODE_INTER ||
1183
2/2
✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
168873 (lc->tu.chroma_mode_c == 4)));
1184
1185
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4694374 times.
4886799 if (lc->tu.cross_pf) {
1186 192425 hls_cross_component_pred(s, 0);
1187 }
1188
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8867194 times.
✓ Branch 2 taken 5340001 times.
✓ Branch 3 taken 4886799 times.
10226800 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1189
2/2
✓ Branch 0 taken 2960072 times.
✓ Branch 1 taken 2379929 times.
5340001 if (lc->cu.pred_mode == MODE_INTRA) {
1190 2960072 ff_hevc_set_neighbour_available(s, x0, y0 + (i << log2_trafo_size_c), trafo_size_h, trafo_size_v);
1191 2960072 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (i << log2_trafo_size_c), 1);
1192 }
1193
2/2
✓ Branch 0 taken 1488304 times.
✓ Branch 1 taken 3851697 times.
5340001 if (cbf_cb[i])
1194 1488304 ff_hevc_hls_residual_coding(s, x0, y0 + (i << log2_trafo_size_c),
1195 log2_trafo_size_c, scan_idx_c, 1);
1196 else
1197
2/2
✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 3812039 times.
3851697 if (lc->tu.cross_pf) {
1198 39658 ptrdiff_t stride = s->frame->linesize[1];
1199 39658 int hshift = s->ps.sps->hshift[1];
1200 39658 int vshift = s->ps.sps->vshift[1];
1201 39658 int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1202 39658 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1203 39658 int size = 1 << log2_trafo_size_c;
1204
1205 39658 uint8_t *dst = &s->frame->data[1][(y0 >> vshift) * stride +
1206 39658 ((x0 >> hshift) << s->ps.sps->pixel_shift)];
1207
2/2
✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
1871162 for (i = 0; i < (size * size); i++) {
1208 1831504 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1209 }
1210 39658 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1211 }
1212 }
1213
1214
2/2
✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4694374 times.
4886799 if (lc->tu.cross_pf) {
1215 192425 hls_cross_component_pred(s, 1);
1216 }
1217
4/4
✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8867194 times.
✓ Branch 2 taken 5340001 times.
✓ Branch 3 taken 4886799 times.
10226800 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1218
2/2
✓ Branch 0 taken 2960072 times.
✓ Branch 1 taken 2379929 times.
5340001 if (lc->cu.pred_mode == MODE_INTRA) {
1219 2960072 ff_hevc_set_neighbour_available(s, x0, y0 + (i << log2_trafo_size_c), trafo_size_h, trafo_size_v);
1220 2960072 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (i << log2_trafo_size_c), 2);
1221 }
1222
2/2
✓ Branch 0 taken 1603333 times.
✓ Branch 1 taken 3736668 times.
5340001 if (cbf_cr[i])
1223 1603333 ff_hevc_hls_residual_coding(s, x0, y0 + (i << log2_trafo_size_c),
1224 log2_trafo_size_c, scan_idx_c, 2);
1225 else
1226
2/2
✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 3660744 times.
3736668 if (lc->tu.cross_pf) {
1227 75924 ptrdiff_t stride = s->frame->linesize[2];
1228 75924 int hshift = s->ps.sps->hshift[2];
1229 75924 int vshift = s->ps.sps->vshift[2];
1230 75924 int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1231 75924 int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
1232 75924 int size = 1 << log2_trafo_size_c;
1233
1234 75924 uint8_t *dst = &s->frame->data[2][(y0 >> vshift) * stride +
1235 75924 ((x0 >> hshift) << s->ps.sps->pixel_shift)];
1236
2/2
✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
3691476 for (i = 0; i < (size * size); i++) {
1237 3615552 coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1238 }
1239 75924 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
1240 }
1241 }
1242
4/4
✓ Branch 0 taken 5851442 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1503243 times.
✓ Branch 3 taken 4348199 times.
5851634 } else if (s->ps.sps->chroma_format_idc && blk_idx == 3) {
1243 1503243 int trafo_size_h = 1 << (log2_trafo_size + 1);
1244 1503243 int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]);
1245
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2672748 times.
✓ Branch 2 taken 1670112 times.
✓ Branch 3 taken 1503243 times.
3173355 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1246
2/2
✓ Branch 0 taken 1189850 times.
✓ Branch 1 taken 480262 times.
1670112 if (lc->cu.pred_mode == MODE_INTRA) {
1247 1189850 ff_hevc_set_neighbour_available(s, xBase, yBase + (i << log2_trafo_size),
1248 trafo_size_h, trafo_size_v);
1249 1189850 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (i << log2_trafo_size), 1);
1250 }
1251
2/2
✓ Branch 0 taken 632335 times.
✓ Branch 1 taken 1037777 times.
1670112 if (cbf_cb[i])
1252 632335 ff_hevc_hls_residual_coding(s, xBase, yBase + (i << log2_trafo_size),
1253 log2_trafo_size, scan_idx_c, 1);
1254 }
1255
4/4
✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2672748 times.
✓ Branch 2 taken 1670112 times.
✓ Branch 3 taken 1503243 times.
3173355 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
1256
2/2
✓ Branch 0 taken 1189850 times.
✓ Branch 1 taken 480262 times.
1670112 if (lc->cu.pred_mode == MODE_INTRA) {
1257 1189850 ff_hevc_set_neighbour_available(s, xBase, yBase + (i << log2_trafo_size),
1258 trafo_size_h, trafo_size_v);
1259 1189850 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (i << log2_trafo_size), 2);
1260 }
1261
2/2
✓ Branch 0 taken 713268 times.
✓ Branch 1 taken 956844 times.
1670112 if (cbf_cr[i])
1262 713268 ff_hevc_hls_residual_coding(s, xBase, yBase + (i << log2_trafo_size),
1263 log2_trafo_size, scan_idx_c, 2);
1264 }
1265 }
1266
3/4
✓ Branch 0 taken 4445079 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2518733 times.
✓ Branch 3 taken 1926346 times.
4445079 } else if (s->ps.sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
1267
4/4
✓ Branch 0 taken 1581305 times.
✓ Branch 1 taken 937428 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1520717 times.
3516749 if (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3) {
1268 998016 int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]);
1269 998016 int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
1270 998016 ff_hevc_set_neighbour_available(s, x0, y0, trafo_size_h, trafo_size_v);
1271 998016 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0, 1);
1272 998016 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0, 2);
1273
2/2
✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 985549 times.
998016 if (s->ps.sps->chroma_format_idc == 2) {
1274 12467 ff_hevc_set_neighbour_available(s, x0, y0 + (1 << log2_trafo_size_c),
1275 trafo_size_h, trafo_size_v);
1276 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (1 << log2_trafo_size_c), 1);
1277 12467 s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (1 << log2_trafo_size_c), 2);
1278 }
1279
2/2
✓ Branch 0 taken 345163 times.
✓ Branch 1 taken 1175554 times.
1520717 } else if (blk_idx == 3) {
1280 345163 int trafo_size_h = 1 << (log2_trafo_size + 1);
1281 345163 int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]);
1282 345163 ff_hevc_set_neighbour_available(s, xBase, yBase,
1283 trafo_size_h, trafo_size_v);
1284 345163 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase, 1);
1285 345163 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase, 2);
1286
2/2
✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 340967 times.
345163 if (s->ps.sps->chroma_format_idc == 2) {
1287 4196 ff_hevc_set_neighbour_available(s, xBase, yBase + (1 << (log2_trafo_size)),
1288 trafo_size_h, trafo_size_v);
1289 4196 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (1 << (log2_trafo_size)), 1);
1290 4196 s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (1 << (log2_trafo_size)), 2);
1291 }
1292 }
1293 }
1294
1295 15183512 return 0;
1296 }
1297
1298 356478 static void set_deblocking_bypass(HEVCContext *s, int x0, int y0, int log2_cb_size)
1299 {
1300 356478 int cb_size = 1 << log2_cb_size;
1301 356478 int log2_min_pu_size = s->ps.sps->log2_min_pu_size;
1302
1303 356478 int min_pu_width = s->ps.sps->min_pu_width;
1304 356478 int x_end = FFMIN(x0 + cb_size, s->ps.sps->width);
1305 356478 int y_end = FFMIN(y0 + cb_size, s->ps.sps->height);
1306 int i, j;
1307
1308
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++)
1309
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++)
1310 949056 s->is_pcm[i + j * min_pu_width] = 2;
1311 356478 }
1312
1313 18342315 static int hls_transform_tree(HEVCContext *s, int x0, int y0,
1314 int xBase, int yBase, int cb_xBase, int cb_yBase,
1315 int log2_cb_size, int log2_trafo_size,
1316 int trafo_depth, int blk_idx,
1317 const int *base_cbf_cb, const int *base_cbf_cr)
1318 {
1319 18342315 HEVCLocalContext *lc = s->HEVClc;
1320 uint8_t split_transform_flag;
1321 int cbf_cb[2];
1322 int cbf_cr[2];
1323 int ret;
1324
1325 18342315 cbf_cb[0] = base_cbf_cb[0];
1326 18342315 cbf_cb[1] = base_cbf_cb[1];
1327 18342315 cbf_cr[0] = base_cbf_cr[0];
1328 18342315 cbf_cr[1] = base_cbf_cr[1];
1329
1330
2/2
✓ Branch 0 taken 6293841 times.
✓ Branch 1 taken 12048474 times.
18342315 if (lc->cu.intra_split_flag) {
1331
2/2
✓ Branch 0 taken 4733012 times.
✓ Branch 1 taken 1560829 times.
6293841 if (trafo_depth == 1) {
1332 4733012 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1333
2/2
✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4597608 times.
4733012 if (s->ps.sps->chroma_format_idc == 3) {
1334 135404 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx];
1335 135404 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx];
1336 } else {
1337 4597608 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1338 4597608 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1339 }
1340 }
1341 } else {
1342 12048474 lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0];
1343 12048474 lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0];
1344 12048474 lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
1345 }
1346
1347
2/2
✓ Branch 0 taken 18234437 times.
✓ Branch 1 taken 107878 times.
18342315 if (log2_trafo_size <= s->ps.sps->log2_max_trafo_size &&
1348
2/2
✓ Branch 0 taken 9535033 times.
✓ Branch 1 taken 8699404 times.
18234437 log2_trafo_size > s->ps.sps->log2_min_tb_size &&
1349
2/2
✓ Branch 0 taken 7997779 times.
✓ Branch 1 taken 1537254 times.
9535033 trafo_depth < lc->cu.max_trafo_depth &&
1350
4/4
✓ Branch 0 taken 1666478 times.
✓ Branch 1 taken 6331301 times.
✓ Branch 2 taken 490612 times.
✓ Branch 3 taken 1175866 times.
7997779 !(lc->cu.intra_split_flag && trafo_depth == 0)) {
1351 6821913 split_transform_flag = ff_hevc_split_transform_flag_decode(s, log2_trafo_size);
1352 } else {
1353 24627020 int inter_split = s->ps.sps->max_transform_hierarchy_depth_inter == 0 &&
1354
2/2
✓ Branch 0 taken 834875 times.
✓ Branch 1 taken 751341 times.
1586216 lc->cu.pred_mode == MODE_INTER &&
1355
6/6
✓ Branch 0 taken 1586216 times.
✓ Branch 1 taken 9934186 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 159326 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
13106618 lc->cu.part_mode != PART_2Nx2N &&
1356 trafo_depth == 0;
1357
1358 11520402 split_transform_flag = log2_trafo_size > s->ps.sps->log2_max_trafo_size ||
1359
8/8
✓ Branch 0 taken 11412524 times.
✓ Branch 1 taken 107878 times.
✓ Branch 2 taken 5795182 times.
✓ Branch 3 taken 5617342 times.
✓ Branch 4 taken 4619316 times.
✓ Branch 5 taken 1175866 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10118020 times.
11520402 (lc->cu.intra_split_flag && trafo_depth == 0) ||
1360 inter_split;
1361 }
1362
1363
6/6
✓ Branch 0 taken 18342123 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8571324 times.
✓ Branch 3 taken 9770799 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8256908 times.
18342315 if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) {
1364
4/4
✓ Branch 0 taken 4378300 times.
✓ Branch 1 taken 5706915 times.
✓ Branch 2 taken 1219808 times.
✓ Branch 3 taken 3158492 times.
10085215 if (trafo_depth == 0 || cbf_cb[0]) {
1365 6926723 cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1366
6/6
✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 6328457 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
6926723 if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1367 526996 cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1368 }
1369 }
1370
1371
4/4
✓ Branch 0 taken 4378300 times.
✓ Branch 1 taken 5706915 times.
✓ Branch 2 taken 1166360 times.
✓ Branch 3 taken 3211940 times.
10085215 if (trafo_depth == 0 || cbf_cr[0]) {
1372 6873275 cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1373
6/6
✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6127969 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
6873275 if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1374 661961 cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1375 }
1376 }
1377 }
1378
1379
2/2
✓ Branch 0 taken 3158802 times.
✓ Branch 1 taken 15183513 times.
18342315 if (split_transform_flag) {
1380 3158802 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1381 3158802 const int x1 = x0 + trafo_size_split;
1382 3158802 const int y1 = y0 + trafo_size_split;
1383
1384 #define SUBDIVIDE(x, y, idx) \
1385 do { \
1386 ret = hls_transform_tree(s, x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1387 log2_trafo_size - 1, trafo_depth + 1, idx, \
1388 cbf_cb, cbf_cr); \
1389 if (ret < 0) \
1390 return ret; \
1391 } while (0)
1392
1393
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3158802 times.
3158802 SUBDIVIDE(x0, y0, 0);
1394
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3158802 times.
3158802 SUBDIVIDE(x1, y0, 1);
1395
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3158802 times.
3158802 SUBDIVIDE(x0, y1, 2);
1396
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3158802 times.
3158802 SUBDIVIDE(x1, y1, 3);
1397
1398 #undef SUBDIVIDE
1399 } else {
1400 15183513 int min_tu_size = 1 << s->ps.sps->log2_min_tb_size;
1401 15183513 int log2_min_tu_size = s->ps.sps->log2_min_tb_size;
1402 15183513 int min_tu_width = s->ps.sps->min_tb_width;
1403 15183513 int cbf_luma = 1;
1404
1405
4/4
✓ Branch 0 taken 5595562 times.
✓ Branch 1 taken 9587951 times.
✓ Branch 2 taken 978822 times.
✓ Branch 3 taken 4616740 times.
15183513 if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1406
4/4
✓ Branch 0 taken 800529 times.
✓ Branch 1 taken 178293 times.
✓ Branch 2 taken 685601 times.
✓ Branch 3 taken 114928 times.
978822 cbf_cb[0] || cbf_cr[0] ||
1407
6/6
✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 660925 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
685601 (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1408 14510558 cbf_luma = ff_hevc_cbf_luma_decode(s, trafo_depth);
1409 }
1410
1411 15183513 ret = hls_transform_unit(s, x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1412 log2_cb_size, log2_trafo_size,
1413 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1414
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15183512 times.
15183513 if (ret < 0)
1415 1 return ret;
1416 // TODO: store cbf_luma somewhere else
1417
2/2
✓ Branch 0 taken 9636182 times.
✓ Branch 1 taken 5547330 times.
15183512 if (cbf_luma) {
1418 int i, j;
1419
2/2
✓ Branch 0 taken 19591032 times.
✓ Branch 1 taken 9636182 times.
29227214 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1420
2/2
✓ Branch 0 taken 69676934 times.
✓ Branch 1 taken 19591032 times.
89267966 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1421 69676934 int x_tu = (x0 + j) >> log2_min_tu_size;
1422 69676934 int y_tu = (y0 + i) >> log2_min_tu_size;
1423 69676934 s->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1424 }
1425 }
1426
2/2
✓ Branch 0 taken 14650692 times.
✓ Branch 1 taken 532820 times.
15183512 if (!s->sh.disable_deblocking_filter_flag) {
1427 14650692 ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_trafo_size);
1428
2/2
✓ Branch 0 taken 373941 times.
✓ Branch 1 taken 14276751 times.
14650692 if (s->ps.pps->transquant_bypass_enable_flag &&
1429
2/2
✓ Branch 0 taken 275932 times.
✓ Branch 1 taken 98009 times.
373941 lc->cu.cu_transquant_bypass_flag)
1430 275932 set_deblocking_bypass(s, x0, y0, log2_trafo_size);
1431 }
1432 }
1433 18342314 return 0;
1434 }
1435
1436 12433 static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size)
1437 {
1438 12433 HEVCLocalContext *lc = s->HEVClc;
1439 GetBitContext gb;
1440 12433 int cb_size = 1 << log2_cb_size;
1441 12433 ptrdiff_t stride0 = s->frame->linesize[0];
1442 12433 ptrdiff_t stride1 = s->frame->linesize[1];
1443 12433 ptrdiff_t stride2 = s->frame->linesize[2];
1444 12433 uint8_t *dst0 = &s->frame->data[0][y0 * stride0 + (x0 << s->ps.sps->pixel_shift)];
1445 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)];
1446 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)];
1447
1448 12433 int length = cb_size * cb_size * s->ps.sps->pcm.bit_depth +
1449 12433 (((cb_size >> s->ps.sps->hshift[1]) * (cb_size >> s->ps.sps->vshift[1])) +
1450 12433 ((cb_size >> s->ps.sps->hshift[2]) * (cb_size >> s->ps.sps->vshift[2]))) *
1451 12433 s->ps.sps->pcm.bit_depth_chroma;
1452 12433 const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
1453 int ret;
1454
1455
2/2
✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
12433 if (!s->sh.disable_deblocking_filter_flag)
1456 6937 ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
1457
1458 12433 ret = init_get_bits(&gb, pcm, length);
1459
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
1460 return ret;
1461
1462 12433 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, s->ps.sps->pcm.bit_depth);
1463
1/2
✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
12433 if (s->ps.sps->chroma_format_idc) {
1464 12433 s->hevcdsp.put_pcm(dst1, stride1,
1465 12433 cb_size >> s->ps.sps->hshift[1],
1466 12433 cb_size >> s->ps.sps->vshift[1],
1467 12433 &gb, s->ps.sps->pcm.bit_depth_chroma);
1468 12433 s->hevcdsp.put_pcm(dst2, stride2,
1469 12433 cb_size >> s->ps.sps->hshift[2],
1470 12433 cb_size >> s->ps.sps->vshift[2],
1471 12433 &gb, s->ps.sps->pcm.bit_depth_chroma);
1472 }
1473
1474 12433 return 0;
1475 }
1476
1477 /**
1478 * 8.5.3.2.2.1 Luma sample unidirectional interpolation process
1479 *
1480 * @param s HEVC decoding context
1481 * @param dst target buffer for block data at block position
1482 * @param dststride stride of the dst buffer
1483 * @param ref reference picture buffer at origin (0, 0)
1484 * @param mv motion vector (relative to block position) to get pixel data from
1485 * @param x_off horizontal position of block from origin (0, 0)
1486 * @param y_off vertical position of block from origin (0, 0)
1487 * @param block_w width of block
1488 * @param block_h height of block
1489 * @param luma_weight weighting factor applied to the luma prediction
1490 * @param luma_offset additive offset applied to the luma prediction value
1491 */
1492
1493 4802517 static void luma_mc_uni(HEVCContext *s, uint8_t *dst, ptrdiff_t dststride,
1494 AVFrame *ref, const Mv *mv, int x_off, int y_off,
1495 int block_w, int block_h, int luma_weight, int luma_offset)
1496 {
1497 4802517 HEVCLocalContext *lc = s->HEVClc;
1498 4802517 uint8_t *src = ref->data[0];
1499 4802517 ptrdiff_t srcstride = ref->linesize[0];
1500 4802517 int pic_width = s->ps.sps->width;
1501 4802517 int pic_height = s->ps.sps->height;
1502 4802517 int mx = mv->x & 3;
1503 4802517 int my = mv->y & 3;
1504
4/4
✓ Branch 0 taken 1959913 times.
✓ Branch 1 taken 2842604 times.
✓ Branch 2 taken 1914256 times.
✓ Branch 3 taken 45657 times.
9559377 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
1505
4/4
✓ Branch 0 taken 2842604 times.
✓ Branch 1 taken 1914256 times.
✓ Branch 2 taken 60281 times.
✓ Branch 3 taken 2782323 times.
4756860 (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
1506 4802517 int idx = ff_hevc_pel_weight[block_w];
1507
1508 4802517 x_off += mv->x >> 2;
1509 4802517 y_off += mv->y >> 2;
1510 4802517 src += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift));
1511
1512
4/4
✓ Branch 0 taken 4747221 times.
✓ Branch 1 taken 55296 times.
✓ Branch 2 taken 4643356 times.
✓ Branch 3 taken 103865 times.
4802517 if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
1513
2/2
✓ Branch 0 taken 4580428 times.
✓ Branch 1 taken 62928 times.
4643356 x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1514
2/2
✓ Branch 0 taken 192498 times.
✓ Branch 1 taken 4387930 times.
4580428 y_off >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1515 414587 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1516 414587 int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1517 414587 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1518
1519 414587 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
1520 edge_emu_stride, srcstride,
1521 block_w + QPEL_EXTRA,
1522 block_h + QPEL_EXTRA,
1523 x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE,
1524 pic_width, pic_height);
1525 414587 src = lc->edge_emu_buffer + buf_offset;
1526 414587 srcstride = edge_emu_stride;
1527 }
1528
1529
2/2
✓ Branch 0 taken 4696579 times.
✓ Branch 1 taken 105938 times.
4802517 if (!weight_flag)
1530 4696579 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride,
1531 block_h, mx, my, block_w);
1532 else
1533 105938 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride,
1534 105938 block_h, s->sh.luma_log2_weight_denom,
1535 luma_weight, luma_offset, mx, my, block_w);
1536 4802517 }
1537
1538 /**
1539 * 8.5.3.2.2.1 Luma sample bidirectional interpolation process
1540 *
1541 * @param s HEVC decoding context
1542 * @param dst target buffer for block data at block position
1543 * @param dststride stride of the dst buffer
1544 * @param ref0 reference picture0 buffer at origin (0, 0)
1545 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1546 * @param x_off horizontal position of block from origin (0, 0)
1547 * @param y_off vertical position of block from origin (0, 0)
1548 * @param block_w width of block
1549 * @param block_h height of block
1550 * @param ref1 reference picture1 buffer at origin (0, 0)
1551 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1552 * @param current_mv current motion vector structure
1553 */
1554 3781449 static void luma_mc_bi(HEVCContext *s, uint8_t *dst, ptrdiff_t dststride,
1555 AVFrame *ref0, const Mv *mv0, int x_off, int y_off,
1556 int block_w, int block_h, AVFrame *ref1, const Mv *mv1, struct MvField *current_mv)
1557 {
1558 3781449 HEVCLocalContext *lc = s->HEVClc;
1559 3781449 ptrdiff_t src0stride = ref0->linesize[0];
1560 3781449 ptrdiff_t src1stride = ref1->linesize[0];
1561 3781449 int pic_width = s->ps.sps->width;
1562 3781449 int pic_height = s->ps.sps->height;
1563 3781449 int mx0 = mv0->x & 3;
1564 3781449 int my0 = mv0->y & 3;
1565 3781449 int mx1 = mv1->x & 3;
1566 3781449 int my1 = mv1->y & 3;
1567
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) ||
1568
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);
1569 3781449 int x_off0 = x_off + (mv0->x >> 2);
1570 3781449 int y_off0 = y_off + (mv0->y >> 2);
1571 3781449 int x_off1 = x_off + (mv1->x >> 2);
1572 3781449 int y_off1 = y_off + (mv1->y >> 2);
1573 3781449 int idx = ff_hevc_pel_weight[block_w];
1574
1575 3781449 uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift);
1576 3781449 uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift);
1577
1578
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 ||
1579
2/2
✓ Branch 0 taken 3566623 times.
✓ Branch 1 taken 63053 times.
3629676 x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1580
2/2
✓ Branch 0 taken 200716 times.
✓ Branch 1 taken 3365907 times.
3566623 y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1581 415542 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1582 415542 int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1583 415542 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1584
1585 415542 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset,
1586 edge_emu_stride, src0stride,
1587 block_w + QPEL_EXTRA,
1588 block_h + QPEL_EXTRA,
1589 x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE,
1590 pic_width, pic_height);
1591 415542 src0 = lc->edge_emu_buffer + buf_offset;
1592 415542 src0stride = edge_emu_stride;
1593 }
1594
1595
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 ||
1596
2/2
✓ Branch 0 taken 3559536 times.
✓ Branch 1 taken 65349 times.
3624885 x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
1597
2/2
✓ Branch 0 taken 204563 times.
✓ Branch 1 taken 3354973 times.
3559536 y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
1598 426476 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1599 426476 int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1600 426476 int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
1601
1602 426476 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset,
1603 edge_emu_stride, src1stride,
1604 block_w + QPEL_EXTRA,
1605 block_h + QPEL_EXTRA,
1606 x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE,
1607 pic_width, pic_height);
1608 426476 src1 = lc->edge_emu_buffer2 + buf_offset;
1609 426476 src1stride = edge_emu_stride;
1610 }
1611
1612 3781449 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride,
1613 block_h, mx0, my0, block_w);
1614
2/2
✓ Branch 0 taken 3719142 times.
✓ Branch 1 taken 62307 times.
3781449 if (!weight_flag)
1615 3719142 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1616 block_h, mx1, my1, block_w);
1617 else
1618 62307 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp,
1619 62307 block_h, s->sh.luma_log2_weight_denom,
1620 62307 s->sh.luma_weight_l0[current_mv->ref_idx[0]],
1621 62307 s->sh.luma_weight_l1[current_mv->ref_idx[1]],
1622 62307 s->sh.luma_offset_l0[current_mv->ref_idx[0]],
1623 62307 s->sh.luma_offset_l1[current_mv->ref_idx[1]],
1624 mx1, my1, block_w);
1625
1626 3781449 }
1627
1628 /**
1629 * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process
1630 *
1631 * @param s HEVC decoding context
1632 * @param dst1 target buffer for block data at block position (U plane)
1633 * @param dst2 target buffer for block data at block position (V plane)
1634 * @param dststride stride of the dst1 and dst2 buffers
1635 * @param ref reference picture buffer at origin (0, 0)
1636 * @param mv motion vector (relative to block position) to get pixel data from
1637 * @param x_off horizontal position of block from origin (0, 0)
1638 * @param y_off vertical position of block from origin (0, 0)
1639 * @param block_w width of block
1640 * @param block_h height of block
1641 * @param chroma_weight weighting factor applied to the chroma prediction
1642 * @param chroma_offset additive offset applied to the chroma prediction value
1643 */
1644
1645 9605034 static void chroma_mc_uni(HEVCContext *s, uint8_t *dst0,
1646 ptrdiff_t dststride, uint8_t *src0, ptrdiff_t srcstride, int reflist,
1647 int x_off, int y_off, int block_w, int block_h, struct MvField *current_mv, int chroma_weight, int chroma_offset)
1648 {
1649 9605034 HEVCLocalContext *lc = s->HEVClc;
1650 9605034 int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1];
1651 9605034 int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1];
1652 9605034 const Mv *mv = &current_mv->mv[reflist];
1653
4/4
✓ Branch 0 taken 3919826 times.
✓ Branch 1 taken 5685208 times.
✓ Branch 2 taken 3828512 times.
✓ Branch 3 taken 91314 times.
19118754 int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
1654
4/4
✓ Branch 0 taken 5685208 times.
✓ Branch 1 taken 3828512 times.
✓ Branch 2 taken 120562 times.
✓ Branch 3 taken 5564646 times.
9513720 (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
1655 9605034 int idx = ff_hevc_pel_weight[block_w];
1656 9605034 int hshift = s->ps.sps->hshift[1];
1657 9605034 int vshift = s->ps.sps->vshift[1];
1658 9605034 intptr_t mx = av_mod_uintp2(mv->x, 2 + hshift);
1659 9605034 intptr_t my = av_mod_uintp2(mv->y, 2 + vshift);
1660 9605034 intptr_t _mx = mx << (1 - hshift);
1661 9605034 intptr_t _my = my << (1 - vshift);
1662
1663 9605034 x_off += mv->x >> (2 + hshift);
1664 9605034 y_off += mv->y >> (2 + vshift);
1665 9605034 src0 += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift));
1666
1667
4/4
✓ Branch 0 taken 9504440 times.
✓ Branch 1 taken 100594 times.
✓ Branch 2 taken 9296572 times.
✓ Branch 3 taken 207868 times.
9605034 if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1668
2/2
✓ Branch 0 taken 9170724 times.
✓ Branch 1 taken 125848 times.
9296572 x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1669
2/2
✓ Branch 0 taken 385052 times.
✓ Branch 1 taken 8785672 times.
9170724 y_off >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1670 819362 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1671 819362 int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << s->ps.sps->pixel_shift));
1672 819362 int buf_offset0 = EPEL_EXTRA_BEFORE *
1673 819362 (edge_emu_stride + (1 << s->ps.sps->pixel_shift));
1674 819362 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0,
1675 edge_emu_stride, srcstride,
1676 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1677 x_off - EPEL_EXTRA_BEFORE,
1678 y_off - EPEL_EXTRA_BEFORE,
1679 pic_width, pic_height);
1680
1681 819362 src0 = lc->edge_emu_buffer + buf_offset0;
1682 819362 srcstride = edge_emu_stride;
1683 }
1684
2/2
✓ Branch 0 taken 9393158 times.
✓ Branch 1 taken 211876 times.
9605034 if (!weight_flag)
1685 9393158 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1686 block_h, _mx, _my, block_w);
1687 else
1688 211876 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride,
1689 211876 block_h, s->sh.chroma_log2_weight_denom,
1690 chroma_weight, chroma_offset, _mx, _my, block_w);
1691 9605034 }
1692
1693 /**
1694 * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process
1695 *
1696 * @param s HEVC decoding context
1697 * @param dst target buffer for block data at block position
1698 * @param dststride stride of the dst buffer
1699 * @param ref0 reference picture0 buffer at origin (0, 0)
1700 * @param mv0 motion vector0 (relative to block position) to get pixel data from
1701 * @param x_off horizontal position of block from origin (0, 0)
1702 * @param y_off vertical position of block from origin (0, 0)
1703 * @param block_w width of block
1704 * @param block_h height of block
1705 * @param ref1 reference picture1 buffer at origin (0, 0)
1706 * @param mv1 motion vector1 (relative to block position) to get pixel data from
1707 * @param current_mv current motion vector structure
1708 * @param cidx chroma component(cb, cr)
1709 */
1710 7562898 static void chroma_mc_bi(HEVCContext *s, uint8_t *dst0, ptrdiff_t dststride, AVFrame *ref0, AVFrame *ref1,
1711 int x_off, int y_off, int block_w, int block_h, struct MvField *current_mv, int cidx)
1712 {
1713 7562898 HEVCLocalContext *lc = s->HEVClc;
1714 7562898 uint8_t *src1 = ref0->data[cidx+1];
1715 7562898 uint8_t *src2 = ref1->data[cidx+1];
1716 7562898 ptrdiff_t src1stride = ref0->linesize[cidx+1];
1717 7562898 ptrdiff_t src2stride = ref1->linesize[cidx+1];
1718
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) ||
1719
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);
1720 7562898 int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1];
1721 7562898 int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1];
1722 7562898 Mv *mv0 = &current_mv->mv[0];
1723 7562898 Mv *mv1 = &current_mv->mv[1];
1724 7562898 int hshift = s->ps.sps->hshift[1];
1725 7562898 int vshift = s->ps.sps->vshift[1];
1726
1727 7562898 intptr_t mx0 = av_mod_uintp2(mv0->x, 2 + hshift);
1728 7562898 intptr_t my0 = av_mod_uintp2(mv0->y, 2 + vshift);
1729 7562898 intptr_t mx1 = av_mod_uintp2(mv1->x, 2 + hshift);
1730 7562898 intptr_t my1 = av_mod_uintp2(mv1->y, 2 + vshift);
1731 7562898 intptr_t _mx0 = mx0 << (1 - hshift);
1732 7562898 intptr_t _my0 = my0 << (1 - vshift);
1733 7562898 intptr_t _mx1 = mx1 << (1 - hshift);
1734 7562898 intptr_t _my1 = my1 << (1 - vshift);
1735
1736 7562898 int x_off0 = x_off + (mv0->x >> (2 + hshift));
1737 7562898 int y_off0 = y_off + (mv0->y >> (2 + vshift));
1738 7562898 int x_off1 = x_off + (mv1->x >> (2 + hshift));
1739 7562898 int y_off1 = y_off + (mv1->y >> (2 + vshift));
1740 7562898 int idx = ff_hevc_pel_weight[block_w];
1741 7562898 src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift);
1742 7562898 src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift);
1743
1744
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 ||
1745
2/2
✓ Branch 0 taken 7138414 times.
✓ Branch 1 taken 126102 times.
7264516 x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1746
2/2
✓ Branch 0 taken 400782 times.
✓ Branch 1 taken 6737632 times.
7138414 y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1747 825266 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1748 825266 int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << s->ps.sps->pixel_shift));
1749 825266 int buf_offset1 = EPEL_EXTRA_BEFORE *
1750 825266 (edge_emu_stride + (1 << s->ps.sps->pixel_shift));
1751
1752 825266 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1,
1753 edge_emu_stride, src1stride,
1754 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1755 x_off0 - EPEL_EXTRA_BEFORE,
1756 y_off0 - EPEL_EXTRA_BEFORE,
1757 pic_width, pic_height);
1758
1759 825266 src1 = lc->edge_emu_buffer + buf_offset1;
1760 825266 src1stride = edge_emu_stride;
1761 }
1762
1763
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 ||
1764
2/2
✓ Branch 0 taken 7124282 times.
✓ Branch 1 taken 130692 times.
7254974 x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1765
2/2
✓ Branch 0 taken 408782 times.
✓ Branch 1 taken 6715500 times.
7124282 y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1766 847398 const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
1767 847398 int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << s->ps.sps->pixel_shift));
1768 847398 int buf_offset1 = EPEL_EXTRA_BEFORE *
1769 847398 (edge_emu_stride + (1 << s->ps.sps->pixel_shift));
1770
1771 847398 s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1,
1772 edge_emu_stride, src2stride,
1773 block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1774 x_off1 - EPEL_EXTRA_BEFORE,
1775 y_off1 - EPEL_EXTRA_BEFORE,
1776 pic_width, pic_height);
1777
1778 847398 src2 = lc->edge_emu_buffer2 + buf_offset1;
1779 847398 src2stride = edge_emu_stride;
1780 }
1781
1782 7562898 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride,
1783 block_h, _mx0, _my0, block_w);
1784
2/2
✓ Branch 0 taken 7438284 times.
✓ Branch 1 taken 124614 times.
7562898 if (!weight_flag)
1785 7438284 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->frame->linesize[cidx+1],
1786 7438284 src2, src2stride, lc->tmp,
1787 block_h, _mx1, _my1, block_w);
1788 else
1789 124614 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->frame->linesize[cidx+1],
1790 124614 src2, src2stride, lc->tmp,
1791 block_h,
1792 124614 s->sh.chroma_log2_weight_denom,
1793 124614 s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx],
1794 124614 s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx],
1795 124614 s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx],
1796 124614 s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx],
1797 _mx1, _my1, block_w);
1798 7562898 }
1799
1800 12365415 static void hevc_await_progress(HEVCContext *s, HEVCFrame *ref,
1801 const Mv *mv, int y0, int height)
1802 {
1803
2/2
✓ Branch 0 taken 107575 times.
✓ Branch 1 taken 12257840 times.
12365415 if (s->threads_type == FF_THREAD_FRAME ) {
1804 107575 int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9);
1805
1806 107575 ff_thread_await_progress(&ref->tf, y, 0);
1807 }
1808 12365415 }
1809
1810 2379349 static void hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW,
1811 int nPbH, int log2_cb_size, int part_idx,
1812 int merge_idx, MvField *mv)
1813 {
1814 2379349 HEVCLocalContext *lc = s->HEVClc;
1815 2379349 enum InterPredIdc inter_pred_idc = PRED_L0;
1816 int mvp_flag;
1817
1818 2379349 ff_hevc_set_neighbour_available(s, x0, y0, nPbW, nPbH);
1819 2379349 mv->pred_flag = 0;
1820
2/2
✓ Branch 0 taken 1811353 times.
✓ Branch 1 taken 567996 times.
2379349 if (s->sh.slice_type == HEVC_SLICE_B)
1821 1811353 inter_pred_idc = ff_hevc_inter_pred_idc_decode(s, nPbW, nPbH);
1822
1823
2/2
✓ Branch 0 taken 1995330 times.
✓ Branch 1 taken 384019 times.
2379349 if (inter_pred_idc != PRED_L1) {
1824
1/2
✓ Branch 0 taken 1995330 times.
✗ Branch 1 not taken.
1995330 if (s->sh.nb_refs[L0])
1825 1995330 mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L0]);
1826
1827 1995330 mv->pred_flag = PF_L0;
1828 1995330 ff_hevc_hls_mvd_coding(s, x0, y0, 0);
1829 1995330 mvp_flag = ff_hevc_mvp_lx_flag_decode(s);
1830 1995330 ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1831 part_idx, merge_idx, mv, mvp_flag, 0);
1832 1995330 mv->mv[0].x += lc->pu.mvd.x;
1833 1995330 mv->mv[0].y += lc->pu.mvd.y;
1834 }
1835
1836
2/2
✓ Branch 0 taken 788021 times.
✓ Branch 1 taken 1591328 times.
2379349 if (inter_pred_idc != PRED_L0) {
1837
1/2
✓ Branch 0 taken 788021 times.
✗ Branch 1 not taken.
788021 if (s->sh.nb_refs[L1])
1838 788021 mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L1]);
1839
1840
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) {
1841 157794 AV_ZERO32(&lc->pu.mvd);
1842 } else {
1843 630227 ff_hevc_hls_mvd_coding(s, x0, y0, 1);
1844 }
1845
1846 788021 mv->pred_flag += PF_L1;
1847 788021 mvp_flag = ff_hevc_mvp_lx_flag_decode(s);
1848 788021 ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1849 part_idx, merge_idx, mv, mvp_flag, 1);
1850 788021 mv->mv[1].x += lc->pu.mvd.x;
1851 788021 mv->mv[1].y += lc->pu.mvd.y;
1852 }
1853 2379349 }
1854
1855 8583966 static void hls_prediction_unit(HEVCContext *s, int x0, int y0,
1856 int nPbW, int nPbH,
1857 int log2_cb_size, int partIdx, int idx)
1858 {
1859 #define POS(c_idx, x, y) \
1860 &s->frame->data[c_idx][((y) >> s->ps.sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \
1861 (((x) >> s->ps.sps->hshift[c_idx]) << s->ps.sps->pixel_shift)]
1862 8583966 HEVCLocalContext *lc = s->HEVClc;
1863 8583966 int merge_idx = 0;
1864 8583966 struct MvField current_mv = {{{ 0 }}};
1865
1866 8583966 int min_pu_width = s->ps.sps->min_pu_width;
1867
1868 8583966 MvField *tab_mvf = s->ref->tab_mvf;
1869 8583966 RefPicList *refPicList = s->ref->refPicList;
1870 8583966 HEVCFrame *ref0 = NULL, *ref1 = NULL;
1871 8583966 uint8_t *dst0 = POS(0, x0, y0);
1872 8583966 uint8_t *dst1 = POS(1, x0, y0);
1873 8583966 uint8_t *dst2 = POS(2, x0, y0);
1874 8583966 int log2_min_cb_size = s->ps.sps->log2_min_cb_size;
1875 8583966 int min_cb_width = s->ps.sps->min_cb_width;
1876 8583966 int x_cb = x0 >> log2_min_cb_size;
1877 8583966 int y_cb = y0 >> log2_min_cb_size;
1878 int x_pu, y_pu;
1879 int i, j;
1880
1881 8583966 int skip_flag = SAMPLE_CTB(s->skip_flag, x_cb, y_cb);
1882
1883
2/2
✓ Branch 0 taken 4710467 times.
✓ Branch 1 taken 3873499 times.
8583966 if (!skip_flag)
1884 4710467 lc->pu.merge_flag = ff_hevc_merge_flag_decode(s);
1885
1886
4/4
✓ Branch 0 taken 4710467 times.
✓ Branch 1 taken 3873499 times.
✓ Branch 2 taken 2331118 times.
✓ Branch 3 taken 2379349 times.
8583966 if (skip_flag || lc->pu.merge_flag) {
1887
2/2
✓ Branch 0 taken 6127764 times.
✓ Branch 1 taken 76853 times.
6204617 if (s->sh.max_num_merge_cand > 1)
1888 6127764 merge_idx = ff_hevc_merge_idx_decode(s);
1889 else
1890 76853 merge_idx = 0;
1891
1892 6204617 ff_hevc_luma_mv_merge_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1893 partIdx, merge_idx, &current_mv);
1894 } else {
1895 2379349 hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1896 partIdx, merge_idx, &current_mv);
1897 }
1898
1899 8583966 x_pu = x0 >> s->ps.sps->log2_min_pu_size;
1900 8583966 y_pu = y0 >> s->ps.sps->log2_min_pu_size;
1901
1902
2/2
✓ Branch 0 taken 32366746 times.
✓ Branch 1 taken 8583966 times.
40950712 for (j = 0; j < nPbH >> s->ps.sps->log2_min_pu_size; j++)
1903
2/2
✓ Branch 0 taken 205198716 times.
✓ Branch 1 taken 32366746 times.
237565462 for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++)
1904 205198716 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1905
1906
2/2
✓ Branch 0 taken 7823389 times.
✓ Branch 1 taken 760577 times.
8583966 if (current_mv.pred_flag & PF_L0) {
1907 7823389 ref0 = refPicList[0].ref[current_mv.ref_idx[0]];
1908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7823389 times.
7823389 if (!ref0)
1909 return;
1910 7823389 hevc_await_progress(s, ref0, &current_mv.mv[0], y0, nPbH);
1911 }
1912
2/2
✓ Branch 0 taken 4542026 times.
✓ Branch 1 taken 4041940 times.
8583966 if (current_mv.pred_flag & PF_L1) {
1913 4542026 ref1 = refPicList[1].ref[current_mv.ref_idx[1]];
1914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4542026 times.
4542026 if (!ref1)
1915 return;
1916 4542026 hevc_await_progress(s, ref1, &current_mv.mv[1], y0, nPbH);
1917 }
1918
1919
2/2
✓ Branch 0 taken 4041940 times.
✓ Branch 1 taken 4542026 times.
8583966 if (current_mv.pred_flag == PF_L0) {
1920 4041940 int x0_c = x0 >> s->ps.sps->hshift[1];
1921 4041940 int y0_c = y0 >> s->ps.sps->vshift[1];
1922 4041940 int nPbW_c = nPbW >> s->ps.sps->hshift[1];
1923 4041940 int nPbH_c = nPbH >> s->ps.sps->vshift[1];
1924
1925 4041940 luma_mc_uni(s, dst0, s->frame->linesize[0], ref0->frame,
1926 &current_mv.mv[0], x0, y0, nPbW, nPbH,
1927 4041940 s->sh.luma_weight_l0[current_mv.ref_idx[0]],
1928 4041940 s->sh.luma_offset_l0[current_mv.ref_idx[0]]);
1929
1930
1/2
✓ Branch 0 taken 4041940 times.
✗ Branch 1 not taken.
4041940 if (s->ps.sps->chroma_format_idc) {
1931 4041940 chroma_mc_uni(s, dst1, s->frame->linesize[1], ref0->frame->data[1], ref0->frame->linesize[1],
1932 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
1933 4041940 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]);
1934 4041940 chroma_mc_uni(s, dst2, s->frame->linesize[2], ref0->frame->data[2], ref0->frame->linesize[2],
1935 0, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
1936 4041940 s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]);
1937 }
1938
2/2
✓ Branch 0 taken 760577 times.
✓ Branch 1 taken 3781449 times.
4542026 } else if (current_mv.pred_flag == PF_L1) {
1939 760577 int x0_c = x0 >> s->ps.sps->hshift[1];
1940 760577 int y0_c = y0 >> s->ps.sps->vshift[1];
1941 760577 int nPbW_c = nPbW >> s->ps.sps->hshift[1];
1942 760577 int nPbH_c = nPbH >> s->ps.sps->vshift[1];
1943
1944 760577 luma_mc_uni(s, dst0, s->frame->linesize[0], ref1->frame,
1945 &current_mv.mv[1], x0, y0, nPbW, nPbH,
1946 760577 s->sh.luma_weight_l1[current_mv.ref_idx[1]],
1947 760577 s->sh.luma_offset_l1[current_mv.ref_idx[1]]);
1948
1949
1/2
✓ Branch 0 taken 760577 times.
✗ Branch 1 not taken.
760577 if (s->ps.sps->chroma_format_idc) {
1950 760577 chroma_mc_uni(s, dst1, s->frame->linesize[1], ref1->frame->data[1], ref1->frame->linesize[1],
1951 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
1952 760577 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]);
1953
1954 760577 chroma_mc_uni(s, dst2, s->frame->linesize[2], ref1->frame->data[2], ref1->frame->linesize[2],
1955 1, x0_c, y0_c, nPbW_c, nPbH_c, &current_mv,
1956 760577 s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]);
1957 }
1958
1/2
✓ Branch 0 taken 3781449 times.
✗ Branch 1 not taken.
3781449 } else if (current_mv.pred_flag == PF_BI) {
1959 3781449 int x0_c = x0 >> s->ps.sps->hshift[1];
1960 3781449 int y0_c = y0 >> s->ps.sps->vshift[1];
1961 3781449 int nPbW_c = nPbW >> s->ps.sps->hshift[1];
1962 3781449 int nPbH_c = nPbH >> s->ps.sps->vshift[1];
1963
1964 3781449 luma_mc_bi(s, dst0, s->frame->linesize[0], ref0->frame,
1965 &current_mv.mv[0], x0, y0, nPbW, nPbH,
1966 ref1->frame, &current_mv.mv[1], &current_mv);
1967
1968
1/2
✓ Branch 0 taken 3781449 times.
✗ Branch 1 not taken.
3781449 if (s->ps.sps->chroma_format_idc) {
1969 3781449 chroma_mc_bi(s, dst1, s->frame->linesize[1], ref0->frame, ref1->frame,
1970 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 0);
1971
1972 3781449 chroma_mc_bi(s, dst2, s->frame->linesize[2], ref0->frame, ref1->frame,
1973 x0_c, y0_c, nPbW_c, nPbH_c, &current_mv, 1);
1974 }
1975 }
1976 }
1977
1978 /**
1979 * 8.4.1
1980 */
1981 7452578 static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size,
1982 int prev_intra_luma_pred_flag)
1983 {
1984 7452578 HEVCLocalContext *lc = s->HEVClc;
1985 7452578 int x_pu = x0 >> s->ps.sps->log2_min_pu_size;
1986 7452578 int y_pu = y0 >> s->ps.sps->log2_min_pu_size;
1987 7452578 int min_pu_width = s->ps.sps->min_pu_width;
1988 7452578 int size_in_pus = pu_size >> s->ps.sps->log2_min_pu_size;
1989 7452578 int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size);
1990 7452578 int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size);
1991
1992
2/2
✓ Branch 0 taken 1046604 times.
✓ Branch 1 taken 119897 times.
1166501 int cand_up = (lc->ctb_up_flag || y0b) ?
1993
2/2
✓ Branch 0 taken 1166501 times.
✓ Branch 1 taken 6286077 times.
8619079 s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
1994
2/2
✓ Branch 0 taken 563482 times.
✓ Branch 1 taken 75477 times.
638959 int cand_left = (lc->ctb_left_flag || x0b) ?
1995
2/2
✓ Branch 0 taken 638959 times.
✓ Branch 1 taken 6813619 times.
8091537 s->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC;
1996
1997 7452578 int y_ctb = (y0 >> (s->ps.sps->log2_ctb_size)) << (s->ps.sps->log2_ctb_size);
1998
1999 7452578 MvField *tab_mvf = s->ref->tab_mvf;
2000 int intra_pred_mode;
2001 int candidate[3];
2002 int i, j;
2003
2004 // intra_pred_mode prediction does not cross vertical CTB boundaries
2005
2/2
✓ Branch 0 taken 942311 times.
✓ Branch 1 taken 6510267 times.
7452578 if ((y0 - 1) < y_ctb)
2006 942311 cand_up = INTRA_DC;
2007
2008
2/2
✓ Branch 0 taken 1563766 times.
✓ Branch 1 taken 5888812 times.
7452578 if (cand_left == cand_up) {
2009
2/2
✓ Branch 0 taken 920535 times.
✓ Branch 1 taken 643231 times.
1563766 if (cand_left < 2) {
2010 920535 candidate[0] = INTRA_PLANAR;
2011 920535 candidate[1] = INTRA_DC;
2012 920535 candidate[2] = INTRA_ANGULAR_26;
2013 } else {
2014 643231 candidate[0] = cand_left;
2015 643231 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2016 643231 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2017 }
2018 } else {
2019 5888812 candidate[0] = cand_left;
2020 5888812 candidate[1] = cand_up;
2021
4/4
✓ Branch 0 taken 4904693 times.
✓ Branch 1 taken 984119 times.
✓ Branch 2 taken 4060508 times.
✓ Branch 3 taken 844185 times.
5888812 if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) {
2022 4060508 candidate[2] = INTRA_PLANAR;
2023
4/4
✓ Branch 0 taken 1600159 times.
✓ Branch 1 taken 228145 times.
✓ Branch 2 taken 1215854 times.
✓ Branch 3 taken 384305 times.
1828304 } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) {
2024 1215854 candidate[2] = INTRA_DC;
2025 } else {
2026 612450 candidate[2] = INTRA_ANGULAR_26;
2027 }
2028 }
2029
2030
2/2
✓ Branch 0 taken 4456300 times.
✓ Branch 1 taken 2996278 times.
7452578 if (prev_intra_luma_pred_flag) {
2031 4456300 intra_pred_mode = candidate[lc->pu.mpm_idx];
2032 } else {
2033
2/2
✓ Branch 0 taken 1434321 times.
✓ Branch 1 taken 1561957 times.
2996278 if (candidate[0] > candidate[1])
2034 1434321 FFSWAP(uint8_t, candidate[0], candidate[1]);
2035
2/2
✓ Branch 0 taken 1788557 times.
✓ Branch 1 taken 1207721 times.
2996278 if (candidate[0] > candidate[2])
2036 1788557 FFSWAP(uint8_t, candidate[0], candidate[2]);
2037
2/2
✓ Branch 0 taken 2236551 times.
✓ Branch 1 taken 759727 times.
2996278 if (candidate[1] > candidate[2])
2038 2236551 FFSWAP(uint8_t, candidate[1], candidate[2]);
2039
2040 2996278 intra_pred_mode = lc->pu.rem_intra_luma_pred_mode;
2041
2/2
✓ Branch 0 taken 8988834 times.
✓ Branch 1 taken 2996278 times.
11985112 for (i = 0; i < 3; i++)
2042
2/2
✓ Branch 0 taken 6549484 times.
✓ Branch 1 taken 2439350 times.
8988834 if (intra_pred_mode >= candidate[i])
2043 6549484 intra_pred_mode++;
2044 }
2045
2046 /* write the intra prediction units into the mv array */
2047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7452578 times.
7452578 if (!size_in_pus)
2048 size_in_pus = 1;
2049
2/2
✓ Branch 0 taken 12964804 times.
✓ Branch 1 taken 7452578 times.
20417382 for (i = 0; i < size_in_pus; i++) {
2050 12964804 memset(&s->tab_ipm[(y_pu + i) * min_pu_width + x_pu],
2051 intra_pred_mode, size_in_pus);
2052
2053
2/2
✓ Branch 0 taken 40262204 times.
✓ Branch 1 taken 12964804 times.
53227008 for (j = 0; j < size_in_pus; j++) {
2054 40262204 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA;
2055 }
2056 }
2057
2058 7452578 return intra_pred_mode;
2059 }
2060
2061 10908806 static av_always_inline void set_ct_depth(HEVCContext *s, int x0, int y0,
2062 int log2_cb_size, int ct_depth)
2063 {
2064 10908806 int length = (1 << log2_cb_size) >> s->ps.sps->log2_min_cb_size;
2065 10908806 int x_cb = x0 >> s->ps.sps->log2_min_cb_size;
2066 10908806 int y_cb = y0 >> s->ps.sps->log2_min_cb_size;
2067 int y;
2068
2069
2/2
✓ Branch 0 taken 19994581 times.
✓ Branch 1 taken 10908806 times.
30903387 for (y = 0; y < length; y++)
2070 19994581 memset(&s->tab_ct_depth[(y_cb + y) * s->ps.sps->min_cb_width + x_cb],
2071 ct_depth, length);
2072 10908806 }
2073
2074 static const uint8_t tab_mode_idx[] = {
2075 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2076 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2077
2078 3902819 static void intra_prediction_unit(HEVCContext *s, int x0, int y0,
2079 int log2_cb_size)
2080 {
2081 3902819 HEVCLocalContext *lc = s->HEVClc;
2082 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2083 uint8_t prev_intra_luma_pred_flag[4];
2084 3902819 int split = lc->cu.part_mode == PART_NxN;
2085 3902819 int pb_size = (1 << log2_cb_size) >> split;
2086 3902819 int side = split + 1;
2087 int chroma_mode;
2088 int i, j;
2089
2090
2/2
✓ Branch 0 taken 5086072 times.
✓ Branch 1 taken 3902819 times.
8988891 for (i = 0; i < side; i++)
2091
2/2
✓ Branch 0 taken 7452578 times.
✓ Branch 1 taken 5086072 times.
12538650 for (j = 0; j < side; j++)
2092 7452578 prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(s);
2093
2094
2/2
✓ Branch 0 taken 5086072 times.
✓ Branch 1 taken 3902819 times.
8988891 for (i = 0; i < side; i++) {
2095
2/2
✓ Branch 0 taken 7452578 times.
✓ Branch 1 taken 5086072 times.
12538650 for (j = 0; j < side; j++) {
2096
2/2
✓ Branch 0 taken 4456300 times.
✓ Branch 1 taken 2996278 times.
7452578 if (prev_intra_luma_pred_flag[2 * i + j])
2097 4456300 lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(s);
2098 else
2099 2996278 lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(s);
2100
2101 7452578 lc->pu.intra_pred_mode[2 * i + j] =
2102 7452578 luma_intra_pred_mode(s, x0 + pb_size * j, y0 + pb_size * i, pb_size,
2103 7452578 prev_intra_luma_pred_flag[2 * i + j]);
2104 }
2105 }
2106
2107
2/2
✓ Branch 0 taken 105006 times.
✓ Branch 1 taken 3797813 times.
3902819 if (s->ps.sps->chroma_format_idc == 3) {
2108
2/2
✓ Branch 0 taken 138857 times.
✓ Branch 1 taken 105006 times.
243863 for (i = 0; i < side; i++) {
2109
2/2
✓ Branch 0 taken 206559 times.
✓ Branch 1 taken 138857 times.
345416 for (j = 0; j < side; j++) {
2110 206559 lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s);
2111
2/2
✓ Branch 0 taken 34248 times.
✓ Branch 1 taken 172311 times.
206559 if (chroma_mode != 4) {
2112
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])
2113 2343 lc->pu.intra_pred_mode_c[2 * i + j] = 34;
2114 else
2115 31905 lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode];
2116 } else {
2117 172311 lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j];
2118 }
2119 }
2120 }
2121
2/2
✓ Branch 0 taken 247106 times.
✓ Branch 1 taken 3550707 times.
3797813 } else if (s->ps.sps->chroma_format_idc == 2) {
2122 int mode_idx;
2123 247106 lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s);
2124
2/2
✓ Branch 0 taken 73995 times.
✓ Branch 1 taken 173111 times.
247106 if (chroma_mode != 4) {
2125
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])
2126 3515 mode_idx = 34;
2127 else
2128 70480 mode_idx = intra_chroma_table[chroma_mode];
2129 } else {
2130 173111 mode_idx = lc->pu.intra_pred_mode[0];
2131 }
2132 247106 lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx];
2133
2/2
✓ Branch 0 taken 3550515 times.
✓ Branch 1 taken 192 times.
3550707 } else if (s->ps.sps->chroma_format_idc != 0) {
2134 3550515 chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s);
2135
2/2
✓ Branch 0 taken 917964 times.
✓ Branch 1 taken 2632551 times.
3550515 if (chroma_mode != 4) {
2136
2/2
✓ Branch 0 taken 68035 times.
✓ Branch 1 taken 849929 times.
917964 if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2137 68035 lc->pu.intra_pred_mode_c[0] = 34;
2138 else
2139 849929 lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode];
2140 } else {
2141 2632551 lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0];
2142 }
2143 }
2144 3902819 }
2145
2146 7005988 static void intra_prediction_unit_default_value(HEVCContext *s,
2147 int x0, int y0,
2148 int log2_cb_size)
2149 {
2150 7005988 HEVCLocalContext *lc = s->HEVClc;
2151 7005988 int pb_size = 1 << log2_cb_size;
2152 7005988 int size_in_pus = pb_size >> s->ps.sps->log2_min_pu_size;
2153 7005988 int min_pu_width = s->ps.sps->min_pu_width;
2154 7005988 MvField *tab_mvf = s->ref->tab_mvf;
2155 7005988 int x_pu = x0 >> s->ps.sps->log2_min_pu_size;
2156 7005988 int y_pu = y0 >> s->ps.sps->log2_min_pu_size;
2157 int j, k;
2158
2159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7005988 times.
7005988 if (size_in_pus == 0)
2160 size_in_pus = 1;
2161
2/2
✓ Branch 0 taken 29390866 times.
✓ Branch 1 taken 7005988 times.
36396854 for (j = 0; j < size_in_pus; j++)
2162 29390866 memset(&s->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus);
2163
2/2
✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 6993555 times.
7005988 if (lc->cu.pred_mode == MODE_INTRA)
2164
2/2
✓ Branch 0 taken 40908 times.
✓ Branch 1 taken 12433 times.
53341 for (j = 0; j < size_in_pus; j++)
2165
2/2
✓ Branch 0 taken 182512 times.
✓ Branch 1 taken 40908 times.
223420 for (k = 0; k < size_in_pus; k++)
2166 182512 tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA;
2167 7005988 }
2168
2169 10908807 static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
2170 {
2171 10908807 int cb_size = 1 << log2_cb_size;
2172 10908807 HEVCLocalContext *lc = s->HEVClc;
2173 10908807 int log2_min_cb_size = s->ps.sps->log2_min_cb_size;
2174 10908807 int length = cb_size >> log2_min_cb_size;
2175 10908807 int min_cb_width = s->ps.sps->min_cb_width;
2176 10908807 int x_cb = x0 >> log2_min_cb_size;
2177 10908807 int y_cb = y0 >> log2_min_cb_size;
2178 10908807 int idx = log2_cb_size - 2;
2179 10908807 int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2180 int x, y, ret;
2181
2182 10908807 lc->cu.x = x0;
2183 10908807 lc->cu.y = y0;
2184 10908807 lc->cu.pred_mode = MODE_INTRA;
2185 10908807 lc->cu.part_mode = PART_2Nx2N;
2186 10908807 lc->cu.intra_split_flag = 0;
2187
2188 10908807 SAMPLE_CTB(s->skip_flag, x_cb, y_cb) = 0;
2189
2/2
✓ Branch 0 taken 43635228 times.
✓ Branch 1 taken 10908807 times.
54544035 for (x = 0; x < 4; x++)
2190 43635228 lc->pu.intra_pred_mode[x] = 1;
2191
2/2
✓ Branch 0 taken 200139 times.
✓ Branch 1 taken 10708668 times.
10908807 if (s->ps.pps->transquant_bypass_enable_flag) {
2192 200139 lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(s);
2193
2/2
✓ Branch 0 taken 80538 times.
✓ Branch 1 taken 119601 times.
200139 if (lc->cu.cu_transquant_bypass_flag)
2194 80538 set_deblocking_bypass(s, x0, y0, log2_cb_size);
2195 } else
2196 10708668 lc->cu.cu_transquant_bypass_flag = 0;
2197
2198
2/2
✓ Branch 0 taken 8059111 times.
✓ Branch 1 taken 2849696 times.
10908807 if (s->sh.slice_type != HEVC_SLICE_I) {
2199 8059111 uint8_t skip_flag = ff_hevc_skip_flag_decode(s, x0, y0, x_cb, y_cb);
2200
2201 8059111 x = y_cb * min_cb_width + x_cb;
2202
2/2
✓ Branch 0 taken 16271489 times.
✓ Branch 1 taken 8059111 times.
24330600 for (y = 0; y < length; y++) {
2203 16271489 memset(&s->skip_flag[x], skip_flag, length);
2204 16271489 x += min_cb_width;
2205 }
2206
2/2
✓ Branch 0 taken 3873499 times.
✓ Branch 1 taken 4185612 times.
8059111 lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER;
2207 } else {
2208 2849696 x = y_cb * min_cb_width + x_cb;
2209
2/2
✓ Branch 0 taken 3723093 times.
✓ Branch 1 taken 2849696 times.
6572789 for (y = 0; y < length; y++) {
2210 3723093 memset(&s->skip_flag[x], 0, length);
2211 3723093 x += min_cb_width;
2212 }
2213 }
2214
2215
2/2
✓ Branch 0 taken 3873499 times.
✓ Branch 1 taken 7035308 times.
10908807 if (SAMPLE_CTB(s->skip_flag, x_cb, y_cb)) {
2216 3873499 hls_prediction_unit(s, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2217 3873499 intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
2218
2219
2/2
✓ Branch 0 taken 3726986 times.
✓ Branch 1 taken 146513 times.
3873499 if (!s->sh.disable_deblocking_filter_flag)
2220 3726986 ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
2221 } else {
2222 7035308 int pcm_flag = 0;
2223
2224
2/2
✓ Branch 0 taken 4185612 times.
✓ Branch 1 taken 2849696 times.
7035308 if (s->sh.slice_type != HEVC_SLICE_I)
2225 4185612 lc->cu.pred_mode = ff_hevc_pred_mode_decode(s);
2226
2/2
✓ Branch 0 taken 3915252 times.
✓ Branch 1 taken 3120056 times.
7035308 if (lc->cu.pred_mode != MODE_INTRA ||
2227
2/2
✓ Branch 0 taken 3013523 times.
✓ Branch 1 taken 901729 times.
3915252 log2_cb_size == s->ps.sps->log2_min_cb_size) {
2228 6133579 lc->cu.part_mode = ff_hevc_part_mode_decode(s, log2_cb_size);
2229
2/2
✓ Branch 0 taken 1288889 times.
✓ Branch 1 taken 4844690 times.
7422468 lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
2230
2/2
✓ Branch 0 taken 1183253 times.
✓ Branch 1 taken 105636 times.
1288889 lc->cu.pred_mode == MODE_INTRA;
2231 }
2232
2233
2/2
✓ Branch 0 taken 3915252 times.
✓ Branch 1 taken 3120056 times.
7035308 if (lc->cu.pred_mode == MODE_INTRA) {
2234
4/4
✓ Branch 0 taken 2731999 times.
✓ Branch 1 taken 1183253 times.
✓ Branch 2 taken 162684 times.
✓ Branch 3 taken 2569315 times.
3915252 if (lc->cu.part_mode == PART_2Nx2N && s->ps.sps->pcm_enabled_flag &&
2235
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 &&
2236
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) {
2237 153183 pcm_flag = ff_hevc_pcm_flag_decode(s);
2238 }
2239
2/2
✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 3902819 times.
3915252 if (pcm_flag) {
2240 12433 intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
2241 12433 ret = hls_pcm_sample(s, x0, y0, log2_cb_size);
2242
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12425 times.
12433 if (s->ps.sps->pcm.loop_filter_disable_flag)
2243 8 set_deblocking_bypass(s, x0, y0, log2_cb_size);
2244
2245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
12433 if (ret < 0)
2246 return ret;
2247 } else {
2248 3902819 intra_prediction_unit(s, x0, y0, log2_cb_size);
2249 }
2250 } else {
2251 3120056 intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
2252
8/9
✓ Branch 0 taken 1740917 times.
✓ Branch 1 taken 445873 times.
✓ Branch 2 taken 535507 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.
3120056 switch (lc->cu.part_mode) {
2253 1740917 case PART_2Nx2N:
2254 1740917 hls_prediction_unit(s, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2255 1740917 break;
2256 445873 case PART_2NxN:
2257 445873 hls_prediction_unit(s, x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2258 445873 hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2259 445873 break;
2260 535507 case PART_Nx2N:
2261 535507 hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2262 535507 hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2263 535507 break;
2264 63734 case PART_2NxnU:
2265 63734 hls_prediction_unit(s, x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
2266 63734 hls_prediction_unit(s, x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
2267 63734 break;
2268 55171 case PART_2NxnD:
2269 55171 hls_prediction_unit(s, x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
2270 55171 hls_prediction_unit(s, x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
2271 55171 break;
2272 93167 case PART_nLx2N:
2273 93167 hls_prediction_unit(s, x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
2274 93167 hls_prediction_unit(s, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2275 93167 break;
2276 80051 case PART_nRx2N:
2277 80051 hls_prediction_unit(s, x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
2278 80051 hls_prediction_unit(s, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2279 80051 break;
2280 105636 case PART_NxN:
2281 105636 hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
2282 105636 hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2283 105636 hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2284 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);
2285 105636 break;
2286 }
2287 }
2288
2289
2/2
✓ Branch 0 taken 7022875 times.
✓ Branch 1 taken 12433 times.
7035308 if (!pcm_flag) {
2290 7022875 int rqt_root_cbf = 1;
2291
2292
2/2
✓ Branch 0 taken 3120056 times.
✓ Branch 1 taken 3902819 times.
7022875 if (lc->cu.pred_mode != MODE_INTRA &&
2293
4/4
✓ Branch 0 taken 1740917 times.
✓ Branch 1 taken 1379139 times.
✓ Branch 2 taken 968483 times.
✓ Branch 3 taken 772434 times.
3120056 !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) {
2294 2347622 rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(s);
2295 }
2296
2/2
✓ Branch 0 taken 5707107 times.
✓ Branch 1 taken 1315768 times.
7022875 if (rqt_root_cbf) {
2297 const static int cbf[2] = { 0 };
2298
2/2
✓ Branch 0 taken 3902819 times.
✓ Branch 1 taken 1804288 times.
5707107 lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ?
2299 3902819 s->ps.sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
2300 1804288 s->ps.sps->max_transform_hierarchy_depth_inter;
2301 5707107 ret = hls_transform_tree(s, x0, y0, x0, y0, x0, y0,
2302 log2_cb_size,
2303 log2_cb_size, 0, 0, cbf, cbf);
2304
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5707106 times.
5707107 if (ret < 0)
2305 1 return ret;
2306 } else {
2307
2/2
✓ Branch 0 taken 1259336 times.
✓ Branch 1 taken 56432 times.
1315768 if (!s->sh.disable_deblocking_filter_flag)
2308 1259336 ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
2309 }
2310 }
2311 }
2312
2313
4/4
✓ Branch 0 taken 1882391 times.
✓ Branch 1 taken 9026415 times.
✓ Branch 2 taken 746112 times.
✓ Branch 3 taken 1136279 times.
10908806 if (s->ps.pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
2314 746112 ff_hevc_set_qPy(s, x0, y0, log2_cb_size);
2315
2316 10908806 x = y_cb * min_cb_width + x_cb;
2317
2/2
✓ Branch 0 taken 19994581 times.
✓ Branch 1 taken 10908806 times.
30903387 for (y = 0; y < length; y++) {
2318 19994581 memset(&s->qp_y_tab[x], lc->qp_y, length);
2319 19994581 x += min_cb_width;
2320 }
2321
2322
2/2
✓ Branch 0 taken 3689244 times.
✓ Branch 1 taken 7219562 times.
10908806 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2323
2/2
✓ Branch 0 taken 2145190 times.
✓ Branch 1 taken 1544054 times.
3689244 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2324 2145190 lc->qPy_pred = lc->qp_y;
2325 }
2326
2327 10908806 set_ct_depth(s, x0, y0, log2_cb_size, lc->ct_depth);
2328
2329 10908806 return 0;
2330 }
2331
2332 14234571 static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
2333 int log2_cb_size, int cb_depth)
2334 {
2335 14234571 HEVCLocalContext *lc = s->HEVClc;
2336 14234571 const int cb_size = 1 << log2_cb_size;
2337 int ret;
2338 int split_cu;
2339
2340 14234571 lc->ct_depth = cb_depth;
2341
2/2
✓ Branch 0 taken 14205968 times.
✓ Branch 1 taken 28603 times.
14234571 if (x0 + cb_size <= s->ps.sps->width &&
2342
2/2
✓ Branch 0 taken 13891949 times.
✓ Branch 1 taken 314019 times.
14205968 y0 + cb_size <= s->ps.sps->height &&
2343
2/2
✓ Branch 0 taken 7417795 times.
✓ Branch 1 taken 6474154 times.
13891949 log2_cb_size > s->ps.sps->log2_min_cb_size) {
2344 7417795 split_cu = ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0);
2345 } else {
2346 6816776 split_cu = (log2_cb_size > s->ps.sps->log2_min_cb_size);
2347 }
2348
2/2
✓ Branch 0 taken 2446379 times.
✓ Branch 1 taken 11788192 times.
14234571 if (s->ps.pps->cu_qp_delta_enabled_flag &&
2349
2/2
✓ Branch 0 taken 1382431 times.
✓ Branch 1 taken 1063948 times.
2446379 log2_cb_size >= s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth) {
2350 1382431 lc->tu.is_cu_qp_delta_coded = 0;
2351 1382431 lc->tu.cu_qp_delta = 0;
2352 }
2353
2354
2/2
✓ Branch 0 taken 519326 times.
✓ Branch 1 taken 13715245 times.
14234571 if (s->sh.cu_chroma_qp_offset_enabled_flag &&
2355
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) {
2356 519326 lc->tu.is_cu_chroma_qp_offset_coded = 0;
2357 }
2358
2359
2/2
✓ Branch 0 taken 3325764 times.
✓ Branch 1 taken 10908807 times.
14234571 if (split_cu) {
2360 3325764 int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2361 3325764 const int cb_size_split = cb_size >> 1;
2362 3325764 const int x1 = x0 + cb_size_split;
2363 3325764 const int y1 = y0 + cb_size_split;
2364
2365 3325764 int more_data = 0;
2366
2367 3325764 more_data = hls_coding_quadtree(s, x0, y0, log2_cb_size - 1, cb_depth + 1);
2368
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3325762 times.
3325764 if (more_data < 0)
2369 2 return more_data;
2370
2371
4/4
✓ Branch 0 taken 3325753 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3298072 times.
✓ Branch 3 taken 27681 times.
3325762 if (more_data && x1 < s->ps.sps->width) {
2372 3298072 more_data = hls_coding_quadtree(s, x1, y0, log2_cb_size - 1, cb_depth + 1);
2373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3298072 times.
3298072 if (more_data < 0)
2374 return more_data;
2375 }
2376
4/4
✓ Branch 0 taken 3315546 times.
✓ Branch 1 taken 10216 times.
✓ Branch 2 taken 3119385 times.
✓ Branch 3 taken 196161 times.
3325762 if (more_data && y1 < s->ps.sps->height) {
2377 3119385 more_data = hls_coding_quadtree(s, x0, y1, log2_cb_size - 1, cb_depth + 1);
2378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3119385 times.
3119385 if (more_data < 0)
2379 return more_data;
2380 }
2381
4/4
✓ Branch 0 taken 3309461 times.
✓ Branch 1 taken 16301 times.
✓ Branch 2 taken 3287865 times.
✓ Branch 3 taken 21596 times.
3325762 if (more_data && x1 < s->ps.sps->width &&
2382
2/2
✓ Branch 0 taken 3091704 times.
✓ Branch 1 taken 196161 times.
3287865 y1 < s->ps.sps->height) {
2383 3091704 more_data = hls_coding_quadtree(s, x1, y1, log2_cb_size - 1, cb_depth + 1);
2384
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3091703 times.
3091704 if (more_data < 0)
2385 1 return more_data;
2386 }
2387
2388
2/2
✓ Branch 0 taken 1864346 times.
✓ Branch 1 taken 1461415 times.
3325761 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2389
2/2
✓ Branch 0 taken 1387026 times.
✓ Branch 1 taken 477320 times.
1864346 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2390 1387026 lc->qPy_pred = lc->qp_y;
2391
2392
2/2
✓ Branch 0 taken 3290314 times.
✓ Branch 1 taken 35447 times.
3325761 if (more_data)
2393
2/2
✓ Branch 0 taken 90547 times.
✓ Branch 1 taken 3199767 times.
3380861 return ((x1 + cb_size_split) < s->ps.sps->width ||
2394
1/2
✓ Branch 0 taken 90547 times.
✗ Branch 1 not taken.
90547 (y1 + cb_size_split) < s->ps.sps->height);
2395 else
2396 35447 return 0;
2397 } else {
2398 10908807 ret = hls_coding_unit(s, x0, y0, log2_cb_size);
2399
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10908806 times.
10908807 if (ret < 0)
2400 1 return ret;
2401 10908806 if ((!((x0 + cb_size) %
2402
2/2
✓ Branch 0 taken 7970652 times.
✓ Branch 1 taken 2938154 times.
10908806 (1 << (s->ps.sps->log2_ctb_size))) ||
2403
2/2
✓ Branch 0 taken 70697 times.
✓ Branch 1 taken 7899955 times.
7970652 (x0 + cb_size >= s->ps.sps->width)) &&
2404 3008851 (!((y0 + cb_size) %
2405
2/2
✓ Branch 0 taken 1704823 times.
✓ Branch 1 taken 1304028 times.
3008851 (1 << (s->ps.sps->log2_ctb_size))) ||
2406
2/2
✓ Branch 0 taken 95617 times.
✓ Branch 1 taken 1609206 times.
1704823 (y0 + cb_size >= s->ps.sps->height))) {
2407 1399645 int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(s);
2408 1399645 return !end_of_slice_flag;
2409 } else {
2410 9509161 return 1;
2411 }
2412 }
2413
2414 return 0;
2415 }
2416
2417 1399646 static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb,
2418 int ctb_addr_ts)
2419 {
2420 1399646 HEVCLocalContext *lc = s->HEVClc;
2421 1399646 int ctb_size = 1 << s->ps.sps->log2_ctb_size;
2422 1399646 int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2423 1399646 int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
2424
2425 1399646 s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
2426
2427
2/2
✓ Branch 0 taken 97464 times.
✓ Branch 1 taken 1302182 times.
1399646 if (s->ps.pps->entropy_coding_sync_enabled_flag) {
2428
3/4
✓ Branch 0 taken 5402 times.
✓ Branch 1 taken 92062 times.
✓ Branch 2 taken 5402 times.
✗ Branch 3 not taken.
97464 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2429 5402 lc->first_qp_group = 1;
2430 97464 lc->end_of_tiles_x = s->ps.sps->width;
2431
2/2
✓ Branch 0 taken 290050 times.
✓ Branch 1 taken 1012132 times.
1302182 } else if (s->ps.pps->tiles_enabled_flag) {
2432
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]) {
2433 6285 int idxX = s->ps.pps->col_idxX[x_ctb >> s->ps.sps->log2_ctb_size];
2434 6285 lc->end_of_tiles_x = x_ctb + (s->ps.pps->column_width[idxX] << s->ps.sps->log2_ctb_size);
2435 6285 lc->first_qp_group = 1;
2436 }
2437 } else {
2438 1012132 lc->end_of_tiles_x = s->ps.sps->width;
2439 }
2440
2441 1399646 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->ps.sps->height);
2442
2443 1399646 lc->boundary_flags = 0;
2444
2/2
✓ Branch 0 taken 290050 times.
✓ Branch 1 taken 1109596 times.
1399646 if (s->ps.pps->tiles_enabled_flag) {
2445
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]])
2446 30707 lc->boundary_flags |= BOUNDARY_LEFT_TILE;
2447
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])
2448 3695 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2449
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]])
2450 33781 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
2451
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])
2452 14490 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2453 } else {
2454
2/2
✓ Branch 0 taken 17553 times.
✓ Branch 1 taken 1092043 times.
1109596 if (ctb_addr_in_slice <= 0)
2455 17553 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2456
2/2
✓ Branch 0 taken 183944 times.
✓ Branch 1 taken 925652 times.
1109596 if (ctb_addr_in_slice < s->ps.sps->ctb_width)
2457 183944 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2458 }
2459
2460
6/6
✓ Branch 0 taken 1326895 times.
✓ Branch 1 taken 72751 times.
✓ Branch 2 taken 1319008 times.
✓ Branch 3 taken 7887 times.
✓ Branch 4 taken 1289327 times.
✓ Branch 5 taken 29681 times.
1399646 lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
2461
6/6
✓ Branch 0 taken 1281282 times.
✓ Branch 1 taken 118364 times.
✓ Branch 2 taken 1187473 times.
✓ Branch 3 taken 93809 times.
✓ Branch 4 taken 1167353 times.
✓ Branch 5 taken 20120 times.
1399646 lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->ps.sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
2462
6/6
✓ Branch 0 taken 1281282 times.
✓ Branch 1 taken 118364 times.
✓ Branch 2 taken 1190059 times.
✓ Branch 3 taken 91223 times.
✓ Branch 4 taken 1134395 times.
✓ Branch 5 taken 55664 times.
1399646 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]]));
2463
8/8
✓ Branch 0 taken 1326895 times.
✓ Branch 1 taken 72751 times.
✓ Branch 2 taken 1218017 times.
✓ Branch 3 taken 108878 times.
✓ Branch 4 taken 1129271 times.
✓ Branch 5 taken 88746 times.
✓ Branch 6 taken 1085081 times.
✓ Branch 7 taken 44190 times.
1399646 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]]));
2464 1399646 }
2465
2466 27475 static int hls_decode_entry(AVCodecContext *avctxt, void *isFilterThread)
2467 {
2468 27475 HEVCContext *s = avctxt->priv_data;
2469 27475 int ctb_size = 1 << s->ps.sps->log2_ctb_size;
2470 27475 int more_data = 1;
2471 27475 int x_ctb = 0;
2472 27475 int y_ctb = 0;
2473 27475 int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
2474 int ret;
2475
2476
3/4
✓ Branch 0 taken 9486 times.
✓ Branch 1 taken 17989 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9486 times.
27475 if (!ctb_addr_ts && s->sh.dependent_slice_segment_flag) {
2477 av_log(s->avctx, AV_LOG_ERROR, "Impossible initial tile.\n");
2478 return AVERROR_INVALIDDATA;
2479 }
2480
2481
2/2
✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 19528 times.
27475 if (s->sh.dependent_slice_segment_flag) {
2482 7947 int prev_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
2483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
7947 if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
2484 av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
2485 return AVERROR_INVALIDDATA;
2486 }
2487 }
2488
2489
3/4
✓ Branch 0 taken 1399646 times.
✓ Branch 1 taken 27474 times.
✓ Branch 2 taken 1399646 times.
✗ Branch 3 not taken.
1427120 while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2490 1399646 int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2491
2492 1399646 x_ctb = (ctb_addr_rs % ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;
2493 1399646 y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;
2494 1399646 hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts);
2495
2496 1399646 ret = ff_hevc_cabac_init(s, ctb_addr_ts, 0);
2497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1399646 times.
1399646 if (ret < 0) {
2498 s->tab_slice_address[ctb_addr_rs] = -1;
2499 return ret;
2500 }
2501
2502 1399646 hls_sao_param(s, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size);
2503
2504 1399646 s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2505 1399646 s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2506 1399646 s->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
2507
2508 1399646 more_data = hls_coding_quadtree(s, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0);
2509
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1399645 times.
1399646 if (more_data < 0) {
2510 1 s->tab_slice_address[ctb_addr_rs] = -1;
2511 1 return more_data;
2512 }
2513
2514
2515 1399645 ctb_addr_ts++;
2516 1399645 ff_hevc_save_states(s, ctb_addr_ts);
2517 1399645 ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size);
2518 }
2519
2520
2/2
✓ Branch 0 taken 13966 times.
✓ Branch 1 taken 13508 times.
27474 if (x_ctb + ctb_size >= s->ps.sps->width &&
2521
2/2
✓ Branch 0 taken 9485 times.
✓ Branch 1 taken 4481 times.
13966 y_ctb + ctb_size >= s->ps.sps->height)
2522 9485 ff_hevc_hls_filter(s, x_ctb, y_ctb, ctb_size);
2523
2524 27474 return ctb_addr_ts;
2525 }
2526
2527 27475 static int hls_slice_data(HEVCContext *s)
2528 {
2529 int arg[2];
2530 int ret[2];
2531
2532 27475 arg[0] = 0;
2533 27475 arg[1] = 1;
2534
2535 27475 s->avctx->execute(s->avctx, hls_decode_entry, arg, ret , 1, sizeof(int));
2536 27475 return ret[0];
2537 }
2538 static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *input_ctb_row, int job, int self_id)
2539 {
2540 HEVCContext *s1 = avctxt->priv_data, *s;
2541 HEVCLocalContext *lc;
2542 int ctb_size = 1<< s1->ps.sps->log2_ctb_size;
2543 int more_data = 1;
2544 int *ctb_row_p = input_ctb_row;
2545 int ctb_row = ctb_row_p[job];
2546 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);
2547 int ctb_addr_ts = s1->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2548 int thread = ctb_row % s1->threads_number;
2549 int ret;
2550
2551 s = s1->sList[self_id];
2552 lc = s->HEVClc;
2553
2554 if(ctb_row) {
2555 ret = init_get_bits8(&lc->gb, s->data + s->sh.offset[ctb_row - 1], s->sh.size[ctb_row - 1]);
2556 if (ret < 0)
2557 goto error;
2558 ff_init_cabac_decoder(&lc->cc, s->data + s->sh.offset[(ctb_row)-1], s->sh.size[ctb_row - 1]);
2559 }
2560
2561 while(more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2562 int x_ctb = (ctb_addr_rs % s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size;
2563 int y_ctb = (ctb_addr_rs / s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size;
2564
2565 hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts);
2566
2567 ff_thread_await_progress2(s->avctx, ctb_row, thread, SHIFT_CTB_WPP);
2568
2569 if (atomic_load(&s1->wpp_err)) {
2570 ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP);
2571 return 0;
2572 }
2573
2574 ret = ff_hevc_cabac_init(s, ctb_addr_ts, thread);
2575 if (ret < 0)
2576 goto error;
2577 hls_sao_param(s, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size);
2578 more_data = hls_coding_quadtree(s, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0);
2579
2580 if (more_data < 0) {
2581 ret = more_data;
2582 goto error;
2583 }
2584
2585 ctb_addr_ts++;
2586
2587 ff_hevc_save_states(s, ctb_addr_ts);
2588 ff_thread_report_progress2(s->avctx, ctb_row, thread, 1);
2589 ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size);
2590
2591 if (!more_data && (x_ctb+ctb_size) < s->ps.sps->width && ctb_row != s->sh.num_entry_point_offsets) {
2592 atomic_store(&s1->wpp_err, 1);
2593 ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP);
2594 return 0;
2595 }
2596
2597 if ((x_ctb+ctb_size) >= s->ps.sps->width && (y_ctb+ctb_size) >= s->ps.sps->height ) {
2598 ff_hevc_hls_filter(s, x_ctb, y_ctb, ctb_size);
2599 ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP);
2600 return ctb_addr_ts;
2601 }
2602 ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2603 x_ctb+=ctb_size;
2604
2605 if(x_ctb >= s->ps.sps->width) {
2606 break;
2607 }
2608 }
2609 ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP);
2610
2611 return 0;
2612 error:
2613 s->tab_slice_address[ctb_addr_rs] = -1;
2614 atomic_store(&s1->wpp_err, 1);
2615 ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP);
2616 return ret;
2617 }
2618
2619 static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
2620 {
2621 const uint8_t *data = nal->data;
2622 int length = nal->size;
2623 HEVCLocalContext *lc = s->HEVClc;
2624 int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));
2625 int *arg = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));
2626 int64_t offset;
2627 int64_t startheader, cmpt = 0;
2628 int i, j, res = 0;
2629
2630 if (!ret || !arg) {
2631 av_free(ret);
2632 av_free(arg);
2633 return AVERROR(ENOMEM);
2634 }
2635
2636 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) {
2637 av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
2638 s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets,
2639 s->ps.sps->ctb_width, s->ps.sps->ctb_height
2640 );
2641 res = AVERROR_INVALIDDATA;
2642 goto error;
2643 }
2644
2645 ff_alloc_entries(s->avctx, s->sh.num_entry_point_offsets + 1);
2646
2647 for (i = 1; i < s->threads_number; i++) {
2648 if (s->sList[i] && s->HEVClcList[i])
2649 continue;
2650 av_freep(&s->sList[i]);
2651 av_freep(&s->HEVClcList[i]);
2652 s->sList[i] = av_malloc(sizeof(HEVCContext));
2653 s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext));
2654 if (!s->sList[i] || !s->HEVClcList[i]) {
2655 res = AVERROR(ENOMEM);
2656 goto error;
2657 }
2658 memcpy(s->sList[i], s, sizeof(HEVCContext));
2659 s->sList[i]->HEVClc = s->HEVClcList[i];
2660 }
2661
2662 offset = (lc->gb.index >> 3);
2663
2664 for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2665 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2666 startheader--;
2667 cmpt++;
2668 }
2669 }
2670
2671 for (i = 1; i < s->sh.num_entry_point_offsets; i++) {
2672 offset += (s->sh.entry_point_offset[i - 1] - cmpt);
2673 for (j = 0, cmpt = 0, startheader = offset
2674 + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) {
2675 if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
2676 startheader--;
2677 cmpt++;
2678 }
2679 }
2680 s->sh.size[i - 1] = s->sh.entry_point_offset[i] - cmpt;
2681 s->sh.offset[i - 1] = offset;
2682
2683 }
2684 if (s->sh.num_entry_point_offsets != 0) {
2685 offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt;
2686 if (length < offset) {
2687 av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n");
2688 res = AVERROR_INVALIDDATA;
2689 goto error;
2690 }
2691 s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset;
2692 s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset;
2693
2694 }
2695 s->data = data;
2696
2697 for (i = 1; i < s->threads_number; i++) {
2698 s->sList[i]->HEVClc->first_qp_group = 1;
2699 s->sList[i]->HEVClc->qp_y = s->sList[0]->HEVClc->qp_y;
2700 memcpy(s->sList[i], s, sizeof(HEVCContext));
2701 s->sList[i]->HEVClc = s->HEVClcList[i];
2702 }
2703
2704 atomic_store(&s->wpp_err, 0);
2705 ff_reset_entries(s->avctx);
2706
2707 for (i = 0; i <= s->sh.num_entry_point_offsets; i++) {
2708 arg[i] = i;
2709 ret[i] = 0;
2710 }
2711
2712 if (s->ps.pps->entropy_coding_sync_enabled_flag)
2713 s->avctx->execute2(s->avctx, hls_decode_entry_wpp, arg, ret, s->sh.num_entry_point_offsets + 1);
2714
2715 for (i = 0; i <= s->sh.num_entry_point_offsets; i++)
2716 res += ret[i];
2717 error:
2718 av_free(ret);
2719 av_free(arg);
2720 return res;
2721 }
2722
2723 9486 static int set_side_data(HEVCContext *s)
2724 {
2725 9486 AVFrame *out = s->ref->frame;
2726 int ret;
2727
2728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
9486 if (s->sei.frame_packing.present &&
2729 s->sei.frame_packing.arrangement_type >= 3 &&
2730 s->sei.frame_packing.arrangement_type <= 5 &&
2731 s->sei.frame_packing.content_interpretation_type > 0 &&
2732 s->sei.frame_packing.content_interpretation_type < 3) {
2733 AVStereo3D *stereo = av_stereo3d_create_side_data(out);
2734 if (!stereo)
2735 return AVERROR(ENOMEM);
2736
2737 switch (s->sei.frame_packing.arrangement_type) {
2738 case 3:
2739 if (s->sei.frame_packing.quincunx_subsampling)
2740 stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
2741 else
2742 stereo->type = AV_STEREO3D_SIDEBYSIDE;
2743 break;
2744 case 4:
2745 stereo->type = AV_STEREO3D_TOPBOTTOM;
2746 break;
2747 case 5:
2748 stereo->type = AV_STEREO3D_FRAMESEQUENCE;
2749 break;
2750 }
2751
2752 if (s->sei.frame_packing.content_interpretation_type == 2)
2753 stereo->flags = AV_STEREO3D_FLAG_INVERT;
2754
2755 if (s->sei.frame_packing.arrangement_type == 5) {
2756 if (s->sei.frame_packing.current_frame_is_frame0_flag)
2757 stereo->view = AV_STEREO3D_VIEW_LEFT;
2758 else
2759 stereo->view = AV_STEREO3D_VIEW_RIGHT;
2760 }
2761 }
2762
2763
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
9486 if (s->sei.display_orientation.present &&
2764 (s->sei.display_orientation.anticlockwise_rotation ||
2765 s->sei.display_orientation.hflip || s->sei.display_orientation.vflip)) {
2766 double angle = s->sei.display_orientation.anticlockwise_rotation * 360 / (double) (1 << 16);
2767 AVFrameSideData *rotation = av_frame_new_side_data(out,
2768 AV_FRAME_DATA_DISPLAYMATRIX,
2769 sizeof(int32_t) * 9);
2770 if (!rotation)
2771 return AVERROR(ENOMEM);
2772
2773 /* av_display_rotation_set() expects the angle in the clockwise
2774 * direction, hence the first minus.
2775 * The below code applies the flips after the rotation, yet
2776 * the H.2645 specs require flipping to be applied first.
2777 * Because of R O(phi) = O(-phi) R (where R is flipping around
2778 * an arbitatry axis and O(phi) is the proper rotation by phi)
2779 * we can create display matrices as desired by negating
2780 * the degree once for every flip applied. */
2781 angle = -angle * (1 - 2 * !!s->sei.display_orientation.hflip)
2782 * (1 - 2 * !!s->sei.display_orientation.vflip);
2783 av_display_rotation_set((int32_t *)rotation->data, angle);
2784 av_display_matrix_flip((int32_t *)rotation->data,
2785 s->sei.display_orientation.hflip,
2786 s->sei.display_orientation.vflip);
2787 }
2788
2789 // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1
2790 // so the side data persists for the entire coded video sequence.
2791
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9484 times.
9486 if (s->sei.mastering_display.present > 0 &&
2792
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) {
2793 2 s->sei.mastering_display.present--;
2794 }
2795
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9484 times.
9486 if (s->sei.mastering_display.present) {
2796 // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b
2797 2 const int mapping[3] = {2, 0, 1};
2798 2 const int chroma_den = 50000;
2799 2 const int luma_den = 10000;
2800 int i;
2801 AVMasteringDisplayMetadata *metadata =
2802 2 av_mastering_display_metadata_create_side_data(out);
2803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!metadata)
2804 return AVERROR(ENOMEM);
2805
2806
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (i = 0; i < 3; i++) {
2807 6 const int j = mapping[i];
2808 6 metadata->display_primaries[i][0].num = s->sei.mastering_display.display_primaries[j][0];
2809 6 metadata->display_primaries[i][0].den = chroma_den;
2810 6 metadata->display_primaries[i][1].num = s->sei.mastering_display.display_primaries[j][1];
2811 6 metadata->display_primaries[i][1].den = chroma_den;
2812 }
2813 2 metadata->white_point[0].num = s->sei.mastering_display.white_point[0];
2814 2 metadata->white_point[0].den = chroma_den;
2815 2 metadata->white_point[1].num = s->sei.mastering_display.white_point[1];
2816 2 metadata->white_point[1].den = chroma_den;
2817
2818 2 metadata->max_luminance.num = s->sei.mastering_display.max_luminance;
2819 2 metadata->max_luminance.den = luma_den;
2820 2 metadata->min_luminance.num = s->sei.mastering_display.min_luminance;
2821 2 metadata->min_luminance.den = luma_den;
2822 2 metadata->has_luminance = 1;
2823 2 metadata->has_primaries = 1;
2824
2825 2 av_log(s->avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
2826 2 av_log(s->avctx, AV_LOG_DEBUG,
2827 "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
2828 av_q2d(metadata->display_primaries[0][0]),
2829 av_q2d(metadata->display_primaries[0][1]),
2830 av_q2d(metadata->display_primaries[1][0]),
2831 av_q2d(metadata->display_primaries[1][1]),
2832 av_q2d(metadata->display_primaries[2][0]),
2833 av_q2d(metadata->display_primaries[2][1]),
2834 av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]));
2835 2 av_log(s->avctx, AV_LOG_DEBUG,
2836 "min_luminance=%f, max_luminance=%f\n",
2837 av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
2838 }
2839 // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1
2840 // so the side data persists for the entire coded video sequence.
2841
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9484 times.
9486 if (s->sei.content_light.present > 0 &&
2842
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) {
2843 2 s->sei.content_light.present--;
2844 }
2845
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9484 times.
9486 if (s->sei.content_light.present) {
2846 AVContentLightMetadata *metadata =
2847 2 av_content_light_metadata_create_side_data(out);
2848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!metadata)
2849 return AVERROR(ENOMEM);
2850 2 metadata->MaxCLL = s->sei.content_light.max_content_light_level;
2851 2 metadata->MaxFALL = s->sei.content_light.max_pic_average_light_level;
2852
2853 2 av_log(s->avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
2854 2 av_log(s->avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
2855 metadata->MaxCLL, metadata->MaxFALL);
2856 }
2857
2858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
9486 if (s->sei.a53_caption.buf_ref) {
2859 HEVCSEIA53Caption *a53 = &s->sei.a53_caption;
2860
2861 AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_A53_CC, a53->buf_ref);
2862 if (!sd)
2863 av_buffer_unref(&a53->buf_ref);
2864 a53->buf_ref = NULL;
2865 }
2866
2867
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 9486 times.
9493 for (int i = 0; i < s->sei.unregistered.nb_buf_ref; i++) {
2868 7 HEVCSEIUnregistered *unreg = &s->sei.unregistered;
2869
2870
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (unreg->buf_ref[i]) {
2871 7 AVFrameSideData *sd = av_frame_new_side_data_from_buf(out,
2872 AV_FRAME_DATA_SEI_UNREGISTERED,
2873 7 unreg->buf_ref[i]);
2874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (!sd)
2875 av_buffer_unref(&unreg->buf_ref[i]);
2876 7 unreg->buf_ref[i] = NULL;
2877 }
2878 }
2879 9486 s->sei.unregistered.nb_buf_ref = 0;
2880
2881
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9484 times.
9486 if (s->sei.timecode.present) {
2882 uint32_t *tc_sd;
2883 char tcbuf[AV_TIMECODE_STR_SIZE];
2884 2 AVFrameSideData *tcside = av_frame_new_side_data(out, AV_FRAME_DATA_S12M_TIMECODE,
2885 sizeof(uint32_t) * 4);
2886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!tcside)
2887 return AVERROR(ENOMEM);
2888
2889 2 tc_sd = (uint32_t*)tcside->data;
2890 2 tc_sd[0] = s->sei.timecode.num_clock_ts;
2891
2892
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (int i = 0; i < tc_sd[0]; i++) {
2893 2 int drop = s->sei.timecode.cnt_dropped_flag[i];
2894 2 int hh = s->sei.timecode.hours_value[i];
2895 2 int mm = s->sei.timecode.minutes_value[i];
2896 2 int ss = s->sei.timecode.seconds_value[i];
2897 2 int ff = s->sei.timecode.n_frames[i];
2898
2899 2 tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff);
2900 2 av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0);
2901 2 av_dict_set(&out->metadata, "timecode", tcbuf, 0);
2902 }
2903
2904 2 s->sei.timecode.num_clock_ts = 0;
2905 }
2906
2907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
9486 if (s->sei.film_grain_characteristics.present) {
2908 HEVCSEIFilmGrainCharacteristics *fgc = &s->sei.film_grain_characteristics;
2909 AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(out);
2910 if (!fgp)
2911 return AVERROR(ENOMEM);
2912
2913 fgp->type = AV_FILM_GRAIN_PARAMS_H274;
2914 fgp->seed = s->ref->poc; /* no poc_offset in HEVC */
2915
2916 fgp->codec.h274.model_id = fgc->model_id;
2917 if (fgc->separate_colour_description_present_flag) {
2918 fgp->codec.h274.bit_depth_luma = fgc->bit_depth_luma;
2919 fgp->codec.h274.bit_depth_chroma = fgc->bit_depth_chroma;
2920 fgp->codec.h274.color_range = fgc->full_range + 1;
2921 fgp->codec.h274.color_primaries = fgc->color_primaries;
2922 fgp->codec.h274.color_trc = fgc->transfer_characteristics;
2923 fgp->codec.h274.color_space = fgc->matrix_coeffs;
2924 } else {
2925 const HEVCSPS *sps = s->ps.sps;
2926 const VUI *vui = &sps->vui;
2927 fgp->codec.h274.bit_depth_luma = sps->bit_depth;
2928 fgp->codec.h274.bit_depth_chroma = sps->bit_depth_chroma;
2929 if (vui->video_signal_type_present_flag)
2930 fgp->codec.h274.color_range = vui->video_full_range_flag + 1;
2931 else
2932 fgp->codec.h274.color_range = AVCOL_RANGE_UNSPECIFIED;
2933 if (vui->colour_description_present_flag) {
2934 fgp->codec.h274.color_primaries = vui->colour_primaries;
2935 fgp->codec.h274.color_trc = vui->transfer_characteristic;
2936 fgp->codec.h274.color_space = vui->matrix_coeffs;
2937 } else {
2938 fgp->codec.h274.color_primaries = AVCOL_PRI_UNSPECIFIED;
2939 fgp->codec.h274.color_trc = AVCOL_TRC_UNSPECIFIED;
2940 fgp->codec.h274.color_space = AVCOL_SPC_UNSPECIFIED;
2941 }
2942 }
2943 fgp->codec.h274.blending_mode_id = fgc->blending_mode_id;
2944 fgp->codec.h274.log2_scale_factor = fgc->log2_scale_factor;
2945
2946 memcpy(&fgp->codec.h274.component_model_present, &fgc->comp_model_present_flag,
2947 sizeof(fgp->codec.h274.component_model_present));
2948 memcpy(&fgp->codec.h274.num_intensity_intervals, &fgc->num_intensity_intervals,
2949 sizeof(fgp->codec.h274.num_intensity_intervals));
2950 memcpy(&fgp->codec.h274.num_model_values, &fgc->num_model_values,
2951 sizeof(fgp->codec.h274.num_model_values));
2952 memcpy(&fgp->codec.h274.intensity_interval_lower_bound, &fgc->intensity_interval_lower_bound,
2953 sizeof(fgp->codec.h274.intensity_interval_lower_bound));
2954 memcpy(&fgp->codec.h274.intensity_interval_upper_bound, &fgc->intensity_interval_upper_bound,
2955 sizeof(fgp->codec.h274.intensity_interval_upper_bound));
2956 memcpy(&fgp->codec.h274.comp_model_value, &fgc->comp_model_value,
2957 sizeof(fgp->codec.h274.comp_model_value));
2958
2959 fgc->present = fgc->persistence_flag;
2960 }
2961
2962
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9484 times.
9486 if (s->sei.dynamic_hdr_plus.info) {
2963 2 AVBufferRef *info_ref = av_buffer_ref(s->sei.dynamic_hdr_plus.info);
2964
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!info_ref)
2965 return AVERROR(ENOMEM);
2966
2967
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)) {
2968 av_buffer_unref(&info_ref);
2969 return AVERROR(ENOMEM);
2970 }
2971 }
2972
2973
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9484 times.
9486 if (s->rpu_buf) {
2974 2 AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf);
2975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!rpu)
2976 return AVERROR(ENOMEM);
2977
2978 2 s->rpu_buf = NULL;
2979 }
2980
2981
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9486 times.
9486 if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0)
2982 return ret;
2983
2984 9486 return 0;
2985 }
2986
2987 9486 static int hevc_frame_start(HEVCContext *s)
2988 {
2989 9486 HEVCLocalContext *lc = s->HEVClc;
2990 9486 int pic_size_in_ctb = ((s->ps.sps->width >> s->ps.sps->log2_min_cb_size) + 1) *
2991 9486 ((s->ps.sps->height >> s->ps.sps->log2_min_cb_size) + 1);
2992 int ret;
2993
2994 9486 memset(s->horizontal_bs, 0, s->bs_width * s->bs_height);
2995 9486 memset(s->vertical_bs, 0, s->bs_width * s->bs_height);
2996 9486 memset(s->cbf_luma, 0, s->ps.sps->min_tb_width * s->ps.sps->min_tb_height);
2997 9486 memset(s->is_pcm, 0, (s->ps.sps->min_pu_width + 1) * (s->ps.sps->min_pu_height + 1));
2998 9486 memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address));
2999
3000 9486 s->is_decoded = 0;
3001 9486 s->first_nal_type = s->nal_unit_type;
3002
3003
14/14
✓ Branch 0 taken 9127 times.
✓ Branch 1 taken 359 times.
✓ Branch 2 taken 9115 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 9113 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9106 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9105 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 155 times.
✓ Branch 11 taken 8950 times.
✓ Branch 12 taken 8 times.
✓ Branch 13 taken 147 times.
9486 s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos);
3004
3005
2/2
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 8862 times.
9486 if (s->ps.pps->tiles_enabled_flag)
3006 624 lc->end_of_tiles_x = s->ps.pps->column_width[0] << s->ps.sps->log2_ctb_size;
3007
3008 9486 ret = ff_hevc_set_new_ref(s, &s->frame, s->poc);
3009
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
9486 if (ret < 0)
3010 goto fail;
3011
3012 9486 ret = ff_hevc_frame_rps(s);
3013
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
9486 if (ret < 0) {
3014 av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n");
3015 goto fail;
3016 }
3017
3018
3/4
✓ Branch 0 taken 536 times.
✓ Branch 1 taken 8950 times.
✓ Branch 2 taken 536 times.
✗ Branch 3 not taken.
9486 s->ref->frame->key_frame = IS_IRAP(s);
3019
3020 18972 s->ref->needs_fg = s->sei.film_grain_characteristics.present &&
3021
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9486 !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
3022 !s->avctx->hwaccel;
3023
3024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
9486 if (s->ref->needs_fg) {
3025 s->ref->frame_grain->format = s->ref->frame->format;
3026 s->ref->frame_grain->width = s->ref->frame->width;
3027 s->ref->frame_grain->height = s->ref->frame->height;
3028 if ((ret = ff_thread_get_buffer(s->avctx, &s->ref->tf_grain, 0)) < 0)
3029 goto fail;
3030 }
3031
3032 9486 ret = set_side_data(s);
3033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
9486 if (ret < 0)
3034 goto fail;
3035
3036 9486 s->frame->pict_type = 3 - s->sh.slice_type;
3037
3038
3/4
✓ Branch 0 taken 536 times.
✓ Branch 1 taken 8950 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 536 times.
9486 if (!IS_IRAP(s))
3039 8950 ff_hevc_bump_frame(s);
3040
3041 9486 av_frame_unref(s->output_frame);
3042 9486 ret = ff_hevc_output_frame(s, s->output_frame, 0);
3043
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9486 times.
9486 if (ret < 0)
3044 goto fail;
3045
3046
1/2
✓ Branch 0 taken 9486 times.
✗ Branch 1 not taken.
9486 if (!s->avctx->hwaccel)
3047 9486 ff_thread_finish_setup(s->avctx);
3048
3049 9486 return 0;
3050
3051 fail:
3052 if (s->ref)
3053 ff_hevc_unref_frame(s, s->ref, ~0);
3054 s->ref = NULL;
3055 return ret;
3056 }
3057
3058 9485 static int hevc_frame_end(HEVCContext *s)
3059 {
3060 9485 HEVCFrame *out = s->ref;
3061 const AVFrameSideData *sd;
3062 int ret;
3063
3064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9485 times.
9485 if (out->needs_fg) {
3065 sd = av_frame_get_side_data(out->frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
3066 av_assert0(out->frame_grain->buf[0] && sd);
3067 ret = ff_h274_apply_film_grain(out->frame_grain, out->frame, &s->h274db,
3068 (AVFilmGrainParams *) sd->data);
3069
3070 if (ret < 0) {
3071 av_log(s->avctx, AV_LOG_WARNING, "Failed synthesizing film "
3072 "grain, ignoring: %s\n", av_err2str(ret));
3073 out->needs_fg = 0;
3074 }
3075 }
3076
3077 9485 return 0;
3078 }
3079
3080 37871 static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
3081 {
3082 37871 HEVCLocalContext *lc = s->HEVClc;
3083 37871 GetBitContext *gb = &lc->gb;
3084 int ctb_addr_ts, ret;
3085
3086 37871 *gb = nal->gb;
3087 37871 s->nal_unit_type = nal->type;
3088 37871 s->temporal_id = nal->temporal_id;
3089
3090
7/8
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 397 times.
✓ Branch 2 taken 1355 times.
✓ Branch 3 taken 7491 times.
✓ Branch 4 taken 27583 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 641 times.
✗ Branch 7 not taken.
37871 switch (s->nal_unit_type) {
3091 400 case HEVC_NAL_VPS:
3092
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) {
3093 ret = s->avctx->hwaccel->decode_params(s->avctx,
3094 nal->type,
3095 nal->raw_data,
3096 nal->raw_size);
3097 if (ret < 0)
3098 goto fail;
3099 }
3100 400 ret = ff_hevc_decode_nal_vps(gb, s->avctx, &s->ps);
3101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 400 times.
400 if (ret < 0)
3102 goto fail;
3103 400 break;
3104 397 case HEVC_NAL_SPS:
3105
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) {
3106 ret = s->avctx->hwaccel->decode_params(s->avctx,
3107 nal->type,
3108 nal->raw_data,
3109 nal->raw_size);
3110 if (ret < 0)
3111 goto fail;
3112 }
3113 397 ret = ff_hevc_decode_nal_sps(gb, s->avctx, &s->ps,
3114 s->apply_defdispwin);
3115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 397 times.
397 if (ret < 0)
3116 goto fail;
3117 397 break;
3118 1355 case HEVC_NAL_PPS:
3119
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) {
3120 ret = s->avctx->hwaccel->decode_params(s->avctx,
3121 nal->type,
3122 nal->raw_data,
3123 nal->raw_size);
3124 if (ret < 0)
3125 goto fail;
3126 }
3127 1355 ret = ff_hevc_decode_nal_pps(gb, s->avctx, &s->ps);
3128
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1353 times.
1355 if (ret < 0)
3129 2 goto fail;
3130 1353 break;
3131 7491 case HEVC_NAL_SEI_PREFIX:
3132 case HEVC_NAL_SEI_SUFFIX:
3133
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7491 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7491 if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) {
3134 ret = s->avctx->hwaccel->decode_params(s->avctx,
3135 nal->type,
3136 nal->raw_data,
3137 nal->raw_size);
3138 if (ret < 0)
3139