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