From patchwork Fri Apr 12 23:16:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 48034 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp572914pzb; Fri, 12 Apr 2024 16:17:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUFCi1IZf/Olobx47TNzRVQPWgRPFpY8VJhts7z5AvPmD3S/zJ/dHFq0igTJMG4pG7qnD/AdLUmOe7HSbiJhzr/CePT1eUM23eWNw== X-Google-Smtp-Source: AGHT+IEMz1fE1Vjek0+sczabw4A6Ut4yFbjS9Lim48Ff747awAr2zAFFQX/4PpcH9O8ytWx89qMl X-Received: by 2002:a2e:818a:0:b0:2d9:fbbc:e6fe with SMTP id e10-20020a2e818a000000b002d9fbbce6femr2335129ljg.28.1712963851071; Fri, 12 Apr 2024 16:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712963851; cv=none; d=google.com; s=arc-20160816; b=PXk5vt2JXGlUzQG6n+AHwcYMuWxIJt9ASPvHGXvd8wLiPqQofZ3TbamF8oT6+d/duT H46XBQxNXEhlVQBd7gMaqUzYurCqXoVDfo9u2x7uApD5M2GoTpMBinVdVs+uguccR27s u3fDW22muPt+ndJ3BjMiAxEqa5dUPAEHdzbW9avNyakbVLLBwJLPtqItDRBccrnCvOE8 oYixr1oisC+NKNN2LN+/OOPOKoifW8JlzcVp6DdZFHvNL+2lD7T57YujeEOzuNChrqer bkqxkyzx0Z13V202gIWJ5a/5sKQdx9vlSfP4PRqnwxG4CRouUZmcLnG1ns2deLqWuxK0 xdHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=q2aMuOYIBMLpwbhQ0XKN0/zhURiSqRzti5rIfvrg+VA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=qgjb9tH+ywEVDTsZzJxfhRevIacBj/a7J9FPWpVIFnDxU3bOUAErmmWUOivXsemhCV Nbd4OyZ5M0wB531I+Yzx/Ug9yLsk8BAnhiXkQxFnURmck3HFcspZ5MYu6r2hzdfNxaLZ /CCo0YHTbDJQol6hV0R8+nTZMRkMDBu5HSbQzTDav1FXjLs7dQa4gN4o2NhVzyw2LcNI yS6T+Mie39FT1evg9p53TsP9wNnn6+bExBbTjerfkY3oc7CsicytXblv4CkJdb3fq9j8 DJ79S7VXnthNPpO/eCpAO3K1wSIpzlIMK5zMl0sE6jTTmQvuFC+GC9aa/MXpLcGVhJZ7 pn4w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=grHeiPkb; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x25-20020a05651c105900b002d6f3680b6dsi1228398ljm.79.2024.04.12.16.17.30; Fri, 12 Apr 2024 16:17:31 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=grHeiPkb; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D022B68D2EA; Sat, 13 Apr 2024 02:17:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DAFA068D0BD for ; Sat, 13 Apr 2024 02:17:15 +0300 (EEST) Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5c6bd3100fcso902774a12.3 for ; Fri, 12 Apr 2024 16:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712963833; x=1713568633; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=TwBkgYYO3ynJ+ggnnBynPTXbbrkL5cVrV4UCMUpTouw=; b=grHeiPkbRkCiVuRHUBIMu5MV7iruiEeigIvrEEx3rsKV9bBG/3Wnz6WztdWGAZnL1g QIHmG7Gzlng+an4rivztl/x74G6li94QyRdVDguZv2FLkgaYOk6059UYqYK+cg2YaO7O TZmNn/avg/iG1IHRhYxT5eNQw5hB4krI3Krgw82qjeBZavtqH2+2X6y+fTwSdnZETJiI Rhd088/HTjqVhhOm5rpkxQ7iSeWhmbUJ5ROWB7WUC12UYDTEkKH5BtRrrmbsvERJdM6k eDUjMpSS34xQQxoFzbIkxt4BSLY1HRNwdjlAQX8z5NDIhdkaLCcztMXZfhfAegb8jbVz 6aJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712963833; x=1713568633; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TwBkgYYO3ynJ+ggnnBynPTXbbrkL5cVrV4UCMUpTouw=; b=ftMt0MW8DURq6gsx/Q9C7xwzPblfFE+I+mzqS+fRhy1RPCIJs5AulXnom/4cCAJuDA Z5P0dtN40t5mAusyKxLbDMS5LKYnaZ75IKy/n7vVfSmuMY8hsPIvblONqf0dtHqh3Tws ft6ZjucHhGWBdACC9M65f7crHniMaxLDC0NCh5SX6IM7x94HbwZMhItFFhcWHJGDHM2s e9pVxrC2n9/gOTKhNxJweTtC1e2t8YtFT+qMEH8Lcm9f5lNAc9yNIg88SIIYXj8iWvbf PVgd1N73+lumrDMliK7rjX4f0Pla26ee9HbKg+dzU6YbrfHvF8KHVUPcpR1rfthVpLOv vdAQ== X-Gm-Message-State: AOJu0YzBxqV7t1X7jthxg7PCxOjLlndSEad4HnWz1cnQb+OrioTllwnB gpxO/pJGV9QGI85Y4nfIy/71HGtAiJUsxWQ3f4Z1hZuRekim2UwMebwhBw== X-Received: by 2002:a17:90b:710:b0:2a5:badb:30ea with SMTP id s16-20020a17090b071000b002a5badb30eamr4249757pjz.36.1712963833195; Fri, 12 Apr 2024 16:17:13 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id x23-20020a17090a165700b0029b59bf77b4sm5438284pje.42.2024.04.12.16.17.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 16:17:12 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Apr 2024 20:16:57 -0300 Message-ID: <20240412231658.4625-1-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avutil/test/opt: test the AV_OPT_SERIALIZE_SKIP_DEFAULTS flag 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nfBWeJV/S+o3 Signed-off-by: James Almer --- The floats are set to "1.0 / 3" and the serialization prints a value that's not exact, hence them not being skipped. array_int is weird, though. Although it's the only array that doesn't set AVOption.arr libavutil/tests/opt.c | 5 +++++ tests/ref/fate/opt | 1 + 2 files changed, 6 insertions(+) diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c index ccf3a54f96..32301ba842 100644 --- a/libavutil/tests/opt.c +++ b/libavutil/tests/opt.c @@ -279,6 +279,11 @@ int main(void) if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) { printf("%s\n", buf); av_free(buf); + if (av_opt_serialize(&test_ctx, 0, AV_OPT_SERIALIZE_SKIP_DEFAULTS, &buf, '=', ',') >= 0) { + if (strlen(buf)) + printf("%s\n", buf); + av_free(buf); + } } } av_opt_free(&test_ctx); diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt index f4fce1bd49..43bf0929a3 100644 --- a/tests/ref/fate/opt +++ b/tests/ref/fate/opt @@ -179,6 +179,7 @@ Setting entry with key 'array_int' to value '' Setting entry with key 'array_str' to value 'str0|str\|1|str\\2' Setting entry with key 'array_dict' to value 'k00=v\\\\00:k01=v\,01,k10=v\\=1\\:0' num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_int=,array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0 +flt=0.333333,dbl=0.333333,array_int= Testing av_set_options_string() Setting options string '' From patchwork Fri Apr 12 23:16:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 48035 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp572944pzb; Fri, 12 Apr 2024 16:17:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX2wAFncMs0ABsGxQa/jPMxo/AxhnOqBuHTv8Zwgh6AswL2cUYFg1aQlYISHL5DU5BK2PX77kuiVdiYmXnrlakWTUuLUssbvXQpCA== X-Google-Smtp-Source: AGHT+IHpsfwvfb7O+10cdO33XgNGoHwtu/Ysh1wyIokADdu18eCsORaIaZu6YycJ0JeVTNE+/IgW X-Received: by 2002:ac2:410a:0:b0:515:bacd:adbf with SMTP id b10-20020ac2410a000000b00515bacdadbfmr2415338lfi.34.1712963855479; Fri, 12 Apr 2024 16:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712963855; cv=none; d=google.com; s=arc-20160816; b=Ho72m64GiipjesXWZwFuidntKae0VB0I5Ujqobzwpf+QkQS9oO21fgLhzDjvCxq1xF hdLAdZyzdSIwnWzwDIo1Z6xUzqtTjXajvpmPxd7c7v4hXXAgwG1vMJ5SNkcqZufa4d8J lFP1euh6/j+LQVWMy8F5e1eEzfDfCYSpurYETQlP7//poCax1br8fVHEr6hLpToB5fsi Uaq567dAFXwYFnDddwJ+eQ6rw5unfqHcJRLHuVRO/YBEMHogIGjijH8Gb0Yn4iSUbbwx /tSHeqEj/uZrr0qr3sjglYbuIiva8S0Jk3u706lMg5mTXmuxSHWrhE9YuIwZvlecGOFJ +o8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=kXzWWoN70o18WZ7I0Y+mguC9NdOCQE2783T0Fj6AoQ0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=GWxdkhVCKRD/Y1YC1sTItbIxEDjx4vh2DBjgfyPI6CTCQGGoyiK4iG/aSlZJTHrNHL 7ZC9Hvl7nUH9ClvIGI6zLMW0xz3Cys6CWOgr4/0J3BHYZVnzPKHJfz+AcsvG8mGKtBJr b/tuVd6jtOLzLxV498kN1FGV4CUwpd9x3K8oOgz9LX/nv5kK+81NQnGc3YPw/djeMG9j 1EQtK7aab+FMDlSyVh3SD/BUbgUn2z07dDILzlCIv5xThFsgGf3mvFuzJ63++JC1lLtR r9WR5VlR+N4Vb6mVqWVkPOdkgxKiSJEi+YXkO+3DOWwlhGp/i9/aEWIebhTQkgd2P+t6 NyqA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=TWC+A4Z3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n13-20020a05640205cd00b0056e754a3a4dsi2138964edx.617.2024.04.12.16.17.35; Fri, 12 Apr 2024 16:17:35 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=TWC+A4Z3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C883668D2E8; Sat, 13 Apr 2024 02:17:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 43DD468CFE3 for ; Sat, 13 Apr 2024 02:17:17 +0300 (EEST) Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2a502547460so999964a91.2 for ; Fri, 12 Apr 2024 16:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712963835; x=1713568635; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=LhoFMpDJThqsJKaGaH6h4zH2PmgCKB6XwtjwZbrvBWg=; b=TWC+A4Z33wFqHilrltlOibwXkp5afSNDbfWWWvNjIvGTE3rlDofiq53rWaKlHN6C0M W99qRGGvlx9hIn70HsYxOIm/Pl18grmzBlvzaPofEZPXBlx+z7t06c36oVkAvc7VbVRS 3AkCj8LXttd/ftZnrdFvTtW61odWaVm42pqWfSpW6l2/sio7pCsGeUz7UY/+2OmYbxO+ lNYWGqMhXLTLuYbIskfGdD8PEswG1n4fpnTJEvvBDqnNoNYHPbRI7/g+ImLknb/kfN0c rDjsb6RuYbb0yp8S2U9+mgdb/dsA/27pa3V1h6DuAuPn/owVUQgCaR4lzsqC3d/8skMH xQtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712963835; x=1713568635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LhoFMpDJThqsJKaGaH6h4zH2PmgCKB6XwtjwZbrvBWg=; b=oGU6OymHhl2Ci6GWGxpBBeVmFHb4TdF9NMAhM5dFtSnFvHlWB2RxL9CSMniXeT/Map 8ES3sFK4qMC94vaJoSQk6qURyKWZ54HfhSfb+xmSV40RMkvXuTosqk/ICBYkxNEOL0xo vpPcE2BEJg1wd5f7gcYmBp4qF5i0BTjSFfPoI2/sCxdx1qLjIpMjIj3zWg+BSGFmzzb3 BZyFBW+pR47nQbGO2aOeH5DFVyUhXn9Q34mh1s8Uu3hCnV9gdgMouPvnMVM7y6rEitlY un4UL1ZlZb/GqHW73aVugX3g+0Z5pEf8cMcbHlusytNFHP8rU47G2pCliR8tqK1aEMrV F1fA== X-Gm-Message-State: AOJu0YzX4RpPQY+sHjqKKuG8sm1zZzIFzbBzDAjpraC7xQJBBHDgHIbe hcDBuTUp89AAfRol/F+T+eFy/q83m3KbNUfIe+xIg1wnz8zGYgcDlZFOyA== X-Received: by 2002:a17:90b:4b48:b0:2a2:227a:50fc with SMTP id mi8-20020a17090b4b4800b002a2227a50fcmr3534936pjb.41.1712963834557; Fri, 12 Apr 2024 16:17:14 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id x23-20020a17090a165700b0029b59bf77b4sm5438284pje.42.2024.04.12.16.17.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 16:17:14 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Apr 2024 20:16:58 -0300 Message-ID: <20240412231658.4625-2-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412231658.4625-1-jamrial@gmail.com> References: <20240412231658.4625-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avutil/opt: add support for children objects in av_opt_serialize 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: giVgktMw/7d0 Signed-off-by: James Almer --- libavutil/opt.c | 65 +++++++++++++++++++++++++++++-------------- libavutil/opt.h | 1 + libavutil/tests/opt.c | 47 +++++++++++++++++++++++++++++-- tests/ref/fate/opt | 2 +- 4 files changed, 90 insertions(+), 25 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index d11e9d2ac5..ecbf7efe5f 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -2386,26 +2386,22 @@ int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_fla return av_opt_is_set_to_default(target, o); } -int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, - const char key_val_sep, const char pairs_sep) +static int opt_serialize(void *obj, int opt_flags, int flags, int *cnt, + AVBPrint *bprint, const char key_val_sep, const char pairs_sep) { const AVOption *o = NULL; + void *child = NULL; uint8_t *buf; - AVBPrint bprint; - int ret, cnt = 0; + int ret; const char special_chars[] = {pairs_sep, key_val_sep, '\0'}; - if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep || - pairs_sep == '\\' || key_val_sep == '\\') { - av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found."); - return AVERROR(EINVAL); - } - - if (!obj || !buffer) - return AVERROR(EINVAL); - - *buffer = NULL; - av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED); + if (flags & AV_OPT_SERIALIZE_SEARCH_CHILDREN) + while (child = av_opt_child_next(obj, child)) { + ret = opt_serialize(child, opt_flags, flags, cnt, bprint, + key_val_sep, pairs_sep); + if (ret < 0) + return ret; + } while (o = av_opt_next(obj, o)) { if (o->type == AV_OPT_TYPE_CONST) @@ -2417,18 +2413,45 @@ int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, if (flags & AV_OPT_SERIALIZE_SKIP_DEFAULTS && av_opt_is_set_to_default(obj, o) > 0) continue; if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) { - av_bprint_finalize(&bprint, NULL); + av_bprint_finalize(bprint, NULL); return ret; } if (buf) { - if (cnt++) - av_bprint_append_data(&bprint, &pairs_sep, 1); - av_bprint_escape(&bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); - av_bprint_append_data(&bprint, &key_val_sep, 1); - av_bprint_escape(&bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); + if ((*cnt)++) + av_bprint_append_data(bprint, &pairs_sep, 1); + av_bprint_escape(bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); + av_bprint_append_data(bprint, &key_val_sep, 1); + av_bprint_escape(bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); av_freep(&buf); } } + + return 0; +} + +int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, + const char key_val_sep, const char pairs_sep) +{ + AVBPrint bprint; + int ret, cnt = 0; + + if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep || + pairs_sep == '\\' || key_val_sep == '\\') { + av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found."); + return AVERROR(EINVAL); + } + + if (!obj || !buffer) + return AVERROR(EINVAL); + + *buffer = NULL; + av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED); + + ret = opt_serialize(obj, opt_flags, flags, &cnt, &bprint, + key_val_sep, pairs_sep); + if (ret < 0) + return ret; + ret = av_bprint_finalize(&bprint, buffer); if (ret < 0) return ret; diff --git a/libavutil/opt.h b/libavutil/opt.h index e6013662f6..855e363091 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -929,6 +929,7 @@ int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name) #define AV_OPT_SERIALIZE_SKIP_DEFAULTS 0x00000001 ///< Serialize options that are not set to default values only. #define AV_OPT_SERIALIZE_OPT_FLAGS_EXACT 0x00000002 ///< Serialize options that exactly match opt_flags only. +#define AV_OPT_SERIALIZE_SEARCH_CHILDREN 0x00000004 ///< Serialize options in possible children of the given object. /** * Serialize object's options. diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c index 32301ba842..53d8951bcf 100644 --- a/libavutil/tests/opt.c +++ b/libavutil/tests/opt.c @@ -30,6 +30,7 @@ typedef struct TestContext { const AVClass *class; + struct ChildContext *child; int num; int toggle; char *string; @@ -123,10 +124,46 @@ static const char *test_get_name(void *ctx) return "test"; } +typedef struct ChildContext { + const AVClass *class; + int64_t child_num64; + int child_num; +} ChildContext; + +#undef OFFSET +#define OFFSET(x) offsetof(ChildContext, x) + +static const AVOption child_options[]= { + {"child_num64", "set num 64bit", OFFSET(child_num64), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 100, 1 }, + {"child_num", "set child_num", OFFSET(child_num), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 100, 1 }, + { NULL }, +}; + +static const char *child_get_name(void *ctx) +{ + return "child"; +} + +static const AVClass child_class = { + .class_name = "ChildContext", + .item_name = child_get_name, + .option = child_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +static void *test_child_next(void *obj, void *prev) +{ + TestContext *test_ctx = obj; + if (!prev) + return test_ctx->child; + return NULL; +} + static const AVClass test_class = { .class_name = "TestContext", .item_name = test_get_name, .option = test_options, + .child_next = test_child_next, .version = LIBAVUTIL_VERSION_INT, }; @@ -277,11 +314,15 @@ int main(void) av_set_options_string(&test_ctx, buf, "=", ","); av_free(buf); if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) { + ChildContext child_ctx = { 0 }; printf("%s\n", buf); av_free(buf); - if (av_opt_serialize(&test_ctx, 0, AV_OPT_SERIALIZE_SKIP_DEFAULTS, &buf, '=', ',') >= 0) { - if (strlen(buf)) - printf("%s\n", buf); + test_ctx.child = &child_ctx; + child_ctx.class = &child_class; + if (av_opt_serialize(&test_ctx, 0, + AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN, + &buf, '=', ',') >= 0) { + printf("%s\n", buf); av_free(buf); } } diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt index 43bf0929a3..05d57066a1 100644 --- a/tests/ref/fate/opt +++ b/tests/ref/fate/opt @@ -179,7 +179,7 @@ Setting entry with key 'array_int' to value '' Setting entry with key 'array_str' to value 'str0|str\|1|str\\2' Setting entry with key 'array_dict' to value 'k00=v\\\\00:k01=v\,01,k10=v\\=1\\:0' num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_int=,array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0 -flt=0.333333,dbl=0.333333,array_int= +child_num=0,flt=0.333333,dbl=0.333333,array_int= Testing av_set_options_string() Setting options string '' From patchwork Sat Apr 13 14:21:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 48043 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp867292pzb; Sat, 13 Apr 2024 07:21:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVlMq3F8HZqNPYt3cAlHd6na3pVlPlRNjImyMx3q16+h/55Z9oUBHjO4W6FLcA1fWCcfD57Kpw5HZSIz5nMtVw1dD9f5/m9AYsjqw== X-Google-Smtp-Source: AGHT+IFLaXottHnfIZzoMiml7OrsRyPChYGoWpclH/QwsWsp/AcI/slmQYp4ldl8XbqovMCJsLW7 X-Received: by 2002:a17:906:29c4:b0:a52:362e:b4f7 with SMTP id y4-20020a17090629c400b00a52362eb4f7mr2858384eje.3.1713018107619; Sat, 13 Apr 2024 07:21:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713018107; cv=none; d=google.com; s=arc-20160816; b=Nh80y6dQcqCu/Xzl6ukTAodWeiZ86FSCXtahXDk/Ss9orcT2cHx2P/cUQBa7ZL0lWs 6R0SfJ7hxLlnhqK0OOQ3Fqb1wLNHkQ4t7cXEexKq9VwCNYNa1jptjXXV2jfirIxYYg9C Pxo7EmZBIBIKPWQzJzvf5hZUE/VJKlwFNikjS3lxifSvzK1mosxmyp3dIPWMKSx9Rdis i1Tex7C09AzfSLYayhptpxIH8VgWE2uLZgymnyr5Uqj7atruw7vY9XEYUx9jNKKUOVy6 Plo9cWw7oHjnV4cGvYiR4ZdadFHaSozTB7Q+91bznGp8V9Q+sOZDId1nfhKtReUo9qVO 6wrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=nzwk6RCIOk6s3Irxa3HWEHDg9gk8mTs58h0YH3pLy5Q=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=b6B87Ls8+s+ORj7bCHzyXlsY2jESJfh3K1lqkm5XZ7pqM4+X30mJ6jwjwQAWTrYbhc bNz0uIXfuTJA7ehXemXxU4U4ZvvrUh3LxUDcMQ6LPXK5fLL+yy1aEi0bPYkXErdFyp8Q w/AJL1DSCg4rtMksCg7jRhD+t9S5hguBropGJVsA0lS7ZXN/26C5tM7gNL6YCNCndsrJ RykwNQIOTUI5MUtzPbhBUOJ9gO2blDeHz5AlQTLMtpUzpCRerP/hIjAFXsibf6ysWVn5 XH9VZbEF40V3Mk6QTCE9jZnHEnXz57ILBqPWfzfRHM7XE51nNVZ7ME9HBPPTXcdr7otv i7NQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="Pq0Y/Glm"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o16-20020a17090608d000b00a51bc3deb37si2633857eje.1031.2024.04.13.07.21.47; Sat, 13 Apr 2024 07:21:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="Pq0Y/Glm"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1B20468D338; Sat, 13 Apr 2024 17:21:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E518668D332 for ; Sat, 13 Apr 2024 17:21:37 +0300 (EEST) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1e424bd30fbso14303125ad.0 for ; Sat, 13 Apr 2024 07:21:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713018095; x=1713622895; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eB5pHeKV7Ri2ifMri7IFfaT3kt79nDEjt60CfK2+1XU=; b=Pq0Y/Glmlh67VqwWJmQkdI3v1dVOtoWS6UsTm+303cWSBH8bIofSiV/U6hx91A4DEB HNQZg4t0JoqWIWilcq5rWblJ/HLDopBQ2XinwgCPQRmztovgPZx5jE1LstAn4VQFlM2c O23setzHBUlb4jo2OFu9UENmyHc3/Vs6JHWVp2LNZ3q1LkA0hosyrCGai3dymmMO38xX ji14dRdvo8TKqsZFWNokMtVxlplAnPIrnWvMFNGUM/UZD5ZG2fgSynA/HCzuJ4jdbNN3 2scMx3VCLHgG8h4E0N6IoZOwF7qYaSLbTowrUZPz2KzVdON6fTbnzUX4HBlxFN+D/TJQ dFEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713018095; x=1713622895; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eB5pHeKV7Ri2ifMri7IFfaT3kt79nDEjt60CfK2+1XU=; b=DbsHwalzd1HrYve+18NVbEeQ1C8Zvd+H2jP3MrtbnwHES2PwPq9LphVn8t7FOVd9Id Z2u+LNrMsg59o30RtWp7NgvAAcjcj/9aZ/FSRG/k3eFGd84bYlI5KTCfskuji7kQolTU 8O1dJMeDUIFO56qalG7pIeCQuDXINDamKIlCkK+CAWnhwL3KghOSS7jaZjRNN4ig1jsU pbXtQwyksjRwyYbMpLk3+ywI3quTnj32/CD25ilMhIXgqRhC8rlccsVUtLinQptM1frg 4VSl7Aa0ONkgAg/OQASO9VDUXFjQNKkATgvl0uQ2OFKUpfQbRfmUzuvEgmhrLt3nAZws ouBg== X-Gm-Message-State: AOJu0YwmWniliqLPhYiJpwPyPmsvJ4fRTKjttMFd1JIhpiz8oZ344aLJ +W9ZMq6jgpZiPufPAu0pmFIJUvEhRID0WbwS3xsHVUKnck1PhrmSw5bXCA== X-Received: by 2002:a17:902:d4ce:b0:1e5:5cab:92ee with SMTP id o14-20020a170902d4ce00b001e55cab92eemr6489909plg.33.1713018095119; Sat, 13 Apr 2024 07:21:35 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d7-20020a170902654700b001e20afa1038sm4777715pln.8.2024.04.13.07.21.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Apr 2024 07:21:34 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Apr 2024 11:21:28 -0300 Message-ID: <20240413142128.2889-1-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412231658.4625-1-jamrial@gmail.com> References: <20240412231658.4625-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avutil/tests/opt: test av_opt_find2() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KLdvy0x/mF6I Signed-off-by: James Almer --- libavutil/tests/opt.c | 29 +++++++++++++++++++++++++++++ tests/ref/fate/opt | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c index bac0e80bd5..dc968567eb 100644 --- a/libavutil/tests/opt.c +++ b/libavutil/tests/opt.c @@ -452,5 +452,34 @@ int main(void) av_opt_free(&test_ctx); } + printf("\nTesting av_opt_find2()\n"); + { + TestContext test_ctx = { 0 }; + ChildContext child_ctx = { 0 }; + void *target; + const AVOption *opt; + + test_ctx.class = &test_class; + test_ctx.child = &child_ctx; + child_ctx.class = &child_class; + av_opt_set_defaults(&test_ctx); + av_opt_set_defaults(&child_ctx); + + av_log_set_level(AV_LOG_QUIET); + + opt = av_opt_find2(&test_ctx, "num", NULL, 0, 0, &target); + if (opt && target == &test_ctx) + printf("OK '%s'\n", opt->name); + else + printf("Error '%s'\n", "num"); + + opt = av_opt_find2(&test_ctx, "child_num", NULL, 0, AV_OPT_SEARCH_CHILDREN, &target); + if (opt && target == &child_ctx) + printf("OK '%s'\n", opt->name); + else + printf("Error '%s'\n", "child_num"); + av_opt_free(&test_ctx); + } + return 0; } diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt index 05d57066a1..39659b2248 100644 --- a/tests/ref/fate/opt +++ b/tests/ref/fate/opt @@ -449,3 +449,7 @@ Setting options string 'a_very_long_option_name_that_will_need_to_be_ellipsized_ Setting 'a_very_long_option_name_that_will_need_to_be_ellipsized_around_here' to value '42' Option 'a_very_long_option_name_that_will_need_to_be_ellipsized_around_here' not found Error 'a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42' + +Testing av_opt_find2() +OK 'num' +OK 'child_num' From patchwork Mon Apr 15 15:09:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 48069 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp1902911pzb; Mon, 15 Apr 2024 08:09:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX8xMh2ouIbarUBCrvWfZm649v1dyzrJZnow/OO6B8BvdUuzTA1cXKtxv8U6PrTE7uE53cDlcGAq5ESAXixQml2iFWZO6jt3BpsVw== X-Google-Smtp-Source: AGHT+IHxu3nGRFmUXKqi7bkoR+UtkBjVVuvRpXgxUpSYCxuQb3/9G8PCr6Lha852/Il8scjMryBj X-Received: by 2002:ac2:5a0f:0:b0:518:d259:8542 with SMTP id q15-20020ac25a0f000000b00518d2598542mr2699300lfn.2.1713193764031; Mon, 15 Apr 2024 08:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713193764; cv=none; d=google.com; s=arc-20160816; b=pXrx3s2SE55aEaL5q/U5IKjRzZWHe6RYu/27Fd+6qRayOKNXiaQ/BIq0LJaP/Ip5lU QJ4kqGq7UucFJhcxP6yFshnR+BUAwoFYzZNBYHklcEU9AwOQINSvozw0C+9H0mfcPPf5 5lFw2cn2mbLf2Jz60MzO+fpiCM4flHyckJheyO7s9mU4faALPMM83U90c1ZXVvhZCXcS O4NlvHh8SOGy+zO+pA1QCY8ovN9Kyy/mUoBBGPAqI18uHBQM30frrVx+Zr7JJpSjfnql Mqy5mBAN9ryiKWaoucpjhVRzZWoP9f67lldfyREDC+FxWfiewgNp5uv4iNPgQbl49QsT 5uSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=wjj79gnJSkhRevM3i5lR8fyczflZvCdkrlRdJRREilk=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=BnLubJ8xuUB+t6EQMUmX4rP0gkQmswSADijgjDrCzuFmgjBBewUPt6GQg4KDo8r8iu T5XPMPrSXsostA4JlEqYxFjx9aRM7pCkq810J5+9hNpkye0w2r3rU27gU9IWx1dLitlT gvEfssJAlF/nFgx4tzuVt0J+d7BEWobonJcfF6QdnKGW+zA0NZ7i4jR1WmbpAEmEsIkj AssesVPrpoSgKYGd/Ve2ot8pk6FhZ1We2atuqazsyYdMb5B6YnQ2FGtKdKmAsxxaAwUD 9ff7WXkbLD8hcUT58XpPFSziML0zB5ZXWvN7xenIqfgGafjv+e5ATjnVQzOzBHZB9EA2 E75g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=m5bc5WX1; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m21-20020a509995000000b0056e249c1609si4725791edb.235.2024.04.15.08.09.23; Mon, 15 Apr 2024 08:09:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=m5bc5WX1; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 20BF968C942; Mon, 15 Apr 2024 18:09:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 27EC768C545 for ; Mon, 15 Apr 2024 18:09:14 +0300 (EEST) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1e51398cc4eso32067805ad.2 for ; Mon, 15 Apr 2024 08:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713193751; x=1713798551; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=SjdTWgWa/sKIiwri0xW70yvPnpeI2CcaPYaUKGKt+yc=; b=m5bc5WX1F76JHhemK2tHkTrKsQco7xSQR7lCupxjtF6XmNUHRSjPVgQ6rYIg/hXQwC Ofcmf4VGwPrzXcP2pzTmntnFttwZw7t+NvuaGUjxRGIkqwmt5uBUq9lJCVuaffU32y6a QrDMRHKcfM7d87Jh1FqNRQEACBHm648Up+iePeKC5l8tJ1MkDJ3st2/gRVRGizHOjZr2 tC/SO5gbct3cjg+d90EwoxVgn1OT7N/hDd5Q0LryEuMsq7ZvYzbCeLyN/o0ovgj3Y5nw qflGOtH6m2qhIlkkDI4cSLnOYpFSpQazK7wa+fhDYCRnEQBYbbScGthx/pKOqd6UGB0o QT6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713193751; x=1713798551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SjdTWgWa/sKIiwri0xW70yvPnpeI2CcaPYaUKGKt+yc=; b=eCJ9qfHPrslq1/v91NGxWFfnClzbgDNMnxH0Ua4JKx2QMCmpIOl1850PROL5FKW6TW /cphbANFF1AZuEnKe6xo2Ht1T+Zr3heaeJOYM6zhiO5i1nKuQ+oUbmrtHbk9+cIItnWf dPbUWAMCjQEqSHbpPbnpqRy/nPS2ex3SSmEoCY4wP6fWfycGNINGzKjJFIs/zWub3SXr UHa3QBh55L70nI0r6FujryuPWi7wJcMnqprnFbxGMbm/lRZMlpxURu75v7cErmdJLmO1 7MaIfF/9SWRXaMNyKBQTVFkrcLmTkEgQnhD5IIUEOCqmYHXkCOepIE7lVMngLL4oLsYi rOcQ== X-Gm-Message-State: AOJu0YwZeVgtfagaqQ/PGa241d2qrA0bqymk2bhBC4d1GS2DPJJF0o6i BFGfBtqaAIp2/jngf2dl3AUdsrATMtOi9Zcp1EIx5EwswIuJRh7I2R1PPw== X-Received: by 2002:a17:902:ce88:b0:1dc:7bc:d025 with SMTP id f8-20020a170902ce8800b001dc07bcd025mr14610864plg.4.1713193751127; Mon, 15 Apr 2024 08:09:11 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id i5-20020a17090332c500b001e546a10c50sm8020123plr.286.2024.04.15.08.09.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 08:09:10 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Apr 2024 12:09:00 -0300 Message-ID: <20240415150900.1800-1-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412231658.4625-1-jamrial@gmail.com> References: <20240412231658.4625-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] fftools/ffmpeg_mux_init: allow mapping a stream group from one of the inputs 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +tnUreotEs3X Do this by extending the -stream_group option to accept a map key where the value selects the input file and stream group. The can and should set the streams in the output that the copied group will reference, same as they'd do if they created a group from scratch. Example command line: ffmpeg -i input.iamf -map 0 -c:a copy -f null -stream_group \ map=0=0:st=0:st=1:st=2:st=3 -stream_group map=0=1:st=0:st=1:st=2:st=3 Signed-off-by: James Almer --- fftools/ffmpeg_mux_init.c | 154 +++++++++++++++++++++++++++++++++++++- 1 file changed, 152 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6d8bd5bcdf..a46b0628d8 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -2232,11 +2232,137 @@ fail: return ret; } +static int of_serialize_options(Muxer *mux, void *obj, AVBPrint *bp) +{ + char *ptr; + int ret; + + ret = av_opt_serialize(obj, 0, AV_OPT_SERIALIZE_SKIP_DEFAULTS | AV_OPT_SERIALIZE_SEARCH_CHILDREN, + &ptr, '=', ':'); + if (ret < 0) { + av_log(mux, AV_LOG_ERROR, "Failed to serialize group\n"); + return ret; + } + + av_bprintf(bp, "%s", ptr); + ret = strlen(ptr); + av_free(ptr); + + return ret; +} + +#define SERIALIZE(parent, child) do { \ + ret = of_serialize_options(mux, parent->child, bp); \ + if (ret < 0) \ + return ret; \ +} while (0) + +#define SERIALIZE_LOOP(parent, child, suffix, separator) do { \ + for (int j = 0; j < parent->nb_## child ## suffix; j++) { \ + av_bprintf(bp, separator#child "="); \ + SERIALIZE(parent, child ## suffix[j]); \ + } \ +} while (0) + +static int64_t get_stream_group_index_from_id(Muxer *mux, int64_t id) +{ + AVFormatContext *oc = mux->fc; + + for (unsigned i = 0; i < oc->nb_stream_groups; i++) + if (oc->stream_groups[i]->id == id) + return oc->stream_groups[i]->index; + + return AVERROR(EINVAL); +} + +static int of_map_group(Muxer *mux, AVDictionary **dict, AVBPrint *bp, const char *map) +{ + AVStreamGroup *stg; + int ret, file_idx, stream_idx; + char *ptr; + + file_idx = strtol(map, &ptr, 0); + if (file_idx >= nb_input_files || file_idx < 0 || map == ptr) { + av_log(mux, AV_LOG_ERROR, "Invalid input file index: %d.\n", file_idx); + return AVERROR(EINVAL); + } + + stream_idx = strtol(*ptr == '=' ? ptr + 1 : ptr, &ptr, 0); + if (*ptr || stream_idx >= input_files[file_idx]->ctx->nb_stream_groups || stream_idx < 0) { + av_log(mux, AV_LOG_ERROR, "Invalid input stream group index: %d.\n", stream_idx); + return AVERROR(EINVAL); + } + + stg = input_files[file_idx]->ctx->stream_groups[stream_idx]; + ret = of_serialize_options(mux, stg, bp); + if (ret < 0) + return ret; + + ret = av_dict_parse_string(dict, bp->str, "=", ":", 0); + if (ret < 0) + av_log(mux, AV_LOG_ERROR, "Error parsing mapped group specification %s\n", ptr); + av_dict_set_int(dict, "type", stg->type, 0); + + av_log(mux, AV_LOG_VERBOSE, "stg %s\n", bp->str); + av_bprint_clear(bp); + switch(stg->type) { + case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: { + AVIAMFAudioElement *audio_element = stg->params.iamf_audio_element; + + if (audio_element->demixing_info) { + av_bprintf(bp, ",demixing="); + SERIALIZE(audio_element, demixing_info); + } + if (audio_element->recon_gain_info) { + av_bprintf(bp, ",recon_gain="); + SERIALIZE(audio_element, recon_gain_info); + } + SERIALIZE_LOOP(audio_element, layer, s, ","); + break; + } + case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: { + AVIAMFMixPresentation *mix = stg->params.iamf_mix_presentation; + + for (int i = 0; i < mix->nb_submixes; i++) { + AVIAMFSubmix *submix = mix->submixes[i]; + + av_bprintf(bp, ",submix="); + SERIALIZE(mix, submixes[i]); + for (int j = 0; j < submix->nb_elements; j++) { + AVIAMFSubmixElement *element = submix->elements[j]; + int64_t id = get_stream_group_index_from_id(mux, element->audio_element_id); + + if (id < 0) { + av_log(mux, AV_LOG_ERROR, "Invalid or missing stream group index in" + "submix element"); + return id; + } + + av_bprintf(bp, "|element="); + SERIALIZE(submix, elements[j]); + if (ret) + av_bprintf(bp, ":"); + av_bprintf(bp, "stg=%"PRId64, id); + } + SERIALIZE_LOOP(submix, layout, s, "|"); + } + break; + } + default: + av_log(mux, AV_LOG_ERROR, "Unsupported mapped group type %d.\n", stg->type); + ret = AVERROR(EINVAL); + break; + } + av_log(mux, AV_LOG_VERBOSE, "extra %s\n", bp->str); + return 0; +} + static int of_parse_group_token(Muxer *mux, const char *token, char *ptr) { AVFormatContext *oc = mux->fc; AVStreamGroup *stg; AVDictionary *dict = NULL, *tmp = NULL; + char *mapped_string = NULL; const AVDictionaryEntry *e; const AVOption opts[] = { { "type", "Set group type", offsetof(AVStreamGroup, type), AV_OPT_TYPE_INT, @@ -2262,8 +2388,31 @@ static int of_parse_group_token(Muxer *mux, const char *token, char *ptr) return ret; } + av_dict_copy(&tmp, dict, 0); + e = av_dict_get(dict, "map", NULL, 0); + if (e) { + AVBPrint bp; + + if (ptr) { + av_log(mux, AV_LOG_ERROR, "Unexpected extra parameters when mapping a" + " stream group\n"); + ret = AVERROR(EINVAL); + goto end; + } + + av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC); + ret = of_map_group(mux, &tmp, &bp, e->value); + if (ret < 0) { + av_bprint_finalize(&bp, NULL); + goto end; + } + + av_bprint_finalize(&bp, &mapped_string); + ptr = mapped_string; + } + // "type" is not a user settable AVOption in AVStreamGroup, so handle it here - e = av_dict_get(dict, "type", NULL, 0); + e = av_dict_get(tmp, "type", NULL, 0); if (!e) { av_log(mux, AV_LOG_ERROR, "No type specified for Stream Group in \"%s\"\n", token); ret = AVERROR(EINVAL); @@ -2278,7 +2427,6 @@ static int of_parse_group_token(Muxer *mux, const char *token, char *ptr) goto end; } - av_dict_copy(&tmp, dict, 0); stg = avformat_stream_group_create(oc, type, &tmp); if (!stg) { ret = AVERROR(ENOMEM); @@ -2331,6 +2479,7 @@ static int of_parse_group_token(Muxer *mux, const char *token, char *ptr) // make sure that nothing but "st" and "stg" entries are left in the dict e = NULL; + av_dict_set(&tmp, "map", NULL, 0); av_dict_set(&tmp, "type", NULL, 0); while (e = av_dict_iterate(tmp, e)) { if (!strcmp(e->key, "st") || !strcmp(e->key, "stg")) @@ -2343,6 +2492,7 @@ static int of_parse_group_token(Muxer *mux, const char *token, char *ptr) ret = 0; end: + av_free(mapped_string); av_dict_free(&dict); av_dict_free(&tmp);