From patchwork Wed Jan 15 10:55:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 17363 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 0AF1844B4B1 for ; Wed, 15 Jan 2020 12:56:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E830368B0EE; Wed, 15 Jan 2020 12:56:14 +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 CAA5D68A280 for ; Wed, 15 Jan 2020 12:56:06 +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 47yPPy39wszHh9S; 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=bI389JMzPhrrrNh7pXN3NPYTX7AYCjukC4nKbslyXv0=; h=From:To:Cc:Subject:Date:Message-Id; b=eun3UsFVm46xi55t7Qrw4wVKzcZa5Yci5GKW14xh6zBFoyC/Hkhlz9yGuM+MMiy1E 5E2M9XJlqWswlFYcbauMtprs4yd97KHGQ6VVUw3X4oEyRrdv3h6XsHwtDbpT9VkwGz HcVxq+6Fj/0wTTpJmr++6FKfHIWBNio2Aq08t1w0= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 302153FA74; Wed, 15 Jan 2020 11:56:08 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Jan 2020 11:55:56 +0100 Message-Id: <20200115105602.1184-3-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 2/8] avformat/s337m: Split read_packet/get_packet 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 use of s337m_get_packet from outside. --- libavformat/s337m.c | 26 ++++++++++++++++++++------ libavformat/s337m.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 libavformat/s337m.h diff --git a/libavformat/s337m.c b/libavformat/s337m.c index 8956afb23f..9776cf1bf1 100644 --- a/libavformat/s337m.c +++ b/libavformat/s337m.c @@ -21,6 +21,7 @@ #include "libavutil/intreadwrite.h" #include "avformat.h" #include "spdif.h" +#include "s337m.h" #define MARKER_16LE 0x72F81F4E #define MARKER_20LE 0x20876FF0E154 @@ -141,18 +142,20 @@ static void bswap_buf24(uint8_t *data, int size) FFSWAP(uint8_t, data[0], data[2]); } -static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) +int ff_s337m_get_packet(AVIOContext *pb, AVPacket *pkt, int size, enum AVCodecID *codec, void *avc) { - AVIOContext *pb = s->pb; uint64_t state = 0; int ret, data_type, data_size, offset; - enum AVCodecID codec; - int64_t pos; + int64_t pos, orig_pos = avio_tell(pb); while (!IS_LE_MARKER(state)) { state = (state << 8) | avio_r8(pb); if (avio_feof(pb)) return AVERROR_EOF; + if (avio_tell(pb) - orig_pos + 6 >= size) { + av_log(avc, AV_LOG_ERROR, "s337m : sync bytes not found at packet pos=0x%"PRIx64" size=%d\n", orig_pos, size); + return AVERROR_INVALIDDATA; + } } if (IS_16LE_MARKER(state)) { @@ -165,10 +168,10 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) pos = avio_tell(pb); - if ((ret = s337m_get_offset_and_codec(s, state, data_type, data_size, &offset, &codec)) < 0) + if ((ret = s337m_get_offset_and_codec(avc, state, data_type, data_size, &offset, codec)) < 0) return ret; - if ((ret = av_new_packet(pkt, offset)) < 0) + if (ret = av_new_packet(pkt, FFMIN(offset, size - (pos - orig_pos))) < 0) return ret; pkt->pos = pos; @@ -183,6 +186,17 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) else bswap_buf24(pkt->data, pkt->size); + return 0; +} + +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) + return ret; + if (!s->nb_streams) { AVStream *st = avformat_new_stream(s, NULL); if (!st) { diff --git a/libavformat/s337m.h b/libavformat/s337m.h new file mode 100644 index 0000000000..f7bd0c16f6 --- /dev/null +++ b/libavformat/s337m.h @@ -0,0 +1,37 @@ +/* + * SMPTE ST 337 common header + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFORMAT_S337M_H +#define AVFORMAT_S337M_H + +/** + * Read s337m packets in a PCM_S16LE/S24LE stereo stream + * Returns the first inner packet found + * Note that it does not require a clean guard band + * @param pb Associated IO context + * @param pkt On success, returns a DOLBY E packet + * @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 + * @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); + +#endif /* AVFORMAT_S337M_H */