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 E103149BAE for ; Mon, 4 Mar 2024 13:09:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 080F768D43B; Mon, 4 Mar 2024 15:07:28 +0200 (EET) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 70C4968D441 for ; Mon, 4 Mar 2024 15:07:14 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=Ceb9JyYn; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id D12194D46 for ; Mon, 4 Mar 2024 14:07:08 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id F3ztiH84Y-Zu for ; Mon, 4 Mar 2024 14:07:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709557626; bh=7KJQlgqGHZcD/TRASSee7vALsrd93V27XT0QQ6H9FSE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ceb9JyYnAXBJPS08ZhY4TJBA1G+qeTdaLnuEoln1YpkxiPI7FytmXPn3YQavq4nit oTfJllCWsmmxnE4BzrFLTEsGCi0zHxcrsXjDyh9329ZDkuR2w/6m8Ze9t8BCSEXTVT YRrNMZqbJt2/cZAW2XFLkfMDvvww+MSrRcNseordYApCdKExbH+i5KqIbTD6uYwHYH vy4LdLegeLXs8YyeQYMdn7LvwVyik60y0EvkLifQSiw0JUA1rm3jOFrZGM0vpRkC2X Vg0ORhwHoBng1Fb3MKpVTU/cnPiBply6hxynkWnlsqHIhPdKzxaWY5XTD0tmNRlS2z ObY4EVFuN1mtA== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (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 "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 546094D4D for ; Mon, 4 Mar 2024 14:07:06 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 07B2D3A0A6B for ; Mon, 4 Mar 2024 14:07:00 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Mar 2024 14:06:19 +0100 Message-ID: <20240304130657.30631-4-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240304130657.30631-1-anton@khirnov.net> References: <20240304130657.30631-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/29] lavu/opt: factor per-type dispatch out of av_opt_copy() 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: Will be useful in following commits. --- libavutil/opt.c | 89 ++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 051a121331..d18a1c63b7 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -1900,6 +1900,51 @@ void *av_opt_ptr(const AVClass *class, void *obj, const char *name) return (uint8_t*)obj + opt->offset; } +static int opt_copy_elem(void *logctx, enum AVOptionType type, + void *dst, const void *src) +{ + uint8_t **dst8 = (uint8_t **)dst; + const uint8_t **src8 = (const uint8_t **)src; + + if (type == AV_OPT_TYPE_STRING) { + if (*dst8 != *src8) + av_freep(dst8); + *dst8 = av_strdup(*src8); + if (*src8 && !*dst8) + return AVERROR(ENOMEM); + } else if (type == AV_OPT_TYPE_BINARY) { + int len = *(const int *)(src8 + 1); + if (*dst8 != *src8) + av_freep(dst8); + *dst8 = av_memdup(*src8, len); + if (len && !*dst8) { + *(int *)(dst8 + 1) = 0; + return AVERROR(ENOMEM); + } + *(int *)(dst8 + 1) = len; + } else if (type == AV_OPT_TYPE_CONST) { + // do nothing + } else if (type == AV_OPT_TYPE_DICT) { + AVDictionary **sdict = (AVDictionary **)src; + AVDictionary **ddict = (AVDictionary **)dst; + if (*sdict != *ddict) + av_dict_free(ddict); + *ddict = NULL; + return av_dict_copy(ddict, *sdict, 0); + } else if (type == AV_OPT_TYPE_CHLAYOUT) { + if (dst != src) + return av_channel_layout_copy(dst, src); + } else if (opt_is_pod(type)) { + size_t size = opt_elem_size[type]; + memcpy(dst, src, size); + } else { + av_log(logctx, AV_LOG_ERROR, "Unhandled option type: %d\n", type); + return AVERROR(EINVAL); + } + + return 0; +} + int av_opt_copy(void *dst, const void *src) { const AVOption *o = NULL; @@ -1916,48 +1961,10 @@ int av_opt_copy(void *dst, const void *src) while ((o = av_opt_next(src, o))) { void *field_dst = (uint8_t *)dst + o->offset; void *field_src = (uint8_t *)src + o->offset; - uint8_t **field_dst8 = (uint8_t **)field_dst; - uint8_t **field_src8 = (uint8_t **)field_src; - if (o->type == AV_OPT_TYPE_STRING) { - if (*field_dst8 != *field_src8) - av_freep(field_dst8); - *field_dst8 = av_strdup(*field_src8); - if (*field_src8 && !*field_dst8) - ret = AVERROR(ENOMEM); - } else if (o->type == AV_OPT_TYPE_BINARY) { - int len = *(int *)(field_src8 + 1); - if (*field_dst8 != *field_src8) - av_freep(field_dst8); - *field_dst8 = av_memdup(*field_src8, len); - if (len && !*field_dst8) { - ret = AVERROR(ENOMEM); - len = 0; - } - *(int *)(field_dst8 + 1) = len; - } else if (o->type == AV_OPT_TYPE_CONST) { - // do nothing - } else if (o->type == AV_OPT_TYPE_DICT) { - AVDictionary **sdict = (AVDictionary **) field_src; - AVDictionary **ddict = (AVDictionary **) field_dst; - int ret2; - if (*sdict != *ddict) - av_dict_free(ddict); - *ddict = NULL; - ret2 = av_dict_copy(ddict, *sdict, 0); - if (ret2 < 0) - ret = ret2; - } else if (o->type == AV_OPT_TYPE_CHLAYOUT) { - if (field_dst != field_src) - ret = av_channel_layout_copy(field_dst, field_src); - } else if (opt_is_pod(o->type)) { - size_t size = opt_elem_size[o->type]; - memcpy(field_dst, field_src, size); - } else { - av_log(dst, AV_LOG_ERROR, "Unhandled option type: %d\n", - o->type); - ret = AVERROR(EINVAL); - } + int err = opt_copy_elem(dst, o->type, field_dst, field_src); + if (err < 0) + ret = err; } return ret; } -- 2.43.0 _______________________________________________ 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".