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/container_fifo.h" | ||
32 | #include "libavutil/film_grain_params.h" | ||
33 | #include "libavutil/internal.h" | ||
34 | #include "libavutil/md5.h" | ||
35 | #include "libavutil/mem.h" | ||
36 | #include "libavutil/opt.h" | ||
37 | #include "libavutil/pixdesc.h" | ||
38 | #include "libavutil/stereo3d.h" | ||
39 | #include "libavutil/timecode.h" | ||
40 | |||
41 | #include "aom_film_grain.h" | ||
42 | #include "bswapdsp.h" | ||
43 | #include "cabac_functions.h" | ||
44 | #include "codec_internal.h" | ||
45 | #include "decode.h" | ||
46 | #include "golomb.h" | ||
47 | #include "hevc.h" | ||
48 | #include "parse.h" | ||
49 | #include "hevcdec.h" | ||
50 | #include "hwaccel_internal.h" | ||
51 | #include "hwconfig.h" | ||
52 | #include "internal.h" | ||
53 | #include "profiles.h" | ||
54 | #include "progressframe.h" | ||
55 | #include "libavutil/refstruct.h" | ||
56 | #include "thread.h" | ||
57 | #include "threadprogress.h" | ||
58 | |||
59 | 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 }; | ||
60 | |||
61 | /** | ||
62 | * NOTE: Each function hls_foo correspond to the function foo in the | ||
63 | * specification (HLS stands for High Level Syntax). | ||
64 | */ | ||
65 | |||
66 | /** | ||
67 | * Section 5.7 | ||
68 | */ | ||
69 | |||
70 | /* free everything allocated by pic_arrays_init() */ | ||
71 | 1340 | static void pic_arrays_free(HEVCLayerContext *l) | |
72 | { | ||
73 | 1340 | av_freep(&l->sao); | |
74 | 1340 | av_freep(&l->deblock); | |
75 | |||
76 | 1340 | av_freep(&l->skip_flag); | |
77 | 1340 | av_freep(&l->tab_ct_depth); | |
78 | |||
79 | 1340 | av_freep(&l->tab_ipm); | |
80 | 1340 | av_freep(&l->cbf_luma); | |
81 | 1340 | av_freep(&l->is_pcm); | |
82 | |||
83 | 1340 | av_freep(&l->qp_y_tab); | |
84 | 1340 | av_freep(&l->tab_slice_address); | |
85 | 1340 | av_freep(&l->filter_slice_edges); | |
86 | |||
87 | 1340 | av_freep(&l->horizontal_bs); | |
88 | 1340 | av_freep(&l->vertical_bs); | |
89 | |||
90 |
2/2✓ Branch 0 taken 4020 times.
✓ Branch 1 taken 1340 times.
|
5360 | for (int i = 0; i < 3; i++) { |
91 | 4020 | av_freep(&l->sao_pixel_buffer_h[i]); | |
92 | 4020 | av_freep(&l->sao_pixel_buffer_v[i]); | |
93 | } | ||
94 | |||
95 | 1340 | av_refstruct_pool_uninit(&l->tab_mvf_pool); | |
96 | 1340 | av_refstruct_pool_uninit(&l->rpl_tab_pool); | |
97 | 1340 | } | |
98 | |||
99 | /* allocate arrays that depend on frame dimensions */ | ||
100 | 416 | static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps) | |
101 | { | ||
102 | 416 | int log2_min_cb_size = sps->log2_min_cb_size; | |
103 | 416 | int width = sps->width; | |
104 | 416 | int height = sps->height; | |
105 | 416 | int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) * | |
106 | 416 | ((height >> log2_min_cb_size) + 1); | |
107 | 416 | int ctb_count = sps->ctb_width * sps->ctb_height; | |
108 | 416 | int min_pu_size = sps->min_pu_width * sps->min_pu_height; | |
109 | |||
110 | 416 | l->bs_width = (width >> 2) + 1; | |
111 | 416 | l->bs_height = (height >> 2) + 1; | |
112 | |||
113 | 416 | l->sao = av_calloc(ctb_count, sizeof(*l->sao)); | |
114 | 416 | l->deblock = av_calloc(ctb_count, sizeof(*l->deblock)); | |
115 |
2/4✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 416 times.
|
416 | if (!l->sao || !l->deblock) |
116 | ✗ | goto fail; | |
117 | |||
118 | 416 | l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
119 | 416 | l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
120 |
2/4✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 416 times.
|
416 | if (!l->skip_flag || !l->tab_ct_depth) |
121 | ✗ | goto fail; | |
122 | |||
123 | 416 | l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height); | |
124 | 416 | l->tab_ipm = av_mallocz(min_pu_size); | |
125 | 416 | l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1); | |
126 |
3/6✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 416 times.
|
416 | if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm) |
127 | ✗ | goto fail; | |
128 | |||
129 | 416 | l->filter_slice_edges = av_mallocz(ctb_count); | |
130 | 416 | l->tab_slice_address = av_malloc_array(pic_size_in_ctb, | |
131 | sizeof(*l->tab_slice_address)); | ||
132 | 416 | l->qp_y_tab = av_calloc(pic_size_in_ctb, | |
133 | sizeof(*l->qp_y_tab)); | ||
134 |
3/6✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 416 times.
|
416 | if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address) |
135 | ✗ | goto fail; | |
136 | |||
137 | 416 | l->horizontal_bs = av_calloc(l->bs_width, l->bs_height); | |
138 | 416 | l->vertical_bs = av_calloc(l->bs_width, l->bs_height); | |
139 |
2/4✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 416 times.
|
416 | if (!l->horizontal_bs || !l->vertical_bs) |
140 | ✗ | goto fail; | |
141 | |||
142 | 416 | l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0); | |
143 | 416 | l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0); | |
144 |
2/4✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 416 times.
|
416 | if (!l->tab_mvf_pool || !l->rpl_tab_pool) |
145 | ✗ | goto fail; | |
146 | |||
147 |
2/2✓ Branch 0 taken 361 times.
✓ Branch 1 taken 55 times.
|
416 | if (sps->sao_enabled) { |
148 |
2/2✓ Branch 0 taken 359 times.
✓ Branch 1 taken 2 times.
|
361 | int c_count = (sps->chroma_format_idc != 0) ? 3 : 1; |
149 | |||
150 |
2/2✓ Branch 0 taken 1079 times.
✓ Branch 1 taken 361 times.
|
1440 | for (int c_idx = 0; c_idx < c_count; c_idx++) { |
151 | 1079 | int w = sps->width >> sps->hshift[c_idx]; | |
152 | 1079 | int h = sps->height >> sps->vshift[c_idx]; | |
153 | 1079 | l->sao_pixel_buffer_h[c_idx] = | |
154 | 1079 | av_malloc((w * 2 * sps->ctb_height) << | |
155 | 1079 | sps->pixel_shift); | |
156 | 1079 | l->sao_pixel_buffer_v[c_idx] = | |
157 | 1079 | av_malloc((h * 2 * sps->ctb_width) << | |
158 | 1079 | sps->pixel_shift); | |
159 |
1/2✓ Branch 0 taken 1079 times.
✗ Branch 1 not taken.
|
1079 | if (!l->sao_pixel_buffer_h[c_idx] || |
160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1079 times.
|
1079 | !l->sao_pixel_buffer_v[c_idx]) |
161 | ✗ | goto fail; | |
162 | } | ||
163 | } | ||
164 | |||
165 | 416 | return 0; | |
166 | |||
167 | ✗ | fail: | |
168 | ✗ | pic_arrays_free(l); | |
169 | ✗ | return AVERROR(ENOMEM); | |
170 | } | ||
171 | |||
172 | 1443 | static int pred_weight_table(SliceHeader *sh, void *logctx, | |
173 | const HEVCSPS *sps, GetBitContext *gb) | ||
174 | { | ||
175 | 1443 | int i = 0; | |
176 | 1443 | int j = 0; | |
177 | uint8_t luma_weight_l0_flag[16]; | ||
178 | uint8_t chroma_weight_l0_flag[16]; | ||
179 | uint8_t luma_weight_l1_flag[16]; | ||
180 | uint8_t chroma_weight_l1_flag[16]; | ||
181 | int luma_log2_weight_denom; | ||
182 | |||
183 | 1443 | luma_log2_weight_denom = get_ue_golomb_long(gb); | |
184 |
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) { |
185 | ✗ | av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom); | |
186 | ✗ | return AVERROR_INVALIDDATA; | |
187 | } | ||
188 | 1443 | sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3); | |
189 |
1/2✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
|
1443 | if (sps->chroma_format_idc != 0) { |
190 | 1443 | int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb); | |
191 |
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) { |
192 | ✗ | av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom); | |
193 | ✗ | return AVERROR_INVALIDDATA; | |
194 | } | ||
195 | 1443 | sh->chroma_log2_weight_denom = chroma_log2_weight_denom; | |
196 | } | ||
197 | |||
198 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < sh->nb_refs[L0]; i++) { |
199 | 4407 | luma_weight_l0_flag[i] = get_bits1(gb); | |
200 |
2/2✓ Branch 0 taken 1290 times.
✓ Branch 1 taken 3117 times.
|
4407 | if (!luma_weight_l0_flag[i]) { |
201 | 1290 | sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom; | |
202 | 1290 | sh->luma_offset_l0[i] = 0; | |
203 | } | ||
204 | } | ||
205 |
1/2✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
|
1443 | if (sps->chroma_format_idc != 0) { |
206 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < sh->nb_refs[L0]; i++) |
207 | 4407 | chroma_weight_l0_flag[i] = get_bits1(gb); | |
208 | } else { | ||
209 | ✗ | for (i = 0; i < sh->nb_refs[L0]; i++) | |
210 | ✗ | chroma_weight_l0_flag[i] = 0; | |
211 | } | ||
212 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < sh->nb_refs[L0]; i++) { |
213 |
2/2✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1290 times.
|
4407 | if (luma_weight_l0_flag[i]) { |
214 | 3117 | int delta_luma_weight_l0 = get_se_golomb(gb); | |
215 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
|
3117 | if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0) |
216 | ✗ | return AVERROR_INVALIDDATA; | |
217 | 3117 | sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0; | |
218 | 3117 | sh->luma_offset_l0[i] = get_se_golomb(gb); | |
219 | } | ||
220 |
2/2✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3276 times.
|
4407 | if (chroma_weight_l0_flag[i]) { |
221 |
2/2✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
|
3393 | for (j = 0; j < 2; j++) { |
222 | 2262 | int delta_chroma_weight_l0 = get_se_golomb(gb); | |
223 | 2262 | int delta_chroma_offset_l0 = get_se_golomb(gb); | |
224 | |||
225 |
1/2✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
|
2262 | if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0 |
226 |
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)) { |
227 | ✗ | return AVERROR_INVALIDDATA; | |
228 | } | ||
229 | |||
230 | 2262 | sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0; | |
231 | 2262 | sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j]) | |
232 | 2262 | >> sh->chroma_log2_weight_denom) + 128), -128, 127); | |
233 | } | ||
234 | } else { | ||
235 | 3276 | sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom; | |
236 | 3276 | sh->chroma_offset_l0[i][0] = 0; | |
237 | 3276 | sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom; | |
238 | 3276 | sh->chroma_offset_l0[i][1] = 0; | |
239 | } | ||
240 | } | ||
241 |
2/2✓ Branch 0 taken 668 times.
✓ Branch 1 taken 775 times.
|
1443 | if (sh->slice_type == HEVC_SLICE_B) { |
242 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < sh->nb_refs[L1]; i++) { |
243 | 1347 | luma_weight_l1_flag[i] = get_bits1(gb); | |
244 |
2/2✓ Branch 0 taken 601 times.
✓ Branch 1 taken 746 times.
|
1347 | if (!luma_weight_l1_flag[i]) { |
245 | 601 | sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom; | |
246 | 601 | sh->luma_offset_l1[i] = 0; | |
247 | } | ||
248 | } | ||
249 |
1/2✓ Branch 0 taken 668 times.
✗ Branch 1 not taken.
|
668 | if (sps->chroma_format_idc != 0) { |
250 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < sh->nb_refs[L1]; i++) |
251 | 1347 | chroma_weight_l1_flag[i] = get_bits1(gb); | |
252 | } else { | ||
253 | ✗ | for (i = 0; i < sh->nb_refs[L1]; i++) | |
254 | ✗ | chroma_weight_l1_flag[i] = 0; | |
255 | } | ||
256 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < sh->nb_refs[L1]; i++) { |
257 |
2/2✓ Branch 0 taken 746 times.
✓ Branch 1 taken 601 times.
|
1347 | if (luma_weight_l1_flag[i]) { |
258 | 746 | int delta_luma_weight_l1 = get_se_golomb(gb); | |
259 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
|
746 | if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1) |
260 | ✗ | return AVERROR_INVALIDDATA; | |
261 | 746 | sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1; | |
262 | 746 | sh->luma_offset_l1[i] = get_se_golomb(gb); | |
263 | } | ||
264 |
2/2✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1111 times.
|
1347 | if (chroma_weight_l1_flag[i]) { |
265 |
2/2✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
|
708 | for (j = 0; j < 2; j++) { |
266 | 472 | int delta_chroma_weight_l1 = get_se_golomb(gb); | |
267 | 472 | int delta_chroma_offset_l1 = get_se_golomb(gb); | |
268 | |||
269 |
1/2✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
|
472 | if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1 |
270 |
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)) { |
271 | ✗ | return AVERROR_INVALIDDATA; | |
272 | } | ||
273 | |||
274 | 472 | sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1; | |
275 | 472 | sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j]) | |
276 | 472 | >> sh->chroma_log2_weight_denom) + 128), -128, 127); | |
277 | } | ||
278 | } else { | ||
279 | 1111 | sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom; | |
280 | 1111 | sh->chroma_offset_l1[i][0] = 0; | |
281 | 1111 | sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom; | |
282 | 1111 | sh->chroma_offset_l1[i][1] = 0; | |
283 | } | ||
284 | } | ||
285 | } | ||
286 | 1443 | return 0; | |
287 | } | ||
288 | |||
289 | 19763 | static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps, | |
290 | GetBitContext *gb, int cur_poc, int poc_lsb) | ||
291 | { | ||
292 | 19763 | int max_poc_lsb = 1 << sps->log2_max_poc_lsb; | |
293 | 19763 | int prev_delta_msb = 0; | |
294 | 19763 | unsigned int nb_sps = 0, nb_sh; | |
295 | int i; | ||
296 | |||
297 | 19763 | rps->nb_refs = 0; | |
298 |
2/2✓ Branch 0 taken 18727 times.
✓ Branch 1 taken 1036 times.
|
19763 | if (!sps->long_term_ref_pics_present) |
299 | 18727 | return 0; | |
300 | |||
301 |
2/2✓ Branch 0 taken 499 times.
✓ Branch 1 taken 537 times.
|
1036 | if (sps->num_long_term_ref_pics_sps > 0) |
302 | 499 | nb_sps = get_ue_golomb_long(gb); | |
303 | 1036 | nb_sh = get_ue_golomb_long(gb); | |
304 | |||
305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
|
1036 | if (nb_sps > sps->num_long_term_ref_pics_sps) |
306 | ✗ | return AVERROR_INVALIDDATA; | |
307 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
|
1036 | if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc)) |
308 | ✗ | return AVERROR_INVALIDDATA; | |
309 | |||
310 | 1036 | rps->nb_refs = nb_sh + nb_sps; | |
311 | |||
312 |
2/2✓ Branch 0 taken 1562 times.
✓ Branch 1 taken 1036 times.
|
2598 | for (i = 0; i < rps->nb_refs; i++) { |
313 | |||
314 |
2/2✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1378 times.
|
1562 | if (i < nb_sps) { |
315 | 184 | uint8_t lt_idx_sps = 0; | |
316 | |||
317 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (sps->num_long_term_ref_pics_sps > 1) |
318 | 184 | lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps)); | |
319 | |||
320 | 184 | rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps]; | |
321 | 184 | rps->used[i] = !!(sps->used_by_curr_pic_lt & (1U << lt_idx_sps)); | |
322 | } else { | ||
323 | 1378 | rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb); | |
324 | 1378 | rps->used[i] = get_bits1(gb); | |
325 | } | ||
326 | |||
327 | 1562 | rps->poc_msb_present[i] = get_bits1(gb); | |
328 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1514 times.
|
1562 | if (rps->poc_msb_present[i]) { |
329 | 48 | int64_t delta = get_ue_golomb_long(gb); | |
330 | int64_t poc; | ||
331 | |||
332 |
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) |
333 | 31 | delta += prev_delta_msb; | |
334 | |||
335 | 48 | poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb; | |
336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (poc != (int32_t)poc) |
337 | ✗ | return AVERROR_INVALIDDATA; | |
338 | 48 | rps->poc[i] = poc; | |
339 | 48 | prev_delta_msb = delta; | |
340 | } | ||
341 | } | ||
342 | |||
343 | 1036 | return 0; | |
344 | } | ||
345 | |||
346 | 659 | static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) | |
347 | { | ||
348 | 659 | AVCodecContext *avctx = s->avctx; | |
349 | 659 | const HEVCVPS *vps = sps->vps; | |
350 | 659 | const HEVCWindow *ow = &sps->output_window; | |
351 | 659 | unsigned int num = 0, den = 0; | |
352 | |||
353 | 659 | avctx->pix_fmt = sps->pix_fmt; | |
354 | 659 | avctx->coded_width = sps->width; | |
355 | 659 | avctx->coded_height = sps->height; | |
356 | 659 | avctx->width = sps->width - ow->left_offset - ow->right_offset; | |
357 | 659 | avctx->height = sps->height - ow->top_offset - ow->bottom_offset; | |
358 | 659 | avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics; | |
359 | 659 | avctx->profile = sps->ptl.general_ptl.profile_idc; | |
360 | 659 | avctx->level = sps->ptl.general_ptl.level_idc; | |
361 | |||
362 | 659 | ff_set_sar(avctx, sps->vui.common.sar); | |
363 | |||
364 |
2/2✓ Branch 0 taken 59 times.
✓ Branch 1 taken 600 times.
|
659 | if (sps->vui.common.video_signal_type_present_flag) |
365 | 59 | avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG | |
366 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 53 times.
|
59 | : AVCOL_RANGE_MPEG; |
367 | else | ||
368 | 600 | avctx->color_range = AVCOL_RANGE_MPEG; | |
369 | |||
370 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 607 times.
|
659 | if (sps->vui.common.colour_description_present_flag) { |
371 | 52 | avctx->color_primaries = sps->vui.common.colour_primaries; | |
372 | 52 | avctx->color_trc = sps->vui.common.transfer_characteristics; | |
373 | 52 | avctx->colorspace = sps->vui.common.matrix_coeffs; | |
374 | } else { | ||
375 | 607 | avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; | |
376 | 607 | avctx->color_trc = AVCOL_TRC_UNSPECIFIED; | |
377 | 607 | avctx->colorspace = AVCOL_SPC_UNSPECIFIED; | |
378 | } | ||
379 | |||
380 | 659 | avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED; | |
381 |
2/2✓ Branch 0 taken 618 times.
✓ Branch 1 taken 41 times.
|
659 | if (sps->chroma_format_idc == 1) { |
382 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 599 times.
|
618 | if (sps->vui.common.chroma_loc_info_present_flag) { |
383 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | if (sps->vui.common.chroma_sample_loc_type_top_field <= 5) |
384 | 19 | avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1; | |
385 | } else | ||
386 | 599 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; | |
387 | } | ||
388 | |||
389 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 637 times.
|
659 | if (vps->vps_timing_info_present_flag) { |
390 | 22 | num = vps->vps_num_units_in_tick; | |
391 | 22 | den = vps->vps_time_scale; | |
392 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 581 times.
|
637 | } else if (sps->vui.vui_timing_info_present_flag) { |
393 | 56 | num = sps->vui.vui_num_units_in_tick; | |
394 | 56 | den = sps->vui.vui_time_scale; | |
395 | } | ||
396 | |||
397 |
3/4✓ Branch 0 taken 78 times.
✓ Branch 1 taken 581 times.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
|
659 | if (num > 0 && den > 0) |
398 | 78 | av_reduce(&avctx->framerate.den, &avctx->framerate.num, | |
399 | num, den, 1 << 30); | ||
400 | 659 | } | |
401 | |||
402 | 10526 | static int export_stream_params_from_sei(HEVCContext *s) | |
403 | { | ||
404 | 10526 | AVCodecContext *avctx = s->avctx; | |
405 | |||
406 | #if FF_API_CODEC_PROPS | ||
407 | FF_DISABLE_DEPRECATION_WARNINGS | ||
408 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10526 times.
|
10526 | if (s->sei.common.a53_caption.buf_ref) |
409 | ✗ | s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; | |
410 | FF_ENABLE_DEPRECATION_WARNINGS | ||
411 | #endif | ||
412 | |||
413 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10526 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10526 | if (s->sei.common.alternative_transfer.present && |
414 | ✗ | av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) && | |
415 | ✗ | s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) { | |
416 | ✗ | avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics; | |
417 | } | ||
418 | |||
419 | #if FF_API_CODEC_PROPS | ||
420 | FF_DISABLE_DEPRECATION_WARNINGS | ||
421 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10526 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10526 | if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) || |
422 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10526 times.
|
10526 | s->sei.common.aom_film_grain.enable) |
423 | ✗ | avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; | |
424 | FF_ENABLE_DEPRECATION_WARNINGS | ||
425 | #endif | ||
426 | |||
427 | 10526 | return 0; | |
428 | } | ||
429 | |||
430 | 659 | static int export_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
431 | { | ||
432 | 659 | const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi; | |
433 | |||
434 | 659 | av_freep(&s->view_ids_available); | |
435 | 659 | s->nb_view_ids_available = 0; | |
436 | 659 | av_freep(&s->view_pos_available); | |
437 | 659 | s->nb_view_pos_available = 0; | |
438 | |||
439 | // don't export anything in the trivial case (1 layer, view id=0) | ||
440 |
3/4✓ Branch 0 taken 634 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 634 times.
✗ Branch 3 not taken.
|
659 | if (vps->nb_layers < 2 && !vps->view_id[0]) |
441 | 634 | return 0; | |
442 | |||
443 | 25 | s->view_ids_available = av_calloc(vps->nb_layers, sizeof(*s->view_ids_available)); | |
444 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (!s->view_ids_available) |
445 | ✗ | return AVERROR(ENOMEM); | |
446 | |||
447 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
|
25 | if (tdrdi->num_ref_displays) { |
448 | 5 | s->view_pos_available = av_calloc(vps->nb_layers, sizeof(*s->view_pos_available)); | |
449 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!s->view_pos_available) |
450 | ✗ | return AVERROR(ENOMEM); | |
451 | } | ||
452 | |||
453 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 25 times.
|
75 | for (int i = 0; i < vps->nb_layers; i++) { |
454 | 50 | s->view_ids_available[i] = vps->view_id[i]; | |
455 | |||
456 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 40 times.
|
50 | if (s->view_pos_available) { |
457 | 10 | s->view_pos_available[i] = vps->view_id[i] == tdrdi->left_view_id[0] ? | |
458 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
15 | AV_STEREO3D_VIEW_LEFT : |
459 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | vps->view_id[i] == tdrdi->right_view_id[0] ? |
460 | AV_STEREO3D_VIEW_RIGHT : AV_STEREO3D_VIEW_UNSPEC; | ||
461 | } | ||
462 | } | ||
463 | 25 | s->nb_view_ids_available = vps->nb_layers; | |
464 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
|
25 | s->nb_view_pos_available = s->view_pos_available ? vps->nb_layers : 0; |
465 | |||
466 | 25 | return 0; | |
467 | } | ||
468 | |||
469 | 11477 | int ff_hevc_is_alpha_video(const HEVCContext *s) | |
470 | { | ||
471 | 11477 | const HEVCVPS *vps = s->vps; | |
472 | 11477 | int ret = 0; | |
473 | |||
474 |
3/4✓ Branch 0 taken 1023 times.
✓ Branch 1 taken 10454 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1023 times.
|
11477 | if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1]) |
475 | 10454 | return 0; | |
476 | |||
477 | /* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other | ||
478 | * than alpha cannot reach here. | ||
479 | */ | ||
480 | 1023 | ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY); | |
481 | |||
482 |
2/2✓ Branch 0 taken 153 times.
✓ Branch 1 taken 870 times.
|
1023 | av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n", |
483 | ret ? "is" : "not"); | ||
484 | |||
485 | 1023 | return ret; | |
486 | } | ||
487 | |||
488 | 406 | static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
489 | { | ||
490 | 406 | unsigned layers_active_output = 0, highest_layer; | |
491 | |||
492 | 406 | s->layers_active_output = 1; | |
493 | 406 | s->layers_active_decode = 1; | |
494 | |||
495 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 405 times.
|
406 | if (ff_hevc_is_alpha_video(s)) { |
496 | 1 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt); | |
497 | |||
498 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) |
499 | ✗ | return 0; | |
500 | |||
501 | 1 | s->layers_active_decode = (1 << vps->nb_layers) - 1; | |
502 | 1 | s->layers_active_output = 1; | |
503 | |||
504 | 1 | return 0; | |
505 | } | ||
506 | |||
507 | // nothing requested - decode base layer only | ||
508 |
2/2✓ Branch 0 taken 395 times.
✓ Branch 1 taken 10 times.
|
405 | if (!s->nb_view_ids) |
509 | 395 | return 0; | |
510 | |||
511 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
10 | if (s->nb_view_ids == 1 && s->view_ids[0] == -1) { |
512 | ✗ | layers_active_output = (1 << vps->nb_layers) - 1; | |
513 | } else { | ||
514 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 10 times.
|
28 | for (int i = 0; i < s->nb_view_ids; i++) { |
515 | 18 | int view_id = s->view_ids[i]; | |
516 | 18 | int layer_idx = -1; | |
517 | |||
518 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (view_id < 0) { |
519 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
520 | "Invalid view ID requested: %d\n", view_id); | ||
521 | ✗ | return AVERROR(EINVAL); | |
522 | } | ||
523 | |||
524 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | for (int j = 0; j < vps->nb_layers; j++) { |
525 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
|
26 | if (vps->view_id[j] == view_id) { |
526 | 18 | layer_idx = j; | |
527 | 18 | break; | |
528 | } | ||
529 | } | ||
530 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (layer_idx < 0) { |
531 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
532 | "View ID %d not present in VPS\n", view_id); | ||
533 | ✗ | return AVERROR(EINVAL); | |
534 | } | ||
535 | 18 | layers_active_output |= 1 << layer_idx; | |
536 | } | ||
537 | } | ||
538 | |||
539 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (!layers_active_output) { |
540 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No layers selected\n"); | |
541 | ✗ | return AVERROR_BUG; | |
542 | } | ||
543 | |||
544 | 10 | highest_layer = ff_log2(layers_active_output); | |
545 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (highest_layer >= FF_ARRAY_ELEMS(s->layers)) { |
546 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
547 | "Too many layers requested: %u\n", layers_active_output); | ||
548 | ✗ | return AVERROR(EINVAL); | |
549 | } | ||
550 | |||
551 | /* Assume a higher layer depends on all the lower ones. | ||
552 | * This is enforced in VPS parsing currently, this logic will need | ||
553 | * to be changed if we want to support more complex dependency structures. | ||
554 | */ | ||
555 | 10 | s->layers_active_decode = (1 << (highest_layer + 1)) - 1; | |
556 | 10 | s->layers_active_output = layers_active_output; | |
557 | |||
558 | 10 | av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n", | |
559 | s->layers_active_decode, s->layers_active_output); | ||
560 | |||
561 | 10 | return 0; | |
562 | } | ||
563 | |||
564 | 1 | static enum AVPixelFormat map_to_alpha_format(HEVCContext *s, | |
565 | enum AVPixelFormat pix_fmt) | ||
566 | { | ||
567 |
1/9✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
1 | switch (pix_fmt) { |
568 | 1 | case AV_PIX_FMT_YUV420P: | |
569 | case AV_PIX_FMT_YUVJ420P: | ||
570 | 1 | return AV_PIX_FMT_YUVA420P; | |
571 | ✗ | case AV_PIX_FMT_YUV420P10: | |
572 | ✗ | return AV_PIX_FMT_YUVA420P10; | |
573 | ✗ | case AV_PIX_FMT_YUV444P: | |
574 | ✗ | return AV_PIX_FMT_YUVA444P; | |
575 | ✗ | case AV_PIX_FMT_YUV422P: | |
576 | ✗ | return AV_PIX_FMT_YUVA422P; | |
577 | ✗ | case AV_PIX_FMT_YUV422P10LE: | |
578 | ✗ | return AV_PIX_FMT_YUVA422P10LE; | |
579 | ✗ | case AV_PIX_FMT_YUV444P10: | |
580 | ✗ | return AV_PIX_FMT_YUVA444P10; | |
581 | ✗ | case AV_PIX_FMT_YUV444P12: | |
582 | ✗ | return AV_PIX_FMT_YUVA444P12; | |
583 | ✗ | case AV_PIX_FMT_YUV422P12: | |
584 | ✗ | return AV_PIX_FMT_YUVA422P12; | |
585 | ✗ | default: | |
586 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n", | |
587 | av_get_pix_fmt_name(pix_fmt)); | ||
588 | ✗ | return AV_PIX_FMT_NONE; | |
589 | } | ||
590 | } | ||
591 | |||
592 | 406 | static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) | |
593 | { | ||
594 | #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \ | ||
595 | CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \ | ||
596 | CONFIG_HEVC_D3D12VA_HWACCEL + \ | ||
597 | CONFIG_HEVC_NVDEC_HWACCEL + \ | ||
598 | CONFIG_HEVC_VAAPI_HWACCEL + \ | ||
599 | CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \ | ||
600 | CONFIG_HEVC_VDPAU_HWACCEL + \ | ||
601 | CONFIG_HEVC_VULKAN_HWACCEL) | ||
602 | 406 | enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts; | |
603 | 406 | enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE; | |
604 | int ret; | ||
605 | |||
606 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 405 times.
|
406 | if (ff_hevc_is_alpha_video(s)) |
607 | 1 | alpha_fmt = map_to_alpha_format(s, sps->pix_fmt); | |
608 | |||
609 |
6/7✓ Branch 0 taken 343 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
|
406 | switch (sps->pix_fmt) { |
610 | 343 | case AV_PIX_FMT_YUV420P: | |
611 | case AV_PIX_FMT_YUVJ420P: | ||
612 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
613 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
614 | #endif | ||
615 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
616 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
617 | *fmt++ = AV_PIX_FMT_D3D11; | ||
618 | #endif | ||
619 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
620 | *fmt++ = AV_PIX_FMT_D3D12; | ||
621 | #endif | ||
622 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
623 | 343 | *fmt++ = AV_PIX_FMT_VAAPI; | |
624 | #endif | ||
625 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
626 | 343 | *fmt++ = AV_PIX_FMT_VDPAU; | |
627 | #endif | ||
628 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
629 | *fmt++ = AV_PIX_FMT_CUDA; | ||
630 | #endif | ||
631 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
632 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
633 | #endif | ||
634 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
635 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
636 | #endif | ||
637 | 343 | break; | |
638 | 35 | case AV_PIX_FMT_YUV420P10: | |
639 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
640 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
641 | #endif | ||
642 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
643 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
644 | *fmt++ = AV_PIX_FMT_D3D11; | ||
645 | #endif | ||
646 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
647 | *fmt++ = AV_PIX_FMT_D3D12; | ||
648 | #endif | ||
649 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
650 | 35 | *fmt++ = AV_PIX_FMT_VAAPI; | |
651 | #endif | ||
652 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
653 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
654 | #endif | ||
655 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
656 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
657 | #endif | ||
658 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
659 | 35 | *fmt++ = AV_PIX_FMT_VDPAU; | |
660 | #endif | ||
661 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
662 | *fmt++ = AV_PIX_FMT_CUDA; | ||
663 | #endif | ||
664 | 35 | break; | |
665 | 4 | case AV_PIX_FMT_YUV444P: | |
666 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
667 | 4 | *fmt++ = AV_PIX_FMT_VAAPI; | |
668 | #endif | ||
669 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
670 | 4 | *fmt++ = AV_PIX_FMT_VDPAU; | |
671 | #endif | ||
672 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
673 | *fmt++ = AV_PIX_FMT_CUDA; | ||
674 | #endif | ||
675 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
676 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
677 | #endif | ||
678 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
679 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
680 | #endif | ||
681 | 4 | break; | |
682 | 12 | case AV_PIX_FMT_YUV422P: | |
683 | case AV_PIX_FMT_YUV422P10LE: | ||
684 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
685 | 12 | *fmt++ = AV_PIX_FMT_VAAPI; | |
686 | #endif | ||
687 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
688 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
689 | #endif | ||
690 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
691 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
692 | #endif | ||
693 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
694 | *fmt++ = AV_PIX_FMT_CUDA; | ||
695 | #endif | ||
696 | 12 | break; | |
697 | 10 | case AV_PIX_FMT_YUV444P10: | |
698 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
699 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
700 | #endif | ||
701 | /* NOTE: fallthrough */ | ||
702 | case AV_PIX_FMT_YUV420P12: | ||
703 | case AV_PIX_FMT_YUV444P12: | ||
704 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
705 | 10 | *fmt++ = AV_PIX_FMT_VAAPI; | |
706 | #endif | ||
707 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
708 | 10 | *fmt++ = AV_PIX_FMT_VDPAU; | |
709 | #endif | ||
710 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
711 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
712 | #endif | ||
713 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
714 | *fmt++ = AV_PIX_FMT_CUDA; | ||
715 | #endif | ||
716 | 10 | break; | |
717 | ✗ | case AV_PIX_FMT_YUV422P12: | |
718 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
719 | ✗ | *fmt++ = AV_PIX_FMT_VAAPI; | |
720 | #endif | ||
721 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
722 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
723 | #endif | ||
724 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
725 | *fmt++ = AV_PIX_FMT_CUDA; | ||
726 | #endif | ||
727 | ✗ | break; | |
728 | } | ||
729 | |||
730 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 405 times.
|
406 | if (alpha_fmt != AV_PIX_FMT_NONE) |
731 | 1 | *fmt++ = alpha_fmt; | |
732 | 406 | *fmt++ = sps->pix_fmt; | |
733 | 406 | *fmt = AV_PIX_FMT_NONE; | |
734 | |||
735 | // export multilayer information from active VPS to the caller, | ||
736 | // so it is available in get_format() | ||
737 | 406 | ret = export_multilayer(s, sps->vps); | |
738 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 406 times.
|
406 | if (ret < 0) |
739 | ✗ | return ret; | |
740 | |||
741 | 406 | ret = ff_get_format(s->avctx, pix_fmts); | |
742 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 406 times.
|
406 | if (ret < 0) |
743 | ✗ | return ret; | |
744 | 406 | s->avctx->pix_fmt = ret; | |
745 | |||
746 | // set up multilayer decoding, if requested by caller | ||
747 | 406 | ret = setup_multilayer(s, sps->vps); | |
748 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 406 times.
|
406 | if (ret < 0) |
749 | ✗ | return ret; | |
750 | |||
751 | 406 | return 0; | |
752 | } | ||
753 | |||
754 | 416 | static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) | |
755 | { | ||
756 | int ret; | ||
757 | |||
758 | 416 | pic_arrays_free(l); | |
759 | 416 | av_refstruct_unref(&l->sps); | |
760 | 416 | av_refstruct_unref(&s->vps); | |
761 | |||
762 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 416 times.
|
416 | if (!sps) |
763 | ✗ | return 0; | |
764 | |||
765 | 416 | ret = pic_arrays_init(l, sps); | |
766 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 416 times.
|
416 | if (ret < 0) |
767 | ✗ | goto fail; | |
768 | |||
769 | 416 | ff_hevc_pred_init(&s->hpc, sps->bit_depth); | |
770 | 416 | ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); | |
771 | 416 | ff_videodsp_init (&s->vdsp, sps->bit_depth); | |
772 | |||
773 | 416 | l->sps = av_refstruct_ref_c(sps); | |
774 | 416 | s->vps = av_refstruct_ref_c(sps->vps); | |
775 | |||
776 | 416 | return 0; | |
777 | |||
778 | ✗ | fail: | |
779 | ✗ | pic_arrays_free(l); | |
780 | ✗ | av_refstruct_unref(&l->sps); | |
781 | ✗ | return ret; | |
782 | } | ||
783 | |||
784 | 28384 | static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb) | |
785 | { | ||
786 | const HEVCPPS *pps; | ||
787 | const HEVCSPS *sps; | ||
788 | const HEVCVPS *vps; | ||
789 | unsigned pps_id, layer_idx; | ||
790 | int i, ret; | ||
791 | |||
792 | // Coded parameters | ||
793 | 28384 | sh->first_slice_in_pic_flag = get_bits1(gb); | |
794 | |||
795 | 28384 | sh->no_output_of_prior_pics_flag = 0; | |
796 |
3/4✓ Branch 0 taken 1458 times.
✓ Branch 1 taken 26926 times.
✓ Branch 2 taken 1458 times.
✗ Branch 3 not taken.
|
28384 | if (IS_IRAP(s)) |
797 | 1458 | sh->no_output_of_prior_pics_flag = get_bits1(gb); | |
798 | |||
799 | 28384 | pps_id = get_ue_golomb_long(gb); | |
800 |
3/4✓ Branch 0 taken 28384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 28351 times.
|
28384 | if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) { |
801 | 33 | av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); | |
802 | 33 | return AVERROR_INVALIDDATA; | |
803 | } | ||
804 |
3/4✓ Branch 0 taken 18036 times.
✓ Branch 1 taken 10315 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18036 times.
|
28351 | if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) { |
805 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); | |
806 | ✗ | return AVERROR_INVALIDDATA; | |
807 | } | ||
808 | 28351 | sh->pps_id = pps_id; | |
809 | |||
810 | 28351 | pps = s->ps.pps_list[pps_id]; | |
811 | 28351 | sps = pps->sps; | |
812 | 28351 | vps = sps->vps; | |
813 | 28351 | layer_idx = vps->layer_idx[s->nuh_layer_id]; | |
814 | |||
815 |
4/4✓ Branch 0 taken 479 times.
✓ Branch 1 taken 27872 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 464 times.
|
28351 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) |
816 | 15 | sh->no_output_of_prior_pics_flag = 1; | |
817 | |||
818 | 28351 | sh->dependent_slice_segment_flag = 0; | |
819 |
2/2✓ Branch 0 taken 18036 times.
✓ Branch 1 taken 10315 times.
|
28351 | if (!sh->first_slice_in_pic_flag) { |
820 | int slice_address_length; | ||
821 | |||
822 |
2/2✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8944 times.
|
18036 | if (pps->dependent_slice_segments_enabled_flag) |
823 | 9092 | sh->dependent_slice_segment_flag = get_bits1(gb); | |
824 |
3/4✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 10089 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7947 times.
|
18036 | if (sh->dependent_slice_segment_flag && !s->slice_initialized) { |
825 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); | |
826 | ✗ | return AVERROR_INVALIDDATA; | |
827 | } | ||
828 | |||
829 | 18036 | slice_address_length = av_ceil_log2(sps->ctb_width * | |
830 | 18036 | sps->ctb_height); | |
831 | 18036 | sh->slice_segment_addr = get_bitsz(gb, slice_address_length); | |
832 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18036 times.
|
18036 | if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) { |
833 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
834 | "Invalid slice segment address: %u.\n", | ||
835 | sh->slice_segment_addr); | ||
836 | ✗ | return AVERROR_INVALIDDATA; | |
837 | } | ||
838 | |||
839 |
2/2✓ Branch 0 taken 10089 times.
✓ Branch 1 taken 7947 times.
|
18036 | if (!sh->dependent_slice_segment_flag) { |
840 | 10089 | sh->slice_addr = sh->slice_segment_addr; | |
841 | } | ||
842 | } else { | ||
843 | 10315 | sh->slice_segment_addr = sh->slice_addr = 0; | |
844 | } | ||
845 | |||
846 |
2/2✓ Branch 0 taken 20404 times.
✓ Branch 1 taken 7947 times.
|
28351 | if (!sh->dependent_slice_segment_flag) { |
847 |
2/2✓ Branch 0 taken 1078 times.
✓ Branch 1 taken 20404 times.
|
21482 | for (i = 0; i < pps->num_extra_slice_header_bits; i++) |
848 | 1078 | skip_bits(gb, 1); // slice_reserved_undetermined_flag[] | |
849 | |||
850 | 20404 | sh->slice_type = get_ue_golomb_long(gb); | |
851 |
2/2✓ Branch 0 taken 19159 times.
✓ Branch 1 taken 1245 times.
|
20404 | if (!(sh->slice_type == HEVC_SLICE_I || |
852 |
2/2✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3930 times.
|
19159 | sh->slice_type == HEVC_SLICE_P || |
853 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15229 times.
|
15229 | sh->slice_type == HEVC_SLICE_B)) { |
854 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", | |
855 | ✗ | sh->slice_type); | |
856 | ✗ | return AVERROR_INVALIDDATA; | |
857 | } | ||
858 |
5/6✓ Branch 0 taken 1069 times.
✓ Branch 1 taken 19335 times.
✓ Branch 2 taken 1069 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 75 times.
✓ Branch 5 taken 994 times.
|
20404 | if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I && |
859 |
1/2✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
|
75 | !pps->pps_curr_pic_ref_enabled_flag && |
860 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
|
75 | s->nuh_layer_id == 0) { |
861 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); | |
862 | ✗ | return AVERROR_INVALIDDATA; | |
863 | } | ||
864 | |||
865 | // when flag is not present, picture is inferred to be output | ||
866 | 20404 | sh->pic_output_flag = 1; | |
867 |
2/2✓ Branch 0 taken 703 times.
✓ Branch 1 taken 19701 times.
|
20404 | if (pps->output_flag_present_flag) |
868 | 703 | sh->pic_output_flag = get_bits1(gb); | |
869 | |||
870 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20404 times.
|
20404 | if (sps->separate_colour_plane) |
871 | ✗ | sh->colour_plane_id = get_bits(gb, 2); | |
872 | |||
873 |
4/4✓ Branch 0 taken 19792 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 19763 times.
|
20404 | if (!IS_IDR(s) || |
874 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 629 times.
|
641 | (s->nuh_layer_id > 0 && |
875 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 5 times.
|
12 | !(vps->poc_lsb_not_present & (1 << layer_idx)))) { |
876 | int poc; | ||
877 | |||
878 | 19770 | sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb); | |
879 | 19770 | poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type); | |
880 |
3/4✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9902 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
|
19770 | if (!sh->first_slice_in_pic_flag && poc != sh->poc) { |
881 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
882 | "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc); | ||
883 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
884 | ✗ | return AVERROR_INVALIDDATA; | |
885 | ✗ | poc = sh->poc; | |
886 | } | ||
887 | 19770 | sh->poc = poc; | |
888 | } | ||
889 | |||
890 |
4/4✓ Branch 0 taken 19792 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 19763 times.
✓ Branch 3 taken 29 times.
|
40167 | if (!IS_IDR(s)) { |
891 | int pos; | ||
892 | |||
893 | 19763 | sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); | |
894 | 19763 | pos = get_bits_left(gb); | |
895 |
2/2✓ Branch 0 taken 3499 times.
✓ Branch 1 taken 16264 times.
|
19763 | if (!sh->short_term_ref_pic_set_sps_flag) { |
896 | 3499 | ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1); | |
897 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3499 times.
|
3499 | if (ret < 0) |
898 | ✗ | return ret; | |
899 | |||
900 | 3499 | sh->short_term_rps = &sh->slice_rps; | |
901 | } else { | ||
902 | int numbits, rps_idx; | ||
903 | |||
904 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16264 times.
|
16264 | if (!sps->nb_st_rps) { |
905 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); | |
906 | ✗ | return AVERROR_INVALIDDATA; | |
907 | } | ||
908 | |||
909 | 16264 | numbits = av_ceil_log2(sps->nb_st_rps); | |
910 |
2/2✓ Branch 0 taken 16236 times.
✓ Branch 1 taken 28 times.
|
16264 | rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; |
911 | 16264 | sh->short_term_rps = &sps->st_rps[rps_idx]; | |
912 | } | ||
913 | 19763 | sh->short_term_ref_pic_set_size = pos - get_bits_left(gb); | |
914 | |||
915 | 19763 | pos = get_bits_left(gb); | |
916 | 19763 | ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb); | |
917 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19763 times.
|
19763 | if (ret < 0) { |
918 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n"); | |
919 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
920 | ✗ | return AVERROR_INVALIDDATA; | |
921 | } | ||
922 | 19763 | sh->long_term_ref_pic_set_size = pos - get_bits_left(gb); | |
923 | |||
924 |
2/2✓ Branch 0 taken 17332 times.
✓ Branch 1 taken 2431 times.
|
19763 | if (sps->temporal_mvp_enabled) |
925 | 17332 | sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); | |
926 | else | ||
927 | 2431 | sh->slice_temporal_mvp_enabled_flag = 0; | |
928 | } else { | ||
929 | 641 | sh->poc = 0; | |
930 | 641 | sh->pic_order_cnt_lsb = 0; | |
931 | 641 | sh->short_term_ref_pic_set_sps_flag = 0; | |
932 | 641 | sh->short_term_ref_pic_set_size = 0; | |
933 | 641 | sh->short_term_rps = NULL; | |
934 | 641 | sh->long_term_ref_pic_set_size = 0; | |
935 | 641 | sh->slice_temporal_mvp_enabled_flag = 0; | |
936 | } | ||
937 | |||
938 | 20404 | sh->inter_layer_pred = 0; | |
939 |
2/2✓ Branch 0 taken 327 times.
✓ Branch 1 taken 20077 times.
|
20404 | if (s->nuh_layer_id > 0) { |
940 | 327 | int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx]; | |
941 | |||
942 |
2/2✓ Branch 0 taken 229 times.
✓ Branch 1 taken 98 times.
|
327 | if (vps->default_ref_layers_active) |
943 | 229 | sh->inter_layer_pred = !!num_direct_ref_layers; | |
944 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 50 times.
|
98 | else if (num_direct_ref_layers) { |
945 | 48 | sh->inter_layer_pred = get_bits1(gb); | |
946 | |||
947 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
48 | if (sh->inter_layer_pred && num_direct_ref_layers > 1) { |
948 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
949 | "NumDirectRefLayers>1 not supported\n"); | ||
950 | ✗ | return AVERROR_PATCHWELCOME; | |
951 | } | ||
952 | } | ||
953 | } | ||
954 | |||
955 |
2/2✓ Branch 0 taken 16891 times.
✓ Branch 1 taken 3513 times.
|
20404 | if (sps->sao_enabled) { |
956 | 16891 | sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); | |
957 |
2/2✓ Branch 0 taken 16889 times.
✓ Branch 1 taken 2 times.
|
16891 | if (sps->chroma_format_idc) { |
958 | 16889 | sh->slice_sample_adaptive_offset_flag[1] = | |
959 | 16889 | sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); | |
960 | } | ||
961 | } else { | ||
962 | 3513 | sh->slice_sample_adaptive_offset_flag[0] = 0; | |
963 | 3513 | sh->slice_sample_adaptive_offset_flag[1] = 0; | |
964 | 3513 | sh->slice_sample_adaptive_offset_flag[2] = 0; | |
965 | } | ||
966 | |||
967 | 20404 | sh->nb_refs[L0] = sh->nb_refs[L1] = 0; | |
968 |
4/4✓ Branch 0 taken 16474 times.
✓ Branch 1 taken 3930 times.
✓ Branch 2 taken 15229 times.
✓ Branch 3 taken 1245 times.
|
20404 | if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) { |
969 | int nb_refs; | ||
970 | |||
971 | 19159 | sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active; | |
972 |
2/2✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3930 times.
|
19159 | if (sh->slice_type == HEVC_SLICE_B) |
973 | 15229 | sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active; | |
974 | |||
975 |
2/2✓ Branch 1 taken 4954 times.
✓ Branch 2 taken 14205 times.
|
19159 | if (get_bits1(gb)) { // num_ref_idx_active_override_flag |
976 | 4954 | sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1; | |
977 |
2/2✓ Branch 0 taken 2776 times.
✓ Branch 1 taken 2178 times.
|
4954 | if (sh->slice_type == HEVC_SLICE_B) |
978 | 2776 | sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1; | |
979 | } | ||
980 |
2/4✓ Branch 0 taken 19159 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19159 times.
|
19159 | if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) { |
981 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n", | |
982 | sh->nb_refs[L0], sh->nb_refs[L1]); | ||
983 | ✗ | return AVERROR_INVALIDDATA; | |
984 | } | ||
985 | |||
986 | 19159 | sh->rpl_modification_flag[0] = 0; | |
987 | 19159 | sh->rpl_modification_flag[1] = 0; | |
988 | 19159 | nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx); | |
989 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19159 times.
|
19159 | if (!nb_refs) { |
990 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); | |
991 | ✗ | return AVERROR_INVALIDDATA; | |
992 | } | ||
993 | |||
994 |
4/4✓ Branch 0 taken 1930 times.
✓ Branch 1 taken 17229 times.
✓ Branch 2 taken 1795 times.
✓ Branch 3 taken 135 times.
|
19159 | if (pps->lists_modification_present_flag && nb_refs > 1) { |
995 | 1795 | sh->rpl_modification_flag[0] = get_bits1(gb); | |
996 |
2/2✓ Branch 0 taken 1249 times.
✓ Branch 1 taken 546 times.
|
1795 | if (sh->rpl_modification_flag[0]) { |
997 |
2/2✓ Branch 0 taken 3000 times.
✓ Branch 1 taken 1249 times.
|
4249 | for (i = 0; i < sh->nb_refs[L0]; i++) |
998 | 3000 | sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
999 | } | ||
1000 | |||
1001 |
1/2✓ Branch 0 taken 1795 times.
✗ Branch 1 not taken.
|
1795 | if (sh->slice_type == HEVC_SLICE_B) { |
1002 | 1795 | sh->rpl_modification_flag[1] = get_bits1(gb); | |
1003 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 1143 times.
|
1795 | if (sh->rpl_modification_flag[1] == 1) |
1004 |
2/2✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
|
2207 | for (i = 0; i < sh->nb_refs[L1]; i++) |
1005 | 1555 | sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
1006 | } | ||
1007 | } | ||
1008 | |||
1009 |
2/2✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3930 times.
|
19159 | if (sh->slice_type == HEVC_SLICE_B) |
1010 | 15229 | sh->mvd_l1_zero_flag = get_bits1(gb); | |
1011 | |||
1012 |
2/2✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 2849 times.
|
19159 | if (pps->cabac_init_present_flag) |
1013 | 16310 | sh->cabac_init_flag = get_bits1(gb); | |
1014 | else | ||
1015 | 2849 | sh->cabac_init_flag = 0; | |
1016 | |||
1017 | 19159 | sh->collocated_ref_idx = 0; | |
1018 |
2/2✓ Branch 0 taken 16684 times.
✓ Branch 1 taken 2475 times.
|
19159 | if (sh->slice_temporal_mvp_enabled_flag) { |
1019 | 16684 | sh->collocated_list = L0; | |
1020 |
2/2✓ Branch 0 taken 14695 times.
✓ Branch 1 taken 1989 times.
|
16684 | if (sh->slice_type == HEVC_SLICE_B) |
1021 | 14695 | sh->collocated_list = !get_bits1(gb); | |
1022 | |||
1023 |
2/2✓ Branch 0 taken 14826 times.
✓ Branch 1 taken 1858 times.
|
16684 | if (sh->nb_refs[sh->collocated_list] > 1) { |
1024 | 14826 | sh->collocated_ref_idx = get_ue_golomb_long(gb); | |
1025 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14826 times.
|
14826 | if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { |
1026 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1027 | "Invalid collocated_ref_idx: %d.\n", | ||
1028 | sh->collocated_ref_idx); | ||
1029 | ✗ | return AVERROR_INVALIDDATA; | |
1030 | } | ||
1031 | } | ||
1032 | } | ||
1033 | |||
1034 |
4/4✓ Branch 0 taken 1468 times.
✓ Branch 1 taken 17691 times.
✓ Branch 2 taken 693 times.
✓ Branch 3 taken 775 times.
|
19159 | if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) || |
1035 |
3/4✓ Branch 0 taken 668 times.
✓ Branch 1 taken 17716 times.
✓ Branch 2 taken 668 times.
✗ Branch 3 not taken.
|
18384 | (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) { |
1036 | 1443 | int ret = pred_weight_table(sh, s->avctx, sps, gb); | |
1037 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1443 times.
|
1443 | if (ret < 0) |
1038 | ✗ | return ret; | |
1039 | } | ||
1040 | |||
1041 | 19159 | sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb); | |
1042 |
2/4✓ Branch 0 taken 19159 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19159 times.
|
19159 | if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) { |
1043 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1044 | "Invalid number of merging MVP candidates: %d.\n", | ||
1045 | ✗ | sh->max_num_merge_cand); | |
1046 | ✗ | return AVERROR_INVALIDDATA; | |
1047 | } | ||
1048 | |||
1049 | // Syntax in 7.3.6.1 | ||
1050 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19159 times.
|
19159 | if (sps->motion_vector_resolution_control_idc == 2) |
1051 | ✗ | sh->use_integer_mv_flag = get_bits1(gb); | |
1052 | else | ||
1053 | // Inferred to be equal to motion_vector_resolution_control_idc if not present | ||
1054 | 19159 | sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc; | |
1055 | |||
1056 | } | ||
1057 | |||
1058 | 20404 | sh->slice_qp_delta = get_se_golomb(gb); | |
1059 | |||
1060 |
2/2✓ Branch 0 taken 271 times.
✓ Branch 1 taken 20133 times.
|
20404 | if (pps->pic_slice_level_chroma_qp_offsets_present_flag) { |
1061 | 271 | sh->slice_cb_qp_offset = get_se_golomb(gb); | |
1062 | 271 | sh->slice_cr_qp_offset = get_se_golomb(gb); | |
1063 |
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 || |
1064 |
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) { |
1065 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n"); | |
1066 | ✗ | return AVERROR_INVALIDDATA; | |
1067 | } | ||
1068 | } else { | ||
1069 | 20133 | sh->slice_cb_qp_offset = 0; | |
1070 | 20133 | sh->slice_cr_qp_offset = 0; | |
1071 | } | ||
1072 | |||
1073 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20404 times.
|
20404 | if (pps->pps_slice_act_qp_offsets_present_flag) { |
1074 | ✗ | sh->slice_act_y_qp_offset = get_se_golomb(gb); | |
1075 | ✗ | sh->slice_act_cb_qp_offset = get_se_golomb(gb); | |
1076 | ✗ | sh->slice_act_cr_qp_offset = get_se_golomb(gb); | |
1077 | } | ||
1078 | |||
1079 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 20361 times.
|
20404 | if (pps->chroma_qp_offset_list_enabled_flag) |
1080 | 43 | sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb); | |
1081 | else | ||
1082 | 20361 | sh->cu_chroma_qp_offset_enabled_flag = 0; | |
1083 | |||
1084 |
2/2✓ Branch 0 taken 3059 times.
✓ Branch 1 taken 17345 times.
|
20404 | if (pps->deblocking_filter_control_present_flag) { |
1085 | 3059 | int deblocking_filter_override_flag = 0; | |
1086 | |||
1087 |
2/2✓ Branch 0 taken 696 times.
✓ Branch 1 taken 2363 times.
|
3059 | if (pps->deblocking_filter_override_enabled_flag) |
1088 | 696 | deblocking_filter_override_flag = get_bits1(gb); | |
1089 | |||
1090 |
2/2✓ Branch 0 taken 477 times.
✓ Branch 1 taken 2582 times.
|
3059 | if (deblocking_filter_override_flag) { |
1091 | 477 | sh->disable_deblocking_filter_flag = get_bits1(gb); | |
1092 |
2/2✓ Branch 0 taken 357 times.
✓ Branch 1 taken 120 times.
|
477 | if (!sh->disable_deblocking_filter_flag) { |
1093 | 357 | int beta_offset_div2 = get_se_golomb(gb); | |
1094 | 357 | int tc_offset_div2 = get_se_golomb(gb) ; | |
1095 |
3/6✓ Branch 0 taken 357 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 357 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 357 times.
✗ Branch 5 not taken.
|
357 | if (beta_offset_div2 < -6 || beta_offset_div2 > 6 || |
1096 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 357 times.
|
357 | tc_offset_div2 < -6 || tc_offset_div2 > 6) { |
1097 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1098 | "Invalid deblock filter offsets: %d, %d\n", | ||
1099 | beta_offset_div2, tc_offset_div2); | ||
1100 | ✗ | return AVERROR_INVALIDDATA; | |
1101 | } | ||
1102 | 357 | sh->beta_offset = beta_offset_div2 * 2; | |
1103 | 357 | sh->tc_offset = tc_offset_div2 * 2; | |
1104 | } | ||
1105 | } else { | ||
1106 | 2582 | sh->disable_deblocking_filter_flag = pps->disable_dbf; | |
1107 | 2582 | sh->beta_offset = pps->beta_offset; | |
1108 | 2582 | sh->tc_offset = pps->tc_offset; | |
1109 | } | ||
1110 | } else { | ||
1111 | 17345 | sh->disable_deblocking_filter_flag = 0; | |
1112 | 17345 | sh->beta_offset = 0; | |
1113 | 17345 | sh->tc_offset = 0; | |
1114 | } | ||
1115 | |||
1116 |
2/2✓ Branch 0 taken 17736 times.
✓ Branch 1 taken 2668 times.
|
20404 | if (pps->seq_loop_filter_across_slices_enabled_flag && |
1117 |
2/2✓ Branch 0 taken 11732 times.
✓ Branch 1 taken 6004 times.
|
17736 | (sh->slice_sample_adaptive_offset_flag[0] || |
1118 |
2/2✓ Branch 0 taken 11714 times.
✓ Branch 1 taken 18 times.
|
11732 | sh->slice_sample_adaptive_offset_flag[1] || |
1119 |
2/2✓ Branch 0 taken 11651 times.
✓ Branch 1 taken 63 times.
|
11714 | !sh->disable_deblocking_filter_flag)) { |
1120 | 17673 | sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); | |
1121 | } else { | ||
1122 | 2731 | sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag; | |
1123 | } | ||
1124 | } | ||
1125 | |||
1126 | 28351 | sh->num_entry_point_offsets = 0; | |
1127 |
4/4✓ Branch 0 taken 25440 times.
✓ Branch 1 taken 2911 times.
✓ Branch 2 taken 4737 times.
✓ Branch 3 taken 20703 times.
|
28351 | if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) { |
1128 | 7648 | unsigned num_entry_point_offsets = get_ue_golomb_long(gb); | |
1129 | // It would be possible to bound this tighter but this here is simpler | ||
1130 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7648 times.
|
7648 | if (num_entry_point_offsets > get_bits_left(gb)) { |
1131 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets); | |
1132 | ✗ | return AVERROR_INVALIDDATA; | |
1133 | } | ||
1134 | |||
1135 | 7648 | sh->num_entry_point_offsets = num_entry_point_offsets; | |
1136 |
2/2✓ Branch 0 taken 2174 times.
✓ Branch 1 taken 5474 times.
|
7648 | if (sh->num_entry_point_offsets > 0) { |
1137 | 2174 | int offset_len = get_ue_golomb_long(gb) + 1; | |
1138 | |||
1139 |
2/4✓ Branch 0 taken 2174 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2174 times.
|
2174 | if (offset_len < 1 || offset_len > 32) { |
1140 | ✗ | sh->num_entry_point_offsets = 0; | |
1141 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len); | |
1142 | ✗ | return AVERROR_INVALIDDATA; | |
1143 | } | ||
1144 | |||
1145 | 2174 | av_freep(&sh->entry_point_offset); | |
1146 | 2174 | av_freep(&sh->offset); | |
1147 | 2174 | av_freep(&sh->size); | |
1148 | 2174 | sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned)); | |
1149 | 2174 | sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
1150 | 2174 | sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
1151 |
3/6✓ Branch 0 taken 2174 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2174 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2174 times.
|
2174 | if (!sh->entry_point_offset || !sh->offset || !sh->size) { |
1152 | ✗ | sh->num_entry_point_offsets = 0; | |
1153 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n"); | |
1154 | ✗ | return AVERROR(ENOMEM); | |
1155 | } | ||
1156 |
2/2✓ Branch 0 taken 9742 times.
✓ Branch 1 taken 2174 times.
|
11916 | for (i = 0; i < sh->num_entry_point_offsets; i++) { |
1157 | 9742 | unsigned val = get_bits_long(gb, offset_len); | |
1158 | 9742 | sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size | |
1159 | } | ||
1160 | } | ||
1161 | } | ||
1162 | |||
1163 |
2/2✓ Branch 0 taken 2769 times.
✓ Branch 1 taken 25582 times.
|
28351 | if (pps->slice_header_extension_present_flag) { |
1164 | 2769 | unsigned int length = get_ue_golomb_long(gb); | |
1165 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2769 times.
|
2769 | if (length*8LL > get_bits_left(gb)) { |
1166 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n"); | |
1167 | ✗ | return AVERROR_INVALIDDATA; | |
1168 | } | ||
1169 |
2/2✓ Branch 0 taken 20292 times.
✓ Branch 1 taken 2769 times.
|
23061 | for (i = 0; i < length; i++) |
1170 | 20292 | skip_bits(gb, 8); // slice_header_extension_data_byte | |
1171 | } | ||
1172 | |||
1173 | 28351 | ret = get_bits1(gb); | |
1174 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28351 times.
|
28351 | if (!ret) { |
1175 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n"); | |
1176 | ✗ | return AVERROR_INVALIDDATA; | |
1177 | } | ||
1178 | 28351 | sh->data_offset = align_get_bits(gb) - gb->buffer; | |
1179 | |||
1180 | // Inferred parameters | ||
1181 | 28351 | sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta; | |
1182 |
1/2✓ Branch 0 taken 28351 times.
✗ Branch 1 not taken.
|
28351 | if (sh->slice_qp > 51 || |
1183 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28351 times.
|
28351 | sh->slice_qp < -sps->qp_bd_offset) { |
1184 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1185 | "The slice_qp %d is outside the valid range " | ||
1186 | "[%d, 51].\n", | ||
1187 | ✗ | sh->slice_qp, | |
1188 | ✗ | -sps->qp_bd_offset); | |
1189 | ✗ | return AVERROR_INVALIDDATA; | |
1190 | } | ||
1191 | |||
1192 | 28351 | sh->slice_ctb_addr_rs = sh->slice_segment_addr; | |
1193 | |||
1194 |
2/2✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20404 times.
|
28351 | if (sh->dependent_slice_segment_flag && |
1195 |
2/4✓ Branch 0 taken 7947 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7947 times.
|
7947 | (!sh->slice_ctb_addr_rs || !pps->ctb_addr_rs_to_ts[sh->slice_ctb_addr_rs])) { |
1196 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n"); | |
1197 | ✗ | return AVERROR_INVALIDDATA; | |
1198 | } | ||
1199 | |||
1200 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28351 times.
|
28351 | if (get_bits_left(gb) < 0) { |
1201 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1202 | ✗ | "Overread slice header by %d bits\n", -get_bits_left(gb)); | |
1203 | ✗ | return AVERROR_INVALIDDATA; | |
1204 | } | ||
1205 | |||
1206 | 28351 | return 0; | |
1207 | } | ||
1208 | |||
1209 | #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)]) | ||
1210 | |||
1211 | #define SET_SAO(elem, value) \ | ||
1212 | do { \ | ||
1213 | if (!sao_merge_up_flag && !sao_merge_left_flag) \ | ||
1214 | sao->elem = value; \ | ||
1215 | else if (sao_merge_left_flag) \ | ||
1216 | sao->elem = CTB(l->sao, rx-1, ry).elem; \ | ||
1217 | else if (sao_merge_up_flag) \ | ||
1218 | sao->elem = CTB(l->sao, rx, ry-1).elem; \ | ||
1219 | else \ | ||
1220 | sao->elem = 0; \ | ||
1221 | } while (0) | ||
1222 | |||
1223 | 1587220 | static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
1224 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1225 | int rx, int ry) | ||
1226 | { | ||
1227 | 1587220 | const HEVCContext *const s = lc->parent; | |
1228 | 1587220 | int sao_merge_left_flag = 0; | |
1229 | 1587220 | int sao_merge_up_flag = 0; | |
1230 | 1587220 | SAOParams *sao = &CTB(l->sao, rx, ry); | |
1231 | int c_idx, i; | ||
1232 | |||
1233 |
2/2✓ Branch 0 taken 863042 times.
✓ Branch 1 taken 724178 times.
|
1587220 | if (s->sh.slice_sample_adaptive_offset_flag[0] || |
1234 |
2/2✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 861398 times.
|
863042 | s->sh.slice_sample_adaptive_offset_flag[1]) { |
1235 |
2/2✓ Branch 0 taken 689134 times.
✓ Branch 1 taken 36688 times.
|
725822 | if (rx > 0) { |
1236 |
2/2✓ Branch 0 taken 680599 times.
✓ Branch 1 taken 8535 times.
|
689134 | if (lc->ctb_left_flag) |
1237 | 680599 | sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc); | |
1238 | } | ||
1239 |
4/4✓ Branch 0 taken 666917 times.
✓ Branch 1 taken 58905 times.
✓ Branch 2 taken 350417 times.
✓ Branch 3 taken 316500 times.
|
725822 | if (ry > 0 && !sao_merge_left_flag) { |
1240 |
2/2✓ Branch 0 taken 337048 times.
✓ Branch 1 taken 13369 times.
|
350417 | if (lc->ctb_up_flag) |
1241 | 337048 | sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc); | |
1242 | } | ||
1243 | } | ||
1244 | |||
1245 |
4/4✓ Branch 0 taken 6348688 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4761564 times.
✓ Branch 3 taken 1587220 times.
|
6348784 | for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) { |
1246 |
2/2✓ Branch 0 taken 1587220 times.
✓ Branch 1 taken 3174344 times.
|
4761564 | int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma : |
1247 | 3174344 | pps->log2_sao_offset_scale_chroma; | |
1248 | |||
1249 |
2/2✓ Branch 0 taken 3127126 times.
✓ Branch 1 taken 1634438 times.
|
4761564 | if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) { |
1250 | 3127126 | sao->type_idx[c_idx] = SAO_NOT_APPLIED; | |
1251 | 3127126 | continue; | |
1252 | } | ||
1253 | |||
1254 |
2/2✓ Branch 0 taken 455130 times.
✓ Branch 1 taken 1179308 times.
|
1634438 | if (c_idx == 2) { |
1255 | 455130 | sao->type_idx[2] = sao->type_idx[1]; | |
1256 | 455130 | sao->eo_class[2] = sao->eo_class[1]; | |
1257 | } else { | ||
1258 |
7/8✓ Branch 0 taken 1040114 times.
✓ Branch 1 taken 139194 times.
✓ Branch 2 taken 516600 times.
✓ Branch 3 taken 523514 times.
✓ Branch 5 taken 523514 times.
✓ Branch 6 taken 139194 times.
✓ Branch 7 taken 139194 times.
✗ Branch 8 not taken.
|
1179308 | SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc)); |
1259 | } | ||
1260 | |||
1261 |
2/2✓ Branch 0 taken 1097240 times.
✓ Branch 1 taken 537198 times.
|
1634438 | if (sao->type_idx[c_idx] == SAO_NOT_APPLIED) |
1262 | 1097240 | continue; | |
1263 | |||
1264 |
2/2✓ Branch 0 taken 2148792 times.
✓ Branch 1 taken 537198 times.
|
2685990 | for (i = 0; i < 4; i++) |
1265 |
7/8✓ Branch 0 taken 1770148 times.
✓ Branch 1 taken 378644 times.
✓ Branch 2 taken 911152 times.
✓ Branch 3 taken 858996 times.
✓ Branch 5 taken 858996 times.
✓ Branch 6 taken 378644 times.
✓ Branch 7 taken 378644 times.
✗ Branch 8 not taken.
|
2148792 | SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth)); |
1266 | |||
1267 |
2/2✓ Branch 0 taken 119646 times.
✓ Branch 1 taken 417552 times.
|
537198 | if (sao->type_idx[c_idx] == SAO_BAND) { |
1268 |
2/2✓ Branch 0 taken 478584 times.
✓ Branch 1 taken 119646 times.
|
598230 | for (i = 0; i < 4; i++) { |
1269 |
2/2✓ Branch 0 taken 358111 times.
✓ Branch 1 taken 120473 times.
|
478584 | if (sao->offset_abs[c_idx][i]) { |
1270 |
7/8✓ Branch 0 taken 332770 times.
✓ Branch 1 taken 25341 times.
✓ Branch 2 taken 246136 times.
✓ Branch 3 taken 86634 times.
✓ Branch 5 taken 86634 times.
✓ Branch 6 taken 25341 times.
✓ Branch 7 taken 25341 times.
✗ Branch 8 not taken.
|
358111 | SET_SAO(offset_sign[c_idx][i], |
1271 | ff_hevc_sao_offset_sign_decode(lc)); | ||
1272 | } else { | ||
1273 | 120473 | sao->offset_sign[c_idx][i] = 0; | |
1274 | } | ||
1275 | } | ||
1276 |
7/8✓ Branch 0 taken 109384 times.
✓ Branch 1 taken 10262 times.
✓ Branch 2 taken 79308 times.
✓ Branch 3 taken 30076 times.
✓ Branch 5 taken 30076 times.
✓ Branch 6 taken 10262 times.
✓ Branch 7 taken 10262 times.
✗ Branch 8 not taken.
|
119646 | SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc)); |
1277 |
2/2✓ Branch 0 taken 336178 times.
✓ Branch 1 taken 81374 times.
|
417552 | } else if (c_idx != 2) { |
1278 |
7/8✓ Branch 0 taken 268141 times.
✓ Branch 1 taken 68037 times.
✓ Branch 2 taken 115919 times.
✓ Branch 3 taken 152222 times.
✓ Branch 5 taken 152222 times.
✓ Branch 6 taken 68037 times.
✓ Branch 7 taken 68037 times.
✗ Branch 8 not taken.
|
336178 | SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc)); |
1279 | } | ||
1280 | |||
1281 | // Inferred parameters | ||
1282 | 537198 | sao->offset_val[c_idx][0] = 0; | |
1283 |
2/2✓ Branch 0 taken 2148792 times.
✓ Branch 1 taken 537198 times.
|
2685990 | for (i = 0; i < 4; i++) { |
1284 | 2148792 | sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i]; | |
1285 |
2/2✓ Branch 0 taken 1670208 times.
✓ Branch 1 taken 478584 times.
|
2148792 | if (sao->type_idx[c_idx] == SAO_EDGE) { |
1286 |
2/2✓ Branch 0 taken 835104 times.
✓ Branch 1 taken 835104 times.
|
1670208 | if (i > 1) |
1287 | 835104 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1288 |
2/2✓ Branch 0 taken 158152 times.
✓ Branch 1 taken 320432 times.
|
478584 | } else if (sao->offset_sign[c_idx][i]) { |
1289 | 158152 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1290 | } | ||
1291 | 2148792 | sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale; | |
1292 | } | ||
1293 | } | ||
1294 | 1587220 | } | |
1295 | |||
1296 | #undef SET_SAO | ||
1297 | #undef CTB | ||
1298 | |||
1299 | 384850 | static int hls_cross_component_pred(HEVCLocalContext *lc, int idx) | |
1300 | { | ||
1301 | 384850 | int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx); | |
1302 | |||
1303 |
2/2✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
|
384850 | if (log2_res_scale_abs_plus1 != 0) { |
1304 | 235843 | int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx); | |
1305 | 235843 | lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) * | |
1306 | 235843 | (1 - 2 * res_scale_sign_flag); | |
1307 | } else { | ||
1308 | 149007 | lc->tu.res_scale_val = 0; | |
1309 | } | ||
1310 | |||
1311 | |||
1312 | 384850 | return 0; | |
1313 | } | ||
1314 | |||
1315 | 16177488 | static int hls_transform_unit(HEVCLocalContext *lc, | |
1316 | const HEVCLayerContext *l, | ||
1317 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1318 | int x0, int y0, | ||
1319 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1320 | int log2_cb_size, int log2_trafo_size, | ||
1321 | int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr) | ||
1322 | { | ||
1323 | 16177488 | const HEVCContext *const s = lc->parent; | |
1324 | 16177488 | const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1]; | |
1325 | int i; | ||
1326 | |||
1327 |
2/2✓ Branch 0 taken 10218829 times.
✓ Branch 1 taken 5958659 times.
|
16177488 | if (lc->cu.pred_mode == MODE_INTRA) { |
1328 | 10218829 | int trafo_size = 1 << log2_trafo_size; | |
1329 | 10218829 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size); | |
1330 | |||
1331 | 10218829 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0); | |
1332 | } | ||
1333 | |||
1334 |
6/6✓ Branch 0 taken 5862495 times.
✓ Branch 1 taken 10314993 times.
✓ Branch 2 taken 5210048 times.
✓ Branch 3 taken 652447 times.
✓ Branch 4 taken 4761246 times.
✓ Branch 5 taken 448802 times.
|
16177488 | if (cbf_luma || cbf_cb[0] || cbf_cr[0] || |
1335 |
6/6✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4605479 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
|
16239302 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1336 | 11478057 | int scan_idx = SCAN_DIAG; | |
1337 | 11478057 | int scan_idx_c = SCAN_DIAG; | |
1338 |
4/4✓ Branch 0 taken 7721567 times.
✓ Branch 1 taken 3756490 times.
✓ Branch 2 taken 6153597 times.
✓ Branch 3 taken 1567970 times.
|
17631654 | int cbf_chroma = cbf_cb[0] || cbf_cr[0] || |
1339 |
2/2✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 5921887 times.
|
6153597 | (sps->chroma_format_idc == 2 && |
1340 |
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])); |
1341 | |||
1342 |
4/4✓ Branch 0 taken 2367146 times.
✓ Branch 1 taken 9110911 times.
✓ Branch 2 taken 709134 times.
✓ Branch 3 taken 1658012 times.
|
11478057 | if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) { |
1343 | 709134 | lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc); | |
1344 |
2/2✓ Branch 0 taken 390722 times.
✓ Branch 1 taken 318412 times.
|
709134 | if (lc->tu.cu_qp_delta != 0) |
1345 |
2/2✓ Branch 1 taken 215573 times.
✓ Branch 2 taken 175149 times.
|
390722 | if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1) |
1346 | 215573 | lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta; | |
1347 | 709134 | lc->tu.is_cu_qp_delta_coded = 1; | |
1348 | |||
1349 |
2/2✓ Branch 0 taken 709133 times.
✓ Branch 1 taken 1 times.
|
709134 | if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) || |
1350 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 709133 times.
|
709133 | lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) { |
1351 | 1 | av_log(s->avctx, AV_LOG_ERROR, | |
1352 | "The cu_qp_delta %d is outside the valid range " | ||
1353 | "[%d, %d].\n", | ||
1354 | lc->tu.cu_qp_delta, | ||
1355 | 1 | -(26 + sps->qp_bd_offset / 2), | |
1356 | 1 | (25 + sps->qp_bd_offset / 2)); | |
1357 | 1 | return AVERROR_INVALIDDATA; | |
1358 | } | ||
1359 | |||
1360 | 709133 | ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size); | |
1361 | } | ||
1362 | |||
1363 |
4/4✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 10586105 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
|
11478056 | if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma && |
1364 |
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) { |
1365 | 266275 | int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc); | |
1366 |
2/2✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
|
266275 | if (cu_chroma_qp_offset_flag) { |
1367 | 48966 | int cu_chroma_qp_offset_idx = 0; | |
1368 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
|
48966 | if (pps->chroma_qp_offset_list_len_minus1 > 0) { |
1369 | ✗ | cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1); | |
1370 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1371 | "cu_chroma_qp_offset_idx not yet tested.\n"); | ||
1372 | } | ||
1373 | 48966 | lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1374 | 48966 | lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1375 | } else { | ||
1376 | 217309 | lc->tu.cu_qp_offset_cb = 0; | |
1377 | 217309 | lc->tu.cu_qp_offset_cr = 0; | |
1378 | } | ||
1379 | 266275 | lc->tu.is_cu_chroma_qp_offset_coded = 1; | |
1380 | } | ||
1381 | |||
1382 |
4/4✓ Branch 0 taken 7526425 times.
✓ Branch 1 taken 3951631 times.
✓ Branch 2 taken 6536736 times.
✓ Branch 3 taken 989689 times.
|
11478056 | if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) { |
1383 |
2/2✓ Branch 0 taken 4356263 times.
✓ Branch 1 taken 2180473 times.
|
6536736 | if (lc->tu.intra_pred_mode >= 6 && |
1384 |
2/2✓ Branch 0 taken 1561999 times.
✓ Branch 1 taken 2794264 times.
|
4356263 | lc->tu.intra_pred_mode <= 14) { |
1385 | 1561999 | scan_idx = SCAN_VERT; | |
1386 |
2/2✓ Branch 0 taken 2153853 times.
✓ Branch 1 taken 2820884 times.
|
4974737 | } else if (lc->tu.intra_pred_mode >= 22 && |
1387 |
2/2✓ Branch 0 taken 1811955 times.
✓ Branch 1 taken 341898 times.
|
2153853 | lc->tu.intra_pred_mode <= 30) { |
1388 | 1811955 | scan_idx = SCAN_HORIZ; | |
1389 | } | ||
1390 | |||
1391 |
2/2✓ Branch 0 taken 3912194 times.
✓ Branch 1 taken 2624542 times.
|
6536736 | if (lc->tu.intra_pred_mode_c >= 6 && |
1392 |
2/2✓ Branch 0 taken 1471861 times.
✓ Branch 1 taken 2440333 times.
|
3912194 | lc->tu.intra_pred_mode_c <= 14) { |
1393 | 1471861 | scan_idx_c = SCAN_VERT; | |
1394 |
2/2✓ Branch 0 taken 2046283 times.
✓ Branch 1 taken 3018592 times.
|
5064875 | } else if (lc->tu.intra_pred_mode_c >= 22 && |
1395 |
2/2✓ Branch 0 taken 1714788 times.
✓ Branch 1 taken 331495 times.
|
2046283 | lc->tu.intra_pred_mode_c <= 30) { |
1396 | 1714788 | scan_idx_c = SCAN_HORIZ; | |
1397 | } | ||
1398 | } | ||
1399 | |||
1400 | 11478056 | lc->tu.cross_pf = 0; | |
1401 | |||
1402 |
2/2✓ Branch 0 taken 10314992 times.
✓ Branch 1 taken 1163064 times.
|
11478056 | if (cbf_luma) |
1403 | 10314992 | ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0); | |
1404 |
6/6✓ Branch 0 taken 11477864 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6355228 times.
✓ Branch 3 taken 5122636 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 6145665 times.
|
16810255 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
1405 | 5332199 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
1406 | 5332199 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
1407 |
4/4✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 4995358 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
|
5550015 | lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma && |
1408 |
2/2✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
|
217816 | (lc->cu.pred_mode == MODE_INTER || |
1409 |
2/2✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
|
168873 | (lc->tu.chroma_mode_c == 4))); |
1410 | |||
1411 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5139774 times.
|
5332199 | if (lc->tu.cross_pf) { |
1412 | 192425 | hls_cross_component_pred(lc, 0); | |
1413 | } | ||
1414 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9757994 times.
✓ Branch 2 taken 5785401 times.
✓ Branch 3 taken 5332199 times.
|
11117600 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1415 |
2/2✓ Branch 0 taken 3191234 times.
✓ Branch 1 taken 2594167 times.
|
5785401 | if (lc->cu.pred_mode == MODE_INTRA) { |
1416 | 3191234 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
1417 | 3191234 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1418 | 3191234 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1); | |
1419 | } | ||
1420 |
2/2✓ Branch 0 taken 1572006 times.
✓ Branch 1 taken 4213395 times.
|
5785401 | if (cbf_cb[i]) |
1421 | 1572006 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
1422 | log2_trafo_size_c, scan_idx_c, 1); | ||
1423 | else | ||
1424 |
2/2✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 4173737 times.
|
4213395 | if (lc->tu.cross_pf) { |
1425 | 39658 | ptrdiff_t stride = s->cur_frame->f->linesize[1]; | |
1426 | 39658 | int hshift = sps->hshift[1]; | |
1427 | 39658 | int vshift = sps->vshift[1]; | |
1428 | 39658 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1429 | 39658 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1430 | 39658 | int size = 1 << log2_trafo_size_c; | |
1431 | |||
1432 | 39658 | uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride + | |
1433 | 39658 | ((x0 >> hshift) << sps->pixel_shift)]; | |
1434 |
2/2✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
|
1871162 | for (i = 0; i < (size * size); i++) { |
1435 | 1831504 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1436 | } | ||
1437 | 39658 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1438 | } | ||
1439 | } | ||
1440 | |||
1441 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5139774 times.
|
5332199 | if (lc->tu.cross_pf) { |
1442 | 192425 | hls_cross_component_pred(lc, 1); | |
1443 | } | ||
1444 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9757994 times.
✓ Branch 2 taken 5785401 times.
✓ Branch 3 taken 5332199 times.
|
11117600 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1445 |
2/2✓ Branch 0 taken 3191234 times.
✓ Branch 1 taken 2594167 times.
|
5785401 | if (lc->cu.pred_mode == MODE_INTRA) { |
1446 | 3191234 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
1447 | 3191234 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1448 | 3191234 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2); | |
1449 | } | ||
1450 |
2/2✓ Branch 0 taken 1722198 times.
✓ Branch 1 taken 4063203 times.
|
5785401 | if (cbf_cr[i]) |
1451 | 1722198 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
1452 | log2_trafo_size_c, scan_idx_c, 2); | ||
1453 | else | ||
1454 |
2/2✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 3987279 times.
|
4063203 | if (lc->tu.cross_pf) { |
1455 | 75924 | ptrdiff_t stride = s->cur_frame->f->linesize[2]; | |
1456 | 75924 | int hshift = sps->hshift[2]; | |
1457 | 75924 | int vshift = sps->vshift[2]; | |
1458 | 75924 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1459 | 75924 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1460 | 75924 | int size = 1 << log2_trafo_size_c; | |
1461 | |||
1462 | 75924 | uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride + | |
1463 | 75924 | ((x0 >> hshift) << sps->pixel_shift)]; | |
1464 |
2/2✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
|
3691476 | for (i = 0; i < (size * size); i++) { |
1465 | 3615552 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1466 | } | ||
1467 | 75924 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1468 | } | ||
1469 | } | ||
1470 |
4/4✓ Branch 0 taken 6145665 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1579251 times.
✓ Branch 3 taken 4566414 times.
|
6145857 | } else if (sps->chroma_format_idc && blk_idx == 3) { |
1471 | 1579251 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1472 | 1579251 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
1473 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2824764 times.
✓ Branch 2 taken 1746120 times.
✓ Branch 3 taken 1579251 times.
|
3325371 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1474 |
2/2✓ Branch 0 taken 1248351 times.
✓ Branch 1 taken 497769 times.
|
1746120 | if (lc->cu.pred_mode == MODE_INTRA) { |
1475 | 1248351 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
1476 | 1248351 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1477 | 1248351 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1); | |
1478 | } | ||
1479 |
2/2✓ Branch 0 taken 660715 times.
✓ Branch 1 taken 1085405 times.
|
1746120 | if (cbf_cb[i]) |
1480 | 660715 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
1481 | log2_trafo_size, scan_idx_c, 1); | ||
1482 | } | ||
1483 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2824764 times.
✓ Branch 2 taken 1746120 times.
✓ Branch 3 taken 1579251 times.
|
3325371 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1484 |
2/2✓ Branch 0 taken 1248351 times.
✓ Branch 1 taken 497769 times.
|
1746120 | if (lc->cu.pred_mode == MODE_INTRA) { |
1485 | 1248351 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
1486 | 1248351 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1487 | 1248351 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2); | |
1488 | } | ||
1489 |
2/2✓ Branch 0 taken 751123 times.
✓ Branch 1 taken 994997 times.
|
1746120 | if (cbf_cr[i]) |
1490 | 751123 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
1491 | log2_trafo_size, scan_idx_c, 2); | ||
1492 | } | ||
1493 | } | ||
1494 |
3/4✓ Branch 0 taken 4699431 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2692403 times.
✓ Branch 3 taken 2007028 times.
|
4699431 | } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) { |
1495 |
4/4✓ Branch 0 taken 1652739 times.
✓ Branch 1 taken 1039664 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1592151 times.
|
3792655 | if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) { |
1496 | 1100252 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
1497 | 1100252 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
1498 | 1100252 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v, | |
1499 | 1100252 | sps->log2_ctb_size); | |
1500 | 1100252 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1); | |
1501 | 1100252 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2); | |
1502 |
2/2✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 1087785 times.
|
1100252 | if (sps->chroma_format_idc == 2) { |
1503 | 12467 | ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c), | |
1504 | 12467 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1505 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1); | |
1506 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2); | |
1507 | } | ||
1508 |
2/2✓ Branch 0 taken 361032 times.
✓ Branch 1 taken 1231119 times.
|
1592151 | } else if (blk_idx == 3) { |
1509 | 361032 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1510 | 361032 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
1511 | 361032 | ff_hevc_set_neighbour_available(lc, xBase, yBase, | |
1512 | 361032 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1513 | 361032 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1); | |
1514 | 361032 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2); | |
1515 |
2/2✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 356836 times.
|
361032 | if (sps->chroma_format_idc == 2) { |
1516 | 4196 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size), | |
1517 | 4196 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1518 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1); | |
1519 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2); | |
1520 | } | ||
1521 | } | ||
1522 | } | ||
1523 | |||
1524 | 16177487 | return 0; | |
1525 | } | ||
1526 | |||
1527 | 403332 | static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps, | |
1528 | int x0, int y0, int log2_cb_size) | ||
1529 | { | ||
1530 | 403332 | int cb_size = 1 << log2_cb_size; | |
1531 | 403332 | int log2_min_pu_size = sps->log2_min_pu_size; | |
1532 | |||
1533 | 403332 | int min_pu_width = sps->min_pu_width; | |
1534 | 403332 | int x_end = FFMIN(x0 + cb_size, sps->width); | |
1535 | 403332 | int y_end = FFMIN(y0 + cb_size, sps->height); | |
1536 | int i, j; | ||
1537 | |||
1538 |
2/2✓ Branch 0 taken 562404 times.
✓ Branch 1 taken 403332 times.
|
965736 | for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++) |
1539 |
2/2✓ Branch 0 taken 1073856 times.
✓ Branch 1 taken 562404 times.
|
1636260 | for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++) |
1540 | 1073856 | is_pcm[i + j * min_pu_width] = 2; | |
1541 | 403332 | } | |
1542 | |||
1543 | 19484937 | static int hls_transform_tree(HEVCLocalContext *lc, | |
1544 | const HEVCLayerContext *l, | ||
1545 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1546 | int x0, int y0, | ||
1547 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1548 | int log2_cb_size, int log2_trafo_size, | ||
1549 | int trafo_depth, int blk_idx, | ||
1550 | const int *base_cbf_cb, const int *base_cbf_cr) | ||
1551 | { | ||
1552 | 19484937 | const HEVCContext *const s = lc->parent; | |
1553 | uint8_t split_transform_flag; | ||
1554 | int cbf_cb[2]; | ||
1555 | int cbf_cr[2]; | ||
1556 | int ret; | ||
1557 | |||
1558 | 19484937 | cbf_cb[0] = base_cbf_cb[0]; | |
1559 | 19484937 | cbf_cb[1] = base_cbf_cb[1]; | |
1560 | 19484937 | cbf_cr[0] = base_cbf_cr[0]; | |
1561 | 19484937 | cbf_cr[1] = base_cbf_cr[1]; | |
1562 | |||
1563 |
2/2✓ Branch 0 taken 6582346 times.
✓ Branch 1 taken 12902591 times.
|
19484937 | if (lc->cu.intra_split_flag) { |
1564 |
2/2✓ Branch 0 taken 4963816 times.
✓ Branch 1 taken 1618530 times.
|
6582346 | if (trafo_depth == 1) { |
1565 | 4963816 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx]; | |
1566 |
2/2✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4828412 times.
|
4963816 | if (sps->chroma_format_idc == 3) { |
1567 | 135404 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx]; | |
1568 | 135404 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx]; | |
1569 | } else { | ||
1570 | 4828412 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1571 | 4828412 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1572 | } | ||
1573 | } | ||
1574 | } else { | ||
1575 | 12902591 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0]; | |
1576 | 12902591 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1577 | 12902591 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1578 | } | ||
1579 | |||
1580 |
2/2✓ Branch 0 taken 19360742 times.
✓ Branch 1 taken 124195 times.
|
19484937 | if (log2_trafo_size <= sps->log2_max_trafo_size && |
1581 |
2/2✓ Branch 0 taken 10268690 times.
✓ Branch 1 taken 9092052 times.
|
19360742 | log2_trafo_size > sps->log2_min_tb_size && |
1582 |
2/2✓ Branch 0 taken 8634658 times.
✓ Branch 1 taken 1634032 times.
|
10268690 | trafo_depth < lc->cu.max_trafo_depth && |
1583 |
4/4✓ Branch 0 taken 1724179 times.
✓ Branch 1 taken 6910479 times.
✓ Branch 2 taken 490612 times.
✓ Branch 3 taken 1233567 times.
|
8634658 | !(lc->cu.intra_split_flag && trafo_depth == 0)) { |
1584 | 7401091 | split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size); | |
1585 | } else { | ||
1586 | 25848607 | int inter_split = sps->max_transform_hierarchy_depth_inter == 0 && | |
1587 |
2/2✓ Branch 0 taken 836848 times.
✓ Branch 1 taken 844067 times.
|
1680915 | lc->cu.pred_mode == MODE_INTER && |
1588 |
6/6✓ Branch 0 taken 1680915 times.
✓ Branch 1 taken 10402931 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 161299 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
|
13764761 | lc->cu.part_mode != PART_2Nx2N && |
1589 | trafo_depth == 0; | ||
1590 | |||
1591 | 12083846 | split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size || | |
1592 |
8/8✓ Branch 0 taken 11959651 times.
✓ Branch 1 taken 124195 times.
✓ Branch 2 taken 6083687 times.
✓ Branch 3 taken 5875964 times.
✓ Branch 4 taken 4850120 times.
✓ Branch 5 taken 1233567 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10607446 times.
|
12083846 | (lc->cu.intra_split_flag && trafo_depth == 0) || |
1593 | inter_split; | ||
1594 | } | ||
1595 | |||
1596 |
6/6✓ Branch 0 taken 19484745 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8963972 times.
✓ Branch 3 taken 10520773 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8649556 times.
|
19484937 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
1597 |
4/4✓ Branch 0 taken 4580240 times.
✓ Branch 1 taken 6254949 times.
✓ Branch 2 taken 1259672 times.
✓ Branch 3 taken 3320568 times.
|
10835189 | if (trafo_depth == 0 || cbf_cb[0]) { |
1598 | 7514621 | cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1599 |
6/6✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 6916355 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
|
7514621 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1600 | 526996 | cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1601 | } | ||
1602 | } | ||
1603 | |||
1604 |
4/4✓ Branch 0 taken 4580240 times.
✓ Branch 1 taken 6254949 times.
✓ Branch 2 taken 1221820 times.
✓ Branch 3 taken 3358420 times.
|
10835189 | if (trafo_depth == 0 || cbf_cr[0]) { |
1605 | 7476769 | cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1606 |
6/6✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6731463 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
|
7476769 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1607 | 661961 | cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1608 | } | ||
1609 | } | ||
1610 | } | ||
1611 | |||
1612 |
2/2✓ Branch 0 taken 3307449 times.
✓ Branch 1 taken 16177488 times.
|
19484937 | if (split_transform_flag) { |
1613 | 3307449 | const int trafo_size_split = 1 << (log2_trafo_size - 1); | |
1614 | 3307449 | const int x1 = x0 + trafo_size_split; | |
1615 | 3307449 | const int y1 = y0 + trafo_size_split; | |
1616 | |||
1617 | #define SUBDIVIDE(x, y, idx) \ | ||
1618 | do { \ | ||
1619 | ret = hls_transform_tree(lc, l, pps, sps, \ | ||
1620 | x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \ | ||
1621 | log2_trafo_size - 1, trafo_depth + 1, idx, \ | ||
1622 | cbf_cb, cbf_cr); \ | ||
1623 | if (ret < 0) \ | ||
1624 | return ret; \ | ||
1625 | } while (0) | ||
1626 | |||
1627 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3307449 times.
|
3307449 | SUBDIVIDE(x0, y0, 0); |
1628 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3307449 times.
|
3307449 | SUBDIVIDE(x1, y0, 1); |
1629 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3307449 times.
|
3307449 | SUBDIVIDE(x0, y1, 2); |
1630 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3307449 times.
|
3307449 | SUBDIVIDE(x1, y1, 3); |
1631 | |||
1632 | #undef SUBDIVIDE | ||
1633 | } else { | ||
1634 | 16177488 | int min_tu_size = 1 << sps->log2_min_tb_size; | |
1635 | 16177488 | int log2_min_tu_size = sps->log2_min_tb_size; | |
1636 | 16177488 | int min_tu_width = sps->min_tb_width; | |
1637 | 16177488 | int cbf_luma = 1; | |
1638 | |||
1639 |
4/4✓ Branch 0 taken 5958659 times.
✓ Branch 1 taken 10218829 times.
✓ Branch 2 taken 1125721 times.
✓ Branch 3 taken 4832938 times.
|
16177488 | if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 || |
1640 |
4/4✓ Branch 0 taken 924463 times.
✓ Branch 1 taken 201258 times.
✓ Branch 2 taken 790548 times.
✓ Branch 3 taken 133915 times.
|
1125721 | cbf_cb[0] || cbf_cr[0] || |
1641 |
6/6✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 765872 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
|
790548 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1642 | 15399586 | cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth); | |
1643 | } | ||
1644 | |||
1645 | 16177488 | ret = hls_transform_unit(lc, l, pps, sps, | |
1646 | x0, y0, xBase, yBase, cb_xBase, cb_yBase, | ||
1647 | log2_cb_size, log2_trafo_size, | ||
1648 | blk_idx, cbf_luma, cbf_cb, cbf_cr); | ||
1649 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16177487 times.
|
16177488 | if (ret < 0) |
1650 | 1 | return ret; | |
1651 | // TODO: store cbf_luma somewhere else | ||
1652 |
2/2✓ Branch 0 taken 10314992 times.
✓ Branch 1 taken 5862495 times.
|
16177487 | if (cbf_luma) { |
1653 | int i, j; | ||
1654 |
2/2✓ Branch 0 taken 21844231 times.
✓ Branch 1 taken 10314992 times.
|
32159223 | for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size) |
1655 |
2/2✓ Branch 0 taken 82090655 times.
✓ Branch 1 taken 21844231 times.
|
103934886 | for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) { |
1656 | 82090655 | int x_tu = (x0 + j) >> log2_min_tu_size; | |
1657 | 82090655 | int y_tu = (y0 + i) >> log2_min_tu_size; | |
1658 | 82090655 | l->cbf_luma[y_tu * min_tu_width + x_tu] = 1; | |
1659 | } | ||
1660 | } | ||
1661 |
2/2✓ Branch 0 taken 15644667 times.
✓ Branch 1 taken 532820 times.
|
16177487 | if (!s->sh.disable_deblocking_filter_flag) { |
1662 | 15644667 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size); | |
1663 |
2/2✓ Branch 0 taken 409146 times.
✓ Branch 1 taken 15235521 times.
|
15644667 | if (pps->transquant_bypass_enable_flag && |
1664 |
2/2✓ Branch 0 taken 311137 times.
✓ Branch 1 taken 98009 times.
|
409146 | lc->cu.cu_transquant_bypass_flag) |
1665 | 311137 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size); | |
1666 | } | ||
1667 | } | ||
1668 | 19484936 | return 0; | |
1669 | } | ||
1670 | |||
1671 | 12433 | static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
1672 | const HEVCPPS *pps, int x0, int y0, int log2_cb_size) | ||
1673 | { | ||
1674 | 12433 | const HEVCContext *const s = lc->parent; | |
1675 | 12433 | const HEVCSPS *const sps = pps->sps; | |
1676 | GetBitContext gb; | ||
1677 | 12433 | int cb_size = 1 << log2_cb_size; | |
1678 | 12433 | ptrdiff_t stride0 = s->cur_frame->f->linesize[0]; | |
1679 | 12433 | ptrdiff_t stride1 = s->cur_frame->f->linesize[1]; | |
1680 | 12433 | ptrdiff_t stride2 = s->cur_frame->f->linesize[2]; | |
1681 | 12433 | uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)]; | |
1682 | 12433 | uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)]; | |
1683 | 12433 | uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)]; | |
1684 | |||
1685 | 12433 | int length = cb_size * cb_size * sps->pcm.bit_depth + | |
1686 | 12433 | (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) + | |
1687 | 12433 | ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) * | |
1688 | 12433 | sps->pcm.bit_depth_chroma; | |
1689 | 12433 | const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3); | |
1690 | int ret; | ||
1691 | |||
1692 |
2/2✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
|
12433 | if (!s->sh.disable_deblocking_filter_flag) |
1693 | 6937 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
1694 | |||
1695 | 12433 | ret = init_get_bits(&gb, pcm, length); | |
1696 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
|
12433 | if (ret < 0) |
1697 | ✗ | return ret; | |
1698 | |||
1699 | 12433 | s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth); | |
1700 |
1/2✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
|
12433 | if (sps->chroma_format_idc) { |
1701 | 12433 | s->hevcdsp.put_pcm(dst1, stride1, | |
1702 | 12433 | cb_size >> sps->hshift[1], | |
1703 | 12433 | cb_size >> sps->vshift[1], | |
1704 | 12433 | &gb, sps->pcm.bit_depth_chroma); | |
1705 | 12433 | s->hevcdsp.put_pcm(dst2, stride2, | |
1706 | 12433 | cb_size >> sps->hshift[2], | |
1707 | 12433 | cb_size >> sps->vshift[2], | |
1708 | 12433 | &gb, sps->pcm.bit_depth_chroma); | |
1709 | } | ||
1710 | |||
1711 | 12433 | return 0; | |
1712 | } | ||
1713 | |||
1714 | /** | ||
1715 | * 8.5.3.2.2.1 Luma sample unidirectional interpolation process | ||
1716 | * | ||
1717 | * @param s HEVC decoding context | ||
1718 | * @param dst target buffer for block data at block position | ||
1719 | * @param dststride stride of the dst buffer | ||
1720 | * @param ref reference picture buffer at origin (0, 0) | ||
1721 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1722 | * @param x_off horizontal position of block from origin (0, 0) | ||
1723 | * @param y_off vertical position of block from origin (0, 0) | ||
1724 | * @param block_w width of block | ||
1725 | * @param block_h height of block | ||
1726 | * @param luma_weight weighting factor applied to the luma prediction | ||
1727 | * @param luma_offset additive offset applied to the luma prediction value | ||
1728 | */ | ||
1729 | |||
1730 | 5154709 | static void luma_mc_uni(HEVCLocalContext *lc, | |
1731 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1732 | uint8_t *dst, ptrdiff_t dststride, | ||
1733 | const AVFrame *ref, const Mv *mv, int x_off, int y_off, | ||
1734 | int block_w, int block_h, int luma_weight, int luma_offset) | ||
1735 | { | ||
1736 | 5154709 | const HEVCContext *const s = lc->parent; | |
1737 | 5154709 | const uint8_t *src = ref->data[0]; | |
1738 | 5154709 | ptrdiff_t srcstride = ref->linesize[0]; | |
1739 | 5154709 | int pic_width = sps->width; | |
1740 | 5154709 | int pic_height = sps->height; | |
1741 | 5154709 | int mx = mv->x & 3; | |
1742 | 5154709 | int my = mv->y & 3; | |
1743 |
4/4✓ Branch 0 taken 2126467 times.
✓ Branch 1 taken 3028242 times.
✓ Branch 2 taken 2072291 times.
✓ Branch 3 taken 54176 times.
|
10255242 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1744 |
4/4✓ Branch 0 taken 3028242 times.
✓ Branch 1 taken 2072291 times.
✓ Branch 2 taken 70226 times.
✓ Branch 3 taken 2958016 times.
|
5100533 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1745 | 5154709 | int idx = hevc_pel_weight[block_w]; | |
1746 | |||
1747 | 5154709 | x_off += mv->x >> 2; | |
1748 | 5154709 | y_off += mv->y >> 2; | |
1749 | 5154709 | src += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
1750 | |||
1751 |
4/4✓ Branch 0 taken 5094646 times.
✓ Branch 1 taken 60063 times.
✓ Branch 2 taken 4985953 times.
✓ Branch 3 taken 108693 times.
|
5154709 | if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER || |
1752 |
2/2✓ Branch 0 taken 4919543 times.
✓ Branch 1 taken 66410 times.
|
4985953 | x_off >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1753 |
2/2✓ Branch 0 taken 4712016 times.
✓ Branch 1 taken 207527 times.
|
4919543 | y_off >= pic_height - block_h - QPEL_EXTRA_AFTER || |
1754 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4712016 times.
|
4712016 | ref == s->cur_frame->f) { |
1755 | 442693 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1756 | 442693 | int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1757 | 442693 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1758 | |||
1759 | 442693 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset, | |
1760 | edge_emu_stride, srcstride, | ||
1761 | block_w + QPEL_EXTRA, | ||
1762 | block_h + QPEL_EXTRA, | ||
1763 | x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE, | ||
1764 | pic_width, pic_height); | ||
1765 | 442693 | src = lc->edge_emu_buffer + buf_offset; | |
1766 | 442693 | srcstride = edge_emu_stride; | |
1767 | } | ||
1768 | |||
1769 |
2/2✓ Branch 0 taken 5030307 times.
✓ Branch 1 taken 124402 times.
|
5154709 | if (!weight_flag) |
1770 | 5030307 | s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1771 | block_h, mx, my, block_w); | ||
1772 | else | ||
1773 | 124402 | s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1774 | 124402 | block_h, s->sh.luma_log2_weight_denom, | |
1775 | luma_weight, luma_offset, mx, my, block_w); | ||
1776 | 5154709 | } | |
1777 | |||
1778 | /** | ||
1779 | * 8.5.3.2.2.1 Luma sample bidirectional interpolation process | ||
1780 | * | ||
1781 | * @param s HEVC decoding context | ||
1782 | * @param dst target buffer for block data at block position | ||
1783 | * @param dststride stride of the dst buffer | ||
1784 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1785 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1786 | * @param x_off horizontal position of block from origin (0, 0) | ||
1787 | * @param y_off vertical position of block from origin (0, 0) | ||
1788 | * @param block_w width of block | ||
1789 | * @param block_h height of block | ||
1790 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1791 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1792 | * @param current_mv current motion vector structure | ||
1793 | */ | ||
1794 | 3960193 | static void luma_mc_bi(HEVCLocalContext *lc, | |
1795 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1796 | uint8_t *dst, ptrdiff_t dststride, | ||
1797 | const AVFrame *ref0, const Mv *mv0, int x_off, int y_off, | ||
1798 | int block_w, int block_h, const AVFrame *ref1, | ||
1799 | const Mv *mv1, struct MvField *current_mv) | ||
1800 | { | ||
1801 | 3960193 | const HEVCContext *const s = lc->parent; | |
1802 | 3960193 | ptrdiff_t src0stride = ref0->linesize[0]; | |
1803 | 3960193 | ptrdiff_t src1stride = ref1->linesize[0]; | |
1804 | 3960193 | int pic_width = sps->width; | |
1805 | 3960193 | int pic_height = sps->height; | |
1806 | 3960193 | int mx0 = mv0->x & 3; | |
1807 | 3960193 | int my0 = mv0->y & 3; | |
1808 | 3960193 | int mx1 = mv1->x & 3; | |
1809 | 3960193 | int my1 = mv1->y & 3; | |
1810 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3960193 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7920386 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1811 |
3/4✓ Branch 0 taken 3960193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68518 times.
✓ Branch 3 taken 3891675 times.
|
3960193 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1812 | 3960193 | int x_off0 = x_off + (mv0->x >> 2); | |
1813 | 3960193 | int y_off0 = y_off + (mv0->y >> 2); | |
1814 | 3960193 | int x_off1 = x_off + (mv1->x >> 2); | |
1815 | 3960193 | int y_off1 = y_off + (mv1->y >> 2); | |
1816 | 3960193 | int idx = hevc_pel_weight[block_w]; | |
1817 | |||
1818 | 3960193 | const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift); | |
1819 | 3960193 | const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift); | |
1820 | |||
1821 |
4/4✓ Branch 0 taken 3903009 times.
✓ Branch 1 taken 57184 times.
✓ Branch 2 taken 3796710 times.
✓ Branch 3 taken 106299 times.
|
3960193 | if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER || |
1822 |
2/2✓ Branch 0 taken 3728624 times.
✓ Branch 1 taken 68086 times.
|
3796710 | x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1823 |
2/2✓ Branch 0 taken 208159 times.
✓ Branch 1 taken 3520465 times.
|
3728624 | y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1824 | 439728 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1825 | 439728 | int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1826 | 439728 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1827 | |||
1828 | 439728 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset, | |
1829 | edge_emu_stride, src0stride, | ||
1830 | block_w + QPEL_EXTRA, | ||
1831 | block_h + QPEL_EXTRA, | ||
1832 | x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE, | ||
1833 | pic_width, pic_height); | ||
1834 | 439728 | src0 = lc->edge_emu_buffer + buf_offset; | |
1835 | 439728 | src0stride = edge_emu_stride; | |
1836 | } | ||
1837 | |||
1838 |
4/4✓ Branch 0 taken 3896806 times.
✓ Branch 1 taken 63387 times.
✓ Branch 2 taken 3791189 times.
✓ Branch 3 taken 105617 times.
|
3960193 | if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER || |
1839 |
2/2✓ Branch 0 taken 3721188 times.
✓ Branch 1 taken 70001 times.
|
3791189 | x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1840 |
2/2✓ Branch 0 taken 211344 times.
✓ Branch 1 taken 3509844 times.
|
3721188 | y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1841 | 450349 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1842 | 450349 | int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1843 | 450349 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1844 | |||
1845 | 450349 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset, | |
1846 | edge_emu_stride, src1stride, | ||
1847 | block_w + QPEL_EXTRA, | ||
1848 | block_h + QPEL_EXTRA, | ||
1849 | x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE, | ||
1850 | pic_width, pic_height); | ||
1851 | 450349 | src1 = lc->edge_emu_buffer2 + buf_offset; | |
1852 | 450349 | src1stride = edge_emu_stride; | |
1853 | } | ||
1854 | |||
1855 | 3960193 | s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride, | |
1856 | block_h, mx0, my0, block_w); | ||
1857 |
2/2✓ Branch 0 taken 3891675 times.
✓ Branch 1 taken 68518 times.
|
3960193 | if (!weight_flag) |
1858 | 3891675 | s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1859 | block_h, mx1, my1, block_w); | ||
1860 | else | ||
1861 | 68518 | s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1862 | 68518 | block_h, s->sh.luma_log2_weight_denom, | |
1863 | 68518 | s->sh.luma_weight_l0[current_mv->ref_idx[0]], | |
1864 | 68518 | s->sh.luma_weight_l1[current_mv->ref_idx[1]], | |
1865 | 68518 | s->sh.luma_offset_l0[current_mv->ref_idx[0]], | |
1866 | 68518 | s->sh.luma_offset_l1[current_mv->ref_idx[1]], | |
1867 | mx1, my1, block_w); | ||
1868 | |||
1869 | 3960193 | } | |
1870 | |||
1871 | /** | ||
1872 | * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process | ||
1873 | * | ||
1874 | * @param s HEVC decoding context | ||
1875 | * @param dst1 target buffer for block data at block position (U plane) | ||
1876 | * @param dst2 target buffer for block data at block position (V plane) | ||
1877 | * @param dststride stride of the dst1 and dst2 buffers | ||
1878 | * @param ref reference picture buffer at origin (0, 0) | ||
1879 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1880 | * @param x_off horizontal position of block from origin (0, 0) | ||
1881 | * @param y_off vertical position of block from origin (0, 0) | ||
1882 | * @param block_w width of block | ||
1883 | * @param block_h height of block | ||
1884 | * @param chroma_weight weighting factor applied to the chroma prediction | ||
1885 | * @param chroma_offset additive offset applied to the chroma prediction value | ||
1886 | */ | ||
1887 | |||
1888 | 10309418 | static void chroma_mc_uni(HEVCLocalContext *lc, | |
1889 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1890 | uint8_t *dst0, | ||
1891 | ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist, | ||
1892 | int x_off, int y_off, int block_w, int block_h, | ||
1893 | const struct MvField *current_mv, int chroma_weight, int chroma_offset) | ||
1894 | { | ||
1895 | 10309418 | const HEVCContext *const s = lc->parent; | |
1896 | 10309418 | int pic_width = sps->width >> sps->hshift[1]; | |
1897 | 10309418 | int pic_height = sps->height >> sps->vshift[1]; | |
1898 | 10309418 | const Mv *mv = ¤t_mv->mv[reflist]; | |
1899 |
4/4✓ Branch 0 taken 4252934 times.
✓ Branch 1 taken 6056484 times.
✓ Branch 2 taken 4144582 times.
✓ Branch 3 taken 108352 times.
|
20510484 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1900 |
4/4✓ Branch 0 taken 6056484 times.
✓ Branch 1 taken 4144582 times.
✓ Branch 2 taken 140452 times.
✓ Branch 3 taken 5916032 times.
|
10201066 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1901 | 10309418 | int idx = hevc_pel_weight[block_w]; | |
1902 | 10309418 | int hshift = sps->hshift[1]; | |
1903 | 10309418 | int vshift = sps->vshift[1]; | |
1904 | 10309418 | intptr_t mx = av_zero_extend(mv->x, 2 + hshift); | |
1905 | 10309418 | intptr_t my = av_zero_extend(mv->y, 2 + vshift); | |
1906 | 10309418 | intptr_t _mx = mx << (1 - hshift); | |
1907 | 10309418 | intptr_t _my = my << (1 - vshift); | |
1908 |
2/4✓ Branch 0 taken 10309418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10309418 times.
|
10309418 | int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2]; |
1909 | |||
1910 | 10309418 | x_off += mv->x >> (2 + hshift); | |
1911 | 10309418 | y_off += mv->y >> (2 + vshift); | |
1912 | 10309418 | src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
1913 | |||
1914 |
4/4✓ Branch 0 taken 10199866 times.
✓ Branch 1 taken 109552 times.
✓ Branch 2 taken 9982340 times.
✓ Branch 3 taken 217526 times.
|
10309418 | if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER || |
1915 |
2/2✓ Branch 0 taken 9849528 times.
✓ Branch 1 taken 132812 times.
|
9982340 | x_off >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1916 |
3/4✓ Branch 0 taken 9434408 times.
✓ Branch 1 taken 415120 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9434408 times.
|
9849528 | y_off >= pic_height - block_h - EPEL_EXTRA_AFTER || |
1917 | emu) { | ||
1918 | 875010 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1919 | 875010 | int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift)); | |
1920 | 875010 | int buf_offset0 = EPEL_EXTRA_BEFORE * | |
1921 | 875010 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
1922 | 875010 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0, | |
1923 | edge_emu_stride, srcstride, | ||
1924 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1925 | x_off - EPEL_EXTRA_BEFORE, | ||
1926 | y_off - EPEL_EXTRA_BEFORE, | ||
1927 | pic_width, pic_height); | ||
1928 | |||
1929 | 875010 | src0 = lc->edge_emu_buffer + buf_offset0; | |
1930 | 875010 | srcstride = edge_emu_stride; | |
1931 | } | ||
1932 |
2/2✓ Branch 0 taken 10060614 times.
✓ Branch 1 taken 248804 times.
|
10309418 | if (!weight_flag) |
1933 | 10060614 | s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1934 | block_h, _mx, _my, block_w); | ||
1935 | else | ||
1936 | 248804 | s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1937 | 248804 | block_h, s->sh.chroma_log2_weight_denom, | |
1938 | chroma_weight, chroma_offset, _mx, _my, block_w); | ||
1939 | 10309418 | } | |
1940 | |||
1941 | /** | ||
1942 | * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process | ||
1943 | * | ||
1944 | * @param s HEVC decoding context | ||
1945 | * @param dst target buffer for block data at block position | ||
1946 | * @param dststride stride of the dst buffer | ||
1947 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1948 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1949 | * @param x_off horizontal position of block from origin (0, 0) | ||
1950 | * @param y_off vertical position of block from origin (0, 0) | ||
1951 | * @param block_w width of block | ||
1952 | * @param block_h height of block | ||
1953 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1954 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1955 | * @param current_mv current motion vector structure | ||
1956 | * @param cidx chroma component(cb, cr) | ||
1957 | */ | ||
1958 | 7920386 | static void chroma_mc_bi(HEVCLocalContext *lc, | |
1959 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1960 | uint8_t *dst0, ptrdiff_t dststride, | ||
1961 | const AVFrame *ref0, const AVFrame *ref1, | ||
1962 | int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx) | ||
1963 | { | ||
1964 | 7920386 | const HEVCContext *const s = lc->parent; | |
1965 | 7920386 | const uint8_t *src1 = ref0->data[cidx+1]; | |
1966 | 7920386 | const uint8_t *src2 = ref1->data[cidx+1]; | |
1967 | 7920386 | ptrdiff_t src1stride = ref0->linesize[cidx+1]; | |
1968 | 7920386 | ptrdiff_t src2stride = ref1->linesize[cidx+1]; | |
1969 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7920386 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
15840772 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1970 |
3/4✓ Branch 0 taken 7920386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 137036 times.
✓ Branch 3 taken 7783350 times.
|
7920386 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1971 | 7920386 | int pic_width = sps->width >> sps->hshift[1]; | |
1972 | 7920386 | int pic_height = sps->height >> sps->vshift[1]; | |
1973 | 7920386 | const Mv *const mv0 = ¤t_mv->mv[0]; | |
1974 | 7920386 | const Mv *const mv1 = ¤t_mv->mv[1]; | |
1975 | 7920386 | int hshift = sps->hshift[1]; | |
1976 | 7920386 | int vshift = sps->vshift[1]; | |
1977 | |||
1978 | 7920386 | intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift); | |
1979 | 7920386 | intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift); | |
1980 | 7920386 | intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift); | |
1981 | 7920386 | intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift); | |
1982 | 7920386 | intptr_t _mx0 = mx0 << (1 - hshift); | |
1983 | 7920386 | intptr_t _my0 = my0 << (1 - vshift); | |
1984 | 7920386 | intptr_t _mx1 = mx1 << (1 - hshift); | |
1985 | 7920386 | intptr_t _my1 = my1 << (1 - vshift); | |
1986 | |||
1987 | 7920386 | int x_off0 = x_off + (mv0->x >> (2 + hshift)); | |
1988 | 7920386 | int y_off0 = y_off + (mv0->y >> (2 + vshift)); | |
1989 | 7920386 | int x_off1 = x_off + (mv1->x >> (2 + hshift)); | |
1990 | 7920386 | int y_off1 = y_off + (mv1->y >> (2 + vshift)); | |
1991 | 7920386 | int idx = hevc_pel_weight[block_w]; | |
1992 | 7920386 | src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift); | |
1993 | 7920386 | src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift); | |
1994 | |||
1995 |
4/4✓ Branch 0 taken 7812248 times.
✓ Branch 1 taken 108138 times.
✓ Branch 2 taken 7599538 times.
✓ Branch 3 taken 212710 times.
|
7920386 | if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER || |
1996 |
2/2✓ Branch 0 taken 7463370 times.
✓ Branch 1 taken 136168 times.
|
7599538 | x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1997 |
2/2✓ Branch 0 taken 415730 times.
✓ Branch 1 taken 7047640 times.
|
7463370 | y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
1998 | 872746 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1999 | 872746 | int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift)); | |
2000 | 872746 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
2001 | 872746 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
2002 | |||
2003 | 872746 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1, | |
2004 | edge_emu_stride, src1stride, | ||
2005 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
2006 | x_off0 - EPEL_EXTRA_BEFORE, | ||
2007 | y_off0 - EPEL_EXTRA_BEFORE, | ||
2008 | pic_width, pic_height); | ||
2009 | |||
2010 | 872746 | src1 = lc->edge_emu_buffer + buf_offset1; | |
2011 | 872746 | src1stride = edge_emu_stride; | |
2012 | } | ||
2013 | |||
2014 |
4/4✓ Branch 0 taken 7799008 times.
✓ Branch 1 taken 121378 times.
✓ Branch 2 taken 7588052 times.
✓ Branch 3 taken 210956 times.
|
7920386 | if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER || |
2015 |
2/2✓ Branch 0 taken 7448056 times.
✓ Branch 1 taken 139996 times.
|
7588052 | x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
2016 |
2/2✓ Branch 0 taken 422362 times.
✓ Branch 1 taken 7025694 times.
|
7448056 | y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
2017 | 894692 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
2018 | 894692 | int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift)); | |
2019 | 894692 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
2020 | 894692 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
2021 | |||
2022 | 894692 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1, | |
2023 | edge_emu_stride, src2stride, | ||
2024 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
2025 | x_off1 - EPEL_EXTRA_BEFORE, | ||
2026 | y_off1 - EPEL_EXTRA_BEFORE, | ||
2027 | pic_width, pic_height); | ||
2028 | |||
2029 | 894692 | src2 = lc->edge_emu_buffer2 + buf_offset1; | |
2030 | 894692 | src2stride = edge_emu_stride; | |
2031 | } | ||
2032 | |||
2033 | 7920386 | s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride, | |
2034 | block_h, _mx0, _my0, block_w); | ||
2035 |
2/2✓ Branch 0 taken 7783350 times.
✓ Branch 1 taken 137036 times.
|
7920386 | if (!weight_flag) |
2036 | 7783350 | s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1], | |
2037 | 7783350 | src2, src2stride, lc->tmp, | |
2038 | block_h, _mx1, _my1, block_w); | ||
2039 | else | ||
2040 | 137036 | s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1], | |
2041 | 137036 | src2, src2stride, lc->tmp, | |
2042 | block_h, | ||
2043 | 137036 | s->sh.chroma_log2_weight_denom, | |
2044 | 137036 | s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx], | |
2045 | 137036 | s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx], | |
2046 | 137036 | s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx], | |
2047 | 137036 | s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx], | |
2048 | _mx1, _my1, block_w); | ||
2049 | 7920386 | } | |
2050 | |||
2051 | 13075095 | static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref, | |
2052 | const Mv *mv, int y0, int height) | ||
2053 | { | ||
2054 |
2/2✓ Branch 0 taken 111132 times.
✓ Branch 1 taken 12963963 times.
|
13075095 | if (s->avctx->active_thread_type == FF_THREAD_FRAME ) { |
2055 | 111132 | int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9); | |
2056 | |||
2057 | 111132 | ff_progress_frame_await(&ref->tf, y); | |
2058 | } | ||
2059 | 13075095 | } | |
2060 | |||
2061 | 2521175 | static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, | |
2062 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
2063 | int x0, int y0, int nPbW, | ||
2064 | int nPbH, int log2_cb_size, int part_idx, | ||
2065 | int merge_idx, MvField *mv) | ||
2066 | { | ||
2067 | 2521175 | const HEVCContext *const s = lc->parent; | |
2068 | 2521175 | enum InterPredIdc inter_pred_idc = PRED_L0; | |
2069 | int mvp_flag; | ||
2070 | |||
2071 | 2521175 | ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size); | |
2072 | 2521175 | mv->pred_flag = 0; | |
2073 |
2/2✓ Branch 0 taken 1900740 times.
✓ Branch 1 taken 620435 times.
|
2521175 | if (s->sh.slice_type == HEVC_SLICE_B) |
2074 | 1900740 | inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH); | |
2075 | |||
2076 |
2/2✓ Branch 0 taken 2113857 times.
✓ Branch 1 taken 407318 times.
|
2521175 | if (inter_pred_idc != PRED_L1) { |
2077 |
1/2✓ Branch 0 taken 2113857 times.
✗ Branch 1 not taken.
|
2113857 | if (s->sh.nb_refs[L0]) |
2078 | 2113857 | mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]); | |
2079 | |||
2080 | 2113857 | mv->pred_flag = PF_L0; | |
2081 | 2113857 | ff_hevc_hls_mvd_coding(lc, x0, y0, 0); | |
2082 | 2113857 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
2083 | 2113857 | ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
2084 | part_idx, merge_idx, mv, mvp_flag, 0); | ||
2085 | 2113857 | mv->mv[0].x += lc->pu.mvd.x; | |
2086 | 2113857 | mv->mv[0].y += lc->pu.mvd.y; | |
2087 | } | ||
2088 | |||
2089 |
2/2✓ Branch 0 taken 829430 times.
✓ Branch 1 taken 1691745 times.
|
2521175 | if (inter_pred_idc != PRED_L0) { |
2090 |
1/2✓ Branch 0 taken 829430 times.
✗ Branch 1 not taken.
|
829430 | if (s->sh.nb_refs[L1]) |
2091 | 829430 | mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]); | |
2092 | |||
2093 |
4/4✓ Branch 0 taken 192341 times.
✓ Branch 1 taken 637089 times.
✓ Branch 2 taken 162774 times.
✓ Branch 3 taken 29567 times.
|
829430 | if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) { |
2094 | 162774 | AV_ZERO32(&lc->pu.mvd); | |
2095 | } else { | ||
2096 | 666656 | ff_hevc_hls_mvd_coding(lc, x0, y0, 1); | |
2097 | } | ||
2098 | |||
2099 | 829430 | mv->pred_flag += PF_L1; | |
2100 | 829430 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
2101 | 829430 | ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
2102 | part_idx, merge_idx, mv, mvp_flag, 1); | ||
2103 | 829430 | mv->mv[1].x += lc->pu.mvd.x; | |
2104 | 829430 | mv->mv[1].y += lc->pu.mvd.y; | |
2105 | } | ||
2106 | 2521175 | } | |
2107 | |||
2108 | 9114902 | static void hls_prediction_unit(HEVCLocalContext *lc, | |
2109 | const HEVCLayerContext *l, | ||
2110 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
2111 | int x0, int y0, int nPbW, int nPbH, | ||
2112 | int log2_cb_size, int partIdx, int idx) | ||
2113 | { | ||
2114 | #define POS(c_idx, x, y) \ | ||
2115 | &s->cur_frame->f->data[c_idx] ? \ | ||
2116 | &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \ | ||
2117 | (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] : NULL | ||
2118 | 9114902 | const HEVCContext *const s = lc->parent; | |
2119 | 9114902 | int merge_idx = 0; | |
2120 | 9114902 | struct MvField current_mv = {{{ 0 }}}; | |
2121 | |||
2122 | 9114902 | int min_pu_width = sps->min_pu_width; | |
2123 | |||
2124 | 9114902 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
2125 | 9114902 | const RefPicList *refPicList = s->cur_frame->refPicList; | |
2126 | 9114902 | const HEVCFrame *ref0 = NULL, *ref1 = NULL; | |
2127 | 9114902 | const int *linesize = s->cur_frame->f->linesize; | |
2128 |
1/2✓ Branch 0 taken 9114902 times.
✗ Branch 1 not taken.
|
9114902 | uint8_t *dst0 = POS(0, x0, y0); |
2129 |
1/2✓ Branch 0 taken 9114902 times.
✗ Branch 1 not taken.
|
9114902 | uint8_t *dst1 = POS(1, x0, y0); |
2130 |
1/2✓ Branch 0 taken 9114902 times.
✗ Branch 1 not taken.
|
9114902 | uint8_t *dst2 = POS(2, x0, y0); |
2131 | 9114902 | int log2_min_cb_size = sps->log2_min_cb_size; | |
2132 | 9114902 | int min_cb_width = sps->min_cb_width; | |
2133 | 9114902 | int x_cb = x0 >> log2_min_cb_size; | |
2134 | 9114902 | int y_cb = y0 >> log2_min_cb_size; | |
2135 | int x_pu, y_pu; | ||
2136 | int i, j; | ||
2137 | |||
2138 | 9114902 | int skip_flag = SAMPLE_CTB(l->skip_flag, x_cb, y_cb); | |
2139 | |||
2140 |
2/2✓ Branch 0 taken 5016195 times.
✓ Branch 1 taken 4098707 times.
|
9114902 | if (!skip_flag) |
2141 | 5016195 | lc->pu.merge_flag = ff_hevc_merge_flag_decode(lc); | |
2142 | |||
2143 |
4/4✓ Branch 0 taken 5016195 times.
✓ Branch 1 taken 4098707 times.
✓ Branch 2 taken 2495020 times.
✓ Branch 3 taken 2521175 times.
|
9114902 | if (skip_flag || lc->pu.merge_flag) { |
2144 |
2/2✓ Branch 0 taken 6516874 times.
✓ Branch 1 taken 76853 times.
|
6593727 | if (s->sh.max_num_merge_cand > 1) |
2145 | 6516874 | merge_idx = ff_hevc_merge_idx_decode(lc); | |
2146 | else | ||
2147 | 76853 | merge_idx = 0; | |
2148 | |||
2149 | 6593727 | ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
2150 | partIdx, merge_idx, ¤t_mv); | ||
2151 | } else { | ||
2152 | 2521175 | hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size, | |
2153 | partIdx, merge_idx, ¤t_mv); | ||
2154 | } | ||
2155 | |||
2156 | 9114902 | x_pu = x0 >> sps->log2_min_pu_size; | |
2157 | 9114902 | y_pu = y0 >> sps->log2_min_pu_size; | |
2158 | |||
2159 |
2/2✓ Branch 0 taken 35579552 times.
✓ Branch 1 taken 9114902 times.
|
44694454 | for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++) |
2160 |
2/2✓ Branch 0 taken 233867368 times.
✓ Branch 1 taken 35579552 times.
|
269446920 | for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++) |
2161 | 233867368 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; | |
2162 | |||
2163 |
2/2✓ Branch 0 taken 8300775 times.
✓ Branch 1 taken 814127 times.
|
9114902 | if (current_mv.pred_flag & PF_L0) { |
2164 | 8300775 | ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; | |
2165 |
2/4✓ Branch 0 taken 8300775 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8300775 times.
|
8300775 | if (!ref0 || !ref0->f) |
2166 | ✗ | return; | |
2167 | 8300775 | hevc_await_progress(s, ref0, ¤t_mv.mv[0], y0, nPbH); | |
2168 | } | ||
2169 |
2/2✓ Branch 0 taken 4774320 times.
✓ Branch 1 taken 4340582 times.
|
9114902 | if (current_mv.pred_flag & PF_L1) { |
2170 | 4774320 | ref1 = refPicList[1].ref[current_mv.ref_idx[1]]; | |
2171 |
2/4✓ Branch 0 taken 4774320 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4774320 times.
|
4774320 | if (!ref1 || !ref1->f) |
2172 | ✗ | return; | |
2173 | 4774320 | hevc_await_progress(s, ref1, ¤t_mv.mv[1], y0, nPbH); | |
2174 | } | ||
2175 | |||
2176 |
2/2✓ Branch 0 taken 4340582 times.
✓ Branch 1 taken 4774320 times.
|
9114902 | if (current_mv.pred_flag == PF_L0) { |
2177 | 4340582 | int x0_c = x0 >> sps->hshift[1]; | |
2178 | 4340582 | int y0_c = y0 >> sps->vshift[1]; | |
2179 | 4340582 | int nPbW_c = nPbW >> sps->hshift[1]; | |
2180 | 4340582 | int nPbH_c = nPbH >> sps->vshift[1]; | |
2181 | |||
2182 | 4340582 | luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f, | |
2183 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
2184 | 4340582 | s->sh.luma_weight_l0[current_mv.ref_idx[0]], | |
2185 | 4340582 | s->sh.luma_offset_l0[current_mv.ref_idx[0]]); | |
2186 | |||
2187 |
1/2✓ Branch 0 taken 4340582 times.
✗ Branch 1 not taken.
|
4340582 | if (sps->chroma_format_idc) { |
2188 | 4340582 | chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1], | |
2189 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2190 | 4340582 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]); | |
2191 | 4340582 | chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2], | |
2192 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2193 | 4340582 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]); | |
2194 | } | ||
2195 |
2/2✓ Branch 0 taken 814127 times.
✓ Branch 1 taken 3960193 times.
|
4774320 | } else if (current_mv.pred_flag == PF_L1) { |
2196 | 814127 | int x0_c = x0 >> sps->hshift[1]; | |
2197 | 814127 | int y0_c = y0 >> sps->vshift[1]; | |
2198 | 814127 | int nPbW_c = nPbW >> sps->hshift[1]; | |
2199 | 814127 | int nPbH_c = nPbH >> sps->vshift[1]; | |
2200 | |||
2201 | 814127 | luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f, | |
2202 | ¤t_mv.mv[1], x0, y0, nPbW, nPbH, | ||
2203 | 814127 | s->sh.luma_weight_l1[current_mv.ref_idx[1]], | |
2204 | 814127 | s->sh.luma_offset_l1[current_mv.ref_idx[1]]); | |
2205 | |||
2206 |
1/2✓ Branch 0 taken 814127 times.
✗ Branch 1 not taken.
|
814127 | if (sps->chroma_format_idc) { |
2207 | 814127 | chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1], | |
2208 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2209 | 814127 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]); | |
2210 | |||
2211 | 814127 | chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2], | |
2212 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
2213 | 814127 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]); | |
2214 | } | ||
2215 |
1/2✓ Branch 0 taken 3960193 times.
✗ Branch 1 not taken.
|
3960193 | } else if (current_mv.pred_flag == PF_BI) { |
2216 | 3960193 | int x0_c = x0 >> sps->hshift[1]; | |
2217 | 3960193 | int y0_c = y0 >> sps->vshift[1]; | |
2218 | 3960193 | int nPbW_c = nPbW >> sps->hshift[1]; | |
2219 | 3960193 | int nPbH_c = nPbH >> sps->vshift[1]; | |
2220 | |||
2221 | 3960193 | luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f, | |
2222 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
2223 | 3960193 | ref1->f, ¤t_mv.mv[1], ¤t_mv); | |
2224 | |||
2225 |
1/2✓ Branch 0 taken 3960193 times.
✗ Branch 1 not taken.
|
3960193 | if (sps->chroma_format_idc) { |
2226 | 3960193 | chroma_mc_bi(lc, pps, sps, dst1, linesize[1], ref0->f, ref1->f, | |
2227 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0); | ||
2228 | |||
2229 | 3960193 | chroma_mc_bi(lc, pps, sps, dst2, linesize[2], ref0->f, ref1->f, | |
2230 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1); | ||
2231 | } | ||
2232 | } | ||
2233 | } | ||
2234 | |||
2235 | /** | ||
2236 | * 8.4.1 | ||
2237 | */ | ||
2238 | 7981489 | static int luma_intra_pred_mode(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
2239 | const HEVCSPS *sps, | ||
2240 | int x0, int y0, int pu_size, | ||
2241 | int prev_intra_luma_pred_flag) | ||
2242 | { | ||
2243 | 7981489 | const HEVCContext *const s = lc->parent; | |
2244 | 7981489 | int x_pu = x0 >> sps->log2_min_pu_size; | |
2245 | 7981489 | int y_pu = y0 >> sps->log2_min_pu_size; | |
2246 | 7981489 | int min_pu_width = sps->min_pu_width; | |
2247 | 7981489 | int size_in_pus = pu_size >> sps->log2_min_pu_size; | |
2248 | 7981489 | int x0b = av_zero_extend(x0, sps->log2_ctb_size); | |
2249 | 7981489 | int y0b = av_zero_extend(y0, sps->log2_ctb_size); | |
2250 | |||
2251 |
2/2✓ Branch 0 taken 1067668 times.
✓ Branch 1 taken 124828 times.
|
1192496 | int cand_up = (lc->ctb_up_flag || y0b) ? |
2252 |
2/2✓ Branch 0 taken 1192496 times.
✓ Branch 1 taken 6788993 times.
|
9173985 | l->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC; |
2253 |
2/2✓ Branch 0 taken 593794 times.
✓ Branch 1 taken 81768 times.
|
675562 | int cand_left = (lc->ctb_left_flag || x0b) ? |
2254 |
2/2✓ Branch 0 taken 675562 times.
✓ Branch 1 taken 7305927 times.
|
8657051 | l->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC; |
2255 | |||
2256 | 7981489 | int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size); | |
2257 | |||
2258 | 7981489 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
2259 | int intra_pred_mode; | ||
2260 | int candidate[3]; | ||
2261 | int i, j; | ||
2262 | |||
2263 | // intra_pred_mode prediction does not cross vertical CTB boundaries | ||
2264 |
2/2✓ Branch 0 taken 1041922 times.
✓ Branch 1 taken 6939567 times.
|
7981489 | if ((y0 - 1) < y_ctb) |
2265 | 1041922 | cand_up = INTRA_DC; | |
2266 | |||
2267 |
2/2✓ Branch 0 taken 1682285 times.
✓ Branch 1 taken 6299204 times.
|
7981489 | if (cand_left == cand_up) { |
2268 |
2/2✓ Branch 0 taken 998602 times.
✓ Branch 1 taken 683683 times.
|
1682285 | if (cand_left < 2) { |
2269 | 998602 | candidate[0] = INTRA_PLANAR; | |
2270 | 998602 | candidate[1] = INTRA_DC; | |
2271 | 998602 | candidate[2] = INTRA_ANGULAR_26; | |
2272 | } else { | ||
2273 | 683683 | candidate[0] = cand_left; | |
2274 | 683683 | candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31); | |
2275 | 683683 | candidate[2] = 2 + ((cand_left - 2 + 1) & 31); | |
2276 | } | ||
2277 | } else { | ||
2278 | 6299204 | candidate[0] = cand_left; | |
2279 | 6299204 | candidate[1] = cand_up; | |
2280 |
4/4✓ Branch 0 taken 5224915 times.
✓ Branch 1 taken 1074289 times.
✓ Branch 2 taken 4313457 times.
✓ Branch 3 taken 911458 times.
|
6299204 | if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) { |
2281 | 4313457 | candidate[2] = INTRA_PLANAR; | |
2282 |
4/4✓ Branch 0 taken 1735751 times.
✓ Branch 1 taken 249996 times.
✓ Branch 2 taken 1306836 times.
✓ Branch 3 taken 428915 times.
|
1985747 | } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) { |
2283 | 1306836 | candidate[2] = INTRA_DC; | |
2284 | } else { | ||
2285 | 678911 | candidate[2] = INTRA_ANGULAR_26; | |
2286 | } | ||
2287 | } | ||
2288 | |||
2289 |
2/2✓ Branch 0 taken 4795333 times.
✓ Branch 1 taken 3186156 times.
|
7981489 | if (prev_intra_luma_pred_flag) { |
2290 | 4795333 | intra_pred_mode = candidate[lc->pu.mpm_idx]; | |
2291 | } else { | ||
2292 |
2/2✓ Branch 0 taken 1518872 times.
✓ Branch 1 taken 1667284 times.
|
3186156 | if (candidate[0] > candidate[1]) |
2293 | 1518872 | FFSWAP(uint8_t, candidate[0], candidate[1]); | |
2294 |
2/2✓ Branch 0 taken 1889237 times.
✓ Branch 1 taken 1296919 times.
|
3186156 | if (candidate[0] > candidate[2]) |
2295 | 1889237 | FFSWAP(uint8_t, candidate[0], candidate[2]); | |
2296 |
2/2✓ Branch 0 taken 2370000 times.
✓ Branch 1 taken 816156 times.
|
3186156 | if (candidate[1] > candidate[2]) |
2297 | 2370000 | FFSWAP(uint8_t, candidate[1], candidate[2]); | |
2298 | |||
2299 | 3186156 | intra_pred_mode = lc->pu.rem_intra_luma_pred_mode; | |
2300 |
2/2✓ Branch 0 taken 9558468 times.
✓ Branch 1 taken 3186156 times.
|
12744624 | for (i = 0; i < 3; i++) |
2301 |
2/2✓ Branch 0 taken 6963910 times.
✓ Branch 1 taken 2594558 times.
|
9558468 | if (intra_pred_mode >= candidate[i]) |
2302 | 6963910 | intra_pred_mode++; | |
2303 | } | ||
2304 | |||
2305 | /* write the intra prediction units into the mv array */ | ||
2306 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7981489 times.
|
7981489 | if (!size_in_pus) |
2307 | ✗ | size_in_pus = 1; | |
2308 |
2/2✓ Branch 0 taken 14412140 times.
✓ Branch 1 taken 7981489 times.
|
22393629 | for (i = 0; i < size_in_pus; i++) { |
2309 | 14412140 | memset(&l->tab_ipm[(y_pu + i) * min_pu_width + x_pu], | |
2310 | intra_pred_mode, size_in_pus); | ||
2311 | |||
2312 |
2/2✓ Branch 0 taken 47859376 times.
✓ Branch 1 taken 14412140 times.
|
62271516 | for (j = 0; j < size_in_pus; j++) { |
2313 | 47859376 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA; | |
2314 | } | ||
2315 | } | ||
2316 | |||
2317 | 7981489 | return intra_pred_mode; | |
2318 | } | ||
2319 | |||
2320 | 11738363 | static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth, | |
2321 | int x0, int y0, | ||
2322 | int log2_cb_size, int ct_depth) | ||
2323 | { | ||
2324 | 11738363 | int length = (1 << log2_cb_size) >> sps->log2_min_cb_size; | |
2325 | 11738363 | int x_cb = x0 >> sps->log2_min_cb_size; | |
2326 | 11738363 | int y_cb = y0 >> sps->log2_min_cb_size; | |
2327 | int y; | ||
2328 | |||
2329 |
2/2✓ Branch 0 taken 22156793 times.
✓ Branch 1 taken 11738363 times.
|
33895156 | for (y = 0; y < length; y++) |
2330 | 22156793 | memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb], | |
2331 | ct_depth, length); | ||
2332 | 11738363 | } | |
2333 | |||
2334 | static const uint8_t tab_mode_idx[] = { | ||
2335 | 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, | ||
2336 | 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31}; | ||
2337 | |||
2338 | 4258627 | static void intra_prediction_unit(HEVCLocalContext *lc, | |
2339 | const HEVCLayerContext *l, const HEVCSPS *sps, | ||
2340 | int x0, int y0, | ||
2341 | int log2_cb_size) | ||
2342 | { | ||
2343 | static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 }; | ||
2344 | uint8_t prev_intra_luma_pred_flag[4]; | ||
2345 | 4258627 | int split = lc->cu.part_mode == PART_NxN; | |
2346 | 4258627 | int pb_size = (1 << log2_cb_size) >> split; | |
2347 | 4258627 | int side = split + 1; | |
2348 | int chroma_mode; | ||
2349 | int i, j; | ||
2350 | |||
2351 |
2/2✓ Branch 0 taken 5499581 times.
✓ Branch 1 taken 4258627 times.
|
9758208 | for (i = 0; i < side; i++) |
2352 |
2/2✓ Branch 0 taken 7981489 times.
✓ Branch 1 taken 5499581 times.
|
13481070 | for (j = 0; j < side; j++) |
2353 | 7981489 | prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc); | |
2354 | |||
2355 |
2/2✓ Branch 0 taken 5499581 times.
✓ Branch 1 taken 4258627 times.
|
9758208 | for (i = 0; i < side; i++) { |
2356 |
2/2✓ Branch 0 taken 7981489 times.
✓ Branch 1 taken 5499581 times.
|
13481070 | for (j = 0; j < side; j++) { |
2357 |
2/2✓ Branch 0 taken 4795333 times.
✓ Branch 1 taken 3186156 times.
|
7981489 | if (prev_intra_luma_pred_flag[2 * i + j]) |
2358 | 4795333 | lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc); | |
2359 | else | ||
2360 | 3186156 | lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc); | |
2361 | |||
2362 | 7981489 | lc->pu.intra_pred_mode[2 * i + j] = | |
2363 | 7981489 | luma_intra_pred_mode(lc, l, sps, | |
2364 | 7981489 | x0 + pb_size * j, y0 + pb_size * i, pb_size, | |
2365 | 7981489 | prev_intra_luma_pred_flag[2 * i + j]); | |
2366 | } | ||
2367 | } | ||
2368 | |||
2369 |
2/2✓ Branch 0 taken 105006 times.
✓ Branch 1 taken 4153621 times.
|
4258627 | if (sps->chroma_format_idc == 3) { |
2370 |
2/2✓ Branch 0 taken 138857 times.
✓ Branch 1 taken 105006 times.
|
243863 | for (i = 0; i < side; i++) { |
2371 |
2/2✓ Branch 0 taken 206559 times.
✓ Branch 1 taken 138857 times.
|
345416 | for (j = 0; j < side; j++) { |
2372 | 206559 | lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
2373 |
2/2✓ Branch 0 taken 34248 times.
✓ Branch 1 taken 172311 times.
|
206559 | if (chroma_mode != 4) { |
2374 |
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]) |
2375 | 2343 | lc->pu.intra_pred_mode_c[2 * i + j] = 34; | |
2376 | else | ||
2377 | 31905 | lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode]; | |
2378 | } else { | ||
2379 | 172311 | lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j]; | |
2380 | } | ||
2381 | } | ||
2382 | } | ||
2383 |
2/2✓ Branch 0 taken 247106 times.
✓ Branch 1 taken 3906515 times.
|
4153621 | } else if (sps->chroma_format_idc == 2) { |
2384 | int mode_idx; | ||
2385 | 247106 | lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
2386 |
2/2✓ Branch 0 taken 73995 times.
✓ Branch 1 taken 173111 times.
|
247106 | if (chroma_mode != 4) { |
2387 |
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]) |
2388 | 3515 | mode_idx = 34; | |
2389 | else | ||
2390 | 70480 | mode_idx = intra_chroma_table[chroma_mode]; | |
2391 | } else { | ||
2392 | 173111 | mode_idx = lc->pu.intra_pred_mode[0]; | |
2393 | } | ||
2394 | 247106 | lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx]; | |
2395 |
2/2✓ Branch 0 taken 3906323 times.
✓ Branch 1 taken 192 times.
|
3906515 | } else if (sps->chroma_format_idc != 0) { |
2396 | 3906323 | chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
2397 |
2/2✓ Branch 0 taken 974144 times.
✓ Branch 1 taken 2932179 times.
|
3906323 | if (chroma_mode != 4) { |
2398 |
2/2✓ Branch 0 taken 72376 times.
✓ Branch 1 taken 901768 times.
|
974144 | if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode]) |
2399 | 72376 | lc->pu.intra_pred_mode_c[0] = 34; | |
2400 | else | ||
2401 | 901768 | lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode]; | |
2402 | } else { | ||
2403 | 2932179 | lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0]; | |
2404 | } | ||
2405 | } | ||
2406 | 4258627 | } | |
2407 | |||
2408 | 7479737 | static void intra_prediction_unit_default_value(HEVCLocalContext *lc, | |
2409 | const HEVCLayerContext *l, | ||
2410 | const HEVCSPS *sps, | ||
2411 | int x0, int y0, | ||
2412 | int log2_cb_size) | ||
2413 | { | ||
2414 | 7479737 | const HEVCContext *const s = lc->parent; | |
2415 | 7479737 | int pb_size = 1 << log2_cb_size; | |
2416 | 7479737 | int size_in_pus = pb_size >> sps->log2_min_pu_size; | |
2417 | 7479737 | int min_pu_width = sps->min_pu_width; | |
2418 | 7479737 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
2419 | 7479737 | int x_pu = x0 >> sps->log2_min_pu_size; | |
2420 | 7479737 | int y_pu = y0 >> sps->log2_min_pu_size; | |
2421 | int j, k; | ||
2422 | |||
2423 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7479737 times.
|
7479737 | if (size_in_pus == 0) |
2424 | ✗ | size_in_pus = 1; | |
2425 |
2/2✓ Branch 0 taken 32383356 times.
✓ Branch 1 taken 7479737 times.
|
39863093 | for (j = 0; j < size_in_pus; j++) |
2426 | 32383356 | memset(&l->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus); | |
2427 |
2/2✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 7467304 times.
|
7479737 | if (lc->cu.pred_mode == MODE_INTRA) |
2428 |
2/2✓ Branch 0 taken 40908 times.
✓ Branch 1 taken 12433 times.
|
53341 | for (j = 0; j < size_in_pus; j++) |
2429 |
2/2✓ Branch 0 taken 182512 times.
✓ Branch 1 taken 40908 times.
|
223420 | for (k = 0; k < size_in_pus; k++) |
2430 | 182512 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA; | |
2431 | 7479737 | } | |
2432 | |||
2433 | 11738364 | static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, | |
2434 | const HEVCLayerContext *l, | ||
2435 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
2436 | int x0, int y0, int log2_cb_size) | ||
2437 | { | ||
2438 | 11738364 | int cb_size = 1 << log2_cb_size; | |
2439 | 11738364 | int log2_min_cb_size = sps->log2_min_cb_size; | |
2440 | 11738364 | int length = cb_size >> log2_min_cb_size; | |
2441 | 11738364 | int min_cb_width = sps->min_cb_width; | |
2442 | 11738364 | int x_cb = x0 >> log2_min_cb_size; | |
2443 | 11738364 | int y_cb = y0 >> log2_min_cb_size; | |
2444 | 11738364 | int idx = log2_cb_size - 2; | |
2445 | 11738364 | int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1; | |
2446 | int x, y, ret; | ||
2447 | |||
2448 | 11738364 | lc->cu.x = x0; | |
2449 | 11738364 | lc->cu.y = y0; | |
2450 | 11738364 | lc->cu.pred_mode = MODE_INTRA; | |
2451 | 11738364 | lc->cu.part_mode = PART_2Nx2N; | |
2452 | 11738364 | lc->cu.intra_split_flag = 0; | |
2453 | |||
2454 | 11738364 | SAMPLE_CTB(l->skip_flag, x_cb, y_cb) = 0; | |
2455 |
2/2✓ Branch 0 taken 46953456 times.
✓ Branch 1 taken 11738364 times.
|
58691820 | for (x = 0; x < 4; x++) |
2456 | 46953456 | lc->pu.intra_pred_mode[x] = 1; | |
2457 |
2/2✓ Branch 0 taken 211788 times.
✓ Branch 1 taken 11526576 times.
|
11738364 | if (pps->transquant_bypass_enable_flag) { |
2458 | 211788 | lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(lc); | |
2459 |
2/2✓ Branch 0 taken 92187 times.
✓ Branch 1 taken 119601 times.
|
211788 | if (lc->cu.cu_transquant_bypass_flag) |
2460 | 92187 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size); | |
2461 | } else | ||
2462 | 11526576 | lc->cu.cu_transquant_bypass_flag = 0; | |
2463 | |||
2464 |
2/2✓ Branch 0 taken 8617339 times.
✓ Branch 1 taken 3121025 times.
|
11738364 | if (s->sh.slice_type != HEVC_SLICE_I) { |
2465 | 8617339 | const int x0b = av_zero_extend(x0, sps->log2_ctb_size); | |
2466 | 8617339 | const int y0b = av_zero_extend(y0, sps->log2_ctb_size); | |
2467 | 8617339 | uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, l->skip_flag, | |
2468 | x0b, y0b, x_cb, y_cb, | ||
2469 | min_cb_width); | ||
2470 | |||
2471 | 8617339 | x = y_cb * min_cb_width + x_cb; | |
2472 |
2/2✓ Branch 0 taken 17925039 times.
✓ Branch 1 taken 8617339 times.
|
26542378 | for (y = 0; y < length; y++) { |
2473 | 17925039 | memset(&l->skip_flag[x], skip_flag, length); | |
2474 | 17925039 | x += min_cb_width; | |
2475 | } | ||
2476 |
2/2✓ Branch 0 taken 4098707 times.
✓ Branch 1 taken 4518632 times.
|
8617339 | lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER; |
2477 | } else { | ||
2478 | 3121025 | x = y_cb * min_cb_width + x_cb; | |
2479 |
2/2✓ Branch 0 taken 4231755 times.
✓ Branch 1 taken 3121025 times.
|
7352780 | for (y = 0; y < length; y++) { |
2480 | 4231755 | memset(&l->skip_flag[x], 0, length); | |
2481 | 4231755 | x += min_cb_width; | |
2482 | } | ||
2483 | } | ||
2484 | |||
2485 |
2/2✓ Branch 0 taken 4098707 times.
✓ Branch 1 taken 7639657 times.
|
11738364 | if (SAMPLE_CTB(l->skip_flag, x_cb, y_cb)) { |
2486 | 4098707 | hls_prediction_unit(lc, l, pps, sps, | |
2487 | x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | ||
2488 | 4098707 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
2489 | |||
2490 |
2/2✓ Branch 0 taken 3952194 times.
✓ Branch 1 taken 146513 times.
|
4098707 | if (!s->sh.disable_deblocking_filter_flag) |
2491 | 3952194 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
2492 | } else { | ||
2493 | 7639657 | int pcm_flag = 0; | |
2494 | |||
2495 |
2/2✓ Branch 0 taken 4518632 times.
✓ Branch 1 taken 3121025 times.
|
7639657 | if (s->sh.slice_type != HEVC_SLICE_I) |
2496 | 4518632 | lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc); | |
2497 |
2/2✓ Branch 0 taken 4271060 times.
✓ Branch 1 taken 3368597 times.
|
7639657 | if (lc->cu.pred_mode != MODE_INTRA || |
2498 |
2/2✓ Branch 0 taken 3215588 times.
✓ Branch 1 taken 1055472 times.
|
4271060 | log2_cb_size == sps->log2_min_cb_size) { |
2499 | 6584185 | lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size); | |
2500 |
2/2✓ Branch 0 taken 1346590 times.
✓ Branch 1 taken 5237595 times.
|
7930775 | lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN && |
2501 |
2/2✓ Branch 0 taken 1240954 times.
✓ Branch 1 taken 105636 times.
|
1346590 | lc->cu.pred_mode == MODE_INTRA; |
2502 | } | ||
2503 | |||
2504 |
2/2✓ Branch 0 taken 4271060 times.
✓ Branch 1 taken 3368597 times.
|
7639657 | if (lc->cu.pred_mode == MODE_INTRA) { |
2505 |
4/4✓ Branch 0 taken 3030106 times.
✓ Branch 1 taken 1240954 times.
✓ Branch 2 taken 162684 times.
✓ Branch 3 taken 2867422 times.
|
4271060 | if (lc->cu.part_mode == PART_2Nx2N && sps->pcm_enabled && |
2506 |
2/2✓ Branch 0 taken 160815 times.
✓ Branch 1 taken 1869 times.
|
162684 | log2_cb_size >= sps->pcm.log2_min_pcm_cb_size && |
2507 |
2/2✓ Branch 0 taken 153183 times.
✓ Branch 1 taken 7632 times.
|
160815 | log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) { |
2508 | 153183 | pcm_flag = ff_hevc_pcm_flag_decode(lc); | |
2509 | } | ||
2510 |
2/2✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 4258627 times.
|
4271060 | if (pcm_flag) { |
2511 | 12433 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
2512 | 12433 | ret = hls_pcm_sample(lc, l, pps, x0, y0, log2_cb_size); | |
2513 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12425 times.
|
12433 | if (sps->pcm_loop_filter_disabled) |
2514 | 8 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size); | |
2515 | |||
2516 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
|
12433 | if (ret < 0) |
2517 | ✗ | return ret; | |
2518 | } else { | ||
2519 | 4258627 | intra_prediction_unit(lc, l, sps, x0, y0, log2_cb_size); | |
2520 | } | ||
2521 | } else { | ||
2522 | 3368597 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
2523 |
8/9✓ Branch 0 taken 1932271 times.
✓ Branch 1 taken 458403 times.
✓ Branch 2 taken 561832 times.
✓ Branch 3 taken 67005 times.
✓ Branch 4 taken 57888 times.
✓ Branch 5 taken 99971 times.
✓ Branch 6 taken 85591 times.
✓ Branch 7 taken 105636 times.
✗ Branch 8 not taken.
|
3368597 | switch (lc->cu.part_mode) { |
2524 | 1932271 | case PART_2Nx2N: | |
2525 | 1932271 | hls_prediction_unit(lc, l, pps, sps, | |
2526 | x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | ||
2527 | 1932271 | break; | |
2528 | 458403 | case PART_2NxN: | |
2529 | 458403 | hls_prediction_unit(lc, l, pps, sps, | |
2530 | x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx); | ||
2531 | 458403 | hls_prediction_unit(lc, l, pps, sps, | |
2532 | 458403 | x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx); | |
2533 | 458403 | break; | |
2534 | 561832 | case PART_Nx2N: | |
2535 | 561832 | hls_prediction_unit(lc, l, pps, sps, | |
2536 | x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1); | ||
2537 | 561832 | hls_prediction_unit(lc, l, pps, sps, | |
2538 | 561832 | x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1); | |
2539 | 561832 | break; | |
2540 | 67005 | case PART_2NxnU: | |
2541 | 67005 | hls_prediction_unit(lc, l, pps, sps, | |
2542 | x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx); | ||
2543 | 67005 | hls_prediction_unit(lc, l, pps, sps, | |
2544 | 67005 | x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx); | |
2545 | 67005 | break; | |
2546 | 57888 | case PART_2NxnD: | |
2547 | 57888 | hls_prediction_unit(lc, l, pps, sps, | |
2548 | 57888 | x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx); | |
2549 | 57888 | hls_prediction_unit(lc, l, pps, sps, | |
2550 | 57888 | x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx); | |
2551 | 57888 | break; | |
2552 | 99971 | case PART_nLx2N: | |
2553 | 99971 | hls_prediction_unit(lc, l, pps, sps, | |
2554 | x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2); | ||
2555 | 99971 | hls_prediction_unit(lc, l, pps, sps, | |
2556 | 99971 | x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2); | |
2557 | 99971 | break; | |
2558 | 85591 | case PART_nRx2N: | |
2559 | 85591 | hls_prediction_unit(lc, l, pps, sps, | |
2560 | 85591 | x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2); | |
2561 | 85591 | hls_prediction_unit(lc, l, pps, sps, | |
2562 | 85591 | x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2); | |
2563 | 85591 | break; | |
2564 | 105636 | case PART_NxN: | |
2565 | 105636 | hls_prediction_unit(lc, l, pps, sps, | |
2566 | x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1); | ||
2567 | 105636 | hls_prediction_unit(lc, l, pps, sps, | |
2568 | 105636 | x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1); | |
2569 | 105636 | hls_prediction_unit(lc, l, pps, sps, | |
2570 | 105636 | x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1); | |
2571 | 105636 | hls_prediction_unit(lc, l, pps, sps, | |
2572 | 105636 | x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1); | |
2573 | 105636 | break; | |
2574 | } | ||
2575 | } | ||
2576 | |||
2577 |
2/2✓ Branch 0 taken 7627224 times.
✓ Branch 1 taken 12433 times.
|
7639657 | if (!pcm_flag) { |
2578 | 7627224 | int rqt_root_cbf = 1; | |
2579 | |||
2580 |
2/2✓ Branch 0 taken 3368597 times.
✓ Branch 1 taken 4258627 times.
|
7627224 | if (lc->cu.pred_mode != MODE_INTRA && |
2581 |
4/4✓ Branch 0 taken 1932271 times.
✓ Branch 1 taken 1436326 times.
✓ Branch 2 taken 1055811 times.
✓ Branch 3 taken 876460 times.
|
3368597 | !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) { |
2582 | 2492137 | rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc); | |
2583 | } | ||
2584 |
2/2✓ Branch 0 taken 6255141 times.
✓ Branch 1 taken 1372083 times.
|
7627224 | if (rqt_root_cbf) { |
2585 | const static int cbf[2] = { 0 }; | ||
2586 |
2/2✓ Branch 0 taken 4258627 times.
✓ Branch 1 taken 1996514 times.
|
6255141 | lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ? |
2587 | 4258627 | sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag : | |
2588 | 1996514 | sps->max_transform_hierarchy_depth_inter; | |
2589 | 6255141 | ret = hls_transform_tree(lc, l, pps, sps, x0, y0, x0, y0, x0, y0, | |
2590 | log2_cb_size, | ||
2591 | log2_cb_size, 0, 0, cbf, cbf); | ||
2592 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6255140 times.
|
6255141 | if (ret < 0) |
2593 | 1 | return ret; | |
2594 | } else { | ||
2595 |
2/2✓ Branch 0 taken 1315651 times.
✓ Branch 1 taken 56432 times.
|
1372083 | if (!s->sh.disable_deblocking_filter_flag) |
2596 | 1315651 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
2597 | } | ||
2598 | } | ||
2599 | } | ||
2600 | |||
2601 |
4/4✓ Branch 0 taken 2134919 times.
✓ Branch 1 taken 9603444 times.
✓ Branch 2 taken 828240 times.
✓ Branch 3 taken 1306679 times.
|
11738363 | if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0) |
2602 | 828240 | ff_hevc_set_qPy(lc, l, pps, x0, y0, log2_cb_size); | |
2603 | |||
2604 | 11738363 | x = y_cb * min_cb_width + x_cb; | |
2605 |
2/2✓ Branch 0 taken 22156793 times.
✓ Branch 1 taken 11738363 times.
|
33895156 | for (y = 0; y < length; y++) { |
2606 | 22156793 | memset(&l->qp_y_tab[x], lc->qp_y, length); | |
2607 | 22156793 | x += min_cb_width; | |
2608 | } | ||
2609 | |||
2610 |
2/2✓ Branch 0 taken 4088488 times.
✓ Branch 1 taken 7649875 times.
|
11738363 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
2611 |
2/2✓ Branch 0 taken 2443775 times.
✓ Branch 1 taken 1644713 times.
|
4088488 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) { |
2612 | 2443775 | lc->qPy_pred = lc->qp_y; | |
2613 | } | ||
2614 | |||
2615 | 11738363 | set_ct_depth(sps, l->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth); | |
2616 | |||
2617 | 11738363 | return 0; | |
2618 | } | ||
2619 | |||
2620 | 15282659 | static int hls_coding_quadtree(HEVCLocalContext *lc, | |
2621 | const HEVCLayerContext *l, | ||
2622 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
2623 | int x0, int y0, | ||
2624 | int log2_cb_size, int cb_depth) | ||
2625 | { | ||
2626 | 15282659 | const HEVCContext *const s = lc->parent; | |
2627 | 15282659 | const int cb_size = 1 << log2_cb_size; | |
2628 | int ret; | ||
2629 | int split_cu; | ||
2630 | |||
2631 | 15282659 | lc->ct_depth = cb_depth; | |
2632 |
2/2✓ Branch 0 taken 15253696 times.
✓ Branch 1 taken 28963 times.
|
15282659 | if (x0 + cb_size <= sps->width && |
2633 |
2/2✓ Branch 0 taken 14929952 times.
✓ Branch 1 taken 323744 times.
|
15253696 | y0 + cb_size <= sps->height && |
2634 |
2/2✓ Branch 0 taken 8116110 times.
✓ Branch 1 taken 6813842 times.
|
14929952 | log2_cb_size > sps->log2_min_cb_size) { |
2635 | 8116110 | split_cu = ff_hevc_split_coding_unit_flag_decode(lc, l->tab_ct_depth, | |
2636 | sps, cb_depth, x0, y0); | ||
2637 | } else { | ||
2638 | 7166549 | split_cu = (log2_cb_size > sps->log2_min_cb_size); | |
2639 | } | ||
2640 |
2/2✓ Branch 0 taken 2761453 times.
✓ Branch 1 taken 12521206 times.
|
15282659 | if (pps->cu_qp_delta_enabled_flag && |
2641 |
2/2✓ Branch 0 taken 1611571 times.
✓ Branch 1 taken 1149882 times.
|
2761453 | log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) { |
2642 | 1611571 | lc->tu.is_cu_qp_delta_coded = 0; | |
2643 | 1611571 | lc->tu.cu_qp_delta = 0; | |
2644 | } | ||
2645 | |||
2646 |
2/2✓ Branch 0 taken 519326 times.
✓ Branch 1 taken 14763333 times.
|
15282659 | if (s->sh.cu_chroma_qp_offset_enabled_flag && |
2647 |
1/2✓ Branch 0 taken 519326 times.
✗ Branch 1 not taken.
|
519326 | log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_chroma_qp_offset_depth) { |
2648 | 519326 | lc->tu.is_cu_chroma_qp_offset_coded = 0; | |
2649 | } | ||
2650 | |||
2651 |
2/2✓ Branch 0 taken 3544295 times.
✓ Branch 1 taken 11738364 times.
|
15282659 | if (split_cu) { |
2652 | 3544295 | int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1; | |
2653 | 3544295 | const int cb_size_split = cb_size >> 1; | |
2654 | 3544295 | const int x1 = x0 + cb_size_split; | |
2655 | 3544295 | const int y1 = y0 + cb_size_split; | |
2656 | |||
2657 | 3544295 | int more_data = 0; | |
2658 | |||
2659 | 3544295 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
2660 | x0, y0, log2_cb_size - 1, cb_depth + 1); | ||
2661 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3544293 times.
|
3544295 | if (more_data < 0) |
2662 | 2 | return more_data; | |
2663 | |||
2664 |
4/4✓ Branch 0 taken 3544284 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3516343 times.
✓ Branch 3 taken 27941 times.
|
3544293 | if (more_data && x1 < sps->width) { |
2665 | 3516343 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
2666 | x1, y0, log2_cb_size - 1, cb_depth + 1); | ||
2667 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3516343 times.
|
3516343 | if (more_data < 0) |
2668 | ✗ | return more_data; | |
2669 | } | ||
2670 |
4/4✓ Branch 0 taken 3533878 times.
✓ Branch 1 taken 10415 times.
✓ Branch 2 taken 3331371 times.
✓ Branch 3 taken 202507 times.
|
3544293 | if (more_data && y1 < sps->height) { |
2671 | 3331371 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
2672 | x0, y1, log2_cb_size - 1, cb_depth + 1); | ||
2673 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3331371 times.
|
3331371 | if (more_data < 0) |
2674 | ✗ | return more_data; | |
2675 | } | ||
2676 |
4/4✓ Branch 0 taken 3527755 times.
✓ Branch 1 taken 16538 times.
✓ Branch 2 taken 3505937 times.
✓ Branch 3 taken 21818 times.
|
3544293 | if (more_data && x1 < sps->width && |
2677 |
2/2✓ Branch 0 taken 3303430 times.
✓ Branch 1 taken 202507 times.
|
3505937 | y1 < sps->height) { |
2678 | 3303430 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
2679 | x1, y1, log2_cb_size - 1, cb_depth + 1); | ||
2680 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3303429 times.
|
3303430 | if (more_data < 0) |
2681 | 1 | return more_data; | |
2682 | } | ||
2683 | |||
2684 |
2/2✓ Branch 0 taken 2005278 times.
✓ Branch 1 taken 1539014 times.
|
3544292 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
2685 |
2/2✓ Branch 0 taken 1500288 times.
✓ Branch 1 taken 504990 times.
|
2005278 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) |
2686 | 1500288 | lc->qPy_pred = lc->qp_y; | |
2687 | |||
2688 |
2/2✓ Branch 0 taken 3508241 times.
✓ Branch 1 taken 36051 times.
|
3544292 | if (more_data) |
2689 |
2/2✓ Branch 0 taken 96024 times.
✓ Branch 1 taken 3412217 times.
|
3604265 | return ((x1 + cb_size_split) < sps->width || |
2690 |
2/2✓ Branch 0 taken 96023 times.
✓ Branch 1 taken 1 times.
|
96024 | (y1 + cb_size_split) < sps->height); |
2691 | else | ||
2692 | 36051 | return 0; | |
2693 | } else { | ||
2694 | 11738364 | ret = hls_coding_unit(lc, s, l, pps, sps, x0, y0, log2_cb_size); | |
2695 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11738363 times.
|
11738364 | if (ret < 0) |
2696 | 1 | return ret; | |
2697 | 11738363 | if ((!((x0 + cb_size) % | |
2698 |
2/2✓ Branch 0 taken 8490754 times.
✓ Branch 1 taken 3247609 times.
|
11738363 | (1 << (sps->log2_ctb_size))) || |
2699 |
2/2✓ Branch 0 taken 71449 times.
✓ Branch 1 taken 8419305 times.
|
8490754 | (x0 + cb_size >= sps->width)) && |
2700 | 3319058 | (!((y0 + cb_size) % | |
2701 |
2/2✓ Branch 0 taken 1830821 times.
✓ Branch 1 taken 1488237 times.
|
3319058 | (1 << (sps->log2_ctb_size))) || |
2702 |
2/2✓ Branch 0 taken 98982 times.
✓ Branch 1 taken 1731839 times.
|
1830821 | (y0 + cb_size >= sps->height))) { |
2703 | 1587219 | int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc); | |
2704 | 1587219 | return !end_of_slice_flag; | |
2705 | } else { | ||
2706 | 10151144 | return 1; | |
2707 | } | ||
2708 | } | ||
2709 | |||
2710 | return 0; | ||
2711 | } | ||
2712 | |||
2713 | 1587220 | static void hls_decode_neighbour(HEVCLocalContext *lc, | |
2714 | const HEVCLayerContext *l, | ||
2715 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
2716 | int x_ctb, int y_ctb, int ctb_addr_ts) | ||
2717 | { | ||
2718 | 1587220 | const HEVCContext *const s = lc->parent; | |
2719 | 1587220 | int ctb_size = 1 << sps->log2_ctb_size; | |
2720 | 1587220 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2721 | 1587220 | int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr; | |
2722 | |||
2723 | 1587220 | l->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr; | |
2724 | |||
2725 |
2/2✓ Branch 0 taken 167314 times.
✓ Branch 1 taken 1419906 times.
|
1587220 | if (pps->entropy_coding_sync_enabled_flag) { |
2726 |
3/4✓ Branch 0 taken 7469 times.
✓ Branch 1 taken 159845 times.
✓ Branch 2 taken 7469 times.
✗ Branch 3 not taken.
|
167314 | if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0) |
2727 | 7469 | lc->first_qp_group = 1; | |
2728 | 167314 | lc->end_of_tiles_x = sps->width; | |
2729 |
2/2✓ Branch 0 taken 291890 times.
✓ Branch 1 taken 1128016 times.
|
1419906 | } else if (pps->tiles_enabled_flag) { |
2730 |
4/4✓ Branch 0 taken 291264 times.
✓ Branch 1 taken 626 times.
✓ Branch 2 taken 6287 times.
✓ Branch 3 taken 284977 times.
|
291890 | if (ctb_addr_ts && pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) { |
2731 | 6287 | int idxX = pps->col_idxX[x_ctb >> sps->log2_ctb_size]; | |
2732 | 6287 | lc->end_of_tiles_x = x_ctb + (pps->column_width[idxX] << sps->log2_ctb_size); | |
2733 | 6287 | lc->first_qp_group = 1; | |
2734 | } | ||
2735 | } else { | ||
2736 | 1128016 | lc->end_of_tiles_x = sps->width; | |
2737 | } | ||
2738 | |||
2739 | 1587220 | lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height); | |
2740 | |||
2741 | 1587220 | lc->boundary_flags = 0; | |
2742 |
2/2✓ Branch 0 taken 291890 times.
✓ Branch 1 taken 1295330 times.
|
1587220 | if (pps->tiles_enabled_flag) { |
2743 |
4/4✓ Branch 0 taken 279936 times.
✓ Branch 1 taken 11954 times.
✓ Branch 2 taken 30753 times.
✓ Branch 3 taken 249183 times.
|
291890 | if (x_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]]) |
2744 | 30753 | lc->boundary_flags |= BOUNDARY_LEFT_TILE; | |
2745 |
4/4✓ Branch 0 taken 279936 times.
✓ Branch 1 taken 11954 times.
✓ Branch 2 taken 3741 times.
✓ Branch 3 taken 276195 times.
|
291890 | if (x_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - 1]) |
2746 | 3741 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
2747 |
4/4✓ Branch 0 taken 277242 times.
✓ Branch 1 taken 14648 times.
✓ Branch 2 taken 33781 times.
✓ Branch 3 taken 243461 times.
|
291890 | if (y_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - sps->ctb_width]]) |
2748 | 33781 | lc->boundary_flags |= BOUNDARY_UPPER_TILE; | |
2749 |
4/4✓ Branch 0 taken 277242 times.
✓ Branch 1 taken 14648 times.
✓ Branch 2 taken 14490 times.
✓ Branch 3 taken 262752 times.
|
291890 | if (y_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - sps->ctb_width]) |
2750 | 14490 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
2751 | } else { | ||
2752 |
2/2✓ Branch 0 taken 18339 times.
✓ Branch 1 taken 1276991 times.
|
1295330 | if (ctb_addr_in_slice <= 0) |
2753 | 18339 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
2754 |
2/2✓ Branch 0 taken 197192 times.
✓ Branch 1 taken 1098138 times.
|
1295330 | if (ctb_addr_in_slice < sps->ctb_width) |
2755 | 197192 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
2756 | } | ||
2757 | |||
2758 |
6/6✓ Branch 0 taken 1505304 times.
✓ Branch 1 taken 81916 times.
✓ Branch 2 taken 1497415 times.
✓ Branch 3 taken 7889 times.
✓ Branch 4 taken 1467690 times.
✓ Branch 5 taken 29725 times.
|
1587220 | lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE)); |
2759 |
6/6✓ Branch 0 taken 1455549 times.
✓ Branch 1 taken 131671 times.
✓ Branch 2 taken 1361719 times.
✓ Branch 3 taken 93830 times.
✓ Branch 4 taken 1341599 times.
✓ Branch 5 taken 20120 times.
|
1587220 | lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE)); |
2760 |
6/6✓ Branch 0 taken 1455549 times.
✓ Branch 1 taken 131671 times.
✓ Branch 2 taken 1364308 times.
✓ Branch 3 taken 91241 times.
✓ Branch 4 taken 1308556 times.
✓ Branch 5 taken 55752 times.
|
1587220 | lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= sps->ctb_width) && (pps->tile_id[ctb_addr_ts] == pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - sps->ctb_width]])); |
2761 |
8/8✓ Branch 0 taken 1505304 times.
✓ Branch 1 taken 81916 times.
✓ Branch 2 taken 1383904 times.
✓ Branch 3 taken 121400 times.
✓ Branch 4 taken 1295138 times.
✓ Branch 5 taken 88766 times.
✓ Branch 6 taken 1250906 times.
✓ Branch 7 taken 44232 times.
|
1587220 | lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= sps->ctb_width) && (pps->tile_id[ctb_addr_ts] == pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - sps->ctb_width]])); |
2762 | 1587220 | } | |
2763 | |||
2764 | 28265 | static int hls_decode_entry(HEVCContext *s, GetBitContext *gb) | |
2765 | { | ||
2766 | 28265 | HEVCLocalContext *const lc = &s->local_ctx[0]; | |
2767 | 28265 | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
2768 | 28265 | const HEVCPPS *const pps = s->pps; | |
2769 | 28265 | const HEVCSPS *const sps = pps->sps; | |
2770 | 28265 | const uint8_t *slice_data = gb->buffer + s->sh.data_offset; | |
2771 | 28265 | const size_t slice_size = gb->buffer_end - gb->buffer - s->sh.data_offset; | |
2772 | 28265 | int ctb_size = 1 << sps->log2_ctb_size; | |
2773 | 28265 | int more_data = 1; | |
2774 | 28265 | int x_ctb = 0; | |
2775 | 28265 | int y_ctb = 0; | |
2776 | 28265 | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
2777 | int ret; | ||
2778 | |||
2779 |
3/4✓ Branch 0 taken 1587220 times.
✓ Branch 1 taken 28264 times.
✓ Branch 2 taken 1587220 times.
✗ Branch 3 not taken.
|
1615484 | while (more_data && ctb_addr_ts < sps->ctb_size) { |
2780 | 1587220 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2781 | |||
2782 | 1587220 | x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size; | |
2783 | 1587220 | y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size; | |
2784 | 1587220 | hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
2785 | |||
2786 | 1587220 | ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 0); | |
2787 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1587220 times.
|
1587220 | if (ret < 0) { |
2788 | ✗ | l->tab_slice_address[ctb_addr_rs] = -1; | |
2789 | ✗ | return ret; | |
2790 | } | ||
2791 | |||
2792 | 1587220 | hls_sao_param(lc, l, pps, sps, | |
2793 | 1587220 | x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); | |
2794 | |||
2795 | 1587220 | l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
2796 | 1587220 | l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
2797 | 1587220 | l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
2798 | |||
2799 | 1587220 | more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); | |
2800 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1587219 times.
|
1587220 | if (more_data < 0) { |
2801 | 1 | l->tab_slice_address[ctb_addr_rs] = -1; | |
2802 | 1 | return more_data; | |
2803 | } | ||
2804 | |||
2805 | |||
2806 | 1587219 | ctb_addr_ts++; | |
2807 | 1587219 | ff_hevc_save_states(lc, pps, ctb_addr_ts); | |
2808 | 1587219 | ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
2809 | } | ||
2810 | |||
2811 |
2/2✓ Branch 0 taken 14754 times.
✓ Branch 1 taken 13510 times.
|
28264 | if (x_ctb + ctb_size >= sps->width && |
2812 |
2/2✓ Branch 0 taken 10270 times.
✓ Branch 1 taken 4484 times.
|
14754 | y_ctb + ctb_size >= sps->height) |
2813 | 10270 | ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
2814 | |||
2815 | 28264 | return ctb_addr_ts; | |
2816 | } | ||
2817 | |||
2818 | ✗ | static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, | |
2819 | int job, int thread) | ||
2820 | { | ||
2821 | ✗ | HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread]; | |
2822 | ✗ | const HEVCContext *const s = lc->parent; | |
2823 | ✗ | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
2824 | ✗ | const HEVCPPS *const pps = s->pps; | |
2825 | ✗ | const HEVCSPS *const sps = pps->sps; | |
2826 | ✗ | int ctb_size = 1 << sps->log2_ctb_size; | |
2827 | ✗ | int more_data = 1; | |
2828 | ✗ | int ctb_row = job; | |
2829 | ✗ | int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size); | |
2830 | ✗ | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs]; | |
2831 | |||
2832 | ✗ | const uint8_t *data = s->data + s->sh.offset[ctb_row]; | |
2833 | ✗ | const size_t data_size = s->sh.size[ctb_row]; | |
2834 | |||
2835 | ✗ | int progress = 0; | |
2836 | |||
2837 | int ret; | ||
2838 | |||
2839 | ✗ | if (ctb_row) | |
2840 | ✗ | ff_init_cabac_decoder(&lc->cc, data, data_size); | |
2841 | |||
2842 | ✗ | while(more_data && ctb_addr_ts < sps->ctb_size) { | |
2843 | ✗ | int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size; | |
2844 | ✗ | int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size; | |
2845 | |||
2846 | ✗ | hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
2847 | |||
2848 | ✗ | if (ctb_row) | |
2849 | ✗ | ff_thread_progress_await(&s->wpp_progress[ctb_row - 1], | |
2850 | progress + SHIFT_CTB_WPP + 1); | ||
2851 | |||
2852 | /* atomic_load's prototype requires a pointer to non-const atomic variable | ||
2853 | * (due to implementations via mutexes, where reads involve writes). | ||
2854 | * Of course, casting const away here is nevertheless safe. */ | ||
2855 | ✗ | if (atomic_load((atomic_int*)&s->wpp_err)) { | |
2856 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2857 | ✗ | return 0; | |
2858 | } | ||
2859 | |||
2860 | ✗ | ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1); | |
2861 | ✗ | if (ret < 0) | |
2862 | ✗ | goto error; | |
2863 | ✗ | hls_sao_param(lc, l, pps, sps, | |
2864 | ✗ | x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); | |
2865 | |||
2866 | ✗ | l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
2867 | ✗ | l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
2868 | ✗ | l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
2869 | |||
2870 | ✗ | more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); | |
2871 | |||
2872 | ✗ | if (more_data < 0) { | |
2873 | ✗ | ret = more_data; | |
2874 | ✗ | goto error; | |
2875 | } | ||
2876 | |||
2877 | ✗ | ctb_addr_ts++; | |
2878 | |||
2879 | ✗ | ff_hevc_save_states(lc, pps, ctb_addr_ts); | |
2880 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], ++progress); | |
2881 | ✗ | ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
2882 | |||
2883 | ✗ | if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) { | |
2884 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
2885 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
2886 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2887 | ✗ | return 0; | |
2888 | } | ||
2889 | |||
2890 | ✗ | if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) { | |
2891 | ✗ | ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
2892 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2893 | ✗ | return ctb_addr_ts; | |
2894 | } | ||
2895 | ✗ | ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2896 | ✗ | x_ctb+=ctb_size; | |
2897 | |||
2898 | ✗ | if(x_ctb >= sps->width) { | |
2899 | ✗ | break; | |
2900 | } | ||
2901 | } | ||
2902 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2903 | |||
2904 | ✗ | return 0; | |
2905 | ✗ | error: | |
2906 | ✗ | l->tab_slice_address[ctb_addr_rs] = -1; | |
2907 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
2908 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
2909 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
2910 | ✗ | return ret; | |
2911 | } | ||
2912 | |||
2913 | ✗ | static int wpp_progress_init(HEVCContext *s, unsigned count) | |
2914 | { | ||
2915 | ✗ | if (s->nb_wpp_progress < count) { | |
2916 | ✗ | void *tmp = av_realloc_array(s->wpp_progress, count, | |
2917 | sizeof(*s->wpp_progress)); | ||
2918 | ✗ | if (!tmp) | |
2919 | ✗ | return AVERROR(ENOMEM); | |
2920 | |||
2921 | ✗ | s->wpp_progress = tmp; | |
2922 | ✗ | memset(s->wpp_progress + s->nb_wpp_progress, 0, | |
2923 | ✗ | (count - s->nb_wpp_progress) * sizeof(*s->wpp_progress)); | |
2924 | |||
2925 | ✗ | for (int i = s->nb_wpp_progress; i < count; i++) { | |
2926 | ✗ | int ret = ff_thread_progress_init(&s->wpp_progress[i], 1); | |
2927 | ✗ | if (ret < 0) | |
2928 | ✗ | return ret; | |
2929 | ✗ | s->nb_wpp_progress = i + 1; | |
2930 | } | ||
2931 | } | ||
2932 | |||
2933 | ✗ | for (int i = 0; i < count; i++) | |
2934 | ✗ | ff_thread_progress_reset(&s->wpp_progress[i]); | |
2935 | |||
2936 | ✗ | return 0; | |
2937 | } | ||
2938 | |||
2939 | ✗ | static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) | |
2940 | { | ||
2941 | ✗ | const HEVCPPS *const pps = s->pps; | |
2942 | ✗ | const HEVCSPS *const sps = pps->sps; | |
2943 | ✗ | const uint8_t *data = nal->data; | |
2944 | ✗ | int length = nal->size; | |
2945 | int *ret; | ||
2946 | int64_t offset; | ||
2947 | ✗ | int64_t startheader, cmpt = 0; | |
2948 | ✗ | int i, j, res = 0; | |
2949 | |||
2950 | ✗ | if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * sps->ctb_width >= sps->ctb_width * sps->ctb_height) { | |
2951 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n", | |
2952 | s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets, | ||
2953 | ✗ | sps->ctb_width, sps->ctb_height | |
2954 | ); | ||
2955 | ✗ | return AVERROR_INVALIDDATA; | |
2956 | } | ||
2957 | |||
2958 | ✗ | if (s->avctx->thread_count > s->nb_local_ctx) { | |
2959 | ✗ | HEVCLocalContext *tmp = av_malloc_array(s->avctx->thread_count, sizeof(*s->local_ctx)); | |
2960 | |||
2961 | ✗ | if (!tmp) | |
2962 | ✗ | return AVERROR(ENOMEM); | |
2963 | |||
2964 | ✗ | memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx); | |
2965 | ✗ | av_free(s->local_ctx); | |
2966 | ✗ | s->local_ctx = tmp; | |
2967 | |||
2968 | ✗ | for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) { | |
2969 | ✗ | tmp = &s->local_ctx[i]; | |
2970 | |||
2971 | ✗ | memset(tmp, 0, sizeof(*tmp)); | |
2972 | |||
2973 | ✗ | tmp->logctx = s->avctx; | |
2974 | ✗ | tmp->parent = s; | |
2975 | ✗ | tmp->common_cabac_state = &s->cabac; | |
2976 | } | ||
2977 | |||
2978 | ✗ | s->nb_local_ctx = s->avctx->thread_count; | |
2979 | } | ||
2980 | |||
2981 | ✗ | offset = s->sh.data_offset; | |
2982 | |||
2983 | ✗ | for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) { | |
2984 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
2985 | ✗ | startheader--; | |
2986 | ✗ | cmpt++; | |
2987 | } | ||
2988 | } | ||
2989 | |||
2990 | ✗ | for (i = 1; i < s->sh.num_entry_point_offsets; i++) { | |
2991 | ✗ | offset += (s->sh.entry_point_offset[i - 1] - cmpt); | |
2992 | ✗ | for (j = 0, cmpt = 0, startheader = offset | |
2993 | ✗ | + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) { | |
2994 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
2995 | ✗ | startheader--; | |
2996 | ✗ | cmpt++; | |
2997 | } | ||
2998 | } | ||
2999 | ✗ | s->sh.size[i] = s->sh.entry_point_offset[i] - cmpt; | |
3000 | ✗ | s->sh.offset[i] = offset; | |
3001 | |||
3002 | } | ||
3003 | |||
3004 | ✗ | offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt; | |
3005 | ✗ | if (length < offset) { | |
3006 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n"); | |
3007 | ✗ | return AVERROR_INVALIDDATA; | |
3008 | } | ||
3009 | ✗ | s->sh.size [s->sh.num_entry_point_offsets] = length - offset; | |
3010 | ✗ | s->sh.offset[s->sh.num_entry_point_offsets] = offset; | |
3011 | |||
3012 | ✗ | s->sh.offset[0] = s->sh.data_offset; | |
3013 | ✗ | s->sh.size[0] = s->sh.offset[1] - s->sh.offset[0]; | |
3014 | |||
3015 | ✗ | s->data = data; | |
3016 | |||
3017 | ✗ | for (i = 1; i < s->nb_local_ctx; i++) { | |
3018 | ✗ | s->local_ctx[i].first_qp_group = 1; | |
3019 | ✗ | s->local_ctx[i].qp_y = s->local_ctx[0].qp_y; | |
3020 | } | ||
3021 | |||
3022 | ✗ | atomic_store(&s->wpp_err, 0); | |
3023 | ✗ | res = wpp_progress_init(s, s->sh.num_entry_point_offsets + 1); | |
3024 | ✗ | if (res < 0) | |
3025 | ✗ | return res; | |
3026 | |||
3027 | ✗ | ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret)); | |
3028 | ✗ | if (!ret) | |
3029 | ✗ | return AVERROR(ENOMEM); | |
3030 | |||
3031 | ✗ | if (pps->entropy_coding_sync_enabled_flag) | |
3032 | ✗ | s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->local_ctx, ret, s->sh.num_entry_point_offsets + 1); | |
3033 | |||
3034 | ✗ | for (i = 0; i <= s->sh.num_entry_point_offsets; i++) | |
3035 | ✗ | res += ret[i]; | |
3036 | |||
3037 | ✗ | av_free(ret); | |
3038 | ✗ | return res; | |
3039 | } | ||
3040 | |||
3041 | 28265 | static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l, | |
3042 | const H2645NAL *nal, GetBitContext *gb) | ||
3043 | { | ||
3044 | 28265 | const HEVCPPS *pps = s->pps; | |
3045 | int ret; | ||
3046 | |||
3047 |
2/2✓ Branch 0 taken 17994 times.
✓ Branch 1 taken 10271 times.
|
28265 | if (!s->sh.first_slice_in_pic_flag) |
3048 | 17994 | s->slice_idx += !s->sh.dependent_slice_segment_flag; | |
3049 | |||
3050 |
4/4✓ Branch 0 taken 20318 times.
✓ Branch 1 taken 7947 times.
✓ Branch 2 taken 19073 times.
✓ Branch 3 taken 1245 times.
|
28265 | if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) { |
3051 | 19073 | ret = ff_hevc_slice_rpl(s); | |
3052 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19073 times.
|
19073 | if (ret < 0) { |
3053 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
3054 | "Error constructing the reference lists for the current slice.\n"); | ||
3055 | ✗ | return ret; | |
3056 | } | ||
3057 | } | ||
3058 | |||
3059 | 28265 | s->slice_initialized = 1; | |
3060 | |||
3061 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28265 times.
|
28265 | if (s->avctx->hwaccel) |
3062 | ✗ | return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size); | |
3063 | |||
3064 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28265 times.
|
28265 | if (s->avctx->profile == AV_PROFILE_HEVC_SCC) { |
3065 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3066 | "SCC profile is not yet implemented in hevc native decoder.\n"); | ||
3067 | ✗ | return AVERROR_PATCHWELCOME; | |
3068 | } | ||
3069 | |||
3070 |
2/2✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20318 times.
|
28265 | if (s->sh.dependent_slice_segment_flag) { |
3071 | 7947 | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
3072 | 7947 | int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1]; | |
3073 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
|
7947 | if (l->tab_slice_address[prev_rs] != s->sh.slice_addr) { |
3074 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n"); | |
3075 | ✗ | return AVERROR_INVALIDDATA; | |
3076 | } | ||
3077 | } | ||
3078 | |||
3079 | 28265 | s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag; | |
3080 | |||
3081 |
2/2✓ Branch 0 taken 23180 times.
✓ Branch 1 taken 5085 times.
|
28265 | if (!pps->cu_qp_delta_enabled_flag) |
3082 | 23180 | s->local_ctx[0].qp_y = s->sh.slice_qp; | |
3083 | |||
3084 | 28265 | s->local_ctx[0].tu.cu_qp_offset_cb = 0; | |
3085 | 28265 | s->local_ctx[0].tu.cu_qp_offset_cr = 0; | |
3086 | |||
3087 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28265 times.
|
28265 | if (s->avctx->active_thread_type == FF_THREAD_SLICE && |
3088 | ✗ | s->sh.num_entry_point_offsets > 0 && | |
3089 | ✗ | pps->num_tile_rows == 1 && pps->num_tile_columns == 1) | |
3090 | ✗ | return hls_slice_data_wpp(s, nal); | |
3091 | |||
3092 | 28265 | return hls_decode_entry(s, gb); | |
3093 | } | ||
3094 | |||
3095 | 10271 | static int set_side_data(HEVCContext *s) | |
3096 | { | ||
3097 | 10271 | const HEVCSPS *sps = s->cur_frame->pps->sps; | |
3098 | 10271 | AVFrame *out = s->cur_frame->f; | |
3099 | int ret; | ||
3100 | |||
3101 | // Decrement the mastering display and content light level flag when IRAP | ||
3102 | // frame has no_rasl_output_flag=1 so the side data persists for the entire | ||
3103 | // coded video sequence. | ||
3104 |
5/6✓ Branch 0 taken 722 times.
✓ Branch 1 taken 9549 times.
✓ Branch 2 taken 722 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 439 times.
✓ Branch 5 taken 283 times.
|
10271 | if (IS_IRAP(s) && s->no_rasl_output_flag) { |
3105 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 431 times.
|
439 | if (s->sei.common.mastering_display.present > 0) |
3106 | 8 | s->sei.common.mastering_display.present--; | |
3107 | |||
3108 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 433 times.
|
439 | if (s->sei.common.content_light.present > 0) |
3109 | 6 | s->sei.common.content_light.present--; | |
3110 | } | ||
3111 | |||
3112 | 10271 | ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx, | |
3113 | &sps->vui.common, | ||
3114 | 10271 | sps->bit_depth, sps->bit_depth_chroma, | |
3115 | 10271 | s->cur_frame->poc /* no poc_offset in HEVC */); | |
3116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (ret < 0) |
3117 | ✗ | return ret; | |
3118 | |||
3119 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 10248 times.
|
10271 | if (s->sei.timecode.present) { |
3120 | uint32_t *tc_sd; | ||
3121 | char tcbuf[AV_TIMECODE_STR_SIZE]; | ||
3122 | AVFrameSideData *tcside; | ||
3123 | 23 | ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE, | |
3124 | sizeof(uint32_t) * 4, &tcside); | ||
3125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (ret < 0) |
3126 | ✗ | return ret; | |
3127 | |||
3128 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | if (tcside) { |
3129 | 23 | tc_sd = (uint32_t*)tcside->data; | |
3130 | 23 | tc_sd[0] = s->sei.timecode.num_clock_ts; | |
3131 | |||
3132 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 23 times.
|
46 | for (int i = 0; i < tc_sd[0]; i++) { |
3133 | 23 | int drop = s->sei.timecode.cnt_dropped_flag[i]; | |
3134 | 23 | int hh = s->sei.timecode.hours_value[i]; | |
3135 | 23 | int mm = s->sei.timecode.minutes_value[i]; | |
3136 | 23 | int ss = s->sei.timecode.seconds_value[i]; | |
3137 | 23 | int ff = s->sei.timecode.n_frames[i]; | |
3138 | |||
3139 | 23 | tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff); | |
3140 | 23 | av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0); | |
3141 | 23 | av_dict_set(&out->metadata, "timecode", tcbuf, 0); | |
3142 | } | ||
3143 | } | ||
3144 | |||
3145 | 23 | s->sei.timecode.num_clock_ts = 0; | |
3146 | } | ||
3147 | |||
3148 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10267 times.
|
10271 | if (s->sei.common.dynamic_hdr_plus.info) { |
3149 | 4 | AVBufferRef *info_ref = av_buffer_ref(s->sei.common.dynamic_hdr_plus.info); | |
3150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!info_ref) |
3151 | ✗ | return AVERROR(ENOMEM); | |
3152 | |||
3153 | 4 | ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref); | |
3154 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ret < 0) |
3155 | ✗ | return ret; | |
3156 | } | ||
3157 | |||
3158 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10269 times.
|
10271 | if (s->rpu_buf) { |
3159 | 2 | AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf); | |
3160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!rpu) |
3161 | ✗ | return AVERROR(ENOMEM); | |
3162 | |||
3163 | 2 | s->rpu_buf = NULL; | |
3164 | } | ||
3165 | |||
3166 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10271 times.
|
10271 | if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0) |
3167 | ✗ | return ret; | |
3168 | |||
3169 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10269 times.
|
10271 | if (s->sei.common.dynamic_hdr_vivid.info) { |
3170 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!av_frame_side_data_add(&out->side_data, &out->nb_side_data, |
3171 | AV_FRAME_DATA_DYNAMIC_HDR_VIVID, | ||
3172 | &s->sei.common.dynamic_hdr_vivid.info, | ||
3173 | AV_FRAME_SIDE_DATA_FLAG_NEW_REF)) | ||
3174 | ✗ | return AVERROR(ENOMEM); | |
3175 | } | ||
3176 | |||
3177 | 10271 | return 0; | |
3178 | } | ||
3179 | |||
3180 | 9944 | static int find_finish_setup_nal(const HEVCContext *s) | |
3181 | { | ||
3182 | 9944 | int nal_idx = 0; | |
3183 | |||
3184 |
2/2✓ Branch 0 taken 38866 times.
✓ Branch 1 taken 9944 times.
|
48810 | for (int i = nal_idx; i < s->pkt.nb_nals; i++) { |
3185 | 38866 | const H2645NAL *nal = &s->pkt.nals[i]; | |
3186 | 38866 | const int layer_id = nal->nuh_layer_id; | |
3187 | 38866 | GetBitContext gb = nal->gb; | |
3188 | |||
3189 |
2/4✓ Branch 0 taken 38866 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38866 times.
✗ Branch 3 not taken.
|
38866 | if (layer_id > HEVC_MAX_NUH_LAYER_ID || s->vps->layer_idx[layer_id] < 0 || |
3190 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 38850 times.
|
38866 | !(s->layers_active_decode & (1 << s->vps->layer_idx[layer_id]))) |
3191 | 18010 | continue; | |
3192 | |||
3193 |
3/3✓ Branch 0 taken 28266 times.
✓ Branch 1 taken 2264 times.
✓ Branch 2 taken 8320 times.
|
38850 | switch (nal->type) { |
3194 | 28266 | case HEVC_NAL_TRAIL_R: | |
3195 | case HEVC_NAL_TRAIL_N: | ||
3196 | case HEVC_NAL_TSA_N: | ||
3197 | case HEVC_NAL_TSA_R: | ||
3198 | case HEVC_NAL_STSA_N: | ||
3199 | case HEVC_NAL_STSA_R: | ||
3200 | case HEVC_NAL_BLA_W_LP: | ||
3201 | case HEVC_NAL_BLA_W_RADL: | ||
3202 | case HEVC_NAL_BLA_N_LP: | ||
3203 | case HEVC_NAL_IDR_W_RADL: | ||
3204 | case HEVC_NAL_IDR_N_LP: | ||
3205 | case HEVC_NAL_CRA_NUT: | ||
3206 | case HEVC_NAL_RADL_N: | ||
3207 | case HEVC_NAL_RADL_R: | ||
3208 | case HEVC_NAL_RASL_N: | ||
3209 | case HEVC_NAL_RASL_R: | ||
3210 |
2/2✓ Branch 1 taken 17994 times.
✓ Branch 2 taken 10272 times.
|
28266 | if (!get_bits1(&gb)) // first_slice_segment_in_pic_flag |
3211 | 17994 | continue; | |
3212 | case HEVC_NAL_VPS: | ||
3213 | case HEVC_NAL_SPS: | ||
3214 | case HEVC_NAL_PPS: | ||
3215 | 12536 | nal_idx = i; | |
3216 | 12536 | break; | |
3217 | } | ||
3218 | } | ||
3219 | |||
3220 | 9944 | return nal_idx; | |
3221 | } | ||
3222 | |||
3223 | 10271 | static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, | |
3224 | unsigned nal_idx) | ||
3225 | { | ||
3226 | 10271 | const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id]; | |
3227 | 10271 | const HEVCSPS *const sps = pps->sps; | |
3228 | 10271 | int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) * | |
3229 | 10271 | ((sps->height >> sps->log2_min_cb_size) + 1); | |
3230 |
2/2✓ Branch 0 taken 9944 times.
✓ Branch 1 taken 327 times.
|
20215 | int new_sequence = (l == &s->layers[0]) && |
3231 |
12/12✓ Branch 0 taken 9560 times.
✓ Branch 1 taken 384 times.
✓ Branch 2 taken 9536 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 9534 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9527 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9526 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 9 times.
✓ Branch 11 taken 9517 times.
|
9944 | (IS_IDR(s) || IS_BLA(s) || s->last_eos); |
3232 | 10271 | int prev_layers_active_decode = s->layers_active_decode; | |
3233 | 10271 | int prev_layers_active_output = s->layers_active_output; | |
3234 | int ret; | ||
3235 | |||
3236 |
3/4✓ Branch 0 taken 400 times.
✓ Branch 1 taken 9871 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 400 times.
|
10271 | if (sps->vps != s->vps && l != &s->layers[0]) { |
3237 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n"); | |
3238 | ✗ | set_sps(s, l, NULL); | |
3239 | ✗ | return AVERROR_INVALIDDATA; | |
3240 | } | ||
3241 | |||
3242 | 10271 | av_refstruct_replace(&s->pps, pps); | |
3243 |
2/2✓ Branch 0 taken 415 times.
✓ Branch 1 taken 9856 times.
|
10271 | if (l->sps != sps) { |
3244 | 415 | const HEVCSPS *sps_base = s->layers[0].sps; | |
3245 | 415 | enum AVPixelFormat pix_fmt = sps->pix_fmt; | |
3246 | |||
3247 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 406 times.
|
415 | if (l != &s->layers[0]) { |
3248 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (!sps_base) { |
3249 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3250 | "Access unit starts with a non-base layer frame\n"); | ||
3251 | ✗ | return AVERROR_INVALIDDATA; | |
3252 | } | ||
3253 | |||
3254 | // Files produced by Vision Pro lack VPS extension VUI, | ||
3255 | // so the secondary layer has no range information. | ||
3256 | // This check avoids failing in such a case. | ||
3257 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (sps_base->pix_fmt == AV_PIX_FMT_YUVJ420P && |
3258 | ✗ | sps->pix_fmt == AV_PIX_FMT_YUV420P && | |
3259 | ✗ | !sps->vui.common.video_signal_type_present_flag) | |
3260 | ✗ | pix_fmt = sps_base->pix_fmt; | |
3261 | |||
3262 | // Ignore range mismatch between base layer and alpha layer | ||
3263 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8 times.
|
9 | if (ff_hevc_is_alpha_video(s) && |
3264 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | sps_base->pix_fmt == AV_PIX_FMT_YUV420P && |
3265 | pix_fmt == AV_PIX_FMT_YUVJ420P) | ||
3266 | 1 | pix_fmt = sps_base->pix_fmt; | |
3267 | |||
3268 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (pix_fmt != sps_base->pix_fmt || |
3269 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | sps->width != sps_base->width || |
3270 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | sps->height != sps_base->height) { |
3271 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3272 | "Base/non-base layer SPS have unsupported parameter combination\n"); | ||
3273 | ✗ | return AVERROR(ENOSYS); | |
3274 | } | ||
3275 | } | ||
3276 | |||
3277 | 415 | ff_hevc_clear_refs(l); | |
3278 | |||
3279 | 415 | ret = set_sps(s, l, sps); | |
3280 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 415 times.
|
415 | if (ret < 0) |
3281 | ✗ | return ret; | |
3282 | |||
3283 |
2/2✓ Branch 0 taken 406 times.
✓ Branch 1 taken 9 times.
|
415 | if (l == &s->layers[0]) { |
3284 | 406 | export_stream_params(s, sps); | |
3285 | |||
3286 | 406 | ret = get_format(s, sps); | |
3287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 406 times.
|
406 | if (ret < 0) { |
3288 | ✗ | set_sps(s, l, NULL); | |
3289 | ✗ | return ret; | |
3290 | } | ||
3291 | |||
3292 | 406 | new_sequence = 1; | |
3293 | } | ||
3294 | } | ||
3295 | |||
3296 | 10271 | memset(l->horizontal_bs, 0, l->bs_width * l->bs_height); | |
3297 | 10271 | memset(l->vertical_bs, 0, l->bs_width * l->bs_height); | |
3298 | 10271 | memset(l->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height); | |
3299 | 10271 | memset(l->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1)); | |
3300 | 10271 | memset(l->tab_slice_address, -1, pic_size_in_ctb * sizeof(*l->tab_slice_address)); | |
3301 | |||
3302 |
4/4✓ Branch 0 taken 9880 times.
✓ Branch 1 taken 391 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 9851 times.
|
10271 | if (IS_IDR(s)) |
3303 | 420 | ff_hevc_clear_refs(l); | |
3304 | |||
3305 | 10271 | s->slice_idx = 0; | |
3306 | 10271 | s->first_nal_type = s->nal_unit_type; | |
3307 | 10271 | s->poc = s->sh.poc; | |
3308 | |||
3309 |
3/4✓ Branch 0 taken 722 times.
✓ Branch 1 taken 9549 times.
✓ Branch 2 taken 722 times.
✗ Branch 3 not taken.
|
10271 | if (IS_IRAP(s)) { |
3310 |
10/10✓ Branch 0 taken 331 times.
✓ Branch 1 taken 391 times.
✓ Branch 2 taken 302 times.
✓ Branch 3 taken 29 times.
✓ Branch 4 taken 300 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 293 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 292 times.
✓ Branch 9 taken 1 times.
|
1014 | s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || |
3311 |
3/4✓ Branch 0 taken 292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 283 times.
|
292 | (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos); |
3312 | 722 | s->recovery_poc = HEVC_RECOVERY_END; | |
3313 | } | ||
3314 | |||
3315 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 10260 times.
|
10271 | if (s->recovery_poc != HEVC_RECOVERY_END && |
3316 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | s->sei.recovery_point.has_recovery_poc) { |
3317 | ✗ | if (s->recovery_poc == HEVC_RECOVERY_UNSPECIFIED) | |
3318 | ✗ | s->recovery_poc = s->poc + s->sei.recovery_point.recovery_poc_cnt; | |
3319 | ✗ | else if (s->poc >= s->recovery_poc) | |
3320 | ✗ | s->recovery_poc = HEVC_RECOVERY_END; | |
3321 | } | ||
3322 | |||
3323 | /* 8.3.1 */ | ||
3324 |
2/2✓ Branch 0 taken 9929 times.
✓ Branch 1 taken 342 times.
|
10271 | if (s->temporal_id == 0 && |
3325 |
2/2✓ Branch 0 taken 7259 times.
✓ Branch 1 taken 2670 times.
|
9929 | s->nal_unit_type != HEVC_NAL_TRAIL_N && |
3326 |
1/2✓ Branch 0 taken 7259 times.
✗ Branch 1 not taken.
|
7259 | s->nal_unit_type != HEVC_NAL_TSA_N && |
3327 |
1/2✓ Branch 0 taken 7259 times.
✗ Branch 1 not taken.
|
7259 | s->nal_unit_type != HEVC_NAL_STSA_N && |
3328 |
2/2✓ Branch 0 taken 7233 times.
✓ Branch 1 taken 26 times.
|
7259 | s->nal_unit_type != HEVC_NAL_RADL_N && |
3329 |
2/2✓ Branch 0 taken 7211 times.
✓ Branch 1 taken 22 times.
|
7233 | s->nal_unit_type != HEVC_NAL_RADL_R && |
3330 |
2/2✓ Branch 0 taken 6841 times.
✓ Branch 1 taken 370 times.
|
7211 | s->nal_unit_type != HEVC_NAL_RASL_N && |
3331 |
2/2✓ Branch 0 taken 6367 times.
✓ Branch 1 taken 474 times.
|
6841 | s->nal_unit_type != HEVC_NAL_RASL_R) |
3332 | 6367 | s->poc_tid0 = s->poc; | |
3333 | |||
3334 |
2/2✓ Branch 0 taken 626 times.
✓ Branch 1 taken 9645 times.
|
10271 | if (pps->tiles_enabled_flag) |
3335 | 626 | s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size; | |
3336 | |||
3337 |
2/2✓ Branch 0 taken 430 times.
✓ Branch 1 taken 9841 times.
|
10271 | if (new_sequence) { |
3338 | 430 | ret = ff_hevc_output_frames(s, prev_layers_active_decode, prev_layers_active_output, | |
3339 | 430 | 0, 0, s->sh.no_output_of_prior_pics_flag); | |
3340 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 430 times.
|
430 | if (ret < 0) |
3341 | ✗ | return ret; | |
3342 | } | ||
3343 | |||
3344 | 10271 | ret = export_stream_params_from_sei(s); | |
3345 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (ret < 0) |
3346 | ✗ | return ret; | |
3347 | |||
3348 | 10271 | ret = ff_hevc_set_new_ref(s, l, s->poc); | |
3349 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (ret < 0) |
3350 | ✗ | goto fail; | |
3351 | |||
3352 | 10271 | ret = ff_hevc_frame_rps(s, l); | |
3353 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (ret < 0) { |
3354 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n"); | |
3355 | ✗ | goto fail; | |
3356 | } | ||
3357 | |||
3358 |
3/4✓ Branch 0 taken 722 times.
✓ Branch 1 taken 9549 times.
✓ Branch 2 taken 722 times.
✗ Branch 3 not taken.
|
10271 | if (IS_IRAP(s)) |
3359 | 722 | s->cur_frame->f->flags |= AV_FRAME_FLAG_KEY; | |
3360 | else | ||
3361 | 9549 | s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY; | |
3362 | |||
3363 | 20542 | s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics && | |
3364 | ✗ | s->sei.common.film_grain_characteristics->present) || | |
3365 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | s->sei.common.aom_film_grain.enable) && |
3366 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
20542 | !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && |
3367 | ✗ | !s->avctx->hwaccel; | |
3368 | |||
3369 | 10271 | ret = set_side_data(s); | |
3370 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (ret < 0) |
3371 | ✗ | goto fail; | |
3372 | |||
3373 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (s->cur_frame->needs_fg && |
3374 | ✗ | (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present && | |
3375 | ✗ | !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id, | |
3376 | ✗ | s->cur_frame->f->format) || | |
3377 | ✗ | !av_film_grain_params_select(s->cur_frame->f))) { | |
3378 | ✗ | av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown, | |
3379 | "Unsupported film grain parameters. Ignoring film grain.\n"); | ||
3380 | ✗ | s->cur_frame->needs_fg = 0; | |
3381 | } | ||
3382 | |||
3383 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (s->cur_frame->needs_fg) { |
3384 | ✗ | s->cur_frame->frame_grain->format = s->cur_frame->f->format; | |
3385 | ✗ | s->cur_frame->frame_grain->width = s->cur_frame->f->width; | |
3386 | ✗ | s->cur_frame->frame_grain->height = s->cur_frame->f->height; | |
3387 | ✗ | if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0) | |
3388 | ✗ | goto fail; | |
3389 | |||
3390 | ✗ | ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f); | |
3391 | ✗ | if (ret < 0) | |
3392 | ✗ | goto fail; | |
3393 | } | ||
3394 | |||
3395 | 10271 | s->cur_frame->f->pict_type = 3 - s->sh.slice_type; | |
3396 | |||
3397 | 10271 | ret = ff_hevc_output_frames(s, s->layers_active_decode, s->layers_active_output, | |
3398 | 10271 | sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics, | |
3399 | 10271 | sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0); | |
3400 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (ret < 0) |
3401 | ✗ | goto fail; | |
3402 | |||
3403 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (s->avctx->hwaccel) { |
3404 | ✗ | ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0); | |
3405 | ✗ | if (ret < 0) | |
3406 | ✗ | goto fail; | |
3407 | } | ||
3408 | |||
3409 | // after starting the base-layer frame we know which layers will be decoded, | ||
3410 | // so we can now figure out which NALUs to wait for before we can call | ||
3411 | // ff_thread_finish_setup() | ||
3412 |
2/2✓ Branch 0 taken 9944 times.
✓ Branch 1 taken 327 times.
|
10271 | if (l == &s->layers[0]) |
3413 | 9944 | s->finish_setup_nal_idx = find_finish_setup_nal(s); | |
3414 | |||
3415 |
2/2✓ Branch 0 taken 9943 times.
✓ Branch 1 taken 328 times.
|
10271 | if (nal_idx >= s->finish_setup_nal_idx) |
3416 | 9943 | ff_thread_finish_setup(s->avctx); | |
3417 | |||
3418 | 10271 | return 0; | |
3419 | |||
3420 | ✗ | fail: | |
3421 | ✗ | if (l->cur_frame) | |
3422 | ✗ | ff_hevc_unref_frame(l->cur_frame, ~0); | |
3423 | ✗ | l->cur_frame = NULL; | |
3424 | ✗ | s->cur_frame = s->collocated_ref = NULL; | |
3425 | ✗ | s->slice_initialized = 0; | |
3426 | ✗ | return ret; | |
3427 | } | ||
3428 | |||
3429 | ✗ | static int verify_md5(HEVCContext *s, AVFrame *frame) | |
3430 | { | ||
3431 | ✗ | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); | |
3432 | char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)]; | ||
3433 | int pixel_shift; | ||
3434 | ✗ | int err = 0; | |
3435 | int i, j; | ||
3436 | |||
3437 | ✗ | if (!desc) | |
3438 | ✗ | return AVERROR(EINVAL); | |
3439 | |||
3440 | ✗ | pixel_shift = desc->comp[0].depth > 8; | |
3441 | |||
3442 | /* the checksums are LE, so we have to byteswap for >8bpp formats | ||
3443 | * on BE arches */ | ||
3444 | #if HAVE_BIGENDIAN | ||
3445 | if (pixel_shift && !s->checksum_buf) { | ||
3446 | av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size, | ||
3447 | FFMAX3(frame->linesize[0], frame->linesize[1], | ||
3448 | frame->linesize[2])); | ||
3449 | if (!s->checksum_buf) | ||
3450 | return AVERROR(ENOMEM); | ||
3451 | } | ||
3452 | #endif | ||
3453 | |||
3454 | ✗ | msg_buf[0] = '\0'; | |
3455 | ✗ | for (i = 0; frame->data[i]; i++) { | |
3456 | ✗ | int width = s->avctx->coded_width; | |
3457 | ✗ | int height = s->avctx->coded_height; | |
3458 | ✗ | int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width; | |
3459 | ✗ | int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height; | |
3460 | uint8_t md5[16]; | ||
3461 | |||
3462 | ✗ | av_md5_init(s->md5_ctx); | |
3463 | ✗ | for (j = 0; j < h; j++) { | |
3464 | ✗ | const uint8_t *src = frame->data[i] + j * frame->linesize[i]; | |
3465 | #if HAVE_BIGENDIAN | ||
3466 | if (pixel_shift) { | ||
3467 | s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf, | ||
3468 | (const uint16_t *) src, w); | ||
3469 | src = s->checksum_buf; | ||
3470 | } | ||
3471 | #endif | ||
3472 | ✗ | av_md5_update(s->md5_ctx, src, w << pixel_shift); | |
3473 | } | ||
3474 | ✗ | av_md5_final(s->md5_ctx, md5); | |
3475 | |||
3476 | #define MD5_PRI "%016" PRIx64 "%016" PRIx64 | ||
3477 | #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8) | ||
3478 | |||
3479 | ✗ | if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) { | |
3480 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
3481 | "plane %d - correct " MD5_PRI "; ", | ||
3482 | ✗ | i, MD5_PRI_ARG(md5)); | |
3483 | } else { | ||
3484 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
3485 | "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ", | ||
3486 | ✗ | i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i])); | |
3487 | ✗ | err = AVERROR_INVALIDDATA; | |
3488 | } | ||
3489 | } | ||
3490 | |||
3491 | ✗ | av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG, | |
3492 | "Verifying checksum for frame with POC %d: %s\n", | ||
3493 | s->poc, msg_buf); | ||
3494 | |||
3495 | ✗ | return err; | |
3496 | } | ||
3497 | |||
3498 | 10271 | static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l) | |
3499 | { | ||
3500 | 10271 | HEVCFrame *out = l->cur_frame; | |
3501 | const AVFilmGrainParams *fgp; | ||
3502 | av_unused int ret; | ||
3503 | |||
3504 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (out->needs_fg) { |
3505 | ✗ | av_assert0(out->frame_grain->buf[0]); | |
3506 | ✗ | fgp = av_film_grain_params_select(out->f); | |
3507 | ✗ | switch (fgp->type) { | |
3508 | ✗ | case AV_FILM_GRAIN_PARAMS_NONE: | |
3509 | ✗ | av_assert0(0); | |
3510 | return AVERROR_BUG; | ||
3511 | ✗ | case AV_FILM_GRAIN_PARAMS_H274: | |
3512 | ✗ | ret = ff_h274_apply_film_grain(out->frame_grain, out->f, | |
3513 | &s->h274db, fgp); | ||
3514 | ✗ | break; | |
3515 | ✗ | case AV_FILM_GRAIN_PARAMS_AV1: | |
3516 | ✗ | ret = ff_aom_apply_film_grain(out->frame_grain, out->f, fgp); | |
3517 | ✗ | break; | |
3518 | } | ||
3519 | av_assert1(ret >= 0); | ||
3520 | } | ||
3521 | |||
3522 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (s->avctx->hwaccel) { |
3523 | ✗ | ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame); | |
3524 | ✗ | if (ret < 0) { | |
3525 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3526 | "hardware accelerator failed to decode picture\n"); | ||
3527 | ✗ | return ret; | |
3528 | } | ||
3529 | } else { | ||
3530 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (s->avctx->err_recognition & AV_EF_CRCCHECK && |
3531 | ✗ | s->sei.picture_hash.is_md5) { | |
3532 | ✗ | ret = verify_md5(s, out->f); | |
3533 | ✗ | if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) | |
3534 | ✗ | return ret; | |
3535 | } | ||
3536 | } | ||
3537 | 10271 | s->sei.picture_hash.is_md5 = 0; | |
3538 | |||
3539 | 10271 | av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %zu/%d.\n", | |
3540 | 10271 | l - s->layers, s->poc); | |
3541 | |||
3542 | 10271 | return 0; | |
3543 | } | ||
3544 | |||
3545 | 28389 | static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb) | |
3546 | { | ||
3547 |
2/2✓ Branch 0 taken 27961 times.
✓ Branch 1 taken 428 times.
|
28389 | const int layer_idx = s->vps ? s->vps->layer_idx[s->nuh_layer_id] : 0; |
3548 | HEVCLayerContext *l; | ||
3549 | int ret; | ||
3550 | |||
3551 | // skip layers not requested to be decoded | ||
3552 | // layers_active_decode can only change while decoding a base-layer frame, | ||
3553 | // so we can check it for non-base layers | ||
3554 |
1/2✓ Branch 0 taken 28389 times.
✗ Branch 1 not taken.
|
28389 | if (layer_idx < 0 || |
3555 |
4/4✓ Branch 0 taken 332 times.
✓ Branch 1 taken 28057 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 327 times.
|
28389 | (s->nuh_layer_id > 0 && !(s->layers_active_decode & (1 << layer_idx)))) |
3556 | 5 | return 0; | |
3557 | |||
3558 | 28384 | ret = hls_slice_header(&s->sh, s, gb); | |
3559 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 28351 times.
|
28384 | if (ret < 0) { |
3560 | // hls_slice_header() does not cleanup on failure thus the state now is inconsistant so we cannot use it on depandant slices | ||
3561 | 33 | s->slice_initialized = 0; | |
3562 | 33 | return ret; | |
3563 | } | ||
3564 | |||
3565 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28351 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
28351 | if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) || |
3566 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28351 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
28351 | (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) || |
3567 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 28351 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
28351 | (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) || |
3568 |
4/4✓ Branch 0 taken 27206 times.
✓ Branch 1 taken 1145 times.
✓ Branch 2 taken 1066 times.
✓ Branch 3 taken 26140 times.
|
28351 | ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) && |
3569 |
2/2✓ Branch 0 taken 85 times.
✓ Branch 1 taken 2126 times.
|
2211 | s->no_rasl_output_flag)) { |
3570 | 85 | return 0; | |
3571 | } | ||
3572 | |||
3573 | // switching to a new layer, mark previous layer's frame (if any) as done | ||
3574 |
2/2✓ Branch 0 taken 646 times.
✓ Branch 1 taken 27620 times.
|
28266 | if (s->cur_layer != layer_idx && |
3575 |
2/2✓ Branch 0 taken 327 times.
✓ Branch 1 taken 319 times.
|
646 | s->layers[s->cur_layer].cur_frame && |
3576 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 327 times.
|
327 | s->avctx->active_thread_type == FF_THREAD_FRAME) |
3577 | ✗ | ff_progress_frame_report(&s->layers[s->cur_layer].cur_frame->tf, INT_MAX); | |
3578 | |||
3579 | 28266 | s->cur_layer = layer_idx; | |
3580 | 28266 | l = &s->layers[s->cur_layer]; | |
3581 | |||
3582 |
2/2✓ Branch 0 taken 10272 times.
✓ Branch 1 taken 17994 times.
|
28266 | if (s->sh.first_slice_in_pic_flag) { |
3583 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10271 times.
|
10272 | if (l->cur_frame) { |
3584 | 1 | av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n"); | |
3585 | 1 | return AVERROR_INVALIDDATA; | |
3586 | } | ||
3587 | |||
3588 | 10271 | ret = hevc_frame_start(s, l, nal_idx); | |
3589 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10271 times.
|
10271 | if (ret < 0) |
3590 | ✗ | return ret; | |
3591 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17994 times.
|
17994 | } else if (!l->cur_frame) { |
3592 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n"); | |
3593 | ✗ | return AVERROR_INVALIDDATA; | |
3594 | } | ||
3595 | |||
3596 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28265 times.
|
28265 | if (s->nal_unit_type != s->first_nal_type) { |
3597 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3598 | "Non-matching NAL types of the VCL NALUs: %d %d\n", | ||
3599 | ✗ | s->first_nal_type, s->nal_unit_type); | |
3600 | ✗ | return AVERROR_INVALIDDATA; | |
3601 | } | ||
3602 | |||
3603 | 28265 | ret = decode_slice_data(s, l, &s->pkt.nals[nal_idx], gb); | |
3604 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28264 times.
|
28265 | if (ret < 0) |
3605 | 1 | return ret; | |
3606 | |||
3607 | 28264 | return 0; | |
3608 | } | ||
3609 | |||
3610 | 39172 | static int decode_nal_unit(HEVCContext *s, unsigned nal_idx) | |
3611 | { | ||
3612 | 39172 | H2645NAL *nal = &s->pkt.nals[nal_idx]; | |
3613 | 39172 | GetBitContext gb = nal->gb; | |
3614 | int ret; | ||
3615 | |||
3616 | 39172 | s->nal_unit_type = nal->type; | |
3617 | 39172 | s->nuh_layer_id = nal->nuh_layer_id; | |
3618 | 39172 | s->temporal_id = nal->temporal_id; | |
3619 | |||
3620 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 39172 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
39172 | if (FF_HW_HAS_CB(s->avctx, decode_params) && |
3621 | ✗ | (s->nal_unit_type == HEVC_NAL_VPS || | |
3622 | ✗ | s->nal_unit_type == HEVC_NAL_SPS || | |
3623 | ✗ | s->nal_unit_type == HEVC_NAL_PPS || | |
3624 | ✗ | s->nal_unit_type == HEVC_NAL_SEI_PREFIX || | |
3625 | ✗ | s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) { | |
3626 | ✗ | ret = FF_HW_CALL(s->avctx, decode_params, | |
3627 | nal->type, nal->raw_data, nal->raw_size); | ||
3628 | ✗ | if (ret < 0) | |
3629 | ✗ | goto fail; | |
3630 | } | ||
3631 | |||
3632 |
6/7✓ Branch 0 taken 432 times.
✓ Branch 1 taken 441 times.
✓ Branch 2 taken 1401 times.
✓ Branch 3 taken 7827 times.
✓ Branch 4 taken 28389 times.
✓ Branch 5 taken 682 times.
✗ Branch 6 not taken.
|
39172 | switch (s->nal_unit_type) { |
3633 | 432 | case HEVC_NAL_VPS: | |
3634 | 432 | ret = ff_hevc_decode_nal_vps(&gb, s->avctx, &s->ps); | |
3635 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 432 times.
|
432 | if (ret < 0) |
3636 | ✗ | goto fail; | |
3637 | 432 | break; | |
3638 | 441 | case HEVC_NAL_SPS: | |
3639 | 441 | ret = ff_hevc_decode_nal_sps(&gb, s->avctx, &s->ps, | |
3640 | 441 | nal->nuh_layer_id, s->apply_defdispwin); | |
3641 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 441 times.
|
441 | if (ret < 0) |
3642 | ✗ | goto fail; | |
3643 | 441 | break; | |
3644 | 1401 | case HEVC_NAL_PPS: | |
3645 | 1401 | ret = ff_hevc_decode_nal_pps(&gb, s->avctx, &s->ps); | |
3646 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1399 times.
|
1401 | if (ret < 0) |
3647 | 2 | goto fail; | |
3648 | 1399 | break; | |
3649 | 7827 | case HEVC_NAL_SEI_PREFIX: | |
3650 | case HEVC_NAL_SEI_SUFFIX: | ||
3651 | 7827 | ret = ff_hevc_decode_nal_sei(&gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type); | |
3652 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7794 times.
|
7827 | if (ret < 0) |
3653 | 33 | goto fail; | |
3654 | 7794 | break; | |
3655 | 28389 | case HEVC_NAL_TRAIL_R: | |
3656 | case HEVC_NAL_TRAIL_N: | ||
3657 | case HEVC_NAL_TSA_N: | ||
3658 | case HEVC_NAL_TSA_R: | ||
3659 | case HEVC_NAL_STSA_N: | ||
3660 | case HEVC_NAL_STSA_R: | ||
3661 | case HEVC_NAL_BLA_W_LP: | ||
3662 | case HEVC_NAL_BLA_W_RADL: | ||
3663 | case HEVC_NAL_BLA_N_LP: | ||
3664 | case HEVC_NAL_IDR_W_RADL: | ||
3665 | case HEVC_NAL_IDR_N_LP: | ||
3666 | case HEVC_NAL_CRA_NUT: | ||
3667 | case HEVC_NAL_RADL_N: | ||
3668 | case HEVC_NAL_RADL_R: | ||
3669 | case HEVC_NAL_RASL_N: | ||
3670 | case HEVC_NAL_RASL_R: | ||
3671 | 28389 | ret = decode_slice(s, nal_idx, &gb); | |
3672 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 28354 times.
|
28389 | if (ret < 0) |
3673 | 35 | goto fail; | |
3674 | 28354 | break; | |
3675 | 682 | case HEVC_NAL_EOS_NUT: | |
3676 | case HEVC_NAL_EOB_NUT: | ||
3677 | case HEVC_NAL_AUD: | ||
3678 | case HEVC_NAL_FD_NUT: | ||
3679 | case HEVC_NAL_UNSPEC62: | ||
3680 | 682 | break; | |
3681 | ✗ | default: | |
3682 | ✗ | av_log(s->avctx, AV_LOG_INFO, | |
3683 | ✗ | "Skipping NAL unit %d\n", s->nal_unit_type); | |
3684 | } | ||
3685 | |||
3686 | 39102 | return 0; | |
3687 | 70 | fail: | |
3688 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | if (ret == AVERROR_INVALIDDATA && |
3689 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | !(s->avctx->err_recognition & AV_EF_EXPLODE)) { |
3690 | 70 | av_log(s->avctx, AV_LOG_WARNING, | |
3691 | 70 | "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type); | |
3692 | 70 | return 0; | |
3693 | } | ||
3694 | ✗ | return ret; | |
3695 | } | ||
3696 | |||
3697 | 399 | static void decode_reset_recovery_point(HEVCContext *s) | |
3698 | { | ||
3699 | 399 | s->recovery_poc = HEVC_RECOVERY_UNSPECIFIED; | |
3700 | 399 | s->sei.recovery_point.has_recovery_poc = 0; | |
3701 | 399 | } | |
3702 | |||
3703 | 10021 | static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) | |
3704 | { | ||
3705 | 10021 | int i, ret = 0; | |
3706 | 10021 | int eos_at_start = 1; | |
3707 |
2/2✓ Branch 0 taken 170 times.
✓ Branch 1 taken 9851 times.
|
10021 | int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING; |
3708 | |||
3709 | 10021 | s->cur_frame = s->collocated_ref = NULL; | |
3710 | 10021 | s->last_eos = s->eos; | |
3711 | 10021 | s->eos = 0; | |
3712 | 10021 | s->slice_initialized = 0; | |
3713 |
2/2✓ Branch 0 taken 395 times.
✓ Branch 1 taken 9626 times.
|
10021 | if (s->last_eos) |
3714 | 395 | decode_reset_recovery_point(s); | |
3715 | |||
3716 |
2/2✓ Branch 0 taken 20042 times.
✓ Branch 1 taken 10021 times.
|
30063 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
3717 | 20042 | HEVCLayerContext *l = &s->layers[i]; | |
3718 | 20042 | l->cur_frame = NULL; | |
3719 | } | ||
3720 | |||
3721 | /* split the input packet into NAL units, so we know the upper bound on the | ||
3722 | * number of slices in the frame */ | ||
3723 | 10021 | ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx, | |
3724 | 10021 | s->nal_length_size, s->avctx->codec_id, flags); | |
3725 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10021 times.
|
10021 | if (ret < 0) { |
3726 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
3727 | "Error splitting the input into NAL units.\n"); | ||
3728 | ✗ | return ret; | |
3729 | } | ||
3730 | |||
3731 |
2/2✓ Branch 0 taken 39172 times.
✓ Branch 1 taken 10021 times.
|
49193 | for (i = 0; i < s->pkt.nb_nals; i++) { |
3732 |
2/2✓ Branch 0 taken 39171 times.
✓ Branch 1 taken 1 times.
|
39172 | if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT || |
3733 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 39168 times.
|
39171 | s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) { |
3734 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (eos_at_start) { |
3735 | 4 | s->last_eos = 1; | |
3736 | 4 | decode_reset_recovery_point(s); | |
3737 | } else { | ||
3738 | ✗ | s->eos = 1; | |
3739 | } | ||
3740 | } else { | ||
3741 | 39168 | eos_at_start = 0; | |
3742 | } | ||
3743 | } | ||
3744 | |||
3745 | /* | ||
3746 | * Check for RPU delimiter. | ||
3747 | * | ||
3748 | * Dolby Vision RPUs masquerade as unregistered NALs of type 62. | ||
3749 | * | ||
3750 | * We have to do this check here an create the rpu buffer, since RPUs are appended | ||
3751 | * to the end of an AU; they are the last non-EOB/EOS NAL in the AU. | ||
3752 | */ | ||
3753 |
4/4✓ Branch 0 taken 8101 times.
✓ Branch 1 taken 1920 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8099 times.
|
10021 | if (s->pkt.nb_nals > 1 && s->pkt.nals[s->pkt.nb_nals - 1].type == HEVC_NAL_UNSPEC62 && |
3754 |
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 |
3755 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | && !s->pkt.nals[s->pkt.nb_nals - 1].temporal_id) { |
3756 | 2 | H2645NAL *nal = &s->pkt.nals[s->pkt.nb_nals - 1]; | |
3757 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (s->rpu_buf) { |
3758 | ✗ | av_buffer_unref(&s->rpu_buf); | |
3759 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n"); | |
3760 | } | ||
3761 | |||
3762 | 2 | s->rpu_buf = av_buffer_alloc(nal->raw_size - 2); | |
3763 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!s->rpu_buf) |
3764 | ✗ | return AVERROR(ENOMEM); | |
3765 | 2 | memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2); | |
3766 | |||
3767 | 2 | ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2, | |
3768 | 2 | s->avctx->err_recognition); | |
3769 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ret < 0) { |
3770 | ✗ | av_buffer_unref(&s->rpu_buf); | |
3771 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n"); | |
3772 | /* ignore */ | ||
3773 | } | ||
3774 | } | ||
3775 | |||
3776 | /* decode the NAL units */ | ||
3777 |
2/2✓ Branch 0 taken 39172 times.
✓ Branch 1 taken 10021 times.
|
49193 | for (i = 0; i < s->pkt.nb_nals; i++) { |
3778 | 39172 | H2645NAL *nal = &s->pkt.nals[i]; | |
3779 | |||
3780 |
1/2✓ Branch 0 taken 39172 times.
✗ Branch 1 not taken.
|
39172 | if (s->avctx->skip_frame >= AVDISCARD_ALL || |
3781 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 39172 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
39172 | (s->avctx->skip_frame >= AVDISCARD_NONREF && ff_hevc_nal_is_nonref(nal->type))) |
3782 | ✗ | continue; | |
3783 | |||
3784 | 39172 | ret = decode_nal_unit(s, i); | |
3785 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39172 times.
|
39172 | if (ret < 0) { |
3786 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
3787 | "Error parsing NAL unit #%d.\n", i); | ||
3788 | ✗ | goto fail; | |
3789 | } | ||
3790 | } | ||
3791 | |||
3792 | 10021 | fail: | |
3793 |
2/2✓ Branch 0 taken 20042 times.
✓ Branch 1 taken 10021 times.
|
30063 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
3794 | 20042 | HEVCLayerContext *l = &s->layers[i]; | |
3795 | |||
3796 |
2/2✓ Branch 0 taken 9771 times.
✓ Branch 1 taken 10271 times.
|
20042 | if (!l->cur_frame) |
3797 | 9771 | continue; | |
3798 | |||
3799 |
1/2✓ Branch 0 taken 10271 times.
✗ Branch 1 not taken.
|
10271 | if (ret >= 0) |
3800 | 10271 | ret = hevc_frame_end(s, l); | |
3801 | |||
3802 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 10238 times.
|
10271 | if (s->avctx->active_thread_type == FF_THREAD_FRAME) |
3803 | 33 | ff_progress_frame_report(&l->cur_frame->tf, INT_MAX); | |
3804 | } | ||
3805 | |||
3806 | 10021 | return ret; | |
3807 | } | ||
3808 | |||
3809 | 255 | static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first) | |
3810 | { | ||
3811 | int ret, i; | ||
3812 | |||
3813 | 255 | ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff, | |
3814 | 255 | &s->nal_length_size, s->avctx->err_recognition, | |
3815 | 255 | s->apply_defdispwin, s->avctx); | |
3816 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 255 times.
|
255 | if (ret < 0) |
3817 | ✗ | return ret; | |
3818 | |||
3819 | /* export stream parameters from the first SPS */ | ||
3820 |
2/2✓ Branch 0 taken 285 times.
✓ Branch 1 taken 2 times.
|
287 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { |
3821 |
4/4✓ Branch 0 taken 269 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 253 times.
✓ Branch 3 taken 16 times.
|
285 | if (first && s->ps.sps_list[i]) { |
3822 | 253 | const HEVCSPS *sps = s->ps.sps_list[i]; | |
3823 | 253 | export_stream_params(s, sps); | |
3824 | |||
3825 | 253 | ret = export_multilayer(s, sps->vps); | |
3826 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 253 times.
|
253 | if (ret < 0) |
3827 | ✗ | return ret; | |
3828 | |||
3829 | 253 | break; | |
3830 | } | ||
3831 | } | ||
3832 | |||
3833 | /* export stream parameters from SEI */ | ||
3834 | 255 | ret = export_stream_params_from_sei(s); | |
3835 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 255 times.
|
255 | if (ret < 0) |
3836 | ✗ | return ret; | |
3837 | |||
3838 | 255 | return 0; | |
3839 | } | ||
3840 | |||
3841 | 21218 | static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) | |
3842 | { | ||
3843 | 21218 | HEVCContext *s = avctx->priv_data; | |
3844 | 21218 | AVCodecInternal *avci = avctx->internal; | |
3845 | 21218 | AVPacket *avpkt = avci->in_pkt; | |
3846 | |||
3847 | int ret; | ||
3848 | uint8_t *sd; | ||
3849 | size_t sd_size; | ||
3850 | |||
3851 | 21218 | s->pkt_dts = AV_NOPTS_VALUE; | |
3852 | |||
3853 |
2/2✓ Branch 1 taken 948 times.
✓ Branch 2 taken 20270 times.
|
21218 | if (av_container_fifo_can_read(s->output_fifo)) |
3854 | 948 | goto do_output; | |
3855 | |||
3856 | 20270 | av_packet_unref(avpkt); | |
3857 | 20270 | ret = ff_decode_get_packet(avctx, avpkt); | |
3858 |
2/2✓ Branch 0 taken 304 times.
✓ Branch 1 taken 19966 times.
|
20270 | if (ret == AVERROR_EOF) { |
3859 | 304 | ret = ff_hevc_output_frames(s, s->layers_active_decode, | |
3860 | s->layers_active_output, 0, 0, 0); | ||
3861 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
|
304 | if (ret < 0) |
3862 | ✗ | return ret; | |
3863 | 304 | goto do_output; | |
3864 |
2/2✓ Branch 0 taken 9945 times.
✓ Branch 1 taken 10021 times.
|
19966 | } else if (ret < 0) |
3865 | 9945 | return ret; | |
3866 | |||
3867 | 10021 | s->pkt_dts = avpkt->dts; | |
3868 | |||
3869 | 10021 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size); | |
3870 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10020 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
10021 | if (sd && sd_size > 0) { |
3871 | 1 | ret = hevc_decode_extradata(s, sd, sd_size, 0); | |
3872 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
3873 | ✗ | return ret; | |
3874 | } | ||
3875 | |||
3876 | 10021 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size); | |
3877 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10021 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10021 | if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) { |
3878 | ✗ | int old = s->dovi_ctx.cfg.dv_profile; | |
3879 | ✗ | s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd; | |
3880 | ✗ | if (old) | |
3881 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
3882 | "New DOVI configuration record from input packet (profile %d -> %u).\n", | ||
3883 | ✗ | old, s->dovi_ctx.cfg.dv_profile); | |
3884 | } | ||
3885 | |||
3886 | 10021 | ret = decode_nal_units(s, avpkt->data, avpkt->size); | |
3887 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10021 times.
|
10021 | if (ret < 0) |
3888 | ✗ | return ret; | |
3889 | |||
3890 | 10021 | do_output: | |
3891 |
2/2✓ Branch 1 taken 10056 times.
✓ Branch 2 taken 1217 times.
|
11273 | if (av_container_fifo_read(s->output_fifo, frame, 0) >= 0) { |
3892 |
1/2✓ Branch 0 taken 10056 times.
✗ Branch 1 not taken.
|
10056 | if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN)) |
3893 | 10056 | av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS); | |
3894 | |||
3895 | 10056 | return 0; | |
3896 | } | ||
3897 | |||
3898 |
2/2✓ Branch 0 taken 187 times.
✓ Branch 1 taken 1030 times.
|
1217 | return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN); |
3899 | } | ||
3900 | |||
3901 | 67 | static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src) | |
3902 | { | ||
3903 | int ret; | ||
3904 | |||
3905 | 67 | ff_progress_frame_ref(&dst->tf, &src->tf); | |
3906 | |||
3907 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (src->needs_fg) { |
3908 | ✗ | ret = av_frame_ref(dst->frame_grain, src->frame_grain); | |
3909 | ✗ | if (ret < 0) { | |
3910 | ✗ | ff_hevc_unref_frame(dst, ~0); | |
3911 | ✗ | return ret; | |
3912 | } | ||
3913 | ✗ | dst->needs_fg = 1; | |
3914 | } | ||
3915 | |||
3916 | 67 | dst->pps = av_refstruct_ref_c(src->pps); | |
3917 | 67 | dst->tab_mvf = av_refstruct_ref(src->tab_mvf); | |
3918 | 67 | dst->rpl_tab = av_refstruct_ref(src->rpl_tab); | |
3919 | 67 | dst->rpl = av_refstruct_ref(src->rpl); | |
3920 | 67 | dst->nb_rpl_elems = src->nb_rpl_elems; | |
3921 | |||
3922 | 67 | dst->poc = src->poc; | |
3923 | 67 | dst->ctb_count = src->ctb_count; | |
3924 | 67 | dst->flags = src->flags; | |
3925 | |||
3926 | 67 | dst->base_layer_frame = src->base_layer_frame; | |
3927 | |||
3928 | 67 | av_refstruct_replace(&dst->hwaccel_picture_private, | |
3929 | 67 | src->hwaccel_picture_private); | |
3930 | |||
3931 | 67 | return 0; | |
3932 | } | ||
3933 | |||
3934 | 462 | static av_cold int hevc_decode_free(AVCodecContext *avctx) | |
3935 | { | ||
3936 | 462 | HEVCContext *s = avctx->priv_data; | |
3937 | |||
3938 |
2/2✓ Branch 0 taken 924 times.
✓ Branch 1 taken 462 times.
|
1386 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
3939 | 924 | pic_arrays_free(&s->layers[i]); | |
3940 | 924 | av_refstruct_unref(&s->layers[i].sps); | |
3941 | } | ||
3942 | |||
3943 | 462 | av_refstruct_unref(&s->vps); | |
3944 | 462 | av_refstruct_unref(&s->pps); | |
3945 | |||
3946 | 462 | ff_dovi_ctx_unref(&s->dovi_ctx); | |
3947 | 462 | av_buffer_unref(&s->rpu_buf); | |
3948 | |||
3949 | 462 | av_freep(&s->md5_ctx); | |
3950 | |||
3951 | 462 | av_container_fifo_free(&s->output_fifo); | |
3952 | |||
3953 |
2/2✓ Branch 0 taken 924 times.
✓ Branch 1 taken 462 times.
|
1386 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
3954 | 924 | HEVCLayerContext *l = &s->layers[layer]; | |
3955 |
2/2✓ Branch 0 taken 29568 times.
✓ Branch 1 taken 924 times.
|
30492 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
3956 | 29568 | ff_hevc_unref_frame(&l->DPB[i], ~0); | |
3957 | 29568 | av_frame_free(&l->DPB[i].frame_grain); | |
3958 | } | ||
3959 | } | ||
3960 | |||
3961 | 462 | ff_hevc_ps_uninit(&s->ps); | |
3962 | |||
3963 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 462 times.
|
462 | for (int i = 0; i < s->nb_wpp_progress; i++) |
3964 | ✗ | ff_thread_progress_destroy(&s->wpp_progress[i]); | |
3965 | 462 | av_freep(&s->wpp_progress); | |
3966 | |||
3967 | 462 | av_freep(&s->sh.entry_point_offset); | |
3968 | 462 | av_freep(&s->sh.offset); | |
3969 | 462 | av_freep(&s->sh.size); | |
3970 | |||
3971 | 462 | av_freep(&s->local_ctx); | |
3972 | |||
3973 | 462 | ff_h2645_packet_uninit(&s->pkt); | |
3974 | |||
3975 | 462 | ff_hevc_reset_sei(&s->sei); | |
3976 | |||
3977 | 462 | return 0; | |
3978 | } | ||
3979 | |||
3980 | 462 | static av_cold int hevc_init_context(AVCodecContext *avctx) | |
3981 | { | ||
3982 | 462 | HEVCContext *s = avctx->priv_data; | |
3983 | |||
3984 | 462 | s->avctx = avctx; | |
3985 | |||
3986 | 462 | s->local_ctx = av_mallocz(sizeof(*s->local_ctx)); | |
3987 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 462 times.
|
462 | if (!s->local_ctx) |
3988 | ✗ | return AVERROR(ENOMEM); | |
3989 | 462 | s->nb_local_ctx = 1; | |
3990 | |||
3991 | 462 | s->local_ctx[0].parent = s; | |
3992 | 462 | s->local_ctx[0].logctx = avctx; | |
3993 | 462 | s->local_ctx[0].common_cabac_state = &s->cabac; | |
3994 | |||
3995 | 462 | s->output_fifo = av_container_fifo_alloc_avframe(0); | |
3996 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 462 times.
|
462 | if (!s->output_fifo) |
3997 | ✗ | return AVERROR(ENOMEM); | |
3998 | |||
3999 |
2/2✓ Branch 0 taken 924 times.
✓ Branch 1 taken 462 times.
|
1386 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
4000 | 924 | HEVCLayerContext *l = &s->layers[layer]; | |
4001 |
2/2✓ Branch 0 taken 29568 times.
✓ Branch 1 taken 924 times.
|
30492 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
4002 | 29568 | l->DPB[i].frame_grain = av_frame_alloc(); | |
4003 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29568 times.
|
29568 | if (!l->DPB[i].frame_grain) |
4004 | ✗ | return AVERROR(ENOMEM); | |
4005 | } | ||
4006 | } | ||
4007 | |||
4008 | 462 | s->md5_ctx = av_md5_alloc(); | |
4009 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 462 times.
|
462 | if (!s->md5_ctx) |
4010 | ✗ | return AVERROR(ENOMEM); | |
4011 | |||
4012 | 462 | ff_bswapdsp_init(&s->bdsp); | |
4013 | |||
4014 | 462 | s->dovi_ctx.logctx = avctx; | |
4015 | 462 | s->eos = 0; | |
4016 | |||
4017 | 462 | ff_hevc_reset_sei(&s->sei); | |
4018 | |||
4019 | 462 | return 0; | |
4020 | } | ||
4021 | |||
4022 | #if HAVE_THREADS | ||
4023 | 32 | static int hevc_update_thread_context(AVCodecContext *dst, | |
4024 | const AVCodecContext *src) | ||
4025 | { | ||
4026 | 32 | HEVCContext *s = dst->priv_data; | |
4027 | 32 | HEVCContext *s0 = src->priv_data; | |
4028 | int ret; | ||
4029 | |||
4030 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
|
96 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
4031 | 64 | HEVCLayerContext *l = &s->layers[layer]; | |
4032 | 64 | const HEVCLayerContext *l0 = &s0->layers[layer]; | |
4033 |
2/2✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 64 times.
|
2112 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
4034 | 2048 | ff_hevc_unref_frame(&l->DPB[i], ~0); | |
4035 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1981 times.
|
2048 | if (l0->DPB[i].f) { |
4036 | 67 | ret = hevc_ref_frame(&l->DPB[i], &l0->DPB[i]); | |
4037 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (ret < 0) |
4038 | ✗ | return ret; | |
4039 | } | ||
4040 | } | ||
4041 | |||
4042 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
|
64 | if (l->sps != l0->sps) { |
4043 | 1 | ret = set_sps(s, l, l0->sps); | |
4044 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
4045 | ✗ | return ret; | |
4046 | } | ||
4047 | } | ||
4048 | |||
4049 |
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++) |
4050 | 512 | av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); | |
4051 | |||
4052 |
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++) |
4053 | 512 | av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); | |
4054 | |||
4055 |
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++) |
4056 | 2048 | av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); | |
4057 | |||
4058 | // PPS do not persist between frames | ||
4059 | 32 | av_refstruct_unref(&s->pps); | |
4060 | |||
4061 | 32 | s->poc_tid0 = s0->poc_tid0; | |
4062 | 32 | s->eos = s0->eos; | |
4063 | 32 | s->no_rasl_output_flag = s0->no_rasl_output_flag; | |
4064 | |||
4065 | 32 | s->is_nalff = s0->is_nalff; | |
4066 | 32 | s->nal_length_size = s0->nal_length_size; | |
4067 | 32 | s->layers_active_decode = s0->layers_active_decode; | |
4068 | 32 | s->layers_active_output = s0->layers_active_output; | |
4069 | |||
4070 | 32 | s->film_grain_warning_shown = s0->film_grain_warning_shown; | |
4071 | |||
4072 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | if (s->nb_view_ids != s0->nb_view_ids || |
4073 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | memcmp(s->view_ids, s0->view_ids, sizeof(*s->view_ids) * s->nb_view_ids)) { |
4074 | ✗ | av_freep(&s->view_ids); | |
4075 | ✗ | s->nb_view_ids = 0; | |
4076 | |||
4077 | ✗ | if (s0->nb_view_ids) { | |
4078 | ✗ | s->view_ids = av_memdup(s0->view_ids, s0->nb_view_ids * sizeof(*s0->view_ids)); | |
4079 | ✗ | if (!s->view_ids) | |
4080 | ✗ | return AVERROR(ENOMEM); | |
4081 | ✗ | s->nb_view_ids = s0->nb_view_ids; | |
4082 | } | ||
4083 | } | ||
4084 | |||
4085 | 32 | ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common); | |
4086 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
4087 | ✗ | return ret; | |
4088 | |||
4089 | 32 | ret = av_buffer_replace(&s->sei.common.dynamic_hdr_plus.info, | |
4090 | 32 | s0->sei.common.dynamic_hdr_plus.info); | |
4091 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
4092 | ✗ | return ret; | |
4093 | |||
4094 | 32 | ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf); | |
4095 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
4096 | ✗ | return ret; | |
4097 | |||
4098 | 32 | ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx); | |
4099 | |||
4100 | 32 | ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info, | |
4101 | 32 | s0->sei.common.dynamic_hdr_vivid.info); | |
4102 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
4103 | ✗ | return ret; | |
4104 | |||
4105 | 32 | s->sei.common.frame_packing = s0->sei.common.frame_packing; | |
4106 | 32 | s->sei.common.display_orientation = s0->sei.common.display_orientation; | |
4107 | 32 | s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer; | |
4108 | 32 | s->sei.tdrdi = s0->sei.tdrdi; | |
4109 | 32 | s->sei.recovery_point = s0->sei.recovery_point; | |
4110 | 32 | s->recovery_poc = s0->recovery_poc; | |
4111 | |||
4112 | 32 | return 0; | |
4113 | } | ||
4114 | #endif | ||
4115 | |||
4116 | 462 | static av_cold int hevc_decode_init(AVCodecContext *avctx) | |
4117 | { | ||
4118 | 462 | HEVCContext *s = avctx->priv_data; | |
4119 | int ret; | ||
4120 | |||
4121 | 462 | ret = hevc_init_context(avctx); | |
4122 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 462 times.
|
462 | if (ret < 0) |
4123 | ✗ | return ret; | |
4124 | |||
4125 | 462 | s->sei.picture_timing.picture_struct = 0; | |
4126 | 462 | s->eos = 1; | |
4127 | |||
4128 | 462 | atomic_init(&s->wpp_err, 0); | |
4129 | |||
4130 |
2/2✓ Branch 0 taken 461 times.
✓ Branch 1 taken 1 times.
|
462 | if (!avctx->internal->is_copy) { |
4131 | const AVPacketSideData *sd; | ||
4132 | |||
4133 |
3/4✓ Branch 0 taken 254 times.
✓ Branch 1 taken 207 times.
✓ Branch 2 taken 254 times.
✗ Branch 3 not taken.
|
461 | if (avctx->extradata_size > 0 && avctx->extradata) { |
4134 | 254 | ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1); | |
4135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 254 times.
|
254 | if (ret < 0) { |
4136 | ✗ | return ret; | |
4137 | } | ||
4138 | |||
4139 | 254 | ret = ff_h2645_sei_to_context(avctx, &s->sei.common); | |
4140 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 254 times.
|
254 | if (ret < 0) |
4141 | ✗ | return ret; | |
4142 | } | ||
4143 | |||
4144 | 461 | sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF); | |
4145 |
3/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 450 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
461 | if (sd && sd->size >= sizeof(s->dovi_ctx.cfg)) |
4146 | 11 | s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data; | |
4147 | } | ||
4148 | |||
4149 | 462 | return 0; | |
4150 | } | ||
4151 | |||
4152 | 8 | static void hevc_decode_flush(AVCodecContext *avctx) | |
4153 | { | ||
4154 | 8 | HEVCContext *s = avctx->priv_data; | |
4155 | 8 | ff_hevc_flush_dpb(s); | |
4156 | 8 | ff_hevc_reset_sei(&s->sei); | |
4157 | 8 | ff_dovi_ctx_flush(&s->dovi_ctx); | |
4158 | 8 | av_buffer_unref(&s->rpu_buf); | |
4159 | 8 | s->eos = 1; | |
4160 | |||
4161 |
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)) |
4162 | ✗ | FF_HW_SIMPLE_CALL(avctx, flush); | |
4163 | 8 | } | |
4164 | |||
4165 | #define OFFSET(x) offsetof(HEVCContext, x) | ||
4166 | #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) | ||
4167 | |||
4168 | static const AVOption options[] = { | ||
4169 | { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin), | ||
4170 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
4171 | { "strict-displaywin", "stricly apply default display window size", OFFSET(apply_defdispwin), | ||
4172 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
4173 | { "view_ids", "Array of view IDs that should be decoded and output; a single -1 to decode all views", | ||
4174 | .offset = OFFSET(view_ids), .type = AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, | ||
4175 | .min = -1, .max = INT_MAX, .flags = PAR }, | ||
4176 | { "view_ids_available", "Array of available view IDs is exported here", | ||
4177 | .offset = OFFSET(view_ids_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY, | ||
4178 | .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY }, | ||
4179 | { "view_pos_available", "Array of view positions for view_ids_available is exported here, as AVStereo3DView", | ||
4180 | .offset = OFFSET(view_pos_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY, | ||
4181 | .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY, .unit = "view_pos" }, | ||
4182 | { "unspecified", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_UNSPEC }, .unit = "view_pos" }, | ||
4183 | { "left", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_LEFT }, .unit = "view_pos" }, | ||
4184 | { "right", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_RIGHT }, .unit = "view_pos" }, | ||
4185 | |||
4186 | { NULL }, | ||
4187 | }; | ||
4188 | |||
4189 | static const AVClass hevc_decoder_class = { | ||
4190 | .class_name = "HEVC decoder", | ||
4191 | .item_name = av_default_item_name, | ||
4192 | .option = options, | ||
4193 | .version = LIBAVUTIL_VERSION_INT, | ||
4194 | }; | ||
4195 | |||
4196 | const FFCodec ff_hevc_decoder = { | ||
4197 | .p.name = "hevc", | ||
4198 | CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"), | ||
4199 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
4200 | .p.id = AV_CODEC_ID_HEVC, | ||
4201 | .priv_data_size = sizeof(HEVCContext), | ||
4202 | .p.priv_class = &hevc_decoder_class, | ||
4203 | .init = hevc_decode_init, | ||
4204 | .close = hevc_decode_free, | ||
4205 | FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame), | ||
4206 | .flush = hevc_decode_flush, | ||
4207 | UPDATE_THREAD_CONTEXT(hevc_update_thread_context), | ||
4208 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | | ||
4209 | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, | ||
4210 | .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | | ||
4211 | FF_CODEC_CAP_USES_PROGRESSFRAMES | | ||
4212 | FF_CODEC_CAP_INIT_CLEANUP, | ||
4213 | .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles), | ||
4214 | .hw_configs = (const AVCodecHWConfigInternal *const []) { | ||
4215 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
4216 | HWACCEL_DXVA2(hevc), | ||
4217 | #endif | ||
4218 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
4219 | HWACCEL_D3D11VA(hevc), | ||
4220 | #endif | ||
4221 | #if CONFIG_HEVC_D3D11VA2_HWACCEL | ||
4222 | HWACCEL_D3D11VA2(hevc), | ||
4223 | #endif | ||
4224 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
4225 | HWACCEL_D3D12VA(hevc), | ||
4226 | #endif | ||
4227 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
4228 | HWACCEL_NVDEC(hevc), | ||
4229 | #endif | ||
4230 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
4231 | HWACCEL_VAAPI(hevc), | ||
4232 | #endif | ||
4233 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
4234 | HWACCEL_VDPAU(hevc), | ||
4235 | #endif | ||
4236 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
4237 | HWACCEL_VIDEOTOOLBOX(hevc), | ||
4238 | #endif | ||
4239 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
4240 | HWACCEL_VULKAN(hevc), | ||
4241 | #endif | ||
4242 | NULL | ||
4243 | }, | ||
4244 | }; | ||
4245 |