[FFmpeg-cvslog] avformat/mlpdec: fix time_base for packet timestamps

Paul B Mahol git at videolan.org
Tue Sep 7 19:17:39 EEST 2021


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Sep  5 17:55:19 2021 +0200| [7ebeef6affb5f683febdc86f2dc45a339ac97f6c] | committer: Paul B Mahol

avformat/mlpdec: fix time_base for packet timestamps

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7ebeef6affb5f683febdc86f2dc45a339ac97f6c
---

 libavformat/mlpdec.c | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/libavformat/mlpdec.c b/libavformat/mlpdec.c
index 8f0aabb510..f0996fef31 100644
--- a/libavformat/mlpdec.c
+++ b/libavformat/mlpdec.c
@@ -22,8 +22,12 @@
  */
 
 #include "avformat.h"
+#include "avio_internal.h"
+#include "internal.h"
 #include "rawdec.h"
 #include "libavutil/intreadwrite.h"
+#include "libavcodec/mlp.h"
+#include "libavcodec/mlp_parse.h"
 
 static int av_always_inline mlp_thd_probe(const AVProbeData *p, uint32_t sync)
 {
@@ -50,6 +54,40 @@ static int av_always_inline mlp_thd_probe(const AVProbeData *p, uint32_t sync)
     return 0;
 }
 
+static int mlp_read_header(AVFormatContext *s)
+{
+    int ret = ff_raw_audio_read_header(s);
+
+    if (ret < 0)
+        return ret;
+
+    ret = ffio_ensure_seekback(s->pb, 10);
+    if (ret == 0) {
+        uint8_t buffer[10];
+        int read, sample_rate = 0;
+
+        read = avio_read(s->pb, buffer, 10);
+        if (read == 10) {
+            switch (buffer[7]) {
+            case SYNC_TRUEHD:
+                sample_rate = mlp_samplerate(buffer[8] >> 4);
+                break;
+            case SYNC_MLP:
+                sample_rate = mlp_samplerate(buffer[9] >> 4);
+                break;
+            }
+
+            if (sample_rate)
+                avpriv_set_pts_info(s->streams[0], 64, 1, sample_rate);
+        }
+
+        if (read > 0)
+            avio_seek(s->pb, -read, SEEK_CUR);
+    }
+
+    return 0;
+}
+
 #if CONFIG_MLP_DEMUXER
 static int mlp_probe(const AVProbeData *p)
 {
@@ -60,7 +98,7 @@ const AVInputFormat ff_mlp_demuxer = {
     .name           = "mlp",
     .long_name      = NULL_IF_CONFIG_SMALL("raw MLP"),
     .read_probe     = mlp_probe,
-    .read_header    = ff_raw_audio_read_header,
+    .read_header    = mlp_read_header,
     .read_packet    = ff_raw_read_partial_packet,
     .flags          = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
     .extensions     = "mlp",
@@ -80,7 +118,7 @@ const AVInputFormat ff_truehd_demuxer = {
     .name           = "truehd",
     .long_name      = NULL_IF_CONFIG_SMALL("raw TrueHD"),
     .read_probe     = thd_probe,
-    .read_header    = ff_raw_audio_read_header,
+    .read_header    = mlp_read_header,
     .read_packet    = ff_raw_read_partial_packet,
     .flags          = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
     .extensions     = "thd",
@@ -89,4 +127,3 @@ const AVInputFormat ff_truehd_demuxer = {
     .priv_class     = &ff_raw_demuxer_class,
 };
 #endif
-



More information about the ffmpeg-cvslog mailing list