diff mbox series

[FFmpeg-devel,1/2] avformat/mlpdec: fix time_base for packet timestamps

Message ID 20210905162750.13293-1-onemda@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avformat/mlpdec: fix time_base for packet timestamps | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Paul B Mahol Sept. 5, 2021, 4:27 p.m. UTC
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavformat/mlpdec.c | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

Comments

Andreas Rheinhardt Sept. 5, 2021, 4:33 p.m. UTC | #1
Paul B Mahol:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavformat/mlpdec.c | 43 ++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 40 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/mlpdec.c b/libavformat/mlpdec.c
> index 8f0aabb510..cc5b8d07bb 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) & 0xF);

The "& 0xF" is unnecessary now.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/mlpdec.c b/libavformat/mlpdec.c
index 8f0aabb510..cc5b8d07bb 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) & 0xF);
+                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
-