rtpdtmfsrc: Put the inter digit interval at the end, not at the start
authorOlivier Crête <olivier.crete@collabora.com>
Tue, 12 Jul 2011 00:46:20 +0000 (20:46 -0400)
committerOlivier Crête <olivier.crete@collabora.com>
Wed, 24 Aug 2011 16:24:17 +0000 (12:24 -0400)
The reason is to let rtpdtmfmux drop buffers during the inter digit interval,
this way, there will be more silence around the DTMF tones so IVFs will have
a better chance recognizing them.

gst/dtmf/gstrtpdtmfsrc.c

index 8d37f31..19acc6c 100644 (file)
@@ -514,8 +514,7 @@ gst_rtp_dtmf_prepare_timestamps (GstRTPDTMFSrc * dtmfsrc)
     if (clock == NULL)
       return FALSE;
 
-    dtmfsrc->timestamp = gst_clock_get_time (clock)
-        + (MIN_INTER_DIGIT_INTERVAL * GST_MSECOND)
+    dtmfsrc->start_timestamp = gst_clock_get_time (clock)
         - gst_element_get_base_time (GST_ELEMENT (dtmfsrc));
     dtmfsrc->start_timestamp = dtmfsrc->timestamp;
     gst_object_unref (clock);
@@ -591,7 +590,6 @@ gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc * dtmfsrc, GstBuffer * buf)
     GST_BUFFER_DURATION (buf) = dtmfsrc->ptime * GST_MSECOND;
   GST_BUFFER_TIMESTAMP (buf) = dtmfsrc->timestamp;
 
-  dtmfsrc->timestamp += GST_BUFFER_DURATION (buf);
 
   payload = (GstRTPDTMFPayload *) gst_rtp_buffer_get_payload (buf);
 
@@ -606,6 +604,18 @@ gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc * dtmfsrc, GstBuffer * buf)
   if (dtmfsrc->redundancy_count == 0)
     dtmfsrc->payload->duration += dtmfsrc->ptime * dtmfsrc->clock_rate / 1000;
 
+  if (dtmfsrc->redundancy_count == 0 && dtmfsrc->last_packet) {
+    GstClockTime inter_digit_interval = MIN_INTER_DIGIT_INTERVAL;
+
+    if (inter_digit_interval % dtmfsrc->ptime != 0)
+      inter_digit_interval += dtmfsrc->ptime -
+          (MIN_INTER_DIGIT_INTERVAL % dtmfsrc->ptime);
+
+    GST_BUFFER_DURATION (buf) += inter_digit_interval * GST_MSECOND;
+  }
+
+  if (GST_CLOCK_TIME_IS_VALID (dtmfsrc->timestamp))
+    dtmfsrc->timestamp += GST_BUFFER_DURATION (buf);
 }
 
 static GstBuffer *