[FFmpeg-devel] [PATCH v2 03/10] avcodec: add bitstream parser for H266/VVC
James Almer
jamrial at gmail.com
Mon Oct 24 17:38:16 EEST 2022
On 10/24/2022 11:06 AM, Thomas Siedel wrote:
> +static int combine_au(AVCodecParserContext *ctx, AVCodecContext *avctx,
> + const uint8_t **buf, int *buf_size)
> +{
This is being called only when you first assembled AUs from what's
assumed to be raw input. When PARSER_FLAG_COMPLETE_FRAMES is set, it
should also parse the AU for bitstream information.
> + VVCParserContext *s = ctx->priv_data;
> + CodedBitstreamFragment *pu = &s->picture_unit;
> + int ret;
> +
> + s->cbc->log_ctx = avctx;
> +
> + if (avctx->extradata_size && !s->parsed_extradata) {
> + s->parsed_extradata = 1;
> +
> + if ((ret = ff_cbs_read(s->cbc, pu, avctx->extradata, avctx->extradata_size)) < 0)
ff_cbs_read_extradata_from_codec()
> + av_log(avctx, AV_LOG_WARNING, "Failed to parse extradata.\n");
> +
> + ff_cbs_fragment_reset(pu);
> + }
> + av_packet_unref(&s->last_au);
> + ret = parse_nal_units(ctx, *buf, *buf_size, avctx);
> + if (ret == 0) {
> + if (s->last_au.size) {
> + *buf = s->last_au.data;
> + *buf_size = s->last_au.size;
> + } else {
> + //no output
> + ret = 1;
> + }
> + }
> + s->cbc->log_ctx = NULL;
> + return ret;
> +}
> +
> +static int vvc_parser_parse(AVCodecParserContext *ctx, AVCodecContext *avctx,
> + const uint8_t **poutbuf, int *poutbuf_size,
> + const uint8_t *buf, int buf_size)
> +{
> + int next;
> + VVCParserContext *s = ctx->priv_data;
> + ParseContext *pc = &s->pc;
> +
> + if (avctx->extradata && !s->parsed_extradata) {
> + av_log(avctx, AV_LOG_INFO, "extra data is not supported yet.\n");
> + return AVERROR_PATCHWELCOME;
> + }
> +
> + if (ctx->flags & PARSER_FLAG_COMPLETE_FRAMES) {
> + next = buf_size;
> + } else {
> + int ret, flush = !buf_size;
> + next = find_frame_end(ctx, buf, buf_size);
> + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0)
> + goto no_out;
> + ret = combine_au(ctx, avctx, &buf, &buf_size);
> + if (ret > 0 && flush) {
> + buf_size = 0;
> + ret = combine_au(ctx, avctx, &buf, &buf_size);
> + }
> + if (ret != 0) {
> + buf_size = next;
> + goto no_out;
> + }
> + }
> + *poutbuf = buf;
> + *poutbuf_size = buf_size;
> + return next;
> +no_out:
> + *poutbuf = NULL;
> + *poutbuf_size = 0;
> + return buf_size;
> +}
More information about the ffmpeg-devel
mailing list