[FFmpeg-devel] [PATCH 1/2] avcodec/libjxldec: add animated decode support
Anton Khirnov
anton at khirnov.net
Fri Mar 17 20:59:46 EET 2023
Quoting Leo Izen (2023-03-03 21:31:45)
> -static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
> +static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame)
> {
> LibJxlDecodeContext *ctx = avctx->priv_data;
> - const uint8_t *buf = avpkt->data;
> - size_t remaining = avpkt->size;
> JxlDecoderStatus jret;
> int ret;
> - *got_frame = 0;
> + AVPacket *pkt = ctx->avpkt;
> +
> + if (!pkt->size) {
Shouldn't this live inside the loop?
It won't happen currently, but in principle ff_decode_get_packet() could
return more than one packet.
> + av_packet_unref(pkt);
> + ret = ff_decode_get_packet(avctx, pkt);
> + if (ret < 0 && ret != AVERROR_EOF)
> + return ret;
> + ctx->remaining = pkt->size;
> + if (!pkt->size) {
> + /* empty packet means eof */
> + if (ret >= 0) {
> + av_packet_unref(pkt);
> + return AVERROR(EAGAIN);
pkt->size == 0 && ret >= 0
should not happen
> + } else {
> + return AVERROR_EOF;
> + }
> + }
> + }
>
> while (1) {
>
> - jret = JxlDecoderSetInput(ctx->decoder, buf, remaining);
> + jret = JxlDecoderSetInput(ctx->decoder, pkt->data + (pkt->size - ctx->remaining), ctx->remaining);
Wouldn't it be simpler to offset pkt->data and decremented pkt->size?
Then you shouldn't need ctx->remaining at all.
> @@ -419,25 +471,23 @@ static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_f
> /* ownership is transfered, and it is not ref-ed */
> ctx->iccp = NULL;
> }
> - *got_frame = 1;
> - return avpkt->size - remaining;
> + frame->pts = av_rescale_q(ctx->pts, ctx->timebase, avctx->pkt_timebase);
I think pkt_timebase does not have to be set.
Also, you should set frame->duration.
--
Anton Khirnov
More information about the ffmpeg-devel
mailing list