From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 809C8454E1 for ; Tue, 31 Jan 2023 12:48:35 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 170FB68BDC8; Tue, 31 Jan 2023 14:48:33 +0200 (EET) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AFB868BCDC for ; Tue, 31 Jan 2023 14:48:26 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D6E892404EC for ; Tue, 31 Jan 2023 13:48:25 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id dhdsd_6SkoSf for ; Tue, 31 Jan 2023 13:48:25 +0100 (CET) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 2613C240178 for ; Tue, 31 Jan 2023 13:48:25 +0100 (CET) Received: by lain.khirnov.net (Postfix, from userid 1000) id EDEA91601B2; Tue, 31 Jan 2023 13:48:24 +0100 (CET) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: References: Mail-Followup-To: FFmpeg development discussions and patches Date: Tue, 31 Jan 2023 13:48:24 +0100 Message-ID: <167516930493.4503.17110674852156490142@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] add media100 bsf and use it X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 > 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 > --- > 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".