From 984849f8fec0088ec5adf40b0009da2ba86e345a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 20 Dec 2010 16:05:36 +0100 Subject: [PATCH] mpapay: reset payloader on flush Reset the payloader on a flush event. Handle DISCONT better. --- gst/rtp/gstrtpmpapay.c | 59 +++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/gst/rtp/gstrtpmpapay.c b/gst/rtp/gstrtpmpapay.c index f57d628ea..ed0200391 100644 --- a/gst/rtp/gstrtpmpapay.c +++ b/gst/rtp/gstrtpmpapay.c @@ -52,6 +52,7 @@ static void gst_rtp_mpa_pay_finalize (GObject * object); static gboolean gst_rtp_mpa_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps); +static gboolean gst_rtp_mpa_pay_handle_event (GstPad * pad, GstEvent * event); static GstFlowReturn gst_rtp_mpa_pay_handle_buffer (GstBaseRTPPayload * payload, GstBuffer * buffer); @@ -85,6 +86,7 @@ gst_rtp_mpa_pay_class_init (GstRtpMPAPayClass * klass) gobject_class->finalize = gst_rtp_mpa_pay_finalize; gstbasertppayload_class->set_caps = gst_rtp_mpa_pay_setcaps; + gstbasertppayload_class->handle_event = gst_rtp_mpa_pay_handle_event; gstbasertppayload_class->handle_buffer = gst_rtp_mpa_pay_handle_buffer; } @@ -107,6 +109,15 @@ gst_rtp_mpa_pay_finalize (GObject * object) G_OBJECT_CLASS (parent_class)->finalize (object); } +static void +gst_rtp_mpa_pay_reset (GstRtpMPAPay * pay) +{ + pay->first_ts = -1; + pay->duration = 0; + gst_adapter_clear (pay->adapter); + GST_DEBUG_OBJECT (pay, "reset depayloader"); +} + static gboolean gst_rtp_mpa_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps) { @@ -118,6 +129,27 @@ gst_rtp_mpa_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps) return res; } +static gboolean +gst_rtp_mpa_pay_handle_event (GstPad * pad, GstEvent * event) +{ + GstRtpMPAPay *rtpmpapay; + + rtpmpapay = GST_RTP_MPA_PAY (gst_pad_get_parent (pad)); + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_FLUSH_STOP: + gst_rtp_mpa_pay_reset (rtpmpapay); + break; + default: + break; + } + + gst_object_unref (rtpmpapay); + + /* FALSE to let the parent handle the event as well */ + return FALSE; +} + static GstFlowReturn gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay) { @@ -143,7 +175,7 @@ gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay) guint payload_len; guint packet_len; - /* this will be the total lenght of the packet */ + /* this will be the total length of the packet */ packet_len = gst_rtp_buffer_calc_packet_len (4 + avail, 0, 0); /* fill one MTU or all available bytes */ @@ -198,19 +230,21 @@ gst_rtp_mpa_pay_handle_buffer (GstBaseRTPPayload * basepayload, GstFlowReturn ret; guint size, avail; guint packet_len; - GstClockTime duration; + GstClockTime duration, timestamp; rtpmpapay = GST_RTP_MPA_PAY (basepayload); size = GST_BUFFER_SIZE (buffer); duration = GST_BUFFER_DURATION (buffer); + timestamp = GST_BUFFER_TIMESTAMP (buffer); - avail = gst_adapter_available (rtpmpapay->adapter); - if (avail == 0) { - rtpmpapay->first_ts = GST_BUFFER_TIMESTAMP (buffer); - rtpmpapay->duration = 0; + if (GST_BUFFER_IS_DISCONT (buffer)) { + GST_DEBUG_OBJECT (rtpmpapay, "DISCONT"); + gst_rtp_mpa_pay_reset (rtpmpapay); } + avail = gst_adapter_available (rtpmpapay->adapter); + /* get packet length of previous data and this new data, * payload length includes a 4 byte header */ packet_len = gst_rtp_buffer_calc_packet_len (4 + avail + size, 0, 0); @@ -220,14 +254,21 @@ gst_rtp_mpa_pay_handle_buffer (GstBaseRTPPayload * basepayload, if (gst_basertppayload_is_filled (basepayload, packet_len, rtpmpapay->duration + duration)) { ret = gst_rtp_mpa_pay_flush (rtpmpapay); - rtpmpapay->first_ts = GST_BUFFER_TIMESTAMP (buffer); - rtpmpapay->duration = 0; + avail = 0; } else { ret = GST_FLOW_OK; } + if (avail == 0) { + GST_DEBUG_OBJECT (rtpmpapay, + "first packet, save timestamp %" GST_TIME_FORMAT, + GST_TIME_ARGS (timestamp)); + rtpmpapay->first_ts = timestamp; + rtpmpapay->duration = 0; + } + gst_adapter_push (rtpmpapay->adapter, buffer); - rtpmpapay->duration += duration; + rtpmpapay->duration = duration; return ret; } -- 2.34.1