On 5/26/2023 7:31 AM, Dawid Kozinski wrote:
+static int get_temporal_id(const uint8_t *bits, int bits_size) +{ + int temporal_id = 0; + short t = 0; + + if (bits_size >= EVC_NALU_HEADER_SIZE) { + unsigned char *p = (unsigned char *)bits; + // forbidden_zero_bit + if ((p[0] & 0x80) != 0) + return -1; + + for (int i = 0; i < EVC_NALU_HEADER_SIZE; i++) + t = (t << 8) | p[i];
I think this can be replaced with AV_RB16.
+ + temporal_id = (t >> 6) & 0x0007; + } + + return temporal_id; +}
[...]
+static uint32_t read_nal_unit_length(const uint8_t *bits, int bits_size) +{ + uint32_t nalu_len = 0; + + if (bits_size >= EVC_NALU_LENGTH_PREFIX_SIZE) { + + int t = 0; + unsigned char *p = (unsigned char *)bits; + + for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++) + t = (t << 8) | p[i];
AV_RB32.
+ + nalu_len = t; + if (nalu_len == 0) // Invalid bitstream size + return 0; + } + + return nalu_len; +}
[...]
+static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out) +{ + EVCMergeContext *ctx = bsf->priv_data; + AVPacket *in = ctx->in; + + int free_space = 0; + size_t nalu_size = 0; + uint8_t *nalu = NULL; + int au_end_found = 0; + int err; + + err = ff_bsf_get_packet_ref(bsf, in); + if (err < 0) + return err; + + nalu_size = read_nal_unit_length(in->data, EVC_NALU_LENGTH_PREFIX_SIZE); + if(nalu_size <= 0) { + av_packet_unref(in); + return AVERROR_INVALIDDATA; + } + + nalu = in->data + EVC_NALU_LENGTH_PREFIX_SIZE; + nalu_size = in->size - EVC_NALU_LENGTH_PREFIX_SIZE; + + // NAL unit parsing needed to determine if end of AU was found + err = parse_nal_unit(nalu, nalu_size, bsf); + if (err < 0) { + av_log(bsf, AV_LOG_ERROR, "NAL Unit parsing error\n"); + av_packet_unref(in); + + return err; + } + + au_end_found = end_of_access_unit_found(bsf); + + free_space = ctx->au_buffer.capacity - ctx->au_buffer.data_size; + while( free_space < in->size ) { + ctx->au_buffer.capacity *= 2; + free_space = ctx->au_buffer.capacity - ctx->au_buffer.data_size; + + if(free_space >= in->size) { + ctx->au_buffer.data = av_realloc(ctx->au_buffer.data, ctx->au_buffer.capacity); + } + } + + memcpy(ctx->au_buffer.data + ctx->au_buffer.data_size, in->data, in->size);
This is including the Annex-B's nal_unit_lenght value into the assembled packet. I assume libxevd expects this? Also, is it defined as part of the ISOBMFF encapsulation? Patch 07/10 does not seem to strip it.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".