Directory: | ../../../ffmpeg/ |
---|---|
File: | src/libavcodec/hevcdec.c |
Date: | 2022-07-04 19:11:22 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 1845 | 2350 | 78.5% |
Branches: | 1315 | 1783 | 73.8% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * HEVC video Decoder | ||
3 | * | ||
4 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
5 | * Copyright (C) 2012 - 2013 Mickael Raulet | ||
6 | * Copyright (C) 2012 - 2013 Gildas Cocherel | ||
7 | * Copyright (C) 2012 - 2013 Wassim Hamidouche | ||
8 | * | ||
9 | * This file is part of FFmpeg. | ||
10 | * | ||
11 | * FFmpeg is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU Lesser General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2.1 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * FFmpeg is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * Lesser General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Lesser General Public | ||
22 | * License along with FFmpeg; if not, write to the Free Software | ||
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
24 | */ | ||
25 | |||
26 | #include "config_components.h" | ||
27 | |||
28 | #include "libavutil/attributes.h" | ||
29 | #include "libavutil/common.h" | ||
30 | #include "libavutil/display.h" | ||
31 | #include "libavutil/film_grain_params.h" | ||
32 | #include "libavutil/internal.h" | ||
33 | #include "libavutil/mastering_display_metadata.h" | ||
34 | #include "libavutil/md5.h" | ||
35 | #include "libavutil/opt.h" | ||
36 | #include "libavutil/pixdesc.h" | ||
37 | #include "libavutil/stereo3d.h" | ||
38 | #include "libavutil/timecode.h" | ||
39 | |||
40 | #include "bswapdsp.h" | ||
41 | #include "bytestream.h" | ||
42 | #include "cabac_functions.h" | ||
43 | #include "codec_internal.h" | ||
44 | #include "golomb.h" | ||
45 | #include "hevc.h" | ||
46 | #include "hevc_data.h" | ||
47 | #include "hevc_parse.h" | ||
48 | #include "hevcdec.h" | ||
49 | #include "hwconfig.h" | ||
50 | #include "internal.h" | ||
51 | #include "profiles.h" | ||
52 | #include "thread.h" | ||
53 | #include "threadframe.h" | ||
54 | |||
55 | 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 }; | ||
56 | |||
57 | /** | ||
58 | * NOTE: Each function hls_foo correspond to the function foo in the | ||
59 | * specification (HLS stands for High Level Syntax). | ||
60 | */ | ||
61 | |||
62 | /** | ||
63 | * Section 5.7 | ||
64 | */ | ||
65 | |||
66 | /* free everything allocated by pic_arrays_init() */ | ||
67 | 762 | static void pic_arrays_free(HEVCContext *s) | |
68 | { | ||
69 | 762 | av_freep(&s->sao); | |
70 | 762 | av_freep(&s->deblock); | |
71 | |||
72 | 762 | av_freep(&s->skip_flag); | |
73 | 762 | av_freep(&s->tab_ct_depth); | |
74 | |||
75 | 762 | av_freep(&s->tab_ipm); | |
76 | 762 | av_freep(&s->cbf_luma); | |
77 | 762 | av_freep(&s->is_pcm); | |
78 | |||
79 | 762 | av_freep(&s->qp_y_tab); | |
80 | 762 | av_freep(&s->tab_slice_address); | |
81 | 762 | av_freep(&s->filter_slice_edges); | |
82 | |||
83 | 762 | av_freep(&s->horizontal_bs); | |
84 | 762 | av_freep(&s->vertical_bs); | |
85 | |||
86 | 762 | av_freep(&s->sh.entry_point_offset); | |
87 | 762 | av_freep(&s->sh.size); | |
88 | 762 | av_freep(&s->sh.offset); | |
89 | |||
90 | 762 | av_buffer_pool_uninit(&s->tab_mvf_pool); | |
91 | 762 | av_buffer_pool_uninit(&s->rpl_tab_pool); | |
92 | 762 | } | |
93 | |||
94 | /* allocate arrays that depend on frame dimensions */ | ||
95 | 375 | static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps) | |
96 | { | ||
97 | 375 | int log2_min_cb_size = sps->log2_min_cb_size; | |
98 | 375 | int width = sps->width; | |
99 | 375 | int height = sps->height; | |
100 | 375 | int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) * | |
101 | 375 | ((height >> log2_min_cb_size) + 1); | |
102 | 375 | int ctb_count = sps->ctb_width * sps->ctb_height; | |
103 | 375 | int min_pu_size = sps->min_pu_width * sps->min_pu_height; | |
104 | |||
105 | 375 | s->bs_width = (width >> 2) + 1; | |
106 | 375 | s->bs_height = (height >> 2) + 1; | |
107 | |||
108 | 375 | s->sao = av_calloc(ctb_count, sizeof(*s->sao)); | |
109 | 375 | s->deblock = av_calloc(ctb_count, sizeof(*s->deblock)); | |
110 |
2/4✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 375 times.
|
375 | if (!s->sao || !s->deblock) |
111 | ✗ | goto fail; | |
112 | |||
113 | 375 | s->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
114 | 375 | s->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
115 |
2/4✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 375 times.
|
375 | if (!s->skip_flag || !s->tab_ct_depth) |
116 | ✗ | goto fail; | |
117 | |||
118 | 375 | s->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height); | |
119 | 375 | s->tab_ipm = av_mallocz(min_pu_size); | |
120 | 375 | s->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1); | |
121 |
3/6✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 375 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 375 times.
|
375 | if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm) |
122 | ✗ | goto fail; | |
123 | |||
124 | 375 | s->filter_slice_edges = av_mallocz(ctb_count); | |
125 | 375 | s->tab_slice_address = av_malloc_array(pic_size_in_ctb, | |
126 | sizeof(*s->tab_slice_address)); | ||
127 | 375 | s->qp_y_tab = av_malloc_array(pic_size_in_ctb, | |
128 | sizeof(*s->qp_y_tab)); | ||
129 |
3/6✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 375 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 375 times.
|
375 | if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address) |
130 | ✗ | goto fail; | |
131 | |||
132 | 375 | s->horizontal_bs = av_calloc(s->bs_width, s->bs_height); | |
133 | 375 | s->vertical_bs = av_calloc(s->bs_width, s->bs_height); | |
134 |
2/4✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 375 times.
|
375 | if (!s->horizontal_bs || !s->vertical_bs) |
135 | ✗ | goto fail; | |
136 | |||
137 | 375 | s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField), | |
138 | av_buffer_allocz); | ||
139 | 375 | s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab), | |
140 | av_buffer_allocz); | ||
141 |
2/4✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 375 times.
|
375 | if (!s->tab_mvf_pool || !s->rpl_tab_pool) |
142 | ✗ | goto fail; | |
143 | |||
144 | 375 | return 0; | |
145 | |||
146 | ✗ | fail: | |
147 | ✗ | pic_arrays_free(s); | |
148 | ✗ | return AVERROR(ENOMEM); | |
149 | } | ||
150 | |||
151 | 1406 | static int pred_weight_table(HEVCContext *s, GetBitContext *gb) | |
152 | { | ||
153 | 1406 | int i = 0; | |
154 | 1406 | int j = 0; | |
155 | uint8_t luma_weight_l0_flag[16]; | ||
156 | uint8_t chroma_weight_l0_flag[16]; | ||
157 | uint8_t luma_weight_l1_flag[16]; | ||
158 | uint8_t chroma_weight_l1_flag[16]; | ||
159 | int luma_log2_weight_denom; | ||
160 | |||
161 | 1406 | luma_log2_weight_denom = get_ue_golomb_long(gb); | |
162 |
2/4✓ Branch 0 taken 1406 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1406 times.
|
1406 | if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) { |
163 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom); | |
164 | ✗ | return AVERROR_INVALIDDATA; | |
165 | } | ||
166 | 1406 | s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3); | |
167 |
1/2✓ Branch 0 taken 1406 times.
✗ Branch 1 not taken.
|
1406 | if (s->ps.sps->chroma_format_idc != 0) { |
168 | 1406 | int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb); | |
169 |
2/4✓ Branch 0 taken 1406 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1406 times.
|
1406 | if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) { |
170 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom); | |
171 | ✗ | return AVERROR_INVALIDDATA; | |
172 | } | ||
173 | 1406 | s->sh.chroma_log2_weight_denom = chroma_log2_weight_denom; | |
174 | } | ||
175 | |||
176 |
2/2✓ Branch 0 taken 4356 times.
✓ Branch 1 taken 1406 times.
|
5762 | for (i = 0; i < s->sh.nb_refs[L0]; i++) { |
177 | 4356 | luma_weight_l0_flag[i] = get_bits1(gb); | |
178 |
2/2✓ Branch 0 taken 1239 times.
✓ Branch 1 taken 3117 times.
|
4356 | if (!luma_weight_l0_flag[i]) { |
179 | 1239 | s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom; | |
180 | 1239 | s->sh.luma_offset_l0[i] = 0; | |
181 | } | ||
182 | } | ||
183 |
1/2✓ Branch 0 taken 1406 times.
✗ Branch 1 not taken.
|
1406 | if (s->ps.sps->chroma_format_idc != 0) { |
184 |
2/2✓ Branch 0 taken 4356 times.
✓ Branch 1 taken 1406 times.
|
5762 | for (i = 0; i < s->sh.nb_refs[L0]; i++) |
185 | 4356 | chroma_weight_l0_flag[i] = get_bits1(gb); | |
186 | } else { | ||
187 | ✗ | for (i = 0; i < s->sh.nb_refs[L0]; i++) | |
188 | ✗ | chroma_weight_l0_flag[i] = 0; | |
189 | } | ||
190 |
2/2✓ Branch 0 taken 4356 times.
✓ Branch 1 taken 1406 times.
|
5762 | for (i = 0; i < s->sh.nb_refs[L0]; i++) { |
191 |
2/2✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1239 times.
|
4356 | if (luma_weight_l0_flag[i]) { |
192 | 3117 | int delta_luma_weight_l0 = get_se_golomb(gb); | |
193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
|
3117 | if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0) |
194 | ✗ | return AVERROR_INVALIDDATA; | |
195 | 3117 | s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l0; | |
196 | 3117 | s->sh.luma_offset_l0[i] = get_se_golomb(gb); | |
197 | } | ||
198 |
2/2✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3225 times.
|
4356 | if (chroma_weight_l0_flag[i]) { |
199 |
2/2✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
|
3393 | for (j = 0; j < 2; j++) { |
200 | 2262 | int delta_chroma_weight_l0 = get_se_golomb(gb); | |
201 | 2262 | int delta_chroma_offset_l0 = get_se_golomb(gb); | |
202 | |||
203 |
1/2✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
|
2262 | if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0 |
204 |
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)) { |
205 | ✗ | return AVERROR_INVALIDDATA; | |
206 | } | ||
207 | |||
208 | 2262 | s->sh.chroma_weight_l0[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0; | |
209 | 2262 | s->sh.chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * s->sh.chroma_weight_l0[i][j]) | |
210 | 2262 | >> s->sh.chroma_log2_weight_denom) + 128), -128, 127); | |
211 | } | ||
212 | } else { | ||
213 | 3225 | s->sh.chroma_weight_l0[i][0] = 1 << s->sh.chroma_log2_weight_denom; | |
214 | 3225 | s->sh.chroma_offset_l0[i][0] = 0; | |
215 | 3225 | s->sh.chroma_weight_l0[i][1] = 1 << s->sh.chroma_log2_weight_denom; | |
216 | 3225 | s->sh.chroma_offset_l0[i][1] = 0; | |
217 | } | ||
218 | } | ||
219 |
2/2✓ Branch 0 taken 639 times.
✓ Branch 1 taken 767 times.
|
1406 | if (s->sh.slice_type == HEVC_SLICE_B) { |
220 |
2/2✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 639 times.
|
1951 | for (i = 0; i < s->sh.nb_refs[L1]; i++) { |
221 | 1312 | luma_weight_l1_flag[i] = get_bits1(gb); | |
222 |
2/2✓ Branch 0 taken 566 times.
✓ Branch 1 taken 746 times.
|
1312 | if (!luma_weight_l1_flag[i]) { |
223 | 566 | s->sh.luma_weight_l1[i] = 1 << s->sh.luma_log2_weight_denom; | |
224 | 566 | s->sh.luma_offset_l1[i] = 0; | |
225 | } | ||
226 | } | ||
227 |
1/2✓ Branch 0 taken 639 times.
✗ Branch 1 not taken.
|
639 | if (s->ps.sps->chroma_format_idc != 0) { |
228 |
2/2✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 639 times.
|
1951 | for (i = 0; i < s->sh.nb_refs[L1]; i++) |
229 | 1312 | chroma_weight_l1_flag[i] = get_bits1(gb); | |
230 | } else { | ||
231 | ✗ | for (i = 0; i < s->sh.nb_refs[L1]; i++) | |
232 | ✗ | chroma_weight_l1_flag[i] = 0; | |
233 | } | ||
234 |
2/2✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 639 times.
|
1951 | for (i = 0; i < s->sh.nb_refs[L1]; i++) { |
235 |
2/2✓ Branch 0 taken 746 times.
✓ Branch 1 taken 566 times.
|
1312 | if (luma_weight_l1_flag[i]) { |
236 | 746 | int delta_luma_weight_l1 = get_se_golomb(gb); | |
237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
|
746 | if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1) |
238 | ✗ | return AVERROR_INVALIDDATA; | |
239 | 746 | s->sh.luma_weight_l1[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l1; | |
240 | 746 | s->sh.luma_offset_l1[i] = get_se_golomb(gb); | |
241 | } | ||
242 |
2/2✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1076 times.
|
1312 | if (chroma_weight_l1_flag[i]) { |
243 |
2/2✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
|
708 | for (j = 0; j < 2; j++) { |
244 | 472 | int delta_chroma_weight_l1 = get_se_golomb(gb); | |
245 | 472 | int delta_chroma_offset_l1 = get_se_golomb(gb); | |
246 | |||
247 |
1/2✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
|
472 | if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1 |
248 |
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)) { |
249 | ✗ | return AVERROR_INVALIDDATA; | |
250 | } | ||
251 | |||
252 | 472 | s->sh.chroma_weight_l1[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1; | |
253 | 472 | s->sh.chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * s->sh.chroma_weight_l1[i][j]) | |
254 | 472 | >> s->sh.chroma_log2_weight_denom) + 128), -128, 127); | |
255 | } | ||
256 | } else { | ||
257 | 1076 | s->sh.chroma_weight_l1[i][0] = 1 << s->sh.chroma_log2_weight_denom; | |
258 | 1076 | s->sh.chroma_offset_l1[i][0] = 0; | |
259 | 1076 | s->sh.chroma_weight_l1[i][1] = 1 << s->sh.chroma_log2_weight_denom; | |
260 | 1076 | s->sh.chroma_offset_l1[i][1] = 0; | |
261 | } | ||
262 | } | ||
263 | } | ||
264 | 1406 | return 0; | |
265 | } | ||
266 | |||
267 | 19026 | static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb) | |
268 | { | ||
269 | 19026 | const HEVCSPS *sps = s->ps.sps; | |
270 | 19026 | int max_poc_lsb = 1 << sps->log2_max_poc_lsb; | |
271 | 19026 | int prev_delta_msb = 0; | |
272 | 19026 | unsigned int nb_sps = 0, nb_sh; | |
273 | int i; | ||
274 | |||
275 | 19026 | rps->nb_refs = 0; | |
276 |
2/2✓ Branch 0 taken 17992 times.
✓ Branch 1 taken 1034 times.
|
19026 | if (!sps->long_term_ref_pics_present_flag) |
277 | 17992 | return 0; | |
278 | |||
279 |
2/2✓ Branch 0 taken 499 times.
✓ Branch 1 taken 535 times.
|
1034 | if (sps->num_long_term_ref_pics_sps > 0) |
280 | 499 | nb_sps = get_ue_golomb_long(gb); | |
281 | 1034 | nb_sh = get_ue_golomb_long(gb); | |
282 | |||
283 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1034 times.
|
1034 | if (nb_sps > sps->num_long_term_ref_pics_sps) |
284 | ✗ | return AVERROR_INVALIDDATA; | |
285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1034 times.
|
1034 | if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc)) |
286 | ✗ | return AVERROR_INVALIDDATA; | |
287 | |||
288 | 1034 | rps->nb_refs = nb_sh + nb_sps; | |
289 | |||
290 |
2/2✓ Branch 0 taken 1560 times.
✓ Branch 1 taken 1034 times.
|
2594 | for (i = 0; i < rps->nb_refs; i++) { |
291 | |||
292 |
2/2✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1376 times.
|
1560 | if (i < nb_sps) { |
293 | 184 | uint8_t lt_idx_sps = 0; | |
294 | |||
295 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (sps->num_long_term_ref_pics_sps > 1) |
296 | 184 | lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps)); | |
297 | |||
298 | 184 | rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps]; | |
299 | 184 | rps->used[i] = sps->used_by_curr_pic_lt_sps_flag[lt_idx_sps]; | |
300 | } else { | ||
301 | 1376 | rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb); | |
302 | 1376 | rps->used[i] = get_bits1(gb); | |
303 | } | ||
304 | |||
305 | 1560 | rps->poc_msb_present[i] = get_bits1(gb); | |
306 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1512 times.
|
1560 | if (rps->poc_msb_present[i]) { |
307 | 48 | int64_t delta = get_ue_golomb_long(gb); | |
308 | int64_t poc; | ||
309 | |||
310 |
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) |
311 | 31 | delta += prev_delta_msb; | |
312 | |||
313 | 48 | poc = rps->poc[i] + s->poc - delta * max_poc_lsb - s->sh.pic_order_cnt_lsb; | |
314 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (poc != (int32_t)poc) |
315 | ✗ | return AVERROR_INVALIDDATA; | |
316 | 48 | rps->poc[i] = poc; | |
317 | 48 | prev_delta_msb = delta; | |
318 | } | ||
319 | } | ||
320 | |||
321 | 1034 | return 0; | |
322 | } | ||
323 | |||
324 | 568 | static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) | |
325 | { | ||
326 | 568 | AVCodecContext *avctx = s->avctx; | |
327 | 568 | const HEVCParamSets *ps = &s->ps; | |
328 | 568 | const HEVCVPS *vps = (const HEVCVPS*)ps->vps_list[sps->vps_id]->data; | |
329 | 568 | const HEVCWindow *ow = &sps->output_window; | |
330 | 568 | unsigned int num = 0, den = 0; | |
331 | |||
332 | 568 | avctx->pix_fmt = sps->pix_fmt; | |
333 | 568 | avctx->coded_width = sps->width; | |
334 | 568 | avctx->coded_height = sps->height; | |
335 | 568 | avctx->width = sps->width - ow->left_offset - ow->right_offset; | |
336 | 568 | avctx->height = sps->height - ow->top_offset - ow->bottom_offset; | |
337 | 568 | avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics; | |
338 | 568 | avctx->profile = sps->ptl.general_ptl.profile_idc; | |
339 | 568 | avctx->level = sps->ptl.general_ptl.level_idc; | |
340 | |||
341 | 568 | ff_set_sar(avctx, sps->vui.sar); | |
342 | |||
343 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 536 times.
|
568 | if (sps->vui.video_signal_type_present_flag) |
344 | 32 | avctx->color_range = sps->vui.video_full_range_flag ? AVCOL_RANGE_JPEG | |
345 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 25 times.
|
32 | : AVCOL_RANGE_MPEG; |
346 | else | ||
347 | 536 | avctx->color_range = AVCOL_RANGE_MPEG; | |
348 | |||
349 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 539 times.
|
568 | if (sps->vui.colour_description_present_flag) { |
350 | 29 | avctx->color_primaries = sps->vui.colour_primaries; | |
351 | 29 | avctx->color_trc = sps->vui.transfer_characteristic; | |
352 | 29 | avctx->colorspace = sps->vui.matrix_coeffs; | |
353 | } else { | ||
354 | 539 | avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; | |
355 | 539 | avctx->color_trc = AVCOL_TRC_UNSPECIFIED; | |
356 | 539 | avctx->colorspace = AVCOL_SPC_UNSPECIFIED; | |
357 | } | ||
358 | |||
359 | 568 | avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED; | |
360 |
2/2✓ Branch 0 taken 527 times.
✓ Branch 1 taken 41 times.
|
568 | if (sps->chroma_format_idc == 1) { |
361 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 515 times.
|
527 | if (sps->vui.chroma_loc_info_present_flag) { |
362 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (sps->vui.chroma_sample_loc_type_top_field <= 5) |
363 | 12 | avctx->chroma_sample_location = sps->vui.chroma_sample_loc_type_top_field + 1; | |
364 | } else | ||
365 | 515 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; | |
366 | } | ||
367 | |||
368 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 545 times.
|
568 | if (vps->vps_timing_info_present_flag) { |
369 | 23 | num = vps->vps_num_units_in_tick; | |
370 | 23 | den = vps->vps_time_scale; | |
371 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 510 times.
|
545 | } else if (sps->vui.vui_timing_info_present_flag) { |
372 | 35 | num = sps->vui.vui_num_units_in_tick; | |
373 | 35 | den = sps->vui.vui_time_scale; | |
374 | } | ||
375 | |||
376 |
3/4✓ Branch 0 taken 58 times.
✓ Branch 1 taken 510 times.
✓ Branch 2 taken 58 times.
✗ Branch 3 not taken.
|
568 | if (num != 0 && den != 0) |
377 | 58 | av_reduce(&avctx->framerate.den, &avctx->framerate.num, | |
378 | num, den, 1 << 30); | ||
379 | 568 | } | |
380 | |||
381 | 27789 | static int export_stream_params_from_sei(HEVCContext *s) | |
382 | { | ||
383 | 27789 | AVCodecContext *avctx = s->avctx; | |
384 | |||
385 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27789 times.
|
27789 | if (s->sei.a53_caption.buf_ref) |
386 | ✗ | s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; | |
387 | |||
388 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 27789 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
27789 | if (s->sei.alternative_transfer.present && |
389 | ✗ | av_color_transfer_name(s->sei.alternative_transfer.preferred_transfer_characteristics) && | |
390 | ✗ | s->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) { | |
391 | ✗ | avctx->color_trc = s->sei.alternative_transfer.preferred_transfer_characteristics; | |
392 | } | ||
393 | |||
394 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27789 times.
|
27789 | if (s->sei.film_grain_characteristics.present) |
395 | ✗ | avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; | |
396 | |||
397 | 27789 | return 0; | |
398 | } | ||
399 | |||
400 | 374 | static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) | |
401 | { | ||
402 | #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \ | ||
403 | CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \ | ||
404 | CONFIG_HEVC_NVDEC_HWACCEL + \ | ||
405 | CONFIG_HEVC_VAAPI_HWACCEL + \ | ||
406 | CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \ | ||
407 | CONFIG_HEVC_VDPAU_HWACCEL) | ||
408 | 374 | enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts; | |
409 | |||
410 |
6/6✓ Branch 0 taken 319 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 2 times.
|
374 | switch (sps->pix_fmt) { |
411 | 319 | case AV_PIX_FMT_YUV420P: | |
412 | case AV_PIX_FMT_YUVJ420P: | ||
413 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
414 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
415 | #endif | ||
416 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
417 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
418 | *fmt++ = AV_PIX_FMT_D3D11; | ||
419 | #endif | ||
420 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
421 | 319 | *fmt++ = AV_PIX_FMT_VAAPI; | |
422 | #endif | ||
423 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
424 | 319 | *fmt++ = AV_PIX_FMT_VDPAU; | |
425 | #endif | ||
426 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
427 | *fmt++ = AV_PIX_FMT_CUDA; | ||
428 | #endif | ||
429 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
430 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
431 | #endif | ||
432 | 319 | break; | |
433 | 27 | case AV_PIX_FMT_YUV420P10: | |
434 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
435 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
436 | #endif | ||
437 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
438 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
439 | *fmt++ = AV_PIX_FMT_D3D11; | ||
440 | #endif | ||
441 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
442 | 27 | *fmt++ = AV_PIX_FMT_VAAPI; | |
443 | #endif | ||
444 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
445 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
446 | #endif | ||
447 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
448 | 27 | *fmt++ = AV_PIX_FMT_VDPAU; | |
449 | #endif | ||
450 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
451 | *fmt++ = AV_PIX_FMT_CUDA; | ||
452 | #endif | ||
453 | 27 | break; | |
454 | 4 | case AV_PIX_FMT_YUV444P: | |
455 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
456 | 4 | *fmt++ = AV_PIX_FMT_VDPAU; | |
457 | #endif | ||
458 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
459 | *fmt++ = AV_PIX_FMT_CUDA; | ||
460 | #endif | ||
461 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
462 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
463 | #endif | ||
464 | 4 | break; | |
465 | 12 | case AV_PIX_FMT_YUV422P: | |
466 | case AV_PIX_FMT_YUV422P10LE: | ||
467 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
468 | 12 | *fmt++ = AV_PIX_FMT_VAAPI; | |
469 | #endif | ||
470 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
471 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
472 | #endif | ||
473 | 12 | break; | |
474 | 10 | case AV_PIX_FMT_YUV444P10: | |
475 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
476 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
477 | #endif | ||
478 | case AV_PIX_FMT_YUV420P12: | ||
479 | case AV_PIX_FMT_YUV444P12: | ||
480 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
481 | 10 | *fmt++ = AV_PIX_FMT_VDPAU; | |
482 | #endif | ||
483 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
484 | *fmt++ = AV_PIX_FMT_CUDA; | ||
485 | #endif | ||
486 | 10 | break; | |
487 | } | ||
488 | |||
489 | 374 | *fmt++ = sps->pix_fmt; | |
490 | 374 | *fmt = AV_PIX_FMT_NONE; | |
491 | |||
492 | 374 | return ff_thread_get_format(s->avctx, pix_fmts); | |
493 | } | ||
494 | |||
495 | 375 | static int set_sps(HEVCContext *s, const HEVCSPS *sps, | |
496 | enum AVPixelFormat pix_fmt) | ||
497 | { | ||
498 | int ret, i; | ||
499 | |||
500 | 375 | pic_arrays_free(s); | |
501 | 375 | s->ps.sps = NULL; | |
502 | 375 | s->ps.vps = NULL; | |
503 | |||
504 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 375 times.
|
375 | if (!sps) |
505 | ✗ | return 0; | |
506 | |||
507 | 375 | ret = pic_arrays_init(s, sps); | |
508 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 375 times.
|
375 | if (ret < 0) |
509 | ✗ | goto fail; | |
510 | |||
511 | 375 | export_stream_params(s, sps); | |
512 | |||
513 | 375 | s->avctx->pix_fmt = pix_fmt; | |
514 | |||
515 | 375 | ff_hevc_pred_init(&s->hpc, sps->bit_depth); | |
516 | 375 | ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); | |
517 | 375 | ff_videodsp_init (&s->vdsp, sps->bit_depth); | |
518 | |||
519 |
2/2✓ Branch 0 taken 1125 times.
✓ Branch 1 taken 375 times.
|
1500 | for (i = 0; i < 3; i++) { |
520 | 1125 | av_freep(&s->sao_pixel_buffer_h[i]); | |
521 | 1125 | av_freep(&s->sao_pixel_buffer_v[i]); | |
522 | } | ||
523 | |||
524 |
3/4✓ Branch 0 taken 320 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 320 times.
✗ Branch 3 not taken.
|
375 | if (sps->sao_enabled && !s->avctx->hwaccel) { |
525 |
2/2✓ Branch 0 taken 318 times.
✓ Branch 1 taken 2 times.
|
320 | int c_count = (sps->chroma_format_idc != 0) ? 3 : 1; |
526 | int c_idx; | ||
527 | |||
528 |
2/2✓ Branch 0 taken 956 times.
✓ Branch 1 taken 320 times.
|
1276 | for(c_idx = 0; c_idx < c_count; c_idx++) { |
529 | 956 | int w = sps->width >> sps->hshift[c_idx]; | |
530 | 956 | int h = sps->height >> sps->vshift[c_idx]; | |
531 | 956 | s->sao_pixel_buffer_h[c_idx] = | |
532 | 956 | av_malloc((w * 2 * sps->ctb_height) << | |
533 | 956 | sps->pixel_shift); | |
534 | 956 | s->sao_pixel_buffer_v[c_idx] = | |
535 | 956 | av_malloc((h * 2 * sps->ctb_width) << | |
536 | 956 | sps->pixel_shift); | |
537 |
1/2✓ Branch 0 taken 956 times.
✗ Branch 1 not taken.
|
956 | if (!s->sao_pixel_buffer_h[c_idx] || |
538 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 956 times.
|
956 | !s->sao_pixel_buffer_v[c_idx]) |
539 | ✗ | goto fail; | |
540 | } | ||
541 | } | ||
542 | |||
543 | 375 | s->ps.sps = sps; | |
544 | 375 | s->ps.vps = (HEVCVPS*) s->ps.vps_list[s->ps.sps->vps_id]->data; | |
545 | |||
546 | 375 | return 0; | |
547 | |||
548 | ✗ | fail: | |
549 | ✗ | pic_arrays_free(s); | |
550 | ✗ | for (i = 0; i < 3; i++) { | |
551 | ✗ | av_freep(&s->sao_pixel_buffer_h[i]); | |
552 | ✗ | av_freep(&s->sao_pixel_buffer_v[i]); | |
553 | } | ||
554 | ✗ | s->ps.sps = NULL; | |
555 | ✗ | return ret; | |
556 | } | ||
557 | |||
558 | 27585 | static int hls_slice_header(HEVCContext *s) | |
559 | { | ||
560 | 27585 | GetBitContext *gb = &s->HEVClc->gb; | |
561 | 27585 | SliceHeader *sh = &s->sh; | |
562 | int i, ret; | ||
563 | |||
564 | // Coded parameters | ||
565 | 27585 | sh->first_slice_in_pic_flag = get_bits1(gb); | |
566 |
4/4✓ Branch 0 taken 17990 times.
✓ Branch 1 taken 9595 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 17989 times.
|
27585 | if (s->ref && sh->first_slice_in_pic_flag) { |
567 | 1 | av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n"); | |
568 | 1 | return 1; // This slice will be skipped later, do not corrupt state | |
569 | } | ||
570 | |||
571 |
12/12✓ Branch 0 taken 26681 times.
✓ Branch 1 taken 903 times.
✓ Branch 2 taken 26667 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 26665 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 26658 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 26657 times.
✓ Branch 10 taken 383 times.
✓ Branch 11 taken 544 times.
|
27584 | if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) { |
572 | 383 | s->seq_decode = (s->seq_decode + 1) & 0xff; | |
573 | 383 | s->max_ra = INT_MAX; | |
574 |
4/4✓ Branch 0 taken 24 times.
✓ Branch 1 taken 359 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 10 times.
|
383 | if (IS_IDR(s)) |
575 | 373 | ff_hevc_clear_refs(s); | |
576 | } | ||
577 | 27584 | sh->no_output_of_prior_pics_flag = 0; | |
578 |
3/4✓ Branch 0 taken 1269 times.
✓ Branch 1 taken 26315 times.
✓ Branch 2 taken 1269 times.
✗ Branch 3 not taken.
|
27584 | if (IS_IRAP(s)) |
579 | 1269 | sh->no_output_of_prior_pics_flag = get_bits1(gb); | |
580 | |||
581 | 27584 | sh->pps_id = get_ue_golomb_long(gb); | |
582 |
3/4✓ Branch 0 taken 27584 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 27562 times.
|
27584 | if (sh->pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[sh->pps_id]) { |
583 | 22 | av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id); | |
584 | 22 | return AVERROR_INVALIDDATA; | |
585 | } | ||
586 |
2/2✓ Branch 0 taken 18031 times.
✓ Branch 1 taken 9531 times.
|
27562 | if (!sh->first_slice_in_pic_flag && |
587 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18031 times.
|
18031 | s->ps.pps != (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data) { |
588 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); | |
589 | ✗ | return AVERROR_INVALIDDATA; | |
590 | } | ||
591 | 27562 | s->ps.pps = (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data; | |
592 |
4/4✓ Branch 0 taken 342 times.
✓ Branch 1 taken 27220 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 328 times.
|
27562 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) |
593 | 14 | sh->no_output_of_prior_pics_flag = 1; | |
594 | |||
595 |
2/2✓ Branch 0 taken 374 times.
✓ Branch 1 taken 27188 times.
|
27562 | if (s->ps.sps != (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data) { |
596 | 374 | const HEVCSPS *sps = (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data; | |
597 | 374 | const HEVCSPS *last_sps = s->ps.sps; | |
598 | enum AVPixelFormat pix_fmt; | ||
599 | |||
600 |
5/8✓ Branch 0 taken 2 times.
✓ Branch 1 taken 372 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
374 | if (last_sps && IS_IRAP(s) && s->nal_unit_type != HEVC_NAL_CRA_NUT) { |
601 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | if (sps->width != last_sps->width || sps->height != last_sps->height || |
602 | 2 | sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering != | |
603 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | last_sps->temporal_layer[last_sps->max_sub_layers - 1].max_dec_pic_buffering) |
604 | ✗ | sh->no_output_of_prior_pics_flag = 0; | |
605 | } | ||
606 | 374 | ff_hevc_clear_refs(s); | |
607 | |||
608 | 374 | ret = set_sps(s, sps, sps->pix_fmt); | |
609 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 374 times.
|
374 | if (ret < 0) |
610 | ✗ | return ret; | |
611 | |||
612 | 374 | pix_fmt = get_format(s, sps); | |
613 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 374 times.
|
374 | if (pix_fmt < 0) |
614 | ✗ | return pix_fmt; | |
615 | 374 | s->avctx->pix_fmt = pix_fmt; | |
616 | |||
617 | 374 | s->seq_decode = (s->seq_decode + 1) & 0xff; | |
618 | 374 | s->max_ra = INT_MAX; | |
619 | } | ||
620 | |||
621 | 27562 | ret = export_stream_params_from_sei(s); | |
622 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27562 times.
|
27562 | if (ret < 0) |
623 | ✗ | return ret; | |
624 | |||
625 | 27562 | sh->dependent_slice_segment_flag = 0; | |
626 |
2/2✓ Branch 0 taken 18031 times.
✓ Branch 1 taken 9531 times.
|
27562 | if (!sh->first_slice_in_pic_flag) { |
627 | int slice_address_length; | ||
628 | |||
629 |
2/2✓ Branch 0 taken 9092 times.
✓ Branch 1 taken 8939 times.
|
18031 | if (s->ps.pps->dependent_slice_segments_enabled_flag) |
630 | 9092 | sh->dependent_slice_segment_flag = get_bits1(gb); | |
631 | |||
632 | 18031 | slice_address_length = av_ceil_log2(s->ps.sps->ctb_width * | |
633 | 18031 | s->ps.sps->ctb_height); | |
634 | 18031 | sh->slice_segment_addr = get_bitsz(gb, slice_address_length); | |
635 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18031 times.
|
18031 | if (sh->slice_segment_addr >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) { |
636 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
637 | "Invalid slice segment address: %u.\n", | ||
638 | sh->slice_segment_addr); | ||
639 | ✗ | return AVERROR_INVALIDDATA; | |
640 | } | ||
641 | |||
642 |
2/2✓ Branch 0 taken 10084 times.
✓ Branch 1 taken 7947 times.
|
18031 | if (!sh->dependent_slice_segment_flag) { |
643 | 10084 | sh->slice_addr = sh->slice_segment_addr; | |
644 | 10084 | s->slice_idx++; | |
645 | } | ||
646 | } else { | ||
647 | 9531 | sh->slice_segment_addr = sh->slice_addr = 0; | |
648 | 9531 | s->slice_idx = 0; | |
649 | 9531 | s->slice_initialized = 0; | |
650 | } | ||
651 | |||
652 |
2/2✓ Branch 0 taken 19615 times.
✓ Branch 1 taken 7947 times.
|
27562 | if (!sh->dependent_slice_segment_flag) { |
653 | 19615 | s->slice_initialized = 0; | |
654 | |||
655 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 19615 times.
|
19619 | for (i = 0; i < s->ps.pps->num_extra_slice_header_bits; i++) |
656 | 4 | skip_bits(gb, 1); // slice_reserved_undetermined_flag[] | |
657 | |||
658 | 19615 | sh->slice_type = get_ue_golomb_long(gb); | |
659 |
2/2✓ Branch 0 taken 18484 times.
✓ Branch 1 taken 1131 times.
|
19615 | if (!(sh->slice_type == HEVC_SLICE_I || |
660 |
2/2✓ Branch 0 taken 14743 times.
✓ Branch 1 taken 3741 times.
|
18484 | sh->slice_type == HEVC_SLICE_P || |
661 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14743 times.
|
14743 | sh->slice_type == HEVC_SLICE_B)) { |
662 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", | |
663 | ✗ | sh->slice_type); | |
664 | ✗ | return AVERROR_INVALIDDATA; | |
665 | } | ||
666 |
4/6✓ Branch 0 taken 880 times.
✓ Branch 1 taken 18735 times.
✓ Branch 2 taken 880 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 880 times.
|
19615 | if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I) { |
667 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); | |
668 | ✗ | return AVERROR_INVALIDDATA; | |
669 | } | ||
670 | |||
671 | // when flag is not present, picture is inferred to be output | ||
672 | 19615 | sh->pic_output_flag = 1; | |
673 |
2/2✓ Branch 0 taken 703 times.
✓ Branch 1 taken 18912 times.
|
19615 | if (s->ps.pps->output_flag_present_flag) |
674 | 703 | sh->pic_output_flag = get_bits1(gb); | |
675 | |||
676 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19615 times.
|
19615 | if (s->ps.sps->separate_colour_plane_flag) |
677 | ✗ | sh->colour_plane_id = get_bits(gb, 2); | |
678 | |||
679 |
4/4✓ Branch 0 taken 19040 times.
✓ Branch 1 taken 575 times.
✓ Branch 2 taken 19026 times.
✓ Branch 3 taken 14 times.
|
38641 | if (!IS_IDR(s)) { |
680 | int poc, pos; | ||
681 | |||
682 | 19026 | sh->pic_order_cnt_lsb = get_bits(gb, s->ps.sps->log2_max_poc_lsb); | |
683 | 19026 | poc = ff_hevc_compute_poc(s->ps.sps, s->pocTid0, sh->pic_order_cnt_lsb, s->nal_unit_type); | |
684 |
3/4✓ Branch 0 taken 9868 times.
✓ Branch 1 taken 9158 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9868 times.
|
19026 | if (!sh->first_slice_in_pic_flag && poc != s->poc) { |
685 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
686 | "Ignoring POC change between slices: %d -> %d\n", s->poc, poc); | ||
687 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
688 | ✗ | return AVERROR_INVALIDDATA; | |
689 | ✗ | poc = s->poc; | |
690 | } | ||
691 | 19026 | s->poc = poc; | |
692 | |||
693 | 19026 | sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); | |
694 | 19026 | pos = get_bits_left(gb); | |
695 |
2/2✓ Branch 0 taken 3214 times.
✓ Branch 1 taken 15812 times.
|
19026 | if (!sh->short_term_ref_pic_set_sps_flag) { |
696 | 3214 | ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, s->ps.sps, 1); | |
697 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3214 times.
|
3214 | if (ret < 0) |
698 | ✗ | return ret; | |
699 | |||
700 | 3214 | sh->short_term_rps = &sh->slice_rps; | |
701 | } else { | ||
702 | int numbits, rps_idx; | ||
703 | |||
704 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15812 times.
|
15812 | if (!s->ps.sps->nb_st_rps) { |
705 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); | |
706 | ✗ | return AVERROR_INVALIDDATA; | |
707 | } | ||
708 | |||
709 | 15812 | numbits = av_ceil_log2(s->ps.sps->nb_st_rps); | |
710 |
2/2✓ Branch 0 taken 15784 times.
✓ Branch 1 taken 28 times.
|
15812 | rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; |
711 | 15812 | sh->short_term_rps = &s->ps.sps->st_rps[rps_idx]; | |
712 | } | ||
713 | 19026 | sh->short_term_ref_pic_set_size = pos - get_bits_left(gb); | |
714 | |||
715 | 19026 | pos = get_bits_left(gb); | |
716 | 19026 | ret = decode_lt_rps(s, &sh->long_term_rps, gb); | |
717 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19026 times.
|
19026 | if (ret < 0) { |
718 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n"); | |
719 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
720 | ✗ | return AVERROR_INVALIDDATA; | |
721 | } | ||
722 | 19026 | sh->long_term_ref_pic_set_size = pos - get_bits_left(gb); | |
723 | |||
724 |
2/2✓ Branch 0 taken 16595 times.
✓ Branch 1 taken 2431 times.
|
19026 | if (s->ps.sps->sps_temporal_mvp_enabled_flag) |
725 | 16595 | sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); | |
726 | else | ||
727 | 2431 | sh->slice_temporal_mvp_enabled_flag = 0; | |
728 | } else { | ||
729 | 589 | s->sh.short_term_rps = NULL; | |
730 | 589 | s->poc = 0; | |
731 | } | ||
732 | |||
733 | /* 8.3.1 */ | ||
734 |
4/4✓ Branch 0 taken 9531 times.
✓ Branch 1 taken 10084 times.
✓ Branch 2 taken 9188 times.
✓ Branch 3 taken 343 times.
|
19615 | if (sh->first_slice_in_pic_flag && s->temporal_id == 0 && |
735 |
2/2✓ Branch 0 taken 6729 times.
✓ Branch 1 taken 2459 times.
|
9188 | s->nal_unit_type != HEVC_NAL_TRAIL_N && |
736 |
1/2✓ Branch 0 taken 6729 times.
✗ Branch 1 not taken.
|
6729 | s->nal_unit_type != HEVC_NAL_TSA_N && |
737 |
1/2✓ Branch 0 taken 6729 times.
✗ Branch 1 not taken.
|
6729 | s->nal_unit_type != HEVC_NAL_STSA_N && |
738 |
2/2✓ Branch 0 taken 6707 times.
✓ Branch 1 taken 22 times.
|
6729 | s->nal_unit_type != HEVC_NAL_RADL_N && |
739 |
2/2✓ Branch 0 taken 6688 times.
✓ Branch 1 taken 19 times.
|
6707 | s->nal_unit_type != HEVC_NAL_RADL_R && |
740 |
2/2✓ Branch 0 taken 6331 times.
✓ Branch 1 taken 357 times.
|
6688 | s->nal_unit_type != HEVC_NAL_RASL_N && |
741 |
2/2✓ Branch 0 taken 5862 times.
✓ Branch 1 taken 469 times.
|
6331 | s->nal_unit_type != HEVC_NAL_RASL_R) |
742 | 5862 | s->pocTid0 = s->poc; | |
743 | |||
744 |
2/2✓ Branch 0 taken 16102 times.
✓ Branch 1 taken 3513 times.
|
19615 | if (s->ps.sps->sao_enabled) { |
745 | 16102 | sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); | |
746 |
2/2✓ Branch 0 taken 16100 times.
✓ Branch 1 taken 2 times.
|
16102 | if (s->ps.sps->chroma_format_idc) { |
747 | 16100 | sh->slice_sample_adaptive_offset_flag[1] = | |
748 | 16100 | sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); | |
749 | } | ||
750 | } else { | ||
751 | 3513 | sh->slice_sample_adaptive_offset_flag[0] = 0; | |
752 | 3513 | sh->slice_sample_adaptive_offset_flag[1] = 0; | |
753 | 3513 | sh->slice_sample_adaptive_offset_flag[2] = 0; | |
754 | } | ||
755 | |||
756 | 19615 | sh->nb_refs[L0] = sh->nb_refs[L1] = 0; | |
757 |
4/4✓ Branch 0 taken 15874 times.
✓ Branch 1 taken 3741 times.
✓ Branch 2 taken 14743 times.
✓ Branch 3 taken 1131 times.
|
19615 | if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) { |
758 | int nb_refs; | ||
759 | |||
760 | 18484 | sh->nb_refs[L0] = s->ps.pps->num_ref_idx_l0_default_active; | |
761 |
2/2✓ Branch 0 taken 14743 times.
✓ Branch 1 taken 3741 times.
|
18484 | if (sh->slice_type == HEVC_SLICE_B) |
762 | 14743 | sh->nb_refs[L1] = s->ps.pps->num_ref_idx_l1_default_active; | |
763 | |||
764 |
2/2✓ Branch 1 taken 4861 times.
✓ Branch 2 taken 13623 times.
|
18484 | if (get_bits1(gb)) { // num_ref_idx_active_override_flag |
765 | 4861 | sh->nb_refs[L0] = get_ue_golomb_long(gb) + 1; | |
766 |
2/2✓ Branch 0 taken 2699 times.
✓ Branch 1 taken 2162 times.
|
4861 | if (sh->slice_type == HEVC_SLICE_B) |
767 | 2699 | sh->nb_refs[L1] = get_ue_golomb_long(gb) + 1; | |
768 | } | ||
769 |
2/4✓ Branch 0 taken 18484 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18484 times.
|
18484 | if (sh->nb_refs[L0] > HEVC_MAX_REFS || sh->nb_refs[L1] > HEVC_MAX_REFS) { |
770 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n", | |
771 | sh->nb_refs[L0], sh->nb_refs[L1]); | ||
772 | ✗ | return AVERROR_INVALIDDATA; | |
773 | } | ||
774 | |||
775 | 18484 | sh->rpl_modification_flag[0] = 0; | |
776 | 18484 | sh->rpl_modification_flag[1] = 0; | |
777 | 18484 | nb_refs = ff_hevc_frame_nb_refs(s); | |
778 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18484 times.
|
18484 | if (!nb_refs) { |
779 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); | |
780 | ✗ | return AVERROR_INVALIDDATA; | |
781 | } | ||
782 | |||
783 |
4/4✓ Branch 0 taken 1653 times.
✓ Branch 1 taken 16831 times.
✓ Branch 2 taken 1596 times.
✓ Branch 3 taken 57 times.
|
18484 | if (s->ps.pps->lists_modification_present_flag && nb_refs > 1) { |
784 | 1596 | sh->rpl_modification_flag[0] = get_bits1(gb); | |
785 |
2/2✓ Branch 0 taken 1176 times.
✓ Branch 1 taken 420 times.
|
1596 | if (sh->rpl_modification_flag[0]) { |
786 |
2/2✓ Branch 0 taken 2779 times.
✓ Branch 1 taken 1176 times.
|
3955 | for (i = 0; i < sh->nb_refs[L0]; i++) |
787 | 2779 | sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
788 | } | ||
789 | |||
790 |
1/2✓ Branch 0 taken 1596 times.
✗ Branch 1 not taken.
|
1596 | if (sh->slice_type == HEVC_SLICE_B) { |
791 | 1596 | sh->rpl_modification_flag[1] = get_bits1(gb); | |
792 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 944 times.
|
1596 | if (sh->rpl_modification_flag[1] == 1) |
793 |
2/2✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
|
2207 | for (i = 0; i < sh->nb_refs[L1]; i++) |
794 | 1555 | sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
795 | } | ||
796 | } | ||
797 | |||
798 |
2/2✓ Branch 0 taken 14743 times.
✓ Branch 1 taken 3741 times.
|
18484 | if (sh->slice_type == HEVC_SLICE_B) |
799 | 14743 | sh->mvd_l1_zero_flag = get_bits1(gb); | |
800 | |||
801 |
2/2✓ Branch 0 taken 15792 times.
✓ Branch 1 taken 2692 times.
|
18484 | if (s->ps.pps->cabac_init_present_flag) |
802 | 15792 | sh->cabac_init_flag = get_bits1(gb); | |
803 | else | ||
804 | 2692 | sh->cabac_init_flag = 0; | |
805 | |||
806 | 18484 | sh->collocated_ref_idx = 0; | |
807 |
2/2✓ Branch 0 taken 16146 times.
✓ Branch 1 taken 2338 times.
|
18484 | if (sh->slice_temporal_mvp_enabled_flag) { |
808 | 16146 | sh->collocated_list = L0; | |
809 |
2/2✓ Branch 0 taken 14241 times.
✓ Branch 1 taken 1905 times.
|
16146 | if (sh->slice_type == HEVC_SLICE_B) |
810 | 14241 | sh->collocated_list = !get_bits1(gb); | |
811 | |||
812 |
2/2✓ Branch 0 taken 14395 times.
✓ Branch 1 taken 1751 times.
|
16146 | if (sh->nb_refs[sh->collocated_list] > 1) { |
813 | 14395 | sh->collocated_ref_idx = get_ue_golomb_long(gb); | |
814 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14395 times.
|
14395 | if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { |
815 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
816 | "Invalid collocated_ref_idx: %d.\n", | ||
817 | sh->collocated_ref_idx); | ||
818 | ✗ | return AVERROR_INVALIDDATA; | |
819 | } | ||
820 | } | ||
821 | } | ||
822 | |||
823 |
4/4✓ Branch 0 taken 1431 times.
✓ Branch 1 taken 17053 times.
✓ Branch 2 taken 664 times.
✓ Branch 3 taken 767 times.
|
18484 | if ((s->ps.pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) || |
824 |
3/4✓ Branch 0 taken 639 times.
✓ Branch 1 taken 17078 times.
✓ Branch 2 taken 639 times.
✗ Branch 3 not taken.
|
17717 | (s->ps.pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) { |
825 | 1406 | int ret = pred_weight_table(s, gb); | |
826 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1406 times.
|
1406 | if (ret < 0) |
827 | ✗ | return ret; | |
828 | } | ||
829 | |||
830 | 18484 | sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb); | |
831 |
2/4✓ Branch 0 taken 18484 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18484 times.
|
18484 | if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) { |
832 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
833 | "Invalid number of merging MVP candidates: %d.\n", | ||
834 | sh->max_num_merge_cand); | ||
835 | ✗ | return AVERROR_INVALIDDATA; | |
836 | } | ||
837 | } | ||
838 | |||
839 | 19615 | sh->slice_qp_delta = get_se_golomb(gb); | |
840 | |||
841 |
2/2✓ Branch 0 taken 250 times.
✓ Branch 1 taken 19365 times.
|
19615 | if (s->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag) { |
842 | 250 | sh->slice_cb_qp_offset = get_se_golomb(gb); | |
843 | 250 | sh->slice_cr_qp_offset = get_se_golomb(gb); | |
844 |
2/4✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 250 times.
✗ Branch 3 not taken.
|
250 | if (sh->slice_cb_qp_offset < -12 || sh->slice_cb_qp_offset > 12 || |
845 |
2/4✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 250 times.
|
250 | sh->slice_cr_qp_offset < -12 || sh->slice_cr_qp_offset > 12) { |
846 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n"); | |
847 | ✗ | return AVERROR_INVALIDDATA; | |
848 | } | ||
849 | } else { | ||
850 | 19365 | sh->slice_cb_qp_offset = 0; | |
851 | 19365 | sh->slice_cr_qp_offset = 0; | |
852 | } | ||
853 | |||
854 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 19572 times.
|
19615 | if (s->ps.pps->chroma_qp_offset_list_enabled_flag) |
855 | 43 | sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb); | |
856 | else | ||
857 | 19572 | sh->cu_chroma_qp_offset_enabled_flag = 0; | |
858 | |||
859 |
2/2✓ Branch 0 taken 2899 times.
✓ Branch 1 taken 16716 times.
|
19615 | if (s->ps.pps->deblocking_filter_control_present_flag) { |
860 | 2899 | int deblocking_filter_override_flag = 0; | |
861 | |||
862 |
2/2✓ Branch 0 taken 673 times.
✓ Branch 1 taken 2226 times.
|
2899 | if (s->ps.pps->deblocking_filter_override_enabled_flag) |
863 | 673 | deblocking_filter_override_flag = get_bits1(gb); | |
864 | |||
865 |
2/2✓ Branch 0 taken 454 times.
✓ Branch 1 taken 2445 times.
|
2899 | if (deblocking_filter_override_flag) { |
866 | 454 | sh->disable_deblocking_filter_flag = get_bits1(gb); | |
867 |
2/2✓ Branch 0 taken 334 times.
✓ Branch 1 taken 120 times.
|
454 | if (!sh->disable_deblocking_filter_flag) { |
868 | 334 | int beta_offset_div2 = get_se_golomb(gb); | |
869 | 334 | int tc_offset_div2 = get_se_golomb(gb) ; | |
870 |
3/6✓ Branch 0 taken 334 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 334 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 334 times.
✗ Branch 5 not taken.
|
334 | if (beta_offset_div2 < -6 || beta_offset_div2 > 6 || |
871 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 334 times.
|
334 | tc_offset_div2 < -6 || tc_offset_div2 > 6) { |
872 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
873 | "Invalid deblock filter offsets: %d, %d\n", | ||
874 | beta_offset_div2, tc_offset_div2); | ||
875 | ✗ | return AVERROR_INVALIDDATA; | |
876 | } | ||
877 | 334 | sh->beta_offset = beta_offset_div2 * 2; | |
878 | 334 | sh->tc_offset = tc_offset_div2 * 2; | |
879 | } | ||
880 | } else { | ||
881 | 2445 | sh->disable_deblocking_filter_flag = s->ps.pps->disable_dbf; | |
882 | 2445 | sh->beta_offset = s->ps.pps->beta_offset; | |
883 | 2445 | sh->tc_offset = s->ps.pps->tc_offset; | |
884 | } | ||
885 | } else { | ||
886 | 16716 | sh->disable_deblocking_filter_flag = 0; | |
887 | 16716 | sh->beta_offset = 0; | |
888 | 16716 | sh->tc_offset = 0; | |
889 | } | ||
890 | |||
891 |
2/2✓ Branch 0 taken 17080 times.
✓ Branch 1 taken 2535 times.
|
19615 | if (s->ps.pps->seq_loop_filter_across_slices_enabled_flag && |
892 |
2/2✓ Branch 0 taken 11467 times.
✓ Branch 1 taken 5613 times.
|
17080 | (sh->slice_sample_adaptive_offset_flag[0] || |
893 |
2/2✓ Branch 0 taken 11449 times.
✓ Branch 1 taken 18 times.
|
11467 | sh->slice_sample_adaptive_offset_flag[1] || |
894 |
2/2✓ Branch 0 taken 11386 times.
✓ Branch 1 taken 63 times.
|
11449 | !sh->disable_deblocking_filter_flag)) { |
895 | 17017 | sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); | |
896 | } else { | ||
897 | 2598 | sh->slice_loop_filter_across_slices_enabled_flag = s->ps.pps->seq_loop_filter_across_slices_enabled_flag; | |
898 | } | ||
899 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
|
7947 | } else if (!s->slice_initialized) { |
900 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); | |
901 | ✗ | return AVERROR_INVALIDDATA; | |
902 | } | ||
903 | |||
904 | 27562 | sh->num_entry_point_offsets = 0; | |
905 |
4/4✓ Branch 0 taken 24655 times.
✓ Branch 1 taken 2907 times.
✓ Branch 2 taken 4576 times.
✓ Branch 3 taken 20079 times.
|
27562 | if (s->ps.pps->tiles_enabled_flag || s->ps.pps->entropy_coding_sync_enabled_flag) { |
906 | 7483 | unsigned num_entry_point_offsets = get_ue_golomb_long(gb); | |
907 | // It would be possible to bound this tighter but this here is simpler | ||
908 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7483 times.
|
7483 | if (num_entry_point_offsets > get_bits_left(gb)) { |
909 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets); | |
910 | ✗ | return AVERROR_INVALIDDATA; | |
911 | } | ||
912 | |||
913 | 7483 | sh->num_entry_point_offsets = num_entry_point_offsets; | |
914 |
2/2✓ Branch 0 taken 2013 times.
✓ Branch 1 taken 5470 times.
|
7483 | if (sh->num_entry_point_offsets > 0) { |
915 | 2013 | int offset_len = get_ue_golomb_long(gb) + 1; | |
916 | |||
917 |
2/4✓ Branch 0 taken 2013 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2013 times.
|
2013 | if (offset_len < 1 || offset_len > 32) { |
918 | ✗ | sh->num_entry_point_offsets = 0; | |
919 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len); | |
920 | ✗ | return AVERROR_INVALIDDATA; | |
921 | } | ||
922 | |||
923 | 2013 | av_freep(&sh->entry_point_offset); | |
924 | 2013 | av_freep(&sh->offset); | |
925 | 2013 | av_freep(&sh->size); | |
926 | 2013 | sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned)); | |
927 | 2013 | sh->offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); | |
928 | 2013 | sh->size = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); | |
929 |
3/6✓ Branch 0 taken 2013 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2013 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2013 times.
|
2013 | if (!sh->entry_point_offset || !sh->offset || !sh->size) { |
930 | ✗ | sh->num_entry_point_offsets = 0; | |
931 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n"); | |
932 | ✗ | return AVERROR(ENOMEM); | |
933 | } | ||
934 |
2/2✓ Branch 0 taken 7904 times.
✓ Branch 1 taken 2013 times.
|
9917 | for (i = 0; i < sh->num_entry_point_offsets; i++) { |
935 | 7904 | unsigned val = get_bits_long(gb, offset_len); | |
936 | 7904 | sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size | |
937 | } | ||
938 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 2013 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2013 | if (s->threads_number > 1 && (s->ps.pps->num_tile_rows > 1 || s->ps.pps->num_tile_columns > 1)) { |
939 | ✗ | s->enable_parallel_tiles = 0; // TODO: you can enable tiles in parallel here | |
940 | ✗ | s->threads_number = 1; | |
941 | } else | ||
942 | 2013 | s->enable_parallel_tiles = 0; | |
943 | } else | ||
944 | 5470 | s->enable_parallel_tiles = 0; | |
945 | } | ||
946 | |||
947 |
2/2✓ Branch 0 taken 2765 times.
✓ Branch 1 taken 24797 times.
|
27562 | if (s->ps.pps->slice_header_extension_present_flag) { |
948 | 2765 | unsigned int length = get_ue_golomb_long(gb); | |
949 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2765 times.
|
2765 | if (length*8LL > get_bits_left(gb)) { |
950 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n"); | |
951 | ✗ | return AVERROR_INVALIDDATA; | |
952 | } | ||
953 |
2/2✓ Branch 0 taken 20264 times.
✓ Branch 1 taken 2765 times.
|
23029 | for (i = 0; i < length; i++) |
954 | 20264 | skip_bits(gb, 8); // slice_header_extension_data_byte | |
955 | } | ||
956 | |||
957 | // Inferred parameters | ||
958 | 27562 | sh->slice_qp = 26U + s->ps.pps->pic_init_qp_minus26 + sh->slice_qp_delta; | |
959 |
1/2✓ Branch 0 taken 27562 times.
✗ Branch 1 not taken.
|
27562 | if (sh->slice_qp > 51 || |
960 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27562 times.
|
27562 | sh->slice_qp < -s->ps.sps->qp_bd_offset) { |
961 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
962 | "The slice_qp %d is outside the valid range " | ||
963 | "[%d, 51].\n", | ||
964 | ✗ | sh->slice_qp, | |
965 | ✗ | -s->ps.sps->qp_bd_offset); | |
966 | ✗ | return AVERROR_INVALIDDATA; | |
967 | } | ||
968 | |||
969 | 27562 | sh->slice_ctb_addr_rs = sh->slice_segment_addr; | |
970 | |||
971 |
3/4✓ Branch 0 taken 9531 times.
✓ Branch 1 taken 18031 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9531 times.
|
27562 | if (!s->sh.slice_ctb_addr_rs && s->sh.dependent_slice_segment_flag) { |
972 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n"); | |
973 | ✗ | return AVERROR_INVALIDDATA; | |
974 | } | ||
975 | |||
976 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 27562 times.
|
27562 | if (get_bits_left(gb) < 0) { |
977 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
978 | ✗ | "Overread slice header by %d bits\n", -get_bits_left(gb)); | |
979 | ✗ | return AVERROR_INVALIDDATA; | |
980 | } | ||
981 | |||
982 | 27562 | s->HEVClc->first_qp_group = !s->sh.dependent_slice_segment_flag; | |
983 | |||
984 |
2/2✓ Branch 0 taken 22562 times.
✓ Branch 1 taken 5000 times.
|
27562 | if (!s->ps.pps->cu_qp_delta_enabled_flag) |
985 | 22562 | s->HEVClc->qp_y = s->sh.slice_qp; | |
986 | |||
987 | 27562 | s->slice_initialized = 1; | |
988 | 27562 | s->HEVClc->tu.cu_qp_offset_cb = 0; | |
989 | 27562 | s->HEVClc->tu.cu_qp_offset_cr = 0; | |
990 | |||
991 | 27562 | return 0; | |
992 | } | ||
993 | |||
994 | #define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)]) | ||
995 | |||
996 | #define SET_SAO(elem, value) \ | ||
997 | do { \ | ||
998 | if (!sao_merge_up_flag && !sao_merge_left_flag) \ | ||
999 | sao->elem = value; \ | ||
1000 | else if (sao_merge_left_flag) \ | ||
1001 | sao->elem = CTB(s->sao, rx-1, ry).elem; \ | ||
1002 | else if (sao_merge_up_flag) \ | ||
1003 | sao->elem = CTB(s->sao, rx, ry-1).elem; \ | ||
1004 | else \ | ||
1005 | sao->elem = 0; \ | ||
1006 | } while (0) | ||
1007 | |||
1008 | 1403726 | static void hls_sao_param(HEVCContext *s, int rx, int ry) | |
1009 | { | ||
1010 | 1403726 | HEVCLocalContext *lc = s->HEVClc; | |
1011 | 1403726 | int sao_merge_left_flag = 0; | |
1012 | 1403726 | int sao_merge_up_flag = 0; | |
1013 | 1403726 | SAOParams *sao = &CTB(s->sao, rx, ry); | |
1014 | int c_idx, i; | ||
1015 | |||
1016 |
2/2✓ Branch 0 taken 816170 times.
✓ Branch 1 taken 587556 times.
|
1403726 | if (s->sh.slice_sample_adaptive_offset_flag[0] || |
1017 |
2/2✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 814526 times.
|
816170 | s->sh.slice_sample_adaptive_offset_flag[1]) { |
1018 |
2/2✓ Branch 0 taken 558617 times.
✓ Branch 1 taken 30583 times.
|
589200 | if (rx > 0) { |
1019 |
2/2✓ Branch 0 taken 550128 times.
✓ Branch 1 taken 8489 times.
|
558617 | if (lc->ctb_left_flag) |
1020 | 550128 | sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(s); | |
1021 | } | ||
1022 |
4/4✓ Branch 0 taken 539409 times.
✓ Branch 1 taken 49791 times.
✓ Branch 2 taken 262453 times.
✓ Branch 3 taken 276956 times.
|
589200 | if (ry > 0 && !sao_merge_left_flag) { |
1023 |
2/2✓ Branch 0 taken 249105 times.
✓ Branch 1 taken 13348 times.
|
262453 | if (lc->ctb_up_flag) |
1024 | 249105 | sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(s); | |
1025 | } | ||
1026 | } | ||
1027 | |||
1028 |
4/4✓ Branch 0 taken 5614712 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 4211082 times.
✓ Branch 3 taken 1403726 times.
|
5614808 | for (c_idx = 0; c_idx < (s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) { |
1029 |
2/2✓ Branch 0 taken 1403726 times.
✓ Branch 1 taken 2807356 times.
|
4211082 | int log2_sao_offset_scale = c_idx == 0 ? s->ps.pps->log2_sao_offset_scale_luma : |
1030 | 2807356 | s->ps.pps->log2_sao_offset_scale_chroma; | |
1031 | |||
1032 |
2/2✓ Branch 0 taken 2945486 times.
✓ Branch 1 taken 1265596 times.
|
4211082 | if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) { |
1033 | 2945486 | sao->type_idx[c_idx] = SAO_NOT_APPLIED; | |
1034 | 2945486 | continue; | |
1035 | } | ||
1036 | |||
1037 |
2/2✓ Branch 0 taken 339020 times.
✓ Branch 1 taken 926576 times.
|
1265596 | if (c_idx == 2) { |
1038 | 339020 | sao->type_idx[2] = sao->type_idx[1]; | |
1039 | 339020 | sao->eo_class[2] = sao->eo_class[1]; | |
1040 | } else { | ||
1041 |
7/8✓ Branch 0 taken 804235 times.
✓ Branch 1 taken 122341 times.
✓ Branch 2 taken 360849 times.
✓ Branch 3 taken 443386 times.
✓ Branch 5 taken 443386 times.
✓ Branch 6 taken 122341 times.
✓ Branch 7 taken 122341 times.
✗ Branch 8 not taken.
|
926576 | SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(s)); |
1042 | } | ||
1043 | |||
1044 |
2/2✓ Branch 0 taken 773503 times.
✓ Branch 1 taken 492093 times.
|
1265596 | if (sao->type_idx[c_idx] == SAO_NOT_APPLIED) |
1045 | 773503 | continue; | |
1046 | |||
1047 |
2/2✓ Branch 0 taken 1968372 times.
✓ Branch 1 taken 492093 times.
|
2460465 | for (i = 0; i < 4; i++) |
1048 |
7/8✓ Branch 0 taken 1625076 times.
✓ Branch 1 taken 343296 times.
✓ Branch 2 taken 865888 times.
✓ Branch 3 taken 759188 times.
✓ Branch 5 taken 759188 times.
✓ Branch 6 taken 343296 times.
✓ Branch 7 taken 343296 times.
✗ Branch 8 not taken.
|
1968372 | SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(s)); |
1049 | |||
1050 |
2/2✓ Branch 0 taken 116063 times.
✓ Branch 1 taken 376030 times.
|
492093 | if (sao->type_idx[c_idx] == SAO_BAND) { |
1051 |
2/2✓ Branch 0 taken 464252 times.
✓ Branch 1 taken 116063 times.
|
580315 | for (i = 0; i < 4; i++) { |
1052 |
2/2✓ Branch 0 taken 350493 times.
✓ Branch 1 taken 113759 times.
|
464252 | if (sao->offset_abs[c_idx][i]) { |
1053 |
7/8✓ Branch 0 taken 326653 times.
✓ Branch 1 taken 23840 times.
✓ Branch 2 taken 242522 times.
✓ Branch 3 taken 84131 times.
✓ Branch 5 taken 84131 times.
✓ Branch 6 taken 23840 times.
✓ Branch 7 taken 23840 times.
✗ Branch 8 not taken.
|
350493 | SET_SAO(offset_sign[c_idx][i], |
1054 | ff_hevc_sao_offset_sign_decode(s)); | ||
1055 | } else { | ||
1056 | 113759 | sao->offset_sign[c_idx][i] = 0; | |
1057 | } | ||
1058 | } | ||
1059 |
7/8✓ Branch 0 taken 106469 times.
✓ Branch 1 taken 9594 times.
✓ Branch 2 taken 77637 times.
✓ Branch 3 taken 28832 times.
✓ Branch 5 taken 28832 times.
✓ Branch 6 taken 9594 times.
✓ Branch 7 taken 9594 times.
✗ Branch 8 not taken.
|
116063 | SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(s)); |
1060 |
2/2✓ Branch 0 taken 301316 times.
✓ Branch 1 taken 74714 times.
|
376030 | } else if (c_idx != 2) { |
1061 |
7/8✓ Branch 0 taken 240169 times.
✓ Branch 1 taken 61147 times.
✓ Branch 2 taken 108129 times.
✓ Branch 3 taken 132040 times.
✓ Branch 5 taken 132040 times.
✓ Branch 6 taken 61147 times.
✓ Branch 7 taken 61147 times.
✗ Branch 8 not taken.
|
301316 | SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(s)); |
1062 | } | ||
1063 | |||
1064 | // Inferred parameters | ||
1065 | 492093 | sao->offset_val[c_idx][0] = 0; | |
1066 |
2/2✓ Branch 0 taken 1968372 times.
✓ Branch 1 taken 492093 times.
|
2460465 | for (i = 0; i < 4; i++) { |
1067 | 1968372 | sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i]; | |
1068 |
2/2✓ Branch 0 taken 1504120 times.
✓ Branch 1 taken 464252 times.
|
1968372 | if (sao->type_idx[c_idx] == SAO_EDGE) { |
1069 |
2/2✓ Branch 0 taken 752060 times.
✓ Branch 1 taken 752060 times.
|
1504120 | if (i > 1) |
1070 | 752060 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1071 |
2/2✓ Branch 0 taken 154437 times.
✓ Branch 1 taken 309815 times.
|
464252 | } else if (sao->offset_sign[c_idx][i]) { |
1072 | 154437 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
1073 | } | ||
1074 | 1968372 | sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale; | |
1075 | } | ||
1076 | } | ||
1077 | 1403726 | } | |
1078 | |||
1079 | #undef SET_SAO | ||
1080 | #undef CTB | ||
1081 | |||
1082 | 384850 | static int hls_cross_component_pred(HEVCContext *s, int idx) { | |
1083 | 384850 | HEVCLocalContext *lc = s->HEVClc; | |
1084 | 384850 | int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(s, idx); | |
1085 | |||
1086 |
2/2✓ Branch 0 taken 235843 times.
✓ Branch 1 taken 149007 times.
|
384850 | if (log2_res_scale_abs_plus1 != 0) { |
1087 | 235843 | int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(s, idx); | |
1088 | 235843 | lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) * | |
1089 | 235843 | (1 - 2 * res_scale_sign_flag); | |
1090 | } else { | ||
1091 | 149007 | lc->tu.res_scale_val = 0; | |
1092 | } | ||
1093 | |||
1094 | |||
1095 | 384850 | return 0; | |
1096 | } | ||
1097 | |||
1098 | 15218103 | static int hls_transform_unit(HEVCContext *s, int x0, int y0, | |
1099 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1100 | int log2_cb_size, int log2_trafo_size, | ||
1101 | int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr) | ||
1102 | { | ||
1103 | 15218103 | HEVCLocalContext *lc = s->HEVClc; | |
1104 | 15218103 | const int log2_trafo_size_c = log2_trafo_size - s->ps.sps->hshift[1]; | |
1105 | int i; | ||
1106 | |||
1107 |
2/2✓ Branch 0 taken 9622541 times.
✓ Branch 1 taken 5595562 times.
|
15218103 | if (lc->cu.pred_mode == MODE_INTRA) { |
1108 | 9622541 | int trafo_size = 1 << log2_trafo_size; | |
1109 | 9622541 | ff_hevc_set_neighbour_available(s, x0, y0, trafo_size, trafo_size); | |
1110 | |||
1111 | 9622541 | s->hpc.intra_pred[log2_trafo_size - 2](s, x0, y0, 0); | |
1112 | } | ||
1113 | |||
1114 |
6/6✓ Branch 0 taken 5570398 times.
✓ Branch 1 taken 9647705 times.
✓ Branch 2 taken 4946381 times.
✓ Branch 3 taken 624017 times.
✓ Branch 4 taken 4529962 times.
✓ Branch 5 taken 416419 times.
|
15218103 | if (cbf_luma || cbf_cb[0] || cbf_cr[0] || |
1115 |
6/6✓ Branch 0 taken 155767 times.
✓ Branch 1 taken 4374195 times.
✓ Branch 2 taken 146778 times.
✓ Branch 3 taken 8989 times.
✓ Branch 4 taken 52826 times.
✓ Branch 5 taken 93952 times.
|
15279917 | (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1116 | 10749956 | int scan_idx = SCAN_DIAG; | |
1117 | 10749956 | int scan_idx_c = SCAN_DIAG; | |
1118 |
4/4✓ Branch 0 taken 7190688 times.
✓ Branch 1 taken 3559268 times.
✓ Branch 2 taken 5754523 times.
✓ Branch 3 taken 1436165 times.
|
16504479 | int cbf_chroma = cbf_cb[0] || cbf_cr[0] || |
1119 |
2/2✓ Branch 0 taken 231710 times.
✓ Branch 1 taken 5522813 times.
|
5754523 | (s->ps.sps->chroma_format_idc == 2 && |
1120 |
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])); |
1121 | |||
1122 |
4/4✓ Branch 0 taken 2110560 times.
✓ Branch 1 taken 8639396 times.
✓ Branch 2 taken 588011 times.
✓ Branch 3 taken 1522549 times.
|
10749956 | if (s->ps.pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) { |
1123 | 588011 | lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(s); | |
1124 |
2/2✓ Branch 0 taken 368706 times.
✓ Branch 1 taken 219305 times.
|
588011 | if (lc->tu.cu_qp_delta != 0) |
1125 |
2/2✓ Branch 1 taken 203733 times.
✓ Branch 2 taken 164973 times.
|
368706 | if (ff_hevc_cu_qp_delta_sign_flag(s) == 1) |
1126 | 203733 | lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta; | |
1127 | 588011 | lc->tu.is_cu_qp_delta_coded = 1; | |
1128 | |||
1129 |
2/2✓ Branch 0 taken 588010 times.
✓ Branch 1 taken 1 times.
|
588011 | if (lc->tu.cu_qp_delta < -(26 + s->ps.sps->qp_bd_offset / 2) || |
1130 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 588010 times.
|
588010 | lc->tu.cu_qp_delta > (25 + s->ps.sps->qp_bd_offset / 2)) { |
1131 | 1 | av_log(s->avctx, AV_LOG_ERROR, | |
1132 | "The cu_qp_delta %d is outside the valid range " | ||
1133 | "[%d, %d].\n", | ||
1134 | lc->tu.cu_qp_delta, | ||
1135 | 1 | -(26 + s->ps.sps->qp_bd_offset / 2), | |
1136 | 1 | (25 + s->ps.sps->qp_bd_offset / 2)); | |
1137 | 1 | return AVERROR_INVALIDDATA; | |
1138 | } | ||
1139 | |||
1140 | 588010 | ff_hevc_set_qPy(s, cb_xBase, cb_yBase, log2_cb_size); | |
1141 | } | ||
1142 | |||
1143 |
4/4✓ Branch 0 taken 891951 times.
✓ Branch 1 taken 9858004 times.
✓ Branch 2 taken 841055 times.
✓ Branch 3 taken 50896 times.
|
10749955 | if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma && |
1144 |
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) { |
1145 | 266275 | int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(s); | |
1146 |
2/2✓ Branch 0 taken 48966 times.
✓ Branch 1 taken 217309 times.
|
266275 | if (cu_chroma_qp_offset_flag) { |
1147 | 48966 | int cu_chroma_qp_offset_idx = 0; | |
1148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48966 times.
|
48966 | if (s->ps.pps->chroma_qp_offset_list_len_minus1 > 0) { |
1149 | ✗ | cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(s); | |
1150 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1151 | "cu_chroma_qp_offset_idx not yet tested.\n"); | ||
1152 | } | ||
1153 | 48966 | lc->tu.cu_qp_offset_cb = s->ps.pps->cb_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1154 | 48966 | lc->tu.cu_qp_offset_cr = s->ps.pps->cr_qp_offset_list[cu_chroma_qp_offset_idx]; | |
1155 | } else { | ||
1156 | 217309 | lc->tu.cu_qp_offset_cb = 0; | |
1157 | 217309 | lc->tu.cu_qp_offset_cr = 0; | |
1158 | } | ||
1159 | 266275 | lc->tu.is_cu_chroma_qp_offset_coded = 1; | |
1160 | } | ||
1161 | |||
1162 |
4/4✓ Branch 0 taken 7080739 times.
✓ Branch 1 taken 3669216 times.
✓ Branch 2 taken 6217652 times.
✓ Branch 3 taken 863087 times.
|
10749955 | if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) { |
1163 |
2/2✓ Branch 0 taken 4142380 times.
✓ Branch 1 taken 2075272 times.
|
6217652 | if (lc->tu.intra_pred_mode >= 6 && |
1164 |
2/2✓ Branch 0 taken 1498752 times.
✓ Branch 1 taken 2643628 times.
|
4142380 | lc->tu.intra_pred_mode <= 14) { |
1165 | 1498752 | scan_idx = SCAN_VERT; | |
1166 |
2/2✓ Branch 0 taken 2039107 times.
✓ Branch 1 taken 2679793 times.
|
4718900 | } else if (lc->tu.intra_pred_mode >= 22 && |
1167 |
2/2✓ Branch 0 taken 1713097 times.
✓ Branch 1 taken 326010 times.
|
2039107 | lc->tu.intra_pred_mode <= 30) { |
1168 | 1713097 | scan_idx = SCAN_HORIZ; | |
1169 | } | ||
1170 | |||
1171 |
2/2✓ Branch 0 taken 3714281 times.
✓ Branch 1 taken 2503371 times.
|
6217652 | if (lc->tu.intra_pred_mode_c >= 6 && |
1172 |
2/2✓ Branch 0 taken 1409794 times.
✓ Branch 1 taken 2304487 times.
|
3714281 | lc->tu.intra_pred_mode_c <= 14) { |
1173 | 1409794 | scan_idx_c = SCAN_VERT; | |
1174 |
2/2✓ Branch 0 taken 1936335 times.
✓ Branch 1 taken 2871523 times.
|
4807858 | } else if (lc->tu.intra_pred_mode_c >= 22 && |
1175 |
2/2✓ Branch 0 taken 1620477 times.
✓ Branch 1 taken 315858 times.
|
1936335 | lc->tu.intra_pred_mode_c <= 30) { |
1176 | 1620477 | scan_idx_c = SCAN_HORIZ; | |
1177 | } | ||
1178 | } | ||
1179 | |||
1180 | 10749955 | lc->tu.cross_pf = 0; | |
1181 | |||
1182 |
2/2✓ Branch 0 taken 9647704 times.
✓ Branch 1 taken 1102251 times.
|
10749955 | if (cbf_luma) |
1183 | 9647704 | ff_hevc_hls_residual_coding(s, x0, y0, log2_trafo_size, scan_idx, 0); | |
1184 |
6/6✓ Branch 0 taken 10749763 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 6071787 times.
✓ Branch 3 taken 4677976 times.
✓ Branch 4 taken 209563 times.
✓ Branch 5 taken 5862224 times.
|
15637494 | if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) { |
1185 | 4887539 | int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]); | |
1186 | 4887539 | int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]); | |
1187 |
4/4✓ Branch 0 taken 336841 times.
✓ Branch 1 taken 4550698 times.
✓ Branch 2 taken 217816 times.
✓ Branch 3 taken 119025 times.
|
5105355 | lc->tu.cross_pf = (s->ps.pps->cross_component_prediction_enabled_flag && cbf_luma && |
1188 |
2/2✓ Branch 0 taken 168873 times.
✓ Branch 1 taken 48943 times.
|
217816 | (lc->cu.pred_mode == MODE_INTER || |
1189 |
2/2✓ Branch 0 taken 143482 times.
✓ Branch 1 taken 25391 times.
|
168873 | (lc->tu.chroma_mode_c == 4))); |
1190 | |||
1191 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4695114 times.
|
4887539 | if (lc->tu.cross_pf) { |
1192 | 192425 | hls_cross_component_pred(s, 0); | |
1193 | } | ||
1194 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8868674 times.
✓ Branch 2 taken 5340741 times.
✓ Branch 3 taken 4887539 times.
|
10228280 | for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1195 |
2/2✓ Branch 0 taken 2960812 times.
✓ Branch 1 taken 2379929 times.
|
5340741 | if (lc->cu.pred_mode == MODE_INTRA) { |
1196 | 2960812 | ff_hevc_set_neighbour_available(s, x0, y0 + (i << log2_trafo_size_c), trafo_size_h, trafo_size_v); | |
1197 | 2960812 | s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (i << log2_trafo_size_c), 1); | |
1198 | } | ||
1199 |
2/2✓ Branch 0 taken 1488304 times.
✓ Branch 1 taken 3852437 times.
|
5340741 | if (cbf_cb[i]) |
1200 | 1488304 | ff_hevc_hls_residual_coding(s, x0, y0 + (i << log2_trafo_size_c), | |
1201 | log2_trafo_size_c, scan_idx_c, 1); | ||
1202 | else | ||
1203 |
2/2✓ Branch 0 taken 39658 times.
✓ Branch 1 taken 3812779 times.
|
3852437 | if (lc->tu.cross_pf) { |
1204 | 39658 | ptrdiff_t stride = s->frame->linesize[1]; | |
1205 | 39658 | int hshift = s->ps.sps->hshift[1]; | |
1206 | 39658 | int vshift = s->ps.sps->vshift[1]; | |
1207 | 39658 | int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1208 | 39658 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1209 | 39658 | int size = 1 << log2_trafo_size_c; | |
1210 | |||
1211 | 39658 | uint8_t *dst = &s->frame->data[1][(y0 >> vshift) * stride + | |
1212 | 39658 | ((x0 >> hshift) << s->ps.sps->pixel_shift)]; | |
1213 |
2/2✓ Branch 0 taken 1831504 times.
✓ Branch 1 taken 39658 times.
|
1871162 | for (i = 0; i < (size * size); i++) { |
1214 | 1831504 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1215 | } | ||
1216 | 39658 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1217 | } | ||
1218 | } | ||
1219 | |||
1220 |
2/2✓ Branch 0 taken 192425 times.
✓ Branch 1 taken 4695114 times.
|
4887539 | if (lc->tu.cross_pf) { |
1221 | 192425 | hls_cross_component_pred(s, 1); | |
1222 | } | ||
1223 |
4/4✓ Branch 0 taken 1359606 times.
✓ Branch 1 taken 8868674 times.
✓ Branch 2 taken 5340741 times.
✓ Branch 3 taken 4887539 times.
|
10228280 | for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1224 |
2/2✓ Branch 0 taken 2960812 times.
✓ Branch 1 taken 2379929 times.
|
5340741 | if (lc->cu.pred_mode == MODE_INTRA) { |
1225 | 2960812 | ff_hevc_set_neighbour_available(s, x0, y0 + (i << log2_trafo_size_c), trafo_size_h, trafo_size_v); | |
1226 | 2960812 | s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (i << log2_trafo_size_c), 2); | |
1227 | } | ||
1228 |
2/2✓ Branch 0 taken 1603333 times.
✓ Branch 1 taken 3737408 times.
|
5340741 | if (cbf_cr[i]) |
1229 | 1603333 | ff_hevc_hls_residual_coding(s, x0, y0 + (i << log2_trafo_size_c), | |
1230 | log2_trafo_size_c, scan_idx_c, 2); | ||
1231 | else | ||
1232 |
2/2✓ Branch 0 taken 75924 times.
✓ Branch 1 taken 3661484 times.
|
3737408 | if (lc->tu.cross_pf) { |
1233 | 75924 | ptrdiff_t stride = s->frame->linesize[2]; | |
1234 | 75924 | int hshift = s->ps.sps->hshift[2]; | |
1235 | 75924 | int vshift = s->ps.sps->vshift[2]; | |
1236 | 75924 | int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1237 | 75924 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
1238 | 75924 | int size = 1 << log2_trafo_size_c; | |
1239 | |||
1240 | 75924 | uint8_t *dst = &s->frame->data[2][(y0 >> vshift) * stride + | |
1241 | 75924 | ((x0 >> hshift) << s->ps.sps->pixel_shift)]; | |
1242 |
2/2✓ Branch 0 taken 3615552 times.
✓ Branch 1 taken 75924 times.
|
3691476 | for (i = 0; i < (size * size); i++) { |
1243 | 3615552 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1244 | } | ||
1245 | 75924 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
1246 | } | ||
1247 | } | ||
1248 |
4/4✓ Branch 0 taken 5862224 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1505865 times.
✓ Branch 3 taken 4356359 times.
|
5862416 | } else if (s->ps.sps->chroma_format_idc && blk_idx == 3) { |
1249 | 1505865 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1250 | 1505865 | int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]); | |
1251 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2677992 times.
✓ Branch 2 taken 1672734 times.
✓ Branch 3 taken 1505865 times.
|
3178599 | for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1252 |
2/2✓ Branch 0 taken 1192472 times.
✓ Branch 1 taken 480262 times.
|
1672734 | if (lc->cu.pred_mode == MODE_INTRA) { |
1253 | 1192472 | ff_hevc_set_neighbour_available(s, xBase, yBase + (i << log2_trafo_size), | |
1254 | trafo_size_h, trafo_size_v); | ||
1255 | 1192472 | s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (i << log2_trafo_size), 1); | |
1256 | } | ||
1257 |
2/2✓ Branch 0 taken 632335 times.
✓ Branch 1 taken 1040399 times.
|
1672734 | if (cbf_cb[i]) |
1258 | 632335 | ff_hevc_hls_residual_coding(s, xBase, yBase + (i << log2_trafo_size), | |
1259 | log2_trafo_size, scan_idx_c, 1); | ||
1260 | } | ||
1261 |
4/4✓ Branch 0 taken 500607 times.
✓ Branch 1 taken 2677992 times.
✓ Branch 2 taken 1672734 times.
✓ Branch 3 taken 1505865 times.
|
3178599 | for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
1262 |
2/2✓ Branch 0 taken 1192472 times.
✓ Branch 1 taken 480262 times.
|
1672734 | if (lc->cu.pred_mode == MODE_INTRA) { |
1263 | 1192472 | ff_hevc_set_neighbour_available(s, xBase, yBase + (i << log2_trafo_size), | |
1264 | trafo_size_h, trafo_size_v); | ||
1265 | 1192472 | s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (i << log2_trafo_size), 2); | |
1266 | } | ||
1267 |
2/2✓ Branch 0 taken 713268 times.
✓ Branch 1 taken 959466 times.
|
1672734 | if (cbf_cr[i]) |
1268 | 713268 | ff_hevc_hls_residual_coding(s, xBase, yBase + (i << log2_trafo_size), | |
1269 | log2_trafo_size, scan_idx_c, 2); | ||
1270 | } | ||
1271 | } | ||
1272 |
3/4✓ Branch 0 taken 4468147 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2541801 times.
✓ Branch 3 taken 1926346 times.
|
4468147 | } else if (s->ps.sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) { |
1273 |
4/4✓ Branch 0 taken 1584787 times.
✓ Branch 1 taken 957014 times.
✓ Branch 2 taken 60588 times.
✓ Branch 3 taken 1524199 times.
|
3559403 | if (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3) { |
1274 | 1017602 | int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]); | |
1275 | 1017602 | int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]); | |
1276 | 1017602 | ff_hevc_set_neighbour_available(s, x0, y0, trafo_size_h, trafo_size_v); | |
1277 | 1017602 | s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0, 1); | |
1278 | 1017602 | s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0, 2); | |
1279 |
2/2✓ Branch 0 taken 12467 times.
✓ Branch 1 taken 1005135 times.
|
1017602 | if (s->ps.sps->chroma_format_idc == 2) { |
1280 | 12467 | ff_hevc_set_neighbour_available(s, x0, y0 + (1 << log2_trafo_size_c), | |
1281 | trafo_size_h, trafo_size_v); | ||
1282 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (1 << log2_trafo_size_c), 1); | |
1283 | 12467 | s->hpc.intra_pred[log2_trafo_size_c - 2](s, x0, y0 + (1 << log2_trafo_size_c), 2); | |
1284 | } | ||
1285 |
2/2✓ Branch 0 taken 346107 times.
✓ Branch 1 taken 1178092 times.
|
1524199 | } else if (blk_idx == 3) { |
1286 | 346107 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
1287 | 346107 | int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]); | |
1288 | 346107 | ff_hevc_set_neighbour_available(s, xBase, yBase, | |
1289 | trafo_size_h, trafo_size_v); | ||
1290 | 346107 | s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase, 1); | |
1291 | 346107 | s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase, 2); | |
1292 |
2/2✓ Branch 0 taken 4196 times.
✓ Branch 1 taken 341911 times.
|
346107 | if (s->ps.sps->chroma_format_idc == 2) { |
1293 | 4196 | ff_hevc_set_neighbour_available(s, xBase, yBase + (1 << (log2_trafo_size)), | |
1294 | trafo_size_h, trafo_size_v); | ||
1295 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (1 << (log2_trafo_size)), 1); | |
1296 | 4196 | s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase + (1 << (log2_trafo_size)), 2); | |
1297 | } | ||
1298 | } | ||
1299 | } | ||
1300 | |||
1301 | 15218102 | return 0; | |
1302 | } | ||
1303 | |||
1304 | 356478 | static void set_deblocking_bypass(HEVCContext *s, int x0, int y0, int log2_cb_size) | |
1305 | { | ||
1306 | 356478 | int cb_size = 1 << log2_cb_size; | |
1307 | 356478 | int log2_min_pu_size = s->ps.sps->log2_min_pu_size; | |
1308 | |||
1309 | 356478 | int min_pu_width = s->ps.sps->min_pu_width; | |
1310 | 356478 | int x_end = FFMIN(x0 + cb_size, s->ps.sps->width); | |
1311 | 356478 | int y_end = FFMIN(y0 + cb_size, s->ps.sps->height); | |
1312 | int i, j; | ||
1313 | |||
1314 |
2/2✓ Branch 0 taken 494908 times.
✓ Branch 1 taken 356478 times.
|
851386 | for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++) |
1315 |
2/2✓ Branch 0 taken 949056 times.
✓ Branch 1 taken 494908 times.
|
1443964 | for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++) |
1316 | 949056 | s->is_pcm[i + j * min_pu_width] = 2; | |
1317 | 356478 | } | |
1318 | |||
1319 | 18380471 | static int hls_transform_tree(HEVCContext *s, int x0, int y0, | |
1320 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
1321 | int log2_cb_size, int log2_trafo_size, | ||
1322 | int trafo_depth, int blk_idx, | ||
1323 | const int *base_cbf_cb, const int *base_cbf_cr) | ||
1324 | { | ||
1325 | 18380471 | HEVCLocalContext *lc = s->HEVClc; | |
1326 | uint8_t split_transform_flag; | ||
1327 | int cbf_cb[2]; | ||
1328 | int cbf_cr[2]; | ||
1329 | int ret; | ||
1330 | |||
1331 | 18380471 | cbf_cb[0] = base_cbf_cb[0]; | |
1332 | 18380471 | cbf_cb[1] = base_cbf_cb[1]; | |
1333 | 18380471 | cbf_cr[0] = base_cbf_cr[0]; | |
1334 | 18380471 | cbf_cr[1] = base_cbf_cr[1]; | |
1335 | |||
1336 |
2/2✓ Branch 0 taken 6311671 times.
✓ Branch 1 taken 12068800 times.
|
18380471 | if (lc->cu.intra_split_flag) { |
1337 |
2/2✓ Branch 0 taken 4747276 times.
✓ Branch 1 taken 1564395 times.
|
6311671 | if (trafo_depth == 1) { |
1338 | 4747276 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx]; | |
1339 |
2/2✓ Branch 0 taken 135404 times.
✓ Branch 1 taken 4611872 times.
|
4747276 | if (s->ps.sps->chroma_format_idc == 3) { |
1340 | 135404 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx]; | |
1341 | 135404 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx]; | |
1342 | } else { | ||
1343 | 4611872 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1344 | 4611872 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1345 | } | ||
1346 | } | ||
1347 | } else { | ||
1348 | 12068800 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0]; | |
1349 | 12068800 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
1350 | 12068800 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
1351 | } | ||
1352 | |||
1353 |
2/2✓ Branch 0 taken 18272593 times.
✓ Branch 1 taken 107878 times.
|
18380471 | if (log2_trafo_size <= s->ps.sps->log2_max_trafo_size && |
1354 |
2/2✓ Branch 0 taken 9558925 times.
✓ Branch 1 taken 8713668 times.
|
18272593 | log2_trafo_size > s->ps.sps->log2_min_tb_size && |
1355 |
2/2✓ Branch 0 taken 8001345 times.
✓ Branch 1 taken 1557580 times.
|
9558925 | trafo_depth < lc->cu.max_trafo_depth && |
1356 |
4/4✓ Branch 0 taken 1670044 times.
✓ Branch 1 taken 6331301 times.
✓ Branch 2 taken 490612 times.
✓ Branch 3 taken 1179432 times.
|
8001345 | !(lc->cu.intra_split_flag && trafo_depth == 0)) { |
1357 | 6821913 | split_transform_flag = ff_hevc_split_transform_flag_decode(s, log2_trafo_size); | |
1358 | } else { | ||
1359 | 24741488 | int inter_split = s->ps.sps->max_transform_hierarchy_depth_inter == 0 && | |
1360 |
2/2✓ Branch 0 taken 834875 times.
✓ Branch 1 taken 789497 times.
|
1624372 | lc->cu.pred_mode == MODE_INTER && |
1361 |
6/6✓ Branch 0 taken 1624372 times.
✓ Branch 1 taken 9934186 times.
✓ Branch 2 taken 675549 times.
✓ Branch 3 taken 159326 times.
✓ Branch 4 taken 133801 times.
✓ Branch 5 taken 541748 times.
|
13182930 | lc->cu.part_mode != PART_2Nx2N && |
1362 | trafo_depth == 0; | ||
1363 | |||
1364 | 11558558 | split_transform_flag = log2_trafo_size > s->ps.sps->log2_max_trafo_size || | |
1365 |
8/8✓ Branch 0 taken 11450680 times.
✓ Branch 1 taken 107878 times.
✓ Branch 2 taken 5813012 times.
✓ Branch 3 taken 5637668 times.
✓ Branch 4 taken 4633580 times.
✓ Branch 5 taken 1179432 times.
✓ Branch 6 taken 118638 times.
✓ Branch 7 taken 10152610 times.
|
11558558 | (lc->cu.intra_split_flag && trafo_depth == 0) || |
1366 | inter_split; | ||
1367 | } | ||
1368 | |||
1369 |
6/6✓ Branch 0 taken 18380279 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8585588 times.
✓ Branch 3 taken 9794691 times.
✓ Branch 4 taken 314416 times.
✓ Branch 5 taken 8271172 times.
|
18380471 | if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) { |
1370 |
4/4✓ Branch 0 taken 4378300 times.
✓ Branch 1 taken 5730807 times.
✓ Branch 2 taken 1219808 times.
✓ Branch 3 taken 3158492 times.
|
10109107 | if (trafo_depth == 0 || cbf_cb[0]) { |
1371 | 6950615 | cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth); | |
1372 |
6/6✓ Branch 0 taken 598266 times.
✓ Branch 1 taken 6352349 times.
✓ Branch 2 taken 211307 times.
✓ Branch 3 taken 386959 times.
✓ Branch 4 taken 140037 times.
✓ Branch 5 taken 71270 times.
|
6950615 | if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1373 | 526996 | cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth); | |
1374 | } | ||
1375 | } | ||
1376 | |||
1377 |
4/4✓ Branch 0 taken 4378300 times.
✓ Branch 1 taken 5730807 times.
✓ Branch 2 taken 1166360 times.
✓ Branch 3 taken 3211940 times.
|
10109107 | if (trafo_depth == 0 || cbf_cr[0]) { |
1378 | 6897167 | cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth); | |
1379 |
6/6✓ Branch 0 taken 745306 times.
✓ Branch 1 taken 6151861 times.
✓ Branch 2 taken 259088 times.
✓ Branch 3 taken 486218 times.
✓ Branch 4 taken 175743 times.
✓ Branch 5 taken 83345 times.
|
6897167 | if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
1380 | 661961 | cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(s, trafo_depth); | |
1381 | } | ||
1382 | } | ||
1383 | } | ||
1384 | |||
1385 |
2/2✓ Branch 0 taken 3162368 times.
✓ Branch 1 taken 15218103 times.
|
18380471 | if (split_transform_flag) { |
1386 | 3162368 | const int trafo_size_split = 1 << (log2_trafo_size - 1); | |
1387 | 3162368 | const int x1 = x0 + trafo_size_split; | |
1388 | 3162368 | const int y1 = y0 + trafo_size_split; | |
1389 | |||
1390 | #define SUBDIVIDE(x, y, idx) \ | ||
1391 | do { \ | ||
1392 | ret = hls_transform_tree(s, x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \ | ||
1393 | log2_trafo_size - 1, trafo_depth + 1, idx, \ | ||
1394 | cbf_cb, cbf_cr); \ | ||
1395 | if (ret < 0) \ | ||
1396 | return ret; \ | ||
1397 | } while (0) | ||
1398 | |||
1399 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3162368 times.
|
3162368 | SUBDIVIDE(x0, y0, 0); |
1400 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3162368 times.
|
3162368 | SUBDIVIDE(x1, y0, 1); |
1401 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3162368 times.
|
3162368 | SUBDIVIDE(x0, y1, 2); |
1402 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3162368 times.
|
3162368 | SUBDIVIDE(x1, y1, 3); |
1403 | |||
1404 | #undef SUBDIVIDE | ||
1405 | } else { | ||
1406 | 15218103 | int min_tu_size = 1 << s->ps.sps->log2_min_tb_size; | |
1407 | 15218103 | int log2_min_tu_size = s->ps.sps->log2_min_tb_size; | |
1408 | 15218103 | int min_tu_width = s->ps.sps->min_tb_width; | |
1409 | 15218103 | int cbf_luma = 1; | |
1410 | |||
1411 |
4/4✓ Branch 0 taken 5595562 times.
✓ Branch 1 taken 9622541 times.
✓ Branch 2 taken 978822 times.
✓ Branch 3 taken 4616740 times.
|
15218103 | if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 || |
1412 |
4/4✓ Branch 0 taken 800529 times.
✓ Branch 1 taken 178293 times.
✓ Branch 2 taken 685601 times.
✓ Branch 3 taken 114928 times.
|
978822 | cbf_cb[0] || cbf_cr[0] || |
1413 |
6/6✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 660925 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
|
685601 | (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
1414 | 14545148 | cbf_luma = ff_hevc_cbf_luma_decode(s, trafo_depth); | |
1415 | } | ||
1416 | |||
1417 | 15218103 | ret = hls_transform_unit(s, x0, y0, xBase, yBase, cb_xBase, cb_yBase, | |
1418 | log2_cb_size, log2_trafo_size, | ||
1419 | blk_idx, cbf_luma, cbf_cb, cbf_cr); | ||
1420 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15218102 times.
|
15218103 | if (ret < 0) |
1421 | 1 | return ret; | |
1422 | // TODO: store cbf_luma somewhere else | ||
1423 |
2/2✓ Branch 0 taken 9647704 times.
✓ Branch 1 taken 5570398 times.
|
15218102 | if (cbf_luma) { |
1424 | int i, j; | ||
1425 |
2/2✓ Branch 0 taken 19603530 times.
✓ Branch 1 taken 9647704 times.
|
29251234 | for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size) |
1426 |
2/2✓ Branch 0 taken 69692284 times.
✓ Branch 1 taken 19603530 times.
|
89295814 | for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) { |
1427 | 69692284 | int x_tu = (x0 + j) >> log2_min_tu_size; | |
1428 | 69692284 | int y_tu = (y0 + i) >> log2_min_tu_size; | |
1429 | 69692284 | s->cbf_luma[y_tu * min_tu_width + x_tu] = 1; | |
1430 | } | ||
1431 | } | ||
1432 |
2/2✓ Branch 0 taken 14685282 times.
✓ Branch 1 taken 532820 times.
|
15218102 | if (!s->sh.disable_deblocking_filter_flag) { |
1433 | 14685282 | ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_trafo_size); | |
1434 |
2/2✓ Branch 0 taken 373941 times.
✓ Branch 1 taken 14311341 times.
|
14685282 | if (s->ps.pps->transquant_bypass_enable_flag && |
1435 |
2/2✓ Branch 0 taken 275932 times.
✓ Branch 1 taken 98009 times.
|
373941 | lc->cu.cu_transquant_bypass_flag) |
1436 | 275932 | set_deblocking_bypass(s, x0, y0, log2_trafo_size); | |
1437 | } | ||
1438 | } | ||
1439 | 18380470 | return 0; | |
1440 | } | ||
1441 | |||
1442 | 12433 | static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size) | |
1443 | { | ||
1444 | 12433 | HEVCLocalContext *lc = s->HEVClc; | |
1445 | GetBitContext gb; | ||
1446 | 12433 | int cb_size = 1 << log2_cb_size; | |
1447 | 12433 | ptrdiff_t stride0 = s->frame->linesize[0]; | |
1448 | 12433 | ptrdiff_t stride1 = s->frame->linesize[1]; | |
1449 | 12433 | ptrdiff_t stride2 = s->frame->linesize[2]; | |
1450 | 12433 | uint8_t *dst0 = &s->frame->data[0][y0 * stride0 + (x0 << s->ps.sps->pixel_shift)]; | |
1451 | 12433 | uint8_t *dst1 = &s->frame->data[1][(y0 >> s->ps.sps->vshift[1]) * stride1 + ((x0 >> s->ps.sps->hshift[1]) << s->ps.sps->pixel_shift)]; | |
1452 | 12433 | uint8_t *dst2 = &s->frame->data[2][(y0 >> s->ps.sps->vshift[2]) * stride2 + ((x0 >> s->ps.sps->hshift[2]) << s->ps.sps->pixel_shift)]; | |
1453 | |||
1454 | 12433 | int length = cb_size * cb_size * s->ps.sps->pcm.bit_depth + | |
1455 | 12433 | (((cb_size >> s->ps.sps->hshift[1]) * (cb_size >> s->ps.sps->vshift[1])) + | |
1456 | 12433 | ((cb_size >> s->ps.sps->hshift[2]) * (cb_size >> s->ps.sps->vshift[2]))) * | |
1457 | 12433 | s->ps.sps->pcm.bit_depth_chroma; | |
1458 | 12433 | const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3); | |
1459 | int ret; | ||
1460 | |||
1461 |
2/2✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 5496 times.
|
12433 | if (!s->sh.disable_deblocking_filter_flag) |
1462 | 6937 | ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size); | |
1463 | |||
1464 | 12433 | ret = init_get_bits(&gb, pcm, length); | |
1465 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
|
12433 | if (ret < 0) |
1466 | ✗ | return ret; | |
1467 | |||
1468 | 12433 | s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, s->ps.sps->pcm.bit_depth); | |
1469 |
1/2✓ Branch 0 taken 12433 times.
✗ Branch 1 not taken.
|
12433 | if (s->ps.sps->chroma_format_idc) { |
1470 | 12433 | s->hevcdsp.put_pcm(dst1, stride1, | |
1471 | 12433 | cb_size >> s->ps.sps->hshift[1], | |
1472 | 12433 | cb_size >> s->ps.sps->vshift[1], | |
1473 | 12433 | &gb, s->ps.sps->pcm.bit_depth_chroma); | |
1474 | 12433 | s->hevcdsp.put_pcm(dst2, stride2, | |
1475 | 12433 | cb_size >> s->ps.sps->hshift[2], | |
1476 | 12433 | cb_size >> s->ps.sps->vshift[2], | |
1477 | 12433 | &gb, s->ps.sps->pcm.bit_depth_chroma); | |
1478 | } | ||
1479 | |||
1480 | 12433 | return 0; | |
1481 | } | ||
1482 | |||
1483 | /** | ||
1484 | * 8.5.3.2.2.1 Luma sample unidirectional interpolation process | ||
1485 | * | ||
1486 | * @param s HEVC decoding context | ||
1487 | * @param dst target buffer for block data at block position | ||
1488 | * @param dststride stride of the dst buffer | ||
1489 | * @param ref reference picture buffer at origin (0, 0) | ||
1490 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1491 | * @param x_off horizontal position of block from origin (0, 0) | ||
1492 | * @param y_off vertical position of block from origin (0, 0) | ||
1493 | * @param block_w width of block | ||
1494 | * @param block_h height of block | ||
1495 | * @param luma_weight weighting factor applied to the luma prediction | ||
1496 | * @param luma_offset additive offset applied to the luma prediction value | ||
1497 | */ | ||
1498 | |||
1499 | 4802517 | static void luma_mc_uni(HEVCContext *s, uint8_t *dst, ptrdiff_t dststride, | |
1500 | AVFrame *ref, const Mv *mv, int x_off, int y_off, | ||
1501 | int block_w, int block_h, int luma_weight, int luma_offset) | ||
1502 | { | ||
1503 | 4802517 | HEVCLocalContext *lc = s->HEVClc; | |
1504 | 4802517 | uint8_t *src = ref->data[0]; | |
1505 | 4802517 | ptrdiff_t srcstride = ref->linesize[0]; | |
1506 | 4802517 | int pic_width = s->ps.sps->width; | |
1507 | 4802517 | int pic_height = s->ps.sps->height; | |
1508 | 4802517 | int mx = mv->x & 3; | |
1509 | 4802517 | int my = mv->y & 3; | |
1510 |
4/4✓ Branch 0 taken 1959913 times.
✓ Branch 1 taken 2842604 times.
✓ Branch 2 taken 1914256 times.
✓ Branch 3 taken 45657 times.
|
9559377 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) || |
1511 |
4/4✓ Branch 0 taken 2842604 times.
✓ Branch 1 taken 1914256 times.
✓ Branch 2 taken 60281 times.
✓ Branch 3 taken 2782323 times.
|
4756860 | (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag); |
1512 | 4802517 | int idx = hevc_pel_weight[block_w]; | |
1513 | |||
1514 | 4802517 | x_off += mv->x >> 2; | |
1515 | 4802517 | y_off += mv->y >> 2; | |
1516 | 4802517 | src += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift)); | |
1517 | |||
1518 |
4/4✓ Branch 0 taken 4747221 times.
✓ Branch 1 taken 55296 times.
✓ Branch 2 taken 4643356 times.
✓ Branch 3 taken 103865 times.
|
4802517 | if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER || |
1519 |
2/2✓ Branch 0 taken 4580428 times.
✓ Branch 1 taken 62928 times.
|
4643356 | x_off >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1520 |
2/2✓ Branch 0 taken 192498 times.
✓ Branch 1 taken 4387930 times.
|
4580428 | y_off >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1521 | 414587 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1522 | 414587 | int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1523 | 414587 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1524 | |||
1525 | 414587 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset, | |
1526 | edge_emu_stride, srcstride, | ||
1527 | block_w + QPEL_EXTRA, | ||
1528 | block_h + QPEL_EXTRA, | ||
1529 | x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE, | ||
1530 | pic_width, pic_height); | ||
1531 | 414587 | src = lc->edge_emu_buffer + buf_offset; | |
1532 | 414587 | srcstride = edge_emu_stride; | |
1533 | } | ||
1534 | |||
1535 |
2/2✓ Branch 0 taken 4696579 times.
✓ Branch 1 taken 105938 times.
|
4802517 | if (!weight_flag) |
1536 | 4696579 | s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1537 | block_h, mx, my, block_w); | ||
1538 | else | ||
1539 | 105938 | s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
1540 | 105938 | block_h, s->sh.luma_log2_weight_denom, | |
1541 | luma_weight, luma_offset, mx, my, block_w); | ||
1542 | 4802517 | } | |
1543 | |||
1544 | /** | ||
1545 | * 8.5.3.2.2.1 Luma sample bidirectional interpolation process | ||
1546 | * | ||
1547 | * @param s HEVC decoding context | ||
1548 | * @param dst target buffer for block data at block position | ||
1549 | * @param dststride stride of the dst buffer | ||
1550 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1551 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1552 | * @param x_off horizontal position of block from origin (0, 0) | ||
1553 | * @param y_off vertical position of block from origin (0, 0) | ||
1554 | * @param block_w width of block | ||
1555 | * @param block_h height of block | ||
1556 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1557 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1558 | * @param current_mv current motion vector structure | ||
1559 | */ | ||
1560 | 3781449 | static void luma_mc_bi(HEVCContext *s, uint8_t *dst, ptrdiff_t dststride, | |
1561 | AVFrame *ref0, const Mv *mv0, int x_off, int y_off, | ||
1562 | int block_w, int block_h, AVFrame *ref1, const Mv *mv1, struct MvField *current_mv) | ||
1563 | { | ||
1564 | 3781449 | HEVCLocalContext *lc = s->HEVClc; | |
1565 | 3781449 | ptrdiff_t src0stride = ref0->linesize[0]; | |
1566 | 3781449 | ptrdiff_t src1stride = ref1->linesize[0]; | |
1567 | 3781449 | int pic_width = s->ps.sps->width; | |
1568 | 3781449 | int pic_height = s->ps.sps->height; | |
1569 | 3781449 | int mx0 = mv0->x & 3; | |
1570 | 3781449 | int my0 = mv0->y & 3; | |
1571 | 3781449 | int mx1 = mv1->x & 3; | |
1572 | 3781449 | int my1 = mv1->y & 3; | |
1573 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3781449 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7562898 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) || |
1574 |
3/4✓ Branch 0 taken 3781449 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62307 times.
✓ Branch 3 taken 3719142 times.
|
3781449 | (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag); |
1575 | 3781449 | int x_off0 = x_off + (mv0->x >> 2); | |
1576 | 3781449 | int y_off0 = y_off + (mv0->y >> 2); | |
1577 | 3781449 | int x_off1 = x_off + (mv1->x >> 2); | |
1578 | 3781449 | int y_off1 = y_off + (mv1->y >> 2); | |
1579 | 3781449 | int idx = hevc_pel_weight[block_w]; | |
1580 | |||
1581 | 3781449 | uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift); | |
1582 | 3781449 | uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift); | |
1583 | |||
1584 |
4/4✓ Branch 0 taken 3729172 times.
✓ Branch 1 taken 52277 times.
✓ Branch 2 taken 3629676 times.
✓ Branch 3 taken 99496 times.
|
3781449 | if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER || |
1585 |
2/2✓ Branch 0 taken 3566623 times.
✓ Branch 1 taken 63053 times.
|
3629676 | x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1586 |
2/2✓ Branch 0 taken 200716 times.
✓ Branch 1 taken 3365907 times.
|
3566623 | y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1587 | 415542 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1588 | 415542 | int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1589 | 415542 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1590 | |||
1591 | 415542 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset, | |
1592 | edge_emu_stride, src0stride, | ||
1593 | block_w + QPEL_EXTRA, | ||
1594 | block_h + QPEL_EXTRA, | ||
1595 | x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE, | ||
1596 | pic_width, pic_height); | ||
1597 | 415542 | src0 = lc->edge_emu_buffer + buf_offset; | |
1598 | 415542 | src0stride = edge_emu_stride; | |
1599 | } | ||
1600 | |||
1601 |
4/4✓ Branch 0 taken 3723733 times.
✓ Branch 1 taken 57716 times.
✓ Branch 2 taken 3624885 times.
✓ Branch 3 taken 98848 times.
|
3781449 | if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER || |
1602 |
2/2✓ Branch 0 taken 3559536 times.
✓ Branch 1 taken 65349 times.
|
3624885 | x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
1603 |
2/2✓ Branch 0 taken 204563 times.
✓ Branch 1 taken 3354973 times.
|
3559536 | y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
1604 | 426476 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1605 | 426476 | int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1606 | 426476 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift); | |
1607 | |||
1608 | 426476 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset, | |
1609 | edge_emu_stride, src1stride, | ||
1610 | block_w + QPEL_EXTRA, | ||
1611 | block_h + QPEL_EXTRA, | ||
1612 | x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE, | ||
1613 | pic_width, pic_height); | ||
1614 | 426476 | src1 = lc->edge_emu_buffer2 + buf_offset; | |
1615 | 426476 | src1stride = edge_emu_stride; | |
1616 | } | ||
1617 | |||
1618 | 3781449 | s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride, | |
1619 | block_h, mx0, my0, block_w); | ||
1620 |
2/2✓ Branch 0 taken 3719142 times.
✓ Branch 1 taken 62307 times.
|
3781449 | if (!weight_flag) |
1621 | 3719142 | s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1622 | block_h, mx1, my1, block_w); | ||
1623 | else | ||
1624 | 62307 | s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
1625 | 62307 | block_h, s->sh.luma_log2_weight_denom, | |
1626 | 62307 | s->sh.luma_weight_l0[current_mv->ref_idx[0]], | |
1627 | 62307 | s->sh.luma_weight_l1[current_mv->ref_idx[1]], | |
1628 | 62307 | s->sh.luma_offset_l0[current_mv->ref_idx[0]], | |
1629 | 62307 | s->sh.luma_offset_l1[current_mv->ref_idx[1]], | |
1630 | mx1, my1, block_w); | ||
1631 | |||
1632 | 3781449 | } | |
1633 | |||
1634 | /** | ||
1635 | * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process | ||
1636 | * | ||
1637 | * @param s HEVC decoding context | ||
1638 | * @param dst1 target buffer for block data at block position (U plane) | ||
1639 | * @param dst2 target buffer for block data at block position (V plane) | ||
1640 | * @param dststride stride of the dst1 and dst2 buffers | ||
1641 | * @param ref reference picture buffer at origin (0, 0) | ||
1642 | * @param mv motion vector (relative to block position) to get pixel data from | ||
1643 | * @param x_off horizontal position of block from origin (0, 0) | ||
1644 | * @param y_off vertical position of block from origin (0, 0) | ||
1645 | * @param block_w width of block | ||
1646 | * @param block_h height of block | ||
1647 | * @param chroma_weight weighting factor applied to the chroma prediction | ||
1648 | * @param chroma_offset additive offset applied to the chroma prediction value | ||
1649 | */ | ||
1650 | |||
1651 | 9605034 | static void chroma_mc_uni(HEVCContext *s, uint8_t *dst0, | |
1652 | ptrdiff_t dststride, uint8_t *src0, ptrdiff_t srcstride, int reflist, | ||
1653 | int x_off, int y_off, int block_w, int block_h, struct MvField *current_mv, int chroma_weight, int chroma_offset) | ||
1654 | { | ||
1655 | 9605034 | HEVCLocalContext *lc = s->HEVClc; | |
1656 | 9605034 | int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1]; | |
1657 | 9605034 | int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1]; | |
1658 | 9605034 | const Mv *mv = ¤t_mv->mv[reflist]; | |
1659 |
4/4✓ Branch 0 taken 3919826 times.
✓ Branch 1 taken 5685208 times.
✓ Branch 2 taken 3828512 times.
✓ Branch 3 taken 91314 times.
|
19118754 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) || |
1660 |
4/4✓ Branch 0 taken 5685208 times.
✓ Branch 1 taken 3828512 times.
✓ Branch 2 taken 120562 times.
✓ Branch 3 taken 5564646 times.
|
9513720 | (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag); |
1661 | 9605034 | int idx = hevc_pel_weight[block_w]; | |
1662 | 9605034 | int hshift = s->ps.sps->hshift[1]; | |
1663 | 9605034 | int vshift = s->ps.sps->vshift[1]; | |
1664 | 9605034 | intptr_t mx = av_mod_uintp2(mv->x, 2 + hshift); | |
1665 | 9605034 | intptr_t my = av_mod_uintp2(mv->y, 2 + vshift); | |
1666 | 9605034 | intptr_t _mx = mx << (1 - hshift); | |
1667 | 9605034 | intptr_t _my = my << (1 - vshift); | |
1668 | |||
1669 | 9605034 | x_off += mv->x >> (2 + hshift); | |
1670 | 9605034 | y_off += mv->y >> (2 + vshift); | |
1671 | 9605034 | src0 += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift)); | |
1672 | |||
1673 |
4/4✓ Branch 0 taken 9504440 times.
✓ Branch 1 taken 100594 times.
✓ Branch 2 taken 9296572 times.
✓ Branch 3 taken 207868 times.
|
9605034 | if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER || |
1674 |
2/2✓ Branch 0 taken 9170724 times.
✓ Branch 1 taken 125848 times.
|
9296572 | x_off >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1675 |
2/2✓ Branch 0 taken 385052 times.
✓ Branch 1 taken 8785672 times.
|
9170724 | y_off >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
1676 | 819362 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1677 | 819362 | int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << s->ps.sps->pixel_shift)); | |
1678 | 819362 | int buf_offset0 = EPEL_EXTRA_BEFORE * | |
1679 | 819362 | (edge_emu_stride + (1 << s->ps.sps->pixel_shift)); | |
1680 | 819362 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0, | |
1681 | edge_emu_stride, srcstride, | ||
1682 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1683 | x_off - EPEL_EXTRA_BEFORE, | ||
1684 | y_off - EPEL_EXTRA_BEFORE, | ||
1685 | pic_width, pic_height); | ||
1686 | |||
1687 | 819362 | src0 = lc->edge_emu_buffer + buf_offset0; | |
1688 | 819362 | srcstride = edge_emu_stride; | |
1689 | } | ||
1690 |
2/2✓ Branch 0 taken 9393158 times.
✓ Branch 1 taken 211876 times.
|
9605034 | if (!weight_flag) |
1691 | 9393158 | s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1692 | block_h, _mx, _my, block_w); | ||
1693 | else | ||
1694 | 211876 | s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
1695 | 211876 | block_h, s->sh.chroma_log2_weight_denom, | |
1696 | chroma_weight, chroma_offset, _mx, _my, block_w); | ||
1697 | 9605034 | } | |
1698 | |||
1699 | /** | ||
1700 | * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process | ||
1701 | * | ||
1702 | * @param s HEVC decoding context | ||
1703 | * @param dst target buffer for block data at block position | ||
1704 | * @param dststride stride of the dst buffer | ||
1705 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
1706 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
1707 | * @param x_off horizontal position of block from origin (0, 0) | ||
1708 | * @param y_off vertical position of block from origin (0, 0) | ||
1709 | * @param block_w width of block | ||
1710 | * @param block_h height of block | ||
1711 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
1712 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
1713 | * @param current_mv current motion vector structure | ||
1714 | * @param cidx chroma component(cb, cr) | ||
1715 | */ | ||
1716 | 7562898 | static void chroma_mc_bi(HEVCContext *s, uint8_t *dst0, ptrdiff_t dststride, AVFrame *ref0, AVFrame *ref1, | |
1717 | int x_off, int y_off, int block_w, int block_h, struct MvField *current_mv, int cidx) | ||
1718 | { | ||
1719 | 7562898 | HEVCLocalContext *lc = s->HEVClc; | |
1720 | 7562898 | uint8_t *src1 = ref0->data[cidx+1]; | |
1721 | 7562898 | uint8_t *src2 = ref1->data[cidx+1]; | |
1722 | 7562898 | ptrdiff_t src1stride = ref0->linesize[cidx+1]; | |
1723 | 7562898 | ptrdiff_t src2stride = ref1->linesize[cidx+1]; | |
1724 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7562898 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
15125796 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) || |
1725 |
3/4✓ Branch 0 taken 7562898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 124614 times.
✓ Branch 3 taken 7438284 times.
|
7562898 | (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag); |
1726 | 7562898 | int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1]; | |
1727 | 7562898 | int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1]; | |
1728 | 7562898 | Mv *mv0 = ¤t_mv->mv[0]; | |
1729 | 7562898 | Mv *mv1 = ¤t_mv->mv[1]; | |
1730 | 7562898 | int hshift = s->ps.sps->hshift[1]; | |
1731 | 7562898 | int vshift = s->ps.sps->vshift[1]; | |
1732 | |||
1733 | 7562898 | intptr_t mx0 = av_mod_uintp2(mv0->x, 2 + hshift); | |
1734 | 7562898 | intptr_t my0 = av_mod_uintp2(mv0->y, 2 + vshift); | |
1735 | 7562898 | intptr_t mx1 = av_mod_uintp2(mv1->x, 2 + hshift); | |
1736 | 7562898 | intptr_t my1 = av_mod_uintp2(mv1->y, 2 + vshift); | |
1737 | 7562898 | intptr_t _mx0 = mx0 << (1 - hshift); | |
1738 | 7562898 | intptr_t _my0 = my0 << (1 - vshift); | |
1739 | 7562898 | intptr_t _mx1 = mx1 << (1 - hshift); | |
1740 | 7562898 | intptr_t _my1 = my1 << (1 - vshift); | |
1741 | |||
1742 | 7562898 | int x_off0 = x_off + (mv0->x >> (2 + hshift)); | |
1743 | 7562898 | int y_off0 = y_off + (mv0->y >> (2 + vshift)); | |
1744 | 7562898 | int x_off1 = x_off + (mv1->x >> (2 + hshift)); | |
1745 | 7562898 | int y_off1 = y_off + (mv1->y >> (2 + vshift)); | |
1746 | 7562898 | int idx = hevc_pel_weight[block_w]; | |
1747 | 7562898 | src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift); | |
1748 | 7562898 | src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift); | |
1749 | |||
1750 |
4/4✓ Branch 0 taken 7463584 times.
✓ Branch 1 taken 99314 times.
✓ Branch 2 taken 7264516 times.
✓ Branch 3 taken 199068 times.
|
7562898 | if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER || |
1751 |
2/2✓ Branch 0 taken 7138414 times.
✓ Branch 1 taken 126102 times.
|
7264516 | x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1752 |
2/2✓ Branch 0 taken 400782 times.
✓ Branch 1 taken 6737632 times.
|
7138414 | y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
1753 | 825266 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1754 | 825266 | int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << s->ps.sps->pixel_shift)); | |
1755 | 825266 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
1756 | 825266 | (edge_emu_stride + (1 << s->ps.sps->pixel_shift)); | |
1757 | |||
1758 | 825266 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1, | |
1759 | edge_emu_stride, src1stride, | ||
1760 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1761 | x_off0 - EPEL_EXTRA_BEFORE, | ||
1762 | y_off0 - EPEL_EXTRA_BEFORE, | ||
1763 | pic_width, pic_height); | ||
1764 | |||
1765 | 825266 | src1 = lc->edge_emu_buffer + buf_offset1; | |
1766 | 825266 | src1stride = edge_emu_stride; | |
1767 | } | ||
1768 | |||
1769 |
4/4✓ Branch 0 taken 7452390 times.
✓ Branch 1 taken 110508 times.
✓ Branch 2 taken 7254974 times.
✓ Branch 3 taken 197416 times.
|
7562898 | if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER || |
1770 |
2/2✓ Branch 0 taken 7124282 times.
✓ Branch 1 taken 130692 times.
|
7254974 | x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
1771 |
2/2✓ Branch 0 taken 408782 times.
✓ Branch 1 taken 6715500 times.
|
7124282 | y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
1772 | 847398 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; | |
1773 | 847398 | int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << s->ps.sps->pixel_shift)); | |
1774 | 847398 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
1775 | 847398 | (edge_emu_stride + (1 << s->ps.sps->pixel_shift)); | |
1776 | |||
1777 | 847398 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1, | |
1778 | edge_emu_stride, src2stride, | ||
1779 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
1780 | x_off1 - EPEL_EXTRA_BEFORE, | ||
1781 | y_off1 - EPEL_EXTRA_BEFORE, | ||
1782 | pic_width, pic_height); | ||
1783 | |||
1784 | 847398 | src2 = lc->edge_emu_buffer2 + buf_offset1; | |
1785 | 847398 | src2stride = edge_emu_stride; | |
1786 | } | ||
1787 | |||
1788 | 7562898 | s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride, | |
1789 | block_h, _mx0, _my0, block_w); | ||
1790 |
2/2✓ Branch 0 taken 7438284 times.
✓ Branch 1 taken 124614 times.
|
7562898 | if (!weight_flag) |
1791 | 7438284 | s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->frame->linesize[cidx+1], | |
1792 | 7438284 | src2, src2stride, lc->tmp, | |
1793 | block_h, _mx1, _my1, block_w); | ||
1794 | else | ||
1795 | 124614 | s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->frame->linesize[cidx+1], | |
1796 | 124614 | src2, src2stride, lc->tmp, | |
1797 | block_h, | ||
1798 | 124614 | s->sh.chroma_log2_weight_denom, | |
1799 | 124614 | s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx], | |
1800 | 124614 | s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx], | |
1801 | 124614 | s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx], | |
1802 | 124614 | s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx], | |
1803 | _mx1, _my1, block_w); | ||
1804 | 7562898 | } | |
1805 | |||
1806 | 12365415 | static void hevc_await_progress(HEVCContext *s, HEVCFrame *ref, | |
1807 | const Mv *mv, int y0, int height) | ||
1808 | { | ||
1809 |
2/2✓ Branch 0 taken 107575 times.
✓ Branch 1 taken 12257840 times.
|
12365415 | if (s->threads_type == FF_THREAD_FRAME ) { |
1810 | 107575 | int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9); | |
1811 | |||
1812 | 107575 | ff_thread_await_progress(&ref->tf, y, 0); | |
1813 | } | ||
1814 | 12365415 | } | |
1815 | |||
1816 | 2379349 | static void hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, | |
1817 | int nPbH, int log2_cb_size, int part_idx, | ||
1818 | int merge_idx, MvField *mv) | ||
1819 | { | ||
1820 | 2379349 | HEVCLocalContext *lc = s->HEVClc; | |
1821 | 2379349 | enum InterPredIdc inter_pred_idc = PRED_L0; | |
1822 | int mvp_flag; | ||
1823 | |||
1824 | 2379349 | ff_hevc_set_neighbour_available(s, x0, y0, nPbW, nPbH); | |
1825 | 2379349 | mv->pred_flag = 0; | |
1826 |
2/2✓ Branch 0 taken 1811353 times.
✓ Branch 1 taken 567996 times.
|
2379349 | if (s->sh.slice_type == HEVC_SLICE_B) |
1827 | 1811353 | inter_pred_idc = ff_hevc_inter_pred_idc_decode(s, nPbW, nPbH); | |
1828 | |||
1829 |
2/2✓ Branch 0 taken 1995330 times.
✓ Branch 1 taken 384019 times.
|
2379349 | if (inter_pred_idc != PRED_L1) { |
1830 |
1/2✓ Branch 0 taken 1995330 times.
✗ Branch 1 not taken.
|
1995330 | if (s->sh.nb_refs[L0]) |
1831 | 1995330 | mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L0]); | |
1832 | |||
1833 | 1995330 | mv->pred_flag = PF_L0; | |
1834 | 1995330 | ff_hevc_hls_mvd_coding(s, x0, y0, 0); | |
1835 | 1995330 | mvp_flag = ff_hevc_mvp_lx_flag_decode(s); | |
1836 | 1995330 | ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size, | |
1837 | part_idx, merge_idx, mv, mvp_flag, 0); | ||
1838 | 1995330 | mv->mv[0].x += lc->pu.mvd.x; | |
1839 | 1995330 | mv->mv[0].y += lc->pu.mvd.y; | |
1840 | } | ||
1841 | |||
1842 |
2/2✓ Branch 0 taken 788021 times.
✓ Branch 1 taken 1591328 times.
|
2379349 | if (inter_pred_idc != PRED_L0) { |
1843 |
1/2✓ Branch 0 taken 788021 times.
✗ Branch 1 not taken.
|
788021 | if (s->sh.nb_refs[L1]) |
1844 | 788021 | mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L1]); | |
1845 | |||
1846 |
4/4✓ Branch 0 taken 187361 times.
✓ Branch 1 taken 600660 times.
✓ Branch 2 taken 157794 times.
✓ Branch 3 taken 29567 times.
|
788021 | if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) { |
1847 | 157794 | AV_ZERO32(&lc->pu.mvd); | |
1848 | } else { | ||
1849 | 630227 | ff_hevc_hls_mvd_coding(s, x0, y0, 1); | |
1850 | } | ||
1851 | |||
1852 | 788021 | mv->pred_flag += PF_L1; | |
1853 | 788021 | mvp_flag = ff_hevc_mvp_lx_flag_decode(s); | |
1854 | 788021 | ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size, | |
1855 | part_idx, merge_idx, mv, mvp_flag, 1); | ||
1856 | 788021 | mv->mv[1].x += lc->pu.mvd.x; | |
1857 | 788021 | mv->mv[1].y += lc->pu.mvd.y; | |
1858 | } | ||
1859 | 2379349 | } | |
1860 | |||
1861 | 8583966 | static void hls_prediction_unit(HEVCContext *s, int x0, int y0, | |
1862 | int nPbW, int nPbH, | ||
1863 | int log2_cb_size, int partIdx, int idx) | ||
1864 | { | ||
1865 | #define POS(c_idx, x, y) \ | ||
1866 | &s->frame->data[c_idx][((y) >> s->ps.sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \ | ||
1867 | (((x) >> s->ps.sps->hshift[c_idx]) << s->ps.sps->pixel_shift)] | ||
1868 | 8583966 | HEVCLocalContext *lc = s->HEVClc; | |
1869 | 8583966 | int merge_idx = 0; | |
1870 | 8583966 | struct MvField current_mv = {{{ 0 }}}; | |
1871 | |||
1872 | 8583966 | int min_pu_width = s->ps.sps->min_pu_width; | |
1873 | |||
1874 | 8583966 | MvField *tab_mvf = s->ref->tab_mvf; | |
1875 | 8583966 | RefPicList *refPicList = s->ref->refPicList; | |
1876 | 8583966 | HEVCFrame *ref0 = NULL, *ref1 = NULL; | |
1877 | 8583966 | uint8_t *dst0 = POS(0, x0, y0); | |
1878 | 8583966 | uint8_t *dst1 = POS(1, x0, y0); | |
1879 | 8583966 | uint8_t *dst2 = POS(2, x0, y0); | |
1880 | 8583966 | int log2_min_cb_size = s->ps.sps->log2_min_cb_size; | |
1881 | 8583966 | int min_cb_width = s->ps.sps->min_cb_width; | |
1882 | 8583966 | int x_cb = x0 >> log2_min_cb_size; | |
1883 | 8583966 | int y_cb = y0 >> log2_min_cb_size; | |
1884 | int x_pu, y_pu; | ||
1885 | int i, j; | ||
1886 | |||
1887 | 8583966 | int skip_flag = SAMPLE_CTB(s->skip_flag, x_cb, y_cb); | |
1888 | |||
1889 |
2/2✓ Branch 0 taken 4710467 times.
✓ Branch 1 taken 3873499 times.
|
8583966 | if (!skip_flag) |
1890 | 4710467 | lc->pu.merge_flag = ff_hevc_merge_flag_decode(s); | |
1891 | |||
1892 |
4/4✓ Branch 0 taken 4710467 times.
✓ Branch 1 taken 3873499 times.
✓ Branch 2 taken 2331118 times.
✓ Branch 3 taken 2379349 times.
|
8583966 | if (skip_flag || lc->pu.merge_flag) { |
1893 |
2/2✓ Branch 0 taken 6127764 times.
✓ Branch 1 taken 76853 times.
|
6204617 | if (s->sh.max_num_merge_cand > 1) |
1894 | 6127764 | merge_idx = ff_hevc_merge_idx_decode(s); | |
1895 | else | ||
1896 | 76853 | merge_idx = 0; | |
1897 | |||
1898 | 6204617 | ff_hevc_luma_mv_merge_mode(s, x0, y0, nPbW, nPbH, log2_cb_size, | |
1899 | partIdx, merge_idx, ¤t_mv); | ||
1900 | } else { | ||
1901 | 2379349 | hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size, | |
1902 | partIdx, merge_idx, ¤t_mv); | ||
1903 | } | ||
1904 | |||
1905 | 8583966 | x_pu = x0 >> s->ps.sps->log2_min_pu_size; | |
1906 | 8583966 | y_pu = y0 >> s->ps.sps->log2_min_pu_size; | |
1907 | |||
1908 |
2/2✓ Branch 0 taken 32366746 times.
✓ Branch 1 taken 8583966 times.
|
40950712 | for (j = 0; j < nPbH >> s->ps.sps->log2_min_pu_size; j++) |
1909 |
2/2✓ Branch 0 taken 205198716 times.
✓ Branch 1 taken 32366746 times.
|
237565462 | for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) |
1910 | 205198716 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; | |
1911 | |||
1912 |
2/2✓ Branch 0 taken 7823389 times.
✓ Branch 1 taken 760577 times.
|
8583966 | if (current_mv.pred_flag & PF_L0) { |
1913 | 7823389 | ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; | |
1914 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7823389 times.
|
7823389 | if (!ref0) |
1915 | ✗ | return; | |
1916 | 7823389 | hevc_await_progress(s, ref0, ¤t_mv.mv[0], y0, nPbH); | |
1917 | } | ||
1918 |
2/2✓ Branch 0 taken 4542026 times.
✓ Branch 1 taken 4041940 times.
|
8583966 | if (current_mv.pred_flag & PF_L1) { |
1919 | 4542026 | ref1 = refPicList[1].ref[current_mv.ref_idx[1]]; | |
1920 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4542026 times.
|
4542026 | if (!ref1) |
1921 | ✗ | return; | |
1922 | 4542026 | hevc_await_progress(s, ref1, ¤t_mv.mv[1], y0, nPbH); | |
1923 | } | ||
1924 | |||
1925 |
2/2✓ Branch 0 taken 4041940 times.
✓ Branch 1 taken 4542026 times.
|
8583966 | if (current_mv.pred_flag == PF_L0) { |
1926 | 4041940 | int x0_c = x0 >> s->ps.sps->hshift[1]; | |
1927 | 4041940 | int y0_c = y0 >> s->ps.sps->vshift[1]; | |
1928 | 4041940 | int nPbW_c = nPbW >> s->ps.sps->hshift[1]; | |
1929 | 4041940 | int nPbH_c = nPbH >> s->ps.sps->vshift[1]; | |
1930 | |||
1931 | 4041940 | luma_mc_uni(s, dst0, s->frame->linesize[0], ref0->frame, | |
1932 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
1933 | 4041940 | s->sh.luma_weight_l0[current_mv.ref_idx[0]], | |
1934 | 4041940 | s->sh.luma_offset_l0[current_mv.ref_idx[0]]); | |
1935 | |||
1936 |
1/2✓ Branch 0 taken 4041940 times.
✗ Branch 1 not taken.
|
4041940 | if (s->ps.sps->chroma_format_idc) { |
1937 | 4041940 | chroma_mc_uni(s, dst1, s->frame->linesize[1], ref0->frame->data[1], ref0->frame->linesize[1], | |
1938 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
1939 | 4041940 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]); | |
1940 | 4041940 | chroma_mc_uni(s, dst2, s->frame->linesize[2], ref0->frame->data[2], ref0->frame->linesize[2], | |
1941 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
1942 | 4041940 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]); | |
1943 | } | ||
1944 |
2/2✓ Branch 0 taken 760577 times.
✓ Branch 1 taken 3781449 times.
|
4542026 | } else if (current_mv.pred_flag == PF_L1) { |
1945 | 760577 | int x0_c = x0 >> s->ps.sps->hshift[1]; | |
1946 | 760577 | int y0_c = y0 >> s->ps.sps->vshift[1]; | |
1947 | 760577 | int nPbW_c = nPbW >> s->ps.sps->hshift[1]; | |
1948 | 760577 | int nPbH_c = nPbH >> s->ps.sps->vshift[1]; | |
1949 | |||
1950 | 760577 | luma_mc_uni(s, dst0, s->frame->linesize[0], ref1->frame, | |
1951 | ¤t_mv.mv[1], x0, y0, nPbW, nPbH, | ||
1952 | 760577 | s->sh.luma_weight_l1[current_mv.ref_idx[1]], | |
1953 | 760577 | s->sh.luma_offset_l1[current_mv.ref_idx[1]]); | |
1954 | |||
1955 |
1/2✓ Branch 0 taken 760577 times.
✗ Branch 1 not taken.
|
760577 | if (s->ps.sps->chroma_format_idc) { |
1956 | 760577 | chroma_mc_uni(s, dst1, s->frame->linesize[1], ref1->frame->data[1], ref1->frame->linesize[1], | |
1957 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
1958 | 760577 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]); | |
1959 | |||
1960 | 760577 | chroma_mc_uni(s, dst2, s->frame->linesize[2], ref1->frame->data[2], ref1->frame->linesize[2], | |
1961 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
1962 | 760577 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]); | |
1963 | } | ||
1964 |
1/2✓ Branch 0 taken 3781449 times.
✗ Branch 1 not taken.
|
3781449 | } else if (current_mv.pred_flag == PF_BI) { |
1965 | 3781449 | int x0_c = x0 >> s->ps.sps->hshift[1]; | |
1966 | 3781449 | int y0_c = y0 >> s->ps.sps->vshift[1]; | |
1967 | 3781449 | int nPbW_c = nPbW >> s->ps.sps->hshift[1]; | |
1968 | 3781449 | int nPbH_c = nPbH >> s->ps.sps->vshift[1]; | |
1969 | |||
1970 | 3781449 | luma_mc_bi(s, dst0, s->frame->linesize[0], ref0->frame, | |
1971 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
1972 | ref1->frame, ¤t_mv.mv[1], ¤t_mv); | ||
1973 | |||
1974 |
1/2✓ Branch 0 taken 3781449 times.
✗ Branch 1 not taken.
|
3781449 | if (s->ps.sps->chroma_format_idc) { |
1975 | 3781449 | chroma_mc_bi(s, dst1, s->frame->linesize[1], ref0->frame, ref1->frame, | |
1976 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0); | ||
1977 | |||
1978 | 3781449 | chroma_mc_bi(s, dst2, s->frame->linesize[2], ref0->frame, ref1->frame, | |
1979 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1); | ||
1980 | } | ||
1981 | } | ||
1982 | } | ||
1983 | |||
1984 | /** | ||
1985 | * 8.4.1 | ||
1986 | */ | ||
1987 | 7487168 | static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size, | |
1988 | int prev_intra_luma_pred_flag) | ||
1989 | { | ||
1990 | 7487168 | HEVCLocalContext *lc = s->HEVClc; | |
1991 | 7487168 | int x_pu = x0 >> s->ps.sps->log2_min_pu_size; | |
1992 | 7487168 | int y_pu = y0 >> s->ps.sps->log2_min_pu_size; | |
1993 | 7487168 | int min_pu_width = s->ps.sps->min_pu_width; | |
1994 | 7487168 | int size_in_pus = pu_size >> s->ps.sps->log2_min_pu_size; | |
1995 | 7487168 | int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size); | |
1996 | 7487168 | int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size); | |
1997 | |||
1998 |
2/2✓ Branch 0 taken 1046844 times.
✓ Branch 1 taken 120137 times.
|
1166981 | int cand_up = (lc->ctb_up_flag || y0b) ? |
1999 |
2/2✓ Branch 0 taken 1166981 times.
✓ Branch 1 taken 6320187 times.
|
8654149 | s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC; |
2000 |
2/2✓ Branch 0 taken 563622 times.
✓ Branch 1 taken 75613 times.
|
639235 | int cand_left = (lc->ctb_left_flag || x0b) ? |
2001 |
2/2✓ Branch 0 taken 639235 times.
✓ Branch 1 taken 6847933 times.
|
8126403 | s->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC; |
2002 | |||
2003 | 7487168 | int y_ctb = (y0 >> (s->ps.sps->log2_ctb_size)) << (s->ps.sps->log2_ctb_size); | |
2004 | |||
2005 | 7487168 | MvField *tab_mvf = s->ref->tab_mvf; | |
2006 | int intra_pred_mode; | ||
2007 | int candidate[3]; | ||
2008 | int i, j; | ||
2009 | |||
2010 | // intra_pred_mode prediction does not cross vertical CTB boundaries | ||
2011 |
2/2✓ Branch 0 taken 951519 times.
✓ Branch 1 taken 6535649 times.
|
7487168 | if ((y0 - 1) < y_ctb) |
2012 | 951519 | cand_up = INTRA_DC; | |
2013 | |||
2014 |
2/2✓ Branch 0 taken 1569890 times.
✓ Branch 1 taken 5917278 times.
|
7487168 | if (cand_left == cand_up) { |
2015 |
2/2✓ Branch 0 taken 921005 times.
✓ Branch 1 taken 648885 times.
|
1569890 | if (cand_left < 2) { |
2016 | 921005 | candidate[0] = INTRA_PLANAR; | |
2017 | 921005 | candidate[1] = INTRA_DC; | |
2018 | 921005 | candidate[2] = INTRA_ANGULAR_26; | |
2019 | } else { | ||
2020 | 648885 | candidate[0] = cand_left; | |
2021 | 648885 | candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31); | |
2022 | 648885 | candidate[2] = 2 + ((cand_left - 2 + 1) & 31); | |
2023 | } | ||
2024 | } else { | ||
2025 | 5917278 | candidate[0] = cand_left; | |
2026 | 5917278 | candidate[1] = cand_up; | |
2027 |
4/4✓ Branch 0 taken 4926777 times.
✓ Branch 1 taken 990501 times.
✓ Branch 2 taken 4076340 times.
✓ Branch 3 taken 850437 times.
|
5917278 | if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) { |
2028 | 4076340 | candidate[2] = INTRA_PLANAR; | |
2029 |
4/4✓ Branch 0 taken 1607337 times.
✓ Branch 1 taken 233601 times.
✓ Branch 2 taken 1217686 times.
✓ Branch 3 taken 389651 times.
|
1840938 | } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) { |
2030 | 1217686 | candidate[2] = INTRA_DC; | |
2031 | } else { | ||
2032 | 623252 | candidate[2] = INTRA_ANGULAR_26; | |
2033 | } | ||
2034 | } | ||
2035 | |||
2036 |
2/2✓ Branch 0 taken 4483568 times.
✓ Branch 1 taken 3003600 times.
|
7487168 | if (prev_intra_luma_pred_flag) { |
2037 | 4483568 | intra_pred_mode = candidate[lc->pu.mpm_idx]; | |
2038 | } else { | ||
2039 |
2/2✓ Branch 0 taken 1437919 times.
✓ Branch 1 taken 1565681 times.
|
3003600 | if (candidate[0] > candidate[1]) |
2040 | 1437919 | FFSWAP(uint8_t, candidate[0], candidate[1]); | |
2041 |
2/2✓ Branch 0 taken 1794273 times.
✓ Branch 1 taken 1209327 times.
|
3003600 | if (candidate[0] > candidate[2]) |
2042 | 1794273 | FFSWAP(uint8_t, candidate[0], candidate[2]); | |
2043 |
2/2✓ Branch 0 taken 2242935 times.
✓ Branch 1 taken 760665 times.
|
3003600 | if (candidate[1] > candidate[2]) |
2044 | 2242935 | FFSWAP(uint8_t, candidate[1], candidate[2]); | |
2045 | |||
2046 | 3003600 | intra_pred_mode = lc->pu.rem_intra_luma_pred_mode; | |
2047 |
2/2✓ Branch 0 taken 9010800 times.
✓ Branch 1 taken 3003600 times.
|
12014400 | for (i = 0; i < 3; i++) |
2048 |
2/2✓ Branch 0 taken 6563988 times.
✓ Branch 1 taken 2446812 times.
|
9010800 | if (intra_pred_mode >= candidate[i]) |
2049 | 6563988 | intra_pred_mode++; | |
2050 | } | ||
2051 | |||
2052 | /* write the intra prediction units into the mv array */ | ||
2053 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7487168 times.
|
7487168 | if (!size_in_pus) |
2054 | ✗ | size_in_pus = 1; | |
2055 |
2/2✓ Branch 0 taken 13115208 times.
✓ Branch 1 taken 7487168 times.
|
20602376 | for (i = 0; i < size_in_pus; i++) { |
2056 | 13115208 | memset(&s->tab_ipm[(y_pu + i) * min_pu_width + x_pu], | |
2057 | intra_pred_mode, size_in_pus); | ||
2058 | |||
2059 |
2/2✓ Branch 0 taken 41299004 times.
✓ Branch 1 taken 13115208 times.
|
54414212 | for (j = 0; j < size_in_pus; j++) { |
2060 | 41299004 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA; | |
2061 | } | ||
2062 | } | ||
2063 | |||
2064 | 7487168 | return intra_pred_mode; | |
2065 | } | ||
2066 | |||
2067 | 10932698 | static av_always_inline void set_ct_depth(HEVCContext *s, int x0, int y0, | |
2068 | int log2_cb_size, int ct_depth) | ||
2069 | { | ||
2070 | 10932698 | int length = (1 << log2_cb_size) >> s->ps.sps->log2_min_cb_size; | |
2071 | 10932698 | int x_cb = x0 >> s->ps.sps->log2_min_cb_size; | |
2072 | 10932698 | int y_cb = y0 >> s->ps.sps->log2_min_cb_size; | |
2073 | int y; | ||
2074 | |||
2075 |
2/2✓ Branch 0 taken 20066217 times.
✓ Branch 1 taken 10932698 times.
|
30998915 | for (y = 0; y < length; y++) |
2076 | 20066217 | memset(&s->tab_ct_depth[(y_cb + y) * s->ps.sps->min_cb_width + x_cb], | |
2077 | ct_depth, length); | ||
2078 | 10932698 | } | |
2079 | |||
2080 | static const uint8_t tab_mode_idx[] = { | ||
2081 | 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, | ||
2082 | 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31}; | ||
2083 | |||
2084 | 3926711 | static void intra_prediction_unit(HEVCContext *s, int x0, int y0, | |
2085 | int log2_cb_size) | ||
2086 | { | ||
2087 | 3926711 | HEVCLocalContext *lc = s->HEVClc; | |
2088 | static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 }; | ||
2089 | uint8_t prev_intra_luma_pred_flag[4]; | ||
2090 | 3926711 | int split = lc->cu.part_mode == PART_NxN; | |
2091 | 3926711 | int pb_size = (1 << log2_cb_size) >> split; | |
2092 | 3926711 | int side = split + 1; | |
2093 | int chroma_mode; | ||
2094 | int i, j; | ||
2095 | |||
2096 |
2/2✓ Branch 0 taken 5113530 times.
✓ Branch 1 taken 3926711 times.
|
9040241 | for (i = 0; i < side; i++) |
2097 |
2/2✓ Branch 0 taken 7487168 times.
✓ Branch 1 taken 5113530 times.
|
12600698 | for (j = 0; j < side; j++) |
2098 | 7487168 | prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(s); | |
2099 | |||
2100 |
2/2✓ Branch 0 taken 5113530 times.
✓ Branch 1 taken 3926711 times.
|
9040241 | for (i = 0; i < side; i++) { |
2101 |
2/2✓ Branch 0 taken 7487168 times.
✓ Branch 1 taken 5113530 times.
|
12600698 | for (j = 0; j < side; j++) { |
2102 |
2/2✓ Branch 0 taken 4483568 times.
✓ Branch 1 taken 3003600 times.
|
7487168 | if (prev_intra_luma_pred_flag[2 * i + j]) |
2103 | 4483568 | lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(s); | |
2104 | else | ||
2105 | 3003600 | lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(s); | |
2106 | |||
2107 | 7487168 | lc->pu.intra_pred_mode[2 * i + j] = | |
2108 | 7487168 | luma_intra_pred_mode(s, x0 + pb_size * j, y0 + pb_size * i, pb_size, | |
2109 | 7487168 | prev_intra_luma_pred_flag[2 * i + j]); | |
2110 | } | ||
2111 | } | ||
2112 | |||
2113 |
2/2✓ Branch 0 taken 105006 times.
✓ Branch 1 taken 3821705 times.
|
3926711 | if (s->ps.sps->chroma_format_idc == 3) { |
2114 |
2/2✓ Branch 0 taken 138857 times.
✓ Branch 1 taken 105006 times.
|
243863 | for (i = 0; i < side; i++) { |
2115 |
2/2✓ Branch 0 taken 206559 times.
✓ Branch 1 taken 138857 times.
|
345416 | for (j = 0; j < side; j++) { |
2116 | 206559 | lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s); | |
2117 |
2/2✓ Branch 0 taken 34248 times.
✓ Branch 1 taken 172311 times.
|
206559 | if (chroma_mode != 4) { |
2118 |
2/2✓ Branch 0 taken 2343 times.
✓ Branch 1 taken 31905 times.
|
34248 | if (lc->pu.intra_pred_mode[2 * i + j] == intra_chroma_table[chroma_mode]) |
2119 | 2343 | lc->pu.intra_pred_mode_c[2 * i + j] = 34; | |
2120 | else | ||
2121 | 31905 | lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode]; | |
2122 | } else { | ||
2123 | 172311 | lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j]; | |
2124 | } | ||
2125 | } | ||
2126 | } | ||
2127 |
2/2✓ Branch 0 taken 247106 times.
✓ Branch 1 taken 3574599 times.
|
3821705 | } else if (s->ps.sps->chroma_format_idc == 2) { |
2128 | int mode_idx; | ||
2129 | 247106 | lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s); | |
2130 |
2/2✓ Branch 0 taken 73995 times.
✓ Branch 1 taken 173111 times.
|
247106 | if (chroma_mode != 4) { |
2131 |
2/2✓ Branch 0 taken 3515 times.
✓ Branch 1 taken 70480 times.
|
73995 | if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode]) |
2132 | 3515 | mode_idx = 34; | |
2133 | else | ||
2134 | 70480 | mode_idx = intra_chroma_table[chroma_mode]; | |
2135 | } else { | ||
2136 | 173111 | mode_idx = lc->pu.intra_pred_mode[0]; | |
2137 | } | ||
2138 | 247106 | lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx]; | |
2139 |
2/2✓ Branch 0 taken 3574407 times.
✓ Branch 1 taken 192 times.
|
3574599 | } else if (s->ps.sps->chroma_format_idc != 0) { |
2140 | 3574407 | chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s); | |
2141 |
2/2✓ Branch 0 taken 917964 times.
✓ Branch 1 taken 2656443 times.
|
3574407 | if (chroma_mode != 4) { |
2142 |
2/2✓ Branch 0 taken 68035 times.
✓ Branch 1 taken 849929 times.
|
917964 | if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode]) |
2143 | 68035 | lc->pu.intra_pred_mode_c[0] = 34; | |
2144 | else | ||
2145 | 849929 | lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode]; | |
2146 | } else { | ||
2147 | 2656443 | lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0]; | |
2148 | } | ||
2149 | } | ||
2150 | 3926711 | } | |
2151 | |||
2152 | 7005988 | static void intra_prediction_unit_default_value(HEVCContext *s, | |
2153 | int x0, int y0, | ||
2154 | int log2_cb_size) | ||
2155 | { | ||
2156 | 7005988 | HEVCLocalContext *lc = s->HEVClc; | |
2157 | 7005988 | int pb_size = 1 << log2_cb_size; | |
2158 | 7005988 | int size_in_pus = pb_size >> s->ps.sps->log2_min_pu_size; | |
2159 | 7005988 | int min_pu_width = s->ps.sps->min_pu_width; | |
2160 | 7005988 | MvField *tab_mvf = s->ref->tab_mvf; | |
2161 | 7005988 | int x_pu = x0 >> s->ps.sps->log2_min_pu_size; | |
2162 | 7005988 | int y_pu = y0 >> s->ps.sps->log2_min_pu_size; | |
2163 | int j, k; | ||
2164 | |||
2165 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7005988 times.
|
7005988 | if (size_in_pus == 0) |
2166 | ✗ | size_in_pus = 1; | |
2167 |
2/2✓ Branch 0 taken 29390866 times.
✓ Branch 1 taken 7005988 times.
|
36396854 | for (j = 0; j < size_in_pus; j++) |
2168 | 29390866 | memset(&s->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus); | |
2169 |
2/2✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 6993555 times.
|
7005988 | if (lc->cu.pred_mode == MODE_INTRA) |
2170 |
2/2✓ Branch 0 taken 40908 times.
✓ Branch 1 taken 12433 times.
|
53341 | for (j = 0; j < size_in_pus; j++) |
2171 |
2/2✓ Branch 0 taken 182512 times.
✓ Branch 1 taken 40908 times.
|
223420 | for (k = 0; k < size_in_pus; k++) |
2172 | 182512 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA; | |
2173 | 7005988 | } | |
2174 | |||
2175 | 10932699 | static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) | |
2176 | { | ||
2177 | 10932699 | int cb_size = 1 << log2_cb_size; | |
2178 | 10932699 | HEVCLocalContext *lc = s->HEVClc; | |
2179 | 10932699 | int log2_min_cb_size = s->ps.sps->log2_min_cb_size; | |
2180 | 10932699 | int length = cb_size >> log2_min_cb_size; | |
2181 | 10932699 | int min_cb_width = s->ps.sps->min_cb_width; | |
2182 | 10932699 | int x_cb = x0 >> log2_min_cb_size; | |
2183 | 10932699 | int y_cb = y0 >> log2_min_cb_size; | |
2184 | 10932699 | int idx = log2_cb_size - 2; | |
2185 | 10932699 | int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1; | |
2186 | int x, y, ret; | ||
2187 | |||
2188 | 10932699 | lc->cu.x = x0; | |
2189 | 10932699 | lc->cu.y = y0; | |
2190 | 10932699 | lc->cu.pred_mode = MODE_INTRA; | |
2191 | 10932699 | lc->cu.part_mode = PART_2Nx2N; | |
2192 | 10932699 | lc->cu.intra_split_flag = 0; | |
2193 | |||
2194 | 10932699 | SAMPLE_CTB(s->skip_flag, x_cb, y_cb) = 0; | |
2195 |
2/2✓ Branch 0 taken 43730796 times.
✓ Branch 1 taken 10932699 times.
|
54663495 | for (x = 0; x < 4; x++) |
2196 | 43730796 | lc->pu.intra_pred_mode[x] = 1; | |
2197 |
2/2✓ Branch 0 taken 200139 times.
✓ Branch 1 taken 10732560 times.
|
10932699 | if (s->ps.pps->transquant_bypass_enable_flag) { |
2198 | 200139 | lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(s); | |
2199 |
2/2✓ Branch 0 taken 80538 times.
✓ Branch 1 taken 119601 times.
|
200139 | if (lc->cu.cu_transquant_bypass_flag) |
2200 | 80538 | set_deblocking_bypass(s, x0, y0, log2_cb_size); | |
2201 | } else | ||
2202 | 10732560 | lc->cu.cu_transquant_bypass_flag = 0; | |
2203 | |||
2204 |
2/2✓ Branch 0 taken 8059111 times.
✓ Branch 1 taken 2873588 times.
|
10932699 | if (s->sh.slice_type != HEVC_SLICE_I) { |
2205 | 8059111 | uint8_t skip_flag = ff_hevc_skip_flag_decode(s, x0, y0, x_cb, y_cb); | |
2206 | |||
2207 | 8059111 | x = y_cb * min_cb_width + x_cb; | |
2208 |
2/2✓ Branch 0 taken 16271489 times.
✓ Branch 1 taken 8059111 times.
|
24330600 | for (y = 0; y < length; y++) { |
2209 | 16271489 | memset(&s->skip_flag[x], skip_flag, length); | |
2210 | 16271489 | x += min_cb_width; | |
2211 | } | ||
2212 |
2/2✓ Branch 0 taken 3873499 times.
✓ Branch 1 taken 4185612 times.
|
8059111 | lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER; |
2213 | } else { | ||
2214 | 2873588 | x = y_cb * min_cb_width + x_cb; | |
2215 |
2/2✓ Branch 0 taken 3794729 times.
✓ Branch 1 taken 2873588 times.
|
6668317 | for (y = 0; y < length; y++) { |
2216 | 3794729 | memset(&s->skip_flag[x], 0, length); | |
2217 | 3794729 | x += min_cb_width; | |
2218 | } | ||
2219 | } | ||
2220 | |||
2221 |
2/2✓ Branch 0 taken 3873499 times.
✓ Branch 1 taken 7059200 times.
|
10932699 | if (SAMPLE_CTB(s->skip_flag, x_cb, y_cb)) { |
2222 | 3873499 | hls_prediction_unit(s, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | |
2223 | 3873499 | intra_prediction_unit_default_value(s, x0, y0, log2_cb_size); | |
2224 | |||
2225 |
2/2✓ Branch 0 taken 3726986 times.
✓ Branch 1 taken 146513 times.
|
3873499 | if (!s->sh.disable_deblocking_filter_flag) |
2226 | 3726986 | ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size); | |
2227 | } else { | ||
2228 | 7059200 | int pcm_flag = 0; | |
2229 | |||
2230 |
2/2✓ Branch 0 taken 4185612 times.
✓ Branch 1 taken 2873588 times.
|
7059200 | if (s->sh.slice_type != HEVC_SLICE_I) |
2231 | 4185612 | lc->cu.pred_mode = ff_hevc_pred_mode_decode(s); | |
2232 |
2/2✓ Branch 0 taken 3939144 times.
✓ Branch 1 taken 3120056 times.
|
7059200 | if (lc->cu.pred_mode != MODE_INTRA || |
2233 |
2/2✓ Branch 0 taken 3020363 times.
✓ Branch 1 taken 918781 times.
|
3939144 | log2_cb_size == s->ps.sps->log2_min_cb_size) { |
2234 | 6140419 | lc->cu.part_mode = ff_hevc_part_mode_decode(s, log2_cb_size); | |
2235 |
2/2✓ Branch 0 taken 1292455 times.
✓ Branch 1 taken 4847964 times.
|
7432874 | lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN && |
2236 |
2/2✓ Branch 0 taken 1186819 times.
✓ Branch 1 taken 105636 times.
|
1292455 | lc->cu.pred_mode == MODE_INTRA; |
2237 | } | ||
2238 | |||
2239 |
2/2✓ Branch 0 taken 3939144 times.
✓ Branch 1 taken 3120056 times.
|
7059200 | if (lc->cu.pred_mode == MODE_INTRA) { |
2240 |
4/4✓ Branch 0 taken 2752325 times.
✓ Branch 1 taken 1186819 times.
✓ Branch 2 taken 162684 times.
✓ Branch 3 taken 2589641 times.
|
3939144 | if (lc->cu.part_mode == PART_2Nx2N && s->ps.sps->pcm_enabled_flag && |
2241 |
2/2✓ Branch 0 taken 160815 times.
✓ Branch 1 taken 1869 times.
|
162684 | log2_cb_size >= s->ps.sps->pcm.log2_min_pcm_cb_size && |
2242 |
2/2✓ Branch 0 taken 153183 times.
✓ Branch 1 taken 7632 times.
|
160815 | log2_cb_size <= s->ps.sps->pcm.log2_max_pcm_cb_size) { |
2243 | 153183 | pcm_flag = ff_hevc_pcm_flag_decode(s); | |
2244 | } | ||
2245 |
2/2✓ Branch 0 taken 12433 times.
✓ Branch 1 taken 3926711 times.
|
3939144 | if (pcm_flag) { |
2246 | 12433 | intra_prediction_unit_default_value(s, x0, y0, log2_cb_size); | |
2247 | 12433 | ret = hls_pcm_sample(s, x0, y0, log2_cb_size); | |
2248 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12425 times.
|
12433 | if (s->ps.sps->pcm.loop_filter_disable_flag) |
2249 | 8 | set_deblocking_bypass(s, x0, y0, log2_cb_size); | |
2250 | |||
2251 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12433 times.
|
12433 | if (ret < 0) |
2252 | ✗ | return ret; | |
2253 | } else { | ||
2254 | 3926711 | intra_prediction_unit(s, x0, y0, log2_cb_size); | |
2255 | } | ||
2256 | } else { | ||
2257 | 3120056 | intra_prediction_unit_default_value(s, x0, y0, log2_cb_size); | |
2258 |
8/9✓ Branch 0 taken 1740917 times.
✓ Branch 1 taken 445873 times.
✓ Branch 2 taken 535507 times.
✓ Branch 3 taken 63734 times.
✓ Branch 4 taken 55171 times.
✓ Branch 5 taken 93167 times.
✓ Branch 6 taken 80051 times.
✓ Branch 7 taken 105636 times.
✗ Branch 8 not taken.
|
3120056 | switch (lc->cu.part_mode) { |
2259 | 1740917 | case PART_2Nx2N: | |
2260 | 1740917 | hls_prediction_unit(s, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | |
2261 | 1740917 | break; | |
2262 | 445873 | case PART_2NxN: | |
2263 | 445873 | hls_prediction_unit(s, x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx); | |
2264 | 445873 | hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx); | |
2265 | 445873 | break; | |
2266 | 535507 | case PART_Nx2N: | |
2267 | 535507 | hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1); | |
2268 | 535507 | hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1); | |
2269 | 535507 | break; | |
2270 | 63734 | case PART_2NxnU: | |
2271 | 63734 | hls_prediction_unit(s, x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx); | |
2272 | 63734 | hls_prediction_unit(s, x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx); | |
2273 | 63734 | break; | |
2274 | 55171 | case PART_2NxnD: | |
2275 | 55171 | hls_prediction_unit(s, x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx); | |
2276 | 55171 | hls_prediction_unit(s, x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx); | |
2277 | 55171 | break; | |
2278 | 93167 | case PART_nLx2N: | |
2279 | 93167 | hls_prediction_unit(s, x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2); | |
2280 | 93167 | hls_prediction_unit(s, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2); | |
2281 | 93167 | break; | |
2282 | 80051 | case PART_nRx2N: | |
2283 | 80051 | hls_prediction_unit(s, x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2); | |
2284 | 80051 | hls_prediction_unit(s, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2); | |
2285 | 80051 | break; | |
2286 | 105636 | case PART_NxN: | |
2287 | 105636 | hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1); | |
2288 | 105636 | hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1); | |
2289 | 105636 | hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1); | |
2290 | 105636 | hls_prediction_unit(s, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1); | |
2291 | 105636 | break; | |
2292 | } | ||
2293 | } | ||
2294 | |||
2295 |
2/2✓ Branch 0 taken 7046767 times.
✓ Branch 1 taken 12433 times.
|
7059200 | if (!pcm_flag) { |
2296 | 7046767 | int rqt_root_cbf = 1; | |
2297 | |||
2298 |
2/2✓ Branch 0 taken 3120056 times.
✓ Branch 1 taken 3926711 times.
|
7046767 | if (lc->cu.pred_mode != MODE_INTRA && |
2299 |
4/4✓ Branch 0 taken 1740917 times.
✓ Branch 1 taken 1379139 times.
✓ Branch 2 taken 968483 times.
✓ Branch 3 taken 772434 times.
|
3120056 | !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) { |
2300 | 2347622 | rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(s); | |
2301 | } | ||
2302 |
2/2✓ Branch 0 taken 5730999 times.
✓ Branch 1 taken 1315768 times.
|
7046767 | if (rqt_root_cbf) { |
2303 | const static int cbf[2] = { 0 }; | ||
2304 |
2/2✓ Branch 0 taken 3926711 times.
✓ Branch 1 taken 1804288 times.
|
5730999 | lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ? |
2305 | 3926711 | s->ps.sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag : | |
2306 | 1804288 | s->ps.sps->max_transform_hierarchy_depth_inter; | |
2307 | 5730999 | ret = hls_transform_tree(s, x0, y0, x0, y0, x0, y0, | |
2308 | log2_cb_size, | ||
2309 | log2_cb_size, 0, 0, cbf, cbf); | ||
2310 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5730998 times.
|
5730999 | if (ret < 0) |
2311 | 1 | return ret; | |
2312 | } else { | ||
2313 |
2/2✓ Branch 0 taken 1259336 times.
✓ Branch 1 taken 56432 times.
|
1315768 | if (!s->sh.disable_deblocking_filter_flag) |
2314 | 1259336 | ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size); | |
2315 | } | ||
2316 | } | ||
2317 | } | ||
2318 | |||
2319 |
4/4✓ Branch 0 taken 1906283 times.
✓ Branch 1 taken 9026415 times.
✓ Branch 2 taken 763378 times.
✓ Branch 3 taken 1142905 times.
|
10932698 | if (s->ps.pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0) |
2320 | 763378 | ff_hevc_set_qPy(s, x0, y0, log2_cb_size); | |
2321 | |||
2322 | 10932698 | x = y_cb * min_cb_width + x_cb; | |
2323 |
2/2✓ Branch 0 taken 20066217 times.
✓ Branch 1 taken 10932698 times.
|
30998915 | for (y = 0; y < length; y++) { |
2324 | 20066217 | memset(&s->qp_y_tab[x], lc->qp_y, length); | |
2325 | 20066217 | x += min_cb_width; | |
2326 | } | ||
2327 | |||
2328 |
2/2✓ Branch 0 taken 3707142 times.
✓ Branch 1 taken 7225556 times.
|
10932698 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
2329 |
2/2✓ Branch 0 taken 2161270 times.
✓ Branch 1 taken 1545872 times.
|
3707142 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) { |
2330 | 2161270 | lc->qPy_pred = lc->qp_y; | |
2331 | } | ||
2332 | |||
2333 | 10932698 | set_ct_depth(s, x0, y0, log2_cb_size, lc->ct_depth); | |
2334 | |||
2335 | 10932698 | return 0; | |
2336 | } | ||
2337 | |||
2338 | 14265227 | static int hls_coding_quadtree(HEVCContext *s, int x0, int y0, | |
2339 | int log2_cb_size, int cb_depth) | ||
2340 | { | ||
2341 | 14265227 | HEVCLocalContext *lc = s->HEVClc; | |
2342 | 14265227 | const int cb_size = 1 << log2_cb_size; | |
2343 | int ret; | ||
2344 | int split_cu; | ||
2345 | |||
2346 | 14265227 | lc->ct_depth = cb_depth; | |
2347 |
2/2✓ Branch 0 taken 14236624 times.
✓ Branch 1 taken 28603 times.
|
14265227 | if (x0 + cb_size <= s->ps.sps->width && |
2348 |
2/2✓ Branch 0 taken 13922245 times.
✓ Branch 1 taken 314379 times.
|
14236624 | y0 + cb_size <= s->ps.sps->height && |
2349 |
2/2✓ Branch 0 taken 7441251 times.
✓ Branch 1 taken 6480994 times.
|
13922245 | log2_cb_size > s->ps.sps->log2_min_cb_size) { |
2350 | 7441251 | split_cu = ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0); | |
2351 | } else { | ||
2352 | 6823976 | split_cu = (log2_cb_size > s->ps.sps->log2_min_cb_size); | |
2353 | } | ||
2354 |
2/2✓ Branch 0 taken 2477035 times.
✓ Branch 1 taken 11788192 times.
|
14265227 | if (s->ps.pps->cu_qp_delta_enabled_flag && |
2355 |
2/2✓ Branch 0 taken 1402831 times.
✓ Branch 1 taken 1074204 times.
|
2477035 | log2_cb_size >= s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth) { |
2356 | 1402831 | lc->tu.is_cu_qp_delta_coded = 0; | |
2357 | 1402831 | lc->tu.cu_qp_delta = 0; | |
2358 | } | ||
2359 | |||
2360 |
2/2✓ Branch 0 taken 519326 times.
✓ Branch 1 taken 13745901 times.
|
14265227 | if (s->sh.cu_chroma_qp_offset_enabled_flag && |
2361 |
1/2✓ Branch 0 taken 519326 times.
✗ Branch 1 not taken.
|
519326 | log2_cb_size >= s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_chroma_qp_offset_depth) { |
2362 | 519326 | lc->tu.is_cu_chroma_qp_offset_coded = 0; | |
2363 | } | ||
2364 | |||
2365 |
2/2✓ Branch 0 taken 3332528 times.
✓ Branch 1 taken 10932699 times.
|
14265227 | if (split_cu) { |
2366 | 3332528 | int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1; | |
2367 | 3332528 | const int cb_size_split = cb_size >> 1; | |
2368 | 3332528 | const int x1 = x0 + cb_size_split; | |
2369 | 3332528 | const int y1 = y0 + cb_size_split; | |
2370 | |||
2371 | 3332528 | int more_data = 0; | |
2372 | |||
2373 | 3332528 | more_data = hls_coding_quadtree(s, x0, y0, log2_cb_size - 1, cb_depth + 1); | |
2374 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3332526 times.
|
3332528 | if (more_data < 0) |
2375 | 2 | return more_data; | |
2376 | |||
2377 |
4/4✓ Branch 0 taken 3332517 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3304836 times.
✓ Branch 3 taken 27681 times.
|
3332526 | if (more_data && x1 < s->ps.sps->width) { |
2378 | 3304836 | more_data = hls_coding_quadtree(s, x1, y0, log2_cb_size - 1, cb_depth + 1); | |
2379 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3304836 times.
|
3304836 | if (more_data < 0) |
2380 | ✗ | return more_data; | |
2381 | } | ||
2382 |
4/4✓ Branch 0 taken 3322308 times.
✓ Branch 1 taken 10218 times.
✓ Branch 2 taken 3125909 times.
✓ Branch 3 taken 196399 times.
|
3332526 | if (more_data && y1 < s->ps.sps->height) { |
2383 | 3125909 | more_data = hls_coding_quadtree(s, x0, y1, log2_cb_size - 1, cb_depth + 1); | |
2384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3125909 times.
|
3125909 | if (more_data < 0) |
2385 | ✗ | return more_data; | |
2386 | } | ||
2387 |
4/4✓ Branch 0 taken 3316223 times.
✓ Branch 1 taken 16303 times.
✓ Branch 2 taken 3294627 times.
✓ Branch 3 taken 21596 times.
|
3332526 | if (more_data && x1 < s->ps.sps->width && |
2388 |
2/2✓ Branch 0 taken 3098228 times.
✓ Branch 1 taken 196399 times.
|
3294627 | y1 < s->ps.sps->height) { |
2389 | 3098228 | more_data = hls_coding_quadtree(s, x1, y1, log2_cb_size - 1, cb_depth + 1); | |
2390 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3098227 times.
|
3098228 | if (more_data < 0) |
2391 | 1 | return more_data; | |
2392 | } | ||
2393 | |||
2394 |
2/2✓ Branch 0 taken 1870244 times.
✓ Branch 1 taken 1462281 times.
|
3332525 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
2395 |
2/2✓ Branch 0 taken 1392574 times.
✓ Branch 1 taken 477670 times.
|
1870244 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) |
2396 | 1392574 | lc->qPy_pred = lc->qp_y; | |
2397 | |||
2398 |
2/2✓ Branch 0 taken 3297074 times.
✓ Branch 1 taken 35451 times.
|
3332525 | if (more_data) |
2399 |
2/2✓ Branch 0 taken 90613 times.
✓ Branch 1 taken 3206461 times.
|
3387687 | return ((x1 + cb_size_split) < s->ps.sps->width || |
2400 |
1/2✓ Branch 0 taken 90613 times.
✗ Branch 1 not taken.
|
90613 | (y1 + cb_size_split) < s->ps.sps->height); |
2401 | else | ||
2402 | 35451 | return 0; | |
2403 | } else { | ||
2404 | 10932699 | ret = hls_coding_unit(s, x0, y0, log2_cb_size); | |
2405 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10932698 times.
|
10932699 | if (ret < 0) |
2406 | 1 | return ret; | |
2407 | 10932698 | if ((!((x0 + cb_size) % | |
2408 |
2/2✓ Branch 0 taken 7985618 times.
✓ Branch 1 taken 2947080 times.
|
10932698 | (1 << (s->ps.sps->log2_ctb_size))) || |
2409 |
2/2✓ Branch 0 taken 70697 times.
✓ Branch 1 taken 7914921 times.
|
7985618 | (x0 + cb_size >= s->ps.sps->width)) && |
2410 | 3017777 | (!((y0 + cb_size) % | |
2411 |
2/2✓ Branch 0 taken 1709789 times.
✓ Branch 1 taken 1307988 times.
|
3017777 | (1 << (s->ps.sps->log2_ctb_size))) || |
2412 |
2/2✓ Branch 0 taken 95737 times.
✓ Branch 1 taken 1614052 times.
|
1709789 | (y0 + cb_size >= s->ps.sps->height))) { |
2413 | 1403725 | int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(s); | |
2414 | 1403725 | return !end_of_slice_flag; | |
2415 | } else { | ||
2416 | 9528973 | return 1; | |
2417 | } | ||
2418 | } | ||
2419 | |||
2420 | return 0; | ||
2421 | } | ||
2422 | |||
2423 | 1403726 | static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, | |
2424 | int ctb_addr_ts) | ||
2425 | { | ||
2426 | 1403726 | HEVCLocalContext *lc = s->HEVClc; | |
2427 | 1403726 | int ctb_size = 1 << s->ps.sps->log2_ctb_size; | |
2428 | 1403726 | int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2429 | 1403726 | int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr; | |
2430 | |||
2431 | 1403726 | s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr; | |
2432 | |||
2433 |
2/2✓ Branch 0 taken 101544 times.
✓ Branch 1 taken 1302182 times.
|
1403726 | if (s->ps.pps->entropy_coding_sync_enabled_flag) { |
2434 |
3/4✓ Branch 0 taken 5470 times.
✓ Branch 1 taken 96074 times.
✓ Branch 2 taken 5470 times.
✗ Branch 3 not taken.
|
101544 | if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0) |
2435 | 5470 | lc->first_qp_group = 1; | |
2436 | 101544 | lc->end_of_tiles_x = s->ps.sps->width; | |
2437 |
2/2✓ Branch 0 taken 290050 times.
✓ Branch 1 taken 1012132 times.
|
1302182 | } else if (s->ps.pps->tiles_enabled_flag) { |
2438 |
4/4✓ Branch 0 taken 289426 times.
✓ Branch 1 taken 624 times.
✓ Branch 2 taken 6285 times.
✓ Branch 3 taken 283141 times.
|
290050 | if (ctb_addr_ts && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) { |
2439 | 6285 | int idxX = s->ps.pps->col_idxX[x_ctb >> s->ps.sps->log2_ctb_size]; | |
2440 | 6285 | lc->end_of_tiles_x = x_ctb + (s->ps.pps->column_width[idxX] << s->ps.sps->log2_ctb_size); | |
2441 | 6285 | lc->first_qp_group = 1; | |
2442 | } | ||
2443 | } else { | ||
2444 | 1012132 | lc->end_of_tiles_x = s->ps.sps->width; | |
2445 | } | ||
2446 | |||
2447 | 1403726 | lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->ps.sps->height); | |
2448 | |||
2449 | 1403726 | lc->boundary_flags = 0; | |
2450 |
2/2✓ Branch 0 taken 290050 times.
✓ Branch 1 taken 1113676 times.
|
1403726 | if (s->ps.pps->tiles_enabled_flag) { |
2451 |
4/4✓ Branch 0 taken 278142 times.
✓ Branch 1 taken 11908 times.
✓ Branch 2 taken 30707 times.
✓ Branch 3 taken 247435 times.
|
290050 | if (x_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]]) |
2452 | 30707 | lc->boundary_flags |= BOUNDARY_LEFT_TILE; | |
2453 |
4/4✓ Branch 0 taken 278142 times.
✓ Branch 1 taken 11908 times.
✓ Branch 2 taken 3695 times.
✓ Branch 3 taken 274447 times.
|
290050 | if (x_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - 1]) |
2454 | 3695 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
2455 |
4/4✓ Branch 0 taken 275482 times.
✓ Branch 1 taken 14568 times.
✓ Branch 2 taken 33781 times.
✓ Branch 3 taken 241701 times.
|
290050 | if (y_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->ps.sps->ctb_width]]) |
2456 | 33781 | lc->boundary_flags |= BOUNDARY_UPPER_TILE; | |
2457 |
4/4✓ Branch 0 taken 275482 times.
✓ Branch 1 taken 14568 times.
✓ Branch 2 taken 14490 times.
✓ Branch 3 taken 260992 times.
|
290050 | if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - s->ps.sps->ctb_width]) |
2458 | 14490 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
2459 | } else { | ||
2460 |
2/2✓ Branch 0 taken 17555 times.
✓ Branch 1 taken 1096121 times.
|
1113676 | if (ctb_addr_in_slice <= 0) |
2461 | 17555 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
2462 |
2/2✓ Branch 0 taken 184064 times.
✓ Branch 1 taken 929612 times.
|
1113676 | if (ctb_addr_in_slice < s->ps.sps->ctb_width) |
2463 | 184064 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
2464 | } | ||
2465 | |||
2466 |
6/6✓ Branch 0 taken 1330907 times.
✓ Branch 1 taken 72819 times.
✓ Branch 2 taken 1323020 times.
✓ Branch 3 taken 7887 times.
✓ Branch 4 taken 1293339 times.
✓ Branch 5 taken 29681 times.
|
1403726 | lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE)); |
2467 |
6/6✓ Branch 0 taken 1285242 times.
✓ Branch 1 taken 118484 times.
✓ Branch 2 taken 1191433 times.
✓ Branch 3 taken 93809 times.
✓ Branch 4 taken 1171313 times.
✓ Branch 5 taken 20120 times.
|
1403726 | lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->ps.sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE)); |
2468 |
6/6✓ Branch 0 taken 1285242 times.
✓ Branch 1 taken 118484 times.
✓ Branch 2 taken 1194019 times.
✓ Branch 3 taken 91223 times.
✓ Branch 4 taken 1138355 times.
✓ Branch 5 taken 55664 times.
|
1403726 | lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->ps.sps->ctb_width]])); |
2469 |
8/8✓ Branch 0 taken 1330907 times.
✓ Branch 1 taken 72819 times.
✓ Branch 2 taken 1221911 times.
✓ Branch 3 taken 108996 times.
✓ Branch 4 taken 1133165 times.
✓ Branch 5 taken 88746 times.
✓ Branch 6 taken 1088975 times.
✓ Branch 7 taken 44190 times.
|
1403726 | lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->ps.sps->ctb_width]])); |
2470 | 1403726 | } | |
2471 | |||
2472 | 27477 | static int hls_decode_entry(AVCodecContext *avctxt, void *isFilterThread) | |
2473 | { | ||
2474 | 27477 | HEVCContext *s = avctxt->priv_data; | |
2475 | 27477 | int ctb_size = 1 << s->ps.sps->log2_ctb_size; | |
2476 | 27477 | int more_data = 1; | |
2477 | 27477 | int x_ctb = 0; | |
2478 | 27477 | int y_ctb = 0; | |
2479 | 27477 | int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
2480 | int ret; | ||
2481 | |||
2482 |
3/4✓ Branch 0 taken 9488 times.
✓ Branch 1 taken 17989 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9488 times.
|
27477 | if (!ctb_addr_ts && s->sh.dependent_slice_segment_flag) { |
2483 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Impossible initial tile.\n"); | |
2484 | ✗ | return AVERROR_INVALIDDATA; | |
2485 | } | ||
2486 | |||
2487 |
2/2✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 19530 times.
|
27477 | if (s->sh.dependent_slice_segment_flag) { |
2488 | 7947 | int prev_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1]; | |
2489 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7947 times.
|
7947 | if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) { |
2490 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n"); | |
2491 | ✗ | return AVERROR_INVALIDDATA; | |
2492 | } | ||
2493 | } | ||
2494 | |||
2495 |
3/4✓ Branch 0 taken 1403726 times.
✓ Branch 1 taken 27476 times.
✓ Branch 2 taken 1403726 times.
✗ Branch 3 not taken.
|
1431202 | while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) { |
2496 | 1403726 | int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2497 | |||
2498 | 1403726 | x_ctb = (ctb_addr_rs % ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size; | |
2499 | 1403726 | y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size; | |
2500 | 1403726 | hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts); | |
2501 | |||
2502 | 1403726 | ret = ff_hevc_cabac_init(s, ctb_addr_ts, 0); | |
2503 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1403726 times.
|
1403726 | if (ret < 0) { |
2504 | ✗ | s->tab_slice_address[ctb_addr_rs] = -1; | |
2505 | ✗ | return ret; | |
2506 | } | ||
2507 | |||
2508 | 1403726 | hls_sao_param(s, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size); | |
2509 | |||
2510 | 1403726 | s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
2511 | 1403726 | s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
2512 | 1403726 | s->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
2513 | |||
2514 | 1403726 | more_data = hls_coding_quadtree(s, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0); | |
2515 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1403725 times.
|
1403726 | if (more_data < 0) { |
2516 | 1 | s->tab_slice_address[ctb_addr_rs] = -1; | |
2517 | 1 | return more_data; | |
2518 | } | ||
2519 | |||
2520 | |||
2521 | 1403725 | ctb_addr_ts++; | |
2522 | 1403725 | ff_hevc_save_states(s, ctb_addr_ts); | |
2523 | 1403725 | ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size); | |
2524 | } | ||
2525 | |||
2526 |
2/2✓ Branch 0 taken 13968 times.
✓ Branch 1 taken 13508 times.
|
27476 | if (x_ctb + ctb_size >= s->ps.sps->width && |
2527 |
2/2✓ Branch 0 taken 9487 times.
✓ Branch 1 taken 4481 times.
|
13968 | y_ctb + ctb_size >= s->ps.sps->height) |
2528 | 9487 | ff_hevc_hls_filter(s, x_ctb, y_ctb, ctb_size); | |
2529 | |||
2530 | 27476 | return ctb_addr_ts; | |
2531 | } | ||
2532 | |||
2533 | 27477 | static int hls_slice_data(HEVCContext *s) | |
2534 | { | ||
2535 | int arg[2]; | ||
2536 | int ret[2]; | ||
2537 | |||
2538 | 27477 | arg[0] = 0; | |
2539 | 27477 | arg[1] = 1; | |
2540 | |||
2541 | 27477 | s->avctx->execute(s->avctx, hls_decode_entry, arg, ret , 1, sizeof(int)); | |
2542 | 27477 | return ret[0]; | |
2543 | } | ||
2544 | ✗ | static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *input_ctb_row, int job, int self_id) | |
2545 | { | ||
2546 | ✗ | HEVCContext *s1 = avctxt->priv_data, *s; | |
2547 | HEVCLocalContext *lc; | ||
2548 | ✗ | int ctb_size = 1<< s1->ps.sps->log2_ctb_size; | |
2549 | ✗ | int more_data = 1; | |
2550 | ✗ | int *ctb_row_p = input_ctb_row; | |
2551 | ✗ | int ctb_row = ctb_row_p[job]; | |
2552 | ✗ | int ctb_addr_rs = s1->sh.slice_ctb_addr_rs + ctb_row * ((s1->ps.sps->width + ctb_size - 1) >> s1->ps.sps->log2_ctb_size); | |
2553 | ✗ | int ctb_addr_ts = s1->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs]; | |
2554 | ✗ | int thread = ctb_row % s1->threads_number; | |
2555 | int ret; | ||
2556 | |||
2557 | ✗ | s = s1->sList[self_id]; | |
2558 | ✗ | lc = s->HEVClc; | |
2559 | |||
2560 | ✗ | if(ctb_row) { | |
2561 | ✗ | ret = init_get_bits8(&lc->gb, s->data + s->sh.offset[ctb_row - 1], s->sh.size[ctb_row - 1]); | |
2562 | ✗ | if (ret < 0) | |
2563 | ✗ | goto error; | |
2564 | ✗ | ff_init_cabac_decoder(&lc->cc, s->data + s->sh.offset[(ctb_row)-1], s->sh.size[ctb_row - 1]); | |
2565 | } | ||
2566 | |||
2567 | ✗ | while(more_data && ctb_addr_ts < s->ps.sps->ctb_size) { | |
2568 | ✗ | int x_ctb = (ctb_addr_rs % s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size; | |
2569 | ✗ | int y_ctb = (ctb_addr_rs / s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size; | |
2570 | |||
2571 | ✗ | hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts); | |
2572 | |||
2573 | ✗ | ff_thread_await_progress2(s->avctx, ctb_row, thread, SHIFT_CTB_WPP); | |
2574 | |||
2575 | ✗ | if (atomic_load(&s1->wpp_err)) { | |
2576 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP); | |
2577 | ✗ | return 0; | |
2578 | } | ||
2579 | |||
2580 | ✗ | ret = ff_hevc_cabac_init(s, ctb_addr_ts, thread); | |
2581 | ✗ | if (ret < 0) | |
2582 | ✗ | goto error; | |
2583 | ✗ | hls_sao_param(s, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size); | |
2584 | ✗ | more_data = hls_coding_quadtree(s, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0); | |
2585 | |||
2586 | ✗ | if (more_data < 0) { | |
2587 | ✗ | ret = more_data; | |
2588 | ✗ | goto error; | |
2589 | } | ||
2590 | |||
2591 | ✗ | ctb_addr_ts++; | |
2592 | |||
2593 | ✗ | ff_hevc_save_states(s, ctb_addr_ts); | |
2594 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row, thread, 1); | |
2595 | ✗ | ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size); | |
2596 | |||
2597 | ✗ | if (!more_data && (x_ctb+ctb_size) < s->ps.sps->width && ctb_row != s->sh.num_entry_point_offsets) { | |
2598 | ✗ | atomic_store(&s1->wpp_err, 1); | |
2599 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP); | |
2600 | ✗ | return 0; | |
2601 | } | ||
2602 | |||
2603 | ✗ | if ((x_ctb+ctb_size) >= s->ps.sps->width && (y_ctb+ctb_size) >= s->ps.sps->height ) { | |
2604 | ✗ | ff_hevc_hls_filter(s, x_ctb, y_ctb, ctb_size); | |
2605 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP); | |
2606 | ✗ | return ctb_addr_ts; | |
2607 | } | ||
2608 | ✗ | ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
2609 | ✗ | x_ctb+=ctb_size; | |
2610 | |||
2611 | ✗ | if(x_ctb >= s->ps.sps->width) { | |
2612 | ✗ | break; | |
2613 | } | ||
2614 | } | ||
2615 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP); | |
2616 | |||
2617 | ✗ | return 0; | |
2618 | ✗ | error: | |
2619 | ✗ | s->tab_slice_address[ctb_addr_rs] = -1; | |
2620 | ✗ | atomic_store(&s1->wpp_err, 1); | |
2621 | ✗ | ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP); | |
2622 | ✗ | return ret; | |
2623 | } | ||
2624 | |||
2625 | ✗ | static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) | |
2626 | { | ||
2627 | ✗ | const uint8_t *data = nal->data; | |
2628 | ✗ | int length = nal->size; | |
2629 | ✗ | HEVCLocalContext *lc = s->HEVClc; | |
2630 | ✗ | int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int)); | |
2631 | ✗ | int *arg = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int)); | |
2632 | int64_t offset; | ||
2633 | ✗ | int64_t startheader, cmpt = 0; | |
2634 | ✗ | int i, j, res = 0; | |
2635 | |||
2636 | ✗ | if (!ret || !arg) { | |
2637 | ✗ | av_free(ret); | |
2638 | ✗ | av_free(arg); | |
2639 | ✗ | return AVERROR(ENOMEM); | |
2640 | } | ||
2641 | |||
2642 | ✗ | if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * s->ps.sps->ctb_width >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) { | |
2643 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n", | |
2644 | s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets, | ||
2645 | ✗ | s->ps.sps->ctb_width, s->ps.sps->ctb_height | |
2646 | ); | ||
2647 | ✗ | res = AVERROR_INVALIDDATA; | |
2648 | ✗ | goto error; | |
2649 | } | ||
2650 | |||
2651 | ✗ | ff_alloc_entries(s->avctx, s->sh.num_entry_point_offsets + 1); | |
2652 | |||
2653 | ✗ | for (i = 1; i < s->threads_number; i++) { | |
2654 | ✗ | if (s->sList[i] && s->HEVClcList[i]) | |
2655 | ✗ | continue; | |
2656 | ✗ | av_freep(&s->sList[i]); | |
2657 | ✗ | av_freep(&s->HEVClcList[i]); | |
2658 | ✗ | s->sList[i] = av_malloc(sizeof(HEVCContext)); | |
2659 | ✗ | s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); | |
2660 | ✗ | if (!s->sList[i] || !s->HEVClcList[i]) { | |
2661 | ✗ | res = AVERROR(ENOMEM); | |
2662 | ✗ | goto error; | |
2663 | } | ||
2664 | ✗ | memcpy(s->sList[i], s, sizeof(HEVCContext)); | |
2665 | ✗ | s->sList[i]->HEVClc = s->HEVClcList[i]; | |
2666 | } | ||
2667 | |||
2668 | ✗ | offset = (lc->gb.index >> 3); | |
2669 | |||
2670 | ✗ | for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) { | |
2671 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
2672 | ✗ | startheader--; | |
2673 | ✗ | cmpt++; | |
2674 | } | ||
2675 | } | ||
2676 | |||
2677 | ✗ | for (i = 1; i < s->sh.num_entry_point_offsets; i++) { | |
2678 | ✗ | offset += (s->sh.entry_point_offset[i - 1] - cmpt); | |
2679 | ✗ | for (j = 0, cmpt = 0, startheader = offset | |
2680 | ✗ | + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) { | |
2681 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
2682 | ✗ | startheader--; | |
2683 | ✗ | cmpt++; | |
2684 | } | ||
2685 | } | ||
2686 | ✗ | s->sh.size[i - 1] = s->sh.entry_point_offset[i] - cmpt; | |
2687 | ✗ | s->sh.offset[i - 1] = offset; | |
2688 | |||
2689 | } | ||
2690 | ✗ | if (s->sh.num_entry_point_offsets != 0) { | |
2691 | ✗ | offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt; | |
2692 | ✗ | if (length < offset) { | |
2693 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n"); | |
2694 | ✗ | res = AVERROR_INVALIDDATA; | |
2695 | ✗ | goto error; | |
2696 | } | ||
2697 | ✗ | s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset; | |
2698 | ✗ | s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset; | |
2699 | |||
2700 | } | ||
2701 | ✗ | s->data = data; | |
2702 | |||
2703 | ✗ | for (i = 1; i < s->threads_number; i++) { | |
2704 | ✗ | s->sList[i]->HEVClc->first_qp_group = 1; | |
2705 | ✗ | s->sList[i]->HEVClc->qp_y = s->sList[0]->HEVClc->qp_y; | |
2706 | ✗ | memcpy(s->sList[i], s, sizeof(HEVCContext)); | |
2707 | ✗ | s->sList[i]->HEVClc = s->HEVClcList[i]; | |
2708 | } | ||
2709 | |||
2710 | ✗ | atomic_store(&s->wpp_err, 0); | |
2711 | ✗ | ff_reset_entries(s->avctx); | |
2712 | |||
2713 | ✗ | for (i = 0; i <= s->sh.num_entry_point_offsets; i++) { | |
2714 | ✗ | arg[i] = i; | |
2715 | ✗ | ret[i] = 0; | |
2716 | } | ||
2717 | |||
2718 | ✗ | if (s->ps.pps->entropy_coding_sync_enabled_flag) | |
2719 | ✗ | s->avctx->execute2(s->avctx, hls_decode_entry_wpp, arg, ret, s->sh.num_entry_point_offsets + 1); | |
2720 | |||
2721 | ✗ | for (i = 0; i <= s->sh.num_entry_point_offsets; i++) | |
2722 | ✗ | res += ret[i]; | |
2723 | ✗ | error: | |
2724 | ✗ | av_free(ret); | |
2725 | ✗ | av_free(arg); | |
2726 | ✗ | return res; | |
2727 | } | ||
2728 | |||
2729 | 9488 | static int set_side_data(HEVCContext *s) | |
2730 | { | ||
2731 | 9488 | AVFrame *out = s->ref->frame; | |
2732 | int ret; | ||
2733 | |||
2734 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
|
9488 | if (s->sei.frame_packing.present && |
2735 | ✗ | s->sei.frame_packing.arrangement_type >= 3 && | |
2736 | ✗ | s->sei.frame_packing.arrangement_type <= 5 && | |
2737 | ✗ | s->sei.frame_packing.content_interpretation_type > 0 && | |
2738 | ✗ | s->sei.frame_packing.content_interpretation_type < 3) { | |
2739 | ✗ | AVStereo3D *stereo = av_stereo3d_create_side_data(out); | |
2740 | ✗ | if (!stereo) | |
2741 | ✗ | return AVERROR(ENOMEM); | |
2742 | |||
2743 | ✗ | switch (s->sei.frame_packing.arrangement_type) { | |
2744 | ✗ | case 3: | |
2745 | ✗ | if (s->sei.frame_packing.quincunx_subsampling) | |
2746 | ✗ | stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX; | |
2747 | else | ||
2748 | ✗ | stereo->type = AV_STEREO3D_SIDEBYSIDE; | |
2749 | ✗ | break; | |
2750 | ✗ | case 4: | |
2751 | ✗ | stereo->type = AV_STEREO3D_TOPBOTTOM; | |
2752 | ✗ | break; | |
2753 | ✗ | case 5: | |
2754 | ✗ | stereo->type = AV_STEREO3D_FRAMESEQUENCE; | |
2755 | ✗ | break; | |
2756 | } | ||
2757 | |||
2758 | ✗ | if (s->sei.frame_packing.content_interpretation_type == 2) | |
2759 | ✗ | stereo->flags = AV_STEREO3D_FLAG_INVERT; | |
2760 | |||
2761 | ✗ | if (s->sei.frame_packing.arrangement_type == 5) { | |
2762 | ✗ | if (s->sei.frame_packing.current_frame_is_frame0_flag) | |
2763 | ✗ | stereo->view = AV_STEREO3D_VIEW_LEFT; | |
2764 | else | ||
2765 | ✗ | stereo->view = AV_STEREO3D_VIEW_RIGHT; | |
2766 | } | ||
2767 | } | ||
2768 | |||
2769 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
|
9488 | if (s->sei.display_orientation.present && |
2770 | ✗ | (s->sei.display_orientation.anticlockwise_rotation || | |
2771 | ✗ | s->sei.display_orientation.hflip || s->sei.display_orientation.vflip)) { | |
2772 | ✗ | double angle = s->sei.display_orientation.anticlockwise_rotation * 360 / (double) (1 << 16); | |
2773 | ✗ | AVFrameSideData *rotation = av_frame_new_side_data(out, | |
2774 | AV_FRAME_DATA_DISPLAYMATRIX, | ||
2775 | sizeof(int32_t) * 9); | ||
2776 | ✗ | if (!rotation) | |
2777 | ✗ | return AVERROR(ENOMEM); | |
2778 | |||
2779 | /* av_display_rotation_set() expects the angle in the clockwise | ||
2780 | * direction, hence the first minus. | ||
2781 | * The below code applies the flips after the rotation, yet | ||
2782 | * the H.2645 specs require flipping to be applied first. | ||
2783 | * Because of R O(phi) = O(-phi) R (where R is flipping around | ||
2784 | * an arbitatry axis and O(phi) is the proper rotation by phi) | ||
2785 | * we can create display matrices as desired by negating | ||
2786 | * the degree once for every flip applied. */ | ||
2787 | ✗ | angle = -angle * (1 - 2 * !!s->sei.display_orientation.hflip) | |
2788 | ✗ | * (1 - 2 * !!s->sei.display_orientation.vflip); | |
2789 | ✗ | av_display_rotation_set((int32_t *)rotation->data, angle); | |
2790 | ✗ | av_display_matrix_flip((int32_t *)rotation->data, | |
2791 | s->sei.display_orientation.hflip, | ||
2792 | s->sei.display_orientation.vflip); | ||
2793 | } | ||
2794 | |||
2795 | // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1 | ||
2796 | // so the side data persists for the entire coded video sequence. | ||
2797 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9484 times.
|
9488 | if (s->sei.mastering_display.present > 0 && |
2798 |
3/6✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | IS_IRAP(s) && s->no_rasl_output_flag) { |
2799 | 4 | s->sei.mastering_display.present--; | |
2800 | } | ||
2801 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9484 times.
|
9488 | if (s->sei.mastering_display.present) { |
2802 | // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b | ||
2803 | 4 | const int mapping[3] = {2, 0, 1}; | |
2804 | 4 | const int chroma_den = 50000; | |
2805 | 4 | const int luma_den = 10000; | |
2806 | int i; | ||
2807 | AVMasteringDisplayMetadata *metadata = | ||
2808 | 4 | av_mastering_display_metadata_create_side_data(out); | |
2809 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!metadata) |
2810 | ✗ | return AVERROR(ENOMEM); | |
2811 | |||
2812 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
|
16 | for (i = 0; i < 3; i++) { |
2813 | 12 | const int j = mapping[i]; | |
2814 | 12 | metadata->display_primaries[i][0].num = s->sei.mastering_display.display_primaries[j][0]; | |
2815 | 12 | metadata->display_primaries[i][0].den = chroma_den; | |
2816 | 12 | metadata->display_primaries[i][1].num = s->sei.mastering_display.display_primaries[j][1]; | |
2817 | 12 | metadata->display_primaries[i][1].den = chroma_den; | |
2818 | } | ||
2819 | 4 | metadata->white_point[0].num = s->sei.mastering_display.white_point[0]; | |
2820 | 4 | metadata->white_point[0].den = chroma_den; | |
2821 | 4 | metadata->white_point[1].num = s->sei.mastering_display.white_point[1]; | |
2822 | 4 | metadata->white_point[1].den = chroma_den; | |
2823 | |||
2824 | 4 | metadata->max_luminance.num = s->sei.mastering_display.max_luminance; | |
2825 | 4 | metadata->max_luminance.den = luma_den; | |
2826 | 4 | metadata->min_luminance.num = s->sei.mastering_display.min_luminance; | |
2827 | 4 | metadata->min_luminance.den = luma_den; | |
2828 | 4 | metadata->has_luminance = 1; | |
2829 | 4 | metadata->has_primaries = 1; | |
2830 | |||
2831 | 4 | av_log(s->avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n"); | |
2832 | 4 | av_log(s->avctx, AV_LOG_DEBUG, | |
2833 | "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n", | ||
2834 | av_q2d(metadata->display_primaries[0][0]), | ||
2835 | av_q2d(metadata->display_primaries[0][1]), | ||
2836 | av_q2d(metadata->display_primaries[1][0]), | ||
2837 | av_q2d(metadata->display_primaries[1][1]), | ||
2838 | av_q2d(metadata->display_primaries[2][0]), | ||
2839 | av_q2d(metadata->display_primaries[2][1]), | ||
2840 | av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1])); | ||
2841 | 4 | av_log(s->avctx, AV_LOG_DEBUG, | |
2842 | "min_luminance=%f, max_luminance=%f\n", | ||
2843 | av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); | ||
2844 | } | ||
2845 | // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1 | ||
2846 | // so the side data persists for the entire coded video sequence. | ||
2847 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9484 times.
|
9488 | if (s->sei.content_light.present > 0 && |
2848 |
3/6✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | IS_IRAP(s) && s->no_rasl_output_flag) { |
2849 | 4 | s->sei.content_light.present--; | |
2850 | } | ||
2851 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9484 times.
|
9488 | if (s->sei.content_light.present) { |
2852 | AVContentLightMetadata *metadata = | ||
2853 | 4 | av_content_light_metadata_create_side_data(out); | |
2854 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!metadata) |
2855 | ✗ | return AVERROR(ENOMEM); | |
2856 | 4 | metadata->MaxCLL = s->sei.content_light.max_content_light_level; | |
2857 | 4 | metadata->MaxFALL = s->sei.content_light.max_pic_average_light_level; | |
2858 | |||
2859 | 4 | av_log(s->avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); | |
2860 | 4 | av_log(s->avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", | |
2861 | metadata->MaxCLL, metadata->MaxFALL); | ||
2862 | } | ||
2863 | |||
2864 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
|
9488 | if (s->sei.a53_caption.buf_ref) { |
2865 | ✗ | HEVCSEIA53Caption *a53 = &s->sei.a53_caption; | |
2866 | |||
2867 | ✗ | AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_A53_CC, a53->buf_ref); | |
2868 | ✗ | if (!sd) | |
2869 | ✗ | av_buffer_unref(&a53->buf_ref); | |
2870 | ✗ | a53->buf_ref = NULL; | |
2871 | } | ||
2872 | |||
2873 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9488 times.
|
9497 | for (int i = 0; i < s->sei.unregistered.nb_buf_ref; i++) { |
2874 | 9 | HEVCSEIUnregistered *unreg = &s->sei.unregistered; | |
2875 | |||
2876 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (unreg->buf_ref[i]) { |
2877 | 9 | AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, | |
2878 | AV_FRAME_DATA_SEI_UNREGISTERED, | ||
2879 | 9 | unreg->buf_ref[i]); | |
2880 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (!sd) |
2881 | ✗ | av_buffer_unref(&unreg->buf_ref[i]); | |
2882 | 9 | unreg->buf_ref[i] = NULL; | |
2883 | } | ||
2884 | } | ||
2885 | 9488 | s->sei.unregistered.nb_buf_ref = 0; | |
2886 | |||
2887 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9486 times.
|
9488 | if (s->sei.timecode.present) { |
2888 | uint32_t *tc_sd; | ||
2889 | char tcbuf[AV_TIMECODE_STR_SIZE]; | ||
2890 | 2 | AVFrameSideData *tcside = av_frame_new_side_data(out, AV_FRAME_DATA_S12M_TIMECODE, | |
2891 | sizeof(uint32_t) * 4); | ||
2892 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!tcside) |
2893 | ✗ | return AVERROR(ENOMEM); | |
2894 | |||
2895 | 2 | tc_sd = (uint32_t*)tcside->data; | |
2896 | 2 | tc_sd[0] = s->sei.timecode.num_clock_ts; | |
2897 | |||
2898 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | for (int i = 0; i < tc_sd[0]; i++) { |
2899 | 2 | int drop = s->sei.timecode.cnt_dropped_flag[i]; | |
2900 | 2 | int hh = s->sei.timecode.hours_value[i]; | |
2901 | 2 | int mm = s->sei.timecode.minutes_value[i]; | |
2902 | 2 | int ss = s->sei.timecode.seconds_value[i]; | |
2903 | 2 | int ff = s->sei.timecode.n_frames[i]; | |
2904 | |||
2905 | 2 | tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff); | |
2906 | 2 | av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0); | |
2907 | 2 | av_dict_set(&out->metadata, "timecode", tcbuf, 0); | |
2908 | } | ||
2909 | |||
2910 | 2 | s->sei.timecode.num_clock_ts = 0; | |
2911 | } | ||
2912 | |||
2913 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
|
9488 | if (s->sei.film_grain_characteristics.present) { |
2914 | ✗ | HEVCSEIFilmGrainCharacteristics *fgc = &s->sei.film_grain_characteristics; | |
2915 | ✗ | AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(out); | |
2916 | ✗ | if (!fgp) | |
2917 | ✗ | return AVERROR(ENOMEM); | |
2918 | |||
2919 | ✗ | fgp->type = AV_FILM_GRAIN_PARAMS_H274; | |
2920 | ✗ | fgp->seed = s->ref->poc; /* no poc_offset in HEVC */ | |
2921 | |||
2922 | ✗ | fgp->codec.h274.model_id = fgc->model_id; | |
2923 | ✗ | if (fgc->separate_colour_description_present_flag) { | |
2924 | ✗ | fgp->codec.h274.bit_depth_luma = fgc->bit_depth_luma; | |
2925 | ✗ | fgp->codec.h274.bit_depth_chroma = fgc->bit_depth_chroma; | |
2926 | ✗ | fgp->codec.h274.color_range = fgc->full_range + 1; | |
2927 | ✗ | fgp->codec.h274.color_primaries = fgc->color_primaries; | |
2928 | ✗ | fgp->codec.h274.color_trc = fgc->transfer_characteristics; | |
2929 | ✗ | fgp->codec.h274.color_space = fgc->matrix_coeffs; | |
2930 | } else { | ||
2931 | ✗ | const HEVCSPS *sps = s->ps.sps; | |
2932 | ✗ | const VUI *vui = &sps->vui; | |
2933 | ✗ | fgp->codec.h274.bit_depth_luma = sps->bit_depth; | |
2934 | ✗ | fgp->codec.h274.bit_depth_chroma = sps->bit_depth_chroma; | |
2935 | ✗ | if (vui->video_signal_type_present_flag) | |
2936 | ✗ | fgp->codec.h274.color_range = vui->video_full_range_flag + 1; | |
2937 | else | ||
2938 | ✗ | fgp->codec.h274.color_range = AVCOL_RANGE_UNSPECIFIED; | |
2939 | ✗ | if (vui->colour_description_present_flag) { | |
2940 | ✗ | fgp->codec.h274.color_primaries = vui->colour_primaries; | |
2941 | ✗ | fgp->codec.h274.color_trc = vui->transfer_characteristic; | |
2942 | ✗ | fgp->codec.h274.color_space = vui->matrix_coeffs; | |
2943 | } else { | ||
2944 | ✗ | fgp->codec.h274.color_primaries = AVCOL_PRI_UNSPECIFIED; | |
2945 | ✗ | fgp->codec.h274.color_trc = AVCOL_TRC_UNSPECIFIED; | |
2946 | ✗ | fgp->codec.h274.color_space = AVCOL_SPC_UNSPECIFIED; | |
2947 | } | ||
2948 | } | ||
2949 | ✗ | fgp->codec.h274.blending_mode_id = fgc->blending_mode_id; | |
2950 | ✗ | fgp->codec.h274.log2_scale_factor = fgc->log2_scale_factor; | |
2951 | |||
2952 | ✗ | memcpy(&fgp->codec.h274.component_model_present, &fgc->comp_model_present_flag, | |
2953 | sizeof(fgp->codec.h274.component_model_present)); | ||
2954 | ✗ | memcpy(&fgp->codec.h274.num_intensity_intervals, &fgc->num_intensity_intervals, | |
2955 | sizeof(fgp->codec.h274.num_intensity_intervals)); | ||
2956 | ✗ | memcpy(&fgp->codec.h274.num_model_values, &fgc->num_model_values, | |
2957 | sizeof(fgp->codec.h274.num_model_values)); | ||
2958 | ✗ | memcpy(&fgp->codec.h274.intensity_interval_lower_bound, &fgc->intensity_interval_lower_bound, | |
2959 | sizeof(fgp->codec.h274.intensity_interval_lower_bound)); | ||
2960 | ✗ | memcpy(&fgp->codec.h274.intensity_interval_upper_bound, &fgc->intensity_interval_upper_bound, | |
2961 | sizeof(fgp->codec.h274.intensity_interval_upper_bound)); | ||
2962 | ✗ | memcpy(&fgp->codec.h274.comp_model_value, &fgc->comp_model_value, | |
2963 | sizeof(fgp->codec.h274.comp_model_value)); | ||
2964 | |||
2965 | ✗ | fgc->present = fgc->persistence_flag; | |
2966 | } | ||
2967 | |||
2968 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9486 times.
|
9488 | if (s->sei.dynamic_hdr_plus.info) { |
2969 | 2 | AVBufferRef *info_ref = av_buffer_ref(s->sei.dynamic_hdr_plus.info); | |
2970 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!info_ref) |
2971 | ✗ | return AVERROR(ENOMEM); | |
2972 | |||
2973 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, info_ref)) { |
2974 | ✗ | av_buffer_unref(&info_ref); | |
2975 | ✗ | return AVERROR(ENOMEM); | |
2976 | } | ||
2977 | } | ||
2978 | |||
2979 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9486 times.
|
9488 | if (s->rpu_buf) { |
2980 | 2 | AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf); | |
2981 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!rpu) |
2982 | ✗ | return AVERROR(ENOMEM); | |
2983 | |||
2984 | 2 | s->rpu_buf = NULL; | |
2985 | } | ||
2986 | |||
2987 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9488 times.
|
9488 | if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0) |
2988 | ✗ | return ret; | |
2989 | |||
2990 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9486 times.
|
9488 | if (s->sei.dynamic_hdr_vivid.info) { |
2991 | 2 | AVBufferRef *info_ref = av_buffer_ref(s->sei.dynamic_hdr_vivid.info); | |
2992 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!info_ref) |
2993 | ✗ | return AVERROR(ENOMEM); | |
2994 | |||
2995 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DYNAMIC_HDR_VIVID, info_ref)) { |
2996 | ✗ | av_buffer_unref(&info_ref); | |
2997 | ✗ | return AVERROR(ENOMEM); | |
2998 | } | ||
2999 | } | ||
3000 | |||
3001 | 9488 | return 0; | |
3002 | } | ||
3003 | |||
3004 | 9488 | static int hevc_frame_start(HEVCContext *s) | |
3005 | { | ||
3006 | 9488 | HEVCLocalContext *lc = s->HEVClc; | |
3007 | 9488 | int pic_size_in_ctb = ((s->ps.sps->width >> s->ps.sps->log2_min_cb_size) + 1) * | |
3008 | 9488 | ((s->ps.sps->height >> s->ps.sps->log2_min_cb_size) + 1); | |
3009 | int ret; | ||
3010 | |||
3011 | 9488 | memset(s->horizontal_bs, 0, s->bs_width * s->bs_height); | |
3012 | 9488 | memset(s->vertical_bs, 0, s->bs_width * s->bs_height); | |
3013 | 9488 | memset(s->cbf_luma, 0, s->ps.sps->min_tb_width * s->ps.sps->min_tb_height); | |
3014 | 9488 | memset(s->is_pcm, 0, (s->ps.sps->min_pu_width + 1) * (s->ps.sps->min_pu_height + 1)); | |
3015 | 9488 | memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address)); | |
3016 | |||
3017 | 9488 | s->is_decoded = 0; | |
3018 | 9488 | s->first_nal_type = s->nal_unit_type; | |
3019 | |||
3020 |
14/14✓ Branch 0 taken 9129 times.
✓ Branch 1 taken 359 times.
✓ Branch 2 taken 9115 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 9113 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9106 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9105 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 155 times.
✓ Branch 11 taken 8950 times.
✓ Branch 12 taken 8 times.
✓ Branch 13 taken 147 times.
|
9488 | s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos); |
3021 | |||
3022 |
2/2✓ Branch 0 taken 624 times.
✓ Branch 1 taken 8864 times.
|
9488 | if (s->ps.pps->tiles_enabled_flag) |
3023 | 624 | lc->end_of_tiles_x = s->ps.pps->column_width[0] << s->ps.sps->log2_ctb_size; | |
3024 | |||
3025 | 9488 | ret = ff_hevc_set_new_ref(s, &s->frame, s->poc); | |
3026 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
|
9488 | if (ret < 0) |
3027 | ✗ | goto fail; | |
3028 | |||
3029 | 9488 | ret = ff_hevc_frame_rps(s); | |
3030 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
|
9488 | if (ret < 0) { |
3031 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n"); | |
3032 | ✗ | goto fail; | |
3033 | } | ||
3034 | |||
3035 |
3/4✓ Branch 0 taken 538 times.
✓ Branch 1 taken 8950 times.
✓ Branch 2 taken 538 times.
✗ Branch 3 not taken.
|
9488 | s->ref->frame->key_frame = IS_IRAP(s); |
3036 | |||
3037 | 18976 | s->ref->needs_fg = s->sei.film_grain_characteristics.present && | |
3038 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
9488 | !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && |
3039 | ✗ | !s->avctx->hwaccel; | |
3040 | |||
3041 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
|
9488 | if (s->ref->needs_fg) { |
3042 | ✗ | s->ref->frame_grain->format = s->ref->frame->format; | |
3043 | ✗ | s->ref->frame_grain->width = s->ref->frame->width; | |
3044 | ✗ | s->ref->frame_grain->height = s->ref->frame->height; | |
3045 | ✗ | if ((ret = ff_thread_get_buffer(s->avctx, s->ref->frame_grain, 0)) < 0) | |
3046 | ✗ | goto fail; | |
3047 | } | ||
3048 | |||
3049 | 9488 | ret = set_side_data(s); | |
3050 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
|
9488 | if (ret < 0) |
3051 | ✗ | goto fail; | |
3052 | |||
3053 | 9488 | s->frame->pict_type = 3 - s->sh.slice_type; | |
3054 | |||
3055 |
3/4✓ Branch 0 taken 538 times.
✓ Branch 1 taken 8950 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 538 times.
|
9488 | if (!IS_IRAP(s)) |
3056 | 8950 | ff_hevc_bump_frame(s); | |
3057 | |||
3058 | 9488 | av_frame_unref(s->output_frame); | |
3059 | 9488 | ret = ff_hevc_output_frame(s, s->output_frame, 0); | |
3060 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9488 times.
|
9488 | if (ret < 0) |
3061 | ✗ | goto fail; | |
3062 | |||
3063 |
1/2✓ Branch 0 taken 9488 times.
✗ Branch 1 not taken.
|
9488 | if (!s->avctx->hwaccel) |
3064 | 9488 | ff_thread_finish_setup(s->avctx); | |
3065 | |||
3066 | 9488 | return 0; | |
3067 | |||
3068 | ✗ | fail: | |
3069 | ✗ | if (s->ref) | |
3070 | ✗ | ff_hevc_unref_frame(s, s->ref, ~0); | |
3071 | ✗ | s->ref = NULL; | |
3072 | ✗ | return ret; | |
3073 | } | ||
3074 | |||
3075 | 9487 | static int hevc_frame_end(HEVCContext *s) | |
3076 | { | ||
3077 | 9487 | HEVCFrame *out = s->ref; | |
3078 | const AVFrameSideData *sd; | ||
3079 | int ret; | ||
3080 | |||
3081 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9487 times.
|
9487 | if (out->needs_fg) { |
3082 | ✗ | sd = av_frame_get_side_data(out->frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS); | |
3083 | ✗ | av_assert0(out->frame_grain->buf[0] && sd); | |
3084 | ✗ | ret = ff_h274_apply_film_grain(out->frame_grain, out->frame, &s->h274db, | |
3085 | ✗ | (AVFilmGrainParams *) sd->data); | |
3086 | |||
3087 | ✗ | if (ret < 0) { | |
3088 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Failed synthesizing film " | |
3089 | ✗ | "grain, ignoring: %s\n", av_err2str(ret)); | |
3090 | ✗ | out->needs_fg = 0; | |
3091 | } | ||
3092 | } | ||
3093 | |||
3094 | 9487 | return 0; | |
3095 | } | ||
3096 | |||
3097 | 37893 | static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) | |
3098 | { | ||
3099 | 37893 | HEVCLocalContext *lc = s->HEVClc; | |
3100 | 37893 | GetBitContext *gb = &lc->gb; | |
3101 | int ctb_addr_ts, ret; | ||
3102 | |||
3103 | 37893 | *gb = nal->gb; | |
3104 | 37893 | s->nal_unit_type = nal->type; | |
3105 | 37893 | s->temporal_id = nal->temporal_id; | |
3106 | |||
3107 |
7/8✓ Branch 0 taken 404 times.
✓ Branch 1 taken 401 times.
✓ Branch 2 taken 1359 times.
✓ Branch 3 taken 7499 times.
✓ Branch 4 taken 27585 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 641 times.
✗ Branch 7 not taken.
|
37893 | switch (s->nal_unit_type) { |
3108 | 404 | case HEVC_NAL_VPS: | |
3109 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 404 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
404 | if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) { |
3110 | ✗ | ret = s->avctx->hwaccel->decode_params(s->avctx, | |
3111 | ✗ | nal->type, | |
3112 | ✗ | nal->raw_data, | |
3113 | ✗ | nal->raw_size); | |
3114 | ✗ | if (ret < 0) | |
3115 | ✗ | goto fail; | |
3116 | } | ||
3117 | 404 | ret = ff_hevc_decode_nal_vps(gb, s->avctx, &s->ps); | |
3118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 404 times.
|
404 | if (ret < 0) |
3119 | ✗ | goto fail; | |
3120 | 404 | break; | |
3121 | 401 | case HEVC_NAL_SPS: | |
3122 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
401 | if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) { |
3123 | ✗ | ret = s->avctx->hwaccel->decode_params(s->avctx, | |
3124 | ✗ | nal->type, | |
3125 | ✗ | nal->raw_data, | |
3126 | ✗ | nal->raw_size); | |
3127 | ✗ | if (ret < 0) | |
3128 | ✗ | goto fail; | |
3129 | } | ||
3130 | 401 | ret = ff_hevc_decode_nal_sps(gb, s->avctx, &s->ps, | |
3131 | s->apply_defdispwin); | ||
3132 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 401 times.
|
401 | if (ret < 0) |
3133 | ✗ | goto fail; | |
3134 | 401 | break; | |
3135 | 1359 | case HEVC_NAL_PPS: | |
3136 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1359 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1359 | if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) { |
3137 | ✗ | ret = s->avctx->hwaccel->decode_params(s->avctx, | |
3138 | ✗ | nal->type, | |
3139 | ✗ | nal->raw_data, | |
3140 | <