| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * H.26L/H.264/AVC/JVT/14496-10/... decoder | ||
| 3 | * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * H.264 / AVC / MPEG-4 part10 codec. | ||
| 25 | * @author Michael Niedermayer <michaelni@gmx.at> | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include "config_components.h" | ||
| 29 | |||
| 30 | #include "libavutil/avassert.h" | ||
| 31 | #include "libavutil/mem.h" | ||
| 32 | #include "libavutil/pixdesc.h" | ||
| 33 | #include "libavutil/timecode.h" | ||
| 34 | #include "decode.h" | ||
| 35 | #include "cabac.h" | ||
| 36 | #include "cabac_functions.h" | ||
| 37 | #include "error_resilience.h" | ||
| 38 | #include "avcodec.h" | ||
| 39 | #include "h264.h" | ||
| 40 | #include "h264dec.h" | ||
| 41 | #include "h264data.h" | ||
| 42 | #include "h264chroma.h" | ||
| 43 | #include "h264_ps.h" | ||
| 44 | #include "golomb.h" | ||
| 45 | #include "mathops.h" | ||
| 46 | #include "mpegutils.h" | ||
| 47 | #include "rectangle.h" | ||
| 48 | #include "libavutil/refstruct.h" | ||
| 49 | #include "thread.h" | ||
| 50 | #include "threadframe.h" | ||
| 51 | |||
| 52 | static const uint8_t field_scan[16+1] = { | ||
| 53 | 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4, | ||
| 54 | 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4, | ||
| 55 | 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4, | ||
| 56 | 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, | ||
| 57 | }; | ||
| 58 | |||
| 59 | static const uint8_t field_scan8x8[64+1] = { | ||
| 60 | 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8, | ||
| 61 | 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8, | ||
| 62 | 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8, | ||
| 63 | 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8, | ||
| 64 | 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8, | ||
| 65 | 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8, | ||
| 66 | 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8, | ||
| 67 | 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8, | ||
| 68 | 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8, | ||
| 69 | 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8, | ||
| 70 | 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8, | ||
| 71 | 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8, | ||
| 72 | 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8, | ||
| 73 | 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8, | ||
| 74 | 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8, | ||
| 75 | 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8, | ||
| 76 | }; | ||
| 77 | |||
| 78 | static const uint8_t field_scan8x8_cavlc[64+1] = { | ||
| 79 | 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8, | ||
| 80 | 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8, | ||
| 81 | 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8, | ||
| 82 | 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8, | ||
| 83 | 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8, | ||
| 84 | 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8, | ||
| 85 | 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8, | ||
| 86 | 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8, | ||
| 87 | 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8, | ||
| 88 | 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8, | ||
| 89 | 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8, | ||
| 90 | 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8, | ||
| 91 | 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8, | ||
| 92 | 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8, | ||
| 93 | 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8, | ||
| 94 | 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8, | ||
| 95 | }; | ||
| 96 | |||
| 97 | // zigzag_scan8x8_cavlc[i] = zigzag_scan8x8[(i/4) + 16*(i%4)] | ||
| 98 | static const uint8_t zigzag_scan8x8_cavlc[64+1] = { | ||
| 99 | 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8, | ||
| 100 | 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8, | ||
| 101 | 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8, | ||
| 102 | 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8, | ||
| 103 | 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8, | ||
| 104 | 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8, | ||
| 105 | 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8, | ||
| 106 | 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8, | ||
| 107 | 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8, | ||
| 108 | 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8, | ||
| 109 | 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8, | ||
| 110 | 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8, | ||
| 111 | 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8, | ||
| 112 | 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8, | ||
| 113 | 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8, | ||
| 114 | 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8, | ||
| 115 | }; | ||
| 116 | |||
| 117 | 29557 | static void release_unused_pictures(H264Context *h, int remove_current) | |
| 118 | { | ||
| 119 | int i; | ||
| 120 | |||
| 121 | /* release non reference frames */ | ||
| 122 |
2/2✓ Branch 0 taken 1064052 times.
✓ Branch 1 taken 29557 times.
|
1093609 | for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { |
| 123 |
6/6✓ Branch 0 taken 148047 times.
✓ Branch 1 taken 916005 times.
✓ Branch 2 taken 25847 times.
✓ Branch 3 taken 122200 times.
✓ Branch 4 taken 2627 times.
✓ Branch 5 taken 23220 times.
|
1064052 | if (h->DPB[i].f->buf[0] && !h->DPB[i].reference && |
| 124 |
2/2✓ Branch 0 taken 737 times.
✓ Branch 1 taken 1890 times.
|
2627 | (remove_current || &h->DPB[i] != h->cur_pic_ptr)) { |
| 125 | 23957 | ff_h264_unref_picture(&h->DPB[i]); | |
| 126 | } | ||
| 127 | } | ||
| 128 | 29557 | } | |
| 129 | |||
| 130 | 38042 | static int alloc_scratch_buffers(H264SliceContext *sl, int linesize) | |
| 131 | { | ||
| 132 | 38042 | const H264Context *h = sl->h264; | |
| 133 | 38042 | int alloc_size = FFALIGN(FFABS(linesize) + 32, 32); | |
| 134 | |||
| 135 | 38042 | av_fast_malloc(&sl->bipred_scratchpad, &sl->bipred_scratchpad_allocated, 16 * 6 * alloc_size); | |
| 136 | // edge emu needs blocksize + filter length - 1 | ||
| 137 | // (= 21x21 for H.264) | ||
| 138 | 38042 | av_fast_malloc(&sl->edge_emu_buffer, &sl->edge_emu_buffer_allocated, alloc_size * 2 * 21); | |
| 139 | |||
| 140 | 38042 | av_fast_mallocz(&sl->top_borders[0], &sl->top_borders_allocated[0], | |
| 141 | 38042 | h->mb_width * 16 * 3 * sizeof(uint8_t) * 2); | |
| 142 | 38042 | av_fast_mallocz(&sl->top_borders[1], &sl->top_borders_allocated[1], | |
| 143 | 38042 | h->mb_width * 16 * 3 * sizeof(uint8_t) * 2); | |
| 144 | |||
| 145 |
2/4✓ Branch 0 taken 38042 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38042 times.
✗ Branch 3 not taken.
|
38042 | if (!sl->bipred_scratchpad || !sl->edge_emu_buffer || |
| 146 |
2/4✓ Branch 0 taken 38042 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 38042 times.
|
38042 | !sl->top_borders[0] || !sl->top_borders[1]) { |
| 147 | ✗ | av_freep(&sl->bipred_scratchpad); | |
| 148 | ✗ | av_freep(&sl->edge_emu_buffer); | |
| 149 | ✗ | av_freep(&sl->top_borders[0]); | |
| 150 | ✗ | av_freep(&sl->top_borders[1]); | |
| 151 | |||
| 152 | ✗ | sl->bipred_scratchpad_allocated = 0; | |
| 153 | ✗ | sl->edge_emu_buffer_allocated = 0; | |
| 154 | ✗ | sl->top_borders_allocated[0] = 0; | |
| 155 | ✗ | sl->top_borders_allocated[1] = 0; | |
| 156 | ✗ | return AVERROR(ENOMEM); | |
| 157 | } | ||
| 158 | |||
| 159 | 38042 | return 0; | |
| 160 | } | ||
| 161 | |||
| 162 | 617 | static int init_table_pools(H264Context *h) | |
| 163 | { | ||
| 164 | 617 | const int big_mb_num = h->mb_stride * (h->mb_height + 1) + 1; | |
| 165 | 617 | const int mb_array_size = h->mb_stride * h->mb_height; | |
| 166 | 617 | const int b4_stride = h->mb_width * 4 + 1; | |
| 167 | 617 | const int b4_array_size = b4_stride * h->mb_height * 4; | |
| 168 | |||
| 169 | 617 | h->qscale_table_pool = av_refstruct_pool_alloc(big_mb_num + h->mb_stride, 0); | |
| 170 | 617 | h->mb_type_pool = av_refstruct_pool_alloc((big_mb_num + h->mb_stride) * | |
| 171 | sizeof(uint32_t), 0); | ||
| 172 | 617 | h->motion_val_pool = av_refstruct_pool_alloc(2 * (b4_array_size + 4) * | |
| 173 | sizeof(int16_t), 0); | ||
| 174 | 617 | h->ref_index_pool = av_refstruct_pool_alloc(4 * mb_array_size, 0); | |
| 175 | |||
| 176 |
3/6✓ Branch 0 taken 617 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 617 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 617 times.
✗ Branch 5 not taken.
|
617 | if (!h->qscale_table_pool || !h->mb_type_pool || !h->motion_val_pool || |
| 177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 617 times.
|
617 | !h->ref_index_pool) { |
| 178 | ✗ | av_refstruct_pool_uninit(&h->qscale_table_pool); | |
| 179 | ✗ | av_refstruct_pool_uninit(&h->mb_type_pool); | |
| 180 | ✗ | av_refstruct_pool_uninit(&h->motion_val_pool); | |
| 181 | ✗ | av_refstruct_pool_uninit(&h->ref_index_pool); | |
| 182 | ✗ | return AVERROR(ENOMEM); | |
| 183 | } | ||
| 184 | |||
| 185 | 617 | return 0; | |
| 186 | } | ||
| 187 | |||
| 188 | 26139 | static int alloc_picture(H264Context *h, H264Picture *pic) | |
| 189 | { | ||
| 190 | 26139 | int i, ret = 0; | |
| 191 | |||
| 192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26139 times.
|
26139 | av_assert0(!pic->f->data[0]); |
| 193 | |||
| 194 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26139 times.
|
26139 | if (h->sei.common.lcevc.info) { |
| 195 | ✗ | HEVCSEILCEVC *lcevc = &h->sei.common.lcevc; | |
| 196 | ✗ | ret = ff_frame_new_side_data_from_buf(h->avctx, pic->f, AV_FRAME_DATA_LCEVC, &lcevc->info); | |
| 197 | ✗ | if (ret < 0) | |
| 198 | ✗ | return ret; | |
| 199 | } | ||
| 200 | |||
| 201 | 26139 | pic->tf.f = pic->f; | |
| 202 | 26139 | ret = ff_thread_get_ext_buffer(h->avctx, &pic->tf, | |
| 203 | 26139 | pic->reference ? AV_GET_BUFFER_FLAG_REF : 0); | |
| 204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26139 times.
|
26139 | if (ret < 0) |
| 205 | ✗ | goto fail; | |
| 206 | |||
| 207 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26139 times.
|
26139 | if (pic->needs_fg) { |
| 208 | ✗ | pic->f_grain->format = pic->f->format; | |
| 209 | ✗ | pic->f_grain->width = pic->f->width; | |
| 210 | ✗ | pic->f_grain->height = pic->f->height; | |
| 211 | ✗ | ret = ff_thread_get_buffer(h->avctx, pic->f_grain, 0); | |
| 212 | ✗ | if (ret < 0) | |
| 213 | ✗ | goto fail; | |
| 214 | } | ||
| 215 | |||
| 216 | 26139 | ret = ff_hwaccel_frame_priv_alloc(h->avctx, &pic->hwaccel_picture_private); | |
| 217 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26139 times.
|
26139 | if (ret < 0) |
| 218 | ✗ | goto fail; | |
| 219 | |||
| 220 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 26097 times.
|
26139 | if (h->decode_error_flags_pool) { |
| 221 | 42 | pic->decode_error_flags = av_refstruct_pool_get(h->decode_error_flags_pool); | |
| 222 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | if (!pic->decode_error_flags) |
| 223 | ✗ | goto fail; | |
| 224 | 42 | atomic_init(pic->decode_error_flags, 0); | |
| 225 | } | ||
| 226 | |||
| 227 | if (CONFIG_GRAY && !h->avctx->hwaccel && h->flags & AV_CODEC_FLAG_GRAY && pic->f->data[2]) { | ||
| 228 | int h_chroma_shift, v_chroma_shift; | ||
| 229 | av_pix_fmt_get_chroma_sub_sample(pic->f->format, | ||
| 230 | &h_chroma_shift, &v_chroma_shift); | ||
| 231 | |||
| 232 | for(i=0; i<AV_CEIL_RSHIFT(pic->f->height, v_chroma_shift); i++) { | ||
| 233 | memset(pic->f->data[1] + pic->f->linesize[1]*i, | ||
| 234 | 0x80, AV_CEIL_RSHIFT(pic->f->width, h_chroma_shift)); | ||
| 235 | memset(pic->f->data[2] + pic->f->linesize[2]*i, | ||
| 236 | 0x80, AV_CEIL_RSHIFT(pic->f->width, h_chroma_shift)); | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 |
2/2✓ Branch 0 taken 617 times.
✓ Branch 1 taken 25522 times.
|
26139 | if (!h->qscale_table_pool) { |
| 241 | 617 | ret = init_table_pools(h); | |
| 242 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 617 times.
|
617 | if (ret < 0) |
| 243 | ✗ | goto fail; | |
| 244 | } | ||
| 245 | |||
| 246 | 26139 | pic->qscale_table_base = av_refstruct_pool_get(h->qscale_table_pool); | |
| 247 | 26139 | pic->mb_type_base = av_refstruct_pool_get(h->mb_type_pool); | |
| 248 |
2/4✓ Branch 0 taken 26139 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26139 times.
|
26139 | if (!pic->qscale_table_base || !pic->mb_type_base) |
| 249 | ✗ | goto fail; | |
| 250 | |||
| 251 | 26139 | pic->mb_type = pic->mb_type_base + 2 * h->mb_stride + 1; | |
| 252 | 26139 | pic->qscale_table = pic->qscale_table_base + 2 * h->mb_stride + 1; | |
| 253 | |||
| 254 |
2/2✓ Branch 0 taken 52278 times.
✓ Branch 1 taken 26139 times.
|
78417 | for (i = 0; i < 2; i++) { |
| 255 | 52278 | pic->motion_val_base[i] = av_refstruct_pool_get(h->motion_val_pool); | |
| 256 | 52278 | pic->ref_index[i] = av_refstruct_pool_get(h->ref_index_pool); | |
| 257 |
2/4✓ Branch 0 taken 52278 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 52278 times.
|
52278 | if (!pic->motion_val_base[i] || !pic->ref_index[i]) |
| 258 | ✗ | goto fail; | |
| 259 | |||
| 260 | 52278 | pic->motion_val[i] = pic->motion_val_base[i] + 4; | |
| 261 | } | ||
| 262 | |||
| 263 | 26139 | pic->pps = av_refstruct_ref_c(h->ps.pps); | |
| 264 | |||
| 265 | 26139 | pic->mb_width = h->mb_width; | |
| 266 | 26139 | pic->mb_height = h->mb_height; | |
| 267 | 26139 | pic->mb_stride = h->mb_stride; | |
| 268 | |||
| 269 | 26139 | return 0; | |
| 270 | ✗ | fail: | |
| 271 | ✗ | ff_h264_unref_picture(pic); | |
| 272 | ✗ | return (ret < 0) ? ret : AVERROR(ENOMEM); | |
| 273 | } | ||
| 274 | |||
| 275 | 26139 | static int find_unused_picture(const H264Context *h) | |
| 276 | { | ||
| 277 | int i; | ||
| 278 | |||
| 279 |
1/2✓ Branch 0 taken 88226 times.
✗ Branch 1 not taken.
|
88226 | for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { |
| 280 |
2/2✓ Branch 0 taken 26139 times.
✓ Branch 1 taken 62087 times.
|
88226 | if (!h->DPB[i].f->buf[0]) |
| 281 | 26139 | return i; | |
| 282 | } | ||
| 283 | ✗ | return AVERROR_INVALIDDATA; | |
| 284 | } | ||
| 285 | |||
| 286 | |||
| 287 | #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size)))) | ||
| 288 | |||
| 289 | #define REBASE_PICTURE(pic, new_ctx, old_ctx) \ | ||
| 290 | (((pic) && (pic) >= (old_ctx)->DPB && \ | ||
| 291 | (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \ | ||
| 292 | &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL) | ||
| 293 | |||
| 294 | 174 | static void copy_picture_range(H264Picture **to, H264Picture *const *from, int count, | |
| 295 | H264Context *new_base, const H264Context *old_base) | ||
| 296 | { | ||
| 297 | int i; | ||
| 298 | |||
| 299 |
2/2✓ Branch 0 taken 4756 times.
✓ Branch 1 taken 174 times.
|
4930 | for (i = 0; i < count; i++) { |
| 300 | av_assert1(!from[i] || | ||
| 301 | IN_RANGE(from[i], old_base, 1) || | ||
| 302 | IN_RANGE(from[i], old_base->DPB, H264_MAX_PICTURE_COUNT)); | ||
| 303 |
4/6✓ Branch 0 taken 251 times.
✓ Branch 1 taken 4505 times.
✓ Branch 2 taken 251 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
|
4756 | to[i] = REBASE_PICTURE(from[i], new_base, old_base); |
| 304 | } | ||
| 305 | 174 | } | |
| 306 | |||
| 307 | 26 | static void color_frame(AVFrame *frame, const int c[4]) | |
| 308 | { | ||
| 309 | 26 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); | |
| 310 | |||
| 311 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | av_assert0(desc->flags & AV_PIX_FMT_FLAG_PLANAR); |
| 312 | |||
| 313 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 26 times.
|
104 | for (int p = 0; p < desc->nb_components; p++) { |
| 314 | 78 | uint8_t *dst = frame->data[p]; | |
| 315 |
4/4✓ Branch 0 taken 52 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 26 times.
|
78 | int is_chroma = p == 1 || p == 2; |
| 316 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 26 times.
|
78 | int bytes = is_chroma ? AV_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width; |
| 317 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 26 times.
|
78 | int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height; |
| 318 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
|
78 | if (desc->comp[0].depth >= 9) { |
| 319 | ✗ | ((uint16_t*)dst)[0] = c[p]; | |
| 320 | ✗ | av_memcpy_backptr(dst + 2, 2, bytes - 2); | |
| 321 | ✗ | dst += frame->linesize[p]; | |
| 322 | ✗ | for (int y = 1; y < height; y++) { | |
| 323 | ✗ | memcpy(dst, frame->data[p], 2*bytes); | |
| 324 | ✗ | dst += frame->linesize[p]; | |
| 325 | } | ||
| 326 | } else { | ||
| 327 |
2/2✓ Branch 0 taken 31168 times.
✓ Branch 1 taken 78 times.
|
31246 | for (int y = 0; y < height; y++) { |
| 328 | 31168 | memset(dst, c[p], bytes); | |
| 329 | 31168 | dst += frame->linesize[p]; | |
| 330 | } | ||
| 331 | } | ||
| 332 | } | ||
| 333 | 26 | } | |
| 334 | |||
| 335 | static int h264_slice_header_init(H264Context *h); | ||
| 336 | |||
| 337 | 58 | int ff_h264_update_thread_context(AVCodecContext *dst, | |
| 338 | const AVCodecContext *src) | ||
| 339 | { | ||
| 340 | 58 | H264Context *h = dst->priv_data, *h1 = src->priv_data; | |
| 341 | 58 | int inited = h->context_initialized, err = 0; | |
| 342 | 58 | int need_reinit = 0; | |
| 343 | int i, ret; | ||
| 344 | |||
| 345 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (dst == src) |
| 346 | ✗ | return 0; | |
| 347 | |||
| 348 |
3/4✓ Branch 0 taken 42 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 42 times.
|
58 | if (inited && !h1->ps.sps) |
| 349 | ✗ | return AVERROR_INVALIDDATA; | |
| 350 | |||
| 351 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 16 times.
|
58 | if (inited && |
| 352 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | (h->width != h1->width || |
| 353 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->height != h1->height || |
| 354 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->mb_width != h1->mb_width || |
| 355 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->mb_height != h1->mb_height || |
| 356 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | !h->ps.sps || |
| 357 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma || |
| 358 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc || |
| 359 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | h->ps.sps->vui.matrix_coeffs != h1->ps.sps->vui.matrix_coeffs)) { |
| 360 | ✗ | need_reinit = 1; | |
| 361 | } | ||
| 362 | |||
| 363 | /* copy block_offset since frame_start may not be called */ | ||
| 364 | 58 | memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset)); | |
| 365 | |||
| 366 | // SPS/PPS | ||
| 367 |
2/2✓ Branch 0 taken 1856 times.
✓ Branch 1 taken 58 times.
|
1914 | for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) |
| 368 | 1856 | av_refstruct_replace(&h->ps.sps_list[i], h1->ps.sps_list[i]); | |
| 369 |
2/2✓ Branch 0 taken 14848 times.
✓ Branch 1 taken 58 times.
|
14906 | for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) |
| 370 | 14848 | av_refstruct_replace(&h->ps.pps_list[i], h1->ps.pps_list[i]); | |
| 371 | |||
| 372 | 58 | av_refstruct_replace(&h->ps.pps, h1->ps.pps); | |
| 373 | 58 | h->ps.sps = h1->ps.sps; | |
| 374 | |||
| 375 |
3/4✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 42 times.
|
58 | if (need_reinit || !inited) { |
| 376 | 16 | h->width = h1->width; | |
| 377 | 16 | h->height = h1->height; | |
| 378 | 16 | h->mb_height = h1->mb_height; | |
| 379 | 16 | h->mb_width = h1->mb_width; | |
| 380 | 16 | h->mb_num = h1->mb_num; | |
| 381 | 16 | h->mb_stride = h1->mb_stride; | |
| 382 | 16 | h->b_stride = h1->b_stride; | |
| 383 | 16 | h->x264_build = h1->x264_build; | |
| 384 | |||
| 385 |
2/4✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 | if (h->context_initialized || h1->context_initialized) { |
| 386 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
|
16 | if ((err = h264_slice_header_init(h)) < 0) { |
| 387 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed"); | |
| 388 | ✗ | return err; | |
| 389 | } | ||
| 390 | } | ||
| 391 | |||
| 392 | /* copy block_offset since frame_start may not be called */ | ||
| 393 | 16 | memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset)); | |
| 394 | } | ||
| 395 | |||
| 396 | 58 | h->width_from_caller = h1->width_from_caller; | |
| 397 | 58 | h->height_from_caller = h1->height_from_caller; | |
| 398 | 58 | h->first_field = h1->first_field; | |
| 399 | 58 | h->picture_structure = h1->picture_structure; | |
| 400 | 58 | h->mb_aff_frame = h1->mb_aff_frame; | |
| 401 | 58 | h->droppable = h1->droppable; | |
| 402 | |||
| 403 |
2/2✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 58 times.
|
2146 | for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { |
| 404 | 2088 | ret = ff_h264_replace_picture(&h->DPB[i], &h1->DPB[i]); | |
| 405 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2088 times.
|
2088 | if (ret < 0) |
| 406 | ✗ | return ret; | |
| 407 | } | ||
| 408 | |||
| 409 |
4/6✓ Branch 0 taken 42 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
|
58 | h->cur_pic_ptr = REBASE_PICTURE(h1->cur_pic_ptr, h, h1); |
| 410 | 58 | ret = ff_h264_replace_picture(&h->cur_pic, &h1->cur_pic); | |
| 411 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (ret < 0) |
| 412 | ✗ | return ret; | |
| 413 | |||
| 414 | 58 | h->enable_er = h1->enable_er; | |
| 415 | 58 | h->workaround_bugs = h1->workaround_bugs; | |
| 416 | 58 | h->droppable = h1->droppable; | |
| 417 | |||
| 418 | // extradata/NAL handling | ||
| 419 | 58 | h->is_avc = h1->is_avc; | |
| 420 | 58 | h->nal_length_size = h1->nal_length_size; | |
| 421 | |||
| 422 | 58 | memcpy(&h->poc, &h1->poc, sizeof(h->poc)); | |
| 423 | |||
| 424 | 58 | memcpy(h->short_ref, h1->short_ref, sizeof(h->short_ref)); | |
| 425 | 58 | memcpy(h->long_ref, h1->long_ref, sizeof(h->long_ref)); | |
| 426 | 58 | memcpy(h->delayed_pic, h1->delayed_pic, sizeof(h->delayed_pic)); | |
| 427 | 58 | memcpy(h->last_pocs, h1->last_pocs, sizeof(h->last_pocs)); | |
| 428 | |||
| 429 | 58 | h->next_output_pic = h1->next_output_pic; | |
| 430 | 58 | h->next_outputed_poc = h1->next_outputed_poc; | |
| 431 | 58 | h->poc_offset = h1->poc_offset; | |
| 432 | |||
| 433 | 58 | memcpy(h->mmco, h1->mmco, sizeof(h->mmco)); | |
| 434 | 58 | h->nb_mmco = h1->nb_mmco; | |
| 435 | 58 | h->mmco_reset = h1->mmco_reset; | |
| 436 | 58 | h->explicit_ref_marking = h1->explicit_ref_marking; | |
| 437 | 58 | h->long_ref_count = h1->long_ref_count; | |
| 438 | 58 | h->short_ref_count = h1->short_ref_count; | |
| 439 | |||
| 440 | 58 | copy_picture_range(h->short_ref, h1->short_ref, 32, h, h1); | |
| 441 | 58 | copy_picture_range(h->long_ref, h1->long_ref, 32, h, h1); | |
| 442 | 58 | copy_picture_range(h->delayed_pic, h1->delayed_pic, | |
| 443 | FF_ARRAY_ELEMS(h->delayed_pic), h, h1); | ||
| 444 | |||
| 445 | 58 | h->frame_recovered = h1->frame_recovered; | |
| 446 | |||
| 447 | 58 | ret = ff_h2645_sei_ctx_replace(&h->sei.common, &h1->sei.common); | |
| 448 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (ret < 0) |
| 449 | ✗ | return ret; | |
| 450 | |||
| 451 | 58 | h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build; | |
| 452 | |||
| 453 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 42 times.
|
58 | if (!h->cur_pic_ptr) |
| 454 | 16 | return 0; | |
| 455 | |||
| 456 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 15 times.
|
42 | if (!h->droppable) { |
| 457 | 27 | err = ff_h264_execute_ref_pic_marking(h); | |
| 458 | 27 | h->poc.prev_poc_msb = h->poc.poc_msb; | |
| 459 | 27 | h->poc.prev_poc_lsb = h->poc.poc_lsb; | |
| 460 | } | ||
| 461 | 42 | h->poc.prev_frame_num_offset = h->poc.frame_num_offset; | |
| 462 | 42 | h->poc.prev_frame_num = h->poc.frame_num; | |
| 463 | |||
| 464 | 42 | h->recovery_frame = h1->recovery_frame; | |
| 465 | 42 | h->non_gray = h1->non_gray; | |
| 466 | |||
| 467 | 42 | return err; | |
| 468 | } | ||
| 469 | |||
| 470 | 46 | int ff_h264_update_thread_context_for_user(AVCodecContext *dst, | |
| 471 | const AVCodecContext *src) | ||
| 472 | { | ||
| 473 | 46 | H264Context *h = dst->priv_data; | |
| 474 | 46 | const H264Context *h1 = src->priv_data; | |
| 475 | |||
| 476 | 46 | h->is_avc = h1->is_avc; | |
| 477 | 46 | h->nal_length_size = h1->nal_length_size; | |
| 478 | |||
| 479 | 46 | return 0; | |
| 480 | } | ||
| 481 | |||
| 482 | 26139 | static int h264_frame_start(H264Context *h) | |
| 483 | { | ||
| 484 | H264Picture *pic; | ||
| 485 | int i, ret; | ||
| 486 | 26139 | const int pixel_shift = h->pixel_shift; | |
| 487 | |||
| 488 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26139 times.
|
26139 | if (!ff_thread_can_start_frame(h->avctx)) { |
| 489 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n"); | |
| 490 | ✗ | return AVERROR_BUG; | |
| 491 | } | ||
| 492 | |||
| 493 | 26139 | release_unused_pictures(h, 1); | |
| 494 | 26139 | h->cur_pic_ptr = NULL; | |
| 495 | |||
| 496 | 26139 | i = find_unused_picture(h); | |
| 497 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26139 times.
|
26139 | if (i < 0) { |
| 498 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "no frame buffer available\n"); | |
| 499 | ✗ | return i; | |
| 500 | } | ||
| 501 | 26139 | pic = &h->DPB[i]; | |
| 502 | |||
| 503 |
2/2✓ Branch 0 taken 18007 times.
✓ Branch 1 taken 8132 times.
|
26139 | pic->reference = h->droppable ? 0 : h->picture_structure; |
| 504 | 26139 | pic->field_picture = h->picture_structure != PICT_FRAME; | |
| 505 | 26139 | pic->frame_num = h->poc.frame_num; | |
| 506 | /* | ||
| 507 | * Zero key_frame here; IDR markings per slice in frame or fields are ORed | ||
| 508 | * in later. | ||
| 509 | * See decode_nal_units(). | ||
| 510 | */ | ||
| 511 | 26139 | pic->f->flags &= ~AV_FRAME_FLAG_KEY; | |
| 512 | 26139 | pic->mmco_reset = 0; | |
| 513 | 26139 | pic->recovered = 0; | |
| 514 | 26139 | pic->invalid_gap = 0; | |
| 515 | 26139 | pic->sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt; | |
| 516 | |||
| 517 | 26139 | pic->f->pict_type = h->slice_ctx[0].slice_type; | |
| 518 | |||
| 519 | 26139 | pic->f->crop_left = h->crop_left; | |
| 520 | 26139 | pic->f->crop_right = h->crop_right; | |
| 521 | 26139 | pic->f->crop_top = h->crop_top; | |
| 522 | 26139 | pic->f->crop_bottom = h->crop_bottom; | |
| 523 | |||
| 524 | 26139 | pic->needs_fg = | |
| 525 | 26139 | h->sei.common.film_grain_characteristics && | |
| 526 | ✗ | h->sei.common.film_grain_characteristics->present && | |
| 527 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 26139 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
26139 | !h->avctx->hwaccel && |
| 528 | ✗ | !(h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN); | |
| 529 | |||
| 530 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26139 times.
|
26139 | if ((ret = alloc_picture(h, pic)) < 0) |
| 531 | ✗ | return ret; | |
| 532 | |||
| 533 | 26139 | h->cur_pic_ptr = pic; | |
| 534 | 26139 | ff_h264_unref_picture(&h->cur_pic); | |
| 535 | if (CONFIG_ERROR_RESILIENCE) { | ||
| 536 | 26139 | ff_h264_set_erpic(&h->er.cur_pic, NULL); | |
| 537 | } | ||
| 538 | |||
| 539 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26139 times.
|
26139 | if ((ret = ff_h264_ref_picture(&h->cur_pic, h->cur_pic_ptr)) < 0) |
| 540 | ✗ | return ret; | |
| 541 | |||
| 542 |
2/2✓ Branch 0 taken 26439 times.
✓ Branch 1 taken 26139 times.
|
52578 | for (i = 0; i < h->nb_slice_ctx; i++) { |
| 543 | 26439 | h->slice_ctx[i].linesize = h->cur_pic_ptr->f->linesize[0]; | |
| 544 | 26439 | h->slice_ctx[i].uvlinesize = h->cur_pic_ptr->f->linesize[1]; | |
| 545 | } | ||
| 546 | |||
| 547 |
2/2✓ Branch 0 taken 25839 times.
✓ Branch 1 taken 300 times.
|
26139 | if (CONFIG_ERROR_RESILIENCE && h->enable_er) { |
| 548 | 25839 | ff_er_frame_start(&h->er); | |
| 549 | 25839 | ff_h264_set_erpic(&h->er.last_pic, NULL); | |
| 550 | 25839 | ff_h264_set_erpic(&h->er.next_pic, NULL); | |
| 551 | } | ||
| 552 | |||
| 553 |
2/2✓ Branch 0 taken 418224 times.
✓ Branch 1 taken 26139 times.
|
444363 | for (i = 0; i < 16; i++) { |
| 554 | 418224 | h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3); | |
| 555 | 418224 | h->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3); | |
| 556 | } | ||
| 557 |
2/2✓ Branch 0 taken 418224 times.
✓ Branch 1 taken 26139 times.
|
444363 | for (i = 0; i < 16; i++) { |
| 558 | 418224 | h->block_offset[16 + i] = | |
| 559 | 418224 | h->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3); | |
| 560 | 418224 | h->block_offset[48 + 16 + i] = | |
| 561 | 418224 | h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3); | |
| 562 | } | ||
| 563 | |||
| 564 | /* We mark the current picture as non-reference after allocating it, so | ||
| 565 | * that if we break out due to an error it can be released automatically | ||
| 566 | * in the next ff_mpv_frame_start(). | ||
| 567 | */ | ||
| 568 | 26139 | h->cur_pic_ptr->reference = 0; | |
| 569 | |||
| 570 | 26139 | h->cur_pic_ptr->field_poc[0] = h->cur_pic_ptr->field_poc[1] = INT_MAX; | |
| 571 | |||
| 572 | 26139 | h->next_output_pic = NULL; | |
| 573 | |||
| 574 | 26139 | h->postpone_filter = 0; | |
| 575 | |||
| 576 |
4/4✓ Branch 0 taken 2871 times.
✓ Branch 1 taken 23268 times.
✓ Branch 2 taken 2358 times.
✓ Branch 3 taken 513 times.
|
26139 | h->mb_aff_frame = h->ps.sps->mb_aff && (h->picture_structure == PICT_FRAME); |
| 577 | |||
| 578 |
2/2✓ Branch 0 taken 2072 times.
✓ Branch 1 taken 24067 times.
|
26139 | if (h->sei.common.unregistered.x264_build >= 0) |
| 579 | 2072 | h->x264_build = h->sei.common.unregistered.x264_build; | |
| 580 | |||
| 581 | assert(h->cur_pic_ptr->long_ref == 0); | ||
| 582 | |||
| 583 | 26139 | return 0; | |
| 584 | } | ||
| 585 | |||
| 586 | 12803158 | static av_always_inline void backup_mb_border(const H264Context *h, H264SliceContext *sl, | |
| 587 | const uint8_t *src_y, | ||
| 588 | const uint8_t *src_cb, const uint8_t *src_cr, | ||
| 589 | int linesize, int uvlinesize, | ||
| 590 | int simple) | ||
| 591 | { | ||
| 592 | uint8_t *top_border; | ||
| 593 | 12803158 | int top_idx = 1; | |
| 594 | 12803158 | const int pixel_shift = h->pixel_shift; | |
| 595 | 12803158 | int chroma444 = CHROMA444(h); | |
| 596 | 12803158 | int chroma422 = CHROMA422(h); | |
| 597 | |||
| 598 | 12803158 | src_y -= linesize; | |
| 599 | 12803158 | src_cb -= uvlinesize; | |
| 600 | 12803158 | src_cr -= uvlinesize; | |
| 601 | |||
| 602 |
3/4✓ Branch 0 taken 12803158 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2023440 times.
✓ Branch 3 taken 10779718 times.
|
12803158 | if (!simple && FRAME_MBAFF(h)) { |
| 603 |
2/2✓ Branch 0 taken 1011720 times.
✓ Branch 1 taken 1011720 times.
|
2023440 | if (sl->mb_y & 1) { |
| 604 |
2/2✓ Branch 0 taken 748050 times.
✓ Branch 1 taken 263670 times.
|
1011720 | if (!MB_MBAFF(sl)) { |
| 605 | 748050 | top_border = sl->top_borders[0][sl->mb_x]; | |
| 606 | 748050 | AV_COPY128(top_border, src_y + 15 * linesize); | |
| 607 |
2/2✓ Branch 0 taken 213139 times.
✓ Branch 1 taken 534911 times.
|
748050 | if (pixel_shift) |
| 608 | 213139 | AV_COPY128(top_border + 16, src_y + 15 * linesize + 16); | |
| 609 | if (simple || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) { | ||
| 610 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 748050 times.
|
748050 | if (chroma444) { |
| 611 | ✗ | if (pixel_shift) { | |
| 612 | ✗ | AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize); | |
| 613 | ✗ | AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16); | |
| 614 | ✗ | AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize); | |
| 615 | ✗ | AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16); | |
| 616 | } else { | ||
| 617 | ✗ | AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize); | |
| 618 | ✗ | AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize); | |
| 619 | } | ||
| 620 |
2/2✓ Branch 0 taken 106510 times.
✓ Branch 1 taken 641540 times.
|
748050 | } else if (chroma422) { |
| 621 |
1/2✓ Branch 0 taken 106510 times.
✗ Branch 1 not taken.
|
106510 | if (pixel_shift) { |
| 622 | 106510 | AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize); | |
| 623 | 106510 | AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize); | |
| 624 | } else { | ||
| 625 | ✗ | AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize); | |
| 626 | ✗ | AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize); | |
| 627 | } | ||
| 628 | } else { | ||
| 629 |
2/2✓ Branch 0 taken 106629 times.
✓ Branch 1 taken 534911 times.
|
641540 | if (pixel_shift) { |
| 630 | 106629 | AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize); | |
| 631 | 106629 | AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize); | |
| 632 | } else { | ||
| 633 | 534911 | AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize); | |
| 634 | 534911 | AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize); | |
| 635 | } | ||
| 636 | } | ||
| 637 | } | ||
| 638 | } | ||
| 639 |
2/2✓ Branch 0 taken 263670 times.
✓ Branch 1 taken 748050 times.
|
1011720 | } else if (MB_MBAFF(sl)) { |
| 640 | 263670 | top_idx = 0; | |
| 641 | } else | ||
| 642 | 748050 | return; | |
| 643 | } | ||
| 644 | |||
| 645 | 12055108 | top_border = sl->top_borders[top_idx][sl->mb_x]; | |
| 646 | /* There are two lines saved, the line above the top macroblock | ||
| 647 | * of a pair, and the line above the bottom macroblock. */ | ||
| 648 | 12055108 | AV_COPY128(top_border, src_y + 16 * linesize); | |
| 649 |
2/2✓ Branch 0 taken 1389541 times.
✓ Branch 1 taken 10665567 times.
|
12055108 | if (pixel_shift) |
| 650 | 1389541 | AV_COPY128(top_border + 16, src_y + 16 * linesize + 16); | |
| 651 | |||
| 652 | if (simple || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) { | ||
| 653 |
2/2✓ Branch 0 taken 80328 times.
✓ Branch 1 taken 11974780 times.
|
12055108 | if (chroma444) { |
| 654 |
2/2✓ Branch 0 taken 19800 times.
✓ Branch 1 taken 60528 times.
|
80328 | if (pixel_shift) { |
| 655 | 19800 | AV_COPY128(top_border + 32, src_cb + 16 * linesize); | |
| 656 | 19800 | AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16); | |
| 657 | 19800 | AV_COPY128(top_border + 64, src_cr + 16 * linesize); | |
| 658 | 19800 | AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16); | |
| 659 | } else { | ||
| 660 | 60528 | AV_COPY128(top_border + 16, src_cb + 16 * linesize); | |
| 661 | 60528 | AV_COPY128(top_border + 32, src_cr + 16 * linesize); | |
| 662 | } | ||
| 663 |
2/2✓ Branch 0 taken 588635 times.
✓ Branch 1 taken 11386145 times.
|
11974780 | } else if (chroma422) { |
| 664 |
2/2✓ Branch 0 taken 584675 times.
✓ Branch 1 taken 3960 times.
|
588635 | if (pixel_shift) { |
| 665 | 584675 | AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize); | |
| 666 | 584675 | AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize); | |
| 667 | } else { | ||
| 668 | 3960 | AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize); | |
| 669 | 3960 | AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize); | |
| 670 | } | ||
| 671 | } else { | ||
| 672 |
2/2✓ Branch 0 taken 785066 times.
✓ Branch 1 taken 10601079 times.
|
11386145 | if (pixel_shift) { |
| 673 | 785066 | AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize); | |
| 674 | 785066 | AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize); | |
| 675 | } else { | ||
| 676 | 10601079 | AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize); | |
| 677 | 10601079 | AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize); | |
| 678 | } | ||
| 679 | } | ||
| 680 | } | ||
| 681 | } | ||
| 682 | |||
| 683 | /** | ||
| 684 | * Initialize implicit_weight table. | ||
| 685 | * @param field 0/1 initialize the weight for interlaced MBAFF | ||
| 686 | * -1 initializes the rest | ||
| 687 | */ | ||
| 688 | 4019 | static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, int field) | |
| 689 | { | ||
| 690 | int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1; | ||
| 691 | |||
| 692 |
2/2✓ Branch 0 taken 8038 times.
✓ Branch 1 taken 4019 times.
|
12057 | for (i = 0; i < 2; i++) { |
| 693 | 8038 | sl->pwt.luma_weight_flag[i] = 0; | |
| 694 | 8038 | sl->pwt.chroma_weight_flag[i] = 0; | |
| 695 | } | ||
| 696 | |||
| 697 |
2/2✓ Branch 0 taken 2307 times.
✓ Branch 1 taken 1712 times.
|
4019 | if (field < 0) { |
| 698 |
1/2✓ Branch 0 taken 2307 times.
✗ Branch 1 not taken.
|
2307 | if (h->picture_structure == PICT_FRAME) { |
| 699 | 2307 | cur_poc = h->cur_pic_ptr->poc; | |
| 700 | } else { | ||
| 701 | ✗ | cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure - 1]; | |
| 702 | } | ||
| 703 |
6/6✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 1176 times.
✓ Branch 2 taken 821 times.
✓ Branch 3 taken 310 times.
✓ Branch 4 taken 811 times.
✓ Branch 5 taken 10 times.
|
2307 | if (sl->ref_count[0] == 1 && sl->ref_count[1] == 1 && !FRAME_MBAFF(h) && |
| 704 |
2/2✓ Branch 0 taken 543 times.
✓ Branch 1 taken 268 times.
|
811 | sl->ref_list[0][0].poc + (int64_t)sl->ref_list[1][0].poc == 2LL * cur_poc) { |
| 705 | 543 | sl->pwt.use_weight = 0; | |
| 706 | 543 | sl->pwt.use_weight_chroma = 0; | |
| 707 | 543 | return; | |
| 708 | } | ||
| 709 | 1764 | ref_start = 0; | |
| 710 | 1764 | ref_count0 = sl->ref_count[0]; | |
| 711 | 1764 | ref_count1 = sl->ref_count[1]; | |
| 712 | } else { | ||
| 713 | 1712 | cur_poc = h->cur_pic_ptr->field_poc[field]; | |
| 714 | 1712 | ref_start = 16; | |
| 715 | 1712 | ref_count0 = 16 + 2 * sl->ref_count[0]; | |
| 716 | 1712 | ref_count1 = 16 + 2 * sl->ref_count[1]; | |
| 717 | } | ||
| 718 | |||
| 719 | 3476 | sl->pwt.use_weight = 2; | |
| 720 | 3476 | sl->pwt.use_weight_chroma = 2; | |
| 721 | 3476 | sl->pwt.luma_log2_weight_denom = 5; | |
| 722 | 3476 | sl->pwt.chroma_log2_weight_denom = 5; | |
| 723 | |||
| 724 |
2/2✓ Branch 0 taken 11846 times.
✓ Branch 1 taken 3476 times.
|
15322 | for (ref0 = ref_start; ref0 < ref_count0; ref0++) { |
| 725 | 11846 | int64_t poc0 = sl->ref_list[0][ref0].poc; | |
| 726 |
2/2✓ Branch 0 taken 21947 times.
✓ Branch 1 taken 11846 times.
|
33793 | for (ref1 = ref_start; ref1 < ref_count1; ref1++) { |
| 727 | 21947 | int w = 32; | |
| 728 |
2/4✓ Branch 0 taken 21947 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21947 times.
✗ Branch 3 not taken.
|
21947 | if (!sl->ref_list[0][ref0].parent->long_ref && !sl->ref_list[1][ref1].parent->long_ref) { |
| 729 | 21947 | int poc1 = sl->ref_list[1][ref1].poc; | |
| 730 | 21947 | int td = av_clip_int8(poc1 - poc0); | |
| 731 |
2/2✓ Branch 0 taken 21880 times.
✓ Branch 1 taken 67 times.
|
21947 | if (td) { |
| 732 | 21880 | int tb = av_clip_int8(cur_poc - poc0); | |
| 733 | 21880 | int tx = (16384 + (FFABS(td) >> 1)) / td; | |
| 734 | 21880 | int dist_scale_factor = (tb * tx + 32) >> 8; | |
| 735 |
3/4✓ Branch 0 taken 21868 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 21868 times.
✗ Branch 3 not taken.
|
21880 | if (dist_scale_factor >= -64 && dist_scale_factor <= 128) |
| 736 | 21868 | w = 64 - dist_scale_factor; | |
| 737 | } | ||
| 738 | } | ||
| 739 |
2/2✓ Branch 0 taken 6043 times.
✓ Branch 1 taken 15904 times.
|
21947 | if (field < 0) { |
| 740 | 6043 | sl->pwt.implicit_weight[ref0][ref1][0] = | |
| 741 | 6043 | sl->pwt.implicit_weight[ref0][ref1][1] = w; | |
| 742 | } else { | ||
| 743 | 15904 | sl->pwt.implicit_weight[ref0][ref1][field] = w; | |
| 744 | } | ||
| 745 | } | ||
| 746 | } | ||
| 747 | } | ||
| 748 | |||
| 749 | /** | ||
| 750 | * initialize scan tables | ||
| 751 | */ | ||
| 752 | 617 | static void init_scan_tables(H264Context *h) | |
| 753 | { | ||
| 754 | int i; | ||
| 755 |
2/2✓ Branch 0 taken 9872 times.
✓ Branch 1 taken 617 times.
|
10489 | for (i = 0; i < 16; i++) { |
| 756 | #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF) | ||
| 757 | 9872 | h->zigzag_scan[i] = TRANSPOSE(ff_zigzag_scan[i]); | |
| 758 | 9872 | h->field_scan[i] = TRANSPOSE(field_scan[i]); | |
| 759 | #undef TRANSPOSE | ||
| 760 | } | ||
| 761 |
2/2✓ Branch 0 taken 39488 times.
✓ Branch 1 taken 617 times.
|
40105 | for (i = 0; i < 64; i++) { |
| 762 | #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3) | ||
| 763 | 39488 | h->zigzag_scan8x8[i] = TRANSPOSE(ff_zigzag_direct[i]); | |
| 764 | 39488 | h->zigzag_scan8x8_cavlc[i] = TRANSPOSE(zigzag_scan8x8_cavlc[i]); | |
| 765 | 39488 | h->field_scan8x8[i] = TRANSPOSE(field_scan8x8[i]); | |
| 766 | 39488 | h->field_scan8x8_cavlc[i] = TRANSPOSE(field_scan8x8_cavlc[i]); | |
| 767 | #undef TRANSPOSE | ||
| 768 | } | ||
| 769 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 603 times.
|
617 | if (h->ps.sps->transform_bypass) { // FIXME same ugly |
| 770 | 14 | memcpy(h->zigzag_scan_q0 , ff_zigzag_scan , sizeof(h->zigzag_scan_q0 )); | |
| 771 | 14 | memcpy(h->zigzag_scan8x8_q0 , ff_zigzag_direct , sizeof(h->zigzag_scan8x8_q0 )); | |
| 772 | 14 | memcpy(h->zigzag_scan8x8_cavlc_q0 , zigzag_scan8x8_cavlc , sizeof(h->zigzag_scan8x8_cavlc_q0)); | |
| 773 | 14 | memcpy(h->field_scan_q0 , field_scan , sizeof(h->field_scan_q0 )); | |
| 774 | 14 | memcpy(h->field_scan8x8_q0 , field_scan8x8 , sizeof(h->field_scan8x8_q0 )); | |
| 775 | 14 | memcpy(h->field_scan8x8_cavlc_q0 , field_scan8x8_cavlc , sizeof(h->field_scan8x8_cavlc_q0 )); | |
| 776 | } else { | ||
| 777 | 603 | memcpy(h->zigzag_scan_q0 , h->zigzag_scan , sizeof(h->zigzag_scan_q0 )); | |
| 778 | 603 | memcpy(h->zigzag_scan8x8_q0 , h->zigzag_scan8x8 , sizeof(h->zigzag_scan8x8_q0 )); | |
| 779 | 603 | memcpy(h->zigzag_scan8x8_cavlc_q0 , h->zigzag_scan8x8_cavlc , sizeof(h->zigzag_scan8x8_cavlc_q0)); | |
| 780 | 603 | memcpy(h->field_scan_q0 , h->field_scan , sizeof(h->field_scan_q0 )); | |
| 781 | 603 | memcpy(h->field_scan8x8_q0 , h->field_scan8x8 , sizeof(h->field_scan8x8_q0 )); | |
| 782 | 603 | memcpy(h->field_scan8x8_cavlc_q0 , h->field_scan8x8_cavlc , sizeof(h->field_scan8x8_cavlc_q0 )); | |
| 783 | } | ||
| 784 | 617 | } | |
| 785 | |||
| 786 | 29129 | static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) | |
| 787 | { | ||
| 788 | #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \ | ||
| 789 | (CONFIG_H264_D3D11VA_HWACCEL * 2) + \ | ||
| 790 | CONFIG_H264_D3D12VA_HWACCEL + \ | ||
| 791 | CONFIG_H264_NVDEC_HWACCEL + \ | ||
| 792 | CONFIG_H264_VAAPI_HWACCEL + \ | ||
| 793 | CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \ | ||
| 794 | CONFIG_H264_VDPAU_HWACCEL + \ | ||
| 795 | CONFIG_H264_VULKAN_HWACCEL) | ||
| 796 | 29129 | enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts; | |
| 797 | |||
| 798 |
3/6✓ Branch 0 taken 155 times.
✓ Branch 1 taken 373 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 28601 times.
✗ Branch 5 not taken.
|
29129 | switch (h->ps.sps->bit_depth_luma) { |
| 799 | 155 | case 9: | |
| 800 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 155 times.
|
155 | if (CHROMA444(h)) { |
| 801 | ✗ | if (h->avctx->colorspace == AVCOL_SPC_RGB) { | |
| 802 | ✗ | *fmt++ = AV_PIX_FMT_GBRP9; | |
| 803 | } else | ||
| 804 | ✗ | *fmt++ = AV_PIX_FMT_YUV444P9; | |
| 805 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 103 times.
|
155 | } else if (CHROMA422(h)) |
| 806 | 52 | *fmt++ = AV_PIX_FMT_YUV422P9; | |
| 807 | else | ||
| 808 | 103 | *fmt++ = AV_PIX_FMT_YUV420P9; | |
| 809 | 155 | break; | |
| 810 | 373 | case 10: | |
| 811 | #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL | ||
| 812 | if (h->avctx->colorspace != AVCOL_SPC_RGB) | ||
| 813 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
| 814 | #endif | ||
| 815 | #if CONFIG_H264_VULKAN_HWACCEL | ||
| 816 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
| 817 | #endif | ||
| 818 | #if CONFIG_H264_NVDEC_HWACCEL | ||
| 819 | *fmt++ = AV_PIX_FMT_CUDA; | ||
| 820 | #endif | ||
| 821 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 322 times.
|
373 | if (CHROMA444(h)) { |
| 822 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
|
51 | if (h->avctx->colorspace == AVCOL_SPC_RGB) { |
| 823 | ✗ | *fmt++ = AV_PIX_FMT_GBRP10; | |
| 824 | } else | ||
| 825 | 51 | *fmt++ = AV_PIX_FMT_YUV444P10; | |
| 826 |
2/2✓ Branch 0 taken 164 times.
✓ Branch 1 taken 158 times.
|
322 | } else if (CHROMA422(h)) |
| 827 | 164 | *fmt++ = AV_PIX_FMT_YUV422P10; | |
| 828 | else { | ||
| 829 | #if CONFIG_H264_VAAPI_HWACCEL | ||
| 830 | // Just add as candidate. Whether VAProfileH264High10 usable or | ||
| 831 | // not is decided by vaapi_decode_make_config() defined in FFmpeg | ||
| 832 | // and vaQueryCodingProfile() defined in libva. | ||
| 833 | 158 | *fmt++ = AV_PIX_FMT_VAAPI; | |
| 834 | #endif | ||
| 835 | 158 | *fmt++ = AV_PIX_FMT_YUV420P10; | |
| 836 | } | ||
| 837 | 373 | break; | |
| 838 | ✗ | case 12: | |
| 839 | #if CONFIG_H264_VULKAN_HWACCEL | ||
| 840 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
| 841 | #endif | ||
| 842 | ✗ | if (CHROMA444(h)) { | |
| 843 | ✗ | if (h->avctx->colorspace == AVCOL_SPC_RGB) { | |
| 844 | ✗ | *fmt++ = AV_PIX_FMT_GBRP12; | |
| 845 | } else | ||
| 846 | ✗ | *fmt++ = AV_PIX_FMT_YUV444P12; | |
| 847 | ✗ | } else if (CHROMA422(h)) | |
| 848 | ✗ | *fmt++ = AV_PIX_FMT_YUV422P12; | |
| 849 | else | ||
| 850 | ✗ | *fmt++ = AV_PIX_FMT_YUV420P12; | |
| 851 | ✗ | break; | |
| 852 | ✗ | case 14: | |
| 853 | ✗ | if (CHROMA444(h)) { | |
| 854 | ✗ | if (h->avctx->colorspace == AVCOL_SPC_RGB) { | |
| 855 | ✗ | *fmt++ = AV_PIX_FMT_GBRP14; | |
| 856 | } else | ||
| 857 | ✗ | *fmt++ = AV_PIX_FMT_YUV444P14; | |
| 858 | ✗ | } else if (CHROMA422(h)) | |
| 859 | ✗ | *fmt++ = AV_PIX_FMT_YUV422P14; | |
| 860 | else | ||
| 861 | ✗ | *fmt++ = AV_PIX_FMT_YUV420P14; | |
| 862 | ✗ | break; | |
| 863 | 28601 | case 8: | |
| 864 | #if CONFIG_H264_VDPAU_HWACCEL | ||
| 865 | 28601 | *fmt++ = AV_PIX_FMT_VDPAU; | |
| 866 | #endif | ||
| 867 | #if CONFIG_H264_VULKAN_HWACCEL | ||
| 868 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
| 869 | #endif | ||
| 870 | #if CONFIG_H264_NVDEC_HWACCEL | ||
| 871 | *fmt++ = AV_PIX_FMT_CUDA; | ||
| 872 | #endif | ||
| 873 | #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL | ||
| 874 | if (h->avctx->colorspace != AVCOL_SPC_RGB) | ||
| 875 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
| 876 | #endif | ||
| 877 |
2/2✓ Branch 0 taken 484 times.
✓ Branch 1 taken 28117 times.
|
28601 | if (CHROMA444(h)) { |
| 878 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 484 times.
|
484 | if (h->avctx->colorspace == AVCOL_SPC_RGB) |
| 879 | ✗ | *fmt++ = AV_PIX_FMT_GBRP; | |
| 880 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 482 times.
|
484 | else if (h->avctx->color_range == AVCOL_RANGE_JPEG) |
| 881 | 2 | *fmt++ = AV_PIX_FMT_YUVJ444P; | |
| 882 | else | ||
| 883 | 482 | *fmt++ = AV_PIX_FMT_YUV444P; | |
| 884 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 28095 times.
|
28117 | } else if (CHROMA422(h)) { |
| 885 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | if (h->avctx->color_range == AVCOL_RANGE_JPEG) |
| 886 | ✗ | *fmt++ = AV_PIX_FMT_YUVJ422P; | |
| 887 | else | ||
| 888 | 22 | *fmt++ = AV_PIX_FMT_YUV422P; | |
| 889 | } else { | ||
| 890 | #if CONFIG_H264_DXVA2_HWACCEL | ||
| 891 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
| 892 | #endif | ||
| 893 | #if CONFIG_H264_D3D11VA_HWACCEL | ||
| 894 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
| 895 | *fmt++ = AV_PIX_FMT_D3D11; | ||
| 896 | #endif | ||
| 897 | #if CONFIG_H264_D3D12VA_HWACCEL | ||
| 898 | *fmt++ = AV_PIX_FMT_D3D12; | ||
| 899 | #endif | ||
| 900 | #if CONFIG_H264_VAAPI_HWACCEL | ||
| 901 | 28095 | *fmt++ = AV_PIX_FMT_VAAPI; | |
| 902 | #endif | ||
| 903 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28092 times.
|
28095 | if (h->avctx->color_range == AVCOL_RANGE_JPEG) |
| 904 | 3 | *fmt++ = AV_PIX_FMT_YUVJ420P; | |
| 905 | else | ||
| 906 | 28092 | *fmt++ = AV_PIX_FMT_YUV420P; | |
| 907 | } | ||
| 908 | 28601 | break; | |
| 909 | ✗ | default: | |
| 910 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 911 | ✗ | "Unsupported bit depth %d\n", h->ps.sps->bit_depth_luma); | |
| 912 | ✗ | return AVERROR_INVALIDDATA; | |
| 913 | } | ||
| 914 | |||
| 915 | 29129 | *fmt = AV_PIX_FMT_NONE; | |
| 916 | |||
| 917 |
2/2✓ Branch 0 taken 85983 times.
✓ Branch 1 taken 601 times.
|
86584 | for (int i = 0; pix_fmts[i] != AV_PIX_FMT_NONE; i++) |
| 918 |
4/4✓ Branch 0 taken 28783 times.
✓ Branch 1 taken 57200 times.
✓ Branch 2 taken 28528 times.
✓ Branch 3 taken 255 times.
|
85983 | if (pix_fmts[i] == h->avctx->pix_fmt && !force_callback) |
| 919 | 28528 | return pix_fmts[i]; | |
| 920 | 601 | return ff_get_format(h->avctx, pix_fmts); | |
| 921 | } | ||
| 922 | |||
| 923 | /* export coded and cropped frame dimensions to AVCodecContext */ | ||
| 924 | 28868 | static void init_dimensions(H264Context *h) | |
| 925 | { | ||
| 926 | 28868 | const SPS *sps = h->ps.sps; | |
| 927 | 28868 | int cr = sps->crop_right; | |
| 928 | 28868 | int cl = sps->crop_left; | |
| 929 | 28868 | int ct = sps->crop_top; | |
| 930 | 28868 | int cb = sps->crop_bottom; | |
| 931 | 28868 | int width = h->width - (cr + cl); | |
| 932 | 28868 | int height = h->height - (ct + cb); | |
| 933 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28868 times.
|
28868 | av_assert0(sps->crop_right + sps->crop_left < (unsigned)h->width); |
| 934 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28868 times.
|
28868 | av_assert0(sps->crop_top + sps->crop_bottom < (unsigned)h->height); |
| 935 | |||
| 936 | /* handle container cropping */ | ||
| 937 |
3/4✓ Branch 0 taken 26610 times.
✓ Branch 1 taken 2258 times.
✓ Branch 2 taken 26610 times.
✗ Branch 3 not taken.
|
28868 | if (h->width_from_caller > 0 && h->height_from_caller > 0 && |
| 938 |
3/4✓ Branch 0 taken 26609 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 26609 times.
✗ Branch 3 not taken.
|
26610 | !sps->crop_top && !sps->crop_left && |
| 939 |
2/2✓ Branch 0 taken 26598 times.
✓ Branch 1 taken 11 times.
|
26609 | FFALIGN(h->width_from_caller, 16) == FFALIGN(width, 16) && |
| 940 |
1/2✓ Branch 0 taken 26598 times.
✗ Branch 1 not taken.
|
26598 | FFALIGN(h->height_from_caller, 16) == FFALIGN(height, 16) && |
| 941 |
2/2✓ Branch 0 taken 26597 times.
✓ Branch 1 taken 1 times.
|
26598 | h->width_from_caller <= width && |
| 942 |
2/2✓ Branch 0 taken 26589 times.
✓ Branch 1 taken 8 times.
|
26597 | h->height_from_caller <= height) { |
| 943 | 26589 | width = h->width_from_caller; | |
| 944 | 26589 | height = h->height_from_caller; | |
| 945 | 26589 | cl = 0; | |
| 946 | 26589 | ct = 0; | |
| 947 | 26589 | cr = h->width - width; | |
| 948 | 26589 | cb = h->height - height; | |
| 949 | } else { | ||
| 950 | 2279 | h->width_from_caller = 0; | |
| 951 | 2279 | h->height_from_caller = 0; | |
| 952 | } | ||
| 953 | |||
| 954 | 28868 | h->avctx->coded_width = h->width; | |
| 955 | 28868 | h->avctx->coded_height = h->height; | |
| 956 | 28868 | h->avctx->width = width; | |
| 957 | 28868 | h->avctx->height = height; | |
| 958 | 28868 | h->crop_right = cr; | |
| 959 | 28868 | h->crop_left = cl; | |
| 960 | 28868 | h->crop_top = ct; | |
| 961 | 28868 | h->crop_bottom = cb; | |
| 962 | 28868 | } | |
| 963 | |||
| 964 | 617 | static int h264_slice_header_init(H264Context *h) | |
| 965 | { | ||
| 966 | 617 | const SPS *sps = h->ps.sps; | |
| 967 | int i, ret; | ||
| 968 | |||
| 969 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 617 times.
|
617 | if (!sps) { |
| 970 | ✗ | ret = AVERROR_INVALIDDATA; | |
| 971 | ✗ | goto fail; | |
| 972 | } | ||
| 973 | |||
| 974 | 617 | ff_set_sar(h->avctx, sps->vui.sar); | |
| 975 | 617 | av_pix_fmt_get_chroma_sub_sample(h->avctx->pix_fmt, | |
| 976 | &h->chroma_x_shift, &h->chroma_y_shift); | ||
| 977 | |||
| 978 |
2/2✓ Branch 0 taken 197 times.
✓ Branch 1 taken 420 times.
|
617 | if (sps->timing_info_present_flag) { |
| 979 | 197 | int64_t den = sps->time_scale; | |
| 980 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 197 times.
|
197 | if (h->x264_build < 44U) |
| 981 | ✗ | den *= 2; | |
| 982 | 197 | av_reduce(&h->avctx->framerate.den, &h->avctx->framerate.num, | |
| 983 | 197 | sps->num_units_in_tick * 2, den, 1 << 30); | |
| 984 | } | ||
| 985 | |||
| 986 | 617 | ff_h264_free_tables(h); | |
| 987 | |||
| 988 | 617 | h->first_field = 0; | |
| 989 | 617 | h->prev_interlaced_frame = 1; | |
| 990 | |||
| 991 | 617 | init_scan_tables(h); | |
| 992 | 617 | ret = ff_h264_alloc_tables(h); | |
| 993 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 617 times.
|
617 | if (ret < 0) { |
| 994 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Could not allocate memory\n"); | |
| 995 | ✗ | goto fail; | |
| 996 | } | ||
| 997 | |||
| 998 |
2/4✓ Branch 0 taken 617 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 617 times.
✗ Branch 3 not taken.
|
617 | if (sps->bit_depth_luma < 8 || sps->bit_depth_luma > 14 || |
| 999 |
2/4✓ Branch 0 taken 617 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 617 times.
|
617 | sps->bit_depth_luma == 11 || sps->bit_depth_luma == 13 |
| 1000 | ) { | ||
| 1001 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth %d\n", | |
| 1002 | ✗ | sps->bit_depth_luma); | |
| 1003 | ✗ | ret = AVERROR_INVALIDDATA; | |
| 1004 | ✗ | goto fail; | |
| 1005 | } | ||
| 1006 | |||
| 1007 | 617 | h->cur_bit_depth_luma = | |
| 1008 | 617 | h->avctx->bits_per_raw_sample = sps->bit_depth_luma; | |
| 1009 | 617 | h->cur_chroma_format_idc = sps->chroma_format_idc; | |
| 1010 | 617 | h->pixel_shift = sps->bit_depth_luma > 8; | |
| 1011 | 617 | h->chroma_format_idc = sps->chroma_format_idc; | |
| 1012 | 617 | h->bit_depth_luma = sps->bit_depth_luma; | |
| 1013 | |||
| 1014 | 617 | ff_h264dsp_init(&h->h264dsp, sps->bit_depth_luma, | |
| 1015 | 617 | sps->chroma_format_idc); | |
| 1016 | 617 | ff_h264chroma_init(&h->h264chroma, sps->bit_depth_chroma); | |
| 1017 | 617 | ff_h264qpel_init(&h->h264qpel, sps->bit_depth_luma); | |
| 1018 | 617 | ff_h264_pred_init(&h->hpc, AV_CODEC_ID_H264, sps->bit_depth_luma, | |
| 1019 | 617 | sps->chroma_format_idc); | |
| 1020 | 617 | ff_videodsp_init(&h->vdsp, sps->bit_depth_luma); | |
| 1021 | |||
| 1022 |
2/2✓ Branch 0 taken 616 times.
✓ Branch 1 taken 1 times.
|
617 | if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_SLICE)) { |
| 1023 | 616 | ff_h264_slice_context_init(h, &h->slice_ctx[0]); | |
| 1024 | } else { | ||
| 1025 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (i = 0; i < h->nb_slice_ctx; i++) { |
| 1026 | 2 | H264SliceContext *sl = &h->slice_ctx[i]; | |
| 1027 | |||
| 1028 | 2 | sl->h264 = h; | |
| 1029 | 2 | sl->intra4x4_pred_mode = h->intra4x4_pred_mode + i * 8 * 2 * h->mb_stride; | |
| 1030 | 2 | sl->mvd_table[0] = h->mvd_table[0] + i * 8 * 2 * h->mb_stride; | |
| 1031 | 2 | sl->mvd_table[1] = h->mvd_table[1] + i * 8 * 2 * h->mb_stride; | |
| 1032 | |||
| 1033 | 2 | ff_h264_slice_context_init(h, sl); | |
| 1034 | } | ||
| 1035 | } | ||
| 1036 | |||
| 1037 | 617 | h->context_initialized = 1; | |
| 1038 | |||
| 1039 | 617 | return 0; | |
| 1040 | ✗ | fail: | |
| 1041 | ✗ | ff_h264_free_tables(h); | |
| 1042 | ✗ | h->context_initialized = 0; | |
| 1043 | ✗ | return ret; | |
| 1044 | } | ||
| 1045 | |||
| 1046 | 57056 | static enum AVPixelFormat non_j_pixfmt(enum AVPixelFormat a) | |
| 1047 | { | ||
| 1048 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57054 times.
|
57056 | switch (a) { |
| 1049 | 2 | case AV_PIX_FMT_YUVJ420P: return AV_PIX_FMT_YUV420P; | |
| 1050 | ✗ | case AV_PIX_FMT_YUVJ422P: return AV_PIX_FMT_YUV422P; | |
| 1051 | ✗ | case AV_PIX_FMT_YUVJ444P: return AV_PIX_FMT_YUV444P; | |
| 1052 | 57054 | default: | |
| 1053 | 57054 | return a; | |
| 1054 | } | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | 28868 | static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_slice) | |
| 1058 | { | ||
| 1059 | const SPS *sps; | ||
| 1060 | 28868 | int needs_reinit = 0, must_reinit, ret; | |
| 1061 | |||
| 1062 |
2/2✓ Branch 0 taken 28673 times.
✓ Branch 1 taken 195 times.
|
28868 | if (first_slice) |
| 1063 | 28673 | av_refstruct_replace(&h->ps.pps, h->ps.pps_list[sl->pps_id]); | |
| 1064 | |||
| 1065 |
2/2✓ Branch 0 taken 603 times.
✓ Branch 1 taken 28265 times.
|
28868 | if (h->ps.sps != h->ps.pps->sps) { |
| 1066 | 603 | h->ps.sps = h->ps.pps->sps; | |
| 1067 | |||
| 1068 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 596 times.
|
603 | if (h->mb_width != h->ps.sps->mb_width || |
| 1069 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | h->mb_height != h->ps.sps->mb_height || |
| 1070 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
|
7 | h->cur_bit_depth_luma != h->ps.sps->bit_depth_luma || |
| 1071 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
|
6 | h->cur_chroma_format_idc != h->ps.sps->chroma_format_idc |
| 1072 | ) | ||
| 1073 | 598 | needs_reinit = 1; | |
| 1074 | |||
| 1075 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 592 times.
|
603 | if (h->bit_depth_luma != h->ps.sps->bit_depth_luma || |
| 1076 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
|
11 | h->chroma_format_idc != h->ps.sps->chroma_format_idc) |
| 1077 | 593 | needs_reinit = 1; | |
| 1078 | } | ||
| 1079 | 28868 | sps = h->ps.sps; | |
| 1080 | |||
| 1081 |
2/2✓ Branch 0 taken 28275 times.
✓ Branch 1 taken 593 times.
|
57143 | must_reinit = (h->context_initialized && |
| 1082 |
2/2✓ Branch 0 taken 28269 times.
✓ Branch 1 taken 6 times.
|
28275 | ( 16*sps->mb_width != h->avctx->coded_width |
| 1083 |
1/2✓ Branch 0 taken 28269 times.
✗ Branch 1 not taken.
|
28269 | || 16*sps->mb_height != h->avctx->coded_height |
| 1084 |
2/2✓ Branch 0 taken 28268 times.
✓ Branch 1 taken 1 times.
|
28269 | || h->cur_bit_depth_luma != sps->bit_depth_luma |
| 1085 |
2/2✓ Branch 0 taken 28267 times.
✓ Branch 1 taken 1 times.
|
28268 | || h->cur_chroma_format_idc != sps->chroma_format_idc |
| 1086 |
1/2✓ Branch 0 taken 28267 times.
✗ Branch 1 not taken.
|
28267 | || h->mb_width != sps->mb_width |
| 1087 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28267 times.
|
28267 | || h->mb_height != sps->mb_height |
| 1088 | )); | ||
| 1089 |
2/2✓ Branch 0 taken 28528 times.
✓ Branch 1 taken 340 times.
|
28868 | if (h->avctx->pix_fmt == AV_PIX_FMT_NONE |
| 1090 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 28525 times.
|
28528 | || (non_j_pixfmt(h->avctx->pix_fmt) != non_j_pixfmt(get_pixel_format(h, 0)))) |
| 1091 | 343 | must_reinit = 1; | |
| 1092 | |||
| 1093 |
4/4✓ Branch 0 taken 28673 times.
✓ Branch 1 taken 195 times.
✓ Branch 3 taken 81 times.
✓ Branch 4 taken 28592 times.
|
28868 | if (first_slice && av_cmp_q(sps->vui.sar, h->avctx->sample_aspect_ratio)) |
| 1094 | 81 | must_reinit = 1; | |
| 1095 | |||
| 1096 |
1/2✓ Branch 0 taken 28868 times.
✗ Branch 1 not taken.
|
28868 | if (!h->setup_finished) { |
| 1097 | 28868 | h->avctx->profile = ff_h264_get_profile(sps); | |
| 1098 | 28868 | h->avctx->level = sps->level_idc; | |
| 1099 | 28868 | h->avctx->refs = sps->ref_frame_count; | |
| 1100 | |||
| 1101 | 28868 | h->mb_width = sps->mb_width; | |
| 1102 | 28868 | h->mb_height = sps->mb_height; | |
| 1103 | 28868 | h->mb_num = h->mb_width * h->mb_height; | |
| 1104 | 28868 | h->mb_stride = h->mb_width + 1; | |
| 1105 | |||
| 1106 | 28868 | h->b_stride = h->mb_width * 4; | |
| 1107 | |||
| 1108 | 28868 | h->chroma_y_shift = sps->chroma_format_idc <= 1; // 400 uses yuv420p | |
| 1109 | |||
| 1110 | 28868 | h->width = 16 * h->mb_width; | |
| 1111 | 28868 | h->height = 16 * h->mb_height; | |
| 1112 | |||
| 1113 | 28868 | init_dimensions(h); | |
| 1114 | |||
| 1115 |
2/2✓ Branch 0 taken 1288 times.
✓ Branch 1 taken 27580 times.
|
28868 | if (sps->vui.video_signal_type_present_flag) { |
| 1116 | 2576 | h->avctx->color_range = sps->vui.video_full_range_flag > 0 ? AVCOL_RANGE_JPEG | |
| 1117 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1286 times.
|
1288 | : AVCOL_RANGE_MPEG; |
| 1118 |
2/2✓ Branch 0 taken 1190 times.
✓ Branch 1 taken 98 times.
|
1288 | if (sps->vui.colour_description_present_flag) { |
| 1119 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1171 times.
|
1190 | if (h->avctx->colorspace != sps->vui.matrix_coeffs) |
| 1120 | 19 | needs_reinit = 1; | |
| 1121 | 1190 | h->avctx->color_primaries = sps->vui.colour_primaries; | |
| 1122 | 1190 | h->avctx->color_trc = sps->vui.transfer_characteristics; | |
| 1123 | 1190 | h->avctx->colorspace = sps->vui.matrix_coeffs; | |
| 1124 | } | ||
| 1125 | } | ||
| 1126 | |||
| 1127 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28868 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
28868 | if (h->sei.common.alternative_transfer.present && |
| 1128 | ✗ | av_color_transfer_name(h->sei.common.alternative_transfer.preferred_transfer_characteristics) && | |
| 1129 | ✗ | h->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) { | |
| 1130 | ✗ | h->avctx->color_trc = h->sei.common.alternative_transfer.preferred_transfer_characteristics; | |
| 1131 | } | ||
| 1132 | } | ||
| 1133 | 28868 | h->avctx->chroma_sample_location = sps->vui.chroma_location; | |
| 1134 | |||
| 1135 |
5/6✓ Branch 0 taken 28275 times.
✓ Branch 1 taken 593 times.
✓ Branch 2 taken 28267 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 28267 times.
|
28868 | if (!h->context_initialized || must_reinit || needs_reinit) { |
| 1136 | 601 | int flush_changes = h->context_initialized; | |
| 1137 | 601 | h->context_initialized = 0; | |
| 1138 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | if (sl != h->slice_ctx) { |
| 1139 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 1140 | "changing width %d -> %d / height %d -> %d on " | ||
| 1141 | "slice %d\n", | ||
| 1142 | ✗ | h->width, h->avctx->coded_width, | |
| 1143 | ✗ | h->height, h->avctx->coded_height, | |
| 1144 | ✗ | h->current_slice + 1); | |
| 1145 | ✗ | return AVERROR_INVALIDDATA; | |
| 1146 | } | ||
| 1147 | |||
| 1148 | av_assert1(first_slice); | ||
| 1149 | |||
| 1150 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 593 times.
|
601 | if (flush_changes) |
| 1151 | 8 | ff_h264_flush_change(h); | |
| 1152 | |||
| 1153 |
5/6✓ Branch 0 taken 250 times.
✓ Branch 1 taken 351 times.
✓ Branch 2 taken 247 times.
✓ Branch 3 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 601 times.
|
601 | if ((ret = get_pixel_format(h, must_reinit || needs_reinit)) < 0) |
| 1154 | ✗ | return ret; | |
| 1155 | 601 | h->avctx->pix_fmt = ret; | |
| 1156 | |||
| 1157 | 601 | av_log(h->avctx, AV_LOG_VERBOSE, "Reinit context to %dx%d, " | |
| 1158 | 601 | "pix_fmt: %s\n", h->width, h->height, av_get_pix_fmt_name(h->avctx->pix_fmt)); | |
| 1159 | |||
| 1160 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 601 times.
|
601 | if ((ret = h264_slice_header_init(h)) < 0) { |
| 1161 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 1162 | "h264_slice_header_init() failed\n"); | ||
| 1163 | ✗ | return ret; | |
| 1164 | } | ||
| 1165 | } | ||
| 1166 | |||
| 1167 | 28868 | return 0; | |
| 1168 | } | ||
| 1169 | |||
| 1170 | 25444 | static int h264_export_frame_props(H264Context *h) | |
| 1171 | { | ||
| 1172 | 25444 | const SPS *sps = h->ps.sps; | |
| 1173 | 25444 | H264Picture *cur = h->cur_pic_ptr; | |
| 1174 | 25444 | AVFrame *out = cur->f; | |
| 1175 | 25444 | int interlaced_frame = 0, top_field_first = 0; | |
| 1176 | int ret; | ||
| 1177 | |||
| 1178 | 25444 | out->flags &= ~AV_FRAME_FLAG_INTERLACED; | |
| 1179 | 25444 | out->repeat_pict = 0; | |
| 1180 | |||
| 1181 | /* Signal interlacing information externally. */ | ||
| 1182 | /* Prioritize picture timing SEI information over used | ||
| 1183 | * decoding process if it exists. */ | ||
| 1184 |
2/2✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 24016 times.
|
25444 | if (h->sei.picture_timing.present) { |
| 1185 | 1428 | int ret = ff_h264_sei_process_picture_timing(&h->sei.picture_timing, sps, | |
| 1186 | 1428 | h->avctx); | |
| 1187 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1428 times.
|
1428 | if (ret < 0) { |
| 1188 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Error processing a picture timing SEI\n"); | |
| 1189 | ✗ | if (h->avctx->err_recognition & AV_EF_EXPLODE) | |
| 1190 | ✗ | return ret; | |
| 1191 | ✗ | h->sei.picture_timing.present = 0; | |
| 1192 | } | ||
| 1193 | } | ||
| 1194 | |||
| 1195 |
4/4✓ Branch 0 taken 1506 times.
✓ Branch 1 taken 23938 times.
✓ Branch 2 taken 1420 times.
✓ Branch 3 taken 86 times.
|
26864 | if (sps->pic_struct_present_flag && h->sei.picture_timing.present) { |
| 1196 | 1420 | const H264SEIPictureTiming *pt = &h->sei.picture_timing; | |
| 1197 |
4/7✓ Branch 0 taken 132 times.
✓ Branch 1 taken 378 times.
✓ Branch 2 taken 743 times.
✓ Branch 3 taken 167 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
1420 | switch (pt->pic_struct) { |
| 1198 | 132 | case H264_SEI_PIC_STRUCT_FRAME: | |
| 1199 | 132 | break; | |
| 1200 | 378 | case H264_SEI_PIC_STRUCT_TOP_FIELD: | |
| 1201 | case H264_SEI_PIC_STRUCT_BOTTOM_FIELD: | ||
| 1202 | 378 | interlaced_frame = 1; | |
| 1203 | 378 | break; | |
| 1204 | 743 | case H264_SEI_PIC_STRUCT_TOP_BOTTOM: | |
| 1205 | case H264_SEI_PIC_STRUCT_BOTTOM_TOP: | ||
| 1206 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 739 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
743 | if (FIELD_OR_MBAFF_PICTURE(h)) |
| 1207 | 739 | interlaced_frame = 1; | |
| 1208 | else | ||
| 1209 | // try to flag soft telecine progressive | ||
| 1210 | 4 | interlaced_frame = !!h->prev_interlaced_frame; | |
| 1211 | 743 | break; | |
| 1212 | 167 | case H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP: | |
| 1213 | case H264_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM: | ||
| 1214 | /* Signal the possibility of telecined film externally | ||
| 1215 | * (pic_struct 5,6). From these hints, let the applications | ||
| 1216 | * decide if they apply deinterlacing. */ | ||
| 1217 | 167 | out->repeat_pict = 1; | |
| 1218 | 167 | break; | |
| 1219 | ✗ | case H264_SEI_PIC_STRUCT_FRAME_DOUBLING: | |
| 1220 | ✗ | out->repeat_pict = 2; | |
| 1221 | ✗ | break; | |
| 1222 | ✗ | case H264_SEI_PIC_STRUCT_FRAME_TRIPLING: | |
| 1223 | ✗ | out->repeat_pict = 4; | |
| 1224 | ✗ | break; | |
| 1225 | } | ||
| 1226 | |||
| 1227 |
2/2✓ Branch 0 taken 653 times.
✓ Branch 1 taken 767 times.
|
1420 | if ((pt->ct_type & 3) && |
| 1228 |
2/2✓ Branch 0 taken 489 times.
✓ Branch 1 taken 164 times.
|
653 | pt->pic_struct <= H264_SEI_PIC_STRUCT_BOTTOM_TOP) |
| 1229 | 489 | interlaced_frame = ((pt->ct_type & (1 << 1)) != 0); | |
| 1230 | } else { | ||
| 1231 | /* Derive interlacing flag from used decoding process. */ | ||
| 1232 |
4/4✓ Branch 0 taken 22433 times.
✓ Branch 1 taken 1591 times.
✓ Branch 2 taken 2876 times.
✓ Branch 3 taken 19557 times.
|
24024 | interlaced_frame = !!FIELD_OR_MBAFF_PICTURE(h); |
| 1233 | } | ||
| 1234 | 25444 | h->prev_interlaced_frame = interlaced_frame; | |
| 1235 | |||
| 1236 |
2/2✓ Branch 0 taken 3393 times.
✓ Branch 1 taken 22051 times.
|
25444 | if (cur->field_poc[0] != cur->field_poc[1]) { |
| 1237 | /* Derive top_field_first from field pocs. */ | ||
| 1238 | 3393 | top_field_first = (cur->field_poc[0] < cur->field_poc[1]); | |
| 1239 | } else { | ||
| 1240 |
4/4✓ Branch 0 taken 225 times.
✓ Branch 1 taken 21826 times.
✓ Branch 2 taken 139 times.
✓ Branch 3 taken 86 times.
|
22051 | if (sps->pic_struct_present_flag && h->sei.picture_timing.present) { |
| 1241 | /* Use picture timing SEI information. Even if it is a | ||
| 1242 | * information of a past frame, better than nothing. */ | ||
| 1243 |
2/2✓ Branch 0 taken 138 times.
✓ Branch 1 taken 1 times.
|
139 | if (h->sei.picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM || |
| 1244 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 136 times.
|
138 | h->sei.picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP) |
| 1245 | 3 | top_field_first = 1; | |
| 1246 |
2/2✓ Branch 0 taken 2558 times.
✓ Branch 1 taken 19354 times.
|
21912 | } else if (interlaced_frame) { |
| 1247 | /* Default to top field first when pic_struct_present_flag | ||
| 1248 | * is not set but interlaced frame detected */ | ||
| 1249 | 2558 | top_field_first = 1; | |
| 1250 | } // else | ||
| 1251 | /* Most likely progressive */ | ||
| 1252 | } | ||
| 1253 | |||
| 1254 | 25444 | out->flags |= (AV_FRAME_FLAG_INTERLACED * interlaced_frame) | | |
| 1255 | 25444 | (AV_FRAME_FLAG_TOP_FIELD_FIRST * top_field_first); | |
| 1256 | |||
| 1257 | 25444 | ret = ff_h2645_sei_to_frame(out, &h->sei.common, AV_CODEC_ID_H264, h->avctx, | |
| 1258 | 25444 | &sps->vui, sps->bit_depth_luma, sps->bit_depth_chroma, | |
| 1259 | 25444 | cur->poc + (unsigned)(h->poc_offset << 5)); | |
| 1260 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25444 times.
|
25444 | if (ret < 0) |
| 1261 | ✗ | return ret; | |
| 1262 | |||
| 1263 |
2/2✓ Branch 0 taken 653 times.
✓ Branch 1 taken 24791 times.
|
25444 | if (h->sei.picture_timing.timecode_cnt > 0) { |
| 1264 | uint32_t *tc_sd; | ||
| 1265 | char tcbuf[AV_TIMECODE_STR_SIZE]; | ||
| 1266 | AVFrameSideData *tcside; | ||
| 1267 | 653 | ret = ff_frame_new_side_data(h->avctx, out, AV_FRAME_DATA_S12M_TIMECODE, | |
| 1268 | sizeof(uint32_t)*4, &tcside); | ||
| 1269 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 653 times.
|
653 | if (ret < 0) |
| 1270 | ✗ | return ret; | |
| 1271 | |||
| 1272 |
1/2✓ Branch 0 taken 653 times.
✗ Branch 1 not taken.
|
653 | if (tcside) { |
| 1273 | 653 | tc_sd = (uint32_t*)tcside->data; | |
| 1274 | 653 | tc_sd[0] = h->sei.picture_timing.timecode_cnt; | |
| 1275 | |||
| 1276 |
2/2✓ Branch 0 taken 954 times.
✓ Branch 1 taken 653 times.
|
1607 | for (int i = 0; i < tc_sd[0]; i++) { |
| 1277 | 954 | int drop = h->sei.picture_timing.timecode[i].dropframe; | |
| 1278 | 954 | int hh = h->sei.picture_timing.timecode[i].hours; | |
| 1279 | 954 | int mm = h->sei.picture_timing.timecode[i].minutes; | |
| 1280 | 954 | int ss = h->sei.picture_timing.timecode[i].seconds; | |
| 1281 | 954 | int ff = h->sei.picture_timing.timecode[i].frame; | |
| 1282 | |||
| 1283 | 954 | tc_sd[i + 1] = av_timecode_get_smpte(h->avctx->framerate, drop, hh, mm, ss, ff); | |
| 1284 | 954 | av_timecode_make_smpte_tc_string2(tcbuf, h->avctx->framerate, tc_sd[i + 1], 0, 0); | |
| 1285 | 954 | av_dict_set(&out->metadata, "timecode", tcbuf, 0); | |
| 1286 | } | ||
| 1287 | } | ||
| 1288 | 653 | h->sei.picture_timing.timecode_cnt = 0; | |
| 1289 | } | ||
| 1290 | |||
| 1291 | 25444 | return 0; | |
| 1292 | } | ||
| 1293 | |||
| 1294 | 25444 | static int h264_select_output_frame(H264Context *h) | |
| 1295 | { | ||
| 1296 | 25444 | const SPS *sps = h->ps.sps; | |
| 1297 | 25444 | H264Picture *out = h->cur_pic_ptr; | |
| 1298 | 25444 | H264Picture *cur = h->cur_pic_ptr; | |
| 1299 | int i, pics, out_of_order, out_idx; | ||
| 1300 | |||
| 1301 | 25444 | cur->mmco_reset = h->mmco_reset; | |
| 1302 | 25444 | h->mmco_reset = 0; | |
| 1303 | |||
| 1304 |
2/2✓ Branch 0 taken 20029 times.
✓ Branch 1 taken 5415 times.
|
25444 | if (sps->bitstream_restriction_flag || |
| 1305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20029 times.
|
20029 | h->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT) { |
| 1306 | 5415 | h->avctx->has_b_frames = FFMAX(h->avctx->has_b_frames, sps->num_reorder_frames); | |
| 1307 | } | ||
| 1308 | |||
| 1309 | 417272 | for (i = 0; 1; i++) { | |
| 1310 |
4/4✓ Branch 0 taken 401062 times.
✓ Branch 1 taken 16210 times.
✓ Branch 2 taken 9234 times.
✓ Branch 3 taken 391828 times.
|
417272 | if(i == H264_MAX_DPB_FRAMES || cur->poc < h->last_pocs[i]){ |
| 1311 |
1/2✓ Branch 0 taken 25444 times.
✗ Branch 1 not taken.
|
25444 | if(i) |
| 1312 | 25444 | h->last_pocs[i-1] = cur->poc; | |
| 1313 | 25444 | break; | |
| 1314 |
2/2✓ Branch 0 taken 366384 times.
✓ Branch 1 taken 25444 times.
|
391828 | } else if(i) { |
| 1315 | 366384 | h->last_pocs[i-1]= h->last_pocs[i]; | |
| 1316 | } | ||
| 1317 | } | ||
| 1318 | 25444 | out_of_order = H264_MAX_DPB_FRAMES - i; | |
| 1319 |
2/2✓ Branch 0 taken 17092 times.
✓ Branch 1 taken 8352 times.
|
25444 | if( cur->f->pict_type == AV_PICTURE_TYPE_B |
| 1320 |
4/4✓ Branch 0 taken 15954 times.
✓ Branch 1 taken 1138 times.
✓ Branch 2 taken 5208 times.
✓ Branch 3 taken 10746 times.
|
17092 | || (h->last_pocs[H264_MAX_DPB_FRAMES-2] > INT_MIN && h->last_pocs[H264_MAX_DPB_FRAMES-1] - (int64_t)h->last_pocs[H264_MAX_DPB_FRAMES-2] > 2)) |
| 1321 | 13560 | out_of_order = FFMAX(out_of_order, 1); | |
| 1322 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25444 times.
|
25444 | if (out_of_order == H264_MAX_DPB_FRAMES) { |
| 1323 | ✗ | av_log(h->avctx, AV_LOG_VERBOSE, "Invalid POC %d<%d\n", cur->poc, h->last_pocs[0]); | |
| 1324 | ✗ | for (i = 1; i < H264_MAX_DPB_FRAMES; i++) | |
| 1325 | ✗ | h->last_pocs[i] = INT_MIN; | |
| 1326 | ✗ | h->last_pocs[0] = cur->poc; | |
| 1327 | ✗ | cur->mmco_reset = 1; | |
| 1328 |
3/4✓ Branch 0 taken 141 times.
✓ Branch 1 taken 25303 times.
✓ Branch 2 taken 141 times.
✗ Branch 3 not taken.
|
25444 | } else if(h->avctx->has_b_frames < out_of_order && !sps->bitstream_restriction_flag){ |
| 1329 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 108 times.
|
141 | int loglevel = h->avctx->frame_num > 1 ? AV_LOG_WARNING : AV_LOG_VERBOSE; |
| 1330 | 141 | av_log(h->avctx, loglevel, "Increasing reorder buffer to %d\n", out_of_order); | |
| 1331 | 141 | h->avctx->has_b_frames = out_of_order; | |
| 1332 | } | ||
| 1333 | |||
| 1334 | 25444 | pics = 0; | |
| 1335 |
2/2✓ Branch 0 taken 31186 times.
✓ Branch 1 taken 25444 times.
|
56630 | while (h->delayed_pic[pics]) |
| 1336 | 31186 | pics++; | |
| 1337 | |||
| 1338 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25444 times.
|
25444 | av_assert0(pics <= H264_MAX_DPB_FRAMES); |
| 1339 | |||
| 1340 | 25444 | h->delayed_pic[pics++] = cur; | |
| 1341 |
2/2✓ Branch 0 taken 23916 times.
✓ Branch 1 taken 1528 times.
|
25444 | if (cur->reference == 0) |
| 1342 | 23916 | cur->reference = DELAYED_PIC_REF; | |
| 1343 | |||
| 1344 | 25444 | out = h->delayed_pic[0]; | |
| 1345 | 25444 | out_idx = 0; | |
| 1346 | 25444 | for (i = 1; h->delayed_pic[i] && | |
| 1347 |
4/4✓ Branch 0 taken 28735 times.
✓ Branch 1 taken 24974 times.
✓ Branch 2 taken 28352 times.
✓ Branch 3 taken 383 times.
|
53709 | !(h->delayed_pic[i]->f->flags & AV_FRAME_FLAG_KEY) && |
| 1348 |
2/2✓ Branch 0 taken 28265 times.
✓ Branch 1 taken 87 times.
|
28352 | !h->delayed_pic[i]->mmco_reset; |
| 1349 | 28265 | i++) | |
| 1350 |
2/2✓ Branch 0 taken 10583 times.
✓ Branch 1 taken 17682 times.
|
28265 | if (h->delayed_pic[i]->poc < out->poc) { |
| 1351 | 10583 | out = h->delayed_pic[i]; | |
| 1352 | 10583 | out_idx = i; | |
| 1353 | } | ||
| 1354 |
2/2✓ Branch 0 taken 10261 times.
✓ Branch 1 taken 15183 times.
|
25444 | if (h->avctx->has_b_frames == 0 && |
| 1355 |
4/4✓ Branch 0 taken 9467 times.
✓ Branch 1 taken 794 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 9455 times.
|
10261 | ((h->delayed_pic[0]->f->flags & AV_FRAME_FLAG_KEY) || h->delayed_pic[0]->mmco_reset)) |
| 1356 | 806 | h->next_outputed_poc = INT_MIN; | |
| 1357 | 25444 | out_of_order = out->poc < h->next_outputed_poc; | |
| 1358 | |||
| 1359 |
4/4✓ Branch 0 taken 25331 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 24789 times.
✓ Branch 3 taken 542 times.
|
25444 | if (out_of_order || pics > h->avctx->has_b_frames) { |
| 1360 | 24902 | out->reference &= ~DELAYED_PIC_REF; | |
| 1361 |
2/2✓ Branch 0 taken 40412 times.
✓ Branch 1 taken 24902 times.
|
65314 | for (i = out_idx; h->delayed_pic[i]; i++) |
| 1362 | 40412 | h->delayed_pic[i] = h->delayed_pic[i + 1]; | |
| 1363 | } | ||
| 1364 |
4/4✓ Branch 0 taken 25331 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 24789 times.
✓ Branch 3 taken 542 times.
|
25444 | if (!out_of_order && pics > h->avctx->has_b_frames) { |
| 1365 | 24789 | h->next_output_pic = out; | |
| 1366 |
8/8✓ Branch 0 taken 15777 times.
✓ Branch 1 taken 9012 times.
✓ Branch 2 taken 5517 times.
✓ Branch 3 taken 10260 times.
✓ Branch 4 taken 5430 times.
✓ Branch 5 taken 87 times.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 5409 times.
|
24789 | if (out_idx == 0 && h->delayed_pic[0] && ((h->delayed_pic[0]->f->flags & AV_FRAME_FLAG_KEY) || h->delayed_pic[0]->mmco_reset)) { |
| 1367 | 108 | h->next_outputed_poc = INT_MIN; | |
| 1368 | } else | ||
| 1369 | 24681 | h->next_outputed_poc = out->poc; | |
| 1370 | |||
| 1371 | // We have reached an recovery point and all frames after it in | ||
| 1372 | // display order are "recovered". | ||
| 1373 | 24789 | h->frame_recovered |= out->recovered; | |
| 1374 | |||
| 1375 | 24789 | out->recovered |= h->frame_recovered & FRAME_RECOVERED_SEI; | |
| 1376 | |||
| 1377 |
2/2✓ Branch 0 taken 306 times.
✓ Branch 1 taken 24483 times.
|
24789 | if (!out->recovered) { |
| 1378 |
1/2✓ Branch 0 taken 306 times.
✗ Branch 1 not taken.
|
306 | if (!(h->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) && |
| 1379 |
1/2✓ Branch 0 taken 306 times.
✗ Branch 1 not taken.
|
306 | !(h->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL)) { |
| 1380 | 306 | h->next_output_pic = NULL; | |
| 1381 | } else { | ||
| 1382 | ✗ | out->f->flags |= AV_FRAME_FLAG_CORRUPT; | |
| 1383 | } | ||
| 1384 | } | ||
| 1385 | } else { | ||
| 1386 |
2/2✓ Branch 0 taken 113 times.
✓ Branch 1 taken 542 times.
|
655 | av_log(h->avctx, AV_LOG_DEBUG, "no picture %s\n", out_of_order ? "ooo" : ""); |
| 1387 | } | ||
| 1388 | |||
| 1389 | 25444 | return 0; | |
| 1390 | } | ||
| 1391 | |||
| 1392 | /* This function is called right after decoding the slice header for a first | ||
| 1393 | * slice in a field (or a frame). It decides whether we are decoding a new frame | ||
| 1394 | * or a second field in a pair and does the necessary setup. | ||
| 1395 | */ | ||
| 1396 | 28868 | static int h264_field_start(H264Context *h, const H264SliceContext *sl, | |
| 1397 | const H2645NAL *nal, int first_slice) | ||
| 1398 | { | ||
| 1399 | int i; | ||
| 1400 | const SPS *sps; | ||
| 1401 | |||
| 1402 | int last_pic_structure, last_pic_droppable, ret; | ||
| 1403 | |||
| 1404 | 28868 | ret = h264_init_ps(h, sl, first_slice); | |
| 1405 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28868 times.
|
28868 | if (ret < 0) |
| 1406 | ✗ | return ret; | |
| 1407 | |||
| 1408 | 28868 | sps = h->ps.sps; | |
| 1409 | |||
| 1410 |
2/2✓ Branch 0 taken 5800 times.
✓ Branch 1 taken 23068 times.
|
28868 | if (sps->bitstream_restriction_flag && |
| 1411 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 5762 times.
|
5800 | h->avctx->has_b_frames < sps->num_reorder_frames) { |
| 1412 | 38 | h->avctx->has_b_frames = sps->num_reorder_frames; | |
| 1413 | } | ||
| 1414 | |||
| 1415 | 28868 | last_pic_droppable = h->droppable; | |
| 1416 | 28868 | last_pic_structure = h->picture_structure; | |
| 1417 | 28868 | h->droppable = (nal->ref_idc == 0); | |
| 1418 | 28868 | h->picture_structure = sl->picture_structure; | |
| 1419 | |||
| 1420 | 28868 | h->poc.frame_num = sl->frame_num; | |
| 1421 | 28868 | h->poc.poc_lsb = sl->poc_lsb; | |
| 1422 | 28868 | h->poc.delta_poc_bottom = sl->delta_poc_bottom; | |
| 1423 | 28868 | h->poc.delta_poc[0] = sl->delta_poc[0]; | |
| 1424 | 28868 | h->poc.delta_poc[1] = sl->delta_poc[1]; | |
| 1425 | |||
| 1426 |
2/2✓ Branch 0 taken 1094 times.
✓ Branch 1 taken 27774 times.
|
28868 | if (nal->type == H264_NAL_IDR_SLICE) |
| 1427 | 1094 | h->poc_offset = sl->idr_pic_id; | |
| 1428 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27774 times.
|
27774 | else if (h->picture_intra_only) |
| 1429 | ✗ | h->poc_offset = 0; | |
| 1430 | |||
| 1431 | /* Shorten frame num gaps so we don't have to allocate reference | ||
| 1432 | * frames just to throw them away */ | ||
| 1433 |
2/2✓ Branch 0 taken 16469 times.
✓ Branch 1 taken 12399 times.
|
28868 | if (h->poc.frame_num != h->poc.prev_frame_num) { |
| 1434 | 16469 | int unwrap_prev_frame_num = h->poc.prev_frame_num; | |
| 1435 | 16469 | int max_frame_num = 1 << sps->log2_max_frame_num; | |
| 1436 | |||
| 1437 |
2/2✓ Branch 0 taken 201 times.
✓ Branch 1 taken 16268 times.
|
16469 | if (unwrap_prev_frame_num > h->poc.frame_num) |
| 1438 | 201 | unwrap_prev_frame_num -= max_frame_num; | |
| 1439 | |||
| 1440 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 16393 times.
|
16469 | if ((h->poc.frame_num - unwrap_prev_frame_num) > sps->ref_frame_count) { |
| 1441 | 76 | unwrap_prev_frame_num = (h->poc.frame_num - sps->ref_frame_count) - 1; | |
| 1442 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 74 times.
|
76 | if (unwrap_prev_frame_num < 0) |
| 1443 | 2 | unwrap_prev_frame_num += max_frame_num; | |
| 1444 | |||
| 1445 | 76 | h->poc.prev_frame_num = unwrap_prev_frame_num; | |
| 1446 | } | ||
| 1447 | } | ||
| 1448 | |||
| 1449 | /* See if we have a decoded first field looking for a pair... | ||
| 1450 | * Here, we're using that to see if we should mark previously | ||
| 1451 | * decode frames as "finished". | ||
| 1452 | * We have to do that before the "dummy" in-between frame allocation, | ||
| 1453 | * since that can modify h->cur_pic_ptr. */ | ||
| 1454 |
2/2✓ Branch 0 taken 3418 times.
✓ Branch 1 taken 25450 times.
|
28868 | if (h->first_field) { |
| 1455 | 3418 | int last_field = last_pic_structure == PICT_BOTTOM_FIELD; | |
| 1456 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3418 times.
|
3418 | av_assert0(h->cur_pic_ptr); |
| 1457 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3418 times.
|
3418 | av_assert0(h->cur_pic_ptr->f->buf[0]); |
| 1458 | assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF); | ||
| 1459 | |||
| 1460 | /* Mark old field/frame as completed */ | ||
| 1461 |
1/2✓ Branch 0 taken 3418 times.
✗ Branch 1 not taken.
|
3418 | if (h->cur_pic_ptr->tf.owner[last_field] == h->avctx) { |
| 1462 | 3418 | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_field); | |
| 1463 | } | ||
| 1464 | |||
| 1465 | /* figure out if we have a complementary field pair */ | ||
| 1466 |
2/4✓ Branch 0 taken 3418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3418 times.
|
3418 | if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { |
| 1467 | /* Previous field is unmatched. Don't display it, but let it | ||
| 1468 | * remain for reference if marked as such. */ | ||
| 1469 | ✗ | if (last_pic_structure != PICT_FRAME) { | |
| 1470 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, | |
| 1471 | last_pic_structure == PICT_TOP_FIELD); | ||
| 1472 | } | ||
| 1473 | } else { | ||
| 1474 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3418 times.
|
3418 | if (h->cur_pic_ptr->frame_num != h->poc.frame_num) { |
| 1475 | /* This and previous field were reference, but had | ||
| 1476 | * different frame_nums. Consider this field first in | ||
| 1477 | * pair. Throw away previous field except for reference | ||
| 1478 | * purposes. */ | ||
| 1479 | ✗ | if (last_pic_structure != PICT_FRAME) { | |
| 1480 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, | |
| 1481 | last_pic_structure == PICT_TOP_FIELD); | ||
| 1482 | } | ||
| 1483 | } else { | ||
| 1484 | /* Second field in complementary pair */ | ||
| 1485 |
3/4✓ Branch 0 taken 3410 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
3418 | if (!((last_pic_structure == PICT_TOP_FIELD && |
| 1486 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3410 times.
|
3410 | h->picture_structure == PICT_BOTTOM_FIELD) || |
| 1487 | 8 | (last_pic_structure == PICT_BOTTOM_FIELD && | |
| 1488 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | h->picture_structure == PICT_TOP_FIELD))) { |
| 1489 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 1490 | "Invalid field mode combination %d/%d\n", | ||
| 1491 | last_pic_structure, h->picture_structure); | ||
| 1492 | ✗ | h->picture_structure = last_pic_structure; | |
| 1493 | ✗ | h->droppable = last_pic_droppable; | |
| 1494 | ✗ | return AVERROR_INVALIDDATA; | |
| 1495 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3418 times.
|
3418 | } else if (last_pic_droppable != h->droppable) { |
| 1496 | ✗ | avpriv_request_sample(h->avctx, | |
| 1497 | "Found reference and non-reference fields in the same frame, which"); | ||
| 1498 | ✗ | h->picture_structure = last_pic_structure; | |
| 1499 | ✗ | h->droppable = last_pic_droppable; | |
| 1500 | ✗ | return AVERROR_PATCHWELCOME; | |
| 1501 | } | ||
| 1502 | } | ||
| 1503 | } | ||
| 1504 | } | ||
| 1505 | |||
| 1506 |
3/4✓ Branch 0 taken 17158 times.
✓ Branch 1 taken 12399 times.
✓ Branch 2 taken 17158 times.
✗ Branch 3 not taken.
|
58425 | while (h->poc.frame_num != h->poc.prev_frame_num && !h->first_field && |
| 1507 |
2/2✓ Branch 0 taken 689 times.
✓ Branch 1 taken 16469 times.
|
17158 | h->poc.frame_num != (h->poc.prev_frame_num + 1) % (1 << sps->log2_max_frame_num)) { |
| 1508 |
2/2✓ Branch 0 taken 655 times.
✓ Branch 1 taken 34 times.
|
689 | const H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; |
| 1509 | 689 | av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", | |
| 1510 | h->poc.frame_num, h->poc.prev_frame_num); | ||
| 1511 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 577 times.
|
689 | if (!sps->gaps_in_frame_num_allowed_flag) |
| 1512 |
2/2✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 112 times.
|
1904 | for(i=0; i<FF_ARRAY_ELEMS(h->last_pocs); i++) |
| 1513 | 1792 | h->last_pocs[i] = INT_MIN; | |
| 1514 | 689 | ret = h264_frame_start(h); | |
| 1515 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 689 times.
|
689 | if (ret < 0) { |
| 1516 | ✗ | h->first_field = 0; | |
| 1517 | ✗ | return ret; | |
| 1518 | } | ||
| 1519 | |||
| 1520 | 689 | h->poc.prev_frame_num++; | |
| 1521 | 689 | h->poc.prev_frame_num %= 1 << sps->log2_max_frame_num; | |
| 1522 | 689 | h->cur_pic_ptr->frame_num = h->poc.prev_frame_num; | |
| 1523 | 689 | h->cur_pic_ptr->invalid_gap = !sps->gaps_in_frame_num_allowed_flag; | |
| 1524 | 689 | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); | |
| 1525 | 689 | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); | |
| 1526 | |||
| 1527 | 689 | h->explicit_ref_marking = 0; | |
| 1528 | 689 | ret = ff_h264_execute_ref_pic_marking(h); | |
| 1529 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 689 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
689 | if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) |
| 1530 | ✗ | return ret; | |
| 1531 | /* Error concealment: If a ref is missing, copy the previous ref | ||
| 1532 | * in its place. | ||
| 1533 | * FIXME: Avoiding a memcpy would be nice, but ref handling makes | ||
| 1534 | * many assumptions about there being no actual duplicates. | ||
| 1535 | * FIXME: This does not copy padding for out-of-frame motion | ||
| 1536 | * vectors. Given we are concealing a lost frame, this probably | ||
| 1537 | * is not noticeable by comparison, but it should be fixed. */ | ||
| 1538 |
1/2✓ Branch 0 taken 689 times.
✗ Branch 1 not taken.
|
689 | if (h->short_ref_count) { |
| 1539 | 689 | int c[4] = { | |
| 1540 | 689 | 1<<(h->ps.sps->bit_depth_luma-1), | |
| 1541 | 689 | 1<<(h->ps.sps->bit_depth_chroma-1), | |
| 1542 | 689 | 1<<(h->ps.sps->bit_depth_chroma-1), | |
| 1543 | -1 | ||
| 1544 | }; | ||
| 1545 | |||
| 1546 |
2/2✓ Branch 0 taken 655 times.
✓ Branch 1 taken 34 times.
|
689 | if (prev && |
| 1547 |
1/2✓ Branch 0 taken 655 times.
✗ Branch 1 not taken.
|
655 | h->short_ref[0]->f->width == prev->f->width && |
| 1548 |
1/2✓ Branch 0 taken 655 times.
✗ Branch 1 not taken.
|
655 | h->short_ref[0]->f->height == prev->f->height && |
| 1549 |
1/2✓ Branch 0 taken 655 times.
✗ Branch 1 not taken.
|
655 | h->short_ref[0]->f->format == prev->f->format) { |
| 1550 | 655 | ff_thread_await_progress(&prev->tf, INT_MAX, 0); | |
| 1551 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 627 times.
|
655 | if (prev->field_picture) |
| 1552 | 28 | ff_thread_await_progress(&prev->tf, INT_MAX, 1); | |
| 1553 | 655 | ff_thread_release_ext_buffer(&h->short_ref[0]->tf); | |
| 1554 | 655 | h->short_ref[0]->tf.f = h->short_ref[0]->f; | |
| 1555 | 655 | ret = ff_thread_ref_frame(&h->short_ref[0]->tf, &prev->tf); | |
| 1556 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 655 times.
|
655 | if (ret < 0) |
| 1557 | ✗ | return ret; | |
| 1558 | 655 | h->short_ref[0]->poc = prev->poc + 2U; | |
| 1559 | 655 | h->short_ref[0]->gray = prev->gray; | |
| 1560 | 655 | ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 0); | |
| 1561 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 627 times.
|
655 | if (h->short_ref[0]->field_picture) |
| 1562 | 28 | ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 1); | |
| 1563 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 8 times.
|
34 | } else if (!h->frame_recovered) { |
| 1564 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (!h->avctx->hwaccel) |
| 1565 | 26 | color_frame(h->short_ref[0]->f, c); | |
| 1566 | 26 | h->short_ref[0]->gray = 1; | |
| 1567 | } | ||
| 1568 | 689 | h->short_ref[0]->frame_num = h->poc.prev_frame_num; | |
| 1569 | } | ||
| 1570 | } | ||
| 1571 | |||
| 1572 | /* See if we have a decoded first field looking for a pair... | ||
| 1573 | * We're using that to see whether to continue decoding in that | ||
| 1574 | * frame, or to allocate a new one. */ | ||
| 1575 |
2/2✓ Branch 0 taken 3418 times.
✓ Branch 1 taken 25450 times.
|
28868 | if (h->first_field) { |
| 1576 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3418 times.
|
3418 | av_assert0(h->cur_pic_ptr); |
| 1577 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3418 times.
|
3418 | av_assert0(h->cur_pic_ptr->f->buf[0]); |
| 1578 | assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF); | ||
| 1579 | |||
| 1580 | /* figure out if we have a complementary field pair */ | ||
| 1581 |
2/4✓ Branch 0 taken 3418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3418 times.
|
3418 | if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { |
| 1582 | /* Previous field is unmatched. Don't display it, but let it | ||
| 1583 | * remain for reference if marked as such. */ | ||
| 1584 | ✗ | h->missing_fields ++; | |
| 1585 | ✗ | h->cur_pic_ptr = NULL; | |
| 1586 | ✗ | h->first_field = FIELD_PICTURE(h); | |
| 1587 | } else { | ||
| 1588 | 3418 | h->missing_fields = 0; | |
| 1589 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3418 times.
|
3418 | if (h->cur_pic_ptr->frame_num != h->poc.frame_num) { |
| 1590 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, | |
| 1591 | ✗ | h->picture_structure==PICT_BOTTOM_FIELD); | |
| 1592 | /* This and the previous field had different frame_nums. | ||
| 1593 | * Consider this field first in pair. Throw away previous | ||
| 1594 | * one except for reference purposes. */ | ||
| 1595 | ✗ | h->first_field = 1; | |
| 1596 | ✗ | h->cur_pic_ptr = NULL; | |
| 1597 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3418 times.
|
3418 | } else if (h->cur_pic_ptr->reference & DELAYED_PIC_REF) { |
| 1598 | /* This frame was already output, we cannot draw into it | ||
| 1599 | * anymore. | ||
| 1600 | */ | ||
| 1601 | ✗ | h->first_field = 1; | |
| 1602 | ✗ | h->cur_pic_ptr = NULL; | |
| 1603 | } else { | ||
| 1604 | /* Second field in complementary pair */ | ||
| 1605 | 3418 | h->first_field = 0; | |
| 1606 | } | ||
| 1607 | } | ||
| 1608 | } else { | ||
| 1609 | /* Frame or first field in a potentially complementary pair */ | ||
| 1610 | 25450 | h->first_field = FIELD_PICTURE(h); | |
| 1611 | } | ||
| 1612 | |||
| 1613 |
4/4✓ Branch 0 taken 6842 times.
✓ Branch 1 taken 22026 times.
✓ Branch 2 taken 3424 times.
✓ Branch 3 taken 3418 times.
|
28868 | if (!FIELD_PICTURE(h) || h->first_field) { |
| 1614 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25450 times.
|
25450 | if (h264_frame_start(h) < 0) { |
| 1615 | ✗ | h->first_field = 0; | |
| 1616 | ✗ | return AVERROR_INVALIDDATA; | |
| 1617 | } | ||
| 1618 | } else { | ||
| 1619 | 3418 | int field = h->picture_structure == PICT_BOTTOM_FIELD; | |
| 1620 | 3418 | release_unused_pictures(h, 0); | |
| 1621 | 3418 | h->cur_pic_ptr->tf.owner[field] = h->avctx; | |
| 1622 | } | ||
| 1623 | /* Some macroblocks can be accessed before they're available in case | ||
| 1624 | * of lost slices, MBAFF or threading. */ | ||
| 1625 |
2/2✓ Branch 0 taken 6842 times.
✓ Branch 1 taken 22026 times.
|
28868 | if (FIELD_PICTURE(h)) { |
| 1626 |
2/2✓ Branch 0 taken 170420 times.
✓ Branch 1 taken 6842 times.
|
177262 | for(i = (h->picture_structure == PICT_BOTTOM_FIELD); i<h->mb_height; i++) |
| 1627 | 170420 | memset(h->slice_table + i*h->mb_stride, -1, (h->mb_stride - (i+1==h->mb_height)) * sizeof(*h->slice_table)); | |
| 1628 | } else { | ||
| 1629 | 22026 | memset(h->slice_table, -1, | |
| 1630 | 22026 | (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table)); | |
| 1631 | } | ||
| 1632 | |||
| 1633 | 28868 | ret = ff_h264_init_poc(h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc, | |
| 1634 | 28868 | h->ps.sps, &h->poc, h->picture_structure, nal->ref_idc); | |
| 1635 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28868 times.
|
28868 | if (ret < 0) |
| 1636 | ✗ | return ret; | |
| 1637 | |||
| 1638 | 28868 | memcpy(h->mmco, sl->mmco, sl->nb_mmco * sizeof(*h->mmco)); | |
| 1639 | 28868 | h->nb_mmco = sl->nb_mmco; | |
| 1640 | 28868 | h->explicit_ref_marking = sl->explicit_ref_marking; | |
| 1641 | |||
| 1642 | 28868 | h->picture_idr = nal->type == H264_NAL_IDR_SLICE; | |
| 1643 | |||
| 1644 |
2/2✓ Branch 0 taken 98 times.
✓ Branch 1 taken 28770 times.
|
28868 | if (h->sei.recovery_point.recovery_frame_cnt >= 0) { |
| 1645 | 98 | const int sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt; | |
| 1646 | |||
| 1647 |
4/4✓ Branch 0 taken 25 times.
✓ Branch 1 taken 73 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 14 times.
|
98 | if (h->poc.frame_num != sei_recovery_frame_cnt || sl->slice_type_nos != AV_PICTURE_TYPE_I) |
| 1648 | 84 | h->valid_recovery_point = 1; | |
| 1649 | |||
| 1650 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 93 times.
|
98 | if ( h->recovery_frame < 0 |
| 1651 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | || av_zero_extend(h->recovery_frame - h->poc.frame_num, h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) { |
| 1652 | 93 | h->recovery_frame = av_zero_extend(h->poc.frame_num + sei_recovery_frame_cnt, h->ps.sps->log2_max_frame_num); | |
| 1653 | |||
| 1654 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 87 times.
|
93 | if (!h->valid_recovery_point) |
| 1655 | 6 | h->recovery_frame = h->poc.frame_num; | |
| 1656 | } | ||
| 1657 | } | ||
| 1658 | |||
| 1659 |
2/2✓ Branch 0 taken 1094 times.
✓ Branch 1 taken 27774 times.
|
28868 | h->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_KEY * !!(nal->type == H264_NAL_IDR_SLICE); |
| 1660 | |||
| 1661 |
2/2✓ Branch 0 taken 1094 times.
✓ Branch 1 taken 27774 times.
|
28868 | if (nal->type == H264_NAL_IDR_SLICE) { |
| 1662 | 1094 | h->cur_pic_ptr->recovered |= FRAME_RECOVERED_IDR; | |
| 1663 | // If we have an IDR, all frames after it in decoded order are | ||
| 1664 | // "recovered". | ||
| 1665 | 1094 | h->frame_recovered |= FRAME_RECOVERED_IDR; | |
| 1666 | } | ||
| 1667 | |||
| 1668 |
4/4✓ Branch 0 taken 110 times.
✓ Branch 1 taken 28758 times.
✓ Branch 2 taken 92 times.
✓ Branch 3 taken 18 times.
|
28868 | if (h->recovery_frame == h->poc.frame_num && nal->ref_idc) { |
| 1669 | 92 | h->recovery_frame = -1; | |
| 1670 | 92 | h->cur_pic_ptr->recovered |= FRAME_RECOVERED_SEI; | |
| 1671 | } | ||
| 1672 | |||
| 1673 | #if 1 | ||
| 1674 | 28868 | h->cur_pic_ptr->recovered |= h->frame_recovered; | |
| 1675 | #else | ||
| 1676 | h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR); | ||
| 1677 | #endif | ||
| 1678 | |||
| 1679 | /* Set the frame properties/side data. Only done for the second field in | ||
| 1680 | * field coded frames, since some SEI information is present for each field | ||
| 1681 | * and is merged by the SEI parsing code. */ | ||
| 1682 |
5/6✓ Branch 0 taken 6842 times.
✓ Branch 1 taken 22026 times.
✓ Branch 2 taken 3424 times.
✓ Branch 3 taken 3418 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3424 times.
|
28868 | if (!FIELD_PICTURE(h) || !h->first_field || h->missing_fields > 1) { |
| 1683 | 25444 | ret = h264_export_frame_props(h); | |
| 1684 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25444 times.
|
25444 | if (ret < 0) |
| 1685 | ✗ | return ret; | |
| 1686 | |||
| 1687 | 25444 | ret = h264_select_output_frame(h); | |
| 1688 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25444 times.
|
25444 | if (ret < 0) |
| 1689 | ✗ | return ret; | |
| 1690 | } | ||
| 1691 | |||
| 1692 | 28868 | return 0; | |
| 1693 | } | ||
| 1694 | |||
| 1695 | 38289 | static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl, | |
| 1696 | const H2645NAL *nal) | ||
| 1697 | { | ||
| 1698 | const SPS *sps; | ||
| 1699 | const PPS *pps; | ||
| 1700 | int ret; | ||
| 1701 | unsigned int slice_type, tmp, i; | ||
| 1702 | int field_pic_flag, bottom_field_flag; | ||
| 1703 |
4/4✓ Branch 0 taken 37839 times.
✓ Branch 1 taken 450 times.
✓ Branch 2 taken 28916 times.
✓ Branch 3 taken 8923 times.
|
38289 | int first_slice = sl == h->slice_ctx && !h->current_slice; |
| 1704 | int picture_structure; | ||
| 1705 | |||
| 1706 |
2/2✓ Branch 0 taken 28916 times.
✓ Branch 1 taken 9373 times.
|
38289 | if (first_slice) |
| 1707 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28916 times.
|
28916 | av_assert0(!h->setup_finished); |
| 1708 | |||
| 1709 | 38289 | sl->first_mb_addr = get_ue_golomb_long(&sl->gb); | |
| 1710 | |||
| 1711 | 38289 | slice_type = get_ue_golomb_31(&sl->gb); | |
| 1712 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38289 times.
|
38289 | if (slice_type > 9) { |
| 1713 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 1714 | "slice type %d too large at %d\n", | ||
| 1715 | slice_type, sl->first_mb_addr); | ||
| 1716 | ✗ | return AVERROR_INVALIDDATA; | |
| 1717 | } | ||
| 1718 |
2/2✓ Branch 0 taken 24565 times.
✓ Branch 1 taken 13724 times.
|
38289 | if (slice_type > 4) { |
| 1719 | 24565 | slice_type -= 5; | |
| 1720 | 24565 | sl->slice_type_fixed = 1; | |
| 1721 | } else | ||
| 1722 | 13724 | sl->slice_type_fixed = 0; | |
| 1723 | |||
| 1724 | 38289 | slice_type = ff_h264_golomb_to_pict_type[slice_type]; | |
| 1725 | 38289 | sl->slice_type = slice_type; | |
| 1726 | 38289 | sl->slice_type_nos = slice_type & 3; | |
| 1727 | |||
| 1728 |
2/2✓ Branch 0 taken 2282 times.
✓ Branch 1 taken 36007 times.
|
38289 | if (nal->type == H264_NAL_IDR_SLICE && |
| 1729 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2282 times.
|
2282 | sl->slice_type_nos != AV_PICTURE_TYPE_I) { |
| 1730 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n"); | |
| 1731 | ✗ | return AVERROR_INVALIDDATA; | |
| 1732 | } | ||
| 1733 | |||
| 1734 | 38289 | sl->pps_id = get_ue_golomb(&sl->gb); | |
| 1735 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38289 times.
|
38289 | if (sl->pps_id >= MAX_PPS_COUNT) { |
| 1736 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", sl->pps_id); | |
| 1737 | ✗ | return AVERROR_INVALIDDATA; | |
| 1738 | } | ||
| 1739 |
2/2✓ Branch 0 taken 167 times.
✓ Branch 1 taken 38122 times.
|
38289 | if (!h->ps.pps_list[sl->pps_id]) { |
| 1740 | 167 | av_log(h->avctx, AV_LOG_ERROR, | |
| 1741 | "non-existing PPS %u referenced\n", | ||
| 1742 | sl->pps_id); | ||
| 1743 | 167 | return AVERROR_INVALIDDATA; | |
| 1744 | } | ||
| 1745 | 38122 | pps = h->ps.pps_list[sl->pps_id]; | |
| 1746 | 38122 | sps = pps->sps; | |
| 1747 | |||
| 1748 | 38122 | sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num); | |
| 1749 |
2/2✓ Branch 0 taken 9369 times.
✓ Branch 1 taken 28753 times.
|
38122 | if (!first_slice) { |
| 1750 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9369 times.
|
9369 | if (h->poc.frame_num != sl->frame_num) { |
| 1751 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Frame num change from %d to %d\n", | |
| 1752 | ✗ | h->poc.frame_num, sl->frame_num); | |
| 1753 | ✗ | return AVERROR_INVALIDDATA; | |
| 1754 | } | ||
| 1755 | } | ||
| 1756 | |||
| 1757 | 38122 | sl->mb_mbaff = 0; | |
| 1758 | |||
| 1759 |
2/2✓ Branch 0 taken 23409 times.
✓ Branch 1 taken 14713 times.
|
38122 | if (sps->frame_mbs_only_flag) { |
| 1760 | 23409 | picture_structure = PICT_FRAME; | |
| 1761 | } else { | ||
| 1762 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 14713 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
14713 | if (!sps->direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B) { |
| 1763 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n"); | |
| 1764 | ✗ | return -1; | |
| 1765 | } | ||
| 1766 | 14713 | field_pic_flag = get_bits1(&sl->gb); | |
| 1767 |
2/2✓ Branch 0 taken 9240 times.
✓ Branch 1 taken 5473 times.
|
14713 | if (field_pic_flag) { |
| 1768 | 9240 | bottom_field_flag = get_bits1(&sl->gb); | |
| 1769 | 9240 | picture_structure = PICT_TOP_FIELD + bottom_field_flag; | |
| 1770 | } else { | ||
| 1771 | 5473 | picture_structure = PICT_FRAME; | |
| 1772 | } | ||
| 1773 | } | ||
| 1774 | 38122 | sl->picture_structure = picture_structure; | |
| 1775 | 38122 | sl->mb_field_decoding_flag = picture_structure != PICT_FRAME; | |
| 1776 | |||
| 1777 |
2/2✓ Branch 0 taken 28882 times.
✓ Branch 1 taken 9240 times.
|
38122 | if (picture_structure == PICT_FRAME) { |
| 1778 | 28882 | sl->curr_pic_num = sl->frame_num; | |
| 1779 | 28882 | sl->max_pic_num = 1 << sps->log2_max_frame_num; | |
| 1780 | } else { | ||
| 1781 | 9240 | sl->curr_pic_num = 2 * sl->frame_num + 1; | |
| 1782 | 9240 | sl->max_pic_num = 1 << (sps->log2_max_frame_num + 1); | |
| 1783 | } | ||
| 1784 | |||
| 1785 |
2/2✓ Branch 0 taken 2277 times.
✓ Branch 1 taken 35845 times.
|
38122 | if (nal->type == H264_NAL_IDR_SLICE) { |
| 1786 | 2277 | unsigned idr_pic_id = get_ue_golomb_long(&sl->gb); | |
| 1787 |
1/2✓ Branch 0 taken 2277 times.
✗ Branch 1 not taken.
|
2277 | if (idr_pic_id < 65536) { |
| 1788 | 2277 | sl->idr_pic_id = idr_pic_id; | |
| 1789 | } else | ||
| 1790 | ✗ | av_log(h->avctx, AV_LOG_WARNING, "idr_pic_id is invalid\n"); | |
| 1791 | } | ||
| 1792 | |||
| 1793 | 38122 | sl->poc_lsb = 0; | |
| 1794 | 38122 | sl->delta_poc_bottom = 0; | |
| 1795 |
2/2✓ Branch 0 taken 30341 times.
✓ Branch 1 taken 7781 times.
|
38122 | if (sps->poc_type == 0) { |
| 1796 | 30341 | sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb); | |
| 1797 | |||
| 1798 |
4/4✓ Branch 0 taken 8524 times.
✓ Branch 1 taken 21817 times.
✓ Branch 2 taken 6632 times.
✓ Branch 3 taken 1892 times.
|
30341 | if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME) |
| 1799 | 6632 | sl->delta_poc_bottom = get_se_golomb(&sl->gb); | |
| 1800 | } | ||
| 1801 | |||
| 1802 | 38122 | sl->delta_poc[0] = sl->delta_poc[1] = 0; | |
| 1803 |
4/4✓ Branch 0 taken 3055 times.
✓ Branch 1 taken 35067 times.
✓ Branch 2 taken 2848 times.
✓ Branch 3 taken 207 times.
|
38122 | if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) { |
| 1804 | 2848 | sl->delta_poc[0] = get_se_golomb(&sl->gb); | |
| 1805 | |||
| 1806 |
4/4✓ Branch 0 taken 770 times.
✓ Branch 1 taken 2078 times.
✓ Branch 2 taken 453 times.
✓ Branch 3 taken 317 times.
|
2848 | if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME) |
| 1807 | 453 | sl->delta_poc[1] = get_se_golomb(&sl->gb); | |
| 1808 | } | ||
| 1809 | |||
| 1810 | 38122 | sl->redundant_pic_count = 0; | |
| 1811 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38122 times.
|
38122 | if (pps->redundant_pic_cnt_present) |
| 1812 | ✗ | sl->redundant_pic_count = get_ue_golomb(&sl->gb); | |
| 1813 | |||
| 1814 |
2/2✓ Branch 0 taken 13516 times.
✓ Branch 1 taken 24606 times.
|
38122 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B) |
| 1815 | 13516 | sl->direct_spatial_mv_pred = get_bits1(&sl->gb); | |
| 1816 | |||
| 1817 | 38122 | ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count, | |
| 1818 | &sl->gb, pps, sl->slice_type_nos, | ||
| 1819 | 38122 | picture_structure, h->avctx); | |
| 1820 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38122 times.
|
38122 | if (ret < 0) |
| 1821 | ✗ | return ret; | |
| 1822 | |||
| 1823 |
2/2✓ Branch 0 taken 33637 times.
✓ Branch 1 taken 4485 times.
|
38122 | if (sl->slice_type_nos != AV_PICTURE_TYPE_I) { |
| 1824 | 33637 | ret = ff_h264_decode_ref_pic_list_reordering(sl, h->avctx); | |
| 1825 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33637 times.
|
33637 | if (ret < 0) { |
| 1826 | ✗ | sl->ref_count[1] = sl->ref_count[0] = 0; | |
| 1827 | ✗ | return ret; | |
| 1828 | } | ||
| 1829 | } | ||
| 1830 | |||
| 1831 | 38122 | sl->pwt.use_weight = 0; | |
| 1832 |
2/2✓ Branch 0 taken 76244 times.
✓ Branch 1 taken 38122 times.
|
114366 | for (i = 0; i < 2; i++) { |
| 1833 | 76244 | sl->pwt.luma_weight_flag[i] = 0; | |
| 1834 | 76244 | sl->pwt.chroma_weight_flag[i] = 0; | |
| 1835 | } | ||
| 1836 |
4/4✓ Branch 0 taken 4775 times.
✓ Branch 1 taken 33347 times.
✓ Branch 2 taken 1826 times.
✓ Branch 3 taken 2949 times.
|
38122 | if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) || |
| 1837 |
2/2✓ Branch 0 taken 390 times.
✓ Branch 1 taken 34783 times.
|
35173 | (pps->weighted_bipred_idc == 1 && |
| 1838 |
2/2✓ Branch 0 taken 386 times.
✓ Branch 1 taken 4 times.
|
390 | sl->slice_type_nos == AV_PICTURE_TYPE_B)) { |
| 1839 | 3335 | ret = ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count, | |
| 1840 | sl->slice_type_nos, &sl->pwt, | ||
| 1841 | 3335 | picture_structure, h->avctx); | |
| 1842 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3335 times.
|
3335 | if (ret < 0) |
| 1843 | ✗ | return ret; | |
| 1844 | } | ||
| 1845 | |||
| 1846 | 38122 | sl->explicit_ref_marking = 0; | |
| 1847 |
2/2✓ Branch 0 taken 25447 times.
✓ Branch 1 taken 12675 times.
|
38122 | if (nal->ref_idc) { |
| 1848 | 25447 | ret = ff_h264_decode_ref_pic_marking(sl, &sl->gb, nal, h->avctx); | |
| 1849 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 25447 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
25447 | if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) |
| 1850 | ✗ | return AVERROR_INVALIDDATA; | |
| 1851 | } | ||
| 1852 | |||
| 1853 |
4/4✓ Branch 0 taken 33637 times.
✓ Branch 1 taken 4485 times.
✓ Branch 2 taken 18825 times.
✓ Branch 3 taken 14812 times.
|
38122 | if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) { |
| 1854 | 18825 | tmp = get_ue_golomb_31(&sl->gb); | |
| 1855 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18825 times.
|
18825 | if (tmp > 2) { |
| 1856 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp); | |
| 1857 | ✗ | return AVERROR_INVALIDDATA; | |
| 1858 | } | ||
| 1859 | 18825 | sl->cabac_init_idc = tmp; | |
| 1860 | } | ||
| 1861 | |||
| 1862 | 38122 | sl->last_qscale_diff = 0; | |
| 1863 | 38122 | tmp = pps->init_qp + (unsigned)get_se_golomb(&sl->gb); | |
| 1864 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38122 times.
|
38122 | if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) { |
| 1865 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); | |
| 1866 | ✗ | return AVERROR_INVALIDDATA; | |
| 1867 | } | ||
| 1868 | 38122 | sl->qscale = tmp; | |
| 1869 | 38122 | sl->chroma_qp[0] = get_chroma_qp(pps, 0, sl->qscale); | |
| 1870 | 38122 | sl->chroma_qp[1] = get_chroma_qp(pps, 1, sl->qscale); | |
| 1871 | // FIXME qscale / qp ... stuff | ||
| 1872 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38122 times.
|
38122 | if (sl->slice_type == AV_PICTURE_TYPE_SP) |
| 1873 | ✗ | get_bits1(&sl->gb); /* sp_for_switch_flag */ | |
| 1874 |
1/2✓ Branch 0 taken 38122 times.
✗ Branch 1 not taken.
|
38122 | if (sl->slice_type == AV_PICTURE_TYPE_SP || |
| 1875 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38122 times.
|
38122 | sl->slice_type == AV_PICTURE_TYPE_SI) |
| 1876 | ✗ | get_se_golomb(&sl->gb); /* slice_qs_delta */ | |
| 1877 | |||
| 1878 | 38122 | sl->deblocking_filter = 1; | |
| 1879 | 38122 | sl->slice_alpha_c0_offset = 0; | |
| 1880 | 38122 | sl->slice_beta_offset = 0; | |
| 1881 |
2/2✓ Branch 0 taken 23325 times.
✓ Branch 1 taken 14797 times.
|
38122 | if (pps->deblocking_filter_parameters_present) { |
| 1882 | 23325 | tmp = get_ue_golomb_31(&sl->gb); | |
| 1883 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23325 times.
|
23325 | if (tmp > 2) { |
| 1884 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 1885 | "deblocking_filter_idc %u out of range\n", tmp); | ||
| 1886 | ✗ | return AVERROR_INVALIDDATA; | |
| 1887 | } | ||
| 1888 | 23325 | sl->deblocking_filter = tmp; | |
| 1889 |
2/2✓ Branch 0 taken 20622 times.
✓ Branch 1 taken 2703 times.
|
23325 | if (sl->deblocking_filter < 2) |
| 1890 | 20622 | sl->deblocking_filter ^= 1; // 1<->0 | |
| 1891 | |||
| 1892 |
2/2✓ Branch 0 taken 15614 times.
✓ Branch 1 taken 7711 times.
|
23325 | if (sl->deblocking_filter) { |
| 1893 | 15614 | int slice_alpha_c0_offset_div2 = get_se_golomb(&sl->gb); | |
| 1894 | 15614 | int slice_beta_offset_div2 = get_se_golomb(&sl->gb); | |
| 1895 |
2/4✓ Branch 0 taken 15614 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15614 times.
✗ Branch 3 not taken.
|
15614 | if (slice_alpha_c0_offset_div2 > 6 || |
| 1896 |
1/2✓ Branch 0 taken 15614 times.
✗ Branch 1 not taken.
|
15614 | slice_alpha_c0_offset_div2 < -6 || |
| 1897 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15614 times.
|
15614 | slice_beta_offset_div2 > 6 || |
| 1898 | slice_beta_offset_div2 < -6) { | ||
| 1899 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 1900 | "deblocking filter parameters %d %d out of range\n", | ||
| 1901 | slice_alpha_c0_offset_div2, slice_beta_offset_div2); | ||
| 1902 | ✗ | return AVERROR_INVALIDDATA; | |
| 1903 | } | ||
| 1904 | 15614 | sl->slice_alpha_c0_offset = slice_alpha_c0_offset_div2 * 2; | |
| 1905 | 15614 | sl->slice_beta_offset = slice_beta_offset_div2 * 2; | |
| 1906 | } | ||
| 1907 | } | ||
| 1908 | |||
| 1909 | 38122 | return 0; | |
| 1910 | } | ||
| 1911 | |||
| 1912 | /* do all the per-slice initialization needed before we can start decoding the | ||
| 1913 | * actual MBs */ | ||
| 1914 | 38042 | static int h264_slice_init(H264Context *h, H264SliceContext *sl, | |
| 1915 | const H2645NAL *nal) | ||
| 1916 | { | ||
| 1917 | 38042 | int i, j, ret = 0; | |
| 1918 | |||
| 1919 |
3/4✓ Branch 0 taken 2277 times.
✓ Branch 1 taken 35765 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2277 times.
|
38042 | if (h->picture_idr && nal->type != H264_NAL_IDR_SLICE) { |
| 1920 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Invalid mix of IDR and non-IDR slices\n"); | |
| 1921 | ✗ | return AVERROR_INVALIDDATA; | |
| 1922 | } | ||
| 1923 | |||
| 1924 | av_assert1(h->mb_num == h->mb_width * h->mb_height); | ||
| 1925 |
5/6✓ Branch 0 taken 33066 times.
✓ Branch 1 taken 4976 times.
✓ Branch 2 taken 9160 times.
✓ Branch 3 taken 23906 times.
✓ Branch 4 taken 38042 times.
✗ Branch 5 not taken.
|
38042 | if (sl->first_mb_addr << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num || |
| 1926 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | sl->first_mb_addr >= h->mb_num) { |
| 1927 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); | |
| 1928 | ✗ | return AVERROR_INVALIDDATA; | |
| 1929 | } | ||
| 1930 | 38042 | sl->resync_mb_x = sl->mb_x = sl->first_mb_addr % h->mb_width; | |
| 1931 | 76084 | sl->resync_mb_y = sl->mb_y = (sl->first_mb_addr / h->mb_width) << | |
| 1932 |
4/4✓ Branch 0 taken 33066 times.
✓ Branch 1 taken 4976 times.
✓ Branch 2 taken 9160 times.
✓ Branch 3 taken 23906 times.
|
38042 | FIELD_OR_MBAFF_PICTURE(h); |
| 1933 |
2/2✓ Branch 0 taken 4576 times.
✓ Branch 1 taken 33466 times.
|
38042 | if (h->picture_structure == PICT_BOTTOM_FIELD) |
| 1934 | 4576 | sl->resync_mb_y = sl->mb_y = sl->mb_y + 1; | |
| 1935 | av_assert1(sl->mb_y < h->mb_height); | ||
| 1936 | |||
| 1937 | 38042 | ret = ff_h264_build_ref_list(h, sl); | |
| 1938 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | if (ret < 0) |
| 1939 | ✗ | return ret; | |
| 1940 | |||
| 1941 |
2/2✓ Branch 0 taken 4273 times.
✓ Branch 1 taken 33769 times.
|
38042 | if (h->ps.pps->weighted_bipred_idc == 2 && |
| 1942 |
2/2✓ Branch 0 taken 2307 times.
✓ Branch 1 taken 1966 times.
|
4273 | sl->slice_type_nos == AV_PICTURE_TYPE_B) { |
| 1943 | 2307 | implicit_weight_table(h, sl, -1); | |
| 1944 |
2/2✓ Branch 0 taken 856 times.
✓ Branch 1 taken 1451 times.
|
2307 | if (FRAME_MBAFF(h)) { |
| 1945 | 856 | implicit_weight_table(h, sl, 0); | |
| 1946 | 856 | implicit_weight_table(h, sl, 1); | |
| 1947 | } | ||
| 1948 | } | ||
| 1949 | |||
| 1950 |
4/4✓ Branch 0 taken 13472 times.
✓ Branch 1 taken 24570 times.
✓ Branch 2 taken 7710 times.
✓ Branch 3 taken 5762 times.
|
38042 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred) |
| 1951 | 7710 | ff_h264_direct_dist_scale_factor(h, sl); | |
| 1952 |
1/2✓ Branch 0 taken 38042 times.
✗ Branch 1 not taken.
|
38042 | if (!h->setup_finished) |
| 1953 | 38042 | ff_h264_direct_ref_list_init(h, sl); | |
| 1954 | |||
| 1955 |
1/2✓ Branch 0 taken 38042 times.
✗ Branch 1 not taken.
|
38042 | if (h->avctx->skip_loop_filter >= AVDISCARD_ALL || |
| 1956 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY && |
| 1957 | ✗ | h->nal_unit_type != H264_NAL_IDR_SLICE) || | |
| 1958 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | (h->avctx->skip_loop_filter >= AVDISCARD_NONINTRA && |
| 1959 | ✗ | sl->slice_type_nos != AV_PICTURE_TYPE_I) || | |
| 1960 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR && |
| 1961 | ✗ | sl->slice_type_nos == AV_PICTURE_TYPE_B) || | |
| 1962 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | (h->avctx->skip_loop_filter >= AVDISCARD_NONREF && |
| 1963 | ✗ | nal->ref_idc == 0)) | |
| 1964 | ✗ | sl->deblocking_filter = 0; | |
| 1965 | |||
| 1966 |
3/4✓ Branch 0 taken 27628 times.
✓ Branch 1 taken 10414 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27628 times.
|
38042 | if (sl->deblocking_filter == 1 && h->nb_slice_ctx > 1) { |
| 1967 | ✗ | if (h->avctx->flags2 & AV_CODEC_FLAG2_FAST) { | |
| 1968 | /* Cheat slightly for speed: | ||
| 1969 | * Do not bother to deblock across slices. */ | ||
| 1970 | ✗ | sl->deblocking_filter = 2; | |
| 1971 | } else { | ||
| 1972 | ✗ | h->postpone_filter = 1; | |
| 1973 | } | ||
| 1974 | } | ||
| 1975 | 38042 | sl->qp_thresh = 15 - | |
| 1976 | 38042 | FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) - | |
| 1977 | 38042 | FFMAX3(0, | |
| 1978 | h->ps.pps->chroma_qp_index_offset[0], | ||
| 1979 | 38042 | h->ps.pps->chroma_qp_index_offset[1]) + | |
| 1980 | 38042 | 6 * (h->ps.sps->bit_depth_luma - 8); | |
| 1981 | |||
| 1982 | 38042 | sl->slice_num = ++h->current_slice; | |
| 1983 | |||
| 1984 |
1/2✓ Branch 0 taken 38042 times.
✗ Branch 1 not taken.
|
38042 | if (sl->slice_num) |
| 1985 | 38042 | h->slice_row[(sl->slice_num-1)&(MAX_SLICES-1)]= sl->resync_mb_y; | |
| 1986 |
2/2✓ Branch 0 taken 35069 times.
✓ Branch 1 taken 2973 times.
|
38042 | if ( h->slice_row[sl->slice_num&(MAX_SLICES-1)] + 3 >= sl->resync_mb_y |
| 1987 |
2/2✓ Branch 0 taken 26231 times.
✓ Branch 1 taken 8838 times.
|
35069 | && h->slice_row[sl->slice_num&(MAX_SLICES-1)] <= sl->resync_mb_y |
| 1988 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26231 times.
|
26231 | && sl->slice_num >= MAX_SLICES) { |
| 1989 | //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case | ||
| 1990 | ✗ | av_log(h->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", sl->slice_num, MAX_SLICES); | |
| 1991 | } | ||
| 1992 | |||
| 1993 |
2/2✓ Branch 0 taken 76084 times.
✓ Branch 1 taken 38042 times.
|
114126 | for (j = 0; j < 2; j++) { |
| 1994 | int id_list[16]; | ||
| 1995 | 76084 | int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j]; | |
| 1996 |
2/2✓ Branch 0 taken 1217344 times.
✓ Branch 1 taken 76084 times.
|
1293428 | for (i = 0; i < 16; i++) { |
| 1997 | 1217344 | id_list[i] = 60; | |
| 1998 |
4/4✓ Branch 0 taken 752464 times.
✓ Branch 1 taken 464880 times.
✓ Branch 2 taken 142005 times.
✓ Branch 3 taken 610459 times.
|
1217344 | if (j < sl->list_count && i < sl->ref_count[j] && |
| 1999 |
1/2✓ Branch 0 taken 142005 times.
✗ Branch 1 not taken.
|
142005 | sl->ref_list[j][i].parent->f->buf[0]) { |
| 2000 | int k; | ||
| 2001 | 142005 | const AVBuffer *buf = sl->ref_list[j][i].parent->f->buf[0]->buffer; | |
| 2002 |
2/2✓ Branch 0 taken 472135 times.
✓ Branch 1 taken 1933 times.
|
474068 | for (k = 0; k < h->short_ref_count; k++) |
| 2003 |
2/2✓ Branch 0 taken 140072 times.
✓ Branch 1 taken 332063 times.
|
472135 | if (h->short_ref[k]->f->buf[0]->buffer == buf) { |
| 2004 | 140072 | id_list[i] = k; | |
| 2005 | 140072 | break; | |
| 2006 | } | ||
| 2007 |
2/2✓ Branch 0 taken 11870 times.
✓ Branch 1 taken 140213 times.
|
152083 | for (k = 0; k < h->long_ref_count; k++) |
| 2008 |
4/4✓ Branch 0 taken 11269 times.
✓ Branch 1 taken 601 times.
✓ Branch 2 taken 1792 times.
✓ Branch 3 taken 9477 times.
|
11870 | if (h->long_ref[k] && h->long_ref[k]->f->buf[0]->buffer == buf) { |
| 2009 | 1792 | id_list[i] = h->short_ref_count + k; | |
| 2010 | 1792 | break; | |
| 2011 | } | ||
| 2012 | } | ||
| 2013 | } | ||
| 2014 | |||
| 2015 | 76084 | ref2frm[0] = | |
| 2016 | 76084 | ref2frm[1] = -1; | |
| 2017 |
2/2✓ Branch 0 taken 1217344 times.
✓ Branch 1 taken 76084 times.
|
1293428 | for (i = 0; i < 16; i++) |
| 2018 | 1217344 | ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3); | |
| 2019 | 76084 | ref2frm[18 + 0] = | |
| 2020 | 76084 | ref2frm[18 + 1] = -1; | |
| 2021 |
2/2✓ Branch 0 taken 2434688 times.
✓ Branch 1 taken 76084 times.
|
2510772 | for (i = 16; i < 48; i++) |
| 2022 | 2434688 | ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] + | |
| 2023 | 2434688 | (sl->ref_list[j][i].reference & 3); | |
| 2024 | } | ||
| 2025 | |||
| 2026 |
2/2✓ Branch 0 taken 4485 times.
✓ Branch 1 taken 33557 times.
|
38042 | if (sl->slice_type_nos == AV_PICTURE_TYPE_I) { |
| 2027 | 4485 | h->cur_pic_ptr->gray = 0; | |
| 2028 | 4485 | h->non_gray = 1; | |
| 2029 | } else { | ||
| 2030 | 33557 | int gray = 0; | |
| 2031 |
2/2✓ Branch 0 taken 47029 times.
✓ Branch 1 taken 33557 times.
|
80586 | for (j = 0; j < sl->list_count; j++) { |
| 2032 |
2/2✓ Branch 0 taken 142005 times.
✓ Branch 1 taken 47029 times.
|
189034 | for (i = 0; i < sl->ref_count[j]; i++) { |
| 2033 | 142005 | gray |= sl->ref_list[j][i].parent->gray; | |
| 2034 | } | ||
| 2035 | } | ||
| 2036 | 33557 | h->cur_pic_ptr->gray = gray; | |
| 2037 | } | ||
| 2038 | |||
| 2039 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | if (h->avctx->debug & FF_DEBUG_PICT_INFO) { |
| 2040 | ✗ | av_log(h->avctx, AV_LOG_DEBUG, | |
| 2041 | "slice:%d %c mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", | ||
| 2042 | sl->slice_num, | ||
| 2043 | ✗ | (h->picture_structure == PICT_FRAME ? 'F' : h->picture_structure == PICT_TOP_FIELD ? 'T' : 'B'), | |
| 2044 | ✗ | sl->mb_y * h->mb_width + sl->mb_x, | |
| 2045 | ✗ | av_get_picture_type_char(sl->slice_type), | |
| 2046 | ✗ | sl->slice_type_fixed ? " fix" : "", | |
| 2047 | ✗ | nal->type == H264_NAL_IDR_SLICE ? " IDR" : "", | |
| 2048 | h->poc.frame_num, | ||
| 2049 | ✗ | h->cur_pic_ptr->field_poc[0], | |
| 2050 | ✗ | h->cur_pic_ptr->field_poc[1], | |
| 2051 | sl->ref_count[0], sl->ref_count[1], | ||
| 2052 | sl->qscale, | ||
| 2053 | sl->deblocking_filter, | ||
| 2054 | sl->slice_alpha_c0_offset, sl->slice_beta_offset, | ||
| 2055 | sl->pwt.use_weight, | ||
| 2056 | ✗ | sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "", | |
| 2057 | ✗ | sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""); | |
| 2058 | } | ||
| 2059 | |||
| 2060 | 38042 | return 0; | |
| 2061 | } | ||
| 2062 | |||
| 2063 | 38289 | int ff_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal) | |
| 2064 | { | ||
| 2065 | 38289 | H264SliceContext *sl = h->slice_ctx + h->nb_slice_ctx_queued; | |
| 2066 |
4/4✓ Branch 0 taken 37839 times.
✓ Branch 1 taken 450 times.
✓ Branch 2 taken 28916 times.
✓ Branch 3 taken 8923 times.
|
38289 | int first_slice = sl == h->slice_ctx && !h->current_slice; |
| 2067 | int ret; | ||
| 2068 | |||
| 2069 | 38289 | sl->gb = nal->gb; | |
| 2070 | |||
| 2071 | 38289 | ret = h264_slice_header_parse(h, sl, nal); | |
| 2072 |
2/2✓ Branch 0 taken 167 times.
✓ Branch 1 taken 38122 times.
|
38289 | if (ret < 0) |
| 2073 | 167 | return ret; | |
| 2074 | |||
| 2075 | // discard redundant pictures | ||
| 2076 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38122 times.
|
38122 | if (sl->redundant_pic_count > 0) { |
| 2077 | ✗ | sl->ref_count[0] = sl->ref_count[1] = 0; | |
| 2078 | ✗ | return 0; | |
| 2079 | } | ||
| 2080 | |||
| 2081 |
3/4✓ Branch 0 taken 9174 times.
✓ Branch 1 taken 28948 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9174 times.
|
38122 | if (sl->first_mb_addr == 0 || !h->current_slice) { |
| 2082 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28948 times.
|
28948 | if (h->setup_finished) { |
| 2083 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Too many fields\n"); | |
| 2084 | ✗ | return AVERROR_INVALIDDATA; | |
| 2085 | } | ||
| 2086 | } | ||
| 2087 | |||
| 2088 |
2/2✓ Branch 0 taken 28948 times.
✓ Branch 1 taken 9174 times.
|
38122 | if (sl->first_mb_addr == 0) { // FIXME better field boundary detection |
| 2089 |
2/2✓ Branch 0 taken 195 times.
✓ Branch 1 taken 28753 times.
|
28948 | if (h->current_slice) { |
| 2090 | // this slice starts a new field | ||
| 2091 | // first decode any pending queued slices | ||
| 2092 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
|
195 | if (h->nb_slice_ctx_queued) { |
| 2093 | H264SliceContext tmp_ctx; | ||
| 2094 | |||
| 2095 | ✗ | ret = ff_h264_execute_decode_slices(h); | |
| 2096 | ✗ | if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) | |
| 2097 | ✗ | return ret; | |
| 2098 | |||
| 2099 | ✗ | memcpy(&tmp_ctx, h->slice_ctx, sizeof(tmp_ctx)); | |
| 2100 | ✗ | memcpy(h->slice_ctx, sl, sizeof(tmp_ctx)); | |
| 2101 | ✗ | memcpy(sl, &tmp_ctx, sizeof(tmp_ctx)); | |
| 2102 | ✗ | sl = h->slice_ctx; | |
| 2103 | } | ||
| 2104 | |||
| 2105 |
3/6✓ Branch 0 taken 195 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 195 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 195 times.
✗ Branch 5 not taken.
|
195 | if (h->cur_pic_ptr && FIELD_PICTURE(h) && h->first_field) { |
| 2106 | 195 | ret = ff_h264_field_end(h, h->slice_ctx, 1); | |
| 2107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
|
195 | if (ret < 0) |
| 2108 | ✗ | return ret; | |
| 2109 | ✗ | } else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type == H264_NAL_IDR_SLICE) { | |
| 2110 | ✗ | av_log(h->avctx, AV_LOG_WARNING, "Broken frame packetizing\n"); | |
| 2111 | ✗ | ret = ff_h264_field_end(h, h->slice_ctx, 1); | |
| 2112 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); | |
| 2113 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); | |
| 2114 | ✗ | h->cur_pic_ptr = NULL; | |
| 2115 | ✗ | if (ret < 0) | |
| 2116 | ✗ | return ret; | |
| 2117 | } else | ||
| 2118 | ✗ | return AVERROR_INVALIDDATA; | |
| 2119 | } | ||
| 2120 | |||
| 2121 |
2/2✓ Branch 0 taken 25530 times.
✓ Branch 1 taken 3418 times.
|
28948 | if (!h->first_field) { |
| 2122 |
3/4✓ Branch 0 taken 299 times.
✓ Branch 1 taken 25231 times.
✓ Branch 2 taken 299 times.
✗ Branch 3 not taken.
|
25530 | if (h->cur_pic_ptr && !h->droppable) { |
| 2123 | 299 | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, | |
| 2124 | 299 | h->picture_structure == PICT_BOTTOM_FIELD); | |
| 2125 | } | ||
| 2126 | 25530 | h->cur_pic_ptr = NULL; | |
| 2127 | } | ||
| 2128 | } | ||
| 2129 | |||
| 2130 |
2/2✓ Branch 0 taken 28948 times.
✓ Branch 1 taken 9174 times.
|
38122 | if (!h->current_slice) |
| 2131 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28948 times.
|
28948 | av_assert0(sl == h->slice_ctx); |
| 2132 | |||
| 2133 |
4/4✓ Branch 0 taken 28948 times.
✓ Branch 1 taken 9174 times.
✓ Branch 2 taken 25530 times.
✓ Branch 3 taken 3418 times.
|
38122 | if (h->current_slice == 0 && !h->first_field) { |
| 2134 | 25530 | if ( | |
| 2135 |
3/4✓ Branch 0 taken 84 times.
✓ Branch 1 taken 25446 times.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
|
25530 | (h->avctx->skip_frame >= AVDISCARD_NONREF && !h->nal_ref_idc) || |
| 2136 |
4/4✓ Branch 0 taken 84 times.
✓ Branch 1 taken 25446 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 44 times.
|
25530 | (h->avctx->skip_frame >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || |
| 2137 |
4/4✓ Branch 0 taken 40 times.
✓ Branch 1 taken 25446 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 36 times.
|
25486 | (h->avctx->skip_frame >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || |
| 2138 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 25448 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
25450 | (h->avctx->skip_frame >= AVDISCARD_NONKEY && h->nal_unit_type != H264_NAL_IDR_SLICE && h->sei.recovery_point.recovery_frame_cnt < 0) || |
| 2139 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25450 times.
|
25450 | h->avctx->skip_frame >= AVDISCARD_ALL) { |
| 2140 | 80 | return 0; | |
| 2141 | } | ||
| 2142 | } | ||
| 2143 | |||
| 2144 |
2/2✓ Branch 0 taken 9369 times.
✓ Branch 1 taken 28673 times.
|
38042 | if (!first_slice) { |
| 2145 | 9369 | const PPS *pps = h->ps.pps_list[sl->pps_id]; | |
| 2146 | |||
| 2147 |
1/2✓ Branch 0 taken 9369 times.
✗ Branch 1 not taken.
|
9369 | if (h->ps.pps->sps_id != pps->sps_id || |
| 2148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9369 times.
|
9369 | h->ps.pps->transform_8x8_mode != pps->transform_8x8_mode /*|| |
| 2149 | (h->setup_finished && h->ps.pps != pps)*/) { | ||
| 2150 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "PPS changed between slices\n"); | |
| 2151 | ✗ | return AVERROR_INVALIDDATA; | |
| 2152 | } | ||
| 2153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9369 times.
|
9369 | if (h->ps.sps != pps->sps) { |
| 2154 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 2155 | "SPS changed in the middle of the frame\n"); | ||
| 2156 | ✗ | return AVERROR_INVALIDDATA; | |
| 2157 | } | ||
| 2158 | } | ||
| 2159 | |||
| 2160 |
2/2✓ Branch 0 taken 28868 times.
✓ Branch 1 taken 9174 times.
|
38042 | if (h->current_slice == 0) { |
| 2161 | 28868 | ret = h264_field_start(h, sl, nal, first_slice); | |
| 2162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28868 times.
|
28868 | if (ret < 0) |
| 2163 | ✗ | return ret; | |
| 2164 | } else { | ||
| 2165 |
1/2✓ Branch 0 taken 9174 times.
✗ Branch 1 not taken.
|
9174 | if (h->picture_structure != sl->picture_structure || |
| 2166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9174 times.
|
9174 | h->droppable != (nal->ref_idc == 0)) { |
| 2167 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 2168 | "Changing field mode (%d -> %d) between slices is not allowed\n", | ||
| 2169 | h->picture_structure, sl->picture_structure); | ||
| 2170 | ✗ | return AVERROR_INVALIDDATA; | |
| 2171 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9174 times.
|
9174 | } else if (!h->cur_pic_ptr) { |
| 2172 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 2173 | "unset cur_pic_ptr on slice %d\n", | ||
| 2174 | ✗ | h->current_slice + 1); | |
| 2175 | ✗ | return AVERROR_INVALIDDATA; | |
| 2176 | } | ||
| 2177 | } | ||
| 2178 | |||
| 2179 | 38042 | ret = h264_slice_init(h, sl, nal); | |
| 2180 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | if (ret < 0) |
| 2181 | ✗ | return ret; | |
| 2182 | |||
| 2183 | 38042 | h->nb_slice_ctx_queued++; | |
| 2184 | |||
| 2185 | 38042 | return 0; | |
| 2186 | } | ||
| 2187 | |||
| 2188 | ✗ | int ff_h264_get_slice_type(const H264SliceContext *sl) | |
| 2189 | { | ||
| 2190 | ✗ | switch (sl->slice_type) { | |
| 2191 | ✗ | case AV_PICTURE_TYPE_P: | |
| 2192 | ✗ | return 0; | |
| 2193 | ✗ | case AV_PICTURE_TYPE_B: | |
| 2194 | ✗ | return 1; | |
| 2195 | ✗ | case AV_PICTURE_TYPE_I: | |
| 2196 | ✗ | return 2; | |
| 2197 | ✗ | case AV_PICTURE_TYPE_SP: | |
| 2198 | ✗ | return 3; | |
| 2199 | ✗ | case AV_PICTURE_TYPE_SI: | |
| 2200 | ✗ | return 4; | |
| 2201 | ✗ | default: | |
| 2202 | ✗ | return AVERROR_INVALIDDATA; | |
| 2203 | } | ||
| 2204 | } | ||
| 2205 | |||
| 2206 | 12578855 | static av_always_inline void fill_filter_caches_inter(const H264Context *h, | |
| 2207 | H264SliceContext *sl, | ||
| 2208 | int mb_type, int top_xy, | ||
| 2209 | const int left_xy[LEFT_MBS], | ||
| 2210 | int top_type, | ||
| 2211 | const int left_type[LEFT_MBS], | ||
| 2212 | int mb_xy, int list) | ||
| 2213 | { | ||
| 2214 | 12578855 | int b_stride = h->b_stride; | |
| 2215 | 12578855 | int16_t(*mv_dst)[2] = &sl->mv_cache[list][scan8[0]]; | |
| 2216 | 12578855 | int8_t *ref_cache = &sl->ref_cache[list][scan8[0]]; | |
| 2217 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 12578855 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
12578855 | if (IS_INTER(mb_type) || IS_DIRECT(mb_type)) { |
| 2218 |
2/2✓ Branch 0 taken 10119900 times.
✓ Branch 1 taken 2458955 times.
|
12578855 | if (USES_LIST(top_type, list)) { |
| 2219 | 10119900 | const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; | |
| 2220 | 10119900 | const int b8_xy = 4 * top_xy + 2; | |
| 2221 |
2/2✓ Branch 0 taken 343379 times.
✓ Branch 1 taken 9776521 times.
|
10119900 | const int *ref2frm = &h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][list][(MB_MBAFF(sl) ? 20 : 2)]; |
| 2222 | 10119900 | AV_COPY128(mv_dst - 1 * 8, h->cur_pic.motion_val[list][b_xy + 0]); | |
| 2223 | 10119900 | ref_cache[0 - 1 * 8] = | |
| 2224 | 10119900 | ref_cache[1 - 1 * 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 0]]; | |
| 2225 | 10119900 | ref_cache[2 - 1 * 8] = | |
| 2226 | 10119900 | ref_cache[3 - 1 * 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 1]]; | |
| 2227 | } else { | ||
| 2228 | 2458955 | AV_ZERO128(mv_dst - 1 * 8); | |
| 2229 | 2458955 | AV_WN32A(&ref_cache[0 - 1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
| 2230 | } | ||
| 2231 | |||
| 2232 |
2/2✓ Branch 0 taken 12144142 times.
✓ Branch 1 taken 434713 times.
|
12578855 | if (!IS_INTERLACED(mb_type ^ left_type[LTOP])) { |
| 2233 |
2/2✓ Branch 0 taken 10149444 times.
✓ Branch 1 taken 1994698 times.
|
12144142 | if (USES_LIST(left_type[LTOP], list)) { |
| 2234 | 10149444 | const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3; | |
| 2235 | 10149444 | const int b8_xy = 4 * left_xy[LTOP] + 1; | |
| 2236 |
2/2✓ Branch 0 taken 240429 times.
✓ Branch 1 taken 9909015 times.
|
10149444 | const int *ref2frm = &h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][list][(MB_MBAFF(sl) ? 20 : 2)]; |
| 2237 | 10149444 | AV_COPY32(mv_dst - 1 + 0, h->cur_pic.motion_val[list][b_xy + b_stride * 0]); | |
| 2238 | 10149444 | AV_COPY32(mv_dst - 1 + 8, h->cur_pic.motion_val[list][b_xy + b_stride * 1]); | |
| 2239 | 10149444 | AV_COPY32(mv_dst - 1 + 16, h->cur_pic.motion_val[list][b_xy + b_stride * 2]); | |
| 2240 | 10149444 | AV_COPY32(mv_dst - 1 + 24, h->cur_pic.motion_val[list][b_xy + b_stride * 3]); | |
| 2241 | 10149444 | ref_cache[-1 + 0] = | |
| 2242 | 10149444 | ref_cache[-1 + 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 2 * 0]]; | |
| 2243 | 10149444 | ref_cache[-1 + 16] = | |
| 2244 | 10149444 | ref_cache[-1 + 24] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 2 * 1]]; | |
| 2245 | } else { | ||
| 2246 | 1994698 | AV_ZERO32(mv_dst - 1 + 0); | |
| 2247 | 1994698 | AV_ZERO32(mv_dst - 1 + 8); | |
| 2248 | 1994698 | AV_ZERO32(mv_dst - 1 + 16); | |
| 2249 | 1994698 | AV_ZERO32(mv_dst - 1 + 24); | |
| 2250 | 1994698 | ref_cache[-1 + 0] = | |
| 2251 | 1994698 | ref_cache[-1 + 8] = | |
| 2252 | 1994698 | ref_cache[-1 + 16] = | |
| 2253 | 1994698 | ref_cache[-1 + 24] = LIST_NOT_USED; | |
| 2254 | } | ||
| 2255 | } | ||
| 2256 | } | ||
| 2257 | |||
| 2258 |
2/2✓ Branch 0 taken 1400827 times.
✓ Branch 1 taken 11178028 times.
|
12578855 | if (!USES_LIST(mb_type, list)) { |
| 2259 | 1400827 | fill_rectangle(mv_dst, 4, 4, 8, pack16to32(0, 0), 4); | |
| 2260 | 1400827 | AV_WN32A(&ref_cache[0 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
| 2261 | 1400827 | AV_WN32A(&ref_cache[1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
| 2262 | 1400827 | AV_WN32A(&ref_cache[2 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
| 2263 | 1400827 | AV_WN32A(&ref_cache[3 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
| 2264 | 1400827 | return; | |
| 2265 | } | ||
| 2266 | |||
| 2267 | { | ||
| 2268 | 11178028 | const int8_t *ref = &h->cur_pic.ref_index[list][4 * mb_xy]; | |
| 2269 |
2/2✓ Branch 0 taken 414359 times.
✓ Branch 1 taken 10763669 times.
|
11178028 | const int *ref2frm = &h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][list][(MB_MBAFF(sl) ? 20 : 2)]; |
| 2270 | 11178028 | uint32_t ref01 = (pack16to32(ref2frm[ref[0]], ref2frm[ref[1]]) & 0x00FF00FF) * 0x0101; | |
| 2271 | 11178028 | uint32_t ref23 = (pack16to32(ref2frm[ref[2]], ref2frm[ref[3]]) & 0x00FF00FF) * 0x0101; | |
| 2272 | 11178028 | AV_WN32A(&ref_cache[0 * 8], ref01); | |
| 2273 | 11178028 | AV_WN32A(&ref_cache[1 * 8], ref01); | |
| 2274 | 11178028 | AV_WN32A(&ref_cache[2 * 8], ref23); | |
| 2275 | 11178028 | AV_WN32A(&ref_cache[3 * 8], ref23); | |
| 2276 | } | ||
| 2277 | |||
| 2278 | { | ||
| 2279 | 11178028 | int16_t(*mv_src)[2] = &h->cur_pic.motion_val[list][4 * sl->mb_x + 4 * sl->mb_y * b_stride]; | |
| 2280 | 11178028 | AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride); | |
| 2281 | 11178028 | AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride); | |
| 2282 | 11178028 | AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride); | |
| 2283 | 11178028 | AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride); | |
| 2284 | } | ||
| 2285 | } | ||
| 2286 | |||
| 2287 | /** | ||
| 2288 | * @return non zero if the loop filter can be skipped | ||
| 2289 | */ | ||
| 2290 | 12803158 | static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type) | |
| 2291 | { | ||
| 2292 | 12803158 | const int mb_xy = sl->mb_xy; | |
| 2293 | int top_xy, left_xy[LEFT_MBS]; | ||
| 2294 | int top_type, left_type[LEFT_MBS]; | ||
| 2295 | const uint8_t *nnz; | ||
| 2296 | uint8_t *nnz_cache; | ||
| 2297 | |||
| 2298 | 12803158 | top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl)); | |
| 2299 | |||
| 2300 | 12803158 | left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1; | |
| 2301 |
2/2✓ Branch 0 taken 2023440 times.
✓ Branch 1 taken 10779718 times.
|
12803158 | if (FRAME_MBAFF(h)) { |
| 2302 | 2023440 | const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]); | |
| 2303 | 2023440 | const int curr_mb_field_flag = IS_INTERLACED(mb_type); | |
| 2304 |
2/2✓ Branch 0 taken 1011720 times.
✓ Branch 1 taken 1011720 times.
|
2023440 | if (sl->mb_y & 1) { |
| 2305 |
2/2✓ Branch 0 taken 205032 times.
✓ Branch 1 taken 806688 times.
|
1011720 | if (left_mb_field_flag != curr_mb_field_flag) |
| 2306 | 205032 | left_xy[LTOP] -= h->mb_stride; | |
| 2307 | } else { | ||
| 2308 |
2/2✓ Branch 0 taken 263670 times.
✓ Branch 1 taken 748050 times.
|
1011720 | if (curr_mb_field_flag) |
| 2309 | 263670 | top_xy += h->mb_stride & | |
| 2310 | 263670 | (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1); | |
| 2311 |
2/2✓ Branch 0 taken 205032 times.
✓ Branch 1 taken 806688 times.
|
1011720 | if (left_mb_field_flag != curr_mb_field_flag) |
| 2312 | 205032 | left_xy[LBOT] += h->mb_stride; | |
| 2313 | } | ||
| 2314 | } | ||
| 2315 | |||
| 2316 | 12803158 | sl->top_mb_xy = top_xy; | |
| 2317 | 12803158 | sl->left_mb_xy[LTOP] = left_xy[LTOP]; | |
| 2318 | 12803158 | sl->left_mb_xy[LBOT] = left_xy[LBOT]; | |
| 2319 | { | ||
| 2320 | /* For sufficiently low qp, filtering wouldn't do anything. | ||
| 2321 | * This is a conservative estimate: could also check beta_offset | ||
| 2322 | * and more accurate chroma_qp. */ | ||
| 2323 | 12803158 | int qp_thresh = sl->qp_thresh; // FIXME strictly we should store qp_thresh for each mb of a slice | |
| 2324 | 12803158 | int qp = h->cur_pic.qscale_table[mb_xy]; | |
| 2325 |
2/2✓ Branch 0 taken 1837763 times.
✓ Branch 1 taken 10965395 times.
|
12803158 | if (qp <= qp_thresh && |
| 2326 |
2/2✓ Branch 0 taken 1835784 times.
✓ Branch 1 taken 1979 times.
|
1837763 | (left_xy[LTOP] < 0 || |
| 2327 |
4/4✓ Branch 0 taken 1774887 times.
✓ Branch 1 taken 60897 times.
✓ Branch 2 taken 1686260 times.
✓ Branch 3 taken 90606 times.
|
1837763 | ((qp + h->cur_pic.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh) && |
| 2328 | 1686260 | (top_xy < 0 || | |
| 2329 |
2/2✓ Branch 0 taken 1489956 times.
✓ Branch 1 taken 196304 times.
|
1686260 | ((qp + h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) { |
| 2330 |
2/2✓ Branch 0 taken 1264751 times.
✓ Branch 1 taken 315811 times.
|
1580562 | if (!FRAME_MBAFF(h)) |
| 2331 | 1264751 | return 1; | |
| 2332 |
2/2✓ Branch 0 taken 315680 times.
✓ Branch 1 taken 131 times.
|
315811 | if ((left_xy[LTOP] < 0 || |
| 2333 |
2/2✓ Branch 0 taken 315151 times.
✓ Branch 1 taken 529 times.
|
315680 | ((qp + h->cur_pic.qscale_table[left_xy[LBOT]] + 1) >> 1) <= qp_thresh) && |
| 2334 |
2/2✓ Branch 0 taken 294673 times.
✓ Branch 1 taken 20609 times.
|
315282 | (top_xy < h->mb_stride || |
| 2335 |
2/2✓ Branch 0 taken 271562 times.
✓ Branch 1 taken 23111 times.
|
294673 | ((qp + h->cur_pic.qscale_table[top_xy - h->mb_stride] + 1) >> 1) <= qp_thresh)) |
| 2336 | 292171 | return 1; | |
| 2337 | } | ||
| 2338 | } | ||
| 2339 | |||
| 2340 | 11246236 | top_type = h->cur_pic.mb_type[top_xy]; | |
| 2341 | 11246236 | left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]]; | |
| 2342 | 11246236 | left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]]; | |
| 2343 |
2/2✓ Branch 0 taken 490374 times.
✓ Branch 1 taken 10755862 times.
|
11246236 | if (sl->deblocking_filter == 2) { |
| 2344 |
2/2✓ Branch 0 taken 61322 times.
✓ Branch 1 taken 429052 times.
|
490374 | if (h->slice_table[top_xy] != sl->slice_num) |
| 2345 | 61322 | top_type = 0; | |
| 2346 |
2/2✓ Branch 0 taken 14783 times.
✓ Branch 1 taken 475591 times.
|
490374 | if (h->slice_table[left_xy[LBOT]] != sl->slice_num) |
| 2347 | 14783 | left_type[LTOP] = left_type[LBOT] = 0; | |
| 2348 | } else { | ||
| 2349 |
2/2✓ Branch 0 taken 478208 times.
✓ Branch 1 taken 10277654 times.
|
10755862 | if (h->slice_table[top_xy] == 0xFFFF) |
| 2350 | 478208 | top_type = 0; | |
| 2351 |
2/2✓ Branch 0 taken 310301 times.
✓ Branch 1 taken 10445561 times.
|
10755862 | if (h->slice_table[left_xy[LBOT]] == 0xFFFF) |
| 2352 | 310301 | left_type[LTOP] = left_type[LBOT] = 0; | |
| 2353 | } | ||
| 2354 | 11246236 | sl->top_type = top_type; | |
| 2355 | 11246236 | sl->left_type[LTOP] = left_type[LTOP]; | |
| 2356 | 11246236 | sl->left_type[LBOT] = left_type[LBOT]; | |
| 2357 | |||
| 2358 |
2/2✓ Branch 0 taken 2993158 times.
✓ Branch 1 taken 8253078 times.
|
11246236 | if (IS_INTRA(mb_type)) |
| 2359 | 2993158 | return 0; | |
| 2360 | |||
| 2361 | 8253078 | fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy, | |
| 2362 | top_type, left_type, mb_xy, 0); | ||
| 2363 |
2/2✓ Branch 0 taken 4325777 times.
✓ Branch 1 taken 3927301 times.
|
8253078 | if (sl->list_count == 2) |
| 2364 | 4325777 | fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy, | |
| 2365 | top_type, left_type, mb_xy, 1); | ||
| 2366 | |||
| 2367 | 8253078 | nnz = h->non_zero_count[mb_xy]; | |
| 2368 | 8253078 | nnz_cache = sl->non_zero_count_cache; | |
| 2369 | 8253078 | AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]); | |
| 2370 | 8253078 | AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]); | |
| 2371 | 8253078 | AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]); | |
| 2372 | 8253078 | AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]); | |
| 2373 | 8253078 | sl->cbp = h->cbp_table[mb_xy]; | |
| 2374 | |||
| 2375 |
2/2✓ Branch 0 taken 7817681 times.
✓ Branch 1 taken 435397 times.
|
8253078 | if (top_type) { |
| 2376 | 7817681 | nnz = h->non_zero_count[top_xy]; | |
| 2377 | 7817681 | AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]); | |
| 2378 | } | ||
| 2379 | |||
| 2380 |
2/2✓ Branch 0 taken 7982767 times.
✓ Branch 1 taken 270311 times.
|
8253078 | if (left_type[LTOP]) { |
| 2381 | 7982767 | nnz = h->non_zero_count[left_xy[LTOP]]; | |
| 2382 | 7982767 | nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4]; | |
| 2383 | 7982767 | nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4]; | |
| 2384 | 7982767 | nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4]; | |
| 2385 | 7982767 | nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4]; | |
| 2386 | } | ||
| 2387 | |||
| 2388 | /* CAVLC 8x8dct requires NNZ values for residual decoding that differ | ||
| 2389 | * from what the loop filter needs */ | ||
| 2390 |
4/4✓ Branch 0 taken 2070968 times.
✓ Branch 1 taken 6182110 times.
✓ Branch 2 taken 246166 times.
✓ Branch 3 taken 1824802 times.
|
8253078 | if (!CABAC(h) && h->ps.pps->transform_8x8_mode) { |
| 2391 |
2/2✓ Branch 0 taken 107789 times.
✓ Branch 1 taken 138377 times.
|
246166 | if (IS_8x8DCT(top_type)) { |
| 2392 | 107789 | nnz_cache[4 + 8 * 0] = | |
| 2393 | 107789 | nnz_cache[5 + 8 * 0] = (h->cbp_table[top_xy] & 0x4000) >> 12; | |
| 2394 | 107789 | nnz_cache[6 + 8 * 0] = | |
| 2395 | 107789 | nnz_cache[7 + 8 * 0] = (h->cbp_table[top_xy] & 0x8000) >> 12; | |
| 2396 | } | ||
| 2397 |
2/2✓ Branch 0 taken 110456 times.
✓ Branch 1 taken 135710 times.
|
246166 | if (IS_8x8DCT(left_type[LTOP])) { |
| 2398 | 110456 | nnz_cache[3 + 8 * 1] = | |
| 2399 | 110456 | nnz_cache[3 + 8 * 2] = (h->cbp_table[left_xy[LTOP]] & 0x2000) >> 12; // FIXME check MBAFF | |
| 2400 | } | ||
| 2401 |
2/2✓ Branch 0 taken 110556 times.
✓ Branch 1 taken 135610 times.
|
246166 | if (IS_8x8DCT(left_type[LBOT])) { |
| 2402 | 110556 | nnz_cache[3 + 8 * 3] = | |
| 2403 | 110556 | nnz_cache[3 + 8 * 4] = (h->cbp_table[left_xy[LBOT]] & 0x8000) >> 12; // FIXME check MBAFF | |
| 2404 | } | ||
| 2405 | |||
| 2406 |
2/2✓ Branch 0 taken 104872 times.
✓ Branch 1 taken 141294 times.
|
246166 | if (IS_8x8DCT(mb_type)) { |
| 2407 | 104872 | nnz_cache[scan8[0]] = | |
| 2408 | 104872 | nnz_cache[scan8[1]] = | |
| 2409 | 104872 | nnz_cache[scan8[2]] = | |
| 2410 | 104872 | nnz_cache[scan8[3]] = (sl->cbp & 0x1000) >> 12; | |
| 2411 | |||
| 2412 | 104872 | nnz_cache[scan8[0 + 4]] = | |
| 2413 | 104872 | nnz_cache[scan8[1 + 4]] = | |
| 2414 | 104872 | nnz_cache[scan8[2 + 4]] = | |
| 2415 | 104872 | nnz_cache[scan8[3 + 4]] = (sl->cbp & 0x2000) >> 12; | |
| 2416 | |||
| 2417 | 104872 | nnz_cache[scan8[0 + 8]] = | |
| 2418 | 104872 | nnz_cache[scan8[1 + 8]] = | |
| 2419 | 104872 | nnz_cache[scan8[2 + 8]] = | |
| 2420 | 104872 | nnz_cache[scan8[3 + 8]] = (sl->cbp & 0x4000) >> 12; | |
| 2421 | |||
| 2422 | 104872 | nnz_cache[scan8[0 + 12]] = | |
| 2423 | 104872 | nnz_cache[scan8[1 + 12]] = | |
| 2424 | 104872 | nnz_cache[scan8[2 + 12]] = | |
| 2425 | 104872 | nnz_cache[scan8[3 + 12]] = (sl->cbp & 0x8000) >> 12; | |
| 2426 | } | ||
| 2427 | } | ||
| 2428 | |||
| 2429 | 8253078 | return 0; | |
| 2430 | } | ||
| 2431 | |||
| 2432 | 411450 | static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, int end_x) | |
| 2433 | { | ||
| 2434 | uint8_t *dest_y, *dest_cb, *dest_cr; | ||
| 2435 | int linesize, uvlinesize, mb_x, mb_y; | ||
| 2436 | 411450 | const int end_mb_y = sl->mb_y + FRAME_MBAFF(h); | |
| 2437 | 411450 | const int old_slice_type = sl->slice_type; | |
| 2438 | 411450 | const int pixel_shift = h->pixel_shift; | |
| 2439 | 411450 | const int block_h = 16 >> h->chroma_y_shift; | |
| 2440 | |||
| 2441 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 411450 times.
|
411450 | if (h->postpone_filter) |
| 2442 | ✗ | return; | |
| 2443 | |||
| 2444 |
2/2✓ Branch 0 taken 334482 times.
✓ Branch 1 taken 76968 times.
|
411450 | if (sl->deblocking_filter) { |
| 2445 |
2/2✓ Branch 0 taken 11791438 times.
✓ Branch 1 taken 334482 times.
|
12125920 | for (mb_x = start_x; mb_x < end_x; mb_x++) |
| 2446 |
2/2✓ Branch 0 taken 12803158 times.
✓ Branch 1 taken 11791438 times.
|
24594596 | for (mb_y = end_mb_y - FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) { |
| 2447 | int mb_xy, mb_type; | ||
| 2448 | 12803158 | mb_xy = sl->mb_xy = mb_x + mb_y * h->mb_stride; | |
| 2449 | 12803158 | mb_type = h->cur_pic.mb_type[mb_xy]; | |
| 2450 | |||
| 2451 |
2/2✓ Branch 0 taken 2023440 times.
✓ Branch 1 taken 10779718 times.
|
12803158 | if (FRAME_MBAFF(h)) |
| 2452 | 2023440 | sl->mb_mbaff = | |
| 2453 | 2023440 | sl->mb_field_decoding_flag = !!IS_INTERLACED(mb_type); | |
| 2454 | |||
| 2455 | 12803158 | sl->mb_x = mb_x; | |
| 2456 | 12803158 | sl->mb_y = mb_y; | |
| 2457 | 12803158 | dest_y = h->cur_pic.f->data[0] + | |
| 2458 | 12803158 | ((mb_x << pixel_shift) + mb_y * sl->linesize) * 16; | |
| 2459 | 25606316 | dest_cb = h->cur_pic.f->data[1] + | |
| 2460 |
2/2✓ Branch 0 taken 80328 times.
✓ Branch 1 taken 12722830 times.
|
12803158 | (mb_x << pixel_shift) * (8 << CHROMA444(h)) + |
| 2461 | 12803158 | mb_y * sl->uvlinesize * block_h; | |
| 2462 | 25606316 | dest_cr = h->cur_pic.f->data[2] + | |
| 2463 |
2/2✓ Branch 0 taken 80328 times.
✓ Branch 1 taken 12722830 times.
|
12803158 | (mb_x << pixel_shift) * (8 << CHROMA444(h)) + |
| 2464 | 12803158 | mb_y * sl->uvlinesize * block_h; | |
| 2465 | // FIXME simplify above | ||
| 2466 | |||
| 2467 |
2/2✓ Branch 0 taken 4679076 times.
✓ Branch 1 taken 8124082 times.
|
12803158 | if (MB_FIELD(sl)) { |
| 2468 | 4679076 | linesize = sl->mb_linesize = sl->linesize * 2; | |
| 2469 | 4679076 | uvlinesize = sl->mb_uvlinesize = sl->uvlinesize * 2; | |
| 2470 |
2/2✓ Branch 0 taken 2336700 times.
✓ Branch 1 taken 2342376 times.
|
4679076 | if (mb_y & 1) { // FIXME move out of this function? |
| 2471 | 2336700 | dest_y -= sl->linesize * 15; | |
| 2472 | 2336700 | dest_cb -= sl->uvlinesize * (block_h - 1); | |
| 2473 | 2336700 | dest_cr -= sl->uvlinesize * (block_h - 1); | |
| 2474 | } | ||
| 2475 | } else { | ||
| 2476 | 8124082 | linesize = sl->mb_linesize = sl->linesize; | |
| 2477 | 8124082 | uvlinesize = sl->mb_uvlinesize = sl->uvlinesize; | |
| 2478 | } | ||
| 2479 | 12803158 | backup_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize, | |
| 2480 | uvlinesize, 0); | ||
| 2481 |
2/2✓ Branch 1 taken 1556922 times.
✓ Branch 2 taken 11246236 times.
|
12803158 | if (fill_filter_caches(h, sl, mb_type)) |
| 2482 | 1556922 | continue; | |
| 2483 | 11246236 | sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mb_xy]); | |
| 2484 | 11246236 | sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mb_xy]); | |
| 2485 | |||
| 2486 |
2/2✓ Branch 0 taken 1731269 times.
✓ Branch 1 taken 9514967 times.
|
11246236 | if (FRAME_MBAFF(h)) { |
| 2487 | 1731269 | ff_h264_filter_mb(h, sl, mb_x, mb_y, dest_y, dest_cb, dest_cr, | |
| 2488 | linesize, uvlinesize); | ||
| 2489 | } else { | ||
| 2490 | 9514967 | ff_h264_filter_mb_fast(h, sl, mb_x, mb_y, dest_y, dest_cb, | |
| 2491 | dest_cr, linesize, uvlinesize); | ||
| 2492 | } | ||
| 2493 | } | ||
| 2494 | } | ||
| 2495 | 411450 | sl->slice_type = old_slice_type; | |
| 2496 | 411450 | sl->mb_x = end_x; | |
| 2497 | 411450 | sl->mb_y = end_mb_y - FRAME_MBAFF(h); | |
| 2498 | 411450 | sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale); | |
| 2499 | 411450 | sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale); | |
| 2500 | } | ||
| 2501 | |||
| 2502 | 24071 | static void predict_field_decoding_flag(const H264Context *h, H264SliceContext *sl) | |
| 2503 | { | ||
| 2504 | 24071 | const int mb_xy = sl->mb_x + sl->mb_y * h->mb_stride; | |
| 2505 | 48142 | int mb_type = (h->slice_table[mb_xy - 1] == sl->slice_num) ? | |
| 2506 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24071 times.
|
48142 | h->cur_pic.mb_type[mb_xy - 1] : |
| 2507 |
2/2✓ Branch 0 taken 23935 times.
✓ Branch 1 taken 136 times.
|
24071 | (h->slice_table[mb_xy - h->mb_stride] == sl->slice_num) ? |
| 2508 | 23935 | h->cur_pic.mb_type[mb_xy - h->mb_stride] : 0; | |
| 2509 | 24071 | sl->mb_mbaff = sl->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0; | |
| 2510 | 24071 | } | |
| 2511 | |||
| 2512 | /** | ||
| 2513 | * Draw edges and report progress for the last MB row. | ||
| 2514 | */ | ||
| 2515 | 406890 | static void decode_finish_row(const H264Context *h, H264SliceContext *sl) | |
| 2516 | { | ||
| 2517 | 406890 | int top = 16 * (sl->mb_y >> FIELD_PICTURE(h)); | |
| 2518 | 406890 | int pic_height = 16 * h->mb_height >> FIELD_PICTURE(h); | |
| 2519 | 406890 | int height = 16 << FRAME_MBAFF(h); | |
| 2520 | 406890 | int deblock_border = (16 + 4) << FRAME_MBAFF(h); | |
| 2521 | |||
| 2522 |
2/2✓ Branch 0 taken 331390 times.
✓ Branch 1 taken 75500 times.
|
406890 | if (sl->deblocking_filter) { |
| 2523 |
2/2✓ Branch 0 taken 23015 times.
✓ Branch 1 taken 308375 times.
|
331390 | if ((top + height) >= pic_height) |
| 2524 | 23015 | height += deblock_border; | |
| 2525 | 331390 | top -= deblock_border; | |
| 2526 | } | ||
| 2527 | |||
| 2528 |
3/4✓ Branch 0 taken 406890 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23016 times.
✓ Branch 3 taken 383874 times.
|
406890 | if (top >= pic_height || (top + height) < 0) |
| 2529 | 23016 | return; | |
| 2530 | |||
| 2531 | 383874 | height = FFMIN(height, pic_height - top); | |
| 2532 |
2/2✓ Branch 0 taken 23016 times.
✓ Branch 1 taken 360858 times.
|
383874 | if (top < 0) { |
| 2533 | 23016 | height = top + height; | |
| 2534 | 23016 | top = 0; | |
| 2535 | } | ||
| 2536 | |||
| 2537 | 383874 | ff_h264_draw_horiz_band(h, sl, top, height); | |
| 2538 | |||
| 2539 |
3/4✓ Branch 0 taken 247755 times.
✓ Branch 1 taken 136119 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 247755 times.
|
383874 | if (h->droppable || h->er.error_occurred) |
| 2540 | 136119 | return; | |
| 2541 | |||
| 2542 | 247755 | ff_thread_report_progress(&h->cur_pic_ptr->tf, top + height - 1, | |
| 2543 | 247755 | h->picture_structure == PICT_BOTTOM_FIELD); | |
| 2544 | } | ||
| 2545 | |||
| 2546 | 38042 | static void er_add_slice(H264SliceContext *sl, | |
| 2547 | int startx, int starty, | ||
| 2548 | int endx, int endy, int status) | ||
| 2549 | { | ||
| 2550 |
2/2✓ Branch 0 taken 1200 times.
✓ Branch 1 taken 36842 times.
|
38042 | if (!sl->h264->enable_er) |
| 2551 | 1200 | return; | |
| 2552 | |||
| 2553 | if (CONFIG_ERROR_RESILIENCE) { | ||
| 2554 | 36842 | ff_er_add_slice(sl->er, startx, starty, endx, endy, status); | |
| 2555 | } | ||
| 2556 | } | ||
| 2557 | |||
| 2558 | 38042 | static int decode_slice(struct AVCodecContext *avctx, void *arg) | |
| 2559 | { | ||
| 2560 | 38042 | H264SliceContext *sl = arg; | |
| 2561 | 38042 | const H264Context *h = sl->h264; | |
| 2562 | 38042 | int lf_x_start = sl->mb_x; | |
| 2563 | 38042 | int orig_deblock = sl->deblocking_filter; | |
| 2564 | int ret; | ||
| 2565 | |||
| 2566 | 38042 | sl->linesize = h->cur_pic_ptr->f->linesize[0]; | |
| 2567 | 38042 | sl->uvlinesize = h->cur_pic_ptr->f->linesize[1]; | |
| 2568 | |||
| 2569 | 38042 | ret = alloc_scratch_buffers(sl, sl->linesize); | |
| 2570 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | if (ret < 0) |
| 2571 | ✗ | return ret; | |
| 2572 | |||
| 2573 | 38042 | sl->mb_skip_run = -1; | |
| 2574 | |||
| 2575 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | av_assert0(h->block_offset[15] == (4 * ((scan8[15] - scan8[0]) & 7) << h->pixel_shift) + 4 * sl->linesize * ((scan8[15] - scan8[0]) >> 3)); |
| 2576 | |||
| 2577 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38042 times.
|
38042 | if (h->postpone_filter) |
| 2578 | ✗ | sl->deblocking_filter = 0; | |
| 2579 | |||
| 2580 |
4/4✓ Branch 0 taken 33066 times.
✓ Branch 1 taken 4976 times.
✓ Branch 2 taken 9160 times.
✓ Branch 3 taken 23906 times.
|
38042 | sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME || |
| 2581 | (CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY)); | ||
| 2582 | |||
| 2583 |
5/6✓ Branch 0 taken 36842 times.
✓ Branch 1 taken 1200 times.
✓ Branch 2 taken 27682 times.
✓ Branch 3 taken 9160 times.
✓ Branch 4 taken 27682 times.
✗ Branch 5 not taken.
|
38042 | if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && sl->er->error_status_table) { |
| 2584 | 27682 | const int start_i = av_clip(sl->resync_mb_x + sl->resync_mb_y * h->mb_width, 0, h->mb_num - 1); | |
| 2585 |
2/2✓ Branch 0 taken 5956 times.
✓ Branch 1 taken 21726 times.
|
27682 | if (start_i) { |
| 2586 | 5956 | int prev_status = sl->er->error_status_table[sl->er->mb_index2xy[start_i - 1]]; | |
| 2587 | 5956 | prev_status &= ~ VP_START; | |
| 2588 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5956 times.
|
5956 | if (prev_status != (ER_MV_END | ER_DC_END | ER_AC_END)) |
| 2589 | ✗ | sl->er->error_occurred = 1; | |
| 2590 | } | ||
| 2591 | } | ||
| 2592 | |||
| 2593 |
2/2✓ Branch 0 taken 21301 times.
✓ Branch 1 taken 16741 times.
|
38042 | if (h->ps.pps->cabac) { |
| 2594 | /* realign */ | ||
| 2595 | 21301 | align_get_bits(&sl->gb); | |
| 2596 | |||
| 2597 | /* init cabac */ | ||
| 2598 | 42602 | ret = ff_init_cabac_decoder(&sl->cabac, | |
| 2599 | 21301 | sl->gb.buffer + get_bits_count(&sl->gb) / 8, | |
| 2600 | 21301 | (get_bits_left(&sl->gb) + 7) / 8); | |
| 2601 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21301 times.
|
21301 | if (ret < 0) |
| 2602 | ✗ | return ret; | |
| 2603 | |||
| 2604 | 21301 | ff_h264_init_cabac_states(h, sl); | |
| 2605 | |||
| 2606 | 9581774 | for (;;) { | |
| 2607 | int ret, eos; | ||
| 2608 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9603075 times.
|
9603075 | if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) { |
| 2609 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at %d\n", | |
| 2610 | sl->next_slice_idx); | ||
| 2611 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
| 2612 | sl->mb_y, ER_MB_ERROR); | ||
| 2613 | ✗ | return AVERROR_INVALIDDATA; | |
| 2614 | } | ||
| 2615 | |||
| 2616 | 9603075 | ret = ff_h264_decode_mb_cabac(h, sl); | |
| 2617 | |||
| 2618 |
2/2✓ Branch 0 taken 9603074 times.
✓ Branch 1 taken 1 times.
|
9603075 | if (ret >= 0) |
| 2619 | 9603074 | ff_h264_hl_decode_mb(h, sl); | |
| 2620 | |||
| 2621 | // FIXME optimal? or let mb_decode decode 16x32 ? | ||
| 2622 |
4/4✓ Branch 0 taken 9603074 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 903372 times.
✓ Branch 3 taken 8699702 times.
|
9603075 | if (ret >= 0 && FRAME_MBAFF(h)) { |
| 2623 | 903372 | sl->mb_y++; | |
| 2624 | |||
| 2625 | 903372 | ret = ff_h264_decode_mb_cabac(h, sl); | |
| 2626 | |||
| 2627 |
1/2✓ Branch 0 taken 903372 times.
✗ Branch 1 not taken.
|
903372 | if (ret >= 0) |
| 2628 | 903372 | ff_h264_hl_decode_mb(h, sl); | |
| 2629 | 903372 | sl->mb_y--; | |
| 2630 | } | ||
| 2631 | 9603075 | eos = get_cabac_terminate(&sl->cabac); | |
| 2632 | |||
| 2633 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9603075 times.
|
9603075 | if ((h->workaround_bugs & FF_BUG_TRUNCATED) && |
| 2634 | ✗ | sl->cabac.bytestream > sl->cabac.bytestream_end + 2) { | |
| 2635 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1, | |
| 2636 | sl->mb_y, ER_MB_END); | ||
| 2637 | ✗ | if (sl->mb_x >= lf_x_start) | |
| 2638 | ✗ | loop_filter(h, sl, lf_x_start, sl->mb_x + 1); | |
| 2639 | ✗ | goto finish; | |
| 2640 | } | ||
| 2641 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9603074 times.
|
9603075 | if (sl->cabac.bytestream > sl->cabac.bytestream_end + 2 ) |
| 2642 | 1 | av_log(h->avctx, AV_LOG_DEBUG, "bytestream overread %td\n", sl->cabac.bytestream_end - sl->cabac.bytestream); | |
| 2643 |
4/4✓ Branch 0 taken 9603074 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9603073 times.
|
9603075 | if (ret < 0 || sl->cabac.bytestream > sl->cabac.bytestream_end + 4) { |
| 2644 | 2 | av_log(h->avctx, AV_LOG_ERROR, | |
| 2645 | "error while decoding MB %d %d, bytestream %td\n", | ||
| 2646 | sl->mb_x, sl->mb_y, | ||
| 2647 | 2 | sl->cabac.bytestream_end - sl->cabac.bytestream); | |
| 2648 | 2 | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
| 2649 | sl->mb_y, ER_MB_ERROR); | ||
| 2650 | 2 | return AVERROR_INVALIDDATA; | |
| 2651 | } | ||
| 2652 | |||
| 2653 |
2/2✓ Branch 0 taken 245926 times.
✓ Branch 1 taken 9357147 times.
|
9603073 | if (++sl->mb_x >= h->mb_width) { |
| 2654 | 245926 | loop_filter(h, sl, lf_x_start, sl->mb_x); | |
| 2655 | 245926 | sl->mb_x = lf_x_start = 0; | |
| 2656 | 245926 | decode_finish_row(h, sl); | |
| 2657 | 245926 | ++sl->mb_y; | |
| 2658 |
4/4✓ Branch 0 taken 225002 times.
✓ Branch 1 taken 20924 times.
✓ Branch 2 taken 60241 times.
✓ Branch 3 taken 164761 times.
|
245926 | if (FIELD_OR_MBAFF_PICTURE(h)) { |
| 2659 | 81165 | ++sl->mb_y; | |
| 2660 |
4/4✓ Branch 0 taken 20924 times.
✓ Branch 1 taken 60241 times.
✓ Branch 2 taken 19093 times.
✓ Branch 3 taken 1831 times.
|
81165 | if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height) |
| 2661 | 19093 | predict_field_decoding_flag(h, sl); | |
| 2662 | } | ||
| 2663 | } | ||
| 2664 | |||
| 2665 |
3/4✓ Branch 0 taken 9581774 times.
✓ Branch 1 taken 21299 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9581774 times.
|
9603073 | if (eos || sl->mb_y >= h->mb_height) { |
| 2666 | ff_tlog(h->avctx, "slice end %d %d\n", | ||
| 2667 | get_bits_count(&sl->gb), sl->gb.size_in_bits); | ||
| 2668 | 21299 | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1, | |
| 2669 | sl->mb_y, ER_MB_END); | ||
| 2670 |
2/2✓ Branch 0 taken 1382 times.
✓ Branch 1 taken 19917 times.
|
21299 | if (sl->mb_x > lf_x_start) |
| 2671 | 1382 | loop_filter(h, sl, lf_x_start, sl->mb_x); | |
| 2672 | 21299 | goto finish; | |
| 2673 | } | ||
| 2674 | } | ||
| 2675 | } else { | ||
| 2676 | 4575657 | for (;;) { | |
| 2677 | int ret; | ||
| 2678 | |||
| 2679 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4592398 times.
|
4592398 | if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) { |
| 2680 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at %d\n", | |
| 2681 | sl->next_slice_idx); | ||
| 2682 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
| 2683 | sl->mb_y, ER_MB_ERROR); | ||
| 2684 | ✗ | return AVERROR_INVALIDDATA; | |
| 2685 | } | ||
| 2686 | |||
| 2687 | 4592398 | ret = ff_h264_decode_mb_cavlc(h, sl); | |
| 2688 | |||
| 2689 |
1/2✓ Branch 0 taken 4592398 times.
✗ Branch 1 not taken.
|
4592398 | if (ret >= 0) |
| 2690 | 4592398 | ff_h264_hl_decode_mb(h, sl); | |
| 2691 | |||
| 2692 | // FIXME optimal? or let mb_decode decode 16x32 ? | ||
| 2693 |
3/4✓ Branch 0 taken 4592398 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 254472 times.
✓ Branch 3 taken 4337926 times.
|
4592398 | if (ret >= 0 && FRAME_MBAFF(h)) { |
| 2694 | 254472 | sl->mb_y++; | |
| 2695 | 254472 | ret = ff_h264_decode_mb_cavlc(h, sl); | |
| 2696 | |||
| 2697 |
1/2✓ Branch 0 taken 254472 times.
✗ Branch 1 not taken.
|
254472 | if (ret >= 0) |
| 2698 | 254472 | ff_h264_hl_decode_mb(h, sl); | |
| 2699 | 254472 | sl->mb_y--; | |
| 2700 | } | ||
| 2701 | |||
| 2702 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4592398 times.
|
4592398 | if (ret < 0) { |
| 2703 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
| 2704 | "error while decoding MB %d %d\n", sl->mb_x, sl->mb_y); | ||
| 2705 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
| 2706 | sl->mb_y, ER_MB_ERROR); | ||
| 2707 | ✗ | return ret; | |
| 2708 | } | ||
| 2709 | |||
| 2710 |
2/2✓ Branch 0 taken 160964 times.
✓ Branch 1 taken 4431434 times.
|
4592398 | if (++sl->mb_x >= h->mb_width) { |
| 2711 | 160964 | loop_filter(h, sl, lf_x_start, sl->mb_x); | |
| 2712 | 160964 | sl->mb_x = lf_x_start = 0; | |
| 2713 | 160964 | decode_finish_row(h, sl); | |
| 2714 | 160964 | ++sl->mb_y; | |
| 2715 |
4/4✓ Branch 0 taken 155487 times.
✓ Branch 1 taken 5477 times.
✓ Branch 2 taken 26666 times.
✓ Branch 3 taken 128821 times.
|
160964 | if (FIELD_OR_MBAFF_PICTURE(h)) { |
| 2716 | 32143 | ++sl->mb_y; | |
| 2717 |
4/4✓ Branch 0 taken 5477 times.
✓ Branch 1 taken 26666 times.
✓ Branch 2 taken 4978 times.
✓ Branch 3 taken 499 times.
|
32143 | if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height) |
| 2718 | 4978 | predict_field_decoding_flag(h, sl); | |
| 2719 | } | ||
| 2720 |
2/2✓ Branch 0 taken 12651 times.
✓ Branch 1 taken 148313 times.
|
160964 | if (sl->mb_y >= h->mb_height) { |
| 2721 | ff_tlog(h->avctx, "slice end %d %d\n", | ||
| 2722 | get_bits_count(&sl->gb), sl->gb.size_in_bits); | ||
| 2723 | |||
| 2724 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12651 times.
|
12651 | if ( get_bits_left(&sl->gb) == 0 |
| 2725 | ✗ | || get_bits_left(&sl->gb) > 0 && !(h->avctx->err_recognition & AV_EF_AGGRESSIVE)) { | |
| 2726 | 12651 | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, | |
| 2727 | 12651 | sl->mb_x - 1, sl->mb_y, ER_MB_END); | |
| 2728 | |||
| 2729 | 12651 | goto finish; | |
| 2730 | } else { | ||
| 2731 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, | |
| 2732 | sl->mb_x, sl->mb_y, ER_MB_END); | ||
| 2733 | |||
| 2734 | ✗ | return AVERROR_INVALIDDATA; | |
| 2735 | } | ||
| 2736 | } | ||
| 2737 | } | ||
| 2738 | |||
| 2739 |
4/4✓ Branch 1 taken 238513 times.
✓ Branch 2 taken 4341234 times.
✓ Branch 3 taken 4090 times.
✓ Branch 4 taken 234423 times.
|
4579747 | if (get_bits_left(&sl->gb) <= 0 && sl->mb_skip_run <= 0) { |
| 2740 | ff_tlog(h->avctx, "slice end %d %d\n", | ||
| 2741 | get_bits_count(&sl->gb), sl->gb.size_in_bits); | ||
| 2742 | |||
| 2743 |
1/2✓ Branch 1 taken 4090 times.
✗ Branch 2 not taken.
|
4090 | if (get_bits_left(&sl->gb) == 0) { |
| 2744 | 4090 | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, | |
| 2745 | 4090 | sl->mb_x - 1, sl->mb_y, ER_MB_END); | |
| 2746 |
2/2✓ Branch 0 taken 3178 times.
✓ Branch 1 taken 912 times.
|
4090 | if (sl->mb_x > lf_x_start) |
| 2747 | 3178 | loop_filter(h, sl, lf_x_start, sl->mb_x); | |
| 2748 | |||
| 2749 | 4090 | goto finish; | |
| 2750 | } else { | ||
| 2751 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
| 2752 | sl->mb_y, ER_MB_ERROR); | ||
| 2753 | |||
| 2754 | ✗ | return AVERROR_INVALIDDATA; | |
| 2755 | } | ||
| 2756 | } | ||
| 2757 | } | ||
| 2758 | } | ||
| 2759 | |||
| 2760 | 38040 | finish: | |
| 2761 | 38040 | sl->deblocking_filter = orig_deblock; | |
| 2762 | 38040 | return 0; | |
| 2763 | } | ||
| 2764 | |||
| 2765 | /** | ||
| 2766 | * Call decode_slice() for each context. | ||
| 2767 | * | ||
| 2768 | * @param h h264 master context | ||
| 2769 | */ | ||
| 2770 | 67011 | int ff_h264_execute_decode_slices(H264Context *h) | |
| 2771 | { | ||
| 2772 | 67011 | AVCodecContext *const avctx = h->avctx; | |
| 2773 | H264SliceContext *sl; | ||
| 2774 | 67011 | int context_count = h->nb_slice_ctx_queued; | |
| 2775 | 67011 | int ret = 0; | |
| 2776 | int i, j; | ||
| 2777 | |||
| 2778 | 67011 | h->slice_ctx[0].next_slice_idx = INT_MAX; | |
| 2779 | |||
| 2780 |
3/4✓ Branch 0 taken 67011 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29419 times.
✓ Branch 3 taken 37592 times.
|
67011 | if (h->avctx->hwaccel || context_count < 1) |
| 2781 | 29419 | return 0; | |
| 2782 | |||
| 2783 |
2/4✓ Branch 0 taken 37592 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37592 times.
|
37592 | av_assert0(context_count && h->slice_ctx[context_count - 1].mb_y < h->mb_height); |
| 2784 | |||
| 2785 |
2/2✓ Branch 0 taken 37142 times.
✓ Branch 1 taken 450 times.
|
37592 | if (context_count == 1) { |
| 2786 | |||
| 2787 | 37142 | h->slice_ctx[0].next_slice_idx = h->mb_width * h->mb_height; | |
| 2788 | 37142 | h->postpone_filter = 0; | |
| 2789 | |||
| 2790 | 37142 | ret = decode_slice(avctx, &h->slice_ctx[0]); | |
| 2791 | 37142 | h->mb_y = h->slice_ctx[0].mb_y; | |
| 2792 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 37140 times.
|
37142 | if (ret < 0) |
| 2793 | 2 | goto finish; | |
| 2794 | } else { | ||
| 2795 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
|
450 | av_assert0(context_count > 0); |
| 2796 |
2/2✓ Branch 0 taken 900 times.
✓ Branch 1 taken 450 times.
|
1350 | for (i = 0; i < context_count; i++) { |
| 2797 | 900 | int next_slice_idx = h->mb_width * h->mb_height; | |
| 2798 | int slice_idx; | ||
| 2799 | |||
| 2800 | 900 | sl = &h->slice_ctx[i]; | |
| 2801 | |||
| 2802 | /* make sure none of those slices overlap */ | ||
| 2803 | 900 | slice_idx = sl->mb_y * h->mb_width + sl->mb_x; | |
| 2804 |
2/2✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 900 times.
|
2700 | for (j = 0; j < context_count; j++) { |
| 2805 | 1800 | H264SliceContext *sl2 = &h->slice_ctx[j]; | |
| 2806 | 1800 | int slice_idx2 = sl2->mb_y * h->mb_width + sl2->mb_x; | |
| 2807 | |||
| 2808 |
4/4✓ Branch 0 taken 900 times.
✓ Branch 1 taken 900 times.
✓ Branch 2 taken 450 times.
✓ Branch 3 taken 450 times.
|
1800 | if (i == j || slice_idx2 < slice_idx) |
| 2809 | 1350 | continue; | |
| 2810 | 450 | next_slice_idx = FFMIN(next_slice_idx, slice_idx2); | |
| 2811 | } | ||
| 2812 | 900 | sl->next_slice_idx = next_slice_idx; | |
| 2813 | } | ||
| 2814 | |||
| 2815 | 450 | avctx->execute(avctx, decode_slice, h->slice_ctx, | |
| 2816 | NULL, context_count, sizeof(h->slice_ctx[0])); | ||
| 2817 | |||
| 2818 | /* pull back stuff from slices to master context */ | ||
| 2819 | 450 | sl = &h->slice_ctx[context_count - 1]; | |
| 2820 | 450 | h->mb_y = sl->mb_y; | |
| 2821 | |||
| 2822 |
1/2✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
|
450 | if (h->postpone_filter) { |
| 2823 | ✗ | h->postpone_filter = 0; | |
| 2824 | |||
| 2825 | ✗ | for (i = 0; i < context_count; i++) { | |
| 2826 | int y_end, x_end; | ||
| 2827 | |||
| 2828 | ✗ | sl = &h->slice_ctx[i]; | |
| 2829 | ✗ | y_end = FFMIN(sl->mb_y + 1, h->mb_height); | |
| 2830 | ✗ | x_end = (sl->mb_y >= h->mb_height) ? h->mb_width : sl->mb_x; | |
| 2831 | |||
| 2832 | ✗ | for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) { | |
| 2833 | ✗ | sl->mb_y = j; | |
| 2834 | ✗ | loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x, | |
| 2835 | ✗ | j == y_end - 1 ? x_end : h->mb_width); | |
| 2836 | } | ||
| 2837 | } | ||
| 2838 | } | ||
| 2839 | } | ||
| 2840 | |||
| 2841 | 450 | finish: | |
| 2842 | 37592 | h->nb_slice_ctx_queued = 0; | |
| 2843 | 37592 | return ret; | |
| 2844 | } | ||
| 2845 |