aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMåns Rullgård <mans@mansr.com>2007-11-08 21:27:37 +0000
committerMåns Rullgård <mans@mansr.com>2007-11-08 21:27:37 +0000
commit2c18784703760803558706d3df8d5ff4789194f4 (patch)
treeac04c4a88fb8f0d68b02e57f8b4ba8743f5dfaba
parent73039e0fb4e5fbd13602c866ec98e097a777f1f5 (diff)
downloadffmpeg-2c18784703760803558706d3df8d5ff4789194f4.tar.gz
Improve Sofdec file detection
Originally committed as revision 10967 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/mpeg.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 076cc8fea1..4bfd80369e 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -114,17 +114,18 @@ static int mpegps_read_header(AVFormatContext *s,
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 @@ static int mpegps_read_pes_header(AVFormatContext *s,
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 @@ static int mpegps_read_packet(AVFormatContext *s,
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;