rtpdtmfsrc: Post the messages after the clock wait
authorOlivier Crête <olivier.crete@collabora.com>
Sat, 26 Jan 2013 01:39:33 +0000 (20:39 -0500)
committerOlivier Crête <olivier.crete@collabora.com>
Sat, 26 Jan 2013 01:45:43 +0000 (20:45 -0500)
This way, the messages will be closer in time to when the packets are sent out

gst/dtmf/gstrtpdtmfsrc.c

index ccba67f6443448c254926a92676b175c72837fbb..834ec480e4764651083385d01b189b82588025f5 100644 (file)
@@ -642,12 +642,11 @@ gst_rtp_dtmf_src_create_next_rtp_packet (GstRTPDTMFSrc * dtmfsrc)
   return buf;
 }
 
-
-static void
-gst_dtmf_src_post_message (GstRTPDTMFSrc * dtmfsrc, const gchar * message_name,
-    GstRTPDTMFSrcEvent * event)
+static GstMessage *
+gst_dtmf_src_prepare_message (GstRTPDTMFSrc * dtmfsrc,
+    const gchar * message_name, GstRTPDTMFSrcEvent * event)
 {
-  GstStructure *s = NULL;
+  GstStructure *s;
 
   switch (event->event_type) {
     case RTP_DTMF_EVENT_TYPE_START:
@@ -664,12 +663,21 @@ gst_dtmf_src_post_message (GstRTPDTMFSrc * dtmfsrc, const gchar * message_name,
           "start", G_TYPE_BOOLEAN, FALSE, NULL);
       break;
     case RTP_DTMF_EVENT_TYPE_PAUSE_TASK:
-      return;
+      return NULL;
   }
 
-  if (s)
-    gst_element_post_message (GST_ELEMENT (dtmfsrc),
-        gst_message_new_element (GST_OBJECT (dtmfsrc), s));
+  return gst_message_new_element (GST_OBJECT (dtmfsrc), s);
+}
+
+static void
+gst_dtmf_src_post_message (GstRTPDTMFSrc * dtmfsrc, const gchar * message_name,
+    GstRTPDTMFSrcEvent * event)
+{
+  GstMessage *m = gst_dtmf_src_prepare_message (dtmfsrc, message_name, event);
+
+
+  if (m)
+    gst_element_post_message (GST_ELEMENT (dtmfsrc), m);
 }
 
 
@@ -682,6 +690,8 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
   GstClock *clock;
   GstClockID *clockid;
   GstClockReturn clockret;
+  GstMessage *message;
+  GQueue messages = G_QUEUE_INIT;
 
   dtmfsrc = GST_RTP_DTMF_SRC (basesrc);
 
@@ -708,7 +718,9 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
           if (!gst_rtp_dtmf_prepare_timestamps (dtmfsrc))
             goto no_clock;
 
-          gst_dtmf_src_post_message (dtmfsrc, "dtmf-event-processed", event);
+          g_queue_push_tail (&messages,
+              gst_dtmf_src_prepare_message (dtmfsrc, "dtmf-event-processed",
+                  event));
           dtmfsrc->payload = event->payload;
           dtmfsrc->payload->duration =
               dtmfsrc->ptime * dtmfsrc->clock_rate / 1000;
@@ -752,7 +764,9 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
             dtmfsrc->last_packet = TRUE;
             /* Set the redundancy on the last packet */
             dtmfsrc->redundancy_count = dtmfsrc->packet_redundancy;
-            gst_dtmf_src_post_message (dtmfsrc, "dtmf-event-processed", event);
+            g_queue_push_tail (&messages,
+                gst_dtmf_src_prepare_message (dtmfsrc, "dtmf-event-processed",
+                    event));
             break;
 
           case RTP_DTMF_EVENT_TYPE_PAUSE_TASK:
@@ -801,6 +815,9 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
   dtmfsrc->clockid = NULL;
   GST_OBJECT_UNLOCK (dtmfsrc);
 
+  while ((message = g_queue_pop_head (&messages)) != NULL)
+    gst_element_post_message (GST_ELEMENT (dtmfsrc), message);
+
   if (clockret == GST_CLOCK_UNSCHEDULED) {
     goto paused;
   }