From: Nicolas Gaullier <nicolas.gaullier@cji.paris>
To: ffmpeg-devel@ffmpeg.org
Cc: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Subject: [FFmpeg-devel] [PATCH 3/6] avformat/s337m: New ff_s337m_probe()
Date: Mon, 13 Feb 2023 19:09:33 +0100
Message-ID: <20230213180936.815-4-nicolas.gaullier@cji.paris> (raw)
In-Reply-To: <20230213180936.815-1-nicolas.gaullier@cji.paris>
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
--
2.30.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-02-13 18:10 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 18:09 [FFmpeg-devel] [PATCH 0/6] wavdev: s337m support Nicolas Gaullier
2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 1/6] avformat/s337m: Split read_packet/get_packet Nicolas Gaullier
2023-02-16 10:36 ` Tomas Härdin
2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 2/6] avformat/s337m: Consider container bit resolution Nicolas Gaullier
2023-02-16 10:36 ` Tomas Härdin
2023-02-17 9:44 ` Nicolas Gaullier
2023-02-21 9:47 ` Tomas Härdin
2023-02-21 10:43 ` Nicolas Gaullier
2023-02-22 10:07 ` Tomas Härdin
2023-02-13 18:09 ` Nicolas Gaullier [this message]
2023-02-16 10:36 ` [FFmpeg-devel] [PATCH 3/6] avformat/s337m: New ff_s337m_probe() Tomas Härdin
2023-02-17 10:12 ` Nicolas Gaullier
2023-02-21 9:41 ` Tomas Härdin
2023-02-21 10:57 ` Nicolas Gaullier
2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 4/6] avformat/wavdec: s337m support Nicolas Gaullier
2023-02-16 10:36 ` Tomas Härdin
2023-02-17 10:30 ` Nicolas Gaullier
2023-02-21 9:53 ` Tomas Härdin
2023-02-21 12:30 ` Nicolas Gaullier
2023-02-22 10:10 ` Tomas Härdin
2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 5/6] avformat/wavdec.c: Reindent after last commit Nicolas Gaullier
2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 6/6] avformat/wavdec: Test s337m Nicolas Gaullier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230213180936.815-4-nicolas.gaullier@cji.paris \
--to=nicolas.gaullier@cji.paris \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git