diff mbox series

[FFmpeg-devel,v2,5/8] avformat/wavdec: s337m support

Message ID 20200115105602.1184-6-nicolas.gaullier@cji.paris
State Superseded
Headers show
Series avformat: Use s337m subdemux inside wav | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Nicolas Gaullier Jan. 15, 2020, 10:55 a.m. UTC
Add s337m probing/reading similarly to spdif.
---
 libavformat/wavdec.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

Comments

Carl Eugen Hoyos Jan. 15, 2020, 12:38 p.m. UTC | #1
Am Mi., 15. Jan. 2020 um 11:57 Uhr schrieb Nicolas Gaullier
<nicolas.gaullier@cji.paris>:
>
> Add s337m probing/reading similarly to spdif.
> ---
>  libavformat/wavdec.c | 23 +++++++++++++++++++----
>  1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
> index 575c667452..d030ed9f9d 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,17 @@ typedef struct WAVDemuxContext {
>      int audio_eof;
>      int ignore_length;
>      int spdif;
> +    int s337m;
>      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) {

Did you test this with both "--disable-everything
--enable-demuxer=spdif" and "--disable-everything
--enable-demuxer=s337m"?
Neither should fail compilation.

Carl Eugen
Nicolas Gaullier Jan. 15, 2020, 6:16 p.m. UTC | #2
>> Add s337m probing/reading similarly to spdif.
>> ---
>>  libavformat/wavdec.c | 23 +++++++++++++++++++----
>>  1 file changed, 19 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 
>> 575c667452..d030ed9f9d 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,17 @@ typedef struct WAVDemuxContext {
>>      int audio_eof;
>>      int ignore_length;
>>      int spdif;
>> +    int s337m;
>>      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) {
>
>Did you test this with both "--disable-everything --enable-demuxer=spdif" and "--disable-everything --enable-demuxer=s337m"?
>Neither should fail compilation.
>
>Carl Eugen

I just have tested both, and compilation is ok.

Nicolas
Nicolas Gaullier Jan. 16, 2020, 10:30 a.m. UTC | #3
>> >> Add s337m probing/reading similarly to spdif.
>> >> ---
>> >>  libavformat/wavdec.c | 23 +++++++++++++++++++----
>> >>  1 file changed, 19 insertions(+), 4 deletions(-)
>> >>
>> >> diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 
>> >> 575c667452..d030ed9f9d 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,17 @@ typedef struct WAVDemuxContext {
>> >>      int audio_eof;
>> >>      int ignore_length;
>> >>      int spdif;
>> >> +    int s337m;
>> >>      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) {
>> >
>> >Did you test this with both "--disable-everything --enable-demuxer=spdif" and "--disable-everything --enable-demuxer=s337m"?
>> >Neither should fail compilation.
>> >
>> >Carl Eugen
>>
>> I just have tested both, and compilation is ok.
>
>Sorry, this should have been "--disable-everything --enable-demuxer=wav,spdif" and "--disable-everything --enable-demuxer=wav,s337m".
>
>Carl Eugen

Sorry, I missed that. I send a new patch.
diff mbox series

Patch

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 575c667452..d030ed9f9d 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,17 @@  typedef struct WAVDemuxContext {
     int audio_eof;
     int ignore_length;
     int spdif;
+    int s337m;
     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 +83,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 ((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, 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 +605,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;
 }
@@ -700,6 +709,10 @@  smv_out:
         wav->data_end = avio_tell(s->pb) + left;
     }
 
+    if (CONFIG_S337M_DEMUXER && wav->s337m == 1) {
+        size = FFMIN(S337M_MAX_OFFSET, left);
+        ret  = ff_s337m_get_packet(s->pb, pkt, size, NULL, s, st->codecpar->bits_per_coded_sample);
+    } else {
     size = MAX_SIZE;
     if (st->codecpar->block_align > 1) {
         if (size < st->codecpar->block_align)
@@ -708,6 +721,8 @@  smv_out:
     }
     size = FFMIN(size, left);
     ret  = av_get_packet(s->pb, pkt, size);
+    }
+
     if (ret < 0)
         return ret;
     pkt->stream_index = 0;
@@ -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;
 }