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