1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Improve Sofdec file detection

Originally committed as revision 10967 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Måns Rullgård 2007-11-08 21:27:37 +00:00
parent 73039e0fb4
commit 2c18784703

View File

@ -114,17 +114,18 @@ static int mpegps_read_header(AVFormatContext *s,
AVFormatParameters *ap) AVFormatParameters *ap)
{ {
MpegDemuxContext *m = s->priv_data; MpegDemuxContext *m = s->priv_data;
uint8_t buffer[8192]; const char *sofdec = "Sofdec";
char *p; int v, i = 0;
m->header_state = 0xff; m->header_state = 0xff;
s->ctx_flags |= AVFMTCTX_NOHEADER; s->ctx_flags |= AVFMTCTX_NOHEADER;
get_buffer(&s->pb, buffer, sizeof(buffer)); m->sofdec = -1;
if ((p=memchr(buffer, 'S', sizeof(buffer)-5))) do {
if (!memcmp(p, "Sofdec", 6)) v = get_byte(&s->pb);
m->sofdec = 1; m->header_state = m->header_state << 8 | v;
url_fseek(&s->pb, -(offset_t)sizeof(buffer), SEEK_CUR); m->sofdec++;
} while (v == sofdec[i] && i++ < 6);
/* no need to do more */ /* no need to do more */
return 0; return 0;
@ -269,10 +270,24 @@ static int mpegps_read_pes_header(AVFormatContext *s,
goto redo; goto redo;
if (startcode == SYSTEM_HEADER_START_CODE) if (startcode == SYSTEM_HEADER_START_CODE)
goto redo; goto redo;
if (startcode == PADDING_STREAM || if (startcode == PADDING_STREAM) {
startcode == PRIVATE_STREAM_2) { url_fskip(&s->pb, get_be16(&s->pb));
/* skip them */ goto redo;
}
if (startcode == PRIVATE_STREAM_2) {
len = get_be16(&s->pb); 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); url_fskip(&s->pb, len);
goto redo; goto redo;
} }
@ -459,7 +474,7 @@ static int mpegps_read_packet(AVFormatContext *s,
type = CODEC_TYPE_VIDEO; type = CODEC_TYPE_VIDEO;
} else if (startcode >= 0x1c0 && startcode <= 0x1df) { } else if (startcode >= 0x1c0 && startcode <= 0x1df) {
type = CODEC_TYPE_AUDIO; 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) { } else if (startcode >= 0x80 && startcode <= 0x87) {
type = CODEC_TYPE_AUDIO; type = CODEC_TYPE_AUDIO;
codec_id = CODEC_ID_AC3; codec_id = CODEC_ID_AC3;