- Slightly better error recovery

Original commit message from CVS:
- Slightly better error recovery
- correctly handle ISO11172 end code
This commit is contained in:
Wim Taymans 2003-03-28 17:33:20 +00:00
parent 51f231f90b
commit 38a1831a3b
2 changed files with 31 additions and 5 deletions

View file

@ -66,6 +66,7 @@ parse_packhead (GstMPEGPacketize * packetize)
got_bytes = gst_bytestream_peek_bytes (packetize->bs, &buf, length); got_bytes = gst_bytestream_peek_bytes (packetize->bs, &buf, length);
if (got_bytes < length) if (got_bytes < length)
return NULL; return NULL;
buf += 4; buf += 4;
GST_DEBUG (0, "code %02x", *buf); GST_DEBUG (0, "code %02x", *buf);
@ -91,6 +92,19 @@ parse_packhead (GstMPEGPacketize * packetize)
return GST_DATA (outbuf); return GST_DATA (outbuf);
} }
static GstData*
parse_end (GstMPEGPacketize *packetize)
{
guint32 got_bytes;
GstBuffer *outbuf;
got_bytes = gst_bytestream_read (packetize->bs, &outbuf, 4);
if (got_bytes < 4)
return NULL;
return GST_DATA (outbuf);
}
static inline GstData* static inline GstData*
parse_generic (GstMPEGPacketize *packetize) parse_generic (GstMPEGPacketize *packetize)
{ {
@ -105,6 +119,7 @@ parse_generic (GstMPEGPacketize *packetize)
got_bytes = gst_bytestream_peek_bytes (bs, (guint8**)&buf, length); got_bytes = gst_bytestream_peek_bytes (bs, (guint8**)&buf, length);
if (got_bytes < 6) if (got_bytes < 6)
return NULL; return NULL;
buf += 4; buf += 4;
length += GUINT16_FROM_BE (*(guint16 *) buf); length += GUINT16_FROM_BE (*(guint16 *) buf);
@ -129,7 +144,8 @@ parse_chunk (GstMPEGPacketize *packetize)
chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096); chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096);
if (chunksize == 0) if (chunksize == 0)
return FALSE; return NULL;
offset = 4; offset = 4;
code = GUINT32_FROM_BE (*((guint32 *)(buf+offset))); code = GUINT32_FROM_BE (*((guint32 *)(buf+offset)));
@ -168,18 +184,19 @@ find_start_code (GstMPEGPacketize *packetize)
gint chunksize; gint chunksize;
chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096); chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096);
if (chunksize == 0) if (chunksize < 5)
return FALSE; return FALSE;
offset = 4; offset = 4;
code = GUINT32_FROM_BE (*((guint32 *)(buf))); code = GUINT32_FROM_BE (*((guint32 *)(buf)));
GST_DEBUG (0, "code = %08x", code); GST_DEBUG (0, "code = %08x %p %08x", code, buf, chunksize);
while ((code & 0xffffff00) != 0x100L) { while ((code & 0xffffff00) != 0x100L) {
code = (code << 8) | buf[offset++]; code = (code << 8) | buf[offset++];
GST_DEBUG (0, " code = %08x", code); GST_DEBUG (0, " code = %08x %p %08x", code, buf, chunksize);
if (offset == chunksize) { if (offset == chunksize) {
gst_bytestream_flush_fast (bs, offset); gst_bytestream_flush_fast (bs, offset);
@ -204,6 +221,8 @@ gst_mpeg_packetize_read (GstMPEGPacketize *packetize)
gboolean got_event = FALSE; gboolean got_event = FALSE;
GstData *outbuf = NULL; GstData *outbuf = NULL;
g_return_val_if_fail (packetize != NULL, NULL);
while (outbuf == NULL) { while (outbuf == NULL) {
if (!find_start_code (packetize)) if (!find_start_code (packetize))
got_event = TRUE; got_event = TRUE;
@ -229,6 +248,11 @@ gst_mpeg_packetize_read (GstMPEGPacketize *packetize)
if (!outbuf) if (!outbuf)
got_event = TRUE; got_event = TRUE;
break; break;
case ISO11172_END_START_CODE:
outbuf = parse_end (packetize);
if (!outbuf)
got_event = TRUE;
break;
default: default:
if (packetize->MPEG2 && ((packetize->id < 0xBD) || (packetize->id > 0xFE))) { if (packetize->MPEG2 && ((packetize->id < 0xBD) || (packetize->id > 0xFE))) {
g_warning ("packetize: ******** unknown id 0x%02X",packetize->id); g_warning ("packetize: ******** unknown id 0x%02X",packetize->id);

View file

@ -424,6 +424,8 @@ gst_mpeg_parse_loop (GstElement *element)
GST_DEBUG (0, "have chunk 0x%02X", id); GST_DEBUG (0, "have chunk 0x%02X", id);
switch (id) { switch (id) {
case 0xb9:
break;
case 0xba: case 0xba:
if (CLASS (mpeg_parse)->parse_packhead) { if (CLASS (mpeg_parse)->parse_packhead) {
CLASS (mpeg_parse)->parse_packhead (mpeg_parse, buffer); CLASS (mpeg_parse)->parse_packhead (mpeg_parse, buffer);