Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * HEVC video Decoder | ||
3 | * | ||
4 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
5 | * Copyright (C) 2012 - 2013 Mickael Raulet | ||
6 | * Copyright (C) 2012 - 2013 Gildas Cocherel | ||
7 | * Copyright (C) 2012 - 2013 Wassim Hamidouche | ||
8 | * | ||
9 | * This file is part of FFmpeg. | ||
10 | * | ||
11 | * FFmpeg is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU Lesser General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2.1 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * FFmpeg is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * Lesser General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Lesser General Public | ||
22 | * License along with FFmpeg; if not, write to the Free Software | ||
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
24 | */ | ||
25 | |||
26 | #include "config_components.h" | ||
27 | |||
28 | #include "libavutil/attributes.h" | ||
29 | #include "libavutil/avstring.h" | ||
30 | #include "libavutil/common.h" | ||
31 | #include "libavutil/container_fifo.h" | ||
32 | #include "libavutil/film_grain_params.h" | ||
33 | #include "libavutil/internal.h" | ||
34 | #include "libavutil/md5.h" | ||
35 | #include "libavutil/mem.h" | ||
36 | #include "libavutil/opt.h" | ||
37 | #include "libavutil/pixdesc.h" | ||
38 | #include "libavutil/stereo3d.h" | ||
39 | #include "libavutil/timecode.h" | ||
40 | |||
41 | #include "aom_film_grain.h" | ||
42 | #include "bswapdsp.h" | ||
43 | #include "cabac_functions.h" | ||
44 | #include "codec_internal.h" | ||
45 | #include "decode.h" | ||
46 | #include "golomb.h" | ||
47 | #include "hevc.h" | ||
48 | #include "parse.h" | ||
49 | #include "hevcdec.h" | ||
50 | #include "hwaccel_internal.h" | ||
51 | #include "hwconfig.h" | ||
52 | #include "internal.h" | ||
53 | #include "profiles.h" | ||
54 | #include "progressframe.h" | ||
55 | #include "libavutil/refstruct.h" | ||
56 | #include "thread.h" | ||
57 | #include "threadprogress.h" | ||
58 | |||
59 | static const uint8_t hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, [12] = 4, [16] = 5, [24] = 6, [32] = 7, [48] = 8, [64] = 9 }; | ||
60 | |||
61 | /** | ||
62 | * NOTE: Each function hls_foo correspond to the function foo in the | ||
63 | * specification (HLS stands for High Level Syntax). | ||
64 | */ | ||
65 | |||
66 | /** | ||
67 | * Section 5.7 | ||
68 | */ | ||
69 | |||
70 | /* free everything allocated by pic_arrays_init() */ | ||
71 | 1334 | static void pic_arrays_free(HEVCLayerContext *l) | |
72 | { | ||
73 | 1334 | av_freep(&l->sao); | |
74 | 1334 | av_freep(&l->deblock); | |
75 | |||
76 | 1334 | av_freep(&l->skip_flag); | |
77 | 1334 | av_freep(&l->tab_ct_depth); | |
78 | |||
79 | 1334 | av_freep(&l->tab_ipm); | |
80 | 1334 | av_freep(&l->cbf_luma); | |
81 | 1334 | av_freep(&l->is_pcm); | |
82 | |||
83 | 1334 | av_freep(&l->qp_y_tab); | |
84 | 1334 | av_freep(&l->tab_slice_address); | |
85 | 1334 | av_freep(&l->filter_slice_edges); | |
86 | |||
87 | 1334 | av_freep(&l->horizontal_bs); | |
88 | 1334 | av_freep(&l->vertical_bs); | |
89 | |||
90 |
2/2✓ Branch 0 taken 4002 times.
✓ Branch 1 taken 1334 times.
|
5336 | for (int i = 0; i < 3; i++) { |
91 | 4002 | av_freep(&l->sao_pixel_buffer_h[i]); | |
92 | 4002 | av_freep(&l->sao_pixel_buffer_v[i]); | |
93 | } | ||
94 | |||
95 | 1334 | av_refstruct_pool_uninit(&l->tab_mvf_pool); | |
96 | 1334 | av_refstruct_pool_uninit(&l->rpl_tab_pool); | |
97 | 1334 | } | |
98 | |||
99 | /* allocate arrays that depend on frame dimensions */ | ||
100 | 414 | static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps) | |
101 | { | ||
102 | 414 | int log2_min_cb_size = sps->log2_min_cb_size; | |
103 | 414 | int width = sps->width; | |
104 | 414 | int height = sps->height; | |
105 | 414 | int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) * | |
106 | 414 | ((height >> log2_min_cb_size) + 1); | |
107 | 414 | int ctb_count = sps->ctb_width * sps->ctb_height; | |
108 | 414 | int min_pu_size = sps->min_pu_width * sps->min_pu_height; | |
109 | |||
110 | 414 | l->bs_width = (width >> 2) + 1; | |
111 | 414 | l->bs_height = (height >> 2) + 1; | |
112 | |||
113 | 414 | l->sao = av_calloc(ctb_count, sizeof(*l->sao)); | |
114 | 414 | l->deblock = av_calloc(ctb_count, sizeof(*l->deblock)); | |
115 |
2/4✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
|
414 | if (!l->sao || !l->deblock) |
116 | ✗ | goto fail; | |
117 | |||
118 | 414 | l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
119 | 414 | l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
120 |
2/4✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
|
414 | if (!l->skip_flag || !l->tab_ct_depth) |
121 | ✗ | goto fail; | |
122 | |||
123 | 414 | l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height); | |
124 | 414 | l->tab_ipm = av_mallocz(min_pu_size); | |
125 | 414 | l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1); | |
126 |
3/6✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 414 times.
|
414 | if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm) |
127 | ✗ | goto fail; | |
128 | |||
129 | 414 | l->filter_slice_edges = av_mallocz(ctb_count); | |
130 | 414 | l->tab_slice_address = av_malloc_array(pic_size_in_ctb, | |
131 | sizeof(*l->tab_slice_address)); | ||
132 | 414 | l->qp_y_tab = av_calloc(pic_size_in_ctb, | |
133 | sizeof(*l->qp_y_tab)); | ||
134 |
3/6✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 414 times.
|
414 | if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address) |
135 | ✗ | goto fail; | |
136 | |||
137 | 414 | l->horizontal_bs = av_calloc(l->bs_width, l->bs_height); | |
138 | 414 | l->vertical_bs = av_calloc(l->bs_width, l->bs_height); | |
139 |
2/4✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
|
414 | if (!l->horizontal_bs || !l->vertical_bs) |
140 | ✗ | goto fail; | |
141 | |||
142 | 414 | l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0); | |
143 | 414 | l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0); | |
144 |
2/4✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 414 times.
|
414 | if (!l->tab_mvf_pool || !l->rpl_tab_pool) |
145 | ✗ | goto fail; | |
146 | |||
147 |
2/2✓ Branch 0 taken 359 times.
✓ Branch 1 taken 55 times.
|
414 | if (sps->sao_enabled) { |
148 |
2/2✓ Branch 0 taken 357 times.
✓ Branch 1 taken 2 times.
|
359 | int c_count = (sps->chroma_format_idc != 0) ? 3 : 1; |
149 | |||
150 |
2/2✓ Branch 0 taken 1073 times.
✓ Branch 1 taken 359 times.
|
1432 | for (int c_idx = 0; c_idx < c_count; c_idx++) { |
151 | 1073 | int w = sps->width >> sps->hshift[c_idx]; | |
152 | 1073 | int h = sps->height >> sps->vshift[c_idx]; | |
153 | 1073 | l->sao_pixel_buffer_h[c_idx] = | |
154 | 1073 | av_malloc((w * 2 * sps->ctb_height) << | |
155 | 1073 | sps->pixel_shift); | |
156 | 1073 | l->sao_pixel_buffer_v[c_idx] = | |
157 | 1073 | av_malloc((h * 2 * sps->ctb_width) << | |
158 | 1073 | sps->pixel_shift); | |
159 |
1/2✓ Branch 0 taken 1073 times.
✗ Branch 1 not taken.
|
1073 | if (!l->sao_pixel_buffer_h[c_idx] || |
160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1073 times.
|
1073 | !l->sao_pixel_buffer_v[c_idx]) |
161 | ✗ | goto fail; | |
162 | } | ||
163 | } | ||
164 | |||
165 | 414 | return 0; | |
166 | |||
167 | ✗ | fail: | |
168 | ✗ | pic_arrays_free(l); | |
169 | ✗ | return AVERROR(ENOMEM); | |
170 | } | ||
171 | |||
172 | 1443 | static int pred_weight_table(SliceHeader *sh, void *logctx, | |
173 | const HEVCSPS *sps, GetBitContext *gb) | ||
174 | { | ||
175 | 1443 | int i = 0; | |
176 | 1443 | int j = 0; | |
177 | uint8_t luma_weight_l0_flag[16]; | ||
178 | uint8_t chroma_weight_l0_flag[16]; | ||
179 | uint8_t luma_weight_l1_flag[16]; | ||
180 | uint8_t chroma_weight_l1_flag[16]; | ||
181 | int luma_log2_weight_denom; | ||
182 | |||
183 | 1443 | luma_log2_weight_denom = get_ue_golomb_long(gb); | |
184 |
2/4✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1443 times.
|
1443 | if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) { |
185 | ✗ | av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom); | |
186 | ✗ | return AVERROR_INVALIDDATA; | |
187 | } | ||
188 | 1443 | sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3); | |
189 |
1/2✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
|
1443 | if (sps->chroma_format_idc != 0) { |
190 | 1443 | int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb); | |
191 |
2/4✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1443 times.
|
1443 | if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) { |
192 | ✗ | av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom); | |
193 | ✗ | return AVERROR_INVALIDDATA; | |
194 | } | ||
195 | 1443 | sh->chroma_log2_weight_denom = chroma_log2_weight_denom; | |
196 | } | ||
197 | |||
198 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < sh->nb_refs[L0]; i++) { |
199 | 4407 | luma_weight_l0_flag[i] = get_bits1(gb); | |
200 |
2/2✓ Branch 0 taken 1290 times.
✓ Branch 1 taken 3117 times.
|
4407 | if (!luma_weight_l0_flag[i]) { |
201 | 1290 | sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom; | |
202 | 1290 | sh->luma_offset_l0[i] = 0; | |
203 | } | ||
204 | } | ||
205 |
1/2✓ Branch 0 taken 1443 times.
✗ Branch 1 not taken.
|
1443 | if (sps->chroma_format_idc != 0) { |
206 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < sh->nb_refs[L0]; i++) |
207 | 4407 | chroma_weight_l0_flag[i] = get_bits1(gb); | |
208 | } else { | ||
209 | ✗ | for (i = 0; i < sh->nb_refs[L0]; i++) | |
210 | ✗ | chroma_weight_l0_flag[i] = 0; | |
211 | } | ||
212 |
2/2✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 1443 times.
|
5850 | for (i = 0; i < sh->nb_refs[L0]; i++) { |
213 |
2/2✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1290 times.
|
4407 | if (luma_weight_l0_flag[i]) { |
214 | 3117 | int delta_luma_weight_l0 = get_se_golomb(gb); | |
215 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
|
3117 | if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0) |
216 | ✗ | return AVERROR_INVALIDDATA; | |
217 | 3117 | sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0; | |
218 | 3117 | sh->luma_offset_l0[i] = get_se_golomb(gb); | |
219 | } | ||
220 |
2/2✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3276 times.
|
4407 | if (chroma_weight_l0_flag[i]) { |
221 |
2/2✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
|
3393 | for (j = 0; j < 2; j++) { |
222 | 2262 | int delta_chroma_weight_l0 = get_se_golomb(gb); | |
223 | 2262 | int delta_chroma_offset_l0 = get_se_golomb(gb); | |
224 | |||
225 |
1/2✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
|
2262 | if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0 |
226 |
2/4✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2262 times.
|
2262 | || delta_chroma_offset_l0 < -(1<<17) || delta_chroma_offset_l0 > (1<<17)) { |
227 | ✗ | return AVERROR_INVALIDDATA; | |
228 | } | ||
229 | |||
230 | 2262 | sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0; | |
231 | 2262 | sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j]) | |
232 | 2262 | >> sh->chroma_log2_weight_denom) + 128), -128, 127); | |
233 | } | ||
234 | } else { | ||
235 | 3276 | sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom; | |
236 | 3276 | sh->chroma_offset_l0[i][0] = 0; | |
237 | 3276 | sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom; | |
238 | 3276 | sh->chroma_offset_l0[i][1] = 0; | |
239 | } | ||
240 | } | ||
241 |
2/2✓ Branch 0 taken 668 times.
✓ Branch 1 taken 775 times.
|
1443 | if (sh->slice_type == HEVC_SLICE_B) { |
242 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < sh->nb_refs[L1]; i++) { |
243 | 1347 | luma_weight_l1_flag[i] = get_bits1(gb); | |
244 |
2/2✓ Branch 0 taken 601 times.
✓ Branch 1 taken 746 times.
|
1347 | if (!luma_weight_l1_flag[i]) { |
245 | 601 | sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom; | |
246 | 601 | sh->luma_offset_l1[i] = 0; | |
247 | } | ||
248 | } | ||
249 |
1/2✓ Branch 0 taken 668 times.
✗ Branch 1 not taken.
|
668 | if (sps->chroma_format_idc != 0) { |
250 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < sh->nb_refs[L1]; i++) |
251 | 1347 | chroma_weight_l1_flag[i] = get_bits1(gb); | |
252 | } else { | ||
253 | ✗ | for (i = 0; i < sh->nb_refs[L1]; i++) | |
254 | ✗ | chroma_weight_l1_flag[i] = 0; | |
255 | } | ||
256 |
2/2✓ Branch 0 taken 1347 times.
✓ Branch 1 taken 668 times.
|
2015 | for (i = 0; i < sh->nb_refs[L1]; i++) { |
257 |
2/2✓ Branch 0 taken 746 times.
✓ Branch 1 taken 601 times.
|
1347 | if (luma_weight_l1_flag[i]) { |
258 | 746 | int delta_luma_weight_l1 = get_se_golomb(gb); | |
259 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
|
746 | if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1) |
260 | ✗ | return AVERROR_INVALIDDATA; | |
261 | 746 | sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1; | |
262 | 746 | sh->luma_offset_l1[i] = get_se_golomb(gb); | |
263 | } | ||
264 |
2/2✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1111 times.
|
1347 | if (chroma_weight_l1_flag[i]) { |
265 |
2/2✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
|
708 | for (j = 0; j < 2; j++) { |
266 | 472 | int delta_chroma_weight_l1 = get_se_golomb(gb); | |
267 | 472 | int delta_chroma_offset_l1 = get_se_golomb(gb); | |
268 | |||
269 |
1/2✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
|
472 | if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1 |
270 |
2/4✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 472 times.
|
472 | || delta_chroma_offset_l1 < -(1<<17) || delta_chroma_offset_l1 > (1<<17)) { |
271 | ✗ | return AVERROR_INVALIDDATA; | |
272 | } | ||
273 | |||
274 | 472 | sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1; | |
275 | 472 | sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j]) | |
276 | 472 | >> sh->chroma_log2_weight_denom) + 128), -128, 127); | |
277 | } | ||
278 | } else { | ||
279 | 1111 | sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom; | |
280 | 1111 | sh->chroma_offset_l1[i][0] = 0; | |
281 | 1111 | sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom; | |
282 | 1111 | sh->chroma_offset_l1[i][1] = 0; | |
283 | } | ||
284 | } | ||
285 | } | ||
286 | 1443 | return 0; | |
287 | } | ||
288 | |||
289 | 19673 | static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps, | |
290 | GetBitContext *gb, int cur_poc, int poc_lsb) | ||
291 | { | ||
292 | 19673 | int max_poc_lsb = 1 << sps->log2_max_poc_lsb; | |
293 | 19673 | int prev_delta_msb = 0; | |
294 | 19673 | unsigned int nb_sps = 0, nb_sh; | |
295 | int i; | ||
296 | |||
297 | 19673 | rps->nb_refs = 0; | |
298 |
2/2✓ Branch 0 taken 18637 times.
✓ Branch 1 taken 1036 times.
|
19673 | if (!sps->long_term_ref_pics_present) |
299 | 18637 | return 0; | |
300 | |||
301 |
2/2✓ Branch 0 taken 499 times.
✓ Branch 1 taken 537 times.
|
1036 | if (sps->num_long_term_ref_pics_sps > 0) |
302 | 499 | nb_sps = get_ue_golomb_long(gb); | |
303 | 1036 | nb_sh = get_ue_golomb_long(gb); | |
304 | |||
305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
|
1036 | if (nb_sps > sps->num_long_term_ref_pics_sps) |
306 | ✗ | return AVERROR_INVALIDDATA; | |
307 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1036 times.
|
1036 | if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc)) |
308 | ✗ | return AVERROR_INVALIDDATA; | |
309 | |||
310 | 1036 | rps->nb_refs = nb_sh + nb_sps; | |
311 | |||
312 |
2/2✓ Branch 0 taken 1562 times.
✓ Branch 1 taken 1036 times.
|
2598 | for (i = 0; i < rps->nb_refs; i++) { |
313 | |||
314 |
2/2✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1378 times.
|
1562 | if (i < nb_sps) { |
315 | 184 | uint8_t lt_idx_sps = 0; | |
316 | |||
317 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (sps->num_long_term_ref_pics_sps > 1) |
318 | 184 | lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps)); | |
319 | |||
320 | 184 | rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps]; | |
321 | 184 | rps->used[i] = !!(sps->used_by_curr_pic_lt & (1U << lt_idx_sps)); | |
322 | } else { | ||
323 | 1378 | rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb); | |
324 | 1378 | rps->used[i] = get_bits1(gb); | |
325 | } | ||
326 | |||
327 | 1562 | rps->poc_msb_present[i] = get_bits1(gb); | |
328 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1514 times.
|
1562 | if (rps->poc_msb_present[i]) { |
329 | 48 | int64_t delta = get_ue_golomb_long(gb); | |
330 | int64_t poc; | ||
331 | |||
332 |
3/4✓ Branch 0 taken 31 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
|
48 | if (i && i != nb_sps) |
333 | 31 | delta += prev_delta_msb; | |
334 | |||
335 | 48 | poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb; | |
336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (poc != (int32_t)poc) |
337 | ✗ | return AVERROR_INVALIDDATA; | |
338 | 48 | rps->poc[i] = poc; | |
339 | 48 | prev_delta_msb = delta; | |
340 | } | ||
341 | } | ||
342 | |||
343 | 1036 | return 0; | |
344 | } | ||
345 | |||
346 | 656 | static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) | |
347 | { | ||
348 | 656 | AVCodecContext *avctx = s->avctx; | |
349 | 656 | const HEVCVPS *vps = sps->vps; | |
350 | 656 | const HEVCWindow *ow = &sps->output_window; | |
351 | 656 | unsigned int num = 0, den = 0; | |
352 | |||
353 | 656 | avctx->pix_fmt = sps->pix_fmt; | |
354 | 656 | avctx->coded_width = sps->width; | |
355 | 656 | avctx->coded_height = sps->height; | |
356 | 656 | avctx->width = sps->width - ow->left_offset - ow->right_offset; | |
357 | 656 | avctx->height = sps->height - ow->top_offset - ow->bottom_offset; | |
358 | 656 | avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics; | |
359 | 656 | avctx->profile = sps->ptl.general_ptl.profile_idc; | |
360 | 656 | avctx->level = sps->ptl.general_ptl.level_idc; | |
361 | |||
362 | 656 | ff_set_sar(avctx, sps->vui.common.sar); | |
363 | |||
364 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 600 times.
|
656 | if (sps->vui.common.video_signal_type_present_flag) |
365 | 56 | avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG | |
366 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 50 times.
|
56 | : AVCOL_RANGE_MPEG; |
367 | else | ||
368 | 600 | avctx->color_range = AVCOL_RANGE_MPEG; | |
369 | |||
370 |
2/2✓ Branch 0 taken 49 times.
✓ Branch 1 taken 607 times.
|
656 | if (sps->vui.common.colour_description_present_flag) { |
371 | 49 | avctx->color_primaries = sps->vui.common.colour_primaries; | |
372 | 49 | avctx->color_trc = sps->vui.common.transfer_characteristics; | |
373 | 49 | avctx->colorspace = sps->vui.common.matrix_coeffs; | |
374 | } else { | ||
375 | 607 | avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; | |
376 | 607 | avctx->color_trc = AVCOL_TRC_UNSPECIFIED; | |
377 | 607 | avctx->colorspace = AVCOL_SPC_UNSPECIFIED; | |
378 | } | ||
379 | |||
380 | 656 | avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED; | |
381 |
2/2✓ Branch 0 taken 615 times.
✓ Branch 1 taken 41 times.
|
656 | if (sps->chroma_format_idc == 1) { |
382 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 596 times.
|
615 | if (sps->vui.common.chroma_loc_info_present_flag) { |
383 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | if (sps->vui.common.chroma_sample_loc_type_top_field <= 5) |
384 | 19 | avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1; | |
385 | } else | ||
386 | 596 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; | |
387 | } | ||
388 | |||
389 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 634 times.
|
656 | if (vps->vps_timing_info_present_flag) { |
390 | 22 | num = vps->vps_num_units_in_tick; | |
391 | 22 | den = vps->vps_time_scale; | |
392 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 578 times.
|
634 | } else if (sps->vui.vui_timing_info_present_flag) { |
393 | 56 | num = sps->vui.vui_num_units_in_tick; | |
394 | 56 | den = sps->vui.vui_time_scale; | |
395 | } | ||
396 | |||
397 |
3/4✓ Branch 0 taken 78 times.
✓ Branch 1 taken 578 times.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
|
656 | if (num > 0 && den > 0) |
398 | 78 | av_reduce(&avctx->framerate.den, &avctx->framerate.num, | |
399 | num, den, 1 << 30); | ||
400 | 656 | } | |
401 | |||
402 | 10424 | static int export_stream_params_from_sei(HEVCContext *s) | |
403 | { | ||
404 | 10424 | AVCodecContext *avctx = s->avctx; | |
405 | |||
406 | #if FF_API_CODEC_PROPS | ||
407 | FF_DISABLE_DEPRECATION_WARNINGS | ||
408 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10424 times.
|
10424 | if (s->sei.common.a53_caption.buf_ref) |
409 | ✗ | s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; | |
410 | FF_ENABLE_DEPRECATION_WARNINGS | ||
411 | #endif | ||
412 | |||
413 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10424 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10424 | if (s->sei.common.alternative_transfer.present && |
414 | ✗ | av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) && | |
415 | ✗ | s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) { | |
416 | ✗ | avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics; | |
417 | } | ||
418 | |||
419 | #if FF_API_CODEC_PROPS | ||
420 | FF_DISABLE_DEPRECATION_WARNINGS | ||
421 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10424 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10424 | if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) || |
422 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10424 times.
|
10424 | s->sei.common.aom_film_grain.enable) |
423 | ✗ | avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; | |
424 | FF_ENABLE_DEPRECATION_WARNINGS | ||
425 | #endif | ||
426 | |||
427 | 10424 | return 0; | |
428 | } | ||
429 | |||
430 | 656 | static int export_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
431 | { | ||
432 | 656 | const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi; | |
433 | |||
434 | 656 | av_freep(&s->view_ids_available); | |
435 | 656 | s->nb_view_ids_available = 0; | |
436 | 656 | av_freep(&s->view_pos_available); | |
437 | 656 | s->nb_view_pos_available = 0; | |
438 | |||
439 | // don't export anything in the trivial case (1 layer, view id=0) | ||
440 |
3/4✓ Branch 0 taken 634 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 634 times.
✗ Branch 3 not taken.
|
656 | if (vps->nb_layers < 2 && !vps->view_id[0]) |
441 | 634 | return 0; | |
442 | |||
443 | 22 | s->view_ids_available = av_calloc(vps->nb_layers, sizeof(*s->view_ids_available)); | |
444 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | if (!s->view_ids_available) |
445 | ✗ | return AVERROR(ENOMEM); | |
446 | |||
447 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
|
22 | if (tdrdi->num_ref_displays) { |
448 | 5 | s->view_pos_available = av_calloc(vps->nb_layers, sizeof(*s->view_pos_available)); | |
449 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!s->view_pos_available) |
450 | ✗ | return AVERROR(ENOMEM); | |
451 | } | ||
452 | |||
453 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 22 times.
|
66 | for (int i = 0; i < vps->nb_layers; i++) { |
454 | 44 | s->view_ids_available[i] = vps->view_id[i]; | |
455 | |||
456 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 34 times.
|
44 | if (s->view_pos_available) { |
457 | 10 | s->view_pos_available[i] = vps->view_id[i] == tdrdi->left_view_id[0] ? | |
458 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
15 | AV_STEREO3D_VIEW_LEFT : |
459 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | vps->view_id[i] == tdrdi->right_view_id[0] ? |
460 | AV_STEREO3D_VIEW_RIGHT : AV_STEREO3D_VIEW_UNSPEC; | ||
461 | } | ||
462 | } | ||
463 | 22 | s->nb_view_ids_available = vps->nb_layers; | |
464 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
|
22 | s->nb_view_pos_available = s->view_pos_available ? vps->nb_layers : 0; |
465 | |||
466 | 22 | return 0; | |
467 | } | ||
468 | |||
469 | 405 | static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
470 | { | ||
471 | 405 | unsigned layers_active_output = 0, highest_layer; | |
472 | |||
473 | 405 | s->layers_active_output = 1; | |
474 | 405 | s->layers_active_decode = 1; | |
475 | |||
476 | // nothing requested - decode base layer only | ||
477 |
2/2✓ Branch 0 taken 395 times.
✓ Branch 1 taken 10 times.
|
405 | if (!s->nb_view_ids) |
478 | 395 | return 0; | |
479 | |||
480 |
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) { |
481 | ✗ | layers_active_output = (1 << vps->nb_layers) - 1; | |
482 | } else { | ||
483 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 10 times.
|
28 | for (int i = 0; i < s->nb_view_ids; i++) { |
484 | 18 | int view_id = s->view_ids[i]; | |
485 | 18 | int layer_idx = -1; | |
486 | |||
487 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (view_id < 0) { |
488 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
489 | "Invalid view ID requested: %d\n", view_id); | ||
490 | ✗ | return AVERROR(EINVAL); | |
491 | } | ||
492 | |||
493 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | for (int j = 0; j < vps->nb_layers; j++) { |
494 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
|
26 | if (vps->view_id[j] == view_id) { |
495 | 18 | layer_idx = j; | |
496 | 18 | break; | |
497 | } | ||
498 | } | ||
499 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (layer_idx < 0) { |
500 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
501 | "View ID %d not present in VPS\n", view_id); | ||
502 | ✗ | return AVERROR(EINVAL); | |
503 | } | ||
504 | 18 | layers_active_output |= 1 << layer_idx; | |
505 | } | ||
506 | } | ||
507 | |||
508 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (!layers_active_output) { |
509 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No layers selected\n"); | |
510 | ✗ | return AVERROR_BUG; | |
511 | } | ||
512 | |||
513 | 10 | highest_layer = ff_log2(layers_active_output); | |
514 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (highest_layer >= FF_ARRAY_ELEMS(s->layers)) { |
515 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
516 | "Too many layers requested: %u\n", layers_active_output); | ||
517 | ✗ | return AVERROR(EINVAL); | |
518 | } | ||
519 | |||
520 | /* Assume a higher layer depends on all the lower ones. | ||
521 | * This is enforced in VPS parsing currently, this logic will need | ||
522 | * to be changed if we want to support more complex dependency structures. | ||
523 | */ | ||
524 | 10 | s->layers_active_decode = (1 << (highest_layer + 1)) - 1; | |
525 | 10 | s->layers_active_output = layers_active_output; | |
526 | |||
527 | 10 | av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n", | |
528 | s->layers_active_decode, s->layers_active_output); | ||
529 | |||
530 | 10 | return 0; | |
531 | } | ||
532 | |||
533 | 405 | static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) | |
534 | { | ||
535 | #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \ | ||
536 | CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \ | ||
537 | CONFIG_HEVC_D3D12VA_HWACCEL + \ | ||
538 | CONFIG_HEVC_NVDEC_HWACCEL + \ | ||
539 | CONFIG_HEVC_VAAPI_HWACCEL + \ | ||
540 | CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \ | ||
541 | CONFIG_HEVC_VDPAU_HWACCEL + \ | ||
542 | CONFIG_HEVC_VULKAN_HWACCEL) | ||
543 | 405 | enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts; | |
544 | int ret; | ||
545 | |||
546 |
6/7✓ Branch 0 taken 342 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
|
405 | switch (sps->pix_fmt) { |
547 | 342 | case AV_PIX_FMT_YUV420P: | |
548 | case AV_PIX_FMT_YUVJ420P: | ||
549 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
550 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
551 | #endif | ||
552 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
553 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
554 | *fmt++ = AV_PIX_FMT_D3D11; | ||
555 | #endif | ||
556 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
557 | *fmt++ = AV_PIX_FMT_D3D12; | ||
558 | #endif | ||
559 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
560 | 342 | *fmt++ = AV_PIX_FMT_VAAPI; | |
561 | #endif | ||
562 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
563 | 342 | *fmt++ = AV_PIX_FMT_VDPAU; | |
564 | #endif | ||
565 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
566 | *fmt++ = AV_PIX_FMT_CUDA; | ||
567 | #endif | ||
568 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
569 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
570 | #endif | ||
571 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
572 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
573 | #endif | ||
574 | 342 | break; | |
575 | 35 | case AV_PIX_FMT_YUV420P10: | |
576 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
577 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
578 | #endif | ||
579 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
580 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
581 | *fmt++ = AV_PIX_FMT_D3D11; | ||
582 | #endif | ||
583 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
584 | *fmt++ = AV_PIX_FMT_D3D12; | ||
585 | #endif | ||
586 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
587 | 35 | *fmt++ = AV_PIX_FMT_VAAPI; | |
588 | #endif | ||
589 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
590 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
591 | #endif | ||
592 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
593 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
594 | #endif | ||
595 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
596 | 35 | *fmt++ = AV_PIX_FMT_VDPAU; | |
597 | #endif | ||
598 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
599 | *fmt++ = AV_PIX_FMT_CUDA; | ||
600 | #endif | ||
601 | 35 | break; | |
602 | 4 | case AV_PIX_FMT_YUV444P: | |
603 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
604 | 4 | *fmt++ = AV_PIX_FMT_VAAPI; | |
605 | #endif | ||
606 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
607 | 4 | *fmt++ = AV_PIX_FMT_VDPAU; | |
608 | #endif | ||
609 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
610 | *fmt++ = AV_PIX_FMT_CUDA; | ||
611 | #endif | ||
612 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
613 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
614 | #endif | ||
615 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
616 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
617 | #endif | ||
618 | 4 | break; | |
619 | 12 | case AV_PIX_FMT_YUV422P: | |
620 | case AV_PIX_FMT_YUV422P10LE: | ||
621 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
622 | 12 | *fmt++ = AV_PIX_FMT_VAAPI; | |
623 | #endif | ||
624 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
625 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
626 | #endif | ||
627 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
628 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
629 | #endif | ||
630 | 12 | break; | |
631 | 10 | case AV_PIX_FMT_YUV444P10: | |
632 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
633 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
634 | #endif | ||
635 | /* NOTE: fallthrough */ | ||
636 | case AV_PIX_FMT_YUV420P12: | ||
637 | case AV_PIX_FMT_YUV444P12: | ||
638 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
639 | 10 | *fmt++ = AV_PIX_FMT_VAAPI; | |
640 | #endif | ||
641 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
642 | 10 | *fmt++ = AV_PIX_FMT_VDPAU; | |
643 | #endif | ||
644 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
645 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
646 | #endif | ||
647 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
648 | *fmt++ = AV_PIX_FMT_CUDA; | ||
649 | #endif | ||
650 | 10 | break; | |
651 | ✗ | case AV_PIX_FMT_YUV422P12: | |
652 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
653 | ✗ | *fmt++ = AV_PIX_FMT_VAAPI; | |
654 | #endif | ||
655 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
656 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
657 | #endif | ||
658 | ✗ | break; | |
659 | } | ||
660 | |||
661 | 405 | *fmt++ = sps->pix_fmt; | |
662 | 405 | *fmt = AV_PIX_FMT_NONE; | |
663 | |||
664 | // export multilayer information from active VPS to the caller, | ||
665 | // so it is available in get_format() | ||
666 | 405 | ret = export_multilayer(s, sps->vps); | |
667 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
|
405 | if (ret < 0) |
668 | ✗ | return ret; | |
669 | |||
670 | 405 | ret = ff_get_format(s->avctx, pix_fmts); | |
671 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
|
405 | if (ret < 0) |
672 | ✗ | return ret; | |
673 | 405 | s->avctx->pix_fmt = ret; | |
674 | |||
675 | // set up multilayer decoding, if requested by caller | ||
676 | 405 | ret = setup_multilayer(s, sps->vps); | |
677 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
|
405 | if (ret < 0) |
678 | ✗ | return ret; | |
679 | |||
680 | 405 | return 0; | |
681 | } | ||
682 | |||
683 | 414 | static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) | |
684 | { | ||
685 | int ret; | ||
686 | |||
687 | 414 | pic_arrays_free(l); | |
688 | 414 | av_refstruct_unref(&l->sps); | |
689 | 414 | av_refstruct_unref(&s->vps); | |
690 | |||
691 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
|
414 | if (!sps) |
692 | ✗ | return 0; | |
693 | |||
694 | 414 | ret = pic_arrays_init(l, sps); | |
695 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
|
414 | if (ret < 0) |
696 | ✗ | goto fail; | |
697 | |||
698 | 414 | ff_hevc_pred_init(&s->hpc, sps->bit_depth); | |
699 | 414 | ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); | |
700 | 414 | ff_videodsp_init (&s->vdsp, sps->bit_depth); | |
701 | |||
702 | 414 | l->sps = av_refstruct_ref_c(sps); | |
703 | 414 | s->vps = av_refstruct_ref_c(sps->vps); | |
704 | |||
705 | 414 | return 0; | |
706 | |||
707 | ✗ | fail: | |
708 | ✗ | pic_arrays_free(l); | |
709 | ✗ | av_refstruct_unref(&l->sps); | |
710 | ✗ | return ret; | |
711 | } | ||
712 | |||
713 | 28284 | static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb) | |
714 | { | ||
715 | const HEVCPPS *pps; | ||
716 | const HEVCSPS *sps; | ||
717 | const HEVCVPS *vps; | ||
718 | unsigned pps_id, layer_idx; | ||
719 | int i, ret; | ||
720 | |||
721 | // Coded parameters | ||
722 | 28284 | sh->first_slice_in_pic_flag = get_bits1(gb); | |
723 | |||
724 | 28284 | sh->no_output_of_prior_pics_flag = 0; | |
725 |
3/4✓ Branch 0 taken 1448 times.
✓ Branch 1 taken 26836 times.
✓ Branch 2 taken 1448 times.
✗ Branch 3 not taken.
|
28284 | if (IS_IRAP(s)) |
726 | 1448 | sh->no_output_of_prior_pics_flag = get_bits1(gb); | |
727 | |||
728 | 28284 | pps_id = get_ue_golomb_long(gb); | |
729 |
3/4✓ Branch 0 taken 28284 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 28251 times.
|
28284 | if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) { |
730 | 33 | av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); | |
731 | 33 | return AVERROR_INVALIDDATA; | |
732 | } | ||
733 |
3/4✓ Branch 0 taken 18036 times.
✓ Branch 1 taken 10215 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18036 times.
|
28251 | if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) { |
734 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); | |
735 | ✗ | return AVERROR_INVALIDDATA; | |
736 | } | ||
737 | 28251 | sh->pps_id = pps_id; | |
738 | |||
739 | 28251 | pps = s->ps.pps_list[pps_id]; | |
740 | 28251 | sps = pps->sps; | |
741 | 28251 | vps = sps->vps; | |
742 | 28251 | layer_idx = vps->layer_idx[s->nuh_layer_id]; | |
743 | |||
744 |
4/4✓ Branch 0 taken 479 times.
✓ Branch 1 taken 27772 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 464 times.
|
28251 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) |
745 | 15 | sh->no_output_of_prior_pics_flag = 1; | |
746 | |||
747 | 28251 | sh->dependent_slice_segment_flag = 0; | |
748 |
2/2✓ Branch 0 taken 18036 times.
✓ Branch 1 taken 10215 times.
|
28251 | if (!sh->first_slice_in_pic_flag) { |
749 | int slice_address_length; | ||
750 | |||
751 |
2/2✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8944 times.
|
18036 | if (pps->dependent_slice_segments_enabled_flag) |
752 | 9092 | sh->dependent_slice_segment_flag = get_bits1(gb); | |
753 |
3/4✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 10089 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7947 times.
|
18036 | if (sh->dependent_slice_segment_flag && !s->slice_initialized) { |
754 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); | |
755 | ✗ | return AVERROR_INVALIDDATA; | |
756 | } | ||
757 | |||
758 | 18036 | slice_address_length = av_ceil_log2(sps->ctb_width * | |
759 | 18036 | sps->ctb_height); | |
760 | 18036 | sh->slice_segment_addr = get_bitsz(gb, slice_address_length); | |
761 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18036 times.
|
18036 | if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) { |
762 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
763 | "Invalid slice segment address: %u.\n", | ||
764 | sh->slice_segment_addr); | ||
765 | ✗ | return AVERROR_INVALIDDATA; | |
766 | } | ||
767 | |||
768 |
2/2✓ Branch 0 taken 10089 times.
✓ Branch 1 taken 7947 times.
|
18036 | if (!sh->dependent_slice_segment_flag) { |
769 | 10089 | sh->slice_addr = sh->slice_segment_addr; | |
770 | } | ||
771 | } else { | ||
772 | 10215 | sh->slice_segment_addr = sh->slice_addr = 0; | |
773 | } | ||
774 | |||
775 |
2/2✓ Branch 0 taken 20304 times.
✓ Branch 1 taken 7947 times.
|
28251 | if (!sh->dependent_slice_segment_flag) { |
776 |
2/2✓ Branch 0 taken 1078 times.
✓ Branch 1 taken 20304 times.
|
21382 | for (i = 0; i < pps->num_extra_slice_header_bits; i++) |
777 | 1078 | skip_bits(gb, 1); // slice_reserved_undetermined_flag[] | |
778 | |||
779 | 20304 | sh->slice_type = get_ue_golomb_long(gb); | |
780 |
2/2✓ Branch 0 taken 19069 times.
✓ Branch 1 taken 1235 times.
|
20304 | if (!(sh->slice_type == HEVC_SLICE_I || |
781 |
2/2✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3840 times.
|
19069 | sh->slice_type == HEVC_SLICE_P || |
782 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15229 times.
|
15229 | sh->slice_type == HEVC_SLICE_B)) { |
783 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", | |
784 | ✗ | sh->slice_type); | |
785 | ✗ | return AVERROR_INVALIDDATA; | |
786 | } | ||
787 |
5/6✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 19245 times.
✓ Branch 2 taken 1059 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 75 times.
✓ Branch 5 taken 984 times.
|
20304 | if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I && |
788 |
1/2✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
|
75 | !pps->pps_curr_pic_ref_enabled_flag && |
789 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
|
75 | s->nuh_layer_id == 0) { |
790 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); | |
791 | ✗ | return AVERROR_INVALIDDATA; | |
792 | } | ||
793 | |||
794 | // when flag is not present, picture is inferred to be output | ||
795 | 20304 | sh->pic_output_flag = 1; | |
796 |
2/2✓ Branch 0 taken 703 times.
✓ Branch 1 taken 19601 times.
|
20304 | if (pps->output_flag_present_flag) |
797 | 703 | sh->pic_output_flag = get_bits1(gb); | |
798 | |||
799 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20304 times.
|
20304 | if (sps->separate_colour_plane) |
800 | ✗ | sh->colour_plane_id = get_bits(gb, 2); | |
801 | |||
802 |
4/4✓ Branch 0 taken 19692 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 19673 times.
|
20304 | if (!IS_IDR(s) || |
803 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 624 times.
|
631 | (s->nuh_layer_id > 0 && |
804 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | !(vps->poc_lsb_not_present & (1 << layer_idx)))) { |
805 | int poc; | ||
806 | |||
807 | 19680 | sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb); | |
808 | 19680 | poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type); | |
809 |
3/4✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9812 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
|
19680 | if (!sh->first_slice_in_pic_flag && poc != sh->poc) { |
810 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
811 | "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc); | ||
812 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
813 | ✗ | return AVERROR_INVALIDDATA; | |
814 | ✗ | poc = sh->poc; | |
815 | } | ||
816 | 19680 | sh->poc = poc; | |
817 | } | ||
818 | |||
819 |
4/4✓ Branch 0 taken 19692 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 19673 times.
✓ Branch 3 taken 19 times.
|
39977 | if (!IS_IDR(s)) { |
820 | int pos; | ||
821 | |||
822 | 19673 | sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); | |
823 | 19673 | pos = get_bits_left(gb); | |
824 |
2/2✓ Branch 0 taken 3499 times.
✓ Branch 1 taken 16174 times.
|
19673 | if (!sh->short_term_ref_pic_set_sps_flag) { |
825 | 3499 | ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1); | |
826 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3499 times.
|
3499 | if (ret < 0) |
827 | ✗ | return ret; | |
828 | |||
829 | 3499 | sh->short_term_rps = &sh->slice_rps; | |
830 | } else { | ||
831 | int numbits, rps_idx; | ||
832 | |||
833 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16174 times.
|
16174 | if (!sps->nb_st_rps) { |
834 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); | |
835 | ✗ | return AVERROR_INVALIDDATA; | |
836 | } | ||
837 | |||
838 | 16174 | numbits = av_ceil_log2(sps->nb_st_rps); | |
839 |
2/2✓ Branch 0 taken 16146 times.
✓ Branch 1 taken 28 times.
|
16174 | rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; |
840 | 16174 | sh->short_term_rps = &sps->st_rps[rps_idx]; | |
841 | } | ||
842 | 19673 | sh->short_term_ref_pic_set_size = pos - get_bits_left(gb); | |
843 | |||
844 | 19673 | pos = get_bits_left(gb); | |
845 | 19673 | ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb); | |
846 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19673 times.
|
19673 | if (ret < 0) { |
847 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n"); | |
848 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
849 | ✗ | return AVERROR_INVALIDDATA; | |
850 | } | ||
851 | 19673 | sh->long_term_ref_pic_set_size = pos - get_bits_left(gb); | |
852 | |||
853 |
2/2✓ Branch 0 taken 17242 times.
✓ Branch 1 taken 2431 times.
|
19673 | if (sps->temporal_mvp_enabled) |
854 | 17242 | sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); | |
855 | else | ||
856 | 2431 | sh->slice_temporal_mvp_enabled_flag = 0; | |
857 | } else { | ||
858 | 631 | sh->poc = 0; | |
859 | 631 | sh->pic_order_cnt_lsb = 0; | |
860 | 631 | sh->short_term_ref_pic_set_sps_flag = 0; | |
861 | 631 | sh->short_term_ref_pic_set_size = 0; | |
862 | 631 | sh->short_term_rps = NULL; | |
863 | 631 | sh->long_term_ref_pic_set_size = 0; | |
864 | 631 | sh->slice_temporal_mvp_enabled_flag = 0; | |
865 | } | ||
866 | |||
867 | 20304 | sh->inter_layer_pred = 0; | |
868 |
2/2✓ Branch 0 taken 277 times.
✓ Branch 1 taken 20027 times.
|
20304 | if (s->nuh_layer_id > 0) { |
869 | 277 | int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx]; | |
870 | |||
871 |
2/2✓ Branch 0 taken 229 times.
✓ Branch 1 taken 48 times.
|
277 | if (vps->default_ref_layers_active) |
872 | 229 | sh->inter_layer_pred = !!num_direct_ref_layers; | |
873 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | else if (num_direct_ref_layers) { |
874 | 48 | sh->inter_layer_pred = get_bits1(gb); | |
875 | |||
876 |
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) { |
877 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
878 | "NumDirectRefLayers>1 not supported\n"); | ||
879 | ✗ | return AVERROR_PATCHWELCOME; | |
880 | } | ||
881 | } | ||
882 | } | ||
883 | |||
884 |
2/2✓ Branch 0 taken 16791 times.
✓ Branch 1 taken 3513 times.
|
20304 | if (sps->sao_enabled) { |
885 | 16791 | sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); | |
886 |
2/2✓ Branch 0 taken 16789 times.
✓ Branch 1 taken 2 times.
|
16791 | if (sps->chroma_format_idc) { |
887 | 16789 | sh->slice_sample_adaptive_offset_flag[1] = | |
888 | 16789 | sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); | |
889 | } | ||
890 | } else { | ||
891 | 3513 | sh->slice_sample_adaptive_offset_flag[0] = 0; | |
892 | 3513 | sh->slice_sample_adaptive_offset_flag[1] = 0; | |
893 | 3513 | sh->slice_sample_adaptive_offset_flag[2] = 0; | |
894 | } | ||
895 | |||
896 | 20304 | sh->nb_refs[L0] = sh->nb_refs[L1] = 0; | |
897 |
4/4✓ Branch 0 taken 16464 times.
✓ Branch 1 taken 3840 times.
✓ Branch 2 taken 15229 times.
✓ Branch 3 taken 1235 times.
|
20304 | if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) { |
898 | int nb_refs; | ||
899 | |||
900 | 19069 | sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active; | |
901 |
2/2✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3840 times.
|
19069 | if (sh->slice_type == HEVC_SLICE_B) |
902 | 15229 | sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active; | |
903 | |||
904 |
2/2✓ Branch 1 taken 4954 times.
✓ Branch 2 taken 14115 times.
|
19069 | if (get_bits1(gb)) { // num_ref_idx_active_override_flag |
905 | 4954 | sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1; | |
906 |
2/2✓ Branch 0 taken 2776 times.
✓ Branch 1 taken 2178 times.
|
4954 | if (sh->slice_type == HEVC_SLICE_B) |
907 | 2776 | sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1; | |
908 | } | ||
909 |
2/4✓ Branch 0 taken 19069 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19069 times.
|
19069 | if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) { |
910 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n", | |
911 | sh->nb_refs[L0], sh->nb_refs[L1]); | ||
912 | ✗ | return AVERROR_INVALIDDATA; | |
913 | } | ||
914 | |||
915 | 19069 | sh->rpl_modification_flag[0] = 0; | |
916 | 19069 | sh->rpl_modification_flag[1] = 0; | |
917 | 19069 | nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx); | |
918 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19069 times.
|
19069 | if (!nb_refs) { |
919 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); | |
920 | ✗ | return AVERROR_INVALIDDATA; | |
921 | } | ||
922 | |||
923 |
4/4✓ Branch 0 taken 1930 times.
✓ Branch 1 taken 17139 times.
✓ Branch 2 taken 1795 times.
✓ Branch 3 taken 135 times.
|
19069 | if (pps->lists_modification_present_flag && nb_refs > 1) { |
924 | 1795 | sh->rpl_modification_flag[0] = get_bits1(gb); | |
925 |
2/2✓ Branch 0 taken 1249 times.
✓ Branch 1 taken 546 times.
|
1795 | if (sh->rpl_modification_flag[0]) { |
926 |
2/2✓ Branch 0 taken 3000 times.
✓ Branch 1 taken 1249 times.
|
4249 | for (i = 0; i < sh->nb_refs[L0]; i++) |
927 | 3000 | sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
928 | } | ||
929 | |||
930 |
1/2✓ Branch 0 taken 1795 times.
✗ Branch 1 not taken.
|
1795 | if (sh->slice_type == HEVC_SLICE_B) { |
931 | 1795 | sh->rpl_modification_flag[1] = get_bits1(gb); | |
932 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 1143 times.
|
1795 | if (sh->rpl_modification_flag[1] == 1) |
933 |
2/2✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
|
2207 | for (i = 0; i < sh->nb_refs[L1]; i++) |
934 | 1555 | sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
935 | } | ||
936 | } | ||
937 | |||
938 |
2/2✓ Branch 0 taken 15229 times.
✓ Branch 1 taken 3840 times.
|
19069 | if (sh->slice_type == HEVC_SLICE_B) |
939 | 15229 | sh->mvd_l1_zero_flag = get_bits1(gb); | |
940 | |||
941 |
2/2✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 2759 times.
|
19069 | if (pps->cabac_init_present_flag) |
942 | 16310 | sh->cabac_init_flag = get_bits1(gb); | |
943 | else | ||
944 | 2759 | sh->cabac_init_flag = 0; | |
945 | |||
946 | 19069 | sh->collocated_ref_idx = 0; | |
947 |
2/2✓ Branch 0 taken 16684 times.
✓ Branch 1 taken 2385 times.
|
19069 | if (sh->slice_temporal_mvp_enabled_flag) { |
948 | 16684 | sh->collocated_list = L0; | |
949 |
2/2✓ Branch 0 taken 14695 times.
✓ Branch 1 taken 1989 times.
|
16684 | if (sh->slice_type == HEVC_SLICE_B) |
950 | 14695 | sh->collocated_list = !get_bits1(gb); | |
951 | |||
952 |
2/2✓ Branch 0 taken 14826 times.
✓ Branch 1 taken 1858 times.
|
16684 | if (sh->nb_refs[sh->collocated_list] > 1) { |
953 | 14826 | sh->collocated_ref_idx = get_ue_golomb_long(gb); | |
954 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14826 times.
|
14826 | if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { |
955 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
956 | "Invalid collocated_ref_idx: %d.\n", | ||
957 | sh->collocated_ref_idx); | ||
958 | ✗ | return AVERROR_INVALIDDATA; | |
959 | } | ||
960 | } | ||
961 | } | ||
962 | |||
963 |
4/4✓ Branch 0 taken 1468 times.
✓ Branch 1 taken 17601 times.
✓ Branch 2 taken 693 times.
✓ Branch 3 taken 775 times.
|
19069 | if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) || |
964 |
3/4✓ Branch 0 taken 668 times.
✓ Branch 1 taken 17626 times.
✓ Branch 2 taken 668 times.
✗ Branch 3 not taken.
|
18294 | (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) { |
965 | 1443 | int ret = pred_weight_table(sh, s->avctx, sps, gb); | |
966 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1443 times.
|
1443 | if (ret < 0) |
967 | ✗ | return ret; | |
968 | } | ||
969 | |||
970 | 19069 | sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb); | |
971 |
2/4✓ Branch 0 taken 19069 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19069 times.
|
19069 | if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) { |
972 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
973 | "Invalid number of merging MVP candidates: %d.\n", | ||
974 | ✗ | sh->max_num_merge_cand); | |
975 | ✗ | return AVERROR_INVALIDDATA; | |
976 | } | ||
977 | |||
978 | // Syntax in 7.3.6.1 | ||
979 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19069 times.
|
19069 | if (sps->motion_vector_resolution_control_idc == 2) |
980 | ✗ | sh->use_integer_mv_flag = get_bits1(gb); | |
981 | else | ||
982 | // Inferred to be equal to motion_vector_resolution_control_idc if not present | ||
983 | 19069 | sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc; | |
984 | |||
985 | } | ||
986 | |||
987 | 20304 | sh->slice_qp_delta = get_se_golomb(gb); | |
988 | |||
989 |
2/2✓ Branch 0 taken 271 times.
✓ Branch 1 taken 20033 times.
|
20304 | if (pps->pic_slice_level_chroma_qp_offsets_present_flag) { |
990 | 271 | sh->slice_cb_qp_offset = get_se_golomb(gb); | |
991 | 271 | sh->slice_cr_qp_offset = get_se_golomb(gb); | |
992 |
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 || |
993 |
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) { |
994 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n"); | |
995 | ✗ | return AVERROR_INVALIDDATA; | |
996 | } | ||
997 | } else { | ||
998 | 20033 | sh->slice_cb_qp_offset = 0; | |
999 | 20033 | sh->slice_cr_qp_offset = 0; | |
1000 | } | ||
1001 | |||
1002 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20304 times.
|
20304 | if (pps->pps_slice_act_qp_offsets_present_flag) { |
1003 | ✗ | sh->slice_act_y_qp_offset = get_se_golomb(gb); | |
1004 | ✗ | sh->slice_act_cb_qp_offset = get_se_golomb(gb); | |
1005 | ✗ | sh->slice_act_cr_qp_offset = get_se_golomb(gb); | |
1006 | } | ||
1007 | |||
1008 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 20261 times.
|
20304 | if (pps->chroma_qp_offset_list_enabled_flag) |
1009 | 43 | sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb); | |
1010 | else | ||
1011 | 20261 | sh->cu_chroma_qp_offset_enabled_flag = 0; | |
1012 | |||
1013 |
2/2✓ Branch 0 taken 2959 times.
✓ Branch 1 taken 17345 times.
|
20304 | if (pps->deblocking_filter_control_present_flag) { |
1014 | 2959 | int deblocking_filter_override_flag = 0; | |
1015 | |||
1016 |
2/2✓ Branch 0 taken 696 times.
✓ Branch 1 taken 2263 times.
|
2959 | if (pps->deblocking_filter_override_enabled_flag) |
1017 | 696 | deblocking_filter_override_flag = get_bits1(gb); | |
1018 | |||
1019 |
2/2✓ Branch 0 taken 477 times.
✓ Branch 1 taken 2482 times.
|
2959 | if (deblocking_filter_override_flag) { |
1020 | 477 | sh->disable_deblocking_filter_flag = get_bits1(gb); | |
1021 |
2/2✓ Branch 0 taken 357 times.
✓ Branch 1 taken 120 times.
|
477 | if (!sh->disable_deblocking_filter_flag) { |
1022 | 357 | int beta_offset_div2 = get_se_golomb(gb); | |
1023 | 357 | int tc_offset_div2 = get_se_golomb(gb) ; | |
1024 |
3/6✓ Branch 0 taken 357 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 357 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 357 times.
✗ Branch 5 not taken.
|
357 | if (beta_offset_div2 < -6 || beta_offset_div2 > 6 || |
1025 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 357 times.
|
357 | tc_offset_div2 < -6 || tc_offset_div2 > 6) { |
1026 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1027 | "Invalid deblock filter offsets: %d, %d\n", | ||
1028 | beta_offset_div2, tc_offset_div2); | ||
1029 | ✗ | return AVERROR_INVALIDDATA; | |
1030 | } | ||
1031 | 357 | sh->beta_offset = beta_offset_div2 * 2; | |
1032 | 357 | sh->tc_offset = tc_offset_div2 * 2; | |
1033 | } | ||
1034 | } else { | ||
1035 | 2482 | sh->disable_deblocking_filter_flag = pps->disable_dbf; | |
1036 | 2482 | sh->beta_offset = pps->beta_offset; | |
1037 | 2482 | sh->tc_offset = pps->tc_offset; | |
1038 | } | ||
1039 | } else { | ||
1040 | 17345 | sh->disable_deblocking_filter_flag = 0; | |
1041 | 17345 | sh->beta_offset = 0; | |
1042 | 17345 | sh->tc_offset = 0; | |
1043 | } | ||
1044 | |||
1045 |
2/2✓ Branch 0 taken 17736 times.
✓ Branch 1 taken 2568 times.
|
20304 | if (pps->seq_loop_filter_across_slices_enabled_flag && |
1046 |
2/2✓ Branch 0 taken 11732 times.
✓ Branch 1 taken 6004 times.
|
17736 | (sh->slice_sample_adaptive_offset_flag[0] || |
1047 |
2/2✓ Branch 0 taken 11714 times.
✓ Branch 1 taken 18 times.
|
11732 | sh->slice_sample_adaptive_offset_flag[1] || |
1048 |
2/2✓ Branch 0 taken 11651 times.
✓ Branch 1 taken 63 times.
|
11714 | !sh->disable_deblocking_filter_flag)) { |
1049 | 17673 | sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); | |
1050 | } else { | ||
1051 | 2631 | sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag; | |
1052 | } | ||
1053 | } | ||
1054 | |||
1055 | 28251 | sh->num_entry_point_offsets = 0; | |
1056 |
4/4✓ Branch 0 taken 25340 times.
✓ Branch 1 taken 2911 times.
✓ Branch 2 taken 4637 times.
✓ Branch 3 taken 20703 times.
|
28251 | if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) { |
1057 | 7548 | unsigned num_entry_point_offsets = get_ue_golomb_long(gb); | |
1058 | // It would be possible to bound this tighter but this here is simpler | ||
1059 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7548 times.
|
7548 | if (num_entry_point_offsets > get_bits_left(gb)) { |
1060 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets); | |
1061 | ✗ | return AVERROR_INVALIDDATA; | |
1062 | } | ||
1063 | |||
1064 | 7548 | sh->num_entry_point_offsets = num_entry_point_offsets; | |
1065 |
2/2✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 5474 times.
|
7548 | if (sh->num_entry_point_offsets > 0) { |
1066 | 2074 | int offset_len = get_ue_golomb_long(gb) + 1; | |
1067 | |||
1068 |
2/4✓ Branch 0 taken 2074 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2074 times.
|
2074 | if (offset_len < 1 || offset_len > 32) { |
1069 | ✗ | sh->num_entry_point_offsets = 0; | |
1070 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len); | |
1071 | ✗ | return AVERROR_INVALIDDATA; | |
1072 | } | ||
1073 | |||
1074 | 2074 | av_freep(&sh->entry_point_offset); | |
1075 | 2074 | av_freep(&sh->offset); | |
1076 | 2074 | av_freep(&sh->size); | |
1077 | 2074 | sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned)); | |
1078 | 2074 | sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
1079 | 2074 | sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
1080 |
3/6✓ Branch 0 taken 2074 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2074 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2074 times.
|
2074 | if (!sh->entry_point_offset || !sh->offset || !sh->size) { |
1081 | ✗ | sh->num_entry_point_offsets = 0; | |
1082 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n"); | |
1083 | ✗ | return AVERROR(ENOMEM); | |
1084 | } | ||
1085 |
2/2✓ Branch 0 taken 8942 times.
✓ Branch 1 taken 2074 times.
|
11016 | for (i = 0; i < sh->num_entry_point_offsets; i++) { |
1086 | 8942 | unsigned val = get_bits_long(gb, offset_len); | |
1087 | 8942 | sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size | |
1088 | } | ||
1089 | } | ||
1090 | } | ||
1091 | |||
1092 |
2/2✓ Branch 0 taken 2769 times.
✓ Branch 1 taken 25482 times.
|
28251 | if (pps->slice_header_extension_present_flag) { |
1093 | 2769 | unsigned int length = get_ue_golomb_long(gb); | |
1094 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2769 times.
|
2769 | if (length*8LL > get_bits_left(gb)) { |
1095 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n"); | |
1096 | ✗ | return AVERROR_INVALIDDATA; | |
1097 | } | ||
1098 |
2/2✓ Branch 0 taken 20292 times.
✓ Branch 1 taken 2769 times.
|
23061 | for (i = 0; i < length; i++) |
1099 | 20292 | skip_bits(gb, 8); // slice_header_extension_data_byte | |
1100 | } | ||
1101 | |||
1102 | 28251 | ret = get_bits1(gb); | |
1103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
|
28251 | if (!ret) { |
1104 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n"); | |
1105 | ✗ | return AVERROR_INVALIDDATA; | |
1106 | } | ||
1107 | 28251 | sh->data_offset = align_get_bits(gb) - gb->buffer; | |
1108 | |||
1109 | // Inferred parameters | ||
1110 | 28251 | sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta; | |
1111 |
1/2✓ Branch 0 taken 28251 times.
✗ Branch 1 not taken.
|
28251 | if (sh->slice_qp > 51 || |
1112 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
|
28251 | sh->slice_qp < -sps->qp_bd_offset) { |
1113 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1114 | "The slice_qp %d is outside the valid range " | ||
1115 | "[%d, 51].\n", | ||
1116 | ✗ | sh->slice_qp, | |
1117 | ✗ | -sps->qp_bd_offset); | |
1118 | ✗ | return AVERROR_INVALIDDATA; | |
1119 | } | ||
1120 | |||
1121 | 28251 | sh->slice_ctb_addr_rs = sh->slice_segment_addr; | |
1122 | |||
1123 |
2/2✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 20304 times.
|
28251 | if (sh->dependent_slice_segment_flag && |
1124 |
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])) { |
1125 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n"); | |
1126 | ✗ | return AVERROR_INVALIDDATA; | |
1127 | } | ||
1128 | |||
1129 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28251 times.
|
28251 | if (get_bits_left(gb) < 0) { |
1130 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1131 | ✗ | "Overread slice header by %d bits\n", -get_bits_left(gb)); | |
1132 | ✗ | return AVERROR_INVALIDDATA; | |
1133 | } | ||
1134 | |||
1135 | 28251 | return 0; | |
1136 | } | ||
1137 | |||
1138 | #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)]) | ||
1139 | |||
1140 | #define SET_SAO(elem, value) \ | ||
1141 | do { \ | ||
1142 | if (!sao_merge_up_flag && !sao_merge_left_flag) \ | ||
1143 | sao->elem = value; \ | ||
1144 | else if (sao_merge_left_flag) \ | ||
1145 | sao->elem = CTB(l->sao, rx-1, ry).elem; \ | ||
1146 | else if (sao_merge_up_flag) \ | ||
1147 | sao->elem = CTB(l->sao, rx, ry-1).elem; \ | ||
1148 | else \ | ||
1149 | sao->elem = 0; \ | ||
1150 | } while (0) | ||
1151 | |||
1152 | 1573720 | static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
1153 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1154 | int rx, int ry) | ||
1155 | { | ||
1156 | 1573720 | const HEVCContext *const s = lc->parent; | |
1157 | 1573720 | int sao_merge_left_flag = 0; | |
1158 | 1573720 | int sao_merge_up_flag = 0; | |
1159 | 1573720 | SAOParams *sao = &CTB(l->sao, rx, ry); | |
1160 | int c_idx, i; | ||
1161 | |||
1162 |
2/2✓ Branch 0 taken 863042 times.
✓ Branch 1 taken 710678 times.
|
1573720 | if (s->sh.slice_sample_adaptive_offset_flag[0] || |
1163 |
2/2✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 861398 times.
|
863042 | s->sh.slice_sample_adaptive_offset_flag[1]) { |
1164 |
2/2✓ Branch 0 taken 676534 times.
✓ Branch 1 taken 35788 times.
|
712322 | if (rx > 0) { |
1165 |
2/2✓ Branch 0 taken 667999 times.
✓ Branch 1 taken 8535 times.
|
676534 | if (lc->ctb_left_flag) |
1166 | 667999 | sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc); | |
1167 | } | ||
1168 |
4/4✓ Branch 0 taken 654917 times.
✓ Branch 1 taken 57405 times.
✓ Branch 2 taken 342185 times.
✓ Branch 3 taken 312732 times.
|
712322 | if (ry > 0 && !sao_merge_left_flag) { |
1169 |
2/2✓ Branch 0 taken 328816 times.
✓ Branch 1 taken 13369 times.
|
342185 | if (lc->ctb_up_flag) |
1170 | 328816 | sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc); | |
1171 | } | ||
1172 | } | ||
1173 | |||
1174 |
4/4✓ Branch 0 taken 6294688 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4721064 times.
✓ Branch 3 taken 1573720 times.
|
6294784 | for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) { |
1175 |
2/2✓ Branch 0 taken 1573720 times.
✓ Branch 1 taken 3147344 times.
|
4721064 | int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma : |
1176 | 3147344 | pps->log2_sao_offset_scale_chroma; | |
1177 | |||
1178 |
2/2✓ Branch 0 taken 3127126 times.
✓ Branch 1 taken 1593938 times.
|
4721064 | if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) { |
1179 | 3127126 | sao->type_idx[c_idx] = SAO_NOT_APPLIED; | |
1180 | 3127126 | continue; | |
1181 | } | ||
1182 | |||
1183 |
2/2✓ Branch 0 taken 441630 times.
✓ Branch 1 taken 1152308 times.
|
1593938 | if (c_idx == 2) { |
1184 | 441630 | sao->type_idx[2] = sao->type_idx[1]; | |
1185 | 441630 | sao->eo_class[2] = sao->eo_class[1]; | |
1186 | } else { | ||
1187 |
7/8✓ Branch 0 taken 1013958 times.
✓ Branch 1 taken 138350 times.
✓ Branch 2 taken 497980 times.
✓ Branch 3 taken 515978 times.
✓ Branch 5 taken 515978 times.
✓ Branch 6 taken 138350 times.
✓ Branch 7 taken 138350 times.
✗ Branch 8 not taken.
|
1152308 | SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc)); |
1188 | } | ||
1189 | |||
1190 |
2/2✓ Branch 0 taken 1057774 times.
✓ Branch 1 taken 536164 times.
|
1593938 | if (sao->type_idx[c_idx] == SAO_NOT_APPLIED) |
1191 | 1057774 | continue; | |
1192 | |||
1193 |
2/2✓ Branch 0 taken 2144656 times.
✓ Branch 1 taken 536164 times.
|
2680820 | for (i = 0; i < 4; i++) |
1194 |
7/8✓ Branch 0 taken 1766928 times.
✓ Branch 1 taken 377728 times.
✓ Branch 2 taken 909988 times.
✓ Branch 3 taken 856940 times.
✓ Branch 5 taken 856940 times.
✓ Branch 6 taken 377728 times.
✓ Branch 7 taken 377728 times.
✗ Branch 8 not taken.
|
2144656 | SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth)); |
1195 | |||
1196 |
2/2✓ Branch 0 taken 119646 times.
✓ Branch 1 taken 416518 times.
|
536164 | if (sao->type_idx[c_idx] == SAO_BAND) { |
1197 |
2/2✓ Branch 0 taken 478584 times.
✓ Branch 1 taken 119646 times.
|
598230 | for (i = 0; i < 4; i++) { |
1198 |
2/2✓ Branch 0 taken 358111 times.
✓ Branch 1 taken 120473 times.
|
478584 | if (sao->offset_abs[c_idx][i]) { |
1199 |
7/8✓ Branch 0 taken 332770 times.
✓ Branch 1 taken 25341 times.
✓ Branch 2 taken 246136 times.
✓ Branch 3 taken 86634 times.
✓ Branch 5 taken 86634 times.
✓ Branch 6 taken 25341 times.
✓ Branch 7 taken 25341 times.
✗ Branch 8 not taken.
|
358111 | SET_SAO(offset_sign[c_idx][i], |
1200 | ff_hevc_sao_offset_sign_decode(lc)); | ||
1201 | } else { | ||
1202 | 120473 | sao->offset_sign[c_idx][i] = 0; | |
1203 | } | ||
1204 | } | ||
1205 |
7/8✓ Branch 0 taken 109384 times.
✓ Branch 1 taken 10262 times.
✓ Branch 2 taken 79308 times.
✓ Branch 3 taken 30076 times.
✓ Branch 5 taken 30076 times.
✓ Branch 6 taken 10262 times.
✓ Branch 7 taken 10262 times.
✗ Branch 8 not taken.
|
119646 | SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc)); |
1206 |
2/2✓ Branch 0 taken 335144 times.
✓ Branch 1 taken 81374 times.
|
416518 | } else if (c_idx != 2) { |
1207 |
7/8✓ Branch 0 taken 267336 times.
✓ Branch 1 taken 67808 times.
✓ Branch 2 taken 115628 times.
✓ Branch 3 taken 151708 times.
✓ Branch 5 taken 151708 times.
✓ Branch 6 taken 67808 times.
✓ Branch 7 taken 67808 times.
✗ Branch 8 not taken.
|
335144 | SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc)); |
1208 | } | ||
1209 | |||
1210 | // Inferred parameters | ||
1211 | 536164 | sao->offset_val[c_idx][0] = 0; | |
1212 |
2/2✓ Branch 0 taken 2144656 times.
✓ Branch 1 taken 536164 times.
|
2680820 | for (i = 0; i < 4; i++) { |
1213 | 2144656 | sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i]; | |
1214 |
2/2✓ Branch 0 taken 1666072 times.
✓ Branch 1 taken 478584 times.
|
2144656 | if (sao->type_idx[c_idx] == SAO_EDGE) { |
1215 |
2/2✓ Branch 0 taken 833036 times.
✓ Branch 1 taken 833036 times.
|
1666072 | if (i > 1) |
1216 | 833036 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1217 |
2/2✓ Branch 0 taken 158152 times.
✓ Branch 1 taken 320432 times.
|
478584 | } else if (sao->offset_sign[c_idx][i]) { |
1218 | 158152 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1219 | } | ||
1220 | 2144656 | sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale; | |
1221 | } | ||
1222 | } | ||
1223 | 1573720 | } | |
1224 | |||
1225 | #undef SET_SAO | ||
1226 | #undef CTB | ||
1227 | |||
1228 | 384850 | static int hls_cross_component_pred(HEVCLocalContext *lc, int idx) | |
1229 | { | ||
1230 | 384850 | int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx); | |
1231 | |||
1232 |
2/2✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
|
384850 | if (log2_res_scale_abs_plus1 != 0) { |
1233 | 235843 | int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx); | |
1234 | 235843 | lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) * | |
1235 | 235843 | (1 - 2 * res_scale_sign_flag); | |
1236 | } else { | ||
1237 | 149007 | lc->tu.res_scale_val = 0; | |
1238 | } | ||
1239 | |||
1240 | |||
1241 | 384850 | return 0; | |
1242 | } | ||
1243 | |||
1244 | 16059232 | static int hls_transform_unit(HEVCLocalContext *lc, | |
1245 | const HEVCLayerContext *l, | ||
1246 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1247 | int x0, int y0, | ||
1248 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1249 | int log2_cb_size, int log2_trafo_size, | ||
1250 | int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr) | ||
1251 | { | ||
1252 | 16059232 | const HEVCContext *const s = lc->parent; | |
1253 | 16059232 | const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1]; | |
1254 | int i; | ||
1255 | |||
1256 |
2/2✓ Branch 0 taken 10175157 times.
✓ Branch 1 taken 5884075 times.
|
16059232 | if (lc->cu.pred_mode == MODE_INTRA) { |
1257 | 10175157 | int trafo_size = 1 << log2_trafo_size; | |
1258 | 10175157 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size); | |
1259 | |||
1260 | 10175157 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0); | |
1261 | } | ||
1262 | |||
1263 |
6/6✓ Branch 0 taken 5836378 times.
✓ Branch 1 taken 10222854 times.
✓ Branch 2 taken 5189985 times.
✓ Branch 3 taken 646393 times.
✓ Branch 4 taken 4745748 times.
✓ Branch 5 taken 444237 times.
|
16059232 | if (cbf_luma || cbf_cb[0] || cbf_cr[0] || |
1264 |
6/6✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4589981 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
|
16121046 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1265 | 11375299 | int scan_idx = SCAN_DIAG; | |
1266 | 11375299 | int scan_idx_c = SCAN_DIAG; | |
1267 |
4/4✓ Branch 0 taken 7663737 times.
✓ Branch 1 taken 3711562 times.
✓ Branch 2 taken 6115356 times.
✓ Branch 3 taken 1548381 times.
|
17490655 | int cbf_chroma = cbf_cb[0] || cbf_cr[0] || |
1268 |
2/2✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 5883646 times.
|
6115356 | (sps->chroma_format_idc == 2 && |
1269 |
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])); |
1270 | |||
1271 |
4/4✓ Branch 0 taken 2273880 times.
✓ Branch 1 taken 9101419 times.
✓ Branch 2 taken 661320 times.
✓ Branch 3 taken 1612560 times.
|
11375299 | if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) { |
1272 | 661320 | lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc); | |
1273 |
2/2✓ Branch 0 taken 374341 times.
✓ Branch 1 taken 286979 times.
|
661320 | if (lc->tu.cu_qp_delta != 0) |
1274 |
2/2✓ Branch 1 taken 207150 times.
✓ Branch 2 taken 167191 times.
|
374341 | if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1) |
1275 | 207150 | lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta; | |
1276 | 661320 | lc->tu.is_cu_qp_delta_coded = 1; | |
1277 | |||
1278 |
2/2✓ Branch 0 taken 661319 times.
✓ Branch 1 taken 1 times.
|
661320 | if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) || |
1279 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 661319 times.
|
661319 | lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) { |
1280 | 1 | av_log(s->avctx, AV_LOG_ERROR, | |
1281 | "The cu_qp_delta %d is outside the valid range " | ||
1282 | "[%d, %d].\n", | ||
1283 | lc->tu.cu_qp_delta, | ||
1284 | 1 | -(26 + sps->qp_bd_offset / 2), | |
1285 | 1 | (25 + sps->qp_bd_offset / 2)); | |
1286 | 1 | return AVERROR_INVALIDDATA; | |
1287 | } | ||
1288 | |||
1289 | 661319 | ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size); | |
1290 | } | ||
1291 | |||
1292 |
4/4✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 10483347 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
|
11375298 | if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma && |
1293 |
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) { |
1294 | 266275 | int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc); | |
1295 |
2/2✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
|
266275 | if (cu_chroma_qp_offset_flag) { |
1296 | 48966 | int cu_chroma_qp_offset_idx = 0; | |
1297 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
|
48966 | if (pps->chroma_qp_offset_list_len_minus1 > 0) { |
1298 | ✗ | cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1); | |
1299 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1300 | "cu_chroma_qp_offset_idx not yet tested.\n"); | ||
1301 | } | ||
1302 | 48966 | lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1303 | 48966 | lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1304 | } else { | ||
1305 | 217309 | lc->tu.cu_qp_offset_cb = 0; | |
1306 | 217309 | lc->tu.cu_qp_offset_cr = 0; | |
1307 | } | ||
1308 | 266275 | lc->tu.is_cu_chroma_qp_offset_coded = 1; | |
1309 | } | ||
1310 | |||
1311 |
4/4✓ Branch 0 taken 7486771 times.
✓ Branch 1 taken 3888527 times.
✓ Branch 2 taken 6500521 times.
✓ Branch 3 taken 986250 times.
|
11375298 | if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) { |
1312 |
2/2✓ Branch 0 taken 4329402 times.
✓ Branch 1 taken 2171119 times.
|
6500521 | if (lc->tu.intra_pred_mode >= 6 && |
1313 |
2/2✓ Branch 0 taken 1551675 times.
✓ Branch 1 taken 2777727 times.
|
4329402 | lc->tu.intra_pred_mode <= 14) { |
1314 | 1551675 | scan_idx = SCAN_VERT; | |
1315 |
2/2✓ Branch 0 taken 2142003 times.
✓ Branch 1 taken 2806843 times.
|
4948846 | } else if (lc->tu.intra_pred_mode >= 22 && |
1316 |
2/2✓ Branch 0 taken 1802346 times.
✓ Branch 1 taken 339657 times.
|
2142003 | lc->tu.intra_pred_mode <= 30) { |
1317 | 1802346 | scan_idx = SCAN_HORIZ; | |
1318 | } | ||
1319 | |||
1320 |
2/2✓ Branch 0 taken 3889316 times.
✓ Branch 1 taken 2611205 times.
|
6500521 | if (lc->tu.intra_pred_mode_c >= 6 && |
1321 |
2/2✓ Branch 0 taken 1463056 times.
✓ Branch 1 taken 2426260 times.
|
3889316 | lc->tu.intra_pred_mode_c <= 14) { |
1322 | 1463056 | scan_idx_c = SCAN_VERT; | |
1323 |
2/2✓ Branch 0 taken 2034714 times.
✓ Branch 1 taken 3002751 times.
|
5037465 | } else if (lc->tu.intra_pred_mode_c >= 22 && |
1324 |
2/2✓ Branch 0 taken 1705423 times.
✓ Branch 1 taken 329291 times.
|
2034714 | lc->tu.intra_pred_mode_c <= 30) { |
1325 | 1705423 | scan_idx_c = SCAN_HORIZ; | |
1326 | } | ||
1327 | } | ||
1328 | |||
1329 | 11375298 | lc->tu.cross_pf = 0; | |
1330 | |||
1331 |
2/2✓ Branch 0 taken 10222853 times.
✓ Branch 1 taken 1152445 times.
|
11375298 | if (cbf_luma) |
1332 | 10222853 | ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0); | |
1333 |
6/6✓ Branch 0 taken 11375106 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6287255 times.
✓ Branch 3 taken 5087851 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 6077692 times.
|
16672712 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
1334 | 5297414 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
1335 | 5297414 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
1336 |
4/4✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 4960573 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
|
5515230 | lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma && |
1337 |
2/2✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
|
217816 | (lc->cu.pred_mode == MODE_INTER || |
1338 |
2/2✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
|
168873 | (lc->tu.chroma_mode_c == 4))); |
1339 | |||
1340 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5104989 times.
|
5297414 | if (lc->tu.cross_pf) { |
1341 | 192425 | hls_cross_component_pred(lc, 0); | |
1342 | } | ||
1343 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9688424 times.
✓ Branch 2 taken 5750616 times.
✓ Branch 3 taken 5297414 times.
|
11048030 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1344 |
2/2✓ Branch 0 taken 3176481 times.
✓ Branch 1 taken 2574135 times.
|
5750616 | if (lc->cu.pred_mode == MODE_INTRA) { |
1345 | 3176481 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
1346 | 3176481 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1347 | 3176481 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1); | |
1348 | } | ||
1349 |
2/2✓ Branch 0 taken 1560246 times.
✓ Branch 1 taken 4190370 times.
|
5750616 | if (cbf_cb[i]) |
1350 | 1560246 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
1351 | log2_trafo_size_c, scan_idx_c, 1); | ||
1352 | else | ||
1353 |
2/2✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 4150712 times.
|
4190370 | if (lc->tu.cross_pf) { |
1354 | 39658 | ptrdiff_t stride = s->cur_frame->f->linesize[1]; | |
1355 | 39658 | int hshift = sps->hshift[1]; | |
1356 | 39658 | int vshift = sps->vshift[1]; | |
1357 | 39658 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1358 | 39658 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1359 | 39658 | int size = 1 << log2_trafo_size_c; | |
1360 | |||
1361 | 39658 | uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride + | |
1362 | 39658 | ((x0 >> hshift) << sps->pixel_shift)]; | |
1363 |
2/2✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
|
1871162 | for (i = 0; i < (size * size); i++) { |
1364 | 1831504 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1365 | } | ||
1366 | 39658 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1367 | } | ||
1368 | } | ||
1369 | |||
1370 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 5104989 times.
|
5297414 | if (lc->tu.cross_pf) { |
1371 | 192425 | hls_cross_component_pred(lc, 1); | |
1372 | } | ||
1373 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 9688424 times.
✓ Branch 2 taken 5750616 times.
✓ Branch 3 taken 5297414 times.
|
11048030 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1374 |
2/2✓ Branch 0 taken 3176481 times.
✓ Branch 1 taken 2574135 times.
|
5750616 | if (lc->cu.pred_mode == MODE_INTRA) { |
1375 | 3176481 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
1376 | 3176481 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1377 | 3176481 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2); | |
1378 | } | ||
1379 |
2/2✓ Branch 0 taken 1708790 times.
✓ Branch 1 taken 4041826 times.
|
5750616 | if (cbf_cr[i]) |
1380 | 1708790 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
1381 | log2_trafo_size_c, scan_idx_c, 2); | ||
1382 | else | ||
1383 |
2/2✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 3965902 times.
|
4041826 | if (lc->tu.cross_pf) { |
1384 | 75924 | ptrdiff_t stride = s->cur_frame->f->linesize[2]; | |
1385 | 75924 | int hshift = sps->hshift[2]; | |
1386 | 75924 | int vshift = sps->vshift[2]; | |
1387 | 75924 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1388 | 75924 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1389 | 75924 | int size = 1 << log2_trafo_size_c; | |
1390 | |||
1391 | 75924 | uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride + | |
1392 | 75924 | ((x0 >> hshift) << sps->pixel_shift)]; | |
1393 |
2/2✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
|
3691476 | for (i = 0; i < (size * size); i++) { |
1394 | 3615552 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1395 | } | ||
1396 | 75924 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1397 | } | ||
1398 | } | ||
1399 |
4/4✓ Branch 0 taken 6077692 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1561978 times.
✓ Branch 3 taken 4515714 times.
|
6077884 | } else if (sps->chroma_format_idc && blk_idx == 3) { |
1400 | 1561978 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1401 | 1561978 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
1402 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2790218 times.
✓ Branch 2 taken 1728847 times.
✓ Branch 3 taken 1561978 times.
|
3290825 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1403 |
2/2✓ Branch 0 taken 1242036 times.
✓ Branch 1 taken 486811 times.
|
1728847 | if (lc->cu.pred_mode == MODE_INTRA) { |
1404 | 1242036 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
1405 | 1242036 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1406 | 1242036 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1); | |
1407 | } | ||
1408 |
2/2✓ Branch 0 taken 652423 times.
✓ Branch 1 taken 1076424 times.
|
1728847 | if (cbf_cb[i]) |
1409 | 652423 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
1410 | log2_trafo_size, scan_idx_c, 1); | ||
1411 | } | ||
1412 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2790218 times.
✓ Branch 2 taken 1728847 times.
✓ Branch 3 taken 1561978 times.
|
3290825 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1413 |
2/2✓ Branch 0 taken 1242036 times.
✓ Branch 1 taken 486811 times.
|
1728847 | if (lc->cu.pred_mode == MODE_INTRA) { |
1414 | 1242036 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
1415 | 1242036 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1416 | 1242036 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2); | |
1417 | } | ||
1418 |
2/2✓ Branch 0 taken 741276 times.
✓ Branch 1 taken 987571 times.
|
1728847 | if (cbf_cr[i]) |
1419 | 741276 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
1420 | log2_trafo_size, scan_idx_c, 2); | ||
1421 | } | ||
1422 | } | ||
1423 |
3/4✓ Branch 0 taken 4683933 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2688385 times.
✓ Branch 3 taken 1995548 times.
|
4683933 | } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) { |
1424 |
4/4✓ Branch 0 taken 1650024 times.
✓ Branch 1 taken 1038361 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1589436 times.
|
3787334 | if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) { |
1425 | 1098949 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
1426 | 1098949 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
1427 | 1098949 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v, | |
1428 | 1098949 | sps->log2_ctb_size); | |
1429 | 1098949 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1); | |
1430 | 1098949 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2); | |
1431 |
2/2✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 1086482 times.
|
1098949 | if (sps->chroma_format_idc == 2) { |
1432 | 12467 | ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c), | |
1433 | 12467 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1434 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1); | |
1435 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2); | |
1436 | } | ||
1437 |
2/2✓ Branch 0 taken 360443 times.
✓ Branch 1 taken 1228993 times.
|
1589436 | } else if (blk_idx == 3) { |
1438 | 360443 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1439 | 360443 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
1440 | 360443 | ff_hevc_set_neighbour_available(lc, xBase, yBase, | |
1441 | 360443 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1442 | 360443 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1); | |
1443 | 360443 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2); | |
1444 |
2/2✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 356247 times.
|
360443 | if (sps->chroma_format_idc == 2) { |
1445 | 4196 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size), | |
1446 | 4196 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
1447 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1); | |
1448 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2); | |
1449 | } | ||
1450 | } | ||
1451 | } | ||
1452 | |||
1453 | 16059231 | return 0; | |
1454 | } | ||
1455 | |||
1456 | 403332 | static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps, | |
1457 | int x0, int y0, int log2_cb_size) | ||
1458 | { | ||
1459 | 403332 | int cb_size = 1 << log2_cb_size; | |
1460 | 403332 | int log2_min_pu_size = sps->log2_min_pu_size; | |
1461 | |||
1462 | 403332 | int min_pu_width = sps->min_pu_width; | |
1463 | 403332 | int x_end = FFMIN(x0 + cb_size, sps->width); | |
1464 | 403332 | int y_end = FFMIN(y0 + cb_size, sps->height); | |
1465 | int i, j; | ||
1466 | |||
1467 |
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++) |
1468 |
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++) |
1469 | 1073856 | is_pcm[i + j * min_pu_width] = 2; | |
1470 | 403332 | } | |
1471 | |||
1472 | 19346139 | static int hls_transform_tree(HEVCLocalContext *lc, | |
1473 | const HEVCLayerContext *l, | ||
1474 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1475 | int x0, int y0, | ||
1476 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1477 | int log2_cb_size, int log2_trafo_size, | ||
1478 | int trafo_depth, int blk_idx, | ||
1479 | const int *base_cbf_cb, const int *base_cbf_cr) | ||
1480 | { | ||
1481 | 19346139 | const HEVCContext *const s = lc->parent; | |
1482 | uint8_t split_transform_flag; | ||
1483 | int cbf_cb[2]; | ||
1484 | int cbf_cr[2]; | ||
1485 | int ret; | ||
1486 | |||
1487 | 19346139 | cbf_cb[0] = base_cbf_cb[0]; | |
1488 | 19346139 | cbf_cb[1] = base_cbf_cb[1]; | |
1489 | 19346139 | cbf_cr[0] = base_cbf_cr[0]; | |
1490 | 19346139 | cbf_cr[1] = base_cbf_cr[1]; | |
1491 | |||
1492 |
2/2✓ Branch 0 taken 6547826 times.
✓ Branch 1 taken 12798313 times.
|
19346139 | if (lc->cu.intra_split_flag) { |
1493 |
2/2✓ Branch 0 taken 4936200 times.
✓ Branch 1 taken 1611626 times.
|
6547826 | if (trafo_depth == 1) { |
1494 | 4936200 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx]; | |
1495 |
2/2✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4800796 times.
|
4936200 | if (sps->chroma_format_idc == 3) { |
1496 | 135404 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx]; | |
1497 | 135404 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx]; | |
1498 | } else { | ||
1499 | 4800796 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1500 | 4800796 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1501 | } | ||
1502 | } | ||
1503 | } else { | ||
1504 | 12798313 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0]; | |
1505 | 12798313 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1506 | 12798313 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1507 | } | ||
1508 | |||
1509 |
2/2✓ Branch 0 taken 19221944 times.
✓ Branch 1 taken 124195 times.
|
19346139 | if (log2_trafo_size <= sps->log2_max_trafo_size && |
1510 |
2/2✓ Branch 0 taken 10212060 times.
✓ Branch 1 taken 9009884 times.
|
19221944 | log2_trafo_size > sps->log2_min_tb_size && |
1511 |
2/2✓ Branch 0 taken 8594084 times.
✓ Branch 1 taken 1617976 times.
|
10212060 | trafo_depth < lc->cu.max_trafo_depth && |
1512 |
4/4✓ Branch 0 taken 1717275 times.
✓ Branch 1 taken 6876809 times.
✓ Branch 2 taken 490612 times.
✓ Branch 3 taken 1226663 times.
|
8594084 | !(lc->cu.intra_split_flag && trafo_depth == 0)) { |
1513 | 7367421 | split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size); | |
1514 | } else { | ||
1515 | 25638351 | int inter_split = sps->max_transform_hierarchy_depth_inter == 0 && | |
1516 |
2/2✓ Branch 0 taken 836848 times.
✓ Branch 1 taken 844067 times.
|
1680915 | lc->cu.pred_mode == MODE_INTER && |
1517 |
6/6✓ Branch 0 taken 1680915 times.
✓ Branch 1 taken 10297803 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 161299 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
|
13659633 | lc->cu.part_mode != PART_2Nx2N && |
1518 | trafo_depth == 0; | ||
1519 | |||
1520 | 11978718 | split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size || | |
1521 |
8/8✓ Branch 0 taken 11854523 times.
✓ Branch 1 taken 124195 times.
✓ Branch 2 taken 6049167 times.
✓ Branch 3 taken 5805356 times.
✓ Branch 4 taken 4822504 times.
✓ Branch 5 taken 1226663 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10509222 times.
|
11978718 | (lc->cu.intra_split_flag && trafo_depth == 0) || |
1522 | inter_split; | ||
1523 | } | ||
1524 | |||
1525 |
6/6✓ Branch 0 taken 19345947 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8881804 times.
✓ Branch 3 taken 10464143 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8567388 times.
|
19346139 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
1526 |
4/4✓ Branch 0 taken 4580240 times.
✓ Branch 1 taken 6198319 times.
✓ Branch 2 taken 1259672 times.
✓ Branch 3 taken 3320568 times.
|
10778559 | if (trafo_depth == 0 || cbf_cb[0]) { |
1527 | 7457991 | cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1528 |
6/6✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 6859725 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
|
7457991 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1529 | 526996 | cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1530 | } | ||
1531 | } | ||
1532 | |||
1533 |
4/4✓ Branch 0 taken 4580240 times.
✓ Branch 1 taken 6198319 times.
✓ Branch 2 taken 1221820 times.
✓ Branch 3 taken 3358420 times.
|
10778559 | if (trafo_depth == 0 || cbf_cr[0]) { |
1534 | 7420139 | cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1535 |
6/6✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6674833 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
|
7420139 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1536 | 661961 | cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
1537 | } | ||
1538 | } | ||
1539 | } | ||
1540 | |||
1541 |
2/2✓ Branch 0 taken 3286907 times.
✓ Branch 1 taken 16059232 times.
|
19346139 | if (split_transform_flag) { |
1542 | 3286907 | const int trafo_size_split = 1 << (log2_trafo_size - 1); | |
1543 | 3286907 | const int x1 = x0 + trafo_size_split; | |
1544 | 3286907 | const int y1 = y0 + trafo_size_split; | |
1545 | |||
1546 | #define SUBDIVIDE(x, y, idx) \ | ||
1547 | do { \ | ||
1548 | ret = hls_transform_tree(lc, l, pps, sps, \ | ||
1549 | x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \ | ||
1550 | log2_trafo_size - 1, trafo_depth + 1, idx, \ | ||
1551 | cbf_cb, cbf_cr); \ | ||
1552 | if (ret < 0) \ | ||
1553 | return ret; \ | ||
1554 | } while (0) | ||
1555 | |||
1556 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
|
3286907 | SUBDIVIDE(x0, y0, 0); |
1557 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
|
3286907 | SUBDIVIDE(x1, y0, 1); |
1558 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
|
3286907 | SUBDIVIDE(x0, y1, 2); |
1559 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3286907 times.
|
3286907 | SUBDIVIDE(x1, y1, 3); |
1560 | |||
1561 | #undef SUBDIVIDE | ||
1562 | } else { | ||
1563 | 16059232 | int min_tu_size = 1 << sps->log2_min_tb_size; | |
1564 | 16059232 | int log2_min_tu_size = sps->log2_min_tb_size; | |
1565 | 16059232 | int min_tu_width = sps->min_tb_width; | |
1566 | 16059232 | int cbf_luma = 1; | |
1567 | |||
1568 |
4/4✓ Branch 0 taken 5884075 times.
✓ Branch 1 taken 10175157 times.
✓ Branch 2 taken 1105689 times.
✓ Branch 3 taken 4778386 times.
|
16059232 | if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 || |
1569 |
4/4✓ Branch 0 taken 909623 times.
✓ Branch 1 taken 196066 times.
✓ Branch 2 taken 779586 times.
✓ Branch 3 taken 130037 times.
|
1105689 | cbf_cb[0] || cbf_cr[0] || |
1570 |
6/6✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 754910 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
|
779586 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1571 | 15292292 | cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth); | |
1572 | } | ||
1573 | |||
1574 | 16059232 | ret = hls_transform_unit(lc, l, pps, sps, | |
1575 | x0, y0, xBase, yBase, cb_xBase, cb_yBase, | ||
1576 | log2_cb_size, log2_trafo_size, | ||
1577 | blk_idx, cbf_luma, cbf_cb, cbf_cr); | ||
1578 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16059231 times.
|
16059232 | if (ret < 0) |
1579 | 1 | return ret; | |
1580 | // TODO: store cbf_luma somewhere else | ||
1581 |
2/2✓ Branch 0 taken 10222853 times.
✓ Branch 1 taken 5836378 times.
|
16059231 | if (cbf_luma) { |
1582 | int i, j; | ||
1583 |
2/2✓ Branch 0 taken 21688627 times.
✓ Branch 1 taken 10222853 times.
|
31911480 | for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size) |
1584 |
2/2✓ Branch 0 taken 81671243 times.
✓ Branch 1 taken 21688627 times.
|
103359870 | for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) { |
1585 | 81671243 | int x_tu = (x0 + j) >> log2_min_tu_size; | |
1586 | 81671243 | int y_tu = (y0 + i) >> log2_min_tu_size; | |
1587 | 81671243 | l->cbf_luma[y_tu * min_tu_width + x_tu] = 1; | |
1588 | } | ||
1589 | } | ||
1590 |
2/2✓ Branch 0 taken 15526411 times.
✓ Branch 1 taken 532820 times.
|
16059231 | if (!s->sh.disable_deblocking_filter_flag) { |
1591 | 15526411 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size); | |
1592 |
2/2✓ Branch 0 taken 409146 times.
✓ Branch 1 taken 15117265 times.
|
15526411 | if (pps->transquant_bypass_enable_flag && |
1593 |
2/2✓ Branch 0 taken 311137 times.
✓ Branch 1 taken 98009 times.
|
409146 | lc->cu.cu_transquant_bypass_flag) |
1594 | 311137 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size); | |
1595 | } | ||
1596 | } | ||
1597 | 19346138 | return 0; | |
1598 | } | ||
1599 | |||
1600 | 12433 | static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
1601 | const HEVCPPS *pps, int x0, int y0, int log2_cb_size) | ||
1602 | { | ||
1603 | 12433 | const HEVCContext *const s = lc->parent; | |
1604 | 12433 | const HEVCSPS *const sps = pps->sps; | |
1605 | GetBitContext gb; | ||
1606 | 12433 | int cb_size = 1 << log2_cb_size; | |
1607 | 12433 | ptrdiff_t stride0 = s->cur_frame->f->linesize[0]; | |
1608 | 12433 | ptrdiff_t stride1 = s->cur_frame->f->linesize[1]; | |
1609 | 12433 | ptrdiff_t stride2 = s->cur_frame->f->linesize[2]; | |
1610 | 12433 | uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)]; | |
1611 | 12433 | uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)]; | |
1612 | 12433 | uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)]; | |
1613 | |||
1614 | 12433 | int length = cb_size * cb_size * sps->pcm.bit_depth + | |
1615 | 12433 | (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) + | |
1616 | 12433 | ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) * | |
1617 | 12433 | sps->pcm.bit_depth_chroma; | |
1618 | 12433 | const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3); | |
1619 | int ret; | ||
1620 | |||
1621 |
2/2✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
|
12433 | if (!s->sh.disable_deblocking_filter_flag) |
1622 | 6937 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
1623 | |||
1624 | 12433 | ret = init_get_bits(&gb, pcm, length); | |
1625 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
|
12433 | if (ret < 0) |
1626 | ✗ | return ret; | |
1627 | |||
1628 | 12433 | s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth); | |
1629 |
1/2✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
|
12433 | if (sps->chroma_format_idc) { |
1630 | 12433 | s->hevcdsp.put_pcm(dst1, stride1, | |
1631 | 12433 | cb_size >> sps->hshift[1], | |
1632 | 12433 | cb_size >> sps->vshift[1], | |
1633 | 12433 | &gb, sps->pcm.bit_depth_chroma); | |
1634 | 12433 | s->hevcdsp.put_pcm(dst2, stride2, | |
1635 | 12433 | cb_size >> sps->hshift[2], | |
1636 | 12433 | cb_size >> sps->vshift[2], | |
1637 | 12433 | &gb, sps->pcm.bit_depth_chroma); | |
1638 | } | ||
1639 | |||
1640 | 12433 | return 0; | |
1641 | } | ||
1642 | |||
1643 | /** | ||
1644 | * 8.5.3.2.2.1 Luma sample unidirectional interpolation process | ||
1645 | * | ||
1646 | * @param s HEVC decoding context | ||
1647 | * @param dst target buffer for block data at block position | ||
1648 | * @param dststride stride of the dst buffer | ||
1649 | * @param ref reference picture buffer at origin (0, 0) | ||
1650 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1651 | * @param x_off horizontal position of block from origin (0, 0) | ||
1652 | * @param y_off vertical position of block from origin (0, 0) | ||
1653 | * @param block_w width of block | ||
1654 | * @param block_h height of block | ||
1655 | * @param luma_weight weighting factor applied to the luma prediction | ||
1656 | * @param luma_offset additive offset applied to the luma prediction value | ||
1657 | */ | ||
1658 | |||
1659 | 5095556 | static void luma_mc_uni(HEVCLocalContext *lc, | |
1660 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1661 | uint8_t *dst, ptrdiff_t dststride, | ||
1662 | const AVFrame *ref, const Mv *mv, int x_off, int y_off, | ||
1663 | int block_w, int block_h, int luma_weight, int luma_offset) | ||
1664 | { | ||
1665 | 5095556 | const HEVCContext *const s = lc->parent; | |
1666 | 5095556 | const uint8_t *src = ref->data[0]; | |
1667 | 5095556 | ptrdiff_t srcstride = ref->linesize[0]; | |
1668 | 5095556 | int pic_width = sps->width; | |
1669 | 5095556 | int pic_height = sps->height; | |
1670 | 5095556 | int mx = mv->x & 3; | |
1671 | 5095556 | int my = mv->y & 3; | |
1672 |
4/4✓ Branch 0 taken 2067314 times.
✓ Branch 1 taken 3028242 times.
✓ Branch 2 taken 2013138 times.
✓ Branch 3 taken 54176 times.
|
10136936 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1673 |
4/4✓ Branch 0 taken 3028242 times.
✓ Branch 1 taken 2013138 times.
✓ Branch 2 taken 70226 times.
✓ Branch 3 taken 2958016 times.
|
5041380 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1674 | 5095556 | int idx = hevc_pel_weight[block_w]; | |
1675 | |||
1676 | 5095556 | x_off += mv->x >> 2; | |
1677 | 5095556 | y_off += mv->y >> 2; | |
1678 | 5095556 | src += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
1679 | |||
1680 |
4/4✓ Branch 0 taken 5036595 times.
✓ Branch 1 taken 58961 times.
✓ Branch 2 taken 4929898 times.
✓ Branch 3 taken 106697 times.
|
5095556 | if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER || |
1681 |
2/2✓ Branch 0 taken 4864534 times.
✓ Branch 1 taken 65364 times.
|
4929898 | x_off >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1682 |
2/2✓ Branch 0 taken 4659765 times.
✓ Branch 1 taken 204769 times.
|
4864534 | y_off >= pic_height - block_h - QPEL_EXTRA_AFTER || |
1683 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4659765 times.
|
4659765 | ref == s->cur_frame->f) { |
1684 | 435791 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1685 | 435791 | int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1686 | 435791 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1687 | |||
1688 | 435791 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset, | |
1689 | edge_emu_stride, srcstride, | ||
1690 | block_w + QPEL_EXTRA, | ||
1691 | block_h + QPEL_EXTRA, | ||
1692 | x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE, | ||
1693 | pic_width, pic_height); | ||
1694 | 435791 | src = lc->edge_emu_buffer + buf_offset; | |
1695 | 435791 | srcstride = edge_emu_stride; | |
1696 | } | ||
1697 | |||
1698 |
2/2✓ Branch 0 taken 4971154 times.
✓ Branch 1 taken 124402 times.
|
5095556 | if (!weight_flag) |
1699 | 4971154 | s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1700 | block_h, mx, my, block_w); | ||
1701 | else | ||
1702 | 124402 | s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1703 | 124402 | block_h, s->sh.luma_log2_weight_denom, | |
1704 | luma_weight, luma_offset, mx, my, block_w); | ||
1705 | 5095556 | } | |
1706 | |||
1707 | /** | ||
1708 | * 8.5.3.2.2.1 Luma sample bidirectional interpolation process | ||
1709 | * | ||
1710 | * @param s HEVC decoding context | ||
1711 | * @param dst target buffer for block data at block position | ||
1712 | * @param dststride stride of the dst buffer | ||
1713 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1714 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1715 | * @param x_off horizontal position of block from origin (0, 0) | ||
1716 | * @param y_off vertical position of block from origin (0, 0) | ||
1717 | * @param block_w width of block | ||
1718 | * @param block_h height of block | ||
1719 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1720 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1721 | * @param current_mv current motion vector structure | ||
1722 | */ | ||
1723 | 3960193 | static void luma_mc_bi(HEVCLocalContext *lc, | |
1724 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1725 | uint8_t *dst, ptrdiff_t dststride, | ||
1726 | const AVFrame *ref0, const Mv *mv0, int x_off, int y_off, | ||
1727 | int block_w, int block_h, const AVFrame *ref1, | ||
1728 | const Mv *mv1, struct MvField *current_mv) | ||
1729 | { | ||
1730 | 3960193 | const HEVCContext *const s = lc->parent; | |
1731 | 3960193 | ptrdiff_t src0stride = ref0->linesize[0]; | |
1732 | 3960193 | ptrdiff_t src1stride = ref1->linesize[0]; | |
1733 | 3960193 | int pic_width = sps->width; | |
1734 | 3960193 | int pic_height = sps->height; | |
1735 | 3960193 | int mx0 = mv0->x & 3; | |
1736 | 3960193 | int my0 = mv0->y & 3; | |
1737 | 3960193 | int mx1 = mv1->x & 3; | |
1738 | 3960193 | int my1 = mv1->y & 3; | |
1739 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3960193 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7920386 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1740 |
3/4✓ Branch 0 taken 3960193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68518 times.
✓ Branch 3 taken 3891675 times.
|
3960193 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1741 | 3960193 | int x_off0 = x_off + (mv0->x >> 2); | |
1742 | 3960193 | int y_off0 = y_off + (mv0->y >> 2); | |
1743 | 3960193 | int x_off1 = x_off + (mv1->x >> 2); | |
1744 | 3960193 | int y_off1 = y_off + (mv1->y >> 2); | |
1745 | 3960193 | int idx = hevc_pel_weight[block_w]; | |
1746 | |||
1747 | 3960193 | const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift); | |
1748 | 3960193 | const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift); | |
1749 | |||
1750 |
4/4✓ Branch 0 taken 3903009 times.
✓ Branch 1 taken 57184 times.
✓ Branch 2 taken 3796710 times.
✓ Branch 3 taken 106299 times.
|
3960193 | if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER || |
1751 |
2/2✓ Branch 0 taken 3728624 times.
✓ Branch 1 taken 68086 times.
|
3796710 | x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1752 |
2/2✓ Branch 0 taken 208159 times.
✓ Branch 1 taken 3520465 times.
|
3728624 | y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1753 | 439728 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1754 | 439728 | int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1755 | 439728 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1756 | |||
1757 | 439728 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset, | |
1758 | edge_emu_stride, src0stride, | ||
1759 | block_w + QPEL_EXTRA, | ||
1760 | block_h + QPEL_EXTRA, | ||
1761 | x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE, | ||
1762 | pic_width, pic_height); | ||
1763 | 439728 | src0 = lc->edge_emu_buffer + buf_offset; | |
1764 | 439728 | src0stride = edge_emu_stride; | |
1765 | } | ||
1766 | |||
1767 |
4/4✓ Branch 0 taken 3896806 times.
✓ Branch 1 taken 63387 times.
✓ Branch 2 taken 3791189 times.
✓ Branch 3 taken 105617 times.
|
3960193 | if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER || |
1768 |
2/2✓ Branch 0 taken 3721188 times.
✓ Branch 1 taken 70001 times.
|
3791189 | x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1769 |
2/2✓ Branch 0 taken 211344 times.
✓ Branch 1 taken 3509844 times.
|
3721188 | y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1770 | 450349 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1771 | 450349 | int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1772 | 450349 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
1773 | |||
1774 | 450349 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset, | |
1775 | edge_emu_stride, src1stride, | ||
1776 | block_w + QPEL_EXTRA, | ||
1777 | block_h + QPEL_EXTRA, | ||
1778 | x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE, | ||
1779 | pic_width, pic_height); | ||
1780 | 450349 | src1 = lc->edge_emu_buffer2 + buf_offset; | |
1781 | 450349 | src1stride = edge_emu_stride; | |
1782 | } | ||
1783 | |||
1784 | 3960193 | s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride, | |
1785 | block_h, mx0, my0, block_w); | ||
1786 |
2/2✓ Branch 0 taken 3891675 times.
✓ Branch 1 taken 68518 times.
|
3960193 | if (!weight_flag) |
1787 | 3891675 | s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1788 | block_h, mx1, my1, block_w); | ||
1789 | else | ||
1790 | 68518 | s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1791 | 68518 | block_h, s->sh.luma_log2_weight_denom, | |
1792 | 68518 | s->sh.luma_weight_l0[current_mv->ref_idx[0]], | |
1793 | 68518 | s->sh.luma_weight_l1[current_mv->ref_idx[1]], | |
1794 | 68518 | s->sh.luma_offset_l0[current_mv->ref_idx[0]], | |
1795 | 68518 | s->sh.luma_offset_l1[current_mv->ref_idx[1]], | |
1796 | mx1, my1, block_w); | ||
1797 | |||
1798 | 3960193 | } | |
1799 | |||
1800 | /** | ||
1801 | * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process | ||
1802 | * | ||
1803 | * @param s HEVC decoding context | ||
1804 | * @param dst1 target buffer for block data at block position (U plane) | ||
1805 | * @param dst2 target buffer for block data at block position (V plane) | ||
1806 | * @param dststride stride of the dst1 and dst2 buffers | ||
1807 | * @param ref reference picture buffer at origin (0, 0) | ||
1808 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1809 | * @param x_off horizontal position of block from origin (0, 0) | ||
1810 | * @param y_off vertical position of block from origin (0, 0) | ||
1811 | * @param block_w width of block | ||
1812 | * @param block_h height of block | ||
1813 | * @param chroma_weight weighting factor applied to the chroma prediction | ||
1814 | * @param chroma_offset additive offset applied to the chroma prediction value | ||
1815 | */ | ||
1816 | |||
1817 | 10191112 | static void chroma_mc_uni(HEVCLocalContext *lc, | |
1818 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1819 | uint8_t *dst0, | ||
1820 | ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist, | ||
1821 | int x_off, int y_off, int block_w, int block_h, | ||
1822 | const struct MvField *current_mv, int chroma_weight, int chroma_offset) | ||
1823 | { | ||
1824 | 10191112 | const HEVCContext *const s = lc->parent; | |
1825 | 10191112 | int pic_width = sps->width >> sps->hshift[1]; | |
1826 | 10191112 | int pic_height = sps->height >> sps->vshift[1]; | |
1827 | 10191112 | const Mv *mv = ¤t_mv->mv[reflist]; | |
1828 |
4/4✓ Branch 0 taken 4134628 times.
✓ Branch 1 taken 6056484 times.
✓ Branch 2 taken 4026276 times.
✓ Branch 3 taken 108352 times.
|
20273872 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1829 |
4/4✓ Branch 0 taken 6056484 times.
✓ Branch 1 taken 4026276 times.
✓ Branch 2 taken 140452 times.
✓ Branch 3 taken 5916032 times.
|
10082760 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1830 | 10191112 | int idx = hevc_pel_weight[block_w]; | |
1831 | 10191112 | int hshift = sps->hshift[1]; | |
1832 | 10191112 | int vshift = sps->vshift[1]; | |
1833 | 10191112 | intptr_t mx = av_zero_extend(mv->x, 2 + hshift); | |
1834 | 10191112 | intptr_t my = av_zero_extend(mv->y, 2 + vshift); | |
1835 | 10191112 | intptr_t _mx = mx << (1 - hshift); | |
1836 | 10191112 | intptr_t _my = my << (1 - vshift); | |
1837 |
2/4✓ Branch 0 taken 10191112 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10191112 times.
|
10191112 | int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2]; |
1838 | |||
1839 | 10191112 | x_off += mv->x >> (2 + hshift); | |
1840 | 10191112 | y_off += mv->y >> (2 + vshift); | |
1841 | 10191112 | src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
1842 | |||
1843 |
4/4✓ Branch 0 taken 10083642 times.
✓ Branch 1 taken 107470 times.
✓ Branch 2 taken 9870108 times.
✓ Branch 3 taken 213534 times.
|
10191112 | if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER || |
1844 |
2/2✓ Branch 0 taken 9739388 times.
✓ Branch 1 taken 130720 times.
|
9870108 | x_off >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1845 |
3/4✓ Branch 0 taken 9329792 times.
✓ Branch 1 taken 409596 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9329792 times.
|
9739388 | y_off >= pic_height - block_h - EPEL_EXTRA_AFTER || |
1846 | emu) { | ||
1847 | 861320 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
1848 | 861320 | int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift)); | |
1849 | 861320 | int buf_offset0 = EPEL_EXTRA_BEFORE * | |
1850 | 861320 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
1851 | 861320 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0, | |
1852 | edge_emu_stride, srcstride, | ||
1853 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1854 | x_off - EPEL_EXTRA_BEFORE, | ||
1855 | y_off - EPEL_EXTRA_BEFORE, | ||
1856 | pic_width, pic_height); | ||
1857 | |||
1858 | 861320 | src0 = lc->edge_emu_buffer + buf_offset0; | |
1859 | 861320 | srcstride = edge_emu_stride; | |
1860 | } | ||
1861 |
2/2✓ Branch 0 taken 9942308 times.
✓ Branch 1 taken 248804 times.
|
10191112 | if (!weight_flag) |
1862 | 9942308 | s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1863 | block_h, _mx, _my, block_w); | ||
1864 | else | ||
1865 | 248804 | s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1866 | 248804 | block_h, s->sh.chroma_log2_weight_denom, | |
1867 | chroma_weight, chroma_offset, _mx, _my, block_w); | ||
1868 | 10191112 | } | |
1869 | |||
1870 | /** | ||
1871 | * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process | ||
1872 | * | ||
1873 | * @param s HEVC decoding context | ||
1874 | * @param dst target buffer for block data at block position | ||
1875 | * @param dststride stride of the dst buffer | ||
1876 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1877 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1878 | * @param x_off horizontal position of block from origin (0, 0) | ||
1879 | * @param y_off vertical position of block from origin (0, 0) | ||
1880 | * @param block_w width of block | ||
1881 | * @param block_h height of block | ||
1882 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1883 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1884 | * @param current_mv current motion vector structure | ||
1885 | * @param cidx chroma component(cb, cr) | ||
1886 | */ | ||
1887 | 7920386 | static void chroma_mc_bi(HEVCLocalContext *lc, | |
1888 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
1889 | uint8_t *dst0, ptrdiff_t dststride, | ||
1890 | const AVFrame *ref0, const AVFrame *ref1, | ||
1891 | int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx) | ||
1892 | { | ||
1893 | 7920386 | const HEVCContext *const s = lc->parent; | |
1894 | 7920386 | const uint8_t *src1 = ref0->data[cidx+1]; | |
1895 | 7920386 | const uint8_t *src2 = ref1->data[cidx+1]; | |
1896 | 7920386 | ptrdiff_t src1stride = ref0->linesize[cidx+1]; | |
1897 | 7920386 | ptrdiff_t src2stride = ref1->linesize[cidx+1]; | |
1898 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7920386 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
15840772 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
1899 |
3/4✓ Branch 0 taken 7920386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 137036 times.
✓ Branch 3 taken 7783350 times.
|
7920386 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
1900 | 7920386 | int pic_width = sps->width >> sps->hshift[1]; | |
1901 | 7920386 | int pic_height = sps->height >> sps->vshift[1]; | |
1902 | 7920386 | const Mv *const mv0 = ¤t_mv->mv[0]; | |
1903 | 7920386 | const Mv *const mv1 = ¤t_mv->mv[1]; | |
1904 | 7920386 | int hshift = sps->hshift[1]; | |
1905 | 7920386 | int vshift = sps->vshift[1]; | |
1906 | |||
1907 | 7920386 | intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift); | |
1908 | 7920386 | intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift); | |
1909 | 7920386 | intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift< |