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 ESMTPS id AD43A4DAA6 for ; Fri, 28 Feb 2025 05:03:23 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3482D68DD8D; Fri, 28 Feb 2025 07:02:48 +0200 (EET) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 39D5868DD68 for ; Fri, 28 Feb 2025 07:02:41 +0200 (EET) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-22113560c57so33244245ad.2; Thu, 27 Feb 2025 21:02:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740718959; x=1741323759; darn=ffmpeg.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=cKHDcBBMX1yFygcdvcskEcfc+2Z4aXPIUNfKGmY4v14=; b=QjtwqkPnw4/IRcJVeEMZpuUUrihqt7rCXGI+T5LpssJWZmqxWnnqmAnhv+CZfCCCqO ztXTo93XLmMIxNaQ67Mt+6Dyy/C5Um4SDIqKlZRCW++grV5qj8uT5mzZ2wkoMzePO0sR fZcIu4d71vNVA0NhNC9ECSZq1tLwD9NKLnLFFObpnszJDQd0dU1Ef1bLr+JMHYmD16u7 VsIesCm5BdR/ZD3qeM9KzRSr3wzGimJMzjo87/+Yq5lIawY897nPIEtjOADKrNzpwMJR F2tnVKzWziLKEotkXAyzaxQRO5QhCLFP3Fmkn/y3KjSSDHPsS6diCb/2+ZII3xIt20JX Cn3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740718959; x=1741323759; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=cKHDcBBMX1yFygcdvcskEcfc+2Z4aXPIUNfKGmY4v14=; b=pY+Mer7TPp7shI3jag/CCzjksw96yXyxew2rn5ZWARoKILYzS1i1dQ9WAalnbUxSx4 pKej8I1XmOv4L9KkexaQqXI4QwB5NSfuqMJlZfrvihyaZeLHU1EW83bu4ZEqP2wal3IE 0+T3IeOhac7gvUVy0o4zj689/9yl4s/uL7Euf7IdwYv64fB6ZOUUR7PykHWPCZ8YA6BS nxL9amoXsic7TUTFm9TEHyrvJHMCboT4xIM0OqYXpM4/eygX5nVRyO82GBhrcEHHxYci P7FuBR5lz8Nb4wlxbCzgCJOQ19CA09hqb4VY/I+5xMeOyAUSlrvdYw7zANc5SyzXox6P zZtA== X-Forwarded-Encrypted: i=1; AJvYcCVt6PUMxk9B+OPOA4iSqwZMwSqwWHY8m/ZN30oZvGzVs0KH5Fbz/SyWM5oivB5XNZWoJaqyT/IMle1aVMVCyrARLxKYRK1I7UY=@ffmpeg.org X-Gm-Message-State: AOJu0Yy2Kr7CROr1E5AcoS/cN6cmQ3B+XC4ald1nrY9WX0v45sY2nKTn SZ67QGS7ZOJr2WU8KdrZnhMh+Emr73XUdFqnFvmvrh/aADPNYP9Jus7UHg== X-Gm-Gg: ASbGncvvH0FkYRBDpOgm6oUbPvriX3VT3gTDAMVFLGW1yAbjam1bT7xHgLXWTwLkhb1 BHCnYW5nsArplb8TyltTGSu3tj7W9PCZWrt98THdlOdVMEMySWdZ7BSstiEwIlT6JFCoLcf5L0L kEbBaC16n/y7+DmlTSCxokQ684K6f3rnGlu1IVSRtxyVR2fELgARofnQH+PioGf44k93bfN/MLe l/vCY4n3iRpkE/ruzuG2JJnEzolo2GrXYf48a6s7bnq7KRPFxHXMiDD2Em8dGojiYc/HoIJxedt 5YvJAeNyLAGeC+RHl2z9/G7Npu/WikINTTUp+J6+ftiX X-Google-Smtp-Source: AGHT+IE6Zkrxa3QiHaLx4NbS1Dt39TKC/knIhsUwNi1dv17ss9zZeQSktAyljRJdwa6kGU16BhV6QA== X-Received: by 2002:a17:902:f548:b0:21f:baa:80be with SMTP id d9443c01a7336-22369259666mr30008035ad.46.1740718959462; Thu, 27 Feb 2025 21:02:39 -0800 (PST) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7349fe2a65asm2750292b3a.28.2025.02.27.21.02.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Feb 2025 21:02:39 -0800 (PST) From: softworkz X-Google-Original-From: softworkz Message-Id: <01413dfbc0c60ee17c79370086abb88d78552929.1740718936.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Fri, 28 Feb 2025 05:02:11 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 3/8] ffprobe/avtextformat: Generalize ffprobe specifics 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 Cc: Michael Niedermayer , Soft Works , softworkz 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: From: softworkz Signed-off-by: softworkz --- fftools/ffprobe.c | 34 +++++++++++++++-------------- libavutil/avtextformat.h | 13 +++++------ libavutil/textformat/avtextformat.c | 30 ++++++++++--------------- 3 files changed, 35 insertions(+), 42 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 837e21c0e2..5560f6b87e 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -272,7 +272,7 @@ static struct AVTextFormatSection sections[] = { [SECTION_ID_LIBRARY_VERSIONS] = { SECTION_ID_LIBRARY_VERSIONS, "library_versions", SECTION_FLAG_IS_ARRAY, { SECTION_ID_LIBRARY_VERSION, -1 } }, [SECTION_ID_LIBRARY_VERSION] = { SECTION_ID_LIBRARY_VERSION, "library_version", 0, { -1 } }, [SECTION_ID_PACKETS] = { SECTION_ID_PACKETS, "packets", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET, -1} }, - [SECTION_ID_PACKETS_AND_FRAMES] = { SECTION_ID_PACKETS_AND_FRAMES, "packets_and_frames", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET, -1} }, + [SECTION_ID_PACKETS_AND_FRAMES] = { SECTION_ID_PACKETS_AND_FRAMES, "packets_and_frames", SECTION_FLAG_IS_ARRAY | SECTION_FLAG_NUMBERING_BY_TYPE, { SECTION_ID_PACKET, -1} }, [SECTION_ID_PACKET] = { SECTION_ID_PACKET, "packet", 0, { SECTION_ID_PACKET_TAGS, SECTION_ID_PACKET_SIDE_DATA_LIST, -1 } }, [SECTION_ID_PACKET_TAGS] = { SECTION_ID_PACKET_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "packet_tags" }, [SECTION_ID_PACKET_SIDE_DATA_LIST] ={ SECTION_ID_PACKET_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "packet_side_data_list" }, @@ -547,7 +547,7 @@ static const AVTextFormatter default_formatter = { .print_section_footer = default_print_section_footer, .print_integer = default_print_int, .print_string = default_print_str, - .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS, + .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS, .priv_class = &default_class, }; @@ -747,7 +747,7 @@ static const AVTextFormatter compact_formatter = { .print_section_footer = compact_print_section_footer, .print_integer = compact_print_int, .print_string = compact_print_str, - .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS, + .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS, .priv_class = &compact_class, }; @@ -778,7 +778,7 @@ static const AVTextFormatter csv_formatter = { .print_section_footer = compact_print_section_footer, .print_integer = compact_print_int, .print_string = compact_print_str, - .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS, + .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS, .priv_class = &csv_class, }; @@ -870,8 +870,9 @@ static void flat_print_section_header(AVTextFormatContext *wctx, const void *dat av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str); if (parent_section->flags & SECTION_FLAG_IS_ARRAY) { - int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ? - wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1]; + int n = parent_section->flags & SECTION_FLAG_NUMBERING_BY_TYPE ? + wctx->nb_item_type[wctx->level-1][section->id] : + wctx->nb_item[wctx->level-1]; av_bprintf(buf, "%d%s", n, flat->sep_str); } } @@ -902,7 +903,7 @@ static const AVTextFormatter flat_formatter = { .print_section_header = flat_print_section_header, .print_integer = flat_print_int, .print_string = flat_print_str, - .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS|WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER, + .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS|AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, .priv_class = &flat_class, }; @@ -974,8 +975,9 @@ static void ini_print_section_header(AVTextFormatContext *wctx, const void *data av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name); if (parent_section->flags & SECTION_FLAG_IS_ARRAY) { - int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ? - wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1]; + int n = parent_section->flags & SECTION_FLAG_NUMBERING_BY_TYPE ? + wctx->nb_item_type[wctx->level-1][section->id] : + wctx->nb_item[wctx->level-1]; av_bprintf(buf, ".%d", n); } } @@ -1006,7 +1008,7 @@ static const AVTextFormatter ini_formatter = { .print_section_header = ini_print_section_header, .print_integer = ini_print_int, .print_string = ini_print_str, - .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS|WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER, + .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS|AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, .priv_class = &ini_class, }; @@ -1090,7 +1092,7 @@ static void json_print_section_header(AVTextFormatContext *wctx, const void *dat writer_printf(wctx, "{%s", json->item_start_end); /* this is required so the parser can distinguish between packets and frames */ - if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) { + if (parent_section && parent_section->flags & SECTION_FLAG_NUMBERING_BY_TYPE) { if (!json->compact) JSON_INDENT(); writer_printf(wctx, "\"type\": \"%s\"", section->name); @@ -1141,7 +1143,7 @@ static void json_print_str(AVTextFormatContext *wctx, const char *key, const cha const struct AVTextFormatSection *parent_section = wctx->level ? wctx->section[wctx->level-1] : NULL; - if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES)) + if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & SECTION_FLAG_NUMBERING_BY_TYPE)) writer_put_str(wctx, json->item_sep); if (!json->compact) JSON_INDENT(); @@ -1155,7 +1157,7 @@ static void json_print_int(AVTextFormatContext *wctx, const char *key, int64_t v wctx->section[wctx->level-1] : NULL; AVBPrint buf; - if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES)) + if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & SECTION_FLAG_NUMBERING_BY_TYPE)) writer_put_str(wctx, json->item_sep); if (!json->compact) JSON_INDENT(); @@ -1173,7 +1175,7 @@ static const AVTextFormatter json_formatter = { .print_section_footer = json_print_section_footer, .print_integer = json_print_int, .print_string = json_print_str, - .flags = WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER, + .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, .priv_class = &json_class, }; @@ -1345,7 +1347,7 @@ static AVTextFormatter xml_formatter = { .print_section_footer = xml_print_section_footer, .print_integer = xml_print_int, .print_string = xml_print_str, - .flags = WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER, + .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, .priv_class = &xml_class, }; @@ -3421,7 +3423,7 @@ static int probe_file(AVTextFormatContext *wctx, const char *filename, if (do_read_frames || do_read_packets) { if (do_show_frames && do_show_packets && - wctx->writer->flags & WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER) + wctx->writer->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT) section_id = SECTION_ID_PACKETS_AND_FRAMES; else if (do_show_packets && !do_show_frames) section_id = SECTION_ID_PACKETS; diff --git a/libavutil/avtextformat.h b/libavutil/avtextformat.h index e1aa227aff..a7f8055783 100644 --- a/libavutil/avtextformat.h +++ b/libavutil/avtextformat.h @@ -42,6 +42,7 @@ struct AVTextFormatSection { #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4 ///< the section may contain a variable number of fields with variable keys. /// For these sections the element_name field is mandatory. #define SECTION_FLAG_HAS_TYPE 8 ///< the section contains a type to distinguish multiple nested elements +#define SECTION_FLAG_NUMBERING_BY_TYPE 16 ///< the items in this array section should be numbered individually by type int flags; const int children_ids[SECTION_MAX_NB_CHILDREN+1]; ///< list of children section IDS, terminated by -1 @@ -54,8 +55,8 @@ struct AVTextFormatSection { typedef struct AVTextFormatContext AVTextFormatContext; -#define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1 -#define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2 +#define AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS 1 +#define AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT 2 typedef enum { WRITER_STRING_VALIDATION_FAIL, @@ -80,7 +81,8 @@ typedef struct AVTextFormatter { int flags; ///< a combination or WRITER_FLAG_* } AVTextFormatter; -#define SECTION_MAX_NB_LEVELS 12 +#define SECTION_MAX_NB_LEVELS 12 +#define SECTION_MAX_NB_SECTIONS 100 struct AVTextFormatContext { const AVClass *class; ///< class of the writer @@ -101,16 +103,13 @@ struct AVTextFormatContext { /** number of the item printed in the given section, starting from 0 */ unsigned int nb_item[SECTION_MAX_NB_LEVELS]; + unsigned int nb_item_type[SECTION_MAX_NB_LEVELS][SECTION_MAX_NB_SECTIONS]; /** section per each level */ const struct AVTextFormatSection *section[SECTION_MAX_NB_LEVELS]; AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section, /// used by various writers - unsigned int nb_section_packet; ///< number of the packet section in case we are in "packets_and_frames" section - unsigned int nb_section_frame; ///< number of the frame section in case we are in "packets_and_frames" section - unsigned int nb_section_packet_frame; ///< nb_section_packet or nb_section_frame according if is_packets_and_frames - int show_optional_fields; int show_value_unit; int use_value_prefix; diff --git a/libavutil/textformat/avtextformat.c b/libavutil/textformat/avtextformat.c index c4777ccca1..9516c114b9 100644 --- a/libavutil/textformat/avtextformat.c +++ b/libavutil/textformat/avtextformat.c @@ -190,6 +190,11 @@ int avtext_context_open(AVTextFormatContext **pwctx, const AVTextFormatter *writ wctx->use_byte_value_binary_prefix = use_byte_value_binary_prefix; wctx->use_value_sexagesimal_format = use_value_sexagesimal_format; wctx->show_optional_fields = show_optional_fields; + + if (nb_sections > SECTION_MAX_NB_SECTIONS) { + av_log(wctx, AV_LOG_ERROR, "The number of section definitions (%d) is larger than the maximum allowed (%d)\n", nb_sections, SECTION_MAX_NB_SECTIONS); + goto fail; + } wctx->class = &textcontext_class; wctx->writer = writer; @@ -294,8 +299,6 @@ fail: } /* Temporary definitions during refactoring */ -#define SECTION_ID_PACKETS_AND_FRAMES 24 -#define SECTION_ID_PACKET 21 static const char unit_second_str[] = "s" ; static const char unit_hertz_str[] = "Hz" ; static const char unit_byte_str[] = "byte" ; @@ -306,23 +309,13 @@ void avtext_print_section_header(AVTextFormatContext *wctx, const void *data, int section_id) { - int parent_section_id; wctx->level++; av_assert0(wctx->level < SECTION_MAX_NB_LEVELS); - parent_section_id = wctx->level ? - (wctx->section[wctx->level-1])->id : SECTION_ID_NONE; wctx->nb_item[wctx->level] = 0; + memset(wctx->nb_item_type[wctx->level], 0, sizeof(wctx->nb_item_type[wctx->level])); wctx->section[wctx->level] = &wctx->sections[section_id]; - if (section_id == SECTION_ID_PACKETS_AND_FRAMES) { - wctx->nb_section_packet = wctx->nb_section_frame = - wctx->nb_section_packet_frame = 0; - } else if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) { - wctx->nb_section_packet_frame = section_id == SECTION_ID_PACKET ? - wctx->nb_section_packet : wctx->nb_section_frame; - } - if (wctx->writer->print_section_header) wctx->writer->print_section_header(wctx, data); } @@ -333,12 +326,11 @@ void avtext_print_section_footer(AVTextFormatContext *wctx) int parent_section_id = wctx->level ? wctx->section[wctx->level-1]->id : SECTION_ID_NONE; - if (parent_section_id != SECTION_ID_NONE) - wctx->nb_item[wctx->level-1]++; - if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) { - if (section_id == SECTION_ID_PACKET) wctx->nb_section_packet++; - else wctx->nb_section_frame++; + if (parent_section_id != SECTION_ID_NONE) { + wctx->nb_item[wctx->level - 1]++; + wctx->nb_item_type[wctx->level - 1][section_id]++; } + if (wctx->writer->print_section_footer) wctx->writer->print_section_footer(wctx); wctx->level--; @@ -487,7 +479,7 @@ int avtext_print_string(AVTextFormatContext *wctx, const char *key, const char * if (wctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER || (wctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && (flags & PRINT_STRING_OPT) - && !(wctx->writer->flags & WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS))) + && !(wctx->writer->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS))) return 0; if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) { -- ffmpeg-codebot _______________________________________________ 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".