From 6aa66ac48ddbec842fd2deffe3855239f49a05f7 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 18 May 2005 10:23:41 +0000 Subject: gst/mpeg1videoparse/gstmp1videoparse.c: Prevent crash, detect keyframes (#303650). Original commit message from CVS: * gst/mpeg1videoparse/gstmp1videoparse.c: (mp1videoparse_valid_sync), (gst_mp1videoparse_real_chain): Prevent crash, detect keyframes (#303650). --- ChangeLog | 6 ++++++ gst/mpeg1videoparse/gstmp1videoparse.c | 26 +++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58acc643..67c4ee1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-05-18 Ronald S. Bultje + + * gst/mpeg1videoparse/gstmp1videoparse.c: + (mp1videoparse_valid_sync), (gst_mp1videoparse_real_chain): + Prevent crash, detect keyframes (#303650). + 2005-05-18 Brian Cameron Reviewed by: Ronald S. Bultje diff --git a/gst/mpeg1videoparse/gstmp1videoparse.c b/gst/mpeg1videoparse/gstmp1videoparse.c index c1510f0f..34e9ae46 100644 --- a/gst/mpeg1videoparse/gstmp1videoparse.c +++ b/gst/mpeg1videoparse/gstmp1videoparse.c @@ -220,14 +220,17 @@ mp1videoparse_valid_sync (Mp1VideoParse * mp1videoparse, guint32 head, GstBuffer * buf) { switch (head) { - case SEQ_START_CODE:{ - GstBuffer *subbuf = gst_buffer_create_sub (buf, 4, - GST_BUFFER_SIZE (buf) - 4); - - mp1videoparse_parse_seq (mp1videoparse, subbuf); - gst_buffer_unref (subbuf); + case SEQ_START_CODE: + /* FIXME: may sometimes not update header (although that'll probably + * never happen in practice). */ + if (GST_BUFFER_SIZE (buf) >= 8) { + GstBuffer *subbuf = gst_buffer_create_sub (buf, 4, + GST_BUFFER_SIZE (buf) - 4); + + mp1videoparse_parse_seq (mp1videoparse, subbuf); + gst_buffer_unref (subbuf); + } return TRUE; - } case GOP_START_CODE: case PICTURE_START_CODE: case USER_START_CODE: @@ -505,6 +508,8 @@ gst_mp1videoparse_real_chain (Mp1VideoParse * mp1videoparse, GstBuffer * buf, } if (GST_PAD_CAPS (outpad) != NULL) { + guint8 *p_ptr; + if (mp1videoparse->need_discont && GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) { GstEvent *event = gst_event_new_discontinuous (FALSE, @@ -517,6 +522,13 @@ gst_mp1videoparse_real_chain (Mp1VideoParse * mp1videoparse, GstBuffer * buf, } GST_DEBUG ("mp1videoparse: pushing %d bytes %" G_GUINT64_FORMAT, GST_BUFFER_SIZE (outbuf), GST_BUFFER_TIMESTAMP (outbuf)); + p_ptr = GST_BUFFER_DATA (outbuf); + while (p_ptr[0] != 0x0 || p_ptr[1] != 0x0 || + p_ptr[2] != 0x1 || p_ptr[3] != (PICTURE_START_CODE & 0xff)) + p_ptr++; + if (((p_ptr[5] >> 3) & 0x7) == 0x1) { + GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT); + } gst_pad_push (outpad, GST_DATA (outbuf)); GST_DEBUG ("mp1videoparse: pushing done"); } else { -- cgit v1.2.1