From patchwork Mon Feb 13 18:09:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 40381 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp3676586pzk; Mon, 13 Feb 2023 10:09:55 -0800 (PST) X-Google-Smtp-Source: AK7set9UoNtDIsnmlYnFh5fu5HNrDrrag6BkXGq/RrzkP1hfJRkte1sZvS++BT52nXrYBlSAngz0 X-Received: by 2002:a17:906:7f10:b0:881:d1ad:1640 with SMTP id d16-20020a1709067f1000b00881d1ad1640mr22561387ejr.57.1676311795567; Mon, 13 Feb 2023 10:09:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676311795; cv=none; d=google.com; s=arc-20160816; b=sT15h7JaKrGWBaSfCjSyYIMeMHonF0EdNgNP3+CRRAKKg/PgB+ho0RL5D5nvqtian1 nrOtgZIuKOZHFI6rRcqbjEJ1BfttB9cFilBNWZzx0uPUBxxUkNtRCBRRctiVWx1bMz2M CzlTPwee7SCkVIo8nK6EyddShqDl8VI0/JbvhicAnjV70KQ0GvlNJGsLJGK2iQK2l/C3 nTKrA7w0h8dgCvs2zIHqFmR5o7teojdzuXRf9IfqDLcVtgXsmCFWUlx3tJc4VDq96cQ1 fnaHnYSOmcJm1kwisSRkf6jga8JhEyWwpoBkAXDYIL/JXxMoVZVZXKcFGh1aftFmzD0x hhZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=GxwjqZ4cRUx8BiekgHTFmIwxCuZ6bfuFmfyTJEg1puY=; b=DSVU4l84b504S2Mrp7a4+RS39XI6oDH6SKZXhS+6POLahL5OWDLvlLxxJssecSHm34 fg4wK4ppWGaZqsEv61OML62R+4RerBK7B0fzkuJsaAfU313eei/rDTOcHV0uPiAu9N2X a0ATvypTeldEr4x49l8tDBgdx02FLL5Li50s4lOnwo6h2/bVSX/TA0LFZVi13+LvDXQO 6bqFuGFOm427ldGp417lkHGXWOR8XFeytErF94w9qhKnW85UscRlVUtTIZYrsxn2cUYM LGArZVn1P+PeqGuuEUpA4Y+uxJcUbdItaQQNGseGjtpHdXX0SNSnZhq9Q3gO6Gu8sloE 4eOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id oh10-20020a17090784ca00b0088a6700e203si12679222ejc.128.2023.02.13.10.09.54; Mon, 13 Feb 2023 10:09:55 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A6B968BE3B; Mon, 13 Feb 2023 20:09:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from srv-infra-2.infra.inf.glb.tvvideoms.com (www.inf.tvvideoms.com [213.205.126.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CBEFB68BD27 for ; Mon, 13 Feb 2023 20:09:44 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-2.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 2561442B55; Mon, 13 Feb 2023 18:09:44 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Feb 2023 19:09:31 +0100 Message-Id: <20230213180936.815-2-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.39.1.windows.1 In-Reply-To: <20230213180936.815-1-nicolas.gaullier@cji.paris> References: <20230213180936.815-1-nicolas.gaullier@cji.paris> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6] avformat/s337m: Split read_packet/get_packet X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: wCzPv4zdJ1U1 Prepare use of s337m_get_packet from outside. --- libavformat/s337m.c | 24 ++++++++++++++++++++---- libavformat/s337m.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 libavformat/s337m.h diff --git a/libavformat/s337m.c b/libavformat/s337m.c index 6fecfeffae..582c8b3670 100644 --- a/libavformat/s337m.c +++ b/libavformat/s337m.c @@ -22,6 +22,7 @@ #include "avformat.h" #include "internal.h" #include "spdif.h" +#include "s337m.h" #define MARKER_16LE 0x72F81F4E #define MARKER_20LE 0x20876FF0E154 @@ -142,17 +143,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 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)) { @@ -163,8 +167,9 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) data_size = avio_rl24(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; + offset = FFMIN(offset, size - (avio_tell(pb) - orig_pos)); if ((ret = av_get_packet(pb, pkt, offset)) != offset) return ret < 0 ? ret : AVERROR_EOF; @@ -174,6 +179,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 */