| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "libavutil/attributes.h" | ||
| 20 | #include "libavutil/avassert.h" | ||
| 21 | #include "libavutil/mem.h" | ||
| 22 | |||
| 23 | #include "bytestream.h" | ||
| 24 | #include "cbs.h" | ||
| 25 | #include "cbs_internal.h" | ||
| 26 | #include "cbs_h2645.h" | ||
| 27 | #include "h264.h" | ||
| 28 | #include "h2645_parse.h" | ||
| 29 | #include "vvc.h" | ||
| 30 | |||
| 31 | #include "hevc/hevc.h" | ||
| 32 | |||
| 33 | 19 | int ff_cbs_h2645_payload_extension_present(GetBitContext *gbc, uint32_t payload_size, | |
| 34 | int cur_pos) | ||
| 35 | { | ||
| 36 | 19 | int bits_left = payload_size * 8 - cur_pos; | |
| 37 |
4/4✓ Branch 0 taken 14 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 9 times.
|
24 | return (bits_left > 0 && |
| 38 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | (bits_left > 7 || show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1))); |
| 39 | } | ||
| 40 | |||
| 41 | 348301 | int ff_cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc, | |
| 42 | const char *name, const int *subscripts, | ||
| 43 | uint32_t *write_to, | ||
| 44 | uint32_t range_min, uint32_t range_max) | ||
| 45 | { | ||
| 46 | uint32_t leading_bits, value; | ||
| 47 | int max_length, leading_zeroes; | ||
| 48 | |||
| 49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 348301 times.
|
348301 | CBS_TRACE_READ_START(); |
| 50 | |||
| 51 |
2/2✓ Branch 1 taken 11580 times.
✓ Branch 2 taken 336721 times.
|
348301 | max_length = FFMIN(get_bits_left(gbc), 32); |
| 52 | |||
| 53 |
1/2✓ Branch 0 taken 348301 times.
✗ Branch 1 not taken.
|
348301 | leading_bits = max_length ? show_bits_long(gbc, max_length) : 0; |
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 348301 times.
|
348301 | if (leading_bits == 0) { |
| 55 | ✗ | if (max_length >= 32) { | |
| 56 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at " | |
| 57 | "%s: more than 31 zeroes.\n", name); | ||
| 58 | ✗ | return AVERROR_INVALIDDATA; | |
| 59 | } else { | ||
| 60 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at " | |
| 61 | "%s: bitstream ended.\n", name); | ||
| 62 | ✗ | return AVERROR_INVALIDDATA; | |
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | 348301 | leading_zeroes = max_length - 1 - av_log2(leading_bits); | |
| 67 | 348301 | skip_bits_long(gbc, leading_zeroes); | |
| 68 | |||
| 69 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 348301 times.
|
348301 | if (get_bits_left(gbc) < leading_zeroes + 1) { |
| 70 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at " | |
| 71 | "%s: bitstream ended.\n", name); | ||
| 72 | ✗ | return AVERROR_INVALIDDATA; | |
| 73 | } | ||
| 74 | |||
| 75 | 348301 | value = get_bits_long(gbc, leading_zeroes + 1) - 1; | |
| 76 | |||
| 77 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 348301 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
348301 | CBS_TRACE_READ_END(); |
| 78 | |||
| 79 |
2/4✓ Branch 0 taken 348301 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 348301 times.
|
348301 | if (value < range_min || value > range_max) { |
| 80 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
| 81 | "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n", | ||
| 82 | name, value, range_min, range_max); | ||
| 83 | ✗ | return AVERROR_INVALIDDATA; | |
| 84 | } | ||
| 85 | |||
| 86 | 348301 | *write_to = value; | |
| 87 | 348301 | return 0; | |
| 88 | } | ||
| 89 | |||
| 90 | 167358 | int ff_cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc, | |
| 91 | const char *name, const int *subscripts, | ||
| 92 | int32_t *write_to, | ||
| 93 | int32_t range_min, int32_t range_max) | ||
| 94 | { | ||
| 95 | uint32_t leading_bits, unsigned_value; | ||
| 96 | int max_length, leading_zeroes; | ||
| 97 | int32_t value; | ||
| 98 | |||
| 99 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 167358 times.
|
167358 | CBS_TRACE_READ_START(); |
| 100 | |||
| 101 |
2/2✓ Branch 1 taken 9980 times.
✓ Branch 2 taken 157378 times.
|
167358 | max_length = FFMIN(get_bits_left(gbc), 32); |
| 102 | |||
| 103 |
1/2✓ Branch 0 taken 167358 times.
✗ Branch 1 not taken.
|
167358 | leading_bits = max_length ? show_bits_long(gbc, max_length) : 0; |
| 104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 167358 times.
|
167358 | if (leading_bits == 0) { |
| 105 | ✗ | if (max_length >= 32) { | |
| 106 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at " | |
| 107 | "%s: more than 31 zeroes.\n", name); | ||
| 108 | ✗ | return AVERROR_INVALIDDATA; | |
| 109 | } else { | ||
| 110 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at " | |
| 111 | "%s: bitstream ended.\n", name); | ||
| 112 | ✗ | return AVERROR_INVALIDDATA; | |
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | 167358 | leading_zeroes = max_length - 1 - av_log2(leading_bits); | |
| 117 | 167358 | skip_bits_long(gbc, leading_zeroes); | |
| 118 | |||
| 119 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 167358 times.
|
167358 | if (get_bits_left(gbc) < leading_zeroes + 1) { |
| 120 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at " | |
| 121 | "%s: bitstream ended.\n", name); | ||
| 122 | ✗ | return AVERROR_INVALIDDATA; | |
| 123 | } | ||
| 124 | |||
| 125 | 167358 | unsigned_value = get_bits_long(gbc, leading_zeroes + 1); | |
| 126 | |||
| 127 |
2/2✓ Branch 0 taken 89843 times.
✓ Branch 1 taken 77515 times.
|
167358 | if (unsigned_value & 1) |
| 128 | 89843 | value = -(int32_t)(unsigned_value / 2); | |
| 129 | else | ||
| 130 | 77515 | value = unsigned_value / 2; | |
| 131 | |||
| 132 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 167358 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
167358 | CBS_TRACE_READ_END(); |
| 133 | |||
| 134 |
2/4✓ Branch 0 taken 167358 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 167358 times.
|
167358 | if (value < range_min || value > range_max) { |
| 135 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
| 136 | "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n", | ||
| 137 | name, value, range_min, range_max); | ||
| 138 | ✗ | return AVERROR_INVALIDDATA; | |
| 139 | } | ||
| 140 | |||
| 141 | 167358 | *write_to = value; | |
| 142 | 167358 | return 0; | |
| 143 | } | ||
| 144 | |||
| 145 | 155423 | int ff_cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, | |
| 146 | const char *name, const int *subscripts, | ||
| 147 | uint32_t value, | ||
| 148 | uint32_t range_min, uint32_t range_max) | ||
| 149 | { | ||
| 150 | int len; | ||
| 151 | |||
| 152 |
2/2✓ Branch 0 taken 152354 times.
✓ Branch 1 taken 3069 times.
|
155423 | CBS_TRACE_WRITE_START(); |
| 153 | |||
| 154 |
2/4✓ Branch 0 taken 155423 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 155423 times.
|
155423 | if (value < range_min || value > range_max) { |
| 155 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
| 156 | "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n", | ||
| 157 | name, value, range_min, range_max); | ||
| 158 | ✗ | return AVERROR_INVALIDDATA; | |
| 159 | } | ||
| 160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 155423 times.
|
155423 | av_assert0(value != UINT32_MAX); |
| 161 | |||
| 162 | 155423 | len = av_log2(value + 1); | |
| 163 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 155423 times.
|
155423 | if (put_bits_left(pbc) < 2 * len + 1) |
| 164 | ✗ | return AVERROR(ENOSPC); | |
| 165 | |||
| 166 | 155423 | put_bits(pbc, len, 0); | |
| 167 |
1/2✓ Branch 0 taken 155423 times.
✗ Branch 1 not taken.
|
155423 | if (len + 1 < 32) |
| 168 | 155423 | put_bits(pbc, len + 1, value + 1); | |
| 169 | else | ||
| 170 | ✗ | put_bits32(pbc, value + 1); | |
| 171 | |||
| 172 |
3/4✓ Branch 0 taken 152354 times.
✓ Branch 1 taken 3069 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 152354 times.
|
155423 | CBS_TRACE_WRITE_END(); |
| 173 | |||
| 174 | 155423 | return 0; | |
| 175 | } | ||
| 176 | |||
| 177 | 84109 | int ff_cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, | |
| 178 | const char *name, const int *subscripts, | ||
| 179 | int32_t value, | ||
| 180 | int32_t range_min, int32_t range_max) | ||
| 181 | { | ||
| 182 | int len; | ||
| 183 | uint32_t uvalue; | ||
| 184 | |||
| 185 |
2/2✓ Branch 0 taken 83539 times.
✓ Branch 1 taken 570 times.
|
84109 | CBS_TRACE_WRITE_START(); |
| 186 | |||
| 187 |
2/4✓ Branch 0 taken 84109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 84109 times.
|
84109 | if (value < range_min || value > range_max) { |
| 188 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
| 189 | "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n", | ||
| 190 | name, value, range_min, range_max); | ||
| 191 | ✗ | return AVERROR_INVALIDDATA; | |
| 192 | } | ||
| 193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 84109 times.
|
84109 | av_assert0(value != INT32_MIN); |
| 194 | |||
| 195 |
2/2✓ Branch 0 taken 19190 times.
✓ Branch 1 taken 64919 times.
|
84109 | if (value == 0) |
| 196 | 19190 | uvalue = 0; | |
| 197 |
2/2✓ Branch 0 taken 36580 times.
✓ Branch 1 taken 28339 times.
|
64919 | else if (value > 0) |
| 198 | 36580 | uvalue = 2 * (uint32_t)value - 1; | |
| 199 | else | ||
| 200 | 28339 | uvalue = 2 * (uint32_t)-value; | |
| 201 | |||
| 202 | 84109 | len = av_log2(uvalue + 1); | |
| 203 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 84109 times.
|
84109 | if (put_bits_left(pbc) < 2 * len + 1) |
| 204 | ✗ | return AVERROR(ENOSPC); | |
| 205 | |||
| 206 | 84109 | put_bits(pbc, len, 0); | |
| 207 |
1/2✓ Branch 0 taken 84109 times.
✗ Branch 1 not taken.
|
84109 | if (len + 1 < 32) |
| 208 | 84109 | put_bits(pbc, len + 1, uvalue + 1); | |
| 209 | else | ||
| 210 | ✗ | put_bits32(pbc, uvalue + 1); | |
| 211 | |||
| 212 |
3/4✓ Branch 0 taken 83539 times.
✓ Branch 1 taken 570 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 83539 times.
|
84109 | CBS_TRACE_WRITE_END(); |
| 213 | |||
| 214 | 84109 | return 0; | |
| 215 | } | ||
| 216 | |||
| 217 | 29956 | int ff_cbs_h2645_read_more_rbsp_data(GetBitContext *gbc) | |
| 218 | { | ||
| 219 | 29956 | int bits_left = get_bits_left(gbc); | |
| 220 |
2/2✓ Branch 0 taken 22389 times.
✓ Branch 1 taken 7567 times.
|
29956 | if (bits_left > 8) |
| 221 | 22389 | return 1; | |
| 222 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7567 times.
|
7567 | if (bits_left == 0) |
| 223 | ✗ | return 0; | |
| 224 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 2 taken 7556 times.
|
7567 | if (show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1)) |
| 225 | 11 | return 1; | |
| 226 | 7556 | return 0; | |
| 227 | } | ||
| 228 | |||
| 229 | 12592 | int ff_cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, | |
| 230 | CodedBitstreamFragment *frag, | ||
| 231 | const H2645Packet *packet) | ||
| 232 | { | ||
| 233 | int err, i; | ||
| 234 | |||
| 235 |
2/2✓ Branch 0 taken 38706 times.
✓ Branch 1 taken 12592 times.
|
51298 | for (i = 0; i < packet->nb_nals; i++) { |
| 236 | 38706 | const H2645NAL *nal = &packet->nals[i]; | |
| 237 | AVBufferRef *ref; | ||
| 238 | 38706 | size_t size = nal->size; | |
| 239 | 38706 | enum AVCodecID codec_id = ctx->codec->codec_id; | |
| 240 | |||
| 241 |
3/4✓ Branch 0 taken 9960 times.
✓ Branch 1 taken 28746 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9960 times.
|
38706 | if (codec_id == AV_CODEC_ID_HEVC && nal->nuh_layer_id > 0 && |
| 242 | ✗ | (nal->type < HEVC_NAL_VPS || nal->type > HEVC_NAL_PPS)) | |
| 243 | ✗ | continue; | |
| 244 | |||
| 245 | // Remove trailing zeroes. | ||
| 246 |
3/4✓ Branch 0 taken 47285 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8579 times.
✓ Branch 3 taken 38706 times.
|
47285 | while (size > 0 && nal->data[size - 1] == 0) |
| 247 | 8579 | --size; | |
| 248 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38706 times.
|
38706 | if (size == 0) { |
| 249 | ✗ | av_log(ctx->log_ctx, AV_LOG_VERBOSE, "Discarding empty 0 NAL unit\n"); | |
| 250 | ✗ | continue; | |
| 251 | } | ||
| 252 | |||
| 253 | 77412 | ref = (nal->data == nal->raw_data) ? frag->data_ref | |
| 254 |
2/2✓ Branch 0 taken 37231 times.
✓ Branch 1 taken 1475 times.
|
38706 | : packet->rbsp.rbsp_buffer_ref; |
| 255 | |||
| 256 | 38706 | err = ff_cbs_append_unit_data(frag, nal->type, | |
| 257 | 38706 | (uint8_t*)nal->data, size, ref); | |
| 258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38706 times.
|
38706 | if (err < 0) |
| 259 | ✗ | return err; | |
| 260 | } | ||
| 261 | |||
| 262 | 12592 | return 0; | |
| 263 | } | ||
| 264 | |||
| 265 | 14273 | int ff_cbs_h2645_write_slice_data(CodedBitstreamContext *ctx, | |
| 266 | PutBitContext *pbc, const uint8_t *data, | ||
| 267 | size_t data_size, int data_bit_start) | ||
| 268 | { | ||
| 269 | 14273 | size_t rest = data_size - (data_bit_start + 7) / 8; | |
| 270 | 14273 | const uint8_t *pos = data + data_bit_start / 8; | |
| 271 | |||
| 272 |
2/4✓ Branch 0 taken 14273 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14273 times.
|
14273 | av_assert0(data_bit_start >= 0 && |
| 273 | data_size > data_bit_start / 8); | ||
| 274 | |||
| 275 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 14273 times.
|
14273 | if (data_size * 8 + 8 > put_bits_left(pbc)) |
| 276 | ✗ | return AVERROR(ENOSPC); | |
| 277 | |||
| 278 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 14272 times.
|
14273 | if (!rest) |
| 279 | 1 | goto rbsp_stop_one_bit; | |
| 280 | |||
| 281 | // First copy the remaining bits of the first byte | ||
| 282 | // The above check ensures that we do not accidentally | ||
| 283 | // copy beyond the rbsp_stop_one_bit. | ||
| 284 |
2/2✓ Branch 0 taken 3729 times.
✓ Branch 1 taken 10543 times.
|
14272 | if (data_bit_start % 8) |
| 285 | 3729 | put_bits(pbc, 8 - data_bit_start % 8, | |
| 286 | 3729 | *pos++ & MAX_UINT_BITS(8 - data_bit_start % 8)); | |
| 287 | |||
| 288 |
2/2✓ Branch 1 taken 14163 times.
✓ Branch 2 taken 109 times.
|
14272 | if (put_bits_count(pbc) % 8 == 0) { |
| 289 | // If the writer is aligned at this point, | ||
| 290 | // memcpy can be used to improve performance. | ||
| 291 | // This happens normally for CABAC. | ||
| 292 | 14163 | flush_put_bits(pbc); | |
| 293 | 14163 | memcpy(put_bits_ptr(pbc), pos, rest); | |
| 294 | 14163 | skip_put_bytes(pbc, rest); | |
| 295 | } else { | ||
| 296 | // If not, we have to copy manually. | ||
| 297 | // rbsp_stop_one_bit forces us to special-case | ||
| 298 | // the last byte. | ||
| 299 | uint8_t temp; | ||
| 300 | int i; | ||
| 301 | |||
| 302 |
2/2✓ Branch 0 taken 98762 times.
✓ Branch 1 taken 109 times.
|
98871 | for (; rest > 4; rest -= 4, pos += 4) |
| 303 | 98762 | put_bits32(pbc, AV_RB32(pos)); | |
| 304 | |||
| 305 |
2/2✓ Branch 0 taken 165 times.
✓ Branch 1 taken 109 times.
|
274 | for (; rest > 1; rest--, pos++) |
| 306 | 165 | put_bits(pbc, 8, *pos); | |
| 307 | |||
| 308 | 109 | rbsp_stop_one_bit: | |
| 309 |
2/2✓ Branch 0 taken 109 times.
✓ Branch 1 taken 1 times.
|
110 | temp = rest ? *pos : *pos & MAX_UINT_BITS(8 - data_bit_start % 8); |
| 310 | |||
| 311 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 110 times.
|
110 | av_assert0(temp); |
| 312 | 110 | i = ff_ctz(*pos); | |
| 313 | 110 | temp = temp >> i; | |
| 314 |
2/2✓ Branch 0 taken 109 times.
✓ Branch 1 taken 1 times.
|
110 | i = rest ? (8 - i) : (8 - i - data_bit_start % 8); |
| 315 | 110 | put_bits(pbc, i, temp); | |
| 316 |
2/2✓ Branch 1 taken 92 times.
✓ Branch 2 taken 18 times.
|
110 | if (put_bits_count(pbc) % 8) |
| 317 | 92 | put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0); | |
| 318 | } | ||
| 319 | |||
| 320 | 14273 | return 0; | |
| 321 | } | ||
| 322 | |||
| 323 | 21877 | int ff_cbs_h2645_unit_requires_zero_byte(enum AVCodecID codec_id, | |
| 324 | CodedBitstreamUnitType type, | ||
| 325 | int nal_unit_index) | ||
| 326 | { | ||
| 327 | // Section B.1.2 in H.264, section B.2.2 in H.265, H.266. | ||
| 328 |
2/2✓ Branch 0 taken 7327 times.
✓ Branch 1 taken 14550 times.
|
21877 | if (nal_unit_index == 0) { |
| 329 | // Assume that this is the first NAL unit in an access unit. | ||
| 330 | 7327 | return 1; | |
| 331 | } | ||
| 332 |
2/2✓ Branch 0 taken 5028 times.
✓ Branch 1 taken 9522 times.
|
14550 | if (codec_id == AV_CODEC_ID_H264) |
| 333 |
4/4✓ Branch 0 taken 5018 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 450 times.
✓ Branch 3 taken 4568 times.
|
5028 | return type == H264_NAL_SPS || type == H264_NAL_PPS; |
| 334 |
2/2✓ Branch 0 taken 5877 times.
✓ Branch 1 taken 3645 times.
|
9522 | if (codec_id == AV_CODEC_ID_HEVC) |
| 335 |
6/6✓ Branch 0 taken 5874 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 5812 times.
✓ Branch 3 taken 62 times.
✓ Branch 4 taken 60 times.
✓ Branch 5 taken 5752 times.
|
5877 | return type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS; |
| 336 |
1/2✓ Branch 0 taken 3645 times.
✗ Branch 1 not taken.
|
3645 | if (codec_id == AV_CODEC_ID_VVC) |
| 337 |
4/4✓ Branch 0 taken 2642 times.
✓ Branch 1 taken 1003 times.
✓ Branch 2 taken 438 times.
✓ Branch 3 taken 2204 times.
|
3645 | return type >= VVC_OPI_NUT && type <= VVC_SUFFIX_APS_NUT; |
| 338 | ✗ | return 0; | |
| 339 | } | ||
| 340 | |||
| 341 | 7328 | int ff_cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, | |
| 342 | CodedBitstreamFragment *frag) | ||
| 343 | { | ||
| 344 | uint8_t *data; | ||
| 345 | size_t max_size, dp, sp; | ||
| 346 | int err, i, zero_run; | ||
| 347 | |||
| 348 |
2/2✓ Branch 0 taken 21877 times.
✓ Branch 1 taken 7328 times.
|
29205 | for (i = 0; i < frag->nb_units; i++) { |
| 349 | // Data should already all have been written when we get here. | ||
| 350 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21877 times.
|
21877 | av_assert0(frag->units[i].data); |
| 351 | } | ||
| 352 | |||
| 353 | 7328 | max_size = 0; | |
| 354 |
2/2✓ Branch 0 taken 21877 times.
✓ Branch 1 taken 7328 times.
|
29205 | for (i = 0; i < frag->nb_units; i++) { |
| 355 | // Start code + content with worst-case emulation prevention. | ||
| 356 | 21877 | max_size += 4 + frag->units[i].data_size * 3 / 2; | |
| 357 | } | ||
| 358 | |||
| 359 | 7328 | data = av_realloc(NULL, max_size + AV_INPUT_BUFFER_PADDING_SIZE); | |
| 360 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7328 times.
|
7328 | if (!data) |
| 361 | ✗ | return AVERROR(ENOMEM); | |
| 362 | |||
| 363 | 7328 | dp = 0; | |
| 364 |
2/2✓ Branch 0 taken 21877 times.
✓ Branch 1 taken 7328 times.
|
29205 | for (i = 0; i < frag->nb_units; i++) { |
| 365 | 21877 | CodedBitstreamUnit *unit = &frag->units[i]; | |
| 366 | |||
| 367 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21877 times.
|
21877 | if (unit->data_bit_padding > 0) { |
| 368 | ✗ | if (i < frag->nb_units - 1) | |
| 369 | ✗ | av_log(ctx->log_ctx, AV_LOG_WARNING, "Probably invalid " | |
| 370 | "unaligned padding on non-final NAL unit.\n"); | ||
| 371 | else | ||
| 372 | ✗ | frag->data_bit_padding = unit->data_bit_padding; | |
| 373 | } | ||
| 374 | |||
| 375 |
2/2✓ Branch 1 taken 8350 times.
✓ Branch 2 taken 13527 times.
|
21877 | if (ff_cbs_h2645_unit_requires_zero_byte(ctx->codec->codec_id, unit->type, i)) { |
| 376 | // zero_byte | ||
| 377 | 8350 | data[dp++] = 0; | |
| 378 | } | ||
| 379 | // start_code_prefix_one_3bytes | ||
| 380 | 21877 | data[dp++] = 0; | |
| 381 | 21877 | data[dp++] = 0; | |
| 382 | 21877 | data[dp++] = 1; | |
| 383 | |||
| 384 | 21877 | zero_run = 0; | |
| 385 |
2/2✓ Branch 0 taken 19230787 times.
✓ Branch 1 taken 21877 times.
|
19252664 | for (sp = 0; sp < unit->data_size; sp++) { |
| 386 |
2/2✓ Branch 0 taken 19223304 times.
✓ Branch 1 taken 7483 times.
|
19230787 | if (zero_run < 2) { |
| 387 |
2/2✓ Branch 0 taken 157971 times.
✓ Branch 1 taken 19065333 times.
|
19223304 | if (unit->data[sp] == 0) |
| 388 | 157971 | ++zero_run; | |
| 389 | else | ||
| 390 | 19065333 | zero_run = 0; | |
| 391 | } else { | ||
| 392 |
2/2✓ Branch 0 taken 1325 times.
✓ Branch 1 taken 6158 times.
|
7483 | if ((unit->data[sp] & ~3) == 0) { |
| 393 | // emulation_prevention_three_byte | ||
| 394 | 1325 | data[dp++] = 3; | |
| 395 | } | ||
| 396 | 7483 | zero_run = unit->data[sp] == 0; | |
| 397 | } | ||
| 398 | 19230787 | data[dp++] = unit->data[sp]; | |
| 399 | } | ||
| 400 | } | ||
| 401 | |||
| 402 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7328 times.
|
7328 | av_assert0(dp <= max_size); |
| 403 | 7328 | err = av_reallocp(&data, dp + AV_INPUT_BUFFER_PADDING_SIZE); | |
| 404 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7328 times.
|
7328 | if (err) |
| 405 | ✗ | return err; | |
| 406 | 7328 | memset(data + dp, 0, AV_INPUT_BUFFER_PADDING_SIZE); | |
| 407 | |||
| 408 | 7328 | frag->data_ref = av_buffer_create(data, dp + AV_INPUT_BUFFER_PADDING_SIZE, | |
| 409 | NULL, NULL, 0); | ||
| 410 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7328 times.
|
7328 | if (!frag->data_ref) { |
| 411 | ✗ | av_freep(&data); | |
| 412 | ✗ | return AVERROR(ENOMEM); | |
| 413 | } | ||
| 414 | |||
| 415 | 7328 | frag->data = data; | |
| 416 | 7328 | frag->data_size = dp; | |
| 417 | |||
| 418 | 7328 | return 0; | |
| 419 | } | ||
| 420 |