- Small cleanups

Original commit message from CVS:
- Small cleanups
- parse even the last few bytes of the stream
This commit is contained in:
Wim Taymans 2003-01-19 13:42:43 +00:00
parent dd96efe6f1
commit 3438f4f459
3 changed files with 42 additions and 34 deletions

View file

@ -64,7 +64,8 @@ parse_packhead (GstMPEGPacketize * packetize)
GST_DEBUG (0, "packetize: in parse_packhead"); GST_DEBUG (0, "packetize: in parse_packhead");
got_bytes = gst_bytestream_peek_bytes (packetize->bs, &buf, length); got_bytes = gst_bytestream_peek_bytes (packetize->bs, &buf, length);
if (got_bytes < length) return NULL; if (got_bytes < length)
return NULL;
buf += 4; buf += 4;
GST_DEBUG (0, "code %02x", *buf); GST_DEBUG (0, "code %02x", *buf);
@ -75,7 +76,8 @@ parse_packhead (GstMPEGPacketize * packetize)
packetize->MPEG2 = TRUE; packetize->MPEG2 = TRUE;
length += 2; length += 2;
got_bytes = gst_bytestream_peek_bytes (packetize->bs, &buf, length); got_bytes = gst_bytestream_peek_bytes (packetize->bs, &buf, length);
if (got_bytes < length) return NULL; if (got_bytes < length)
return NULL;
} }
else { else {
GST_DEBUG (0, "packetize::parse_packhead setting mpeg1"); GST_DEBUG (0, "packetize::parse_packhead setting mpeg1");
@ -83,7 +85,8 @@ parse_packhead (GstMPEGPacketize * packetize)
} }
got_bytes = gst_bytestream_read (packetize->bs, &outbuf, length); got_bytes = gst_bytestream_read (packetize->bs, &outbuf, length);
if (got_bytes < length) return NULL; if (got_bytes < length)
return NULL;
return GST_DATA (outbuf); return GST_DATA (outbuf);
} }
@ -91,23 +94,25 @@ parse_packhead (GstMPEGPacketize * packetize)
static inline GstData* static inline GstData*
parse_generic (GstMPEGPacketize *packetize) parse_generic (GstMPEGPacketize *packetize)
{ {
guint16 length;
GstByteStream *bs = packetize->bs; GstByteStream *bs = packetize->bs;
guchar *buf; guchar *buf;
GstBuffer *outbuf; GstBuffer *outbuf;
guint32 got_bytes; guint32 got_bytes;
gint16 length = 6;
GST_DEBUG (0, "packetize: in parse_generic"); GST_DEBUG (0, "packetize: in parse_generic");
got_bytes = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 2 + 4); got_bytes = gst_bytestream_peek_bytes (bs, (guint8**)&buf, length);
if (got_bytes < 6) return NULL; if (got_bytes < 6)
return NULL;
buf += 4; buf += 4;
length = GUINT16_FROM_BE (*(guint16 *) buf); length += GUINT16_FROM_BE (*(guint16 *) buf);
GST_DEBUG (0, "packetize: header_length %d", length); GST_DEBUG (0, "packetize: header_length %d", length);
got_bytes = gst_bytestream_read (packetize->bs, &outbuf, 2 + length + 4); got_bytes = gst_bytestream_read (packetize->bs, &outbuf, length);
if (got_bytes < 2 + length + 4) return NULL; if (got_bytes < length)
return NULL;
return GST_DATA (outbuf); return GST_DATA (outbuf);
} }
@ -119,12 +124,11 @@ parse_chunk (GstMPEGPacketize *packetize)
guchar *buf; guchar *buf;
gint offset; gint offset;
guint32 code; guint32 code;
const gint chunksize = 4096; gint chunksize;
GstBuffer *outbuf = NULL; GstBuffer *outbuf = NULL;
guint32 got_bytes;
got_bytes = gst_bytestream_peek_bytes (bs, (guint8**)&buf, chunksize); chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096);
if (got_bytes < chunksize) if (chunksize == 0)
return FALSE; return FALSE;
offset = 4; offset = 4;
@ -137,14 +141,17 @@ parse_chunk (GstMPEGPacketize *packetize)
GST_DEBUG (0, " code = %08x", code); GST_DEBUG (0, " code = %08x", code);
if ((offset % chunksize) == 0) { if (offset == chunksize) {
got_bytes = gst_bytestream_peek_bytes (bs, (guint8**)&buf, offset + chunksize); chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, offset + 4096);
if (got_bytes < offset + chunksize) if (chunksize == 0)
return NULL; return NULL;
chunksize += offset;
} }
} }
if (offset > 4) { if (offset > 4) {
got_bytes = gst_bytestream_read (bs, &outbuf, offset-4); chunksize = gst_bytestream_read (bs, &outbuf, offset-4);
if (chunksize == 0)
return NULL;
} }
return GST_DATA (outbuf); return GST_DATA (outbuf);
} }
@ -158,11 +165,10 @@ find_start_code (GstMPEGPacketize *packetize)
guchar *buf; guchar *buf;
gint offset; gint offset;
guint32 code; guint32 code;
const gint chunksize = 4096; gint chunksize;
guint32 got_bytes;
got_bytes = gst_bytestream_peek_bytes (bs, (guint8**)&buf, chunksize); chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096);
if (got_bytes < chunksize) if (chunksize == 0)
return FALSE; return FALSE;
offset = 4; offset = 4;
@ -176,18 +182,18 @@ find_start_code (GstMPEGPacketize *packetize)
GST_DEBUG (0, " code = %08x", code); GST_DEBUG (0, " code = %08x", code);
if (offset == chunksize) { if (offset == chunksize) {
if (!gst_bytestream_flush (bs, offset)) gst_bytestream_flush_fast (bs, offset);
return FALSE;
got_bytes = gst_bytestream_peek_bytes (bs, (guint8**)&buf, chunksize); chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096);
if (got_bytes < chunksize) if (chunksize == 0)
return FALSE; return FALSE;
offset = 0; offset = 0;
} }
} }
packetize->id = code & 0xff; packetize->id = code & 0xff;
if (offset > 4) { if (offset > 4) {
if (!gst_bytestream_flush (bs, offset - 4)) gst_bytestream_flush_fast (bs, offset - 4);
return FALSE;
} }
return TRUE; return TRUE;
} }
@ -206,8 +212,7 @@ gst_mpeg_packetize_read (GstMPEGPacketize *packetize)
if (packetize->type == GST_MPEG_PACKETIZE_SYSTEM) { if (packetize->type == GST_MPEG_PACKETIZE_SYSTEM) {
if (packetize->resync) { if (packetize->resync) {
if (packetize->id != PACK_START_CODE) { if (packetize->id != PACK_START_CODE) {
if (!gst_bytestream_flush (packetize->bs, 4)) gst_bytestream_flush_fast (packetize->bs, 4);
got_event = TRUE;
continue; continue;
} }

View file

@ -540,13 +540,13 @@ gst_mpeg_parse_loop (GstElement *element)
/* /*
* The mpeg spec says something like this, but that doesn't really work: * The mpeg spec says something like this, but that doesn't really work:
* *
* mpeg_parse->next_scr = (scr * br + bss * 90000LL) / (90000LL + br); * mpeg_parse->next_scr = (scr * br + bss * CLOCK_FREQ) / (CLOCK_FREQ + br);
*/ */
mpeg_parse->next_scr = scr + (bss * 90000LL) / br; mpeg_parse->next_scr = scr + (bss * CLOCK_FREQ) / br;
} }
else { else {
/* we are interpolating the scr here */ /* we are interpolating the scr here */
mpeg_parse->next_scr = scr + (bss * 90000LL) / br; mpeg_parse->next_scr = scr + (bss * CLOCK_FREQ) / br;
} }
} }
else { else {

View file

@ -43,8 +43,11 @@ extern "C" {
#define GST_MPEG_PARSE_IS_MPEG2(parse) (GST_MPEG_PACKETIZE_IS_MPEG2 (GST_MPEG_PARSE (parse)->packetize)) #define GST_MPEG_PARSE_IS_MPEG2(parse) (GST_MPEG_PACKETIZE_IS_MPEG2 (GST_MPEG_PARSE (parse)->packetize))
#define MPEGTIME_TO_GSTTIME(time) (((time) * (GST_MSECOND/10)) / 9LL) #define CLOCK_BASE 9LL
#define GSTTIME_TO_MPEGTIME(time) (((time) * 9) / (GST_MSECOND/10)) #define CLOCK_FREQ CLOCK_BASE * 10000
#define MPEGTIME_TO_GSTTIME(time) (((time) * (GST_MSECOND/10)) / CLOCK_BASE)
#define GSTTIME_TO_MPEGTIME(time) (((time) * CLOCK_BASE) / (GST_MSECOND/10))
typedef struct _GstMPEGParse GstMPEGParse; typedef struct _GstMPEGParse GstMPEGParse;
typedef struct _GstMPEGParseClass GstMPEGParseClass; typedef struct _GstMPEGParseClass GstMPEGParseClass;