Mercurial > libavformat.hg
changeset 2728:e00622d9d3c9 libavformat
Improve Sofdec file detection
author | mru |
---|---|
date | Thu, 08 Nov 2007 21:27:37 +0000 |
parents | a21454bf80b8 |
children | e808770ba0c6 |
files | mpeg.c |
diffstat | 1 files changed, 26 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mpeg.c Thu Nov 08 20:53:06 2007 +0000 +++ b/mpeg.c Thu Nov 08 21:27:37 2007 +0000 @@ -114,17 +114,18 @@ AVFormatParameters *ap) { MpegDemuxContext *m = s->priv_data; - uint8_t buffer[8192]; - char *p; + const char *sofdec = "Sofdec"; + int v, i = 0; m->header_state = 0xff; s->ctx_flags |= AVFMTCTX_NOHEADER; - get_buffer(&s->pb, buffer, sizeof(buffer)); - if ((p=memchr(buffer, 'S', sizeof(buffer)-5))) - if (!memcmp(p, "Sofdec", 6)) - m->sofdec = 1; - url_fseek(&s->pb, -(offset_t)sizeof(buffer), SEEK_CUR); + m->sofdec = -1; + do { + v = get_byte(&s->pb); + m->header_state = m->header_state << 8 | v; + m->sofdec++; + } while (v == sofdec[i] && i++ < 6); /* no need to do more */ return 0; @@ -269,10 +270,24 @@ goto redo; if (startcode == SYSTEM_HEADER_START_CODE) goto redo; - if (startcode == PADDING_STREAM || - startcode == PRIVATE_STREAM_2) { - /* skip them */ + if (startcode == PADDING_STREAM) { + url_fskip(&s->pb, get_be16(&s->pb)); + goto redo; + } + if (startcode == PRIVATE_STREAM_2) { len = get_be16(&s->pb); + if (!m->sofdec) { + while (len-- >= 6) { + if (get_byte(&s->pb) == 'S') { + uint8_t buf[5]; + get_buffer(&s->pb, buf, sizeof(buf)); + m->sofdec = !memcmp(buf, "ofdec", 5); + len -= sizeof(buf); + break; + } + } + m->sofdec -= !m->sofdec; + } url_fskip(&s->pb, len); goto redo; } @@ -459,7 +474,7 @@ type = CODEC_TYPE_VIDEO; } else if (startcode >= 0x1c0 && startcode <= 0x1df) { type = CODEC_TYPE_AUDIO; - codec_id = m->sofdec ? CODEC_ID_ADPCM_ADX : CODEC_ID_MP2; + codec_id = m->sofdec > 0 ? CODEC_ID_ADPCM_ADX : CODEC_ID_MP2; } else if (startcode >= 0x80 && startcode <= 0x87) { type = CODEC_TYPE_AUDIO; codec_id = CODEC_ID_AC3;