Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: toots@rastageeks.org
To: ffmpeg-devel@ffmpeg.org
Cc: Romain Beauxis <toots@rastageeks.org>
Subject: [FFmpeg-devel] [PATCH v2 2/3] libavformat/oggparseopus.c: Accept empty packets, decode metadata packets.
Date: Fri,  5 May 2023 08:28:49 -0500
Message-ID: <20230505132848.18011-2-toots@rastageeks.org> (raw)
In-Reply-To: <20230505132848.18011-1-toots@rastageeks.org>

From: Romain Beauxis <toots@rastageeks.org>

This patch provides the same functionality as the previous patch but for
ogg/opus.

The need to accept empty packets on end of stream (EOS) is explained in the
final patch of the series.

---
 libavformat/oggparseopus.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index 54aa725be6..7991e9db42 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -117,8 +117,9 @@ static int opus_packet(AVFormatContext *avf, int idx)
     uint8_t *packet              = os->buf + os->pstart;
     int ret;
 
-    if (!os->psize)
+    if (!os->psize && !(os->flags & OGG_FLAG_EOS))
         return AVERROR_INVALIDDATA;
+
     if (os->granule > (1LL << 62)) {
         av_log(avf, AV_LOG_ERROR, "Unsupported huge granule pos %"PRId64 "\n", os->granule);
         return AVERROR_INVALIDDATA;
@@ -152,14 +153,23 @@ static int opus_packet(AVFormatContext *avf, int idx)
         os->lastdts                 = os->granule - duration;
     }
 
-    if ((ret = opus_duration(packet, os->psize)) < 0)
-        return ret;
+    if (os->psize > 0) {
+        if ((ret = opus_duration(packet, os->psize)) < 0)
+            return ret;
+
+        os->pduration = ret;
+        if (os->lastpts != AV_NOPTS_VALUE) {
+            if (st->start_time == AV_NOPTS_VALUE)
+                st->start_time = os->lastpts;
+            priv->cur_dts = os->lastdts = os->lastpts -= priv->pre_skip;
+        }
+    }
 
-    os->pduration = ret;
-    if (os->lastpts != AV_NOPTS_VALUE) {
-        if (st->start_time == AV_NOPTS_VALUE)
-            st->start_time = os->lastpts;
-        priv->cur_dts = os->lastdts = os->lastpts -= priv->pre_skip;
+    if (os->psize > 8 && !memcmp(os->buf + os->pstart, "OpusTags", 8)) {
+        av_dict_free(&st->metadata);
+        ret = ff_vorbis_stream_comment(avf, st, os->buf + os->pstart + 8,
+                                       os->psize - 8);
+        if (ret < 0) return ret;
     }
 
     priv->cur_dts += os->pduration;
-- 
2.37.1 (Apple Git-137.1)

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

  reply	other threads:[~2023-05-05 13:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05 13:28 [FFmpeg-devel] [PATCH v2 1/3] libavformat/oggparseflac.c: Decode " toots
2023-05-05 13:28 ` toots [this message]
2023-05-05 13:28 ` [FFmpeg-devel] [PATCH v2 3/3] libavformat/oggdec.c: keep reading on empty packets to accommodate for chained bitstreams toots

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230505132848.18011-2-toots@rastageeks.org \
    --to=toots@rastageeks.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git