From bcde8c1b297540c1297c70b06b3eea878b93a4e9 Mon Sep 17 00:00:00 2001 From: Thijs Vermeir Date: Tue, 12 Oct 2010 15:02:42 +0200 Subject: rtpmpvpay: fix timestamping of rtp buffers Incomming buffer is only pushed on the adapter at the end of the handle_buffer function. But duration/timestamp of this buffer is already taken into account for the current data in the adapter. This leads to wrong rtp timestamps and extra latency. --- gst/rtp/gstrtpmpvpay.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/gst/rtp/gstrtpmpvpay.c b/gst/rtp/gstrtpmpvpay.c index 50bff2793..6523dbbed 100644 --- a/gst/rtp/gstrtpmpvpay.c +++ b/gst/rtp/gstrtpmpvpay.c @@ -27,6 +27,9 @@ #include "gstrtpmpvpay.h" +GST_DEBUG_CATEGORY_STATIC (rtpmpvpay_debug); +#define GST_CAT_DEFAULT (rtpmpvpay_debug) + static GstStaticPadTemplate gst_rtp_mpv_pay_sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, @@ -83,6 +86,9 @@ gst_rtp_mpv_pay_class_init (GstRTPMPVPayClass * klass) gstbasertppayload_class->set_caps = gst_rtp_mpv_pay_setcaps; gstbasertppayload_class->handle_buffer = gst_rtp_mpv_pay_handle_buffer; + + GST_DEBUG_CATEGORY_INIT (rtpmpvpay_debug, "rtpmpvpay", 0, + "MPEG2 ES Video RTP Payloader"); } static void @@ -190,27 +196,31 @@ gst_rtp_mpv_pay_handle_buffer (GstBaseRTPPayload * basepayload, if (duration == -1) duration = 0; - /* Initialize new RTP payload */ - if (avail == 0) { + if (rtpmpvpay->first_ts == GST_CLOCK_TIME_NONE || avail == 0) rtpmpvpay->first_ts = timestamp; + + if (avail == 0) { rtpmpvpay->duration = duration; + } else { + rtpmpvpay->duration += duration; } + gst_adapter_push (rtpmpvpay->adapter, buffer); + avail = gst_adapter_available (rtpmpvpay->adapter); + /* get packet length of previous data and this new data, * payload length includes a 4 byte MPEG video-specific header */ packet_len = gst_rtp_buffer_calc_packet_len (avail, 4, 0); + GST_LOG_OBJECT (rtpmpvpay, "available %d, rtp packet length %d", avail, + packet_len); if (gst_basertppayload_is_filled (basepayload, - packet_len, rtpmpvpay->duration + duration)) { + packet_len, rtpmpvpay->duration)) { ret = gst_rtp_mpv_pay_flush (rtpmpvpay); + } else { rtpmpvpay->first_ts = timestamp; - rtpmpvpay->duration = 0; } - gst_adapter_push (rtpmpvpay->adapter, buffer); - - rtpmpvpay->duration += duration; - return ret; } -- cgit v1.2.3