From patchwork Sat Oct 14 17:24:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Sabatini X-Patchwork-Id: 44261 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4b15:b0:15d:8365:d4b8 with SMTP id fp21csp1692326pzb; Sat, 14 Oct 2023 10:24:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIbHI3Shn6+Ow+4inE0hO19hLgqKDItj9gOiCmQ7Ng0tPbscBsuRjjA/7HFXnRZrrX5Oy2 X-Received: by 2002:a50:9feb:0:b0:53e:7881:6bdf with SMTP id c98-20020a509feb000000b0053e78816bdfmr1496809edf.14.1697304281597; Sat, 14 Oct 2023 10:24:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697304281; cv=none; d=google.com; s=arc-20160816; b=FvFwiz0EaXIMF9jvPfiijc9EOG0Ti5uC+f7HcDGSfNdaQR8Mg54SnK8Cfkste3gkSE Mo8LdDwj7AAic1h1+ecXzwQts0FQF5X0d5Lbhls6rI03Lui5vaZUjzKmyPOpcdAYqwPx WrtShj7v/XEEclOZDtkFvlcTEtB9qoyMBxOuToxp97HXXZ8IBYrzELoAUZh+pbtGFTVJ C6jswZ3bwnkmjzanSFxUWAmBvCsvNblHzwMYLPKLfTmAXRprvRF1E/Zw8boergu25Pay Fotan4LeJqCeqSOjOzRcHUtD/hn71iVvmbtYdZ+KRh97bxgGthDl9e9SAm8OPBzC9vgU PbfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=3P296qQw3mdMxiUb19qP6lKnvvtkGrGvO9Ep9PqZZFk=; fh=QdWxt2OToL83TTnLQn0lGhLakV7i1QyAJdC8te7qN0E=; b=ULvIW6Ktr8e7C5xBDlCDOY3bkbKwcuOGLrC2ym6sqrjOftGUIWuPfIMQgTSlt0dK1o TS/nt4aGPA4qVYm4nAc9l/M1IPYpFJ0cBZXavRjAPjbEbFVhVOnZH451p6n8sFtI7BBd FK598wHs9zsW0OtVkODHVRrzuZncF8s5nfzEX+ptOi8NZXGJMnoHBRPE1eSqgu5DsA17 ZQm5T/Mr0LORkj6xEgaIRn74dkYktI0XNPOaswBEi8n6hb9lj2WzyY0TsjWh8Z/H8+eU ROFmjdKWOkWJdV46QWQVUcmcQiIWXkA0RS5qXoejP32zlyHSObb3NqlzPxS66Mn8udCJ kB9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=SAbymYNN; 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 r16-20020a50d690000000b0053e2bf61f4fsi2290434edi.403.2023.10.14.10.24.41; Sat, 14 Oct 2023 10:24:41 -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=SAbymYNN; 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 0239B68C6DE; Sat, 14 Oct 2023 20:24:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D5A4568C09A for ; Sat, 14 Oct 2023 20:24:31 +0300 (EEST) Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40684f53d11so36352725e9.1 for ; Sat, 14 Oct 2023 10:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697304271; x=1697909071; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=M9jpxCB8KfkhQAJ+TJIVY7cG2jX9xdJivTpzauSULO8=; b=SAbymYNNHCmmk+mC6WUeUPQGJd/so3R2QAyeyKPg+l7aZuoL0UMbIH7k1oQxLc2Rmx JehY/xY63193/zY/TOMCjilyU61jG4M/X9FZP91WPDGuAMIvsdniYje/a33Smu7ohhPR wGn8HfuTOawho9LVwITsDAgf0edDvRHfLDwdZfNHmMgZNfmnra/062LJ19J3Qv+0CxV3 3cCUuRUJEptDQiaXXP5DsKdqPEJC0bqy7+dnNQBdjrQL6tu1iKvXFjY6Ozde3Tnp5rG2 mwIcM65UPX6XlQAeuyxfb4IHJM77u4v9Fpn5F3tocfwsC5+tgnI+mO81Zh2PotKcM+Rx K3Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697304271; x=1697909071; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=M9jpxCB8KfkhQAJ+TJIVY7cG2jX9xdJivTpzauSULO8=; b=bJ49Fslqn1Fo9dLAlYIo1Uc4iHjWKPRlK4WYS4OrWM5qGKr22I4JIQKyvXOxc/VcKe /jtB4qUZXiFX4VPwtec9TVlO+evrFlpXha/H4qamCvu2igGy+vDsOGWGf/MpEFPohlyJ dQXsdUBwGNAzToDtAkJ55KfZzs+3TFUKxexljOJ9B+vkCXjfePNBBbBZsu1hdLpRJO9w 1RceVODB/dOp9bMauszop2LXESy4Wy90pEpBNeiycw+PxC8oPCVEloTAN9bPJe5xlQ/S WC2FKkDO2XYOB39WM8MkaQTL8O6OFdWsA991IgGD56cjERkHwktsTNShktqXQRyiD0Rn Cbrg== X-Gm-Message-State: AOJu0YxFJY5BarahGwrS2w8G141p4kywoEE2n9a7WMhCZZpcBA1cPvd9 gUYNo9w2NdwBvmgsTr7KrBCCSz7LtsJgETJt X-Received: by 2002:a7b:ca4c:0:b0:3fe:1b4e:c484 with SMTP id m12-20020a7bca4c000000b003fe1b4ec484mr25724697wml.5.1697304270353; Sat, 14 Oct 2023 10:24:30 -0700 (PDT) Received: from mariano (dynamic-adsl-84-220-189-10.clienti.tiscali.it. [84.220.189.10]) by smtp.gmail.com with ESMTPSA id r17-20020a05600c459100b003fee8793911sm2447246wmo.44.2023.10.14.10.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 10:24:29 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id B381ABFCDA; Sat, 14 Oct 2023 19:24:28 +0200 (CEST) From: Stefano Sabatini To: FFmpeg development discussions and patches Date: Sat, 14 Oct 2023 19:24:28 +0200 Message-Id: <20231014172428.382368-1-stefasab@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] ffprobe: fix XML rendering, review XML layout 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: Stefano Sabatini Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: sktmKTrWUITF Fix rendering of int values within a side data element, which was broken since commit d2d3a83ad93, where the side data element was correctly marked as a variable fields element. Logic to render a string variable was implemented already, but it was not implemented for the int fields path, which was enabled by that commit. Also, code and schema is changed in order to account for multiple variable-fields elements - such as side data, contained within the same parent. Previously it was assumed that a single variable-fields element was contained within the parent, which was the case for tags, but is not the case for side-data. Previously data was rendered as: Now as: Now variable-fields elements are rendered with a containing element containing generic key/values elements, enabling use of strict XML schema. Fix trac issue: https://trac.ffmpeg.org/ticket/10613 --- Changelog | 2 ++ doc/ffprobe.xsd | 29 ++++++++++++++++------ fftools/ffprobe.c | 51 +++++++++++++++++++++++++++----------- tests/ref/fate/ffprobe_xml | 26 ++++++++++++------- 4 files changed, 77 insertions(+), 31 deletions(-) diff --git a/Changelog b/Changelog index 0c73f66546..259180e190 100644 --- a/Changelog +++ b/Changelog @@ -35,6 +35,8 @@ version : - CRI USM demuxer - ffmpeg CLI '-top' option deprecated in favor of the setfield filter - VAAPI AV1 encoder +- ffprobe XML output schema changed to account for multiple + variable-fields elements within the same parent element version 6.0: diff --git a/doc/ffprobe.xsd b/doc/ffprobe.xsd index 87ca265d63..6b815a89df 100644 --- a/doc/ffprobe.xsd +++ b/doc/ffprobe.xsd @@ -43,9 +43,13 @@ + + + + - + @@ -69,14 +73,23 @@ + - - + + + + + + + + + + - + @@ -209,7 +222,7 @@ - + @@ -270,7 +283,7 @@ - + @@ -283,7 +296,7 @@ - + @@ -325,7 +338,7 @@ - + diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 40bb3f46e1..9db266d3fb 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -268,8 +268,8 @@ static struct section sections[] = { [SECTION_ID_PACKETS_AND_FRAMES] = { SECTION_ID_PACKETS_AND_FRAMES, "packets_and_frames", SECTION_FLAG_IS_ARRAY, { 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" }, - [SECTION_ID_PACKET_SIDE_DATA] = { SECTION_ID_PACKET_SIDE_DATA, "side_data", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { -1 }, .unique_name = "packet_side_data", .get_type = get_packet_side_data_type }, + [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_list", .unique_name = "packet_side_data_list" }, + [SECTION_ID_PACKET_SIDE_DATA] = { SECTION_ID_PACKET_SIDE_DATA, "side_data", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { -1 }, .unique_name = "packet_side_data", .element_name = "side_datum", .get_type = get_packet_side_data_type }, [SECTION_ID_PIXEL_FORMATS] = { SECTION_ID_PIXEL_FORMATS, "pixel_formats", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PIXEL_FORMAT, -1 } }, [SECTION_ID_PIXEL_FORMAT] = { SECTION_ID_PIXEL_FORMAT, "pixel_format", 0, { SECTION_ID_PIXEL_FORMAT_FLAGS, SECTION_ID_PIXEL_FORMAT_COMPONENTS, -1 } }, [SECTION_ID_PIXEL_FORMAT_FLAGS] = { SECTION_ID_PIXEL_FORMAT_FLAGS, "flags", 0, { -1 }, .unique_name = "pixel_format_flags" }, @@ -292,7 +292,7 @@ static struct section sections[] = { [SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_disposition" }, [SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_tags" }, [SECTION_ID_STREAM_SIDE_DATA_LIST] ={ SECTION_ID_STREAM_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "stream_side_data_list" }, - [SECTION_ID_STREAM_SIDE_DATA] = { SECTION_ID_STREAM_SIDE_DATA, "side_data", SECTION_FLAG_HAS_TYPE|SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .unique_name = "stream_side_data", .get_type = get_packet_side_data_type }, + [SECTION_ID_STREAM_SIDE_DATA] = { SECTION_ID_STREAM_SIDE_DATA, "side_data", SECTION_FLAG_HAS_TYPE|SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .unique_name = "stream_side_data", .element_name = "side_datum", .get_type = get_packet_side_data_type }, [SECTION_ID_SUBTITLE] = { SECTION_ID_SUBTITLE, "subtitle", 0, { -1 } }, }; @@ -1818,21 +1818,27 @@ static void xml_print_section_header(WriterContext *wctx, void *data) xml->within_tag = 0; writer_put_str(wctx, ">\n"); } - if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) { - xml->indent_level++; - } else { + if (parent_section && (parent_section->flags & SECTION_FLAG_IS_WRAPPER) && wctx->level && wctx->nb_item[wctx->level-1]) writer_w8(wctx, '\n'); xml->indent_level++; - if (section->flags & SECTION_FLAG_IS_ARRAY) { - XML_INDENT(); writer_printf(wctx, "<%s>\n", section->name); + if (section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_HAS_VARIABLE_FIELDS)) { + XML_INDENT(); writer_printf(wctx, "<%s", section->name); + + if (section->flags & SECTION_FLAG_HAS_TYPE) { + AVBPrint buf; + av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); + av_bprint_escape(&buf, section->get_type(data), NULL, + AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); + writer_printf(wctx, " type=\"%s\"", buf.str); + } + writer_printf(wctx, ">\n", section->name); } else { XML_INDENT(); writer_printf(wctx, "<%s ", section->name); xml->within_tag = 1; } - } } static void xml_print_section_footer(WriterContext *wctx) @@ -1846,8 +1852,6 @@ static void xml_print_section_footer(WriterContext *wctx) xml->within_tag = 0; writer_put_str(wctx, "/>\n"); xml->indent_level--; - } else if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) { - xml->indent_level--; } else { XML_INDENT(); writer_printf(wctx, "\n", section->name); xml->indent_level--; @@ -1863,6 +1867,7 @@ static void xml_print_str(WriterContext *wctx, const char *key, const char *valu av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) { + xml->indent_level++; XML_INDENT(); av_bprint_escape(&buf, key, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); @@ -1873,6 +1878,7 @@ static void xml_print_str(WriterContext *wctx, const char *key, const char *valu av_bprint_escape(&buf, value, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); writer_printf(wctx, " value=\"%s\"/>\n", buf.str); + xml->indent_level--; } else { if (wctx->nb_item[wctx->level]) writer_w8(wctx, ' '); @@ -1887,9 +1893,26 @@ static void xml_print_str(WriterContext *wctx, const char *key, const char *valu static void xml_print_int(WriterContext *wctx, const char *key, long long int value) { - if (wctx->nb_item[wctx->level]) - writer_w8(wctx, ' '); - writer_printf(wctx, "%s=\"%lld\"", key, value); + XMLContext *xml = wctx->priv; + const struct section *section = wctx->section[wctx->level]; + + if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) { + AVBPrint buf; + av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); + + xml->indent_level++; + XML_INDENT(); + av_bprint_escape(&buf, key, NULL, + AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); + writer_printf(wctx, "<%s key=\"%s\"", + section->element_name, buf.str); + writer_printf(wctx, " value=\"%lld\"/>\n", value); + xml->indent_level--; + } else { + if (wctx->nb_item[wctx->level]) + writer_w8(wctx, ' '); + writer_printf(wctx, "%s=\"%lld\"", key, value); + } } static Writer xml_writer = { diff --git a/tests/ref/fate/ffprobe_xml b/tests/ref/fate/ffprobe_xml index 4e893edaa9..a0839db46d 100644 --- a/tests/ref/fate/ffprobe_xml +++ b/tests/ref/fate/ffprobe_xml @@ -34,24 +34,32 @@ - - + + + + - - - + + + + + - + + + - - - + + + + +