From: Romain Beauxis <[email protected]>

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
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

Reply via email to