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