From patchwork Fri Oct 2 22:23:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 22709 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 872E244BDEC for ; Sat, 3 Oct 2020 01:24:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 77A7F68A994; Sat, 3 Oct 2020 01:24:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from srv-infra-1.infra.inf.glb.tvvideoms.com (unknown [213.205.126.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF97968A94D for ; Sat, 3 Oct 2020 01:24:00 +0300 (EEST) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-1.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 4942120223; Fri, 2 Oct 2020 22:23:56 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Sat, 3 Oct 2020 00:23:42 +0200 Message-Id: <20201002222346.1196-6-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20201002222346.1196-1-nicolas.gaullier@cji.paris> References: <20201002222346.1196-1-nicolas.gaullier@cji.paris> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 5/9] avformat/wavdec: s337m support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nicolas Gaullier Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Add s337m probing/reading similarly to spdif. --- libavformat/wavdec.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index d6ab0dde35..b755ab5514 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -43,6 +43,7 @@ #include "riff.h" #include "w64.h" #include "spdif.h" +#include "s337m.h" typedef struct WAVDemuxContext { const AVClass *class; @@ -58,15 +59,17 @@ typedef struct WAVDemuxContext { int ignore_length; int max_size; 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); @@ -79,10 +82,20 @@ static void set_spdif(AVFormatContext *s, WAVDemuxContext *wav) int64_t pos = avio_tell(s->pb); len = ret = avio_read(s->pb, buf, len); if (len >= 0) { - ret = ff_spdif_probe(buf, len, &codec); - if (ret > AVPROBE_SCORE_EXTENSION) { - s->streams[0]->codecpar->codec_id = codec; - wav->spdif = 1; + if (CONFIG_SPDIF_DEMUXER) { + ret = ff_spdif_probe(buf, len, &codec); + if (ret > AVPROBE_SCORE_EXTENSION) { + par->codec_id = codec; + wav->spdif = 1; + } + } + if (CONFIG_S337M_DEMUXER && !wav->spdif + && (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) { + par->codec_id = codec; + wav->s337m = 1; + } } } avio_seek(s->pb, pos, SEEK_SET); @@ -91,7 +104,7 @@ static void set_spdif(AVFormatContext *s, WAVDemuxContext *wav) } if (ret < 0) - av_log(s, AV_LOG_WARNING, "Cannot check for SPDIF\n"); + av_log(s, AV_LOG_WARNING, "Cannot check for SPDIF/S337M\n"); } } @@ -649,7 +662,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; } @@ -751,6 +764,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 = wav->max_size; if (st->codecpar->block_align > 1) { if (size < st->codecpar->block_align) @@ -759,6 +776,8 @@ smv_out: } size = FFMIN(size, left); ret = av_get_packet(s->pb, pkt, size); + } + if (ret < 0) return ret; pkt->stream_index = 0; @@ -947,7 +966,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; }