Commit e887d685 authored by Clément Bœsch's avatar Clément Bœsch

Merge commit 'ed1cd810'

* commit 'ed1cd810':
  flac demuxer: improve probing

Suggested commit very closely matches our code, except with regards to
AVPROBE_SCORE_EXTENSION. The code layout is mostly merged but preserves
our behaviour.
Merged-by: 's avatarClément Bœsch <u@pkh.me>
parents dd0abace ed1cd810
...@@ -231,16 +231,27 @@ static int flac_probe(AVProbeData *p) ...@@ -231,16 +231,27 @@ static int flac_probe(AVProbeData *p)
{ {
if ((AV_RB16(p->buf) & 0xFFFE) == 0xFFF8) if ((AV_RB16(p->buf) & 0xFFFE) == 0xFFF8)
return raw_flac_probe(p); return raw_flac_probe(p);
if (p->buf_size < 4 || memcmp(p->buf, "fLaC", 4))
return 0; /* file header + metadata header + checked bytes of streaminfo */
if ( p->buf[4] & 0x7f != FLAC_METADATA_TYPE_STREAMINFO if (p->buf_size >= 4 + 4 + 13) {
|| AV_RB24(p->buf + 5) != FLAC_STREAMINFO_SIZE int type = p->buf[4] & 0x7f;
|| AV_RB16(p->buf + 8) < 16 int size = AV_RB24(p->buf + 5);
|| AV_RB16(p->buf + 8) > AV_RB16(p->buf + 10) int min_block_size = AV_RB16(p->buf + 8);
|| !(AV_RB24(p->buf + 18) >> 4) int max_block_size = AV_RB16(p->buf + 10);
|| AV_RB24(p->buf + 18) >> 4 > 655350) int sample_rate = AV_RB24(p->buf + 18) >> 4;
if (memcmp(p->buf, "fLaC", 4))
return 0;
if (type == FLAC_METADATA_TYPE_STREAMINFO &&
size == FLAC_STREAMINFO_SIZE &&
min_block_size >= 16 &&
max_block_size >= min_block_size &&
sample_rate && sample_rate <= 655350)
return AVPROBE_SCORE_MAX;
return AVPROBE_SCORE_EXTENSION; return AVPROBE_SCORE_EXTENSION;
return AVPROBE_SCORE_MAX; }
return 0;
} }
static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index, static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment