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 -- 2.14.1.windows.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".