[gst-cvs] CVS: gstreamer/plugins/mpeg2/parse mpeg2parse.c,1.32.4.4,1.32.4.5
Wim Taymans
wtay at users.sourceforge.net
Mon Sep 24 12:38:02 PDT 2001
Update of /cvsroot/gstreamer/gstreamer/plugins/mpeg2/parse
In directory usw-pr-cvs1:/tmp/cvs-serv4070
Modified Files:
Tag: BRANCH-EVENTS1
mpeg2parse.c
Log Message:
More mpeg1 timestamp parsing.
Added private_stream_1 parsing code.
Index: mpeg2parse.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/plugins/mpeg2/parse/mpeg2parse.c,v
retrieving revision 1.32.4.4
retrieving revision 1.32.4.5
diff -u -d -r1.32.4.4 -r1.32.4.5
--- mpeg2parse.c 2001/09/23 23:23:53 1.32.4.4
+++ mpeg2parse.c 2001/09/24 19:37:05 1.32.4.5
@@ -86,7 +86,7 @@
GST_PAD_SOMETIMES,
GST_CAPS_NEW (
"mpeg2parse_private1",
- "audio/ac3",
+ "audio/a52",
NULL
)
);
@@ -211,12 +211,12 @@
looks odd (marker bits not correct), it will return FALSE and not set
the values in the mpeg2parse structure. */
static inline gboolean
-parse_packhead (Mpeg2Parse *mpeg2parse)
+parse_packhead (Mpeg2Parse * mpeg2parse)
{
gint length = 8;
guint8 *buf;
- GST_DEBUG (0,"mpeg2parse: in parse_packhead\n");
+ GST_DEBUG (0, "mpeg2parse: in parse_packhead\n");
buf = gst_bytestream_peek_bytes (mpeg2parse->bs, length);
@@ -224,14 +224,14 @@
// start parsing the stream
if ((*buf & 0xf0) == 0x40) {
- GST_DEBUG (0,"mpeg2parse::parse_packhead setting mpeg2\n");
+ GST_DEBUG (0, "mpeg2parse::parse_packhead setting mpeg2\n");
mpeg2parse->MPEG2 = TRUE;
length += 2;
buf = gst_bytestream_peek_bytes (mpeg2parse->bs, length);
buf += 3;
}
else {
- GST_DEBUG (0,"mpeg2parse::parse_packhead setting mpeg1\n");
+ GST_DEBUG (0, "mpeg2parse::parse_packhead setting mpeg1\n");
mpeg2parse->MPEG2 = FALSE;
buf += 1;
}
@@ -239,14 +239,14 @@
// FIXME parse more stuff here...
buf += 4;
- mpeg2parse->bit_rate = GUINT32_FROM_BE ((*(guint32 *)buf)) & 0xffffff00;
- GST_DEBUG (0,"mpeg2parse: stream is %1.3fMbps\n",((float)(mpeg2parse->bit_rate*50))/1000000);
+ mpeg2parse->bit_rate = GUINT32_FROM_BE ((*(guint32 *) buf)) & 0xffffff00;
+ GST_DEBUG (0, "mpeg2parse: stream is %1.3fMbps\n",
+ ((float) (mpeg2parse->bit_rate * 50)) / 1000000);
gst_bytestream_flush (mpeg2parse->bs, length);
return TRUE;
}
-
static inline gboolean
parse_syshead (Mpeg2Parse * mpeg2parse)
{
@@ -318,6 +318,8 @@
// private_stream_1
if (stream_id == 0xBD) {
+ name = NULL;
+ outpad = NULL;
}
// private_stream_2
else if (stream_id == 0xBF) {
@@ -349,7 +351,7 @@
// create the pad and add it to self if it does not yet exist
// this should trigger the NEW_PAD signal, which should be caught by
// the app and used to attach to desired streams.
- if (*outpad == NULL) {
+ if (outpad && *outpad == NULL) {
(*outpad) = gst_pad_new_from_template (newtemp, name);
gst_pad_set_caps (*outpad, gst_pad_get_padtemplate_caps (*outpad));
gst_element_add_pad (GST_ELEMENT (mpeg2parse), (*outpad));
@@ -384,29 +386,28 @@
gboolean *need_flush = NULL;
guint16 packet_length;
- gboolean std_buffer_scale;
- guint16 std_buffer_size;
+ gboolean STD_buffer_bound_scale;
+ guint16 STD_buffer_size_bound;
guint64 dts;
+ guint8 ps_id_code;
guint16 datalen;
gulong outoffset = 0;
- guint8 ac3_track_code;
GstPad **outpad = NULL;
GstBuffer *outbuf;
- guchar *buf;
+ guint8 *buf, *basebuf;
GstByteStream *bs = mpeg2parse->bs;
GST_DEBUG (0,"mpeg2parse::parse_packet: in parse_packet\n");
-
buf = gst_bytestream_peek_bytes (bs, 2);
// start parsing
packet_length = GUINT16_FROM_BE (*((guint16 *)buf));
GST_DEBUG (0,"mpeg2parse: got packet_length %d\n",packet_length);
- buf = gst_bytestream_peek_bytes (bs, 2 + packet_length);
+ basebuf = buf = gst_bytestream_peek_bytes (bs, 2 + packet_length);
buf += 2;
headerlen = 2;
@@ -426,29 +427,41 @@
break;
case 0x40:
GST_DEBUG (0,"mpeg2parse::parse_packet: have STD\n");
- buf++;
- //std_buffer_scale = gst_getbits1(&mpeg2parse->gb);
- //std_buffer_size = gst_getbits13(&mpeg2parse->gb);
+
+ STD_buffer_bound_scale = bits & 0x20;
+ STD_buffer_size_bound = (bits & 0x1F) << 8;
+ STD_buffer_size_bound |= *buf++;
+
headerlen += 2;
break;
case 0x00:
switch (bits & 0x30) {
case 0x20:
- buf += 4;
- // timestamp:36
- //calc_time_stamp(&mpeg2parse->gb, mpeg2parse->last_pts);
+ // pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1
+ mpeg2parse->last_pts = (bits & 0x0E) << 29;
+ mpeg2parse->last_pts |= *buf++ << 22;
+ mpeg2parse->last_pts |= (*buf++ & 0xFE) << 14;
+ mpeg2parse->last_pts |= *buf++ << 7;
+ mpeg2parse->last_pts |= (*buf++ & 0xFE) >> 1;
+
GST_DEBUG (0,"mpeg2parse::parse_packet: PTS = %llu\n", mpeg2parse->last_pts);
headerlen += 5;
goto done;
case 0x30:
- // timestamp:36
- buf += 4;
- //calc_time_stamp(&mpeg2parse->gb, mpeg2parse->last_pts);
- // sync:4==1
- buf++;
- // timestamp:36
- buf += 4;
- //calc_time_stamp(&mpeg2parse->gb, dts);
+ // pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1
+ mpeg2parse->last_pts = (bits & 0x0E) << 29;
+ mpeg2parse->last_pts |= *buf++ << 22;
+ mpeg2parse->last_pts |= (*buf++ & 0xFE) << 14;
+ mpeg2parse->last_pts |= *buf++ << 7;
+ mpeg2parse->last_pts |= (*buf++ & 0xFE) >> 1;
+
+ // sync:4 ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1
+ dts = (*buf++ & 0x0E) << 29;
+ dts |= *buf++ << 22;
+ dts |= (*buf++ & 0xFE) << 14;
+ dts |= *buf++ << 7;
+ dts |= (*buf++ & 0xFE) >> 1;
+
GST_DEBUG (0,"mpeg2parse::parse_packet: PTS = %llu, DTS = %llu\n", mpeg2parse->last_pts, dts);
headerlen += 10;
goto done;
@@ -478,16 +491,16 @@
// private_stream_1
if (id == 0xBD) {
// first find the track code
- //ac3_track_code = *(guint8 *)(data+headerlen);
+ ps_id_code = *(basebuf + headerlen);
// make sure it's valid
- //if ((ac3_track_code >= 0x80) && (ac3_track_code <= 0x87)) {
- // GST_DEBUG (0,"mpeg2parse::parse_packet: 0x%02X: we have a private_stream_1 (AC3) packet, track %d\n",
- // id, ac3_track_code - 0x80);
- // outpad = &mpeg2parse->private_1_pad[ac3_track_code - 0x80];
+ if ((ps_id_code >= 0x80) && (ps_id_code <= 0x87)) {
+ GST_DEBUG (0,"mpeg2parse::parse_packet: 0x%02X: we have a private_stream_1 (AC3) packet, track %d\n",
+ id, ps_id_code - 0x80);
+ outpad = &mpeg2parse->private_1_pad[ps_id_code - 0x80];
// scrap first 4 bytes (so-called "mystery AC3 tag")
headerlen += 4;
datalen -= 4;
- //}
+ }
// private_stream_1
} else if (id == 0xBF) {
GST_DEBUG (0,"mpeg2parse::parse_packet: 0x%02X: we have a private_stream_2 packet\n", id);
@@ -522,10 +535,6 @@
goto error;
}
- //if (!GST_STATE_IS_SET(mpeg2parse, GST_STATE_COMPLETE)) {
- // gst_element_set_state(GST_ELEMENT(mpeg2parse), GST_STATE_COMPLETE);
- //}
-
// create the buffer and send it off to the Other Side
if (GST_PAD_CONNECTED(*outpad) && datalen > 0) {
// if this is part of the buffer, create a subbuffer
@@ -577,7 +586,7 @@
GstPad **outpad = NULL;
GstBuffer *outbuf;
GstPadTemplate *newtemp = NULL;
- guint8 *buf;
+ guint8 *buf, *basebuf;
GST_DEBUG (0,"mpeg2parse: in parse_pes\n");
@@ -587,7 +596,7 @@
packet_length = GUINT16_FROM_BE (*((guint16 *)buf));
GST_DEBUG (0,"mpeg2parse: got packet_length %d\n",packet_length);
- buf = gst_bytestream_peek_bytes (bs, 2 + packet_length);
+ basebuf = buf = gst_bytestream_peek_bytes (bs, 2 + packet_length);
buf += 2;
// we don't operate on: program_stream_map, padding_stream,
@@ -646,8 +655,7 @@
// private_stream_1
if (id == 0xBD) {
// first find the track code
- //ps_id_code = *(guint8 *)(buf+headerlen);
- ps_id_code = *buf;
+ ps_id_code = *(basebuf + headerlen);
// make sure it's valid
if ((ps_id_code >= 0x80) && (ps_id_code <= 0x87)) {
GST_DEBUG (0,"mpeg2parse: we have a private_stream_1 (AC3) packet, track %d\n",
More information about the Gstreamer-commits
mailing list