From: Anton Khirnov <anton@khirnov.net>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH] add media100 bsf and use it
Date: Tue, 31 Jan 2023 13:48:24 +0100
Message-ID: <167516930493.4503.17110674852156490142@lain.khirnov.net> (raw)
In-Reply-To: <CAPYw7P5-MfOkHnnxaQa5DLtx_hRSEg4ACafrbGPUjTBr0ZsS8w@mail.gmail.com>
Quoting Paul B Mahol (2023-01-31 11:18:52)
> Patch attached.
>
> From c9ec824211cccb745b3a4ab014d6be726c8ef1b9 Mon Sep 17 00:00:00 2001
> From: Paul B Mahol <onemda@gmail.com>
> Date: Tue, 31 Jan 2023 10:18:17 +0100
> Subject: [PATCH] avcodec: add media100_to_mjpegb bitstream filter and use it
>
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
> libavcodec/Makefile | 3 +-
> libavcodec/bitstream_filters.c | 1 +
> .../{media100.c => media100_to_mjpegb_bsf.c} | 112 +++++++-----------
> libavcodec/mjpegbdec.c | 15 +++
> 4 files changed, 61 insertions(+), 70 deletions(-)
> rename libavcodec/{media100.c => media100_to_mjpegb_bsf.c} (65%)
Needs media100_decoder_select="media100_to_mjpegb_bsf" in configure and
a changelog entry.
> -static av_cold int media100_decode_init(AVCodecContext *avctx)
> +static av_cold int init(AVBSFContext *ctx)
> {
> - Media100Context *ctx = avctx->priv_data;
> - const AVCodec *codec;
> - int ret;
> -
> - codec = avcodec_find_decoder(AV_CODEC_ID_MJPEGB);
> - if (!codec)
> - return AVERROR_BUG;
> - ctx->avctx = avcodec_alloc_context3(codec);
> - if (!ctx->avctx)
> - return AVERROR(ENOMEM);
> - ctx->avctx->thread_count = 1;
> - ctx->avctx->flags = avctx->flags;
> - ctx->avctx->flags2 = avctx->flags2;
> - ctx->avctx->width = ctx->avctx->coded_width = avctx->width;
> - ctx->avctx->height = ctx->avctx->coded_height = avctx->height;
> -
> - ret = avcodec_open2(ctx->avctx, codec, NULL);
> - if (ret < 0)
> - return ret;
> + Media100Context *s = ctx->priv_data;
>
> - ctx->pkt = av_packet_alloc();
> - if (!ctx->pkt)
> + s->pkt = av_packet_alloc();
> + if (!s->pkt)
> return AVERROR(ENOMEM);
Should set ctx->par_out->codec_id to AV_CODEC_ID_MJPEGB, so people can
use this bsf standalone.
>
> return 0;
> }
>
> -static int media100_decode_frame(AVCodecContext *avctx,
> - AVFrame *frame, int *got_frame,
> - AVPacket *avpkt)
> +static int filter(AVBSFContext *ctx, AVPacket *avpkt)
> {
> - Media100Context *ctx = avctx->priv_data;
> + Media100Context *s = ctx->priv_data;
> unsigned second_field_offset = 0;
> unsigned next_field = 0;
> unsigned dht_offset[2];
> @@ -83,18 +62,20 @@ static int media100_decode_frame(AVCodecContext *avctx,
> AVPacket *pkt;
> int ret;
>
> - if (avpkt->size + 1024 > ctx->pkt->size) {
> - ret = av_grow_packet(ctx->pkt, avpkt->size + 1024 - ctx->pkt->size);
> - if (ret < 0)
> - return ret;
> - }
> + ret = ff_bsf_get_packet_ref(ctx, avpkt);
> + if (ret < 0)
> + return ret;
>
> - ret = av_packet_make_writable(ctx->pkt);
> + ret = av_new_packet(s->pkt, avpkt->size + 1024);
> + if (ret < 0)
> + return ret;
> +
> + ret = av_packet_make_writable(s->pkt);
> if (ret < 0)
> return ret;
>
> bytestream2_init(&gb, avpkt->data, avpkt->size);
> - bytestream2_init_writer(&pb, ctx->pkt->data, ctx->pkt->size);
> + bytestream2_init_writer(&pb, s->pkt->data, s->pkt->size);
>
> second_field:
> bytestream2_put_be32(&pb, 0);
> @@ -107,8 +88,8 @@ second_field:
> sof_offset[field] = bytestream2_tell_p(&pb);
> bytestream2_put_be16(&pb, 17);
> bytestream2_put_byte(&pb, 8);
> - bytestream2_put_be16(&pb, avctx->height / 2);
> - bytestream2_put_be16(&pb, avctx->width);
> + bytestream2_put_be16(&pb, ctx->par_in->height / 2);
> + bytestream2_put_be16(&pb, ctx->par_in->width);
> bytestream2_put_byte(&pb, 3);
> bytestream2_put_byte(&pb, 1);
> bytestream2_put_byte(&pb, 0x21);
> @@ -164,7 +145,7 @@ second_field:
> goto second_field;
> }
>
> - pkt = ctx->pkt;
> + pkt = s->pkt;
>
> AV_WB32(pkt->data + 8, second_field_offset);
> AV_WB32(pkt->data + 12, second_field_offset);
> @@ -186,40 +167,33 @@ second_field:
>
> pkt->size = bytestream2_tell_p(&pb);
>
> - ret = avcodec_send_packet(ctx->avctx, pkt);
> - if (ret < 0) {
> - av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
> - return ret;
> - }
> + av_packet_copy_props(pkt, avpkt);
check the return value
A FATE test would be nice.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-01-31 12:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-31 10:18 Paul B Mahol
2023-01-31 11:20 ` Andreas Rheinhardt
2023-01-31 12:48 ` Anton Khirnov [this message]
2023-01-31 15:33 ` Paul B Mahol
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=167516930493.4503.17110674852156490142@lain.khirnov.net \
--to=anton@khirnov.net \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git