| 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 | 1398 | static void pic_arrays_free(HEVCLayerContext *l) | |
| 75 | { | ||
| 76 | 1398 | av_freep(&l->sao); | |
| 77 | 1398 | av_freep(&l->deblock); | |
| 78 | |||
| 79 | 1398 | av_freep(&l->skip_flag); | |
| 80 | 1398 | av_freep(&l->tab_ct_depth); | |
| 81 | |||
| 82 | 1398 | av_freep(&l->tab_ipm); | |
| 83 | 1398 | av_freep(&l->cbf_luma); | |
| 84 | 1398 | av_freep(&l->is_pcm); | |
| 85 | |||
| 86 | 1398 | av_freep(&l->qp_y_tab); | |
| 87 | 1398 | av_freep(&l->tab_slice_address); | |
| 88 | 1398 | av_freep(&l->filter_slice_edges); | |
| 89 | |||
| 90 | 1398 | av_freep(&l->horizontal_bs); | |
| 91 | 1398 | av_freep(&l->vertical_bs); | |
| 92 | |||
| 93 |
2/2✓ Branch 0 taken 4194 times.
✓ Branch 1 taken 1398 times.
|
5592 | for (int i = 0; i < 3; i++) { |
| 94 | 4194 | av_freep(&l->sao_pixel_buffer_h[i]); | |
| 95 | 4194 | av_freep(&l->sao_pixel_buffer_v[i]); | |
| 96 | } | ||
| 97 | |||
| 98 | 1398 | av_refstruct_pool_uninit(&l->tab_mvf_pool); | |
| 99 | 1398 | av_refstruct_pool_uninit(&l->rpl_tab_pool); | |
| 100 | 1398 | } | |
| 101 | |||
| 102 | /* allocate arrays that depend on frame dimensions */ | ||
| 103 | 244 | static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps) | |
| 104 | { | ||
| 105 | 244 | int log2_min_cb_size = sps->log2_min_cb_size; | |
| 106 | 244 | int width = sps->width; | |
| 107 | 244 | int height = sps->height; | |
| 108 | 244 | int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) * | |
| 109 | 244 | ((height >> log2_min_cb_size) + 1); | |
| 110 | 244 | int ctb_count = sps->ctb_width * sps->ctb_height; | |
| 111 | 244 | int min_pu_size = sps->min_pu_width * sps->min_pu_height; | |
| 112 | |||
| 113 | 244 | l->bs_width = (width >> 2) + 1; | |
| 114 | 244 | l->bs_height = (height >> 2) + 1; | |
| 115 | |||
| 116 | 244 | l->sao = av_calloc(ctb_count, sizeof(*l->sao)); | |
| 117 | 244 | l->deblock = av_calloc(ctb_count, sizeof(*l->deblock)); | |
| 118 |
2/4✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 244 times.
|
244 | if (!l->sao || !l->deblock) |
| 119 | ✗ | goto fail; | |
| 120 | |||
| 121 | 244 | l->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
| 122 | 244 | l->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width); | |
| 123 |
2/4✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 244 times.
|
244 | if (!l->skip_flag || !l->tab_ct_depth) |
| 124 | ✗ | goto fail; | |
| 125 | |||
| 126 | 244 | l->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height); | |
| 127 | 244 | l->tab_ipm = av_mallocz(min_pu_size); | |
| 128 | 244 | l->is_pcm = av_malloc_array(sps->min_pu_width + 1, sps->min_pu_height + 1); | |
| 129 |
3/6✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 244 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 244 times.
|
244 | if (!l->tab_ipm || !l->cbf_luma || !l->is_pcm) |
| 130 | ✗ | goto fail; | |
| 131 | |||
| 132 | 244 | l->filter_slice_edges = av_mallocz(ctb_count); | |
| 133 | 244 | l->tab_slice_address = av_malloc_array(pic_size_in_ctb, | |
| 134 | sizeof(*l->tab_slice_address)); | ||
| 135 | 244 | l->qp_y_tab = av_calloc(pic_size_in_ctb, | |
| 136 | sizeof(*l->qp_y_tab)); | ||
| 137 |
3/6✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 244 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 244 times.
|
244 | if (!l->qp_y_tab || !l->filter_slice_edges || !l->tab_slice_address) |
| 138 | ✗ | goto fail; | |
| 139 | |||
| 140 | 244 | l->horizontal_bs = av_calloc(l->bs_width, l->bs_height); | |
| 141 | 244 | l->vertical_bs = av_calloc(l->bs_width, l->bs_height); | |
| 142 |
2/4✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 244 times.
|
244 | if (!l->horizontal_bs || !l->vertical_bs) |
| 143 | ✗ | goto fail; | |
| 144 | |||
| 145 | 244 | l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0); | |
| 146 | 244 | l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0); | |
| 147 |
2/4✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 244 times.
|
244 | if (!l->tab_mvf_pool || !l->rpl_tab_pool) |
| 148 | ✗ | goto fail; | |
| 149 | |||
| 150 |
2/2✓ Branch 0 taken 215 times.
✓ Branch 1 taken 29 times.
|
244 | if (sps->sao_enabled) { |
| 151 |
2/2✓ Branch 0 taken 214 times.
✓ Branch 1 taken 1 times.
|
215 | int c_count = (sps->chroma_format_idc != 0) ? 3 : 1; |
| 152 | |||
| 153 |
2/2✓ Branch 0 taken 643 times.
✓ Branch 1 taken 215 times.
|
858 | for (int c_idx = 0; c_idx < c_count; c_idx++) { |
| 154 | 643 | int w = sps->width >> sps->hshift[c_idx]; | |
| 155 | 643 | int h = sps->height >> sps->vshift[c_idx]; | |
| 156 | 643 | l->sao_pixel_buffer_h[c_idx] = | |
| 157 | 643 | av_mallocz((w * 2 * sps->ctb_height) << | |
| 158 | 643 | sps->pixel_shift); | |
| 159 | 643 | l->sao_pixel_buffer_v[c_idx] = | |
| 160 | 643 | av_mallocz((h * 2 * sps->ctb_width) << | |
| 161 | 643 | sps->pixel_shift); | |
| 162 |
1/2✓ Branch 0 taken 643 times.
✗ Branch 1 not taken.
|
643 | if (!l->sao_pixel_buffer_h[c_idx] || |
| 163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 643 times.
|
643 | !l->sao_pixel_buffer_v[c_idx]) |
| 164 | ✗ | goto fail; | |
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | 244 | 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 | 20243 | static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps, | |
| 276 | GetBitContext *gb, int cur_poc, int poc_lsb) | ||
| 277 | { | ||
| 278 | 20243 | int max_poc_lsb = 1 << sps->log2_max_poc_lsb; | |
| 279 | 20243 | int prev_delta_msb = 0; | |
| 280 | 20243 | unsigned int nb_sps = 0, nb_sh; | |
| 281 | int i; | ||
| 282 | |||
| 283 | 20243 | rps->nb_refs = 0; | |
| 284 |
2/2✓ Branch 0 taken 18841 times.
✓ Branch 1 taken 1402 times.
|
20243 | if (!sps->long_term_ref_pics_present) |
| 285 | 18841 | 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 | 808 | static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) | |
| 333 | { | ||
| 334 | 808 | AVCodecContext *avctx = s->avctx; | |
| 335 | 808 | const HEVCVPS *vps = sps->vps; | |
| 336 | 808 | const HEVCWindow *ow = &sps->output_window; | |
| 337 | 808 | unsigned int num = 0, den = 0; | |
| 338 | |||
| 339 | 808 | avctx->pix_fmt = sps->pix_fmt; | |
| 340 | 808 | avctx->coded_width = sps->width; | |
| 341 | 808 | avctx->coded_height = sps->height; | |
| 342 | 808 | avctx->width = sps->width - ow->left_offset - ow->right_offset; | |
| 343 | 808 | avctx->height = sps->height - ow->top_offset - ow->bottom_offset; | |
| 344 | 808 | avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics; | |
| 345 | 808 | avctx->profile = sps->ptl.general_ptl.profile_idc; | |
| 346 | 808 | avctx->level = sps->ptl.general_ptl.level_idc; | |
| 347 | |||
| 348 | 808 | ff_set_sar(avctx, sps->vui.common.sar); | |
| 349 | |||
| 350 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 680 times.
|
808 | if (sps->vui.common.video_signal_type_present_flag) |
| 351 | 128 | avctx->color_range = sps->vui.common.video_full_range_flag ? AVCOL_RANGE_JPEG | |
| 352 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 118 times.
|
128 | : AVCOL_RANGE_MPEG; |
| 353 | else | ||
| 354 | 680 | avctx->color_range = AVCOL_RANGE_MPEG; | |
| 355 | |||
| 356 |
2/2✓ Branch 0 taken 121 times.
✓ Branch 1 taken 687 times.
|
808 | if (sps->vui.common.colour_description_present_flag) { |
| 357 | 121 | avctx->color_primaries = sps->vui.common.colour_primaries; | |
| 358 | 121 | avctx->color_trc = sps->vui.common.transfer_characteristics; | |
| 359 | 121 | avctx->colorspace = sps->vui.common.matrix_coeffs; | |
| 360 | } else { | ||
| 361 | 687 | avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; | |
| 362 | 687 | avctx->color_trc = AVCOL_TRC_UNSPECIFIED; | |
| 363 | 687 | avctx->colorspace = AVCOL_SPC_UNSPECIFIED; | |
| 364 | } | ||
| 365 | |||
| 366 | 808 | avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED; | |
| 367 |
2/2✓ Branch 0 taken 767 times.
✓ Branch 1 taken 41 times.
|
808 | if (sps->chroma_format_idc == 1) { |
| 368 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 724 times.
|
767 | if (sps->vui.common.chroma_loc_info_present_flag) { |
| 369 |
1/2✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
|
43 | if (sps->vui.common.chroma_sample_loc_type_top_field <= 5) |
| 370 | 43 | avctx->chroma_sample_location = sps->vui.common.chroma_sample_loc_type_top_field + 1; | |
| 371 | } else | ||
| 372 | 724 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; | |
| 373 | } | ||
| 374 | |||
| 375 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 762 times.
|
808 | if (vps->vps_timing_info_present_flag) { |
| 376 | 46 | num = vps->vps_num_units_in_tick; | |
| 377 | 46 | den = vps->vps_time_scale; | |
| 378 |
2/2✓ Branch 0 taken 105 times.
✓ Branch 1 taken 657 times.
|
762 | } else if (sps->vui.vui_timing_info_present_flag) { |
| 379 | 105 | num = sps->vui.vui_num_units_in_tick; | |
| 380 | 105 | den = sps->vui.vui_time_scale; | |
| 381 | } | ||
| 382 | |||
| 383 |
3/4✓ Branch 0 taken 151 times.
✓ Branch 1 taken 657 times.
✓ Branch 2 taken 151 times.
✗ Branch 3 not taken.
|
808 | if (num > 0 && den > 0) |
| 384 | 151 | av_reduce(&avctx->framerate.den, &avctx->framerate.num, | |
| 385 | num, den, 1 << 30); | ||
| 386 | 808 | } | |
| 387 | |||
| 388 | 10927 | static int export_stream_params_from_sei(HEVCContext *s) | |
| 389 | { | ||
| 390 | 10927 | AVCodecContext *avctx = s->avctx; | |
| 391 | |||
| 392 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10927 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10927 | 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 | 10927 | return 0; | |
| 399 | } | ||
| 400 | |||
| 401 | 586 | static int export_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
| 402 | { | ||
| 403 | 586 | const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi; | |
| 404 | |||
| 405 | 586 | av_freep(&s->view_ids_available); | |
| 406 | 586 | s->nb_view_ids_available = 0; | |
| 407 | 586 | av_freep(&s->view_pos_available); | |
| 408 | 586 | 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 563 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 563 times.
✗ Branch 3 not taken.
|
586 | if (vps->nb_layers < 2 && !vps->view_id[0]) |
| 412 | 563 | 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 | 11261 | int ff_hevc_is_alpha_video(const HEVCContext *s) | |
| 441 | { | ||
| 442 | 11261 | const HEVCVPS *vps = s->vps; | |
| 443 | 11261 | int ret = 0; | |
| 444 | |||
| 445 |
3/4✓ Branch 0 taken 1200 times.
✓ Branch 1 taken 10061 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1200 times.
|
11261 | if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1]) |
| 446 | 10061 | return 0; | |
| 447 | |||
| 448 | /* decode_vps_ext() guarantees that SCALABILITY_AUXILIARY with AuxId other | ||
| 449 | * than alpha cannot reach here. | ||
| 450 | */ | ||
| 451 | 1200 | ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY); | |
| 452 | |||
| 453 |
2/2✓ Branch 0 taken 153 times.
✓ Branch 1 taken 1047 times.
|
1200 | av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n", |
| 454 | ret ? "is" : "not"); | ||
| 455 | |||
| 456 | 1200 | return ret; | |
| 457 | } | ||
| 458 | |||
| 459 | 232 | int ff_hevc_requested_layers(const HEVCContext *s, const HEVCVPS *vps, | |
| 460 | unsigned *active_output) | ||
| 461 | { | ||
| 462 | 232 | unsigned layers_active_output = 0, highest_layer; | |
| 463 | |||
| 464 | // nothing requested - decode base layer only | ||
| 465 |
2/2✓ Branch 0 taken 221 times.
✓ Branch 1 taken 11 times.
|
232 | if (!s->nb_view_ids) { |
| 466 | 221 | *active_output = 1; | |
| 467 | 221 | 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 | 233 | static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps) | |
| 520 | { | ||
| 521 | unsigned layers_active_output; | ||
| 522 | int nb_decode_layers; | ||
| 523 | |||
| 524 | 233 | s->layers_active_output = 1; | |
| 525 | 233 | s->layers_active_decode = 1; | |
| 526 | |||
| 527 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 232 times.
|
233 | 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 | 232 | nb_decode_layers = ff_hevc_requested_layers(s, vps, &layers_active_output); | |
| 540 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 232 times.
|
232 | if (nb_decode_layers < 0) |
| 541 | ✗ | return nb_decode_layers; | |
| 542 | |||
| 543 | 232 | s->layers_active_decode = (1 << nb_decode_layers) - 1; | |
| 544 | 232 | s->layers_active_output = layers_active_output; | |
| 545 | |||
| 546 | 232 | av_log(s->avctx, AV_LOG_DEBUG, "decode/output layers: %x/%x\n", | |
| 547 | s->layers_active_decode, s->layers_active_output); | ||
| 548 | |||
| 549 | 232 | 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 | 233 | 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 | 233 | enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts; | |
| 592 | 233 | enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE; | |
| 593 | int ret; | ||
| 594 | |||
| 595 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 232 times.
|
233 | 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 189 times.
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
|
233 | switch (sps->pix_fmt) { |
| 599 | 189 | 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 | 189 | *fmt++ = AV_PIX_FMT_VAAPI; | |
| 613 | #endif | ||
| 614 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
| 615 | 189 | *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 | 189 | 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 | 6 | case AV_PIX_FMT_YUV422P: | |
| 681 | case AV_PIX_FMT_YUV422P10LE: | ||
| 682 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
| 683 | 6 | *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 | 6 | 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 232 times.
|
233 | if (alpha_fmt != AV_PIX_FMT_NONE) |
| 738 | 1 | *fmt++ = alpha_fmt; | |
| 739 | 233 | *fmt++ = sps->pix_fmt; | |
| 740 | 233 | *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 | 233 | ret = export_multilayer(s, sps->vps); | |
| 745 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 233 times.
|
233 | if (ret < 0) |
| 746 | ✗ | return ret; | |
| 747 | |||
| 748 | 233 | ret = ff_get_format(s->avctx, pix_fmts); | |
| 749 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 233 times.
|
233 | if (ret < 0) |
| 750 | ✗ | return ret; | |
| 751 | 233 | s->avctx->pix_fmt = ret; | |
| 752 | |||
| 753 | // set up multilayer decoding, if requested by caller | ||
| 754 | 233 | ret = setup_multilayer(s, sps->vps); | |
| 755 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 233 times.
|
233 | if (ret < 0) |
| 756 | ✗ | return ret; | |
| 757 | |||
| 758 | 233 | return 0; | |
| 759 | } | ||
| 760 | |||
| 761 | 244 | static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) | |
| 762 | { | ||
| 763 | int ret; | ||
| 764 | |||
| 765 | 244 | pic_arrays_free(l); | |
| 766 | 244 | av_refstruct_unref(&l->sps); | |
| 767 | 244 | av_refstruct_unref(&s->vps); | |
| 768 | |||
| 769 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 244 times.
|
244 | if (!sps) |
| 770 | ✗ | return 0; | |
| 771 | |||
| 772 | 244 | ret = pic_arrays_init(l, sps); | |
| 773 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 244 times.
|
244 | if (ret < 0) |
| 774 | ✗ | goto fail; | |
| 775 | |||
| 776 | 244 | ff_hevc_pred_init(&s->hpc, sps->bit_depth); | |
| 777 | 244 | ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); | |
| 778 | 244 | ff_videodsp_init (&s->vdsp, sps->bit_depth); | |
| 779 | |||
| 780 | 244 | l->sps = av_refstruct_ref_c(sps); | |
| 781 | 244 | s->vps = av_refstruct_ref_c(sps->vps); | |
| 782 | |||
| 783 | 244 | return 0; | |
| 784 | |||
| 785 | ✗ | fail: | |
| 786 | ✗ | pic_arrays_free(l); | |
| 787 | ✗ | av_refstruct_unref(&l->sps); | |
| 788 | ✗ | return ret; | |
| 789 | } | ||
| 790 | |||
| 791 | 28417 | 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, layer_idx; | ||
| 797 | int i, ret; | ||
| 798 | |||
| 799 | // Coded parameters | ||
| 800 | 28417 | sh->first_slice_in_pic_flag = get_bits1(gb); | |
| 801 | |||
| 802 | 28417 | sh->no_output_of_prior_pics_flag = 0; | |
| 803 |
3/4✓ Branch 0 taken 1038 times.
✓ Branch 1 taken 27379 times.
✓ Branch 2 taken 1038 times.
✗ Branch 3 not taken.
|
28417 | if (IS_IRAP(s)) |
| 804 | 1038 | sh->no_output_of_prior_pics_flag = get_bits1(gb); | |
| 805 | |||
| 806 | 28417 | pps_id = get_ue_golomb_long(gb); | |
| 807 |
2/4✓ Branch 0 taken 28417 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 28417 times.
|
28417 | 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 10421 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17996 times.
|
28417 | 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 | 28417 | sh->pps_id = pps_id; | |
| 816 | |||
| 817 | 28417 | pps = s->ps.pps_list[pps_id]; | |
| 818 | 28417 | sps = pps->sps; | |
| 819 | 28417 | vps = sps->vps; | |
| 820 | 28417 | layer_idx = vps->layer_idx[s->nuh_layer_id]; | |
| 821 | |||
| 822 |
4/4✓ Branch 0 taken 487 times.
✓ Branch 1 taken 27930 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 478 times.
|
28417 | if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) |
| 823 | 9 | sh->no_output_of_prior_pics_flag = 1; | |
| 824 | |||
| 825 | 28417 | sh->dependent_slice_segment_flag = 0; | |
| 826 |
2/2✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10421 times.
|
28417 | if (!sh->first_slice_in_pic_flag) { |
| 827 | int slice_address_length; | ||
| 828 | |||
| 829 |
2/2✓ Branch 0 taken 8936 times.
✓ Branch 1 taken 9060 times.
|
17996 | if (pps->dependent_slice_segments_enabled_flag) |
| 830 | 8936 | sh->dependent_slice_segment_flag = get_bits1(gb); | |
| 831 |
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) { |
| 832 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); | |
| 833 | ✗ | return AVERROR_INVALIDDATA; | |
| 834 | } | ||
| 835 | |||
| 836 | 17996 | slice_address_length = av_ceil_log2(sps->ctb_width * | |
| 837 | 17996 | sps->ctb_height); | |
| 838 | 17996 | sh->slice_segment_addr = get_bitsz(gb, slice_address_length); | |
| 839 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17996 times.
|
17996 | if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) { |
| 840 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 841 | "Invalid slice segment address: %u.\n", | ||
| 842 | sh->slice_segment_addr); | ||
| 843 | ✗ | return AVERROR_INVALIDDATA; | |
| 844 | } | ||
| 845 | |||
| 846 |
2/2✓ Branch 0 taken 10202 times.
✓ Branch 1 taken 7794 times.
|
17996 | if (!sh->dependent_slice_segment_flag) { |
| 847 | 10202 | sh->slice_addr = sh->slice_segment_addr; | |
| 848 | } | ||
| 849 | } else { | ||
| 850 | 10421 | sh->slice_segment_addr = sh->slice_addr = 0; | |
| 851 | } | ||
| 852 | |||
| 853 |
2/2✓ Branch 0 taken 20623 times.
✓ Branch 1 taken 7794 times.
|
28417 | if (!sh->dependent_slice_segment_flag) { |
| 854 |
2/2✓ Branch 0 taken 1823 times.
✓ Branch 1 taken 20623 times.
|
22446 | for (i = 0; i < pps->num_extra_slice_header_bits; i++) |
| 855 | 1823 | skip_bits(gb, 1); // slice_reserved_undetermined_flag[] | |
| 856 | |||
| 857 | 20623 | sh->slice_type = get_ue_golomb_long(gb); | |
| 858 |
2/2✓ Branch 0 taken 19642 times.
✓ Branch 1 taken 981 times.
|
20623 | if (!(sh->slice_type == HEVC_SLICE_I || |
| 859 |
2/2✓ Branch 0 taken 15309 times.
✓ Branch 1 taken 4333 times.
|
19642 | sh->slice_type == HEVC_SLICE_P || |
| 860 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15309 times.
|
15309 | sh->slice_type == HEVC_SLICE_B)) { |
| 861 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", | |
| 862 | ✗ | sh->slice_type); | |
| 863 | ✗ | return AVERROR_INVALIDDATA; | |
| 864 | } | ||
| 865 |
5/6✓ Branch 0 taken 802 times.
✓ Branch 1 taken 19821 times.
✓ Branch 2 taken 802 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 721 times.
|
20623 | if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I && |
| 866 |
1/2✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
|
81 | !pps->pps_curr_pic_ref_enabled_flag && |
| 867 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
|
81 | s->nuh_layer_id == 0) { |
| 868 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); | |
| 869 | ✗ | return AVERROR_INVALIDDATA; | |
| 870 | } | ||
| 871 | |||
| 872 | // when flag is not present, picture is inferred to be output | ||
| 873 | 20623 | sh->pic_output_flag = 1; | |
| 874 |
2/2✓ Branch 0 taken 700 times.
✓ Branch 1 taken 19923 times.
|
20623 | if (pps->output_flag_present_flag) |
| 875 | 700 | sh->pic_output_flag = get_bits1(gb); | |
| 876 | |||
| 877 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20623 times.
|
20623 | if (sps->separate_colour_plane) |
| 878 | ✗ | sh->colour_plane_id = get_bits(gb, 2); | |
| 879 | |||
| 880 |
4/4✓ Branch 0 taken 20279 times.
✓ Branch 1 taken 344 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 20243 times.
|
20623 | if (!IS_IDR(s) || |
| 881 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 362 times.
|
380 | (s->nuh_layer_id > 0 && |
| 882 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5 times.
|
18 | !(vps->poc_lsb_not_present & (1 << layer_idx)))) { |
| 883 | int poc; | ||
| 884 | |||
| 885 | 20256 | sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb); | |
| 886 | 20256 | poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type); | |
| 887 |
3/4✓ Branch 0 taken 10073 times.
✓ Branch 1 taken 10183 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10073 times.
|
20256 | if (!sh->first_slice_in_pic_flag && poc != sh->poc) { |
| 888 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
| 889 | "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc); | ||
| 890 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
| 891 | ✗ | return AVERROR_INVALIDDATA; | |
| 892 | ✗ | poc = sh->poc; | |
| 893 | } | ||
| 894 | 20256 | sh->poc = poc; | |
| 895 | } | ||
| 896 | |||
| 897 |
4/4✓ Branch 0 taken 20279 times.
✓ Branch 1 taken 344 times.
✓ Branch 2 taken 20243 times.
✓ Branch 3 taken 36 times.
|
40866 | if (!IS_IDR(s)) { |
| 898 | int pos; | ||
| 899 | |||
| 900 | 20243 | sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); | |
| 901 | 20243 | pos = get_bits_left(gb); | |
| 902 |
2/2✓ Branch 0 taken 3938 times.
✓ Branch 1 taken 16305 times.
|
20243 | if (!sh->short_term_ref_pic_set_sps_flag) { |
| 903 | 3938 | ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1); | |
| 904 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3938 times.
|
3938 | if (ret < 0) |
| 905 | ✗ | return ret; | |
| 906 | |||
| 907 | 3938 | sh->short_term_rps = &sh->slice_rps; | |
| 908 | } else { | ||
| 909 | int numbits, rps_idx; | ||
| 910 | |||
| 911 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16305 times.
|
16305 | if (!sps->nb_st_rps) { |
| 912 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); | |
| 913 | ✗ | return AVERROR_INVALIDDATA; | |
| 914 | } | ||
| 915 | |||
| 916 | 16305 | numbits = av_ceil_log2(sps->nb_st_rps); | |
| 917 |
2/2✓ Branch 0 taken 16277 times.
✓ Branch 1 taken 28 times.
|
16305 | rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; |
| 918 | 16305 | sh->short_term_rps = &sps->st_rps[rps_idx]; | |
| 919 | } | ||
| 920 | 20243 | sh->short_term_ref_pic_set_size = pos - get_bits_left(gb); | |
| 921 | |||
| 922 | 20243 | pos = get_bits_left(gb); | |
| 923 | 20243 | ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb); | |
| 924 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20243 times.
|
20243 | if (ret < 0) { |
| 925 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n"); | |
| 926 | ✗ | if (s->avctx->err_recognition & AV_EF_EXPLODE) | |
| 927 | ✗ | return AVERROR_INVALIDDATA; | |
| 928 | } | ||
| 929 | 20243 | sh->long_term_ref_pic_set_size = pos - get_bits_left(gb); | |
| 930 | |||
| 931 |
2/2✓ Branch 0 taken 17809 times.
✓ Branch 1 taken 2434 times.
|
20243 | if (sps->temporal_mvp_enabled) |
| 932 | 17809 | sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); | |
| 933 | else | ||
| 934 | 2434 | sh->slice_temporal_mvp_enabled_flag = 0; | |
| 935 | } else { | ||
| 936 | 380 | sh->poc = 0; | |
| 937 | 380 | sh->pic_order_cnt_lsb = 0; | |
| 938 | 380 | sh->short_term_ref_pic_set_sps_flag = 0; | |
| 939 | 380 | sh->short_term_ref_pic_set_size = 0; | |
| 940 | 380 | sh->short_term_rps = NULL; | |
| 941 | 380 | sh->long_term_ref_pic_set_size = 0; | |
| 942 | 380 | sh->long_term_rps.nb_refs = 0; | |
| 943 | 380 | sh->slice_temporal_mvp_enabled_flag = 0; | |
| 944 | } | ||
| 945 | |||
| 946 | 20623 | sh->inter_layer_pred = 0; | |
| 947 |
2/2✓ Branch 0 taken 516 times.
✓ Branch 1 taken 20107 times.
|
20623 | if (s->nuh_layer_id > 0) { |
| 948 | 516 | int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx]; | |
| 949 | |||
| 950 |
2/2✓ Branch 0 taken 418 times.
✓ Branch 1 taken 98 times.
|
516 | if (vps->default_ref_layers_active) |
| 951 | 418 | sh->inter_layer_pred = !!num_direct_ref_layers; | |
| 952 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 50 times.
|
98 | else if (num_direct_ref_layers) { |
| 953 | 48 | sh->inter_layer_pred = get_bits1(gb); | |
| 954 | |||
| 955 |
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) { |
| 956 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 957 | "NumDirectRefLayers>1 not supported\n"); | ||
| 958 | ✗ | return AVERROR_PATCHWELCOME; | |
| 959 | } | ||
| 960 | } | ||
| 961 | } | ||
| 962 | |||
| 963 |
2/2✓ Branch 0 taken 17237 times.
✓ Branch 1 taken 3386 times.
|
20623 | if (sps->sao_enabled) { |
| 964 | 17237 | sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); | |
| 965 |
2/2✓ Branch 0 taken 17236 times.
✓ Branch 1 taken 1 times.
|
17237 | if (sps->chroma_format_idc) { |
| 966 | 17236 | sh->slice_sample_adaptive_offset_flag[1] = | |
| 967 | 17236 | sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); | |
| 968 | } | ||
| 969 | } else { | ||
| 970 | 3386 | sh->slice_sample_adaptive_offset_flag[0] = 0; | |
| 971 | 3386 | sh->slice_sample_adaptive_offset_flag[1] = 0; | |
| 972 | 3386 | sh->slice_sample_adaptive_offset_flag[2] = 0; | |
| 973 | } | ||
| 974 | |||
| 975 | 20623 | sh->nb_refs[L0] = sh->nb_refs[L1] = 0; | |
| 976 |
4/4✓ Branch 0 taken 16290 times.
✓ Branch 1 taken 4333 times.
✓ Branch 2 taken 15309 times.
✓ Branch 3 taken 981 times.
|
20623 | if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) { |
| 977 | int nb_refs; | ||
| 978 | |||
| 979 | 19642 | sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active; | |
| 980 |
2/2✓ Branch 0 taken 15309 times.
✓ Branch 1 taken 4333 times.
|
19642 | if (sh->slice_type == HEVC_SLICE_B) |
| 981 | 15309 | sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active; | |
| 982 | |||
| 983 |
2/2✓ Branch 1 taken 5430 times.
✓ Branch 2 taken 14212 times.
|
19642 | if (get_bits1(gb)) { // num_ref_idx_active_override_flag |
| 984 | 5430 | sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1; | |
| 985 |
2/2✓ Branch 0 taken 2862 times.
✓ Branch 1 taken 2568 times.
|
5430 | if (sh->slice_type == HEVC_SLICE_B) |
| 986 | 2862 | sh->nb_refs[L1] = get_ue_golomb_31(gb) + 1; | |
| 987 | } | ||
| 988 |
2/4✓ Branch 0 taken 19642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19642 times.
|
19642 | if (sh->nb_refs[L0] >= HEVC_MAX_REFS || sh->nb_refs[L1] >= HEVC_MAX_REFS) { |
| 989 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n", | |
| 990 | sh->nb_refs[L0], sh->nb_refs[L1]); | ||
| 991 | ✗ | return AVERROR_INVALIDDATA; | |
| 992 | } | ||
| 993 | |||
| 994 | 19642 | sh->rpl_modification_flag[0] = 0; | |
| 995 | 19642 | sh->rpl_modification_flag[1] = 0; | |
| 996 | 19642 | nb_refs = ff_hevc_frame_nb_refs(sh, pps, layer_idx); | |
| 997 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19642 times.
|
19642 | if (!nb_refs) { |
| 998 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); | |
| 999 | ✗ | return AVERROR_INVALIDDATA; | |
| 1000 | } | ||
| 1001 | |||
| 1002 |
4/4✓ Branch 0 taken 2302 times.
✓ Branch 1 taken 17340 times.
✓ Branch 2 taken 1978 times.
✓ Branch 3 taken 324 times.
|
19642 | if (pps->lists_modification_present_flag && nb_refs > 1) { |
| 1003 | 1978 | sh->rpl_modification_flag[0] = get_bits1(gb); | |
| 1004 |
2/2✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 546 times.
|
1978 | if (sh->rpl_modification_flag[0]) { |
| 1005 |
2/2✓ Branch 0 taken 3366 times.
✓ Branch 1 taken 1432 times.
|
4798 | for (i = 0; i < sh->nb_refs[L0]; i++) |
| 1006 | 3366 | sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
| 1007 | } | ||
| 1008 | |||
| 1009 |
2/2✓ Branch 0 taken 1795 times.
✓ Branch 1 taken 183 times.
|
1978 | if (sh->slice_type == HEVC_SLICE_B) { |
| 1010 | 1795 | sh->rpl_modification_flag[1] = get_bits1(gb); | |
| 1011 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 1143 times.
|
1795 | if (sh->rpl_modification_flag[1] == 1) |
| 1012 |
2/2✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 652 times.
|
2207 | for (i = 0; i < sh->nb_refs[L1]; i++) |
| 1013 | 1555 | sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs)); | |
| 1014 | } | ||
| 1015 | } | ||
| 1016 | |||
| 1017 |
2/2✓ Branch 0 taken 15309 times.
✓ Branch 1 taken 4333 times.
|
19642 | if (sh->slice_type == HEVC_SLICE_B) |
| 1018 | 15309 | sh->mvd_l1_zero_flag = get_bits1(gb); | |
| 1019 | |||
| 1020 |
2/2✓ Branch 0 taken 16714 times.
✓ Branch 1 taken 2928 times.
|
19642 | if (pps->cabac_init_present_flag) |
| 1021 | 16714 | sh->cabac_init_flag = get_bits1(gb); | |
| 1022 | else | ||
| 1023 | 2928 | sh->cabac_init_flag = 0; | |
| 1024 | |||
| 1025 | 19642 | sh->collocated_ref_idx = 0; | |
| 1026 |
2/2✓ Branch 0 taken 17157 times.
✓ Branch 1 taken 2485 times.
|
19642 | if (sh->slice_temporal_mvp_enabled_flag) { |
| 1027 | 17157 | sh->collocated_list = L0; | |
| 1028 |
2/2✓ Branch 0 taken 14772 times.
✓ Branch 1 taken 2385 times.
|
17157 | if (sh->slice_type == HEVC_SLICE_B) |
| 1029 | 14772 | sh->collocated_list = !get_bits1(gb); | |
| 1030 | |||
| 1031 |
2/2✓ Branch 0 taken 15090 times.
✓ Branch 1 taken 2067 times.
|
17157 | if (sh->nb_refs[sh->collocated_list] > 1) { |
| 1032 | 15090 | sh->collocated_ref_idx = get_ue_golomb_long(gb); | |
| 1033 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15090 times.
|
15090 | if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { |
| 1034 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1035 | "Invalid collocated_ref_idx: %d.\n", | ||
| 1036 | sh->collocated_ref_idx); | ||
| 1037 | ✗ | return AVERROR_INVALIDDATA; | |
| 1038 | } | ||
| 1039 | } | ||
| 1040 | } | ||
| 1041 | |||
| 1042 |
4/4✓ Branch 0 taken 1547 times.
✓ Branch 1 taken 18095 times.
✓ Branch 2 taken 742 times.
✓ Branch 3 taken 805 times.
|
19642 | if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) || |
| 1043 |
3/4✓ Branch 0 taken 696 times.
✓ Branch 1 taken 18141 times.
✓ Branch 2 taken 696 times.
✗ Branch 3 not taken.
|
18837 | (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) { |
| 1044 | 1501 | ret = pred_weight_table(sh, s->avctx, sps, gb); | |
| 1045 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1501 times.
|
1501 | if (ret < 0) |
| 1046 | ✗ | return ret; | |
| 1047 | } | ||
| 1048 | |||
| 1049 | 19642 | sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb); | |
| 1050 |
2/4✓ Branch 0 taken 19642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19642 times.
|
19642 | if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) { |
| 1051 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1052 | "Invalid number of merging MVP candidates: %d.\n", | ||
| 1053 | ✗ | sh->max_num_merge_cand); | |
| 1054 | ✗ | return AVERROR_INVALIDDATA; | |
| 1055 | } | ||
| 1056 | |||
| 1057 | // Syntax in 7.3.6.1 | ||
| 1058 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19642 times.
|
19642 | if (sps->motion_vector_resolution_control_idc == 2) |
| 1059 | ✗ | sh->use_integer_mv_flag = get_bits1(gb); | |
| 1060 | else | ||
| 1061 | // Inferred to be equal to motion_vector_resolution_control_idc if not present | ||
| 1062 | 19642 | sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc; | |
| 1063 | |||
| 1064 | } | ||
| 1065 | |||
| 1066 | 20623 | sh->slice_qp_delta = get_se_golomb(gb); | |
| 1067 | |||
| 1068 |
2/2✓ Branch 0 taken 260 times.
✓ Branch 1 taken 20363 times.
|
20623 | if (pps->pic_slice_level_chroma_qp_offsets_present_flag) { |
| 1069 | 260 | sh->slice_cb_qp_offset = get_se_golomb(gb); | |
| 1070 | 260 | sh->slice_cr_qp_offset = get_se_golomb(gb); | |
| 1071 |
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 || |
| 1072 |
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) { |
| 1073 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid slice cx qp offset.\n"); | |
| 1074 | ✗ | return AVERROR_INVALIDDATA; | |
| 1075 | } | ||
| 1076 | } else { | ||
| 1077 | 20363 | sh->slice_cb_qp_offset = 0; | |
| 1078 | 20363 | sh->slice_cr_qp_offset = 0; | |
| 1079 | } | ||
| 1080 | |||
| 1081 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20623 times.
|
20623 | if (pps->pps_slice_act_qp_offsets_present_flag) { |
| 1082 | ✗ | sh->slice_act_y_qp_offset = get_se_golomb(gb); | |
| 1083 | ✗ | sh->slice_act_cb_qp_offset = get_se_golomb(gb); | |
| 1084 | ✗ | sh->slice_act_cr_qp_offset = get_se_golomb(gb); | |
| 1085 | } | ||
| 1086 | |||
| 1087 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 20582 times.
|
20623 | if (pps->chroma_qp_offset_list_enabled_flag) |
| 1088 | 41 | sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb); | |
| 1089 | else | ||
| 1090 | 20582 | sh->cu_chroma_qp_offset_enabled_flag = 0; | |
| 1091 | |||
| 1092 |
2/2✓ Branch 0 taken 3307 times.
✓ Branch 1 taken 17316 times.
|
20623 | if (pps->deblocking_filter_control_present_flag) { |
| 1093 | 3307 | int deblocking_filter_override_flag = 0; | |
| 1094 | |||
| 1095 |
2/2✓ Branch 0 taken 1007 times.
✓ Branch 1 taken 2300 times.
|
3307 | if (pps->deblocking_filter_override_enabled_flag) |
| 1096 | 1007 | deblocking_filter_override_flag = get_bits1(gb); | |
| 1097 | |||
| 1098 |
2/2✓ Branch 0 taken 416 times.
✓ Branch 1 taken 2891 times.
|
3307 | if (deblocking_filter_override_flag) { |
| 1099 | 416 | sh->disable_deblocking_filter_flag = get_bits1(gb); | |
| 1100 |
2/2✓ Branch 0 taken 304 times.
✓ Branch 1 taken 112 times.
|
416 | if (!sh->disable_deblocking_filter_flag) { |
| 1101 | 304 | int beta_offset_div2 = get_se_golomb(gb); | |
| 1102 | 304 | int tc_offset_div2 = get_se_golomb(gb) ; | |
| 1103 |
3/6✓ Branch 0 taken 304 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 304 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 304 times.
✗ Branch 5 not taken.
|
304 | if (beta_offset_div2 < -6 || beta_offset_div2 > 6 || |
| 1104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
|
304 | tc_offset_div2 < -6 || tc_offset_div2 > 6) { |
| 1105 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1106 | "Invalid deblock filter offsets: %d, %d\n", | ||
| 1107 | beta_offset_div2, tc_offset_div2); | ||
| 1108 | ✗ | return AVERROR_INVALIDDATA; | |
| 1109 | } | ||
| 1110 | 304 | sh->beta_offset = beta_offset_div2 * 2; | |
| 1111 | 304 | sh->tc_offset = tc_offset_div2 * 2; | |
| 1112 | } | ||
| 1113 | } else { | ||
| 1114 | 2891 | sh->disable_deblocking_filter_flag = pps->disable_dbf; | |
| 1115 | 2891 | sh->beta_offset = pps->beta_offset; | |
| 1116 | 2891 | sh->tc_offset = pps->tc_offset; | |
| 1117 | } | ||
| 1118 | } else { | ||
| 1119 | 17316 | sh->disable_deblocking_filter_flag = 0; | |
| 1120 | 17316 | sh->beta_offset = 0; | |
| 1121 | 17316 | sh->tc_offset = 0; | |
| 1122 | } | ||
| 1123 | |||
| 1124 |
2/2✓ Branch 0 taken 18041 times.
✓ Branch 1 taken 2582 times.
|
20623 | if (pps->seq_loop_filter_across_slices_enabled_flag && |
| 1125 |
2/2✓ Branch 0 taken 11680 times.
✓ Branch 1 taken 6361 times.
|
18041 | (sh->slice_sample_adaptive_offset_flag[0] || |
| 1126 |
2/2✓ Branch 0 taken 11663 times.
✓ Branch 1 taken 17 times.
|
11680 | sh->slice_sample_adaptive_offset_flag[1] || |
| 1127 |
2/2✓ Branch 0 taken 11608 times.
✓ Branch 1 taken 55 times.
|
11663 | !sh->disable_deblocking_filter_flag)) { |
| 1128 | 17986 | sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); | |
| 1129 | } else { | ||
| 1130 | 2637 | sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag; | |
| 1131 | } | ||
| 1132 | } | ||
| 1133 | |||
| 1134 | 28417 | sh->num_entry_point_offsets = 0; | |
| 1135 |
4/4✓ Branch 0 taken 25274 times.
✓ Branch 1 taken 3143 times.
✓ Branch 2 taken 4809 times.
✓ Branch 3 taken 20465 times.
|
28417 | if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) { |
| 1136 | 7952 | unsigned num_entry_point_offsets = get_ue_golomb_long(gb); | |
| 1137 | // It would be possible to bound this tighter but this here is simpler | ||
| 1138 |
2/4✓ Branch 1 taken 7952 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 7952 times.
|
7952 | if (num_entry_point_offsets > get_bits_left(gb) || num_entry_point_offsets > UINT16_MAX) { |
| 1139 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets); | |
| 1140 | ✗ | return AVERROR_INVALIDDATA; | |
| 1141 | } | ||
| 1142 | |||
| 1143 | 7952 | sh->num_entry_point_offsets = num_entry_point_offsets; | |
| 1144 |
2/2✓ Branch 0 taken 2201 times.
✓ Branch 1 taken 5751 times.
|
7952 | if (sh->num_entry_point_offsets > 0) { |
| 1145 | 2201 | int offset_len = get_ue_golomb_long(gb) + 1; | |
| 1146 | |||
| 1147 |
2/4✓ Branch 0 taken 2201 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2201 times.
|
2201 | if (offset_len < 1 || offset_len > 32) { |
| 1148 | ✗ | sh->num_entry_point_offsets = 0; | |
| 1149 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len); | |
| 1150 | ✗ | return AVERROR_INVALIDDATA; | |
| 1151 | } | ||
| 1152 | |||
| 1153 | 2201 | av_freep(&sh->entry_point_offset); | |
| 1154 | 2201 | av_freep(&sh->offset); | |
| 1155 | 2201 | av_freep(&sh->size); | |
| 1156 | 2201 | sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned)); | |
| 1157 | 2201 | sh->offset = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
| 1158 | 2201 | sh->size = av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int)); | |
| 1159 |
3/6✓ Branch 0 taken 2201 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2201 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2201 times.
|
2201 | if (!sh->entry_point_offset || !sh->offset || !sh->size) { |
| 1160 | ✗ | sh->num_entry_point_offsets = 0; | |
| 1161 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n"); | |
| 1162 | ✗ | return AVERROR(ENOMEM); | |
| 1163 | } | ||
| 1164 |
2/2✓ Branch 0 taken 9904 times.
✓ Branch 1 taken 2201 times.
|
12105 | for (i = 0; i < sh->num_entry_point_offsets; i++) { |
| 1165 | 9904 | unsigned val = get_bits_long(gb, offset_len); | |
| 1166 | 9904 | sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size | |
| 1167 | } | ||
| 1168 | } | ||
| 1169 | } | ||
| 1170 | |||
| 1171 |
2/2✓ Branch 0 taken 2749 times.
✓ Branch 1 taken 25668 times.
|
28417 | if (pps->slice_header_extension_present_flag) { |
| 1172 | 2749 | unsigned int length = get_ue_golomb_long(gb); | |
| 1173 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2749 times.
|
2749 | if (length*8LL > get_bits_left(gb)) { |
| 1174 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n"); | |
| 1175 | ✗ | return AVERROR_INVALIDDATA; | |
| 1176 | } | ||
| 1177 |
2/2✓ Branch 0 taken 19903 times.
✓ Branch 1 taken 2749 times.
|
22652 | for (i = 0; i < length; i++) |
| 1178 | 19903 | skip_bits(gb, 8); // slice_header_extension_data_byte | |
| 1179 | } | ||
| 1180 | |||
| 1181 | 28417 | ret = get_bits1(gb); | |
| 1182 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28417 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
28417 | if (!ret && get_bits_left(gb) >= 0) { |
| 1183 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n"); | |
| 1184 | ✗ | return AVERROR_INVALIDDATA; | |
| 1185 | } | ||
| 1186 | 28417 | sh->data_offset = align_get_bits(gb) - gb->buffer; | |
| 1187 | |||
| 1188 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28417 times.
|
28417 | if (get_bits_left(gb) < 0) { |
| 1189 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1190 | ✗ | "Overread slice header by %d bits\n", -get_bits_left(gb)); | |
| 1191 | ✗ | return AVERROR_INVALIDDATA; | |
| 1192 | } | ||
| 1193 | |||
| 1194 | // Inferred parameters | ||
| 1195 | 28417 | sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta; | |
| 1196 |
1/2✓ Branch 0 taken 28417 times.
✗ Branch 1 not taken.
|
28417 | if (sh->slice_qp > 51 || |
| 1197 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28417 times.
|
28417 | sh->slice_qp < -sps->qp_bd_offset) { |
| 1198 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1199 | "The slice_qp %d is outside the valid range " | ||
| 1200 | "[%d, 51].\n", | ||
| 1201 | ✗ | sh->slice_qp, | |
| 1202 | ✗ | -sps->qp_bd_offset); | |
| 1203 | ✗ | return AVERROR_INVALIDDATA; | |
| 1204 | } | ||
| 1205 | |||
| 1206 | 28417 | sh->slice_ctb_addr_rs = sh->slice_segment_addr; | |
| 1207 | |||
| 1208 |
2/2✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 20623 times.
|
28417 | if (sh->dependent_slice_segment_flag && |
| 1209 |
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])) { |
| 1210 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n"); | |
| 1211 | ✗ | return AVERROR_INVALIDDATA; | |
| 1212 | } | ||
| 1213 | |||
| 1214 | 28417 | return 0; | |
| 1215 | } | ||
| 1216 | |||
| 1217 | #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)]) | ||
| 1218 | |||
| 1219 | #define SET_SAO(elem, value) \ | ||
| 1220 | do { \ | ||
| 1221 | if (!sao_merge_up_flag && !sao_merge_left_flag) \ | ||
| 1222 | sao->elem = value; \ | ||
| 1223 | else if (sao_merge_left_flag) \ | ||
| 1224 | sao->elem = CTB(l->sao, rx-1, ry).elem; \ | ||
| 1225 | else if (sao_merge_up_flag) \ | ||
| 1226 | sao->elem = CTB(l->sao, rx, ry-1).elem; \ | ||
| 1227 | else \ | ||
| 1228 | sao->elem = 0; \ | ||
| 1229 | } while (0) | ||
| 1230 | |||
| 1231 | 1941354 | static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
| 1232 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1233 | int rx, int ry) | ||
| 1234 | { | ||
| 1235 | 1941354 | const HEVCContext *const s = lc->parent; | |
| 1236 | 1941354 | int sao_merge_left_flag = 0; | |
| 1237 | 1941354 | int sao_merge_up_flag = 0; | |
| 1238 | 1941354 | SAOParams *sao = &CTB(l->sao, rx, ry); | |
| 1239 | int c_idx, i; | ||
| 1240 | |||
| 1241 |
2/2✓ Branch 0 taken 860644 times.
✓ Branch 1 taken 1080710 times.
|
1941354 | if (s->sh.slice_sample_adaptive_offset_flag[0] || |
| 1242 |
2/2✓ Branch 0 taken 1540 times.
✓ Branch 1 taken 859104 times.
|
860644 | s->sh.slice_sample_adaptive_offset_flag[1]) { |
| 1243 |
2/2✓ Branch 0 taken 1040482 times.
✓ Branch 1 taken 41768 times.
|
1082250 | if (rx > 0) { |
| 1244 |
2/2✓ Branch 0 taken 1021463 times.
✓ Branch 1 taken 19019 times.
|
1040482 | if (lc->ctb_left_flag) |
| 1245 | 1021463 | sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(lc); | |
| 1246 | } | ||
| 1247 |
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) { |
| 1248 |
2/2✓ Branch 0 taken 408759 times.
✓ Branch 1 taken 13007 times.
|
421766 | if (lc->ctb_up_flag) |
| 1249 | 408759 | sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(lc); | |
| 1250 | } | ||
| 1251 | } | ||
| 1252 | |||
| 1253 |
4/4✓ Branch 0 taken 7765320 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 5824014 times.
✓ Branch 3 taken 1941354 times.
|
7765368 | for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) { |
| 1254 |
2/2✓ Branch 0 taken 1941354 times.
✓ Branch 1 taken 3882660 times.
|
5824014 | int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma : |
| 1255 | 3882660 | pps->log2_sao_offset_scale_chroma; | |
| 1256 | |||
| 1257 |
2/2✓ Branch 0 taken 3127748 times.
✓ Branch 1 taken 2696266 times.
|
5824014 | if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) { |
| 1258 | 3127748 | sao->type_idx[c_idx] = SAO_NOT_APPLIED; | |
| 1259 | 3127748 | continue; | |
| 1260 | } | ||
| 1261 | |||
| 1262 |
2/2✓ Branch 0 taken 807778 times.
✓ Branch 1 taken 1888488 times.
|
2696266 | if (c_idx == 2) { |
| 1263 | 807778 | sao->type_idx[2] = sao->type_idx[1]; | |
| 1264 | 807778 | sao->eo_class[2] = sao->eo_class[1]; | |
| 1265 | } else { | ||
| 1266 |
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)); |
| 1267 | } | ||
| 1268 | |||
| 1269 |
2/2✓ Branch 0 taken 2009626 times.
✓ Branch 1 taken 686640 times.
|
2696266 | if (sao->type_idx[c_idx] == SAO_NOT_APPLIED) |
| 1270 | 2009626 | continue; | |
| 1271 | |||
| 1272 |
2/2✓ Branch 0 taken 2746560 times.
✓ Branch 1 taken 686640 times.
|
3433200 | for (i = 0; i < 4; i++) |
| 1273 |
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)); |
| 1274 | |||
| 1275 |
2/2✓ Branch 0 taken 108424 times.
✓ Branch 1 taken 578216 times.
|
686640 | if (sao->type_idx[c_idx] == SAO_BAND) { |
| 1276 |
2/2✓ Branch 0 taken 433696 times.
✓ Branch 1 taken 108424 times.
|
542120 | for (i = 0; i < 4; i++) { |
| 1277 |
2/2✓ Branch 0 taken 323582 times.
✓ Branch 1 taken 110114 times.
|
433696 | if (sao->offset_abs[c_idx][i]) { |
| 1278 |
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], |
| 1279 | ff_hevc_sao_offset_sign_decode(lc)); | ||
| 1280 | } else { | ||
| 1281 | 110114 | sao->offset_sign[c_idx][i] = 0; | |
| 1282 | } | ||
| 1283 | } | ||
| 1284 |
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)); |
| 1285 |
2/2✓ Branch 0 taken 506073 times.
✓ Branch 1 taken 72143 times.
|
578216 | } else if (c_idx != 2) { |
| 1286 |
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)); |
| 1287 | } | ||
| 1288 | |||
| 1289 | // Inferred parameters | ||
| 1290 | 686640 | sao->offset_val[c_idx][0] = 0; | |
| 1291 |
2/2✓ Branch 0 taken 2746560 times.
✓ Branch 1 taken 686640 times.
|
3433200 | for (i = 0; i < 4; i++) { |
| 1292 | 2746560 | sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i]; | |
| 1293 |
2/2✓ Branch 0 taken 2312864 times.
✓ Branch 1 taken 433696 times.
|
2746560 | if (sao->type_idx[c_idx] == SAO_EDGE) { |
| 1294 |
2/2✓ Branch 0 taken 1156432 times.
✓ Branch 1 taken 1156432 times.
|
2312864 | if (i > 1) |
| 1295 | 1156432 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
| 1296 |
2/2✓ Branch 0 taken 144543 times.
✓ Branch 1 taken 289153 times.
|
433696 | } else if (sao->offset_sign[c_idx][i]) { |
| 1297 | 144543 | sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1]; | |
| 1298 | } | ||
| 1299 | 2746560 | sao->offset_val[c_idx][i + 1] *= 1 << log2_sao_offset_scale; | |
| 1300 | } | ||
| 1301 | } | ||
| 1302 | 1941354 | } | |
| 1303 | |||
| 1304 | #undef SET_SAO | ||
| 1305 | #undef CTB | ||
| 1306 | |||
| 1307 | 251428 | static int hls_cross_component_pred(HEVCLocalContext *lc, int idx) | |
| 1308 | { | ||
| 1309 | 251428 | int log2_res_scale_abs_plus1 = ff_hevc_log2_res_scale_abs(lc, idx); | |
| 1310 | |||
| 1311 |
2/2✓ Branch 0 taken 142161 times.
✓ Branch 1 taken 109267 times.
|
251428 | if (log2_res_scale_abs_plus1 != 0) { |
| 1312 | 142161 | int res_scale_sign_flag = ff_hevc_res_scale_sign_flag(lc, idx); | |
| 1313 | 142161 | lc->tu.res_scale_val = (1 << (log2_res_scale_abs_plus1 - 1)) * | |
| 1314 | 142161 | (1 - 2 * res_scale_sign_flag); | |
| 1315 | } else { | ||
| 1316 | 109267 | lc->tu.res_scale_val = 0; | |
| 1317 | } | ||
| 1318 | |||
| 1319 | |||
| 1320 | 251428 | return 0; | |
| 1321 | } | ||
| 1322 | |||
| 1323 | 15386391 | static int hls_transform_unit(HEVCLocalContext *lc, | |
| 1324 | const HEVCLayerContext *l, | ||
| 1325 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1326 | int x0, int y0, | ||
| 1327 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
| 1328 | int log2_cb_size, int log2_trafo_size, | ||
| 1329 | int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr) | ||
| 1330 | { | ||
| 1331 | 15386391 | const HEVCContext *const s = lc->parent; | |
| 1332 | 15386391 | const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1]; | |
| 1333 | int i; | ||
| 1334 | |||
| 1335 |
2/2✓ Branch 0 taken 8724226 times.
✓ Branch 1 taken 6662165 times.
|
15386391 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1336 | 8724226 | int trafo_size = 1 << log2_trafo_size; | |
| 1337 | 8724226 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size); | |
| 1338 | |||
| 1339 | 8724226 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0); | |
| 1340 | } | ||
| 1341 | |||
| 1342 |
6/6✓ Branch 0 taken 5642279 times.
✓ Branch 1 taken 9744112 times.
✓ Branch 2 taken 4998066 times.
✓ Branch 3 taken 644213 times.
✓ Branch 4 taken 4565113 times.
✓ Branch 5 taken 432953 times.
|
15386391 | if (cbf_luma || cbf_cb[0] || cbf_cr[0] || |
| 1343 |
6/6✓ Branch 0 taken 140838 times.
✓ Branch 1 taken 4424275 times.
✓ Branch 2 taken 133247 times.
✓ Branch 3 taken 7591 times.
✓ Branch 4 taken 51975 times.
✓ Branch 5 taken 81272 times.
|
15445956 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
| 1344 | 10880844 | int scan_idx = SCAN_DIAG; | |
| 1345 | 10880844 | int scan_idx_c = SCAN_DIAG; | |
| 1346 |
4/4✓ Branch 0 taken 7612397 times.
✓ Branch 1 taken 3268447 times.
✓ Branch 2 taken 6157025 times.
✓ Branch 3 taken 1455372 times.
|
17037869 | int cbf_chroma = cbf_cb[0] || cbf_cr[0] || |
| 1347 |
2/2✓ Branch 0 taken 196699 times.
✓ Branch 1 taken 5960326 times.
|
6157025 | (sps->chroma_format_idc == 2 && |
| 1348 |
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])); |
| 1349 | |||
| 1350 |
4/4✓ Branch 0 taken 2714348 times.
✓ Branch 1 taken 8166496 times.
✓ Branch 2 taken 920242 times.
✓ Branch 3 taken 1794106 times.
|
10880844 | if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) { |
| 1351 | 920242 | lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc); | |
| 1352 |
2/2✓ Branch 0 taken 485048 times.
✓ Branch 1 taken 435194 times.
|
920242 | if (lc->tu.cu_qp_delta != 0) |
| 1353 |
2/2✓ Branch 1 taken 262087 times.
✓ Branch 2 taken 222961 times.
|
485048 | if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1) |
| 1354 | 262087 | lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta; | |
| 1355 | 920242 | lc->tu.is_cu_qp_delta_coded = 1; | |
| 1356 | |||
| 1357 |
2/2✓ Branch 0 taken 920241 times.
✓ Branch 1 taken 1 times.
|
920242 | if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) || |
| 1358 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 920241 times.
|
920241 | lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) { |
| 1359 | 1 | av_log(s->avctx, AV_LOG_ERROR, | |
| 1360 | "The cu_qp_delta %d is outside the valid range " | ||
| 1361 | "[%d, %d].\n", | ||
| 1362 | lc->tu.cu_qp_delta, | ||
| 1363 | 1 | -(26 + sps->qp_bd_offset / 2), | |
| 1364 | 1 | (25 + sps->qp_bd_offset / 2)); | |
| 1365 | 1 | return AVERROR_INVALIDDATA; | |
| 1366 | } | ||
| 1367 | |||
| 1368 | 920241 | ff_hevc_set_qPy(lc, l, pps, cb_xBase, cb_yBase, log2_cb_size); | |
| 1369 | } | ||
| 1370 | |||
| 1371 |
4/4✓ Branch 0 taken 779607 times.
✓ Branch 1 taken 10101236 times.
✓ Branch 2 taken 730220 times.
✓ Branch 3 taken 49387 times.
|
10880843 | if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma && |
| 1372 |
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) { |
| 1373 | 228078 | int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc); | |
| 1374 |
2/2✓ Branch 0 taken 35811 times.
✓ Branch 1 taken 192267 times.
|
228078 | if (cu_chroma_qp_offset_flag) { |
| 1375 | 35811 | int cu_chroma_qp_offset_idx = 0; | |
| 1376 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35811 times.
|
35811 | if (pps->chroma_qp_offset_list_len_minus1 > 0) { |
| 1377 | ✗ | cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1); | |
| 1378 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 1379 | "cu_chroma_qp_offset_idx not yet tested.\n"); | ||
| 1380 | } | ||
| 1381 | 35811 | lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx]; | |
| 1382 | 35811 | lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx]; | |
| 1383 | } else { | ||
| 1384 | 192267 | lc->tu.cu_qp_offset_cb = 0; | |
| 1385 | 192267 | lc->tu.cu_qp_offset_cr = 0; | |
| 1386 | } | ||
| 1387 | 228078 | lc->tu.is_cu_chroma_qp_offset_coded = 1; | |
| 1388 | } | ||
| 1389 | |||
| 1390 |
4/4✓ Branch 0 taken 6333043 times.
✓ Branch 1 taken 4547800 times.
✓ Branch 2 taken 5489439 times.
✓ Branch 3 taken 843604 times.
|
10880843 | if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) { |
| 1391 |
2/2✓ Branch 0 taken 3646895 times.
✓ Branch 1 taken 1842544 times.
|
5489439 | if (lc->tu.intra_pred_mode >= 6 && |
| 1392 |
2/2✓ Branch 0 taken 1267460 times.
✓ Branch 1 taken 2379435 times.
|
3646895 | lc->tu.intra_pred_mode <= 14) { |
| 1393 | 1267460 | scan_idx = SCAN_VERT; | |
| 1394 |
2/2✓ Branch 0 taken 1842352 times.
✓ Branch 1 taken 2379627 times.
|
4221979 | } else if (lc->tu.intra_pred_mode >= 22 && |
| 1395 |
2/2✓ Branch 0 taken 1555358 times.
✓ Branch 1 taken 286994 times.
|
1842352 | lc->tu.intra_pred_mode <= 30) { |
| 1396 | 1555358 | scan_idx = SCAN_HORIZ; | |
| 1397 | } | ||
| 1398 | |||
| 1399 |
2/2✓ Branch 0 taken 3304109 times.
✓ Branch 1 taken 2185330 times.
|
5489439 | if (lc->tu.intra_pred_mode_c >= 6 && |
| 1400 |
2/2✓ Branch 0 taken 1216445 times.
✓ Branch 1 taken 2087664 times.
|
3304109 | lc->tu.intra_pred_mode_c <= 14) { |
| 1401 | 1216445 | scan_idx_c = SCAN_VERT; | |
| 1402 |
2/2✓ Branch 0 taken 1753394 times.
✓ Branch 1 taken 2519600 times.
|
4272994 | } else if (lc->tu.intra_pred_mode_c >= 22 && |
| 1403 |
2/2✓ Branch 0 taken 1474007 times.
✓ Branch 1 taken 279387 times.
|
1753394 | lc->tu.intra_pred_mode_c <= 30) { |
| 1404 | 1474007 | scan_idx_c = SCAN_HORIZ; | |
| 1405 | } | ||
| 1406 | } | ||
| 1407 | |||
| 1408 | 10880843 | lc->tu.cross_pf = 0; | |
| 1409 | |||
| 1410 |
2/2✓ Branch 0 taken 9744111 times.
✓ Branch 1 taken 1136732 times.
|
10880843 | if (cbf_luma) |
| 1411 | 9744111 | ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0); | |
| 1412 |
6/6✓ Branch 0 taken 10880747 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 5580703 times.
✓ Branch 3 taken 5300044 times.
✓ Branch 4 taken 148785 times.
✓ Branch 5 taken 5431918 times.
|
16329672 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
| 1413 | 5448829 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
| 1414 | 5448829 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
| 1415 |
4/4✓ Branch 0 taken 246342 times.
✓ Branch 1 taken 5202487 times.
✓ Branch 2 taken 140024 times.
✓ Branch 3 taken 106318 times.
|
5588853 | lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma && |
| 1416 |
2/2✓ Branch 0 taken 91081 times.
✓ Branch 1 taken 48943 times.
|
140024 | (lc->cu.pred_mode == MODE_INTER || |
| 1417 |
2/2✓ Branch 0 taken 76771 times.
✓ Branch 1 taken 14310 times.
|
91081 | (lc->tu.chroma_mode_c == 4))); |
| 1418 | |||
| 1419 |
2/2✓ Branch 0 taken 125714 times.
✓ Branch 1 taken 5323115 times.
|
5448829 | if (lc->tu.cross_pf) { |
| 1420 | 125714 | hls_cross_component_pred(lc, 0); | |
| 1421 | } | ||
| 1422 |
4/4✓ Branch 0 taken 1078236 times.
✓ Branch 1 taken 10178834 times.
✓ Branch 2 taken 5808241 times.
✓ Branch 3 taken 5448829 times.
|
11257070 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
| 1423 |
2/2✓ Branch 0 taken 2623670 times.
✓ Branch 1 taken 3184571 times.
|
5808241 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1424 | 2623670 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
| 1425 | 2623670 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1426 | 2623670 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1); | |
| 1427 | } | ||
| 1428 |
2/2✓ Branch 0 taken 1440397 times.
✓ Branch 1 taken 4367844 times.
|
5808241 | if (cbf_cb[i]) |
| 1429 | 1440397 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
| 1430 | log2_trafo_size_c, scan_idx_c, 1); | ||
| 1431 | else | ||
| 1432 |
2/2✓ Branch 0 taken 27018 times.
✓ Branch 1 taken 4340826 times.
|
4367844 | if (lc->tu.cross_pf) { |
| 1433 | 27018 | ptrdiff_t stride = s->cur_frame->f->linesize[1]; | |
| 1434 | 27018 | int hshift = sps->hshift[1]; | |
| 1435 | 27018 | int vshift = sps->vshift[1]; | |
| 1436 | 27018 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
| 1437 | 27018 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
| 1438 | 27018 | int size = 1 << log2_trafo_size_c; | |
| 1439 | |||
| 1440 | 27018 | uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride + | |
| 1441 | 27018 | ((x0 >> hshift) << sps->pixel_shift)]; | |
| 1442 |
2/2✓ Branch 0 taken 1473408 times.
✓ Branch 1 taken 27018 times.
|
1500426 | for (i = 0; i < (size * size); i++) { |
| 1443 | 1473408 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
| 1444 | } | ||
| 1445 | 27018 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
| 1446 | } | ||
| 1447 | } | ||
| 1448 | |||
| 1449 |
2/2✓ Branch 0 taken 125714 times.
✓ Branch 1 taken 5323115 times.
|
5448829 | if (lc->tu.cross_pf) { |
| 1450 | 125714 | hls_cross_component_pred(lc, 1); | |
| 1451 | } | ||
| 1452 |
4/4✓ Branch 0 taken 1078236 times.
✓ Branch 1 taken 10178834 times.
✓ Branch 2 taken 5808241 times.
✓ Branch 3 taken 5448829 times.
|
11257070 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
| 1453 |
2/2✓ Branch 0 taken 2623670 times.
✓ Branch 1 taken 3184571 times.
|
5808241 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1454 | 2623670 | ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), | |
| 1455 | 2623670 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1456 | 2623670 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2); | |
| 1457 | } | ||
| 1458 |
2/2✓ Branch 0 taken 1512457 times.
✓ Branch 1 taken 4295784 times.
|
5808241 | if (cbf_cr[i]) |
| 1459 | 1512457 | ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c), | |
| 1460 | log2_trafo_size_c, scan_idx_c, 2); | ||
| 1461 | else | ||
| 1462 |
2/2✓ Branch 0 taken 52981 times.
✓ Branch 1 taken 4242803 times.
|
4295784 | if (lc->tu.cross_pf) { |
| 1463 | 52981 | ptrdiff_t stride = s->cur_frame->f->linesize[2]; | |
| 1464 | 52981 | int hshift = sps->hshift[2]; | |
| 1465 | 52981 | int vshift = sps->vshift[2]; | |
| 1466 | 52981 | const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
| 1467 | 52981 | int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2; | |
| 1468 | 52981 | int size = 1 << log2_trafo_size_c; | |
| 1469 | |||
| 1470 | 52981 | uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride + | |
| 1471 | 52981 | ((x0 >> hshift) << sps->pixel_shift)]; | |
| 1472 |
2/2✓ Branch 0 taken 2927920 times.
✓ Branch 1 taken 52981 times.
|
2980901 | for (i = 0; i < (size * size); i++) { |
| 1473 | 2927920 | coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
| 1474 | } | ||
| 1475 | 52981 | s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride); | |
| 1476 | } | ||
| 1477 | } | ||
| 1478 |
4/4✓ Branch 0 taken 5431918 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 1396560 times.
✓ Branch 3 taken 4035358 times.
|
5432014 | } else if (sps->chroma_format_idc && blk_idx == 3) { |
| 1479 | 1396560 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
| 1480 | 1396560 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
| 1481 |
4/4✓ Branch 0 taken 412647 times.
✓ Branch 1 taken 2518022 times.
✓ Branch 2 taken 1534109 times.
✓ Branch 3 taken 1396560 times.
|
2930669 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
| 1482 |
2/2✓ Branch 0 taken 1034762 times.
✓ Branch 1 taken 499347 times.
|
1534109 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1483 | 1034762 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
| 1484 | 1034762 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1485 | 1034762 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1); | |
| 1486 | } | ||
| 1487 |
2/2✓ Branch 0 taken 535908 times.
✓ Branch 1 taken 998201 times.
|
1534109 | if (cbf_cb[i]) |
| 1488 | 535908 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
| 1489 | log2_trafo_size, scan_idx_c, 1); | ||
| 1490 | } | ||
| 1491 |
4/4✓ Branch 0 taken 412647 times.
✓ Branch 1 taken 2518022 times.
✓ Branch 2 taken 1534109 times.
✓ Branch 3 taken 1396560 times.
|
2930669 | for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) { |
| 1492 |
2/2✓ Branch 0 taken 1034762 times.
✓ Branch 1 taken 499347 times.
|
1534109 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 1493 | 1034762 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size), | |
| 1494 | 1034762 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1495 | 1034762 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2); | |
| 1496 | } | ||
| 1497 |
2/2✓ Branch 0 taken 623929 times.
✓ Branch 1 taken 910180 times.
|
1534109 | if (cbf_cr[i]) |
| 1498 | 623929 | ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size), | |
| 1499 | log2_trafo_size, scan_idx_c, 2); | ||
| 1500 | } | ||
| 1501 | } | ||
| 1502 |
3/4✓ Branch 0 taken 4505547 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2391182 times.
✓ Branch 3 taken 2114365 times.
|
4505547 | } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) { |
| 1503 |
4/4✓ Branch 0 taken 1445233 times.
✓ Branch 1 taken 945949 times.
✓ Branch 2 taken 46806 times.
✓ Branch 3 taken 1398427 times.
|
3383937 | if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) { |
| 1504 | 992755 | int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]); | |
| 1505 | 992755 | int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]); | |
| 1506 | 992755 | ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v, | |
| 1507 | 992755 | sps->log2_ctb_size); | |
| 1508 | 992755 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1); | |
| 1509 | 992755 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2); | |
| 1510 |
2/2✓ Branch 0 taken 7467 times.
✓ Branch 1 taken 985288 times.
|
992755 | if (sps->chroma_format_idc == 2) { |
| 1511 | 7467 | ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c), | |
| 1512 | 7467 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1513 | 7467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1); | |
| 1514 | 7467 | s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2); | |
| 1515 | } | ||
| 1516 |
2/2✓ Branch 0 taken 316992 times.
✓ Branch 1 taken 1081435 times.
|
1398427 | } else if (blk_idx == 3) { |
| 1517 | 316992 | int trafo_size_h = 1 << (log2_trafo_size + 1); | |
| 1518 | 316992 | int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]); | |
| 1519 | 316992 | ff_hevc_set_neighbour_available(lc, xBase, yBase, | |
| 1520 | 316992 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1521 | 316992 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1); | |
| 1522 | 316992 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2); | |
| 1523 |
2/2✓ Branch 0 taken 2373 times.
✓ Branch 1 taken 314619 times.
|
316992 | if (sps->chroma_format_idc == 2) { |
| 1524 | 2373 | ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size), | |
| 1525 | 2373 | trafo_size_h, trafo_size_v, sps->log2_ctb_size); | |
| 1526 | 2373 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1); | |
| 1527 | 2373 | s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2); | |
| 1528 | } | ||
| 1529 | } | ||
| 1530 | } | ||
| 1531 | |||
| 1532 | 15386390 | return 0; | |
| 1533 | } | ||
| 1534 | |||
| 1535 | 339768 | static void set_deblocking_bypass(uint8_t *is_pcm, const HEVCSPS *sps, | |
| 1536 | int x0, int y0, int log2_cb_size) | ||
| 1537 | { | ||
| 1538 | 339768 | int cb_size = 1 << log2_cb_size; | |
| 1539 | 339768 | int log2_min_pu_size = sps->log2_min_pu_size; | |
| 1540 | |||
| 1541 | 339768 | int min_pu_width = sps->min_pu_width; | |
| 1542 | 339768 | int x_end = FFMIN(x0 + cb_size, sps->width); | |
| 1543 | 339768 | int y_end = FFMIN(y0 + cb_size, sps->height); | |
| 1544 | int i, j; | ||
| 1545 | |||
| 1546 |
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++) |
| 1547 |
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++) |
| 1548 | 964500 | is_pcm[i + j * min_pu_width] = 2; | |
| 1549 | 339768 | } | |
| 1550 | |||
| 1551 | 18463602 | static int hls_transform_tree(HEVCLocalContext *lc, | |
| 1552 | const HEVCLayerContext *l, | ||
| 1553 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1554 | int x0, int y0, | ||
| 1555 | int xBase, int yBase, int cb_xBase, int cb_yBase, | ||
| 1556 | int log2_cb_size, int log2_trafo_size, | ||
| 1557 | int trafo_depth, int blk_idx, | ||
| 1558 | const int *base_cbf_cb, const int *base_cbf_cr) | ||
| 1559 | { | ||
| 1560 | 18463602 | const HEVCContext *const s = lc->parent; | |
| 1561 | uint8_t split_transform_flag; | ||
| 1562 | int cbf_cb[2]; | ||
| 1563 | int cbf_cr[2]; | ||
| 1564 | int ret; | ||
| 1565 | |||
| 1566 | 18463602 | cbf_cb[0] = base_cbf_cb[0]; | |
| 1567 | 18463602 | cbf_cb[1] = base_cbf_cb[1]; | |
| 1568 | 18463602 | cbf_cr[0] = base_cbf_cr[0]; | |
| 1569 | 18463602 | cbf_cr[1] = base_cbf_cr[1]; | |
| 1570 | |||
| 1571 |
2/2✓ Branch 0 taken 5559011 times.
✓ Branch 1 taken 12904591 times.
|
18463602 | if (lc->cu.intra_split_flag) { |
| 1572 |
2/2✓ Branch 0 taken 4165244 times.
✓ Branch 1 taken 1393767 times.
|
5559011 | if (trafo_depth == 1) { |
| 1573 | 4165244 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx]; | |
| 1574 |
2/2✓ Branch 0 taken 74576 times.
✓ Branch 1 taken 4090668 times.
|
4165244 | if (sps->chroma_format_idc == 3) { |
| 1575 | 74576 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx]; | |
| 1576 | 74576 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx]; | |
| 1577 | } else { | ||
| 1578 | 4090668 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
| 1579 | 4090668 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
| 1580 | } | ||
| 1581 | } | ||
| 1582 | } else { | ||
| 1583 | 12904591 | lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[0]; | |
| 1584 | 12904591 | lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[0]; | |
| 1585 | 12904591 | lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0]; | |
| 1586 | } | ||
| 1587 | |||
| 1588 |
2/2✓ Branch 0 taken 18347658 times.
✓ Branch 1 taken 115944 times.
|
18463602 | if (log2_trafo_size <= sps->log2_max_trafo_size && |
| 1589 |
2/2✓ Branch 0 taken 10271714 times.
✓ Branch 1 taken 8075944 times.
|
18347658 | log2_trafo_size > sps->log2_min_tb_size && |
| 1590 |
2/2✓ Branch 0 taken 7850060 times.
✓ Branch 1 taken 2421654 times.
|
10271714 | trafo_depth < lc->cu.max_trafo_depth && |
| 1591 |
4/4✓ Branch 0 taken 1506116 times.
✓ Branch 1 taken 6343944 times.
✓ Branch 2 taken 469616 times.
✓ Branch 3 taken 1036500 times.
|
7850060 | !(lc->cu.intra_split_flag && trafo_depth == 0)) { |
| 1592 | 6813560 | split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size); | |
| 1593 | } else { | ||
| 1594 | 25641873 | int inter_split = sps->max_transform_hierarchy_depth_inter == 0 && | |
| 1595 |
2/2✓ Branch 0 taken 1552658 times.
✓ Branch 1 taken 789131 times.
|
2341789 | lc->cu.pred_mode == MODE_INTER && |
| 1596 |
6/6✓ Branch 0 taken 2341789 times.
✓ Branch 1 taken 9308253 times.
✓ Branch 2 taken 930859 times.
✓ Branch 3 taken 621799 times.
✓ Branch 4 taken 184863 times.
✓ Branch 5 taken 745996 times.
|
13991831 | lc->cu.part_mode != PART_2Nx2N && |
| 1597 | trafo_depth == 0; | ||
| 1598 | |||
| 1599 | 11650042 | split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size || | |
| 1600 |
8/8✓ Branch 0 taken 11534098 times.
✓ Branch 1 taken 115944 times.
✓ Branch 2 taken 5084192 times.
✓ Branch 3 taken 6449906 times.
✓ Branch 4 taken 4047692 times.
✓ Branch 5 taken 1036500 times.
✓ Branch 6 taken 169700 times.
✓ Branch 7 taken 10327898 times.
|
11650042 | (lc->cu.intra_split_flag && trafo_depth == 0) || |
| 1601 | inter_split; | ||
| 1602 | } | ||
| 1603 | |||
| 1604 |
6/6✓ Branch 0 taken 18463506 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 7989448 times.
✓ Branch 3 taken 10474058 times.
✓ Branch 4 taken 239856 times.
✓ Branch 5 taken 7749592 times.
|
18463602 | if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) { |
| 1605 |
4/4✓ Branch 0 taken 4559252 times.
✓ Branch 1 taken 6154662 times.
✓ Branch 2 taken 1165872 times.
✓ Branch 3 taken 3393380 times.
|
10713914 | if (trafo_depth == 0 || cbf_cb[0]) { |
| 1606 | 7320534 | cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
| 1607 |
6/6✓ Branch 0 taken 458668 times.
✓ Branch 1 taken 6861866 times.
✓ Branch 2 taken 170236 times.
✓ Branch 3 taken 288432 times.
✓ Branch 4 taken 108956 times.
✓ Branch 5 taken 61280 times.
|
7320534 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
| 1608 | 397388 | cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
| 1609 | } | ||
| 1610 | } | ||
| 1611 | |||
| 1612 |
4/4✓ Branch 0 taken 4559252 times.
✓ Branch 1 taken 6154662 times.
✓ Branch 2 taken 1098848 times.
✓ Branch 3 taken 3460404 times.
|
10713914 | if (trafo_depth == 0 || cbf_cr[0]) { |
| 1613 | 7253510 | cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
| 1614 |
6/6✓ Branch 0 taken 605644 times.
✓ Branch 1 taken 6647866 times.
✓ Branch 2 taken 217952 times.
✓ Branch 3 taken 387692 times.
✓ Branch 4 taken 144600 times.
✓ Branch 5 taken 73352 times.
|
7253510 | if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) { |
| 1615 | 532292 | cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth); | |
| 1616 | } | ||
| 1617 | } | ||
| 1618 | } | ||
| 1619 | |||
| 1620 |
2/2✓ Branch 0 taken 3077211 times.
✓ Branch 1 taken 15386391 times.
|
18463602 | if (split_transform_flag) { |
| 1621 | 3077211 | const int trafo_size_split = 1 << (log2_trafo_size - 1); | |
| 1622 | 3077211 | const int x1 = x0 + trafo_size_split; | |
| 1623 | 3077211 | const int y1 = y0 + trafo_size_split; | |
| 1624 | |||
| 1625 | #define SUBDIVIDE(x, y, idx) \ | ||
| 1626 | do { \ | ||
| 1627 | ret = hls_transform_tree(lc, l, pps, sps, \ | ||
| 1628 | x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \ | ||
| 1629 | log2_trafo_size - 1, trafo_depth + 1, idx, \ | ||
| 1630 | cbf_cb, cbf_cr); \ | ||
| 1631 | if (ret < 0) \ | ||
| 1632 | return ret; \ | ||
| 1633 | } while (0) | ||
| 1634 | |||
| 1635 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3077211 times.
|
3077211 | SUBDIVIDE(x0, y0, 0); |
| 1636 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3077211 times.
|
3077211 | SUBDIVIDE(x1, y0, 1); |
| 1637 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3077211 times.
|
3077211 | SUBDIVIDE(x0, y1, 2); |
| 1638 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3077211 times.
|
3077211 | SUBDIVIDE(x1, y1, 3); |
| 1639 | |||
| 1640 | #undef SUBDIVIDE | ||
| 1641 | } else { | ||
| 1642 | 15386391 | int min_tu_size = 1 << sps->log2_min_tb_size; | |
| 1643 | 15386391 | int log2_min_tu_size = sps->log2_min_tb_size; | |
| 1644 | 15386391 | int min_tu_width = sps->min_tb_width; | |
| 1645 | 15386391 | int cbf_luma = 1; | |
| 1646 | |||
| 1647 |
4/4✓ Branch 0 taken 6662165 times.
✓ Branch 1 taken 8724226 times.
✓ Branch 2 taken 1589494 times.
✓ Branch 3 taken 5072671 times.
|
15386391 | if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 || |
| 1648 |
4/4✓ Branch 0 taken 1257801 times.
✓ Branch 1 taken 331693 times.
✓ Branch 2 taken 1090362 times.
✓ Branch 3 taken 167439 times.
|
1589494 | cbf_cb[0] || cbf_cr[0] || |
| 1649 |
6/6✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 1065686 times.
✓ Branch 2 taken 23413 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 11383 times.
✓ Branch 5 taken 12030 times.
|
1090362 | (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) { |
| 1650 | 14308675 | cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth); | |
| 1651 | } | ||
| 1652 | |||
| 1653 | 15386391 | ret = hls_transform_unit(lc, l, pps, sps, | |
| 1654 | x0, y0, xBase, yBase, cb_xBase, cb_yBase, | ||
| 1655 | log2_cb_size, log2_trafo_size, | ||
| 1656 | blk_idx, cbf_luma, cbf_cb, cbf_cr); | ||
| 1657 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15386390 times.
|
15386391 | if (ret < 0) |
| 1658 | 1 | return ret; | |
| 1659 | // TODO: store cbf_luma somewhere else | ||
| 1660 |
2/2✓ Branch 0 taken 9744111 times.
✓ Branch 1 taken 5642279 times.
|
15386390 | if (cbf_luma) { |
| 1661 | int i, j; | ||
| 1662 |
2/2✓ Branch 0 taken 22006960 times.
✓ Branch 1 taken 9744111 times.
|
31751071 | for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size) |
| 1663 |
2/2✓ Branch 0 taken 86690898 times.
✓ Branch 1 taken 22006960 times.
|
108697858 | for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) { |
| 1664 | 86690898 | int x_tu = (x0 + j) >> log2_min_tu_size; | |
| 1665 | 86690898 | int y_tu = (y0 + i) >> log2_min_tu_size; | |
| 1666 | 86690898 | l->cbf_luma[y_tu * min_tu_width + x_tu] = 1; | |
| 1667 | } | ||
| 1668 | } | ||
| 1669 |
2/2✓ Branch 0 taken 14891329 times.
✓ Branch 1 taken 495061 times.
|
15386390 | if (!s->sh.disable_deblocking_filter_flag) { |
| 1670 | 14891329 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size); | |
| 1671 |
2/2✓ Branch 0 taken 319726 times.
✓ Branch 1 taken 14571603 times.
|
14891329 | if (pps->transquant_bypass_enable_flag && |
| 1672 |
2/2✓ Branch 0 taken 260054 times.
✓ Branch 1 taken 59672 times.
|
319726 | lc->cu.cu_transquant_bypass_flag) |
| 1673 | 260054 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_trafo_size); | |
| 1674 | } | ||
| 1675 | } | ||
| 1676 | 18463601 | return 0; | |
| 1677 | } | ||
| 1678 | |||
| 1679 | 11207 | static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
| 1680 | const HEVCPPS *pps, int x0, int y0, int log2_cb_size) | ||
| 1681 | { | ||
| 1682 | 11207 | const HEVCContext *const s = lc->parent; | |
| 1683 | 11207 | const HEVCSPS *const sps = pps->sps; | |
| 1684 | GetBitContext gb; | ||
| 1685 | 11207 | int cb_size = 1 << log2_cb_size; | |
| 1686 | 11207 | ptrdiff_t stride0 = s->cur_frame->f->linesize[0]; | |
| 1687 | 11207 | uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)]; | |
| 1688 | |||
| 1689 | 22414 | int length = cb_size * cb_size * sps->pcm.bit_depth + (sps->chroma_format_idc != 0 ? | |
| 1690 | 11207 | (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) + | |
| 1691 | 11207 | ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) * | |
| 1692 |
1/2✓ Branch 0 taken 11207 times.
✗ Branch 1 not taken.
|
11207 | sps->pcm.bit_depth_chroma : 0); |
| 1693 | 11207 | const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3); | |
| 1694 | int ret; | ||
| 1695 | |||
| 1696 |
2/2✓ Branch 0 taken 6041 times.
✓ Branch 1 taken 5166 times.
|
11207 | if (!s->sh.disable_deblocking_filter_flag) |
| 1697 | 6041 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
| 1698 | |||
| 1699 | 11207 | ret = init_get_bits(&gb, pcm, length); | |
| 1700 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11207 times.
|
11207 | if (ret < 0) |
| 1701 | ✗ | return ret; | |
| 1702 | |||
| 1703 | 11207 | s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth); | |
| 1704 |
1/2✓ Branch 0 taken 11207 times.
✗ Branch 1 not taken.
|
11207 | if (sps->chroma_format_idc) { |
| 1705 | 11207 | ptrdiff_t stride1 = s->cur_frame->f->linesize[1]; | |
| 1706 | 11207 | ptrdiff_t stride2 = s->cur_frame->f->linesize[2]; | |
| 1707 | 11207 | uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)]; | |
| 1708 | 11207 | uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)]; | |
| 1709 | |||
| 1710 | 11207 | s->hevcdsp.put_pcm(dst1, stride1, | |
| 1711 | 11207 | cb_size >> sps->hshift[1], | |
| 1712 | 11207 | cb_size >> sps->vshift[1], | |
| 1713 | 11207 | &gb, sps->pcm.bit_depth_chroma); | |
| 1714 | 11207 | s->hevcdsp.put_pcm(dst2, stride2, | |
| 1715 | 11207 | cb_size >> sps->hshift[2], | |
| 1716 | 11207 | cb_size >> sps->vshift[2], | |
| 1717 | 11207 | &gb, sps->pcm.bit_depth_chroma); | |
| 1718 | } | ||
| 1719 | |||
| 1720 | 11207 | return 0; | |
| 1721 | } | ||
| 1722 | |||
| 1723 | /** | ||
| 1724 | * 8.5.3.2.2.1 Luma sample unidirectional interpolation process | ||
| 1725 | * | ||
| 1726 | * @param s HEVC decoding context | ||
| 1727 | * @param dst target buffer for block data at block position | ||
| 1728 | * @param dststride stride of the dst buffer | ||
| 1729 | * @param ref reference picture buffer at origin (0, 0) | ||
| 1730 | * @param mv motion vector (relative to block position) to get pixel data from | ||
| 1731 | * @param x_off horizontal position of block from origin (0, 0) | ||
| 1732 | * @param y_off vertical position of block from origin (0, 0) | ||
| 1733 | * @param block_w width of block | ||
| 1734 | * @param block_h height of block | ||
| 1735 | * @param luma_weight weighting factor applied to the luma prediction | ||
| 1736 | * @param luma_offset additive offset applied to the luma prediction value | ||
| 1737 | */ | ||
| 1738 | |||
| 1739 | 6342554 | static void luma_mc_uni(HEVCLocalContext *lc, | |
| 1740 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1741 | uint8_t *dst, ptrdiff_t dststride, | ||
| 1742 | const AVFrame *ref, const Mv *mv, int x_off, int y_off, | ||
| 1743 | int block_w, int block_h, int luma_weight, int luma_offset) | ||
| 1744 | { | ||
| 1745 | 6342554 | const HEVCContext *const s = lc->parent; | |
| 1746 | 6342554 | const uint8_t *src = ref->data[0]; | |
| 1747 | 6342554 | ptrdiff_t srcstride = ref->linesize[0]; | |
| 1748 | 6342554 | int pic_width = sps->width; | |
| 1749 | 6342554 | int pic_height = sps->height; | |
| 1750 | 6342554 | int mx = mv->x & 3; | |
| 1751 | 6342554 | int my = mv->y & 3; | |
| 1752 |
4/4✓ Branch 0 taken 3280827 times.
✓ Branch 1 taken 3061727 times.
✓ Branch 2 taken 3220239 times.
✓ Branch 3 taken 60588 times.
|
12624520 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
| 1753 |
4/4✓ Branch 0 taken 3061727 times.
✓ Branch 1 taken 3220239 times.
✓ Branch 2 taken 73276 times.
✓ Branch 3 taken 2988451 times.
|
6281966 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
| 1754 | 6342554 | int idx = hevc_pel_weight[block_w]; | |
| 1755 | |||
| 1756 | 6342554 | x_off += mv->x >> 2; | |
| 1757 | 6342554 | y_off += mv->y >> 2; | |
| 1758 | 6342554 | src += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
| 1759 | |||
| 1760 |
4/4✓ Branch 0 taken 6274424 times.
✓ Branch 1 taken 68130 times.
✓ Branch 2 taken 6154893 times.
✓ Branch 3 taken 119531 times.
|
6342554 | if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER || |
| 1761 |
2/2✓ Branch 0 taken 6078917 times.
✓ Branch 1 taken 75976 times.
|
6154893 | x_off >= pic_width - block_w - QPEL_EXTRA_AFTER || |
| 1762 |
2/2✓ Branch 0 taken 5860745 times.
✓ Branch 1 taken 218172 times.
|
6078917 | y_off >= pic_height - block_h - QPEL_EXTRA_AFTER || |
| 1763 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5860745 times.
|
5860745 | ref == s->cur_frame->f) { |
| 1764 | 481809 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 1765 | 481809 | int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1766 | 481809 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1767 | |||
| 1768 | 481809 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset, | |
| 1769 | edge_emu_stride, srcstride, | ||
| 1770 | block_w + QPEL_EXTRA, | ||
| 1771 | block_h + QPEL_EXTRA, | ||
| 1772 | x_off - QPEL_EXTRA_BEFORE, y_off - QPEL_EXTRA_BEFORE, | ||
| 1773 | pic_width, pic_height); | ||
| 1774 | 481809 | src = lc->edge_emu_buffer + buf_offset; | |
| 1775 | 481809 | srcstride = edge_emu_stride; | |
| 1776 | } | ||
| 1777 | |||
| 1778 |
2/2✓ Branch 0 taken 6208690 times.
✓ Branch 1 taken 133864 times.
|
6342554 | if (!weight_flag) |
| 1779 | 6208690 | s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
| 1780 | block_h, mx, my, block_w); | ||
| 1781 | else | ||
| 1782 | 133864 | s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride, src, srcstride, | |
| 1783 | 133864 | block_h, s->sh.luma_log2_weight_denom, | |
| 1784 | luma_weight, luma_offset, mx, my, block_w); | ||
| 1785 | 6342554 | } | |
| 1786 | |||
| 1787 | /** | ||
| 1788 | * 8.5.3.2.2.1 Luma sample bidirectional interpolation process | ||
| 1789 | * | ||
| 1790 | * @param s HEVC decoding context | ||
| 1791 | * @param dst target buffer for block data at block position | ||
| 1792 | * @param dststride stride of the dst buffer | ||
| 1793 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
| 1794 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
| 1795 | * @param x_off horizontal position of block from origin (0, 0) | ||
| 1796 | * @param y_off vertical position of block from origin (0, 0) | ||
| 1797 | * @param block_w width of block | ||
| 1798 | * @param block_h height of block | ||
| 1799 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
| 1800 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
| 1801 | * @param current_mv current motion vector structure | ||
| 1802 | */ | ||
| 1803 | 3992083 | static void luma_mc_bi(HEVCLocalContext *lc, | |
| 1804 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1805 | uint8_t *dst, ptrdiff_t dststride, | ||
| 1806 | const AVFrame *ref0, const Mv *mv0, int x_off, int y_off, | ||
| 1807 | int block_w, int block_h, const AVFrame *ref1, | ||
| 1808 | const Mv *mv1, struct MvField *current_mv) | ||
| 1809 | { | ||
| 1810 | 3992083 | const HEVCContext *const s = lc->parent; | |
| 1811 | 3992083 | ptrdiff_t src0stride = ref0->linesize[0]; | |
| 1812 | 3992083 | ptrdiff_t src1stride = ref1->linesize[0]; | |
| 1813 | 3992083 | int pic_width = sps->width; | |
| 1814 | 3992083 | int pic_height = sps->height; | |
| 1815 | 3992083 | int mx0 = mv0->x & 3; | |
| 1816 | 3992083 | int my0 = mv0->y & 3; | |
| 1817 | 3992083 | int mx1 = mv1->x & 3; | |
| 1818 | 3992083 | int my1 = mv1->y & 3; | |
| 1819 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3992083 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7984166 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
| 1820 |
3/4✓ Branch 0 taken 3992083 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 73498 times.
✓ Branch 3 taken 3918585 times.
|
3992083 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
| 1821 | 3992083 | int x_off0 = x_off + (mv0->x >> 2); | |
| 1822 | 3992083 | int y_off0 = y_off + (mv0->y >> 2); | |
| 1823 | 3992083 | int x_off1 = x_off + (mv1->x >> 2); | |
| 1824 | 3992083 | int y_off1 = y_off + (mv1->y >> 2); | |
| 1825 | 3992083 | int idx = hevc_pel_weight[block_w]; | |
| 1826 | |||
| 1827 | 3992083 | const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift); | |
| 1828 | 3992083 | const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift); | |
| 1829 | |||
| 1830 |
4/4✓ Branch 0 taken 3934283 times.
✓ Branch 1 taken 57800 times.
✓ Branch 2 taken 3826999 times.
✓ Branch 3 taken 107284 times.
|
3992083 | if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER || |
| 1831 |
2/2✓ Branch 0 taken 3757951 times.
✓ Branch 1 taken 69048 times.
|
3826999 | x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
| 1832 |
2/2✓ Branch 0 taken 209680 times.
✓ Branch 1 taken 3548271 times.
|
3757951 | y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
| 1833 | 443812 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 1834 | 443812 | int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1835 | 443812 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1836 | |||
| 1837 | 443812 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset, | |
| 1838 | edge_emu_stride, src0stride, | ||
| 1839 | block_w + QPEL_EXTRA, | ||
| 1840 | block_h + QPEL_EXTRA, | ||
| 1841 | x_off0 - QPEL_EXTRA_BEFORE, y_off0 - QPEL_EXTRA_BEFORE, | ||
| 1842 | pic_width, pic_height); | ||
| 1843 | 443812 | src0 = lc->edge_emu_buffer + buf_offset; | |
| 1844 | 443812 | src0stride = edge_emu_stride; | |
| 1845 | } | ||
| 1846 | |||
| 1847 |
4/4✓ Branch 0 taken 3928081 times.
✓ Branch 1 taken 64002 times.
✓ Branch 2 taken 3821452 times.
✓ Branch 3 taken 106629 times.
|
3992083 | if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER || |
| 1848 |
2/2✓ Branch 0 taken 3750497 times.
✓ Branch 1 taken 70955 times.
|
3821452 | x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER || |
| 1849 |
2/2✓ Branch 0 taken 212853 times.
✓ Branch 1 taken 3537644 times.
|
3750497 | y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) { |
| 1850 | 454439 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 1851 | 454439 | int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1852 | 454439 | int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift); | |
| 1853 | |||
| 1854 | 454439 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset, | |
| 1855 | edge_emu_stride, src1stride, | ||
| 1856 | block_w + QPEL_EXTRA, | ||
| 1857 | block_h + QPEL_EXTRA, | ||
| 1858 | x_off1 - QPEL_EXTRA_BEFORE, y_off1 - QPEL_EXTRA_BEFORE, | ||
| 1859 | pic_width, pic_height); | ||
| 1860 | 454439 | src1 = lc->edge_emu_buffer2 + buf_offset; | |
| 1861 | 454439 | src1stride = edge_emu_stride; | |
| 1862 | } | ||
| 1863 | |||
| 1864 | 3992083 | s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->tmp, src0, src0stride, | |
| 1865 | block_h, mx0, my0, block_w); | ||
| 1866 |
2/2✓ Branch 0 taken 3918585 times.
✓ Branch 1 taken 73498 times.
|
3992083 | if (!weight_flag) |
| 1867 | 3918585 | s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
| 1868 | block_h, mx1, my1, block_w); | ||
| 1869 | else | ||
| 1870 | 73498 | s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride, src1, src1stride, lc->tmp, | |
| 1871 | 73498 | block_h, s->sh.luma_log2_weight_denom, | |
| 1872 | 73498 | s->sh.luma_weight_l0[current_mv->ref_idx[0]], | |
| 1873 | 73498 | s->sh.luma_weight_l1[current_mv->ref_idx[1]], | |
| 1874 | 73498 | s->sh.luma_offset_l0[current_mv->ref_idx[0]] + | |
| 1875 | 73498 | s->sh.luma_offset_l1[current_mv->ref_idx[1]], | |
| 1876 | mx1, my1, block_w); | ||
| 1877 | |||
| 1878 | 3992083 | } | |
| 1879 | |||
| 1880 | /** | ||
| 1881 | * 8.5.3.2.2.2 Chroma sample uniprediction interpolation process | ||
| 1882 | * | ||
| 1883 | * @param s HEVC decoding context | ||
| 1884 | * @param dst1 target buffer for block data at block position (U plane) | ||
| 1885 | * @param dst2 target buffer for block data at block position (V plane) | ||
| 1886 | * @param dststride stride of the dst1 and dst2 buffers | ||
| 1887 | * @param ref reference picture buffer at origin (0, 0) | ||
| 1888 | * @param mv motion vector (relative to block position) to get pixel data from | ||
| 1889 | * @param x_off horizontal position of block from origin (0, 0) | ||
| 1890 | * @param y_off vertical position of block from origin (0, 0) | ||
| 1891 | * @param block_w width of block | ||
| 1892 | * @param block_h height of block | ||
| 1893 | * @param chroma_weight weighting factor applied to the chroma prediction | ||
| 1894 | * @param chroma_offset additive offset applied to the chroma prediction value | ||
| 1895 | */ | ||
| 1896 | |||
| 1897 | 12685108 | static void chroma_mc_uni(HEVCLocalContext *lc, | |
| 1898 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1899 | uint8_t *dst0, | ||
| 1900 | ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist, | ||
| 1901 | int x_off, int y_off, int block_w, int block_h, | ||
| 1902 | const struct MvField *current_mv, int chroma_weight, int chroma_offset) | ||
| 1903 | { | ||
| 1904 | 12685108 | const HEVCContext *const s = lc->parent; | |
| 1905 | 12685108 | int pic_width = sps->width >> sps->hshift[1]; | |
| 1906 | 12685108 | int pic_height = sps->height >> sps->vshift[1]; | |
| 1907 | 12685108 | const Mv *mv = ¤t_mv->mv[reflist]; | |
| 1908 |
4/4✓ Branch 0 taken 6561654 times.
✓ Branch 1 taken 6123454 times.
✓ Branch 2 taken 6440478 times.
✓ Branch 3 taken 121176 times.
|
25249040 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
| 1909 |
4/4✓ Branch 0 taken 6123454 times.
✓ Branch 1 taken 6440478 times.
✓ Branch 2 taken 146552 times.
✓ Branch 3 taken 5976902 times.
|
12563932 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
| 1910 | 12685108 | int idx = hevc_pel_weight[block_w]; | |
| 1911 | 12685108 | int hshift = sps->hshift[1]; | |
| 1912 | 12685108 | int vshift = sps->vshift[1]; | |
| 1913 | 12685108 | intptr_t mx = av_zero_extend(mv->x, 2 + hshift); | |
| 1914 | 12685108 | intptr_t my = av_zero_extend(mv->y, 2 + vshift); | |
| 1915 | 12685108 | intptr_t _mx = mx << (1 - hshift); | |
| 1916 | 12685108 | intptr_t _my = my << (1 - vshift); | |
| 1917 |
2/4✓ Branch 0 taken 12685108 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12685108 times.
|
12685108 | int emu = src0 == s->cur_frame->f->data[1] || src0 == s->cur_frame->f->data[2]; |
| 1918 | |||
| 1919 | 12685108 | x_off += mv->x >> (2 + hshift); | |
| 1920 | 12685108 | y_off += mv->y >> (2 + vshift); | |
| 1921 | 12685108 | src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift)); | |
| 1922 | |||
| 1923 |
4/4✓ Branch 0 taken 12562024 times.
✓ Branch 1 taken 123084 times.
✓ Branch 2 taken 12322816 times.
✓ Branch 3 taken 239208 times.
|
12685108 | if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER || |
| 1924 |
2/2✓ Branch 0 taken 12170872 times.
✓ Branch 1 taken 151944 times.
|
12322816 | x_off >= pic_width - block_w - EPEL_EXTRA_AFTER || |
| 1925 |
3/4✓ Branch 0 taken 11734450 times.
✓ Branch 1 taken 436422 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11734450 times.
|
12170872 | y_off >= pic_height - block_h - EPEL_EXTRA_AFTER || |
| 1926 | emu) { | ||
| 1927 | 950658 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 1928 | 950658 | int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift)); | |
| 1929 | 950658 | int buf_offset0 = EPEL_EXTRA_BEFORE * | |
| 1930 | 950658 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
| 1931 | 950658 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0, | |
| 1932 | edge_emu_stride, srcstride, | ||
| 1933 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
| 1934 | x_off - EPEL_EXTRA_BEFORE, | ||
| 1935 | y_off - EPEL_EXTRA_BEFORE, | ||
| 1936 | pic_width, pic_height); | ||
| 1937 | |||
| 1938 | 950658 | src0 = lc->edge_emu_buffer + buf_offset0; | |
| 1939 | 950658 | srcstride = edge_emu_stride; | |
| 1940 | } | ||
| 1941 |
2/2✓ Branch 0 taken 12417380 times.
✓ Branch 1 taken 267728 times.
|
12685108 | if (!weight_flag) |
| 1942 | 12417380 | s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
| 1943 | block_h, _mx, _my, block_w); | ||
| 1944 | else | ||
| 1945 | 267728 | s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride, src0, srcstride, | |
| 1946 | 267728 | block_h, s->sh.chroma_log2_weight_denom, | |
| 1947 | chroma_weight, chroma_offset, _mx, _my, block_w); | ||
| 1948 | 12685108 | } | |
| 1949 | |||
| 1950 | /** | ||
| 1951 | * 8.5.3.2.2.2 Chroma sample bidirectional interpolation process | ||
| 1952 | * | ||
| 1953 | * @param s HEVC decoding context | ||
| 1954 | * @param dst target buffer for block data at block position | ||
| 1955 | * @param dststride stride of the dst buffer | ||
| 1956 | * @param ref0 reference picture0 buffer at origin (0, 0) | ||
| 1957 | * @param mv0 motion vector0 (relative to block position) to get pixel data from | ||
| 1958 | * @param x_off horizontal position of block from origin (0, 0) | ||
| 1959 | * @param y_off vertical position of block from origin (0, 0) | ||
| 1960 | * @param block_w width of block | ||
| 1961 | * @param block_h height of block | ||
| 1962 | * @param ref1 reference picture1 buffer at origin (0, 0) | ||
| 1963 | * @param mv1 motion vector1 (relative to block position) to get pixel data from | ||
| 1964 | * @param current_mv current motion vector structure | ||
| 1965 | * @param cidx chroma component(cb, cr) | ||
| 1966 | */ | ||
| 1967 | 7984166 | static void chroma_mc_bi(HEVCLocalContext *lc, | |
| 1968 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 1969 | uint8_t *dst0, ptrdiff_t dststride, | ||
| 1970 | const AVFrame *ref0, const AVFrame *ref1, | ||
| 1971 | int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx) | ||
| 1972 | { | ||
| 1973 | 7984166 | const HEVCContext *const s = lc->parent; | |
| 1974 | 7984166 | const uint8_t *src1 = ref0->data[cidx+1]; | |
| 1975 | 7984166 | const uint8_t *src2 = ref1->data[cidx+1]; | |
| 1976 | 7984166 | ptrdiff_t src1stride = ref0->linesize[cidx+1]; | |
| 1977 | 7984166 | ptrdiff_t src2stride = ref1->linesize[cidx+1]; | |
| 1978 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7984166 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
15968332 | int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) || |
| 1979 |
3/4✓ Branch 0 taken 7984166 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 146996 times.
✓ Branch 3 taken 7837170 times.
|
7984166 | (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag); |
| 1980 | 7984166 | int pic_width = sps->width >> sps->hshift[1]; | |
| 1981 | 7984166 | int pic_height = sps->height >> sps->vshift[1]; | |
| 1982 | 7984166 | const Mv *const mv0 = ¤t_mv->mv[0]; | |
| 1983 | 7984166 | const Mv *const mv1 = ¤t_mv->mv[1]; | |
| 1984 | 7984166 | int hshift = sps->hshift[1]; | |
| 1985 | 7984166 | int vshift = sps->vshift[1]; | |
| 1986 | |||
| 1987 | 7984166 | intptr_t mx0 = av_zero_extend(mv0->x, 2 + hshift); | |
| 1988 | 7984166 | intptr_t my0 = av_zero_extend(mv0->y, 2 + vshift); | |
| 1989 | 7984166 | intptr_t mx1 = av_zero_extend(mv1->x, 2 + hshift); | |
| 1990 | 7984166 | intptr_t my1 = av_zero_extend(mv1->y, 2 + vshift); | |
| 1991 | 7984166 | intptr_t _mx0 = mx0 << (1 - hshift); | |
| 1992 | 7984166 | intptr_t _my0 = my0 << (1 - vshift); | |
| 1993 | 7984166 | intptr_t _mx1 = mx1 << (1 - hshift); | |
| 1994 | 7984166 | intptr_t _my1 = my1 << (1 - vshift); | |
| 1995 | |||
| 1996 | 7984166 | int x_off0 = x_off + (mv0->x >> (2 + hshift)); | |
| 1997 | 7984166 | int y_off0 = y_off + (mv0->y >> (2 + vshift)); | |
| 1998 | 7984166 | int x_off1 = x_off + (mv1->x >> (2 + hshift)); | |
| 1999 | 7984166 | int y_off1 = y_off + (mv1->y >> (2 + vshift)); | |
| 2000 | 7984166 | int idx = hevc_pel_weight[block_w]; | |
| 2001 | 7984166 | src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift); | |
| 2002 | 7984166 | src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift); | |
| 2003 | |||
| 2004 |
4/4✓ Branch 0 taken 7874824 times.
✓ Branch 1 taken 109342 times.
✓ Branch 2 taken 7660144 times.
✓ Branch 3 taken 214680 times.
|
7984166 | if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER || |
| 2005 |
2/2✓ Branch 0 taken 7522052 times.
✓ Branch 1 taken 138092 times.
|
7660144 | x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
| 2006 |
2/2✓ Branch 0 taken 418772 times.
✓ Branch 1 taken 7103280 times.
|
7522052 | y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
| 2007 | 880886 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 2008 | 880886 | int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift)); | |
| 2009 | 880886 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
| 2010 | 880886 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
| 2011 | |||
| 2012 | 880886 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1, | |
| 2013 | edge_emu_stride, src1stride, | ||
| 2014 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
| 2015 | x_off0 - EPEL_EXTRA_BEFORE, | ||
| 2016 | y_off0 - EPEL_EXTRA_BEFORE, | ||
| 2017 | pic_width, pic_height); | ||
| 2018 | |||
| 2019 | 880886 | src1 = lc->edge_emu_buffer + buf_offset1; | |
| 2020 | 880886 | src1stride = edge_emu_stride; | |
| 2021 | } | ||
| 2022 | |||
| 2023 |
4/4✓ Branch 0 taken 7861558 times.
✓ Branch 1 taken 122608 times.
✓ Branch 2 taken 7648578 times.
✓ Branch 3 taken 212980 times.
|
7984166 | if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER || |
| 2024 |
2/2✓ Branch 0 taken 7506674 times.
✓ Branch 1 taken 141904 times.
|
7648578 | x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER || |
| 2025 |
2/2✓ Branch 0 taken 425380 times.
✓ Branch 1 taken 7081294 times.
|
7506674 | y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) { |
| 2026 | 902872 | const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift; | |
| 2027 | 902872 | int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift)); | |
| 2028 | 902872 | int buf_offset1 = EPEL_EXTRA_BEFORE * | |
| 2029 | 902872 | (edge_emu_stride + (1 << sps->pixel_shift)); | |
| 2030 | |||
| 2031 | 902872 | s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1, | |
| 2032 | edge_emu_stride, src2stride, | ||
| 2033 | block_w + EPEL_EXTRA, block_h + EPEL_EXTRA, | ||
| 2034 | x_off1 - EPEL_EXTRA_BEFORE, | ||
| 2035 | y_off1 - EPEL_EXTRA_BEFORE, | ||
| 2036 | pic_width, pic_height); | ||
| 2037 | |||
| 2038 | 902872 | src2 = lc->edge_emu_buffer2 + buf_offset1; | |
| 2039 | 902872 | src2stride = edge_emu_stride; | |
| 2040 | } | ||
| 2041 | |||
| 2042 | 7984166 | s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->tmp, src1, src1stride, | |
| 2043 | block_h, _mx0, _my0, block_w); | ||
| 2044 |
2/2✓ Branch 0 taken 7837170 times.
✓ Branch 1 taken 146996 times.
|
7984166 | if (!weight_flag) |
| 2045 | 7837170 | s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1], | |
| 2046 | 7837170 | src2, src2stride, lc->tmp, | |
| 2047 | block_h, _mx1, _my1, block_w); | ||
| 2048 | else | ||
| 2049 | 146996 | s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0, s->cur_frame->f->linesize[cidx+1], | |
| 2050 | 146996 | src2, src2stride, lc->tmp, | |
| 2051 | block_h, | ||
| 2052 | 146996 | s->sh.chroma_log2_weight_denom, | |
| 2053 | 146996 | s->sh.chroma_weight_l0[current_mv->ref_idx[0]][cidx], | |
| 2054 | 146996 | s->sh.chroma_weight_l1[current_mv->ref_idx[1]][cidx], | |
| 2055 | 146996 | s->sh.chroma_offset_l0[current_mv->ref_idx[0]][cidx] + | |
| 2056 | 146996 | s->sh.chroma_offset_l1[current_mv->ref_idx[1]][cidx], | |
| 2057 | _mx1, _my1, block_w); | ||
| 2058 | 7984166 | } | |
| 2059 | |||
| 2060 | 14326720 | static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref, | |
| 2061 | const Mv *mv, int y0, int height) | ||
| 2062 | { | ||
| 2063 |
2/2✓ Branch 0 taken 111132 times.
✓ Branch 1 taken 14215588 times.
|
14326720 | if (s->avctx->active_thread_type == FF_THREAD_FRAME ) { |
| 2064 | 111132 | int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9); | |
| 2065 | |||
| 2066 | 111132 | ff_progress_frame_await(&ref->tf, y); | |
| 2067 | } | ||
| 2068 | 14326720 | } | |
| 2069 | |||
| 2070 | 2833077 | static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, | |
| 2071 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2072 | int x0, int y0, int nPbW, | ||
| 2073 | int nPbH, int log2_cb_size, int part_idx, | ||
| 2074 | int merge_idx, MvField *mv) | ||
| 2075 | { | ||
| 2076 | 2833077 | const HEVCContext *const s = lc->parent; | |
| 2077 | 2833077 | enum InterPredIdc inter_pred_idc = PRED_L0; | |
| 2078 | int mvp_flag; | ||
| 2079 | |||
| 2080 | 2833077 | ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size); | |
| 2081 | 2833077 | mv->pred_flag = 0; | |
| 2082 |
2/2✓ Branch 0 taken 1922844 times.
✓ Branch 1 taken 910233 times.
|
2833077 | if (s->sh.slice_type == HEVC_SLICE_B) |
| 2083 | 1922844 | inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH); | |
| 2084 | |||
| 2085 |
2/2✓ Branch 0 taken 2423759 times.
✓ Branch 1 taken 409318 times.
|
2833077 | if (inter_pred_idc != PRED_L1) { |
| 2086 |
1/2✓ Branch 0 taken 2423759 times.
✗ Branch 1 not taken.
|
2423759 | if (s->sh.nb_refs[L0]) |
| 2087 | 2423759 | mv->ref_idx[0]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L0]); | |
| 2088 | |||
| 2089 | 2423759 | mv->pred_flag = PF_L0; | |
| 2090 | 2423759 | ff_hevc_hls_mvd_coding(lc, x0, y0, 0); | |
| 2091 | 2423759 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
| 2092 | 2423759 | ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
| 2093 | part_idx, merge_idx, mv, mvp_flag, 0); | ||
| 2094 | 2423759 | mv->mv[0].x += lc->pu.mvd.x; | |
| 2095 | 2423759 | mv->mv[0].y += lc->pu.mvd.y; | |
| 2096 | } | ||
| 2097 | |||
| 2098 |
2/2✓ Branch 0 taken 834243 times.
✓ Branch 1 taken 1998834 times.
|
2833077 | if (inter_pred_idc != PRED_L0) { |
| 2099 |
1/2✓ Branch 0 taken 834243 times.
✗ Branch 1 not taken.
|
834243 | if (s->sh.nb_refs[L1]) |
| 2100 | 834243 | mv->ref_idx[1]= ff_hevc_ref_idx_lx_decode(lc, s->sh.nb_refs[L1]); | |
| 2101 | |||
| 2102 |
4/4✓ Branch 0 taken 193172 times.
✓ Branch 1 taken 641071 times.
✓ Branch 2 taken 163605 times.
✓ Branch 3 taken 29567 times.
|
834243 | if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) { |
| 2103 | 163605 | AV_ZERO32(&lc->pu.mvd); | |
| 2104 | } else { | ||
| 2105 | 670638 | ff_hevc_hls_mvd_coding(lc, x0, y0, 1); | |
| 2106 | } | ||
| 2107 | |||
| 2108 | 834243 | mv->pred_flag += PF_L1; | |
| 2109 | 834243 | mvp_flag = ff_hevc_mvp_lx_flag_decode(lc); | |
| 2110 | 834243 | ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
| 2111 | part_idx, merge_idx, mv, mvp_flag, 1); | ||
| 2112 | 834243 | mv->mv[1].x += lc->pu.mvd.x; | |
| 2113 | 834243 | mv->mv[1].y += lc->pu.mvd.y; | |
| 2114 | } | ||
| 2115 | 2833077 | } | |
| 2116 | |||
| 2117 | 10334637 | static void hls_prediction_unit(HEVCLocalContext *lc, | |
| 2118 | const HEVCLayerContext *l, | ||
| 2119 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2120 | int x0, int y0, int nPbW, int nPbH, | ||
| 2121 | int log2_cb_size, int partIdx, int idx) | ||
| 2122 | { | ||
| 2123 | #define POS(c_idx, x, y) \ | ||
| 2124 | s->cur_frame->f->data[c_idx] ? \ | ||
| 2125 | &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \ | ||
| 2126 | (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] : NULL | ||
| 2127 | 10334637 | const HEVCContext *const s = lc->parent; | |
| 2128 | 10334637 | int merge_idx = 0; | |
| 2129 | 10334637 | struct MvField current_mv = {{{ 0 }}}; | |
| 2130 | |||
| 2131 | 10334637 | int min_pu_width = sps->min_pu_width; | |
| 2132 | |||
| 2133 | 10334637 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
| 2134 | 10334637 | const RefPicList *refPicList = s->cur_frame->refPicList; | |
| 2135 | 10334637 | const HEVCFrame *ref0 = NULL, *ref1 = NULL; | |
| 2136 | 10334637 | const int *linesize = s->cur_frame->f->linesize; | |
| 2137 | 10334637 | uint8_t *dst0 = s->cur_frame->f->data[0] + y0 * linesize[0] + (x0 << sps->pixel_shift); | |
| 2138 |
1/2✓ Branch 0 taken 10334637 times.
✗ Branch 1 not taken.
|
10334637 | uint8_t *dst1 = POS(1, x0, y0); |
| 2139 |
1/2✓ Branch 0 taken 10334637 times.
✗ Branch 1 not taken.
|
10334637 | uint8_t *dst2 = POS(2, x0, y0); |
| 2140 | 10334637 | int log2_min_cb_size = sps->log2_min_cb_size; | |
| 2141 | 10334637 | int min_cb_width = sps->min_cb_width; | |
| 2142 | 10334637 | int x_cb = x0 >> log2_min_cb_size; | |
| 2143 | 10334637 | int y_cb = y0 >> log2_min_cb_size; | |
| 2144 | int x_pu, y_pu; | ||
| 2145 | int i, j; | ||
| 2146 | |||
| 2147 | 10334637 | int skip_flag = SAMPLE_CTB(l->skip_flag, x_cb, y_cb); | |
| 2148 | |||
| 2149 |
2/2✓ Branch 0 taken 5769030 times.
✓ Branch 1 taken 4565607 times.
|
10334637 | if (!skip_flag) |
| 2150 | 5769030 | lc->pu.merge_flag = ff_hevc_merge_flag_decode(lc); | |
| 2151 | |||
| 2152 |
4/4✓ Branch 0 taken 5769030 times.
✓ Branch 1 taken 4565607 times.
✓ Branch 2 taken 2935953 times.
✓ Branch 3 taken 2833077 times.
|
10334637 | if (skip_flag || lc->pu.merge_flag) { |
| 2153 |
2/2✓ Branch 0 taken 7424707 times.
✓ Branch 1 taken 76853 times.
|
7501560 | if (s->sh.max_num_merge_cand > 1) |
| 2154 | 7424707 | merge_idx = ff_hevc_merge_idx_decode(lc); | |
| 2155 | else | ||
| 2156 | 76853 | merge_idx = 0; | |
| 2157 | |||
| 2158 | 7501560 | ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size, | |
| 2159 | partIdx, merge_idx, ¤t_mv); | ||
| 2160 | } else { | ||
| 2161 | 2833077 | hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size, | |
| 2162 | partIdx, merge_idx, ¤t_mv); | ||
| 2163 | } | ||
| 2164 | |||
| 2165 | 10334637 | x_pu = x0 >> sps->log2_min_pu_size; | |
| 2166 | 10334637 | y_pu = y0 >> sps->log2_min_pu_size; | |
| 2167 | |||
| 2168 |
2/2✓ Branch 0 taken 40422698 times.
✓ Branch 1 taken 10334637 times.
|
50757335 | for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++) |
| 2169 |
2/2✓ Branch 0 taken 258353932 times.
✓ Branch 1 taken 40422698 times.
|
298776630 | for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++) |
| 2170 | 258353932 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; | |
| 2171 | |||
| 2172 |
2/2✓ Branch 0 taken 9515439 times.
✓ Branch 1 taken 819198 times.
|
10334637 | if (current_mv.pred_flag & PF_L0) { |
| 2173 | 9515439 | ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; | |
| 2174 |
2/4✓ Branch 0 taken 9515439 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9515439 times.
|
9515439 | if (!ref0 || !ref0->f) |
| 2175 | ✗ | return; | |
| 2176 | 9515439 | hevc_await_progress(s, ref0, ¤t_mv.mv[0], y0, nPbH); | |
| 2177 | } | ||
| 2178 |
2/2✓ Branch 0 taken 4811281 times.
✓ Branch 1 taken 5523356 times.
|
10334637 | if (current_mv.pred_flag & PF_L1) { |
| 2179 | 4811281 | ref1 = refPicList[1].ref[current_mv.ref_idx[1]]; | |
| 2180 |
2/4✓ Branch 0 taken 4811281 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4811281 times.
|
4811281 | if (!ref1 || !ref1->f) |
| 2181 | ✗ | return; | |
| 2182 | 4811281 | hevc_await_progress(s, ref1, ¤t_mv.mv[1], y0, nPbH); | |
| 2183 | } | ||
| 2184 | |||
| 2185 |
2/2✓ Branch 0 taken 5523356 times.
✓ Branch 1 taken 4811281 times.
|
10334637 | if (current_mv.pred_flag == PF_L0) { |
| 2186 | 5523356 | int x0_c = x0 >> sps->hshift[1]; | |
| 2187 | 5523356 | int y0_c = y0 >> sps->vshift[1]; | |
| 2188 | 5523356 | int nPbW_c = nPbW >> sps->hshift[1]; | |
| 2189 | 5523356 | int nPbH_c = nPbH >> sps->vshift[1]; | |
| 2190 | |||
| 2191 | 5523356 | luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f, | |
| 2192 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
| 2193 | 5523356 | s->sh.luma_weight_l0[current_mv.ref_idx[0]], | |
| 2194 | 5523356 | s->sh.luma_offset_l0[current_mv.ref_idx[0]]); | |
| 2195 | |||
| 2196 |
1/2✓ Branch 0 taken 5523356 times.
✗ Branch 1 not taken.
|
5523356 | if (sps->chroma_format_idc) { |
| 2197 | 5523356 | chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1], | |
| 2198 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
| 2199 | 5523356 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]); | |
| 2200 | 5523356 | chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2], | |
| 2201 | 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
| 2202 | 5523356 | s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]); | |
| 2203 | } | ||
| 2204 |
2/2✓ Branch 0 taken 819198 times.
✓ Branch 1 taken 3992083 times.
|
4811281 | } else if (current_mv.pred_flag == PF_L1) { |
| 2205 | 819198 | int x0_c = x0 >> sps->hshift[1]; | |
| 2206 | 819198 | int y0_c = y0 >> sps->vshift[1]; | |
| 2207 | 819198 | int nPbW_c = nPbW >> sps->hshift[1]; | |
| 2208 | 819198 | int nPbH_c = nPbH >> sps->vshift[1]; | |
| 2209 | |||
| 2210 | 819198 | luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f, | |
| 2211 | ¤t_mv.mv[1], x0, y0, nPbW, nPbH, | ||
| 2212 | 819198 | s->sh.luma_weight_l1[current_mv.ref_idx[1]], | |
| 2213 | 819198 | s->sh.luma_offset_l1[current_mv.ref_idx[1]]); | |
| 2214 | |||
| 2215 |
1/2✓ Branch 0 taken 819198 times.
✗ Branch 1 not taken.
|
819198 | if (sps->chroma_format_idc) { |
| 2216 | 819198 | chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1], | |
| 2217 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
| 2218 | 819198 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]); | |
| 2219 | |||
| 2220 | 819198 | chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2], | |
| 2221 | 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, | ||
| 2222 | 819198 | s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]); | |
| 2223 | } | ||
| 2224 |
1/2✓ Branch 0 taken 3992083 times.
✗ Branch 1 not taken.
|
3992083 | } else if (current_mv.pred_flag == PF_BI) { |
| 2225 | 3992083 | int x0_c = x0 >> sps->hshift[1]; | |
| 2226 | 3992083 | int y0_c = y0 >> sps->vshift[1]; | |
| 2227 | 3992083 | int nPbW_c = nPbW >> sps->hshift[1]; | |
| 2228 | 3992083 | int nPbH_c = nPbH >> sps->vshift[1]; | |
| 2229 | |||
| 2230 | 3992083 | luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f, | |
| 2231 | ¤t_mv.mv[0], x0, y0, nPbW, nPbH, | ||
| 2232 | 3992083 | ref1->f, ¤t_mv.mv[1], ¤t_mv); | |
| 2233 | |||
| 2234 |
1/2✓ Branch 0 taken 3992083 times.
✗ Branch 1 not taken.
|
3992083 | if (sps->chroma_format_idc) { |
| 2235 | 3992083 | chroma_mc_bi(lc, pps, sps, dst1, linesize[1], ref0->f, ref1->f, | |
| 2236 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0); | ||
| 2237 | |||
| 2238 | 3992083 | chroma_mc_bi(lc, pps, sps, dst2, linesize[2], ref0->f, ref1->f, | |
| 2239 | x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1); | ||
| 2240 | } | ||
| 2241 | } | ||
| 2242 | } | ||
| 2243 | |||
| 2244 | /** | ||
| 2245 | * 8.4.1 | ||
| 2246 | */ | ||
| 2247 | 6761317 | static int luma_intra_pred_mode(HEVCLocalContext *lc, const HEVCLayerContext *l, | |
| 2248 | const HEVCSPS *sps, | ||
| 2249 | int x0, int y0, int pu_size, | ||
| 2250 | int prev_intra_luma_pred_flag) | ||
| 2251 | { | ||
| 2252 | 6761317 | const HEVCContext *const s = lc->parent; | |
| 2253 | 6761317 | int x_pu = x0 >> sps->log2_min_pu_size; | |
| 2254 | 6761317 | int y_pu = y0 >> sps->log2_min_pu_size; | |
| 2255 | 6761317 | int min_pu_width = sps->min_pu_width; | |
| 2256 | 6761317 | int size_in_pus = pu_size >> sps->log2_min_pu_size; | |
| 2257 | 6761317 | int x0b = av_zero_extend(x0, sps->log2_ctb_size); | |
| 2258 | 6761317 | int y0b = av_zero_extend(y0, sps->log2_ctb_size); | |
| 2259 | |||
| 2260 |
2/2✓ Branch 0 taken 896869 times.
✓ Branch 1 taken 105287 times.
|
1002156 | int cand_up = (lc->ctb_up_flag || y0b) ? |
| 2261 |
2/2✓ Branch 0 taken 1002156 times.
✓ Branch 1 taken 5759161 times.
|
7763473 | l->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC; |
| 2262 |
2/2✓ Branch 0 taken 485793 times.
✓ Branch 1 taken 68222 times.
|
554015 | int cand_left = (lc->ctb_left_flag || x0b) ? |
| 2263 |
2/2✓ Branch 0 taken 554015 times.
✓ Branch 1 taken 6207302 times.
|
7315332 | l->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC; |
| 2264 | |||
| 2265 | 6761317 | int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size); | |
| 2266 | |||
| 2267 | 6761317 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
| 2268 | int intra_pred_mode; | ||
| 2269 | int candidate[3]; | ||
| 2270 | int i, j; | ||
| 2271 | |||
| 2272 | // intra_pred_mode prediction does not cross vertical CTB boundaries | ||
| 2273 |
2/2✓ Branch 0 taken 906591 times.
✓ Branch 1 taken 5854726 times.
|
6761317 | if ((y0 - 1) < y_ctb) |
| 2274 | 906591 | cand_up = INTRA_DC; | |
| 2275 | |||
| 2276 |
2/2✓ Branch 0 taken 1510566 times.
✓ Branch 1 taken 5250751 times.
|
6761317 | if (cand_left == cand_up) { |
| 2277 |
2/2✓ Branch 0 taken 969747 times.
✓ Branch 1 taken 540819 times.
|
1510566 | if (cand_left < 2) { |
| 2278 | 969747 | candidate[0] = INTRA_PLANAR; | |
| 2279 | 969747 | candidate[1] = INTRA_DC; | |
| 2280 | 969747 | candidate[2] = INTRA_ANGULAR_26; | |
| 2281 | } else { | ||
| 2282 | 540819 | candidate[0] = cand_left; | |
| 2283 | 540819 | candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31); | |
| 2284 | 540819 | candidate[2] = 2 + ((cand_left - 2 + 1) & 31); | |
| 2285 | } | ||
| 2286 | } else { | ||
| 2287 | 5250751 | candidate[0] = cand_left; | |
| 2288 | 5250751 | candidate[1] = cand_up; | |
| 2289 |
4/4✓ Branch 0 taken 4356599 times.
✓ Branch 1 taken 894152 times.
✓ Branch 2 taken 3600619 times.
✓ Branch 3 taken 755980 times.
|
5250751 | if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) { |
| 2290 | 3600619 | candidate[2] = INTRA_PLANAR; | |
| 2291 |
4/4✓ Branch 0 taken 1434773 times.
✓ Branch 1 taken 215359 times.
✓ Branch 2 taken 1069940 times.
✓ Branch 3 taken 364833 times.
|
1650132 | } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) { |
| 2292 | 1069940 | candidate[2] = INTRA_DC; | |
| 2293 | } else { | ||
| 2294 | 580192 | candidate[2] = INTRA_ANGULAR_26; | |
| 2295 | } | ||
| 2296 | } | ||
| 2297 | |||
| 2298 |
2/2✓ Branch 0 taken 4012676 times.
✓ Branch 1 taken 2748641 times.
|
6761317 | if (prev_intra_luma_pred_flag) { |
| 2299 | 4012676 | intra_pred_mode = candidate[lc->pu.mpm_idx]; | |
| 2300 | } else { | ||
| 2301 |
2/2✓ Branch 0 taken 1262937 times.
✓ Branch 1 taken 1485704 times.
|
2748641 | if (candidate[0] > candidate[1]) |
| 2302 | 1262937 | FFSWAP(uint8_t, candidate[0], candidate[1]); | |
| 2303 |
2/2✓ Branch 0 taken 1587166 times.
✓ Branch 1 taken 1161475 times.
|
2748641 | if (candidate[0] > candidate[2]) |
| 2304 | 1587166 | FFSWAP(uint8_t, candidate[0], candidate[2]); | |
| 2305 |
2/2✓ Branch 0 taken 1982612 times.
✓ Branch 1 taken 766029 times.
|
2748641 | if (candidate[1] > candidate[2]) |
| 2306 | 1982612 | FFSWAP(uint8_t, candidate[1], candidate[2]); | |
| 2307 | |||
| 2308 | 2748641 | intra_pred_mode = lc->pu.rem_intra_luma_pred_mode; | |
| 2309 |
2/2✓ Branch 0 taken 8245923 times.
✓ Branch 1 taken 2748641 times.
|
10994564 | for (i = 0; i < 3; i++) |
| 2310 |
2/2✓ Branch 0 taken 6015586 times.
✓ Branch 1 taken 2230337 times.
|
8245923 | if (intra_pred_mode >= candidate[i]) |
| 2311 | 6015586 | intra_pred_mode++; | |
| 2312 | } | ||
| 2313 | |||
| 2314 | /* write the intra prediction units into the mv array */ | ||
| 2315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6761317 times.
|
6761317 | if (!size_in_pus) |
| 2316 | ✗ | size_in_pus = 1; | |
| 2317 |
2/2✓ Branch 0 taken 12295582 times.
✓ Branch 1 taken 6761317 times.
|
19056899 | for (i = 0; i < size_in_pus; i++) { |
| 2318 | 12295582 | memset(&l->tab_ipm[(y_pu + i) * min_pu_width + x_pu], | |
| 2319 | intra_pred_mode, size_in_pus); | ||
| 2320 | |||
| 2321 |
2/2✓ Branch 0 taken 41237824 times.
✓ Branch 1 taken 12295582 times.
|
53533406 | for (j = 0; j < size_in_pus; j++) { |
| 2322 | 41237824 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag = PF_INTRA; | |
| 2323 | } | ||
| 2324 | } | ||
| 2325 | |||
| 2326 | 6761317 | return intra_pred_mode; | |
| 2327 | } | ||
| 2328 | |||
| 2329 | 12248004 | static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth, | |
| 2330 | int x0, int y0, | ||
| 2331 | int log2_cb_size, int ct_depth) | ||
| 2332 | { | ||
| 2333 | 12248004 | int length = (1 << log2_cb_size) >> sps->log2_min_cb_size; | |
| 2334 | 12248004 | int x_cb = x0 >> sps->log2_min_cb_size; | |
| 2335 | 12248004 | int y_cb = y0 >> sps->log2_min_cb_size; | |
| 2336 | int y; | ||
| 2337 | |||
| 2338 |
2/2✓ Branch 0 taken 23601676 times.
✓ Branch 1 taken 12248004 times.
|
35849680 | for (y = 0; y < length; y++) |
| 2339 | 23601676 | memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb], | |
| 2340 | ct_depth, length); | ||
| 2341 | 12248004 | } | |
| 2342 | |||
| 2343 | static const uint8_t tab_mode_idx[] = { | ||
| 2344 | 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, | ||
| 2345 | 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31}; | ||
| 2346 | |||
| 2347 | 3637384 | static void intra_prediction_unit(HEVCLocalContext *lc, | |
| 2348 | const HEVCLayerContext *l, const HEVCSPS *sps, | ||
| 2349 | int x0, int y0, | ||
| 2350 | int log2_cb_size) | ||
| 2351 | { | ||
| 2352 | static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 }; | ||
| 2353 | uint8_t prev_intra_luma_pred_flag[4]; | ||
| 2354 | 3637384 | int split = lc->cu.part_mode == PART_NxN; | |
| 2355 | 3637384 | int pb_size = (1 << log2_cb_size) >> split; | |
| 2356 | 3637384 | int side = split + 1; | |
| 2357 | int chroma_mode; | ||
| 2358 | int i, j; | ||
| 2359 | |||
| 2360 |
2/2✓ Branch 0 taken 4678695 times.
✓ Branch 1 taken 3637384 times.
|
8316079 | for (i = 0; i < side; i++) |
| 2361 |
2/2✓ Branch 0 taken 6761317 times.
✓ Branch 1 taken 4678695 times.
|
11440012 | for (j = 0; j < side; j++) |
| 2362 | 6761317 | prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(lc); | |
| 2363 | |||
| 2364 |
2/2✓ Branch 0 taken 4678695 times.
✓ Branch 1 taken 3637384 times.
|
8316079 | for (i = 0; i < side; i++) { |
| 2365 |
2/2✓ Branch 0 taken 6761317 times.
✓ Branch 1 taken 4678695 times.
|
11440012 | for (j = 0; j < side; j++) { |
| 2366 |
2/2✓ Branch 0 taken 4012676 times.
✓ Branch 1 taken 2748641 times.
|
6761317 | if (prev_intra_luma_pred_flag[2 * i + j]) |
| 2367 | 4012676 | lc->pu.mpm_idx = ff_hevc_mpm_idx_decode(lc); | |
| 2368 | else | ||
| 2369 | 2748641 | lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc); | |
| 2370 | |||
| 2371 | 6761317 | lc->pu.intra_pred_mode[2 * i + j] = | |
| 2372 | 6761317 | luma_intra_pred_mode(lc, l, sps, | |
| 2373 | 6761317 | x0 + pb_size * j, y0 + pb_size * i, pb_size, | |
| 2374 | 6761317 | prev_intra_luma_pred_flag[2 * i + j]); | |
| 2375 | } | ||
| 2376 | } | ||
| 2377 | |||
| 2378 |
2/2✓ Branch 0 taken 59336 times.
✓ Branch 1 taken 3578048 times.
|
3637384 | if (sps->chroma_format_idc == 3) { |
| 2379 |
2/2✓ Branch 0 taken 77980 times.
✓ Branch 1 taken 59336 times.
|
137316 | for (i = 0; i < side; i++) { |
| 2380 |
2/2✓ Branch 0 taken 115268 times.
✓ Branch 1 taken 77980 times.
|
193248 | for (j = 0; j < side; j++) { |
| 2381 | 115268 | lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
| 2382 |
2/2✓ Branch 0 taken 19491 times.
✓ Branch 1 taken 95777 times.
|
115268 | if (chroma_mode != 4) { |
| 2383 |
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]) |
| 2384 | 1462 | lc->pu.intra_pred_mode_c[2 * i + j] = 34; | |
| 2385 | else | ||
| 2386 | 18029 | lc->pu.intra_pred_mode_c[2 * i + j] = intra_chroma_table[chroma_mode]; | |
| 2387 | } else { | ||
| 2388 | 95777 | lc->pu.intra_pred_mode_c[2 * i + j] = lc->pu.intra_pred_mode[2 * i + j]; | |
| 2389 | } | ||
| 2390 | } | ||
| 2391 | } | ||
| 2392 |
2/2✓ Branch 0 taken 147152 times.
✓ Branch 1 taken 3430896 times.
|
3578048 | } else if (sps->chroma_format_idc == 2) { |
| 2393 | int mode_idx; | ||
| 2394 | 147152 | lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
| 2395 |
2/2✓ Branch 0 taken 46479 times.
✓ Branch 1 taken 100673 times.
|
147152 | if (chroma_mode != 4) { |
| 2396 |
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]) |
| 2397 | 2238 | mode_idx = 34; | |
| 2398 | else | ||
| 2399 | 44241 | mode_idx = intra_chroma_table[chroma_mode]; | |
| 2400 | } else { | ||
| 2401 | 100673 | mode_idx = lc->pu.intra_pred_mode[0]; | |
| 2402 | } | ||
| 2403 | 147152 | lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx]; | |
| 2404 |
2/2✓ Branch 0 taken 3430800 times.
✓ Branch 1 taken 96 times.
|
3430896 | } else if (sps->chroma_format_idc != 0) { |
| 2405 | 3430800 | chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc); | |
| 2406 |
2/2✓ Branch 0 taken 822839 times.
✓ Branch 1 taken 2607961 times.
|
3430800 | if (chroma_mode != 4) { |
| 2407 |
2/2✓ Branch 0 taken 61000 times.
✓ Branch 1 taken 761839 times.
|
822839 | if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode]) |
| 2408 | 61000 | lc->pu.intra_pred_mode_c[0] = 34; | |
| 2409 | else | ||
| 2410 | 761839 | lc->pu.intra_pred_mode_c[0] = intra_chroma_table[chroma_mode]; | |
| 2411 | } else { | ||
| 2412 | 2607961 | lc->pu.intra_pred_mode_c[0] = lc->pu.intra_pred_mode[0]; | |
| 2413 | } | ||
| 2414 | } | ||
| 2415 | 3637384 | } | |
| 2416 | |||
| 2417 | 8610621 | static void intra_prediction_unit_default_value(HEVCLocalContext *lc, | |
| 2418 | const HEVCLayerContext *l, | ||
| 2419 | const HEVCSPS *sps, | ||
| 2420 | int x0, int y0, | ||
| 2421 | int log2_cb_size) | ||
| 2422 | { | ||
| 2423 | 8610621 | const HEVCContext *const s = lc->parent; | |
| 2424 | 8610621 | int pb_size = 1 << log2_cb_size; | |
| 2425 | 8610621 | int size_in_pus = pb_size >> sps->log2_min_pu_size; | |
| 2426 | 8610621 | int min_pu_width = sps->min_pu_width; | |
| 2427 | 8610621 | MvField *tab_mvf = s->cur_frame->tab_mvf; | |
| 2428 | 8610621 | int x_pu = x0 >> sps->log2_min_pu_size; | |
| 2429 | 8610621 | int y_pu = y0 >> sps->log2_min_pu_size; | |
| 2430 | int j, k; | ||
| 2431 | |||
| 2432 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8610621 times.
|
8610621 | if (size_in_pus == 0) |
| 2433 | ✗ | size_in_pus = 1; | |
| 2434 |
2/2✓ Branch 0 taken 36990394 times.
✓ Branch 1 taken 8610621 times.
|
45601015 | for (j = 0; j < size_in_pus; j++) |
| 2435 | 36990394 | memset(&l->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus); | |
| 2436 |
2/2✓ Branch 0 taken 11207 times.
✓ Branch 1 taken 8599414 times.
|
8610621 | if (lc->cu.pred_mode == MODE_INTRA) |
| 2437 |
2/2✓ Branch 0 taken 37756 times.
✓ Branch 1 taken 11207 times.
|
48963 | for (j = 0; j < size_in_pus; j++) |
| 2438 |
2/2✓ Branch 0 taken 172544 times.
✓ Branch 1 taken 37756 times.
|
210300 | for (k = 0; k < size_in_pus; k++) |
| 2439 | 172544 | tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA; | |
| 2440 | 8610621 | } | |
| 2441 | |||
| 2442 | 12248005 | static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, | |
| 2443 | const HEVCLayerContext *l, | ||
| 2444 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2445 | int x0, int y0, int log2_cb_size) | ||
| 2446 | { | ||
| 2447 | 12248005 | int cb_size = 1 << log2_cb_size; | |
| 2448 | 12248005 | int log2_min_cb_size = sps->log2_min_cb_size; | |
| 2449 | 12248005 | int length = cb_size >> log2_min_cb_size; | |
| 2450 | 12248005 | int min_cb_width = sps->min_cb_width; | |
| 2451 | 12248005 | int x_cb = x0 >> log2_min_cb_size; | |
| 2452 | 12248005 | int y_cb = y0 >> log2_min_cb_size; | |
| 2453 | 12248005 | int idx = log2_cb_size - 2; | |
| 2454 | 12248005 | int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1; | |
| 2455 | int x, y, ret; | ||
| 2456 | |||
| 2457 | 12248005 | lc->cu.x = x0; | |
| 2458 | 12248005 | lc->cu.y = y0; | |
| 2459 | 12248005 | lc->cu.pred_mode = MODE_INTRA; | |
| 2460 | 12248005 | lc->cu.part_mode = PART_2Nx2N; | |
| 2461 | 12248005 | lc->cu.intra_split_flag = 0; | |
| 2462 | |||
| 2463 | 12248005 | SAMPLE_CTB(l->skip_flag, x_cb, y_cb) = 0; | |
| 2464 |
2/2✓ Branch 0 taken 48992020 times.
✓ Branch 1 taken 12248005 times.
|
61240025 | for (x = 0; x < 4; x++) |
| 2465 | 48992020 | lc->pu.intra_pred_mode[x] = 1; | |
| 2466 |
2/2✓ Branch 0 taken 179649 times.
✓ Branch 1 taken 12068356 times.
|
12248005 | if (pps->transquant_bypass_enable_flag) { |
| 2467 | 179649 | lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(lc); | |
| 2468 |
2/2✓ Branch 0 taken 79710 times.
✓ Branch 1 taken 99939 times.
|
179649 | if (lc->cu.cu_transquant_bypass_flag) |
| 2469 | 79710 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size); | |
| 2470 | } else | ||
| 2471 | 12068356 | lc->cu.cu_transquant_bypass_flag = 0; | |
| 2472 | |||
| 2473 |
2/2✓ Branch 0 taken 9866641 times.
✓ Branch 1 taken 2381364 times.
|
12248005 | if (s->sh.slice_type != HEVC_SLICE_I) { |
| 2474 | 9866641 | const int x0b = av_zero_extend(x0, sps->log2_ctb_size); | |
| 2475 | 9866641 | const int y0b = av_zero_extend(y0, sps->log2_ctb_size); | |
| 2476 | 9866641 | uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, l->skip_flag, | |
| 2477 | x0b, y0b, x_cb, y_cb, | ||
| 2478 | min_cb_width); | ||
| 2479 | |||
| 2480 | 9866641 | x = y_cb * min_cb_width + x_cb; | |
| 2481 |
2/2✓ Branch 0 taken 20398545 times.
✓ Branch 1 taken 9866641 times.
|
30265186 | for (y = 0; y < length; y++) { |
| 2482 | 20398545 | memset(&l->skip_flag[x], skip_flag, length); | |
| 2483 | 20398545 | x += min_cb_width; | |
| 2484 | } | ||
| 2485 |
2/2✓ Branch 0 taken 4565607 times.
✓ Branch 1 taken 5301034 times.
|
9866641 | lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER; |
| 2486 | } else { | ||
| 2487 | 2381364 | x = y_cb * min_cb_width + x_cb; | |
| 2488 |
2/2✓ Branch 0 taken 3203132 times.
✓ Branch 1 taken 2381364 times.
|
5584496 | for (y = 0; y < length; y++) { |
| 2489 | 3203132 | memset(&l->skip_flag[x], 0, length); | |
| 2490 | 3203132 | x += min_cb_width; | |
| 2491 | } | ||
| 2492 | } | ||
| 2493 | |||
| 2494 |
2/2✓ Branch 0 taken 4565607 times.
✓ Branch 1 taken 7682398 times.
|
12248005 | if (SAMPLE_CTB(l->skip_flag, x_cb, y_cb)) { |
| 2495 | 4565607 | hls_prediction_unit(lc, l, pps, sps, | |
| 2496 | x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | ||
| 2497 | 4565607 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
| 2498 | |||
| 2499 |
2/2✓ Branch 0 taken 4419094 times.
✓ Branch 1 taken 146513 times.
|
4565607 | if (!s->sh.disable_deblocking_filter_flag) |
| 2500 | 4419094 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
| 2501 | } else { | ||
| 2502 | 7682398 | int pcm_flag = 0; | |
| 2503 | |||
| 2504 |
2/2✓ Branch 0 taken 5301034 times.
✓ Branch 1 taken 2381364 times.
|
7682398 | if (s->sh.slice_type != HEVC_SLICE_I) |
| 2505 | 5301034 | lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc); | |
| 2506 |
2/2✓ Branch 0 taken 3648591 times.
✓ Branch 1 taken 4033807 times.
|
7682398 | if (lc->cu.pred_mode != MODE_INTRA || |
| 2507 |
2/2✓ Branch 0 taken 2742596 times.
✓ Branch 1 taken 905995 times.
|
3648591 | log2_cb_size == sps->log2_min_cb_size) { |
| 2508 | 6776403 | lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size); | |
| 2509 |
2/2✓ Branch 0 taken 1149466 times.
✓ Branch 1 taken 5626937 times.
|
7925869 | lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN && |
| 2510 |
2/2✓ Branch 0 taken 1041311 times.
✓ Branch 1 taken 108155 times.
|
1149466 | lc->cu.pred_mode == MODE_INTRA; |
| 2511 | } | ||
| 2512 | |||
| 2513 |
2/2✓ Branch 0 taken 3648591 times.
✓ Branch 1 taken 4033807 times.
|
7682398 | if (lc->cu.pred_mode == MODE_INTRA) { |
| 2514 |
4/4✓ Branch 0 taken 2607280 times.
✓ Branch 1 taken 1041311 times.
✓ Branch 2 taken 134413 times.
✓ Branch 3 taken 2472867 times.
|
3648591 | if (lc->cu.part_mode == PART_2Nx2N && sps->pcm_enabled && |
| 2515 |
2/2✓ Branch 0 taken 133790 times.
✓ Branch 1 taken 623 times.
|
134413 | log2_cb_size >= sps->pcm.log2_min_pcm_cb_size && |
| 2516 |
2/2✓ Branch 0 taken 126478 times.
✓ Branch 1 taken 7312 times.
|
133790 | log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) { |
| 2517 | 126478 | pcm_flag = ff_hevc_pcm_flag_decode(lc); | |
| 2518 | } | ||
| 2519 |
2/2✓ Branch 0 taken 11207 times.
✓ Branch 1 taken 3637384 times.
|
3648591 | if (pcm_flag) { |
| 2520 | 11207 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
| 2521 | 11207 | ret = hls_pcm_sample(lc, l, pps, x0, y0, log2_cb_size); | |
| 2522 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11203 times.
|
11207 | if (sps->pcm_loop_filter_disabled) |
| 2523 | 4 | set_deblocking_bypass(l->is_pcm, sps, x0, y0, log2_cb_size); | |
| 2524 | |||
| 2525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11207 times.
|
11207 | if (ret < 0) |
| 2526 | ✗ | return ret; | |
| 2527 | } else { | ||
| 2528 | 3637384 | intra_prediction_unit(lc, l, sps, x0, y0, log2_cb_size); | |
| 2529 | } | ||
| 2530 | } else { | ||
| 2531 | 4033807 | intra_prediction_unit_default_value(lc, l, sps, x0, y0, log2_cb_size); | |
| 2532 |
8/9✓ Branch 0 taken 2514894 times.
✓ Branch 1 taken 499267 times.
✓ Branch 2 taken 599864 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.
|
4033807 | switch (lc->cu.part_mode) { |
| 2533 | 2514894 | case PART_2Nx2N: | |
| 2534 | 2514894 | hls_prediction_unit(lc, l, pps, sps, | |
| 2535 | x0, y0, cb_size, cb_size, log2_cb_size, 0, idx); | ||
| 2536 | 2514894 | break; | |
| 2537 | 499267 | case PART_2NxN: | |
| 2538 | 499267 | hls_prediction_unit(lc, l, pps, sps, | |
| 2539 | x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx); | ||
| 2540 | 499267 | hls_prediction_unit(lc, l, pps, sps, | |
| 2541 | 499267 | x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx); | |
| 2542 | 499267 | break; | |
| 2543 | 599864 | case PART_Nx2N: | |
| 2544 | 599864 | hls_prediction_unit(lc, l, pps, sps, | |
| 2545 | x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1); | ||
| 2546 | 599864 | hls_prediction_unit(lc, l, pps, sps, | |
| 2547 | 599864 | x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1); | |
| 2548 | 599864 | break; | |
| 2549 | 67350 | case PART_2NxnU: | |
| 2550 | 67350 | hls_prediction_unit(lc, l, pps, sps, | |
| 2551 | x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx); | ||
| 2552 | 67350 | hls_prediction_unit(lc, l, pps, sps, | |
| 2553 | 67350 | x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx); | |
| 2554 | 67350 | break; | |
| 2555 | 58153 | case PART_2NxnD: | |
| 2556 | 58153 | hls_prediction_unit(lc, l, pps, sps, | |
| 2557 | 58153 | x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx); | |
| 2558 | 58153 | hls_prediction_unit(lc, l, pps, sps, | |
| 2559 | 58153 | x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx); | |
| 2560 | 58153 | break; | |
| 2561 | 100281 | case PART_nLx2N: | |
| 2562 | 100281 | hls_prediction_unit(lc, l, pps, sps, | |
| 2563 | x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2); | ||
| 2564 | 100281 | hls_prediction_unit(lc, l, pps, sps, | |
| 2565 | 100281 | x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2); | |
| 2566 | 100281 | break; | |
| 2567 | 85843 | case PART_nRx2N: | |
| 2568 | 85843 | hls_prediction_unit(lc, l, pps, sps, | |
| 2569 | 85843 | x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2); | |
| 2570 | 85843 | hls_prediction_unit(lc, l, pps, sps, | |
| 2571 | 85843 | x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2); | |
| 2572 | 85843 | break; | |
| 2573 | 108155 | case PART_NxN: | |
| 2574 | 108155 | hls_prediction_unit(lc, l, pps, sps, | |
| 2575 | x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1); | ||
| 2576 | 108155 | hls_prediction_unit(lc, l, pps, sps, | |
| 2577 | 108155 | x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1); | |
| 2578 | 108155 | hls_prediction_unit(lc, l, pps, sps, | |
| 2579 | 108155 | x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1); | |
| 2580 | 108155 | hls_prediction_unit(lc, l, pps, sps, | |
| 2581 | 108155 | x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1); | |
| 2582 | 108155 | break; | |
| 2583 | } | ||
| 2584 | } | ||
| 2585 | |||
| 2586 |
2/2✓ Branch 0 taken 7671191 times.
✓ Branch 1 taken 11207 times.
|
7682398 | if (!pcm_flag) { |
| 2587 | 7671191 | int rqt_root_cbf = 1; | |
| 2588 | |||
| 2589 |
2/2✓ Branch 0 taken 4033807 times.
✓ Branch 1 taken 3637384 times.
|
7671191 | if (lc->cu.pred_mode != MODE_INTRA && |
| 2590 |
4/4✓ Branch 0 taken 2514894 times.
✓ Branch 1 taken 1518913 times.
✓ Branch 2 taken 1307742 times.
✓ Branch 3 taken 1207152 times.
|
4033807 | !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) { |
| 2591 | 2826655 | rqt_root_cbf = ff_hevc_no_residual_syntax_flag_decode(lc); | |
| 2592 | } | ||
| 2593 |
2/2✓ Branch 0 taken 6154758 times.
✓ Branch 1 taken 1516433 times.
|
7671191 | if (rqt_root_cbf) { |
| 2594 | const static int cbf[2] = { 0 }; | ||
| 2595 |
2/2✓ Branch 0 taken 3637384 times.
✓ Branch 1 taken 2517374 times.
|
6154758 | lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ? |
| 2596 | 3637384 | sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag : | |
| 2597 | 2517374 | sps->max_transform_hierarchy_depth_inter; | |
| 2598 | 6154758 | ret = hls_transform_tree(lc, l, pps, sps, x0, y0, x0, y0, x0, y0, | |
| 2599 | log2_cb_size, | ||
| 2600 | log2_cb_size, 0, 0, cbf, cbf); | ||
| 2601 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6154757 times.
|
6154758 | if (ret < 0) |
| 2602 | 1 | return ret; | |
| 2603 | } else { | ||
| 2604 |
2/2✓ Branch 0 taken 1460001 times.
✓ Branch 1 taken 56432 times.
|
1516433 | if (!s->sh.disable_deblocking_filter_flag) |
| 2605 | 1460001 | ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); | |
| 2606 | } | ||
| 2607 | } | ||
| 2608 | } | ||
| 2609 | |||
| 2610 |
4/4✓ Branch 0 taken 3206772 times.
✓ Branch 1 taken 9041232 times.
✓ Branch 2 taken 1172325 times.
✓ Branch 3 taken 2034447 times.
|
12248004 | if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0) |
| 2611 | 1172325 | ff_hevc_set_qPy(lc, l, pps, x0, y0, log2_cb_size); | |
| 2612 | |||
| 2613 | 12248004 | x = y_cb * min_cb_width + x_cb; | |
| 2614 |
2/2✓ Branch 0 taken 23601676 times.
✓ Branch 1 taken 12248004 times.
|
35849680 | for (y = 0; y < length; y++) { |
| 2615 | 23601676 | memset(&l->qp_y_tab[x], lc->qp_y, length); | |
| 2616 | 23601676 | x += min_cb_width; | |
| 2617 | } | ||
| 2618 | |||
| 2619 |
2/2✓ Branch 0 taken 4495773 times.
✓ Branch 1 taken 7752231 times.
|
12248004 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
| 2620 |
2/2✓ Branch 0 taken 2720496 times.
✓ Branch 1 taken 1775277 times.
|
4495773 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) { |
| 2621 | 2720496 | lc->qPy_pred = lc->qp_y; | |
| 2622 | } | ||
| 2623 | |||
| 2624 | 12248004 | set_ct_depth(sps, l->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth); | |
| 2625 | |||
| 2626 | 12248004 | return 0; | |
| 2627 | } | ||
| 2628 | |||
| 2629 | 15841410 | static int hls_coding_quadtree(HEVCLocalContext *lc, | |
| 2630 | const HEVCLayerContext *l, | ||
| 2631 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2632 | int x0, int y0, | ||
| 2633 | int log2_cb_size, int cb_depth) | ||
| 2634 | { | ||
| 2635 | 15841410 | const HEVCContext *const s = lc->parent; | |
| 2636 | 15841410 | const int cb_size = 1 << log2_cb_size; | |
| 2637 | int ret; | ||
| 2638 | int split_cu; | ||
| 2639 | |||
| 2640 | 15841410 | lc->ct_depth = cb_depth; | |
| 2641 |
2/2✓ Branch 0 taken 15812212 times.
✓ Branch 1 taken 29198 times.
|
15841410 | if (x0 + cb_size <= sps->width && |
| 2642 |
2/2✓ Branch 0 taken 15494755 times.
✓ Branch 1 taken 317457 times.
|
15812212 | y0 + cb_size <= sps->height && |
| 2643 |
2/2✓ Branch 0 taken 8723164 times.
✓ Branch 1 taken 6771591 times.
|
15494755 | log2_cb_size > sps->log2_min_cb_size) { |
| 2644 | 8723164 | split_cu = ff_hevc_split_coding_unit_flag_decode(lc, l->tab_ct_depth, | |
| 2645 | sps, cb_depth, x0, y0); | ||
| 2646 | } else { | ||
| 2647 | 7118246 | split_cu = (log2_cb_size > sps->log2_min_cb_size); | |
| 2648 | } | ||
| 2649 |
2/2✓ Branch 0 taken 4063509 times.
✓ Branch 1 taken 11777901 times.
|
15841410 | if (pps->cu_qp_delta_enabled_flag && |
| 2650 |
2/2✓ Branch 0 taken 1887190 times.
✓ Branch 1 taken 2176319 times.
|
4063509 | log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) { |
| 2651 | 1887190 | lc->tu.is_cu_qp_delta_coded = 0; | |
| 2652 | 1887190 | lc->tu.cu_qp_delta = 0; | |
| 2653 | } | ||
| 2654 | |||
| 2655 |
2/2✓ Branch 0 taken 467556 times.
✓ Branch 1 taken 15373854 times.
|
15841410 | if (s->sh.cu_chroma_qp_offset_enabled_flag && |
| 2656 |
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) { |
| 2657 | 467556 | lc->tu.is_cu_chroma_qp_offset_coded = 0; | |
| 2658 | } | ||
| 2659 | |||
| 2660 |
2/2✓ Branch 0 taken 3593405 times.
✓ Branch 1 taken 12248005 times.
|
15841410 | if (split_cu) { |
| 2661 | 3593405 | int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1; | |
| 2662 | 3593405 | const int cb_size_split = cb_size >> 1; | |
| 2663 | 3593405 | const int x1 = x0 + cb_size_split; | |
| 2664 | 3593405 | const int y1 = y0 + cb_size_split; | |
| 2665 | |||
| 2666 | 3593405 | int more_data = 0; | |
| 2667 | |||
| 2668 | 3593405 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
| 2669 | x0, y0, log2_cb_size - 1, cb_depth + 1); | ||
| 2670 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3593403 times.
|
3593405 | if (more_data < 0) |
| 2671 | 2 | return more_data; | |
| 2672 | |||
| 2673 |
4/4✓ Branch 0 taken 3593395 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 3565589 times.
✓ Branch 3 taken 27806 times.
|
3593403 | if (more_data && x1 < sps->width) { |
| 2674 | 3565589 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
| 2675 | x1, y0, log2_cb_size - 1, cb_depth + 1); | ||
| 2676 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3565589 times.
|
3565589 | if (more_data < 0) |
| 2677 | ✗ | return more_data; | |
| 2678 | } | ||
| 2679 |
4/4✓ Branch 0 taken 3583129 times.
✓ Branch 1 taken 10274 times.
✓ Branch 2 taken 3384434 times.
✓ Branch 3 taken 198695 times.
|
3593403 | if (more_data && y1 < sps->height) { |
| 2680 | 3384434 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
| 2681 | x0, y1, log2_cb_size - 1, cb_depth + 1); | ||
| 2682 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3384434 times.
|
3384434 | if (more_data < 0) |
| 2683 | ✗ | return more_data; | |
| 2684 | } | ||
| 2685 |
4/4✓ Branch 0 taken 3577014 times.
✓ Branch 1 taken 16389 times.
✓ Branch 2 taken 3555323 times.
✓ Branch 3 taken 21691 times.
|
3593403 | if (more_data && x1 < sps->width && |
| 2686 |
2/2✓ Branch 0 taken 3356628 times.
✓ Branch 1 taken 198695 times.
|
3555323 | y1 < sps->height) { |
| 2687 | 3356628 | more_data = hls_coding_quadtree(lc, l, pps, sps, | |
| 2688 | x1, y1, log2_cb_size - 1, cb_depth + 1); | ||
| 2689 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3356627 times.
|
3356628 | if (more_data < 0) |
| 2690 | 1 | return more_data; | |
| 2691 | } | ||
| 2692 | |||
| 2693 |
2/2✓ Branch 0 taken 2109131 times.
✓ Branch 1 taken 1484271 times.
|
3593402 | if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 && |
| 2694 |
2/2✓ Branch 0 taken 1610254 times.
✓ Branch 1 taken 498877 times.
|
2109131 | ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) |
| 2695 | 1610254 | lc->qPy_pred = lc->qp_y; | |
| 2696 | |||
| 2697 |
2/2✓ Branch 0 taken 3557913 times.
✓ Branch 1 taken 35489 times.
|
3593402 | if (more_data) |
| 2698 |
2/2✓ Branch 0 taken 94847 times.
✓ Branch 1 taken 3463066 times.
|
3652760 | return ((x1 + cb_size_split) < sps->width || |
| 2699 |
2/2✓ Branch 0 taken 94846 times.
✓ Branch 1 taken 1 times.
|
94847 | (y1 + cb_size_split) < sps->height); |
| 2700 | else | ||
| 2701 | 35489 | return 0; | |
| 2702 | } else { | ||
| 2703 | 12248005 | ret = hls_coding_unit(lc, s, l, pps, sps, x0, y0, log2_cb_size); | |
| 2704 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 12248004 times.
|
12248005 | if (ret < 0) |
| 2705 | 1 | return ret; | |
| 2706 | 12248004 | if ((!((x0 + cb_size) % | |
| 2707 |
2/2✓ Branch 0 taken 8527579 times.
✓ Branch 1 taken 3720425 times.
|
12248004 | (1 << (sps->log2_ctb_size))) || |
| 2708 |
2/2✓ Branch 0 taken 69669 times.
✓ Branch 1 taken 8457910 times.
|
8527579 | (x0 + cb_size >= sps->width)) && |
| 2709 | 3790094 | (!((y0 + cb_size) % | |
| 2710 |
2/2✓ Branch 0 taken 1945728 times.
✓ Branch 1 taken 1844366 times.
|
3790094 | (1 << (sps->log2_ctb_size))) || |
| 2711 |
2/2✓ Branch 0 taken 96987 times.
✓ Branch 1 taken 1848741 times.
|
1945728 | (y0 + cb_size >= sps->height))) { |
| 2712 | 1941353 | int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc); | |
| 2713 | 1941353 | return !end_of_slice_flag; | |
| 2714 | } else { | ||
| 2715 | 10306651 | return 1; | |
| 2716 | } | ||
| 2717 | } | ||
| 2718 | |||
| 2719 | return 0; | ||
| 2720 | } | ||
| 2721 | |||
| 2722 | 1941354 | static void hls_decode_neighbour(HEVCLocalContext *lc, | |
| 2723 | const HEVCLayerContext *l, | ||
| 2724 | const HEVCPPS *pps, const HEVCSPS *sps, | ||
| 2725 | int x_ctb, int y_ctb, int ctb_addr_ts) | ||
| 2726 | { | ||
| 2727 | 1941354 | const HEVCContext *const s = lc->parent; | |
| 2728 | 1941354 | int ctb_size = 1 << sps->log2_ctb_size; | |
| 2729 | 1941354 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
| 2730 | 1941354 | int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr; | |
| 2731 | |||
| 2732 | 1941354 | l->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr; | |
| 2733 | |||
| 2734 |
2/2✓ Branch 0 taken 168556 times.
✓ Branch 1 taken 1772798 times.
|
1941354 | if (pps->entropy_coding_sync_enabled_flag) { |
| 2735 |
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) |
| 2736 | 7942 | lc->first_qp_group = 1; | |
| 2737 | 168556 | lc->end_of_tiles_x = sps->width; | |
| 2738 |
2/2✓ Branch 0 taken 655296 times.
✓ Branch 1 taken 1117502 times.
|
1772798 | } else if (pps->tiles_enabled_flag) { |
| 2739 |
4/4✓ Branch 0 taken 654565 times.
✓ Branch 1 taken 731 times.
✓ Branch 2 taken 6381 times.
✓ Branch 3 taken 648184 times.
|
655296 | if (ctb_addr_ts && pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) { |
| 2740 | 6381 | int idxX = pps->col_idxX[x_ctb >> sps->log2_ctb_size]; | |
| 2741 | 6381 | lc->end_of_tiles_x = x_ctb + (pps->column_width[idxX] << sps->log2_ctb_size); | |
| 2742 | 6381 | lc->first_qp_group = 1; | |
| 2743 | } | ||
| 2744 | } else { | ||
| 2745 | 1117502 | lc->end_of_tiles_x = sps->width; | |
| 2746 | } | ||
| 2747 | |||
| 2748 | 1941354 | lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height); | |
| 2749 | |||
| 2750 | 1941354 | lc->boundary_flags = 0; | |
| 2751 |
2/2✓ Branch 0 taken 655296 times.
✓ Branch 1 taken 1286058 times.
|
1941354 | if (pps->tiles_enabled_flag) { |
| 2752 |
4/4✓ Branch 0 taken 638081 times.
✓ Branch 1 taken 17215 times.
✓ Branch 2 taken 40841 times.
✓ Branch 3 taken 597240 times.
|
655296 | if (x_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]]) |
| 2753 | 40841 | lc->boundary_flags |= BOUNDARY_LEFT_TILE; | |
| 2754 |
4/4✓ Branch 0 taken 638081 times.
✓ Branch 1 taken 17215 times.
✓ Branch 2 taken 15689 times.
✓ Branch 3 taken 622392 times.
|
655296 | if (x_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - 1]) |
| 2755 | 15689 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
| 2756 |
4/4✓ Branch 0 taken 633209 times.
✓ Branch 1 taken 22087 times.
✓ Branch 2 taken 32582 times.
✓ Branch 3 taken 600627 times.
|
655296 | 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]]) |
| 2757 | 32582 | lc->boundary_flags |= BOUNDARY_UPPER_TILE; | |
| 2758 |
4/4✓ Branch 0 taken 633209 times.
✓ Branch 1 taken 22087 times.
✓ Branch 2 taken 13570 times.
✓ Branch 3 taken 619639 times.
|
655296 | if (y_ctb > 0 && l->tab_slice_address[ctb_addr_rs] != l->tab_slice_address[ctb_addr_rs - sps->ctb_width]) |
| 2759 | 13570 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
| 2760 | } else { | ||
| 2761 |
2/2✓ Branch 0 taken 18267 times.
✓ Branch 1 taken 1267791 times.
|
1286058 | if (ctb_addr_in_slice <= 0) |
| 2762 | 18267 | lc->boundary_flags |= BOUNDARY_LEFT_SLICE; | |
| 2763 |
2/2✓ Branch 0 taken 196252 times.
✓ Branch 1 taken 1089806 times.
|
1286058 | if (ctb_addr_in_slice < sps->ctb_width) |
| 2764 | 196252 | lc->boundary_flags |= BOUNDARY_UPPER_SLICE; | |
| 2765 | } | ||
| 2766 | |||
| 2767 |
6/6✓ Branch 0 taken 1854551 times.
✓ Branch 1 taken 86803 times.
✓ Branch 2 taken 1846462 times.
✓ Branch 3 taken 8089 times.
✓ Branch 4 taken 1806867 times.
✓ Branch 5 taken 39595 times.
|
1941354 | lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE)); |
| 2768 |
6/6✓ Branch 0 taken 1803092 times.
✓ Branch 1 taken 138262 times.
✓ Branch 2 taken 1710266 times.
✓ Branch 3 taken 92826 times.
✓ Branch 4 taken 1690433 times.
✓ Branch 5 taken 19833 times.
|
1941354 | lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE)); |
| 2769 |
6/6✓ Branch 0 taken 1803092 times.
✓ Branch 1 taken 138262 times.
✓ Branch 2 taken 1712813 times.
✓ Branch 3 taken 90279 times.
✓ Branch 4 taken 1642207 times.
✓ Branch 5 taken 70606 times.
|
1941354 | 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]])); |
| 2770 |
8/8✓ Branch 0 taken 1854551 times.
✓ Branch 1 taken 86803 times.
✓ Branch 2 taken 1726639 times.
✓ Branch 3 taken 127912 times.
✓ Branch 4 taken 1638601 times.
✓ Branch 5 taken 88038 times.
✓ Branch 6 taken 1584903 times.
✓ Branch 7 taken 53698 times.
|
1941354 | 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]])); |
| 2771 | 1941354 | } | |
| 2772 | |||
| 2773 | 28346 | static int hls_decode_entry(HEVCContext *s, GetBitContext *gb) | |
| 2774 | { | ||
| 2775 | 28346 | HEVCLocalContext *const lc = &s->local_ctx[0]; | |
| 2776 | 28346 | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
| 2777 | 28346 | const HEVCPPS *const pps = s->pps; | |
| 2778 | 28346 | const HEVCSPS *const sps = pps->sps; | |
| 2779 | 28346 | const uint8_t *slice_data = gb->buffer + s->sh.data_offset; | |
| 2780 | 28346 | const size_t slice_size = get_bits_bytesize(gb, 1) - s->sh.data_offset; | |
| 2781 | 28346 | int ctb_size = 1 << sps->log2_ctb_size; | |
| 2782 | 28346 | int more_data = 1; | |
| 2783 | 28346 | int x_ctb = 0; | |
| 2784 | 28346 | int y_ctb = 0; | |
| 2785 | 28346 | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
| 2786 | int ret; | ||
| 2787 | |||
| 2788 |
3/4✓ Branch 0 taken 1941354 times.
✓ Branch 1 taken 28345 times.
✓ Branch 2 taken 1941354 times.
✗ Branch 3 not taken.
|
1969699 | while (more_data && ctb_addr_ts < sps->ctb_size) { |
| 2789 | 1941354 | int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
| 2790 | |||
| 2791 | 1941354 | x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size; | |
| 2792 | 1941354 | y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size; | |
| 2793 | 1941354 | hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
| 2794 | |||
| 2795 | 1941354 | ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 0); | |
| 2796 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1941354 times.
|
1941354 | if (ret < 0) { |
| 2797 | ✗ | l->tab_slice_address[ctb_addr_rs] = -1; | |
| 2798 | ✗ | return ret; | |
| 2799 | } | ||
| 2800 | |||
| 2801 | 1941354 | hls_sao_param(lc, l, pps, sps, | |
| 2802 | 1941354 | x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); | |
| 2803 | |||
| 2804 | 1941354 | l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
| 2805 | 1941354 | l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
| 2806 | 1941354 | l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
| 2807 | |||
| 2808 | 1941354 | more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); | |
| 2809 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1941353 times.
|
1941354 | if (more_data < 0) { |
| 2810 | 1 | l->tab_slice_address[ctb_addr_rs] = -1; | |
| 2811 | 1 | return more_data; | |
| 2812 | } | ||
| 2813 | |||
| 2814 | |||
| 2815 | 1941353 | ctb_addr_ts++; | |
| 2816 | 1941353 | ff_hevc_save_states(lc, pps, ctb_addr_ts); | |
| 2817 | 1941353 | ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
| 2818 | } | ||
| 2819 | |||
| 2820 |
2/2✓ Branch 0 taken 14776 times.
✓ Branch 1 taken 13569 times.
|
28345 | if (x_ctb + ctb_size >= sps->width && |
| 2821 |
2/2✓ Branch 0 taken 10349 times.
✓ Branch 1 taken 4427 times.
|
14776 | y_ctb + ctb_size >= sps->height) |
| 2822 | 10349 | ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
| 2823 | |||
| 2824 | 28345 | return ctb_addr_ts; | |
| 2825 | } | ||
| 2826 | |||
| 2827 | ✗ | static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, | |
| 2828 | int job, int thread) | ||
| 2829 | { | ||
| 2830 | ✗ | HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[thread]; | |
| 2831 | ✗ | const HEVCContext *const s = lc->parent; | |
| 2832 | ✗ | const HEVCLayerContext *const l = &s->layers[s->cur_layer]; | |
| 2833 | ✗ | const HEVCPPS *const pps = s->pps; | |
| 2834 | ✗ | const HEVCSPS *const sps = pps->sps; | |
| 2835 | ✗ | int ctb_size = 1 << sps->log2_ctb_size; | |
| 2836 | ✗ | int more_data = 1; | |
| 2837 | ✗ | int ctb_row = job; | |
| 2838 | ✗ | int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size); | |
| 2839 | ✗ | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs]; | |
| 2840 | |||
| 2841 | ✗ | const uint8_t *data = s->data + s->sh.offset[ctb_row]; | |
| 2842 | ✗ | const size_t data_size = s->sh.size[ctb_row]; | |
| 2843 | |||
| 2844 | ✗ | int progress = 0; | |
| 2845 | |||
| 2846 | int ret; | ||
| 2847 | |||
| 2848 | ✗ | if (ctb_row) | |
| 2849 | ✗ | ff_init_cabac_decoder(&lc->cc, data, data_size); | |
| 2850 | |||
| 2851 | ✗ | while(more_data && ctb_addr_ts < sps->ctb_size) { | |
| 2852 | ✗ | int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size; | |
| 2853 | ✗ | int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size; | |
| 2854 | |||
| 2855 | ✗ | hls_decode_neighbour(lc, l, pps, sps, x_ctb, y_ctb, ctb_addr_ts); | |
| 2856 | |||
| 2857 | ✗ | if (ctb_row) | |
| 2858 | ✗ | ff_thread_progress_await(&s->wpp_progress[ctb_row - 1], | |
| 2859 | progress + SHIFT_CTB_WPP + 1); | ||
| 2860 | |||
| 2861 | /* atomic_load's prototype requires a pointer to non-const atomic variable | ||
| 2862 | * (due to implementations via mutexes, where reads involve writes). | ||
| 2863 | * Of course, casting const away here is nevertheless safe. */ | ||
| 2864 | ✗ | if (atomic_load((atomic_int*)&s->wpp_err)) { | |
| 2865 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2866 | ✗ | return 0; | |
| 2867 | } | ||
| 2868 | |||
| 2869 | ✗ | ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1); | |
| 2870 | ✗ | if (ret < 0) | |
| 2871 | ✗ | goto error; | |
| 2872 | ✗ | hls_sao_param(lc, l, pps, sps, | |
| 2873 | ✗ | x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); | |
| 2874 | |||
| 2875 | ✗ | l->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; | |
| 2876 | ✗ | l->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; | |
| 2877 | ✗ | l->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; | |
| 2878 | |||
| 2879 | ✗ | more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); | |
| 2880 | |||
| 2881 | ✗ | if (more_data < 0) { | |
| 2882 | ✗ | ret = more_data; | |
| 2883 | ✗ | goto error; | |
| 2884 | } | ||
| 2885 | |||
| 2886 | ✗ | ctb_addr_ts++; | |
| 2887 | |||
| 2888 | ✗ | ff_hevc_save_states(lc, pps, ctb_addr_ts); | |
| 2889 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], ++progress); | |
| 2890 | ✗ | ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
| 2891 | |||
| 2892 | ✗ | if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) { | |
| 2893 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
| 2894 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
| 2895 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2896 | ✗ | return 0; | |
| 2897 | } | ||
| 2898 | |||
| 2899 | ✗ | if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) { | |
| 2900 | ✗ | ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); | |
| 2901 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2902 | ✗ | return ctb_addr_ts; | |
| 2903 | } | ||
| 2904 | ✗ | ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts]; | |
| 2905 | ✗ | x_ctb+=ctb_size; | |
| 2906 | |||
| 2907 | ✗ | if(x_ctb >= sps->width) { | |
| 2908 | ✗ | break; | |
| 2909 | } | ||
| 2910 | } | ||
| 2911 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2912 | |||
| 2913 | ✗ | return 0; | |
| 2914 | ✗ | error: | |
| 2915 | ✗ | l->tab_slice_address[ctb_addr_rs] = -1; | |
| 2916 | /* Casting const away here is safe, because it is an atomic operation. */ | ||
| 2917 | ✗ | atomic_store((atomic_int*)&s->wpp_err, 1); | |
| 2918 | ✗ | ff_thread_progress_report(&s->wpp_progress[ctb_row], INT_MAX); | |
| 2919 | ✗ | return ret; | |
| 2920 | } | ||
| 2921 | |||
| 2922 | ✗ | static int wpp_progress_init(HEVCContext *s, unsigned count) | |
| 2923 | { | ||
| 2924 | ✗ | if (s->nb_wpp_progress < count) { | |
| 2925 | ✗ | void *tmp = av_realloc_array(s->wpp_progress, count, | |
| 2926 | sizeof(*s->wpp_progress)); | ||
| 2927 | ✗ | if (!tmp) | |
| 2928 | ✗ | return AVERROR(ENOMEM); | |
| 2929 | |||
| 2930 | ✗ | s->wpp_progress = tmp; | |
| 2931 | ✗ | memset(s->wpp_progress + s->nb_wpp_progress, 0, | |
| 2932 | ✗ | (count - s->nb_wpp_progress) * sizeof(*s->wpp_progress)); | |
| 2933 | |||
| 2934 | ✗ | for (int i = s->nb_wpp_progress; i < count; i++) { | |
| 2935 | ✗ | int ret = ff_thread_progress_init(&s->wpp_progress[i], 1); | |
| 2936 | ✗ | if (ret < 0) | |
| 2937 | ✗ | return ret; | |
| 2938 | ✗ | s->nb_wpp_progress = i + 1; | |
| 2939 | } | ||
| 2940 | } | ||
| 2941 | |||
| 2942 | ✗ | for (int i = 0; i < count; i++) | |
| 2943 | ✗ | ff_thread_progress_reset(&s->wpp_progress[i]); | |
| 2944 | |||
| 2945 | ✗ | return 0; | |
| 2946 | } | ||
| 2947 | |||
| 2948 | ✗ | static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) | |
| 2949 | { | ||
| 2950 | ✗ | const HEVCPPS *const pps = s->pps; | |
| 2951 | ✗ | const HEVCSPS *const sps = pps->sps; | |
| 2952 | ✗ | const uint8_t *data = nal->data; | |
| 2953 | ✗ | int length = nal->size; | |
| 2954 | int *ret; | ||
| 2955 | int64_t offset; | ||
| 2956 | ✗ | int64_t startheader, cmpt = 0; | |
| 2957 | ✗ | int j, res = 0; | |
| 2958 | |||
| 2959 | ✗ | 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) { | |
| 2960 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n", | |
| 2961 | s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets, | ||
| 2962 | ✗ | sps->ctb_width, sps->ctb_height | |
| 2963 | ); | ||
| 2964 | ✗ | return AVERROR_INVALIDDATA; | |
| 2965 | } | ||
| 2966 | |||
| 2967 | ✗ | if (s->avctx->thread_count > s->nb_local_ctx) { | |
| 2968 | ✗ | HEVCLocalContext *tmp = av_malloc_array(s->avctx->thread_count, sizeof(*s->local_ctx)); | |
| 2969 | |||
| 2970 | ✗ | if (!tmp) | |
| 2971 | ✗ | return AVERROR(ENOMEM); | |
| 2972 | |||
| 2973 | ✗ | memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx); | |
| 2974 | ✗ | av_free(s->local_ctx); | |
| 2975 | ✗ | s->local_ctx = tmp; | |
| 2976 | |||
| 2977 | ✗ | for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) { | |
| 2978 | ✗ | tmp = &s->local_ctx[i]; | |
| 2979 | |||
| 2980 | ✗ | memset(tmp, 0, sizeof(*tmp)); | |
| 2981 | |||
| 2982 | ✗ | tmp->logctx = s->avctx; | |
| 2983 | ✗ | tmp->parent = s; | |
| 2984 | ✗ | tmp->common_cabac_state = &s->cabac; | |
| 2985 | } | ||
| 2986 | |||
| 2987 | ✗ | s->nb_local_ctx = s->avctx->thread_count; | |
| 2988 | } | ||
| 2989 | |||
| 2990 | ✗ | offset = s->sh.data_offset; | |
| 2991 | |||
| 2992 | ✗ | for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) { | |
| 2993 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
| 2994 | ✗ | startheader--; | |
| 2995 | ✗ | cmpt++; | |
| 2996 | } | ||
| 2997 | } | ||
| 2998 | |||
| 2999 | ✗ | for (int i = 1; i < s->sh.num_entry_point_offsets; i++) { | |
| 3000 | ✗ | offset += (s->sh.entry_point_offset[i - 1] - cmpt); | |
| 3001 | ✗ | for (j = 0, cmpt = 0, startheader = offset | |
| 3002 | ✗ | + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) { | |
| 3003 | ✗ | if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { | |
| 3004 | ✗ | startheader--; | |
| 3005 | ✗ | cmpt++; | |
| 3006 | } | ||
| 3007 | } | ||
| 3008 | ✗ | s->sh.size[i] = s->sh.entry_point_offset[i] - cmpt; | |
| 3009 | ✗ | s->sh.offset[i] = offset; | |
| 3010 | |||
| 3011 | } | ||
| 3012 | |||
| 3013 | ✗ | offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt; | |
| 3014 | ✗ | if (length < offset) { | |
| 3015 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n"); | |
| 3016 | ✗ | return AVERROR_INVALIDDATA; | |
| 3017 | } | ||
| 3018 | ✗ | s->sh.size [s->sh.num_entry_point_offsets] = length - offset; | |
| 3019 | ✗ | s->sh.offset[s->sh.num_entry_point_offsets] = offset; | |
| 3020 | |||
| 3021 | ✗ | s->sh.offset[0] = s->sh.data_offset; | |
| 3022 | ✗ | s->sh.size[0] = s->sh.offset[1] - s->sh.offset[0]; | |
| 3023 | |||
| 3024 | ✗ | s->data = data; | |
| 3025 | |||
| 3026 | ✗ | for (unsigned i = 1; i < s->nb_local_ctx; i++) { | |
| 3027 | ✗ | s->local_ctx[i].first_qp_group = 1; | |
| 3028 | ✗ | s->local_ctx[i].qp_y = s->local_ctx[0].qp_y; | |
| 3029 | } | ||
| 3030 | |||
| 3031 | ✗ | atomic_store(&s->wpp_err, 0); | |
| 3032 | ✗ | res = wpp_progress_init(s, s->sh.num_entry_point_offsets + 1); | |
| 3033 | ✗ | if (res < 0) | |
| 3034 | ✗ | return res; | |
| 3035 | |||
| 3036 | ✗ | ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret)); | |
| 3037 | ✗ | if (!ret) | |
| 3038 | ✗ | return AVERROR(ENOMEM); | |
| 3039 | |||
| 3040 | ✗ | if (pps->entropy_coding_sync_enabled_flag) | |
| 3041 | ✗ | s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->local_ctx, ret, s->sh.num_entry_point_offsets + 1); | |
| 3042 | |||
| 3043 | ✗ | for (int i = 0; i <= s->sh.num_entry_point_offsets; i++) | |
| 3044 | ✗ | res += ret[i]; | |
| 3045 | |||
| 3046 | ✗ | av_free(ret); | |
| 3047 | ✗ | return res; | |
| 3048 | } | ||
| 3049 | |||
| 3050 | 28346 | static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l, | |
| 3051 | const H2645NAL *nal, GetBitContext *gb) | ||
| 3052 | { | ||
| 3053 | 28346 | const HEVCPPS *pps = s->pps; | |
| 3054 | int ret; | ||
| 3055 | |||
| 3056 |
2/2✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10350 times.
|
28346 | if (!s->sh.first_slice_in_pic_flag) |
| 3057 | 17996 | s->slice_idx += !s->sh.dependent_slice_segment_flag; | |
| 3058 | |||
| 3059 |
4/4✓ Branch 0 taken 20552 times.
✓ Branch 1 taken 7794 times.
✓ Branch 2 taken 19571 times.
✓ Branch 3 taken 981 times.
|
28346 | if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) { |
| 3060 | 19571 | ret = ff_hevc_slice_rpl(s); | |
| 3061 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19571 times.
|
19571 | if (ret < 0) { |
| 3062 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
| 3063 | "Error constructing the reference lists for the current slice.\n"); | ||
| 3064 | ✗ | return ret; | |
| 3065 | } | ||
| 3066 | } | ||
| 3067 | |||
| 3068 | 28346 | s->slice_initialized = 1; | |
| 3069 | |||
| 3070 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28346 times.
|
28346 | if (s->avctx->hwaccel) |
| 3071 | ✗ | return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size); | |
| 3072 | |||
| 3073 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28346 times.
|
28346 | if (s->avctx->profile == AV_PROFILE_HEVC_SCC) { |
| 3074 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3075 | "SCC profile is not yet implemented in hevc native decoder.\n"); | ||
| 3076 | ✗ | return AVERROR_PATCHWELCOME; | |
| 3077 | } | ||
| 3078 | |||
| 3079 |
2/2✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 20552 times.
|
28346 | if (s->sh.dependent_slice_segment_flag) { |
| 3080 | 7794 | int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; | |
| 3081 | 7794 | int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1]; | |
| 3082 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7794 times.
|
7794 | if (l->tab_slice_address[prev_rs] != s->sh.slice_addr) { |
| 3083 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n"); | |
| 3084 | ✗ | return AVERROR_INVALIDDATA; | |
| 3085 | } | ||
| 3086 | } | ||
| 3087 | |||
| 3088 | 28346 | s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag; | |
| 3089 | |||
| 3090 |
2/2✓ Branch 0 taken 22847 times.
✓ Branch 1 taken 5499 times.
|
28346 | if (!pps->cu_qp_delta_enabled_flag) |
| 3091 | 22847 | s->local_ctx[0].qp_y = s->sh.slice_qp; | |
| 3092 | |||
| 3093 | 28346 | s->local_ctx[0].tu.cu_qp_offset_cb = 0; | |
| 3094 | 28346 | s->local_ctx[0].tu.cu_qp_offset_cr = 0; | |
| 3095 | |||
| 3096 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28346 times.
|
28346 | if (s->avctx->active_thread_type == FF_THREAD_SLICE && |
| 3097 | ✗ | s->sh.num_entry_point_offsets > 0 && | |
| 3098 | ✗ | pps->num_tile_rows == 1 && pps->num_tile_columns == 1) | |
| 3099 | ✗ | return hls_slice_data_wpp(s, nal); | |
| 3100 | |||
| 3101 | 28346 | return hls_decode_entry(s, gb); | |
| 3102 | } | ||
| 3103 | |||
| 3104 | 10350 | static int set_side_data(HEVCContext *s) | |
| 3105 | { | ||
| 3106 | 10350 | const HEVCSPS *sps = s->cur_frame->pps->sps; | |
| 3107 | 10350 | AVFrame *out = s->cur_frame->f; | |
| 3108 | int ret; | ||
| 3109 | |||
| 3110 | // Decrement the mastering display and content light level flag when IRAP | ||
| 3111 | // frame has no_rasl_output_flag=1 so the side data persists for the entire | ||
| 3112 | // coded video sequence. | ||
| 3113 |
5/6✓ Branch 0 taken 544 times.
✓ Branch 1 taken 9806 times.
✓ Branch 2 taken 544 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 263 times.
✓ Branch 5 taken 281 times.
|
10350 | if (IS_IRAP(s) && s->no_rasl_output_flag) { |
| 3114 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 247 times.
|
263 | if (s->sei.common.mastering_display.present > 0) |
| 3115 | 16 | s->sei.common.mastering_display.present--; | |
| 3116 | |||
| 3117 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 259 times.
|
263 | if (s->sei.common.content_light.present > 0) |
| 3118 | 4 | s->sei.common.content_light.present--; | |
| 3119 | } | ||
| 3120 | |||
| 3121 | 10350 | ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx, | |
| 3122 | &sps->vui.common, | ||
| 3123 | 10350 | sps->bit_depth, sps->bit_depth_chroma, | |
| 3124 | 10350 | s->cur_frame->poc /* no poc_offset in HEVC */); | |
| 3125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (ret < 0) |
| 3126 | ✗ | return ret; | |
| 3127 | |||
| 3128 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10330 times.
|
10350 | if (s->sei.timecode.present) { |
| 3129 | uint32_t *tc_sd; | ||
| 3130 | char tcbuf[AV_TIMECODE_STR_SIZE]; | ||
| 3131 | AVFrameSideData *tcside; | ||
| 3132 | 20 | ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE, | |
| 3133 | sizeof(uint32_t) * 4, &tcside); | ||
| 3134 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (ret < 0) |
| 3135 | ✗ | return ret; | |
| 3136 | |||
| 3137 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (tcside) { |
| 3138 | 20 | tc_sd = (uint32_t*)tcside->data; | |
| 3139 | 20 | tc_sd[0] = s->sei.timecode.num_clock_ts; | |
| 3140 | |||
| 3141 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | for (int i = 0; i < tc_sd[0]; i++) { |
| 3142 | 20 | int drop = s->sei.timecode.cnt_dropped_flag[i]; | |
| 3143 | 20 | int hh = s->sei.timecode.hours_value[i]; | |
| 3144 | 20 | int mm = s->sei.timecode.minutes_value[i]; | |
| 3145 | 20 | int ss = s->sei.timecode.seconds_value[i]; | |
| 3146 | 20 | int ff = s->sei.timecode.n_frames[i]; | |
| 3147 | |||
| 3148 | 20 | tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff); | |
| 3149 | 20 | av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0); | |
| 3150 | 20 | av_dict_set(&out->metadata, "timecode", tcbuf, 0); | |
| 3151 | } | ||
| 3152 | } | ||
| 3153 | |||
| 3154 | 20 | s->sei.timecode.num_clock_ts = 0; | |
| 3155 | } | ||
| 3156 | |||
| 3157 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10347 times.
|
10350 | if (s->sei.common.itut_t35.hdr_plus) { |
| 3158 | 3 | AVBufferRef *info_ref = av_buffer_ref(s->sei.common.itut_t35.hdr_plus); | |
| 3159 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!info_ref) |
| 3160 | ✗ | return AVERROR(ENOMEM); | |
| 3161 | |||
| 3162 | 3 | ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref); | |
| 3163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (ret < 0) |
| 3164 | ✗ | return ret; | |
| 3165 | } | ||
| 3166 | |||
| 3167 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (s->sei.common.itut_t35.hdr_smpte2094_app5) { |
| 3168 | ✗ | AVBufferRef *info_ref = av_buffer_ref(s->sei.common.itut_t35.hdr_smpte2094_app5); | |
| 3169 | ✗ | if (!info_ref) | |
| 3170 | ✗ | return AVERROR(ENOMEM); | |
| 3171 | |||
| 3172 | ✗ | ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5, &info_ref); | |
| 3173 | ✗ | if (ret < 0) | |
| 3174 | ✗ | return ret; | |
| 3175 | } | ||
| 3176 | |||
| 3177 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10348 times.
|
10350 | if (s->rpu_buf) { |
| 3178 | 2 | AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf); | |
| 3179 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!rpu) |
| 3180 | ✗ | return AVERROR(ENOMEM); | |
| 3181 | |||
| 3182 | 2 | s->rpu_buf = NULL; | |
| 3183 | } | ||
| 3184 | |||
| 3185 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10350 times.
|
10350 | if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0) |
| 3186 | ✗ | return ret; | |
| 3187 | |||
| 3188 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10349 times.
|
10350 | if (s->sei.common.itut_t35.hdr_vivid) { |
| 3189 |
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, |
| 3190 | AV_FRAME_DATA_DYNAMIC_HDR_VIVID, | ||
| 3191 | &s->sei.common.itut_t35.hdr_vivid, | ||
| 3192 | AV_FRAME_SIDE_DATA_FLAG_NEW_REF)) | ||
| 3193 | ✗ | return AVERROR(ENOMEM); | |
| 3194 | } | ||
| 3195 | |||
| 3196 | 10350 | return 0; | |
| 3197 | } | ||
| 3198 | |||
| 3199 | 9960 | static int find_finish_setup_nal(const HEVCContext *s) | |
| 3200 | { | ||
| 3201 | 9960 | int nal_idx = 0; | |
| 3202 | |||
| 3203 |
2/2✓ Branch 0 taken 38102 times.
✓ Branch 1 taken 9960 times.
|
48062 | for (int i = nal_idx; i < s->pkt.nb_nals; i++) { |
| 3204 | 38102 | const H2645NAL *nal = &s->pkt.nals[i]; | |
| 3205 | 38102 | const int layer_id = nal->nuh_layer_id; | |
| 3206 | 38102 | GetBitContext gb = nal->gb; | |
| 3207 | |||
| 3208 |
2/4✓ Branch 0 taken 38102 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38102 times.
✗ Branch 3 not taken.
|
38102 | if (layer_id > HEVC_MAX_NUH_LAYER_ID || s->vps->layer_idx[layer_id] < 0 || |
| 3209 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38102 times.
|
38102 | !(s->layers_active_decode & (1 << s->vps->layer_idx[layer_id]))) |
| 3210 | 17996 | continue; | |
| 3211 | |||
| 3212 |
3/3✓ Branch 0 taken 28347 times.
✓ Branch 1 taken 1572 times.
✓ Branch 2 taken 8183 times.
|
38102 | switch (nal->type) { |
| 3213 | 28347 | case HEVC_NAL_TRAIL_R: | |
| 3214 | case HEVC_NAL_TRAIL_N: | ||
| 3215 | case HEVC_NAL_TSA_N: | ||
| 3216 | case HEVC_NAL_TSA_R: | ||
| 3217 | case HEVC_NAL_STSA_N: | ||
| 3218 | case HEVC_NAL_STSA_R: | ||
| 3219 | case HEVC_NAL_BLA_W_LP: | ||
| 3220 | case HEVC_NAL_BLA_W_RADL: | ||
| 3221 | case HEVC_NAL_BLA_N_LP: | ||
| 3222 | case HEVC_NAL_IDR_W_RADL: | ||
| 3223 | case HEVC_NAL_IDR_N_LP: | ||
| 3224 | case HEVC_NAL_CRA_NUT: | ||
| 3225 | case HEVC_NAL_RADL_N: | ||
| 3226 | case HEVC_NAL_RADL_R: | ||
| 3227 | case HEVC_NAL_RASL_N: | ||
| 3228 | case HEVC_NAL_RASL_R: | ||
| 3229 |
2/2✓ Branch 1 taken 17996 times.
✓ Branch 2 taken 10351 times.
|
28347 | if (!get_bits1(&gb)) // first_slice_segment_in_pic_flag |
| 3230 | 17996 | continue; | |
| 3231 | av_fallthrough; | ||
| 3232 | case HEVC_NAL_VPS: | ||
| 3233 | case HEVC_NAL_SPS: | ||
| 3234 | case HEVC_NAL_PPS: | ||
| 3235 | 11923 | nal_idx = i; | |
| 3236 | 11923 | break; | |
| 3237 | } | ||
| 3238 | } | ||
| 3239 | |||
| 3240 | 9960 | return nal_idx; | |
| 3241 | } | ||
| 3242 | |||
| 3243 | 10350 | static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, | |
| 3244 | unsigned nal_idx) | ||
| 3245 | { | ||
| 3246 | 10350 | const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id]; | |
| 3247 | 10350 | const HEVCSPS *const sps = pps->sps; | |
| 3248 | 10350 | int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) * | |
| 3249 | 10350 | ((sps->height >> sps->log2_min_cb_size) + 1); | |
| 3250 |
2/2✓ Branch 0 taken 9960 times.
✓ Branch 1 taken 390 times.
|
20310 | int new_sequence = (l == &s->layers[0]) && |
| 3251 |
12/12✓ Branch 0 taken 9755 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 9727 times.
✓ Branch 3 taken 28 times.
✓ Branch 4 taken 9725 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 9718 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 9717 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 15 times.
✓ Branch 11 taken 9702 times.
|
9960 | (IS_IDR(s) || IS_BLA(s) || s->last_eos); |
| 3252 | 10350 | int prev_layers_active_decode = s->layers_active_decode; | |
| 3253 | 10350 | int prev_layers_active_output = s->layers_active_output; | |
| 3254 | int ret; | ||
| 3255 | |||
| 3256 |
3/4✓ Branch 0 taken 227 times.
✓ Branch 1 taken 10123 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 227 times.
|
10350 | if (sps->vps != s->vps && l != &s->layers[0]) { |
| 3257 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n"); | |
| 3258 | ✗ | set_sps(s, l, NULL); | |
| 3259 | ✗ | return AVERROR_INVALIDDATA; | |
| 3260 | } | ||
| 3261 | |||
| 3262 | 10350 | av_refstruct_replace(&s->pps, pps); | |
| 3263 |
2/2✓ Branch 0 taken 243 times.
✓ Branch 1 taken 10107 times.
|
10350 | if (l->sps != sps) { |
| 3264 | 243 | const HEVCSPS *sps_base = s->layers[0].sps; | |
| 3265 | 243 | enum AVPixelFormat pix_fmt = sps->pix_fmt; | |
| 3266 | |||
| 3267 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 233 times.
|
243 | if (l != &s->layers[0]) { |
| 3268 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (!sps_base) { |
| 3269 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3270 | "Access unit starts with a non-base layer frame\n"); | ||
| 3271 | ✗ | return AVERROR_INVALIDDATA; | |
| 3272 | } | ||
| 3273 | |||
| 3274 | // Files produced by Vision Pro lack VPS extension VUI, | ||
| 3275 | // so the secondary layer has no range information. | ||
| 3276 | // This check avoids failing in such a case. | ||
| 3277 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (sps_base->pix_fmt == AV_PIX_FMT_YUVJ420P && |
| 3278 | ✗ | sps->pix_fmt == AV_PIX_FMT_YUV420P && | |
| 3279 | ✗ | !sps->vui.common.video_signal_type_present_flag) | |
| 3280 | ✗ | pix_fmt = sps_base->pix_fmt; | |
| 3281 | |||
| 3282 | // Ignore range mismatch between base layer and alpha layer | ||
| 3283 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
|
10 | if (ff_hevc_is_alpha_video(s) && |
| 3284 |
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 && |
| 3285 | pix_fmt == AV_PIX_FMT_YUVJ420P) | ||
| 3286 | 1 | pix_fmt = sps_base->pix_fmt; | |
| 3287 | |||
| 3288 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | if (pix_fmt != sps_base->pix_fmt || |
| 3289 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | sps->width != sps_base->width || |
| 3290 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | sps->height != sps_base->height) { |
| 3291 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3292 | "Base/non-base layer SPS have unsupported parameter combination\n"); | ||
| 3293 | ✗ | return AVERROR(ENOSYS); | |
| 3294 | } | ||
| 3295 | } | ||
| 3296 | |||
| 3297 | 243 | ff_hevc_clear_refs(l); | |
| 3298 | |||
| 3299 | 243 | ret = set_sps(s, l, sps); | |
| 3300 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 243 times.
|
243 | if (ret < 0) |
| 3301 | ✗ | return ret; | |
| 3302 | |||
| 3303 |
2/2✓ Branch 0 taken 233 times.
✓ Branch 1 taken 10 times.
|
243 | if (l == &s->layers[0]) { |
| 3304 | 233 | export_stream_params(s, sps); | |
| 3305 | |||
| 3306 | 233 | ret = get_format(s, sps); | |
| 3307 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 233 times.
|
233 | if (ret < 0) { |
| 3308 | ✗ | set_sps(s, l, NULL); | |
| 3309 | ✗ | return ret; | |
| 3310 | } | ||
| 3311 | |||
| 3312 | 233 | new_sequence = 1; | |
| 3313 | } | ||
| 3314 | } | ||
| 3315 | |||
| 3316 | 10350 | memset(l->horizontal_bs, 0, l->bs_width * l->bs_height); | |
| 3317 | 10350 | memset(l->vertical_bs, 0, l->bs_width * l->bs_height); | |
| 3318 | 10350 | memset(l->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height); | |
| 3319 | 10350 | memset(l->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1)); | |
| 3320 | 10350 | memset(l->tab_slice_address, -1, pic_size_in_ctb * sizeof(*l->tab_slice_address)); | |
| 3321 | |||
| 3322 |
4/4✓ Branch 0 taken 10136 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 10103 times.
|
10350 | if (IS_IDR(s)) |
| 3323 | 247 | ff_hevc_clear_refs(l); | |
| 3324 | |||
| 3325 | 10350 | s->slice_idx = 0; | |
| 3326 | 10350 | s->first_nal_type = s->nal_unit_type; | |
| 3327 | 10350 | s->poc = s->sh.poc; | |
| 3328 | |||
| 3329 |
3/4✓ Branch 0 taken 544 times.
✓ Branch 1 taken 9806 times.
✓ Branch 2 taken 544 times.
✗ Branch 3 not taken.
|
10350 | if (IS_IRAP(s)) { |
| 3330 |
10/10✓ Branch 0 taken 330 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 297 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 295 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 288 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 287 times.
✓ Branch 9 taken 1 times.
|
831 | s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || |
| 3331 |
3/4✓ Branch 0 taken 287 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 281 times.
|
287 | (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos); |
| 3332 | 544 | s->recovery_poc = HEVC_RECOVERY_END; | |
| 3333 | } | ||
| 3334 | |||
| 3335 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10330 times.
|
10350 | if (s->recovery_poc != HEVC_RECOVERY_END && |
| 3336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | s->sei.recovery_point.has_recovery_poc) { |
| 3337 | ✗ | if (s->recovery_poc == HEVC_RECOVERY_UNSPECIFIED) | |
| 3338 | ✗ | s->recovery_poc = s->poc + s->sei.recovery_point.recovery_poc_cnt; | |
| 3339 | ✗ | else if (s->poc >= s->recovery_poc) | |
| 3340 | ✗ | s->recovery_poc = HEVC_RECOVERY_END; | |
| 3341 | } | ||
| 3342 | |||
| 3343 | /* 8.3.1 */ | ||
| 3344 |
2/2✓ Branch 0 taken 10008 times.
✓ Branch 1 taken 342 times.
|
10350 | if (s->temporal_id == 0 && |
| 3345 |
2/2✓ Branch 0 taken 7271 times.
✓ Branch 1 taken 2737 times.
|
10008 | s->nal_unit_type != HEVC_NAL_TRAIL_N && |
| 3346 |
1/2✓ Branch 0 taken 7271 times.
✗ Branch 1 not taken.
|
7271 | s->nal_unit_type != HEVC_NAL_TSA_N && |
| 3347 |
1/2✓ Branch 0 taken 7271 times.
✗ Branch 1 not taken.
|
7271 | s->nal_unit_type != HEVC_NAL_STSA_N && |
| 3348 |
2/2✓ Branch 0 taken 7245 times.
✓ Branch 1 taken 26 times.
|
7271 | s->nal_unit_type != HEVC_NAL_RADL_N && |
| 3349 |
2/2✓ Branch 0 taken 7223 times.
✓ Branch 1 taken 22 times.
|
7245 | s->nal_unit_type != HEVC_NAL_RADL_R && |
| 3350 |
2/2✓ Branch 0 taken 6853 times.
✓ Branch 1 taken 370 times.
|
7223 | s->nal_unit_type != HEVC_NAL_RASL_N && |
| 3351 |
2/2✓ Branch 0 taken 6379 times.
✓ Branch 1 taken 474 times.
|
6853 | s->nal_unit_type != HEVC_NAL_RASL_R) |
| 3352 | 6379 | s->poc_tid0 = s->poc; | |
| 3353 | |||
| 3354 |
2/2✓ Branch 0 taken 731 times.
✓ Branch 1 taken 9619 times.
|
10350 | if (pps->tiles_enabled_flag) |
| 3355 | 731 | s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size; | |
| 3356 | |||
| 3357 |
2/2✓ Branch 0 taken 258 times.
✓ Branch 1 taken 10092 times.
|
10350 | if (new_sequence) { |
| 3358 | 258 | ret = ff_hevc_output_frames(s, prev_layers_active_decode, prev_layers_active_output, | |
| 3359 | 258 | 0, 0, s->sh.no_output_of_prior_pics_flag); | |
| 3360 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 258 times.
|
258 | if (ret < 0) |
| 3361 | ✗ | return ret; | |
| 3362 | } | ||
| 3363 | |||
| 3364 | 10350 | ret = export_stream_params_from_sei(s); | |
| 3365 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (ret < 0) |
| 3366 | ✗ | return ret; | |
| 3367 | |||
| 3368 | 10350 | ret = ff_hevc_set_new_ref(s, l, s->poc); | |
| 3369 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (ret < 0) |
| 3370 | ✗ | goto fail; | |
| 3371 | |||
| 3372 | 10350 | ret = ff_hevc_frame_rps(s, l); | |
| 3373 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (ret < 0) { |
| 3374 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n"); | |
| 3375 | ✗ | goto fail; | |
| 3376 | } | ||
| 3377 | |||
| 3378 |
3/4✓ Branch 0 taken 544 times.
✓ Branch 1 taken 9806 times.
✓ Branch 2 taken 544 times.
✗ Branch 3 not taken.
|
10350 | if (IS_IRAP(s)) |
| 3379 | 544 | s->cur_frame->f->flags |= AV_FRAME_FLAG_KEY; | |
| 3380 | else | ||
| 3381 | 9806 | s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY; | |
| 3382 | |||
| 3383 | 20700 | s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics && | |
| 3384 | ✗ | s->sei.common.film_grain_characteristics->present) || | |
| 3385 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | s->sei.common.itut_t35.aom_film_grain.enable) && |
| 3386 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
20700 | !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && |
| 3387 | ✗ | !s->avctx->hwaccel; | |
| 3388 | |||
| 3389 | 10350 | ret = set_side_data(s); | |
| 3390 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (ret < 0) |
| 3391 | ✗ | goto fail; | |
| 3392 | |||
| 3393 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (s->cur_frame->needs_fg && |
| 3394 | ✗ | (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present && | |
| 3395 | ✗ | !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id, | |
| 3396 | ✗ | s->cur_frame->f->format) || | |
| 3397 | ✗ | !av_film_grain_params_select(s->cur_frame->f))) { | |
| 3398 | ✗ | av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown, | |
| 3399 | "Unsupported film grain parameters. Ignoring film grain.\n"); | ||
| 3400 | ✗ | s->cur_frame->needs_fg = 0; | |
| 3401 | } | ||
| 3402 | |||
| 3403 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (s->cur_frame->needs_fg) { |
| 3404 | ✗ | s->cur_frame->frame_grain->format = s->cur_frame->f->format; | |
| 3405 | ✗ | s->cur_frame->frame_grain->width = s->cur_frame->f->width; | |
| 3406 | ✗ | s->cur_frame->frame_grain->height = s->cur_frame->f->height; | |
| 3407 | ✗ | if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0) | |
| 3408 | ✗ | goto fail; | |
| 3409 | |||
| 3410 | ✗ | ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f); | |
| 3411 | ✗ | if (ret < 0) | |
| 3412 | ✗ | goto fail; | |
| 3413 | } | ||
| 3414 | |||
| 3415 | 10350 | s->cur_frame->f->pict_type = 3 - s->sh.slice_type; | |
| 3416 | |||
| 3417 | 10350 | ret = ff_hevc_output_frames(s, s->layers_active_decode, s->layers_active_output, | |
| 3418 | 10350 | sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics, | |
| 3419 | 10350 | sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0); | |
| 3420 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (ret < 0) |
| 3421 | ✗ | goto fail; | |
| 3422 | |||
| 3423 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (s->avctx->hwaccel) { |
| 3424 | ✗ | AVCodecInternal *avci = s->avctx->internal; | |
| 3425 | ✗ | AVPacket *avpkt = avci->in_pkt; | |
| 3426 | ✗ | ret = FF_HW_CALL(s->avctx, start_frame, | |
| 3427 | avpkt->buf, NULL, 0); | ||
| 3428 | ✗ | if (ret < 0) | |
| 3429 | ✗ | goto fail; | |
| 3430 | } | ||
| 3431 | |||
| 3432 | // after starting the base-layer frame we know which layers will be decoded, | ||
| 3433 | // so we can now figure out which NALUs to wait for before we can call | ||
| 3434 | // ff_thread_finish_setup() | ||
| 3435 |
2/2✓ Branch 0 taken 9960 times.
✓ Branch 1 taken 390 times.
|
10350 | if (l == &s->layers[0]) |
| 3436 | 9960 | s->finish_setup_nal_idx = find_finish_setup_nal(s); | |
| 3437 | |||
| 3438 |
2/2✓ Branch 0 taken 9959 times.
✓ Branch 1 taken 391 times.
|
10350 | if (nal_idx >= s->finish_setup_nal_idx) |
| 3439 | 9959 | ff_thread_finish_setup(s->avctx); | |
| 3440 | |||
| 3441 | 10350 | return 0; | |
| 3442 | |||
| 3443 | ✗ | fail: | |
| 3444 | ✗ | if (l->cur_frame) | |
| 3445 | ✗ | ff_hevc_unref_frame(l->cur_frame, ~0); | |
| 3446 | ✗ | l->cur_frame = NULL; | |
| 3447 | ✗ | s->cur_frame = s->collocated_ref = NULL; | |
| 3448 | ✗ | return ret; | |
| 3449 | } | ||
| 3450 | |||
| 3451 | ✗ | static int verify_md5(HEVCContext *s, AVFrame *frame) | |
| 3452 | { | ||
| 3453 | ✗ | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); | |
| 3454 | char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)]; | ||
| 3455 | int pixel_shift; | ||
| 3456 | ✗ | int err = 0; | |
| 3457 | int i, j; | ||
| 3458 | |||
| 3459 | ✗ | if (!desc) | |
| 3460 | ✗ | return AVERROR(EINVAL); | |
| 3461 | |||
| 3462 | ✗ | pixel_shift = desc->comp[0].depth > 8; | |
| 3463 | |||
| 3464 | /* the checksums are LE, so we have to byteswap for >8bpp formats | ||
| 3465 | * on BE arches */ | ||
| 3466 | #if HAVE_BIGENDIAN | ||
| 3467 | if (pixel_shift && !s->checksum_buf) { | ||
| 3468 | av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size, | ||
| 3469 | FFMAX3(frame->linesize[0], frame->linesize[1], | ||
| 3470 | frame->linesize[2])); | ||
| 3471 | if (!s->checksum_buf) | ||
| 3472 | return AVERROR(ENOMEM); | ||
| 3473 | } | ||
| 3474 | #endif | ||
| 3475 | |||
| 3476 | ✗ | msg_buf[0] = '\0'; | |
| 3477 | ✗ | for (i = 0; frame->data[i]; i++) { | |
| 3478 | ✗ | int width = s->avctx->coded_width; | |
| 3479 | ✗ | int height = s->avctx->coded_height; | |
| 3480 | ✗ | int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width; | |
| 3481 | ✗ | int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height; | |
| 3482 | uint8_t md5[16]; | ||
| 3483 | |||
| 3484 | ✗ | av_md5_init(s->md5_ctx); | |
| 3485 | ✗ | for (j = 0; j < h; j++) { | |
| 3486 | ✗ | const uint8_t *src = frame->data[i] + j * frame->linesize[i]; | |
| 3487 | #if HAVE_BIGENDIAN | ||
| 3488 | if (pixel_shift) { | ||
| 3489 | s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf, | ||
| 3490 | (const uint16_t *) src, w); | ||
| 3491 | src = s->checksum_buf; | ||
| 3492 | } | ||
| 3493 | #endif | ||
| 3494 | ✗ | av_md5_update(s->md5_ctx, src, w << pixel_shift); | |
| 3495 | } | ||
| 3496 | ✗ | av_md5_final(s->md5_ctx, md5); | |
| 3497 | |||
| 3498 | #define MD5_PRI "%016" PRIx64 "%016" PRIx64 | ||
| 3499 | #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8) | ||
| 3500 | |||
| 3501 | ✗ | if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) { | |
| 3502 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
| 3503 | "plane %d - correct " MD5_PRI "; ", | ||
| 3504 | ✗ | i, MD5_PRI_ARG(md5)); | |
| 3505 | } else { | ||
| 3506 | ✗ | av_strlcatf(msg_buf, sizeof(msg_buf), | |
| 3507 | "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ", | ||
| 3508 | ✗ | i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i])); | |
| 3509 | ✗ | err = AVERROR_INVALIDDATA; | |
| 3510 | } | ||
| 3511 | } | ||
| 3512 | |||
| 3513 | ✗ | av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG, | |
| 3514 | "Verifying checksum for frame with POC %d: %s\n", | ||
| 3515 | s->poc, msg_buf); | ||
| 3516 | |||
| 3517 | ✗ | return err; | |
| 3518 | } | ||
| 3519 | |||
| 3520 | 10350 | static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l) | |
| 3521 | { | ||
| 3522 | 10350 | HEVCFrame *out = l->cur_frame; | |
| 3523 | const AVFilmGrainParams *fgp; | ||
| 3524 | av_unused int ret; | ||
| 3525 | |||
| 3526 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (out->needs_fg) { |
| 3527 | ✗ | av_assert0(out->frame_grain->buf[0]); | |
| 3528 | ✗ | fgp = av_film_grain_params_select(out->f); | |
| 3529 | ✗ | switch (fgp->type) { | |
| 3530 | ✗ | case AV_FILM_GRAIN_PARAMS_NONE: | |
| 3531 | ✗ | av_assert0(0); | |
| 3532 | return AVERROR_BUG; | ||
| 3533 | ✗ | case AV_FILM_GRAIN_PARAMS_H274: | |
| 3534 | ✗ | ret = ff_h274_apply_film_grain(out->frame_grain, out->f, fgp); | |
| 3535 | ✗ | break; | |
| 3536 | ✗ | case AV_FILM_GRAIN_PARAMS_AV1: | |
| 3537 | ✗ | ret = ff_aom_apply_film_grain(out->frame_grain, out->f, fgp); | |
| 3538 | ✗ | break; | |
| 3539 | } | ||
| 3540 | av_assert1(ret >= 0); | ||
| 3541 | } | ||
| 3542 | |||
| 3543 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (s->avctx->hwaccel) { |
| 3544 | ✗ | ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame); | |
| 3545 | ✗ | if (ret < 0) { | |
| 3546 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3547 | "hardware accelerator failed to decode picture\n"); | ||
| 3548 | ✗ | return ret; | |
| 3549 | } | ||
| 3550 | } else { | ||
| 3551 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (s->avctx->err_recognition & AV_EF_CRCCHECK && |
| 3552 | ✗ | s->sei.picture_hash.is_md5) { | |
| 3553 | ✗ | ret = verify_md5(s, out->f); | |
| 3554 | ✗ | if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) | |
| 3555 | ✗ | return ret; | |
| 3556 | } | ||
| 3557 | } | ||
| 3558 | 10350 | s->sei.picture_hash.is_md5 = 0; | |
| 3559 | |||
| 3560 | 10350 | av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %zu/%d.\n", | |
| 3561 | 10350 | l - s->layers, s->poc); | |
| 3562 | |||
| 3563 | 10350 | return 0; | |
| 3564 | } | ||
| 3565 | |||
| 3566 | 28903 | static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb) | |
| 3567 | { | ||
| 3568 |
2/2✓ Branch 0 taken 28682 times.
✓ Branch 1 taken 221 times.
|
28903 | const int layer_idx = s->vps ? s->vps->layer_idx[s->nuh_layer_id] : 0; |
| 3569 | HEVCLayerContext *l; | ||
| 3570 | int ret; | ||
| 3571 | |||
| 3572 | // skip layers not requested to be decoded | ||
| 3573 | // layers_active_decode can only change while decoding a base-layer frame, | ||
| 3574 | // so we can check it for non-base layers | ||
| 3575 |
1/2✓ Branch 0 taken 28903 times.
✗ Branch 1 not taken.
|
28903 | if (layer_idx < 0 || |
| 3576 |
3/4✓ Branch 0 taken 516 times.
✓ Branch 1 taken 28387 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 516 times.
|
28903 | (s->nuh_layer_id > 0 && !(s->layers_active_decode & (1 << layer_idx)))) |
| 3577 | ✗ | return 0; | |
| 3578 | |||
| 3579 | // the first slice of this picture was skipped, so drop the remaining | ||
| 3580 | // slices before parsing, the context is stale for them | ||
| 3581 |
4/4✓ Branch 0 taken 553 times.
✓ Branch 1 taken 28350 times.
✓ Branch 3 taken 486 times.
✓ Branch 4 taken 67 times.
|
28903 | if (s->skipping_frame && !show_bits1(gb)) |
| 3582 | 486 | return 0; | |
| 3583 | |||
| 3584 | 28417 | ret = hls_slice_header(&s->sh, s, gb); | |
| 3585 | // Once hls_slice_header has been called, the context is inconsistent with the slice header | ||
| 3586 | // until the context is reinitialized according to the contents of the new slice header | ||
| 3587 | // at the start of decode_slice_data. | ||
| 3588 | 28417 | s->slice_initialized = 0; | |
| 3589 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28417 times.
|
28417 | if (ret < 0) { |
| 3590 | ✗ | return ret; | |
| 3591 | } | ||
| 3592 | |||
| 3593 |
4/4✓ Branch 0 taken 81 times.
✓ Branch 1 taken 28336 times.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 26 times.
|
28417 | if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) || |
| 3594 |
4/4✓ Branch 0 taken 55 times.
✓ Branch 1 taken 28336 times.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 1 times.
|
28391 | (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) || |
| 3595 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 28390 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
28390 | (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) || |
| 3596 |
4/4✓ Branch 0 taken 27266 times.
✓ Branch 1 taken 1124 times.
✓ Branch 2 taken 1045 times.
✓ Branch 3 taken 26221 times.
|
28390 | ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) && |
| 3597 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 2126 times.
|
2169 | s->no_rasl_output_flag)) { |
| 3598 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | if (s->sh.first_slice_in_pic_flag) |
| 3599 | 70 | s->skipping_frame = 1; | |
| 3600 | 70 | return 0; | |
| 3601 | } | ||
| 3602 |
2/2✓ Branch 0 taken 10351 times.
✓ Branch 1 taken 17996 times.
|
28347 | if (s->sh.first_slice_in_pic_flag) |
| 3603 | 10351 | s->skipping_frame = 0; | |
| 3604 | |||
| 3605 | // switching to a new layer, mark previous layer's frame (if any) as done | ||
| 3606 |
2/2✓ Branch 0 taken 771 times.
✓ Branch 1 taken 27576 times.
|
28347 | if (s->cur_layer != layer_idx && |
| 3607 |
2/2✓ Branch 0 taken 390 times.
✓ Branch 1 taken 381 times.
|
771 | s->layers[s->cur_layer].cur_frame && |
| 3608 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
|
390 | s->avctx->active_thread_type == FF_THREAD_FRAME) |
| 3609 | ✗ | ff_progress_frame_report(&s->layers[s->cur_layer].cur_frame->tf, INT_MAX); | |
| 3610 | |||
| 3611 | 28347 | s->cur_layer = layer_idx; | |
| 3612 | 28347 | l = &s->layers[s->cur_layer]; | |
| 3613 | |||
| 3614 |
2/2✓ Branch 0 taken 10351 times.
✓ Branch 1 taken 17996 times.
|
28347 | if (s->sh.first_slice_in_pic_flag) { |
| 3615 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10350 times.
|
10351 | if (l->cur_frame) { |
| 3616 | 1 | av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n"); | |
| 3617 | 1 | return AVERROR_INVALIDDATA; | |
| 3618 | } | ||
| 3619 | |||
| 3620 | 10350 | ret = hevc_frame_start(s, l, nal_idx); | |
| 3621 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10350 times.
|
10350 | if (ret < 0) |
| 3622 | ✗ | return ret; | |
| 3623 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17996 times.
|
17996 | } else if (!l->cur_frame) { |
| 3624 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n"); | |
| 3625 | ✗ | return AVERROR_INVALIDDATA; | |
| 3626 | } | ||
| 3627 | |||
| 3628 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28346 times.
|
28346 | if (s->nal_unit_type != s->first_nal_type) { |
| 3629 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3630 | "Non-matching NAL types of the VCL NALUs: %d %d\n", | ||
| 3631 | ✗ | s->first_nal_type, s->nal_unit_type); | |
| 3632 | ✗ | return AVERROR_INVALIDDATA; | |
| 3633 | } | ||
| 3634 | |||
| 3635 | 28346 | ret = decode_slice_data(s, l, &s->pkt.nals[nal_idx], gb); | |
| 3636 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28345 times.
|
28346 | if (ret < 0) |
| 3637 | 1 | return ret; | |
| 3638 | |||
| 3639 | 28345 | return 0; | |
| 3640 | } | ||
| 3641 | |||
| 3642 | 39857 | static int decode_nal_unit(HEVCContext *s, unsigned nal_idx) | |
| 3643 | { | ||
| 3644 | 39857 | H2645NAL *nal = &s->pkt.nals[nal_idx]; | |
| 3645 | 39857 | GetBitContext gb = nal->gb; | |
| 3646 | int ret; | ||
| 3647 | |||
| 3648 | 39857 | s->nal_unit_type = nal->type; | |
| 3649 | 39857 | s->nuh_layer_id = nal->nuh_layer_id; | |
| 3650 | 39857 | s->temporal_id = nal->temporal_id; | |
| 3651 | |||
| 3652 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 39857 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
39857 | if (FF_HW_HAS_CB(s->avctx, decode_params) && |
| 3653 | ✗ | (s->nal_unit_type == HEVC_NAL_VPS || | |
| 3654 | ✗ | s->nal_unit_type == HEVC_NAL_SPS || | |
| 3655 | ✗ | s->nal_unit_type == HEVC_NAL_PPS || | |
| 3656 | ✗ | s->nal_unit_type == HEVC_NAL_SEI_PREFIX || | |
| 3657 | ✗ | s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) { | |
| 3658 | ✗ | ret = FF_HW_CALL(s->avctx, decode_params, | |
| 3659 | nal->type, nal->raw_data, nal->raw_size); | ||
| 3660 | ✗ | if (ret < 0) | |
| 3661 | ✗ | goto fail; | |
| 3662 | } | ||
| 3663 | |||
| 3664 |
6/7✓ Branch 0 taken 454 times.
✓ Branch 1 taken 464 times.
✓ Branch 2 taken 1423 times.
✓ Branch 3 taken 7950 times.
✓ Branch 4 taken 28903 times.
✓ Branch 5 taken 663 times.
✗ Branch 6 not taken.
|
39857 | switch (s->nal_unit_type) { |
| 3665 | 454 | case HEVC_NAL_VPS: | |
| 3666 | 454 | ret = ff_hevc_decode_nal_vps(&gb, s->avctx, &s->ps); | |
| 3667 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 454 times.
|
454 | if (ret < 0) |
| 3668 | ✗ | goto fail; | |
| 3669 | 454 | break; | |
| 3670 | 464 | case HEVC_NAL_SPS: | |
| 3671 | 464 | ret = ff_hevc_decode_nal_sps(&gb, s->avctx, &s->ps, | |
| 3672 | 464 | nal->nuh_layer_id, s->apply_defdispwin); | |
| 3673 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 464 times.
|
464 | if (ret < 0) |
| 3674 | ✗ | goto fail; | |
| 3675 | 464 | break; | |
| 3676 | 1423 | case HEVC_NAL_PPS: | |
| 3677 | 1423 | ret = ff_hevc_decode_nal_pps(&gb, s->avctx, &s->ps); | |
| 3678 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1421 times.
|
1423 | if (ret < 0) |
| 3679 | 2 | goto fail; | |
| 3680 | 1421 | break; | |
| 3681 | 7950 | case HEVC_NAL_SEI_PREFIX: | |
| 3682 | case HEVC_NAL_SEI_SUFFIX: | ||
| 3683 | 7950 | ret = ff_hevc_decode_nal_sei(&gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type); | |
| 3684 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7917 times.
|
7950 | if (ret < 0) |
| 3685 | 33 | goto fail; | |
| 3686 | 7917 | break; | |
| 3687 | 28903 | case HEVC_NAL_TRAIL_R: | |
| 3688 | case HEVC_NAL_TRAIL_N: | ||
| 3689 | case HEVC_NAL_TSA_N: | ||
| 3690 | case HEVC_NAL_TSA_R: | ||
| 3691 | case HEVC_NAL_STSA_N: | ||
| 3692 | case HEVC_NAL_STSA_R: | ||
| 3693 | case HEVC_NAL_BLA_W_LP: | ||
| 3694 | case HEVC_NAL_BLA_W_RADL: | ||
| 3695 | case HEVC_NAL_BLA_N_LP: | ||
| 3696 | case HEVC_NAL_IDR_W_RADL: | ||
| 3697 | case HEVC_NAL_IDR_N_LP: | ||
| 3698 | case HEVC_NAL_CRA_NUT: | ||
| 3699 | case HEVC_NAL_RADL_N: | ||
| 3700 | case HEVC_NAL_RADL_R: | ||
| 3701 | case HEVC_NAL_RASL_N: | ||
| 3702 | case HEVC_NAL_RASL_R: | ||
| 3703 | 28903 | ret = decode_slice(s, nal_idx, &gb); | |
| 3704 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 28901 times.
|
28903 | if (ret < 0) |
| 3705 | 2 | goto fail; | |
| 3706 | 28901 | break; | |
| 3707 | 663 | case HEVC_NAL_EOS_NUT: | |
| 3708 | case HEVC_NAL_EOB_NUT: | ||
| 3709 | case HEVC_NAL_AUD: | ||
| 3710 | case HEVC_NAL_FD_NUT: | ||
| 3711 | case HEVC_NAL_UNSPEC62: // Dolby Vision RPU | ||
| 3712 | case HEVC_NAL_UNSPEC63: // Dolby Vision EL | ||
| 3713 | 663 | break; | |
| 3714 | ✗ | default: | |
| 3715 | ✗ | av_log(s->avctx, AV_LOG_VERBOSE, | |
| 3716 | ✗ | "Skipping NAL unit %d\n", s->nal_unit_type); | |
| 3717 | } | ||
| 3718 | |||
| 3719 | 39820 | return 0; | |
| 3720 | 37 | fail: | |
| 3721 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | if (ret == AVERROR_INVALIDDATA && |
| 3722 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | !(s->avctx->err_recognition & AV_EF_EXPLODE)) { |
| 3723 | 37 | av_log(s->avctx, AV_LOG_WARNING, | |
| 3724 | 37 | "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type); | |
| 3725 | 37 | return 0; | |
| 3726 | } | ||
| 3727 | ✗ | return ret; | |
| 3728 | } | ||
| 3729 | |||
| 3730 | 447 | static void decode_reset_recovery_point(HEVCContext *s) | |
| 3731 | { | ||
| 3732 | 447 | s->recovery_poc = HEVC_RECOVERY_UNSPECIFIED; | |
| 3733 | 447 | s->sei.recovery_point.has_recovery_poc = 0; | |
| 3734 | 447 | } | |
| 3735 | |||
| 3736 | 308 | static int export_stream_params_from_slice(HEVCContext *s, const H2645NAL *nal) | |
| 3737 | { | ||
| 3738 | 308 | GetBitContext gb = nal->gb; | |
| 3739 | const HEVCSPS *sps; | ||
| 3740 | const HEVCVPS *vps; | ||
| 3741 | unsigned pps_id; | ||
| 3742 | |||
| 3743 |
2/2✓ Branch 0 taken 275 times.
✓ Branch 1 taken 33 times.
|
583 | int is_slice = nal->type <= HEVC_NAL_RASL_R || |
| 3744 |
1/2✓ Branch 0 taken 275 times.
✗ Branch 1 not taken.
|
275 | (nal->type >= HEVC_NAL_BLA_W_LP && |
| 3745 |
2/2✓ Branch 0 taken 222 times.
✓ Branch 1 taken 53 times.
|
275 | nal->type <= HEVC_NAL_CRA_NUT); |
| 3746 | |||
| 3747 |
3/4✓ Branch 0 taken 255 times.
✓ Branch 1 taken 53 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 255 times.
|
308 | if (!is_slice || nal->nuh_layer_id) |
| 3748 | 53 | return 0; | |
| 3749 | |||
| 3750 | 255 | skip_bits1(&gb); // first_slice_segment_in_pic_flag | |
| 3751 |
2/2✓ Branch 0 taken 222 times.
✓ Branch 1 taken 33 times.
|
255 | if (nal->type >= HEVC_NAL_BLA_W_LP) |
| 3752 | 222 | skip_bits1(&gb); // no_output_of_prior_pics_flag | |
| 3753 | 255 | pps_id = get_ue_golomb_long(&gb); | |
| 3754 |
3/4✓ Branch 0 taken 255 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 222 times.
|
255 | if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) |
| 3755 | 33 | return 0; | |
| 3756 | 222 | sps = s->ps.pps_list[pps_id]->sps; | |
| 3757 | 222 | vps = sps->vps; | |
| 3758 | |||
| 3759 | 222 | export_stream_params(s, sps); | |
| 3760 | |||
| 3761 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 217 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
222 | if (vps->nb_layers == 2 && vps->layer_id_in_nuh[1] && |
| 3762 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY) { |
| 3763 | ✗ | enum AVPixelFormat alpha_fmt = map_to_alpha_format(s, sps->pix_fmt); | |
| 3764 | |||
| 3765 | ✗ | if (alpha_fmt != AV_PIX_FMT_NONE) | |
| 3766 | ✗ | s->avctx->pix_fmt = alpha_fmt; | |
| 3767 | } | ||
| 3768 | |||
| 3769 | 222 | return 1; | |
| 3770 | } | ||
| 3771 | |||
| 3772 | 10315 | static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) | |
| 3773 | { | ||
| 3774 | 10315 | int ret = 0; | |
| 3775 | 10315 | int eos_at_start = 1; | |
| 3776 | 10315 | int params_exported = 0; | |
| 3777 |
2/2✓ Branch 0 taken 350 times.
✓ Branch 1 taken 9965 times.
|
10315 | int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING; |
| 3778 | |||
| 3779 | 10315 | s->cur_frame = s->collocated_ref = NULL; | |
| 3780 | 10315 | s->last_eos = s->eos; | |
| 3781 | 10315 | s->eos = 0; | |
| 3782 | 10315 | s->slice_initialized = 0; | |
| 3783 |
2/2✓ Branch 0 taken 443 times.
✓ Branch 1 taken 9872 times.
|
10315 | if (s->last_eos) |
| 3784 | 443 | decode_reset_recovery_point(s); | |
| 3785 | |||
| 3786 |
2/2✓ Branch 0 taken 20630 times.
✓ Branch 1 taken 10315 times.
|
30945 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
| 3787 | 20630 | HEVCLayerContext *l = &s->layers[i]; | |
| 3788 | 20630 | l->cur_frame = NULL; | |
| 3789 | } | ||
| 3790 | |||
| 3791 | /* split the input packet into NAL units, so we know the upper bound on the | ||
| 3792 | * number of slices in the frame */ | ||
| 3793 | 10315 | ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx, | |
| 3794 | 10315 | s->nal_length_size, s->avctx->codec_id, flags); | |
| 3795 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10315 times.
|
10315 | if (ret < 0) { |
| 3796 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
| 3797 | "Error splitting the input into NAL units.\n"); | ||
| 3798 | ✗ | return ret; | |
| 3799 | } | ||
| 3800 | |||
| 3801 |
2/2✓ Branch 0 taken 41017 times.
✓ Branch 1 taken 10315 times.
|
51332 | for (int i = 0; i < s->pkt.nb_nals; i++) { |
| 3802 |
2/2✓ Branch 0 taken 41016 times.
✓ Branch 1 taken 1 times.
|
41017 | if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT || |
| 3803 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 41013 times.
|
41016 | s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) { |
| 3804 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (eos_at_start) { |
| 3805 | 4 | s->last_eos = 1; | |
| 3806 | 4 | decode_reset_recovery_point(s); | |
| 3807 | } else { | ||
| 3808 | ✗ | s->eos = 1; | |
| 3809 | } | ||
| 3810 | } else { | ||
| 3811 | 41013 | eos_at_start = 0; | |
| 3812 | } | ||
| 3813 | } | ||
| 3814 | |||
| 3815 | /* | ||
| 3816 | * Check for RPU delimiter. | ||
| 3817 | * | ||
| 3818 | * Dolby Vision RPUs masquerade as unregistered NALs of type 62. | ||
| 3819 | * | ||
| 3820 | * We have to do this check here an create the rpu buffer, since RPUs are appended | ||
| 3821 | * to the end of an AU; they are normally the last non-EOB/EOS NAL in the AU. | ||
| 3822 | */ | ||
| 3823 | 10315 | H2645NAL *rpu_nal = NULL; | |
| 3824 |
2/2✓ Branch 0 taken 30701 times.
✓ Branch 1 taken 10313 times.
|
41014 | for (int i = s->pkt.nb_nals - 1; i > 0 ; i--) { |
| 3825 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 30699 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
30701 | if (s->pkt.nals[i].type == HEVC_NAL_UNSPEC62 && s->pkt.nals[i].size > 2 |
| 3826 |
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) { |
| 3827 | 2 | rpu_nal = &s->pkt.nals[i]; | |
| 3828 | 2 | break; | |
| 3829 | } | ||
| 3830 | } | ||
| 3831 | |||
| 3832 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10313 times.
|
10315 | if (rpu_nal) { |
| 3833 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (s->rpu_buf) { |
| 3834 | ✗ | av_buffer_unref(&s->rpu_buf); | |
| 3835 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n"); | |
| 3836 | } | ||
| 3837 | |||
| 3838 | 2 | s->rpu_buf = av_buffer_alloc(rpu_nal->raw_size - 2); | |
| 3839 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!s->rpu_buf) { |
| 3840 | ✗ | ret = AVERROR(ENOMEM); | |
| 3841 | ✗ | goto fail; | |
| 3842 | } | ||
| 3843 | 2 | memcpy(s->rpu_buf->data, rpu_nal->raw_data + 2, rpu_nal->raw_size - 2); | |
| 3844 | |||
| 3845 | 2 | ret = ff_dovi_rpu_parse(&s->dovi_ctx, rpu_nal->data + 2, rpu_nal->size - 2, | |
| 3846 | 2 | s->avctx->err_recognition); | |
| 3847 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ret < 0) { |
| 3848 | ✗ | av_buffer_unref(&s->rpu_buf); | |
| 3849 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n"); | |
| 3850 | /* ignore */ | ||
| 3851 | } | ||
| 3852 | } | ||
| 3853 | |||
| 3854 | /* decode the NAL units */ | ||
| 3855 |
2/2✓ Branch 0 taken 41017 times.
✓ Branch 1 taken 10315 times.
|
51332 | for (int i = 0; i < s->pkt.nb_nals; i++) { |
| 3856 | 41017 | H2645NAL *nal = &s->pkt.nals[i]; | |
| 3857 | |||
| 3858 |
2/2✓ Branch 0 taken 1742 times.
✓ Branch 1 taken 39275 times.
|
41017 | if (s->avctx->skip_frame >= AVDISCARD_ALL) { |
| 3859 |
2/2✓ Branch 0 taken 1087 times.
✓ Branch 1 taken 655 times.
|
1742 | switch (nal->type) { |
| 3860 | 1087 | case HEVC_NAL_VPS: | |
| 3861 | case HEVC_NAL_SPS: | ||
| 3862 | case HEVC_NAL_PPS: | ||
| 3863 | case HEVC_NAL_SEI_PREFIX: | ||
| 3864 | case HEVC_NAL_SEI_SUFFIX: | ||
| 3865 | 1087 | break; | |
| 3866 | 655 | default: | |
| 3867 |
3/4✓ Branch 0 taken 655 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 308 times.
✓ Branch 3 taken 347 times.
|
655 | if (!s->layers[0].sps && !params_exported) |
| 3868 | 308 | params_exported = export_stream_params_from_slice(s, nal); | |
| 3869 | 655 | continue; | |
| 3870 | } | ||
| 3871 |
4/4✓ Branch 0 taken 1095 times.
✓ Branch 1 taken 38180 times.
✓ Branch 2 taken 505 times.
✓ Branch 3 taken 590 times.
|
40370 | } else if (s->avctx->skip_frame >= AVDISCARD_NONREF && |
| 3872 | 1095 | ff_hevc_nal_is_nonref(nal->type)) | |
| 3873 | 505 | continue; | |
| 3874 | |||
| 3875 | 39857 | ret = decode_nal_unit(s, i); | |
| 3876 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39857 times.
|
39857 | if (ret < 0) { |
| 3877 | ✗ | av_log(s->avctx, AV_LOG_WARNING, | |
| 3878 | "Error parsing NAL unit #%d.\n", i); | ||
| 3879 | ✗ | goto fail; | |
| 3880 | } | ||
| 3881 | } | ||
| 3882 | |||
| 3883 |
2/2✓ Branch 0 taken 10093 times.
✓ Branch 1 taken 222 times.
|
10315 | if (params_exported) { |
| 3884 | 222 | ret = export_stream_params_from_sei(s); | |
| 3885 |
1/2✓ Branch 0 taken 222 times.
✗ Branch 1 not taken.
|
222 | if (ret < 0) |
| 3886 | ✗ | goto fail; | |
| 3887 | } | ||
| 3888 | |||
| 3889 | 10315 | fail: | |
| 3890 |
2/2✓ Branch 0 taken 20630 times.
✓ Branch 1 taken 10315 times.
|
30945 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
| 3891 | 20630 | HEVCLayerContext *l = &s->layers[i]; | |
| 3892 | |||
| 3893 |
2/2✓ Branch 0 taken 10280 times.
✓ Branch 1 taken 10350 times.
|
20630 | if (!l->cur_frame) |
| 3894 | 10280 | continue; | |
| 3895 | |||
| 3896 |
1/2✓ Branch 0 taken 10350 times.
✗ Branch 1 not taken.
|
10350 | if (ret >= 0) |
| 3897 | 10350 | ret = hevc_frame_end(s, l); | |
| 3898 | |||
| 3899 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 10317 times.
|
10350 | if (s->avctx->active_thread_type == FF_THREAD_FRAME) |
| 3900 | 33 | ff_progress_frame_report(&l->cur_frame->tf, INT_MAX); | |
| 3901 | } | ||
| 3902 | |||
| 3903 | 10315 | return ret; | |
| 3904 | } | ||
| 3905 | |||
| 3906 | 355 | static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first) | |
| 3907 | { | ||
| 3908 | int ret, i; | ||
| 3909 | |||
| 3910 | 355 | ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff, | |
| 3911 | 355 | &s->nal_length_size, s->avctx->err_recognition, | |
| 3912 | 355 | s->apply_defdispwin, s->avctx); | |
| 3913 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 355 times.
|
355 | if (ret < 0) |
| 3914 | ✗ | return ret; | |
| 3915 | |||
| 3916 | /* export stream parameters from the first SPS */ | ||
| 3917 |
2/2✓ Branch 0 taken 385 times.
✓ Branch 1 taken 2 times.
|
387 | for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { |
| 3918 |
4/4✓ Branch 0 taken 369 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 353 times.
✓ Branch 3 taken 16 times.
|
385 | if (first && s->ps.sps_list[i]) { |
| 3919 | 353 | const HEVCSPS *sps = s->ps.sps_list[i]; | |
| 3920 | 353 | export_stream_params(s, sps); | |
| 3921 | |||
| 3922 | 353 | ret = export_multilayer(s, sps->vps); | |
| 3923 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 353 times.
|
353 | if (ret < 0) |
| 3924 | ✗ | return ret; | |
| 3925 | |||
| 3926 | 353 | break; | |
| 3927 | } | ||
| 3928 | } | ||
| 3929 | |||
| 3930 | /* export stream parameters from SEI */ | ||
| 3931 | 355 | ret = export_stream_params_from_sei(s); | |
| 3932 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 355 times.
|
355 | if (ret < 0) |
| 3933 | ✗ | return ret; | |
| 3934 | |||
| 3935 | 355 | return 0; | |
| 3936 | } | ||
| 3937 | |||
| 3938 | 21941 | static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) | |
| 3939 | { | ||
| 3940 | 21941 | HEVCContext *s = avctx->priv_data; | |
| 3941 | 21941 | AVCodecInternal *avci = avctx->internal; | |
| 3942 | 21941 | AVPacket *avpkt = avci->in_pkt; | |
| 3943 | |||
| 3944 | int ret; | ||
| 3945 | uint8_t *sd; | ||
| 3946 | size_t sd_size; | ||
| 3947 | |||
| 3948 | 21941 | s->pkt_dts = AV_NOPTS_VALUE; | |
| 3949 | |||
| 3950 |
2/2✓ Branch 1 taken 961 times.
✓ Branch 2 taken 20980 times.
|
21941 | if (av_container_fifo_can_read(s->output_fifo)) |
| 3951 | 961 | goto do_output; | |
| 3952 | |||
| 3953 | 20980 | av_packet_unref(avpkt); | |
| 3954 | 20980 | ret = ff_decode_get_packet(avctx, avpkt); | |
| 3955 |
2/2✓ Branch 0 taken 350 times.
✓ Branch 1 taken 20630 times.
|
20980 | if (ret == AVERROR_EOF) { |
| 3956 | 350 | ret = ff_hevc_output_frames(s, s->layers_active_decode, | |
| 3957 | s->layers_active_output, 0, 0, 0); | ||
| 3958 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 350 times.
|
350 | if (ret < 0) |
| 3959 | ✗ | return ret; | |
| 3960 | 350 | goto do_output; | |
| 3961 |
2/2✓ Branch 0 taken 10315 times.
✓ Branch 1 taken 10315 times.
|
20630 | } else if (ret < 0) |
| 3962 | 10315 | return ret; | |
| 3963 | |||
| 3964 | 10315 | s->pkt_dts = avpkt->dts; | |
| 3965 | |||
| 3966 | 10315 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size); | |
| 3967 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10314 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
10315 | if (sd && sd_size > 0) { |
| 3968 | 1 | ret = hevc_decode_extradata(s, sd, sd_size, 0); | |
| 3969 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
| 3970 | ✗ | return ret; | |
| 3971 | } | ||
| 3972 | |||
| 3973 | 10315 | sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size); | |
| 3974 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10315 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10315 | if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) { |
| 3975 | ✗ | int old = s->dovi_ctx.cfg.dv_profile; | |
| 3976 | ✗ | s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd; | |
| 3977 | ✗ | if (old) | |
| 3978 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
| 3979 | "New DOVI configuration record from input packet (profile %d -> %u).\n", | ||
| 3980 | ✗ | old, s->dovi_ctx.cfg.dv_profile); | |
| 3981 | } | ||
| 3982 | |||
| 3983 | 10315 | ret = decode_nal_units(s, avpkt->data, avpkt->size); | |
| 3984 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10315 times.
|
10315 | if (ret < 0) |
| 3985 | ✗ | return ret; | |
| 3986 | |||
| 3987 | 10315 | do_output: | |
| 3988 |
2/2✓ Branch 1 taken 10199 times.
✓ Branch 2 taken 1427 times.
|
11626 | if (av_container_fifo_read(s->output_fifo, frame, 0) >= 0) { |
| 3989 |
1/2✓ Branch 0 taken 10199 times.
✗ Branch 1 not taken.
|
10199 | if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN)) |
| 3990 | 10199 | av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS); | |
| 3991 | |||
| 3992 | 10199 | return 0; | |
| 3993 | } | ||
| 3994 | |||
| 3995 |
2/2✓ Branch 0 taken 219 times.
✓ Branch 1 taken 1208 times.
|
1427 | return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN); |
| 3996 | } | ||
| 3997 | |||
| 3998 | 67 | static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src) | |
| 3999 | { | ||
| 4000 | int ret; | ||
| 4001 | |||
| 4002 | 67 | ff_progress_frame_ref(&dst->tf, &src->tf); | |
| 4003 | |||
| 4004 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (src->needs_fg) { |
| 4005 | ✗ | ret = av_frame_ref(dst->frame_grain, src->frame_grain); | |
| 4006 | ✗ | if (ret < 0) { | |
| 4007 | ✗ | ff_hevc_unref_frame(dst, ~0); | |
| 4008 | ✗ | return ret; | |
| 4009 | } | ||
| 4010 | ✗ | dst->needs_fg = 1; | |
| 4011 | } | ||
| 4012 | |||
| 4013 | 67 | dst->pps = av_refstruct_ref_c(src->pps); | |
| 4014 | 67 | dst->tab_mvf = av_refstruct_ref(src->tab_mvf); | |
| 4015 | 67 | dst->rpl_tab = av_refstruct_ref(src->rpl_tab); | |
| 4016 | 67 | dst->rpl = av_refstruct_ref(src->rpl); | |
| 4017 | 67 | dst->nb_rpl_elems = src->nb_rpl_elems; | |
| 4018 | |||
| 4019 | 67 | dst->poc = src->poc; | |
| 4020 | 67 | dst->ctb_count = src->ctb_count; | |
| 4021 | 67 | dst->flags = src->flags; | |
| 4022 | |||
| 4023 | 67 | dst->base_layer_frame = src->base_layer_frame; | |
| 4024 | |||
| 4025 | 67 | av_refstruct_replace(&dst->hwaccel_picture_private, | |
| 4026 | 67 | src->hwaccel_picture_private); | |
| 4027 | |||
| 4028 | 67 | return 0; | |
| 4029 | } | ||
| 4030 | |||
| 4031 | 577 | static av_cold int hevc_decode_free(AVCodecContext *avctx) | |
| 4032 | { | ||
| 4033 | 577 | HEVCContext *s = avctx->priv_data; | |
| 4034 | |||
| 4035 |
2/2✓ Branch 0 taken 1154 times.
✓ Branch 1 taken 577 times.
|
1731 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
| 4036 | 1154 | pic_arrays_free(&s->layers[i]); | |
| 4037 | 1154 | av_refstruct_unref(&s->layers[i].sps); | |
| 4038 | } | ||
| 4039 | |||
| 4040 | 577 | av_refstruct_unref(&s->vps); | |
| 4041 | 577 | av_refstruct_unref(&s->pps); | |
| 4042 | |||
| 4043 | 577 | ff_dovi_ctx_unref(&s->dovi_ctx); | |
| 4044 | 577 | av_buffer_unref(&s->rpu_buf); | |
| 4045 | |||
| 4046 | 577 | av_freep(&s->md5_ctx); | |
| 4047 | |||
| 4048 | 577 | av_container_fifo_free(&s->output_fifo); | |
| 4049 | |||
| 4050 |
2/2✓ Branch 0 taken 1154 times.
✓ Branch 1 taken 577 times.
|
1731 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
| 4051 | 1154 | HEVCLayerContext *l = &s->layers[layer]; | |
| 4052 |
2/2✓ Branch 0 taken 36928 times.
✓ Branch 1 taken 1154 times.
|
38082 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
| 4053 | 36928 | ff_hevc_unref_frame(&l->DPB[i], ~0); | |
| 4054 | 36928 | av_frame_free(&l->DPB[i].frame_grain); | |
| 4055 | } | ||
| 4056 | } | ||
| 4057 | |||
| 4058 | 577 | ff_hevc_ps_uninit(&s->ps); | |
| 4059 | |||
| 4060 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 577 times.
|
577 | for (int i = 0; i < s->nb_wpp_progress; i++) |
| 4061 | ✗ | ff_thread_progress_destroy(&s->wpp_progress[i]); | |
| 4062 | 577 | av_freep(&s->wpp_progress); | |
| 4063 | |||
| 4064 | 577 | av_freep(&s->sh.entry_point_offset); | |
| 4065 | 577 | av_freep(&s->sh.offset); | |
| 4066 | 577 | av_freep(&s->sh.size); | |
| 4067 | |||
| 4068 | 577 | av_freep(&s->local_ctx); | |
| 4069 | |||
| 4070 | 577 | ff_h2645_packet_uninit(&s->pkt); | |
| 4071 | |||
| 4072 | 577 | ff_hevc_reset_sei(&s->sei); | |
| 4073 | |||
| 4074 | 577 | return 0; | |
| 4075 | } | ||
| 4076 | |||
| 4077 | 577 | static av_cold int hevc_init_context(AVCodecContext *avctx) | |
| 4078 | { | ||
| 4079 | 577 | HEVCContext *s = avctx->priv_data; | |
| 4080 | |||
| 4081 | 577 | s->avctx = avctx; | |
| 4082 | |||
| 4083 | 577 | s->local_ctx = av_mallocz(sizeof(*s->local_ctx)); | |
| 4084 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 577 times.
|
577 | if (!s->local_ctx) |
| 4085 | ✗ | return AVERROR(ENOMEM); | |
| 4086 | 577 | s->nb_local_ctx = 1; | |
| 4087 | |||
| 4088 | 577 | s->local_ctx[0].parent = s; | |
| 4089 | 577 | s->local_ctx[0].logctx = avctx; | |
| 4090 | 577 | s->local_ctx[0].common_cabac_state = &s->cabac; | |
| 4091 | |||
| 4092 | 577 | s->output_fifo = av_container_fifo_alloc_avframe(0); | |
| 4093 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 577 times.
|
577 | if (!s->output_fifo) |
| 4094 | ✗ | return AVERROR(ENOMEM); | |
| 4095 | |||
| 4096 |
2/2✓ Branch 0 taken 1154 times.
✓ Branch 1 taken 577 times.
|
1731 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
| 4097 | 1154 | HEVCLayerContext *l = &s->layers[layer]; | |
| 4098 |
2/2✓ Branch 0 taken 36928 times.
✓ Branch 1 taken 1154 times.
|
38082 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
| 4099 | 36928 | l->DPB[i].frame_grain = av_frame_alloc(); | |
| 4100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36928 times.
|
36928 | if (!l->DPB[i].frame_grain) |
| 4101 | ✗ | return AVERROR(ENOMEM); | |
| 4102 | } | ||
| 4103 | } | ||
| 4104 | |||
| 4105 | 577 | s->md5_ctx = av_md5_alloc(); | |
| 4106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 577 times.
|
577 | if (!s->md5_ctx) |
| 4107 | ✗ | return AVERROR(ENOMEM); | |
| 4108 | |||
| 4109 | 577 | ff_bswapdsp_init(&s->bdsp); | |
| 4110 | |||
| 4111 | 577 | s->dovi_ctx.logctx = avctx; | |
| 4112 | 577 | s->eos = 0; | |
| 4113 | |||
| 4114 | 577 | ff_hevc_reset_sei(&s->sei); | |
| 4115 | |||
| 4116 | 577 | return 0; | |
| 4117 | } | ||
| 4118 | |||
| 4119 | #if HAVE_THREADS | ||
| 4120 | 32 | static int hevc_update_thread_context(AVCodecContext *dst, | |
| 4121 | const AVCodecContext *src) | ||
| 4122 | { | ||
| 4123 | 32 | HEVCContext *s = dst->priv_data; | |
| 4124 | 32 | HEVCContext *s0 = src->priv_data; | |
| 4125 | int ret; | ||
| 4126 | |||
| 4127 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
|
96 | for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { |
| 4128 | 64 | HEVCLayerContext *l = &s->layers[layer]; | |
| 4129 | 64 | const HEVCLayerContext *l0 = &s0->layers[layer]; | |
| 4130 |
2/2✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 64 times.
|
2112 | for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { |
| 4131 | 2048 | ff_hevc_unref_frame(&l->DPB[i], ~0); | |
| 4132 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1981 times.
|
2048 | if (l0->DPB[i].f) { |
| 4133 | 67 | ret = hevc_ref_frame(&l->DPB[i], &l0->DPB[i]); | |
| 4134 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | if (ret < 0) |
| 4135 | ✗ | return ret; | |
| 4136 | } | ||
| 4137 | } | ||
| 4138 | |||
| 4139 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
|
64 | if (l->sps != l0->sps) { |
| 4140 | 1 | ret = set_sps(s, l, l0->sps); | |
| 4141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
| 4142 | ✗ | return ret; | |
| 4143 | } | ||
| 4144 | } | ||
| 4145 | |||
| 4146 |
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++) |
| 4147 | 512 | av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); | |
| 4148 | |||
| 4149 |
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++) |
| 4150 | 512 | av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); | |
| 4151 | |||
| 4152 |
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++) |
| 4153 | 2048 | av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); | |
| 4154 | |||
| 4155 | // PPS do not persist between frames | ||
| 4156 | 32 | av_refstruct_unref(&s->pps); | |
| 4157 | |||
| 4158 | 32 | s->poc_tid0 = s0->poc_tid0; | |
| 4159 | 32 | s->eos = s0->eos; | |
| 4160 | 32 | s->no_rasl_output_flag = s0->no_rasl_output_flag; | |
| 4161 | 32 | s->skipping_frame = s0->skipping_frame; | |
| 4162 | |||
| 4163 | 32 | s->is_nalff = s0->is_nalff; | |
| 4164 | 32 | s->nal_length_size = s0->nal_length_size; | |
| 4165 | 32 | s->layers_active_decode = s0->layers_active_decode; | |
| 4166 | 32 | s->layers_active_output = s0->layers_active_output; | |
| 4167 | |||
| 4168 | 32 | s->film_grain_warning_shown = s0->film_grain_warning_shown; | |
| 4169 | |||
| 4170 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | if (s->nb_view_ids != s0->nb_view_ids || |
| 4171 |
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)) { |
| 4172 | ✗ | av_freep(&s->view_ids); | |
| 4173 | ✗ | s->nb_view_ids = 0; | |
| 4174 | |||
| 4175 | ✗ | if (s0->nb_view_ids) { | |
| 4176 | ✗ | s->view_ids = av_memdup(s0->view_ids, s0->nb_view_ids * sizeof(*s0->view_ids)); | |
| 4177 | ✗ | if (!s->view_ids) | |
| 4178 | ✗ | return AVERROR(ENOMEM); | |
| 4179 | ✗ | s->nb_view_ids = s0->nb_view_ids; | |
| 4180 | } | ||
| 4181 | } | ||
| 4182 | |||
| 4183 | 32 | ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common); | |
| 4184 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
| 4185 | ✗ | return ret; | |
| 4186 | |||
| 4187 | 32 | ret = av_buffer_replace(&s->sei.common.itut_t35.hdr_plus, | |
| 4188 | 32 | s0->sei.common.itut_t35.hdr_plus); | |
| 4189 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
| 4190 | ✗ | return ret; | |
| 4191 | |||
| 4192 | 32 | ret = av_buffer_replace(&s->rpu_buf, s0->rpu_buf); | |
| 4193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
| 4194 | ✗ | return ret; | |
| 4195 | |||
| 4196 | 32 | ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx); | |
| 4197 | |||
| 4198 | 32 | ret = av_buffer_replace(&s->sei.common.itut_t35.hdr_vivid, | |
| 4199 | 32 | s0->sei.common.itut_t35.hdr_vivid); | |
| 4200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (ret < 0) |
| 4201 | ✗ | return ret; | |
| 4202 | |||
| 4203 | 32 | s->sei.common.frame_packing = s0->sei.common.frame_packing; | |
| 4204 | 32 | s->sei.common.display_orientation = s0->sei.common.display_orientation; | |
| 4205 | 32 | s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer; | |
| 4206 | 32 | s->sei.tdrdi = s0->sei.tdrdi; | |
| 4207 | 32 | s->sei.recovery_point = s0->sei.recovery_point; | |
| 4208 | 32 | s->recovery_poc = s0->recovery_poc; | |
| 4209 | |||
| 4210 | 32 | return 0; | |
| 4211 | } | ||
| 4212 | #endif | ||
| 4213 | |||
| 4214 | 354 | static int hevc_sei_to_context(AVCodecContext *avctx, HEVCSEI *sei) | |
| 4215 | { | ||
| 4216 | int ret; | ||
| 4217 | |||
| 4218 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 350 times.
|
354 | if (sei->tdrdi.present) { |
| 4219 | AVBufferRef *buf; | ||
| 4220 | size_t size; | ||
| 4221 | 4 | AV3DReferenceDisplaysInfo *tdrdi = av_tdrdi_alloc(sei->tdrdi.num_ref_displays, &size); | |
| 4222 | |||
| 4223 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!tdrdi) |
| 4224 | ✗ | return AVERROR(ENOMEM); | |
| 4225 | |||
| 4226 | 4 | buf = av_buffer_create((uint8_t *)tdrdi, size, NULL, NULL, 0); | |
| 4227 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!buf) { |
| 4228 | ✗ | av_free(tdrdi); | |
| 4229 | ✗ | return AVERROR(ENOMEM); | |
| 4230 | } | ||
| 4231 | |||
| 4232 | 4 | tdrdi->prec_ref_display_width = sei->tdrdi.prec_ref_display_width; | |
| 4233 | 4 | tdrdi->ref_viewing_distance_flag = sei->tdrdi.ref_viewing_distance_flag; | |
| 4234 | 4 | tdrdi->prec_ref_viewing_dist = sei->tdrdi.prec_ref_viewing_dist; | |
| 4235 | 4 | tdrdi->num_ref_displays = sei->tdrdi.num_ref_displays; | |
| 4236 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | for (int i = 0; i < sei->tdrdi.num_ref_displays; i++) { |
| 4237 | 4 | AV3DReferenceDisplay *display = av_tdrdi_get_display(tdrdi, i); | |
| 4238 | |||
| 4239 | 4 | display->left_view_id = sei->tdrdi.left_view_id[i]; | |
| 4240 | 4 | display->right_view_id = sei->tdrdi.right_view_id[i]; | |
| 4241 | 4 | display->exponent_ref_display_width = sei->tdrdi.exponent_ref_display_width[i]; | |
| 4242 | 4 | display->mantissa_ref_display_width = sei->tdrdi.mantissa_ref_display_width[i]; | |
| 4243 | 4 | display->exponent_ref_viewing_distance = sei->tdrdi.exponent_ref_viewing_distance[i]; | |
| 4244 | 4 | display->mantissa_ref_viewing_distance = sei->tdrdi.mantissa_ref_viewing_distance[i]; | |
| 4245 | 4 | display->additional_shift_present_flag = sei->tdrdi.additional_shift_present_flag[i]; | |
| 4246 | 4 | display->num_sample_shift = sei->tdrdi.num_sample_shift[i]; | |
| 4247 | } | ||
| 4248 | 4 | ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data, | |
| 4249 | AV_FRAME_DATA_3D_REFERENCE_DISPLAYS, &buf); | ||
| 4250 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ret < 0) { |
| 4251 | ✗ | av_buffer_unref(&buf); | |
| 4252 | ✗ | return ret; | |
| 4253 | } | ||
| 4254 | } | ||
| 4255 | |||
| 4256 | 354 | ret = ff_h2645_sei_to_context(avctx, &sei->common); | |
| 4257 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
|
354 | if (ret < 0) |
| 4258 | ✗ | return ret; | |
| 4259 | |||
| 4260 | 354 | return 0; | |
| 4261 | } | ||
| 4262 | |||
| 4263 | 577 | static av_cold int hevc_decode_init(AVCodecContext *avctx) | |
| 4264 | { | ||
| 4265 | 577 | HEVCContext *s = avctx->priv_data; | |
| 4266 | int ret; | ||
| 4267 | |||
| 4268 | 577 | ret = hevc_init_context(avctx); | |
| 4269 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 577 times.
|
577 | if (ret < 0) |
| 4270 | ✗ | return ret; | |
| 4271 | |||
| 4272 | 577 | s->sei.picture_timing.picture_struct = 0; | |
| 4273 | 577 | s->eos = 1; | |
| 4274 | |||
| 4275 | 577 | atomic_init(&s->wpp_err, 0); | |
| 4276 | |||
| 4277 |
2/2✓ Branch 0 taken 576 times.
✓ Branch 1 taken 1 times.
|
577 | if (!avctx->internal->is_copy) { |
| 4278 | const AVPacketSideData *sd; | ||
| 4279 | |||
| 4280 |
3/4✓ Branch 0 taken 354 times.
✓ Branch 1 taken 222 times.
✓ Branch 2 taken 354 times.
✗ Branch 3 not taken.
|
576 | if (avctx->extradata_size > 0 && avctx->extradata) { |
| 4281 | 354 | ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1); | |
| 4282 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
|
354 | if (ret < 0) { |
| 4283 | ✗ | return ret; | |
| 4284 | } | ||
| 4285 | |||
| 4286 | 354 | ret = hevc_sei_to_context(avctx, &s->sei); | |
| 4287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
|
354 | if (ret < 0) |
| 4288 | ✗ | return ret; | |
| 4289 | } | ||
| 4290 | |||
| 4291 | 576 | sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF); | |
| 4292 |
3/4✓ Branch 0 taken 35 times.
✓ Branch 1 taken 541 times.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
|
576 | if (sd && sd->size >= sizeof(s->dovi_ctx.cfg)) |
| 4293 | 35 | s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data; | |
| 4294 | } | ||
| 4295 | |||
| 4296 | 577 | return 0; | |
| 4297 | } | ||
| 4298 | |||
| 4299 | ✗ | static av_cold void hevc_decode_flush(AVCodecContext *avctx) | |
| 4300 | { | ||
| 4301 | ✗ | HEVCContext *s = avctx->priv_data; | |
| 4302 | ✗ | ff_hevc_flush_dpb(s); | |
| 4303 | ✗ | ff_hevc_reset_sei(&s->sei); | |
| 4304 | ✗ | ff_dovi_ctx_flush(&s->dovi_ctx); | |
| 4305 | ✗ | av_buffer_unref(&s->rpu_buf); | |
| 4306 | ✗ | s->eos = 1; | |
| 4307 | ✗ | s->skipping_frame = 0; | |
| 4308 | |||
| 4309 | ✗ | if (FF_HW_HAS_CB(avctx, flush)) | |
| 4310 | ✗ | FF_HW_SIMPLE_CALL(avctx, flush); | |
| 4311 | ✗ | } | |
| 4312 | |||
| 4313 | #define OFFSET(x) offsetof(HEVCContext, x) | ||
| 4314 | #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) | ||
| 4315 | |||
| 4316 | static const AVOption options[] = { | ||
| 4317 | { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin), | ||
| 4318 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
| 4319 | { "strict-displaywin", "strictly apply default display window size", OFFSET(apply_defdispwin), | ||
| 4320 | AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, | ||
| 4321 | { "view_ids", "Array of view IDs that should be decoded and output; a single -1 to decode all views", | ||
| 4322 | .offset = OFFSET(view_ids), .type = AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, | ||
| 4323 | .min = -1, .max = INT_MAX, .flags = PAR }, | ||
| 4324 | { "view_ids_available", "Array of available view IDs is exported here", | ||
| 4325 | .offset = OFFSET(view_ids_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY, | ||
| 4326 | .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY }, | ||
| 4327 | { "view_pos_available", "Array of view positions for view_ids_available is exported here, as AVStereo3DView", | ||
| 4328 | .offset = OFFSET(view_pos_available), .type = AV_OPT_TYPE_UINT | AV_OPT_TYPE_FLAG_ARRAY, | ||
| 4329 | .flags = PAR | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY, .unit = "view_pos" }, | ||
| 4330 | { "unspecified", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_UNSPEC }, .unit = "view_pos" }, | ||
| 4331 | { "left", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_LEFT }, .unit = "view_pos" }, | ||
| 4332 | { "right", .type = AV_OPT_TYPE_CONST, .default_val = { .i64 = AV_STEREO3D_VIEW_RIGHT }, .unit = "view_pos" }, | ||
| 4333 | |||
| 4334 | { NULL }, | ||
| 4335 | }; | ||
| 4336 | |||
| 4337 | static const AVClass hevc_decoder_class = { | ||
| 4338 | .class_name = "HEVC decoder", | ||
| 4339 | .item_name = av_default_item_name, | ||
| 4340 | .option = options, | ||
| 4341 | .version = LIBAVUTIL_VERSION_INT, | ||
| 4342 | }; | ||
| 4343 | |||
| 4344 | const FFCodec ff_hevc_decoder = { | ||
| 4345 | .p.name = "hevc", | ||
| 4346 | CODEC_LONG_NAME("HEVC (High Efficiency Video Coding)"), | ||
| 4347 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 4348 | .p.id = AV_CODEC_ID_HEVC, | ||
| 4349 | .priv_data_size = sizeof(HEVCContext), | ||
| 4350 | .p.priv_class = &hevc_decoder_class, | ||
| 4351 | .init = hevc_decode_init, | ||
| 4352 | .close = hevc_decode_free, | ||
| 4353 | FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame), | ||
| 4354 | .flush = hevc_decode_flush, | ||
| 4355 | UPDATE_THREAD_CONTEXT(hevc_update_thread_context), | ||
| 4356 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | | ||
| 4357 | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, | ||
| 4358 | .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | | ||
| 4359 | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | | ||
| 4360 | FF_CODEC_CAP_USES_PROGRESSFRAMES | | ||
| 4361 | FF_CODEC_CAP_INIT_CLEANUP, | ||
| 4362 | .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles), | ||
| 4363 | .hw_configs = (const AVCodecHWConfigInternal *const []) { | ||
| 4364 | #if CONFIG_HEVC_DXVA2_HWACCEL | ||
| 4365 | HWACCEL_DXVA2(hevc), | ||
| 4366 | #endif | ||
| 4367 | #if CONFIG_HEVC_D3D11VA_HWACCEL | ||
| 4368 | HWACCEL_D3D11VA(hevc), | ||
| 4369 | #endif | ||
| 4370 | #if CONFIG_HEVC_D3D11VA2_HWACCEL | ||
| 4371 | HWACCEL_D3D11VA2(hevc), | ||
| 4372 | #endif | ||
| 4373 | #if CONFIG_HEVC_D3D12VA_HWACCEL | ||
| 4374 | HWACCEL_D3D12VA(hevc), | ||
| 4375 | #endif | ||
| 4376 | #if CONFIG_HEVC_NVDEC_HWACCEL | ||
| 4377 | HWACCEL_NVDEC(hevc), | ||
| 4378 | #endif | ||
| 4379 | #if CONFIG_HEVC_NVDEC_CUARRAY_HWACCEL | ||
| 4380 | HWACCEL_NVDEC_CUARRAY(hevc), | ||
| 4381 | #endif | ||
| 4382 | #if CONFIG_HEVC_VAAPI_HWACCEL | ||
| 4383 | HWACCEL_VAAPI(hevc), | ||
| 4384 | #endif | ||
| 4385 | #if CONFIG_HEVC_VDPAU_HWACCEL | ||
| 4386 | HWACCEL_VDPAU(hevc), | ||
| 4387 | #endif | ||
| 4388 | #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL | ||
| 4389 | HWACCEL_VIDEOTOOLBOX(hevc), | ||
| 4390 | #endif | ||
| 4391 | #if CONFIG_HEVC_VULKAN_HWACCEL | ||
| 4392 | HWACCEL_VULKAN(hevc), | ||
| 4393 | #endif | ||
| 4394 | NULL | ||
| 4395 | }, | ||
| 4396 | }; | ||
| 4397 |