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 37BE445958 for ; Fri, 28 Apr 2023 09:56:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B31C168BFE7; Fri, 28 Apr 2023 12:55:25 +0300 (EEST) 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 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: 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; + } +} -- 2.39.2 _______________________________________________ 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".