From patchwork Fri Apr 28 09:55:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 41398 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1188596pzb; Fri, 28 Apr 2023 02:56:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/OvpV2gmouSOl0sg8RRYUwvQQYCldydaQuxCXQyg8v1iZHn3vL8CMdqtF2gU0s47JVvuc X-Received: by 2002:aa7:de92:0:b0:504:8929:71ca with SMTP id j18-20020aa7de92000000b00504892971camr3831353edv.6.1682675784912; Fri, 28 Apr 2023 02:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682675784; cv=none; d=google.com; s=arc-20160816; b=VZnHJkr1r07g+U8Sn48rOX4xW9gBzskTVi6gZ2dbqixpfsz3O26EKMlv9jQDx4gZN9 W0TAlQIjSk/FFOC0qToFOCTIy5GWDwz82o1hGN3a5Bwj830YFS2uNMbbBFGJli9TYWEL M2Km4d0mf2acYutut3bbAyk5RKr7d7r2i382vI1SFSTVCJb8/tStVVUwP0YVrzPvtkZM kwDnufSkjsIW4N1l11G3m1IrNd5Zfeb/tUkDTwbfZSYVRoUFPoOg0nfSU2TsGyPMil6P V8w5V4gCmH4jpfQCbUjeiLZjeE7+z+NGinTitSiBQmx8yUoMUkh93VdgmJS+TLMEKuRn hhXA== 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:delivered-to; bh=X/wn6IFA2KxDeiEn8Hu7fT2TE4+IJtMaC+/hyDRHEwA=; b=FiF+nxePdf31ziMVu3WXi7cJWbqEpO7f23tYLHlh/n9VMT01f4UrhACAcDn+9cB9kP H5WgYBiU79fPebRVOcogo3MViaM6Xz0j2AFSoi8dBQbv803eFyk1lr/9W3tFB2mWN5Hl 7uPv2w8tu9QkJiiFea6b1O6P4rwjrQHuq/TF9QjZXDlnVqszeNvtxNnA0PYgdZAjZscm hSggFBS5p35BjKViVG6WV4tzVgfGuo6jAnHt5y0CIBYI5ZXBAN8t0qy1YrshihhN0I7R eqyvILZAY20Ws+iaa6lhbWkke204RLjx2ZHVh32EaRcmS7fQzdVlVbj/nGGfRjfz02ZD l94w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r23-20020a056402035700b00506addaaabasi15561835edw.64.2023.04.28.02.56.24; Fri, 28 Apr 2023 02:56:24 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E100A68BFE8; Fri, 28 Apr 2023 12:55:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A50FF68BFA9 for ; Fri, 28 Apr 2023 12:55:16 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 33S9tFMR014813 for ; Fri, 28 Apr 2023 11:55:16 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id EEF11EB5BF; Fri, 28 Apr 2023 11:55:15 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Fri, 28 Apr 2023 11:55:07 +0200 Message-Id: <20230428095508.221826-7-george@nsup.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230428095508.221826-1-george@nsup.org> References: <20230428095508.221826-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Fri, 28 Apr 2023 11:55:16 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 7/8] lavf/options: add av_disposition_write() 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: 3ewcjGvqP57F TODO APIchanges entry Signed-off-by: Nicolas George --- libavformat/avformat.h | 14 ++++++++++++++ libavformat/options.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) This and the next patch show the kind of fruits become low-hanging thanks to the platform of AVWriter. Eventually, I want that every public structure and enumeration to have a _write() function with a standardized API, and later we will be able to use a custom %something format string in printf directly. Another project of mine (that has AVWriter as a prerequisite) would invert the logic of this function: instead of having the to-string and from-string function explore the options table, we would have the options system quety the to-string and from-string functions. diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 5302a34c0d..51fd78b71c 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -824,6 +824,20 @@ int av_disposition_from_string(const char *disp); */ const char *av_disposition_to_string(int disposition); +/** + * Write a disposition as a string. + * The before and after string are written around each element of the + * disposition and the between string is written between them, if they are + * not NULL. + * Unknown disposition bits are written as an extra hexadecimal value. + * No flags are defined. + */ +void av_disposition_write(AVWriter wr, unsigned disposition, + const char *before, + const char *after, + const char *between, + unsigned flags); + /** * Options for behavior on timestamp wrap detection. */ diff --git a/libavformat/options.c b/libavformat/options.c index e4a3aceed0..a813e11060 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -29,6 +29,7 @@ #include "libavutil/internal.h" #include "libavutil/intmath.h" #include "libavutil/opt.h" +#include "libavutil/writer.h" /** * @file @@ -348,3 +349,36 @@ const char *av_disposition_to_string(int disposition) return NULL; } + +void av_disposition_write(AVWriter wr, unsigned disposition, + const char *before, + const char *after, + const char *between, + unsigned flags) +{ + int sep = 0; + + for (const AVOption *opt = stream_options; opt->name; opt++) { + if (option_is_disposition(opt) && (disposition & opt->default_val.i64)) { + if (sep && between) + av_writer_print(wr, between); + if (before) + av_writer_print(wr, before); + av_writer_print(wr, opt->name); + if (after) + av_writer_print(wr, after); + disposition &= ~opt->default_val.i64; + sep = 1; + } + } + if (disposition) { + if (sep && between) + av_writer_print(wr, between); + if (before) + av_writer_print(wr, before); + av_writer_printf(wr, "%x?", disposition); + if (after) + av_writer_print(wr, after); + sep = 1; + } +}