[FFmpeg-devel] [PATCH 5/9] avformat/wavdec: s337m support

Nicolas Gaullier nicolas.gaullier at cji.paris
Fri Jan 3 17:56:32 EET 2020


Add s337m probing/reading similarly to spdif.
Add a new AVOption 'dolbyeprobe' to enable it.
---
 libavformat/wavdec.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 575c667452..2796905e1f 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -41,6 +41,7 @@
 #include "riff.h"
 #include "w64.h"
 #include "spdif.h"
+#include "s337m.h"
 
 typedef struct WAVDemuxContext {
     const AVClass *class;
@@ -55,15 +56,18 @@ typedef struct WAVDemuxContext {
     int audio_eof;
     int ignore_length;
     int spdif;
+    int s337m;
+    int s337m_probe;
     int smv_cur_pt;
     int smv_given_first;
     int unaligned; // e.g. if an odd number of bytes ID3 tag was prepended
     int rifx; // RIFX: integer byte order for parameters is big endian
 } WAVDemuxContext;
 
-static void set_spdif(AVFormatContext *s, WAVDemuxContext *wav)
+static void set_spdif_s337m(AVFormatContext *s, WAVDemuxContext *wav)
 {
-    if (CONFIG_SPDIF_DEMUXER && s->streams[0]->codecpar->codec_tag == 1) {
+    AVCodecParameters *par = s->streams[0]->codecpar;
+    if ((CONFIG_SPDIF_DEMUXER || CONFIG_S337M_DEMUXER) && par->codec_tag == 1) {
         enum AVCodecID codec;
         int len = 1<<16;
         int ret = ffio_ensure_seekback(s->pb, len);
@@ -80,6 +84,12 @@ static void set_spdif(AVFormatContext *s, WAVDemuxContext *wav)
                     if (ret > AVPROBE_SCORE_EXTENSION) {
                         s->streams[0]->codecpar->codec_id = codec;
                         wav->spdif = 1;
+                    } else if (wav->s337m_probe && (par->codec_id == AV_CODEC_ID_PCM_S16LE || par->codec_id == AV_CODEC_ID_PCM_S24LE) && par->channels == 2) {
+                        ret = ff_s337m_probe(buf, len, &codec, s, par->bits_per_coded_sample);
+                        if (ret > AVPROBE_SCORE_EXTENSION) {
+                            s->streams[0]->codecpar->codec_id = codec;
+                            wav->s337m = 1;
+                        }
                     }
                 }
                 avio_seek(s->pb, pos, SEEK_SET);
@@ -596,7 +606,7 @@ break_loop:
     ff_metadata_conv_ctx(s, NULL, wav_metadata_conv);
     ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv);
 
-    set_spdif(s, wav);
+    set_spdif_s337m(s, wav);
 
     return 0;
 }
@@ -633,6 +643,8 @@ static int wav_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     if (CONFIG_SPDIF_DEMUXER && wav->spdif == 1)
         return ff_spdif_read_packet(s, pkt);
+    if (CONFIG_S337M_DEMUXER && wav->s337m == 1)
+        return ff_s337m_read_packet(s, pkt);
 
     if (wav->smv_data_ofs > 0) {
         int64_t audio_dts, video_dts;
@@ -753,6 +765,9 @@ static int wav_read_seek(AVFormatContext *s,
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 static const AVOption demux_options[] = {
     { "ignore_length", "Ignore length", OFFSET(ignore_length), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, DEC },
+#if CONFIG_S337M_DEMUXER
+    {"dolbyeprobe", "Probe Dolby E in pcm/stereo streams", OFFSET(s337m_probe), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC },
+#endif
     { NULL },
 };
 
@@ -895,7 +910,7 @@ static int w64_read_header(AVFormatContext *s)
 
     avio_seek(pb, data_ofs, SEEK_SET);
 
-    set_spdif(s, wav);
+    set_spdif_s337m(s, wav);
 
     return 0;
 }
-- 
2.14.1.windows.1



More information about the ffmpeg-devel mailing list