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 CED1340CB8 for ; Sat, 9 Apr 2022 15:38:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D9DAC68B2F2; Sat, 9 Apr 2022 18:37:57 +0300 (EEST) Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 662A568B0E4 for ; Sat, 9 Apr 2022 18:37:52 +0300 (EEST) Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-e2442907a1so12369339fac.8 for ; Sat, 09 Apr 2022 08:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:content-language:to :references:from:subject:in-reply-to:content-transfer-encoding; bh=F9SFP380kJ8AuWJGi2HrpkdfSwrl72k62TgYIJiGdo0=; b=oj7w2aicryy/oMI1gW9lY39KkU1OGui3sU3oCR6UUB8f4mAlY8ptMlWVd1ghiVqwv9 Pof39cTHpP/zk925XUR2il1MeBKZ8z+Vw0wQrjkm51gCi2VBhMgc+VKEKLAyDCuF2Xmp teHhoijTP68s/BYxYA08fJG9Fsj4iN+jkxmTvdk4wlTYo+i0/YQFuM+SUb4C8o4Gd0ff vYfBtfgs9OzKj+4f/5imyAktDX3TzID0YhSEGDh/yrdQ0VROc/nIUgCAzNVxDbukA5fO KfGc5y9BWtS1sFcKMkGHa+qAoIHpLtj58Dkd+LJeFtCAelTYFvJMiUiJt+CE/jAqdHN4 wAcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:references:from:subject:in-reply-to :content-transfer-encoding; bh=F9SFP380kJ8AuWJGi2HrpkdfSwrl72k62TgYIJiGdo0=; b=E5v/iLUCY3FIyyENFP20CuEBpMuDqVrfMPbMlxoR3uzrkgUzmWzkl/izYtqeAPOZFI VlN1DxNX3HHdSoYW4553qDXiv33gCMif2V+uq3PnXpkqUpAsDzPKZZGqjdng9GdMUArH 0ODkPWMO/39+UgHEzJ0WsXIvMgPSnEPo6mZp3IaLD2I54mKc2StyqPIRkceNFQeMWiBt GQxtd8i7Icvwv0GxaQrsssP2n/UaFld0dsKsYjOYvKyCkCl3UjkUfLeO0ZA47i2iz5vu O5UcOTqxKrNpgd5ZCPFZeHxyQwMSLEWQ9Bn5vga9r0aJciEN5bKzTL0UmHu7PQwL80LS LYOw== X-Gm-Message-State: AOAM533eWMaJbrP3BSSL1lg4QrJKhxgYw19IFTiTAUb8ydg9esaosepe oe47APP1r4Fo2Gy2nxXLvbRIBE3HHEo= X-Google-Smtp-Source: ABdhPJzPpuqghkxG7h7emGjQfFHCZWsNhq25Pv6WHb3Gsp6yJbCYFZ3IR92Xm2qnvju0aPTnRhkPtA== X-Received: by 2002:a05:6870:438d:b0:e2:b4a3:a103 with SMTP id r13-20020a056870438d00b000e2b4a3a103mr544701oah.217.1649518670279; Sat, 09 Apr 2022 08:37:50 -0700 (PDT) Received: from [192.168.0.12] ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id r17-20020a0568080ab100b002f9fef240f7sm235950oij.50.2022.04.09.08.37.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 Apr 2022 08:37:49 -0700 (PDT) Message-ID: <1df72419-967b-df7b-e819-e4cb9b9bf08e@gmail.com> Date: Sat, 9 Apr 2022 12:37:47 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20220405165504.29261-1-leo.izen@gmail.com> <20220405165504.29261-4-leo.izen@gmail.com> <164951025246.21047.6570158843618793411@lain.red.khirnov.net> From: James Almer In-Reply-To: <164951025246.21047.6570158843618793411@lain.red.khirnov.net> Subject: Re: [FFmpeg-devel] [PATCH v13 3/4] avcodec/libjxl: add Jpeg XL encoding via libjxl 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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".