| 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 | #include "libavutil/refstruct.h" | ||
| 42 | |||
| 43 | #include "libavcodec/aom_film_grain.h" | ||
| 44 | #include "libavcodec/bswapdsp.h" | ||
| 45 | #include "libavcodec/cabac_functions.h" | ||
| 46 | #include "libavcodec/codec_internal.h" | ||
| 47 | #include "libavcodec/decode.h" | ||
| 48 | #include "libavcodec/golomb.h" | ||
| 49 | #include "libavcodec/h274.h" | ||
| 50 | #include "libavcodec/hwaccel_internal.h" | ||
| 51 | #include "libavcodec/hwconfig.h" | ||
| 52 | #include "libavcodec/internal.h" | ||
| 53 | #include "libavcodec/profiles.h" | ||
| 54 | #include "libavcodec/progressframe.h" | ||
| 55 | #include "libavcodec/thread.h" | ||
| 56 | #include "libavcodec/threadprogress.h" | ||
| 57 | |||
| 58 | #include "hevc.h" | ||
| 59 | #include "parse.h" | ||
| 60 | #include "hevcdec.h" | ||
| 61 | |||
| 62 | 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 }; | ||
| 63 | |||
| 64 | /** | ||
| 65 | * NOTE: Each function hls_foo correspond to the function foo in the | ||
| 66 | * specification (HLS stands for High Level Syntax). | ||
| 67 | */ | ||
| 68 | |||
| 69 | /** | ||
| 70 | * Section 5.7 | ||
| 71 | */ | ||
| 72 | |||
| 73 | /* free everything allocated by pic_arrays_init() */ | ||
| 74 | 1463 | static void pic_arrays_free(HEVCLayerContext *l) | |
| 75 | { | ||
| 76 | 1463 | av_freep(&l->sao); | |
| 77 | 1463 | av_freep(&l->deblock); | |
| 78 | |||
| 79 | 1463 | av_freep(&l->skip_flag); | |
| 80 | 1463 | av_freep(&l->tab_ct_depth); | |
| 81 | |||
| 82 | 1463 | av_freep(&l->tab_ipm); | |
| 83 | 1463 | av_freep(&l->cbf_luma); | |
| 84 | 1463 | av_freep(&l->is_pcm); | |
| 85 | |||
| 86 | 1463 | av_freep(&l->qp_y_tab); | |
| 87 | 1463 | av_freep(&l->tab_slice_address); | |
| 88 | 1463 | av_freep(&l->filter_slice_edges); | |
| 89 | |||
| 90 | 1463 | av_freep(&l->horizontal_bs); | |
| 91 | 1463 | av_freep(&l->vertical_bs); | |
| 92 | |||
| 93 |
2/2✓ Branch 0 taken 4389 times.
✓ Branch 1 taken 1463 times.
|
5852 | for (int i = 0; i < 3; i++) { |
| 94 | 4389 | av_freep(&l->sao_pixel_buffer_h[i]); | |
| 95 | 4389 | av_freep(&l->sao_pixel_buffer_v[i]); | |
| 96 | } | ||
| 97 | |||
| 98 | 1463 | av_refstruct_pool_uninit(&l->tab_mvf_pool); | |
| 99 | 1463 | av_refstruct_pool_uninit(&l->rpl_tab_pool); | |
| 100 | 1463 | } | |
| 101 | |||
| 102 | /* allocate arrays that depend on frame dimensions */ | ||
| 103 | 261 | static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps) | |
| 104 | { | ||
| 105 | 261 | int log2_min_cb_size = sps->log2_min_cb_size; | |
| 106 | 261 | int width = sps->width; | |
| 107 | 261 | int height = sps->height; | |
| 108 | 261 | int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) * | |
| 109 | 261 | ((height >> log2_min_cb_size) + 1); | |
| 110 | 261 | int ctb_count = sps->ctb_width * sps->ctb_height; | |
| 111 | 261 | int min_pu_size = sps->min_pu_width * sps->min_pu_height; | |
| 112 | |||
| 113 | 261 | l->bs_width = (width >> 2) + 1; | |
| 114 | 261 | l->bs_height = (height >> 2) + 1; | |
| 115 | |||
| 116 | 261 | l->sao = av_calloc(ctb_count, sizeof(*l->sao)); | |
| 117 | 261 | l->deblock = av_calloc(ctb_count, sizeof(*l->deblock)); | |
| 118 |
2/4✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 261 times.
|
261 | if (!l->sao || !l->deblock) |
| 119 | ✗ | goto fail; | |
| 120 | |||
| 121 | 261 | l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
| 122 | 261 | l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
| 123 |
2/4✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 261 times.
|
261 | if (!l->skip_flag || !l->tab_ct_depth) |
| 124 | ✗ | goto fail; | |
| 125 | |||
| 126 | 261 | l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height); | |
| 127 | 261 | l->tab_ipm = av_mallocz(min_pu_size); | |
| 128 | 261 | l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1); | |
| 129 |
3/6✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 261 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 261 times.
|
261 | if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm) |
| 130 | ✗ | goto fail; | |
| 131 | |||
| 132 | 261 | l->filter_slice_edges = av_mallocz(ctb_count); | |
| 133 | 261 | l->tab_slice_address = av_malloc_array(pic_size_in_ctb, | |
| 134 | sizeof(*l->tab_slice_address)); | ||
| 135 | 261 | l->qp_y_tab = av_calloc(pic_size_in_ctb, | |
| 136 | sizeof(*l->qp_y_tab)); | ||
| 137 |
3/6✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 261 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 261 times.
|
261 | if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address) |
| 138 | ✗ | goto fail; | |
| 139 | |||
| 140 | 261 | l->horizontal_bs = av_calloc(l->bs_width, l->bs_height); | |
| 141 | 261 | l->vertical_bs = av_calloc(l->bs_width, l->bs_height); | |
| 142 |
2/4✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 261 times.
|
261 | if (!l->horizontal_bs || !l->vertical_bs) |
| 143 | ✗ | goto fail; | |
| 144 | |||
| 145 | 261 | l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0); | |
| 146 | 261 | l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0); | |
| 147 |
2/4✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 261 times.
|
261 | if (!l->tab_mvf_pool || !l->rpl_tab_pool) |
| 148 | ✗ | goto fail; | |
| 149 | |||
| 150 |
2/2✓ Branch 0 taken 217 times.
✓ Branch 1 taken 44 times.
|
261 | if (sps->sao_enabled) { |
| 151 |
2/2✓ Branch 0 taken 216 times.
✓ Branch 1 taken 1 times.
|
217 | int c_count = (sps->chroma_format_idc != 0) ? 3 : 1; |
| 152 | |||
| 153 |
2/2✓ Branch 0 taken 649 times.
✓ Branch 1 taken 217 times.
|
866 | for (int c_idx = 0; c_idx < c_count; c_idx++) { |
| 154 | 649 | int w = sps->width >> sps->hshift[c_idx]; | |
| 155 | 649 | int h = sps->height >> sps->vshift[c_idx]; | |
| 156 | 649 | l->sao_pixel_buffer_h[c_idx] = | |
| 157 | 649 | av_mallocz((w * 2 * sps->ctb_height) << | |
| 158 | 649 | sps->pixel_shift); | |
| 159 | 649 | l->sao_pixel_buffer_v[c_idx] = | |
| 160 | 649 | av_mallocz((h * 2 * sps->ctb_width) << | |
| 161 | 649 | sps->pixel_shift); | |
| 162 |
1/2✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
|
649 | if (!l->sao_pixel_buffer_h[c_idx] || |
| 163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 649 times.
|
649 | !l->sao_pixel_buffer_v[c_idx]) |
| 164 | ✗ | goto fail; | |
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | 261 | return 0; | |
| 169 | |||
| 170 | ✗ | fail: | |
| 171 | ✗ | pic_arrays_free(l); | |
| 172 | ✗ | return AVERROR(ENOMEM); | |
| 173 | } | ||
| 174 | |||
| 175 | 1501 | static int pred_weight_table(SliceHeader *sh, void *logctx, | |
| 176 | const HEVCSPS *sps, GetBitContext *gb) | ||
| 177 | { | ||
| 178 | 1501 | int i = 0; | |
| 179 | 1501 | int j = 0; | |
| 180 | int luma_log2_weight_denom; | ||
| 181 | unsigned luma_weight_flags, chroma_weight_flags; | ||
| 182 | |||
| 183 | 1501 | luma_log2_weight_denom = get_ue_golomb_long(gb); | |
| 184 |
2/4✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1501 times.
|
1501 | if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) { |
| 185 | ✗ | av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom); | |
| 186 | ✗ | return AVERROR_INVALIDDATA; | |
| 187 | } | ||
| 188 | 1501 | sh->luma_log2_weight_denom = luma_log2_weight_denom; | |
| 189 |
1/2✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
|
1501 | if (sps->chroma_format_idc != 0) { |
| 190 | 1501 | int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb); | |
| 191 |
2/4✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1501 times.
|
1501 | if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) { |
| 192 | ✗ | av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom); | |
| 193 | ✗ | return AVERROR_INVALIDDATA; | |
| 194 | } | ||
| 195 | 1501 | sh->chroma_log2_weight_denom = chroma_log2_weight_denom; | |
| 196 | } | ||
| 197 | |||
| 198 | 1501 | luma_weight_flags = get_bits(gb, sh->nb_refs[L0]); | |
| 199 |
1/2✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
|
1501 | chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L0]) : 0; |
| 200 |
2/2✓ Branch 0 taken 4549 times.
✓ Branch 1 taken 1501 times.
|
6050 | for (i = 0; i < sh->nb_refs[L0]; i++) { |
| 201 | 4549 | unsigned flag_bit = 1 << (sh->nb_refs[L0] - 1 - i); | |
| 202 | |||
| 203 |
2/2✓ Branch 0 taken 3117 times.
✓ Branch 1 taken 1432 times.
|
4549 | if (luma_weight_flags & flag_bit) { |
| 204 | 3117 | int delta_luma_weight_l0 = get_se_golomb(gb); | |
| 205 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3117 times.
|
3117 | if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0) |
| 206 | ✗ | return AVERROR_INVALIDDATA; | |
| 207 | 3117 | sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0; | |
| 208 | 3117 | sh->luma_offset_l0[i] = get_se_golomb(gb); | |
| 209 | } else { | ||
| 210 | 1432 | sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom; | |
| 211 | 1432 | sh->luma_offset_l0[i] = 0; | |
| 212 | } | ||
| 213 |
2/2✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 3418 times.
|
4549 | if (chroma_weight_flags & flag_bit) { |
| 214 |
2/2✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 1131 times.
|
3393 | for (j = 0; j < 2; j++) { |
| 215 | 2262 | int delta_chroma_weight_l0 = get_se_golomb(gb); | |
| 216 | 2262 | int delta_chroma_offset_l0 = get_se_golomb(gb); | |
| 217 | |||
| 218 |
1/2✓ Branch 0 taken 2262 times.
✗ Branch 1 not taken.
|
2262 | if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0 |
| 219 |
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)) { |
| 220 | ✗ | return AVERROR_INVALIDDATA; | |
| 221 | } | ||
| 222 | |||
| 223 | 2262 | sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0; | |
| 224 | 2262 | sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j]) | |
| 225 | 2262 | >> sh->chroma_log2_weight_denom) + 128), -128, 127); | |
| 226 | } | ||
| 227 | } else { | ||
| 228 | 3418 | sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom; | |
| 229 | 3418 | sh->chroma_offset_l0[i][0] = 0; | |
| 230 | 3418 | sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom; | |
| 231 | 3418 | sh->chroma_offset_l0[i][1] = 0; | |
| 232 | } | ||
| 233 | } | ||
| 234 |
2/2✓ Branch 0 taken 696 times.
✓ Branch 1 taken 805 times.
|
1501 | if (sh->slice_type == HEVC_SLICE_B) { |
| 235 | 696 | luma_weight_flags = get_bits(gb, sh->nb_refs[L1]); | |
| 236 |
1/2✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
|
696 | chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L1]) : 0; |
| 237 |
2/2✓ Branch 0 taken 1405 times.
✓ Branch 1 taken 696 times.
|
2101 | for (i = 0; i < sh->nb_refs[L1]; i++) { |
| 238 | 1405 | unsigned flag_bit = 1 << (sh->nb_refs[L1] - 1 - i); | |
| 239 | |||
| 240 |
2/2✓ Branch 0 taken 746 times.
✓ Branch 1 taken 659 times.
|
1405 | if (luma_weight_flags & flag_bit) { |
| 241 | 746 | int delta_luma_weight_l1 = get_se_golomb(gb); | |
| 242 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 746 times.
|
746 | if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1) |
| 243 | ✗ | return AVERROR_INVALIDDATA; | |
| 244 | 746 | sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1; | |
| 245 | 746 | sh->luma_offset_l1[i] = get_se_golomb(gb); | |
| 246 | } else { | ||
| 247 | 659 | sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom; | |
| 248 | 659 | sh->luma_offset_l1[i] = 0; | |
| 249 | } | ||
| 250 |
2/2✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1169 times.
|
1405 | if (chroma_weight_flags & flag_bit) { |
| 251 |
2/2✓ Branch 0 taken 472 times.
✓ Branch 1 taken 236 times.
|
708 | for (j = 0; j < 2; j++) { |
| 252 | 472 | int delta_chroma_weight_l1 = get_se_golomb(gb); | |
| 253 | 472 | int delta_chroma_offset_l1 = get_se_golomb(gb); | |
| 254 | |||
| 255 |
1/2✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
|
472 | if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1 |
| 256 |
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)) { |
| 257 | ✗ | return AVERROR_INVALIDDATA; | |
| 258 | } | ||
| 259 | |||
| 260 | 472 | sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1; | |
| 261 | 472 | sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j]) | |
| 262 | 472 | >> sh->chroma_log2_weight_denom) + 128), -128, 127); | |
| 263 | } | ||
| 264 | } else { | ||
| 265 | 1169 | sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom; | |
| 266 | 1169 | sh->chroma_offset_l1[i][0] = 0; | |
| 267 | 1169 | sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom; | |
| 268 | 1169 | sh->chroma_offset_l1[i][1] = 0; | |
| 269 | } | ||
| 270 | } | ||
| 271 | } | ||
| 272 | 1501 | return 0; | |
| 273 | } | ||
| 274 | |||
| 275 | 20478 | static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps, | |
| 276 | GetBitContext *gb, int cur_poc, int poc_lsb) | ||
| 277 | { | ||
| 278 | 20478 | int max_poc_lsb = 1 << sps->log2_max_poc_lsb; | |
| 279 | 20478 | int prev_delta_msb = 0; | |
| 280 | 20478 | unsigned int nb_sps = 0, nb_sh; | |
| 281 | int i; | ||
| 282 | |||
| 283 | 20478 | rps->nb_refs = 0; | |
| 284 |
2/2✓ Branch 0 taken 19076 times.
✓ Branch 1 taken 1402 times.
|
20478 | if (!sps->long_term_ref_pics_present) |
| 285 | 19076 | return 0; | |
| 286 | |||
| 287 |
2/2✓ Branch 0 taken 499 times.
✓ Branch 1 taken 903 times.
|
1402 | if (sps->num_long_term_ref_pics_sps > 0) |
| 288 | 499 | nb_sps = get_ue_golomb_long(gb); | |
| 289 | 1402 | nb_sh = get_ue_golomb_long(gb); | |
| 290 | |||
| 291 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1402 times.
|
1402 | if (nb_sps > sps->num_long_term_ref_pics_sps) |
| 292 | ✗ | return AVERROR_INVALIDDATA; | |
| 293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1402 times.
|
1402 | if (nb_sh + (uint64_t)nb_sps > FF_ARRAY_ELEMS(rps->poc)) |
| 294 | ✗ | return AVERROR_INVALIDDATA; | |
| 295 | |||
| 296 | 1402 | rps->nb_refs = nb_sh + nb_sps; | |
| 297 | |||
| 298 |
2/2✓ Branch 0 taken 1928 times.
✓ Branch 1 taken 1402 times.
|
3330 | for (i = 0; i < rps->nb_refs; i++) { |
| 299 | |||
| 300 |
2/2✓ Branch 0 taken 184 times.
✓ Branch 1 taken 1744 times.
|
1928 | if (i < nb_sps) { |
| 301 | 184 | uint8_t lt_idx_sps = 0; | |
| 302 | |||
| 303 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (sps->num_long_term_ref_pics_sps > 1) |
| 304 | 184 | lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps)); | |
| 305 | |||
| 306 | 184 | rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps]; | |
| 307 | 184 | rps->used[i] = !!(sps->used_by_curr_pic_lt & (1U << lt_idx_sps)); | |
| 308 | } else { | ||
| 309 | 1744 | rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb); | |
| 310 | 1744 | rps->used[i] = get_bits1(gb); | |
| 311 | } | ||
| 312 | |||
| 313 | 1928 | rps->poc_msb_present[i] = get_bits1(gb); | |
| 314 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1880 times.
|
1928 | if (rps->poc_msb_present[i]) { |
| 315 | 48 | int64_t delta = get_ue_golomb_long(gb); | |
| 316 | int64_t poc; | ||
| 317 | |||
| 318 |
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) |
| 319 | 31 | delta += prev_delta_msb; | |
| 320 | |||
| 321 | 48 | poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb; | |
| 322 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (poc != (int32_t)poc) |
| 323 | ✗ | return AVERROR_INVALIDDATA; | |
| 324 | 48 | rps->poc[i] = poc; | |
| 325 | 48 | prev_delta_msb = delta; | |
| 326 | } | ||
| 327 | } | ||
| 328 | |||
| 329 | 1402 | return 0; | |
| 330 | } | ||
| 331 | |||
| 332 | 839 | static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) | |
| 333 | { | ||
| 334 | 839 | AVCodecContext *avctx = s->avctx; | |
| 335 | 839 | const HEVCVPS *vps = sps->vps; | |
| 336 | 839 | const HEVCWindow *ow = &sps->output_window; | |
| 337 | 839 | unsigned int num = 0, den = 0; | |
| 338 | |||
| 339 | 839 | avctx->pix_fmt = sps->pix_fmt; | |
| 340 | 839 | avctx->coded_width = sps->width; | |
| 341 | 839 | avctx->coded_height = sps->height; | |
| 342 | 839 | avctx->width = sps->width - ow->left_offset - ow->right_offset; | |
| 343 | 839 | avctx->height = sps->height - ow->top_offset - ow->bottom_offset; | |
| 344 | 839 | avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics; | |
| 345 | 839 | avctx->profile = sps->ptl.general_ptl.profile_idc; | |
| 346 | 839 | avctx->level = sps->ptl.general_ptl.level_idc; | |
| 347 | |||
| 348 | 839 | ff_set_sar(avctx, sps->vui.common.sar); | |
| 349 | |||
| 350 |
2/2✓ Branch 0 taken 132 times.
✓ Branch 1 taken 707 times.
|
839 | if (sps->vui.common.video_signal_type_present_flag) |
| 351 | 132 | avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG | |
| 352 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 122 times.
|
132 | : AVCOL_RANGE_MPEG; |
| 353 | else | ||
| 354 | 707 | avctx->color_range = AVCOL_RANGE_MPEG; | |
| 355 | |||
| 356 |
2/2✓ Branch 0 taken 125 times.
✓ Branch 1 taken 714 times.
|
839 | if (sps->vui.common.colour_description_present_flag) { |
| 357 | 125 | avctx->color_primaries = sps->vui.common.colour_primaries; | |
| 358 | 125 | avctx->color_trc = sps->vui.common.transfer_characteristics; | |
| 359 | 125 | avctx->colorspace = sps->vui.common.matrix_coeffs; | |
| 360 | } else { | ||
| 361 | 714 | avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; | |
| 362 | 714 | avctx->color_trc = AVCOL_TRC_UNSPECIFIED; | |
| 363 | 714 | avctx->colorspace = AVCOL_SPC_UNSPECIFIED; | |
| 364 | } | ||
| 365 | |||
| 366 | 839 | avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED; | |
| 367 |
2/2✓ Branch 0 taken 795 times.
✓ Branch 1 taken 44 times.
|
839 | if (sps->chroma_format_idc == 1) { |
| 368 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 748 times.
|
795 | if (sps->vui.common.chroma_loc_info_present_flag) { |
| 369 |
1/2✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
|
47 | if (sps->vui.common.chroma_sample_loc_type_top_field <= 5) |
| 370 | 47 | avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1; | |
| 371 | } else | ||
| 372 | 748 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; | |
| 373 | } | ||
| 374 | |||
| 375 |
2/2✓ Branch 0 taken 49 times.
✓ Branch 1 taken 790 times.
|
839 | if (vps->vps_timing_info_present_flag) { |
| 376 | 49 | num = vps->vps_num_units_in_tick; | |
| 377 | 49 | den = vps->vps_time_scale; | |
| 378 |
2/2✓ Branch 0 taken 125 times.
✓ Branch 1 taken 665 times.
|
790 | } else if (sps->vui.vui_timing_info_present_flag) { |
| 379 | 125 | num = sps->vui.vui_num_units_in_tick; | |
| 380 | 125 | den = sps->vui.vui_time_scale; | |
| 381 | } | ||
| 382 | |||
| 383 |
3/4✓ Branch 0 taken 174 times.
✓ Branch 1 taken 665 times.
✓ Branch 2 taken 174 times.
✗ Branch 3 not taken.
|
839 | if (num > 0 && den > 0) |
| 384 | 174 | av_reduce(&avctx->framerate.den, &avctx->framerate.num, | |
| 385 | num, den, 1 << 30); | ||
| 386 | 839 | } | |
| 387 | |||
| 388 | 11178 | static int export_stream_params_from_sei(HEVCContext *s) | |
| 389 | { | ||
| 390 | 11178 | AVCodecContext *avctx = s->avctx; | |
| 391 | |||
| 392 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 11178 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
11178 | if (s->sei.common.alternative_transfer.present && |
| 393 | ✗ | av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) && | |
| 394 | ✗ | s->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) { | |
| 395 | ✗ | avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics; | |
| 396 | } | ||
| 397 | |||
| 398 | 11178 | return 0; | |
| 399 | } | ||
| 400 | |||
| 401 | 611 | static int export_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
| 402 | { | ||
| 403 | 611 | const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi; | |
| 404 | |||
| 405 | 611 | av_freep(&s->view_ids_available); | |
| 406 | 611 | s->nb_view_ids_available = 0; | |
| 407 | 611 | av_freep(&s->view_pos_available); | |
| 408 | 611 | s->nb_view_pos_available = 0; | |
| 409 | |||
| 410 | // don't export anything in the trivial case (1 layer, view id=0) | ||
| 411 |
3/4✓ Branch 0 taken 588 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 588 times.
✗ Branch 3 not taken.
|
611 | if (vps->nb_layers < 2 && !vps->view_id[0]) |
| 412 | 588 | return 0; | |
| 413 | |||
| 414 | 23 | s->view_ids_available = av_calloc(vps->nb_layers, sizeof(*s->view_ids_available)); | |
| 415 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (!s->view_ids_available) |
| 416 | ✗ | return AVERROR(ENOMEM); | |
| 417 | |||
| 418 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 18 times.
|
23 | if (tdrdi->num_ref_displays) { |
| 419 | 5 | s->view_pos_available = av_calloc(vps->nb_layers, sizeof(*s->view_pos_available)); | |
| 420 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!s->view_pos_available) |
| 421 | ✗ | return AVERROR(ENOMEM); | |
| 422 | } | ||
| 423 | |||
| 424 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 23 times.
|
69 | for (int i = 0; i < vps->nb_layers; i++) { |
| 425 | 46 | s->view_ids_available[i] = vps->view_id[i]; | |
| 426 | |||
| 427 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 36 times.
|
46 | if (s->view_pos_available) { |
| 428 | 10 | s->view_pos_available[i] = vps->view_id[i] == tdrdi->left_view_id[0] ? | |
| 429 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
15 | AV_STEREO3D_VIEW_LEFT : |
| 430 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | vps->view_id[i] == tdrdi->right_view_id[0] ? |
| 431 | AV_STEREO3D_VIEW_RIGHT : AV_STEREO3D_VIEW_UNSPEC; | ||
| 432 | } | ||
| 433 | } | ||
| 434 | 23 | s->nb_view_ids_available = vps->nb_layers; | |
| 435 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 18 times.
|
23 | s->nb_view_pos_available = s->view_pos_available ? vps->nb_layers : 0; |
| 436 | |||
| 437 | 23 | return 0; | |
| 438 | } | ||
| 439 | |||
| 440 | 11932 | int ff_hevc_is_alpha_video(const HEVCContext *s) | |
| 441 | { | ||
| 442 | 11932 | const HEVCVPS *vps = s->vps; | |
| 443 | 11932 | int ret = 0; | |
| 444 | |||
| 445 |
3/4✓ Branch 0 taken 1590 times.
✓ Branch 1 taken 10342 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1590 times.
|
11932 | if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1]) |
| 446 | 10342 | return 0; | |
| 447 | |||
| 448 | /* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other | ||
| 449 | * than alpha cannot reach here. | ||
| 450 | */ | ||
| 451 | 1590 | ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY); | |
| 452 | |||
| 453 |
2/2✓ Branch 0 taken 203 times.
✓ Branch 1 taken 1387 times.
|
1590 | av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n", |
| 454 | ret ? "is" : "not"); | ||
| 455 | |||
| 456 | 1590 | return ret; | |
| 457 | } | ||
| 458 | |||
| 459 | 249 | int ff_hevc_requested_layers(const HEVCContext *s, const HEVCVPS *vps, | |
| 460 | unsigned *active_output) | ||
| 461 | { | ||
| 462 | 249 | unsigned layers_active_output = 0, highest_layer; | |
| 463 | |||
| 464 | // nothing requested - decode base layer only | ||
| 465 |
2/2✓ Branch 0 taken 238 times.
✓ Branch 1 taken 11 times.
|
249 | if (!s->nb_view_ids) { |
| 466 | 238 | *active_output = 1; | |
| 467 | 238 | return 1; | |
| 468 | } | ||
| 469 | |||
| 470 |
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) { |
| 471 | ✗ | layers_active_output = (1 << vps->nb_layers) - 1; | |
| 472 | } else { | ||
| 473 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 11 times.
|
30 | for (int i = 0; i < s->nb_view_ids; i++) { |
| 474 | 19 | int view_id = s->view_ids[i]; | |
| 475 | 19 | int layer_idx = -1; | |
| 476 | |||
| 477 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (view_id < 0) { |
| 478 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 479 | "Invalid view ID requested: %d\n", view_id); | ||
| 480 | ✗ | return AVERROR(EINVAL); | |
| 481 | } | ||
| 482 | |||
| 483 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | for (int j = 0; j < vps->nb_layers; j++) { |
| 484 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 9 times.
|
28 | if (vps->view_id[j] == view_id) { |
| 485 | 19 | layer_idx = j; | |
| 486 | 19 | break; | |
| 487 | } | ||
| 488 | } | ||
| 489 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (layer_idx < 0) { |
| 490 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 491 | "View ID %d not present in VPS\n", view_id); | ||
| 492 | ✗ | return AVERROR(EINVAL); | |
| 493 | } | ||
| 494 | 19 | layers_active_output |= 1 << layer_idx; | |
| 495 | } | ||
| 496 | } | ||
| 497 | |||
| 498 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (!layers_active_output) { |
| 499 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No layers selected\n"); | |
| 500 | ✗ | return AVERROR_BUG; | |
| 501 | } | ||
| 502 | |||
| 503 | 11 | highest_layer = ff_log2(layers_active_output); | |
| 504 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (highest_layer >= FF_ARRAY_ELEMS(s->layers)) { |
| 505 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 506 | "Too many layers requested: %u\n", layers_active_output); | ||
| 507 | ✗ | return AVERROR(EINVAL); | |
| 508 | } | ||
| 509 | |||
| 510 | 11 | *active_output = layers_active_output; | |
| 511 | |||
| 512 | /* Assume a higher layer depends on all the lower ones. | ||
| 513 | * This is enforced in VPS parsing currently, this logic will need | ||
| 514 | * to be changed if we want to support more complex dependency structures. | ||
| 515 | */ | ||
| 516 | 11 | return highest_layer + 1; | |
| 517 | } | ||
| 518 | |||
| 519 | 250 | static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
| 520 | { | ||
| 521 | unsigned layers_active_output; | ||
| 522 | int nb_decode_layers; | ||
| 523 | |||
| 524 | 250 | s->layers_active_output = 1; | |
| 525 | 250 | s->layers_active_decode = 1; | |
| 526 | |||
| 527 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 249 times.
|
250 | if (ff_hevc_is_alpha_video(s)) { |
| 528 | 1 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt); | |
| 529 | |||
| 530 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) |
| 531 | ✗ | return 0; | |
| 532 | |||
| 533 | 1 | s->layers_active_decode = (1 << vps->nb_layers) - 1; | |
| 534 | 1 | s->layers_active_output = 1; | |
| 535 | |||
| 536 | 1 | return 0; | |
| 537 | } | ||
| 538 | |||
| 539 | 249 | nb_decode_layers = ff_hevc_requested_layers(s, vps, &layers_active_output); | |
| 540 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 249 times.
|
249 | if (nb_decode_layers < 0) |
| 541 | ✗ | return nb_decode_layers; | |
| 542 | |||
| 543 | 249 | s->layers_active_decode = (1 << nb_decode_layers) - 1; | |
| 544 | 249 | s->layers_active_output = layers_active_output; | |
| 545 | |||
| 546 | 249 | av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n", | |
| 547 | s->layers_active_decode, s->layers_active_output); | ||
| 548 | |||
| 549 | 249 | return 0; | |
| 550 | } | ||
| 551 | |||
| 552 | 1 | static enum AVPixelFormat map_to_alpha_format(HEVCContext *s, | |
| 553 | enum AVPixelFormat pix_fmt) | ||
| 554 | { | ||
| 555 |
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) { |
| 556 | 1 | case AV_PIX_FMT_YUV420P: | |
| 557 | case AV_PIX_FMT_YUVJ420P: | ||
| 558 | 1 | return AV_PIX_FMT_YUVA420P; | |
| 559 | ✗ | case AV_PIX_FMT_YUV420P10: | |
| 560 | ✗ | return AV_PIX_FMT_YUVA420P10; | |
| 561 | ✗ | case AV_PIX_FMT_YUV444P: | |
| 562 | ✗ | return AV_PIX_FMT_YUVA444P; | |
| 563 | ✗ | case AV_PIX_FMT_YUV422P: | |
| 564 | ✗ | return AV_PIX_FMT_YUVA422P; | |
| 565 | ✗ | case AV_PIX_FMT_YUV422P10LE: | |
| 566 | ✗ | return AV_PIX_FMT_YUVA422P10LE; | |
| 567 | ✗ | case AV_PIX_FMT_YUV444P10: | |
| 568 | ✗ | return AV_PIX_FMT_YUVA444P10; | |
| 569 | ✗ | case AV_PIX_FMT_YUV444P12: | |
| 570 | ✗ | return AV_PIX_FMT_YUVA444P12; | |
| 571 | ✗ | case AV_PIX_FMT_YUV422P12: | |
| 572 | ✗ | return AV_PIX_FMT_YUVA422P12; | |
| 573 | ✗ | default: | |
| 574 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n", | |
| 575 | av_get_pix_fmt_name(pix_fmt)); | ||
| 576 | ✗ | return AV_PIX_FMT_NONE; | |
| 577 | } | ||
| 578 | } | ||
| 579 | |||
| 580 | 250 | static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) | |
| 581 | { | ||
| 582 | #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \ | ||
| 583 | CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \ | ||
| 584 | CONFIG_HEVC_D3D12VA_HWACCEL + \ | ||
| 585 | CONFIG_HEVC_NVDEC_HWACCEL + \ | ||
| 586 | CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL + \ | ||
| 587 | CONFIG_HEVC_VAAPI_HWACCEL + \ | ||
| 588 | CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \ | ||
| 589 | CONFIG_HEVC_VDPAU_HWACCEL + \ | ||
| 590 | CONFIG_HEVC_VULKAN_HWACCEL) | ||
| 591 | 250 | enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts; | |
| 592 | 250 | enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE; | |
| 593 | int ret; | ||
| 594 | |||
| 595 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 249 times.
|
250 | if (ff_hevc_is_alpha_video(s)) |
| 596 | 1 | alpha_fmt = map_to_alpha_format(s, sps->pix_fmt); | |
| 597 | |||
| 598 |
6/7✓ Branch 0 taken 205 times.
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
|
250 | switch (sps->pix_fmt) { |
| 599 | 205 | case AV_PIX_FMT_YUV420P: | |
| 600 | case AV_PIX_FMT_YUVJ420P: | ||
| 601 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
| 602 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
| 603 | #endif | ||
| 604 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
| 605 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
| 606 | *fmt++ = AV_PIX_FMT_D3D11; | ||
| 607 | #endif | ||
| 608 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
| 609 | *fmt++ = AV_PIX_FMT_D3D12; | ||
| 610 | #endif | ||
| 611 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
| 612 | 205 | *fmt++ = AV_PIX_FMT_VAAPI; | |
| 613 | #endif | ||
| 614 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
| 615 | 205 | *fmt++ = AV_PIX_FMT_VDPAU; | |
| 616 | #endif | ||
| 617 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
| 618 | *fmt++ = AV_PIX_FMT_CUDA; | ||
| 619 | #endif | ||
| 620 | #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL | ||
| 621 | *fmt++ = AV_PIX_FMT_CUARRAY; | ||
| 622 | #endif | ||
| 623 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
| 624 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
| 625 | #endif | ||
| 626 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
| 627 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
| 628 | #endif | ||
| 629 | 205 | break; | |
| 630 | 29 | case AV_PIX_FMT_YUV420P10: | |
| 631 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
| 632 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
| 633 | #endif | ||
| 634 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
| 635 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
| 636 | *fmt++ = AV_PIX_FMT_D3D11; | ||
| 637 | #endif | ||
| 638 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
| 639 | *fmt++ = AV_PIX_FMT_D3D12; | ||
| 640 | #endif | ||
| 641 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
| 642 | 29 | *fmt++ = AV_PIX_FMT_VAAPI; | |
| 643 | #endif | ||
| 644 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
| 645 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
| 646 | #endif | ||
| 647 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
| 648 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
| 649 | #endif | ||
| 650 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
| 651 | 29 | *fmt++ = AV_PIX_FMT_VDPAU; | |
| 652 | #endif | ||
| 653 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
| 654 | *fmt++ = AV_PIX_FMT_CUDA; | ||
| 655 | #endif | ||
| 656 | #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL | ||
| 657 | *fmt++ = AV_PIX_FMT_CUARRAY; | ||
| 658 | #endif | ||
| 659 | 29 | break; | |
| 660 | 2 | case AV_PIX_FMT_YUV444P: | |
| 661 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
| 662 | 2 | *fmt++ = AV_PIX_FMT_VAAPI; | |
| 663 | #endif | ||
| 664 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
| 665 | 2 | *fmt++ = AV_PIX_FMT_VDPAU; | |
| 666 | #endif | ||
| 667 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
| 668 | *fmt++ = AV_PIX_FMT_CUDA; | ||
| 669 | #endif | ||
| 670 | #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL | ||
| 671 | *fmt++ = AV_PIX_FMT_CUARRAY; | ||
| 672 | #endif | ||
| 673 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
| 674 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
| 675 | #endif | ||
| 676 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
| 677 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
| 678 | #endif | ||
| 679 | 2 | break; | |
| 680 | 7 | case AV_PIX_FMT_YUV422P: | |
| 681 | case AV_PIX_FMT_YUV422P10LE: | ||
| 682 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
| 683 | 7 | *fmt++ = AV_PIX_FMT_VAAPI; | |
| 684 | #endif | ||
| 685 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
| 686 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
| 687 | #endif | ||
| 688 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
| 689 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
| 690 | #endif | ||
| 691 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
| 692 | *fmt++ = AV_PIX_FMT_CUDA; | ||
| 693 | #endif | ||
| 694 | #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL | ||
| 695 | *fmt++ = AV_PIX_FMT_CUARRAY; | ||
| 696 | #endif | ||
| 697 | 7 | break; | |
| 698 | 6 | case AV_PIX_FMT_YUV444P10: | |
| 699 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
| 700 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
| 701 | #endif | ||
| 702 | av_fallthrough; | ||
| 703 | case AV_PIX_FMT_YUV420P12: | ||
| 704 | case AV_PIX_FMT_YUV444P12: | ||
| 705 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
| 706 | 6 | *fmt++ = AV_PIX_FMT_VAAPI; | |
| 707 | #endif | ||
| 708 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
| 709 | 6 | *fmt++ = AV_PIX_FMT_VDPAU; | |
| 710 | #endif | ||
| 711 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
| 712 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
| 713 | #endif | ||
| 714 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
| 715 | *fmt++ = AV_PIX_FMT_CUDA; | ||
| 716 | #endif | ||
| 717 | #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL | ||
| 718 | *fmt++ = AV_PIX_FMT_CUARRAY; | ||
| 719 | #endif | ||
| 720 | 6 | break; | |
| 721 | ✗ | case AV_PIX_FMT_YUV422P12: | |
| 722 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
| 723 | ✗ | *fmt++ = AV_PIX_FMT_VAAPI; | |
| 724 | #endif | ||
| 725 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
| 726 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
| 727 | #endif | ||
| 728 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
| 729 | *fmt++ = AV_PIX_FMT_CUDA; | ||
| 730 | #endif | ||
| 731 | #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL | ||
| 732 | *fmt++ = AV_PIX_FMT_CUARRAY; | ||
| 733 | #endif | ||
| 734 | ✗ | break; | |
| 735 | } | ||
| 736 | |||
| 737 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 249 times.
|
250 | if (alpha_fmt != AV_PIX_FMT_NONE) |
| 738 | 1 | *fmt++ = alpha_fmt; | |
| 739 | 250 | *fmt++ = sps->pix_fmt; | |
| 740 | 250 | *fmt = AV_PIX_FMT_NONE; | |
| 741 | |||
| 742 | // export multilayer information from active VPS to the caller, | ||
| 743 | // so it is available in get_format() | ||
| 744 | 250 | ret = export_multilayer(s, sps->vps); | |
| 745 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 250 times.
|
250 | if (ret < 0) |
| 746 | ✗ | return ret; | |
| 747 | |||
| 748 | 250 | ret = ff_get_format(s->avctx, pix_fmts); | |
| 749 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 250 times.
|
250 | if (ret < 0) |
| 750 | ✗ | return ret; | |
| 751 | 250 | s->avctx->pix_fmt = ret; | |
| 752 | |||
| 753 | // set up multilayer decoding, if requested by caller | ||
| 754 | 250 | ret = setup_multilayer(s, sps->vps); | |
| 755 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 250 times.
|
250 | if (ret < 0) |
| 756 | ✗ | return ret; | |
| 757 | |||
| 758 | 250 | return 0; | |
| 759 | } | ||
| 760 | |||
| 761 | 261 | static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) | |
| 762 | { | ||
| 763 | int ret; | ||
| 764 | |||
| 765 | 261 | pic_arrays_free(l); | |
| 766 | 261 | av_refstruct_unref(&l->sps); | |
| 767 | 261 | av_refstruct_unref(&s->vps); | |
| 768 | |||
| 769 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 261 times.
|
261 | if (!sps) |
| 770 | ✗ | return 0; | |
| 771 | |||
| 772 | 261 | ret = pic_arrays_init(l, sps); | |
| 773 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 261 times.
|
261 | if (ret < 0) |
| 774 | ✗ | goto fail; | |
| 775 | |||
| 776 | 261 | ff_hevc_pred_init(&s->hpc, sps->bit_depth); | |
| 777 | 261 | ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); | |
| 778 | 261 | ff_videodsp_init (&s->vdsp, sps->bit_depth); | |
| 779 | |||
| 780 | 261 | l->sps = av_refstruct_ref_c(sps); | |
| 781 | 261 | s->vps = av_refstruct_ref_c(sps->vps); | |
| 782 | |||
| 783 | 261 | return 0; | |
| 784 | |||
| 785 | ✗ | fail: | |
| 786 | ✗ | pic_arrays_free(l); | |
| 787 | ✗ | av_refstruct_unref(&l->sps); | |
| 788 | ✗ | return ret; | |
| 789 | } | ||
| 790 | |||
| 791 | 28667 | static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb) | |
| 792 | { | ||
| 793 | const HEVCPPS *pps; | ||
| 794 | const HEVCSPS *sps; | ||
| 795 | const HEVCVPS *vps; | ||
| 796 | unsigned pps_id; | ||
| 797 | int i, ret, layer_idx; | ||
| 798 | |||
| 799 | // Coded parameters | ||
| 800 | 28667 | sh->first_slice_in_pic_flag = get_bits1(gb); | |
| 801 | |||
| 802 | 28667 | sh->no_output_of_prior_pics_flag = 0; | |
| 803 |
3/4✓ Branch 0 taken 1068 times.
✓ Branch 1 taken 27599 times.
✓ Branch 2 taken 1068 times.
✗ Branch 3 not taken.
|
28667 | if (IS_IRAP(s)) |
| 804 | 1068 | sh->no_output_of_prior_pics_flag = get_bits1(gb); | |
| 805 | |||
| 806 | 28667 | pps_id = get_ue_golomb_long(gb); | |
| 807 |
2/4✓ Branch 0 taken 28667 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 28667 times.
|
28667 | if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) { |
| 808 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); | |
| 809 | ✗ | return AVERROR_INVALIDDATA; | |
| 810 | } | ||
| 811 |
3/4✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10671 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17996 times.
|
28667 | if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) { |
| 812 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); | |
| 813 | ✗ | return AVERROR_INVALIDDATA; | |
| 814 | } | ||
| 815 | 28667 | sh->pps_id = pps_id; | |
| 816 | |||
| 817 | 28667 | pps = s->ps.pps_list[pps_id]; | |
| 818 | 28667 | sps = pps->sps; | |
| 819 | 28667 | vps = sps->vps; | |
| 820 | 28667 | layer_idx = vps->layer_idx[s->nuh_layer_id]; | |
| 821 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28667 times.
|
28667 | if (layer_idx < 0) { |
| 822 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Layer %d is not in the VPS\n", s->nuh_layer_id); | |
| 823 | ✗ | return AVERROR_INVALIDDATA; | |
| 824 | } | ||
| 825 | |||
| 826 |
4/4✓ Branch 0 taken 502 times.
✓ Branch 1 taken 28165 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 491 times.
|
28667 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) |
| 827 | 11 | sh->no_output_of_prior_pics_flag = 1; | |
| 828 | |||
| 829 | 28667 | sh->dependent_slice_segment_flag = 0; | |
| 830 |
2/2✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10671 times.
|
28667 | if (!sh->first_slice_in_pic_flag) { |
| 831 | int slice_address_length; | ||
| 832 | |||
| 833 |
2/2✓ Branch 0 taken 8936 times.
✓ Branch 1 taken 9060 times.
|
17996 | if (pps->dependent_slice_segments_enabled_flag) |
| 834 | 8936 | sh->dependent_slice_segment_flag = get_bits1(gb); | |
| 835 |
3/4✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 10202 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7794 times.
|
17996 | if (sh->dependent_slice_segment_flag && !s->slice_initialized) { |
| 836 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); | |
| 837 | ✗ | return AVERROR_INVALIDDATA; | |
| 838 | } | ||
| 839 | |||
| 840 | 17996 | slice_address_length = av_ceil_log2(sps->ctb_width * | |
| 841 | 17996 | sps->ctb_height); | |
| 842 | 17996 | sh->slice_segment_addr = get_bitsz(gb, slice_address_length); | |
| 843 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17996 times.
|
17996 | if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) { |
| 844 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 845 | "Invalid slice segment address: %u.\n", | ||
| 846 | sh->slice_segment_addr); | ||
| 847 | ✗ | return AVERROR_INVALIDDATA; | |
| 848 | } | ||
| 849 | |||
| 850 |
2/2✓ Branch 0 taken 10202 times.
✓ Branch 1 taken 7794 times.
|
17996 | if (!sh->dependent_slice_segment_flag) { |
| 851 | 10202 | sh->slice_addr = sh->slice_segment_addr; | |
| 852 | } | ||
| 853 | } else { | ||
| 854 | 10671 | sh->slice_segment_addr = sh->slice_addr = 0; | |
| 855 | } | ||
| 856 | |||
| 857 |
2/2✓ Branch 0 taken 20873 times.
✓ Branch 1 taken 7794 times.
|
28667 | if (!sh->dependent_slice_segment_flag) { |
| 858 |
2/2✓ Branch 0 taken 1823 times.
✓ Branch 1 taken 20873 times.
|
22696 | for (i = 0; i < pps->num_extra_slice_header_bits; i++) |
| 859 | 1823 | skip_bits(gb, 1); // slice_reserved_undetermined_flag[] | |
| 860 | |||
| 861 | 20873 | sh->slice_type = get_ue_golomb_long(gb); | |
| 862 |
2/2✓ Branch 0 taken 19862 times.
✓ Branch 1 taken 1011 times.
|
20873 | if (!(sh->slice_type == HEVC_SLICE_I || |
| 863 |
2/2✓ Branch 0 taken 15427 times.
✓ Branch 1 taken 4435 times.
|
19862 | sh->slice_type == HEVC_SLICE_P || |
| 864 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15427 times.
|
15427 | sh->slice_type == HEVC_SLICE_B)) { |
| 865 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", | |
| 866 | ✗ | sh->slice_type); | |
| 867 | ✗ | return AVERROR_INVALIDDATA; | |
| 868 | } | ||
| 869 |
5/6✓ Branch 0 taken 832 times.
✓ Branch 1 taken 20041 times.
✓ Branch 2 taken 832 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 751 times.
|
20873 | if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I && |
| 870 |
1/2✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
|
81 | !pps->pps_curr_pic_ref_enabled_flag && |
| 871 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
|
81 | s->nuh_layer_id == 0) { |
| 872 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); | |
| 873 | ✗ | return AVERROR_INVALIDDATA; | |
| 874 | } | ||
| 875 | |||
| 876 | // when flag is not present, picture is inferred to be output | ||
| 877 | 20873 | sh->pic_output_flag = 1; | |
| 878 |
2/2✓ Branch 0 taken 700 times.
✓ Branch 1 taken 20173 times.
|
20873 | if (pps->output_flag_present_flag) |
| 879 | 700 | sh->pic_output_flag = get_bits1(gb); | |
| 880 | |||
| 881 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20873 times.
|
20873 | if (sps->separate_colour_plane) |
| 882 | ✗ | sh->colour_plane_id = get_bits(gb, 2); | |
| 883 | |||
| 884 |
4/4✓ Branch 0 taken 20524 times.
✓ Branch 1 taken 349 times.
✓ Branch 2 taken 46 times.
✓ Branch 3 taken 20478 times.
|
20873 | if (!IS_IDR(s) || |
| 885 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 377 times.
|
395 | (s->nuh_layer_id > 0 && |
| 886 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5 times.
|
18 | !(vps->poc_lsb_not_present & (1 << layer_idx)))) { |
| 887 | int poc; | ||
| 888 | |||
| 889 | 20491 | sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb); | |
| 890 | 20491 | poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type); | |
| 891 |
3/4✓ Branch 0 taken 10073 times.
✓ Branch 1 taken 10418 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10073 times.
|
20491 | if (!sh->first_slice_in_pic_flag && poc != sh->poc) { |
| 892 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
| 893 | "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc); | ||
| 894 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
| 895 | ✗ | return AVERROR_INVALIDDATA; | |
| 896 | ✗ | poc = sh->poc; | |
| 897 | } | ||
| 898 | 20491 | sh->poc = poc; | |
| 899 | } | ||
| 900 | |||
| 901 |
4/4✓ Branch 0 taken 20524 times.
✓ Branch 1 taken 349 times.
✓ Branch 2 taken 20478 times.
✓ Branch 3 taken 46 times.
|
41351 | if (!IS_IDR(s)) { |
| 902 | int pos; | ||
| 903 | |||
| 904 | 20478 | sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); | |
| 905 | 20478 | pos = get_bits_left(gb); | |
| 906 |
2/2✓ Branch 0 taken 4095 times.
✓ Branch 1 taken 16383 times.
|
20478 | if (!sh->short_term_ref_pic_set_sps_flag) { |
| 907 | 4095 | ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1); | |
| 908 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4095 times.
|
4095 | if (ret < 0) |
| 909 | ✗ | return ret; | |
| 910 | |||
| 911 | 4095 | sh->short_term_rps = &sh->slice_rps; | |
| 912 | } else { | ||
| 913 | int numbits, rps_idx; | ||
| 914 | |||
| 915 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16383 times.
|
16383 | if (!sps->nb_st_rps) { |
| 916 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); | |
| 917 | ✗ | return AVERROR_INVALIDDATA; | |
| 918 | } | ||
| 919 | |||
| 920 | 16383 | numbits = av_ceil_log2(sps->nb_st_rps); | |
| 921 |
2/2✓ Branch 0 taken 16355 times.
✓ Branch 1 taken 28 times.
|
16383 | rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; |
| 922 | 16383 | sh->short_term_rps = &sps->st_rps[rps_idx]; | |
| 923 | } | ||
| 924 | 20478 | sh->short_term_ref_pic_set_size = pos - get_bits_left(gb); | |
| 925 | |||
| 926 | 20478 | pos = get_bits_left(gb); | |
| 927 | 20478 | ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb); | |
| 928 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20478 times.
|
20478 | if (ret < 0) { |
| 929 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n"); | |
| 930 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
| 931 | ✗ | return AVERROR_INVALIDDATA; | |
| 932 | } | ||
| 933 | 20478 | sh->long_term_ref_pic_set_size = pos - get_bits_left(gb); | |
| 934 | |||
| 935 |
2/2✓ Branch 0 taken 17921 times.
✓ Branch 1 taken 2557 times.
|
20478 | if (sps->temporal_mvp_enabled) |
| 936 | 17921 | sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); | |
| 937 | else | ||
| 938 | 2557 | sh->slice_temporal_mvp_enabled_flag = 0; | |
| 939 | } else { | ||
| 940 | 395 | sh->poc = 0; | |
| 941 | 395 | sh->pic_order_cnt_lsb = 0; | |
| 942 | 395 | sh->short_term_ref_pic_set_sps_flag = 0; | |
| 943 | 395 | sh->short_term_ref_pic_set_size = 0; | |
| 944 | 395 | sh->short_term_rps = NULL; | |
| 945 | 395 | sh->long_term_ref_pic_set_size = 0; | |
| 946 | 395 | sh->long_term_rps.nb_refs = 0; | |
| 947 | 395 | sh->slice_temporal_mvp_enabled_flag = 0; | |
| 948 | } | ||
| 949 | |||
| 950 | 20873 | sh->inter_layer_pred = 0; | |
| 951 |
2/2✓ Branch 0 taken 516 times.
✓ Branch 1 taken 20357 times.
|
20873 | if (s->nuh_layer_id > 0) { |
| 952 | 516 | int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx]; | |
| 953 | |||
| 954 |
2/2✓ Branch 0 taken 418 times.
✓ Branch 1 taken 98 times.
|
516 | if (vps->default_ref_layers_active) |
| 955 | 418 | sh->inter_layer_pred = !!num_direct_ref_layers; | |
| 956 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 50 times.
|
98 | else if (num_direct_ref_layers) { |
| 957 | 48 | sh->inter_layer_pred = get_bits1(gb); | |
| 958 | |||
| 959 |
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) { |
| 960 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 961 | "NumDirectRefLayers>1 not supported\n"); | ||
| 962 | ✗ | return AVERROR_PATCHWELCOME; | |
| 963 | } | ||
| 964 | } | ||
| 965 | } | ||
| 966 | |||
| 967 |
2/2✓ Branch 0 taken 17307 times.
✓ Branch 1 taken 3566 times.
|
20873 | if (sps->sao_enabled) { |
| 968 | 17307 | sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); | |
| 969 |
2/2✓ Branch 0 taken 17306 times.
✓ Branch 1 taken 1 times.
|
17307 | if (sps->chroma_format_idc) { |
| 970 | 17306 | sh->slice_sample_adaptive_offset_flag[1] = | |
| 971 | 17306 | sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); | |
| 972 | } | ||
| 973 | } else { | ||
| 974 | 3566 | sh->slice_sample_adaptive_offset_flag[0] = 0; | |
| 975 | 3566 | sh->slice_sample_adaptive_offset_flag[1] = 0; | |
| 976 | 3566 | sh->slice_sample_adaptive_offset_flag[2] = 0; | |
| 977 | } | ||
| 978 | |||
| 979 | 20873 | sh->nb_refs[L0] = sh->nb_refs[L1] = 0; | |
| 980 |
4/4✓ Branch 0 taken 16438 times.
✓ Branch 1 taken 4435 times.
✓ Branch 2 taken 15427 times.
✓ Branch 3 taken 1011 times.
|
20873 | if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) { |
| 981 | int nb_refs; | ||
| 982 | |||
| 983 | 19862 | sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active; | |
| 984 |
2/2✓ Branch 0 taken 15427 times.
✓ Branch 1 taken 4435 times.
|
19862 | if (sh->slice_type == HEVC_SLICE_B) |
| 985 | 15427 | sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active; | |
| 986 | |||
| 987 |
2/2✓ Branch 1 taken 5551 times.
✓ Branch 2 taken 14311 times.
|
19862 | if (get_bits1(gb)) { // num_ref_idx_active_override_flag |
| 988 | 5551 | sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1; | |
| 989 |
2/2✓ Branch 0 taken 2881 times.
✓ Branch 1 taken 2670 times.
|
5551 | if (sh->slice_type == HEVC_SLICE_B) |
| 990 | 2881 | sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1; | |
| 991 | } | ||
| 992 |
2/4✓ Branch 0 taken 19862 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19862 times.
|
19862 | if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) { |
| 993 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n", | |
| 994 | sh->nb_refs[L0], sh->nb_refs[L1]); | ||
| 995 | ✗ | return AVERROR_INVALIDDATA; | |
| 996 | } | ||
| 997 | |||
| 998 | 19862 | sh->rpl_modification_flag[0] = 0; | |
| 999 | 19862 | sh->rpl_modification_flag[1] = 0; | |
| 1000 | 19862 | nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx); | |
| 1001 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19862 times.
|
19862 | if (!nb_refs) { |
| 1002 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); | |
| 1003 | ✗ | return AVERROR_INVALIDDATA; | |
| 1004 | } | ||
| 1005 | |||
| 1006 |
4/4✓ Branch 0 taken 2311 times.
✓ Branch 1 taken 17551 times.
✓ Branch 2 taken 1986 times.
✓ Branch 3 taken 325 times.
|
19862 | if (pps->lists_modification_present_flag && nb_refs > 1) { |
| 1007 | 1986 | sh->rpl_modification_flag[0] = get_bits1(gb); | |
| 1008 |
2/2✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 554 times.
|
1986 | if (sh->rpl_modification_flag[0]) { |
| 1009 |
2/2✓ Branch 0 taken 3366 times.
✓ Branch 1 taken 1432 times.
|
4798 | for (i = 0; i < sh->nb_refs[L0]; i++) |
| 1010 | 3366 | sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
| 1011 | } | ||
| 1012 | |||
| 1013 |
2/2✓ Branch 0 taken 1803 times.
✓ Branch 1 taken 183 times.
|
1986 | if (sh->slice_type == HEVC_SLICE_B) { |
| 1014 | 1803 | sh->rpl_modification_flag[1] = get_bits1(gb); | |
| 1015 |
2/2✓ Branch 0 taken 655 times.
✓ Branch 1 taken 1148 times.
|
1803 | if (sh->rpl_modification_flag[1] == 1) |
| 1016 |
2/2✓ Branch 0 taken 1558 times.
✓ Branch 1 taken 655 times.
|
2213 | for (i = 0; i < sh->nb_refs[L1]; i++) |
| 1017 | 1558 | sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
| 1018 | } | ||
| 1019 | } | ||
| 1020 | |||
| 1021 |
2/2✓ Branch 0 taken 15427 times.
✓ Branch 1 taken 4435 times.
|
19862 | if (sh->slice_type == HEVC_SLICE_B) |
| 1022 | 15427 | sh->mvd_l1_zero_flag = get_bits1(gb); | |
| 1023 | |||
| 1024 |
2/2✓ Branch 0 taken 16800 times.
✓ Branch 1 taken 3062 times.
|
19862 | if (pps->cabac_init_present_flag) |
| 1025 | 16800 | sh->cabac_init_flag = get_bits1(gb); | |
| 1026 | else | ||
| 1027 | 3062 | sh->cabac_init_flag = 0; | |
| 1028 | |||
| 1029 | 19862 | sh->collocated_ref_idx = 0; | |
| 1030 |
2/2✓ Branch 0 taken 17255 times.
✓ Branch 1 taken 2607 times.
|
19862 | if (sh->slice_temporal_mvp_enabled_flag) { |
| 1031 | 17255 | sh->collocated_list = L0; | |
| 1032 |
2/2✓ Branch 0 taken 14870 times.
✓ Branch 1 taken 2385 times.
|
17255 | if (sh->slice_type == HEVC_SLICE_B) |
| 1033 | 14870 | sh->collocated_list = !get_bits1(gb); | |
| 1034 | |||
| 1035 |
2/2✓ Branch 0 taken 15172 times.
✓ Branch 1 taken 2083 times.
|
17255 | if (sh->nb_refs[sh->collocated_list] > 1) { |
| 1036 | 15172 | sh->collocated_ref_idx = get_ue_golomb_long(gb); | |
| 1037 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15172 times.
|
15172 | if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { |
| 1038 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1039 | "Invalid collocated_ref_idx: %d.\n", | ||
| 1040 | sh->collocated_ref_idx); | ||
| 1041 | ✗ | return AVERROR_INVALIDDATA; | |
| 1042 | } | ||
| 1043 | } | ||
| 1044 | } | ||
| 1045 | |||
| 1046 |
4/4✓ Branch 0 taken 1559 times.
✓ Branch 1 taken 18303 times.
✓ Branch 2 taken 754 times.
✓ Branch 3 taken 805 times.
|
19862 | if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) || |
| 1047 |
3/4✓ Branch 0 taken 696 times.
✓ Branch 1 taken 18361 times.
✓ Branch 2 taken 696 times.
✗ Branch 3 not taken.
|
19057 | (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) { |
| 1048 | 1501 | ret = pred_weight_table(sh, s->avctx, sps, gb); | |
| 1049 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1501 times.
|
1501 | if (ret < 0) |
| 1050 | ✗ | return ret; | |
| 1051 | } | ||
| 1052 | |||
| 1053 | 19862 | sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb); | |
| 1054 |
2/4✓ Branch 0 taken 19862 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19862 times.
|
19862 | if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) { |
| 1055 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1056 | "Invalid number of merging MVP candidates: %d.\n", | ||
| 1057 | ✗ | sh->max_num_merge_cand); | |
| 1058 | ✗ | return AVERROR_INVALIDDATA; | |
| 1059 | } | ||
| 1060 | |||
| 1061 | // Syntax in 7.3.6.1 | ||
| 1062 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19862 times.
|
19862 | if (sps->motion_vector_resolution_control_idc == 2) |
| 1063 | ✗ | sh->use_integer_mv_flag = get_bits1(gb); | |
| 1064 | else | ||
| 1065 | // Inferred to be equal to motion_vector_resolution_control_idc if not present | ||
| 1066 | 19862 | sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc; | |
| 1067 | |||
| 1068 | } | ||
| 1069 | |||
| 1070 | 20873 | sh->slice_qp_delta = get_se_golomb(gb); | |
| 1071 | |||
| 1072 |
2/2✓ Branch 0 taken 260 times.
✓ Branch 1 taken 20613 times.
|
20873 | if (pps->pic_slice_level_chroma_qp_offsets_present_flag) { |
| 1073 | 260 | sh->slice_cb_qp_offset = get_se_golomb(gb); | |
| 1074 | 260 | sh->slice_cr_qp_offset = get_se_golomb(gb); | |
| 1075 |
2/4✓ Branch 0 taken 260 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 260 times.
✗ Branch 3 not taken.
|
260 | if (sh->slice_cb_qp_offset < -12 || sh->slice_cb_qp_offset > 12 || |
| 1076 |
2/4✓ Branch 0 taken 260 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 260 times.
|
260 | sh->slice_cr_qp_offset < -12 || sh->slice_cr_qp_offset > 12) { |
| 1077 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n"); | |
| 1078 | ✗ | return AVERROR_INVALIDDATA; | |
| 1079 | } | ||
| 1080 | } else { | ||
| 1081 | 20613 | sh->slice_cb_qp_offset = 0; | |
| 1082 | 20613 | sh->slice_cr_qp_offset = 0; | |
| 1083 | } | ||
| 1084 | |||
| 1085 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20873 times.
|
20873 | if (pps->pps_slice_act_qp_offsets_present_flag) { |
| 1086 | ✗ | sh->slice_act_y_qp_offset = get_se_golomb(gb); | |
| 1087 | ✗ | sh->slice_act_cb_qp_offset = get_se_golomb(gb); | |
| 1088 | ✗ | sh->slice_act_cr_qp_offset = get_se_golomb(gb); | |
| 1089 | } | ||
| 1090 | |||
| 1091 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 20832 times.
|
20873 | if (pps->chroma_qp_offset_list_enabled_flag) |
| 1092 | 41 | sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb); | |
| 1093 | else | ||
| 1094 | 20832 | sh->cu_chroma_qp_offset_enabled_flag = 0; | |
| 1095 | |||
| 1096 |
2/2✓ Branch 0 taken 3512 times.
✓ Branch 1 taken 17361 times.
|
20873 | if (pps->deblocking_filter_control_present_flag) { |
| 1097 | 3512 | int deblocking_filter_override_flag = 0; | |
| 1098 | |||
| 1099 |
2/2✓ Branch 0 taken 1097 times.
✓ Branch 1 taken 2415 times.
|
3512 | if (pps->deblocking_filter_override_enabled_flag) |
| 1100 | 1097 | deblocking_filter_override_flag = get_bits1(gb); | |
| 1101 | |||
| 1102 |
2/2✓ Branch 0 taken 506 times.
✓ Branch 1 taken 3006 times.
|
3512 | if (deblocking_filter_override_flag) { |
| 1103 | 506 | sh->disable_deblocking_filter_flag = get_bits1(gb); | |
| 1104 |
2/2✓ Branch 0 taken 349 times.
✓ Branch 1 taken 157 times.
|
506 | if (!sh->disable_deblocking_filter_flag) { |
| 1105 | 349 | int beta_offset_div2 = get_se_golomb(gb); | |
| 1106 | 349 | int tc_offset_div2 = get_se_golomb(gb) ; | |
| 1107 |
3/6✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
|
349 | if (beta_offset_div2 < -6 || beta_offset_div2 > 6 || |
| 1108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 349 times.
|
349 | tc_offset_div2 < -6 || tc_offset_div2 > 6) { |
| 1109 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1110 | "Invalid deblock filter offsets: %d, %d\n", | ||
| 1111 | beta_offset_div2, tc_offset_div2); | ||
| 1112 | ✗ | return AVERROR_INVALIDDATA; | |
| 1113 | } | ||
| 1114 | 349 | sh->beta_offset = beta_offset_div2 * 2; | |
| 1115 | 349 | sh->tc_offset = tc_offset_div2 * 2; | |
| 1116 | } | ||
| 1117 | } else { | ||
| 1118 | 3006 | sh->disable_deblocking_filter_flag = pps->disable_dbf; | |
| 1119 | 3006 | sh->beta_offset = pps->beta_offset; | |
| 1120 | 3006 | sh->tc_offset = pps->tc_offset; | |
| 1121 | } | ||
| 1122 | } else { | ||
| 1123 | 17361 | sh->disable_deblocking_filter_flag = 0; | |
| 1124 | 17361 | sh->beta_offset = 0; | |
| 1125 | 17361 | sh->tc_offset = 0; | |
| 1126 | } | ||
| 1127 | |||
| 1128 |
2/2✓ Branch 0 taken 18266 times.
✓ Branch 1 taken 2607 times.
|
20873 | if (pps->seq_loop_filter_across_slices_enabled_flag && |
| 1129 |
2/2✓ Branch 0 taken 11868 times.
✓ Branch 1 taken 6398 times.
|
18266 | (sh->slice_sample_adaptive_offset_flag[0] || |
| 1130 |
2/2✓ Branch 0 taken 11851 times.
✓ Branch 1 taken 17 times.
|
11868 | sh->slice_sample_adaptive_offset_flag[1] || |
| 1131 |
2/2✓ Branch 0 taken 11751 times.
✓ Branch 1 taken 100 times.
|
11851 | !sh->disable_deblocking_filter_flag)) { |
| 1132 | 18166 | sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); | |
| 1133 | } else { | ||
| 1134 | 2707 | sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag; | |
| 1135 | } | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | 28667 | sh->num_entry_point_offsets = 0; | |
| 1139 |
4/4✓ Branch 0 taken 25409 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 4834 times.
✓ Branch 3 taken 20575 times.
|
28667 | if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) { |
| 1140 | 8092 | unsigned num_entry_point_offsets = get_ue_golomb_long(gb); | |
| 1141 | // It would be possible to bound this tighter but this here is simpler | ||
| 1142 |
2/4✓ Branch 1 taken 8092 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8092 times.
|
8092 | if (num_entry_point_offsets > get_bits_left(gb) || num_entry_point_offsets > UINT16_MAX) { |
| 1143 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets); | |
| 1144 | ✗ | return AVERROR_INVALIDDATA; | |
| 1145 | } | ||
| 1146 | |||
| 1147 | 8092 | sh->num_entry_point_offsets = num_entry_point_offsets; | |
| 1148 |
2/2✓ Branch 0 taken 2341 times.
✓ Branch 1 taken 5751 times.
|
8092 | if (sh->num_entry_point_offsets > 0) { |
| 1149 | 2341 | int offset_len = get_ue_golomb_long(gb) + 1; | |
| 1150 | |||
| 1151 |
2/4✓ Branch 0 taken 2341 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2341 times.
|
2341 | if (offset_len < 1 || offset_len > 32) { |
| 1152 | ✗ | sh->num_entry_point_offsets = 0; | |
| 1153 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len); | |
| 1154 | ✗ | return AVERROR_INVALIDDATA; | |
| 1155 | } | ||
| 1156 | |||
| 1157 | 2341 | av_freep(&sh->entry_point_offset); | |
| 1158 | 2341 | av_freep(&sh->offset); | |
| 1159 | 2341 | av_freep(&sh->size); | |
| 1160 | 2341 | sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned)); | |
| 1161 | 2341 | sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
| 1162 | 2341 | sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
| 1163 |
3/6✓ Branch 0 taken 2341 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2341 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2341 times.
|
2341 | if (!sh->entry_point_offset || !sh->offset || !sh->size) { |
| 1164 | ✗ | sh->num_entry_point_offsets = 0; | |
| 1165 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n"); | |
| 1166 | ✗ | return AVERROR(ENOMEM); | |
| 1167 | } | ||
| 1168 |
2/2✓ Branch 0 taken 12499 times.
✓ Branch 1 taken 2341 times.
|
14840 | for (i = 0; i < sh->num_entry_point_offsets; i++) { |
| 1169 | 12499 | unsigned val = get_bits_long(gb, offset_len); | |
| 1170 | 12499 | sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size | |
| 1171 | } | ||
| 1172 | } | ||
| 1173 | } | ||
| 1174 | |||
| 1175 |
2/2✓ Branch 0 taken 2749 times.
✓ Branch 1 taken 25918 times.
|
28667 | if (pps->slice_header_extension_present_flag) { |
| 1176 | 2749 | unsigned int length = get_ue_golomb_long(gb); | |
| 1177 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2749 times.
|
2749 | if (length*8LL > get_bits_left(gb)) { |
| 1178 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n"); | |
| 1179 | ✗ | return AVERROR_INVALIDDATA; | |
| 1180 | } | ||
| 1181 |
2/2✓ Branch 0 taken 19903 times.
✓ Branch 1 taken 2749 times.
|
22652 | for (i = 0; i < length; i++) |
| 1182 | 19903 | skip_bits(gb, 8); // slice_header_extension_data_byte | |
| 1183 | } | ||
| 1184 | |||
| 1185 | 28667 | ret = get_bits1(gb); | |
| 1186 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28667 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
28667 | if (!ret && get_bits_left(gb) >= 0) { |
| 1187 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n"); | |
| 1188 | ✗ | return AVERROR_INVALIDDATA; | |
| 1189 | } | ||
| 1190 | 28667 | sh->data_offset = align_get_bits(gb) - gb->buffer; | |
| 1191 | |||
| 1192 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28667 times.
|
28667 | if (get_bits_left(gb) < 0) { |
| 1193 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1194 | ✗ | "Overread slice header by %d bits\n", -get_bits_left(gb)); | |
| 1195 | ✗ | return AVERROR_INVALIDDATA; | |
| 1196 | } | ||
| 1197 | |||
| 1198 | // Inferred parameters | ||
| 1199 | 28667 | sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta; | |
| 1200 |
1/2✓ Branch 0 taken 28667 times.
✗ Branch 1 not taken.
|
28667 | if (sh->slice_qp > 51 || |
| 1201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28667 times.
|
28667 | sh->slice_qp < -sps->qp_bd_offset) { |
| 1202 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1203 | "The slice_qp %d is outside the valid range " | ||
| 1204 | "[%d, 51].\n", | ||
| 1205 | ✗ | sh->slice_qp, | |
| 1206 | ✗ | -sps->qp_bd_offset); | |
| 1207 | ✗ | return AVERROR_INVALIDDATA; | |
| 1208 | } | ||
| 1209 | |||
| 1210 | 28667 | sh->slice_ctb_addr_rs = sh->slice_segment_addr; | |
| 1211 | |||
| 1212 |
2/2✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 20873 times.
|
28667 | if (sh->dependent_slice_segment_flag && |
| 1213 |
2/4✓ Branch 0 taken 7794 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7794 times.
|
7794 | (!sh->slice_ctb_addr_rs || !pps->ctb_addr_rs_to_ts[sh->slice_ctb_addr_rs])) { |
| 1214 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n"); | |
| 1215 | ✗ | return AVERROR_INVALIDDATA; | |
| 1216 | } | ||
| 1217 | |||
| 1218 | 28667 | return 0; | |
| 1219 | } | ||
| 1220 | |||
| 1221 | #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)]) | ||
| 1222 | |||
| 1223 | #define SET_SAO(elem, value) \ | ||
| 1224 | do { \ | ||
| 1225 | if (!sao_merge_up_flag && !sao_merge_left_flag) \ | ||
| 1226 | sao->elem = value; \ | ||
| 1227 | else if (sao_merge_left_flag) \ | ||
| 1228 | sao->elem = CTB(l->sao, rx-1, ry).elem; \ | ||
| 1229 | else if (sao_merge_up_flag) \ | ||
| 1230 | sao->elem = CTB(l->sao, rx, ry-1).elem; \ | ||
| 1231 | else \ | ||
| 1232 | sao->elem = 0; \ | ||
| 1233 | } while (0) | ||
| 1234 | |||
| 1235 | 1993954 | static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
| 1236 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1237 | int rx, int ry) | ||
| 1238 | { | ||
| 1239 | 1993954 | const HEVCContext *const s = lc->parent; | |
| 1240 | 1993954 | int sao_merge_left_flag = 0; | |
| 1241 | 1993954 | int sao_merge_up_flag = 0; | |
| 1242 | 1993954 | SAOParams *sao = &CTB(l->sao, rx, ry); | |
| 1243 | int c_idx, i; | ||
| 1244 | |||
| 1245 |
2/2✓ Branch 0 taken 913244 times.
✓ Branch 1 taken 1080710 times.
|
1993954 | if (s->sh.slice_sample_adaptive_offset_flag[0] || |
| 1246 |
2/2✓ Branch 0 taken 1540 times.
✓ Branch 1 taken 911704 times.
|
913244 | s->sh.slice_sample_adaptive_offset_flag[1]) { |
| 1247 |
2/2✓ Branch 0 taken 1040482 times.
✓ Branch 1 taken 41768 times.
|
1082250 | if (rx > 0) { |
| 1248 |
2/2✓ Branch 0 taken 1021463 times.
✓ Branch 1 taken 19019 times.
|
1040482 | if (lc->ctb_left_flag) |
| 1249 | 1021463 | sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc); | |
| 1250 | } | ||
| 1251 |
4/4✓ Branch 0 taken 1016391 times.
✓ Branch 1 taken 65859 times.
✓ Branch 2 taken 421766 times.
✓ Branch 3 taken 594625 times.
|
1082250 | if (ry > 0 && !sao_merge_left_flag) { |
| 1252 |
2/2✓ Branch 0 taken 408759 times.
✓ Branch 1 taken 13007 times.
|
421766 | if (lc->ctb_up_flag) |
| 1253 | 408759 | sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc); | |
| 1254 | } | ||
| 1255 | } | ||
| 1256 | |||
| 1257 |
4/4✓ Branch 0 taken 7975720 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 5981814 times.
✓ Branch 3 taken 1993954 times.
|
7975768 | for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) { |
| 1258 |
2/2✓ Branch 0 taken 1993954 times.
✓ Branch 1 taken 3987860 times.
|
5981814 | int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma : |
| 1259 | 3987860 | pps->log2_sao_offset_scale_chroma; | |
| 1260 | |||
| 1261 |
2/2✓ Branch 0 taken 3285548 times.
✓ Branch 1 taken 2696266 times.
|
5981814 | if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) { |
| 1262 | 3285548 | sao->type_idx[c_idx] = SAO_NOT_APPLIED; | |
| 1263 | 3285548 | continue; | |
| 1264 | } | ||
| 1265 | |||
| 1266 |
2/2✓ Branch 0 taken 807778 times.
✓ Branch 1 taken 1888488 times.
|
2696266 | if (c_idx == 2) { |
| 1267 | 807778 | sao->type_idx[2] = sao->type_idx[1]; | |
| 1268 | 807778 | sao->eo_class[2] = sao->eo_class[1]; | |
| 1269 | } else { | ||
| 1270 |
7/8✓ Branch 0 taken 1649043 times.
✓ Branch 1 taken 239445 times.
✓ Branch 2 taken 561205 times.
✓ Branch 3 taken 1087838 times.
✓ Branch 5 taken 1087838 times.
✓ Branch 6 taken 239445 times.
✓ Branch 7 taken 239445 times.
✗ Branch 8 not taken.
|
1888488 | SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(lc)); |
| 1271 | } | ||
| 1272 | |||
| 1273 |
2/2✓ Branch 0 taken 2009626 times.
✓ Branch 1 taken 686640 times.
|
2696266 | if (sao->type_idx[c_idx] == SAO_NOT_APPLIED) |
| 1274 | 2009626 | continue; | |
| 1275 | |||
| 1276 |
2/2✓ Branch 0 taken 2746560 times.
✓ Branch 1 taken 686640 times.
|
3433200 | for (i = 0; i < 4; i++) |
| 1277 |
7/8✓ Branch 0 taken 2251500 times.
✓ Branch 1 taken 495060 times.
✓ Branch 2 taken 875640 times.
✓ Branch 3 taken 1375860 times.
✓ Branch 5 taken 1375860 times.
✓ Branch 6 taken 495060 times.
✓ Branch 7 taken 495060 times.
✗ Branch 8 not taken.
|
2746560 | SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth)); |
| 1278 | |||
| 1279 |
2/2✓ Branch 0 taken 108424 times.
✓ Branch 1 taken 578216 times.
|
686640 | if (sao->type_idx[c_idx] == SAO_BAND) { |
| 1280 |
2/2✓ Branch 0 taken 433696 times.
✓ Branch 1 taken 108424 times.
|
542120 | for (i = 0; i < 4; i++) { |
| 1281 |
2/2✓ Branch 0 taken 323582 times.
✓ Branch 1 taken 110114 times.
|
433696 | if (sao->offset_abs[c_idx][i]) { |
| 1282 |
7/8✓ Branch 0 taken 300849 times.
✓ Branch 1 taken 22733 times.
✓ Branch 2 taken 223920 times.
✓ Branch 3 taken 76929 times.
✓ Branch 5 taken 76929 times.
✓ Branch 6 taken 22733 times.
✓ Branch 7 taken 22733 times.
✗ Branch 8 not taken.
|
323582 | SET_SAO(offset_sign[c_idx][i], |
| 1283 | ff_hevc_sao_offset_sign_decode(lc)); | ||
| 1284 | } else { | ||
| 1285 | 110114 | sao->offset_sign[c_idx][i] = 0; | |
| 1286 | } | ||
| 1287 | } | ||
| 1288 |
7/8✓ Branch 0 taken 99262 times.
✓ Branch 1 taken 9162 times.
✓ Branch 2 taken 72036 times.
✓ Branch 3 taken 27226 times.
✓ Branch 5 taken 27226 times.
✓ Branch 6 taken 9162 times.
✓ Branch 7 taken 9162 times.
✗ Branch 8 not taken.
|
108424 | SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(lc)); |
| 1289 |
2/2✓ Branch 0 taken 506073 times.
✓ Branch 1 taken 72143 times.
|
578216 | } else if (c_idx != 2) { |
| 1290 |
7/8✓ Branch 0 taken 405950 times.
✓ Branch 1 taken 100123 times.
✓ Branch 2 taken 119922 times.
✓ Branch 3 taken 286028 times.
✓ Branch 5 taken 286028 times.
✓ Branch 6 taken 100123 times.
✓ Branch 7 taken 100123 times.
✗ Branch 8 not taken.
|
506073 | SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(lc)); |
| 1291 | } | ||
| 1292 | |||
| 1293 | // Inferred parameters | ||
| 1294 | 686640 | sao->offset_val[c_idx][0] = 0; | |
| 1295 |
2/2✓ Branch 0 taken 2746560 times.
✓ Branch 1 taken 686640 times.
|
3433200 | for (i = 0; i < 4; i++) { |
| 1296 | 2746560 | sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i]; | |
| 1297 |
2/2✓ Branch 0 taken 2312864 times.
✓ Branch 1 taken 433696 times.
|
2746560 | if (sao->type_idx[c_idx] == SAO_EDGE) { |
| 1298 |
2/2✓ Branch 0 taken 1156432 times.
✓ Branch 1 taken 1156432 times.
|
2312864 | if (i > 1) |
| 1299 | 1156432 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
| 1300 |
2/2✓ Branch 0 taken 144543 times.
✓ Branch 1 taken 289153 times.
|
433696 | } else if (sao->offset_sign[c_idx][i]) { |
| 1301 | 144543 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
| 1302 | } | ||
| 1303 | 2746560 | sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale; | |
| 1304 | } | ||
| 1305 | } | ||
| 1306 | 1993954 | } | |
| 1307 | |||
| 1308 | #undef SET_SAO | ||
| 1309 | #undef CTB | ||
| 1310 | |||
| 1311 | 251428 | static int hls_cross_component_pred(HEVCLocalContext *lc, int idx) | |
| 1312 | { | ||
| 1313 | 251428 | int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx); | |
| 1314 | |||
| 1315 |
2/2✓ Branch 0 taken 142161 times.
✓ Branch 1 taken 109267 times.
|
251428 | if (log2_res_scale_abs_plus1 != 0) { |
| 1316 | 142161 | int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx); | |
| 1317 | 142161 | lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) * | |
| 1318 | 142161 | (1 - 2 * res_scale_sign_flag); | |
| 1319 | } else { | ||
| 1320 | 109267 | lc->tu.res_scale_val = 0; | |
| 1321 | } | ||
| 1322 | |||
| 1323 | |||
| 1324 | 251428 | return 0; | |
| 1325 | } | ||
| 1326 | |||
| 1327 | 15619248 | static int hls_transform_unit(HEVCLocalContext *lc, | |
| 1328 | const HEVCLayerContext *l, | ||
| 1329 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1330 | int x0, int y0, | ||
| 1331 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
| 1332 | int log2_cb_size, int log2_trafo_size, | ||
| 1333 | int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr) | ||
| 1334 | { | ||
| 1335 | 15619248 | const HEVCContext *const s = lc->parent; | |
| 1336 | 15619248 | const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1]; | |
| 1337 | int i; | ||
| 1338 | |||
| 1339 |
2/2✓ Branch 0 taken 8785712 times.
✓ Branch 1 taken 6833536 times.
|
15619248 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1340 | 8785712 | int trafo_size = 1 << log2_trafo_size; | |
| 1341 | 8785712 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size); | |
| 1342 | |||
| 1343 | 8785712 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0); | |
| 1344 | } | ||
| 1345 | |||
| 1346 |
6/6✓ Branch 0 taken 5743553 times.
✓ Branch 1 taken 9875695 times.
✓ Branch 2 taken 5096203 times.
✓ Branch 3 taken 647350 times.
✓ Branch 4 taken 4662257 times.
✓ Branch 5 taken 433946 times.
|
15619248 | if (cbf_luma || cbf_cb[0] || cbf_cr[0] || |
| 1347 |
6/6✓ Branch 0 taken 140838 times.
✓ Branch 1 taken 4521419 times.
✓ Branch 2 taken 133247 times.
✓ Branch 3 taken 7591 times.
✓ Branch 4 taken 51975 times.
✓ Branch 5 taken 81272 times.
|
15678813 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
| 1348 | 11016557 | int scan_idx = SCAN_DIAG; | |
| 1349 | 11016557 | int scan_idx_c = SCAN_DIAG; | |
| 1350 |
4/4✓ Branch 0 taken 7732318 times.
✓ Branch 1 taken 3284239 times.
✓ Branch 2 taken 6273055 times.
✓ Branch 3 taken 1459263 times.
|
17289612 | int cbf_chroma = cbf_cb[0] || cbf_cr[0] || |
| 1351 |
2/2✓ Branch 0 taken 196699 times.
✓ Branch 1 taken 6076356 times.
|
6273055 | (sps->chroma_format_idc == 2 && |
| 1352 |
4/4✓ Branch 0 taken 170962 times.
✓ Branch 1 taken 25737 times.
✓ Branch 2 taken 97068 times.
✓ Branch 3 taken 73894 times.
|
196699 | (cbf_cb[1] || cbf_cr[1])); |
| 1353 | |||
| 1354 |
4/4✓ Branch 0 taken 2714358 times.
✓ Branch 1 taken 8302199 times.
✓ Branch 2 taken 920252 times.
✓ Branch 3 taken 1794106 times.
|
11016557 | if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) { |
| 1355 | 920252 | lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc); | |
| 1356 |
2/2✓ Branch 0 taken 485048 times.
✓ Branch 1 taken 435204 times.
|
920252 | if (lc->tu.cu_qp_delta != 0) |
| 1357 |
2/2✓ Branch 1 taken 262087 times.
✓ Branch 2 taken 222961 times.
|
485048 | if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1) |
| 1358 | 262087 | lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta; | |
| 1359 | 920252 | lc->tu.is_cu_qp_delta_coded = 1; | |
| 1360 | |||
| 1361 |
2/2✓ Branch 0 taken 920251 times.
✓ Branch 1 taken 1 times.
|
920252 | if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) || |
| 1362 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 920251 times.
|
920251 | lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) { |
| 1363 | 1 | av_log(s->avctx, AV_LOG_ERROR, | |
| 1364 | "The cu_qp_delta %d is outside the valid range " | ||
| 1365 | "[%d, %d].\n", | ||
| 1366 | lc->tu.cu_qp_delta, | ||
| 1367 | 1 | -(26 + sps->qp_bd_offset / 2), | |
| 1368 | 1 | (25 + sps->qp_bd_offset / 2)); | |
| 1369 | 1 | return AVERROR_INVALIDDATA; | |
| 1370 | } | ||
| 1371 | |||
| 1372 | 920251 | ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size); | |
| 1373 | } | ||
| 1374 | |||
| 1375 |
4/4✓ Branch 0 taken 779607 times.
✓ Branch 1 taken 10236949 times.
✓ Branch 2 taken 730220 times.
✓ Branch 3 taken 49387 times.
|
11016556 | if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma && |
| 1376 |
3/4✓ Branch 0 taken 730220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 228078 times.
✓ Branch 3 taken 502142 times.
|
730220 | !lc->cu.cu_transquant_bypass_flag && !lc->tu.is_cu_chroma_qp_offset_coded) { |
| 1377 | 228078 | int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc); | |
| 1378 |
2/2✓ Branch 0 taken 35811 times.
✓ Branch 1 taken 192267 times.
|
228078 | if (cu_chroma_qp_offset_flag) { |
| 1379 | 35811 | int cu_chroma_qp_offset_idx = 0; | |
| 1380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35811 times.
|
35811 | if (pps->chroma_qp_offset_list_len_minus1 > 0) { |
| 1381 | ✗ | cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1); | |
| 1382 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1383 | "cu_chroma_qp_offset_idx not yet tested.\n"); | ||
| 1384 | } | ||
| 1385 | 35811 | lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx]; | |
| 1386 | 35811 | lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx]; | |
| 1387 | } else { | ||
| 1388 | 192267 | lc->tu.cu_qp_offset_cb = 0; | |
| 1389 | 192267 | lc->tu.cu_qp_offset_cr = 0; | |
| 1390 | } | ||
| 1391 | 228078 | lc->tu.is_cu_chroma_qp_offset_coded = 1; | |
| 1392 | } | ||
| 1393 | |||
| 1394 |
4/4✓ Branch 0 taken 6373189 times.
✓ Branch 1 taken 4643367 times.
✓ Branch 2 taken 5521157 times.
✓ Branch 3 taken 852032 times.
|
11016556 | if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) { |
| 1395 |
2/2✓ Branch 0 taken 3668307 times.
✓ Branch 1 taken 1852850 times.
|
5521157 | if (lc->tu.intra_pred_mode >= 6 && |
| 1396 |
2/2✓ Branch 0 taken 1275231 times.
✓ Branch 1 taken 2393076 times.
|
3668307 | lc->tu.intra_pred_mode <= 14) { |
| 1397 | 1275231 | scan_idx = SCAN_VERT; | |
| 1398 |
2/2✓ Branch 0 taken 1853474 times.
✓ Branch 1 taken 2392452 times.
|
4245926 | } else if (lc->tu.intra_pred_mode >= 22 && |
| 1399 |
2/2✓ Branch 0 taken 1564881 times.
✓ Branch 1 taken 288593 times.
|
1853474 | lc->tu.intra_pred_mode <= 30) { |
| 1400 | 1564881 | scan_idx = SCAN_HORIZ; | |
| 1401 | } | ||
| 1402 | |||
| 1403 |
2/2✓ Branch 0 taken 3325154 times.
✓ Branch 1 taken 2196003 times.
|
5521157 | if (lc->tu.intra_pred_mode_c >= 6 && |
| 1404 |
2/2✓ Branch 0 taken 1224177 times.
✓ Branch 1 taken 2100977 times.
|
3325154 | lc->tu.intra_pred_mode_c <= 14) { |
| 1405 | 1224177 | scan_idx_c = SCAN_VERT; | |
| 1406 |
2/2✓ Branch 0 taken 1764478 times.
✓ Branch 1 taken 2532502 times.
|
4296980 | } else if (lc->tu.intra_pred_mode_c >= 22 && |
| 1407 |
2/2✓ Branch 0 taken 1483713 times.
✓ Branch 1 taken 280765 times.
|
1764478 | lc->tu.intra_pred_mode_c <= 30) { |
| 1408 | 1483713 | scan_idx_c = SCAN_HORIZ; | |
| 1409 | } | ||
| 1410 | } | ||
| 1411 | |||
| 1412 | 11016556 | lc->tu.cross_pf = 0; | |
| 1413 | |||
| 1414 |
2/2✓ Branch 0 taken 9875694 times.
✓ Branch 1 taken 1140862 times.
|
11016556 | if (cbf_luma) |
| 1415 | 9875694 | ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0); | |
| 1416 |
6/6✓ Branch 0 taken 11016460 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 5616972 times.
✓ Branch 3 taken 5399488 times.
✓ Branch 4 taken 148785 times.
✓ Branch 5 taken 5468187 times.
|
16564829 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
| 1417 | 5548273 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
| 1418 | 5548273 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
| 1419 |
4/4✓ Branch 0 taken 246342 times.
✓ Branch 1 taken 5301931 times.
✓ Branch 2 taken 140024 times.
✓ Branch 3 taken 106318 times.
|
5688297 | lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma && |
| 1420 |
2/2✓ Branch 0 taken 91081 times.
✓ Branch 1 taken 48943 times.
|
140024 | (lc->cu.pred_mode == MODE_INTER || |
| 1421 |
2/2✓ Branch 0 taken 76771 times.
✓ Branch 1 taken 14310 times.
|
91081 | (lc->tu.chroma_mode_c == 4))); |
| 1422 | |||
| 1423 |
2/2✓ Branch 0 taken 125714 times.
✓ Branch 1 taken 5422559 times.
|
5548273 | if (lc->tu.cross_pf) { |
| 1424 | 125714 | hls_cross_component_pred(lc, 0); | |
| 1425 | } | ||
| 1426 |
4/4✓ Branch 0 taken 1078236 times.
✓ Branch 1 taken 10377722 times.
✓ Branch 2 taken 5907685 times.
✓ Branch 3 taken 5548273 times.
|
11455958 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
| 1427 |
2/2✓ Branch 0 taken 2643886 times.
✓ Branch 1 taken 3263799 times.
|
5907685 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1428 | 2643886 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
| 1429 | 2643886 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1430 | 2643886 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1); | |
| 1431 | } | ||
| 1432 |
2/2✓ Branch 0 taken 1450177 times.
✓ Branch 1 taken 4457508 times.
|
5907685 | if (cbf_cb[i]) |
| 1433 | 1450177 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
| 1434 | log2_trafo_size_c, scan_idx_c, 1); | ||
| 1435 | else | ||
| 1436 |
2/2✓ Branch 0 taken 27018 times.
✓ Branch 1 taken 4430490 times.
|
4457508 | if (lc->tu.cross_pf) { |
| 1437 | 27018 | ptrdiff_t stride = s->cur_frame->f->linesize[1]; | |
| 1438 | 27018 | int hshift = sps->hshift[1]; | |
| 1439 | 27018 | int vshift = sps->vshift[1]; | |
| 1440 | 27018 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
| 1441 | 27018 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
| 1442 | 27018 | int size = 1 << log2_trafo_size_c; | |
| 1443 | |||
| 1444 | 27018 | uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride + | |
| 1445 | 27018 | ((x0 >> hshift) << sps->pixel_shift)]; | |
| 1446 |
2/2✓ Branch 0 taken 1473408 times.
✓ Branch 1 taken 27018 times.
|
1500426 | for (i = 0; i < (size * size); i++) { |
| 1447 | 1473408 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
| 1448 | } | ||
| 1449 | 27018 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
| 1450 | } | ||
| 1451 | } | ||
| 1452 | |||
| 1453 |
2/2✓ Branch 0 taken 125714 times.
✓ Branch 1 taken 5422559 times.
|
5548273 | if (lc->tu.cross_pf) { |
| 1454 | 125714 | hls_cross_component_pred(lc, 1); | |
| 1455 | } | ||
| 1456 |
4/4✓ Branch 0 taken 1078236 times.
✓ Branch 1 taken 10377722 times.
✓ Branch 2 taken 5907685 times.
✓ Branch 3 taken 5548273 times.
|
11455958 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
| 1457 |
2/2✓ Branch 0 taken 2643886 times.
✓ Branch 1 taken 3263799 times.
|
5907685 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1458 | 2643886 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
| 1459 | 2643886 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1460 | 2643886 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2); | |
| 1461 | } | ||
| 1462 |
2/2✓ Branch 0 taken 1520468 times.
✓ Branch 1 taken 4387217 times.
|
5907685 | if (cbf_cr[i]) |
| 1463 | 1520468 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
| 1464 | log2_trafo_size_c, scan_idx_c, 2); | ||
| 1465 | else | ||
| 1466 |
2/2✓ Branch 0 taken 52981 times.
✓ Branch 1 taken 4334236 times.
|
4387217 | if (lc->tu.cross_pf) { |
| 1467 | 52981 | ptrdiff_t stride = s->cur_frame->f->linesize[2]; | |
| 1468 | 52981 | int hshift = sps->hshift[2]; | |
| 1469 | 52981 | int vshift = sps->vshift[2]; | |
| 1470 | 52981 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
| 1471 | 52981 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
| 1472 | 52981 | int size = 1 << log2_trafo_size_c; | |
| 1473 | |||
| 1474 | 52981 | uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride + | |
| 1475 | 52981 | ((x0 >> hshift) << sps->pixel_shift)]; | |
| 1476 |
2/2✓ Branch 0 taken 2927920 times.
✓ Branch 1 taken 52981 times.
|
2980901 | for (i = 0; i < (size * size); i++) { |
| 1477 | 2927920 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
| 1478 | } | ||
| 1479 | 52981 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
| 1480 | } | ||
| 1481 | } | ||
| 1482 |
4/4✓ Branch 0 taken 5468187 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 1405734 times.
✓ Branch 3 taken 4062453 times.
|
5468283 | } else if (sps->chroma_format_idc && blk_idx == 3) { |
| 1483 | 1405734 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
| 1484 | 1405734 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
| 1485 |
4/4✓ Branch 0 taken 412647 times.
✓ Branch 1 taken 2536370 times.
✓ Branch 2 taken 1543283 times.
✓ Branch 3 taken 1405734 times.
|
2949017 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
| 1486 |
2/2✓ Branch 0 taken 1040057 times.
✓ Branch 1 taken 503226 times.
|
1543283 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1487 | 1040057 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
| 1488 | 1040057 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1489 | 1040057 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1); | |
| 1490 | } | ||
| 1491 |
2/2✓ Branch 0 taken 537411 times.
✓ Branch 1 taken 1005872 times.
|
1543283 | if (cbf_cb[i]) |
| 1492 | 537411 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
| 1493 | log2_trafo_size, scan_idx_c, 1); | ||
| 1494 | } | ||
| 1495 |
4/4✓ Branch 0 taken 412647 times.
✓ Branch 1 taken 2536370 times.
✓ Branch 2 taken 1543283 times.
✓ Branch 3 taken 1405734 times.
|
2949017 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
| 1496 |
2/2✓ Branch 0 taken 1040057 times.
✓ Branch 1 taken 503226 times.
|
1543283 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1497 | 1040057 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
| 1498 | 1040057 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1499 | 1040057 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2); | |
| 1500 | } | ||
| 1501 |
2/2✓ Branch 0 taken 625006 times.
✓ Branch 1 taken 918277 times.
|
1543283 | if (cbf_cr[i]) |
| 1502 | 625006 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
| 1503 | log2_trafo_size, scan_idx_c, 2); | ||
| 1504 | } | ||
| 1505 | } | ||
| 1506 |
3/4✓ Branch 0 taken 4602691 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2412522 times.
✓ Branch 3 taken 2190169 times.
|
4602691 | } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) { |
| 1507 |
4/4✓ Branch 0 taken 1458459 times.
✓ Branch 1 taken 954063 times.
✓ Branch 2 taken 46806 times.
✓ Branch 3 taken 1411653 times.
|
3413391 | if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) { |
| 1508 | 1000869 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
| 1509 | 1000869 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
| 1510 | 1000869 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v, | |
| 1511 | 1000869 | sps->log2_ctb_size); | |
| 1512 | 1000869 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1); | |
| 1513 | 1000869 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2); | |
| 1514 |
2/2✓ Branch 0 taken 7467 times.
✓ Branch 1 taken 993402 times.
|
1000869 | if (sps->chroma_format_idc == 2) { |
| 1515 | 7467 | ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c), | |
| 1516 | 7467 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1517 | 7467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1); | |
| 1518 | 7467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2); | |
| 1519 | } | ||
| 1520 |
2/2✓ Branch 0 taken 319986 times.
✓ Branch 1 taken 1091667 times.
|
1411653 | } else if (blk_idx == 3) { |
| 1521 | 319986 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
| 1522 | 319986 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
| 1523 | 319986 | ff_hevc_set_neighbour_available(lc, xBase, yBase, | |
| 1524 | 319986 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1525 | 319986 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1); | |
| 1526 | 319986 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2); | |
| 1527 |
2/2✓ Branch 0 taken 2373 times.
✓ Branch 1 taken 317613 times.
|
319986 | if (sps->chroma_format_idc == 2) { |
| 1528 | 2373 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size), | |
| 1529 | 2373 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1530 | 2373 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1); | |
| 1531 | 2373 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2); | |
| 1532 | } | ||
| 1533 | } | ||
| 1534 | } | ||
| 1535 | |||
| 1536 | 15619247 | return 0; | |
| 1537 | } | ||
| 1538 | |||
| 1539 | 339768 | static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps, | |
| 1540 | int x0, int y0, int log2_cb_size) | ||
| 1541 | { | ||
| 1542 | 339768 | int cb_size = 1 << log2_cb_size; | |
| 1543 | 339768 | int log2_min_pu_size = sps->log2_min_pu_size; | |
| 1544 | |||
| 1545 | 339768 | int min_pu_width = sps->min_pu_width; | |
| 1546 | 339768 | int x_end = FFMIN(x0 + cb_size, sps->width); | |
| 1547 | 339768 | int y_end = FFMIN(y0 + cb_size, sps->height); | |
| 1548 | int i, j; | ||
| 1549 | |||
| 1550 |
2/2✓ Branch 0 taken 485180 times.
✓ Branch 1 taken 339768 times.
|
824948 | for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++) |
| 1551 |
2/2✓ Branch 0 taken 964500 times.
✓ Branch 1 taken 485180 times.
|
1449680 | for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++) |
| 1552 | 964500 | is_pcm[i + j * min_pu_width] = 2; | |
| 1553 | 339768 | } | |
| 1554 | |||
| 1555 | 18751005 | static int hls_transform_tree(HEVCLocalContext *lc, | |
| 1556 | const HEVCLayerContext *l, | ||
| 1557 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1558 | int x0, int y0, | ||
| 1559 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
| 1560 | int log2_cb_size, int log2_trafo_size, | ||
| 1561 | int trafo_depth, int blk_idx, | ||
| 1562 | const int *base_cbf_cb, const int *base_cbf_cr) | ||
| 1563 | { | ||
| 1564 | 18751005 | const HEVCContext *const s = lc->parent; | |
| 1565 | uint8_t split_transform_flag; | ||
| 1566 | int cbf_cb[2]; | ||
| 1567 | int cbf_cr[2]; | ||
| 1568 | int ret; | ||
| 1569 | |||
| 1570 | 18751005 | cbf_cb[0] = base_cbf_cb[0]; | |
| 1571 | 18751005 | cbf_cb[1] = base_cbf_cb[1]; | |
| 1572 | 18751005 | cbf_cr[0] = base_cbf_cr[0]; | |
| 1573 | 18751005 | cbf_cr[1] = base_cbf_cr[1]; | |
| 1574 | |||
| 1575 |
2/2✓ Branch 0 taken 5600456 times.
✓ Branch 1 taken 13150549 times.
|
18751005 | if (lc->cu.intra_split_flag) { |
| 1576 |
2/2✓ Branch 0 taken 4198400 times.
✓ Branch 1 taken 1402056 times.
|
5600456 | if (trafo_depth == 1) { |
| 1577 | 4198400 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx]; | |
| 1578 |
2/2✓ Branch 0 taken 74576 times.
✓ Branch 1 taken 4123824 times.
|
4198400 | if (sps->chroma_format_idc == 3) { |
| 1579 | 74576 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx]; | |
| 1580 | 74576 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx]; | |
| 1581 | } else { | ||
| 1582 | 4123824 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
| 1583 | 4123824 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
| 1584 | } | ||
| 1585 | } | ||
| 1586 | } else { | ||
| 1587 | 13150549 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0]; | |
| 1588 | 13150549 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
| 1589 | 13150549 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
| 1590 | } | ||
| 1591 | |||
| 1592 |
2/2✓ Branch 0 taken 18631833 times.
✓ Branch 1 taken 119172 times.
|
18751005 | if (log2_trafo_size <= sps->log2_max_trafo_size && |
| 1593 |
2/2✓ Branch 0 taken 10485125 times.
✓ Branch 1 taken 8146708 times.
|
18631833 | log2_trafo_size > sps->log2_min_tb_size && |
| 1594 |
2/2✓ Branch 0 taken 7973548 times.
✓ Branch 1 taken 2511577 times.
|
10485125 | trafo_depth < lc->cu.max_trafo_depth && |
| 1595 |
4/4✓ Branch 0 taken 1514405 times.
✓ Branch 1 taken 6459143 times.
✓ Branch 2 taken 469616 times.
✓ Branch 3 taken 1044789 times.
|
7973548 | !(lc->cu.intra_split_flag && trafo_depth == 0)) { |
| 1596 | 6928759 | split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size); | |
| 1597 | } else { | ||
| 1598 | 25995143 | int inter_split = sps->max_transform_hierarchy_depth_inter == 0 && | |
| 1599 |
2/2✓ Branch 0 taken 1554001 times.
✓ Branch 1 taken 796650 times.
|
2350651 | lc->cu.pred_mode == MODE_INTER && |
| 1600 |
6/6✓ Branch 0 taken 2350651 times.
✓ Branch 1 taken 9471595 times.
✓ Branch 2 taken 930859 times.
✓ Branch 3 taken 623142 times.
✓ Branch 4 taken 184863 times.
✓ Branch 5 taken 745996 times.
|
14172897 | lc->cu.part_mode != PART_2Nx2N && |
| 1601 | trafo_depth == 0; | ||
| 1602 | |||
| 1603 | 11822246 | split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size || | |
| 1604 |
8/8✓ Branch 0 taken 11703074 times.
✓ Branch 1 taken 119172 times.
✓ Branch 2 taken 5125637 times.
✓ Branch 3 taken 6577437 times.
✓ Branch 4 taken 4080848 times.
✓ Branch 5 taken 1044789 times.
✓ Branch 6 taken 169700 times.
✓ Branch 7 taken 10488585 times.
|
11822246 | (lc->cu.intra_split_flag && trafo_depth == 0) || |
| 1605 | inter_split; | ||
| 1606 | } | ||
| 1607 | |||
| 1608 |
6/6✓ Branch 0 taken 18750909 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 8060212 times.
✓ Branch 3 taken 10690697 times.
✓ Branch 4 taken 239856 times.
✓ Branch 5 taken 7820356 times.
|
18751005 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
| 1609 |
4/4✓ Branch 0 taken 4706672 times.
✓ Branch 1 taken 6223881 times.
✓ Branch 2 taken 1173700 times.
✓ Branch 3 taken 3532972 times.
|
10930553 | if (trafo_depth == 0 || cbf_cb[0]) { |
| 1610 | 7397581 | cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
| 1611 |
6/6✓ Branch 0 taken 458668 times.
✓ Branch 1 taken 6938913 times.
✓ Branch 2 taken 170236 times.
✓ Branch 3 taken 288432 times.
✓ Branch 4 taken 108956 times.
✓ Branch 5 taken 61280 times.
|
7397581 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
| 1612 | 397388 | cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
| 1613 | } | ||
| 1614 | } | ||
| 1615 | |||
| 1616 |
4/4✓ Branch 0 taken 4706672 times.
✓ Branch 1 taken 6223881 times.
✓ Branch 2 taken 1102716 times.
✓ Branch 3 taken 3603956 times.
|
10930553 | if (trafo_depth == 0 || cbf_cr[0]) { |
| 1617 | 7326597 | cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
| 1618 |
6/6✓ Branch 0 taken 605644 times.
✓ Branch 1 taken 6720953 times.
✓ Branch 2 taken 217952 times.
✓ Branch 3 taken 387692 times.
✓ Branch 4 taken 144600 times.
✓ Branch 5 taken 73352 times.
|
7326597 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
| 1619 | 532292 | cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
| 1620 | } | ||
| 1621 | } | ||
| 1622 | } | ||
| 1623 | |||
| 1624 |
2/2✓ Branch 0 taken 3131757 times.
✓ Branch 1 taken 15619248 times.
|
18751005 | if (split_transform_flag) { |
| 1625 | 3131757 | const int trafo_size_split = 1 << (log2_trafo_size - 1); | |
| 1626 | 3131757 | const int x1 = x0 + trafo_size_split; | |
| 1627 | 3131757 | const int y1 = y0 + trafo_size_split; | |
| 1628 | |||
| 1629 | #define SUBDIVIDE(x, y, idx) \ | ||
| 1630 | do { \ | ||
| 1631 | ret = hls_transform_tree(lc, l, pps, sps, \ | ||
| 1632 | x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \ | ||
| 1633 | log2_trafo_size - 1, trafo_depth + 1, idx, \ | ||
| 1634 | cbf_cb, cbf_cr); \ | ||
| 1635 | if (ret < 0) \ | ||
| 1636 | return ret; \ | ||
| 1637 | } while (0) | ||
| 1638 | |||
| 1639 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3131757 times.
|
3131757 | SUBDIVIDE(x0, y0, 0); |
| 1640 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3131757 times.
|
3131757 | SUBDIVIDE(x1, y0, 1); |
| 1641 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3131757 times.
|
3131757 | SUBDIVIDE(x0, y1, 2); |
| 1642 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3131757 times.
|
3131757 | SUBDIVIDE(x1, y1, 3); |
| 1643 | |||
| 1644 | #undef SUBDIVIDE | ||
| 1645 | } else { | ||
| 1646 | 15619248 | int min_tu_size = 1 << sps->log2_min_tb_size; | |
| 1647 | 15619248 | int log2_min_tu_size = sps->log2_min_tb_size; | |
| 1648 | 15619248 | int min_tu_width = sps->min_tb_width; | |
| 1649 | 15619248 | int cbf_luma = 1; | |
| 1650 | |||
| 1651 |
4/4✓ Branch 0 taken 6833536 times.
✓ Branch 1 taken 8785712 times.
✓ Branch 2 taken 1601800 times.
✓ Branch 3 taken 5231736 times.
|
15619248 | if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 || |
| 1652 |
4/4✓ Branch 0 taken 1268507 times.
✓ Branch 1 taken 333293 times.
✓ Branch 2 taken 1100833 times.
✓ Branch 3 taken 167674 times.
|
1601800 | cbf_cb[0] || cbf_cr[0] || |
| 1653 |
6/6✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 1076157 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
|
1100833 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
| 1654 | 14531061 | cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth); | |
| 1655 | } | ||
| 1656 | |||
| 1657 | 15619248 | ret = hls_transform_unit(lc, l, pps, sps, | |
| 1658 | x0, y0, xBase, yBase, cb_xBase, cb_yBase, | ||
| 1659 | log2_cb_size, log2_trafo_size, | ||
| 1660 | blk_idx, cbf_luma, cbf_cb, cbf_cr); | ||
| 1661 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15619247 times.
|
15619248 | if (ret < 0) |
| 1662 | 1 | return ret; | |
| 1663 | // TODO: store cbf_luma somewhere else | ||
| 1664 |
2/2✓ Branch 0 taken 9875694 times.
✓ Branch 1 taken 5743553 times.
|
15619247 | if (cbf_luma) { |
| 1665 | int i, j; | ||
| 1666 |
2/2✓ Branch 0 taken 22373471 times.
✓ Branch 1 taken 9875694 times.
|
32249165 | for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size) |
| 1667 |
2/2✓ Branch 0 taken 88256787 times.
✓ Branch 1 taken 22373471 times.
|
110630258 | for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) { |
| 1668 | 88256787 | int x_tu = (x0 + j) >> log2_min_tu_size; | |
| 1669 | 88256787 | int y_tu = (y0 + i) >> log2_min_tu_size; | |
| 1670 | 88256787 | l->cbf_luma[y_tu * min_tu_width + x_tu] = 1; | |
| 1671 | } | ||
| 1672 | } | ||
| 1673 |
2/2✓ Branch 0 taken 15115683 times.
✓ Branch 1 taken 503564 times.
|
15619247 | if (!s->sh.disable_deblocking_filter_flag) { |
| 1674 | 15115683 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size); | |
| 1675 |
2/2✓ Branch 0 taken 319726 times.
✓ Branch 1 taken 14795957 times.
|
15115683 | if (pps->transquant_bypass_enable_flag && |
| 1676 |
2/2✓ Branch 0 taken 260054 times.
✓ Branch 1 taken 59672 times.
|
319726 | lc->cu.cu_transquant_bypass_flag) |
| 1677 | 260054 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size); | |
| 1678 | } | ||
| 1679 | } | ||
| 1680 | 18751004 | return 0; | |
| 1681 | } | ||
| 1682 | |||
| 1683 | 11207 | static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
| 1684 | const HEVCPPS *pps, int x0, int y0, int log2_cb_size) | ||
| 1685 | { | ||
| 1686 | 11207 | const HEVCContext *const s = lc->parent; | |
| 1687 | 11207 | const HEVCSPS *const sps = pps->sps; | |
| 1688 | GetBitContext gb; | ||
| 1689 | 11207 | int cb_size = 1 << log2_cb_size; | |
| 1690 | 11207 | ptrdiff_t stride0 = s->cur_frame->f->linesize[0]; | |
| 1691 | 11207 | uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)]; | |
| 1692 | |||
| 1693 | 22414 | int length = cb_size * cb_size * sps->pcm.bit_depth + (sps->chroma_format_idc != 0 ? | |
| 1694 | 11207 | (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) + | |
| 1695 | 11207 | ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) * | |
| 1696 |
1/2✓ Branch 0 taken 11207 times.
✗ Branch 1 not taken.
|
11207 | sps->pcm.bit_depth_chroma : 0); |
| 1697 | 11207 | const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3); | |
| 1698 | int ret; | ||
| 1699 | |||
| 1700 |
2/2✓ Branch 0 taken 6041 times.
✓ Branch 1 taken 5166 times.
|
11207 | if (!s->sh.disable_deblocking_filter_flag) |
| 1701 | 6041 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
| 1702 | |||
| 1703 | 11207 | ret = init_get_bits(&gb, pcm, length); | |
| 1704 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11207 times.
|
11207 | if (ret < 0) |
| 1705 | ✗ | return ret; | |
| 1706 | |||
| 1707 | 11207 | s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth); | |
| 1708 |
1/2✓ Branch 0 taken 11207 times.
✗ Branch 1 not taken.
|
11207 | if (sps->chroma_format_idc) { |
| 1709 | 11207 | ptrdiff_t stride1 = s->cur_frame->f->linesize[1]; | |
| 1710 | 11207 | ptrdiff_t stride2 = s->cur_frame->f->linesize[2]; | |
| 1711 | 11207 | uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)]; | |
| 1712 | 11207 | uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)]; | |
| 1713 | |||
| 1714 | 11207 | s->hevcdsp.put_pcm(dst1, stride1, | |
| 1715 | 11207 | cb_size >> sps->hshift[1], | |
| 1716 | 11207 | cb_size >> sps->vshift[1], | |
| 1717 | 11207 | &gb, sps->pcm.bit_depth_chroma); | |
| 1718 | 11207 | s->hevcdsp.put_pcm(dst2, stride2, | |
| 1719 | 11207 | cb_size >> sps->hshift[2], | |
| 1720 | 11207 | cb_size >> sps->vshift[2], | |
| 1721 | 11207 | &gb, sps->pcm.bit_depth_chroma); | |
| 1722 | } | ||
| 1723 | |||
| 1724 | 11207 | return 0; | |
| 1725 | } | ||
| 1726 | |||
| 1727 | /** | ||
| 1728 | * 8.5.3.2.2.1 Luma sample unidirectional interpolation process | ||
| 1729 | * | ||
| 1730 | * @param s HEVC decoding context | ||
| 1731 | * @param dst target buffer for block data at block position | ||
| 1732 | * @param dststride stride of the dst buffer | ||
| 1733 | * @param ref reference picture buffer at origin (0, 0) | ||
| 1734 | * @param mv motion vector (relative to block position) to get pixel data from | ||
| 1735 | * @param x_off horizontal position of block from origin (0, 0) | ||
| 1736 | * @param y_off vertical position of block from origin (0, 0) | ||
| 1737 | * @param block_w width of block | ||
| 1738 | * @param block_h height of block | ||
| 1739 | * @param luma_weight weighting factor applied to the luma prediction | ||
| 1740 | * @param luma_offset additive offset applied to the luma prediction value | ||
| 1741 | */ | ||
| 1742 | |||
| 1743 | 6593619 | static void luma_mc_uni(HEVCLocalContext *lc, | |
| 1744 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1745 | uint8_t *dst, ptrdiff_t dststride, | ||
| 1746 | const AVFrame *ref, const Mv *mv, int x_off, int y_off, | ||
| 1747 | int block_w, int block_h, int luma_weight, int luma_offset) | ||
| 1748 | { | ||
| 1749 | 6593619 | const HEVCContext *const s = lc->parent; | |
| 1750 | 6593619 | const uint8_t *src = ref->data[0]; | |
| 1751 | 6593619 | ptrdiff_t srcstride = ref->linesize[0]; | |
| 1752 | 6593619 | int pic_width = sps->width; | |
| 1753 | 6593619 | int pic_height = sps->height; | |
| 1754 | 6593619 | int mx = mv->x & 3; | |
| 1755 | 6593619 | int my = mv->y & 3; | |
| 1756 |
4/4✓ Branch 0 taken 3530684 times.
✓ Branch 1 taken 3062935 times.
✓ Branch 2 taken 3470096 times.
✓ Branch 3 taken 60588 times.
|
13126650 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
| 1757 |
4/4✓ Branch 0 taken 3062935 times.
✓ Branch 1 taken 3470096 times.
✓ Branch 2 taken 73276 times.
✓ Branch 3 taken 2989659 times.
|
6533031 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
| 1758 | 6593619 | int idx = hevc_pel_weight[block_w]; | |
| 1759 | |||
| 1760 | 6593619 | x_off += mv->x >> 2; | |
| 1761 | 6593619 | y_off += mv->y >> 2; | |
| 1762 | 6593619 | src += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
| 1763 | |||
| 1764 |
4/4✓ Branch 0 taken 6523554 times.
✓ Branch 1 taken 70065 times.
✓ Branch 2 taken 6399302 times.
✓ Branch 3 taken 124252 times.
|
6593619 | if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER || |
| 1765 |
2/2✓ Branch 0 taken 6320486 times.
✓ Branch 1 taken 78816 times.
|
6399302 | x_off >= pic_width - block_w - QPEL_EXTRA_AFTER || |
| 1766 |
2/2✓ Branch 0 taken 6078959 times.
✓ Branch 1 taken 241527 times.
|
6320486 | y_off >= pic_height - block_h - QPEL_EXTRA_AFTER || |
| 1767 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6078959 times.
|
6078959 | ref == s->cur_frame->f) { |
| 1768 | 514660 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 1769 | 514660 | int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1770 | 514660 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1771 | |||
| 1772 | 514660 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset, | |
| 1773 | edge_emu_stride, srcstride, | ||
| 1774 | block_w + QPEL_EXTRA, | ||
| 1775 | block_h + QPEL_EXTRA, | ||
| 1776 | x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE, | ||
| 1777 | pic_width, pic_height); | ||
| 1778 | 514660 | src = lc->edge_emu_buffer + buf_offset; | |
| 1779 | 514660 | srcstride = edge_emu_stride; | |
| 1780 | } | ||
| 1781 | |||
| 1782 |
2/2✓ Branch 0 taken 6459755 times.
✓ Branch 1 taken 133864 times.
|
6593619 | if (!weight_flag) |
| 1783 | 6459755 | s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
| 1784 | block_h, mx, my, block_w); | ||
| 1785 | else | ||
| 1786 | 133864 | s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
| 1787 | 133864 | block_h, s->sh.luma_log2_weight_denom, | |
| 1788 | luma_weight, luma_offset, mx, my, block_w); | ||
| 1789 | 6593619 | } | |
| 1790 | |||
| 1791 | /** | ||
| 1792 | * 8.5.3.2.2.1 Luma sample bidirectional interpolation process | ||
| 1793 | * | ||
| 1794 | * @param s HEVC decoding context | ||
| 1795 | * @param dst target buffer for block data at block position | ||
| 1796 | * @param dststride stride of the dst buffer | ||
| 1797 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
| 1798 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
| 1799 | * @param x_off horizontal position of block from origin (0, 0) | ||
| 1800 | * @param y_off vertical position of block from origin (0, 0) | ||
| 1801 | * @param block_w width of block | ||
| 1802 | * @param block_h height of block | ||
| 1803 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
| 1804 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
| 1805 | * @param current_mv current motion vector structure | ||
| 1806 | */ | ||
| 1807 | 3992260 | static void luma_mc_bi(HEVCLocalContext *lc, | |
| 1808 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1809 | uint8_t *dst, ptrdiff_t dststride, | ||
| 1810 | const AVFrame *ref0, const Mv *mv0, int x_off, int y_off, | ||
| 1811 | int block_w, int block_h, const AVFrame *ref1, | ||
| 1812 | const Mv *mv1, struct MvField *current_mv) | ||
| 1813 | { | ||
| 1814 | 3992260 | const HEVCContext *const s = lc->parent; | |
| 1815 | 3992260 | ptrdiff_t src0stride = ref0->linesize[0]; | |
| 1816 | 3992260 | ptrdiff_t src1stride = ref1->linesize[0]; | |
| 1817 | 3992260 | int pic_width = sps->width; | |
| 1818 | 3992260 | int pic_height = sps->height; | |
| 1819 | 3992260 | int mx0 = mv0->x & 3; | |
| 1820 | 3992260 | int my0 = mv0->y & 3; | |
| 1821 | 3992260 | int mx1 = mv1->x & 3; | |
| 1822 | 3992260 | int my1 = mv1->y & 3; | |
| 1823 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3992260 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7984520 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
| 1824 |
3/4✓ Branch 0 taken 3992260 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 73498 times.
✓ Branch 3 taken 3918762 times.
|
3992260 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
| 1825 | 3992260 | int x_off0 = x_off + (mv0->x >> 2); | |
| 1826 | 3992260 | int y_off0 = y_off + (mv0->y >> 2); | |
| 1827 | 3992260 | int x_off1 = x_off + (mv1->x >> 2); | |
| 1828 | 3992260 | int y_off1 = y_off + (mv1->y >> 2); | |
| 1829 | 3992260 | int idx = hevc_pel_weight[block_w]; | |
| 1830 | |||
| 1831 | 3992260 | const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift); | |
| 1832 | 3992260 | const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift); | |
| 1833 | |||
| 1834 |
4/4✓ Branch 0 taken 3934452 times.
✓ Branch 1 taken 57808 times.
✓ Branch 2 taken 3827160 times.
✓ Branch 3 taken 107292 times.
|
3992260 | if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER || |
| 1835 |
2/2✓ Branch 0 taken 3758110 times.
✓ Branch 1 taken 69050 times.
|
3827160 | x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
| 1836 |
2/2✓ Branch 0 taken 209692 times.
✓ Branch 1 taken 3548418 times.
|
3758110 | y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
| 1837 | 443842 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 1838 | 443842 | int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1839 | 443842 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1840 | |||
| 1841 | 443842 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset, | |
| 1842 | edge_emu_stride, src0stride, | ||
| 1843 | block_w + QPEL_EXTRA, | ||
| 1844 | block_h + QPEL_EXTRA, | ||
| 1845 | x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE, | ||
| 1846 | pic_width, pic_height); | ||
| 1847 | 443842 | src0 = lc->edge_emu_buffer + buf_offset; | |
| 1848 | 443842 | src0stride = edge_emu_stride; | |
| 1849 | } | ||
| 1850 | |||
| 1851 |
4/4✓ Branch 0 taken 3928250 times.
✓ Branch 1 taken 64010 times.
✓ Branch 2 taken 3821613 times.
✓ Branch 3 taken 106637 times.
|
3992260 | if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER || |
| 1852 |
2/2✓ Branch 0 taken 3750656 times.
✓ Branch 1 taken 70957 times.
|
3821613 | x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
| 1853 |
2/2✓ Branch 0 taken 212865 times.
✓ Branch 1 taken 3537791 times.
|
3750656 | y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
| 1854 | 454469 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 1855 | 454469 | int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1856 | 454469 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1857 | |||
| 1858 | 454469 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset, | |
| 1859 | edge_emu_stride, src1stride, | ||
| 1860 | block_w + QPEL_EXTRA, | ||
| 1861 | block_h + QPEL_EXTRA, | ||
| 1862 | x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE, | ||
| 1863 | pic_width, pic_height); | ||
| 1864 | 454469 | src1 = lc->edge_emu_buffer2 + buf_offset; | |
| 1865 | 454469 | src1stride = edge_emu_stride; | |
| 1866 | } | ||
| 1867 | |||
| 1868 | 3992260 | s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride, | |
| 1869 | block_h, mx0, my0, block_w); | ||
| 1870 |
2/2✓ Branch 0 taken 3918762 times.
✓ Branch 1 taken 73498 times.
|
3992260 | if (!weight_flag) |
| 1871 | 3918762 | s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
| 1872 | block_h, mx1, my1, block_w); | ||
| 1873 | else | ||
| 1874 | 73498 | s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
| 1875 | 73498 | block_h, s->sh.luma_log2_weight_denom, | |
| 1876 | 73498 | s->sh.luma_weight_l0[current_mv->ref_idx[0]], | |
| 1877 | 73498 | s->sh.luma_weight_l1[current_mv->ref_idx[1]], | |
| 1878 | 73498 | s->sh.luma_offset_l0[current_mv->ref_idx[0]] + | |
| 1879 | 73498 | s->sh.luma_offset_l1[current_mv->ref_idx[1]], | |
| 1880 | mx1, my1, block_w); | ||
| 1881 | |||
| 1882 | 3992260 | } | |
| 1883 | |||
| 1884 | /** | ||
| 1885 | * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process | ||
| 1886 | * | ||
| 1887 | * @param s HEVC decoding context | ||
| 1888 | * @param dst1 target buffer for block data at block position (U plane) | ||
| 1889 | * @param dst2 target buffer for block data at block position (V plane) | ||
| 1890 | * @param dststride stride of the dst1 and dst2 buffers | ||
| 1891 | * @param ref reference picture buffer at origin (0, 0) | ||
| 1892 | * @param mv motion vector (relative to block position) to get pixel data from | ||
| 1893 | * @param x_off horizontal position of block from origin (0, 0) | ||
| 1894 | * @param y_off vertical position of block from origin (0, 0) | ||
| 1895 | * @param block_w width of block | ||
| 1896 | * @param block_h height of block | ||
| 1897 | * @param chroma_weight weighting factor applied to the chroma prediction | ||
| 1898 | * @param chroma_offset additive offset applied to the chroma prediction value | ||
| 1899 | */ | ||
| 1900 | |||
| 1901 | 13187238 | static void chroma_mc_uni(HEVCLocalContext *lc, | |
| 1902 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1903 | uint8_t *dst0, | ||
| 1904 | ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist, | ||
| 1905 | int x_off, int y_off, int block_w, int block_h, | ||
| 1906 | const struct MvField *current_mv, int chroma_weight, int chroma_offset) | ||
| 1907 | { | ||
| 1908 | 13187238 | const HEVCContext *const s = lc->parent; | |
| 1909 | 13187238 | int pic_width = sps->width >> sps->hshift[1]; | |
| 1910 | 13187238 | int pic_height = sps->height >> sps->vshift[1]; | |
| 1911 | 13187238 | const Mv *mv = ¤t_mv->mv[reflist]; | |
| 1912 |
4/4✓ Branch 0 taken 7061368 times.
✓ Branch 1 taken 6125870 times.
✓ Branch 2 taken 6940192 times.
✓ Branch 3 taken 121176 times.
|
26253300 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
| 1913 |
4/4✓ Branch 0 taken 6125870 times.
✓ Branch 1 taken 6940192 times.
✓ Branch 2 taken 146552 times.
✓ Branch 3 taken 5979318 times.
|
13066062 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
| 1914 | 13187238 | int idx = hevc_pel_weight[block_w]; | |
| 1915 | 13187238 | int hshift = sps->hshift[1]; | |
| 1916 | 13187238 | int vshift = sps->vshift[1]; | |
| 1917 | 13187238 | intptr_t mx = av_zero_extend(mv->x, 2 + hshift); | |
| 1918 | 13187238 | intptr_t my = av_zero_extend(mv->y, 2 + vshift); | |
| 1919 | 13187238 | intptr_t _mx = mx << (1 - hshift); | |
| 1920 | 13187238 | intptr_t _my = my << (1 - vshift); | |
| 1921 |
2/4✓ Branch 0 taken 13187238 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13187238 times.
|
13187238 | int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2]; |
| 1922 | |||
| 1923 | 13187238 | x_off += mv->x >> (2 + hshift); | |
| 1924 | 13187238 | y_off += mv->y >> (2 + vshift); | |
| 1925 | 13187238 | src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
| 1926 | |||
| 1927 |
4/4✓ Branch 0 taken 13061514 times.
✓ Branch 1 taken 125724 times.
✓ Branch 2 taken 12812810 times.
✓ Branch 3 taken 248704 times.
|
13187238 | if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER || |
| 1928 |
2/2✓ Branch 0 taken 12655186 times.
✓ Branch 1 taken 157624 times.
|
12812810 | x_off >= pic_width - block_w - EPEL_EXTRA_AFTER || |
| 1929 |
3/4✓ Branch 0 taken 12172004 times.
✓ Branch 1 taken 483182 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12172004 times.
|
12655186 | y_off >= pic_height - block_h - EPEL_EXTRA_AFTER || |
| 1930 | emu) { | ||
| 1931 | 1015234 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 1932 | 1015234 | int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift)); | |
| 1933 | 1015234 | int buf_offset0 = EPEL_EXTRA_BEFORE * | |
| 1934 | 1015234 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
| 1935 | 1015234 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0, | |
| 1936 | edge_emu_stride, srcstride, | ||
| 1937 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
| 1938 | x_off - EPEL_EXTRA_BEFORE, | ||
| 1939 | y_off - EPEL_EXTRA_BEFORE, | ||
| 1940 | pic_width, pic_height); | ||
| 1941 | |||
| 1942 | 1015234 | src0 = lc->edge_emu_buffer + buf_offset0; | |
| 1943 | 1015234 | srcstride = edge_emu_stride; | |
| 1944 | } | ||
| 1945 |
2/2✓ Branch 0 taken 12919510 times.
✓ Branch 1 taken 267728 times.
|
13187238 | if (!weight_flag) |
| 1946 | 12919510 | s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
| 1947 | block_h, _mx, _my, block_w); | ||
| 1948 | else | ||
| 1949 | 267728 | s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
| 1950 | 267728 | block_h, s->sh.chroma_log2_weight_denom, | |
| 1951 | chroma_weight, chroma_offset, _mx, _my, block_w); | ||
| 1952 | 13187238 | } | |
| 1953 | |||
| 1954 | /** | ||
| 1955 | * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process | ||
| 1956 | * | ||
| 1957 | * @param s HEVC decoding context | ||
| 1958 | * @param dst target buffer for block data at block position | ||
| 1959 | * @param dststride stride of the dst buffer | ||
| 1960 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
| 1961 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
| 1962 | * @param x_off horizontal position of block from origin (0, 0) | ||
| 1963 | * @param y_off vertical position of block from origin (0, 0) | ||
| 1964 | * @param block_w width of block | ||
| 1965 | * @param block_h height of block | ||
| 1966 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
| 1967 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
| 1968 | * @param current_mv current motion vector structure | ||
| 1969 | * @param cidx chroma component(cb, cr) | ||
| 1970 | */ | ||
| 1971 | 7984520 | static void chroma_mc_bi(HEVCLocalContext *lc, | |
| 1972 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1973 | uint8_t *dst0, ptrdiff_t dststride, | ||
| 1974 | const AVFrame *ref0, const AVFrame *ref1, | ||
| 1975 | int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx) | ||
| 1976 | { | ||
| 1977 | 7984520 | const HEVCContext *const s = lc->parent; | |
| 1978 | 7984520 | const uint8_t *src1 = ref0->data[cidx+1]; | |
| 1979 | 7984520 | const uint8_t *src2 = ref1->data[cidx+1]; | |
| 1980 | 7984520 | ptrdiff_t src1stride = ref0->linesize[cidx+1]; | |
| 1981 | 7984520 | ptrdiff_t src2stride = ref1->linesize[cidx+1]; | |
| 1982 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7984520 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
15969040 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
| 1983 |
3/4✓ Branch 0 taken 7984520 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 146996 times.
✓ Branch 3 taken 7837524 times.
|
7984520 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
| 1984 | 7984520 | int pic_width = sps->width >> sps->hshift[1]; | |
| 1985 | 7984520 | int pic_height = sps->height >> sps->vshift[1]; | |
| 1986 | 7984520 | const Mv *const mv0 = ¤t_mv->mv[0]; | |
| 1987 | 7984520 | const Mv *const mv1 = ¤t_mv->mv[1]; | |
| 1988 | 7984520 | int hshift = sps->hshift[1]; | |
| 1989 | 7984520 | int vshift = sps->vshift[1]; | |
| 1990 | |||
| 1991 | 7984520 | intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift); | |
| 1992 | 7984520 | intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift); | |
| 1993 | 7984520 | intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift); | |
| 1994 | 7984520 | intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift); | |
| 1995 | 7984520 | intptr_t _mx0 = mx0 << (1 - hshift); | |
| 1996 | 7984520 | intptr_t _my0 = my0 << (1 - vshift); | |
| 1997 | 7984520 | intptr_t _mx1 = mx1 << (1 - hshift); | |
| 1998 | 7984520 | intptr_t _my1 = my1 << (1 - vshift); | |
| 1999 | |||
| 2000 | 7984520 | int x_off0 = x_off + (mv0->x >> (2 + hshift)); | |
| 2001 | 7984520 | int y_off0 = y_off + (mv0->y >> (2 + vshift)); | |
| 2002 | 7984520 | int x_off1 = x_off + (mv1->x >> (2 + hshift)); | |
| 2003 | 7984520 | int y_off1 = y_off + (mv1->y >> (2 + vshift)); | |
| 2004 | 7984520 | int idx = hevc_pel_weight[block_w]; | |
| 2005 | 7984520 | src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift); | |
| 2006 | 7984520 | src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift); | |
| 2007 | |||
| 2008 |
4/4✓ Branch 0 taken 7875162 times.
✓ Branch 1 taken 109358 times.
✓ Branch 2 taken 7660466 times.
✓ Branch 3 taken 214696 times.
|
7984520 | if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER || |
| 2009 |
2/2✓ Branch 0 taken 7522370 times.
✓ Branch 1 taken 138096 times.
|
7660466 | x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
| 2010 |
2/2✓ Branch 0 taken 418796 times.
✓ Branch 1 taken 7103574 times.
|
7522370 | y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
| 2011 | 880946 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 2012 | 880946 | int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift)); | |
| 2013 | 880946 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
| 2014 | 880946 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
| 2015 | |||
| 2016 | 880946 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1, | |
| 2017 | edge_emu_stride, src1stride, | ||
| 2018 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
| 2019 | x_off0 - EPEL_EXTRA_BEFORE, | ||
| 2020 | y_off0 - EPEL_EXTRA_BEFORE, | ||
| 2021 | pic_width, pic_height); | ||
| 2022 | |||
| 2023 | 880946 | src1 = lc->edge_emu_buffer + buf_offset1; | |
| 2024 | 880946 | src1stride = edge_emu_stride; | |
| 2025 | } | ||
| 2026 | |||
| 2027 |
4/4✓ Branch 0 taken 7861896 times.
✓ Branch 1 taken 122624 times.
✓ Branch 2 taken 7648900 times.
✓ Branch 3 taken 212996 times.
|
7984520 | if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER || |
| 2028 |
2/2✓ Branch 0 taken 7506992 times.
✓ Branch 1 taken 141908 times.
|
7648900 | x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
| 2029 |
2/2✓ Branch 0 taken 425404 times.
✓ Branch 1 taken 7081588 times.
|
7506992 | y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
| 2030 | 902932 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 2031 | 902932 | int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift)); | |
| 2032 | 902932 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
| 2033 | 902932 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
| 2034 | |||
| 2035 | 902932 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1, | |
| 2036 | edge_emu_stride, src2stride, | ||
| 2037 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
| 2038 | x_off1 - EPEL_EXTRA_BEFORE, | ||
| 2039 | y_off1 - EPEL_EXTRA_BEFORE, | ||
| 2040 | pic_width, pic_height); | ||
| 2041 | |||
| 2042 | 902932 | src2 = lc->edge_emu_buffer2 + buf_offset1; | |
| 2043 | 902932 | src2stride = edge_emu_stride; | |
| 2044 | } | ||
| 2045 | |||
| 2046 | 7984520 | s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride, | |
| 2047 | block_h, _mx0, _my0, block_w); | ||
| 2048 |
2/2✓ Branch 0 taken 7837524 times.
✓ Branch 1 taken 146996 times.
|
7984520 | if (!weight_flag) |
| 2049 | 7837524 | s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1], | |
| 2050 | 7837524 | src2, src2stride, lc->tmp, | |
| 2051 | block_h, _mx1, _my1, block_w); | ||
| 2052 | else | ||
| 2053 | 146996 | s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1], | |
| 2054 | 146996 | src2, src2stride, lc->tmp, | |
| 2055 | block_h, | ||
| 2056 | 146996 | s->sh.chroma_log2_weight_denom, | |
| 2057 | 146996 | s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx], | |
| 2058 | 146996 | s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx], | |
| 2059 | 146996 | s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx] + | |
| 2060 | 146996 | s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx], | |
| 2061 | _mx1, _my1, block_w); | ||
| 2062 | 7984520 | } | |
| 2063 | |||
| 2064 | 14578139 | static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref, | |
| 2065 | const Mv *mv, int y0, int height) | ||
| 2066 | { | ||
| 2067 |
2/2✓ Branch 0 taken 111132 times.
✓ Branch 1 taken 14467007 times.
|
14578139 | if (s->avctx->active_thread_type == FF_THREAD_FRAME ) { |
| 2068 | 111132 | int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9); | |
| 2069 | |||
| 2070 | 111132 | ff_progress_frame_await(&ref->tf, y); | |
| 2071 | } | ||
| 2072 | 14578139 | } | |
| 2073 | |||
| 2074 | 2924907 | static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, | |
| 2075 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2076 | int x0, int y0, int nPbW, | ||
| 2077 | int nPbH, int log2_cb_size, int part_idx, | ||
| 2078 | int merge_idx, MvField *mv) | ||
| 2079 | { | ||
| 2080 | 2924907 | const HEVCContext *const s = lc->parent; | |
| 2081 | 2924907 | enum InterPredIdc inter_pred_idc = PRED_L0; | |
| 2082 | int mvp_flag; | ||
| 2083 | |||
| 2084 | 2924907 | ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size); | |
| 2085 | 2924907 | mv->pred_flag = 0; | |
| 2086 |
2/2✓ Branch 0 taken 1923220 times.
✓ Branch 1 taken 1001687 times.
|
2924907 | if (s->sh.slice_type == HEVC_SLICE_B) |
| 2087 | 1923220 | inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH); | |
| 2088 | |||
| 2089 |
2/2✓ Branch 0 taken 2515419 times.
✓ Branch 1 taken 409488 times.
|
2924907 | if (inter_pred_idc != PRED_L1) { |
| 2090 |
1/2✓ Branch 0 taken 2515419 times.
✗ Branch 1 not taken.
|
2515419 | if (s->sh.nb_refs[L0]) |
| 2091 | 2515419 | mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]); | |
| 2092 | |||
| 2093 | 2515419 | mv->pred_flag = PF_L0; | |
| 2094 | 2515419 | ff_hevc_hls_mvd_coding(lc, x0, y0, 0); | |
| 2095 | 2515419 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
| 2096 | 2515419 | ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
| 2097 | part_idx, merge_idx, mv, mvp_flag, 0); | ||
| 2098 | 2515419 | mv->mv[0].x += lc->pu.mvd.x; | |
| 2099 | 2515419 | mv->mv[0].y += lc->pu.mvd.y; | |
| 2100 | } | ||
| 2101 | |||
| 2102 |
2/2✓ Branch 0 taken 834466 times.
✓ Branch 1 taken 2090441 times.
|
2924907 | if (inter_pred_idc != PRED_L0) { |
| 2103 |
1/2✓ Branch 0 taken 834466 times.
✗ Branch 1 not taken.
|
834466 | if (s->sh.nb_refs[L1]) |
| 2104 | 834466 | mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]); | |
| 2105 | |||
| 2106 |
4/4✓ Branch 0 taken 193172 times.
✓ Branch 1 taken 641294 times.
✓ Branch 2 taken 163605 times.
✓ Branch 3 taken 29567 times.
|
834466 | if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) { |
| 2107 | 163605 | AV_ZERO32(&lc->pu.mvd); | |
| 2108 | } else { | ||
| 2109 | 670861 | ff_hevc_hls_mvd_coding(lc, x0, y0, 1); | |
| 2110 | } | ||
| 2111 | |||
| 2112 | 834466 | mv->pred_flag += PF_L1; | |
| 2113 | 834466 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
| 2114 | 834466 | ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
| 2115 | part_idx, merge_idx, mv, mvp_flag, 1); | ||
| 2116 | 834466 | mv->mv[1].x += lc->pu.mvd.x; | |
| 2117 | 834466 | mv->mv[1].y += lc->pu.mvd.y; | |
| 2118 | } | ||
| 2119 | 2924907 | } | |
| 2120 | |||
| 2121 | 10585879 | static void hls_prediction_unit(HEVCLocalContext *lc, | |
| 2122 | const HEVCLayerContext *l, | ||
| 2123 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2124 | int x0, int y0, int nPbW, int nPbH, | ||
| 2125 | int log2_cb_size, int partIdx, int idx) | ||
| 2126 | { | ||
| 2127 | #define POS(c_idx, x, y) \ | ||
| 2128 | s->cur_frame->f->data[c_idx] ? \ | ||
| 2129 | &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \ | ||
| 2130 | (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] : NULL | ||
| 2131 | 10585879 | const HEVCContext *const s = lc->parent; | |
| 2132 | 10585879 | int merge_idx = 0; | |
| 2133 | 10585879 | struct MvField current_mv = {{{ 0 }}}; | |
| 2134 | |||
| 2135 | 10585879 | int min_pu_width = sps->min_pu_width; | |
| 2136 | |||
| 2137 | 10585879 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
| 2138 | 10585879 | const RefPicList *refPicList = s->cur_frame->refPicList; | |
| 2139 | 10585879 | const HEVCFrame *ref0 = NULL, *ref1 = NULL; | |
| 2140 | 10585879 | const int *linesize = s->cur_frame->f->linesize; | |
| 2141 | 10585879 | uint8_t *dst0 = s->cur_frame->f->data[0] + y0 * linesize[0] + (x0 << sps->pixel_shift); | |
| 2142 |
1/2✓ Branch 0 taken 10585879 times.
✗ Branch 1 not taken.
|
10585879 | uint8_t *dst1 = POS(1, x0, y0); |
| 2143 |
1/2✓ Branch 0 taken 10585879 times.
✗ Branch 1 not taken.
|
10585879 | uint8_t *dst2 = POS(2, x0, y0); |
| 2144 | 10585879 | int log2_min_cb_size = sps->log2_min_cb_size; | |
| 2145 | 10585879 | int min_cb_width = sps->min_cb_width; | |
| 2146 | 10585879 | int x_cb = x0 >> log2_min_cb_size; | |
| 2147 | 10585879 | int y_cb = y0 >> log2_min_cb_size; | |
| 2148 | int x_pu, y_pu; | ||
| 2149 | int i, j; | ||
| 2150 | |||
| 2151 | 10585879 | int skip_flag = SAMPLE_CTB(l->skip_flag, x_cb, y_cb); | |
| 2152 | |||
| 2153 |
2/2✓ Branch 0 taken 5861787 times.
✓ Branch 1 taken 4724092 times.
|
10585879 | if (!skip_flag) |
| 2154 | 5861787 | lc->pu.merge_flag = ff_hevc_merge_flag_decode(lc); | |
| 2155 | |||
| 2156 |
4/4✓ Branch 0 taken 5861787 times.
✓ Branch 1 taken 4724092 times.
✓ Branch 2 taken 2936880 times.
✓ Branch 3 taken 2924907 times.
|
10585879 | if (skip_flag || lc->pu.merge_flag) { |
| 2157 |
2/2✓ Branch 0 taken 7584119 times.
✓ Branch 1 taken 76853 times.
|
7660972 | if (s->sh.max_num_merge_cand > 1) |
| 2158 | 7584119 | merge_idx = ff_hevc_merge_idx_decode(lc); | |
| 2159 | else | ||
| 2160 | 76853 | merge_idx = 0; | |
| 2161 | |||
| 2162 | 7660972 | ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
| 2163 | partIdx, merge_idx, ¤t_mv); | ||
| 2164 | } else { | ||
| 2165 | 2924907 | hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size, | |
| 2166 | partIdx, merge_idx, ¤t_mv); | ||
| 2167 | } | ||
| 2168 | |||
| 2169 | 10585879 | x_pu = x0 >> sps->log2_min_pu_size; | |
| 2170 | 10585879 | y_pu = y0 >> sps->log2_min_pu_size; | |
| 2171 | |||
| 2172 |
2/2✓ Branch 0 taken 41855258 times.
✓ Branch 1 taken 10585879 times.
|
52441137 | for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++) |
| 2173 |
2/2✓ Branch 0 taken 271172596 times.
✓ Branch 1 taken 41855258 times.
|
313027854 | for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++) |
| 2174 | 271172596 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; | |
| 2175 | |||
| 2176 |
2/2✓ Branch 0 taken 9766042 times.
✓ Branch 1 taken 819837 times.
|
10585879 | if (current_mv.pred_flag & PF_L0) { |
| 2177 | 9766042 | ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; | |
| 2178 |
2/4✓ Branch 0 taken 9766042 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9766042 times.
|
9766042 | if (!ref0 || !ref0->f) |
| 2179 | ✗ | return; | |
| 2180 | 9766042 | hevc_await_progress(s, ref0, ¤t_mv.mv[0], y0, nPbH); | |
| 2181 | } | ||
| 2182 |
2/2✓ Branch 0 taken 4812097 times.
✓ Branch 1 taken 5773782 times.
|
10585879 | if (current_mv.pred_flag & PF_L1) { |
| 2183 | 4812097 | ref1 = refPicList[1].ref[current_mv.ref_idx[1]]; | |
| 2184 |
2/4✓ Branch 0 taken 4812097 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4812097 times.
|
4812097 | if (!ref1 || !ref1->f) |
| 2185 | ✗ | return; | |
| 2186 | 4812097 | hevc_await_progress(s, ref1, ¤t_mv.mv[1], y0, nPbH); | |
| 2187 | } | ||
| 2188 | |||
| 2189 |
2/2✓ Branch 0 taken 5773782 times.
✓ Branch 1 taken 4812097 times.
|
10585879 | if (current_mv.pred_flag == PF_L0) { |
| 2190 | 5773782 | int x0_c = x0 >> sps->hshift[1]; | |
| 2191 | 5773782 | int y0_c = y0 >> sps->vshift[1]; | |
| 2192 | 5773782 | int nPbW_c = nPbW >> sps->hshift[1]; | |
| 2193 | 5773782 | int nPbH_c = nPbH >> sps->vshift[1]; | |
| 2194 | |||
| 2195 | 5773782 | luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f, | |
| 2196 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
| 2197 | 5773782 | s->sh.luma_weight_l0[current_mv.ref_idx[0]], | |
| 2198 | 5773782 | s->sh.luma_offset_l0[current_mv.ref_idx[0]]); | |
| 2199 | |||
| 2200 |
1/2✓ Branch 0 taken 5773782 times.
✗ Branch 1 not taken.
|
5773782 | if (sps->chroma_format_idc) { |
| 2201 | 5773782 | chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1], | |
| 2202 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
| 2203 | 5773782 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]); | |
| 2204 | 5773782 | chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2], | |
| 2205 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
| 2206 | 5773782 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]); | |
| 2207 | } | ||
| 2208 |
2/2✓ Branch 0 taken 819837 times.
✓ Branch 1 taken 3992260 times.
|
4812097 | } else if (current_mv.pred_flag == PF_L1) { |
| 2209 | 819837 | int x0_c = x0 >> sps->hshift[1]; | |
| 2210 | 819837 | int y0_c = y0 >> sps->vshift[1]; | |
| 2211 | 819837 | int nPbW_c = nPbW >> sps->hshift[1]; | |
| 2212 | 819837 | int nPbH_c = nPbH >> sps->vshift[1]; | |
| 2213 | |||
| 2214 | 819837 | luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f, | |
| 2215 | ¤t_mv.mv[1], x0, y0, nPbW, nPbH, | ||
| 2216 | 819837 | s->sh.luma_weight_l1[current_mv.ref_idx[1]], | |
| 2217 | 819837 | s->sh.luma_offset_l1[current_mv.ref_idx[1]]); | |
| 2218 | |||
| 2219 |
1/2✓ Branch 0 taken 819837 times.
✗ Branch 1 not taken.
|
819837 | if (sps->chroma_format_idc) { |
| 2220 | 819837 | chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1], | |
| 2221 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
| 2222 | 819837 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]); | |
| 2223 | |||
| 2224 | 819837 | chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2], | |
| 2225 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
| 2226 | 819837 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]); | |
| 2227 | } | ||
| 2228 |
1/2✓ Branch 0 taken 3992260 times.
✗ Branch 1 not taken.
|
3992260 | } else if (current_mv.pred_flag == PF_BI) { |
| 2229 | 3992260 | int x0_c = x0 >> sps->hshift[1]; | |
| 2230 | 3992260 | int y0_c = y0 >> sps->vshift[1]; | |
| 2231 | 3992260 | int nPbW_c = nPbW >> sps->hshift[1]; | |
| 2232 | 3992260 | int nPbH_c = nPbH >> sps->vshift[1]; | |
| 2233 | |||
| 2234 | 3992260 | luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f, | |
| 2235 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
| 2236 | 3992260 | ref1->f, ¤t_mv.mv[1], ¤t_mv); | |
| 2237 | |||
| 2238 |
1/2✓ Branch 0 taken 3992260 times.
✗ Branch 1 not taken.
|
3992260 | if (sps->chroma_format_idc) { |
| 2239 | 3992260 | chroma_mc_bi(lc, pps, sps, dst1, linesize[1], ref0->f, ref1->f, | |
| 2240 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0); | ||
| 2241 | |||
| 2242 | 3992260 | chroma_mc_bi(lc, pps, sps, dst2, linesize[2], ref0->f, ref1->f, | |
| 2243 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1); | ||
| 2244 | } | ||
| 2245 | } | ||
| 2246 | } | ||
| 2247 | |||
| 2248 | /** | ||
| 2249 | * 8.4.1 | ||
| 2250 | */ | ||
| 2251 | 6821846 | static int luma_intra_pred_mode(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
| 2252 | const HEVCSPS *sps, | ||
| 2253 | int x0, int y0, int pu_size, | ||
| 2254 | int prev_intra_luma_pred_flag) | ||
| 2255 | { | ||
| 2256 | 6821846 | const HEVCContext *const s = lc->parent; | |
| 2257 | 6821846 | int x_pu = x0 >> sps->log2_min_pu_size; | |
| 2258 | 6821846 | int y_pu = y0 >> sps->log2_min_pu_size; | |
| 2259 | 6821846 | int min_pu_width = sps->min_pu_width; | |
| 2260 | 6821846 | int size_in_pus = pu_size >> sps->log2_min_pu_size; | |
| 2261 | 6821846 | int x0b = av_zero_extend(x0, sps->log2_ctb_size); | |
| 2262 | 6821846 | int y0b = av_zero_extend(y0, sps->log2_ctb_size); | |
| 2263 | |||
| 2264 |
2/2✓ Branch 0 taken 914216 times.
✓ Branch 1 taken 107884 times.
|
1022100 | int cand_up = (lc->ctb_up_flag || y0b) ? |
| 2265 |
2/2✓ Branch 0 taken 1022100 times.
✓ Branch 1 taken 5799746 times.
|
7843946 | l->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC; |
| 2266 |
2/2✓ Branch 0 taken 495156 times.
✓ Branch 1 taken 69573 times.
|
564729 | int cand_left = (lc->ctb_left_flag || x0b) ? |
| 2267 |
2/2✓ Branch 0 taken 564729 times.
✓ Branch 1 taken 6257117 times.
|
7386575 | l->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC; |
| 2268 | |||
| 2269 | 6821846 | int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size); | |
| 2270 | |||
| 2271 | 6821846 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
| 2272 | int intra_pred_mode; | ||
| 2273 | int candidate[3]; | ||
| 2274 | int i, j; | ||
| 2275 | |||
| 2276 | // intra_pred_mode prediction does not cross vertical CTB boundaries | ||
| 2277 |
2/2✓ Branch 0 taken 914520 times.
✓ Branch 1 taken 5907326 times.
|
6821846 | if ((y0 - 1) < y_ctb) |
| 2278 | 914520 | cand_up = INTRA_DC; | |
| 2279 | |||
| 2280 |
2/2✓ Branch 0 taken 1528322 times.
✓ Branch 1 taken 5293524 times.
|
6821846 | if (cand_left == cand_up) { |
| 2281 |
2/2✓ Branch 0 taken 980707 times.
✓ Branch 1 taken 547615 times.
|
1528322 | if (cand_left < 2) { |
| 2282 | 980707 | candidate[0] = INTRA_PLANAR; | |
| 2283 | 980707 | candidate[1] = INTRA_DC; | |
| 2284 | 980707 | candidate[2] = INTRA_ANGULAR_26; | |
| 2285 | } else { | ||
| 2286 | 547615 | candidate[0] = cand_left; | |
| 2287 | 547615 | candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31); | |
| 2288 | 547615 | candidate[2] = 2 + ((cand_left - 2 + 1) & 31); | |
| 2289 | } | ||
| 2290 | } else { | ||
| 2291 | 5293524 | candidate[0] = cand_left; | |
| 2292 | 5293524 | candidate[1] = cand_up; | |
| 2293 |
4/4✓ Branch 0 taken 4392382 times.
✓ Branch 1 taken 901142 times.
✓ Branch 2 taken 3629903 times.
✓ Branch 3 taken 762479 times.
|
5293524 | if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) { |
| 2294 | 3629903 | candidate[2] = INTRA_PLANAR; | |
| 2295 |
4/4✓ Branch 0 taken 1445704 times.
✓ Branch 1 taken 217917 times.
✓ Branch 2 taken 1077577 times.
✓ Branch 3 taken 368127 times.
|
1663621 | } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) { |
| 2296 | 1077577 | candidate[2] = INTRA_DC; | |
| 2297 | } else { | ||
| 2298 | 586044 | candidate[2] = INTRA_ANGULAR_26; | |
| 2299 | } | ||
| 2300 | } | ||
| 2301 | |||
| 2302 |
2/2✓ Branch 0 taken 4052132 times.
✓ Branch 1 taken 2769714 times.
|
6821846 | if (prev_intra_luma_pred_flag) { |
| 2303 | 4052132 | intra_pred_mode = candidate[lc->pu.mpm_idx]; | |
| 2304 | } else { | ||
| 2305 |
2/2✓ Branch 0 taken 1272161 times.
✓ Branch 1 taken 1497553 times.
|
2769714 | if (candidate[0] > candidate[1]) |
| 2306 | 1272161 | FFSWAP(uint8_t, candidate[0], candidate[1]); | |
| 2307 |
2/2✓ Branch 0 taken 1597845 times.
✓ Branch 1 taken 1171869 times.
|
2769714 | if (candidate[0] > candidate[2]) |
| 2308 | 1597845 | FFSWAP(uint8_t, candidate[0], candidate[2]); | |
| 2309 |
2/2✓ Branch 0 taken 1996198 times.
✓ Branch 1 taken 773516 times.
|
2769714 | if (candidate[1] > candidate[2]) |
| 2310 | 1996198 | FFSWAP(uint8_t, candidate[1], candidate[2]); | |
| 2311 | |||
| 2312 | 2769714 | intra_pred_mode = lc->pu.rem_intra_luma_pred_mode; | |
| 2313 |
2/2✓ Branch 0 taken 8309142 times.
✓ Branch 1 taken 2769714 times.
|
11078856 | for (i = 0; i < 3; i++) |
| 2314 |
2/2✓ Branch 0 taken 6060402 times.
✓ Branch 1 taken 2248740 times.
|
8309142 | if (intra_pred_mode >= candidate[i]) |
| 2315 | 6060402 | intra_pred_mode++; | |
| 2316 | } | ||
| 2317 | |||
| 2318 | /* write the intra prediction units into the mv array */ | ||
| 2319 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6821846 times.
|
6821846 | if (!size_in_pus) |
| 2320 | ✗ | size_in_pus = 1; | |
| 2321 |
2/2✓ Branch 0 taken 12422700 times.
✓ Branch 1 taken 6821846 times.
|
19244546 | for (i = 0; i < size_in_pus; i++) { |
| 2322 | 12422700 | memset(&l->tab_ipm[(y_pu + i) * min_pu_width + x_pu], | |
| 2323 | intra_pred_mode, size_in_pus); | ||
| 2324 | |||
| 2325 |
2/2✓ Branch 0 taken 41754200 times.
✓ Branch 1 taken 12422700 times.
|
54176900 | for (j = 0; j < size_in_pus; j++) { |
| 2326 | 41754200 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA; | |
| 2327 | } | ||
| 2328 | } | ||
| 2329 | |||
| 2330 | 6821846 | return intra_pred_mode; | |
| 2331 | } | ||
| 2332 | |||
| 2333 | 12517996 | static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth, | |
| 2334 | int x0, int y0, | ||
| 2335 | int log2_cb_size, int ct_depth) | ||
| 2336 | { | ||
| 2337 | 12517996 | int length = (1 << log2_cb_size) >> sps->log2_min_cb_size; | |
| 2338 | 12517996 | int x_cb = x0 >> sps->log2_min_cb_size; | |
| 2339 | 12517996 | int y_cb = y0 >> sps->log2_min_cb_size; | |
| 2340 | int y; | ||
| 2341 | |||
| 2342 |
2/2✓ Branch 0 taken 24343198 times.
✓ Branch 1 taken 12517996 times.
|
36861194 | for (y = 0; y < length; y++) |
| 2343 | 24343198 | memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb], | |
| 2344 | ct_depth, length); | ||
| 2345 | 12517996 | } | |
| 2346 | |||
| 2347 | static const uint8_t tab_mode_idx[] = { | ||
| 2348 | 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, | ||
| 2349 | 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31}; | ||
| 2350 | |||
| 2351 | 3673046 | static void intra_prediction_unit(HEVCLocalContext *lc, | |
| 2352 | const HEVCLayerContext *l, const HEVCSPS *sps, | ||
| 2353 | int x0, int y0, | ||
| 2354 | int log2_cb_size) | ||
| 2355 | { | ||
| 2356 | static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 }; | ||
| 2357 | uint8_t prev_intra_luma_pred_flag[4]; | ||
| 2358 | 3673046 | int split = lc->cu.part_mode == PART_NxN; | |
| 2359 | 3673046 | int pb_size = (1 << log2_cb_size) >> split; | |
| 2360 | 3673046 | int side = split + 1; | |
| 2361 | int chroma_mode; | ||
| 2362 | int i, j; | ||
| 2363 | |||
| 2364 |
2/2✓ Branch 0 taken 4722646 times.
✓ Branch 1 taken 3673046 times.
|
8395692 | for (i = 0; i < side; i++) |
| 2365 |
2/2✓ Branch 0 taken 6821846 times.
✓ Branch 1 taken 4722646 times.
|
11544492 | for (j = 0; j < side; j++) |
| 2366 | 6821846 | prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc); | |
| 2367 | |||
| 2368 |
2/2✓ Branch 0 taken 4722646 times.
✓ Branch 1 taken 3673046 times.
|
8395692 | for (i = 0; i < side; i++) { |
| 2369 |
2/2✓ Branch 0 taken 6821846 times.
✓ Branch 1 taken 4722646 times.
|
11544492 | for (j = 0; j < side; j++) { |
| 2370 |
2/2✓ Branch 0 taken 4052132 times.
✓ Branch 1 taken 2769714 times.
|
6821846 | if (prev_intra_luma_pred_flag[2 * i + j]) |
| 2371 | 4052132 | lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc); | |
| 2372 | else | ||
| 2373 | 2769714 | lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc); | |
| 2374 | |||
| 2375 | 6821846 | lc->pu.intra_pred_mode[2 * i + j] = | |
| 2376 | 6821846 | luma_intra_pred_mode(lc, l, sps, | |
| 2377 | 6821846 | x0 + pb_size * j, y0 + pb_size * i, pb_size, | |
| 2378 | 6821846 | prev_intra_luma_pred_flag[2 * i + j]); | |
| 2379 | } | ||
| 2380 | } | ||
| 2381 | |||
| 2382 |
2/2✓ Branch 0 taken 59336 times.
✓ Branch 1 taken 3613710 times.
|
3673046 | if (sps->chroma_format_idc == 3) { |
| 2383 |
2/2✓ Branch 0 taken 77980 times.
✓ Branch 1 taken 59336 times.
|
137316 | for (i = 0; i < side; i++) { |
| 2384 |
2/2✓ Branch 0 taken 115268 times.
✓ Branch 1 taken 77980 times.
|
193248 | for (j = 0; j < side; j++) { |
| 2385 | 115268 | lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
| 2386 |
2/2✓ Branch 0 taken 19491 times.
✓ Branch 1 taken 95777 times.
|
115268 | if (chroma_mode != 4) { |
| 2387 |
2/2✓ Branch 0 taken 1462 times.
✓ Branch 1 taken 18029 times.
|
19491 | if (lc->pu.intra_pred_mode[2 * i + j] == intra_chroma_table[chroma_mode]) |
| 2388 | 1462 | lc->pu.intra_pred_mode_c[2 * i + j] = 34; | |
| 2389 | else | ||
| 2390 | 18029 | lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode]; | |
| 2391 | } else { | ||
| 2392 | 95777 | lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j]; | |
| 2393 | } | ||
| 2394 | } | ||
| 2395 | } | ||
| 2396 |
2/2✓ Branch 0 taken 147152 times.
✓ Branch 1 taken 3466558 times.
|
3613710 | } else if (sps->chroma_format_idc == 2) { |
| 2397 | int mode_idx; | ||
| 2398 | 147152 | lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
| 2399 |
2/2✓ Branch 0 taken 46479 times.
✓ Branch 1 taken 100673 times.
|
147152 | if (chroma_mode != 4) { |
| 2400 |
2/2✓ Branch 0 taken 2238 times.
✓ Branch 1 taken 44241 times.
|
46479 | if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode]) |
| 2401 | 2238 | mode_idx = 34; | |
| 2402 | else | ||
| 2403 | 44241 | mode_idx = intra_chroma_table[chroma_mode]; | |
| 2404 | } else { | ||
| 2405 | 100673 | mode_idx = lc->pu.intra_pred_mode[0]; | |
| 2406 | } | ||
| 2407 | 147152 | lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx]; | |
| 2408 |
2/2✓ Branch 0 taken 3466462 times.
✓ Branch 1 taken 96 times.
|
3466558 | } else if (sps->chroma_format_idc != 0) { |
| 2409 | 3466462 | chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
| 2410 |
2/2✓ Branch 0 taken 822901 times.
✓ Branch 1 taken 2643561 times.
|
3466462 | if (chroma_mode != 4) { |
| 2411 |
2/2✓ Branch 0 taken 61006 times.
✓ Branch 1 taken 761895 times.
|
822901 | if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode]) |
| 2412 | 61006 | lc->pu.intra_pred_mode_c[0] = 34; | |
| 2413 | else | ||
| 2414 | 761895 | lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode]; | |
| 2415 | } else { | ||
| 2416 | 2643561 | lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0]; | |
| 2417 | } | ||
| 2418 | } | ||
| 2419 | 3673046 | } | |
| 2420 | |||
| 2421 | 8844951 | static void intra_prediction_unit_default_value(HEVCLocalContext *lc, | |
| 2422 | const HEVCLayerContext *l, | ||
| 2423 | const HEVCSPS *sps, | ||
| 2424 | int x0, int y0, | ||
| 2425 | int log2_cb_size) | ||
| 2426 | { | ||
| 2427 | 8844951 | const HEVCContext *const s = lc->parent; | |
| 2428 | 8844951 | int pb_size = 1 << log2_cb_size; | |
| 2429 | 8844951 | int size_in_pus = pb_size >> sps->log2_min_pu_size; | |
| 2430 | 8844951 | int min_pu_width = sps->min_pu_width; | |
| 2431 | 8844951 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
| 2432 | 8844951 | int x_pu = x0 >> sps->log2_min_pu_size; | |
| 2433 | 8844951 | int y_pu = y0 >> sps->log2_min_pu_size; | |
| 2434 | int j, k; | ||
| 2435 | |||
| 2436 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8844951 times.
|
8844951 | if (size_in_pus == 0) |
| 2437 | ✗ | size_in_pus = 1; | |
| 2438 |
2/2✓ Branch 0 taken 38362898 times.
✓ Branch 1 taken 8844951 times.
|
47207849 | for (j = 0; j < size_in_pus; j++) |
| 2439 | 38362898 | memset(&l->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus); | |
| 2440 |
2/2✓ Branch 0 taken 11207 times.
✓ Branch 1 taken 8833744 times.
|
8844951 | if (lc->cu.pred_mode == MODE_INTRA) |
| 2441 |
2/2✓ Branch 0 taken 37756 times.
✓ Branch 1 taken 11207 times.
|
48963 | for (j = 0; j < size_in_pus; j++) |
| 2442 |
2/2✓ Branch 0 taken 172544 times.
✓ Branch 1 taken 37756 times.
|
210300 | for (k = 0; k < size_in_pus; k++) |
| 2443 | 172544 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA; | |
| 2444 | 8844951 | } | |
| 2445 | |||
| 2446 | 12517997 | static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, | |
| 2447 | const HEVCLayerContext *l, | ||
| 2448 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2449 | int x0, int y0, int log2_cb_size) | ||
| 2450 | { | ||
| 2451 | 12517997 | int cb_size = 1 << log2_cb_size; | |
| 2452 | 12517997 | int log2_min_cb_size = sps->log2_min_cb_size; | |
| 2453 | 12517997 | int length = cb_size >> log2_min_cb_size; | |
| 2454 | 12517997 | int min_cb_width = sps->min_cb_width; | |
| 2455 | 12517997 | int x_cb = x0 >> log2_min_cb_size; | |
| 2456 | 12517997 | int y_cb = y0 >> log2_min_cb_size; | |
| 2457 | 12517997 | int idx = log2_cb_size - 2; | |
| 2458 | 12517997 | int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1; | |
| 2459 | int x, y, ret; | ||
| 2460 | |||
| 2461 | 12517997 | lc->cu.x = x0; | |
| 2462 | 12517997 | lc->cu.y = y0; | |
| 2463 | 12517997 | lc->cu.pred_mode = MODE_INTRA; | |
| 2464 | 12517997 | lc->cu.part_mode = PART_2Nx2N; | |
| 2465 | 12517997 | lc->cu.intra_split_flag = 0; | |
| 2466 | |||
| 2467 | 12517997 | SAMPLE_CTB(l->skip_flag, x_cb, y_cb) = 0; | |
| 2468 |
2/2✓ Branch 0 taken 50071988 times.
✓ Branch 1 taken 12517997 times.
|
62589985 | for (x = 0; x < 4; x++) |
| 2469 | 50071988 | lc->pu.intra_pred_mode[x] = 1; | |
| 2470 |
2/2✓ Branch 0 taken 179649 times.
✓ Branch 1 taken 12338348 times.
|
12517997 | if (pps->transquant_bypass_enable_flag) { |
| 2471 | 179649 | lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(lc); | |
| 2472 |
2/2✓ Branch 0 taken 79710 times.
✓ Branch 1 taken 99939 times.
|
179649 | if (lc->cu.cu_transquant_bypass_flag) |
| 2473 | 79710 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size); | |
| 2474 | } else | ||
| 2475 | 12338348 | lc->cu.cu_transquant_bypass_flag = 0; | |
| 2476 | |||
| 2477 |
2/2✓ Branch 0 taken 10114738 times.
✓ Branch 1 taken 2403259 times.
|
12517997 | if (s->sh.slice_type != HEVC_SLICE_I) { |
| 2478 | 10114738 | const int x0b = av_zero_extend(x0, sps->log2_ctb_size); | |
| 2479 | 10114738 | const int y0b = av_zero_extend(y0, sps->log2_ctb_size); | |
| 2480 | 10114738 | uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, l->skip_flag, | |
| 2481 | x0b, y0b, x_cb, y_cb, | ||
| 2482 | min_cb_width); | ||
| 2483 | |||
| 2484 | 10114738 | x = y_cb * min_cb_width + x_cb; | |
| 2485 |
2/2✓ Branch 0 taken 21113041 times.
✓ Branch 1 taken 10114738 times.
|
31227779 | for (y = 0; y < length; y++) { |
| 2486 | 21113041 | memset(&l->skip_flag[x], skip_flag, length); | |
| 2487 | 21113041 | x += min_cb_width; | |
| 2488 | } | ||
| 2489 |
2/2✓ Branch 0 taken 4724092 times.
✓ Branch 1 taken 5390646 times.
|
10114738 | lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER; |
| 2490 | } else { | ||
| 2491 | 2403259 | x = y_cb * min_cb_width + x_cb; | |
| 2492 |
2/2✓ Branch 0 taken 3230158 times.
✓ Branch 1 taken 2403259 times.
|
5633417 | for (y = 0; y < length; y++) { |
| 2493 | 3230158 | memset(&l->skip_flag[x], 0, length); | |
| 2494 | 3230158 | x += min_cb_width; | |
| 2495 | } | ||
| 2496 | } | ||
| 2497 | |||
| 2498 |
2/2✓ Branch 0 taken 4724092 times.
✓ Branch 1 taken 7793905 times.
|
12517997 | if (SAMPLE_CTB(l->skip_flag, x_cb, y_cb)) { |
| 2499 | 4724092 | hls_prediction_unit(lc, l, pps, sps, | |
| 2500 | x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | ||
| 2501 | 4724092 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
| 2502 | |||
| 2503 |
2/2✓ Branch 0 taken 4577464 times.
✓ Branch 1 taken 146628 times.
|
4724092 | if (!s->sh.disable_deblocking_filter_flag) |
| 2504 | 4577464 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
| 2505 | } else { | ||
| 2506 | 7793905 | int pcm_flag = 0; | |
| 2507 | |||
| 2508 |
2/2✓ Branch 0 taken 5390646 times.
✓ Branch 1 taken 2403259 times.
|
7793905 | if (s->sh.slice_type != HEVC_SLICE_I) |
| 2509 | 5390646 | lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc); | |
| 2510 |
2/2✓ Branch 0 taken 3684253 times.
✓ Branch 1 taken 4109652 times.
|
7793905 | if (lc->cu.pred_mode != MODE_INTRA || |
| 2511 |
2/2✓ Branch 0 taken 2767634 times.
✓ Branch 1 taken 916619 times.
|
3684253 | log2_cb_size == sps->log2_min_cb_size) { |
| 2512 | 6877286 | lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size); | |
| 2513 |
2/2✓ Branch 0 taken 1157755 times.
✓ Branch 1 taken 5719531 times.
|
8035041 | lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN && |
| 2514 |
2/2✓ Branch 0 taken 1049600 times.
✓ Branch 1 taken 108155 times.
|
1157755 | lc->cu.pred_mode == MODE_INTRA; |
| 2515 | } | ||
| 2516 | |||
| 2517 |
2/2✓ Branch 0 taken 3684253 times.
✓ Branch 1 taken 4109652 times.
|
7793905 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 2518 |
4/4✓ Branch 0 taken 2634653 times.
✓ Branch 1 taken 1049600 times.
✓ Branch 2 taken 134413 times.
✓ Branch 3 taken 2500240 times.
|
3684253 | if (lc->cu.part_mode == PART_2Nx2N && sps->pcm_enabled && |
| 2519 |
2/2✓ Branch 0 taken 133790 times.
✓ Branch 1 taken 623 times.
|
134413 | log2_cb_size >= sps->pcm.log2_min_pcm_cb_size && |
| 2520 |
2/2✓ Branch 0 taken 126478 times.
✓ Branch 1 taken 7312 times.
|
133790 | log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) { |
| 2521 | 126478 | pcm_flag = ff_hevc_pcm_flag_decode(lc); | |
| 2522 | } | ||
| 2523 |
2/2✓ Branch 0 taken 11207 times.
✓ Branch 1 taken 3673046 times.
|
3684253 | if (pcm_flag) { |
| 2524 | 11207 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
| 2525 | 11207 | ret = hls_pcm_sample(lc, l, pps, x0, y0, log2_cb_size); | |
| 2526 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11203 times.
|
11207 | if (sps->pcm_loop_filter_disabled) |
| 2527 | 4 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size); | |
| 2528 | |||
| 2529 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11207 times.
|
11207 | if (ret < 0) |
| 2530 | ✗ | return ret; | |
| 2531 | } else { | ||
| 2532 | 3673046 | intra_prediction_unit(lc, l, sps, x0, y0, log2_cb_size); | |
| 2533 | } | ||
| 2534 | } else { | ||
| 2535 | 4109652 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
| 2536 |
8/9✓ Branch 0 taken 2573827 times.
✓ Branch 1 taken 508582 times.
✓ Branch 2 taken 607461 times.
✓ Branch 3 taken 67350 times.
✓ Branch 4 taken 58153 times.
✓ Branch 5 taken 100281 times.
✓ Branch 6 taken 85843 times.
✓ Branch 7 taken 108155 times.
✗ Branch 8 not taken.
|
4109652 | switch (lc->cu.part_mode) { |
| 2537 | 2573827 | case PART_2Nx2N: | |
| 2538 | 2573827 | hls_prediction_unit(lc, l, pps, sps, | |
| 2539 | x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | ||
| 2540 | 2573827 | break; | |
| 2541 | 508582 | case PART_2NxN: | |
| 2542 | 508582 | hls_prediction_unit(lc, l, pps, sps, | |
| 2543 | x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx); | ||
| 2544 | 508582 | hls_prediction_unit(lc, l, pps, sps, | |
| 2545 | 508582 | x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx); | |
| 2546 | 508582 | break; | |
| 2547 | 607461 | case PART_Nx2N: | |
| 2548 | 607461 | hls_prediction_unit(lc, l, pps, sps, | |
| 2549 | x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1); | ||
| 2550 | 607461 | hls_prediction_unit(lc, l, pps, sps, | |
| 2551 | 607461 | x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1); | |
| 2552 | 607461 | break; | |
| 2553 | 67350 | case PART_2NxnU: | |
| 2554 | 67350 | hls_prediction_unit(lc, l, pps, sps, | |
| 2555 | x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx); | ||
| 2556 | 67350 | hls_prediction_unit(lc, l, pps, sps, | |
| 2557 | 67350 | x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx); | |
| 2558 | 67350 | break; | |
| 2559 | 58153 | case PART_2NxnD: | |
| 2560 | 58153 | hls_prediction_unit(lc, l, pps, sps, | |
| 2561 | 58153 | x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx); | |
| 2562 | 58153 | hls_prediction_unit(lc, l, pps, sps, | |
| 2563 | 58153 | x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx); | |
| 2564 | 58153 | break; | |
| 2565 | 100281 | case PART_nLx2N: | |
| 2566 | 100281 | hls_prediction_unit(lc, l, pps, sps, | |
| 2567 | x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2); | ||
| 2568 | 100281 | hls_prediction_unit(lc, l, pps, sps, | |
| 2569 | 100281 | x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2); | |
| 2570 | 100281 | break; | |
| 2571 | 85843 | case PART_nRx2N: | |
| 2572 | 85843 | hls_prediction_unit(lc, l, pps, sps, | |
| 2573 | 85843 | x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2); | |
| 2574 | 85843 | hls_prediction_unit(lc, l, pps, sps, | |
| 2575 | 85843 | x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2); | |
| 2576 | 85843 | break; | |
| 2577 | 108155 | case PART_NxN: | |
| 2578 | 108155 | hls_prediction_unit(lc, l, pps, sps, | |
| 2579 | x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1); | ||
| 2580 | 108155 | hls_prediction_unit(lc, l, pps, sps, | |
| 2581 | 108155 | x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1); | |
| 2582 | 108155 | hls_prediction_unit(lc, l, pps, sps, | |
| 2583 | 108155 | x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1); | |
| 2584 | 108155 | hls_prediction_unit(lc, l, pps, sps, | |
| 2585 | 108155 | x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1); | |
| 2586 | 108155 | break; | |
| 2587 | } | ||
| 2588 | } | ||
| 2589 | |||
| 2590 |
2/2✓ Branch 0 taken 7782698 times.
✓ Branch 1 taken 11207 times.
|
7793905 | if (!pcm_flag) { |
| 2591 | 7782698 | int rqt_root_cbf = 1; | |
| 2592 | |||
| 2593 |
2/2✓ Branch 0 taken 4109652 times.
✓ Branch 1 taken 3673046 times.
|
7782698 | if (lc->cu.pred_mode != MODE_INTRA && |
| 2594 |
4/4✓ Branch 0 taken 2573827 times.
✓ Branch 1 taken 1535825 times.
✓ Branch 2 taken 1365748 times.
✓ Branch 3 taken 1208079 times.
|
4109652 | !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) { |
| 2595 | 2901573 | rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc); | |
| 2596 | } | ||
| 2597 |
2/2✓ Branch 0 taken 6223977 times.
✓ Branch 1 taken 1558721 times.
|
7782698 | if (rqt_root_cbf) { |
| 2598 | const static int cbf[2] = { 0 }; | ||
| 2599 |
2/2✓ Branch 0 taken 3673046 times.
✓ Branch 1 taken 2550931 times.
|
6223977 | lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ? |
| 2600 | 3673046 | sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag : | |
| 2601 | 2550931 | sps->max_transform_hierarchy_depth_inter; | |
| 2602 | 6223977 | ret = hls_transform_tree(lc, l, pps, sps, x0, y0, x0, y0, x0, y0, | |
| 2603 | log2_cb_size, | ||
| 2604 | log2_cb_size, 0, 0, cbf, cbf); | ||
| 2605 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6223976 times.
|
6223977 | if (ret < 0) |
| 2606 | 1 | return ret; | |
| 2607 | } else { | ||
| 2608 |
2/2✓ Branch 0 taken 1502270 times.
✓ Branch 1 taken 56451 times.
|
1558721 | if (!s->sh.disable_deblocking_filter_flag) |
| 2609 | 1502270 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
| 2610 | } | ||
| 2611 | } | ||
| 2612 | } | ||
| 2613 | |||
| 2614 |
4/4✓ Branch 0 taken 3206812 times.
✓ Branch 1 taken 9311184 times.
✓ Branch 2 taken 1172355 times.
✓ Branch 3 taken 2034457 times.
|
12517996 | if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0) |
| 2615 | 1172355 | ff_hevc_set_qPy(lc, l, pps, x0, y0, log2_cb_size); | |
| 2616 | |||
| 2617 | 12517996 | x = y_cb * min_cb_width + x_cb; | |
| 2618 |
2/2✓ Branch 0 taken 24343198 times.
✓ Branch 1 taken 12517996 times.
|
36861194 | for (y = 0; y < length; y++) { |
| 2619 | 24343198 | memset(&l->qp_y_tab[x], lc->qp_y, length); | |
| 2620 | 24343198 | x += min_cb_width; | |
| 2621 | } | ||
| 2622 | |||
| 2623 |
2/2✓ Branch 0 taken 4588392 times.
✓ Branch 1 taken 7929604 times.
|
12517996 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
| 2624 |
2/2✓ Branch 0 taken 2769901 times.
✓ Branch 1 taken 1818491 times.
|
4588392 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) { |
| 2625 | 2769901 | lc->qPy_pred = lc->qp_y; | |
| 2626 | } | ||
| 2627 | |||
| 2628 | 12517996 | set_ct_depth(sps, l->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth); | |
| 2629 | |||
| 2630 | 12517996 | return 0; | |
| 2631 | } | ||
| 2632 | |||
| 2633 | 16191996 | static int hls_coding_quadtree(HEVCLocalContext *lc, | |
| 2634 | const HEVCLayerContext *l, | ||
| 2635 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2636 | int x0, int y0, | ||
| 2637 | int log2_cb_size, int cb_depth) | ||
| 2638 | { | ||
| 2639 | 16191996 | const HEVCContext *const s = lc->parent; | |
| 2640 | 16191996 | const int cb_size = 1 << log2_cb_size; | |
| 2641 | int ret; | ||
| 2642 | int split_cu; | ||
| 2643 | |||
| 2644 | 16191996 | lc->ct_depth = cb_depth; | |
| 2645 |
2/2✓ Branch 0 taken 16162798 times.
✓ Branch 1 taken 29198 times.
|
16191996 | if (x0 + cb_size <= sps->width && |
| 2646 |
2/2✓ Branch 0 taken 15824146 times.
✓ Branch 1 taken 338652 times.
|
16162798 | y0 + cb_size <= sps->height && |
| 2647 |
2/2✓ Branch 0 taken 8950583 times.
✓ Branch 1 taken 6873563 times.
|
15824146 | log2_cb_size > sps->log2_min_cb_size) { |
| 2648 | 8950583 | split_cu = ff_hevc_split_coding_unit_flag_decode(lc, l->tab_ct_depth, | |
| 2649 | sps, cb_depth, x0, y0); | ||
| 2650 | } else { | ||
| 2651 | 7241413 | split_cu = (log2_cb_size > sps->log2_min_cb_size); | |
| 2652 | } | ||
| 2653 |
2/2✓ Branch 0 taken 4063549 times.
✓ Branch 1 taken 12128447 times.
|
16191996 | if (pps->cu_qp_delta_enabled_flag && |
| 2654 |
2/2✓ Branch 0 taken 1887230 times.
✓ Branch 1 taken 2176319 times.
|
4063549 | log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) { |
| 2655 | 1887230 | lc->tu.is_cu_qp_delta_coded = 0; | |
| 2656 | 1887230 | lc->tu.cu_qp_delta = 0; | |
| 2657 | } | ||
| 2658 | |||
| 2659 |
2/2✓ Branch 0 taken 467556 times.
✓ Branch 1 taken 15724440 times.
|
16191996 | if (s->sh.cu_chroma_qp_offset_enabled_flag && |
| 2660 |
1/2✓ Branch 0 taken 467556 times.
✗ Branch 1 not taken.
|
467556 | log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_chroma_qp_offset_depth) { |
| 2661 | 467556 | lc->tu.is_cu_chroma_qp_offset_coded = 0; | |
| 2662 | } | ||
| 2663 | |||
| 2664 |
2/2✓ Branch 0 taken 3673999 times.
✓ Branch 1 taken 12517997 times.
|
16191996 | if (split_cu) { |
| 2665 | 3673999 | int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1; | |
| 2666 | 3673999 | const int cb_size_split = cb_size >> 1; | |
| 2667 | 3673999 | const int x1 = x0 + cb_size_split; | |
| 2668 | 3673999 | const int y1 = y0 + cb_size_split; | |
| 2669 | |||
| 2670 | 3673999 | int more_data = 0; | |
| 2671 | |||
| 2672 | 3673999 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
| 2673 | x0, y0, log2_cb_size - 1, cb_depth + 1); | ||
| 2674 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3673997 times.
|
3673999 | if (more_data < 0) |
| 2675 | 2 | return more_data; | |
| 2676 | |||
| 2677 |
4/4✓ Branch 0 taken 3673989 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 3646183 times.
✓ Branch 3 taken 27806 times.
|
3673997 | if (more_data && x1 < sps->width) { |
| 2678 | 3646183 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
| 2679 | x1, y0, log2_cb_size - 1, cb_depth + 1); | ||
| 2680 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3646183 times.
|
3646183 | if (more_data < 0) |
| 2681 | ✗ | return more_data; | |
| 2682 | } | ||
| 2683 |
4/4✓ Branch 0 taken 3663608 times.
✓ Branch 1 taken 10389 times.
✓ Branch 2 taken 3452833 times.
✓ Branch 3 taken 210775 times.
|
3673997 | if (more_data && y1 < sps->height) { |
| 2684 | 3452833 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
| 2685 | x0, y1, log2_cb_size - 1, cb_depth + 1); | ||
| 2686 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3452833 times.
|
3452833 | if (more_data < 0) |
| 2687 | ✗ | return more_data; | |
| 2688 | } | ||
| 2689 |
4/4✓ Branch 0 taken 3657493 times.
✓ Branch 1 taken 16504 times.
✓ Branch 2 taken 3635802 times.
✓ Branch 3 taken 21691 times.
|
3673997 | if (more_data && x1 < sps->width && |
| 2690 |
2/2✓ Branch 0 taken 3425027 times.
✓ Branch 1 taken 210775 times.
|
3635802 | y1 < sps->height) { |
| 2691 | 3425027 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
| 2692 | x1, y1, log2_cb_size - 1, cb_depth + 1); | ||
| 2693 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3425026 times.
|
3425027 | if (more_data < 0) |
| 2694 | 1 | return more_data; | |
| 2695 | } | ||
| 2696 | |||
| 2697 |
2/2✓ Branch 0 taken 2152345 times.
✓ Branch 1 taken 1521651 times.
|
3673996 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
| 2698 |
2/2✓ Branch 0 taken 1644099 times.
✓ Branch 1 taken 508246 times.
|
2152345 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) |
| 2699 | 1644099 | lc->qPy_pred = lc->qp_y; | |
| 2700 | |||
| 2701 |
2/2✓ Branch 0 taken 3638191 times.
✓ Branch 1 taken 35805 times.
|
3673996 | if (more_data) |
| 2702 |
2/2✓ Branch 0 taken 96004 times.
✓ Branch 1 taken 3542187 times.
|
3734195 | return ((x1 + cb_size_split) < sps->width || |
| 2703 |
2/2✓ Branch 0 taken 96003 times.
✓ Branch 1 taken 1 times.
|
96004 | (y1 + cb_size_split) < sps->height); |
| 2704 | else | ||
| 2705 | 35805 | return 0; | |
| 2706 | } else { | ||
| 2707 | 12517997 | ret = hls_coding_unit(lc, s, l, pps, sps, x0, y0, log2_cb_size); | |
| 2708 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 12517996 times.
|
12517997 | if (ret < 0) |
| 2709 | 1 | return ret; | |
| 2710 | 12517996 | if ((!((x0 + cb_size) % | |
| 2711 |
2/2✓ Branch 0 taken 8704952 times.
✓ Branch 1 taken 3813044 times.
|
12517996 | (1 << (sps->log2_ctb_size))) || |
| 2712 |
2/2✓ Branch 0 taken 69669 times.
✓ Branch 1 taken 8635283 times.
|
8704952 | (x0 + cb_size >= sps->width)) && |
| 2713 | 3882713 | (!((y0 + cb_size) % | |
| 2714 |
2/2✓ Branch 0 taken 1988942 times.
✓ Branch 1 taken 1893771 times.
|
3882713 | (1 << (sps->log2_ctb_size))) || |
| 2715 |
2/2✓ Branch 0 taken 100182 times.
✓ Branch 1 taken 1888760 times.
|
1988942 | (y0 + cb_size >= sps->height))) { |
| 2716 | 1993953 | int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc); | |
| 2717 | 1993953 | return !end_of_slice_flag; | |
| 2718 | } else { | ||
| 2719 | 10524043 | return 1; | |
| 2720 | } | ||
| 2721 | } | ||
| 2722 | |||
| 2723 | return 0; | ||
| 2724 | } | ||
| 2725 | |||
| 2726 | 2074564 | static void hls_decode_neighbour(HEVCLocalContext *lc, | |
| 2727 | const HEVCLayerContext *l, | ||
| 2728 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2729 | int x_ctb, int y_ctb, int ctb_addr_ts) | ||
| 2730 | { | ||
| 2731 | 2074564 | const HEVCContext *const s = lc->parent; | |
| 2732 | 2074564 | int ctb_size = 1 << sps->log2_ctb_size; | |
| 2733 | 2074564 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
| 2734 | 2074564 | int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr; | |
| 2735 | |||
| 2736 | /* the tile-parallel path pre-fills this serially, workers only read it */ | ||
| 2737 |
2/2✓ Branch 0 taken 2022004 times.
✓ Branch 1 taken 52560 times.
|
2074564 | if (!lc->tile_bs_defer) |
| 2738 | 2022004 | l->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr; | |
| 2739 | |||
| 2740 |
2/2✓ Branch 0 taken 168556 times.
✓ Branch 1 taken 1906008 times.
|
2074564 | if (pps->entropy_coding_sync_enabled_flag) { |
| 2741 |
3/4✓ Branch 0 taken 7942 times.
✓ Branch 1 taken 160614 times.
✓ Branch 2 taken 7942 times.
✗ Branch 3 not taken.
|
168556 | if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0) |
| 2742 | 7942 | lc->first_qp_group = 1; | |
| 2743 | 168556 | lc->end_of_tiles_x = sps->width; | |
| 2744 |
2/2✓ Branch 0 taken 788466 times.
✓ Branch 1 taken 1117542 times.
|
1906008 | } else if (pps->tiles_enabled_flag) { |
| 2745 |
4/4✓ Branch 0 taken 787450 times.
✓ Branch 1 taken 1016 times.
✓ Branch 2 taken 12741 times.
✓ Branch 3 taken 774709 times.
|
788466 | if (ctb_addr_ts && pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) { |
| 2746 | 12741 | int idxX = pps->col_idxX[x_ctb >> sps->log2_ctb_size]; | |
| 2747 | 12741 | lc->end_of_tiles_x = x_ctb + (pps->column_width[idxX] << sps->log2_ctb_size); | |
| 2748 | 12741 | lc->first_qp_group = 1; | |
| 2749 | } | ||
| 2750 | } else { | ||
| 2751 | 1117542 | lc->end_of_tiles_x = sps->width; | |
| 2752 | } | ||
| 2753 | |||
| 2754 | 2074564 | lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height); | |
| 2755 | |||
| 2756 | 2074564 | lc->boundary_flags = 0; | |
| 2757 |
2/2✓ Branch 0 taken 788466 times.
✓ Branch 1 taken 1286098 times.
|
2074564 | if (pps->tiles_enabled_flag) { |
| 2758 |
4/4✓ Branch 0 taken 766676 times.
✓ Branch 1 taken 21790 times.
✓ Branch 2 taken 58661 times.
✓ Branch 3 taken 708015 times.
|
788466 | if (x_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]]) |
| 2759 | 58661 | lc->boundary_flags |= BOUNDARY_LEFT_TILE; | |
| 2760 |
4/4✓ Branch 0 taken 766676 times.
✓ Branch 1 taken 21790 times.
✓ Branch 2 taken 15689 times.
✓ Branch 3 taken 750987 times.
|
788466 | if (x_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - 1]) |
| 2761 | 15689 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
| 2762 |
4/4✓ Branch 0 taken 758339 times.
✓ Branch 1 taken 30127 times.
✓ Branch 2 taken 63962 times.
✓ Branch 3 taken 694377 times.
|
788466 | 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]]) |
| 2763 | 63962 | lc->boundary_flags |= BOUNDARY_UPPER_TILE; | |
| 2764 |
4/4✓ Branch 0 taken 758339 times.
✓ Branch 1 taken 30127 times.
✓ Branch 2 taken 13570 times.
✓ Branch 3 taken 744769 times.
|
788466 | if (y_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - sps->ctb_width]) |
| 2765 | 13570 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
| 2766 | } else { | ||
| 2767 |
2/2✓ Branch 0 taken 18277 times.
✓ Branch 1 taken 1267821 times.
|
1286098 | if (ctb_addr_in_slice <= 0) |
| 2768 | 18277 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
| 2769 |
2/2✓ Branch 0 taken 196272 times.
✓ Branch 1 taken 1089826 times.
|
1286098 | if (ctb_addr_in_slice < sps->ctb_width) |
| 2770 | 196272 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
| 2771 | } | ||
| 2772 | |||
| 2773 |
6/6✓ Branch 0 taken 1983166 times.
✓ Branch 1 taken 91398 times.
✓ Branch 2 taken 1975077 times.
✓ Branch 3 taken 8089 times.
✓ Branch 4 taken 1917662 times.
✓ Branch 5 taken 57415 times.
|
2074564 | lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE)); |
| 2774 |
6/6✓ Branch 0 taken 1928242 times.
✓ Branch 1 taken 146322 times.
✓ Branch 2 taken 1835416 times.
✓ Branch 3 taken 92826 times.
✓ Branch 4 taken 1784203 times.
✓ Branch 5 taken 51213 times.
|
2074564 | lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE)); |
| 2775 |
6/6✓ Branch 0 taken 1928242 times.
✓ Branch 1 taken 146322 times.
✓ Branch 2 taken 1837963 times.
✓ Branch 3 taken 90279 times.
✓ Branch 4 taken 1720227 times.
✓ Branch 5 taken 117736 times.
|
2074564 | 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]])); |
| 2776 |
8/8✓ Branch 0 taken 1983166 times.
✓ Branch 1 taken 91398 times.
✓ Branch 2 taken 1847489 times.
✓ Branch 3 taken 135677 times.
✓ Branch 4 taken 1759451 times.
✓ Branch 5 taken 88038 times.
✓ Branch 6 taken 1662913 times.
✓ Branch 7 taken 96538 times.
|
2074564 | 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]])); |
| 2777 | 2074564 | } | |
| 2778 | |||
| 2779 | 28356 | static int hls_decode_entry(HEVCContext *s, GetBitContext *gb) | |
| 2780 | { | ||
| 2781 | 28356 | HEVCLocalContext *const lc = &s->local_ctx[0]; | |
| 2782 | 28356 | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
| 2783 | 28356 | const HEVCPPS *const pps = s->pps; | |
| 2784 | 28356 | const HEVCSPS *const sps = pps->sps; | |
| 2785 | 28356 | const uint8_t *slice_data = gb->buffer + s->sh.data_offset; | |
| 2786 | 28356 | const size_t slice_size = get_bits_bytesize(gb, 1) - s->sh.data_offset; | |
| 2787 | 28356 | int ctb_size = 1 << sps->log2_ctb_size; | |
| 2788 | 28356 | int more_data = 1; | |
| 2789 | 28356 | int x_ctb = 0; | |
| 2790 | 28356 | int y_ctb = 0; | |
| 2791 | 28356 | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
| 2792 | int ret; | ||
| 2793 | |||
| 2794 |
3/4✓ Branch 0 taken 1941394 times.
✓ Branch 1 taken 28355 times.
✓ Branch 2 taken 1941394 times.
✗ Branch 3 not taken.
|
1969749 | while (more_data && ctb_addr_ts < sps->ctb_size) { |
| 2795 | 1941394 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
| 2796 | |||
| 2797 | 1941394 | x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size; | |
| 2798 | 1941394 | y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size; | |
| 2799 | 1941394 | hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
| 2800 | |||
| 2801 | 1941394 | ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 0); | |
| 2802 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1941394 times.
|
1941394 | if (ret < 0) { |
| 2803 | ✗ | l->tab_slice_address[ctb_addr_rs] = -1; | |
| 2804 | ✗ | return ret; | |
| 2805 | } | ||
| 2806 | |||
| 2807 | 1941394 | hls_sao_param(lc, l, pps, sps, | |
| 2808 | 1941394 | x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); | |
| 2809 | |||
| 2810 | 1941394 | l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
| 2811 | 1941394 | l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
| 2812 | 1941394 | l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
| 2813 | |||
| 2814 | 1941394 | more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); | |
| 2815 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1941393 times.
|
1941394 | if (more_data < 0) { |
| 2816 | 1 | l->tab_slice_address[ctb_addr_rs] = -1; | |
| 2817 | 1 | return more_data; | |
| 2818 | } | ||
| 2819 | |||
| 2820 | |||
| 2821 | 1941393 | ctb_addr_ts++; | |
| 2822 | 1941393 | ff_hevc_save_states(lc, pps, ctb_addr_ts); | |
| 2823 | 1941393 | ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
| 2824 | } | ||
| 2825 | |||
| 2826 |
2/2✓ Branch 0 taken 14786 times.
✓ Branch 1 taken 13569 times.
|
28355 | if (x_ctb + ctb_size >= sps->width && |
| 2827 |
2/2✓ Branch 0 taken 10359 times.
✓ Branch 1 taken 4427 times.
|
14786 | y_ctb + ctb_size >= sps->height) |
| 2828 | 10359 | ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
| 2829 | |||
| 2830 | 28355 | return ctb_addr_ts; | |
| 2831 | } | ||
| 2832 | |||
| 2833 | ✗ | static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, | |
| 2834 | int job, int thread) | ||
| 2835 | { | ||
| 2836 | ✗ | HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread]; | |
| 2837 | ✗ | const HEVCContext *const s = lc->parent; | |
| 2838 | ✗ | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
| 2839 | ✗ | const HEVCPPS *const pps = s->pps; | |
| 2840 | ✗ | const HEVCSPS *const sps = pps->sps; | |
| 2841 | ✗ | int ctb_size = 1 << sps->log2_ctb_size; | |
| 2842 | ✗ | int more_data = 1; | |
| 2843 | ✗ | int ctb_row = job; | |
| 2844 | ✗ | int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size); | |
| 2845 | ✗ | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs]; | |
| 2846 | |||
| 2847 | ✗ | const uint8_t *data = s->data + s->sh.offset[ctb_row]; | |
| 2848 | ✗ | const size_t data_size = s->sh.size[ctb_row]; | |
| 2849 | |||
| 2850 | ✗ | int progress = 0; | |
| 2851 | |||
| 2852 | int ret; | ||
| 2853 | |||
| 2854 | ✗ | if (ctb_row) | |
| 2855 | ✗ | ff_init_cabac_decoder(&lc->cc, data, data_size); | |
| 2856 | |||
| 2857 | ✗ | while(more_data && ctb_addr_ts < sps->ctb_size) { | |
| 2858 | ✗ | int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size; | |
| 2859 | ✗ | int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size; | |
| 2860 | |||
| 2861 | ✗ | hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
| 2862 | |||
| 2863 | ✗ | if (ctb_row) | |
| 2864 | ✗ | ff_thread_progress_await(&s->wpp_progress[ctb_row - 1], | |
| 2865 | progress + SHIFT_CTB_WPP + 1); | ||
| 2866 | |||
| 2867 | /* atomic_load's prototype requires a pointer to non-const atomic variable | ||
| 2868 | * (due to implementations via mutexes, where reads involve writes). | ||
| 2869 | * Of course, casting const away here is nevertheless safe. */ | ||
| 2870 | ✗ | if (atomic_load((atomic_int*)&s->wpp_err)) { | |
| 2871 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2872 | ✗ | return 0; | |
| 2873 | } | ||
| 2874 | |||
| 2875 | ✗ | ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1); | |
| 2876 | ✗ | if (ret < 0) | |
| 2877 | ✗ | goto error; | |
| 2878 | ✗ | hls_sao_param(lc, l, pps, sps, | |
| 2879 | ✗ | x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); | |
| 2880 | |||
| 2881 | ✗ | l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
| 2882 | ✗ | l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
| 2883 | ✗ | l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
| 2884 | |||
| 2885 | ✗ | more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); | |
| 2886 | |||
| 2887 | ✗ | if (more_data < 0) { | |
| 2888 | ✗ | ret = more_data; | |
| 2889 | ✗ | goto error; | |
| 2890 | } | ||
| 2891 | |||
| 2892 | ✗ | ctb_addr_ts++; | |
| 2893 | |||
| 2894 | ✗ | ff_hevc_save_states(lc, pps, ctb_addr_ts); | |
| 2895 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], ++progress); | |
| 2896 | ✗ | ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
| 2897 | |||
| 2898 | ✗ | if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) { | |
| 2899 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
| 2900 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
| 2901 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2902 | ✗ | return 0; | |
| 2903 | } | ||
| 2904 | |||
| 2905 | ✗ | if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) { | |
| 2906 | ✗ | ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
| 2907 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2908 | ✗ | return ctb_addr_ts; | |
| 2909 | } | ||
| 2910 | ✗ | ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
| 2911 | ✗ | x_ctb+=ctb_size; | |
| 2912 | |||
| 2913 | ✗ | if(x_ctb >= sps->width) { | |
| 2914 | ✗ | break; | |
| 2915 | } | ||
| 2916 | } | ||
| 2917 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2918 | |||
| 2919 | ✗ | return 0; | |
| 2920 | ✗ | error: | |
| 2921 | ✗ | l->tab_slice_address[ctb_addr_rs] = -1; | |
| 2922 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
| 2923 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
| 2924 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2925 | ✗ | return ret; | |
| 2926 | } | ||
| 2927 | |||
| 2928 | ✗ | static int wpp_progress_init(HEVCContext *s, unsigned count) | |
| 2929 | { | ||
| 2930 | ✗ | if (s->nb_wpp_progress < count) { | |
| 2931 | ✗ | void *tmp = av_realloc_array(s->wpp_progress, count, | |
| 2932 | sizeof(*s->wpp_progress)); | ||
| 2933 | ✗ | if (!tmp) | |
| 2934 | ✗ | return AVERROR(ENOMEM); | |
| 2935 | |||
| 2936 | ✗ | s->wpp_progress = tmp; | |
| 2937 | ✗ | memset(s->wpp_progress + s->nb_wpp_progress, 0, | |
| 2938 | ✗ | (count - s->nb_wpp_progress) * sizeof(*s->wpp_progress)); | |
| 2939 | |||
| 2940 | ✗ | for (int i = s->nb_wpp_progress; i < count; i++) { | |
| 2941 | ✗ | int ret = ff_thread_progress_init(&s->wpp_progress[i], 1); | |
| 2942 | ✗ | if (ret < 0) | |
| 2943 | ✗ | return ret; | |
| 2944 | ✗ | s->nb_wpp_progress = i + 1; | |
| 2945 | } | ||
| 2946 | } | ||
| 2947 | |||
| 2948 | ✗ | for (int i = 0; i < count; i++) | |
| 2949 | ✗ | ff_thread_progress_reset(&s->wpp_progress[i]); | |
| 2950 | |||
| 2951 | ✗ | return 0; | |
| 2952 | } | ||
| 2953 | |||
| 2954 | 115 | static int alloc_local_ctxs(HEVCContext *s) | |
| 2955 | { | ||
| 2956 | HEVCLocalContext *tmp; | ||
| 2957 | |||
| 2958 |
2/2✓ Branch 0 taken 113 times.
✓ Branch 1 taken 2 times.
|
115 | if (s->avctx->thread_count <= s->nb_local_ctx) |
| 2959 | 113 | return 0; | |
| 2960 | |||
| 2961 | 2 | tmp = av_malloc_array(s->avctx->thread_count, sizeof(*s->local_ctx)); | |
| 2962 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!tmp) |
| 2963 | ✗ | return AVERROR(ENOMEM); | |
| 2964 | |||
| 2965 | 2 | memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx); | |
| 2966 | 2 | av_free(s->local_ctx); | |
| 2967 | 2 | s->local_ctx = tmp; | |
| 2968 | |||
| 2969 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
|
8 | for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) { |
| 2970 | 6 | tmp = &s->local_ctx[i]; | |
| 2971 | |||
| 2972 | 6 | memset(tmp, 0, sizeof(*tmp)); | |
| 2973 | |||
| 2974 | 6 | tmp->logctx = s->avctx; | |
| 2975 | 6 | tmp->parent = s; | |
| 2976 | 6 | tmp->common_cabac_state = &s->cabac; | |
| 2977 | } | ||
| 2978 | |||
| 2979 | 2 | s->nb_local_ctx = s->avctx->thread_count; | |
| 2980 | |||
| 2981 | 2 | return 0; | |
| 2982 | } | ||
| 2983 | |||
| 2984 | 115 | static int slice_substreams_init(HEVCContext *s, const H2645NAL *nal) | |
| 2985 | { | ||
| 2986 | 115 | int64_t offset, startheader, cmpt = 0; | |
| 2987 | int j; | ||
| 2988 | |||
| 2989 | 115 | offset = s->sh.data_offset; | |
| 2990 | |||
| 2991 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 115 times.
|
126 | for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) { |
| 2992 |
2/4✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
|
11 | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { |
| 2993 | ✗ | startheader--; | |
| 2994 | ✗ | cmpt++; | |
| 2995 | } | ||
| 2996 | } | ||
| 2997 | |||
| 2998 |
2/2✓ Branch 0 taken 2405 times.
✓ Branch 1 taken 115 times.
|
2520 | for (int i = 1; i < s->sh.num_entry_point_offsets; i++) { |
| 2999 | 2405 | offset += (s->sh.entry_point_offset[i - 1] - cmpt); | |
| 3000 | 2405 | for (j = 0, cmpt = 0, startheader = offset | |
| 3001 |
2/2✓ Branch 0 taken 253 times.
✓ Branch 1 taken 2405 times.
|
2658 | + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) { |
| 3002 |
4/4✓ Branch 0 taken 59 times.
✓ Branch 1 taken 194 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 48 times.
|
253 | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { |
| 3003 | 11 | startheader--; | |
| 3004 | 11 | cmpt++; | |
| 3005 | } | ||
| 3006 | } | ||
| 3007 | 2405 | s->sh.size[i] = s->sh.entry_point_offset[i] - cmpt; | |
| 3008 | 2405 | s->sh.offset[i] = offset; | |
| 3009 | |||
| 3010 | } | ||
| 3011 | |||
| 3012 | 115 | offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt; | |
| 3013 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
|
115 | if (nal->size < offset) { |
| 3014 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n"); | |
| 3015 | ✗ | return AVERROR_INVALIDDATA; | |
| 3016 | } | ||
| 3017 | 115 | s->sh.size [s->sh.num_entry_point_offsets] = nal->size - offset; | |
| 3018 | 115 | s->sh.offset[s->sh.num_entry_point_offsets] = offset; | |
| 3019 | |||
| 3020 | 115 | s->sh.offset[0] = s->sh.data_offset; | |
| 3021 | 115 | s->sh.size[0] = s->sh.offset[1] - s->sh.offset[0]; | |
| 3022 | |||
| 3023 | 115 | s->data = nal->data; | |
| 3024 | |||
| 3025 | 115 | return 0; | |
| 3026 | } | ||
| 3027 | |||
| 3028 | ✗ | static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) | |
| 3029 | { | ||
| 3030 | ✗ | const HEVCPPS *const pps = s->pps; | |
| 3031 | ✗ | const HEVCSPS *const sps = pps->sps; | |
| 3032 | int *ret; | ||
| 3033 | ✗ | int res = 0; | |
| 3034 | |||
| 3035 | ✗ | if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * (int64_t)sps->ctb_width >= sps->ctb_width * (int64_t)sps->ctb_height) { | |
| 3036 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n", | |
| 3037 | s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets, | ||
| 3038 | ✗ | sps->ctb_width, sps->ctb_height | |
| 3039 | ); | ||
| 3040 | ✗ | return AVERROR_INVALIDDATA; | |
| 3041 | } | ||
| 3042 | |||
| 3043 | ✗ | res = alloc_local_ctxs(s); | |
| 3044 | ✗ | if (res < 0) | |
| 3045 | ✗ | return res; | |
| 3046 | |||
| 3047 | ✗ | res = slice_substreams_init(s, nal); | |
| 3048 | ✗ | if (res < 0) | |
| 3049 | ✗ | return res; | |
| 3050 | |||
| 3051 | ✗ | for (unsigned i = 1; i < s->nb_local_ctx; i++) { | |
| 3052 | ✗ | s->local_ctx[i].first_qp_group = 1; | |
| 3053 | ✗ | s->local_ctx[i].qp_y = s->local_ctx[0].qp_y; | |
| 3054 | } | ||
| 3055 | |||
| 3056 | ✗ | atomic_store(&s->wpp_err, 0); | |
| 3057 | ✗ | res = wpp_progress_init(s, s->sh.num_entry_point_offsets + 1); | |
| 3058 | ✗ | if (res < 0) | |
| 3059 | ✗ | return res; | |
| 3060 | |||
| 3061 | ✗ | ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret)); | |
| 3062 | ✗ | if (!ret) | |
| 3063 | ✗ | return AVERROR(ENOMEM); | |
| 3064 | |||
| 3065 | ✗ | if (pps->entropy_coding_sync_enabled_flag) | |
| 3066 | ✗ | s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->local_ctx, ret, s->sh.num_entry_point_offsets + 1); | |
| 3067 | |||
| 3068 | ✗ | for (int i = 0; i <= s->sh.num_entry_point_offsets; i++) | |
| 3069 | ✗ | res += ret[i]; | |
| 3070 | |||
| 3071 | ✗ | av_free(ret); | |
| 3072 | ✗ | return res; | |
| 3073 | } | ||
| 3074 | |||
| 3075 | 2635 | static int hls_decode_entry_tile(AVCodecContext *avctx, void *hevc_lclist, | |
| 3076 | int job, int thread) | ||
| 3077 | { | ||
| 3078 | 2635 | HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread]; | |
| 3079 | 2635 | const HEVCContext *const s = lc->parent; | |
| 3080 | 2635 | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
| 3081 | 2635 | const HEVCPPS *const pps = s->pps; | |
| 3082 | 2635 | const HEVCSPS *const sps = pps->sps; | |
| 3083 | 2635 | const uint8_t *data = s->data + s->sh.offset[job]; | |
| 3084 | 2635 | const size_t data_size = s->sh.size[job]; | |
| 3085 | /* the slice covers every tile, so job and tile are the same index */ | ||
| 3086 | 2635 | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[pps->row_bd[job / pps->num_tile_columns] * sps->ctb_width + | |
| 3087 | 2635 | pps->col_bd[job % pps->num_tile_columns]]; | |
| 3088 | 2635 | int more_data = 1, ret; | |
| 3089 | |||
| 3090 | 2635 | lc->tile_bs_defer = 1; | |
| 3091 | 2635 | lc->tu.cu_qp_offset_cb = 0; | |
| 3092 | 2635 | lc->tu.cu_qp_offset_cr = 0; | |
| 3093 | /* hls_decode_neighbour() skips this for the first CTB of the picture */ | ||
| 3094 | 2635 | lc->end_of_tiles_x = pps->col_bd[job % pps->num_tile_columns + 1] << sps->log2_ctb_size; | |
| 3095 | |||
| 3096 |
3/4✓ Branch 0 taken 55080 times.
✓ Branch 1 taken 115 times.
✓ Branch 2 taken 55080 times.
✗ Branch 3 not taken.
|
55195 | while (more_data && ctb_addr_ts < sps->ctb_size && |
| 3097 |
2/2✓ Branch 0 taken 52560 times.
✓ Branch 1 taken 2520 times.
|
55080 | pps->tile_id[ctb_addr_ts] == job) { |
| 3098 | 52560 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
| 3099 | 52560 | int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size; | |
| 3100 | 52560 | int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size; | |
| 3101 | |||
| 3102 | 52560 | hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
| 3103 | |||
| 3104 | 52560 | ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1); | |
| 3105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52560 times.
|
52560 | if (ret < 0) |
| 3106 | ✗ | return ret; | |
| 3107 | |||
| 3108 | 52560 | hls_sao_param(lc, l, pps, sps, | |
| 3109 | 52560 | x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); | |
| 3110 | |||
| 3111 | 52560 | l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
| 3112 | 52560 | l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
| 3113 | 52560 | l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
| 3114 | |||
| 3115 | 52560 | more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); | |
| 3116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52560 times.
|
52560 | if (more_data < 0) |
| 3117 | ✗ | return more_data; | |
| 3118 | 52560 | ctb_addr_ts++; | |
| 3119 | } | ||
| 3120 | 2635 | return ctb_addr_ts; | |
| 3121 | } | ||
| 3122 | |||
| 3123 | 115 | static int hls_slice_data_tiles(HEVCContext *s, const H2645NAL *nal) | |
| 3124 | { | ||
| 3125 | 115 | const HEVCPPS *const pps = s->pps; | |
| 3126 | 115 | const HEVCSPS *const sps = pps->sps; | |
| 3127 | 115 | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
| 3128 | 115 | const int ctb_size = 1 << sps->log2_ctb_size; | |
| 3129 | 115 | const int nb_tiles = s->sh.num_entry_point_offsets + 1; | |
| 3130 | 115 | const int start_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
| 3131 | 115 | int res = 0, ctb_addr_ts, x_ctb = 0, y_ctb = 0; | |
| 3132 | int *ret; | ||
| 3133 | |||
| 3134 | 115 | res = alloc_local_ctxs(s); | |
| 3135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
|
115 | if (res < 0) |
| 3136 | ✗ | return res; | |
| 3137 | |||
| 3138 | 115 | res = slice_substreams_init(s, nal); | |
| 3139 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
|
115 | if (res < 0) |
| 3140 | ✗ | return res; | |
| 3141 | |||
| 3142 |
2/2✓ Branch 0 taken 345 times.
✓ Branch 1 taken 115 times.
|
460 | for (unsigned i = 1; i < s->nb_local_ctx; i++) { |
| 3143 | 345 | s->local_ctx[i].first_qp_group = 1; | |
| 3144 | 345 | s->local_ctx[i].qp_y = s->local_ctx[0].qp_y; | |
| 3145 | } | ||
| 3146 | |||
| 3147 |
2/2✓ Branch 0 taken 52560 times.
✓ Branch 1 taken 115 times.
|
52675 | for (ctb_addr_ts = start_ts; ctb_addr_ts < sps->ctb_size; ctb_addr_ts++) |
| 3148 | 52560 | l->tab_slice_address[pps->ctb_addr_ts_to_rs[ctb_addr_ts]] = s->sh.slice_addr; | |
| 3149 | |||
| 3150 | 115 | ret = av_calloc(nb_tiles, sizeof(*ret)); | |
| 3151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
|
115 | if (!ret) |
| 3152 | ✗ | return AVERROR(ENOMEM); | |
| 3153 | 115 | s->avctx->execute2(s->avctx, hls_decode_entry_tile, s->local_ctx, ret, nb_tiles); | |
| 3154 |
2/2✓ Branch 0 taken 2635 times.
✓ Branch 1 taken 115 times.
|
2750 | for (int i = 0; i < nb_tiles; i++) |
| 3155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2635 times.
|
2635 | if (ret[i] < 0) |
| 3156 | ✗ | res = ret[i]; | |
| 3157 | 115 | av_free(ret); | |
| 3158 | |||
| 3159 |
2/2✓ Branch 0 taken 460 times.
✓ Branch 1 taken 115 times.
|
575 | for (unsigned i = 0; i < s->nb_local_ctx; i++) |
| 3160 | 460 | s->local_ctx[i].tile_bs_defer = 0; | |
| 3161 | |||
| 3162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
|
115 | if (res < 0) |
| 3163 | ✗ | return res; | |
| 3164 | |||
| 3165 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 45 times.
|
115 | if (pps->loop_filter_across_tiles_enabled_flag && |
| 3166 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 15 times.
|
70 | !s->sh.disable_deblocking_filter_flag) { |
| 3167 |
2/2✓ Branch 0 taken 28050 times.
✓ Branch 1 taken 55 times.
|
28105 | for (ctb_addr_ts = start_ts; ctb_addr_ts < sps->ctb_size; ctb_addr_ts++) { |
| 3168 | 28050 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
| 3169 | 28050 | x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size; | |
| 3170 | 28050 | y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size; | |
| 3171 | 28050 | hls_decode_neighbour(&s->local_ctx[0], l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
| 3172 |
2/2✓ Branch 0 taken 9460 times.
✓ Branch 1 taken 18590 times.
|
28050 | if (s->local_ctx[0].boundary_flags & (BOUNDARY_LEFT_TILE | BOUNDARY_UPPER_TILE)) |
| 3173 | 9460 | ff_hevc_tile_boundary_bs(&s->local_ctx[0], l, pps, x_ctb, y_ctb); | |
| 3174 | } | ||
| 3175 | } | ||
| 3176 | |||
| 3177 |
2/2✓ Branch 0 taken 52560 times.
✓ Branch 1 taken 115 times.
|
52675 | for (ctb_addr_ts = start_ts; ctb_addr_ts < sps->ctb_size; ctb_addr_ts++) { |
| 3178 | 52560 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
| 3179 | 52560 | x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size; | |
| 3180 | 52560 | y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size; | |
| 3181 | 52560 | hls_decode_neighbour(&s->local_ctx[0], l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
| 3182 | 52560 | ff_hevc_hls_filters(&s->local_ctx[0], l, pps, x_ctb, y_ctb, ctb_size); | |
| 3183 | } | ||
| 3184 |
2/4✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115 times.
✗ Branch 3 not taken.
|
115 | if (x_ctb + ctb_size >= sps->width && y_ctb + ctb_size >= sps->height) |
| 3185 | 115 | ff_hevc_hls_filter(&s->local_ctx[0], l, pps, x_ctb, y_ctb, ctb_size); | |
| 3186 | |||
| 3187 | 115 | return sps->ctb_size; | |
| 3188 | } | ||
| 3189 | |||
| 3190 | 28583 | static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l, | |
| 3191 | const H2645NAL *nal, GetBitContext *gb) | ||
| 3192 | { | ||
| 3193 | 28583 | const HEVCPPS *pps = s->pps; | |
| 3194 | int ret; | ||
| 3195 | |||
| 3196 |
2/2✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10587 times.
|
28583 | if (!s->sh.first_slice_in_pic_flag) |
| 3197 | 17996 | s->slice_idx += !s->sh.dependent_slice_segment_flag; | |
| 3198 | |||
| 3199 |
4/4✓ Branch 0 taken 20789 times.
✓ Branch 1 taken 7794 times.
✓ Branch 2 taken 19778 times.
✓ Branch 3 taken 1011 times.
|
28583 | if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) { |
| 3200 | 19778 | ret = ff_hevc_slice_rpl(s); | |
| 3201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19778 times.
|
19778 | if (ret < 0) { |
| 3202 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
| 3203 | "Error constructing the reference lists for the current slice.\n"); | ||
| 3204 | ✗ | return ret; | |
| 3205 | } | ||
| 3206 | } | ||
| 3207 | |||
| 3208 | 28583 | s->slice_initialized = 1; | |
| 3209 | |||
| 3210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28583 times.
|
28583 | if (s->avctx->hwaccel) |
| 3211 | ✗ | return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size); | |
| 3212 | |||
| 3213 |
2/2✓ Branch 1 taken 112 times.
✓ Branch 2 taken 28471 times.
|
28583 | if (ff_decode_skip_all_pixels(s->avctx)) |
| 3214 | 112 | return 0; | |
| 3215 | |||
| 3216 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28471 times.
|
28471 | if (s->avctx->profile == AV_PROFILE_HEVC_SCC) { |
| 3217 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3218 | "SCC profile is not yet implemented in hevc native decoder.\n"); | ||
| 3219 | ✗ | return AVERROR_PATCHWELCOME; | |
| 3220 | } | ||
| 3221 | |||
| 3222 |
2/2✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 20677 times.
|
28471 | if (s->sh.dependent_slice_segment_flag) { |
| 3223 | 7794 | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
| 3224 | 7794 | int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1]; | |
| 3225 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7794 times.
|
7794 | if (l->tab_slice_address[prev_rs] != s->sh.slice_addr) { |
| 3226 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n"); | |
| 3227 | ✗ | return AVERROR_INVALIDDATA; | |
| 3228 | } | ||
| 3229 | } | ||
| 3230 | |||
| 3231 | 28471 | s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag; | |
| 3232 | |||
| 3233 |
2/2✓ Branch 0 taken 22962 times.
✓ Branch 1 taken 5509 times.
|
28471 | if (!pps->cu_qp_delta_enabled_flag) |
| 3234 | 22962 | s->local_ctx[0].qp_y = s->sh.slice_qp; | |
| 3235 | |||
| 3236 | 28471 | s->local_ctx[0].tu.cu_qp_offset_cb = 0; | |
| 3237 | 28471 | s->local_ctx[0].tu.cu_qp_offset_cr = 0; | |
| 3238 | |||
| 3239 |
2/2✓ Branch 0 taken 115 times.
✓ Branch 1 taken 28356 times.
|
28471 | if (s->avctx->active_thread_type == FF_THREAD_SLICE && |
| 3240 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | s->sh.num_entry_point_offsets > 0 && |
| 3241 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
115 | pps->num_tile_rows == 1 && pps->num_tile_columns == 1) |
| 3242 | ✗ | return hls_slice_data_wpp(s, nal); | |
| 3243 | |||
| 3244 |
2/2✓ Branch 0 taken 115 times.
✓ Branch 1 taken 28356 times.
|
28471 | if (s->avctx->active_thread_type == FF_THREAD_SLICE && |
| 3245 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | s->sh.num_entry_point_offsets > 0 && |
| 3246 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | pps->tiles_enabled_flag && |
| 3247 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | !pps->entropy_coding_sync_enabled_flag && |
| 3248 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | s->sh.first_slice_in_pic_flag && |
| 3249 |
1/2✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
|
115 | s->sh.num_entry_point_offsets + 1 == pps->num_tile_rows * pps->num_tile_columns) |
| 3250 | 115 | return hls_slice_data_tiles(s, nal); | |
| 3251 | |||
| 3252 | 28356 | return hls_decode_entry(s, gb); | |
| 3253 | } | ||
| 3254 | |||
| 3255 | 10587 | static int set_side_data(HEVCContext *s) | |
| 3256 | { | ||
| 3257 | 10587 | const HEVCSPS *sps = s->cur_frame->pps->sps; | |
| 3258 | 10587 | AVFrame *out = s->cur_frame->f; | |
| 3259 | int ret; | ||
| 3260 | |||
| 3261 | // Decrement the mastering display and content light level flag when IRAP | ||
| 3262 | // frame has no_rasl_output_flag=1 so the side data persists for the entire | ||
| 3263 | // coded video sequence. | ||
| 3264 |
5/6✓ Branch 0 taken 574 times.
✓ Branch 1 taken 10013 times.
✓ Branch 2 taken 574 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 280 times.
✓ Branch 5 taken 294 times.
|
10587 | if (IS_IRAP(s) && s->no_rasl_output_flag) { |
| 3265 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 264 times.
|
280 | if (s->sei.common.mastering_display.present > 0) |
| 3266 | 16 | s->sei.common.mastering_display.present--; | |
| 3267 | |||
| 3268 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 276 times.
|
280 | if (s->sei.common.content_light.present > 0) |
| 3269 | 4 | s->sei.common.content_light.present--; | |
| 3270 | } | ||
| 3271 | |||
| 3272 | 10587 | ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx, | |
| 3273 | &sps->vui.common, | ||
| 3274 | 10587 | sps->bit_depth, sps->bit_depth_chroma, | |
| 3275 | 10587 | s->cur_frame->poc /* no poc_offset in HEVC */); | |
| 3276 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (ret < 0) |
| 3277 | ✗ | return ret; | |
| 3278 | |||
| 3279 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10567 times.
|
10587 | if (s->sei.timecode.present) { |
| 3280 | uint32_t *tc_sd; | ||
| 3281 | char tcbuf[AV_TIMECODE_STR_SIZE]; | ||
| 3282 | AVFrameSideData *tcside; | ||
| 3283 | 20 | ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE, | |
| 3284 | sizeof(uint32_t) * 4, &tcside); | ||
| 3285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (ret < 0) |
| 3286 | ✗ | return ret; | |
| 3287 | |||
| 3288 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (tcside) { |
| 3289 | 20 | tc_sd = (uint32_t*)tcside->data; | |
| 3290 | 20 | tc_sd[0] = s->sei.timecode.num_clock_ts; | |
| 3291 | |||
| 3292 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | for (int i = 0; i < tc_sd[0]; i++) { |
| 3293 | 20 | int drop = s->sei.timecode.cnt_dropped_flag[i]; | |
| 3294 | 20 | int hh = s->sei.timecode.hours_value[i]; | |
| 3295 | 20 | int mm = s->sei.timecode.minutes_value[i]; | |
| 3296 | 20 | int ss = s->sei.timecode.seconds_value[i]; | |
| 3297 | 20 | int ff = s->sei.timecode.n_frames[i]; | |
| 3298 | |||
| 3299 | 20 | tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff); | |
| 3300 | 20 | av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0); | |
| 3301 | 20 | av_dict_set(&out->metadata, "timecode", tcbuf, 0); | |
| 3302 | } | ||
| 3303 | } | ||
| 3304 | |||
| 3305 | 20 | s->sei.timecode.num_clock_ts = 0; | |
| 3306 | } | ||
| 3307 | |||
| 3308 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10584 times.
|
10587 | if (s->sei.common.itut_t35.hdr_plus) { |
| 3309 | 3 | AVBufferRef *info_ref = av_buffer_ref(s->sei.common.itut_t35.hdr_plus); | |
| 3310 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!info_ref) |
| 3311 | ✗ | return AVERROR(ENOMEM); | |
| 3312 | |||
| 3313 | 3 | ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref); | |
| 3314 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (ret < 0) |
| 3315 | ✗ | return ret; | |
| 3316 | } | ||
| 3317 | |||
| 3318 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (s->sei.common.itut_t35.hdr_smpte2094_app5) { |
| 3319 | ✗ | AVBufferRef *info_ref = av_buffer_ref(s->sei.common.itut_t35.hdr_smpte2094_app5); | |
| 3320 | ✗ | if (!info_ref) | |
| 3321 | ✗ | return AVERROR(ENOMEM); | |
| 3322 | |||
| 3323 | ✗ | ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5, &info_ref); | |
| 3324 | ✗ | if (ret < 0) | |
| 3325 | ✗ | return ret; | |
| 3326 | } | ||
| 3327 | |||
| 3328 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10585 times.
|
10587 | if (s->rpu_buf) { |
| 3329 | 2 | AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf); | |
| 3330 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!rpu) |
| 3331 | ✗ | return AVERROR(ENOMEM); | |
| 3332 | |||
| 3333 | 2 | s->rpu_buf = NULL; | |
| 3334 | } | ||
| 3335 | |||
| 3336 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10587 times.
|
10587 | if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0) |
| 3337 | ✗ | return ret; | |
| 3338 | |||
| 3339 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10586 times.
|
10587 | if (s->sei.common.itut_t35.hdr_vivid) { |
| 3340 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!av_frame_side_data_add(&out->side_data, &out->nb_side_data, |
| 3341 | AV_FRAME_DATA_DYNAMIC_HDR_VIVID, | ||
| 3342 | &s->sei.common.itut_t35.hdr_vivid, | ||
| 3343 | AV_FRAME_SIDE_DATA_FLAG_NEW_REF)) | ||
| 3344 | ✗ | return AVERROR(ENOMEM); | |
| 3345 | } | ||
| 3346 | |||
| 3347 | 10587 | return 0; | |
| 3348 | } | ||
| 3349 | |||
| 3350 | 10197 | static int find_finish_setup_nal(const HEVCContext *s) | |
| 3351 | { | ||
| 3352 | 10197 | int nal_idx = 0; | |
| 3353 | |||
| 3354 |
2/2✓ Branch 0 taken 38640 times.
✓ Branch 1 taken 10197 times.
|
48837 | for (int i = nal_idx; i < s->pkt.nb_nals; i++) { |
| 3355 | 38640 | const H2645NAL *nal = &s->pkt.nals[i]; | |
| 3356 | 38640 | const int layer_id = nal->nuh_layer_id; | |
| 3357 | 38640 | GetBitContext gb = nal->gb; | |
| 3358 | |||
| 3359 |
2/4✓ Branch 0 taken 38640 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38640 times.
✗ Branch 3 not taken.
|
38640 | if (layer_id > HEVC_MAX_NUH_LAYER_ID || s->vps->layer_idx[layer_id] < 0 || |
| 3360 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38640 times.
|
38640 | !(s->layers_active_decode & (1 << s->vps->layer_idx[layer_id]))) |
| 3361 | 17996 | continue; | |
| 3362 | |||
| 3363 |
3/3✓ Branch 0 taken 28584 times.
✓ Branch 1 taken 1761 times.
✓ Branch 2 taken 8295 times.
|
38640 | switch (nal->type) { |
| 3364 | 28584 | case HEVC_NAL_TRAIL_R: | |
| 3365 | case HEVC_NAL_TRAIL_N: | ||
| 3366 | case HEVC_NAL_TSA_N: | ||
| 3367 | case HEVC_NAL_TSA_R: | ||
| 3368 | case HEVC_NAL_STSA_N: | ||
| 3369 | case HEVC_NAL_STSA_R: | ||
| 3370 | case HEVC_NAL_BLA_W_LP: | ||
| 3371 | case HEVC_NAL_BLA_W_RADL: | ||
| 3372 | case HEVC_NAL_BLA_N_LP: | ||
| 3373 | case HEVC_NAL_IDR_W_RADL: | ||
| 3374 | case HEVC_NAL_IDR_N_LP: | ||
| 3375 | case HEVC_NAL_CRA_NUT: | ||
| 3376 | case HEVC_NAL_RADL_N: | ||
| 3377 | case HEVC_NAL_RADL_R: | ||
| 3378 | case HEVC_NAL_RASL_N: | ||
| 3379 | case HEVC_NAL_RASL_R: | ||
| 3380 |
2/2✓ Branch 1 taken 17996 times.
✓ Branch 2 taken 10588 times.
|
28584 | if (!get_bits1(&gb)) // first_slice_segment_in_pic_flag |
| 3381 | 17996 | continue; | |
| 3382 | av_fallthrough; | ||
| 3383 | case HEVC_NAL_VPS: | ||
| 3384 | case HEVC_NAL_SPS: | ||
| 3385 | case HEVC_NAL_PPS: | ||
| 3386 | 12349 | nal_idx = i; | |
| 3387 | 12349 | break; | |
| 3388 | } | ||
| 3389 | } | ||
| 3390 | |||
| 3391 | 10197 | return nal_idx; | |
| 3392 | } | ||
| 3393 | |||
| 3394 | 10587 | static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, | |
| 3395 | unsigned nal_idx) | ||
| 3396 | { | ||
| 3397 | 10587 | const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id]; | |
| 3398 | 10587 | const HEVCSPS *const sps = pps->sps; | |
| 3399 | 10587 | int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) * | |
| 3400 | 10587 | ((sps->height >> sps->log2_min_cb_size) + 1); | |
| 3401 |
2/2✓ Branch 0 taken 10197 times.
✓ Branch 1 taken 390 times.
|
20784 | int new_sequence = (l == &s->layers[0]) && |
| 3402 |
12/12✓ Branch 0 taken 9987 times.
✓ Branch 1 taken 210 times.
✓ Branch 2 taken 9949 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 9947 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9940 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9939 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 17 times.
✓ Branch 11 taken 9922 times.
|
10197 | (IS_IDR(s) || IS_BLA(s) || s->last_eos); |
| 3403 | 10587 | int prev_layers_active_decode = s->layers_active_decode; | |
| 3404 | 10587 | int prev_layers_active_output = s->layers_active_output; | |
| 3405 | int ret; | ||
| 3406 | |||
| 3407 |
3/4✓ Branch 0 taken 242 times.
✓ Branch 1 taken 10345 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 242 times.
|
10587 | if (sps->vps != s->vps && l != &s->layers[0]) { |
| 3408 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n"); | |
| 3409 | ✗ | set_sps(s, l, NULL); | |
| 3410 | ✗ | return AVERROR_INVALIDDATA; | |
| 3411 | } | ||
| 3412 | |||
| 3413 |
5/6✓ Branch 0 taken 390 times.
✓ Branch 1 taken 10197 times.
✓ Branch 3 taken 50 times.
✓ Branch 4 taken 340 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 50 times.
|
10587 | if (l != &s->layers[0] && ff_hevc_is_alpha_video(s) && !s->layers[0].cur_frame) { |
| 3414 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Alpha layer frame without a base layer frame\n"); | |
| 3415 | ✗ | return AVERROR_INVALIDDATA; | |
| 3416 | } | ||
| 3417 | |||
| 3418 | 10587 | av_refstruct_replace(&s->pps, pps); | |
| 3419 |
2/2✓ Branch 0 taken 260 times.
✓ Branch 1 taken 10327 times.
|
10587 | if (l->sps != sps) { |
| 3420 | 260 | const HEVCSPS *sps_base = s->layers[0].sps; | |
| 3421 | 260 | enum AVPixelFormat pix_fmt = sps->pix_fmt; | |
| 3422 | |||
| 3423 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 250 times.
|
260 | if (l != &s->layers[0]) { |
| 3424 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (!sps_base) { |
| 3425 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3426 | "Access unit starts with a non-base layer frame\n"); | ||
| 3427 | ✗ | return AVERROR_INVALIDDATA; | |
| 3428 | } | ||
| 3429 | |||
| 3430 | // Files produced by Vision Pro lack VPS extension VUI, | ||
| 3431 | // so the secondary layer has no range information. | ||
| 3432 | // This check avoids failing in such a case. | ||
| 3433 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (sps_base->pix_fmt == AV_PIX_FMT_YUVJ420P && |
| 3434 | ✗ | sps->pix_fmt == AV_PIX_FMT_YUV420P && | |
| 3435 | ✗ | !sps->vui.common.video_signal_type_present_flag) | |
| 3436 | ✗ | pix_fmt = sps_base->pix_fmt; | |
| 3437 | |||
| 3438 | // Ignore range mismatch between base layer and alpha layer | ||
| 3439 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
|
10 | if (ff_hevc_is_alpha_video(s) && |
| 3440 |
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 && |
| 3441 | pix_fmt == AV_PIX_FMT_YUVJ420P) | ||
| 3442 | 1 | pix_fmt = sps_base->pix_fmt; | |
| 3443 | |||
| 3444 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | if (pix_fmt != sps_base->pix_fmt || |
| 3445 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | sps->width != sps_base->width || |
| 3446 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | sps->height != sps_base->height) { |
| 3447 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3448 | "Base/non-base layer SPS have unsupported parameter combination\n"); | ||
| 3449 | ✗ | return AVERROR(ENOSYS); | |
| 3450 | } | ||
| 3451 | } | ||
| 3452 | |||
| 3453 | 260 | ff_hevc_clear_refs(l); | |
| 3454 | |||
| 3455 | 260 | ret = set_sps(s, l, sps); | |
| 3456 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 260 times.
|
260 | if (ret < 0) |
| 3457 | ✗ | return ret; | |
| 3458 | |||
| 3459 |
2/2✓ Branch 0 taken 250 times.
✓ Branch 1 taken 10 times.
|
260 | if (l == &s->layers[0]) { |
| 3460 | 250 | export_stream_params(s, sps); | |
| 3461 | |||
| 3462 | 250 | ret = get_format(s, sps); | |
| 3463 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 250 times.
|
250 | if (ret < 0) { |
| 3464 | ✗ | set_sps(s, l, NULL); | |
| 3465 | ✗ | return ret; | |
| 3466 | } | ||
| 3467 | |||
| 3468 | 250 | new_sequence = 1; | |
| 3469 | } | ||
| 3470 | } | ||
| 3471 | |||
| 3472 | 10587 | memset(l->horizontal_bs, 0, l->bs_width * l->bs_height); | |
| 3473 | 10587 | memset(l->vertical_bs, 0, l->bs_width * l->bs_height); | |
| 3474 | 10587 | memset(l->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height); | |
| 3475 | 10587 | memset(l->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1)); | |
| 3476 | 10587 | memset(l->tab_slice_address, -1, pic_size_in_ctb * sizeof(*l->tab_slice_address)); | |
| 3477 | |||
| 3478 |
4/4✓ Branch 0 taken 10368 times.
✓ Branch 1 taken 219 times.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 10325 times.
|
10587 | if (IS_IDR(s)) |
| 3479 | 262 | ff_hevc_clear_refs(l); | |
| 3480 | |||
| 3481 | 10587 | s->slice_idx = 0; | |
| 3482 | 10587 | s->first_nal_type = s->nal_unit_type; | |
| 3483 | 10587 | s->poc = s->sh.poc; | |
| 3484 | |||
| 3485 |
3/4✓ Branch 0 taken 574 times.
✓ Branch 1 taken 10013 times.
✓ Branch 2 taken 574 times.
✗ Branch 3 not taken.
|
10587 | if (IS_IRAP(s)) { |
| 3486 |
10/10✓ Branch 0 taken 355 times.
✓ Branch 1 taken 219 times.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 43 times.
✓ Branch 4 taken 310 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 303 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 302 times.
✓ Branch 9 taken 1 times.
|
876 | s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || |
| 3487 |
3/4✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 294 times.
|
302 | (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos); |
| 3488 | 574 | s->recovery_poc = HEVC_RECOVERY_END; | |
| 3489 | } | ||
| 3490 | |||
| 3491 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10567 times.
|
10587 | if (s->recovery_poc != HEVC_RECOVERY_END && |
| 3492 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | s->sei.recovery_point.has_recovery_poc) { |
| 3493 | ✗ | if (s->recovery_poc == HEVC_RECOVERY_UNSPECIFIED) | |
| 3494 | ✗ | s->recovery_poc = s->poc + s->sei.recovery_point.recovery_poc_cnt; | |
| 3495 | ✗ | else if (s->poc >= s->recovery_poc) | |
| 3496 | ✗ | s->recovery_poc = HEVC_RECOVERY_END; | |
| 3497 | } | ||
| 3498 | |||
| 3499 | /* 8.3.1 */ | ||
| 3500 |
2/2✓ Branch 0 taken 10245 times.
✓ Branch 1 taken 342 times.
|
10587 | if (s->temporal_id == 0 && |
| 3501 |
2/2✓ Branch 0 taken 7472 times.
✓ Branch 1 taken 2773 times.
|
10245 | s->nal_unit_type != HEVC_NAL_TRAIL_N && |
| 3502 |
1/2✓ Branch 0 taken 7472 times.
✗ Branch 1 not taken.
|
7472 | s->nal_unit_type != HEVC_NAL_TSA_N && |
| 3503 |
1/2✓ Branch 0 taken 7472 times.
✗ Branch 1 not taken.
|
7472 | s->nal_unit_type != HEVC_NAL_STSA_N && |
| 3504 |
2/2✓ Branch 0 taken 7446 times.
✓ Branch 1 taken 26 times.
|
7472 | s->nal_unit_type != HEVC_NAL_RADL_N && |
| 3505 |
2/2✓ Branch 0 taken 7424 times.
✓ Branch 1 taken 22 times.
|
7446 | s->nal_unit_type != HEVC_NAL_RADL_R && |
| 3506 |
2/2✓ Branch 0 taken 7038 times.
✓ Branch 1 taken 386 times.
|
7424 | s->nal_unit_type != HEVC_NAL_RASL_N && |
| 3507 |
2/2✓ Branch 0 taken 6561 times.
✓ Branch 1 taken 477 times.
|
7038 | s->nal_unit_type != HEVC_NAL_RASL_R) |
| 3508 | 6561 | s->poc_tid0 = s->poc; | |
| 3509 | |||
| 3510 |
2/2✓ Branch 0 taken 846 times.
✓ Branch 1 taken 9741 times.
|
10587 | if (pps->tiles_enabled_flag) |
| 3511 | 846 | s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size; | |
| 3512 | |||
| 3513 |
2/2✓ Branch 0 taken 275 times.
✓ Branch 1 taken 10312 times.
|
10587 | if (new_sequence) { |
| 3514 | 275 | ret = ff_hevc_output_frames(s, prev_layers_active_decode, prev_layers_active_output, | |
| 3515 | 275 | 0, 0, s->sh.no_output_of_prior_pics_flag); | |
| 3516 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 275 times.
|
275 | if (ret < 0) |
| 3517 | ✗ | return ret; | |
| 3518 | } | ||
| 3519 | |||
| 3520 | 10587 | ret = export_stream_params_from_sei(s); | |
| 3521 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (ret < 0) |
| 3522 | ✗ | return ret; | |
| 3523 | |||
| 3524 | 10587 | ret = ff_hevc_set_new_ref(s, l, s->poc); | |
| 3525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (ret < 0) |
| 3526 | ✗ | goto fail; | |
| 3527 | |||
| 3528 | 10587 | ret = ff_hevc_frame_rps(s, l); | |
| 3529 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (ret < 0) { |
| 3530 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n"); | |
| 3531 | ✗ | goto fail; | |
| 3532 | } | ||
| 3533 | |||
| 3534 |
3/4✓ Branch 0 taken 574 times.
✓ Branch 1 taken 10013 times.
✓ Branch 2 taken 574 times.
✗ Branch 3 not taken.
|
10587 | if (IS_IRAP(s)) |
| 3535 | 574 | s->cur_frame->f->flags |= AV_FRAME_FLAG_KEY; | |
| 3536 | else | ||
| 3537 | 10013 | s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY; | |
| 3538 | |||
| 3539 | 21174 | s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics && | |
| 3540 | ✗ | s->sei.common.film_grain_characteristics->present) || | |
| 3541 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | s->sei.common.itut_t35.aom_film_grain.enable) && |
| 3542 | ✗ | !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && | |
| 3543 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
21174 | !ff_decode_skip_all_pixels(s->avctx) && |
| 3544 | ✗ | !s->avctx->hwaccel; | |
| 3545 | |||
| 3546 | 10587 | ret = set_side_data(s); | |
| 3547 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (ret < 0) |
| 3548 | ✗ | goto fail; | |
| 3549 | |||
| 3550 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (s->cur_frame->needs_fg && |
| 3551 | ✗ | (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present && | |
| 3552 | ✗ | !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id, | |
| 3553 | ✗ | s->cur_frame->f->format) || | |
| 3554 | ✗ | !av_film_grain_params_select(s->cur_frame->f))) { | |
| 3555 | ✗ | av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown, | |
| 3556 | "Unsupported film grain parameters. Ignoring film grain.\n"); | ||
| 3557 | ✗ | s->cur_frame->needs_fg = 0; | |
| 3558 | } | ||
| 3559 | |||
| 3560 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (s->cur_frame->needs_fg) { |
| 3561 | ✗ | s->cur_frame->frame_grain->format = s->cur_frame->f->format; | |
| 3562 | ✗ | s->cur_frame->frame_grain->width = s->cur_frame->f->width; | |
| 3563 | ✗ | s->cur_frame->frame_grain->height = s->cur_frame->f->height; | |
| 3564 | ✗ | if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0) | |
| 3565 | ✗ | goto fail; | |
| 3566 | |||
| 3567 | ✗ | ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f); | |
| 3568 | ✗ | if (ret < 0) | |
| 3569 | ✗ | goto fail; | |
| 3570 | } | ||
| 3571 | |||
| 3572 | 10587 | s->cur_frame->f->pict_type = 3 - s->sh.slice_type; | |
| 3573 | |||
| 3574 | 10587 | ret = ff_hevc_output_frames(s, s->layers_active_decode, s->layers_active_output, | |
| 3575 | 10587 | sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics, | |
| 3576 | 10587 | sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0); | |
| 3577 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (ret < 0) |
| 3578 | ✗ | goto fail; | |
| 3579 | |||
| 3580 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (s->avctx->hwaccel) { |
| 3581 | ✗ | AVCodecInternal *avci = s->avctx->internal; | |
| 3582 | ✗ | AVPacket *avpkt = avci->in_pkt; | |
| 3583 | ✗ | ret = FF_HW_CALL(s->avctx, start_frame, | |
| 3584 | avpkt->buf, NULL, 0); | ||
| 3585 | ✗ | if (ret < 0) | |
| 3586 | ✗ | goto fail; | |
| 3587 | } | ||
| 3588 | |||
| 3589 | // after starting the base-layer frame we know which layers will be decoded, | ||
| 3590 | // so we can now figure out which NALUs to wait for before we can call | ||
| 3591 | // ff_thread_finish_setup() | ||
| 3592 |
2/2✓ Branch 0 taken 10197 times.
✓ Branch 1 taken 390 times.
|
10587 | if (l == &s->layers[0]) |
| 3593 | 10197 | s->finish_setup_nal_idx = find_finish_setup_nal(s); | |
| 3594 | |||
| 3595 |
2/2✓ Branch 0 taken 10196 times.
✓ Branch 1 taken 391 times.
|
10587 | if (nal_idx >= s->finish_setup_nal_idx) |
| 3596 | 10196 | ff_thread_finish_setup(s->avctx); | |
| 3597 | |||
| 3598 | 10587 | return 0; | |
| 3599 | |||
| 3600 | ✗ | fail: | |
| 3601 | ✗ | if (l->cur_frame) | |
| 3602 | ✗ | ff_hevc_unref_frame(l->cur_frame, ~0); | |
| 3603 | ✗ | l->cur_frame = NULL; | |
| 3604 | ✗ | s->cur_frame = s->collocated_ref = NULL; | |
| 3605 | ✗ | return ret; | |
| 3606 | } | ||
| 3607 | |||
| 3608 | ✗ | static int verify_md5(HEVCContext *s, AVFrame *frame) | |
| 3609 | { | ||
| 3610 | ✗ | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); | |
| 3611 | char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)]; | ||
| 3612 | int pixel_shift; | ||
| 3613 | ✗ | int err = 0; | |
| 3614 | int i, j; | ||
| 3615 | |||
| 3616 | ✗ | if (!desc) | |
| 3617 | ✗ | return AVERROR(EINVAL); | |
| 3618 | |||
| 3619 | ✗ | pixel_shift = desc->comp[0].depth > 8; | |
| 3620 | |||
| 3621 | /* the checksums are LE, so we have to byteswap for >8bpp formats | ||
| 3622 | * on BE arches */ | ||
| 3623 | #if HAVE_BIGENDIAN | ||
| 3624 | if (pixel_shift && !s->checksum_buf) { | ||
| 3625 | av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size, | ||
| 3626 | FFMAX3(frame->linesize[0], frame->linesize[1], | ||
| 3627 | frame->linesize[2])); | ||
| 3628 | if (!s->checksum_buf) | ||
| 3629 | return AVERROR(ENOMEM); | ||
| 3630 | } | ||
| 3631 | #endif | ||
| 3632 | |||
| 3633 | ✗ | msg_buf[0] = '\0'; | |
| 3634 | ✗ | for (i = 0; frame->data[i]; i++) { | |
| 3635 | ✗ | int width = s->avctx->coded_width; | |
| 3636 | ✗ | int height = s->avctx->coded_height; | |
| 3637 | ✗ | int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width; | |
| 3638 | ✗ | int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height; | |
| 3639 | uint8_t md5[16]; | ||
| 3640 | |||
| 3641 | ✗ | av_md5_init(s->md5_ctx); | |
| 3642 | ✗ | for (j = 0; j < h; j++) { | |
| 3643 | ✗ | const uint8_t *src = frame->data[i] + j * frame->linesize[i]; | |
| 3644 | #if HAVE_BIGENDIAN | ||
| 3645 | if (pixel_shift) { | ||
| 3646 | s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf, | ||
| 3647 | (const uint16_t *) src, w); | ||
| 3648 | src = s->checksum_buf; | ||
| 3649 | } | ||
| 3650 | #endif | ||
| 3651 | ✗ | av_md5_update(s->md5_ctx, src, w << pixel_shift); | |
| 3652 | } | ||
| 3653 | ✗ | av_md5_final(s->md5_ctx, md5); | |
| 3654 | |||
| 3655 | #define MD5_PRI "%016" PRIx64 "%016" PRIx64 | ||
| 3656 | #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8) | ||
| 3657 | |||
| 3658 | ✗ | if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) { | |
| 3659 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
| 3660 | "plane %d - correct " MD5_PRI "; ", | ||
| 3661 | ✗ | i, MD5_PRI_ARG(md5)); | |
| 3662 | } else { | ||
| 3663 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
| 3664 | "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ", | ||
| 3665 | ✗ | i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i])); | |
| 3666 | ✗ | err = AVERROR_INVALIDDATA; | |
| 3667 | } | ||
| 3668 | } | ||
| 3669 | |||
| 3670 | ✗ | av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG, | |
| 3671 | "Verifying checksum for frame with POC %d: %s\n", | ||
| 3672 | s->poc, msg_buf); | ||
| 3673 | |||
| 3674 | ✗ | return err; | |
| 3675 | } | ||
| 3676 | |||
| 3677 | 10587 | static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l) | |
| 3678 | { | ||
| 3679 | 10587 | HEVCFrame *out = l->cur_frame; | |
| 3680 | const AVFilmGrainParams *fgp; | ||
| 3681 | av_unused int ret; | ||
| 3682 | |||
| 3683 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (out->needs_fg) { |
| 3684 | ✗ | av_assert0(out->frame_grain->buf[0]); | |
| 3685 | ✗ | fgp = av_film_grain_params_select(out->f); | |
| 3686 | ✗ | switch (fgp->type) { | |
| 3687 | ✗ | case AV_FILM_GRAIN_PARAMS_NONE: | |
| 3688 | ✗ | av_assert0(0); | |
| 3689 | return AVERROR_BUG; | ||
| 3690 | ✗ | case AV_FILM_GRAIN_PARAMS_H274: | |
| 3691 | ✗ | ret = ff_h274_apply_film_grain(out->frame_grain, out->f, fgp); | |
| 3692 | ✗ | break; | |
| 3693 | ✗ | case AV_FILM_GRAIN_PARAMS_AV1: | |
| 3694 | ✗ | ret = ff_aom_apply_film_grain(out->frame_grain, out->f, fgp); | |
| 3695 | ✗ | break; | |
| 3696 | } | ||
| 3697 | av_assert1(ret >= 0); | ||
| 3698 | } | ||
| 3699 | |||
| 3700 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (s->avctx->hwaccel) { |
| 3701 | ✗ | ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame); | |
| 3702 | ✗ | if (ret < 0) { | |
| 3703 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3704 | "hardware accelerator failed to decode picture\n"); | ||
| 3705 | ✗ | return ret; | |
| 3706 | } | ||
| 3707 | } else { | ||
| 3708 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (s->avctx->err_recognition & AV_EF_CRCCHECK && |
| 3709 | ✗ | s->sei.picture_hash.is_md5) { | |
| 3710 | ✗ | ret = verify_md5(s, out->f); | |
| 3711 | ✗ | if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) | |
| 3712 | ✗ | return ret; | |
| 3713 | } | ||
| 3714 | } | ||
| 3715 | 10587 | s->sei.picture_hash.is_md5 = 0; | |
| 3716 | |||
| 3717 | 10587 | av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %zu/%d.\n", | |
| 3718 | 10587 | l - s->layers, s->poc); | |
| 3719 | |||
| 3720 | 10587 | return 0; | |
| 3721 | } | ||
| 3722 | |||
| 3723 | 29153 | static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb) | |
| 3724 | { | ||
| 3725 |
2/2✓ Branch 0 taken 28917 times.
✓ Branch 1 taken 236 times.
|
29153 | const int layer_idx = s->vps ? s->vps->layer_idx[s->nuh_layer_id] : 0; |
| 3726 | HEVCLayerContext *l; | ||
| 3727 | int ret; | ||
| 3728 | |||
| 3729 | // skip layers not requested to be decoded | ||
| 3730 | // layers_active_decode can only change while decoding a base-layer frame, | ||
| 3731 | // so we can check it for non-base layers | ||
| 3732 |
1/2✓ Branch 0 taken 29153 times.
✗ Branch 1 not taken.
|
29153 | if (layer_idx < 0 || |
| 3733 |
3/4✓ Branch 0 taken 516 times.
✓ Branch 1 taken 28637 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 516 times.
|
29153 | (s->nuh_layer_id > 0 && !(s->layers_active_decode & (1 << layer_idx)))) |
| 3734 | ✗ | return 0; | |
| 3735 | |||
| 3736 | // the first slice of this picture was skipped, so drop the remaining | ||
| 3737 | // slices before parsing, the context is stale for them | ||
| 3738 |
4/4✓ Branch 0 taken 566 times.
✓ Branch 1 taken 28587 times.
✓ Branch 3 taken 486 times.
✓ Branch 4 taken 80 times.
|
29153 | if (s->skipping_frame && !show_bits1(gb)) |
| 3739 | 486 | return 0; | |
| 3740 | |||
| 3741 | 28667 | ret = hls_slice_header(&s->sh, s, gb); | |
| 3742 | // Once hls_slice_header has been called, the context is inconsistent with the slice header | ||
| 3743 | // until the context is reinitialized according to the contents of the new slice header | ||
| 3744 | // at the start of decode_slice_data. | ||
| 3745 | 28667 | s->slice_initialized = 0; | |
| 3746 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28667 times.
|
28667 | if (ret < 0) { |
| 3747 | ✗ | return ret; | |
| 3748 | } | ||
| 3749 | |||
| 3750 |
4/4✓ Branch 0 taken 81 times.
✓ Branch 1 taken 28586 times.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 26 times.
|
28667 | if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) || |
| 3751 |
4/4✓ Branch 0 taken 55 times.
✓ Branch 1 taken 28586 times.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 1 times.
|
28641 | (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) || |
| 3752 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 28640 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
28640 | (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) || |
| 3753 |
4/4✓ Branch 0 taken 27506 times.
✓ Branch 1 taken 1134 times.
✓ Branch 2 taken 1067 times.
✓ Branch 3 taken 26439 times.
|
28640 | ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) && |
| 3754 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 2145 times.
|
2201 | s->no_rasl_output_flag)) { |
| 3755 |
1/2✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
|
83 | if (s->sh.first_slice_in_pic_flag) |
| 3756 | 83 | s->skipping_frame = 1; | |
| 3757 | 83 | return 0; | |
| 3758 | } | ||
| 3759 |
2/2✓ Branch 0 taken 10588 times.
✓ Branch 1 taken 17996 times.
|
28584 | if (s->sh.first_slice_in_pic_flag) |
| 3760 | 10588 | s->skipping_frame = 0; | |
| 3761 | |||
| 3762 | // switching to a new layer, mark previous layer's frame (if any) as done | ||
| 3763 |
2/2✓ Branch 0 taken 771 times.
✓ Branch 1 taken 27813 times.
|
28584 | if (s->cur_layer != layer_idx && |
| 3764 |
2/2✓ Branch 0 taken 390 times.
✓ Branch 1 taken 381 times.
|
771 | s->layers[s->cur_layer].cur_frame && |
| 3765 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
|
390 | s->avctx->active_thread_type == FF_THREAD_FRAME) |
| 3766 | ✗ | ff_progress_frame_report(&s->layers[s->cur_layer].cur_frame->tf, INT_MAX); | |
| 3767 | |||
| 3768 | 28584 | s->cur_layer = layer_idx; | |
| 3769 | 28584 | l = &s->layers[s->cur_layer]; | |
| 3770 | |||
| 3771 |
2/2✓ Branch 0 taken 10588 times.
✓ Branch 1 taken 17996 times.
|
28584 | if (s->sh.first_slice_in_pic_flag) { |
| 3772 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10587 times.
|
10588 | if (l->cur_frame) { |
| 3773 | 1 | av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n"); | |
| 3774 | 1 | return AVERROR_INVALIDDATA; | |
| 3775 | } | ||
| 3776 | |||
| 3777 | 10587 | ret = hevc_frame_start(s, l, nal_idx); | |
| 3778 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10587 times.
|
10587 | if (ret < 0) |
| 3779 | ✗ | return ret; | |
| 3780 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17996 times.
|
17996 | } else if (!l->cur_frame) { |
| 3781 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n"); | |
| 3782 | ✗ | return AVERROR_INVALIDDATA; | |
| 3783 | } | ||
| 3784 | |||
| 3785 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28583 times.
|
28583 | if (s->nal_unit_type != s->first_nal_type) { |
| 3786 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3787 | "Non-matching NAL types of the VCL NALUs: %d %d\n", | ||
| 3788 | ✗ | s->first_nal_type, s->nal_unit_type); | |
| 3789 | ✗ | return AVERROR_INVALIDDATA; | |
| 3790 | } | ||
| 3791 | |||
| 3792 | 28583 | ret = decode_slice_data(s, l, &s->pkt.nals[nal_idx], gb); | |
| 3793 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28582 times.
|
28583 | if (ret < 0) |
| 3794 | 1 | return ret; | |
| 3795 | |||
| 3796 | 28582 | return 0; | |
| 3797 | } | ||
| 3798 | |||
| 3799 | 40525 | static int decode_nal_unit(HEVCContext *s, unsigned nal_idx) | |
| 3800 | { | ||
| 3801 | 40525 | H2645NAL *nal = &s->pkt.nals[nal_idx]; | |
| 3802 | 40525 | GetBitContext gb = nal->gb; | |
| 3803 | int ret; | ||
| 3804 | |||
| 3805 | 40525 | s->nal_unit_type = nal->type; | |
| 3806 | 40525 | s->nuh_layer_id = nal->nuh_layer_id; | |
| 3807 | 40525 | s->temporal_id = nal->temporal_id; | |
| 3808 | |||
| 3809 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 40525 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
40525 | if (FF_HW_HAS_CB(s->avctx, decode_params) && |
| 3810 | ✗ | (s->nal_unit_type == HEVC_NAL_VPS || | |
| 3811 | ✗ | s->nal_unit_type == HEVC_NAL_SPS || | |
| 3812 | ✗ | s->nal_unit_type == HEVC_NAL_PPS || | |
| 3813 | ✗ | s->nal_unit_type == HEVC_NAL_SEI_PREFIX || | |
| 3814 | ✗ | s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) { | |
| 3815 | ✗ | ret = FF_HW_CALL(s->avctx, decode_params, | |
| 3816 | nal->type, nal->raw_data, nal->raw_size); | ||
| 3817 | ✗ | if (ret < 0) | |
| 3818 | ✗ | goto fail; | |
| 3819 | } | ||
| 3820 | |||
| 3821 |
6/7✓ Branch 0 taken 479 times.
✓ Branch 1 taken 491 times.
✓ Branch 2 taken 1580 times.
✓ Branch 3 taken 8148 times.
✓ Branch 4 taken 29153 times.
✓ Branch 5 taken 674 times.
✗ Branch 6 not taken.
|
40525 | switch (s->nal_unit_type) { |
| 3822 | 479 | case HEVC_NAL_VPS: | |
| 3823 | 479 | ret = ff_hevc_decode_nal_vps(&gb, s->avctx, &s->ps); | |
| 3824 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 479 times.
|
479 | if (ret < 0) |
| 3825 | ✗ | goto fail; | |
| 3826 | 479 | break; | |
| 3827 | 491 | case HEVC_NAL_SPS: | |
| 3828 | 491 | ret = ff_hevc_decode_nal_sps(&gb, s->avctx, &s->ps, | |
| 3829 | 491 | nal->nuh_layer_id, s->apply_defdispwin); | |
| 3830 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 491 times.
|
491 | if (ret < 0) |
| 3831 | ✗ | goto fail; | |
| 3832 | 491 | break; | |
| 3833 | 1580 | case HEVC_NAL_PPS: | |
| 3834 | 1580 | ret = ff_hevc_decode_nal_pps(&gb, s->avctx, &s->ps); | |
| 3835 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1578 times.
|
1580 | if (ret < 0) |
| 3836 | 2 | goto fail; | |
| 3837 | 1578 | break; | |
| 3838 | 8148 | case HEVC_NAL_SEI_PREFIX: | |
| 3839 | case HEVC_NAL_SEI_SUFFIX: | ||
| 3840 | 8148 | ret = ff_hevc_decode_nal_sei(&gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type); | |
| 3841 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 8093 times.
|
8148 | if (ret < 0) |
| 3842 | 55 | goto fail; | |
| 3843 | 8093 | break; | |
| 3844 | 29153 | case HEVC_NAL_TRAIL_R: | |
| 3845 | case HEVC_NAL_TRAIL_N: | ||
| 3846 | case HEVC_NAL_TSA_N: | ||
| 3847 | case HEVC_NAL_TSA_R: | ||
| 3848 | case HEVC_NAL_STSA_N: | ||
| 3849 | case HEVC_NAL_STSA_R: | ||
| 3850 | case HEVC_NAL_BLA_W_LP: | ||
| 3851 | case HEVC_NAL_BLA_W_RADL: | ||
| 3852 | case HEVC_NAL_BLA_N_LP: | ||
| 3853 | case HEVC_NAL_IDR_W_RADL: | ||
| 3854 | case HEVC_NAL_IDR_N_LP: | ||
| 3855 | case HEVC_NAL_CRA_NUT: | ||
| 3856 | case HEVC_NAL_RADL_N: | ||
| 3857 | case HEVC_NAL_RADL_R: | ||
| 3858 | case HEVC_NAL_RASL_N: | ||
| 3859 | case HEVC_NAL_RASL_R: | ||
| 3860 | 29153 | ret = decode_slice(s, nal_idx, &gb); | |
| 3861 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 29151 times.
|
29153 | if (ret < 0) |
| 3862 | 2 | goto fail; | |
| 3863 | 29151 | break; | |
| 3864 | 674 | case HEVC_NAL_EOS_NUT: | |
| 3865 | case HEVC_NAL_EOB_NUT: | ||
| 3866 | case HEVC_NAL_AUD: | ||
| 3867 | case HEVC_NAL_FD_NUT: | ||
| 3868 | case HEVC_NAL_UNSPEC62: // Dolby Vision RPU | ||
| 3869 | case HEVC_NAL_UNSPEC63: // Dolby Vision EL | ||
| 3870 | 674 | break; | |
| 3871 | ✗ | default: | |
| 3872 | ✗ | av_log(s->avctx, AV_LOG_VERBOSE, | |
| 3873 | ✗ | "Skipping NAL unit %d\n", s->nal_unit_type); | |
| 3874 | } | ||
| 3875 | |||
| 3876 | 40466 | return 0; | |
| 3877 | 59 | fail: | |
| 3878 |
1/2✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
|
59 | if (ret == AVERROR_INVALIDDATA && |
| 3879 |
1/2✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
|
59 | !(s->avctx->err_recognition & AV_EF_EXPLODE)) { |
| 3880 | 59 | av_log(s->avctx, AV_LOG_WARNING, | |
| 3881 | 59 | "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type); | |
| 3882 | 59 | return 0; | |
| 3883 | } | ||
| 3884 | ✗ | return ret; | |
| 3885 | } | ||
| 3886 | |||
| 3887 | 469 | static void decode_reset_recovery_point(HEVCContext *s) | |
| 3888 | { | ||
| 3889 | 469 | s->recovery_poc = HEVC_RECOVERY_UNSPECIFIED; | |
| 3890 | 469 | s->sei.recovery_point.has_recovery_poc = 0; | |
| 3891 | 469 | } | |
| 3892 | |||
| 3893 | 361 | static int export_stream_params_from_slice(HEVCContext *s, const H2645NAL *nal) | |
| 3894 | { | ||
| 3895 | 361 | GetBitContext gb = nal->gb; | |
| 3896 | const HEVCSPS *sps; | ||
| 3897 | const HEVCVPS *vps; | ||
| 3898 | unsigned pps_id; | ||
| 3899 | |||
| 3900 |
2/2✓ Branch 0 taken 306 times.
✓ Branch 1 taken 55 times.
|
667 | int is_slice = nal->type <= HEVC_NAL_RASL_R || |
| 3901 |
1/2✓ Branch 0 taken 306 times.
✗ Branch 1 not taken.
|
306 | (nal->type >= HEVC_NAL_BLA_W_LP && |
| 3902 |
2/2✓ Branch 0 taken 228 times.
✓ Branch 1 taken 78 times.
|
306 | nal->type <= HEVC_NAL_CRA_NUT); |
| 3903 | |||
| 3904 |
3/4✓ Branch 0 taken 283 times.
✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 283 times.
|
361 | if (!is_slice || nal->nuh_layer_id) |
| 3905 | 78 | return 0; | |
| 3906 | |||
| 3907 | 283 | skip_bits1(&gb); // first_slice_segment_in_pic_flag | |
| 3908 |
2/2✓ Branch 0 taken 228 times.
✓ Branch 1 taken 55 times.
|
283 | if (nal->type >= HEVC_NAL_BLA_W_LP) |
| 3909 | 228 | skip_bits1(&gb); // no_output_of_prior_pics_flag | |
| 3910 | 283 | pps_id = get_ue_golomb_long(&gb); | |
| 3911 |
3/4✓ Branch 0 taken 283 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 228 times.
|
283 | if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) |
| 3912 | 55 | return 0; | |
| 3913 | 228 | sps = s->ps.pps_list[pps_id]->sps; | |
| 3914 | 228 | vps = sps->vps; | |
| 3915 | |||
| 3916 | 228 | export_stream_params(s, sps); | |
| 3917 | |||
| 3918 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 223 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
228 | if (vps->nb_layers == 2 && vps->layer_id_in_nuh[1] && |
| 3919 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY) { |
| 3920 | ✗ | enum AVPixelFormat alpha_fmt = map_to_alpha_format(s, sps->pix_fmt); | |
| 3921 | |||
| 3922 | ✗ | if (alpha_fmt != AV_PIX_FMT_NONE) | |
| 3923 | ✗ | s->avctx->pix_fmt = alpha_fmt; | |
| 3924 | } | ||
| 3925 | |||
| 3926 | 228 | return 1; | |
| 3927 | } | ||
| 3928 | |||
| 3929 | 10593 | static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) | |
| 3930 | { | ||
| 3931 | 10593 | int ret = 0; | |
| 3932 | 10593 | int eos_at_start = 1; | |
| 3933 | 10593 | int params_exported = 0; | |
| 3934 |
2/2✓ Branch 0 taken 375 times.
✓ Branch 1 taken 10218 times.
|
10593 | int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING; |
| 3935 | |||
| 3936 | 10593 | s->cur_frame = s->collocated_ref = NULL; | |
| 3937 | 10593 | s->last_eos = s->eos; | |
| 3938 | 10593 | s->eos = 0; | |
| 3939 | 10593 | s->slice_initialized = 0; | |
| 3940 |
2/2✓ Branch 0 taken 464 times.
✓ Branch 1 taken 10129 times.
|
10593 | if (s->last_eos) |
| 3941 | 464 | decode_reset_recovery_point(s); | |
| 3942 | |||
| 3943 |
2/2✓ Branch 0 taken 21186 times.
✓ Branch 1 taken 10593 times.
|
31779 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
| 3944 | 21186 | HEVCLayerContext *l = &s->layers[i]; | |
| 3945 | 21186 | l->cur_frame = NULL; | |
| 3946 | } | ||
| 3947 | |||
| 3948 | /* split the input packet into NAL units, so we know the upper bound on the | ||
| 3949 | * number of slices in the frame */ | ||
| 3950 | 10593 | ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx, | |
| 3951 | 10593 | s->nal_length_size, s->avctx->codec_id, flags); | |
| 3952 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10593 times.
|
10593 | if (ret < 0) { |
| 3953 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3954 | "Error splitting the input into NAL units.\n"); | ||
| 3955 | ✗ | return ret; | |
| 3956 | } | ||
| 3957 | |||
| 3958 |
2/2✓ Branch 0 taken 41738 times.
✓ Branch 1 taken 10593 times.
|
52331 | for (int i = 0; i < s->pkt.nb_nals; i++) { |
| 3959 |
2/2✓ Branch 0 taken 41737 times.
✓ Branch 1 taken 1 times.
|
41738 | if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT || |
| 3960 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 41733 times.
|
41737 | s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) { |
| 3961 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (eos_at_start) { |
| 3962 | 5 | s->last_eos = 1; | |
| 3963 | 5 | decode_reset_recovery_point(s); | |
| 3964 | } else { | ||
| 3965 | ✗ | s->eos = 1; | |
| 3966 | } | ||
| 3967 | } else { | ||
| 3968 | 41733 | eos_at_start = 0; | |
| 3969 | } | ||
| 3970 | } | ||
| 3971 | |||
| 3972 | /* | ||
| 3973 | * Check for RPU delimiter. | ||
| 3974 | * | ||
| 3975 | * Dolby Vision RPUs masquerade as unregistered NALs of type 62. | ||
| 3976 | * | ||
| 3977 | * We have to do this check here an create the rpu buffer, since RPUs are appended | ||
| 3978 | * to the end of an AU; they are normally the last non-EOB/EOS NAL in the AU. | ||
| 3979 | */ | ||
| 3980 | 10593 | H2645NAL *rpu_nal = NULL; | |
| 3981 |
2/2✓ Branch 0 taken 31144 times.
✓ Branch 1 taken 10591 times.
|
41735 | for (int i = s->pkt.nb_nals - 1; i > 0 ; i--) { |
| 3982 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 31142 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
31144 | if (s->pkt.nals[i].type == HEVC_NAL_UNSPEC62 && s->pkt.nals[i].size > 2 |
| 3983 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | && !s->pkt.nals[i].nuh_layer_id && !s->pkt.nals[i].temporal_id) { |
| 3984 | 2 | rpu_nal = &s->pkt.nals[i]; | |
| 3985 | 2 | break; | |
| 3986 | } | ||
| 3987 | } | ||
| 3988 | |||
| 3989 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10591 times.
|
10593 | if (rpu_nal) { |
| 3990 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (s->rpu_buf) { |
| 3991 | ✗ | av_buffer_unref(&s->rpu_buf); | |
| 3992 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n"); | |
| 3993 | } | ||
| 3994 | |||
| 3995 | 2 | s->rpu_buf = av_buffer_alloc(rpu_nal->raw_size - 2); | |
| 3996 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!s->rpu_buf) { |
| 3997 | ✗ | ret = AVERROR(ENOMEM); | |
| 3998 | ✗ | goto fail; | |
| 3999 | } | ||
| 4000 | 2 | memcpy(s->rpu_buf->data, rpu_nal->raw_data + 2, rpu_nal->raw_size - 2); | |
| 4001 | |||
| 4002 | 2 | ret = ff_dovi_rpu_parse(&s->dovi_ctx, rpu_nal->data + 2, rpu_nal->size - 2, | |
| 4003 | 2 | s->avctx->err_recognition); | |
| 4004 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ret < 0) { |
| 4005 | ✗ | av_buffer_unref(&s->rpu_buf); | |
| 4006 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n"); | |
| 4007 | /* ignore */ | ||
| 4008 | } | ||
| 4009 | } | ||
| 4010 | |||
| 4011 | /* decode the NAL units */ | ||
| 4012 |
2/2✓ Branch 0 taken 41738 times.
✓ Branch 1 taken 10593 times.
|
52331 | for (int i = 0; i < s->pkt.nb_nals; i++) { |
| 4013 | 41738 | H2645NAL *nal = &s->pkt.nals[i]; | |
| 4014 | |||
| 4015 |
2/2✓ Branch 0 taken 1893 times.
✓ Branch 1 taken 39845 times.
|
41738 | if (s->avctx->skip_frame >= AVDISCARD_ALL) { |
| 4016 |
2/2✓ Branch 0 taken 1185 times.
✓ Branch 1 taken 708 times.
|
1893 | switch (nal->type) { |
| 4017 | 1185 | case HEVC_NAL_VPS: | |
| 4018 | case HEVC_NAL_SPS: | ||
| 4019 | case HEVC_NAL_PPS: | ||
| 4020 | case HEVC_NAL_SEI_PREFIX: | ||
| 4021 | case HEVC_NAL_SEI_SUFFIX: | ||
| 4022 | 1185 | break; | |
| 4023 | 708 | default: | |
| 4024 |
3/4✓ Branch 0 taken 708 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 361 times.
✓ Branch 3 taken 347 times.
|
708 | if (!s->layers[0].sps && !params_exported) |
| 4025 | 361 | params_exported = export_stream_params_from_slice(s, nal); | |
| 4026 | 708 | continue; | |
| 4027 | } | ||
| 4028 |
4/4✓ Branch 0 taken 1095 times.
✓ Branch 1 taken 38750 times.
✓ Branch 2 taken 505 times.
✓ Branch 3 taken 590 times.
|
40940 | } else if (s->avctx->skip_frame >= AVDISCARD_NONREF && |
| 4029 | 1095 | ff_hevc_nal_is_nonref(nal->type)) | |
| 4030 | 505 | continue; | |
| 4031 | |||
| 4032 | 40525 | ret = decode_nal_unit(s, i); | |
| 4033 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40525 times.
|
40525 | if (ret < 0) { |
| 4034 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
| 4035 | "Error parsing NAL unit #%d.\n", i); | ||
| 4036 | ✗ | goto fail; | |
| 4037 | } | ||
| 4038 | } | ||
| 4039 | |||
| 4040 |
2/2✓ Branch 0 taken 10365 times.
✓ Branch 1 taken 228 times.
|
10593 | if (params_exported) { |
| 4041 | 228 | ret = export_stream_params_from_sei(s); | |
| 4042 |
1/2✓ Branch 0 taken 228 times.
✗ Branch 1 not taken.
|
228 | if (ret < 0) |
| 4043 | ✗ | goto fail; | |
| 4044 | } | ||
| 4045 | |||
| 4046 | 10593 | fail: | |
| 4047 |
2/2✓ Branch 0 taken 21186 times.
✓ Branch 1 taken 10593 times.
|
31779 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
| 4048 | 21186 | HEVCLayerContext *l = &s->layers[i]; | |
| 4049 | |||
| 4050 |
2/2✓ Branch 0 taken 10599 times.
✓ Branch 1 taken 10587 times.
|
21186 | if (!l->cur_frame) |
| 4051 | 10599 | continue; | |
| 4052 | |||
| 4053 |
1/2✓ Branch 0 taken 10587 times.
✗ Branch 1 not taken.
|
10587 | if (ret >= 0) |
| 4054 | 10587 | ret = hevc_frame_end(s, l); | |
| 4055 | |||
| 4056 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 10554 times.
|
10587 | if (s->avctx->active_thread_type == FF_THREAD_FRAME) |
| 4057 | 33 | ff_progress_frame_report(&l->cur_frame->tf, INT_MAX); | |
| 4058 | } | ||
| 4059 | |||
| 4060 | 10593 | return ret; | |
| 4061 | } | ||
| 4062 | |||
| 4063 | 363 | static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first) | |
| 4064 | { | ||
| 4065 | int ret, i; | ||
| 4066 | |||
| 4067 | 363 | ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff, | |
| 4068 | 363 | &s->nal_length_size, s->avctx->err_recognition, | |
| 4069 | 363 | s->apply_defdispwin, s->avctx); | |
| 4070 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 363 times.
|
363 | if (ret < 0) |
| 4071 | ✗ | return ret; | |
| 4072 | |||
| 4073 | /* export stream parameters from the first SPS */ | ||
| 4074 |
2/2✓ Branch 0 taken 393 times.
✓ Branch 1 taken 2 times.
|
395 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { |
| 4075 |
4/4✓ Branch 0 taken 377 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 361 times.
✓ Branch 3 taken 16 times.
|
393 | if (first && s->ps.sps_list[i]) { |
| 4076 | 361 | const HEVCSPS *sps = s->ps.sps_list[i]; | |
| 4077 | 361 | export_stream_params(s, sps); | |
| 4078 | |||
| 4079 | 361 | ret = export_multilayer(s, sps->vps); | |
| 4080 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 361 times.
|
361 | if (ret < 0) |
| 4081 | ✗ | return ret; | |
| 4082 | |||
| 4083 | 361 | break; | |
| 4084 | } | ||
| 4085 | } | ||
| 4086 | |||
| 4087 | /* export stream parameters from SEI */ | ||
| 4088 | 363 | ret = export_stream_params_from_sei(s); | |
| 4089 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 363 times.
|
363 | if (ret < 0) |
| 4090 | ✗ | return ret; | |
| 4091 | |||
| 4092 | 363 | return 0; | |
| 4093 | } | ||
| 4094 | |||
| 4095 | 22545 | static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) | |
| 4096 | { | ||
| 4097 | 22545 | HEVCContext *s = avctx->priv_data; | |
| 4098 | 22545 | AVCodecInternal *avci = avctx->internal; | |
| 4099 | 22545 | AVPacket *avpkt = avci->in_pkt; | |
| 4100 | |||
| 4101 | int ret; | ||
| 4102 | uint8_t *sd; | ||
| 4103 | size_t sd_size; | ||
| 4104 | |||
| 4105 | 22545 | s->pkt_dts = AV_NOPTS_VALUE; | |
| 4106 | |||
| 4107 |
2/2✓ Branch 1 taken 980 times.
✓ Branch 2 taken 21565 times.
|
22545 | if (av_container_fifo_can_read(s->output_fifo)) |
| 4108 | 980 | goto do_output; | |
| 4109 | |||
| 4110 | 21565 | av_packet_unref(avpkt); | |
| 4111 | 21565 | ret = ff_decode_get_packet(avctx, avpkt); | |
| 4112 |
2/2✓ Branch 0 taken 379 times.
✓ Branch 1 taken 21186 times.
|
21565 | if (ret == AVERROR_EOF) { |
| 4113 | 379 | ret = ff_hevc_output_frames(s, s->layers_active_decode, | |
| 4114 | s->layers_active_output, 0, 0, 0); | ||
| 4115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 379 times.
|
379 | if (ret < 0) |
| 4116 | ✗ | return ret; | |
| 4117 | 379 | goto do_output; | |
| 4118 |
2/2✓ Branch 0 taken 10593 times.
✓ Branch 1 taken 10593 times.
|
21186 | } else if (ret < 0) |
| 4119 | 10593 | return ret; | |
| 4120 | |||
| 4121 | 10593 | s->pkt_dts = avpkt->dts; | |
| 4122 | |||
| 4123 | 10593 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size); | |
| 4124 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10592 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
10593 | if (sd && sd_size > 0) { |
| 4125 | 1 | ret = hevc_decode_extradata(s, sd, sd_size, 0); | |
| 4126 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
| 4127 | ✗ | return ret; | |
| 4128 | } | ||
| 4129 | |||
| 4130 | 10593 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size); | |
| 4131 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10593 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10593 | if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) { |
| 4132 | ✗ | int old = s->dovi_ctx.cfg.dv_profile; | |
| 4133 | ✗ | s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd; | |
| 4134 | ✗ | if (old) | |
| 4135 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
| 4136 | "New DOVI configuration record from input packet (profile %d -> %u).\n", | ||
| 4137 | ✗ | old, s->dovi_ctx.cfg.dv_profile); | |
| 4138 | } | ||
| 4139 | |||
| 4140 | 10593 | ret = decode_nal_units(s, avpkt->data, avpkt->size); | |
| 4141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10593 times.
|
10593 | if (ret < 0) |
| 4142 | ✗ | return ret; | |
| 4143 | |||
| 4144 | 10593 | do_output: | |
| 4145 |
2/2✓ Branch 1 taken 10433 times.
✓ Branch 2 taken 1519 times.
|
11952 | if (av_container_fifo_read(s->output_fifo, frame, 0) >= 0) { |
| 4146 |
1/2✓ Branch 0 taken 10433 times.
✗ Branch 1 not taken.
|
10433 | if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN)) |
| 4147 | 10433 | av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS); | |
| 4148 | |||
| 4149 | 10433 | return 0; | |
| 4150 | } | ||
| 4151 | |||
| 4152 |
2/2✓ Branch 0 taken 234 times.
✓ Branch 1 taken 1285 times.
|
1519 | return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN); |
| 4153 | } | ||
| 4154 | |||
| 4155 | 67 | static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src) | |
| 4156 | { | ||
| 4157 | int ret; | ||
| 4158 | |||
| 4159 | 67 | ff_progress_frame_ref(&dst->tf, &src->tf); | |
| 4160 | |||
| 4161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (src->needs_fg) { |
| 4162 | ✗ | ret = av_frame_ref(dst->frame_grain, src->frame_grain); | |
| 4163 | ✗ | if (ret < 0) { | |
| 4164 | ✗ | ff_hevc_unref_frame(dst, ~0); | |
| 4165 | ✗ | return ret; | |
| 4166 | } | ||
| 4167 | ✗ | dst->needs_fg = 1; | |
| 4168 | } | ||
| 4169 | |||
| 4170 | 67 | dst->pps = av_refstruct_ref_c(src->pps); | |
| 4171 | 67 | dst->tab_mvf = av_refstruct_ref(src->tab_mvf); | |
| 4172 | 67 | dst->rpl_tab = av_refstruct_ref(src->rpl_tab); | |
| 4173 | 67 | dst->rpl = av_refstruct_ref(src->rpl); | |
| 4174 | 67 | dst->nb_rpl_elems = src->nb_rpl_elems; | |
| 4175 | |||
| 4176 | 67 | dst->poc = src->poc; | |
| 4177 | 67 | dst->ctb_count = src->ctb_count; | |
| 4178 | 67 | dst->flags = src->flags; | |
| 4179 | |||
| 4180 | 67 | dst->base_layer_frame = src->base_layer_frame; | |
| 4181 | |||
| 4182 | 67 | av_refstruct_replace(&dst->hwaccel_picture_private, | |
| 4183 | 67 | src->hwaccel_picture_private); | |
| 4184 | |||
| 4185 | 67 | return 0; | |
| 4186 | } | ||
| 4187 | |||
| 4188 | 601 | static av_cold int hevc_decode_free(AVCodecContext *avctx) | |
| 4189 | { | ||
| 4190 | 601 | HEVCContext *s = avctx->priv_data; | |
| 4191 | |||
| 4192 |
2/2✓ Branch 0 taken 1202 times.
✓ Branch 1 taken 601 times.
|
1803 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
| 4193 | 1202 | pic_arrays_free(&s->layers[i]); | |
| 4194 | 1202 | av_refstruct_unref(&s->layers[i].sps); | |
| 4195 | } | ||
| 4196 | |||
| 4197 | 601 | av_refstruct_unref(&s->vps); | |
| 4198 | 601 | av_refstruct_unref(&s->pps); | |
| 4199 | |||
| 4200 | 601 | ff_dovi_ctx_unref(&s->dovi_ctx); | |
| 4201 | 601 | av_buffer_unref(&s->rpu_buf); | |
| 4202 | |||
| 4203 | 601 | av_freep(&s->md5_ctx); | |
| 4204 | |||
| 4205 | 601 | av_container_fifo_free(&s->output_fifo); | |
| 4206 | |||
| 4207 |
2/2✓ Branch 0 taken 1202 times.
✓ Branch 1 taken 601 times.
|
1803 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
| 4208 | 1202 | HEVCLayerContext *l = &s->layers[layer]; | |
| 4209 |
2/2✓ Branch 0 taken 38464 times.
✓ Branch 1 taken 1202 times.
|
39666 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
| 4210 | 38464 | ff_hevc_unref_frame(&l->DPB[i], ~0); | |
| 4211 | 38464 | av_frame_free(&l->DPB[i].frame_grain); | |
| 4212 | } | ||
| 4213 | } | ||
| 4214 | |||
| 4215 | 601 | ff_hevc_ps_uninit(&s->ps); | |
| 4216 | |||
| 4217 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | for (int i = 0; i < s->nb_wpp_progress; i++) |
| 4218 | ✗ | ff_thread_progress_destroy(&s->wpp_progress[i]); | |
| 4219 | 601 | av_freep(&s->wpp_progress); | |
| 4220 | |||
| 4221 | 601 | av_freep(&s->sh.entry_point_offset); | |
| 4222 | 601 | av_freep(&s->sh.offset); | |
| 4223 | 601 | av_freep(&s->sh.size); | |
| 4224 | |||
| 4225 | 601 | av_freep(&s->local_ctx); | |
| 4226 | |||
| 4227 | 601 | ff_h2645_packet_uninit(&s->pkt); | |
| 4228 | |||
| 4229 | 601 | ff_hevc_reset_sei(&s->sei); | |
| 4230 | |||
| 4231 | 601 | return 0; | |
| 4232 | } | ||
| 4233 | |||
| 4234 | 601 | static av_cold int hevc_init_context(AVCodecContext *avctx) | |
| 4235 | { | ||
| 4236 | 601 | HEVCContext *s = avctx->priv_data; | |
| 4237 | |||
| 4238 | 601 | s->avctx = avctx; | |
| 4239 | |||
| 4240 | 601 | s->local_ctx = av_mallocz(sizeof(*s->local_ctx)); | |
| 4241 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | if (!s->local_ctx) |
| 4242 | ✗ | return AVERROR(ENOMEM); | |
| 4243 | 601 | s->nb_local_ctx = 1; | |
| 4244 | |||
| 4245 | 601 | s->local_ctx[0].parent = s; | |
| 4246 | 601 | s->local_ctx[0].logctx = avctx; | |
| 4247 | 601 | s->local_ctx[0].common_cabac_state = &s->cabac; | |
| 4248 | |||
| 4249 | 601 | s->output_fifo = av_container_fifo_alloc_avframe(0); | |
| 4250 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | if (!s->output_fifo) |
| 4251 | ✗ | return AVERROR(ENOMEM); | |
| 4252 | |||
| 4253 |
2/2✓ Branch 0 taken 1202 times.
✓ Branch 1 taken 601 times.
|
1803 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
| 4254 | 1202 | HEVCLayerContext *l = &s->layers[layer]; | |
| 4255 |
2/2✓ Branch 0 taken 38464 times.
✓ Branch 1 taken 1202 times.
|
39666 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
| 4256 | 38464 | l->DPB[i].frame_grain = av_frame_alloc(); | |
| 4257 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38464 times.
|
38464 | if (!l->DPB[i].frame_grain) |
| 4258 | ✗ | return AVERROR(ENOMEM); | |
| 4259 | } | ||
| 4260 | } | ||
| 4261 | |||
| 4262 | 601 | s->md5_ctx = av_md5_alloc(); | |
| 4263 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | if (!s->md5_ctx) |
| 4264 | ✗ | return AVERROR(ENOMEM); | |
| 4265 | |||
| 4266 | 601 | ff_bswapdsp_init(&s->bdsp); | |
| 4267 | |||
| 4268 | 601 | s->dovi_ctx.logctx = avctx; | |
| 4269 | 601 | s->eos = 0; | |
| 4270 | |||
| 4271 | 601 | ff_hevc_reset_sei(&s->sei); | |
| 4272 | |||
| 4273 | 601 | return 0; | |
| 4274 | } | ||
| 4275 | |||
| 4276 | #if HAVE_THREADS | ||
| 4277 | 32 | static int hevc_update_thread_context(AVCodecContext *dst, | |
| 4278 | const AVCodecContext *src) | ||
| 4279 | { | ||
| 4280 | 32 | HEVCContext *s = dst->priv_data; | |
| 4281 | 32 | HEVCContext *s0 = src->priv_data; | |
| 4282 | int ret; | ||
| 4283 | |||
| 4284 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
|
96 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
| 4285 | 64 | HEVCLayerContext *l = &s->layers[layer]; | |
| 4286 | 64 | const HEVCLayerContext *l0 = &s0->layers[layer]; | |
| 4287 |
2/2✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 64 times.
|
2112 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
| 4288 | 2048 | ff_hevc_unref_frame(&l->DPB[i], ~0); | |
| 4289 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1981 times.
|
2048 | if (l0->DPB[i].f) { |
| 4290 | 67 | ret = hevc_ref_frame(&l->DPB[i], &l0->DPB[i]); | |
| 4291 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (ret < 0) |
| 4292 | ✗ | return ret; | |
| 4293 | } | ||
| 4294 | } | ||
| 4295 | |||
| 4296 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
|
64 | if (l->sps != l0->sps) { |
| 4297 | 1 | ret = set_sps(s, l, l0->sps); | |
| 4298 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
| 4299 | ✗ | return ret; | |
| 4300 | } | ||
| 4301 | } | ||
| 4302 | |||
| 4303 |
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++) |
| 4304 | 512 | av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); | |
| 4305 | |||
| 4306 |
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++) |
| 4307 | 512 | av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); | |
| 4308 | |||
| 4309 |
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++) |
| 4310 | 2048 | av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); | |
| 4311 | |||
| 4312 | // PPS do not persist between frames | ||
| 4313 | 32 | av_refstruct_unref(&s->pps); | |
| 4314 | |||
| 4315 | 32 | s->poc_tid0 = s0->poc_tid0; | |
| 4316 | 32 | s->eos = s0->eos; | |
| 4317 | 32 | s->no_rasl_output_flag = s0->no_rasl_output_flag; | |
| 4318 | 32 | s->skipping_frame = s0->skipping_frame; | |
| 4319 | |||
| 4320 | 32 | s->is_nalff = s0->is_nalff; | |
| 4321 | 32 | s->nal_length_size = s0->nal_length_size; | |
| 4322 | 32 | s->layers_active_decode = s0->layers_active_decode; | |
| 4323 | 32 | s->layers_active_output = s0->layers_active_output; | |
| 4324 | |||
| 4325 | 32 | s->film_grain_warning_shown = s0->film_grain_warning_shown; | |
| 4326 | |||
| 4327 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | if (s->nb_view_ids != s0->nb_view_ids || |
| 4328 |
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)) { |
| 4329 | ✗ | av_freep(&s->view_ids); | |
| 4330 | ✗ | s->nb_view_ids = 0; | |
| 4331 | |||
| 4332 | ✗ | if (s0->nb_view_ids) { | |
| 4333 | ✗ | s->view_ids = av_memdup(s0->view_ids, s0->nb_view_ids * sizeof(*s0->view_ids)); | |
| 4334 | ✗ | if (!s->view_ids) | |
| 4335 | ✗ | return AVERROR(ENOMEM); | |
| 4336 | ✗ | s->nb_view_ids = s0->nb_view_ids; | |
| 4337 | } | ||
| 4338 | } | ||
| 4339 | |||
| 4340 | 32 | ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common); | |
| 4341 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
| 4342 | ✗ | return ret; | |
| 4343 | |||
| 4344 | 32 | ret = av_buffer_replace(&s->sei.common.itut_t35.hdr_plus, | |
| 4345 | 32 | s0->sei.common.itut_t35.hdr_plus); | |
| 4346 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
| 4347 | ✗ | return ret; | |
| 4348 | |||
| 4349 | 32 | ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf); | |
| 4350 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
| 4351 | ✗ | return ret; | |
| 4352 | |||
| 4353 | 32 | ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx); | |
| 4354 | |||
| 4355 | 32 | ret = av_buffer_replace(&s->sei.common.itut_t35.hdr_vivid, | |
| 4356 | 32 | s0->sei.common.itut_t35.hdr_vivid); | |
| 4357 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
| 4358 | ✗ | return ret; | |
| 4359 | |||
| 4360 | 32 | s->sei.common.frame_packing = s0->sei.common.frame_packing; | |
| 4361 | 32 | s->sei.common.display_orientation = s0->sei.common.display_orientation; | |
| 4362 | 32 | s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer; | |
| 4363 | 32 | s->sei.tdrdi = s0->sei.tdrdi; | |
| 4364 | 32 | s->sei.recovery_point = s0->sei.recovery_point; | |
| 4365 | 32 | s->recovery_poc = s0->recovery_poc; | |
| 4366 | |||
| 4367 | 32 | return 0; | |
| 4368 | } | ||
| 4369 | #endif | ||
| 4370 | |||
| 4371 | 362 | static int hevc_sei_to_context(AVCodecContext *avctx, HEVCSEI *sei) | |
| 4372 | { | ||
| 4373 | int ret; | ||
| 4374 | |||
| 4375 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 358 times.
|
362 | if (sei->tdrdi.present) { |
| 4376 | AVBufferRef *buf; | ||
| 4377 | size_t size; | ||
| 4378 | 4 | AV3DReferenceDisplaysInfo *tdrdi = av_tdrdi_alloc(sei->tdrdi.num_ref_displays, &size); | |
| 4379 | |||
| 4380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!tdrdi) |
| 4381 | ✗ | return AVERROR(ENOMEM); | |
| 4382 | |||
| 4383 | 4 | buf = av_buffer_create((uint8_t *)tdrdi, size, NULL, NULL, 0); | |
| 4384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!buf) { |
| 4385 | ✗ | av_free(tdrdi); | |
| 4386 | ✗ | return AVERROR(ENOMEM); | |
| 4387 | } | ||
| 4388 | |||
| 4389 | 4 | tdrdi->prec_ref_display_width = sei->tdrdi.prec_ref_display_width; | |
| 4390 | 4 | tdrdi->ref_viewing_distance_flag = sei->tdrdi.ref_viewing_distance_flag; | |
| 4391 | 4 | tdrdi->prec_ref_viewing_dist = sei->tdrdi.prec_ref_viewing_dist; | |
| 4392 | 4 | tdrdi->num_ref_displays = sei->tdrdi.num_ref_displays; | |
| 4393 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | for (int i = 0; i < sei->tdrdi.num_ref_displays; i++) { |
| 4394 | 4 | AV3DReferenceDisplay *display = av_tdrdi_get_display(tdrdi, i); | |
| 4395 | |||
| 4396 | 4 | display->left_view_id = sei->tdrdi.left_view_id[i]; | |
| 4397 | 4 | display->right_view_id = sei->tdrdi.right_view_id[i]; | |
| 4398 | 4 | display->exponent_ref_display_width = sei->tdrdi.exponent_ref_display_width[i]; | |
| 4399 | 4 | display->mantissa_ref_display_width = sei->tdrdi.mantissa_ref_display_width[i]; | |
| 4400 | 4 | display->exponent_ref_viewing_distance = sei->tdrdi.exponent_ref_viewing_distance[i]; | |
| 4401 | 4 | display->mantissa_ref_viewing_distance = sei->tdrdi.mantissa_ref_viewing_distance[i]; | |
| 4402 | 4 | display->additional_shift_present_flag = sei->tdrdi.additional_shift_present_flag[i]; | |
| 4403 | 4 | display->num_sample_shift = sei->tdrdi.num_sample_shift[i]; | |
| 4404 | } | ||
| 4405 | 4 | ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data, | |
| 4406 | AV_FRAME_DATA_3D_REFERENCE_DISPLAYS, &buf); | ||
| 4407 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ret < 0) { |
| 4408 | ✗ | av_buffer_unref(&buf); | |
| 4409 | ✗ | return ret; | |
| 4410 | } | ||
| 4411 | } | ||
| 4412 | |||
| 4413 | 362 | ret = ff_h2645_sei_to_context(avctx, &sei->common); | |
| 4414 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 362 times.
|
362 | if (ret < 0) |
| 4415 | ✗ | return ret; | |
| 4416 | |||
| 4417 | 362 | return 0; | |
| 4418 | } | ||
| 4419 | |||
| 4420 | 601 | static av_cold int hevc_decode_init(AVCodecContext *avctx) | |
| 4421 | { | ||
| 4422 | 601 | HEVCContext *s = avctx->priv_data; | |
| 4423 | int ret; | ||
| 4424 | |||
| 4425 | 601 | ret = hevc_init_context(avctx); | |
| 4426 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | if (ret < 0) |
| 4427 | ✗ | return ret; | |
| 4428 | |||
| 4429 | 601 | s->sei.picture_timing.picture_struct = 0; | |
| 4430 | 601 | s->eos = 1; | |
| 4431 | |||
| 4432 | 601 | atomic_init(&s->wpp_err, 0); | |
| 4433 | |||
| 4434 |
2/2✓ Branch 0 taken 600 times.
✓ Branch 1 taken 1 times.
|
601 | if (!avctx->internal->is_copy) { |
| 4435 | const AVPacketSideData *sd; | ||
| 4436 | |||
| 4437 |
3/4✓ Branch 0 taken 362 times.
✓ Branch 1 taken 238 times.
✓ Branch 2 taken 362 times.
✗ Branch 3 not taken.
|
600 | if (avctx->extradata_size > 0 && avctx->extradata) { |
| 4438 | 362 | ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1); | |
| 4439 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 362 times.
|
362 | if (ret < 0) { |
| 4440 | ✗ | return ret; | |
| 4441 | } | ||
| 4442 | |||
| 4443 | 362 | ret = hevc_sei_to_context(avctx, &s->sei); | |
| 4444 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 362 times.
|
362 | if (ret < 0) |
| 4445 | ✗ | return ret; | |
| 4446 | } | ||
| 4447 | |||
| 4448 | 600 | sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF); | |
| 4449 |
3/4✓ Branch 0 taken 35 times.
✓ Branch 1 taken 565 times.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
|
600 | if (sd && sd->size >= sizeof(s->dovi_ctx.cfg)) |
| 4450 | 35 | s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data; | |
| 4451 | } | ||
| 4452 | |||
| 4453 | 601 | return 0; | |
| 4454 | } | ||
| 4455 | |||
| 4456 | ✗ | static av_cold void hevc_decode_flush(AVCodecContext *avctx) | |
| 4457 | { | ||
| 4458 | ✗ | HEVCContext *s = avctx->priv_data; | |
| 4459 | ✗ | ff_hevc_flush_dpb(s); | |
| 4460 | ✗ | ff_hevc_reset_sei(&s->sei); | |
| 4461 | ✗ | ff_dovi_ctx_flush(&s->dovi_ctx); | |
| 4462 | ✗ | av_buffer_unref(&s->rpu_buf); | |
| 4463 | ✗ | s->eos = 1; | |
| 4464 | ✗ | s->skipping_frame = 0; | |
| 4465 | |||
| 4466 | ✗ | if (FF_HW_HAS_CB(avctx, flush)) | |
| 4467 | ✗ | FF_HW_SIMPLE_CALL(avctx, flush); | |
| 4468 | ✗ | } | |
| 4469 | |||
| 4470 | #define OFFSET(x) offsetof(HEVCContext, x) | ||
| 4471 | #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) | ||
| 4472 | |||
| 4473 | static const AVOption options[] = { | ||
| 4474 | { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin), | ||
| 4475 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
| 4476 | { "strict-displaywin", "strictly apply default display window size", OFFSET(apply_defdispwin), | ||
| 4477 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
| 4478 | { "view_ids", "Array of view IDs that should be decoded and output; a single -1 to decode all views", | ||
| 4479 | .offset = OFFSET(view_ids), .type = AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, | ||
| 4480 | .min = -1, .max = INT_MAX, .flags = PAR }, | ||
| 4481 | { "view_ids_available", "Array of available view IDs is exported here", | ||
| 4482 | .offset = OFFSET(view_ids_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY, | ||
| 4483 | .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY }, | ||
| 4484 | { "view_pos_available", "Array of view positions for view_ids_available is exported here, as AVStereo3DView", | ||
| 4485 | .offset = OFFSET(view_pos_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY, | ||
| 4486 | .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY, .unit = "view_pos" }, | ||
| 4487 | { "unspecified", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_UNSPEC }, .unit = "view_pos" }, | ||
| 4488 | { "left", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_LEFT }, .unit = "view_pos" }, | ||
| 4489 | { "right", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_RIGHT }, .unit = "view_pos" }, | ||
| 4490 | |||
| 4491 | { NULL }, | ||
| 4492 | }; | ||
| 4493 | |||
| 4494 | static const AVClass hevc_decoder_class = { | ||
| 4495 | .class_name = "HEVC decoder", | ||
| 4496 | .item_name = av_default_item_name, | ||
| 4497 | .option = options, | ||
| 4498 | .version = LIBAVUTIL_VERSION_INT, | ||
| 4499 | }; | ||
| 4500 | |||
| 4501 | const FFCodec ff_hevc_decoder = { | ||
| 4502 | .p.name = "hevc", | ||
| 4503 | CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"), | ||
| 4504 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 4505 | .p.id = AV_CODEC_ID_HEVC, | ||
| 4506 | .priv_data_size = sizeof(HEVCContext), | ||
| 4507 | .p.priv_class = &hevc_decoder_class, | ||
| 4508 | .init = hevc_decode_init, | ||
| 4509 | .close = hevc_decode_free, | ||
| 4510 | FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame), | ||
| 4511 | .flush = hevc_decode_flush, | ||
| 4512 | UPDATE_THREAD_CONTEXT(hevc_update_thread_context), | ||
| 4513 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | | ||
| 4514 | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, | ||
| 4515 | .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | | ||
| 4516 | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | | ||
| 4517 | FF_CODEC_CAP_USES_PROGRESSFRAMES | | ||
| 4518 | FF_CODEC_CAP_INIT_CLEANUP, | ||
| 4519 | .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles), | ||
| 4520 | .hw_configs = (const AVCodecHWConfigInternal *const []) { | ||
| 4521 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
| 4522 | HWACCEL_DXVA2(hevc), | ||
| 4523 | #endif | ||
| 4524 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
| 4525 | HWACCEL_D3D11VA(hevc), | ||
| 4526 | #endif | ||
| 4527 | #if CONFIG_HEVC_D3D11VA2_HWACCEL | ||
| 4528 | HWACCEL_D3D11VA2(hevc), | ||
| 4529 | #endif | ||
| 4530 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
| 4531 | HWACCEL_D3D12VA(hevc), | ||
| 4532 | #endif | ||
| 4533 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
| 4534 | HWACCEL_NVDEC(hevc), | ||
| 4535 | #endif | ||
| 4536 | #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL | ||
| 4537 | HWACCEL_NVDEC_CUARRAY(hevc), | ||
| 4538 | #endif | ||
| 4539 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
| 4540 | HWACCEL_VAAPI(hevc), | ||
| 4541 | #endif | ||
| 4542 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
| 4543 | HWACCEL_VDPAU(hevc), | ||
| 4544 | #endif | ||
| 4545 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
| 4546 | HWACCEL_VIDEOTOOLBOX(hevc), | ||
| 4547 | #endif | ||
| 4548 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
| 4549 | HWACCEL_VULKAN(hevc), | ||
| 4550 | #endif | ||
| 4551 | NULL | ||
| 4552 | }, | ||
| 4553 | }; | ||
| 4554 |