From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 3E9144CDA7
	for <ffmpegdev@gitmailbox.com>; Tue, 25 Feb 2025 22:02:58 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8957368CC70;
	Wed, 26 Feb 2025 00:02:02 +0200 (EET)
Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com
 [209.85.128.174])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AD5EB68CC2D
 for <ffmpeg-devel@ffmpeg.org>; Wed, 26 Feb 2025 00:01:54 +0200 (EET)
Received: by mail-yw1-f174.google.com with SMTP id
 00721157ae682-6fb2a0e4125so43020227b3.1
 for <ffmpeg-devel@ffmpeg.org>; Tue, 25 Feb 2025 14:01:54 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1740520913; x=1741125713; darn=ffmpeg.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=b0gH4nL4cGGyvOjPQUIk04w5+ziqRnR4Os0818gimYg=;
 b=LHq7cbunXziz2HUeUGuiS0Y+F4/pbq94py3MVz7O4QOIE+TjorVDoIVp73kZu2vXZz
 p9/WsKlhOoWf2LrQI9SscZpprCV8wy/4Qc4OPvCRfcneSeMxpbsSZn+5qInmeNkyFB9h
 Cm9dtPRQ1XMylv++BQ2pnyAZXShiebWYjfYTP7lTTRFxmCtJFBIPuzdkJQR6F2F0rL8k
 fLovAF9XE68jAY21e8Rq4yGlj3XmDshdejMWhkQmCOzOu0mztZd9ns7Qyoojpb7WFncl
 dl/qtFkhKiVECAp/+t9SleoxaWcpdd7womIkDRPWiX5gn+Rft9y4Q2gej8CTBv+OV4Qu
 35OA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1740520913; x=1741125713;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=b0gH4nL4cGGyvOjPQUIk04w5+ziqRnR4Os0818gimYg=;
 b=m4qEU7MCJSRWf6WJwG4dM0VKMxtnii2rTKVmT0DHR3fTga6TmDfZ9xhSOdXoCKsgFO
 ECo6Uod/YCNV+G3mdlTKzP/pYvNQef14V36lZHtXaDA6T4/aDuw6Hl1wlDISuui+0V4f
 vKcHKIMUGqXRDEqPW751LDV0gAIgED7gCVjtg9wL8Yv+dn0HcG5yqs2Ekjgo0NGl+uE7
 ATPwoS7XdZSNXEpyi47if0PoL1cUmMO+MYQUFRLjgM12B3xTt7frgLAB0ADapLXPsFkJ
 MKppxmEl93Tx/L2Rdv1GYexIL6kOecXekQfiEA2pmzFyb78MSyNW4TKwDUVJvw/MzZqN
 BrQQ==
X-Gm-Message-State: AOJu0YwUkoRcCH+kVRZgc1YEPBypLRyo6FxokFxoLdXqdhN5hWpb829J
 OFrvA8XFVJr/y1U24KXLGPdPCIn9xU+2DNL6MEvDbj3zO+IwG5nzMcQkiK1a
X-Gm-Gg: ASbGncsmISBwWoFRme5sfjBo5dcrOOpl3osQTIafKB3YBAaNjnEW0oS2k6IJJ66UoOE
 ZD5X0Jz0GpYasp5ZfXkXBnOI6ZrZcopFuqeIyOYOF5V3bcePLmkcbcGoKDq7JDiUEcgChWE5O7V
 g4qWRTkDMBBvT7K4LWb1Esgs/ExWVxEzH8dRarlyoa5h4WJmh0TaFxwZ7QluRdnge8IWvprM6lY
 vdDtTUdDD0xUvDo4QPqdCLOVa1P/STMKvgjOgP3tMzv2uJBm8kM6fOMblf8jb/CvrRq1GzJ+Ih7
 CSsCEYG0/CBPahAbcG1/Re2nYmrl7pYnUz+IQToqMh7D3PzjH37/v5UQ99R63cnGRXg=
X-Google-Smtp-Source: AGHT+IHq93FpZ8KPLbwuQTG/LcRcfKNgPXswwSMvQAOSD6RCzwSz7lgLNPpXV7D7qOPZJn9Zn7huEg==
X-Received: by 2002:a05:690c:380e:b0:6f6:cd43:543c with SMTP id
 00721157ae682-6fd10afd409mr44523147b3.34.1740520912725; 
 Tue, 25 Feb 2025 14:01:52 -0800 (PST)
Received: from localhost.localdomain
 ([2607:fb90:e333:5b39:2036:1eaa:d627:4a51])
 by smtp.gmail.com with ESMTPSA id
 00721157ae682-6fd117dd70csm6487767b3.83.2025.02.25.14.01.51
 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
 Tue, 25 Feb 2025 14:01:52 -0800 (PST)
From: Romain Beauxis <romain.beauxis@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Date: Tue, 25 Feb 2025 16:01:17 -0600
Message-Id: <20250225220121.98449-5-romain.beauxis@gmail.com>
X-Mailer: git-send-email 2.39.5 (Apple Git-154)
In-Reply-To: <20250225220121.98449-1-romain.beauxis@gmail.com>
References: <20250225220121.98449-1-romain.beauxis@gmail.com>
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH v7 4/8] libavformat/oggdec.h,
 libavformat/oggparsevorbis.c: Factor out vorbis metadata update
 mechanism.
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Romain Beauxis <romain.beauxis@gmail.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250225220121.98449-5-romain.beauxis@gmail.com/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

---
 libavformat/oggdec.h         | 14 ++++++++++++++
 libavformat/oggparsevorbis.c | 25 +++++++++++++++++--------
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h
index 43df23f4cb..c8460a66e9 100644
--- a/libavformat/oggdec.h
+++ b/libavformat/oggdec.h
@@ -151,6 +151,20 @@ int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m,
 int ff_vorbis_stream_comment(AVFormatContext *as, AVStream *st,
                              const uint8_t *buf, int size);
 
+/**
+ * Parse Vorbis comments, add metadata to an AVStream
+ *
+ * This function also attaches the metadata to the next decoded
+ * packet as AV_PKT_DATA_METADATA_UPDATE
+ *
+ * @note  The buffer will be temporarily modifed by this function,
+ *        so it needs to be writable. Furthermore it must be padded
+ *        by a single byte (not counted in size).
+ *        All changes will have been reverted upon return.
+ */
+int ff_vorbis_update_metadata(AVFormatContext *s, AVStream *st,
+                              const uint8_t *buf, int size);
+
 static inline int
 ogg_find_stream (struct ogg * ogg, int serial)
 {
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index 9f50ab9ffc..308deb7feb 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -263,20 +263,16 @@ static void vorbis_cleanup(AVFormatContext *s, int idx)
     }
 }
 
-static int vorbis_update_metadata(AVFormatContext *s, int idx)
+int ff_vorbis_update_metadata(AVFormatContext *s, AVStream *st,
+                              const uint8_t *buf, int size)
 {
     struct ogg *ogg = s->priv_data;
-    struct ogg_stream *os = ogg->streams + idx;
-    AVStream *st = s->streams[idx];
+    struct ogg_stream *os = ogg->streams + st->index;
     int ret;
 
-    if (os->psize <= 8)
-        return 0;
-
     /* New metadata packet; release old data. */
     av_dict_free(&st->metadata);
-    ret = ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 7,
-                                   os->psize - 8);
+    ret = ff_vorbis_stream_comment(s, st, buf, size);
     if (ret < 0)
         return ret;
 
@@ -293,6 +289,19 @@ static int vorbis_update_metadata(AVFormatContext *s, int idx)
     return ret;
 }
 
+static int vorbis_update_metadata(AVFormatContext *s, int idx)
+{
+    struct ogg *ogg = s->priv_data;
+    struct ogg_stream *os = ogg->streams + idx;
+    AVStream *st = s->streams[idx];
+
+    if (os->psize <= 8)
+        return 0;
+
+    return ff_vorbis_update_metadata(s, st, os->buf + os->pstart + 7,
+                                     os->psize - 8);
+}
+
 static int vorbis_header(AVFormatContext *s, int idx)
 {
     struct ogg *ogg = s->priv_data;
-- 
2.39.5 (Apple Git-154)

_______________________________________________
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".