diff mbox series

[FFmpeg-devel,v2,2/3] libavformat/oggparseopus.c: Accept empty packets, decode metadata packets.

Message ID 20230505132848.18011-2-toots@rastageeks.org
State New
Headers show
Series [FFmpeg-devel,v2,1/3] libavformat/oggparseflac.c: Decode metadata packets. | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Romain Beauxis May 5, 2023, 1:28 p.m. UTC
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 mbox series

Patch

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;