rtp: Properly timestamp buffers in the GStreamer sender pipeline
authorSebastian Dröge <sebastian@centricular.com>
Mon, 14 Mar 2016 17:17:03 +0000 (19:17 +0200)
committerArun Raghavan <arun@arunraghavan.net>
Fri, 8 Nov 2019 12:09:40 +0000 (17:39 +0530)
Otherwise default timestamping will happen, which might not be correct,
especially not after the stream was suspended for a while.

src/modules/rtp/rtp-gstreamer.c

index fa66363..52ebd41 100644 (file)
@@ -233,6 +233,19 @@ int pa_rtp_send(pa_rtp_context *c, pa_memblockq *q) {
         return -1;
 
     while (!stop && pa_memblockq_peek(q, &chunk) == 0) {
+        GstClock *clock;
+        GstClockTime timestamp, clock_time;
+
+        clock = gst_element_get_clock(c->pipeline);
+        clock_time = gst_clock_get_time(clock);
+        gst_object_unref(clock);
+
+        timestamp = gst_element_get_base_time(c->pipeline);
+        if (timestamp > clock_time)
+          timestamp -= clock_time;
+        else
+          timestamp = 0;
+
         pa_assert(chunk.memblock);
 
         data = pa_memblock_acquire(chunk.memblock);
@@ -241,6 +254,8 @@ int pa_rtp_send(pa_rtp_context *c, pa_memblockq *q) {
                                           data, chunk.length, chunk.index, chunk.length, chunk.memblock,
                                           (GDestroyNotify) free_buffer);
 
+        GST_BUFFER_PTS(buf) = timestamp;
+
         if (gst_app_src_push_buffer(GST_APP_SRC(c->appsrc), buf) != GST_FLOW_OK) {
             pa_log_error("Could not push buffer");
             stop = true;