From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH v13 3/4] avcodec/libjxl: add Jpeg XL encoding via libjxl Date: Sat, 9 Apr 2022 12:37:47 -0300 Message-ID: <1df72419-967b-df7b-e819-e4cb9b9bf08e@gmail.com> (raw) In-Reply-To: <164951025246.21047.6570158843618793411@lain.red.khirnov.net> On 4/9/2022 10:17 AM, Anton Khirnov wrote: > Quoting Leo Izen (2022-04-05 18:55:03) >> +static int libjxl_init_jxl_encoder(AVCodecContext *avctx) >> +{ >> + LibJxlEncodeContext *ctx = avctx->priv_data; >> + >> + /* reset the encoder every frame for image2 muxer */ >> + JxlEncoderReset(ctx->encoder); >> + >> + ctx->options = JxlEncoderFrameSettingsCreate(ctx->encoder, NULL); >> + if (!ctx->options) { >> + av_log(avctx, AV_LOG_ERROR, "Failed to create JxlEncoderOptions\n"); >> + return AVERROR_EXTERNAL; >> + } >> + >> + /* This needs to be set each time the decoder is reset */ >> + if (JxlEncoderSetParallelRunner(ctx->encoder, JxlThreadParallelRunner, ctx->runner) >> + != JXL_ENC_SUCCESS) { >> + av_log(avctx, AV_LOG_ERROR, "Failed to set JxlThreadParallelRunner\n"); >> + return AVERROR_EXTERNAL; >> + } >> + >> + /* these shouldn't fail, libjxl bug notwithstanding */ >> + if (JxlEncoderFrameSettingsSetOption(ctx->options, JXL_ENC_FRAME_SETTING_EFFORT, ctx->effort) >> + != JXL_ENC_SUCCESS) { >> + av_log(avctx, AV_LOG_ERROR, "Failed to set effort to: %d\n", ctx->effort); >> + return AVERROR_EXTERNAL; >> + } >> + >> + /* check for negative zero, our default */ >> + if (1.0f / ctx->distance == 1.0f / -0.0f) { > > IIRC division by zero is UB. Why not make the default -1.0 and then just > check whether the number is negative? > >> + /* >> + * This buffer will be copied when the generic >> + * code makes this packet refcounted, >> + * so we can use the buffer again. >> + */ >> + pkt->data = ctx->buffer; >> + pkt->size = bytes_written; > > This is very evil. Encoders should return refcounted packets and not > rely on the generic code fixing stuff up for them. Agree. Call avcodec_default_get_encode_buffer() then memcpy the data to the returned buffer. Don't use ff_alloc_packet() as that function does basically the same thing you're doing here with a growable non refcounted buffer. > > Also, pointers from av_malloc() cannot be passed to av_realloc(). You > need to allocate it with av_realloc() in the first place. Is this documented? afaik realloc() can be used with malloc'd pointers. It will, i assume, also realloc it the first time you call it even if you request the exact same amount of memory malloc already allocated. But in any case it's hardly a problem if he can just use av_realloc the first time. _______________________________________________ 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:[~2022-04-09 15:38 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-05 16:55 [FFmpeg-devel] [PATCH v13 0/4] Jpeg XL Patch Set Leo Izen 2022-04-05 16:55 ` [FFmpeg-devel] [PATCH v13 1/4] avcodec/jpegxl: add Jpeg XL image codec Leo Izen 2022-04-05 16:55 ` [FFmpeg-devel] [PATCH v13 2/4] avcodec/libjxl: add Jpeg XL decoding via libjxl Leo Izen 2022-04-05 16:55 ` [FFmpeg-devel] [PATCH v13 3/4] avcodec/libjxl: add Jpeg XL encoding " Leo Izen 2022-04-09 13:17 ` Anton Khirnov 2022-04-09 15:37 ` James Almer [this message] 2022-04-09 15:44 ` Hendrik Leppkes 2022-04-11 12:54 ` Anton Khirnov 2022-04-11 11:16 ` Leo Izen 2022-04-11 12:52 ` Anton Khirnov 2022-04-05 16:55 ` [FFmpeg-devel] [PATCH v13 4/4] avformat/image2: add Jpeg XL as image2 format Leo Izen
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=1df72419-967b-df7b-e819-e4cb9b9bf08e@gmail.com \ --to=jamrial@gmail.com \ --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