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 6190A4E47C
	for <ffmpegdev@gitmailbox.com>; Tue, 11 Mar 2025 16:56:23 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1590368E1D3;
	Tue, 11 Mar 2025 18:56:08 +0200 (EET)
Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com
 [209.85.128.170])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 04D9868E198
 for <ffmpeg-devel@ffmpeg.org>; Tue, 11 Mar 2025 18:55:30 +0200 (EET)
Received: by mail-yw1-f170.google.com with SMTP id
 00721157ae682-6feb229b716so51921157b3.3
 for <ffmpeg-devel@ffmpeg.org>; Tue, 11 Mar 2025 09:55:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1741712129; x=1742316929; 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=UxeGAcz1Ff1aNarqZRnvHXmldknC4xm3fOI6awXYySG7G1SPf6zkRr+MoWcR/xl9nF
 T6GeXEVGt5L1nHivx6ZLhLRPeMJcjQZrlB9JBa8JyHvWAZmMcfHzDZNXLtFn2Iu4mmxT
 cBZmz/W/e9loJJoD8qHXQ00p4ue2VYjAC6TmaCqRUgLlNRGhfm/fgh2VpnCVKab7ugu7
 IVLaSA5Jce0CbhiOM8rLAx0iY5gZQPr7J4uNGoaM1ROBrDjpEfdkVqCpZscrLAYLGM41
 zGZqyI6uFDDxfbAm/KaUmi/1iAy289D0mplhwmwEmQL51c2tXFh0tzUH03Gx3KoBYgSs
 QxDw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1741712129; x=1742316929;
 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=NYrzYc4ssKTceWR0J2N/v5E0Xft4I3Hahpbkj2/OMrFCcVWst+Rf3defALvkQJ02cn
 PCZy3NrOgOSMwewkx8/brVfdgKLSAJVFTLBYsY7oZvQ7+bNuqKRgXzOmVnYi8fxgWjub
 EbgxH531Qsu8t5QtHmeFHfb2EOWnmKDJ4aW8TcjYb6GW6yVx6YYDZYqWtS751AiPINu9
 zzT7lUKgZcEm3HqWPkiM6z96/06671+g6etKDyaen91O4im1QbkH+r0BUp/zcOnDHJaD
 BBfLoTXIbdm514E5Iyr45lIiw59a5iaKrm9FWt6I+6cVMY5jbmlWMohanA1GKKG+6mGS
 thhQ==
X-Gm-Message-State: AOJu0Yzi/E8Dq185eOW8n6ye01UatkerBiy+DkO3pFa8hqhYSTAmzFhY
 MY4jsOW0uL+eViFNf/8tsmxCSnrGABqXQcS0EPEgbmWIylGWdolJoCSadVsT
X-Gm-Gg: ASbGncvgbOKZ5SYb7MnrrHhn24BfMT8Cy2Tz545bSATbyauCpm+HjJ+jF/GskPhQCl8
 uKEpn9So7JXWXAnV9xvAjesgVUtbgboJcylNbsUdKTB9AdMzdlf+ooJHqKWqaUwBfra9KH52YwQ
 V9jOiWM0GTXn8GMuxcCCvoC1wAEebNV3EN+QCJuaabHeub1KYsXW925XMk0VChhK1xpvsXu9wgX
 MZCEo/Kygoj5uZGbuDE7uC5IEk5/GYOFZIw6/wgvkUE7p/F/z2Z30/4RdFUO1E3oQd7jiNzbxtW
 sRoSkoa1kyw/w0f7i8nVJHlCdp0TsVj/LuGqWJG/s2gS9S0xWtgpivcqMMUV6H+d6aT8cJBN1Lm
 fwYzG6t2wSRfZ+ETAPZw=
X-Google-Smtp-Source: AGHT+IHwCPrLwqf3Kvq6NMvvQYMfUVM5yPXAYa4uD7VYIu0IEvA64y/ggENqzTBUPOhTpORHsjLLbA==
X-Received: by 2002:a05:690c:6d13:b0:6f6:7b3f:2a68 with SMTP id
 00721157ae682-6febf3accb1mr270802537b3.31.1741712128849; 
 Tue, 11 Mar 2025 09:55:28 -0700 (PDT)
Received: from localhost.localdomain ([2607:fb90:ee62:1559:4ce8:9cd:68c0:bf98])
 by smtp.gmail.com with ESMTPSA id
 00721157ae682-6feb2c64b57sm27544217b3.119.2025.03.11.09.55.27
 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
 Tue, 11 Mar 2025 09:55:28 -0700 (PDT)
From: Romain Beauxis <romain.beauxis@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Date: Tue, 11 Mar 2025 11:55:09 -0500
Message-Id: <20250311165513.17834-5-romain.beauxis@gmail.com>
X-Mailer: git-send-email 2.39.5 (Apple Git-154)
In-Reply-To: <20250311165513.17834-1-romain.beauxis@gmail.com>
References: <20250311165513.17834-1-romain.beauxis@gmail.com>
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH v8 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/20250311165513.17834-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".