summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorIsaac Richards <ijr@po.cwru.edu>2003-07-10 09:04:04 +0000
committerMichael Niedermayer <michaelni@gmx.at>2003-07-10 09:04:04 +0000
commitec23a47286a9be0ca67b78f4d8b9d87220c18286 (patch)
tree0cc1d63b3c2569916c81fcd2aab95f03a98f0e00 /libavformat
parent3d32b429d3dfbb5f39528a598fe13e88b0543e85 (diff)
- Looks a tiny bit harder in mpegps_probe() for a valid start code. This is
needed to detect some files produced by pvr-250/350 capture cards. - Adds AC3 audio support to the mpegts demuxer, and makes it a little more tolerant of bad files. patch by (Isaac Richards <ijr at po dot cwru dot edu>) Originally committed as revision 2028 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/mpeg.c34
-rw-r--r--libavformat/mpegts.c33
-rw-r--r--libavformat/mpegts.h2
3 files changed, 50 insertions, 19 deletions
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index f9000a74d8..ad87178aa5 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -405,9 +405,10 @@ static int mpeg_mux_end(AVFormatContext *ctx)
static int mpegps_probe(AVProbeData *p)
{
- int code;
+ int code, c, i;
const uint8_t *d;
+ code = 0xff;
/* we search the first start code. If it is a packet start code,
then we decide it is mpeg ps. We do not send highest value to
give a chance to mpegts */
@@ -416,20 +417,23 @@ static int mpegps_probe(AVProbeData *p)
if (p->buf_size < 6)
return 0;
- d = p->buf;
- code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]);
- if ((code & 0xffffff00) == 0x100) {
- if (code == PACK_START_CODE ||
- code == SYSTEM_HEADER_START_CODE ||
- (code >= 0x1e0 && code <= 0x1ef) ||
- (code >= 0x1c0 && code <= 0x1df) ||
- code == PRIVATE_STREAM_2 ||
- code == PROGRAM_STREAM_MAP ||
- code == PRIVATE_STREAM_1 ||
- code == PADDING_STREAM)
- return AVPROBE_SCORE_MAX - 1;
- else
- return 0;
+
+ for (i = 0; i < 20; i++) {
+ c = p->buf[i];
+ code = (code << 8) | c;
+ if ((code & 0xffffff00) == 0x100) {
+ if (code == PACK_START_CODE ||
+ code == SYSTEM_HEADER_START_CODE ||
+ (code >= 0x1e0 && code <= 0x1ef) ||
+ (code >= 0x1c0 && code <= 0x1df) ||
+ code == PRIVATE_STREAM_2 ||
+ code == PROGRAM_STREAM_MAP ||
+ code == PRIVATE_STREAM_1 ||
+ code == PADDING_STREAM)
+ return AVPROBE_SCORE_MAX - 1;
+ else
+ return 0;
+ }
}
return 0;
}
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index ab621dbb81..96b2d39645 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -387,6 +387,7 @@ static void pmt_cb(void *opaque, const uint8_t *section, int section_len)
case STREAM_TYPE_AUDIO_MPEG2:
case STREAM_TYPE_VIDEO_MPEG1:
case STREAM_TYPE_VIDEO_MPEG2:
+ case STREAM_TYPE_AUDIO_AC3:
add_pes_stream(ts->stream, pid);
break;
default:
@@ -613,16 +614,19 @@ static void mpegts_push_data(void *opaque,
if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
pes->header[2] == 0x01) {
/* it must be an mpeg2 PES stream */
- /* XXX: add AC3 support */
code = pes->header[3] | 0x100;
if (!((code >= 0x1c0 && code <= 0x1df) ||
- (code >= 0x1e0 && code <= 0x1ef)))
+ (code >= 0x1e0 && code <= 0x1ef) ||
+ (code == 0x1bd)))
goto skip;
if (!pes->st) {
/* allocate stream */
if (code >= 0x1c0 && code <= 0x1df) {
codec_type = CODEC_TYPE_AUDIO;
codec_id = CODEC_ID_MP2;
+ } else if (code == 0x1bd) {
+ codec_type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_AC3;
} else {
codec_type = CODEC_TYPE_VIDEO;
codec_id = CODEC_ID_MPEG1VIDEO;
@@ -805,6 +809,8 @@ static int handle_packets(AVFormatContext *s, int nb_packets)
ByteIOContext *pb = &s->pb;
uint8_t packet[TS_FEC_PACKET_SIZE];
int packet_num, len;
+ int i, found = 0;
+ int64_t pos;
ts->stop_parse = 0;
packet_num = 0;
@@ -814,13 +820,32 @@ static int handle_packets(AVFormatContext *s, int nb_packets)
packet_num++;
if (nb_packets != 0 && packet_num >= nb_packets)
break;
+ pos = url_ftell(pb);
len = get_buffer(pb, packet, ts->raw_packet_size);
if (len != ts->raw_packet_size)
return AVERROR_IO;
/* check paquet sync byte */
- /* XXX: accept to resync ? */
if (packet[0] != 0x47)
- return AVERROR_INVALIDDATA;
+ {
+ //printf("bad packet: 0x%x\n", packet[0]);
+ found = 0;
+ for (i = 0; i < ts->raw_packet_size; i++)
+ {
+ if (packet[i] == 0x47)
+ {
+ found = 1;
+ //printf("packet start at: %d\n", i);
+ break;
+ }
+ }
+
+ if (found)
+ {
+ url_fseek(pb, pos + i, SEEK_SET);
+ continue;
+ }
+ return AVERROR_INVALIDDATA;
+ }
handle_packet(s, packet);
}
return 0;
diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index 8296ccfb98..6e56a8e44c 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -38,5 +38,7 @@
#define STREAM_TYPE_PRIVATE_SECTION 0x05
#define STREAM_TYPE_PRIVATE_DATA 0x06
+#define STREAM_TYPE_AUDIO_AC3 0x81
+
unsigned int mpegts_crc32(const uint8_t *data, int len);
extern AVOutputFormat mpegts_mux;