From patchwork Wed Jan 15 10:55:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 17366 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 D2B7A44B4B1 for ; Wed, 15 Jan 2020 12:56:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE99268B0FD; Wed, 15 Jan 2020 12:56:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp-2.arkena.net (smtp-2.arkena.net [95.81.173.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A80368B05E for ; Wed, 15 Jan 2020 12:56:07 +0200 (EET) Received: from secu2 (unknown [10.180.103.10]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-2.arkena.net (Postfix) with ESMTPSA id 47yPPy5rlGzHh9Y; Wed, 15 Jan 2020 10:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cji.paris; s=20150421; t=1579085766; bh=RMk14FzYtEeJzttqe6gSowpR6kMq2W+c1mS0jCRWSo0=; h=From:To:Cc:Subject:Date:Message-Id; b=k23fKfeJKLghi4auVqduBJ/ynSuTj1IlqmC/mB+rRiZU+X/1+tMGFvSZRs9WD2kDh FaHNj2HiLIpN0/Ngze7K54TjtmWXRSQFRxZ8TiPdvnnSIrtzjlAkM5SYWTu5bIjPxn jZEa4Go9Pz8aCQMD1LBfUenS8rhXZjkjPwf6OUm0= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 8D5223FA6D; Wed, 15 Jan 2020 11:56:08 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Jan 2020 11:55:57 +0100 Message-Id: <20200115105602.1184-4-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200115105602.1184-1-nicolas.gaullier@cji.paris> References: <20200115105602.1184-1-nicolas.gaullier@cji.paris> Subject: [FFmpeg-devel] [PATCH v2 3/8] avformat/s337m: Consider container bit resolution 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Prepare the support of s337m in muxers other than raw (ex: wav). For example, this forbids reading 16 bits DolbyE stream from a 24 bit wav file. --- libavformat/s337m.c | 20 ++++++++++++++------ libavformat/s337m.h | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/libavformat/s337m.c b/libavformat/s337m.c index 9776cf1bf1..f162f86762 100644 --- a/libavformat/s337m.c +++ b/libavformat/s337m.c @@ -34,7 +34,7 @@ static int s337m_get_offset_and_codec(void *avc, uint64_t state, - int data_type, int data_size, + int data_type, int data_size, int container_word_bits, int *offset, enum AVCodecID *codec) { int word_bits; @@ -55,6 +55,11 @@ static int s337m_get_offset_and_codec(void *avc, avpriv_report_missing_feature(avc, "Data type %#x in SMPTE 337M", data_type & 0x1F); return AVERROR_PATCHWELCOME; } + if (container_word_bits && !(container_word_bits == 16 && word_bits == 16) && !(container_word_bits == 24 && word_bits == 20) && !(container_word_bits == 24 && word_bits == 24)) { + if (avc) + av_log(avc, AV_LOG_ERROR, "s337m: Container is %d bits vs. stream is %d bits\n", container_word_bits, word_bits); + return AVERROR_INVALIDDATA; + } if (codec) *codec = AV_CODEC_ID_DOLBY_E; @@ -104,7 +109,7 @@ static int s337m_probe(const AVProbeData *p) data_size = AV_RL24(buf + 3); } - if (s337m_get_offset_and_codec(NULL, state, data_type, data_size, &offset, NULL)) + if (s337m_get_offset_and_codec(NULL, state, data_type, data_size, 0, &offset, NULL)) continue; i = IS_16LE_MARKER(state) ? 0 : IS_20LE_MARKER(state) ? 1 : 2; @@ -142,13 +147,16 @@ static void bswap_buf24(uint8_t *data, int size) FFSWAP(uint8_t, data[0], data[2]); } -int ff_s337m_get_packet(AVIOContext *pb, AVPacket *pkt, int size, enum AVCodecID *codec, void *avc) +int ff_s337m_get_packet(AVIOContext *pb, AVPacket *pkt, int size, enum AVCodecID *codec, void *avc, int container_word_bits) { uint64_t state = 0; int ret, data_type, data_size, offset; int64_t pos, orig_pos = avio_tell(pb); - while (!IS_LE_MARKER(state)) { + if (container_word_bits && container_word_bits != 16 && container_word_bits != 24) + return AVERROR_INVALIDDATA; + while ((container_word_bits == 24 || !IS_16LE_MARKER(state)) + && (container_word_bits == 16 || !IS_20LE_MARKER(state) && !IS_24LE_MARKER(state))) { state = (state << 8) | avio_r8(pb); if (avio_feof(pb)) return AVERROR_EOF; @@ -168,7 +176,7 @@ int ff_s337m_get_packet(AVIOContext *pb, AVPacket *pkt, int size, enum AVCodecID pos = avio_tell(pb); - if ((ret = s337m_get_offset_and_codec(avc, state, data_type, data_size, &offset, codec)) < 0) + if ((ret = s337m_get_offset_and_codec(avc, state, data_type, data_size, container_word_bits, &offset, codec)) < 0) return ret; if (ret = av_new_packet(pkt, FFMIN(offset, size - (pos - orig_pos))) < 0) @@ -194,7 +202,7 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) enum AVCodecID codec; int ret; - if ((ret = ff_s337m_get_packet(s->pb, pkt, avio_size(s->pb), &codec, s)) < 0) + if ((ret = ff_s337m_get_packet(s->pb, pkt, avio_size(s->pb), &codec, s, 0)) < 0) return ret; if (!s->nb_streams) { diff --git a/libavformat/s337m.h b/libavformat/s337m.h index f7bd0c16f6..af2c4c85a3 100644 --- a/libavformat/s337m.h +++ b/libavformat/s337m.h @@ -30,8 +30,9 @@ * @param size Maximum IO read size available for reading at current position * @param codec Returns AV_CODEC_ID_DOLBY_E * @param avc For av_log + * @param container_word_bits 16,24, or 0 for autodetect * @return = 0 on success (an error is raised if no s337m was found) */ -int ff_s337m_get_packet(AVIOContext *pb, AVPacket *pkt, int size, enum AVCodecID *codec, void *avc); +int ff_s337m_get_packet(AVIOContext *pb, AVPacket *pkt, int size, enum AVCodecID *codec, void *avc, int container_word_bits); #endif /* AVFORMAT_S337M_H */