| 525 | } |
| 526 | |
| 527 | int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, |
| 528 | void *logctx, int nal_length_size, |
| 529 | enum AVCodecID codec_id, int flags) |
| 530 | { |
| 531 | GetByteContext bc; |
| 532 | int consumed, ret = 0; |
| 533 | int next_avc = (flags & H2645_FLAG_IS_NALFF) ? 0 : length; |
| 534 | int64_t padding = (flags & H2645_FLAG_SMALL_PADDING) ? 0 : MAX_MBPAIR_SIZE; |
| 535 | |
| 536 | bytestream2_init(&bc, buf, length); |
| 537 | alloc_rbsp_buffer(&pkt->rbsp, length + padding, !!(flags & H2645_FLAG_USE_REF)); |
| 538 | |
| 539 | if (!pkt->rbsp.rbsp_buffer) |
| 540 | return AVERROR(ENOMEM); |
| 541 | |
| 542 | pkt->rbsp.rbsp_buffer_size = 0; |
| 543 | pkt->nb_nals = 0; |
| 544 | while (bytestream2_get_bytes_left(&bc) >= 4) { |
| 545 | H2645NAL *nal; |
| 546 | int extract_length = 0; |
| 547 | int skip_trailing_zeros = 1; |
| 548 | |
| 549 | if (bytestream2_tell(&bc) == next_avc) { |
| 550 | int i = 0; |
| 551 | extract_length = get_nalsize(nal_length_size, |
| 552 | bc.buffer, bytestream2_get_bytes_left(&bc), &i, logctx); |
| 553 | if (extract_length < 0) |
| 554 | return extract_length; |
| 555 | |
| 556 | bytestream2_skip(&bc, nal_length_size); |
| 557 | |
| 558 | next_avc = bytestream2_tell(&bc) + extract_length; |
| 559 | } else { |
| 560 | int buf_index; |
| 561 | |
| 562 | if (bytestream2_tell(&bc) > next_avc) |
| 563 | av_log(logctx, AV_LOG_WARNING, "Exceeded next NALFF position, re-syncing.\n"); |
| 564 | |
| 565 | /* search start code */ |
| 566 | buf_index = find_next_start_code(bc.buffer, buf + next_avc); |
| 567 | |
| 568 | bytestream2_skip(&bc, buf_index); |
| 569 | |
| 570 | if (!bytestream2_get_bytes_left(&bc)) { |
| 571 | if (pkt->nb_nals > 0) { |
| 572 | // No more start codes: we discarded some irrelevant |
| 573 | // bytes at the end of the packet. |
| 574 | return 0; |
| 575 | } else { |
| 576 | av_log(logctx, AV_LOG_ERROR, "No start code is found.\n"); |
| 577 | return AVERROR_INVALIDDATA; |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | extract_length = FFMIN(bytestream2_get_bytes_left(&bc), next_avc - bytestream2_tell(&bc)); |
| 582 | |
| 583 | if (bytestream2_tell(&bc) >= next_avc) { |
| 584 | /* skip to the start of the next NAL */ |
no test coverage detected