diff options
Diffstat (limited to 'gst/dtmf')
-rw-r--r-- | gst/dtmf/gstdtmfsrc.c | 26 | ||||
-rw-r--r-- | gst/dtmf/gstrtpdtmfsrc.c | 32 |
2 files changed, 38 insertions, 20 deletions
diff --git a/gst/dtmf/gstdtmfsrc.c b/gst/dtmf/gstdtmfsrc.c index 8595adf8..7a1f14b2 100644 --- a/gst/dtmf/gstdtmfsrc.c +++ b/gst/dtmf/gstdtmfsrc.c @@ -287,6 +287,12 @@ gst_dtmf_src_class_init (GstDTMFSrcClass * klass) gstbasesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_dtmf_src_negotiate); } +static void +event_free (GstDTMFSrcEvent * event) +{ + if (event) + g_slice_free (GstDTMFSrcEvent, event); +} static void gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass * g_class) @@ -297,7 +303,7 @@ gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass * g_class) dtmfsrc->interval = DEFAULT_PACKET_INTERVAL; - dtmfsrc->event_queue = g_async_queue_new (); + dtmfsrc->event_queue = g_async_queue_new_full ((GDestroyNotify) event_free); dtmfsrc->last_event = NULL; dtmfsrc->sample_rate = DEFAULT_SAMPLE_RATE; @@ -482,7 +488,7 @@ gst_dtmf_src_add_start_event (GstDTMFSrc * dtmfsrc, gint event_number, gint event_volume) { - GstDTMFSrcEvent *event = g_malloc (sizeof (GstDTMFSrcEvent)); + GstDTMFSrcEvent *event = g_slice_new0 (GstDTMFSrcEvent); event->event_type = DTMF_EVENT_TYPE_START; event->sample = 0; event->event_number = CLAMP (event_number, MIN_EVENT, MAX_EVENT); @@ -495,7 +501,7 @@ static void gst_dtmf_src_add_stop_event (GstDTMFSrc * dtmfsrc) { - GstDTMFSrcEvent *event = g_malloc (sizeof (GstDTMFSrcEvent)); + GstDTMFSrcEvent *event = g_slice_new0 (GstDTMFSrcEvent); event->event_type = DTMF_EVENT_TYPE_STOP; event->sample = 0; event->event_number = 0; @@ -658,7 +664,7 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, break; } if (event) - g_free (event); + g_slice_free (GstDTMFSrcEvent, event); } else if (dtmfsrc->last_event->packet_count * dtmfsrc->interval >= MIN_DUTY_CYCLE) { event = g_async_queue_try_pop (dtmfsrc->event_queue); @@ -673,7 +679,7 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, case DTMF_EVENT_TYPE_STOP: gst_dtmf_src_set_stream_lock (dtmfsrc, FALSE); - g_free (dtmfsrc->last_event); + g_slice_free (GstDTMFSrcEvent, dtmfsrc->last_event); dtmfsrc->last_event = NULL; break; case DTMF_EVENT_TYPE_PAUSE_TASK: @@ -692,7 +698,7 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, break; } - g_free (event); + g_slice_free (GstDTMFSrcEvent, event); } } } while (dtmfsrc->last_event == NULL); @@ -748,7 +754,7 @@ paused: GST_DEBUG_OBJECT (dtmfsrc, "Stopping current event"); /* Don't forget to release the stream lock */ gst_dtmf_src_set_stream_lock (dtmfsrc, FALSE); - g_free (dtmfsrc->last_event); + g_slice_free (GstDTMFSrcEvent, dtmfsrc->last_event); dtmfsrc->last_event = NULL; } @@ -772,7 +778,7 @@ gst_dtmf_src_unlock (GstBaseSrc * src) GST_OBJECT_UNLOCK (dtmfsrc); GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request"); - event = g_malloc (sizeof (GstDTMFSrcEvent)); + event = g_slice_new0 (GstDTMFSrcEvent); event->event_type = DTMF_EVENT_TYPE_PAUSE_TASK; g_async_queue_push (dtmfsrc->event_queue, event); @@ -875,7 +881,7 @@ gst_dtmf_src_change_state (GstElement * element, GstStateChange transition) event = g_async_queue_try_pop (dtmfsrc->event_queue); while (event != NULL) { - g_free (event); + g_slice_free (GstDTMFSrcEvent, event); event = g_async_queue_try_pop (dtmfsrc->event_queue); } no_preroll = TRUE; @@ -899,7 +905,7 @@ gst_dtmf_src_change_state (GstElement * element, GstStateChange transition) event = g_async_queue_try_pop (dtmfsrc->event_queue); while (event != NULL) { - g_free (event); + g_slice_free (GstDTMFSrcEvent, event); event = g_async_queue_try_pop (dtmfsrc->event_queue); } diff --git a/gst/dtmf/gstrtpdtmfsrc.c b/gst/dtmf/gstrtpdtmfsrc.c index 738be59e..65d0ce8c 100644 --- a/gst/dtmf/gstrtpdtmfsrc.c +++ b/gst/dtmf/gstrtpdtmfsrc.c @@ -302,6 +302,16 @@ gst_rtp_dtmf_src_class_init (GstRTPDTMFSrcClass * klass) } static void +gst_rtp_dtmf_src_event_free (GstRTPDTMFSrcEvent * event) +{ + if (event) { + if (event->payload) + g_slice_free (GstRTPDTMFPayload, event->payload); + g_slice_free (GstRTPDTMFSrcEvent, event); + } +} + +static void gst_rtp_dtmf_src_init (GstRTPDTMFSrc * object, GstRTPDTMFSrcClass * g_class) { gst_base_src_set_format (GST_BASE_SRC (object), GST_FORMAT_TIME); @@ -315,7 +325,8 @@ gst_rtp_dtmf_src_init (GstRTPDTMFSrc * object, GstRTPDTMFSrcClass * g_class) object->interval = DEFAULT_PACKET_INTERVAL; object->packet_redundancy = DEFAULT_PACKET_REDUNDANCY; - object->event_queue = g_async_queue_new (); + object->event_queue = + g_async_queue_new_full ((GDestroyNotify) gst_rtp_dtmf_src_event_free); object->payload = NULL; GST_DEBUG_OBJECT (object, "init done"); @@ -557,10 +568,10 @@ gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc * dtmfsrc, gint event_number, gint event_volume) { - GstRTPDTMFSrcEvent *event = g_malloc (sizeof (GstRTPDTMFSrcEvent)); + GstRTPDTMFSrcEvent *event = g_slice_new0 (GstRTPDTMFSrcEvent); event->event_type = RTP_DTMF_EVENT_TYPE_START; - event->payload = g_new0 (GstRTPDTMFPayload, 1); + event->payload = g_slice_new0 (GstRTPDTMFPayload); event->payload->event = CLAMP (event_number, MIN_EVENT, MAX_EVENT); event->payload->volume = CLAMP (event_volume, MIN_VOLUME, MAX_VOLUME); event->payload->duration = dtmfsrc->interval * dtmfsrc->clock_rate / 1000; @@ -572,7 +583,7 @@ static void gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc * dtmfsrc) { - GstRTPDTMFSrcEvent *event = g_malloc (sizeof (GstRTPDTMFSrcEvent)); + GstRTPDTMFSrcEvent *event = g_slice_new0 (GstRTPDTMFSrcEvent); event->event_type = RTP_DTMF_EVENT_TYPE_STOP; g_async_queue_push (dtmfsrc->event_queue, event); @@ -690,6 +701,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, gst_rtp_dtmf_src_set_stream_lock (dtmfsrc, TRUE); dtmfsrc->payload = event->payload; + event->payload = NULL; break; case RTP_DTMF_EVENT_TYPE_PAUSE_TASK: @@ -706,7 +718,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, break; } - g_free (event); + gst_rtp_dtmf_src_event_free (event); } else if (!dtmfsrc->first_packet && !dtmfsrc->last_packet && (dtmfsrc->timestamp - dtmfsrc->start_timestamp) / GST_MSECOND >= MIN_PULSE_DURATION) { @@ -744,7 +756,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, GST_OBJECT_UNLOCK (dtmfsrc); break; } - g_free (event); + gst_rtp_dtmf_src_event_free (event); } } } while (dtmfsrc->payload == NULL); @@ -804,7 +816,7 @@ send_last: /* Don't forget to release the stream lock */ gst_rtp_dtmf_src_set_stream_lock (dtmfsrc, FALSE); - g_free (dtmfsrc->payload); + g_slice_free (GstRTPDTMFPayload, dtmfsrc->payload); dtmfsrc->payload = NULL; dtmfsrc->last_packet = FALSE; @@ -997,7 +1009,7 @@ gst_rtp_dtmf_src_change_state (GstElement * element, GstStateChange transition) /* Flushing the event queue */ while ((event = g_async_queue_try_pop (dtmfsrc->event_queue)) != NULL) - g_free (event); + gst_rtp_dtmf_src_event_free (event); no_preroll = TRUE; break; @@ -1018,7 +1030,7 @@ gst_rtp_dtmf_src_change_state (GstElement * element, GstStateChange transition) /* Flushing the event queue */ while ((event = g_async_queue_try_pop (dtmfsrc->event_queue)) != NULL) - g_free (event); + gst_rtp_dtmf_src_event_free (event); /* Indicate that we don't do PRE_ROLL */ break; @@ -1057,7 +1069,7 @@ gst_rtp_dtmf_src_unlock (GstBaseSrc * src) GST_OBJECT_UNLOCK (dtmfsrc); GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request"); - event = g_malloc (sizeof (GstRTPDTMFSrcEvent)); + event = g_slice_new0 (GstRTPDTMFSrcEvent); event->event_type = RTP_DTMF_EVENT_TYPE_PAUSE_TASK; g_async_queue_push (dtmfsrc->event_queue, event); |