Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * HEVC video Decoder | ||
3 | * | ||
4 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
5 | * Copyright (C) 2012 - 2013 Mickael Raulet | ||
6 | * Copyright (C) 2012 - 2013 Gildas Cocherel | ||
7 | * Copyright (C) 2012 - 2013 Wassim Hamidouche | ||
8 | * | ||
9 | * This file is part of FFmpeg. | ||
10 | * | ||
11 | * FFmpeg is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU Lesser General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2.1 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * FFmpeg is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * Lesser General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Lesser General Public | ||
22 | * License along with FFmpeg; if not, write to the Free Software | ||
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
24 | */ | ||
25 | |||
26 | #include "config_components.h" | ||
27 | |||
28 | #include "libavutil/attributes.h" | ||
29 | #include "libavutil/avstring.h" | ||
30 | #include "libavutil/common.h" | ||
31 | #include "libavutil/film_grain_params.h" | ||
32 | #include "libavutil/internal.h" | ||
33 | #include "libavutil/md5.h" | ||
34 | #include "libavutil/mem.h" | ||
35 | #include "libavutil/opt.h" | ||
36 | #include "libavutil/pixdesc.h" | ||
37 | #include "libavutil/timecode.h" | ||
38 | |||
39 | #include "aom_film_grain.h" | ||
40 | #include "bswapdsp.h" | ||
41 | #include "cabac_functions.h" | ||
42 | #include "codec_internal.h" | ||
43 | #include "decode.h" | ||
44 | #include "golomb.h" | ||
45 | #include "hevc.h" | ||
46 | #include "hevc_parse.h" | ||
47 | #include "hevcdec.h" | ||
48 | #include "hwaccel_internal.h" | ||
49 | #include "hwconfig.h" | ||
50 | #include "internal.h" | ||
51 | #include "profiles.h" | ||
52 | #include "refstruct.h" | ||
53 | #include "thread.h" | ||
54 | #include "threadframe.h" | ||
55 | |||
56 | static const uint8_t hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, [12] = 4, [16] = 5, [24] = 6, [32] = 7, [48] = 8, [64] = 9 }; | ||
57 | |||
58 | /** | ||
59 | * NOTE: Each function hls_foo correspond to the function foo in the | ||
60 | * specification (HLS stands for High Level Syntax). | ||
61 | */ | ||
62 | |||
63 | /** | ||
64 | * Section 5.7 | ||
65 | */ | ||
66 | |||
67 | /* free everything allocated by pic_arrays_init() */ | ||
68 | 813 | static void pic_arrays_free(HEVCContext *s) | |
69 | { | ||
70 | 813 | av_freep(&s->sao); | |
71 | 813 | av_freep(&s->deblock); | |
72 | |||
73 | 813 | av_freep(&s->skip_flag); | |
74 | 813 | av_freep(&s->tab_ct_depth); | |
75 | |||
76 | 813 | av_freep(&s->tab_ipm); | |
77 | 813 | av_freep(&s->cbf_luma); | |
78 | 813 | av_freep(&s->is_pcm); | |
79 | |||
80 | 813 | av_freep(&s->qp_y_tab); | |
81 | 813 | av_freep(&s->tab_slice_address); | |
82 | 813 | av_freep(&s->filter_slice_edges); | |
83 | |||
84 | 813 | av_freep(&s->horizontal_bs); | |
85 | 813 | av_freep(&s->vertical_bs); | |
86 | |||
87 | 813 | av_freep(&s->sh.entry_point_offset); | |
88 | 813 | av_freep(&s->sh.size); | |
89 | 813 | av_freep(&s->sh.offset); | |
90 | |||
91 | 813 | ff_refstruct_pool_uninit(&s->tab_mvf_pool); | |
92 | 813 | ff_refstruct_pool_uninit(&s->rpl_tab_pool); | |
93 | 813 | } | |
94 | |||
95 | /* allocate arrays that depend on frame dimensions */ | ||
96 | 385 | static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps) | |
97 | { | ||
98 | 385 | int log2_min_cb_size = sps->log2_min_cb_size; | |
99 | 385 | int width = sps->width; | |
100 | 385 | int height = sps->height; | |
101 | 385 | int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) * | |
102 | 385 | ((height >> log2_min_cb_size) + 1); | |
103 | 385 | int ctb_count = sps->ctb_width * sps->ctb_height; | |
104 | 385 | int min_pu_size = sps->min_pu_width * sps->min_pu_height; | |
105 | |||
106 | 385 | s->bs_width = (width >> 2) + 1; | |
107 | 385 | s->bs_height = (height >> 2) + 1; | |
108 | |||
109 | 385 | s->sao = av_calloc(ctb_count, sizeof(*s->sao)); | |
110 | 385 | s->deblock = av_calloc(ctb_count, sizeof(*s->deblock)); | |
111 |
2/4✓ Branch 0 taken 385 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 385 times.
|
385 | if (!s->sao || !s->deblock) |
112 | ✗ | goto fail; | |
113 | |||
114 | 385 | s->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
115 | 385 | s->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
116 |
2/4✓ Branch 0 taken 385 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 385 times.
|
385 | if (!s->skip_flag || !s->tab_ct_depth) |
117 | ✗ | goto fail; | |
118 | |||
119 | 385 | s->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height); | |
120 | 385 | s->tab_ipm = av_mallocz(min_pu_size); | |
121 | 385 | s->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1); | |
122 |
3/6✓ Branch 0 taken 385 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 385 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 385 times.
|
385 | if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm) |
123 | ✗ | goto fail; | |
124 | |||
125 | 385 | s->filter_slice_edges = av_mallocz(ctb_count); | |
126 | 385 | s->tab_slice_address = av_malloc_array(pic_size_in_ctb, | |
127 | sizeof(*s->tab_slice_address)); | ||
128 | 385 | s->qp_y_tab = av_malloc_array(pic_size_in_ctb, | |
129 | sizeof(*s->qp_y_tab)); | ||
130 |
3/6✓ Branch 0 taken 385 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 385 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 385 times.
|
385 | if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address) |
131 | ✗ | goto fail; | |
132 | |||
133 | 385 | s->horizontal_bs = av_calloc(s->bs_width, s->bs_height); | |
134 | 385 | s->vertical_bs = av_calloc(s->bs_width, s->bs_height); | |
135 |
2/4✓ Branch 0 taken 385 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 385 times.
|
385 | if (!s->horizontal_bs || !s->vertical_bs) |
136 | ✗ | goto fail; | |
137 | |||
138 | 385 | s->tab_mvf_pool = ff_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0); | |
139 | 385 | s->rpl_tab_pool = ff_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0); | |
140 |
2/4✓ Branch 0 taken 385 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 385 times.
|
385 | if (!s->tab_mvf_pool || !s->rpl_tab_pool) |
141 | ✗ | goto fail; | |
142 | |||
143 | 385 | return 0; | |
144 | |||
145 | ✗ | fail: | |
146 | ✗ | pic_arrays_free(s); | |
147 | ✗ | return AVERROR(ENOMEM); | |
148 | } | ||
149 | |||
150 | 1443 | static int pred_weight_table(HEVCContext *s, GetBitContext *gb) | |
151 | { | ||
152 | 1443 | int i = 0; | |
153 | 1443 | int j = 0; | |
154 | uint8_t luma_weight_l0_flag[16]; | ||
155 | uint8_t chroma_weight_l0_flag[16]; | ||
156 | uint8_t luma_weight_l1_flag[16]; | ||
157 | uint8_t chroma_weight_l1_flag[16]; | ||
158 | int luma_log2_weight_denom; | ||
159 | |||
160 | 1443 | luma_log2_weight_denom = get_ue_golomb_long(gb); | |
161 |
2/4✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1443 times.
|
1443 | if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) { |
162 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom); | |
163 | ✗ | return AVERROR_INVALIDDATA; | |
164 | } | ||
165 | 1443 | s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3); | |
166 |
1/2✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
|
1443 | if (s->ps.sps->chroma_format_idc != 0) { |
167 | 1443 | int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb); | |
168 |
2/4✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1443 times.
|
1443 | if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) { |
169 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom); | |
170 | ✗ | return AVERROR_INVALIDDATA; | |
171 | } | ||
172 | 1443 | s->sh.chroma_log2_weight_denom = chroma_log2_weight_denom; | |
173 | } | ||
174 | |||
175 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < s->sh.nb_refs[L0]; i++) { |
176 | 4407 | luma_weight_l0_flag[i] = get_bits1(gb); | |
177 |
2/2✓ Branch 0 taken 1290 times.
✓ Branch 1 taken 3117 times.
|
4407 | if (!luma_weight_l0_flag[i]) { |
178 | 1290 | s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom; | |
179 | 1290 | s->sh.luma_offset_l0[i] = 0; | |
180 | } | ||
181 | } | ||
182 |
1/2✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
|
1443 | if (s->ps.sps->chroma_format_idc != 0) { |
183 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < s->sh.nb_refs[L0]; i++) |
184 | 4407 | chroma_weight_l0_flag[i] = get_bits1(gb); | |
185 | } else { | ||
186 | ✗ | for (i = 0; i < s->sh.nb_refs[L0]; i++) | |
187 | ✗ | chroma_weight_l0_flag[i] = 0; | |
188 | } | ||
189 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < s->sh.nb_refs[L0]; i++) { |
190 |
2/2✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1290 times.
|
4407 | if (luma_weight_l0_flag[i]) { |
191 | 3117 | int delta_luma_weight_l0 = get_se_golomb(gb); | |
192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
|
3117 | if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0) |
193 | ✗ | return AVERROR_INVALIDDATA; | |
194 | 3117 | s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l0; | |
195 | 3117 | s->sh.luma_offset_l0[i] = get_se_golomb(gb); | |
196 | } | ||
197 |
2/2✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3276 times.
|
4407 | if (chroma_weight_l0_flag[i]) { |
198 |
2/2✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
|
3393 | for (j = 0; j < 2; j++) { |
199 | 2262 | int delta_chroma_weight_l0 = get_se_golomb(gb); | |
200 | 2262 | int delta_chroma_offset_l0 = get_se_golomb(gb); | |
201 | |||
202 |
1/2✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
|
2262 | if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0 |
203 |
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)) { |
204 | ✗ | return AVERROR_INVALIDDATA; | |
205 | } | ||
206 | |||
207 | 2262 | s->sh.chroma_weight_l0[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0; | |
208 | 2262 | s->sh.chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * s->sh.chroma_weight_l0[i][j]) | |
209 | 2262 | >> s->sh.chroma_log2_weight_denom) + 128), -128, 127); | |
210 | } | ||
211 | } else { | ||
212 | 3276 | s->sh.chroma_weight_l0[i][0] = 1 << s->sh.chroma_log2_weight_denom; | |
213 | 3276 | s->sh.chroma_offset_l0[i][0] = 0; | |
214 | 3276 | s->sh.chroma_weight_l0[i][1] = 1 << s->sh.chroma_log2_weight_denom; | |
215 | 3276 | s->sh.chroma_offset_l0[i][1] = 0; | |
216 | } | ||
217 | } | ||
218 |
2/2✓ Branch 0 taken 668 times.
✓ Branch 1 taken 775 times.
|
1443 | if (s->sh.slice_type == HEVC_SLICE_B) { |
219 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < s->sh.nb_refs[L1]; i++) { |
220 | 1347 | luma_weight_l1_flag[i] = get_bits1(gb); | |
221 |
2/2✓ Branch 0 taken 601 times.
✓ Branch 1 taken 746 times.
|
1347 | if (!luma_weight_l1_flag[i]) { |
222 | 601 | s->sh.luma_weight_l1[i] = 1 << s->sh.luma_log2_weight_denom; | |
223 | 601 | s->sh.luma_offset_l1[i] = 0; | |
224 | } | ||
225 | } | ||
226 |
1/2✓ Branch 0 taken 668 times.
✗ Branch 1 not taken.
|
668 | if (s->ps.sps->chroma_format_idc != 0) { |
227 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < s->sh.nb_refs[L1]; i++) |
228 | 1347 | chroma_weight_l1_flag[i] = get_bits1(gb); | |
229 | } else { | ||
230 | ✗ | for (i = 0; i < s->sh.nb_refs[L1]; i++) | |
231 | ✗ | chroma_weight_l1_flag[i] = 0; | |
232 | } | ||
233 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < s->sh.nb_refs[L1]; i++) { |
234 |
2/2✓ Branch 0 taken 746 times.
✓ Branch 1 taken 601 times.
|
1347 | if (luma_weight_l1_flag[i]) { |
235 | 746 | int delta_luma_weight_l1 = get_se_golomb(gb); | |
236 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
|
746 | if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1) |
237 | ✗ | return AVERROR_INVALIDDATA; | |
238 | 746 | s->sh.luma_weight_l1[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l1; | |
239 | 746 | s->sh.luma_offset_l1[i] = get_se_golomb(gb); | |
240 | } | ||
241 |
2/2✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1111 times.
|
1347 | if (chroma_weight_l1_flag[i]) { |
242 |
2/2✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
|
708 | for (j = 0; j < 2; j++) { |
243 | 472 | int delta_chroma_weight_l1 = get_se_golomb(gb); | |
244 | 472 | int delta_chroma_offset_l1 = get_se_golomb(gb); | |
245 | |||
246 |
1/2✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
|
472 | if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1 |
247 |
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)) { |
248 | ✗ | return AVERROR_INVALIDDATA; | |
249 | } | ||
250 | |||
251 | 472 | s->sh.chroma_weight_l1[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1; | |
252 | 472 | s->sh.chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * s->sh.chroma_weight_l1[i][j]) | |
253 | 472 | >> s->sh.chroma_log2_weight_denom) + 128), -128, 127); | |
254 | } | ||
255 | } else { | ||
256 | 1111 | s->sh.chroma_weight_l1[i][0] = 1 << s->sh.chroma_log2_weight_denom; | |
257 | 1111 | s->sh.chroma_offset_l1[i][0] = 0; | |
258 | 1111 | s->sh.chroma_weight_l1[i][1] = 1 << s->sh.chroma_log2_weight_denom; | |
259 | 1111 | s->sh.chroma_offset_l1[i][1] = 0; | |
260 | } | ||
261 | } | ||
262 | } | ||
263 | 1443 | return 0; | |
264 | } | ||
265 | |||
266 | 19068 | static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb) | |
267 | { | ||
268 | 19068 | const HEVCSPS *sps = s->ps.sps; | |
269 | 19068 | int max_poc_lsb = 1 << sps->log2_max_poc_lsb; | |
270 | 19068 | int prev_delta_msb = 0; | |
271 | 19068 | unsigned int nb_sps = 0, nb_sh; | |
272 | int i; | ||
273 | |||
274 | 19068 | rps->nb_refs = 0; | |
275 |
2/2✓ Branch 0 taken 18033 times.
✓ Branch 1 taken 1035 times.
|
19068 | if (!sps->long_term_ref_pics_present_flag) |
276 | 18033 | return 0; | |
277 | |||
278 |
2/2✓ Branch 0 taken 499 times.
✓ Branch 1 taken 536 times.
|
1035 | if (sps->num_long_term_ref_pics_sps > 0) |
279 | 499 | nb_sps = get_ue_golomb_long(gb); | |
280 | 1035 | nb_sh = get_ue_golomb_long(gb); | |
281 | |||
282 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1035 times.
|
1035 | if (nb_sps > sps->num_long_term_ref_pics_sps) |
283 | ✗ | return AVERROR_INVALIDDATA; | |
284 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1035 times.
|
1035 | if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc)) |
285 | ✗ | return AVERROR_INVALIDDATA; | |
286 | |||
287 | 1035 | rps->nb_refs = nb_sh + nb_sps; | |
288 | |||
289 |
2/2✓ Branch 0 taken 1561 times.
✓ Branch 1 taken 1035 times.
|
2596 | for (i = 0; i < rps->nb_refs; i++) { |
290 | |||
291 |
2/2✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1377 times.
|
1561 | if (i < nb_sps) { |
292 | 184 | uint8_t lt_idx_sps = 0; | |
293 | |||
294 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (sps->num_long_term_ref_pics_sps > 1) |
295 | 184 | lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps)); | |
296 | |||
297 | 184 | rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps]; | |
298 | 184 | rps->used[i] = sps->used_by_curr_pic_lt_sps_flag[lt_idx_sps]; | |
299 | } else { | ||
300 | 1377 | rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb); | |
301 | 1377 | rps->used[i] = get_bits1(gb); | |
302 | } | ||
303 | |||
304 | 1561 | rps->poc_msb_present[i] = get_bits1(gb); | |
305 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1513 times.
|
1561 | if (rps->poc_msb_present[i]) { |
306 | 48 | int64_t delta = get_ue_golomb_long(gb); | |
307 | int64_t poc; | ||
308 | |||
309 |
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) |
310 | 31 | delta += prev_delta_msb; | |
311 | |||
312 | 48 | poc = rps->poc[i] + s->poc - delta * max_poc_lsb - s->sh.pic_order_cnt_lsb; | |
313 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (poc != (int32_t)poc) |
314 | ✗ | return AVERROR_INVALIDDATA; | |
315 | 48 | rps->poc[i] = poc; | |
316 | 48 | prev_delta_msb = delta; | |
317 | } | ||
318 | } | ||
319 | |||
320 | 1035 | return 0; | |
321 | } | ||
322 | |||
323 | 613 | static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) | |
324 | { | ||
325 | 613 | AVCodecContext *avctx = s->avctx; | |
326 | 613 | const HEVCParamSets *ps = &s->ps; | |
327 | 613 | const HEVCVPS *vps = ps->vps_list[sps->vps_id]; | |
328 | 613 | const HEVCWindow *ow = &sps->output_window; | |
329 | 613 | unsigned int num = 0, den = 0; | |
330 | |||
331 | 613 | avctx->pix_fmt = sps->pix_fmt; | |
332 | 613 | avctx->coded_width = sps->width; | |
333 | 613 | avctx->coded_height = sps->height; | |
334 | 613 | avctx->width = sps->width - ow->left_offset - ow->right_offset; | |
335 | 613 | avctx->height = sps->height - ow->top_offset - ow->bottom_offset; | |
336 | 613 | avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics; | |
337 | 613 | avctx->profile = sps->ptl.general_ptl.profile_idc; | |
338 | 613 | avctx->level = sps->ptl.general_ptl.level_idc; | |
339 | |||
340 | 613 | ff_set_sar(avctx, sps->vui.common.sar); | |
341 | |||
342 |
2/2✓ Branch 0 taken 45 times.
✓ Branch 1 taken 568 times.
|
613 | if (sps->vui.common.video_signal_type_present_flag) |
343 | 45 | avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG | |
344 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 38 times.
|
45 | : AVCOL_RANGE_MPEG; |
345 | else | ||
346 | 568 | avctx->color_range = AVCOL_RANGE_MPEG; | |
347 | |||
348 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 571 times.
|
613 | if (sps->vui.common.colour_description_present_flag) { |
349 | 42 | avctx->color_primaries = sps->vui.common.colour_primaries; | |
350 | 42 | avctx->color_trc = sps->vui.common.transfer_characteristics; | |
351 | 42 | avctx->colorspace = sps->vui.common.matrix_coeffs; | |
352 | } else { | ||
353 | 571 | avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; | |
354 | 571 | avctx->color_trc = AVCOL_TRC_UNSPECIFIED; | |
355 | 571 | avctx->colorspace = AVCOL_SPC_UNSPECIFIED; | |
356 | } | ||
357 | |||
358 | 613 | avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED; | |
359 |
2/2✓ Branch 0 taken 572 times.
✓ Branch 1 taken 41 times.
|
613 | if (sps->chroma_format_idc == 1) { |
360 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 557 times.
|
572 | if (sps->vui.common.chroma_loc_info_present_flag) { |
361 |
1/2✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
|
15 | if (sps->vui.common.chroma_sample_loc_type_top_field <= 5) |
362 | 15 | avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1; | |
363 | } else | ||
364 | 557 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; | |
365 | } | ||
366 | |||
367 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 590 times.
|
613 | if (vps->vps_timing_info_present_flag) { |
368 | 23 | num = vps->vps_num_units_in_tick; | |
369 | 23 | den = vps->vps_time_scale; | |
370 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 543 times.
|
590 | } else if (sps->vui.vui_timing_info_present_flag) { |
371 | 47 | num = sps->vui.vui_num_units_in_tick; | |
372 | 47 | den = sps->vui.vui_time_scale; | |
373 | } | ||
374 | |||
375 |
3/4✓ Branch 0 taken 70 times.
✓ Branch 1 taken 543 times.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
|
613 | if (num != 0 && den != 0) |
376 | 70 | av_reduce(&avctx->framerate.den, &avctx->framerate.num, | |
377 | num, den, 1 << 30); | ||
378 | 613 | } | |
379 | |||
380 | 27874 | static int export_stream_params_from_sei(HEVCContext *s) | |
381 | { | ||
382 | 27874 | AVCodecContext *avctx = s->avctx; | |
383 | |||
384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27874 times.
|
27874 | if (s->sei.common.a53_caption.buf_ref) |
385 | ✗ | s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; | |
386 | |||
387 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 27874 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
27874 | if (s->sei.common.alternative_transfer.present && |
388 | ✗ | av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) && | |
389 | ✗ | s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) { | |
390 | ✗ | avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics; | |
391 | } | ||
392 | |||
393 |
1/2✓ Branch 0 taken 27874 times.
✗ Branch 1 not taken.
|
27874 | if (s->sei.common.film_grain_characteristics.present || |
394 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27874 times.
|
27874 | s->sei.common.aom_film_grain.enable) |
395 | ✗ | avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; | |
396 | |||
397 | 27874 | return 0; | |
398 | } | ||
399 | |||
400 | 384 | static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) | |
401 | { | ||
402 | #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \ | ||
403 | CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \ | ||
404 | CONFIG_HEVC_D3D12VA_HWACCEL + \ | ||
405 | CONFIG_HEVC_NVDEC_HWACCEL + \ | ||
406 | CONFIG_HEVC_VAAPI_HWACCEL + \ | ||
407 | CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \ | ||
408 | CONFIG_HEVC_VDPAU_HWACCEL + \ | ||
409 | CONFIG_HEVC_VULKAN_HWACCEL) | ||
410 | 384 | enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts; | |
411 | |||
412 |
6/7✓ Branch 0 taken 323 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
|
384 | switch (sps->pix_fmt) { |
413 | 323 | case AV_PIX_FMT_YUV420P: | |
414 | case AV_PIX_FMT_YUVJ420P: | ||
415 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
416 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
417 | #endif | ||
418 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
419 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
420 | *fmt++ = AV_PIX_FMT_D3D11; | ||
421 | #endif | ||
422 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
423 | *fmt++ = AV_PIX_FMT_D3D12; | ||
424 | #endif | ||
425 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
426 | 323 | *fmt++ = AV_PIX_FMT_VAAPI; | |
427 | #endif | ||
428 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
429 | 323 | *fmt++ = AV_PIX_FMT_VDPAU; | |
430 | #endif | ||
431 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
432 | *fmt++ = AV_PIX_FMT_CUDA; | ||
433 | #endif | ||
434 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
435 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
436 | #endif | ||
437 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
438 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
439 | #endif | ||
440 | 323 | break; | |
441 | 33 | case AV_PIX_FMT_YUV420P10: | |
442 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
443 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
444 | #endif | ||
445 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
446 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
447 | *fmt++ = AV_PIX_FMT_D3D11; | ||
448 | #endif | ||
449 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
450 | *fmt++ = AV_PIX_FMT_D3D12; | ||
451 | #endif | ||
452 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
453 | 33 | *fmt++ = AV_PIX_FMT_VAAPI; | |
454 | #endif | ||
455 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
456 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
457 | #endif | ||
458 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
459 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
460 | #endif | ||
461 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
462 | 33 | *fmt++ = AV_PIX_FMT_VDPAU; | |
463 | #endif | ||
464 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
465 | *fmt++ = AV_PIX_FMT_CUDA; | ||
466 | #endif | ||
467 | 33 | break; | |
468 | 4 | case AV_PIX_FMT_YUV444P: | |
469 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
470 | 4 | *fmt++ = AV_PIX_FMT_VAAPI; | |
471 | #endif | ||
472 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
473 | 4 | *fmt++ = AV_PIX_FMT_VDPAU; | |
474 | #endif | ||
475 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
476 | *fmt++ = AV_PIX_FMT_CUDA; | ||
477 | #endif | ||
478 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
479 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
480 | #endif | ||
481 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
482 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
483 | #endif | ||
484 | 4 | break; | |
485 | 12 | case AV_PIX_FMT_YUV422P: | |
486 | case AV_PIX_FMT_YUV422P10LE: | ||
487 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
488 | 12 | *fmt++ = AV_PIX_FMT_VAAPI; | |
489 | #endif | ||
490 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
491 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
492 | #endif | ||
493 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
494 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
495 | #endif | ||
496 | 12 | break; | |
497 | 10 | case AV_PIX_FMT_YUV444P10: | |
498 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
499 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
500 | #endif | ||
501 | /* NOTE: fallthrough */ | ||
502 | case AV_PIX_FMT_YUV420P12: | ||
503 | case AV_PIX_FMT_YUV444P12: | ||
504 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
505 | 10 | *fmt++ = AV_PIX_FMT_VAAPI; | |
506 | #endif | ||
507 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
508 | 10 | *fmt++ = AV_PIX_FMT_VDPAU; | |
509 | #endif | ||
510 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
511 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
512 | #endif | ||
513 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
514 | *fmt++ = AV_PIX_FMT_CUDA; | ||
515 | #endif | ||
516 | 10 | break; | |
517 | ✗ | case AV_PIX_FMT_YUV422P12: | |
518 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
519 | ✗ | *fmt++ = AV_PIX_FMT_VAAPI; | |
520 | #endif | ||
521 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
522 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
523 | #endif | ||
524 | ✗ | break; | |
525 | } | ||
526 | |||
527 | 384 | *fmt++ = sps->pix_fmt; | |
528 | 384 | *fmt = AV_PIX_FMT_NONE; | |
529 | |||
530 | 384 | return ff_get_format(s->avctx, pix_fmts); | |
531 | } | ||
532 | |||
533 | 385 | static int set_sps(HEVCContext *s, const HEVCSPS *sps, | |
534 | enum AVPixelFormat pix_fmt) | ||
535 | { | ||
536 | int ret, i; | ||
537 | |||
538 | 385 | pic_arrays_free(s); | |
539 | 385 | s->ps.sps = NULL; | |
540 | 385 | s->ps.vps = NULL; | |
541 | |||
542 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 385 times.
|
385 | if (!sps) |
543 | ✗ | return 0; | |
544 | |||
545 | 385 | ret = pic_arrays_init(s, sps); | |
546 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 385 times.
|
385 | if (ret < 0) |
547 | ✗ | goto fail; | |
548 | |||
549 | 385 | export_stream_params(s, sps); | |
550 | |||
551 | 385 | s->avctx->pix_fmt = pix_fmt; | |
552 | |||
553 | 385 | ff_hevc_pred_init(&s->hpc, sps->bit_depth); | |
554 | 385 | ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); | |
555 | 385 | ff_videodsp_init (&s->vdsp, sps->bit_depth); | |
556 | |||
557 |
2/2✓ Branch 0 taken 1155 times.
✓ Branch 1 taken 385 times.
|
1540 | for (i = 0; i < 3; i++) { |
558 | 1155 | av_freep(&s->sao_pixel_buffer_h[i]); | |
559 | 1155 | av_freep(&s->sao_pixel_buffer_v[i]); | |
560 | } | ||
561 | |||
562 |
3/4✓ Branch 0 taken 330 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 330 times.
✗ Branch 3 not taken.
|
385 | if (sps->sao_enabled && !s->avctx->hwaccel) { |
563 |
2/2✓ Branch 0 taken 328 times.
✓ Branch 1 taken 2 times.
|
330 | int c_count = (sps->chroma_format_idc != 0) ? 3 : 1; |
564 | int c_idx; | ||
565 | |||
566 |
2/2✓ Branch 0 taken 986 times.
✓ Branch 1 taken 330 times.
|
1316 | for(c_idx = 0; c_idx < c_count; c_idx++) { |
567 | 986 | int w = sps->width >> sps->hshift[c_idx]; | |
568 | 986 | int h = sps->height >> sps->vshift[c_idx]; | |
569 | 986 | s->sao_pixel_buffer_h[c_idx] = | |
570 | 986 | av_malloc((w * 2 * sps->ctb_height) << | |
571 | 986 | sps->pixel_shift); | |
572 | 986 | s->sao_pixel_buffer_v[c_idx] = | |
573 | 986 | av_malloc((h * 2 * sps->ctb_width) << | |
574 | 986 | sps->pixel_shift); | |
575 |
1/2✓ Branch 0 taken 986 times.
✗ Branch 1 not taken.
|
986 | if (!s->sao_pixel_buffer_h[c_idx] || |
576 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 986 times.
|
986 | !s->sao_pixel_buffer_v[c_idx]) |
577 | ✗ | goto fail; | |
578 | } | ||
579 | } | ||
580 | |||
581 | 385 | s->ps.sps = sps; | |
582 | 385 | s->ps.vps = s->ps.vps_list[s->ps.sps->vps_id]; | |
583 | |||
584 | 385 | return 0; | |
585 | |||
586 | ✗ | fail: | |
587 | ✗ | pic_arrays_free(s); | |
588 | ✗ | for (i = 0; i < 3; i++) { | |
589 | ✗ | av_freep(&s->sao_pixel_buffer_h[i]); | |
590 | ✗ | av_freep(&s->sao_pixel_buffer_v[i]); | |
591 | } | ||
592 | ✗ | s->ps.sps = NULL; | |
593 | ✗ | return ret; | |
594 | } | ||
595 | |||
596 | 27646 | static int hls_slice_header(HEVCContext *s) | |
597 | { | ||
598 | 27646 | GetBitContext *gb = &s->HEVClc->gb; | |
599 | 27646 | SliceHeader *sh = &s->sh; | |
600 | int i, ret; | ||
601 | |||
602 | // Coded parameters | ||
603 | 27646 | sh->first_slice_in_pic_flag = get_bits1(gb); | |
604 |
4/4✓ Branch 0 taken 17990 times.
✓ Branch 1 taken 9656 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 17989 times.
|
27646 | if (s->ref && sh->first_slice_in_pic_flag) { |
605 | 1 | av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n"); | |
606 | 1 | return 1; // This slice will be skipped later, do not corrupt state | |
607 | } | ||
608 | |||
609 |
12/12✓ Branch 0 taken 26736 times.
✓ Branch 1 taken 909 times.
✓ Branch 2 taken 26720 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 26718 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 26711 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 26710 times.
✓ Branch 10 taken 391 times.
✓ Branch 11 taken 544 times.
|
27645 | if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) { |
610 | 391 | s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK; | |
611 | 391 | s->max_ra = INT_MAX; | |
612 |
4/4✓ Branch 0 taken 26 times.
✓ Branch 1 taken 365 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 10 times.
|
391 | if (IS_IDR(s)) |
613 | 381 | ff_hevc_clear_refs(s); | |
614 | } | ||
615 | 27645 | sh->no_output_of_prior_pics_flag = 0; | |
616 |
3/4✓ Branch 0 taken 1279 times.
✓ Branch 1 taken 26366 times.
✓ Branch 2 taken 1279 times.
✗ Branch 3 not taken.
|
27645 | if (IS_IRAP(s)) |
617 | 1279 | sh->no_output_of_prior_pics_flag = get_bits1(gb); | |
618 | |||
619 | 27645 | sh->pps_id = get_ue_golomb_long(gb); | |
620 |
3/4✓ Branch 0 taken 27645 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 27612 times.
|
27645 | if (sh->pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[sh->pps_id]) { |
621 | 33 | av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id); | |
622 | 33 | return AVERROR_INVALIDDATA; | |
623 | } | ||
624 |
2/2✓ Branch 0 taken 18031 times.
✓ Branch 1 taken 9581 times.
|
27612 | if (!sh->first_slice_in_pic_flag && |
625 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18031 times.
|
18031 | s->ps.pps != s->ps.pps_list[sh->pps_id]) { |
626 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); | |
627 | ✗ | return AVERROR_INVALIDDATA; | |
628 | } | ||
629 | 27612 | s->ps.pps = s->ps.pps_list[sh->pps_id]; | |
630 |
4/4✓ Branch 0 taken 344 times.
✓ Branch 1 taken 27268 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 330 times.
|
27612 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) |
631 | 14 | sh->no_output_of_prior_pics_flag = 1; | |
632 | |||
633 |
2/2✓ Branch 0 taken 384 times.
✓ Branch 1 taken 27228 times.
|
27612 | if (s->ps.sps != s->ps.sps_list[s->ps.pps->sps_id]) { |
634 | 384 | const HEVCSPS *sps = s->ps.sps_list[s->ps.pps->sps_id]; | |
635 | enum AVPixelFormat pix_fmt; | ||
636 | |||
637 | 384 | ff_hevc_clear_refs(s); | |
638 | |||
639 | 384 | ret = set_sps(s, sps, sps->pix_fmt); | |
640 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 384 times.
|
384 | if (ret < 0) |
641 | ✗ | return ret; | |
642 | |||
643 | 384 | pix_fmt = get_format(s, sps); | |
644 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 384 times.
|
384 | if (pix_fmt < 0) |
645 | ✗ | return pix_fmt; | |
646 | 384 | s->avctx->pix_fmt = pix_fmt; | |
647 | |||
648 | 384 | s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK; | |
649 | 384 | s->max_ra = INT_MAX; | |
650 | } | ||
651 | |||
652 | 27612 | ret = export_stream_params_from_sei(s); | |
653 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27612 times.
|
27612 | if (ret < 0) |
654 | ✗ | return ret; | |
655 | |||
656 | 27612 | sh->dependent_slice_segment_flag = 0; | |
657 |
2/2✓ Branch 0 taken 18031 times.
✓ Branch 1 taken 9581 times.
|
27612 | if (!sh->first_slice_in_pic_flag) { |
658 | int slice_address_length; | ||
659 | |||
660 |
2/2✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8939 times.
|
18031 | if (s->ps.pps->dependent_slice_segments_enabled_flag) |
661 | 9092 | sh->dependent_slice_segment_flag = get_bits1(gb); | |
662 | |||
663 | 18031 | slice_address_length = av_ceil_log2(s->ps.sps->ctb_width * | |
664 | 18031 | s->ps.sps->ctb_height); | |
665 | 18031 | sh->slice_segment_addr = get_bitsz(gb, slice_address_length); | |
666 |
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) { |
667 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
668 | "Invalid slice segment address: %u.\n", | ||
669 | sh->slice_segment_addr); | ||
670 | ✗ | return AVERROR_INVALIDDATA; | |
671 | } | ||
672 | |||
673 |
2/2✓ Branch 0 taken 10084 times.
✓ Branch 1 taken 7947 times.
|
18031 | if (!sh->dependent_slice_segment_flag) { |
674 | 10084 | sh->slice_addr = sh->slice_segment_addr; | |
675 | 10084 | s->slice_idx++; | |
676 | } | ||
677 | } else { | ||
678 | 9581 | sh->slice_segment_addr = sh->slice_addr = 0; | |
679 | 9581 | s->slice_idx = 0; | |
680 | 9581 | s->slice_initialized = 0; | |
681 | } | ||
682 | |||
683 |
2/2✓ Branch 0 taken 19665 times.
✓ Branch 1 taken 7947 times.
|
27612 | if (!sh->dependent_slice_segment_flag) { |
684 | 19665 | s->slice_initialized = 0; | |
685 | |||
686 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 19665 times.
|
19669 | for (i = 0; i < s->ps.pps->num_extra_slice_header_bits; i++) |
687 | 4 | skip_bits(gb, 1); // slice_reserved_undetermined_flag[] | |
688 | |||
689 | 19665 | sh->slice_type = get_ue_golomb_long(gb); | |
690 |
2/2✓ Branch 0 taken 18524 times.
✓ Branch 1 taken 1141 times.
|
19665 | if (!(sh->slice_type == HEVC_SLICE_I || |
691 |
2/2✓ Branch 0 taken 14772 times.
✓ Branch 1 taken 3752 times.
|
18524 | sh->slice_type == HEVC_SLICE_P || |
692 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14772 times.
|
14772 | sh->slice_type == HEVC_SLICE_B)) { |
693 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", | |
694 | ✗ | sh->slice_type); | |
695 | ✗ | return AVERROR_INVALIDDATA; | |
696 | } | ||
697 |
4/6✓ Branch 0 taken 890 times.
✓ Branch 1 taken 18775 times.
✓ Branch 2 taken 890 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 890 times.
|
19665 | if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I && |
698 | ✗ | !s->ps.pps->pps_curr_pic_ref_enabled_flag) { | |
699 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); | |
700 | ✗ | return AVERROR_INVALIDDATA; | |
701 | } | ||
702 | |||
703 | // when flag is not present, picture is inferred to be output | ||
704 | 19665 | sh->pic_output_flag = 1; | |
705 |
2/2✓ Branch 0 taken 703 times.
✓ Branch 1 taken 18962 times.
|
19665 | if (s->ps.pps->output_flag_present_flag) |
706 | 703 | sh->pic_output_flag = get_bits1(gb); | |
707 | |||
708 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19665 times.
|
19665 | if (s->ps.sps->separate_colour_plane_flag) |
709 | ✗ | sh->colour_plane_id = get_bits(gb, 2); | |
710 | |||
711 |
4/4✓ Branch 0 taken 19084 times.
✓ Branch 1 taken 581 times.
✓ Branch 2 taken 19068 times.
✓ Branch 3 taken 16 times.
|
38733 | if (!IS_IDR(s)) { |
712 | int poc, pos; | ||
713 | |||
714 | 19068 | sh->pic_order_cnt_lsb = get_bits(gb, s->ps.sps->log2_max_poc_lsb); | |
715 | 19068 | poc = ff_hevc_compute_poc(s->ps.sps, s->pocTid0, sh->pic_order_cnt_lsb, s->nal_unit_type); | |
716 |
3/4✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9200 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
|
19068 | if (!sh->first_slice_in_pic_flag && poc != s->poc) { |
717 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
718 | "Ignoring POC change between slices: %d -> %d\n", s->poc, poc); | ||
719 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
720 | ✗ | return AVERROR_INVALIDDATA; | |
721 | ✗ | poc = s->poc; | |
722 | } | ||
723 | 19068 | s->poc = poc; | |
724 | |||
725 | 19068 | sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); | |
726 | 19068 | pos = get_bits_left(gb); | |
727 |
2/2✓ Branch 0 taken 3254 times.
✓ Branch 1 taken 15814 times.
|
19068 | if (!sh->short_term_ref_pic_set_sps_flag) { |
728 | 3254 | ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, s->ps.sps, 1); | |
729 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3254 times.
|
3254 | if (ret < 0) |
730 | ✗ | return ret; | |
731 | |||
732 | 3254 | sh->short_term_rps = &sh->slice_rps; | |
733 | } else { | ||
734 | int numbits, rps_idx; | ||
735 | |||
736 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15814 times.
|
15814 | if (!s->ps.sps->nb_st_rps) { |
737 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); | |
738 | ✗ | return AVERROR_INVALIDDATA; | |
739 | } | ||
740 | |||
741 | 15814 | numbits = av_ceil_log2(s->ps.sps->nb_st_rps); | |
742 |
2/2✓ Branch 0 taken 15786 times.
✓ Branch 1 taken 28 times.
|
15814 | rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; |
743 | 15814 | sh->short_term_rps = &s->ps.sps->st_rps[rps_idx]; | |
744 | } | ||
745 | 19068 | sh->short_term_ref_pic_set_size = pos - get_bits_left(gb); | |
746 | |||
747 | 19068 | pos = get_bits_left(gb); | |
748 | 19068 | ret = decode_lt_rps(s, &sh->long_term_rps, gb); | |
749 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19068 times.
|
19068 | if (ret < 0) { |
750 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n"); | |
751 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
752 | ✗ | return AVERROR_INVALIDDATA; | |
753 | } | ||
754 | 19068 | sh->long_term_ref_pic_set_size = pos - get_bits_left(gb); | |
755 | |||
756 |
2/2✓ Branch 0 taken 16637 times.
✓ Branch 1 taken 2431 times.
|
19068 | if (s->ps.sps->sps_temporal_mvp_enabled_flag) |
757 | 16637 | sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); | |
758 | else | ||
759 | 2431 | sh->slice_temporal_mvp_enabled_flag = 0; | |
760 | } else { | ||
761 | 597 | s->poc = 0; | |
762 | 597 | sh->pic_order_cnt_lsb = 0; | |
763 | 597 | sh->short_term_ref_pic_set_sps_flag = 0; | |
764 | 597 | sh->short_term_ref_pic_set_size = 0; | |
765 | 597 | sh->short_term_rps = NULL; | |
766 | 597 | sh->long_term_ref_pic_set_size = 0; | |
767 | 597 | sh->slice_temporal_mvp_enabled_flag = 0; | |
768 | } | ||
769 | |||
770 | /* 8.3.1 */ | ||
771 |
4/4✓ Branch 0 taken 9581 times.
✓ Branch 1 taken 10084 times.
✓ Branch 2 taken 9237 times.
✓ Branch 3 taken 344 times.
|
19665 | if (sh->first_slice_in_pic_flag && s->temporal_id == 0 && |
772 |
2/2✓ Branch 0 taken 6760 times.
✓ Branch 1 taken 2477 times.
|
9237 | s->nal_unit_type != HEVC_NAL_TRAIL_N && |
773 |
1/2✓ Branch 0 taken 6760 times.
✗ Branch 1 not taken.
|
6760 | s->nal_unit_type != HEVC_NAL_TSA_N && |
774 |
1/2✓ Branch 0 taken 6760 times.
✗ Branch 1 not taken.
|
6760 | s->nal_unit_type != HEVC_NAL_STSA_N && |
775 |
2/2✓ Branch 0 taken 6738 times.
✓ Branch 1 taken 22 times.
|
6760 | s->nal_unit_type != HEVC_NAL_RADL_N && |
776 |
2/2✓ Branch 0 taken 6719 times.
✓ Branch 1 taken 19 times.
|
6738 | s->nal_unit_type != HEVC_NAL_RADL_R && |
777 |
2/2✓ Branch 0 taken 6360 times.
✓ Branch 1 taken 359 times.
|
6719 | s->nal_unit_type != HEVC_NAL_RASL_N && |
778 |
2/2✓ Branch 0 taken 5890 times.
✓ Branch 1 taken 470 times.
|
6360 | s->nal_unit_type != HEVC_NAL_RASL_R) |
779 | 5890 | s->pocTid0 = s->poc; | |
780 | |||
781 |
2/2✓ Branch 0 taken 16152 times.
✓ Branch 1 taken 3513 times.
|
19665 | if (s->ps.sps->sao_enabled) { |
782 | 16152 | sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); | |
783 |
2/2✓ Branch 0 taken 16150 times.
✓ Branch 1 taken 2 times.
|
16152 | if (s->ps.sps->chroma_format_idc) { |
784 | 16150 | sh->slice_sample_adaptive_offset_flag[1] = | |
785 | 16150 | sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); | |
786 | } | ||
787 | } else { | ||
788 | 3513 | sh->slice_sample_adaptive_offset_flag[0] = 0; | |
789 | 3513 | sh->slice_sample_adaptive_offset_flag[1] = 0; | |
790 | 3513 | sh->slice_sample_adaptive_offset_flag[2] = 0; | |
791 | } | ||
792 | |||
793 | 19665 | sh->nb_refs[L0] = sh->nb_refs[L1] = 0; | |
794 |
4/4✓ Branch 0 taken 15913 times.
✓ Branch 1 taken 3752 times.
✓ Branch 2 taken 14772 times.
✓ Branch 3 taken 1141 times.
|
19665 | if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) { |
795 | int nb_refs; | ||
796 | |||
797 | 18524 | sh->nb_refs[L0] = s->ps.pps->num_ref_idx_l0_default_active; | |
798 |
2/2✓ Branch 0 taken 14772 times.
✓ Branch 1 taken 3752 times.
|
18524 | if (sh->slice_type == HEVC_SLICE_B) |
799 | 14772 | sh->nb_refs[L1] = s->ps.pps->num_ref_idx_l1_default_active; | |
800 | |||
801 |
2/2✓ Branch 1 taken 4877 times.
✓ Branch 2 taken 13647 times.
|
18524 | if (get_bits1(gb)) { // num_ref_idx_active_override_flag |
802 | 4877 | sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1; | |
803 |
2/2✓ Branch 0 taken 2711 times.
✓ Branch 1 taken 2166 times.
|
4877 | if (sh->slice_type == HEVC_SLICE_B) |
804 | 2711 | sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1; | |
805 | } | ||
806 |
2/4✓ Branch 0 taken 18524 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18524 times.
|
18524 | if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) { |
807 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n", | |
808 | sh->nb_refs[L0], sh->nb_refs[L1]); | ||
809 | ✗ | return AVERROR_INVALIDDATA; | |
810 | } | ||
811 | |||
812 | 18524 | sh->rpl_modification_flag[0] = 0; | |
813 | 18524 | sh->rpl_modification_flag[1] = 0; | |
814 | 18524 | nb_refs = ff_hevc_frame_nb_refs(s); | |
815 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18524 times.
|
18524 | if (!nb_refs) { |
816 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); | |
817 | ✗ | return AVERROR_INVALIDDATA; | |
818 | } | ||
819 | |||
820 |
4/4✓ Branch 0 taken 1653 times.
✓ Branch 1 taken 16871 times.
✓ Branch 2 taken 1596 times.
✓ Branch 3 taken 57 times.
|
18524 | if (s->ps.pps->lists_modification_present_flag && nb_refs > 1) { |
821 | 1596 | sh->rpl_modification_flag[0] = get_bits1(gb); | |
822 |
2/2✓ Branch 0 taken 1176 times.
✓ Branch 1 taken 420 times.
|
1596 | if (sh->rpl_modification_flag[0]) { |
823 |
2/2✓ Branch 0 taken 2779 times.
✓ Branch 1 taken 1176 times.
|
3955 | for (i = 0; i < sh->nb_refs[L0]; i++) |
824 | 2779 | sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
825 | } | ||
826 | |||
827 |
1/2✓ Branch 0 taken 1596 times.
✗ Branch 1 not taken.
|
1596 | if (sh->slice_type == HEVC_SLICE_B) { |
828 | 1596 | sh->rpl_modification_flag[1] = get_bits1(gb); | |
829 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 944 times.
|
1596 | if (sh->rpl_modification_flag[1] == 1) |
830 |
2/2✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
|
2207 | for (i = 0; i < sh->nb_refs[L1]; i++) |
831 | 1555 | sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
832 | } | ||
833 | } | ||
834 | |||
835 |
2/2✓ Branch 0 taken 14772 times.
✓ Branch 1 taken 3752 times.
|
18524 | if (sh->slice_type == HEVC_SLICE_B) |
836 | 14772 | sh->mvd_l1_zero_flag = get_bits1(gb); | |
837 | |||
838 |
2/2✓ Branch 0 taken 15795 times.
✓ Branch 1 taken 2729 times.
|
18524 | if (s->ps.pps->cabac_init_present_flag) |
839 | 15795 | sh->cabac_init_flag = get_bits1(gb); | |
840 | else | ||
841 | 2729 | sh->cabac_init_flag = 0; | |
842 | |||
843 | 18524 | sh->collocated_ref_idx = 0; | |
844 |
2/2✓ Branch 0 taken 16167 times.
✓ Branch 1 taken 2357 times.
|
18524 | if (sh->slice_temporal_mvp_enabled_flag) { |
845 | 16167 | sh->collocated_list = L0; | |
846 |
2/2✓ Branch 0 taken 14255 times.
✓ Branch 1 taken 1912 times.
|
16167 | if (sh->slice_type == HEVC_SLICE_B) |
847 | 14255 | sh->collocated_list = !get_bits1(gb); | |
848 | |||
849 |
2/2✓ Branch 0 taken 14404 times.
✓ Branch 1 taken 1763 times.
|
16167 | if (sh->nb_refs[sh->collocated_list] > 1) { |
850 | 14404 | sh->collocated_ref_idx = get_ue_golomb_long(gb); | |
851 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14404 times.
|
14404 | if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { |
852 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
853 | "Invalid collocated_ref_idx: %d.\n", | ||
854 | sh->collocated_ref_idx); | ||
855 | ✗ | return AVERROR_INVALIDDATA; | |
856 | } | ||
857 | } | ||
858 | } | ||
859 | |||
860 |
4/4✓ Branch 0 taken 1468 times.
✓ Branch 1 taken 17056 times.
✓ Branch 2 taken 693 times.
✓ Branch 3 taken 775 times.
|
18524 | if ((s->ps.pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) || |
861 |
3/4✓ Branch 0 taken 668 times.
✓ Branch 1 taken 17081 times.
✓ Branch 2 taken 668 times.
✗ Branch 3 not taken.
|
17749 | (s->ps.pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) { |
862 | 1443 | int ret = pred_weight_table(s, gb); | |
863 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1443 times.
|
1443 | if (ret < 0) |
864 | ✗ | return ret; | |
865 | } | ||
866 | |||
867 | 18524 | sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb); | |
868 |
2/4✓ Branch 0 taken 18524 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18524 times.
|
18524 | if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) { |
869 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
870 | "Invalid number of merging MVP candidates: %d.\n", | ||
871 | ✗ | sh->max_num_merge_cand); | |
872 | ✗ | return AVERROR_INVALIDDATA; | |
873 | } | ||
874 | |||
875 | // Syntax in 7.3.6.1 | ||
876 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18524 times.
|
18524 | if (s->ps.sps->motion_vector_resolution_control_idc == 2) |
877 | ✗ | sh->use_integer_mv_flag = get_bits1(gb); | |
878 | else | ||
879 | // Inferred to be equal to motion_vector_resolution_control_idc if not present | ||
880 | 18524 | sh->use_integer_mv_flag = s->ps.sps->motion_vector_resolution_control_idc; | |
881 | |||
882 | } | ||
883 | |||
884 | 19665 | sh->slice_qp_delta = get_se_golomb(gb); | |
885 | |||
886 |
2/2✓ Branch 0 taken 271 times.
✓ Branch 1 taken 19394 times.
|
19665 | if (s->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag) { |
887 | 271 | sh->slice_cb_qp_offset = get_se_golomb(gb); | |
888 | 271 | sh->slice_cr_qp_offset = get_se_golomb(gb); | |
889 |
2/4✓ Branch 0 taken 271 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 271 times.
✗ Branch 3 not taken.
|
271 | if (sh->slice_cb_qp_offset < -12 || sh->slice_cb_qp_offset > 12 || |
890 |
2/4✓ Branch 0 taken 271 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 271 times.
|
271 | sh->slice_cr_qp_offset < -12 || sh->slice_cr_qp_offset > 12) { |
891 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n"); | |
892 | ✗ | return AVERROR_INVALIDDATA; | |
893 | } | ||
894 | } else { | ||
895 | 19394 | sh->slice_cb_qp_offset = 0; | |
896 | 19394 | sh->slice_cr_qp_offset = 0; | |
897 | } | ||
898 | |||
899 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19665 times.
|
19665 | if (s->ps.pps->pps_slice_act_qp_offsets_present_flag) { |
900 | ✗ | sh->slice_act_y_qp_offset = get_se_golomb(gb); | |
901 | ✗ | sh->slice_act_cb_qp_offset = get_se_golomb(gb); | |
902 | ✗ | sh->slice_act_cr_qp_offset = get_se_golomb(gb); | |
903 | } | ||
904 | |||
905 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 19622 times.
|
19665 | if (s->ps.pps->chroma_qp_offset_list_enabled_flag) |
906 | 43 | sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb); | |
907 | else | ||
908 | 19622 | sh->cu_chroma_qp_offset_enabled_flag = 0; | |
909 | |||
910 |
2/2✓ Branch 0 taken 2921 times.
✓ Branch 1 taken 16744 times.
|
19665 | if (s->ps.pps->deblocking_filter_control_present_flag) { |
911 | 2921 | int deblocking_filter_override_flag = 0; | |
912 | |||
913 |
2/2✓ Branch 0 taken 695 times.
✓ Branch 1 taken 2226 times.
|
2921 | if (s->ps.pps->deblocking_filter_override_enabled_flag) |
914 | 695 | deblocking_filter_override_flag = get_bits1(gb); | |
915 | |||
916 |
2/2✓ Branch 0 taken 476 times.
✓ Branch 1 taken 2445 times.
|
2921 | if (deblocking_filter_override_flag) { |
917 | 476 | sh->disable_deblocking_filter_flag = get_bits1(gb); | |
918 |
2/2✓ Branch 0 taken 356 times.
✓ Branch 1 taken 120 times.
|
476 | if (!sh->disable_deblocking_filter_flag) { |
919 | 356 | int beta_offset_div2 = get_se_golomb(gb); | |
920 | 356 | int tc_offset_div2 = get_se_golomb(gb) ; | |
921 |
3/6✓ Branch 0 taken 356 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 356 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 356 times.
✗ Branch 5 not taken.
|
356 | if (beta_offset_div2 < -6 || beta_offset_div2 > 6 || |
922 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 356 times.
|
356 | tc_offset_div2 < -6 || tc_offset_div2 > 6) { |
923 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
924 | "Invalid deblock filter offsets: %d, %d\n", | ||
925 | beta_offset_div2, tc_offset_div2); | ||
926 | ✗ | return AVERROR_INVALIDDATA; | |
927 | } | ||
928 | 356 | sh->beta_offset = beta_offset_div2 * 2; | |
929 | 356 | sh->tc_offset = tc_offset_div2 * 2; | |
930 | } | ||
931 | } else { | ||
932 | 2445 | sh->disable_deblocking_filter_flag = s->ps.pps->disable_dbf; | |
933 | 2445 | sh->beta_offset = s->ps.pps->beta_offset; | |
934 | 2445 | sh->tc_offset = s->ps.pps->tc_offset; | |
935 | } | ||
936 | } else { | ||
937 | 16744 | sh->disable_deblocking_filter_flag = 0; | |
938 | 16744 | sh->beta_offset = 0; | |
939 | 16744 | sh->tc_offset = 0; | |
940 | } | ||
941 | |||
942 |
2/2✓ Branch 0 taken 17130 times.
✓ Branch 1 taken 2535 times.
|
19665 | if (s->ps.pps->seq_loop_filter_across_slices_enabled_flag && |
943 |
2/2✓ Branch 0 taken 11467 times.
✓ Branch 1 taken 5663 times.
|
17130 | (sh->slice_sample_adaptive_offset_flag[0] || |
944 |
2/2✓ Branch 0 taken 11449 times.
✓ Branch 1 taken 18 times.
|
11467 | sh->slice_sample_adaptive_offset_flag[1] || |
945 |
2/2✓ Branch 0 taken 11386 times.
✓ Branch 1 taken 63 times.
|
11449 | !sh->disable_deblocking_filter_flag)) { |
946 | 17067 | sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); | |
947 | } else { | ||
948 | 2598 | sh->slice_loop_filter_across_slices_enabled_flag = s->ps.pps->seq_loop_filter_across_slices_enabled_flag; | |
949 | } | ||
950 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
|
7947 | } else if (!s->slice_initialized) { |
951 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); | |
952 | ✗ | return AVERROR_INVALIDDATA; | |
953 | } | ||
954 | |||
955 | 27612 | sh->num_entry_point_offsets = 0; | |
956 |
4/4✓ Branch 0 taken 24705 times.
✓ Branch 1 taken 2907 times.
✓ Branch 2 taken 4604 times.
✓ Branch 3 taken 20101 times.
|
27612 | if (s->ps.pps->tiles_enabled_flag || s->ps.pps->entropy_coding_sync_enabled_flag) { |
957 | 7511 | unsigned num_entry_point_offsets = get_ue_golomb_long(gb); | |
958 | // It would be possible to bound this tighter but this here is simpler | ||
959 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7511 times.
|
7511 | if (num_entry_point_offsets > get_bits_left(gb)) { |
960 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets); | |
961 | ✗ | return AVERROR_INVALIDDATA; | |
962 | } | ||
963 | |||
964 | 7511 | sh->num_entry_point_offsets = num_entry_point_offsets; | |
965 |
2/2✓ Branch 0 taken 2041 times.
✓ Branch 1 taken 5470 times.
|
7511 | if (sh->num_entry_point_offsets > 0) { |
966 | 2041 | int offset_len = get_ue_golomb_long(gb) + 1; | |
967 | |||
968 |
2/4✓ Branch 0 taken 2041 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2041 times.
|
2041 | if (offset_len < 1 || offset_len > 32) { |
969 | ✗ | sh->num_entry_point_offsets = 0; | |
970 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len); | |
971 | ✗ | return AVERROR_INVALIDDATA; | |
972 | } | ||
973 | |||
974 | 2041 | av_freep(&sh->entry_point_offset); | |
975 | 2041 | av_freep(&sh->offset); | |
976 | 2041 | av_freep(&sh->size); | |
977 | 2041 | sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned)); | |
978 | 2041 | sh->offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); | |
979 | 2041 | sh->size = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); | |
980 |
3/6✓ Branch 0 taken 2041 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2041 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2041 times.
|
2041 | if (!sh->entry_point_offset || !sh->offset || !sh->size) { |
981 | ✗ | sh->num_entry_point_offsets = 0; | |
982 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n"); | |
983 | ✗ | return AVERROR(ENOMEM); | |
984 | } | ||
985 |
2/2✓ Branch 0 taken 8040 times.
✓ Branch 1 taken 2041 times.
|
10081 | for (i = 0; i < sh->num_entry_point_offsets; i++) { |
986 | 8040 | unsigned val = get_bits_long(gb, offset_len); | |
987 | 8040 | sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size | |
988 | } | ||
989 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 2041 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2041 | if (s->threads_number > 1 && (s->ps.pps->num_tile_rows > 1 || s->ps.pps->num_tile_columns > 1)) { |
990 | ✗ | s->enable_parallel_tiles = 0; // TODO: you can enable tiles in parallel here | |
991 | ✗ | s->threads_number = 1; | |
992 | } else | ||
993 | 2041 | s->enable_parallel_tiles = 0; | |
994 | } else | ||
995 | 5470 | s->enable_parallel_tiles = 0; | |
996 | } | ||
997 | |||
998 |
2/2✓ Branch 0 taken 2769 times.
✓ Branch 1 taken 24843 times.
|
27612 | if (s->ps.pps->slice_header_extension_present_flag) { |
999 | 2769 | unsigned int length = get_ue_golomb_long(gb); | |
1000 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2769 times.
|
2769 | if (length*8LL > get_bits_left(gb)) { |
1001 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n"); | |
1002 | ✗ | return AVERROR_INVALIDDATA; | |
1003 | } | ||
1004 |
2/2✓ Branch 0 taken 20292 times.
✓ Branch 1 taken 2769 times.
|
23061 | for (i = 0; i < length; i++) |
1005 | 20292 | skip_bits(gb, 8); // slice_header_extension_data_byte | |
1006 | } | ||
1007 | |||
1008 | // Inferred parameters | ||
1009 | 27612 | sh->slice_qp = 26U + s->ps.pps->pic_init_qp_minus26 + sh->slice_qp_delta; | |
1010 |
1/2✓ Branch 0 taken 27612 times.
✗ Branch 1 not taken.
|
27612 | if (sh->slice_qp > 51 || |
1011 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27612 times.
|
27612 | sh->slice_qp < -s->ps.sps->qp_bd_offset) { |
1012 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1013 | "The slice_qp %d is outside the valid range " | ||
1014 | "[%d, 51].\n", | ||
1015 | ✗ | sh->slice_qp, | |
1016 | ✗ | -s->ps.sps->qp_bd_offset); | |
1017 | ✗ | return AVERROR_INVALIDDATA; | |
1018 | } | ||
1019 | |||
1020 | 27612 | sh->slice_ctb_addr_rs = sh->slice_segment_addr; | |
1021 | |||
1022 |
3/4✓ Branch 0 taken 9581 times.
✓ Branch 1 taken 18031 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9581 times.
|
27612 | if (!s->sh.slice_ctb_addr_rs && s->sh.dependent_slice_segment_flag) { |
1023 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n"); | |
1024 | ✗ | return AVERROR_INVALIDDATA; | |
1025 | } | ||
1026 | |||
1027 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 27612 times.
|
27612 | if (get_bits_left(gb) < 0) { |
1028 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1029 | ✗ | "Overread slice header by %d bits\n", -get_bits_left(gb)); | |
1030 | ✗ | return AVERROR_INVALIDDATA; | |
1031 | } | ||
1032 | |||
1033 | 27612 | s->HEVClc->first_qp_group = !s->sh.dependent_slice_segment_flag; | |
1034 | |||
1035 |
2/2✓ Branch 0 taken 22566 times.
✓ Branch 1 taken 5046 times.
|
27612 | if (!s->ps.pps->cu_qp_delta_enabled_flag) |
1036 | 22566 | s->HEVClc->qp_y = s->sh.slice_qp; | |
1037 | |||
1038 | 27612 | s->slice_initialized = 1; | |
1039 | 27612 | s->HEVClc->tu.cu_qp_offset_cb = 0; | |
1040 | 27612 | s->HEVClc->tu.cu_qp_offset_cr = 0; | |
1041 | |||
1042 | 27612 | return 0; | |
1043 | } | ||
1044 | |||
1045 | #define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)]) | ||
1046 | |||
1047 | #define SET_SAO(elem, value) \ | ||
1048 | do { \ | ||
1049 | if (!sao_merge_up_flag && !sao_merge_left_flag) \ | ||
1050 | sao->elem = value; \ | ||
1051 | else if (sao_merge_left_flag) \ | ||
1052 | sao->elem = CTB(s->sao, rx-1, ry).elem; \ | ||
1053 | else if (sao_merge_up_flag) \ | ||
1054 | sao->elem = CTB(s->sao, rx, ry-1).elem; \ | ||
1055 | else \ | ||
1056 | sao->elem = 0; \ | ||
1057 | } while (0) | ||
1058 | |||
1059 | 1415196 | static void hls_sao_param(HEVCLocalContext *lc, int rx, int ry) | |
1060 | { | ||
1061 | 1415196 | const HEVCContext *const s = lc->parent; | |
1062 | 1415196 | int sao_merge_left_flag = 0; | |
1063 | 1415196 | int sao_merge_up_flag = 0; | |
1064 | 1415196 | SAOParams *sao = &CTB(s->sao, rx, ry); | |
1065 | int c_idx, i; | ||
1066 | |||
1067 |
2/2✓ Branch 0 taken 816170 times.
✓ Branch 1 taken 599026 times.
|
1415196 | if (s->sh.slice_sample_adaptive_offset_flag[0] || |
1068 |
2/2✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 814526 times.
|
816170 | s->sh.slice_sample_adaptive_offset_flag[1]) { |
1069 |
2/2✓ Branch 0 taken 569600 times.
✓ Branch 1 taken 31070 times.
|
600670 | if (rx > 0) { |
1070 |
2/2✓ Branch 0 taken 561111 times.
✓ Branch 1 taken 8489 times.
|
569600 | if (lc->ctb_left_flag) |
1071 | 561111 | sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc); | |
1072 | } | ||
1073 |
4/4✓ Branch 0 taken 550037 times.
✓ Branch 1 taken 50633 times.
✓ Branch 2 taken 270263 times.
✓ Branch 3 taken 279774 times.
|
600670 | if (ry > 0 && !sao_merge_left_flag) { |
1074 |
2/2✓ Branch 0 taken 256915 times.
✓ Branch 1 taken 13348 times.
|
270263 | if (lc->ctb_up_flag) |
1075 | 256915 | sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc); | |
1076 | } | ||
1077 | } | ||
1078 | |||
1079 |
4/4✓ Branch 0 taken 5660592 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4245492 times.
✓ Branch 3 taken 1415196 times.
|
5660688 | for (c_idx = 0; c_idx < (s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) { |
1080 |
2/2✓ Branch 0 taken 1415196 times.
✓ Branch 1 taken 2830296 times.
|
4245492 | int log2_sao_offset_scale = c_idx == 0 ? s->ps.pps->log2_sao_offset_scale_luma : |
1081 | 2830296 | s->ps.pps->log2_sao_offset_scale_chroma; | |
1082 | |||
1083 |
2/2✓ Branch 0 taken 2945486 times.
✓ Branch 1 taken 1300006 times.
|
4245492 | if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) { |
1084 | 2945486 | sao->type_idx[c_idx] = SAO_NOT_APPLIED; | |
1085 | 2945486 | continue; | |
1086 | } | ||
1087 | |||
1088 |
2/2✓ Branch 0 taken 350490 times.
✓ Branch 1 taken 949516 times.
|
1300006 | if (c_idx == 2) { |
1089 | 350490 | sao->type_idx[2] = sao->type_idx[1]; | |
1090 | 350490 | sao->eo_class[2] = sao->eo_class[1]; | |
1091 | } else { | ||
1092 |
7/8✓ Branch 0 taken 825297 times.
✓ Branch 1 taken 124219 times.
✓ Branch 2 taken 375747 times.
✓ Branch 3 taken 449550 times.
✓ Branch 5 taken 449550 times.
✓ Branch 6 taken 124219 times.
✓ Branch 7 taken 124219 times.
✗ Branch 8 not taken.
|
949516 | SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc)); |
1093 | } | ||
1094 | |||
1095 |
2/2✓ Branch 0 taken 801455 times.
✓ Branch 1 taken 498551 times.
|
1300006 | if (sao->type_idx[c_idx] == SAO_NOT_APPLIED) |
1096 | 801455 | continue; | |
1097 | |||
1098 |
2/2✓ Branch 0 taken 1994204 times.
✓ Branch 1 taken 498551 times.
|
2492755 | for (i = 0; i < 4; i++) |
1099 |
7/8✓ Branch 0 taken 1645688 times.
✓ Branch 1 taken 348516 times.
✓ Branch 2 taken 871288 times.
✓ Branch 3 taken 774400 times.
✓ Branch 5 taken 774400 times.
✓ Branch 6 taken 348516 times.
✓ Branch 7 taken 348516 times.
✗ Branch 8 not taken.
|
1994204 | SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc)); |
1100 | |||
1101 |
2/2✓ Branch 0 taken 116806 times.
✓ Branch 1 taken 381745 times.
|
498551 | if (sao->type_idx[c_idx] == SAO_BAND) { |
1102 |
2/2✓ Branch 0 taken 467224 times.
✓ Branch 1 taken 116806 times.
|
584030 | for (i = 0; i < 4; i++) { |
1103 |
2/2✓ Branch 0 taken 351900 times.
✓ Branch 1 taken 115324 times.
|
467224 | if (sao->offset_abs[c_idx][i]) { |
1104 |
7/8✓ Branch 0 taken 327846 times.
✓ Branch 1 taken 24054 times.
✓ Branch 2 taken 243186 times.
✓ Branch 3 taken 84660 times.
✓ Branch 5 taken 84660 times.
✓ Branch 6 taken 24054 times.
✓ Branch 7 taken 24054 times.
✗ Branch 8 not taken.
|
351900 | SET_SAO(offset_sign[c_idx][i], |
1105 | ff_hevc_sao_offset_sign_decode(lc)); | ||
1106 | } else { | ||
1107 | 115324 | sao->offset_sign[c_idx][i] = 0; | |
1108 | } | ||
1109 | } | ||
1110 |
7/8✓ Branch 0 taken 107116 times.
✓ Branch 1 taken 9690 times.
✓ Branch 2 taken 77972 times.
✓ Branch 3 taken 29144 times.
✓ Branch 5 taken 29144 times.
✓ Branch 6 taken 9690 times.
✓ Branch 7 taken 9690 times.
✗ Branch 8 not taken.
|
116806 | SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc)); |
1111 |
2/2✓ Branch 0 taken 305303 times.
✓ Branch 1 taken 76442 times.
|
381745 | } else if (c_idx != 2) { |
1112 |
7/8✓ Branch 0 taken 243281 times.
✓ Branch 1 taken 62022 times.
✓ Branch 2 taken 108856 times.
✓ Branch 3 taken 134425 times.
✓ Branch 5 taken 134425 times.
✓ Branch 6 taken 62022 times.
✓ Branch 7 taken 62022 times.
✗ Branch 8 not taken.
|
305303 | SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc)); |
1113 | } | ||
1114 | |||
1115 | // Inferred parameters | ||
1116 | 498551 | sao->offset_val[c_idx][0] = 0; | |
1117 |
2/2✓ Branch 0 taken 1994204 times.
✓ Branch 1 taken 498551 times.
|
2492755 | for (i = 0; i < 4; i++) { |
1118 | 1994204 | sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i]; | |
1119 |
2/2✓ Branch 0 taken 1526980 times.
✓ Branch 1 taken 467224 times.
|
1994204 | if (sao->type_idx[c_idx] == SAO_EDGE) { |
1120 |
2/2✓ Branch 0 taken 763490 times.
✓ Branch 1 taken 763490 times.
|
1526980 | if (i > 1) |
1121 | 763490 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1122 |
2/2✓ Branch 0 taken 155063 times.
✓ Branch 1 taken 312161 times.
|
467224 | } else if (sao->offset_sign[c_idx][i]) { |
1123 | 155063 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1124 | } | ||
1125 | 1994204 | sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale; | |
1126 | } | ||
1127 | } | ||
1128 | 1415196 | } | |
1129 | |||
1130 | #undef SET_SAO | ||
1131 | #undef CTB | ||
1132 | |||
1133 | 384850 | static int hls_cross_component_pred(HEVCLocalContext *lc, int idx) | |
1134 | { | ||
1135 | 384850 | int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx); | |
1136 | |||
1137 |
2/2✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
|
384850 | if (log2_res_scale_abs_plus1 != 0) { |
1138 | 235843 | int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx); | |
1139 | 235843 | lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) * | |
1140 | 235843 | (1 - 2 * res_scale_sign_flag); | |
1141 | } else { | ||
1142 | 149007 | lc->tu.res_scale_val = 0; | |
1143 | } | ||
1144 | |||
1145 | |||
1146 | 384850 | return 0; | |
1147 | } | ||
1148 | |||
1149 | 15292934 | static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0, | |
1150 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1151 | int log2_cb_size, int log2_trafo_size, | ||
1152 | int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr) | ||
1153 | { | ||
1154 | 15292934 | const HEVCContext *const s = lc->parent; | |
1155 | 15292934 | const int log2_trafo_size_c = log2_trafo_size - s->ps.sps->hshift[1]; | |
1156 | int i; | ||
1157 | |||
1158 |
2/2✓ Branch 0 taken 9687550 times.
✓ Branch 1 taken 5605384 times.
|
15292934 | if (lc->cu.pred_mode == MODE_INTRA) { |
1159 | 9687550 | int trafo_size = 1 << log2_trafo_size; | |
1160 | 9687550 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size); | |
1161 | |||
1162 | 9687550 | s->hpc.intra_pred[log2_trafo_size - 2](lc, x0, y0, 0); | |
1163 | } | ||
1164 | |||
1165 |
6/6✓ Branch 0 taken 5594771 times.
✓ Branch 1 taken 9698163 times.
✓ Branch 2 taken 4967146 times.
✓ Branch 3 taken 627625 times.
✓ Branch 4 taken 4548929 times.
✓ Branch 5 taken 418217 times.
|
15292934 | if (cbf_luma || cbf_cb[0] || cbf_cr[0] || |
1166 |
6/6✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4393162 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
|
15354748 | (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1167 | 10805820 | int scan_idx = SCAN_DIAG; | |
1168 | 10805820 | int scan_idx_c = SCAN_DIAG; | |
1169 |
4/4✓ Branch 0 taken 7229625 times.
✓ Branch 1 taken 3576195 times.
✓ Branch 2 taken 5786102 times.
✓ Branch 3 taken 1443523 times.
|
16591922 | int cbf_chroma = cbf_cb[0] || cbf_cr[0] || |
1170 |
2/2✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 5554392 times.
|
5786102 | (s->ps.sps->chroma_format_idc == 2 && |
1171 |
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])); |
1172 | |||
1173 |
4/4✓ Branch 0 taken 2143049 times.
✓ Branch 1 taken 8662771 times.
✓ Branch 2 taken 610425 times.
✓ Branch 3 taken 1532624 times.
|
10805820 | if (s->ps.pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) { |
1174 | 610425 | lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc); | |
1175 |
2/2✓ Branch 0 taken 370890 times.
✓ Branch 1 taken 239535 times.
|
610425 | if (lc->tu.cu_qp_delta != 0) |
1176 |
2/2✓ Branch 1 taken 204940 times.
✓ Branch 2 taken 165950 times.
|
370890 | if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1) |
1177 | 204940 | lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta; | |
1178 | 610425 | lc->tu.is_cu_qp_delta_coded = 1; | |
1179 | |||
1180 |
2/2✓ Branch 0 taken 610424 times.
✓ Branch 1 taken 1 times.
|
610425 | if (lc->tu.cu_qp_delta < -(26 + s->ps.sps->qp_bd_offset / 2) || |
1181 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 610424 times.
|
610424 | lc->tu.cu_qp_delta > (25 + s->ps.sps->qp_bd_offset / 2)) { |
1182 | 1 | av_log(s->avctx, AV_LOG_ERROR, | |
1183 | "The cu_qp_delta %d is outside the valid range " | ||
1184 | "[%d, %d].\n", | ||
1185 | lc->tu.cu_qp_delta, | ||
1186 | 1 | -(26 + s->ps.sps->qp_bd_offset / 2), | |
1187 | 1 | (25 + s->ps.sps->qp_bd_offset / 2)); | |
1188 | 1 | return AVERROR_INVALIDDATA; | |
1189 | } | ||
1190 | |||
1191 | 610424 | ff_hevc_set_qPy(lc, cb_xBase, cb_yBase, log2_cb_size); | |
1192 | } | ||
1193 | |||
1194 |
4/4✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 9913868 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
|
10805819 | if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma && |
1195 |
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) { |
1196 | 266275 | int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc); | |
1197 |
2/2✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
|
266275 | if (cu_chroma_qp_offset_flag) { |
1198 | 48966 | int cu_chroma_qp_offset_idx = 0; | |
1199 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
|
48966 | if (s->ps.pps->chroma_qp_offset_list_len_minus1 > 0) { |
1200 | ✗ | cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc); | |
1201 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1202 | "cu_chroma_qp_offset_idx not yet tested.\n"); | ||
1203 | } | ||
1204 | 48966 | lc->tu.cu_qp_offset_cb = s->ps.pps->cb_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1205 | 48966 | lc->tu.cu_qp_offset_cr = s->ps.pps->cr_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1206 | } else { | ||
1207 | 217309 | lc->tu.cu_qp_offset_cb = 0; | |
1208 | 217309 | lc->tu.cu_qp_offset_cr = 0; | |
1209 | } | ||
1210 | 266275 | lc->tu.is_cu_chroma_qp_offset_coded = 1; | |
1211 | } | ||
1212 | |||
1213 |
4/4✓ Branch 0 taken 7130456 times.
✓ Branch 1 taken 3675363 times.
✓ Branch 2 taken 6255013 times.
✓ Branch 3 taken 875443 times.
|
10805819 | if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) { |
1214 |
2/2✓ Branch 0 taken 4169522 times.
✓ Branch 1 taken 2085491 times.
|
6255013 | if (lc->tu.intra_pred_mode >= 6 && |
1215 |
2/2✓ Branch 0 taken 1510452 times.
✓ Branch 1 taken 2659070 times.
|
4169522 | lc->tu.intra_pred_mode <= 14) { |
1216 | 1510452 | scan_idx = SCAN_VERT; | |
1217 |
2/2✓ Branch 0 taken 2050699 times.
✓ Branch 1 taken 2693862 times.
|
4744561 | } else if (lc->tu.intra_pred_mode >= 22 && |
1218 |
2/2✓ Branch 0 taken 1722876 times.
✓ Branch 1 taken 327823 times.
|
2050699 | lc->tu.intra_pred_mode <= 30) { |
1219 | 1722876 | scan_idx = SCAN_HORIZ; | |
1220 | } | ||
1221 | |||
1222 |
2/2✓ Branch 0 taken 3738884 times.
✓ Branch 1 taken 2516129 times.
|
6255013 | if (lc->tu.intra_pred_mode_c >= 6 && |
1223 |
2/2✓ Branch 0 taken 1421244 times.
✓ Branch 1 taken 2317640 times.
|
3738884 | lc->tu.intra_pred_mode_c <= 14) { |
1224 | 1421244 | scan_idx_c = SCAN_VERT; | |
1225 |
2/2✓ Branch 0 taken 1946813 times.
✓ Branch 1 taken 2886956 times.
|
4833769 | } else if (lc->tu.intra_pred_mode_c >= 22 && |
1226 |
2/2✓ Branch 0 taken 1629296 times.
✓ Branch 1 taken 317517 times.
|
1946813 | lc->tu.intra_pred_mode_c <= 30) { |
1227 | 1629296 | scan_idx_c = SCAN_HORIZ; | |
1228 | } | ||
1229 | } | ||
1230 | |||
1231 | 10805819 | lc->tu.cross_pf = 0; | |
1232 | |||
1233 |
2/2✓ Branch 0 taken 9698162 times.
✓ Branch 1 taken 1107657 times.
|
10805819 | if (cbf_luma) |
1234 | 9698162 | ff_hevc_hls_residual_coding(lc, x0, y0, log2_trafo_size, scan_idx, 0); | |
1235 |
6/6✓ Branch 0 taken 10805627 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6101192 times.
✓ Branch 3 taken 4704435 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 5891629 times.
|
15719817 | if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) { |
1236 | 4913998 | int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]); | |
1237 | 4913998 | int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]); | |
1238 |
4/4✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 4577157 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
|
5131814 | lc->tu.cross_pf = (s->ps.pps->cross_component_prediction_enabled_flag && cbf_luma && |
1239 |
2/2✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
|
217816 | (lc->cu.pred_mode == MODE_INTER || |
1240 |
2/2✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
|
168873 | (lc->tu.chroma_mode_c == 4))); |
1241 | |||
1242 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4721573 times.
|
4913998 | if (lc->tu.cross_pf) { |
1243 | 192425 | hls_cross_component_pred(lc, 0); | |
1244 | } | ||
1245 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8921592 times.
✓ Branch 2 taken 5367200 times.
✓ Branch 3 taken 4913998 times.
|
10281198 | for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1246 |
2/2✓ Branch 0 taken 2982265 times.
✓ Branch 1 taken 2384935 times.
|
5367200 | if (lc->cu.pred_mode == MODE_INTRA) { |
1247 | 2982265 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), trafo_size_h, trafo_size_v); | |
1248 | 2982265 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i << log2_trafo_size_c), 1); | |
1249 | } | ||
1250 |
2/2✓ Branch 0 taken 1493511 times.
✓ Branch 1 taken 3873689 times.
|
5367200 | if (cbf_cb[i]) |
1251 | 1493511 | ff_hevc_hls_residual_coding(lc, x0, y0 + (i << log2_trafo_size_c), | |
1252 | log2_trafo_size_c, scan_idx_c, 1); | ||
1253 | else | ||
1254 |
2/2✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 3834031 times.
|
3873689 | if (lc->tu.cross_pf) { |
1255 | 39658 | ptrdiff_t stride = s->frame->linesize[1]; | |
1256 | 39658 | int hshift = s->ps.sps->hshift[1]; | |
1257 | 39658 | int vshift = s->ps.sps->vshift[1]; | |
1258 | 39658 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1259 | 39658 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1260 | 39658 | int size = 1 << log2_trafo_size_c; | |
1261 | |||
1262 | 39658 | uint8_t *dst = &s->frame->data[1][(y0 >> vshift) * stride + | |
1263 | 39658 | ((x0 >> hshift) << s->ps.sps->pixel_shift)]; | |
1264 |
2/2✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
|
1871162 | for (i = 0; i < (size * size); i++) { |
1265 | 1831504 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1266 | } | ||
1267 | 39658 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1268 | } | ||
1269 | } | ||
1270 | |||
1271 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4721573 times.
|
4913998 | if (lc->tu.cross_pf) { |
1272 | 192425 | hls_cross_component_pred(lc, 1); | |
1273 | } | ||
1274 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8921592 times.
✓ Branch 2 taken 5367200 times.
✓ Branch 3 taken 4913998 times.
|
10281198 | for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1275 |
2/2✓ Branch 0 taken 2982265 times.
✓ Branch 1 taken 2384935 times.
|
5367200 | if (lc->cu.pred_mode == MODE_INTRA) { |
1276 | 2982265 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
1277 | trafo_size_h, trafo_size_v); | ||
1278 | 2982265 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i << log2_trafo_size_c), 2); | |
1279 | } | ||
1280 |
2/2✓ Branch 0 taken 1607584 times.
✓ Branch 1 taken 3759616 times.
|
5367200 | if (cbf_cr[i]) |
1281 | 1607584 | ff_hevc_hls_residual_coding(lc, x0, y0 + (i << log2_trafo_size_c), | |
1282 | log2_trafo_size_c, scan_idx_c, 2); | ||
1283 | else | ||
1284 |
2/2✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 3683692 times.
|
3759616 | if (lc->tu.cross_pf) { |
1285 | 75924 | ptrdiff_t stride = s->frame->linesize[2]; | |
1286 | 75924 | int hshift = s->ps.sps->hshift[2]; | |
1287 | 75924 | int vshift = s->ps.sps->vshift[2]; | |
1288 | 75924 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1289 | 75924 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1290 | 75924 | int size = 1 << log2_trafo_size_c; | |
1291 | |||
1292 | 75924 | uint8_t *dst = &s->frame->data[2][(y0 >> vshift) * stride + | |
1293 | 75924 | ((x0 >> hshift) << s->ps.sps->pixel_shift)]; | |
1294 |
2/2✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
|
3691476 | for (i = 0; i < (size * size); i++) { |
1295 | 3615552 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1296 | } | ||
1297 | 75924 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1298 | } | ||
1299 | } | ||
1300 |
4/4✓ Branch 0 taken 5891629 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1513329 times.
✓ Branch 3 taken 4378300 times.
|
5891821 | } else if (s->ps.sps->chroma_format_idc && blk_idx == 3) { |
1301 | 1513329 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1302 | 1513329 | int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]); | |
1303 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2692920 times.
✓ Branch 2 taken 1680198 times.
✓ Branch 3 taken 1513329 times.
|
3193527 | for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1304 |
2/2✓ Branch 0 taken 1199652 times.
✓ Branch 1 taken 480546 times.
|
1680198 | if (lc->cu.pred_mode == MODE_INTRA) { |
1305 | 1199652 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
1306 | trafo_size_h, trafo_size_v); | ||
1307 | 1199652 | s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (i << log2_trafo_size), 1); | |
1308 | } | ||
1309 |
2/2✓ Branch 0 taken 635265 times.
✓ Branch 1 taken 1044933 times.
|
1680198 | if (cbf_cb[i]) |
1310 | 635265 | ff_hevc_hls_residual_coding(lc, xBase, yBase + (i << log2_trafo_size), | |
1311 | log2_trafo_size, scan_idx_c, 1); | ||
1312 | } | ||
1313 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2692920 times.
✓ Branch 2 taken 1680198 times.
✓ Branch 3 taken 1513329 times.
|
3193527 | for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1314 |
2/2✓ Branch 0 taken 1199652 times.
✓ Branch 1 taken 480546 times.
|
1680198 | if (lc->cu.pred_mode == MODE_INTRA) { |
1315 | 1199652 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
1316 | trafo_size_h, trafo_size_v); | ||
1317 | 1199652 | s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (i << log2_trafo_size), 2); | |
1318 | } | ||
1319 |
2/2✓ Branch 0 taken 716689 times.
✓ Branch 1 taken 963509 times.
|
1680198 | if (cbf_cr[i]) |
1320 | 716689 | ff_hevc_hls_residual_coding(lc, xBase, yBase + (i << log2_trafo_size), | |
1321 | log2_trafo_size, scan_idx_c, 2); | ||
1322 | } | ||
1323 | } | ||
1324 |
3/4✓ Branch 0 taken 4487114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2557093 times.
✓ Branch 3 taken 1930021 times.
|
4487114 | } else if (s->ps.sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) { |
1325 |
4/4✓ Branch 0 taken 1593031 times.
✓ Branch 1 taken 964062 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1532443 times.
|
3581743 | if (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3) { |
1326 | 1024650 | int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]); | |
1327 | 1024650 | int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]); | |
1328 | 1024650 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v); | |
1329 | 1024650 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0, 1); | |
1330 | 1024650 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0, 2); | |
1331 |
2/2✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 1012183 times.
|
1024650 | if (s->ps.sps->chroma_format_idc == 2) { |
1332 | 12467 | ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c), | |
1333 | trafo_size_h, trafo_size_v); | ||
1334 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (1 << log2_trafo_size_c), 1); | |
1335 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (1 << log2_trafo_size_c), 2); | |
1336 | } | ||
1337 |
2/2✓ Branch 0 taken 348054 times.
✓ Branch 1 taken 1184389 times.
|
1532443 | } else if (blk_idx == 3) { |
1338 | 348054 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1339 | 348054 | int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]); | |
1340 | 348054 | ff_hevc_set_neighbour_available(lc, xBase, yBase, | |
1341 | trafo_size_h, trafo_size_v); | ||
1342 | 348054 | s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase, 1); | |
1343 | 348054 | s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase, 2); | |
1344 |
2/2✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 343858 times.
|
348054 | if (s->ps.sps->chroma_format_idc == 2) { |
1345 | 4196 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size), | |
1346 | trafo_size_h, trafo_size_v); | ||
1347 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (1 << log2_trafo_size), 1); | |
1348 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (1 << log2_trafo_size), 2); | |
1349 | } | ||
1350 | } | ||
1351 | } | ||
1352 | |||
1353 | 15292933 | return 0; | |
1354 | } | ||
1355 | |||
1356 | 356478 | static void set_deblocking_bypass(const HEVCContext *s, int x0, int y0, int log2_cb_size) | |
1357 | { | ||
1358 | 356478 | int cb_size = 1 << log2_cb_size; | |
1359 | 356478 | int log2_min_pu_size = s->ps.sps->log2_min_pu_size; | |
1360 | |||
1361 | 356478 | int min_pu_width = s->ps.sps->min_pu_width; | |
1362 | 356478 | int x_end = FFMIN(x0 + cb_size, s->ps.sps->width); | |
1363 | 356478 | int y_end = FFMIN(y0 + cb_size, s->ps.sps->height); | |
1364 | int i, j; | ||
1365 | |||
1366 |
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++) |
1367 |
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++) |
1368 | 949056 | s->is_pcm[i + j * min_pu_width] = 2; | |
1369 | 356478 | } | |
1370 | |||
1371 | 18466393 | static int hls_transform_tree(HEVCLocalContext *lc, int x0, int y0, | |
1372 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1373 | int log2_cb_size, int log2_trafo_size, | ||
1374 | int trafo_depth, int blk_idx, | ||
1375 | const int *base_cbf_cb, const int *base_cbf_cr) | ||
1376 | { | ||
1377 | 18466393 | const HEVCContext *const s = lc->parent; | |
1378 | uint8_t split_transform_flag; | ||
1379 | int cbf_cb[2]; | ||
1380 | int cbf_cr[2]; | ||
1381 | int ret; | ||
1382 | |||
1383 | 18466393 | cbf_cb[0] = base_cbf_cb[0]; | |
1384 | 18466393 | cbf_cb[1] = base_cbf_cb[1]; | |
1385 | 18466393 | cbf_cr[0] = base_cbf_cr[0]; | |
1386 | 18466393 | cbf_cr[1] = base_cbf_cr[1]; | |
1387 | |||
1388 |
2/2✓ Branch 0 taken 6353561 times.
✓ Branch 1 taken 12112832 times.
|
18466393 | if (lc->cu.intra_split_flag) { |
1389 |
2/2✓ Branch 0 taken 4780788 times.
✓ Branch 1 taken 1572773 times.
|
6353561 | if (trafo_depth == 1) { |
1390 | 4780788 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx]; | |
1391 |
2/2✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4645384 times.
|
4780788 | if (s->ps.sps->chroma_format_idc == 3) { |
1392 | 135404 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx]; | |
1393 | 135404 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx]; | |
1394 | } else { | ||
1395 | 4645384 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1396 | 4645384 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1397 | } | ||
1398 | } | ||
1399 | } else { | ||
1400 | 12112832 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0]; | |
1401 | 12112832 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1402 | 12112832 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1403 | } | ||
1404 | |||
1405 |
2/2✓ Branch 0 taken 18357655 times.
✓ Branch 1 taken 108738 times.
|
18466393 | if (log2_trafo_size <= s->ps.sps->log2_max_trafo_size && |
1406 |
2/2✓ Branch 0 taken 9604875 times.
✓ Branch 1 taken 8752780 times.
|
18357655 | log2_trafo_size > s->ps.sps->log2_min_tb_size && |
1407 |
2/2✓ Branch 0 taken 8044634 times.
✓ Branch 1 taken 1560241 times.
|
9604875 | trafo_depth < lc->cu.max_trafo_depth && |
1408 |
4/4✓ Branch 0 taken 1678422 times.
✓ Branch 1 taken 6366212 times.
✓ Branch 2 taken 490612 times.
✓ Branch 3 taken 1187810 times.
|
8044634 | !(lc->cu.intra_split_flag && trafo_depth == 0)) { |
1409 | 6856824 | split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size); | |
1410 | } else { | ||
1411 | 24846803 | int inter_split = s->ps.sps->max_transform_hierarchy_depth_inter == 0 && | |
1412 |
2/2✓ Branch 0 taken 836848 times.
✓ Branch 1 taken 790817 times.
|
1627665 | lc->cu.pred_mode == MODE_INTER && |
1413 |
6/6✓ Branch 0 taken 1627665 times.
✓ Branch 1 taken 9981904 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 161299 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
|
13237234 | lc->cu.part_mode != PART_2Nx2N && |
1414 | trafo_depth == 0; | ||
1415 | |||
1416 | 11609569 | split_transform_flag = log2_trafo_size > s->ps.sps->log2_max_trafo_size || | |
1417 |
8/8✓ Branch 0 taken 11500831 times.
✓ Branch 1 taken 108738 times.
✓ Branch 2 taken 5854902 times.
✓ Branch 3 taken 5645929 times.
✓ Branch 4 taken 4667092 times.
✓ Branch 5 taken 1187810 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10194383 times.
|
11609569 | (lc->cu.intra_split_flag && trafo_depth == 0) || |
1418 | inter_split; | ||
1419 | } | ||
1420 | |||
1421 |
6/6✓ Branch 0 taken 18466201 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8624700 times.
✓ Branch 3 taken 9841501 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8310284 times.
|
18466393 | if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) { |
1422 |
4/4✓ Branch 0 taken 4383552 times.
✓ Branch 1 taken 5772365 times.
✓ Branch 2 taken 1221404 times.
✓ Branch 3 taken 3162148 times.
|
10155917 | if (trafo_depth == 0 || cbf_cb[0]) { |
1423 | 6993769 | cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1424 |
6/6✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 6395503 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
|
6993769 | if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1425 | 526996 | cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1426 | } | ||
1427 | } | ||
1428 | |||
1429 |
4/4✓ Branch 0 taken 4383552 times.
✓ Branch 1 taken 5772365 times.
✓ Branch 2 taken 1166896 times.
✓ Branch 3 taken 3216656 times.
|
10155917 | if (trafo_depth == 0 || cbf_cr[0]) { |
1430 | 6939261 | cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1431 |
6/6✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6193955 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
|
6939261 | if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1432 | 661961 | cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1433 | } | ||
1434 | } | ||
1435 | } | ||
1436 | |||
1437 |
2/2✓ Branch 0 taken 3173459 times.
✓ Branch 1 taken 15292934 times.
|
18466393 | if (split_transform_flag) { |
1438 | 3173459 | const int trafo_size_split = 1 << (log2_trafo_size - 1); | |
1439 | 3173459 | const int x1 = x0 + trafo_size_split; | |
1440 | 3173459 | const int y1 = y0 + trafo_size_split; | |
1441 | |||
1442 | #define SUBDIVIDE(x, y, idx) \ | ||
1443 | do { \ | ||
1444 | ret = hls_transform_tree(lc, x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size,\ | ||
1445 | log2_trafo_size - 1, trafo_depth + 1, idx, \ | ||
1446 | cbf_cb, cbf_cr); \ | ||
1447 | if (ret < 0) \ | ||
1448 | return ret; \ | ||
1449 | } while (0) | ||
1450 | |||
1451 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3173459 times.
|
3173459 | SUBDIVIDE(x0, y0, 0); |
1452 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3173459 times.
|
3173459 | SUBDIVIDE(x1, y0, 1); |
1453 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3173459 times.
|
3173459 | SUBDIVIDE(x0, y1, 2); |
1454 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3173459 times.
|
3173459 | SUBDIVIDE(x1, y1, 3); |
1455 | |||
1456 | #undef SUBDIVIDE | ||
1457 | } else { | ||
1458 | 15292934 | int min_tu_size = 1 << s->ps.sps->log2_min_tb_size; | |
1459 | 15292934 | int log2_min_tu_size = s->ps.sps->log2_min_tb_size; | |
1460 | 15292934 | int min_tu_width = s->ps.sps->min_tb_width; | |
1461 | 15292934 | int cbf_luma = 1; | |
1462 | |||
1463 |
4/4✓ Branch 0 taken 5605384 times.
✓ Branch 1 taken 9687550 times.
✓ Branch 2 taken 982423 times.
✓ Branch 3 taken 4622961 times.
|
15292934 | if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 || |
1464 |
4/4✓ Branch 0 taken 803994 times.
✓ Branch 1 taken 178429 times.
✓ Branch 2 taken 689012 times.
✓ Branch 3 taken 114982 times.
|
982423 | cbf_cb[0] || cbf_cr[0] || |
1465 |
6/6✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 664336 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
|
689012 | (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1466 | 14616568 | cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth); | |
1467 | } | ||
1468 | |||
1469 | 15292934 | ret = hls_transform_unit(lc, x0, y0, xBase, yBase, cb_xBase, cb_yBase, | |
1470 | log2_cb_size, log2_trafo_size, | ||
1471 | blk_idx, cbf_luma, cbf_cb, cbf_cr); | ||
1472 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15292933 times.
|
15292934 | if (ret < 0) |
1473 | 1 | return ret; | |
1474 | // TODO: store cbf_luma somewhere else | ||
1475 |
2/2✓ Branch 0 taken 9698162 times.
✓ Branch 1 taken 5594771 times.
|
15292933 | if (cbf_luma) { |
1476 | int i, j; | ||
1477 |
2/2✓ Branch 0 taken 19737934 times.
✓ Branch 1 taken 9698162 times.
|
29436096 | for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size) |
1478 |
2/2✓ Branch 0 taken 70328480 times.
✓ Branch 1 taken 19737934 times.
|
90066414 | for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) { |
1479 | 70328480 | int x_tu = (x0 + j) >> log2_min_tu_size; | |
1480 | 70328480 | int y_tu = (y0 + i) >> log2_min_tu_size; | |
1481 | 70328480 | s->cbf_luma[y_tu * min_tu_width + x_tu] = 1; | |
1482 | } | ||
1483 | } | ||
1484 |
2/2✓ Branch 0 taken 14760113 times.
✓ Branch 1 taken 532820 times.
|
15292933 | if (!s->sh.disable_deblocking_filter_flag) { |
1485 | 14760113 | ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_trafo_size); | |
1486 |
2/2✓ Branch 0 taken 373941 times.
✓ Branch 1 taken 14386172 times.
|
14760113 | if (s->ps.pps->transquant_bypass_enable_flag && |
1487 |
2/2✓ Branch 0 taken 275932 times.
✓ Branch 1 taken 98009 times.
|
373941 | lc->cu.cu_transquant_bypass_flag) |
1488 | 275932 | set_deblocking_bypass(s, x0, y0, log2_trafo_size); | |
1489 | } | ||
1490 | } | ||
1491 | 18466392 | return 0; | |
1492 | } | ||
1493 | |||
1494 | 12433 | static int hls_pcm_sample(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size) | |
1495 | { | ||
1496 | 12433 | const HEVCContext *const s = lc->parent; | |
1497 | GetBitContext gb; | ||
1498 | 12433 | int cb_size = 1 << log2_cb_size; | |
1499 | 12433 | ptrdiff_t stride0 = s->frame->linesize[0]; | |
1500 | 12433 | ptrdiff_t stride1 = s->frame->linesize[1]; | |
1501 | 12433 | ptrdiff_t stride2 = s->frame->linesize[2]; | |
1502 | 12433 | uint8_t *dst0 = &s->frame->data[0][y0 * stride0 + (x0 << s->ps.sps->pixel_shift)]; | |
1503 | 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)]; | |
1504 | 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)]; | |
1505 | |||
1506 | 12433 | int length = cb_size * cb_size * s->ps.sps->pcm.bit_depth + | |
1507 | 12433 | (((cb_size >> s->ps.sps->hshift[1]) * (cb_size >> s->ps.sps->vshift[1])) + | |
1508 | 12433 | ((cb_size >> s->ps.sps->hshift[2]) * (cb_size >> s->ps.sps->vshift[2]))) * | |
1509 | 12433 | s->ps.sps->pcm.bit_depth_chroma; | |
1510 | 12433 | const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3); | |
1511 | int ret; | ||
1512 | |||
1513 |
2/2✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
|
12433 | if (!s->sh.disable_deblocking_filter_flag) |
1514 | 6937 | ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_cb_size); | |
1515 | |||
1516 | 12433 | ret = init_get_bits(&gb, pcm, length); | |
1517 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
|
12433 | if (ret < 0) |
1518 | ✗ | return ret; | |
1519 | |||
1520 | 12433 | s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, s->ps.sps->pcm.bit_depth); | |
1521 |
1/2✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
|
12433 | if (s->ps.sps->chroma_format_idc) { |
1522 | 12433 | s->hevcdsp.put_pcm(dst1, stride1, | |
1523 | 12433 | cb_size >> s->ps.sps->hshift[1], | |
1524 | 12433 | cb_size >> s->ps.sps->vshift[1], | |
1525 | 12433 | &gb, s->ps.sps->pcm.bit_depth_chroma); | |
1526 | 12433 | s->hevcdsp.put_pcm(dst2, stride2, | |
1527 | 12433 | cb_size >> s->ps.sps->hshift[2], | |
1528 | 12433 | cb_size >> s->ps.sps->vshift[2], | |
1529 | 12433 | &gb, s->ps.sps->pcm.bit_depth_chroma); | |
1530 | } | ||
1531 | |||
1532 | 12433 | return 0; | |
1533 | } | ||
1534 | |||
1535 | /** | ||
1536 | * 8.5.3.2.2.1 Luma sample unidirectional interpolation process | ||
1537 | * | ||
1538 | * @param s HEVC decoding context | ||
1539 | * @param dst target buffer for block data at block position | ||
1540 | * @param dststride stride of the dst buffer | ||
1541 | * @param ref reference picture buffer at origin (0, 0) | ||
1542 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1543 | * @param x_off horizontal position of block from origin (0, 0) | ||
1544 | * @param y_off vertical position of block from origin (0, 0) | ||
1545 | * @param block_w width of block | ||
1546 | * @param block_h height of block | ||
1547 | * @param luma_weight weighting factor applied to the luma prediction | ||
1548 | * @param luma_offset additive offset applied to the luma prediction value | ||
1549 | */ | ||
1550 | |||
1551 | 4826687 | static void luma_mc_uni(HEVCLocalContext *lc, uint8_t *dst, ptrdiff_t dststride, | |
1552 | const AVFrame *ref, const Mv *mv, int x_off, int y_off, | ||
1553 | int block_w, int block_h, int luma_weight, int luma_offset) | ||
1554 | { | ||
1555 | 4826687 | const HEVCContext *const s = lc->parent; | |
1556 | 4826687 | const uint8_t *src = ref->data[0]; | |
1557 | 4826687 | ptrdiff_t srcstride = ref->linesize[0]; | |
1558 | 4826687 | int pic_width = s->ps.sps->width; | |
1559 | 4826687 | int pic_height = s->ps.sps->height; | |
1560 | 4826687 | int mx = mv->x & 3; | |
1561 | 4826687 | int my = mv->y & 3; | |
1562 |
4/4✓ Branch 0 taken 1975858 times.
✓ Branch 1 taken 2850829 times.
✓ Branch 2 taken 1921682 times.
✓ Branch 3 taken 54176 times.
|
9599198 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) || |
1563 |
4/4✓ Branch 0 taken 2850829 times.
✓ Branch 1 taken 1921682 times.
✓ Branch 2 taken 68506 times.
✓ Branch 3 taken 2782323 times.
|
4772511 | (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag); |
1564 | 4826687 | int idx = hevc_pel_weight[block_w]; | |
1565 | |||
1566 | 4826687 | x_off += mv->x >> 2; | |
1567 | 4826687 | y_off += mv->y >> 2; | |
1568 | 4826687 | src += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift)); | |
1569 | |||
1570 |
4/4✓ Branch 0 taken 4771045 times.
✓ Branch 1 taken 55642 times.
✓ Branch 2 taken 4666693 times.
✓ Branch 3 taken 104352 times.
|
4826687 | if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER || |
1571 |
2/2✓ Branch 0 taken 4603261 times.
✓ Branch 1 taken 63432 times.
|
4666693 | x_off >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1572 |
2/2✓ Branch 0 taken 4407267 times.
✓ Branch 1 taken 195994 times.
|
4603261 | y_off >= pic_height - block_h - QPEL_EXTRA_AFTER || |
1573 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4407267 times.
|
4407267 | ref == s->frame) { |
1574 | 419420 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1575 | 419420 | int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1576 | 419420 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1577 | |||
1578 | 419420 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset, | |
1579 | edge_emu_stride, srcstride, | ||
1580 | block_w + QPEL_EXTRA, | ||
1581 | block_h + QPEL_EXTRA, | ||
1582 | x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE, | ||
1583 | pic_width, pic_height); | ||
1584 | 419420 | src = lc->edge_emu_buffer + buf_offset; | |
1585 | 419420 | srcstride = edge_emu_stride; | |
1586 | } | ||
1587 | |||
1588 |
2/2✓ Branch 0 taken 4704005 times.
✓ Branch 1 taken 122682 times.
|
4826687 | if (!weight_flag) |
1589 | 4704005 | s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1590 | block_h, mx, my, block_w); | ||
1591 | else | ||
1592 | 122682 | s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1593 | 122682 | block_h, s->sh.luma_log2_weight_denom, | |
1594 | luma_weight, luma_offset, mx, my, block_w); | ||
1595 | 4826687 | } | |
1596 | |||
1597 | /** | ||
1598 | * 8.5.3.2.2.1 Luma sample bidirectional interpolation process | ||
1599 | * | ||
1600 | * @param s HEVC decoding context | ||
1601 | * @param dst target buffer for block data at block position | ||
1602 | * @param dststride stride of the dst buffer | ||
1603 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1604 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1605 | * @param x_off horizontal position of block from origin (0, 0) | ||
1606 | * @param y_off vertical position of block from origin (0, 0) | ||
1607 | * @param block_w width of block | ||
1608 | * @param block_h height of block | ||
1609 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1610 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1611 | * @param current_mv current motion vector structure | ||
1612 | */ | ||
1613 | 3786478 | static void luma_mc_bi(HEVCLocalContext *lc, uint8_t *dst, ptrdiff_t dststride, | |
1614 | const AVFrame *ref0, const Mv *mv0, int x_off, int y_off, | ||
1615 | int block_w, int block_h, const AVFrame *ref1, | ||
1616 | const Mv *mv1, struct MvField *current_mv) | ||
1617 | { | ||
1618 | 3786478 | const HEVCContext *const s = lc->parent; | |
1619 | 3786478 | ptrdiff_t src0stride = ref0->linesize[0]; | |
1620 | 3786478 | ptrdiff_t src1stride = ref1->linesize[0]; | |
1621 | 3786478 | int pic_width = s->ps.sps->width; | |
1622 | 3786478 | int pic_height = s->ps.sps->height; | |
1623 | 3786478 | int mx0 = mv0->x & 3; | |
1624 | 3786478 | int my0 = mv0->y & 3; | |
1625 | 3786478 | int mx1 = mv1->x & 3; | |
1626 | 3786478 | int my1 = mv1->y & 3; | |
1627 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3786478 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7572956 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) || |
1628 |
3/4✓ Branch 0 taken 3786478 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67336 times.
✓ Branch 3 taken 3719142 times.
|
3786478 | (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag); |
1629 | 3786478 | int x_off0 = x_off + (mv0->x >> 2); | |
1630 | 3786478 | int y_off0 = y_off + (mv0->y >> 2); | |
1631 | 3786478 | int x_off1 = x_off + (mv1->x >> 2); | |
1632 | 3786478 | int y_off1 = y_off + (mv1->y >> 2); | |
1633 | 3786478 | int idx = hevc_pel_weight[block_w]; | |
1634 | |||
1635 | 3786478 | const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift); | |
1636 | 3786478 | const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift); | |
1637 | |||
1638 |
4/4✓ Branch 0 taken 3734016 times.
✓ Branch 1 taken 52462 times.
✓ Branch 2 taken 3634192 times.
✓ Branch 3 taken 99824 times.
|
3786478 | if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER || |
1639 |
2/2✓ Branch 0 taken 3570911 times.
✓ Branch 1 taken 63281 times.
|
3634192 | x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1640 |
2/2✓ Branch 0 taken 201515 times.
✓ Branch 1 taken 3369396 times.
|
3570911 | y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1641 | 417082 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1642 | 417082 | int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1643 | 417082 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1644 | |||
1645 | 417082 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset, | |
1646 | edge_emu_stride, src0stride, | ||
1647 | block_w + QPEL_EXTRA, | ||
1648 | block_h + QPEL_EXTRA, | ||
1649 | x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE, | ||
1650 | pic_width, pic_height); | ||
1651 | 417082 | src0 = lc->edge_emu_buffer + buf_offset; | |
1652 | 417082 | src0stride = edge_emu_stride; | |
1653 | } | ||
1654 | |||
1655 |
4/4✓ Branch 0 taken 3728577 times.
✓ Branch 1 taken 57901 times.
✓ Branch 2 taken 3629394 times.
✓ Branch 3 taken 99183 times.
|
3786478 | if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER || |
1656 |
2/2✓ Branch 0 taken 3563819 times.
✓ Branch 1 taken 65575 times.
|
3629394 | x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1657 |
2/2✓ Branch 0 taken 205314 times.
✓ Branch 1 taken 3358505 times.
|
3563819 | y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1658 | 427973 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1659 | 427973 | int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1660 | 427973 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1661 | |||
1662 | 427973 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset, | |
1663 | edge_emu_stride, src1stride, | ||
1664 | block_w + QPEL_EXTRA, | ||
1665 | block_h + QPEL_EXTRA, | ||
1666 | x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE, | ||
1667 | pic_width, pic_height); | ||
1668 | 427973 | src1 = lc->edge_emu_buffer2 + buf_offset; | |
1669 | 427973 | src1stride = edge_emu_stride; | |
1670 | } | ||
1671 | |||
1672 | 3786478 | s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride, | |
1673 | block_h, mx0, my0, block_w); | ||
1674 |
2/2✓ Branch 0 taken 3719142 times.
✓ Branch 1 taken 67336 times.
|
3786478 | if (!weight_flag) |
1675 | 3719142 | s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1676 | block_h, mx1, my1, block_w); | ||
1677 | else | ||
1678 | 67336 | s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1679 | 67336 | block_h, s->sh.luma_log2_weight_denom, | |
1680 | 67336 | s->sh.luma_weight_l0[current_mv->ref_idx[0]], | |
1681 | 67336 | s->sh.luma_weight_l1[current_mv->ref_idx[1]], | |
1682 | 67336 | s->sh.luma_offset_l0[current_mv->ref_idx[0]], | |
1683 | 67336 | s->sh.luma_offset_l1[current_mv->ref_idx[1]], | |
1684 | mx1, my1, block_w); | ||
1685 | |||
1686 | 3786478 | } | |
1687 | |||
1688 | /** | ||
1689 | * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process | ||
1690 | * | ||
1691 | * @param s HEVC decoding context | ||
1692 | * @param dst1 target buffer for block data at block position (U plane) | ||
1693 | * @param dst2 target buffer for block data at block position (V plane) | ||
1694 | * @param dststride stride of the dst1 and dst2 buffers | ||
1695 | * @param ref reference picture buffer at origin (0, 0) | ||
1696 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1697 | * @param x_off horizontal position of block from origin (0, 0) | ||
1698 | * @param y_off vertical position of block from origin (0, 0) | ||
1699 | * @param block_w width of block | ||
1700 | * @param block_h height of block | ||
1701 | * @param chroma_weight weighting factor applied to the chroma prediction | ||
1702 | * @param chroma_offset additive offset applied to the chroma prediction value | ||
1703 | */ | ||
1704 | |||
1705 | 9653374 | static void chroma_mc_uni(HEVCLocalContext *lc, uint8_t *dst0, | |
1706 | ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist, | ||
1707 | int x_off, int y_off, int block_w, int block_h, | ||
1708 | const struct MvField *current_mv, int chroma_weight, int chroma_offset) | ||
1709 | { | ||
1710 | 9653374 | const HEVCContext *const s = lc->parent; | |
1711 | 9653374 | int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1]; | |
1712 | 9653374 | int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1]; | |
1713 | 9653374 | const Mv *mv = ¤t_mv->mv[reflist]; | |
1714 |
4/4✓ Branch 0 taken 3951716 times.
✓ Branch 1 taken 5701658 times.
✓ Branch 2 taken 3843364 times.
✓ Branch 3 taken 108352 times.
|
19198396 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) || |
1715 |
4/4✓ Branch 0 taken 5701658 times.
✓ Branch 1 taken 3843364 times.
✓ Branch 2 taken 137012 times.
✓ Branch 3 taken 5564646 times.
|
9545022 | (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag); |
1716 | 9653374 | int idx = hevc_pel_weight[block_w]; | |
1717 | 9653374 | int hshift = s->ps.sps->hshift[1]; | |
1718 | 9653374 | int vshift = s->ps.sps->vshift[1]; | |
1719 | 9653374 | intptr_t mx = av_mod_uintp2(mv->x, 2 + hshift); | |
1720 | 9653374 | intptr_t my = av_mod_uintp2(mv->y, 2 + vshift); | |
1721 | 9653374 | intptr_t _mx = mx << (1 - hshift); | |
1722 | 9653374 | intptr_t _my = my << (1 - vshift); | |
1723 |
2/4✓ Branch 0 taken 9653374 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9653374 times.
|
9653374 | int emu = src0 == s->frame->data[1] || src0 == s->frame->data[2]; |
1724 | |||
1725 | 9653374 | x_off += mv->x >> (2 + hshift); | |
1726 | 9653374 | y_off += mv->y >> (2 + vshift); | |
1727 | 9653374 | src0 += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift)); | |
1728 | |||
1729 |
4/4✓ Branch 0 taken 9552090 times.
✓ Branch 1 taken 101284 times.
✓ Branch 2 taken 9343248 times.
✓ Branch 3 taken 208842 times.
|
9653374 | if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER || |
1730 |
2/2✓ Branch 0 taken 9216392 times.
✓ Branch 1 taken 126856 times.
|
9343248 | x_off >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1731 |
3/4✓ Branch 0 taken 8824348 times.
✓ Branch 1 taken 392044 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8824348 times.
|
9216392 | y_off >= pic_height - block_h - EPEL_EXTRA_AFTER || |
1732 | emu) { | ||
1733 | 829026 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1734 | 829026 | int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << s->ps.sps->pixel_shift)); | |
1735 | 829026 | int buf_offset0 = EPEL_EXTRA_BEFORE * | |
1736 | 829026 | (edge_emu_stride + (1 << s->ps.sps->pixel_shift)); | |
1737 | 829026 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0, | |
1738 | edge_emu_stride, srcstride, | ||
1739 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1740 | x_off - EPEL_EXTRA_BEFORE, | ||
1741 | y_off - EPEL_EXTRA_BEFORE, | ||
1742 | pic_width, pic_height); | ||
1743 | |||
1744 | 829026 | src0 = lc->edge_emu_buffer + buf_offset0; | |
1745 | 829026 | srcstride = edge_emu_stride; | |
1746 | } | ||
1747 |
2/2✓ Branch 0 taken 9408010 times.
✓ Branch 1 taken 245364 times.
|
9653374 | if (!weight_flag) |
1748 | 9408010 | s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1749 | block_h, _mx, _my, block_w); | ||
1750 | else | ||
1751 | 245364 | s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1752 | 245364 | block_h, s->sh.chroma_log2_weight_denom, | |
1753 | chroma_weight, chroma_offset, _mx, _my, block_w); | ||
1754 | 9653374 | } | |
1755 | |||
1756 | /** | ||
1757 | * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process | ||
1758 | * | ||
1759 | * @param s HEVC decoding context | ||
1760 | * @param dst target buffer for block data at block position | ||
1761 | * @param dststride stride of the dst buffer | ||
1762 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1763 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1764 | * @param x_off horizontal position of block from origin (0, 0) | ||
1765 | * @param y_off vertical position of block from origin (0, 0) | ||
1766 | * @param block_w width of block | ||
1767 | * @param block_h height of block | ||
1768 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1769 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1770 | * @param current_mv current motion vector structure | ||
1771 | * @param cidx chroma component(cb, cr) | ||
1772 | */ | ||
1773 | 7572956 | static void chroma_mc_bi(HEVCLocalContext *lc, uint8_t *dst0, ptrdiff_t dststride, | |
1774 | const AVFrame *ref0, const AVFrame *ref1, | ||
1775 | int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx) | ||
1776 | { | ||
1777 | 7572956 | const HEVCContext *const s = lc->parent; | |
1778 | 7572956 | const uint8_t *src1 = ref0->data[cidx+1]; | |
1779 | 7572956 | const uint8_t *src2 = ref1->data[cidx+1]; | |
1780 | 7572956 | ptrdiff_t src1stride = ref0->linesize[cidx+1]; | |
1781 | 7572956 | ptrdiff_t src2stride = ref1->linesize[cidx+1]; | |
1782 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7572956 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
15145912 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) || |
1783 |
3/4✓ Branch 0 taken 7572956 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 134672 times.
✓ Branch 3 taken 7438284 times.
|
7572956 | (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag); |
1784 | 7572956 | int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1]; | |
1785 | 7572956 | int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1]; | |
1786 | 7572956 | const Mv *const mv0 = ¤t_mv->mv[0]; | |
1787 | 7572956 | const Mv *const mv1 = ¤t_mv->mv[1]; | |
1788 | 7572956 | int hshift = s->ps.sps->hshift[1]; | |
1789 | 7572956 | int vshift = s->ps.sps->vshift[1]; | |
1790 | |||
1791 | 7572956 | intptr_t mx0 = av_mod_uintp2(mv0->x, 2 + hshift); | |
1792 | 7572956 | intptr_t my0 = av_mod_uintp2(mv0->y, 2 + vshift); | |
1793 | 7572956 | intptr_t mx1 = av_mod_uintp2(mv1->x, 2 + hshift); | |
1794 | 7572956 | intptr_t my1 = av_mod_uintp2(mv1->y, 2 + vshift); | |
1795 | 7572956 | intptr_t _mx0 = mx0 << (1 - hshift); | |
1796 | 7572956 | intptr_t _my0 = my0 << (1 - vshift); | |
1797 | 7572956 | intptr_t _mx1 = mx1 << (1 - hshift); | |
1798 | 7572956 | intptr_t _my1 = my1 << (1 - vshift); | |
1799 | |||
1800 | 7572956 | int x_off0 = x_off + (mv0->x >> (2 + hshift)); | |
1801 | 7572956 | int y_off0 = y_off + (mv0->y >> (2 + vshift)); | |
1802 | 7572956 | int x_off1 = x_off + (mv1->x >> (2 + hshift)); | |
1803 | 7572956 | int y_off1 = y_off + (mv1->y >> (2 + vshift)); | |
1804 | 7572956 | int idx = hevc_pel_weight[block_w]; | |
1805 | 7572956 | src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift); | |
1806 | 7572956 | src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift); | |
1807 | |||
1808 |
4/4✓ Branch 0 taken 7473272 times.
✓ Branch 1 taken 99684 times.
✓ Branch 2 taken 7273548 times.
✓ Branch 3 taken 199724 times.
|
7572956 | if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER || |
1809 |
2/2✓ Branch 0 taken 7146990 times.
✓ Branch 1 taken 126558 times.
|
7273548 | x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1810 |
2/2✓ Branch 0 taken 402380 times.
✓ Branch 1 taken 6744610 times.
|
7146990 | y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
1811 | 828346 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1812 | 828346 | int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << s->ps.sps->pixel_shift)); | |
1813 | 828346 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
1814 | 828346 | (edge_emu_stride + (1 << s->ps.sps->pixel_shift)); | |
1815 | |||
1816 | 828346 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1, | |
1817 | edge_emu_stride, src1stride, | ||
1818 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1819 | x_off0 - EPEL_EXTRA_BEFORE, | ||
1820 | y_off0 - EPEL_EXTRA_BEFORE, | ||
1821 | pic_width, pic_height); | ||
1822 | |||
1823 | 828346 | src1 = lc->edge_emu_buffer + buf_offset1; | |
1824 | 828346 | src1stride = edge_emu_stride; | |
1825 | } | ||
1826 | |||
1827 |
4/4✓ Branch 0 taken 7462078 times.
✓ Branch 1 taken 110878 times.
✓ Branch 2 taken 7263992 times.
✓ Branch 3 taken 198086 times.
|
7572956 | if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER || |
1828 |
2/2✓ Branch 0 taken 7132848 times.
✓ Branch 1 taken 131144 times.
|
7263992 | x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1829 |
2/2✓ Branch 0 taken 410284 times.
✓ Branch 1 taken 6722564 times.
|
7132848 | y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
1830 | 850392 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1831 | 850392 | int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << s->ps.sps->pixel_shift)); | |
1832 | 850392 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
1833 | 850392 | (edge_emu_stride + (1 << s->ps.sps->pixel_shift)); | |
1834 | |||
1835 | 850392 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1, | |
1836 | edge_emu_stride, src2stride, | ||
1837 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1838 | x_off1 - EPEL_EXTRA_BEFORE, | ||
1839 | y_off1 - EPEL_EXTRA_BEFORE, | ||
1840 | pic_width, pic_height); | ||
1841 | |||
1842 | 850392 | src2 = lc->edge_emu_buffer2 + buf_offset1; | |
1843 | 850392 | src2stride = edge_emu_stride; | |
1844 | } | ||
1845 | |||
1846 | 7572956 | s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride, | |
1847 | block_h, _mx0, _my0, block_w); | ||
1848 |
2/2✓ Branch 0 taken 7438284 times.
✓ Branch 1 taken 134672 times.
|
7572956 | if (!weight_flag) |
1849 | 7438284 | s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->frame->linesize[cidx+1], | |
1850 | 7438284 | src2, src2stride, lc->tmp, | |
1851 | block_h, _mx1, _my1, block_w); | ||
1852 | else | ||
1853 | 134672 | s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->frame->linesize[cidx+1], | |
1854 | 134672 | src2, src2stride, lc->tmp, | |
1855 | block_h, | ||
1856 | 134672 | s->sh.chroma_log2_weight_denom, | |
1857 | 134672 | s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx], | |
1858 | 134672 | s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx], | |
1859 | 134672 | s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx], | |
1860 | 134672 | s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx], | |
1861 | _mx1, _my1, block_w); | ||
1862 | 7572956 | } | |
1863 | |||
1864 | 12399643 | static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref, | |
1865 | const Mv *mv, int y0, int height) | ||
1866 | { | ||
1867 |
2/2✓ Branch 0 taken 111132 times.
✓ Branch 1 taken 12288511 times.
|
12399643 | if (s->threads_type == FF_THREAD_FRAME ) { |
1868 | 111132 | int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9); | |
1869 | |||
1870 | 111132 | ff_thread_await_progress(&ref->tf, y, 0); | |
1871 | } | ||
1872 | 12399643 | } | |
1873 | |||
1874 | 2383676 | static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW, | |
1875 | int nPbH, int log2_cb_size, int part_idx, | ||
1876 | int merge_idx, MvField *mv) | ||
1877 | { | ||
1878 | 2383676 | const HEVCContext *const s = lc->parent; | |
1879 | 2383676 | enum InterPredIdc inter_pred_idc = PRED_L0; | |
1880 | int mvp_flag; | ||
1881 | |||
1882 | 2383676 | ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH); | |
1883 | 2383676 | mv->pred_flag = 0; | |
1884 |
2/2✓ Branch 0 taken 1811903 times.
✓ Branch 1 taken 571773 times.
|
2383676 | if (s->sh.slice_type == HEVC_SLICE_B) |
1885 | 1811903 | inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH); | |
1886 | |||
1887 |
2/2✓ Branch 0 taken 1999504 times.
✓ Branch 1 taken 384172 times.
|
2383676 | if (inter_pred_idc != PRED_L1) { |
1888 |
1/2✓ Branch 0 taken 1999504 times.
✗ Branch 1 not taken.
|
1999504 | if (s->sh.nb_refs[L0]) |
1889 | 1999504 | mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]); | |
1890 | |||
1891 | 1999504 | mv->pred_flag = PF_L0; | |
1892 | 1999504 | ff_hevc_hls_mvd_coding(lc, x0, y0, 0); | |
1893 | 1999504 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
1894 | 1999504 | ff_hevc_luma_mv_mvp_mode(lc, x0, y0, nPbW, nPbH, log2_cb_size, | |
1895 | part_idx, merge_idx, mv, mvp_flag, 0); | ||
1896 | 1999504 | mv->mv[0].x += lc->pu.mvd.x; | |
1897 | 1999504 | mv->mv[0].y += lc->pu.mvd.y; | |
1898 | } | ||
1899 | |||
1900 |
2/2✓ Branch 0 taken 788335 times.
✓ Branch 1 taken 1595341 times.
|
2383676 | if (inter_pred_idc != PRED_L0) { |
1901 |
1/2✓ Branch 0 taken 788335 times.
✗ Branch 1 not taken.
|
788335 | if (s->sh.nb_refs[L1]) |
1902 | 788335 | mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]); | |
1903 | |||
1904 |
4/4✓ Branch 0 taken 187361 times.
✓ Branch 1 taken 600974 times.
✓ Branch 2 taken 157794 times.
✓ Branch 3 taken 29567 times.
|
788335 | if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) { |
1905 | 157794 | AV_ZERO32(&lc->pu.mvd); | |
1906 | } else { | ||
1907 | 630541 | ff_hevc_hls_mvd_coding(lc, x0, y0, 1); | |
1908 | } | ||
1909 | |||
1910 | 788335 | mv->pred_flag += PF_L1; | |
1911 | 788335 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
1912 | 788335 | ff_hevc_luma_mv_mvp_mode(lc, x0, y0, nPbW, nPbH, log2_cb_size, | |
1913 | part_idx, merge_idx, mv, mvp_flag, 1); | ||
1914 | 788335 | mv->mv[1].x += lc->pu.mvd.x; | |
1915 | 788335 | mv->mv[1].y += lc->pu.mvd.y; | |
1916 | } | ||
1917 | 2383676 | } | |
1918 | |||
1919 | 8613165 | static void hls_prediction_unit(HEVCLocalContext *lc, int x0, int y0, | |
1920 | int nPbW, int nPbH, | ||
1921 | int log2_cb_size, int partIdx, int idx) | ||
1922 | { | ||
1923 | #define POS(c_idx, x, y) \ | ||
1924 | &s->frame->data[c_idx][((y) >> s->ps.sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \ | ||
1925 | (((x) >> s->ps.sps->hshift[c_idx]) << s->ps.sps->pixel_shift)] | ||
1926 | 8613165 | const HEVCContext *const s = lc->parent; | |
1927 | 8613165 | int merge_idx = 0; | |
1928 | 8613165 | struct MvField current_mv = {{{ 0 }}}; | |
1929 | |||
1930 | 8613165 | int min_pu_width = s->ps.sps->min_pu_width; | |
1931 | |||
1932 | 8613165 | MvField *tab_mvf = s->ref->tab_mvf; | |
1933 | 8613165 | const RefPicList *refPicList = s->ref->refPicList; | |
1934 | 8613165 | const HEVCFrame *ref0 = NULL, *ref1 = NULL; | |
1935 | 8613165 | uint8_t *dst0 = POS(0, x0, y0); | |
1936 | 8613165 | uint8_t *dst1 = POS(1, x0, y0); | |
1937 | 8613165 | uint8_t *dst2 = POS(2, x0, y0); | |
1938 | 8613165 | int log2_min_cb_size = s->ps.sps->log2_min_cb_size; | |
1939 | 8613165 | int min_cb_width = s->ps.sps->min_cb_width; | |
1940 | 8613165 | int x_cb = x0 >> log2_min_cb_size; | |
1941 | 8613165 | int y_cb = y0 >> log2_min_cb_size; | |
1942 | int x_pu, y_pu; | ||
1943 | int i, j; | ||
1944 | |||
1945 | 8613165 | int skip_flag = SAMPLE_CTB(s->skip_flag, x_cb, y_cb); | |
1946 | |||
1947 |
2/2✓ Branch 0 taken 4719272 times.
✓ Branch 1 taken 3893893 times.
|
8613165 | if (!skip_flag) |
1948 | 4719272 | lc->pu.merge_flag = ff_hevc_merge_flag_decode(lc); | |
1949 | |||
1950 |
4/4✓ Branch 0 taken 4719272 times.
✓ Branch 1 taken 3893893 times.
✓ Branch 2 taken 2335596 times.
✓ Branch 3 taken 2383676 times.
|
8613165 | if (skip_flag || lc->pu.merge_flag) { |
1951 |
2/2✓ Branch 0 taken 6152636 times.
✓ Branch 1 taken 76853 times.
|
6229489 | if (s->sh.max_num_merge_cand > 1) |
1952 | 6152636 | merge_idx = ff_hevc_merge_idx_decode(lc); | |
1953 | else | ||
1954 | 76853 | merge_idx = 0; | |
1955 | |||
1956 | 6229489 | ff_hevc_luma_mv_merge_mode(lc, x0, y0, nPbW, nPbH, log2_cb_size, | |
1957 | partIdx, merge_idx, ¤t_mv); | ||
1958 | } else { | ||
1959 | 2383676 | hevc_luma_mv_mvp_mode(lc, x0, y0, nPbW, nPbH, log2_cb_size, | |
1960 | partIdx, merge_idx, ¤t_mv); | ||
1961 | } | ||
1962 | |||
1963 | 8613165 | x_pu = x0 >> s->ps.sps->log2_min_pu_size; | |
1964 | 8613165 | y_pu = y0 >> s->ps.sps->log2_min_pu_size; | |
1965 | |||
1966 |
2/2✓ Branch 0 taken 32575050 times.
✓ Branch 1 taken 8613165 times.
|
41188215 | for (j = 0; j < nPbH >> s->ps.sps->log2_min_pu_size; j++) |
1967 |
2/2✓ Branch 0 taken 207563796 times.
✓ Branch 1 taken 32575050 times.
|
240138846 | for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) |
1968 | 207563796 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; | |
1969 | |||
1970 |
2/2✓ Branch 0 taken 7851595 times.
✓ Branch 1 taken 761570 times.
|
8613165 | if (current_mv.pred_flag & PF_L0) { |
1971 | 7851595 | ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; | |
1972 |
2/4✓ Branch 0 taken 7851595 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7851595 times.
|
7851595 | if (!ref0 || !ref0->frame->data[0]) |
1973 | ✗ | return; | |
1974 | 7851595 | hevc_await_progress(s, ref0, ¤t_mv.mv[0], y0, nPbH); | |
1975 | } | ||
1976 |
2/2✓ Branch 0 taken 4548048 times.
✓ Branch 1 taken 4065117 times.
|
8613165 | if (current_mv.pred_flag & PF_L1) { |
1977 | 4548048 | ref1 = refPicList[1].ref[current_mv.ref_idx[1]]; | |
1978 |
2/4✓ Branch 0 taken 4548048 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4548048 times.
|
4548048 | if (!ref1 || !ref1->frame->data[0]) |
1979 | ✗ | return; | |
1980 | 4548048 | hevc_await_progress(s, ref1, ¤t_mv.mv[1], y0, nPbH); | |
1981 | } | ||
1982 | |||
1983 |
2/2✓ Branch 0 taken 4065117 times.
✓ Branch 1 taken 4548048 times.
|
8613165 | if (current_mv.pred_flag == PF_L0) { |
1984 | 4065117 | int x0_c = x0 >> s->ps.sps->hshift[1]; | |
1985 | 4065117 | int y0_c = y0 >> s->ps.sps->vshift[1]; | |
1986 | 4065117 | int nPbW_c = nPbW >> s->ps.sps->hshift[1]; | |
1987 | 4065117 | int nPbH_c = nPbH >> s->ps.sps->vshift[1]; | |
1988 | |||
1989 | 4065117 | luma_mc_uni(lc, dst0, s->frame->linesize[0], ref0->frame, | |
1990 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
1991 | 4065117 | s->sh.luma_weight_l0[current_mv.ref_idx[0]], | |
1992 | 4065117 | s->sh.luma_offset_l0[current_mv.ref_idx[0]]); | |
1993 | |||
1994 |
1/2✓ Branch 0 taken 4065117 times.
✗ Branch 1 not taken.
|
4065117 | if (s->ps.sps->chroma_format_idc) { |
1995 | 4065117 | chroma_mc_uni(lc, dst1, s->frame->linesize[1], ref0->frame->data[1], ref0->frame->linesize[1], | |
1996 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
1997 | 4065117 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]); | |
1998 | 4065117 | chroma_mc_uni(lc, dst2, s->frame->linesize[2], ref0->frame->data[2], ref0->frame->linesize[2], | |
1999 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2000 | 4065117 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]); | |
2001 | } | ||
2002 |
2/2✓ Branch 0 taken 761570 times.
✓ Branch 1 taken 3786478 times.
|
4548048 | } else if (current_mv.pred_flag == PF_L1) { |
2003 | 761570 | int x0_c = x0 >> s->ps.sps->hshift[1]; | |
2004 | 761570 | int y0_c = y0 >> s->ps.sps->vshift[1]; | |
2005 | 761570 | int nPbW_c = nPbW >> s->ps.sps->hshift[1]; | |
2006 | 761570 | int nPbH_c = nPbH >> s->ps.sps->vshift[1]; | |
2007 | |||
2008 | 761570 | luma_mc_uni(lc, dst0, s->frame->linesize[0], ref1->frame, | |
2009 | ¤t_mv.mv[1], x0, y0, nPbW, nPbH, | ||
2010 | 761570 | s->sh.luma_weight_l1[current_mv.ref_idx[1]], | |
2011 | 761570 | s->sh.luma_offset_l1[current_mv.ref_idx[1]]); | |
2012 | |||
2013 |
1/2✓ Branch 0 taken 761570 times.
✗ Branch 1 not taken.
|
761570 | if (s->ps.sps->chroma_format_idc) { |
2014 | 761570 | chroma_mc_uni(lc, dst1, s->frame->linesize[1], ref1->frame->data[1], ref1->frame->linesize[1], | |
2015 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2016 | 761570 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]); | |
2017 | |||
2018 | 761570 | chroma_mc_uni(lc, dst2, s->frame->linesize[2], ref1->frame->data[2], ref1->frame->linesize[2], | |
2019 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2020 | 761570 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]); | |
2021 | } | ||
2022 |
1/2✓ Branch 0 taken 3786478 times.
✗ Branch 1 not taken.
|
3786478 | } else if (current_mv.pred_flag == PF_BI) { |
2023 | 3786478 | int x0_c = x0 >> s->ps.sps->hshift[1]; | |
2024 | 3786478 | int y0_c = y0 >> s->ps.sps->vshift[1]; | |
2025 | 3786478 | int nPbW_c = nPbW >> s->ps.sps->hshift[1]; | |
2026 | 3786478 | int nPbH_c = nPbH >> s->ps.sps->vshift[1]; | |
2027 | |||
2028 | 3786478 | luma_mc_bi(lc, dst0, s->frame->linesize[0], ref0->frame, | |
2029 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
2030 | 3786478 | ref1->frame, ¤t_mv.mv[1], ¤t_mv); | |
2031 | |||
2032 |
1/2✓ Branch 0 taken 3786478 times.
✗ Branch 1 not taken.
|
3786478 | if (s->ps.sps->chroma_format_idc) { |
2033 | 3786478 | chroma_mc_bi(lc, dst1, s->frame->linesize[1], ref0->frame, ref1->frame, | |
2034 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0); | ||
2035 | |||
2036 | 3786478 | chroma_mc_bi(lc, dst2, s->frame->linesize[2], ref0->frame, ref1->frame, | |
2037 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1); | ||
2038 | } | ||
2039 | } | ||
2040 | } | ||
2041 | |||
2042 | /** | ||
2043 | * 8.4.1 | ||
2044 | */ | ||
2045 | 7548916 | static int luma_intra_pred_mode(HEVCLocalContext *lc, int x0, int y0, int pu_size, | |
2046 | int prev_intra_luma_pred_flag) | ||
2047 | { | ||
2048 | 7548916 | const HEVCContext *const s = lc->parent; | |
2049 | 7548916 | int x_pu = x0 >> s->ps.sps->log2_min_pu_size; | |
2050 | 7548916 | int y_pu = y0 >> s->ps.sps->log2_min_pu_size; | |
2051 | 7548916 | int min_pu_width = s->ps.sps->min_pu_width; | |
2052 | 7548916 | int size_in_pus = pu_size >> s->ps.sps->log2_min_pu_size; | |
2053 | 7548916 | int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size); | |
2054 | 7548916 | int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size); | |
2055 | |||
2056 |
2/2✓ Branch 0 taken 1052468 times.
✓ Branch 1 taken 120845 times.
|
1173313 | int cand_up = (lc->ctb_up_flag || y0b) ? |
2057 |
2/2✓ Branch 0 taken 1173313 times.
✓ Branch 1 taken 6375603 times.
|
8722229 | s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC; |
2058 |
2/2✓ Branch 0 taken 567874 times.
✓ Branch 1 taken 76027 times.
|
643901 | int cand_left = (lc->ctb_left_flag || x0b) ? |
2059 |
2/2✓ Branch 0 taken 643901 times.
✓ Branch 1 taken 6905015 times.
|
8192817 | s->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC; |
2060 | |||
2061 | 7548916 | int y_ctb = (y0 >> (s->ps.sps->log2_ctb_size)) << (s->ps.sps->log2_ctb_size); | |
2062 | |||
2063 | 7548916 | MvField *tab_mvf = s->ref->tab_mvf; | |
2064 | int intra_pred_mode; | ||
2065 | int candidate[3]; | ||
2066 | int i, j; | ||
2067 | |||
2068 | // intra_pred_mode prediction does not cross vertical CTB boundaries | ||
2069 |
2/2✓ Branch 0 taken 959686 times.
✓ Branch 1 taken 6589230 times.
|
7548916 | if ((y0 - 1) < y_ctb) |
2070 | 959686 | cand_up = INTRA_DC; | |
2071 | |||
2072 |
2/2✓ Branch 0 taken 1585356 times.
✓ Branch 1 taken 5963560 times.
|
7548916 | if (cand_left == cand_up) { |
2073 |
2/2✓ Branch 0 taken 929561 times.
✓ Branch 1 taken 655795 times.
|
1585356 | if (cand_left < 2) { |
2074 | 929561 | candidate[0] = INTRA_PLANAR; | |
2075 | 929561 | candidate[1] = INTRA_DC; | |
2076 | 929561 | candidate[2] = INTRA_ANGULAR_26; | |
2077 | } else { | ||
2078 | 655795 | candidate[0] = cand_left; | |
2079 | 655795 | candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31); | |
2080 | 655795 | candidate[2] = 2 + ((cand_left - 2 + 1) & 31); | |
2081 | } | ||
2082 | } else { | ||
2083 | 5963560 | candidate[0] = cand_left; | |
2084 | 5963560 | candidate[1] = cand_up; | |
2085 |
4/4✓ Branch 0 taken 4964126 times.
✓ Branch 1 taken 999434 times.
✓ Branch 2 taken 4106535 times.
✓ Branch 3 taken 857591 times.
|
5963560 | if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) { |
2086 | 4106535 | candidate[2] = INTRA_PLANAR; | |
2087 |
4/4✓ Branch 0 taken 1621157 times.
✓ Branch 1 taken 235868 times.
✓ Branch 2 taken 1227240 times.
✓ Branch 3 taken 393917 times.
|
1857025 | } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) { |
2088 | 1227240 | candidate[2] = INTRA_DC; | |
2089 | } else { | ||
2090 | 629785 | candidate[2] = INTRA_ANGULAR_26; | |
2091 | } | ||
2092 | } | ||
2093 | |||
2094 |
2/2✓ Branch 0 taken 4526900 times.
✓ Branch 1 taken 3022016 times.
|
7548916 | if (prev_intra_luma_pred_flag) { |
2095 | 4526900 | intra_pred_mode = candidate[lc->pu.mpm_idx]; | |
2096 | } else { | ||
2097 |
2/2✓ Branch 0 taken 1446857 times.
✓ Branch 1 taken 1575159 times.
|
3022016 | if (candidate[0] > candidate[1]) |
2098 | 1446857 | FFSWAP(uint8_t, candidate[0], candidate[1]); | |
2099 |
2/2✓ Branch 0 taken 1804701 times.
✓ Branch 1 taken 1217315 times.
|
3022016 | if (candidate[0] > candidate[2]) |
2100 | 1804701 | FFSWAP(uint8_t, candidate[0], candidate[2]); | |
2101 |
2/2✓ Branch 0 taken 2256476 times.
✓ Branch 1 taken 765540 times.
|
3022016 | if (candidate[1] > candidate[2]) |
2102 | 2256476 | FFSWAP(uint8_t, candidate[1], candidate[2]); | |
2103 | |||
2104 | 3022016 | intra_pred_mode = lc->pu.rem_intra_luma_pred_mode; | |
2105 |
2/2✓ Branch 0 taken 9066048 times.
✓ Branch 1 taken 3022016 times.
|
12088064 | for (i = 0; i < 3; i++) |
2106 |
2/2✓ Branch 0 taken 6602670 times.
✓ Branch 1 taken 2463378 times.
|
9066048 | if (intra_pred_mode >= candidate[i]) |
2107 | 6602670 | intra_pred_mode++; | |
2108 | } | ||
2109 | |||
2110 | /* write the intra prediction units into the mv array */ | ||
2111 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7548916 times.
|
7548916 | if (!size_in_pus) |
2112 | ✗ | size_in_pus = 1; | |
2113 |
2/2✓ Branch 0 taken 13251664 times.
✓ Branch 1 taken 7548916 times.
|
20800580 | for (i = 0; i < size_in_pus; i++) { |
2114 | 13251664 | memset(&s->tab_ipm[(y_pu + i) * min_pu_width + x_pu], | |
2115 | intra_pred_mode, size_in_pus); | ||
2116 | |||
2117 |
2/2✓ Branch 0 taken 41841892 times.
✓ Branch 1 taken 13251664 times.
|
55093556 | for (j = 0; j < size_in_pus; j++) { |
2118 | 41841892 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA; | |
2119 | } | ||
2120 | } | ||
2121 | |||
2122 | 7548916 | return intra_pred_mode; | |
2123 | } | ||
2124 | |||
2125 | 10997830 | static av_always_inline void set_ct_depth(const HEVCContext *s, int x0, int y0, | |
2126 | int log2_cb_size, int ct_depth) | ||
2127 | { | ||
2128 | 10997830 | int length = (1 << log2_cb_size) >> s->ps.sps->log2_min_cb_size; | |
2129 | 10997830 | int x_cb = x0 >> s->ps.sps->log2_min_cb_size; | |
2130 | 10997830 | int y_cb = y0 >> s->ps.sps->log2_min_cb_size; | |
2131 | int y; | ||
2132 | |||
2133 |
2/2✓ Branch 0 taken 20229405 times.
✓ Branch 1 taken 10997830 times.
|
31227235 | for (y = 0; y < length; y++) |
2134 | 20229405 | memset(&s->tab_ct_depth[(y_cb + y) * s->ps.sps->min_cb_width + x_cb], | |
2135 | ct_depth, length); | ||
2136 | 10997830 | } | |
2137 | |||
2138 | static const uint8_t tab_mode_idx[] = { | ||
2139 | 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, | ||
2140 | 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31}; | ||
2141 | |||
2142 | 3963325 | static void intra_prediction_unit(HEVCLocalContext *lc, int x0, int y0, | |
2143 | int log2_cb_size) | ||
2144 | { | ||
2145 | 3963325 | const HEVCContext *const s = lc->parent; | |
2146 | static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 }; | ||
2147 | uint8_t prev_intra_luma_pred_flag[4]; | ||
2148 | 3963325 | int split = lc->cu.part_mode == PART_NxN; | |
2149 | 3963325 | int pb_size = (1 << log2_cb_size) >> split; | |
2150 | 3963325 | int side = split + 1; | |
2151 | int chroma_mode; | ||
2152 | int i, j; | ||
2153 | |||
2154 |
2/2✓ Branch 0 taken 5158522 times.
✓ Branch 1 taken 3963325 times.
|
9121847 | for (i = 0; i < side; i++) |
2155 |
2/2✓ Branch 0 taken 7548916 times.
✓ Branch 1 taken 5158522 times.
|
12707438 | for (j = 0; j < side; j++) |
2156 | 7548916 | prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc); | |
2157 | |||
2158 |
2/2✓ Branch 0 taken 5158522 times.
✓ Branch 1 taken 3963325 times.
|
9121847 | for (i = 0; i < side; i++) { |
2159 |
2/2✓ Branch 0 taken 7548916 times.
✓ Branch 1 taken 5158522 times.
|
12707438 | for (j = 0; j < side; j++) { |
2160 |
2/2✓ Branch 0 taken 4526900 times.
✓ Branch 1 taken 3022016 times.
|
7548916 | if (prev_intra_luma_pred_flag[2 * i + j]) |
2161 | 4526900 | lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc); | |
2162 | else | ||
2163 | 3022016 | lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc); | |
2164 | |||
2165 | 7548916 | lc->pu.intra_pred_mode[2 * i + j] = | |
2166 | 7548916 | luma_intra_pred_mode(lc, x0 + pb_size * j, y0 + pb_size * i, pb_size, | |
2167 | 7548916 | prev_intra_luma_pred_flag[2 * i + j]); | |
2168 | } | ||
2169 | } | ||
2170 | |||
2171 |
2/2✓ Branch 0 taken 105006 times.
✓ Branch 1 taken 3858319 times.
|
3963325 | if (s->ps.sps->chroma_format_idc == 3) { |
2172 |
2/2✓ Branch 0 taken 138857 times.
✓ Branch 1 taken 105006 times.
|
243863 | for (i = 0; i < side; i++) { |
2173 |
2/2✓ Branch 0 taken 206559 times.
✓ Branch 1 taken 138857 times.
|
345416 | for (j = 0; j < side; j++) { |
2174 | 206559 | lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
2175 |
2/2✓ Branch 0 taken 34248 times.
✓ Branch 1 taken 172311 times.
|
206559 | if (chroma_mode != 4) { |
2176 |
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]) |
2177 | 2343 | lc->pu.intra_pred_mode_c[2 * i + j] = 34; | |
2178 | else | ||
2179 | 31905 | lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode]; | |
2180 | } else { | ||
2181 | 172311 | lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j]; | |
2182 | } | ||
2183 | } | ||
2184 | } | ||
2185 |
2/2✓ Branch 0 taken 247106 times.
✓ Branch 1 taken 3611213 times.
|
3858319 | } else if (s->ps.sps->chroma_format_idc == 2) { |
2186 | int mode_idx; | ||
2187 | 247106 | lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
2188 |
2/2✓ Branch 0 taken 73995 times.
✓ Branch 1 taken 173111 times.
|
247106 | if (chroma_mode != 4) { |
2189 |
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]) |
2190 | 3515 | mode_idx = 34; | |
2191 | else | ||
2192 | 70480 | mode_idx = intra_chroma_table[chroma_mode]; | |
2193 | } else { | ||
2194 | 173111 | mode_idx = lc->pu.intra_pred_mode[0]; | |
2195 | } | ||
2196 | 247106 | lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx]; | |
2197 |
2/2✓ Branch 0 taken 3611021 times.
✓ Branch 1 taken 192 times.
|
3611213 | } else if (s->ps.sps->chroma_format_idc != 0) { |
2198 | 3611021 | chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
2199 |
2/2✓ Branch 0 taken 922004 times.
✓ Branch 1 taken 2689017 times.
|
3611021 | if (chroma_mode != 4) { |
2200 |
2/2✓ Branch 0 taken 68309 times.
✓ Branch 1 taken 853695 times.
|
922004 | if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode]) |
2201 | 68309 | lc->pu.intra_pred_mode_c[0] = 34; | |
2202 | else | ||
2203 | 853695 | lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode]; | |
2204 | } else { | ||
2205 | 2689017 | lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0]; | |
2206 | } | ||
2207 | } | ||
2208 | 3963325 | } | |
2209 | |||
2210 | 7034506 | static void intra_prediction_unit_default_value(HEVCLocalContext *lc, | |
2211 | int x0, int y0, | ||
2212 | int log2_cb_size) | ||
2213 | { | ||
2214 | 7034506 | const HEVCContext *const s = lc->parent; | |
2215 | 7034506 | int pb_size = 1 << log2_cb_size; | |
2216 | 7034506 | int size_in_pus = pb_size >> s->ps.sps->log2_min_pu_size; | |
2217 | 7034506 | int min_pu_width = s->ps.sps->min_pu_width; | |
2218 | 7034506 | MvField *tab_mvf = s->ref->tab_mvf; | |
2219 | 7034506 | int x_pu = x0 >> s->ps.sps->log2_min_pu_size; | |
2220 | 7034506 | int y_pu = y0 >> s->ps.sps->log2_min_pu_size; | |
2221 | int j, k; | ||
2222 | |||
2223 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7034506 times.
|
7034506 | if (size_in_pus == 0) |
2224 | ✗ | size_in_pus = 1; | |
2225 |
2/2✓ Branch 0 taken 29597542 times.
✓ Branch 1 taken 7034506 times.
|
36632048 | for (j = 0; j < size_in_pus; j++) |
2226 | 29597542 | memset(&s->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus); | |
2227 |
2/2✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 7022073 times.
|
7034506 | if (lc->cu.pred_mode == MODE_INTRA) |
2228 |
2/2✓ Branch 0 taken 40908 times.
✓ Branch 1 taken 12433 times.
|
53341 | for (j = 0; j < size_in_pus; j++) |
2229 |
2/2✓ Branch 0 taken 182512 times.
✓ Branch 1 taken 40908 times.
|
223420 | for (k = 0; k < size_in_pus; k++) |
2230 | 182512 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA; | |
2231 | 7034506 | } | |
2232 | |||
2233 | 10997831 | static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, int y0, int log2_cb_size) | |
2234 | { | ||
2235 | 10997831 | int cb_size = 1 << log2_cb_size; | |
2236 | 10997831 | int log2_min_cb_size = s->ps.sps->log2_min_cb_size; | |
2237 | 10997831 | int length = cb_size >> log2_min_cb_size; | |
2238 | 10997831 | int min_cb_width = s->ps.sps->min_cb_width; | |
2239 | 10997831 | int x_cb = x0 >> log2_min_cb_size; | |
2240 | 10997831 | int y_cb = y0 >> log2_min_cb_size; | |
2241 | 10997831 | int idx = log2_cb_size - 2; | |
2242 | 10997831 | int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1; | |
2243 | int x, y, ret; | ||
2244 | |||
2245 | 10997831 | lc->cu.x = x0; | |
2246 | 10997831 | lc->cu.y = y0; | |
2247 | 10997831 | lc->cu.pred_mode = MODE_INTRA; | |
2248 | 10997831 | lc->cu.part_mode = PART_2Nx2N; | |
2249 | 10997831 | lc->cu.intra_split_flag = 0; | |
2250 | |||
2251 | 10997831 | SAMPLE_CTB(s->skip_flag, x_cb, y_cb) = 0; | |
2252 |
2/2✓ Branch 0 taken 43991324 times.
✓ Branch 1 taken 10997831 times.
|
54989155 | for (x = 0; x < 4; x++) |
2253 | 43991324 | lc->pu.intra_pred_mode[x] = 1; | |
2254 |
2/2✓ Branch 0 taken 200139 times.
✓ Branch 1 taken 10797692 times.
|
10997831 | if (s->ps.pps->transquant_bypass_enable_flag) { |
2255 | 200139 | lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(lc); | |
2256 |
2/2✓ Branch 0 taken 80538 times.
✓ Branch 1 taken 119601 times.
|
200139 | if (lc->cu.cu_transquant_bypass_flag) |
2257 | 80538 | set_deblocking_bypass(s, x0, y0, log2_cb_size); | |
2258 | } else | ||
2259 | 10797692 | lc->cu.cu_transquant_bypass_flag = 0; | |
2260 | |||
2261 |
2/2✓ Branch 0 taken 8093587 times.
✓ Branch 1 taken 2904244 times.
|
10997831 | if (s->sh.slice_type != HEVC_SLICE_I) { |
2262 | 8093587 | uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, x0, y0, x_cb, y_cb); | |
2263 | |||
2264 | 8093587 | x = y_cb * min_cb_width + x_cb; | |
2265 |
2/2✓ Branch 0 taken 16387345 times.
✓ Branch 1 taken 8093587 times.
|
24480932 | for (y = 0; y < length; y++) { |
2266 | 16387345 | memset(&s->skip_flag[x], skip_flag, length); | |
2267 | 16387345 | x += min_cb_width; | |
2268 | } | ||
2269 |
2/2✓ Branch 0 taken 3893893 times.
✓ Branch 1 taken 4199694 times.
|
8093587 | lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER; |
2270 | } else { | ||
2271 | 2904244 | x = y_cb * min_cb_width + x_cb; | |
2272 |
2/2✓ Branch 0 taken 3842061 times.
✓ Branch 1 taken 2904244 times.
|
6746305 | for (y = 0; y < length; y++) { |
2273 | 3842061 | memset(&s->skip_flag[x], 0, length); | |
2274 | 3842061 | x += min_cb_width; | |
2275 | } | ||
2276 | } | ||
2277 | |||
2278 |
2/2✓ Branch 0 taken 3893893 times.
✓ Branch 1 taken 7103938 times.
|
10997831 | if (SAMPLE_CTB(s->skip_flag, x_cb, y_cb)) { |
2279 | 3893893 | hls_prediction_unit(lc, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | |
2280 | 3893893 | intra_prediction_unit_default_value(lc, x0, y0, log2_cb_size); | |
2281 | |||
2282 |
2/2✓ Branch 0 taken 3747380 times.
✓ Branch 1 taken 146513 times.
|
3893893 | if (!s->sh.disable_deblocking_filter_flag) |
2283 | 3747380 | ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_cb_size); | |
2284 | } else { | ||
2285 | 7103938 | int pcm_flag = 0; | |
2286 | |||
2287 |
2/2✓ Branch 0 taken 4199694 times.
✓ Branch 1 taken 2904244 times.
|
7103938 | if (s->sh.slice_type != HEVC_SLICE_I) |
2288 | 4199694 | lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc); | |
2289 |
2/2✓ Branch 0 taken 3975758 times.
✓ Branch 1 taken 3128180 times.
|
7103938 | if (lc->cu.pred_mode != MODE_INTRA || |
2290 |
2/2✓ Branch 0 taken 3043101 times.
✓ Branch 1 taken 932657 times.
|
3975758 | log2_cb_size == s->ps.sps->log2_min_cb_size) { |
2291 | 6171281 | lc->cu.part_mode = ff_hevc_part_mode_decode(lc, log2_cb_size); | |
2292 |
2/2✓ Branch 0 taken 1300833 times.
✓ Branch 1 taken 4870448 times.
|
7472114 | lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN && |
2293 |
2/2✓ Branch 0 taken 1195197 times.
✓ Branch 1 taken 105636 times.
|
1300833 | lc->cu.pred_mode == MODE_INTRA; |
2294 | } | ||
2295 | |||
2296 |
2/2✓ Branch 0 taken 3975758 times.
✓ Branch 1 taken 3128180 times.
|
7103938 | if (lc->cu.pred_mode == MODE_INTRA) { |
2297 |
4/4✓ Branch 0 taken 2780561 times.
✓ Branch 1 taken 1195197 times.
✓ Branch 2 taken 162684 times.
✓ Branch 3 taken 2617877 times.
|
3975758 | if (lc->cu.part_mode == PART_2Nx2N && s->ps.sps->pcm_enabled_flag && |
2298 |
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 && |
2299 |
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) { |
2300 | 153183 | pcm_flag = ff_hevc_pcm_flag_decode(lc); | |
2301 | } | ||
2302 |
2/2✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 3963325 times.
|
3975758 | if (pcm_flag) { |
2303 | 12433 | intra_prediction_unit_default_value(lc, x0, y0, log2_cb_size); | |
2304 | 12433 | ret = hls_pcm_sample(lc, x0, y0, log2_cb_size); | |
2305 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12425 times.
|
12433 | if (s->ps.sps->pcm.loop_filter_disable_flag) |
2306 | 8 | set_deblocking_bypass(s, x0, y0, log2_cb_size); | |
2307 | |||
2308 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
|
12433 | if (ret < 0) |
2309 | ✗ | return ret; | |
2310 | } else { | ||
2311 | 3963325 | intra_prediction_unit(lc, x0, y0, log2_cb_size); | |
2312 | } | ||
2313 | } else { | ||
2314 | 3128180 | intra_prediction_unit_default_value(lc, x0, y0, log2_cb_size); | |
2315 |
8/9✓ Branch 0 taken 1748360 times.
✓ Branch 1 taken 446065 times.
✓ Branch 2 taken 535782 times.
✓ Branch 3 taken 63783 times.
✓ Branch 4 taken 55217 times.
✓ Branch 5 taken 93237 times.
✓ Branch 6 taken 80100 times.
✓ Branch 7 taken 105636 times.
✗ Branch 8 not taken.
|
3128180 | switch (lc->cu.part_mode) { |
2316 | 1748360 | case PART_2Nx2N: | |
2317 | 1748360 | hls_prediction_unit(lc, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | |
2318 | 1748360 | break; | |
2319 | 446065 | case PART_2NxN: | |
2320 | 446065 | hls_prediction_unit(lc, x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx); | |
2321 | 446065 | hls_prediction_unit(lc, x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx); | |
2322 | 446065 | break; | |
2323 | 535782 | case PART_Nx2N: | |
2324 | 535782 | hls_prediction_unit(lc, x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1); | |
2325 | 535782 | hls_prediction_unit(lc, x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1); | |
2326 | 535782 | break; | |
2327 | 63783 | case PART_2NxnU: | |
2328 | 63783 | hls_prediction_unit(lc, x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx); | |
2329 | 63783 | hls_prediction_unit(lc, x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx); | |
2330 | 63783 | break; | |
2331 | 55217 | case PART_2NxnD: | |
2332 | 55217 | hls_prediction_unit(lc, x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx); | |
2333 | 55217 | hls_prediction_unit(lc, x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx); | |
2334 | 55217 | break; | |
2335 | 93237 | case PART_nLx2N: | |
2336 | 93237 | hls_prediction_unit(lc, x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2); | |
2337 | 93237 | hls_prediction_unit(lc, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2); | |
2338 | 93237 | break; | |
2339 | 80100 | case PART_nRx2N: | |
2340 | 80100 | hls_prediction_unit(lc, x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2); | |
2341 | 80100 | hls_prediction_unit(lc, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2); | |
2342 | 80100 | break; | |
2343 | 105636 | case PART_NxN: | |
2344 | 105636 | hls_prediction_unit(lc, x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1); | |
2345 | 105636 | hls_prediction_unit(lc, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1); | |
2346 | 105636 | hls_prediction_unit(lc, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1); | |
2347 | 105636 | hls_prediction_unit(lc, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1); | |
2348 | 105636 | break; | |
2349 | } | ||
2350 | } | ||
2351 | |||
2352 |
2/2✓ Branch 0 taken 7091505 times.
✓ Branch 1 taken 12433 times.
|
7103938 | if (!pcm_flag) { |
2353 | 7091505 | int rqt_root_cbf = 1; | |
2354 | |||
2355 |
2/2✓ Branch 0 taken 3128180 times.
✓ Branch 1 taken 3963325 times.
|
7091505 | if (lc->cu.pred_mode != MODE_INTRA && |
2356 |
4/4✓ Branch 0 taken 1748360 times.
✓ Branch 1 taken 1379820 times.
✓ Branch 2 taken 972239 times.
✓ Branch 3 taken 776121 times.
|
3128180 | !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) { |
2357 | 2352059 | rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc); | |
2358 | } | ||
2359 |
2/2✓ Branch 0 taken 5772557 times.
✓ Branch 1 taken 1318948 times.
|
7091505 | if (rqt_root_cbf) { |
2360 | const static int cbf[2] = { 0 }; | ||
2361 |
2/2✓ Branch 0 taken 3963325 times.
✓ Branch 1 taken 1809232 times.
|
5772557 | lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ? |
2362 | 3963325 | s->ps.sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag : | |
2363 | 1809232 | s->ps.sps->max_transform_hierarchy_depth_inter; | |
2364 | 5772557 | ret = hls_transform_tree(lc, x0, y0, x0, y0, x0, y0, | |
2365 | log2_cb_size, | ||
2366 | log2_cb_size, 0, 0, cbf, cbf); | ||
2367 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5772556 times.
|
5772557 | if (ret < 0) |
2368 | 1 | return ret; | |
2369 | } else { | ||
2370 |
2/2✓ Branch 0 taken 1262516 times.
✓ Branch 1 taken 56432 times.
|
1318948 | if (!s->sh.disable_deblocking_filter_flag) |
2371 | 1262516 | ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_cb_size); | |
2372 | } | ||
2373 | } | ||
2374 | } | ||
2375 | |||
2376 |
4/4✓ Branch 0 taken 1955623 times.
✓ Branch 1 taken 9042207 times.
✓ Branch 2 taken 787605 times.
✓ Branch 3 taken 1168018 times.
|
10997830 | if (s->ps.pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0) |
2377 | 787605 | ff_hevc_set_qPy(lc, x0, y0, log2_cb_size); | |
2378 | |||
2379 | 10997830 | x = y_cb * min_cb_width + x_cb; | |
2380 |
2/2✓ Branch 0 taken 20229405 times.
✓ Branch 1 taken 10997830 times.
|
31227235 | for (y = 0; y < length; y++) { |
2381 | 20229405 | memset(&s->qp_y_tab[x], lc->qp_y, length); | |
2382 | 20229405 | x += min_cb_width; | |
2383 | } | ||
2384 | |||
2385 |
2/2✓ Branch 0 taken 3756464 times.
✓ Branch 1 taken 7241366 times.
|
10997830 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
2386 |
2/2✓ Branch 0 taken 2207687 times.
✓ Branch 1 taken 1548777 times.
|
3756464 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) { |
2387 | 2207687 | lc->qPy_pred = lc->qp_y; | |
2388 | } | ||
2389 | |||
2390 | 10997830 | set_ct_depth(s, x0, y0, log2_cb_size, lc->ct_depth); | |
2391 | |||
2392 | 10997830 | return 0; | |
2393 | } | ||
2394 | |||
2395 | 14349945 | static int hls_coding_quadtree(HEVCLocalContext *lc, int x0, int y0, | |
2396 | int log2_cb_size, int cb_depth) | ||
2397 | { | ||
2398 | 14349945 | const HEVCContext *const s = lc->parent; | |
2399 | 14349945 | const int cb_size = 1 << log2_cb_size; | |
2400 | int ret; | ||
2401 | int split_cu; | ||
2402 | |||
2403 | 14349945 | lc->ct_depth = cb_depth; | |
2404 |
2/2✓ Branch 0 taken 14321026 times.
✓ Branch 1 taken 28919 times.
|
14349945 | if (x0 + cb_size <= s->ps.sps->width && |
2405 |
2/2✓ Branch 0 taken 14002581 times.
✓ Branch 1 taken 318445 times.
|
14321026 | y0 + cb_size <= s->ps.sps->height && |
2406 |
2/2✓ Branch 0 taken 7491019 times.
✓ Branch 1 taken 6511562 times.
|
14002581 | log2_cb_size > s->ps.sps->log2_min_cb_size) { |
2407 | 7491019 | split_cu = ff_hevc_split_coding_unit_flag_decode(lc, cb_depth, x0, y0); | |
2408 | } else { | ||
2409 | 6858926 | split_cu = (log2_cb_size > s->ps.sps->log2_min_cb_size); | |
2410 | } | ||
2411 |
2/2✓ Branch 0 taken 2540953 times.
✓ Branch 1 taken 11808992 times.
|
14349945 | if (s->ps.pps->cu_qp_delta_enabled_flag && |
2412 |
2/2✓ Branch 0 taken 1462041 times.
✓ Branch 1 taken 1078912 times.
|
2540953 | log2_cb_size >= s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth) { |
2413 | 1462041 | lc->tu.is_cu_qp_delta_coded = 0; | |
2414 | 1462041 | lc->tu.cu_qp_delta = 0; | |
2415 | } | ||
2416 | |||
2417 |
2/2✓ Branch 0 taken 519326 times.
✓ Branch 1 taken 13830619 times.
|
14349945 | if (s->sh.cu_chroma_qp_offset_enabled_flag && |
2418 |
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) { |
2419 | 519326 | lc->tu.is_cu_chroma_qp_offset_coded = 0; | |
2420 | } | ||
2421 | |||
2422 |
2/2✓ Branch 0 taken 3352114 times.
✓ Branch 1 taken 10997831 times.
|
14349945 | if (split_cu) { |
2423 | 3352114 | int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1; | |
2424 | 3352114 | const int cb_size_split = cb_size >> 1; | |
2425 | 3352114 | const int x1 = x0 + cb_size_split; | |
2426 | 3352114 | const int y1 = y0 + cb_size_split; | |
2427 | |||
2428 | 3352114 | int more_data = 0; | |
2429 | |||
2430 | 3352114 | more_data = hls_coding_quadtree(lc, x0, y0, log2_cb_size - 1, cb_depth + 1); | |
2431 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3352112 times.
|
3352114 | if (more_data < 0) |
2432 | 2 | return more_data; | |
2433 | |||
2434 |
4/4✓ Branch 0 taken 3352103 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3324206 times.
✓ Branch 3 taken 27897 times.
|
3352112 | if (more_data && x1 < s->ps.sps->width) { |
2435 | 3324206 | more_data = hls_coding_quadtree(lc, x1, y0, log2_cb_size - 1, cb_depth + 1); | |
2436 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3324206 times.
|
3324206 | if (more_data < 0) |
2437 | ✗ | return more_data; | |
2438 | } | ||
2439 |
4/4✓ Branch 0 taken 3341872 times.
✓ Branch 1 taken 10240 times.
✓ Branch 2 taken 3143163 times.
✓ Branch 3 taken 198709 times.
|
3352112 | if (more_data && y1 < s->ps.sps->height) { |
2440 | 3143163 | more_data = hls_coding_quadtree(lc, x0, y1, log2_cb_size - 1, cb_depth + 1); | |
2441 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3143163 times.
|
3143163 | if (more_data < 0) |
2442 | ✗ | return more_data; | |
2443 | } | ||
2444 |
4/4✓ Branch 0 taken 3335763 times.
✓ Branch 1 taken 16349 times.
✓ Branch 2 taken 3313975 times.
✓ Branch 3 taken 21788 times.
|
3352112 | if (more_data && x1 < s->ps.sps->width && |
2445 |
2/2✓ Branch 0 taken 3115266 times.
✓ Branch 1 taken 198709 times.
|
3313975 | y1 < s->ps.sps->height) { |
2446 | 3115266 | more_data = hls_coding_quadtree(lc, x1, y1, log2_cb_size - 1, cb_depth + 1); | |
2447 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3115265 times.
|
3115266 | if (more_data < 0) |
2448 | 1 | return more_data; | |
2449 | } | ||
2450 | |||
2451 |
2/2✓ Branch 0 taken 1886590 times.
✓ Branch 1 taken 1465521 times.
|
3352111 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
2452 |
2/2✓ Branch 0 taken 1407894 times.
✓ Branch 1 taken 478696 times.
|
1886590 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) |
2453 | 1407894 | lc->qPy_pred = lc->qp_y; | |
2454 | |||
2455 |
2/2✓ Branch 0 taken 3316544 times.
✓ Branch 1 taken 35567 times.
|
3352111 | if (more_data) |
2456 |
2/2✓ Branch 0 taken 91172 times.
✓ Branch 1 taken 3225372 times.
|
3407716 | return ((x1 + cb_size_split) < s->ps.sps->width || |
2457 |
2/2✓ Branch 0 taken 91171 times.
✓ Branch 1 taken 1 times.
|
91172 | (y1 + cb_size_split) < s->ps.sps->height); |
2458 | else | ||
2459 | 35567 | return 0; | |
2460 | } else { | ||
2461 | 10997831 | ret = hls_coding_unit(lc, s, x0, y0, log2_cb_size); | |
2462 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10997830 times.
|
10997831 | if (ret < 0) |
2463 | 1 | return ret; | |
2464 | 10997830 | if ((!((x0 + cb_size) % | |
2465 |
2/2✓ Branch 0 taken 8030603 times.
✓ Branch 1 taken 2967227 times.
|
10997830 | (1 << (s->ps.sps->log2_ctb_size))) || |
2466 |
2/2✓ Branch 0 taken 71205 times.
✓ Branch 1 taken 7959398 times.
|
8030603 | (x0 + cb_size >= s->ps.sps->width)) && |
2467 | 3038432 | (!((y0 + cb_size) % | |
2468 |
2/2✓ Branch 0 taken 1719572 times.
✓ Branch 1 taken 1318860 times.
|
3038432 | (1 << (s->ps.sps->log2_ctb_size))) || |
2469 |
2/2✓ Branch 0 taken 96335 times.
✓ Branch 1 taken 1623237 times.
|
1719572 | (y0 + cb_size >= s->ps.sps->height))) { |
2470 | 1415195 | int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc); | |
2471 | 1415195 | return !end_of_slice_flag; | |
2472 | } else { | ||
2473 | 9582635 | return 1; | |
2474 | } | ||
2475 | } | ||
2476 | |||
2477 | return 0; | ||
2478 | } | ||
2479 | |||
2480 | 1415196 | static void hls_decode_neighbour(HEVCLocalContext *lc, int x_ctb, int y_ctb, | |
2481 | int ctb_addr_ts) | ||
2482 | { | ||
2483 | 1415196 | const HEVCContext *const s = lc->parent; | |
2484 | 1415196 | int ctb_size = 1 << s->ps.sps->log2_ctb_size; | |
2485 | 1415196 | int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2486 | 1415196 | int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr; | |
2487 | |||
2488 | 1415196 | s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr; | |
2489 | |||
2490 |
2/2✓ Branch 0 taken 103324 times.
✓ Branch 1 taken 1311872 times.
|
1415196 | if (s->ps.pps->entropy_coding_sync_enabled_flag) { |
2491 |
3/4✓ Branch 0 taken 5634 times.
✓ Branch 1 taken 97690 times.
✓ Branch 2 taken 5634 times.
✗ Branch 3 not taken.
|
103324 | if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0) |
2492 | 5634 | lc->first_qp_group = 1; | |
2493 | 103324 | lc->end_of_tiles_x = s->ps.sps->width; | |
2494 |
2/2✓ Branch 0 taken 290050 times.
✓ Branch 1 taken 1021822 times.
|
1311872 | } else if (s->ps.pps->tiles_enabled_flag) { |
2495 |
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]) { |
2496 | 6285 | int idxX = s->ps.pps->col_idxX[x_ctb >> s->ps.sps->log2_ctb_size]; | |
2497 | 6285 | lc->end_of_tiles_x = x_ctb + (s->ps.pps->column_width[idxX] << s->ps.sps->log2_ctb_size); | |
2498 | 6285 | lc->first_qp_group = 1; | |
2499 | } | ||
2500 | } else { | ||
2501 | 1021822 | lc->end_of_tiles_x = s->ps.sps->width; | |
2502 | } | ||
2503 | |||
2504 | 1415196 | lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->ps.sps->height); | |
2505 | |||
2506 | 1415196 | lc->boundary_flags = 0; | |
2507 |
2/2✓ Branch 0 taken 290050 times.
✓ Branch 1 taken 1125146 times.
|
1415196 | if (s->ps.pps->tiles_enabled_flag) { |
2508 |
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]]) |
2509 | 30707 | lc->boundary_flags |= BOUNDARY_LEFT_TILE; | |
2510 |
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]) |
2511 | 3695 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
2512 |
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]]) |
2513 | 33781 | lc->boundary_flags |= BOUNDARY_UPPER_TILE; | |
2514 |
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]) |
2515 | 14490 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
2516 | } else { | ||
2517 |
2/2✓ Branch 0 taken 17602 times.
✓ Branch 1 taken 1107544 times.
|
1125146 | if (ctb_addr_in_slice <= 0) |
2518 | 17602 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
2519 |
2/2✓ Branch 0 taken 184906 times.
✓ Branch 1 taken 940240 times.
|
1125146 | if (ctb_addr_in_slice < s->ps.sps->ctb_width) |
2520 | 184906 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
2521 | } | ||
2522 | |||
2523 |
6/6✓ Branch 0 taken 1341890 times.
✓ Branch 1 taken 73306 times.
✓ Branch 2 taken 1334003 times.
✓ Branch 3 taken 7887 times.
✓ Branch 4 taken 1304322 times.
✓ Branch 5 taken 29681 times.
|
1415196 | lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE)); |
2524 |
6/6✓ Branch 0 taken 1295870 times.
✓ Branch 1 taken 119326 times.
✓ Branch 2 taken 1202061 times.
✓ Branch 3 taken 93809 times.
✓ Branch 4 taken 1181941 times.
✓ Branch 5 taken 20120 times.
|
1415196 | lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->ps.sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE)); |
2525 |
6/6✓ Branch 0 taken 1295870 times.
✓ Branch 1 taken 119326 times.
✓ Branch 2 taken 1204647 times.
✓ Branch 3 taken 91223 times.
✓ Branch 4 taken 1148983 times.
✓ Branch 5 taken 55664 times.
|
1415196 | 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]])); |
2526 |
8/8✓ Branch 0 taken 1341890 times.
✓ Branch 1 taken 73306 times.
✓ Branch 2 taken 1232099 times.
✓ Branch 3 taken 109791 times.
✓ Branch 4 taken 1143353 times.
✓ Branch 5 taken 88746 times.
✓ Branch 6 taken 1099163 times.
✓ Branch 7 taken 44190 times.
|
1415196 | 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]])); |
2527 | 1415196 | } | |
2528 | |||
2529 | 27524 | static int hls_decode_entry(AVCodecContext *avctxt, void *arg) | |
2530 | { | ||
2531 | 27524 | HEVCContext *s = avctxt->priv_data; | |
2532 | 27524 | HEVCLocalContext *const lc = s->HEVClc; | |
2533 | 27524 | int ctb_size = 1 << s->ps.sps->log2_ctb_size; | |
2534 | 27524 | int more_data = 1; | |
2535 | 27524 | int x_ctb = 0; | |
2536 | 27524 | int y_ctb = 0; | |
2537 | 27524 | int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
2538 | int ret; | ||
2539 | |||
2540 |
3/4✓ Branch 0 taken 9535 times.
✓ Branch 1 taken 17989 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9535 times.
|
27524 | if (!ctb_addr_ts && s->sh.dependent_slice_segment_flag) { |
2541 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Impossible initial tile.\n"); | |
2542 | ✗ | return AVERROR_INVALIDDATA; | |
2543 | } | ||
2544 | |||
2545 |
2/2✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 19577 times.
|
27524 | if (s->sh.dependent_slice_segment_flag) { |
2546 | 7947 | int prev_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1]; | |
2547 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
|
7947 | if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) { |
2548 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n"); | |
2549 | ✗ | return AVERROR_INVALIDDATA; | |
2550 | } | ||
2551 | } | ||
2552 | |||
2553 |
3/4✓ Branch 0 taken 1415196 times.
✓ Branch 1 taken 27523 times.
✓ Branch 2 taken 1415196 times.
✗ Branch 3 not taken.
|
1442719 | while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) { |
2554 | 1415196 | int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2555 | |||
2556 | 1415196 | x_ctb = (ctb_addr_rs % ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size; | |
2557 | 1415196 | y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size; | |
2558 | 1415196 | hls_decode_neighbour(lc, x_ctb, y_ctb, ctb_addr_ts); | |
2559 | |||
2560 | 1415196 | ret = ff_hevc_cabac_init(lc, ctb_addr_ts); | |
2561 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1415196 times.
|
1415196 | if (ret < 0) { |
2562 | ✗ | s->tab_slice_address[ctb_addr_rs] = -1; | |
2563 | ✗ | return ret; | |
2564 | } | ||
2565 | |||
2566 | 1415196 | hls_sao_param(lc, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size); | |
2567 | |||
2568 | 1415196 | s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
2569 | 1415196 | s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
2570 | 1415196 | s->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
2571 | |||
2572 | 1415196 | more_data = hls_coding_quadtree(lc, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0); | |
2573 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1415195 times.
|
1415196 | if (more_data < 0) { |
2574 | 1 | s->tab_slice_address[ctb_addr_rs] = -1; | |
2575 | 1 | return more_data; | |
2576 | } | ||
2577 | |||
2578 | |||
2579 | 1415195 | ctb_addr_ts++; | |
2580 | 1415195 | ff_hevc_save_states(lc, ctb_addr_ts); | |
2581 | 1415195 | ff_hevc_hls_filters(lc, x_ctb, y_ctb, ctb_size); | |
2582 | } | ||
2583 | |||
2584 |
2/2✓ Branch 0 taken 14015 times.
✓ Branch 1 taken 13508 times.
|
27523 | if (x_ctb + ctb_size >= s->ps.sps->width && |
2585 |
2/2✓ Branch 0 taken 9534 times.
✓ Branch 1 taken 4481 times.
|
14015 | y_ctb + ctb_size >= s->ps.sps->height) |
2586 | 9534 | ff_hevc_hls_filter(lc, x_ctb, y_ctb, ctb_size); | |
2587 | |||
2588 | 27523 | return ctb_addr_ts; | |
2589 | } | ||
2590 | |||
2591 | 27524 | static int hls_slice_data(HEVCContext *s) | |
2592 | { | ||
2593 | 27524 | int ret = 0; | |
2594 | |||
2595 | 27524 | s->avctx->execute(s->avctx, hls_decode_entry, NULL, &ret , 1, 0); | |
2596 | 27524 | return ret; | |
2597 | } | ||
2598 | ✗ | static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist, | |
2599 | int job, int self_id) | ||
2600 | { | ||
2601 | ✗ | HEVCLocalContext *lc = ((HEVCLocalContext**)hevc_lclist)[self_id]; | |
2602 | ✗ | const HEVCContext *const s = lc->parent; | |
2603 | ✗ | int ctb_size = 1 << s->ps.sps->log2_ctb_size; | |
2604 | ✗ | int more_data = 1; | |
2605 | ✗ | int ctb_row = job; | |
2606 | ✗ | int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size); | |
2607 | ✗ | int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs]; | |
2608 | ✗ | int thread = ctb_row % s->threads_number; | |
2609 | int ret; | ||
2610 | |||
2611 | ✗ | if(ctb_row) { | |
2612 | ✗ | ret = init_get_bits8(&lc->gb, s->data + s->sh.offset[ctb_row - 1], s->sh.size[ctb_row - 1]); | |
2613 | ✗ | if (ret < 0) | |
2614 | ✗ | goto error; | |
2615 | ✗ | ff_init_cabac_decoder(&lc->cc, s->data + s->sh.offset[(ctb_row)-1], s->sh.size[ctb_row - 1]); | |
2616 | } | ||
2617 | |||
2618 | ✗ | while(more_data && ctb_addr_ts < s->ps.sps->ctb_size) { | |
2619 | ✗ | int x_ctb = (ctb_addr_rs % s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size; | |
2620 | ✗ | int y_ctb = (ctb_addr_rs / s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size; | |
2621 | |||
2622 | ✗ | hls_decode_neighbour(lc, x_ctb, y_ctb, ctb_addr_ts); | |
2623 | |||
2624 | ✗ | ff_thread_await_progress2(s->avctx, ctb_row, thread, SHIFT_CTB_WPP); | |
2625 | |||
2626 | /* atomic_load's prototype requires a pointer to non-const atomic variable | ||
2627 | * (due to implementations via mutexes, where reads involve writes). | ||
2628 | * Of course, casting const away here is nevertheless safe. */ | ||
2629 | ✗ | if (atomic_load((atomic_int*)&s->wpp_err)) { | |
2630 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP); | |
2631 | ✗ | return 0; | |
2632 | } | ||
2633 | |||
2634 | ✗ | ret = ff_hevc_cabac_init(lc, ctb_addr_ts); | |
2635 | ✗ | if (ret < 0) | |
2636 | ✗ | goto error; | |
2637 | ✗ | hls_sao_param(lc, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size); | |
2638 | ✗ | more_data = hls_coding_quadtree(lc, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0); | |
2639 | |||
2640 | ✗ | if (more_data < 0) { | |
2641 | ✗ | ret = more_data; | |
2642 | ✗ | goto error; | |
2643 | } | ||
2644 | |||
2645 | ✗ | ctb_addr_ts++; | |
2646 | |||
2647 | ✗ | ff_hevc_save_states(lc, ctb_addr_ts); | |
2648 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row, thread, 1); | |
2649 | ✗ | ff_hevc_hls_filters(lc, x_ctb, y_ctb, ctb_size); | |
2650 | |||
2651 | ✗ | if (!more_data && (x_ctb+ctb_size) < s->ps.sps->width && ctb_row != s->sh.num_entry_point_offsets) { | |
2652 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
2653 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
2654 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP); | |
2655 | ✗ | return 0; | |
2656 | } | ||
2657 | |||
2658 | ✗ | if ((x_ctb+ctb_size) >= s->ps.sps->width && (y_ctb+ctb_size) >= s->ps.sps->height ) { | |
2659 | ✗ | ff_hevc_hls_filter(lc, x_ctb, y_ctb, ctb_size); | |
2660 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP); | |
2661 | ✗ | return ctb_addr_ts; | |
2662 | } | ||
2663 | ✗ | ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2664 | ✗ | x_ctb+=ctb_size; | |
2665 | |||
2666 | ✗ | if(x_ctb >= s->ps.sps->width) { | |
2667 | ✗ | break; | |
2668 | } | ||
2669 | } | ||
2670 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP); | |
2671 | |||
2672 | ✗ | return 0; | |
2673 | ✗ | error: | |
2674 | ✗ | s->tab_slice_address[ctb_addr_rs] = -1; | |
2675 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
2676 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
2677 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP); | |
2678 | ✗ | return ret; | |
2679 | } | ||
2680 | |||
2681 | ✗ | static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) | |
2682 | { | ||
2683 | ✗ | const uint8_t *data = nal->data; | |
2684 | ✗ | int length = nal->size; | |
2685 | ✗ | HEVCLocalContext *lc = s->HEVClc; | |
2686 | int *ret; | ||
2687 | int64_t offset; | ||
2688 | ✗ | int64_t startheader, cmpt = 0; | |
2689 | ✗ | int i, j, res = 0; | |
2690 | |||
2691 | ✗ | 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) { | |
2692 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n", | |
2693 | s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets, | ||
2694 | ✗ | s->ps.sps->ctb_width, s->ps.sps->ctb_height | |
2695 | ); | ||
2696 | ✗ | return AVERROR_INVALIDDATA; | |
2697 | } | ||
2698 | |||
2699 | ✗ | for (i = 1; i < s->threads_number; i++) { | |
2700 | ✗ | if (s->HEVClcList[i]) | |
2701 | ✗ | continue; | |
2702 | ✗ | s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); | |
2703 | ✗ | if (!s->HEVClcList[i]) | |
2704 | ✗ | return AVERROR(ENOMEM); | |
2705 | ✗ | s->HEVClcList[i]->logctx = s->avctx; | |
2706 | ✗ | s->HEVClcList[i]->parent = s; | |
2707 | ✗ | s->HEVClcList[i]->common_cabac_state = &s->cabac; | |
2708 | } | ||
2709 | |||
2710 | ✗ | offset = (lc->gb.index >> 3); | |
2711 | |||
2712 | ✗ | for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) { | |
2713 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
2714 | ✗ | startheader--; | |
2715 | ✗ | cmpt++; | |
2716 | } | ||
2717 | } | ||
2718 | |||
2719 | ✗ | for (i = 1; i < s->sh.num_entry_point_offsets; i++) { | |
2720 | ✗ | offset += (s->sh.entry_point_offset[i - 1] - cmpt); | |
2721 | ✗ | for (j = 0, cmpt = 0, startheader = offset | |
2722 | ✗ | + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) { | |
2723 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
2724 | ✗ | startheader--; | |
2725 | ✗ | cmpt++; | |
2726 | } | ||
2727 | } | ||
2728 | ✗ | s->sh.size[i - 1] = s->sh.entry_point_offset[i] - cmpt; | |
2729 | ✗ | s->sh.offset[i - 1] = offset; | |
2730 | |||
2731 | } | ||
2732 | ✗ | if (s->sh.num_entry_point_offsets != 0) { | |
2733 | ✗ | offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt; | |
2734 | ✗ | if (length < offset) { | |
2735 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n"); | |
2736 | ✗ | return AVERROR_INVALIDDATA; | |
2737 | } | ||
2738 | ✗ | s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset; | |
2739 | ✗ | s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset; | |
2740 | |||
2741 | } | ||
2742 | ✗ | s->data = data; | |
2743 | |||
2744 | ✗ | for (i = 1; i < s->threads_number; i++) { | |
2745 | ✗ | s->HEVClcList[i]->first_qp_group = 1; | |
2746 | ✗ | s->HEVClcList[i]->qp_y = s->HEVClc->qp_y; | |
2747 | } | ||
2748 | |||
2749 | ✗ | atomic_store(&s->wpp_err, 0); | |
2750 | ✗ | res = ff_slice_thread_allocz_entries(s->avctx, s->sh.num_entry_point_offsets + 1); | |
2751 | ✗ | if (res < 0) | |
2752 | ✗ | return res; | |
2753 | |||
2754 | ✗ | ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret)); | |
2755 | ✗ | if (!ret) | |
2756 | ✗ | return AVERROR(ENOMEM); | |
2757 | |||
2758 | ✗ | if (s->ps.pps->entropy_coding_sync_enabled_flag) | |
2759 | ✗ | s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->HEVClcList, ret, s->sh.num_entry_point_offsets + 1); | |
2760 | |||
2761 | ✗ | for (i = 0; i <= s->sh.num_entry_point_offsets; i++) | |
2762 | ✗ | res += ret[i]; | |
2763 | |||
2764 | ✗ | av_free(ret); | |
2765 | ✗ | return res; | |
2766 | } | ||
2767 | |||
2768 | 9535 | static int set_side_data(HEVCContext *s) | |
2769 | { | ||
2770 | 9535 | AVFrame *out = s->ref->frame; | |
2771 | int ret; | ||
2772 | |||
2773 | // Decrement the mastering display and content light level flag when IRAP | ||
2774 | // frame has no_rasl_output_flag=1 so the side data persists for the entire | ||
2775 | // coded video sequence. | ||
2776 |
5/6✓ Branch 0 taken 548 times.
✓ Branch 1 taken 8987 times.
✓ Branch 2 taken 548 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✓ Branch 5 taken 149 times.
|
9535 | if (IS_IRAP(s) && s->no_rasl_output_flag) { |
2777 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 393 times.
|
399 | if (s->sei.common.mastering_display.present > 0) |
2778 | 6 | s->sei.common.mastering_display.present--; | |
2779 | |||
2780 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 395 times.
|
399 | if (s->sei.common.content_light.present > 0) |
2781 | 4 | s->sei.common.content_light.present--; | |
2782 | } | ||
2783 | |||
2784 | 9535 | ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx, | |
2785 | 9535 | &s->ps.sps->vui.common, | |
2786 | 9535 | s->ps.sps->bit_depth, s->ps.sps->bit_depth_chroma, | |
2787 | 9535 | s->ref->poc /* no poc_offset in HEVC */); | |
2788 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9535 times.
|
9535 | if (ret < 0) |
2789 | ✗ | return ret; | |
2790 | |||
2791 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 9515 times.
|
9535 | if (s->sei.timecode.present) { |
2792 | uint32_t *tc_sd; | ||
2793 | char tcbuf[AV_TIMECODE_STR_SIZE]; | ||
2794 | AVFrameSideData *tcside; | ||
2795 | 20 | ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE, | |
2796 | sizeof(uint32_t) * 4, &tcside); | ||
2797 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (ret < 0) |
2798 | ✗ | return ret; | |
2799 | |||
2800 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (tcside) { |
2801 | 20 | tc_sd = (uint32_t*)tcside->data; | |
2802 | 20 | tc_sd[0] = s->sei.timecode.num_clock_ts; | |
2803 | |||
2804 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | for (int i = 0; i < tc_sd[0]; i++) { |
2805 | 20 | int drop = s->sei.timecode.cnt_dropped_flag[i]; | |
2806 | 20 | int hh = s->sei.timecode.hours_value[i]; | |
2807 | 20 | int mm = s->sei.timecode.minutes_value[i]; | |
2808 | 20 | int ss = s->sei.timecode.seconds_value[i]; | |
2809 | 20 | int ff = s->sei.timecode.n_frames[i]; | |
2810 | |||
2811 | 20 | tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff); | |
2812 | 20 | av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0); | |
2813 | 20 | av_dict_set(&out->metadata, "timecode", tcbuf, 0); | |
2814 | } | ||
2815 | } | ||
2816 | |||
2817 | 20 | s->sei.timecode.num_clock_ts = 0; | |
2818 | } | ||
2819 | |||
2820 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9533 times.
|
9535 | if (s->sei.common.dynamic_hdr_plus.info) { |
2821 | 2 | AVBufferRef *info_ref = av_buffer_ref(s->sei.common.dynamic_hdr_plus.info); | |
2822 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!info_ref) |
2823 | ✗ | return AVERROR(ENOMEM); | |
2824 | |||
2825 | 2 | ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref, NULL); | |
2826 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ret < 0) |
2827 | ✗ | return ret; | |
2828 | } | ||
2829 | |||
2830 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9533 times.
|
9535 | if (s->rpu_buf) { |
2831 | 2 | AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf); | |
2832 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!rpu) |
2833 | ✗ | return AVERROR(ENOMEM); | |
2834 | |||
2835 | 2 | s->rpu_buf = NULL; | |
2836 | } | ||
2837 | |||
2838 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9535 times.
|
9535 | if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0) |
2839 | ✗ | return ret; | |
2840 | |||
2841 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9533 times.
|
9535 | if (s->sei.common.dynamic_hdr_vivid.info) { |
2842 | 2 | AVBufferRef *info_ref = av_buffer_ref(s->sei.common.dynamic_hdr_vivid.info); | |
2843 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!info_ref) |
2844 | ✗ | return AVERROR(ENOMEM); | |
2845 | |||
2846 |
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_VIVID, info_ref)) { |
2847 | ✗ | av_buffer_unref(&info_ref); | |
2848 | ✗ | return AVERROR(ENOMEM); | |
2849 | } | ||
2850 | } | ||
2851 | |||
2852 | 9535 | return 0; | |
2853 | } | ||
2854 | |||
2855 | 9535 | static int hevc_frame_start(HEVCContext *s) | |
2856 | { | ||
2857 | 9535 | HEVCLocalContext *lc = s->HEVClc; | |
2858 | 9535 | int pic_size_in_ctb = ((s->ps.sps->width >> s->ps.sps->log2_min_cb_size) + 1) * | |
2859 | 9535 | ((s->ps.sps->height >> s->ps.sps->log2_min_cb_size) + 1); | |
2860 | int ret; | ||
2861 | |||
2862 | 9535 | memset(s->horizontal_bs, 0, s->bs_width * s->bs_height); | |
2863 | 9535 | memset(s->vertical_bs, 0, s->bs_width * s->bs_height); | |
2864 | 9535 | memset(s->cbf_luma, 0, s->ps.sps->min_tb_width * s->ps.sps->min_tb_height); | |
2865 | 9535 | memset(s->is_pcm, 0, (s->ps.sps->min_pu_width + 1) * (s->ps.sps->min_pu_height + 1)); | |
2866 | 9535 | memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address)); | |
2867 | |||
2868 | 9535 | s->is_decoded = 0; | |
2869 | 9535 | s->first_nal_type = s->nal_unit_type; | |
2870 | |||
2871 |
14/14✓ Branch 0 taken 9170 times.
✓ Branch 1 taken 365 times.
✓ Branch 2 taken 9154 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 9152 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9145 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9144 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 157 times.
✓ Branch 11 taken 8987 times.
✓ Branch 12 taken 8 times.
✓ Branch 13 taken 149 times.
|
9535 | s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos); |
2872 | |||
2873 |
2/2✓ Branch 0 taken 624 times.
✓ Branch 1 taken 8911 times.
|
9535 | if (s->ps.pps->tiles_enabled_flag) |
2874 | 624 | lc->end_of_tiles_x = s->ps.pps->column_width[0] << s->ps.sps->log2_ctb_size; | |
2875 | |||
2876 | 9535 | ret = ff_hevc_set_new_ref(s, &s->frame, s->poc); | |
2877 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9535 times.
|
9535 | if (ret < 0) |
2878 | ✗ | goto fail; | |
2879 | |||
2880 | 9535 | ret = ff_hevc_frame_rps(s); | |
2881 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9535 times.
|
9535 | if (ret < 0) { |
2882 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n"); | |
2883 | ✗ | goto fail; | |
2884 | } | ||
2885 | |||
2886 |
3/4✓ Branch 0 taken 548 times.
✓ Branch 1 taken 8987 times.
✓ Branch 2 taken 548 times.
✗ Branch 3 not taken.
|
9535 | if (IS_IRAP(s)) |
2887 | 548 | s->ref->frame->flags |= AV_FRAME_FLAG_KEY; | |
2888 | else | ||
2889 | 8987 | s->ref->frame->flags &= ~AV_FRAME_FLAG_KEY; | |
2890 | |||
2891 | 28605 | s->ref->needs_fg = (s->sei.common.film_grain_characteristics.present || | |
2892 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9535 times.
|
9535 | s->sei.common.aom_film_grain.enable) && |
2893 |
1/4✓ Branch 0 taken 9535 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
19070 | !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && |
2894 | ✗ | !s->avctx->hwaccel; | |
2895 | |||
2896 | 9535 | ret = set_side_data(s); | |
2897 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9535 times.
|
9535 | if (ret < 0) |
2898 | ✗ | goto fail; | |
2899 | |||
2900 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9535 times.
|
9535 | if (s->ref->needs_fg && |
2901 | ✗ | ( s->sei.common.film_grain_characteristics.present && | |
2902 | ✗ | !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics.model_id, | |
2903 | ✗ | s->ref->frame->format)) | |
2904 |
1/2✓ Branch 1 taken 9535 times.
✗ Branch 2 not taken.
|
9535 | || !av_film_grain_params_select(s->ref->frame)) { |
2905 | 9535 | av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown, | |
2906 | "Unsupported film grain parameters. Ignoring film grain.\n"); | ||
2907 | 9535 | s->ref->needs_fg = 0; | |
2908 | } | ||
2909 | |||
2910 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9535 times.
|
9535 | if (s->ref->needs_fg) { |
2911 | ✗ | s->ref->frame_grain->format = s->ref->frame->format; | |
2912 | ✗ | s->ref->frame_grain->width = s->ref->frame->width; | |
2913 | ✗ | s->ref->frame_grain->height = s->ref->frame->height; | |
2914 | ✗ | if ((ret = ff_thread_get_buffer(s->avctx, s->ref->frame_grain, 0)) < 0) | |
2915 | ✗ | goto fail; | |
2916 | } | ||
2917 | |||
2918 | 9535 | s->frame->pict_type = 3 - s->sh.slice_type; | |
2919 | |||
2920 |
3/4✓ Branch 0 taken 548 times.
✓ Branch 1 taken 8987 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 548 times.
|
9535 | if (!IS_IRAP(s)) |
2921 | 8987 | ff_hevc_bump_frame(s); | |
2922 | |||
2923 | 9535 | av_frame_unref(s->output_frame); | |
2924 | 9535 | ret = ff_hevc_output_frame(s, s->output_frame, 0); | |
2925 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9535 times.
|
9535 | if (ret < 0) |
2926 | ✗ | goto fail; | |
2927 | |||
2928 |
1/2✓ Branch 0 taken 9535 times.
✗ Branch 1 not taken.
|
9535 | if (!s->avctx->hwaccel) |
2929 | 9535 | ff_thread_finish_setup(s->avctx); | |
2930 | |||
2931 | 9535 | return 0; | |
2932 | |||
2933 | ✗ | fail: | |
2934 | ✗ | if (s->ref) | |
2935 | ✗ | ff_hevc_unref_frame(s->ref, ~0); | |
2936 | ✗ | s->ref = s->collocated_ref = NULL; | |
2937 | ✗ | return ret; | |
2938 | } | ||
2939 | |||
2940 | 9534 | static int hevc_frame_end(HEVCContext *s) | |
2941 | { | ||
2942 | 9534 | HEVCFrame *out = s->ref; | |
2943 | const AVFilmGrainParams *fgp; | ||
2944 | av_unused int ret; | ||
2945 | |||
2946 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9534 times.
|
9534 | if (out->needs_fg) { |
2947 | ✗ | av_assert0(out->frame_grain->buf[0]); | |
2948 | ✗ | fgp = av_film_grain_params_select(out->frame); | |
2949 | ✗ | switch (fgp->type) { | |
2950 | ✗ | case AV_FILM_GRAIN_PARAMS_NONE: | |
2951 | ✗ | av_assert0(0); | |
2952 | return AVERROR_BUG; | ||
2953 | ✗ | case AV_FILM_GRAIN_PARAMS_H274: | |
2954 | ✗ | ret = ff_h274_apply_film_grain(out->frame_grain, out->frame, | |
2955 | &s->h274db, fgp); | ||
2956 | ✗ | break; | |
2957 | ✗ | case AV_FILM_GRAIN_PARAMS_AV1: | |
2958 | ✗ | ret = ff_aom_apply_film_grain(out->frame_grain, out->frame, fgp); | |
2959 | ✗ | break; | |
2960 | } | ||
2961 | av_assert1(ret >= 0); | ||
2962 | } | ||
2963 | |||
2964 | 9534 | return 0; | |
2965 | } | ||
2966 | |||
2967 | 38120 | static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) | |
2968 | { | ||
2969 | 38120 | HEVCLocalContext *lc = s->HEVClc; | |
2970 | 38120 | GetBitContext *gb = &lc->gb; | |
2971 | int ctb_addr_ts, ret; | ||
2972 | |||
2973 | 38120 | *gb = nal->gb; | |
2974 | 38120 | s->nal_unit_type = nal->type; | |
2975 | 38120 | s->temporal_id = nal->temporal_id; | |
2976 | |||
2977 |
7/8✓ Branch 0 taken 412 times.
✓ Branch 1 taken 409 times.
✓ Branch 2 taken 1369 times.
✓ Branch 3 taken 7607 times.
✓ Branch 4 taken 27646 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 673 times.
✗ Branch 7 not taken.
|
38120 | switch (s->nal_unit_type) { |
2978 | 412 | case HEVC_NAL_VPS: | |
2979 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 412 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
412 | if (FF_HW_HAS_CB(s->avctx, decode_params)) { |
2980 | ✗ | ret = FF_HW_CALL(s->avctx, decode_params, | |
2981 | nal->type, nal->raw_data, nal->raw_size); | ||
2982 | ✗ | if (ret < 0) | |
2983 | ✗ | goto fail; | |
2984 | } | ||
2985 | 412 | ret = ff_hevc_decode_nal_vps(gb, s->avctx, &s->ps); | |
2986 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 412 times.
|
412 | if (ret < 0) |
2987 | ✗ | goto fail; | |
2988 | 412 | break; | |
2989 | 409 | case HEVC_NAL_SPS: | |
2990 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 409 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
409 | if (FF_HW_HAS_CB(s->avctx, decode_params)) { |
2991 | ✗ | ret = FF_HW_CALL(s->avctx, decode_params, | |
2992 | nal->type, nal->raw_data, nal->raw_size); | ||
2993 | ✗ | if (ret < 0) | |
2994 | ✗ | goto fail; | |
2995 | } | ||
2996 | 409 | ret = ff_hevc_decode_nal_sps(gb, s->avctx, &s->ps, | |
2997 | s->apply_defdispwin); | ||
2998 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 409 times.
|
409 | if (ret < 0) |
2999 | ✗ | goto fail; | |
3000 | 409 | break; | |
3001 | 1369 | case HEVC_NAL_PPS: | |
3002 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1369 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1369 | if (FF_HW_HAS_CB(s->avctx, decode_params)) { |
3003 | ✗ | ret = FF_HW_CALL(s->avctx, decode_params, | |
3004 | nal->type, nal->raw_data, nal->raw_size); | ||
3005 | ✗ | if (ret < 0) | |
3006 | ✗ | goto fail; | |
3007 | } | ||
3008 | 1369 | ret = ff_hevc_decode_nal_pps(gb, s->avctx, &s->ps); | |
3009 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1367 times.
|
1369 | if (ret < 0) |
3010 | 2 | goto fail; | |
3011 | 1367 | break; | |
3012 | 7607 | case HEVC_NAL_SEI_PREFIX: | |
3013 | case HEVC_NAL_SEI_SUFFIX: | ||
3014 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7607 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
7607 | if (FF_HW_HAS_CB(s->avctx, decode_params)) { |
3015 | ✗ | ret = FF_HW_CALL(s->avctx, decode_params, | |
3016 | nal->type, nal->raw_data, nal->raw_size); | ||
3017 | ✗ | if (ret < 0) | |
3018 | ✗ | goto fail; | |
3019 | } | ||
3020 | 7607 | ret = ff_hevc_decode_nal_sei(gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type); | |
3021 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7574 times.
|
7607 | if (ret < 0) |
3022 | 33 | goto fail; | |
3023 | 7574 | break; | |
3024 | 27646 | case HEVC_NAL_TRAIL_R: | |
3025 | case HEVC_NAL_TRAIL_N: | ||
3026 | case HEVC_NAL_TSA_N: | ||
3027 | case HEVC_NAL_TSA_R: | ||
3028 | case HEVC_NAL_STSA_N: | ||
3029 | case HEVC_NAL_STSA_R: | ||
3030 | case HEVC_NAL_BLA_W_LP: | ||
3031 | case HEVC_NAL_BLA_W_RADL: | ||
3032 | case HEVC_NAL_BLA_N_LP: | ||
3033 | case HEVC_NAL_IDR_W_RADL: | ||
3034 | case HEVC_NAL_IDR_N_LP: | ||
3035 | case HEVC_NAL_CRA_NUT: | ||
3036 | case HEVC_NAL_RADL_N: | ||
3037 | case HEVC_NAL_RADL_R: | ||
3038 | case HEVC_NAL_RASL_N: | ||
3039 | case HEVC_NAL_RASL_R: | ||
3040 | 27646 | ret = hls_slice_header(s); | |
3041 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 27613 times.
|
27646 | if (ret < 0) |
3042 | 33 | return ret; | |
3043 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27612 times.
|
27613 | if (ret == 1) { |
3044 | 1 | ret = AVERROR_INVALIDDATA; | |
3045 | 1 | goto fail; | |
3046 | } | ||
3047 | |||
3048 | |||
3049 | 27612 | if ( | |
3050 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 27612 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
27612 | (s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) || |
3051 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 27612 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
27612 | (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) || |
3052 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 27612 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
27612 | (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s))) { |
3053 | break; | ||
3054 | } | ||
3055 | |||
3056 |
2/2✓ Branch 0 taken 9581 times.
✓ Branch 1 taken 18031 times.
|
27612 | if (s->sh.first_slice_in_pic_flag) { |
3057 |
2/2✓ Branch 0 taken 414 times.
✓ Branch 1 taken 9167 times.
|
9581 | if (s->max_ra == INT_MAX) { |
3058 |
8/8✓ Branch 0 taken 402 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 400 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 393 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 392 times.
|
414 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(s)) { |
3059 | 22 | s->max_ra = s->poc; | |
3060 | } else { | ||
3061 |
4/4✓ Branch 0 taken 27 times.
✓ Branch 1 taken 365 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 11 times.
|
392 | if (IS_IDR(s)) |
3062 | 381 | s->max_ra = INT_MIN; | |
3063 | } | ||
3064 | } | ||
3065 | |||
3066 |
4/4✓ Branch 0 taken 9096 times.
✓ Branch 1 taken 485 times.
✓ Branch 2 taken 361 times.
✓ Branch 3 taken 8735 times.
|
9581 | if ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) && |
3067 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 800 times.
|
846 | s->poc <= s->max_ra) { |
3068 | 46 | s->is_decoded = 0; | |
3069 | 46 | break; | |
3070 | } else { | ||
3071 |
3/4✓ Branch 0 taken 463 times.
✓ Branch 1 taken 9072 times.
✓ Branch 2 taken 463 times.
✗ Branch 3 not taken.
|
9535 | if (s->nal_unit_type == HEVC_NAL_RASL_R && s->poc > s->max_ra) |
3072 | 463 | s->max_ra = INT_MIN; | |
3073 | } | ||
3074 | |||
3075 | 9535 | s->overlap ++; | |
3076 | 9535 | ret = hevc_frame_start(s); | |
3077 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9535 times.
|
9535 | if (ret < 0) |
3078 | ✗ | return ret; | |
3079 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 17989 times.
|
18031 | } else if (!s->ref) { |
3080 | 42 | av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n"); | |
3081 | 42 | goto fail; | |
3082 | } | ||
3083 | |||
3084 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27524 times.
|
27524 | if (s->nal_unit_type != s->first_nal_type) { |
3085 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3086 | "Non-matching NAL types of the VCL NALUs: %d %d\n", | ||
3087 | ✗ | s->first_nal_type, s->nal_unit_type); | |
3088 | ✗ | return AVERROR_INVALIDDATA; | |
3089 | } | ||
3090 | |||
3091 |
2/2✓ Branch 0 taken 19577 times.
✓ Branch 1 taken 7947 times.
|
27524 | if (!s->sh.dependent_slice_segment_flag && |
3092 |
2/2✓ Branch 0 taken 18436 times.
✓ Branch 1 taken 1141 times.
|
19577 | s->sh.slice_type != HEVC_SLICE_I) { |
3093 | 18436 | ret = ff_hevc_slice_rpl(s); | |
3094 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18436 times.
|
18436 | if (ret < 0) { |
3095 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
3096 | "Error constructing the reference lists for the current slice.\n"); | ||
3097 | ✗ | goto fail; | |
3098 | } | ||
3099 | } | ||
3100 | |||
3101 |
3/4✓ Branch 0 taken 9535 times.
✓ Branch 1 taken 17989 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9535 times.
|
27524 | if (s->sh.first_slice_in_pic_flag && s->avctx->hwaccel) { |
3102 | ✗ | ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0); | |
3103 | ✗ | if (ret < 0) | |
3104 | ✗ | goto fail; | |
3105 | } | ||
3106 | |||
3107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27524 times.
|
27524 | if (s->avctx->hwaccel) { |
3108 | ✗ | ret = FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size); | |
3109 | ✗ | if (ret < 0) | |
3110 | ✗ | goto fail; | |
3111 | } else { | ||
3112 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27524 times.
|
27524 | if (s->avctx->profile == AV_PROFILE_HEVC_SCC) { |
3113 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3114 | "SCC profile is not yet implemented in hevc native decoder.\n"); | ||
3115 | ✗ | ret = AVERROR_PATCHWELCOME; | |
3116 | ✗ | goto fail; | |
3117 | } | ||
3118 | |||
3119 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 27524 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
27524 | if (s->threads_number > 1 && s->sh.num_entry_point_offsets > 0) |
3120 | ✗ | ctb_addr_ts = hls_slice_data_wpp(s, nal); | |
3121 | else | ||
3122 | 27524 | ctb_addr_ts = hls_slice_data(s); | |
3123 |
2/2✓ Branch 0 taken 9534 times.
✓ Branch 1 taken 17990 times.
|
27524 | if (ctb_addr_ts >= (s->ps.sps->ctb_width * s->ps.sps->ctb_height)) { |
3124 | 9534 | ret = hevc_frame_end(s); | |
3125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9534 times.
|
9534 | if (ret < 0) |
3126 | ✗ | goto fail; | |
3127 | 9534 | s->is_decoded = 1; | |
3128 | } | ||
3129 | |||
3130 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27523 times.
|
27524 | if (ctb_addr_ts < 0) { |
3131 | 1 | ret = ctb_addr_ts; | |
3132 | 1 | goto fail; | |
3133 | } | ||
3134 | } | ||
3135 | 27523 | break; | |
3136 | 4 | case HEVC_NAL_EOS_NUT: | |
3137 | case HEVC_NAL_EOB_NUT: | ||
3138 | 4 | s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK; | |
3139 | 4 | s->max_ra = INT_MAX; | |
3140 | 4 | break; | |
3141 | 673 | case HEVC_NAL_AUD: | |
3142 | case HEVC_NAL_FD_NUT: | ||
3143 | case HEVC_NAL_UNSPEC62: | ||
3144 | 673 | break; | |
3145 | ✗ | default: | |
3146 | ✗ | av_log(s->avctx, AV_LOG_INFO, | |
3147 | ✗ | "Skipping NAL unit %d\n", s->nal_unit_type); | |
3148 | } | ||
3149 | |||
3150 | 38008 | return 0; | |
3151 | 79 | fail: | |
3152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
|
79 | if (s->avctx->err_recognition & AV_EF_EXPLODE) |
3153 | ✗ | return ret; | |
3154 | 79 | return 0; | |
3155 | } | ||
3156 | |||
3157 | 9615 | static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) | |
3158 | { | ||
3159 | 9615 | int i, ret = 0; | |
3160 | 9615 | int eos_at_start = 1; | |
3161 | |||
3162 | 9615 | s->ref = s->collocated_ref = NULL; | |
3163 | 9615 | s->last_eos = s->eos; | |
3164 | 9615 | s->eos = 0; | |
3165 | 9615 | s->overlap = 0; | |
3166 | |||
3167 | /* split the input packet into NAL units, so we know the upper bound on the | ||
3168 | * number of slices in the frame */ | ||
3169 | 9615 | ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx, s->is_nalff, | |
3170 | 9615 | s->nal_length_size, s->avctx->codec_id, 1, 0); | |
3171 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9615 times.
|
9615 | if (ret < 0) { |
3172 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3173 | "Error splitting the input into NAL units.\n"); | ||
3174 | ✗ | return ret; | |
3175 | } | ||
3176 | |||
3177 |
2/2✓ Branch 0 taken 38120 times.
✓ Branch 1 taken 9615 times.
|
47735 | for (i = 0; i < s->pkt.nb_nals; i++) { |
3178 |
2/2✓ Branch 0 taken 38119 times.
✓ Branch 1 taken 1 times.
|
38120 | if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT || |
3179 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 38116 times.
|
38119 | s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) { |
3180 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (eos_at_start) { |
3181 | 4 | s->last_eos = 1; | |
3182 | } else { | ||
3183 | ✗ | s->eos = 1; | |
3184 | } | ||
3185 | } else { | ||
3186 | 38116 | eos_at_start = 0; | |
3187 | } | ||
3188 | } | ||
3189 | |||
3190 | /* | ||
3191 | * Check for RPU delimiter. | ||
3192 | * | ||
3193 | * Dolby Vision RPUs masquerade as unregistered NALs of type 62. | ||
3194 | * | ||
3195 | * We have to do this check here an create the rpu buffer, since RPUs are appended | ||
3196 | * to the end of an AU; they are the last non-EOB/EOS NAL in the AU. | ||
3197 | */ | ||
3198 |
4/4✓ Branch 0 taken 7695 times.
✓ Branch 1 taken 1920 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 7693 times.
|
9615 | if (s->pkt.nb_nals > 1 && s->pkt.nals[s->pkt.nb_nals - 1].type == HEVC_NAL_UNSPEC62 && |
3199 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | s->pkt.nals[s->pkt.nb_nals - 1].size > 2 && !s->pkt.nals[s->pkt.nb_nals - 1].nuh_layer_id |
3200 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | && !s->pkt.nals[s->pkt.nb_nals - 1].temporal_id) { |
3201 | 2 | H2645NAL *nal = &s->pkt.nals[s->pkt.nb_nals - 1]; | |
3202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (s->rpu_buf) { |
3203 | ✗ | av_buffer_unref(&s->rpu_buf); | |
3204 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n"); | |
3205 | } | ||
3206 | |||
3207 | 2 | s->rpu_buf = av_buffer_alloc(nal->raw_size - 2); | |
3208 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!s->rpu_buf) |
3209 | ✗ | return AVERROR(ENOMEM); | |
3210 | 2 | memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2); | |
3211 | |||
3212 | 2 | ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2, | |
3213 | 2 | s->avctx->err_recognition); | |
3214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ret < 0) { |
3215 | ✗ | av_buffer_unref(&s->rpu_buf); | |
3216 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n"); | |
3217 | /* ignore */ | ||
3218 | } | ||
3219 | } | ||
3220 | |||
3221 | /* decode the NAL units */ | ||
3222 |
2/2✓ Branch 0 taken 38120 times.
✓ Branch 1 taken 9582 times.
|
47702 | for (i = 0; i < s->pkt.nb_nals; i++) { |
3223 | 38120 | H2645NAL *nal = &s->pkt.nals[i]; | |
3224 | |||
3225 |
1/2✓ Branch 0 taken 38120 times.
✗ Branch 1 not taken.
|
38120 | if (s->avctx->skip_frame >= AVDISCARD_ALL || |
3226 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38120 times.
|
38120 | (s->avctx->skip_frame >= AVDISCARD_NONREF |
3227 |
1/4✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 38120 times.
|
38120 | && ff_hevc_nal_is_nonref(nal->type)) || nal->nuh_layer_id > 0) |
3228 | ✗ | continue; | |
3229 | |||
3230 | 38120 | ret = decode_nal_unit(s, nal); | |
3231 |
3/4✓ Branch 0 taken 38087 times.
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 38087 times.
|
38120 | if (ret >= 0 && s->overlap > 2) |
3232 | ✗ | ret = AVERROR_INVALIDDATA; | |
3233 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 38087 times.
|
38120 | if (ret < 0) { |
3234 | 33 | av_log(s->avctx, AV_LOG_WARNING, | |
3235 | "Error parsing NAL unit #%d.\n", i); | ||
3236 | 33 | goto fail; | |
3237 | } | ||
3238 | } | ||
3239 | |||
3240 | 9582 | fail: | |
3241 |
4/4✓ Branch 0 taken 9535 times.
✓ Branch 1 taken 80 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 9502 times.
|
9615 | if (s->ref && s->threads_type == FF_THREAD_FRAME) |
3242 | 33 | ff_thread_report_progress(&s->ref->tf, INT_MAX, 0); | |
3243 | |||
3244 | 9615 | return ret; | |
3245 | } | ||
3246 | |||
3247 | ✗ | static int verify_md5(HEVCContext *s, AVFrame *frame) | |
3248 | { | ||
3249 | ✗ | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); | |
3250 | char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)]; | ||
3251 | int pixel_shift; | ||
3252 | ✗ | int err = 0; | |
3253 | int i, j; | ||
3254 | |||
3255 | ✗ | if (!desc) | |
3256 | ✗ | return AVERROR(EINVAL); | |
3257 | |||
3258 | ✗ | pixel_shift = desc->comp[0].depth > 8; | |
3259 | |||
3260 | /* the checksums are LE, so we have to byteswap for >8bpp formats | ||
3261 | * on BE arches */ | ||
3262 | #if HAVE_BIGENDIAN | ||
3263 | if (pixel_shift && !s->checksum_buf) { | ||
3264 | av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size, | ||
3265 | FFMAX3(frame->linesize[0], frame->linesize[1], | ||
3266 | frame->linesize[2])); | ||
3267 | if (!s->checksum_buf) | ||
3268 | return AVERROR(ENOMEM); | ||
3269 | } | ||
3270 | #endif | ||
3271 | |||
3272 | ✗ | msg_buf[0] = '\0'; | |
3273 | ✗ | for (i = 0; frame->data[i]; i++) { | |
3274 | ✗ | int width = s->avctx->coded_width; | |
3275 | ✗ | int height = s->avctx->coded_height; | |
3276 | ✗ | int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width; | |
3277 | ✗ | int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height; | |
3278 | uint8_t md5[16]; | ||
3279 | |||
3280 | ✗ | av_md5_init(s->md5_ctx); | |
3281 | ✗ | for (j = 0; j < h; j++) { | |
3282 | ✗ | const uint8_t *src = frame->data[i] + j * frame->linesize[i]; | |
3283 | #if HAVE_BIGENDIAN | ||
3284 | if (pixel_shift) { | ||
3285 | s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf, | ||
3286 | (const uint16_t *) src, w); | ||
3287 | src = s->checksum_buf; | ||
3288 | } | ||
3289 | #endif | ||
3290 | ✗ | av_md5_update(s->md5_ctx, src, w << pixel_shift); | |
3291 | } | ||
3292 | ✗ | av_md5_final(s->md5_ctx, md5); | |
3293 | |||
3294 | #define MD5_PRI "%016" PRIx64 "%016" PRIx64 | ||
3295 | #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8) | ||
3296 | |||
3297 | ✗ | if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) { | |
3298 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
3299 | "plane %d - correct " MD5_PRI "; ", | ||
3300 | ✗ | i, MD5_PRI_ARG(md5)); | |
3301 | } else { | ||
3302 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
3303 | "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ", | ||
3304 | ✗ | i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i])); | |
3305 | ✗ | err = AVERROR_INVALIDDATA; | |
3306 | } | ||
3307 | } | ||
3308 | |||
3309 | ✗ | av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG, | |
3310 | "Verifying checksum for frame with POC %d: %s\n", | ||
3311 | s->poc, msg_buf); | ||
3312 | |||
3313 | ✗ | return err; | |
3314 | } | ||
3315 | |||
3316 | 230 | static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first) | |
3317 | { | ||
3318 | int ret, i; | ||
3319 | |||
3320 | 230 | ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff, | |
3321 | 230 | &s->nal_length_size, s->avctx->err_recognition, | |
3322 | 230 | s->apply_defdispwin, s->avctx); | |
3323 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 230 times.
|
230 | if (ret < 0) |
3324 | ✗ | return ret; | |
3325 | |||
3326 | /* export stream parameters from the first SPS */ | ||
3327 |
2/2✓ Branch 0 taken 260 times.
✓ Branch 1 taken 2 times.
|
262 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { |
3328 |
4/4✓ Branch 0 taken 244 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 228 times.
✓ Branch 3 taken 16 times.
|
260 | if (first && s->ps.sps_list[i]) { |
3329 | 228 | const HEVCSPS *sps = s->ps.sps_list[i]; | |
3330 | 228 | export_stream_params(s, sps); | |
3331 | 228 | break; | |
3332 | } | ||
3333 | } | ||
3334 | |||
3335 | /* export stream parameters from SEI */ | ||
3336 | 230 | ret = export_stream_params_from_sei(s); | |
3337 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 230 times.
|
230 | if (ret < 0) |
3338 | ✗ | return ret; | |
3339 | |||
3340 | 230 | return 0; | |
3341 | } | ||
3342 | |||
3343 | 10103 | static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe, | |
3344 | int *got_output, AVPacket *avpkt) | ||
3345 | { | ||
3346 | int ret; | ||
3347 | uint8_t *sd; | ||
3348 | size_t sd_size; | ||
3349 | 10103 | HEVCContext *s = avctx->priv_data; | |
3350 | |||
3351 |
2/2✓ Branch 0 taken 488 times.
✓ Branch 1 taken 9615 times.
|
10103 | if (!avpkt->size) { |
3352 | 488 | ret = ff_hevc_output_frame(s, rframe, 1); | |
3353 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 488 times.
|
488 | if (ret < 0) |
3354 | ✗ | return ret; | |
3355 | |||
3356 | 488 | *got_output = ret; | |
3357 | 488 | return 0; | |
3358 | } | ||
3359 | |||
3360 | 9615 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size); | |
3361 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9614 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
9615 | if (sd && sd_size > 0) { |
3362 | 1 | ret = hevc_decode_extradata(s, sd, sd_size, 0); | |
3363 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
3364 | ✗ | return ret; | |
3365 | } | ||
3366 | |||
3367 | 9615 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size); | |
3368 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 9615 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
9615 | if (sd && sd_size > 0) { |
3369 | ✗ | int old = s->dovi_ctx.dv_profile; | |
3370 | |||
3371 | ✗ | ff_dovi_update_cfg(&s->dovi_ctx, (AVDOVIDecoderConfigurationRecord *) sd); | |
3372 | ✗ | if (old) | |
3373 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
3374 | "New DOVI configuration record from input packet (profile %d -> %u).\n", | ||
3375 | ✗ | old, s->dovi_ctx.dv_profile); | |
3376 | } | ||
3377 | |||
3378 | 9615 | s->ref = s->collocated_ref = NULL; | |
3379 | 9615 | ret = decode_nal_units(s, avpkt->data, avpkt->size); | |
3380 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 9582 times.
|
9615 | if (ret < 0) |
3381 | 33 | return ret; | |
3382 | |||
3383 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9582 times.
|
9582 | if (avctx->hwaccel) { |
3384 | ✗ | if (s->ref && (ret = FF_HW_SIMPLE_CALL(avctx, end_frame)) < 0) { | |
3385 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
3386 | "hardware accelerator failed to decode picture\n"); | ||
3387 | ✗ | ff_hevc_unref_frame(s->ref, ~0); | |
3388 | ✗ | return ret; | |
3389 | } | ||
3390 | } else { | ||
3391 | /* verify the SEI checksum */ | ||
3392 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 9582 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
9582 | if (avctx->err_recognition & AV_EF_CRCCHECK && s->ref && s->is_decoded && |
3393 | ✗ | s->sei.picture_hash.is_md5) { | |
3394 | ✗ | ret = verify_md5(s, s->ref->frame); | |
3395 | ✗ | if (ret < 0 && avctx->err_recognition & AV_EF_EXPLODE) { | |
3396 | ✗ | ff_hevc_unref_frame(s->ref, ~0); | |
3397 | ✗ | return ret; | |
3398 | } | ||
3399 | } | ||
3400 | } | ||
3401 | 9582 | s->sei.picture_hash.is_md5 = 0; | |
3402 | |||
3403 |
2/2✓ Branch 0 taken 9534 times.
✓ Branch 1 taken 48 times.
|
9582 | if (s->is_decoded) { |
3404 | 9534 | av_log(avctx, AV_LOG_DEBUG, "Decoded frame with POC %d.\n", s->poc); | |
3405 | 9534 | s->is_decoded = 0; | |
3406 | } | ||
3407 | |||
3408 |
2/2✓ Branch 0 taken 9067 times.
✓ Branch 1 taken 515 times.
|
9582 | if (s->output_frame->buf[0]) { |
3409 | 9067 | av_frame_move_ref(rframe, s->output_frame); | |
3410 | 9067 | *got_output = 1; | |
3411 | } | ||
3412 | |||
3413 | 9582 | return avpkt->size; | |
3414 | } | ||
3415 | |||
3416 | 67 | static int hevc_ref_frame(HEVCFrame *dst, HEVCFrame *src) | |
3417 | { | ||
3418 | int ret; | ||
3419 | |||
3420 | 67 | ret = ff_thread_ref_frame(&dst->tf, &src->tf); | |
3421 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (ret < 0) |
3422 | ✗ | return ret; | |
3423 | |||
3424 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (src->needs_fg) { |
3425 | ✗ | ret = av_frame_ref(dst->frame_grain, src->frame_grain); | |
3426 | ✗ | if (ret < 0) | |
3427 | ✗ | return ret; | |
3428 | ✗ | dst->needs_fg = 1; | |
3429 | } | ||
3430 | |||
3431 | 67 | dst->tab_mvf = ff_refstruct_ref(src->tab_mvf); | |
3432 | 67 | dst->rpl_tab = ff_refstruct_ref(src->rpl_tab); | |
3433 | 67 | dst->rpl = ff_refstruct_ref(src->rpl); | |
3434 | 67 | dst->nb_rpl_elems = src->nb_rpl_elems; | |
3435 | |||
3436 | 67 | dst->poc = src->poc; | |
3437 | 67 | dst->ctb_count = src->ctb_count; | |
3438 | 67 | dst->flags = src->flags; | |
3439 | 67 | dst->sequence = src->sequence; | |
3440 | |||
3441 | 67 | ff_refstruct_replace(&dst->hwaccel_picture_private, | |
3442 | 67 | src->hwaccel_picture_private); | |
3443 | |||
3444 | 67 | return 0; | |
3445 | } | ||
3446 | |||
3447 | 428 | static av_cold int hevc_decode_free(AVCodecContext *avctx) | |
3448 | { | ||
3449 | 428 | HEVCContext *s = avctx->priv_data; | |
3450 | int i; | ||
3451 | |||
3452 | 428 | pic_arrays_free(s); | |
3453 | |||
3454 | 428 | ff_dovi_ctx_unref(&s->dovi_ctx); | |
3455 | 428 | av_buffer_unref(&s->rpu_buf); | |
3456 | |||
3457 | 428 | av_freep(&s->md5_ctx); | |
3458 | |||
3459 |
2/2✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 428 times.
|
1712 | for (i = 0; i < 3; i++) { |
3460 | 1284 | av_freep(&s->sao_pixel_buffer_h[i]); | |
3461 | 1284 | av_freep(&s->sao_pixel_buffer_v[i]); | |
3462 | } | ||
3463 | 428 | av_frame_free(&s->output_frame); | |
3464 | |||
3465 |
2/2✓ Branch 0 taken 13696 times.
✓ Branch 1 taken 428 times.
|
14124 | for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { |
3466 | 13696 | ff_hevc_unref_frame(&s->DPB[i], ~0); | |
3467 | 13696 | av_frame_free(&s->DPB[i].frame); | |
3468 | 13696 | av_frame_free(&s->DPB[i].frame_grain); | |
3469 | } | ||
3470 | |||
3471 | 428 | ff_hevc_ps_uninit(&s->ps); | |
3472 | |||
3473 | 428 | av_freep(&s->sh.entry_point_offset); | |
3474 | 428 | av_freep(&s->sh.offset); | |
3475 | 428 | av_freep(&s->sh.size); | |
3476 | |||
3477 |
1/2✓ Branch 0 taken 428 times.
✗ Branch 1 not taken.
|
428 | if (s->HEVClcList) { |
3478 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 428 times.
|
428 | for (i = 1; i < s->threads_number; i++) { |
3479 | ✗ | av_freep(&s->HEVClcList[i]); | |
3480 | } | ||
3481 | } | ||
3482 | 428 | av_freep(&s->HEVClc); | |
3483 | 428 | av_freep(&s->HEVClcList); | |
3484 | |||
3485 | 428 | ff_h2645_packet_uninit(&s->pkt); | |
3486 | |||
3487 | 428 | ff_hevc_reset_sei(&s->sei); | |
3488 | |||
3489 | 428 | return 0; | |
3490 | } | ||
3491 | |||
3492 | 428 | static av_cold int hevc_init_context(AVCodecContext *avctx) | |
3493 | { | ||
3494 | 428 | HEVCContext *s = avctx->priv_data; | |
3495 | int i; | ||
3496 | |||
3497 | 428 | s->avctx = avctx; | |
3498 | |||
3499 | 428 | s->HEVClc = av_mallocz(sizeof(HEVCLocalContext)); | |
3500 | 428 | s->HEVClcList = av_mallocz(sizeof(HEVCLocalContext*) * s->threads_number); | |
3501 |
2/4✓ Branch 0 taken 428 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 428 times.
|
428 | if (!s->HEVClc || !s->HEVClcList) |
3502 | ✗ | return AVERROR(ENOMEM); | |
3503 | 428 | s->HEVClc->parent = s; | |
3504 | 428 | s->HEVClc->logctx = avctx; | |
3505 | 428 | s->HEVClc->common_cabac_state = &s->cabac; | |
3506 | 428 | s->HEVClcList[0] = s->HEVClc; | |
3507 | |||
3508 | 428 | s->output_frame = av_frame_alloc(); | |
3509 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 428 times.
|
428 | if (!s->output_frame) |
3510 | ✗ | return AVERROR(ENOMEM); | |
3511 | |||
3512 |
2/2✓ Branch 0 taken 13696 times.
✓ Branch 1 taken 428 times.
|
14124 | for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { |
3513 | 13696 | s->DPB[i].frame = av_frame_alloc(); | |
3514 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13696 times.
|
13696 | if (!s->DPB[i].frame) |
3515 | ✗ | return AVERROR(ENOMEM); | |
3516 | 13696 | s->DPB[i].tf.f = s->DPB[i].frame; | |
3517 | |||
3518 | 13696 | s->DPB[i].frame_grain = av_frame_alloc(); | |
3519 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13696 times.
|
13696 | if (!s->DPB[i].frame_grain) |
3520 | ✗ | return AVERROR(ENOMEM); | |
3521 | } | ||
3522 | |||
3523 | 428 | s->max_ra = INT_MAX; | |
3524 | |||
3525 | 428 | s->md5_ctx = av_md5_alloc(); | |
3526 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 428 times.
|
428 | if (!s->md5_ctx) |
3527 | ✗ | return AVERROR(ENOMEM); | |
3528 | |||
3529 | 428 | ff_bswapdsp_init(&s->bdsp); | |
3530 | |||
3531 | 428 | s->dovi_ctx.logctx = avctx; | |
3532 | 428 | s->eos = 0; | |
3533 | |||
3534 | 428 | ff_hevc_reset_sei(&s->sei); | |
3535 | |||
3536 | 428 | return 0; | |
3537 | } | ||
3538 | |||
3539 | #if HAVE_THREADS | ||
3540 | 32 | static int hevc_update_thread_context(AVCodecContext *dst, | |
3541 | const AVCodecContext *src) | ||
3542 | { | ||
3543 | 32 | HEVCContext *s = dst->priv_data; | |
3544 | 32 | HEVCContext *s0 = src->priv_data; | |
3545 | int i, ret; | ||
3546 | |||
3547 |
2/2✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 32 times.
|
1056 | for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { |
3548 | 1024 | ff_hevc_unref_frame(&s->DPB[i], ~0); | |
3549 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 957 times.
|
1024 | if (s0->DPB[i].frame->buf[0]) { |
3550 | 67 | ret = hevc_ref_frame(&s->DPB[i], &s0->DPB[i]); | |
3551 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (ret < 0) |
3552 | ✗ | return ret; | |
3553 | } | ||
3554 | } | ||
3555 | |||
3556 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 31 times.
|
32 | if (s->ps.sps != s0->ps.sps) |
3557 | 1 | s->ps.sps = NULL; | |
3558 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 32 times.
|
544 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) |
3559 | 512 | ff_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); | |
3560 | |||
3561 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 32 times.
|
544 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) |
3562 | 512 | ff_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); | |
3563 | |||
3564 |
2/2✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 32 times.
|
2080 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) |
3565 | 2048 | ff_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); | |
3566 | |||
3567 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 31 times.
|
32 | if (s->ps.sps != s0->ps.sps) |
3568 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if ((ret = set_sps(s, s0->ps.sps, src->pix_fmt)) < 0) |
3569 | ✗ | return ret; | |
3570 | |||
3571 | 32 | s->seq_decode = s0->seq_decode; | |
3572 | 32 | s->seq_output = s0->seq_output; | |
3573 | 32 | s->pocTid0 = s0->pocTid0; | |
3574 | 32 | s->max_ra = s0->max_ra; | |
3575 | 32 | s->eos = s0->eos; | |
3576 | 32 | s->no_rasl_output_flag = s0->no_rasl_output_flag; | |
3577 | |||
3578 | 32 | s->is_nalff = s0->is_nalff; | |
3579 | 32 | s->nal_length_size = s0->nal_length_size; | |
3580 | |||
3581 | 32 | s->threads_number = s0->threads_number; | |
3582 | 32 | s->threads_type = s0->threads_type; | |
3583 | |||
3584 | 32 | s->film_grain_warning_shown = s0->film_grain_warning_shown; | |
3585 | |||
3586 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (s0->eos) { |
3587 | ✗ | s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK; | |
3588 | ✗ | s->max_ra = INT_MAX; | |
3589 | } | ||
3590 | |||
3591 | 32 | ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common); | |
3592 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
3593 | ✗ | return ret; | |
3594 | |||
3595 | 32 | ret = av_buffer_replace(&s->sei.common.dynamic_hdr_plus.info, | |
3596 | 32 | s0->sei.common.dynamic_hdr_plus.info); | |
3597 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
3598 | ✗ | return ret; | |
3599 | |||
3600 | 32 | ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf); | |
3601 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
3602 | ✗ | return ret; | |
3603 | |||
3604 | 32 | ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx); | |
3605 | |||
3606 | 32 | ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info, | |
3607 | 32 | s0->sei.common.dynamic_hdr_vivid.info); | |
3608 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
3609 | ✗ | return ret; | |
3610 | |||
3611 | 32 | s->sei.common.frame_packing = s0->sei.common.frame_packing; | |
3612 | 32 | s->sei.common.display_orientation = s0->sei.common.display_orientation; | |
3613 | 32 | s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer; | |
3614 | 32 | s->sei.common.mastering_display = s0->sei.common.mastering_display; | |
3615 | 32 | s->sei.common.content_light = s0->sei.common.content_light; | |
3616 | 32 | s->sei.common.aom_film_grain = s0->sei.common.aom_film_grain; | |
3617 | |||
3618 | 32 | ret = export_stream_params_from_sei(s); | |
3619 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
3620 | ✗ | return ret; | |
3621 | |||
3622 | 32 | return 0; | |
3623 | } | ||
3624 | #endif | ||
3625 | |||
3626 | 428 | static av_cold int hevc_decode_init(AVCodecContext *avctx) | |
3627 | { | ||
3628 | 428 | HEVCContext *s = avctx->priv_data; | |
3629 | int ret; | ||
3630 | |||
3631 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 428 times.
|
428 | if (avctx->active_thread_type & FF_THREAD_SLICE) { |
3632 | ✗ | s->threads_number = avctx->thread_count; | |
3633 | ✗ | ret = ff_slice_thread_init_progress(avctx); | |
3634 | ✗ | if (ret < 0) | |
3635 | ✗ | return ret; | |
3636 | } else | ||
3637 | 428 | s->threads_number = 1; | |
3638 | |||
3639 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 426 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
428 | if((avctx->active_thread_type & FF_THREAD_FRAME) && avctx->thread_count > 1) |
3640 | 2 | s->threads_type = FF_THREAD_FRAME; | |
3641 | else | ||
3642 | 426 | s->threads_type = FF_THREAD_SLICE; | |
3643 | |||
3644 | 428 | ret = hevc_init_context(avctx); | |
3645 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 428 times.
|
428 | if (ret < 0) |
3646 | ✗ | return ret; | |
3647 | |||
3648 | 428 | s->enable_parallel_tiles = 0; | |
3649 | 428 | s->sei.picture_timing.picture_struct = 0; | |
3650 | 428 | s->eos = 1; | |
3651 | |||
3652 | 428 | atomic_init(&s->wpp_err, 0); | |
3653 | |||
3654 |
2/2✓ Branch 0 taken 427 times.
✓ Branch 1 taken 1 times.
|
428 | if (!avctx->internal->is_copy) { |
3655 | const AVPacketSideData *sd; | ||
3656 | |||
3657 |
3/4✓ Branch 0 taken 229 times.
✓ Branch 1 taken 198 times.
✓ Branch 2 taken 229 times.
✗ Branch 3 not taken.
|
427 | if (avctx->extradata_size > 0 && avctx->extradata) { |
3658 | 229 | ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1); | |
3659 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
|
229 | if (ret < 0) { |
3660 | ✗ | return ret; | |
3661 | } | ||
3662 | |||
3663 | 229 | ret = ff_h2645_sei_to_context(avctx, &s->sei.common); | |
3664 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
|
229 | if (ret < 0) |
3665 | ✗ | return ret; | |
3666 | } | ||
3667 | |||
3668 | 427 | sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF); | |
3669 |
3/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 416 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
427 | if (sd && sd->size > 0) |
3670 | 11 | ff_dovi_update_cfg(&s->dovi_ctx, (AVDOVIDecoderConfigurationRecord *) sd->data); | |
3671 | } | ||
3672 | |||
3673 | 428 | return 0; | |
3674 | } | ||
3675 | |||
3676 | 8 | static void hevc_decode_flush(AVCodecContext *avctx) | |
3677 | { | ||
3678 | 8 | HEVCContext *s = avctx->priv_data; | |
3679 | 8 | ff_hevc_flush_dpb(s); | |
3680 | 8 | ff_hevc_reset_sei(&s->sei); | |
3681 | 8 | ff_dovi_ctx_flush(&s->dovi_ctx); | |
3682 | 8 | av_buffer_unref(&s->rpu_buf); | |
3683 | 8 | s->max_ra = INT_MAX; | |
3684 | 8 | s->eos = 1; | |
3685 | |||
3686 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
8 | if (FF_HW_HAS_CB(avctx, flush)) |
3687 | ✗ | FF_HW_SIMPLE_CALL(avctx, flush); | |
3688 | 8 | } | |
3689 | |||
3690 | #define OFFSET(x) offsetof(HEVCContext, x) | ||
3691 | #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) | ||
3692 | |||
3693 | static const AVOption options[] = { | ||
3694 | { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin), | ||
3695 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
3696 | { "strict-displaywin", "stricly apply default display window size", OFFSET(apply_defdispwin), | ||
3697 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
3698 | { NULL }, | ||
3699 | }; | ||
3700 | |||
3701 | static const AVClass hevc_decoder_class = { | ||
3702 | .class_name = "HEVC decoder", | ||
3703 | .item_name = av_default_item_name, | ||
3704 | .option = options, | ||
3705 | .version = LIBAVUTIL_VERSION_INT, | ||
3706 | }; | ||
3707 | |||
3708 | const FFCodec ff_hevc_decoder = { | ||
3709 | .p.name = "hevc", | ||
3710 | CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"), | ||
3711 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
3712 | .p.id = AV_CODEC_ID_HEVC, | ||
3713 | .priv_data_size = sizeof(HEVCContext), | ||
3714 | .p.priv_class = &hevc_decoder_class, | ||
3715 | .init = hevc_decode_init, | ||
3716 | .close = hevc_decode_free, | ||
3717 | FF_CODEC_DECODE_CB(hevc_decode_frame), | ||
3718 | .flush = hevc_decode_flush, | ||
3719 | UPDATE_THREAD_CONTEXT(hevc_update_thread_context), | ||
3720 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | | ||
3721 | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, | ||
3722 | .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | | ||
3723 | FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP, | ||
3724 | .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles), | ||
3725 | .hw_configs = (const AVCodecHWConfigInternal *const []) { | ||
3726 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
3727 | HWACCEL_DXVA2(hevc), | ||
3728 | #endif | ||
3729 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
3730 | HWACCEL_D3D11VA(hevc), | ||
3731 | #endif | ||
3732 | #if CONFIG_HEVC_D3D11VA2_HWACCEL | ||
3733 | HWACCEL_D3D11VA2(hevc), | ||
3734 | #endif | ||
3735 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
3736 | HWACCEL_D3D12VA(hevc), | ||
3737 | #endif | ||
3738 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
3739 | HWACCEL_NVDEC(hevc), | ||
3740 | #endif | ||
3741 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
3742 | HWACCEL_VAAPI(hevc), | ||
3743 | #endif | ||
3744 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
3745 | HWACCEL_VDPAU(hevc), | ||
3746 | #endif | ||
3747 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
3748 | HWACCEL_VIDEOTOOLBOX(hevc), | ||
3749 | #endif | ||
3750 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
3751 | HWACCEL_VULKAN(hevc), | ||
3752 | #endif | ||
3753 | NULL | ||
3754 | }, | ||
3755 | }; | ||
3756 |