From patchwork Fri Jan 3 15:56:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 17176 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 6830944A938 for ; Fri, 3 Jan 2020 17:56:50 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 535DC68ACEF; Fri, 3 Jan 2020 17:56:50 +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 65FCC68A50F for ; Fri, 3 Jan 2020 17:56:40 +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 47q8fJ0PZBzHh9F; Fri, 3 Jan 2020 15:56:40 +0000 (UTC) Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 0642E3FA6D; Fri, 3 Jan 2020 16:56:41 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Jan 2020 16:56:31 +0100 Message-Id: <20200103155636.7476-5-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200103155636.7476-1-nicolas.gaullier@cji.paris> References: <20200103155636.7476-1-nicolas.gaullier@cji.paris> Subject: [FFmpeg-devel] [PATCH 4/9] avformat/s337m: New ff_s337m_probe() 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" Similar to ff_spdif_probe() with two additionnal parameters: - an AVClass for logging - the bit resolution of the container as it may be 16 or 24 for s337m --- libavformat/s337m.c | 35 +++++++++++++++++++++++++++++++++++ libavformat/s337m.h | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/libavformat/s337m.c b/libavformat/s337m.c index 5c8ab2649c..dc62d6ab98 100644 --- a/libavformat/s337m.c +++ b/libavformat/s337m.c @@ -133,6 +133,41 @@ static int s337m_probe(const AVProbeData *p) return 0; } +int ff_s337m_probe(const uint8_t *buf, int size, enum AVCodecID *codec, void *avc, int container_word_bits) +{ + int pos = 0; + int consecutive_codes = 0; + + if ( size < S337M_MIN_OFFSET) + return 0; + size = FFMIN(2 * S337M_MAX_OFFSET, size); + + 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) + 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(avc, state, data_type, data_size, container_word_bits, &offset, codec)) + return 0; + if (avc) { + double s337m_phase = pos * 4. / container_word_bits / 48000; + av_log(avc, AV_LOG_INFO, "s337m sample %d detected with phase = %.6fs\n", consecutive_codes, s337m_phase); + if (*codec == AV_CODEC_ID_DOLBY_E && (s337m_phase < DOLBY_E_PHASE_MIN || s337m_phase > DOLBY_E_PHASE_MAX)) + av_log(avc, AV_LOG_WARNING, "Dolby E phase is out of valid range (%.6fs-%.6fs)\n", DOLBY_E_PHASE_MIN, DOLBY_E_PHASE_MAX); + } + } while (++consecutive_codes < 2); + + 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 d78ee8c501..707f982c9f 100644 --- a/libavformat/s337m.h +++ b/libavformat/s337m.h @@ -21,6 +21,25 @@ #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 +#define DOLBY_E_PHASE_MIN 0.000610 +#define DOLBY_E_PHASE_MAX 0.001050 + +/** + * Detect s337m packets in a PCM_S16LE/S24LE stereo stream + * Requires two 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 avc For av_log + * @param container_word_bits 16 or 24 + * @return = AVPROBE_SCORE + */ +int ff_s337m_probe(const uint8_t *p_buf, int size, enum AVCodecID *codec, void *avc, int container_word_bits); + /** * Read s337m packets in a PCM_S16LE/S24LE stereo stream * Returns the first inner packet found