From patchwork Mon Feb 13 18:09:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 40383 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp3676960pzk; Mon, 13 Feb 2023 10:10:25 -0800 (PST) X-Google-Smtp-Source: AK7set9U+b2EF/9ibfV8MvI+WVXSyxA2CYdGRBi/Lfmel3n3VU1cWfaERuQw2xvUKoeIeu0ZBliC X-Received: by 2002:a17:907:8d17:b0:8af:346a:c186 with SMTP id tc23-20020a1709078d1700b008af346ac186mr18385637ejc.24.1676311824975; Mon, 13 Feb 2023 10:10:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676311824; cv=none; d=google.com; s=arc-20160816; b=Rg8+ThCFUqfzolCIoU+h1YGLtKFgL/CueCqOJIeYyYYqsSGJBmb+PQCqOwNLhQtvVR pKGMvndhg2eQXmal2IHjd0x3AmltzzT2taf3fp/rIdUYychkkSjo/EvJfe80MXxUANdC 6jd9thadjDPGzMbGFBR1K9lGW5QJ7K/HUcyA3jcnJnXiXjo5gsObXAwwxs9ZWRZqgh9i uUYWS+JgpfssnEPw5MEYaGRweAtPNFOjFSAXCKwtt4VTbdh74gWP9Qhk4y0kfv1iYEWT +VnmdbIkzsET0jcXnwU8UHCDATIXJs3scNwDXwMfvlZus4RXE19NGt6HQMTI3+YcxaRG L2EQ== 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=BlDFBsqecRX+Np7wnb0taiTsds54ywEMlZ312R+23Ek=; b=LExnoKK4eURIM18Nakv2YqnH/4EWOnznyDtA88kc3t/Rem2z9skzFXd0FPjS29BELl GSUXdQiIXSF/AVRmhH4KAPOyDxa1/Zku1F4kvfLKtX25V9raHnFxgBILPXh9x+SWIMR+ 0mQfyRsvgp5ijd+q70RlFcgLSbg7cvcHMG669Yc/Lr/AR4Xd7dvKRG5/Hv3O2idI6D1/ 92Bz0e7JLi2cGnEBWfmqpqt+2+XpSd9GAIsRnUbYVFZv1SqcE2u7bzZhAilFtr50kuMN 0u8cLiuqrT9On26cNd1+lpVEuZtJqSpNleJr1gWannUYBgtmNhwrag1Sv1UOr3yeWAyV GeoA== 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 vz7-20020a17090704c700b00888f1f1e13asi10868501ejb.346.2023.02.13.10.10.24; Mon, 13 Feb 2023 10:10:24 -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 3A55268BE77; Mon, 13 Feb 2023 20:09:54 +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 0B8DC68BD2E for ; Mon, 13 Feb 2023 20:09:45 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-2.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 8FBAC42D59; Mon, 13 Feb 2023 18:09:44 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Feb 2023 19:09:33 +0100 Message-Id: <20230213180936.815-4-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 3/6] avformat/s337m: New ff_s337m_probe() 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: A0I1pJ7PAVfo Similar to ff_spdif_probe() with just an additional checking of the bit resolution of the container as it may be 16 or 24 for s337m. --- libavformat/s337m.c | 32 ++++++++++++++++++++++++++++++++ libavformat/s337m.h | 16 ++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/libavformat/s337m.c b/libavformat/s337m.c index 2a566e3cba..9d2ac265b6 100644 --- a/libavformat/s337m.c +++ b/libavformat/s337m.c @@ -135,6 +135,38 @@ static int s337m_probe(const AVProbeData *p) return 0; } +int ff_s337m_probe(const uint8_t *buf, int size, enum AVCodecID *codec, int container_word_bits) +{ + int pos = 0; + int consecutive_codes = 0; + + if ( size < S337M_MIN_OFFSET) + return 0; + size = FFMIN(3 * S337M_MAX_OFFSET, size); + if (container_word_bits != 16 && container_word_bits != 24) + return AVERROR_INVALIDDATA; + + do { + uint64_t state; + int data_type, data_size, offset; + while (pos < size - 12 && !buf[pos]) { + pos++; + } + if (pos >= size - 12 || pos < S337M_PROBE_GUARDBAND_MIN_BYTES || pos % (container_word_bits == 16 ? 4 : 6)) + return 0; + state = container_word_bits == 16 ? AV_RB32(buf + pos) : AV_RB48(buf + pos); + if (!IS_LE_MARKER(state)) + return 0; + data_type = container_word_bits == 16 ? AV_RL16(buf + pos + 4) : AV_RL24(buf + pos + 6); + data_size = container_word_bits == 16 ? AV_RL16(buf + pos + 6) : AV_RL24(buf + pos + 9); + if (s337m_get_offset_and_codec(NULL, state, data_type, data_size, container_word_bits, &offset, codec)) + return 0; + pos = ++consecutive_codes * (offset + 4*(container_word_bits == 16 ? 4 : 6)); + } while (consecutive_codes < 3); + + return AVPROBE_SCORE_MAX; +} + static int s337m_read_header(AVFormatContext *s) { s->ctx_flags |= AVFMTCTX_NOHEADER; diff --git a/libavformat/s337m.h b/libavformat/s337m.h index af2c4c85a3..94e79dce5d 100644 --- a/libavformat/s337m.h +++ b/libavformat/s337m.h @@ -21,6 +21,22 @@ #ifndef AVFORMAT_S337M_H #define AVFORMAT_S337M_H +#define S337M_MIN_OFFSET 1601*4 +#define S337M_MAX_OFFSET 2002*6 + +#define S337M_PROBE_GUARDBAND_MIN_BYTES 0 + +/** + * Detect s337m packets in a PCM_S16LE/S24LE stereo stream + * Requires 3 samples with enough (S337M_PROBE_GUARDBAND_MIN_BYTES) and clean (set to zero) guard band + * @param p_buf Buffer + * @param size Buffer size + * @param codec Returns AV_CODEC_ID_DOLBY_E upon successful probing + * @param container_word_bits 16 or 24 + * @return = AVPROBE_SCORE + */ +int ff_s337m_probe(const uint8_t *p_buf, int size, enum AVCodecID *codec, int container_word_bits); + /** * Read s337m packets in a PCM_S16LE/S24LE stereo stream * Returns the first inner packet found