From: Volodymyr Brynza Date: Thu, 9 Jun 2016 09:02:33 +0000 (+0300) Subject: Fixed memory leaks X-Git-Tag: accepted/tizen/common/20160610.182447^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F96%2F73796%2F1;p=platform%2Fcore%2Fapi%2Fmediastreamer.git Fixed memory leaks Change-Id: I6bcc4f979c4d9617c412700c29e738899847ab03 Signed-off-by: Volodymyr Brynza --- diff --git a/include/media_streamer_util.h b/include/media_streamer_util.h index 3079de5..01ecb96 100644 --- a/include/media_streamer_util.h +++ b/include/media_streamer_util.h @@ -185,7 +185,7 @@ typedef struct { #define MEDIA_STREAMER_DEFAULT_CAMERA_FORMAT "video/x-raw,format=I420,width=352,height=288" #define MEDIA_STREAMER_DEFAULT_AUDIO_RAW_FORMAT "audio/x-raw,channels=1,rate=8000,format=S16LE" -#define MEDIA_STREAMER_DEFAULT_VIDEO_FORMAT "video/x-h263,width=352,height=288,framrate = 3/1" +#define MEDIA_STREAMER_DEFAULT_VIDEO_FORMAT "video/x-h263,width=352,height=288,framerate = 3/1" #define MEDIA_STREAMER_DEFAULT_AUDIO_FORMAT "audio/AMR ,rate = 8000,channels = 1" #define MEDIA_STREAMER_DEFAULT_VIDEO_RTP_FORMAT "application/x-rtp,media=video" #define MEDIA_STREAMER_DEFAULT_AUDIO_RTP_FORMAT "application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)AMR,encoding-params=(string)1,octet-align=(string)1" @@ -225,12 +225,12 @@ typedef struct { ms_debug("Got a few errors during unprepare [%s] bin.", GST_ELEMENT_NAME(bin));\ } -#define MS_SET_INT_RTP_PARAM(obj, key, value) \ +#define MS_SET_INT_PARAM(obj, key, value) \ do { \ GValue *val = g_malloc0(sizeof(GValue)); \ g_value_init(val, G_TYPE_INT); \ g_value_set_int(val, value); \ - g_object_set_data_full(G_OBJECT(obj), key, (gpointer)val, __ms_rtp_param_value_destroy); \ + g_object_set_data_full(G_OBJECT(obj), key, (gpointer)val, __ms_param_value_destroy); \ } while (0) #define MS_SET_INT_STATIC_STRING_PARAM(obj, key, value) \ @@ -238,7 +238,7 @@ typedef struct { GValue *val = g_malloc0(sizeof(GValue)); \ g_value_init(val, G_TYPE_STRING); \ g_value_set_static_string(val, value); \ - g_object_set_data_full(G_OBJECT(obj), key, (gpointer)val, __ms_rtp_param_value_destroy); \ + g_object_set_data_full(G_OBJECT(obj), key, (gpointer)val, __ms_param_value_destroy); \ } while (0) #define MS_SET_INT_CAPS_PARAM(obj, key, value) \ @@ -246,7 +246,7 @@ typedef struct { GValue *val = g_malloc0(sizeof(GValue)); \ g_value_init(val, GST_TYPE_CAPS); \ gst_value_set_caps(val, value); \ - g_object_set_data_full(G_OBJECT(obj), key, (gpointer)val, __ms_rtp_param_value_destroy); \ + g_object_set_data_full(G_OBJECT(obj), key, (gpointer)val, __ms_param_value_destroy); \ } while (0) #define MS_GET_CAPS_TYPE(caps, type) \ @@ -328,7 +328,7 @@ void __ms_signal_destroy(void *data); * * @since_tizen 3.0 */ -void __ms_rtp_param_value_destroy(gpointer data); +void __ms_param_value_destroy(gpointer data); #ifdef __cplusplus } diff --git a/src/media_streamer.c b/src/media_streamer.c index c3cf041..7a12e33 100644 --- a/src/media_streamer.c +++ b/src/media_streamer.c @@ -590,27 +590,8 @@ int media_streamer_node_link(media_streamer_node_h src_node, const char *src_pad ms_retvm_if(src_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Pad is NULL"); ms_retvm_if(sink_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Pad is NULL"); - gchar *src_element_name = gst_element_get_name(ms_src_node->gst_element); - gchar *sink_element_name = gst_element_get_name(ms_dest_node->gst_element); + gboolean link_ret = gst_element_link_pads(ms_src_node->gst_element, src_pad_name, ms_dest_node->gst_element, sink_pad_name); - GstCaps *src_pad_caps = NULL; - GstCaps *sink_pad_caps = NULL; - GValue *val = NULL; - - val = (GValue *) g_object_get_data(G_OBJECT(ms_src_node->gst_element), src_pad_name); - if (val) { - src_pad_caps = GST_CAPS(gst_value_get_caps(val)); - ms_info("Pad [%s] of node [%s] was set with caps [%s]\n", src_pad_name, ms_src_node->name, gst_caps_to_string(src_pad_caps)); - } - - val = (GValue *) g_object_get_data(G_OBJECT(ms_dest_node->gst_element), sink_pad_name); - if (val) { - sink_pad_caps = GST_CAPS(gst_value_get_caps(val)); - ms_info("Pad [%s] of node [%s] was set with caps [%s]\n", src_pad_name, ms_src_node->name, gst_caps_to_string(sink_pad_caps)); - } - - gboolean link_ret = gst_element_link_pads_filtered(ms_src_node->gst_element, src_pad_name, - ms_dest_node->gst_element, sink_pad_name, src_pad_caps ? src_pad_caps : sink_pad_caps); if (!link_ret) { ms_error("Can not link [%s]:%s pad to [%s]:%s pad, ret code [%d] ", ms_src_node->name, src_pad_name, ms_dest_node->name, sink_pad_name, link_ret); ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; @@ -620,8 +601,6 @@ int media_streamer_node_link(media_streamer_node_h src_node, const char *src_pad ms_dest_node->linked_by_user = TRUE; } - MS_SAFE_GFREE(src_element_name); - MS_SAFE_GFREE(sink_element_name); return ret; } diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index 423fd24..f7b76af 100755 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -245,7 +245,7 @@ static GstElement *__ms_find_peer_element_by_type(GstElement *previous_element, if (g_strrstr(found_klass, node_klass_type->klass_name) || g_strrstr(GST_ELEMENT_NAME(peer_element), node_klass_type->default_name)) ms_info(" Found peer element [%s] ", GST_ELEMENT_NAME(peer_element)); else - peer_element = NULL; + MS_SAFE_UNREF(peer_element); } } else { @@ -258,10 +258,10 @@ static GstElement *__ms_find_peer_element_by_type(GstElement *previous_element, found_klass = gst_element_factory_get_klass(gst_element_get_factory(peer_element)); if (g_strrstr(found_klass, node_klass_type->klass_name) || g_strrstr(GST_ELEMENT_NAME(peer_element), node_klass_type->default_name)) { ms_info(" Found peer element [%s] ", GST_ELEMENT_NAME(peer_element)); + g_value_reset(&src_pad_value); break; - } else { - peer_element = NULL; - } + } else + MS_SAFE_UNREF(peer_element); } g_value_reset(&src_pad_value); } @@ -282,33 +282,40 @@ gboolean __ms_link_two_elements(GstElement *previous_element, GstPad *prev_elem_ GstPad * found_sink_pad = NULL; if (prev_elem_src_pad) { + GstElement *peer_element = __ms_pad_get_peer_element(prev_elem_src_pad); if (!gst_pad_is_linked(prev_elem_src_pad)) { /* Check compatibility of previous element and unlinked found element */ found_sink_pad = gst_element_get_compatible_pad(found_element, prev_elem_src_pad, NULL); if (found_sink_pad) - elements_linked = gst_element_link_pads_filtered(previous_element, GST_PAD_NAME(prev_elem_src_pad), found_element, GST_PAD_NAME(found_sink_pad), NULL); - } else if (__ms_pad_get_peer_element(prev_elem_src_pad) == found_element) { + elements_linked = gst_element_link_pads(previous_element, GST_PAD_NAME(prev_elem_src_pad), found_element, GST_PAD_NAME(found_sink_pad)); + } else if (peer_element == found_element) { elements_linked = TRUE; } + MS_SAFE_UNREF(peer_element); } else { /* Check if previous element has any unlinked src pad */ GstIterator *src_pad_iterator = gst_element_iterate_src_pads(previous_element); while (GST_ITERATOR_OK == gst_iterator_next(src_pad_iterator, &src_pad_value)) { GstPad *src_pad = (GstPad *) g_value_get_object(&src_pad_value); + GstElement *peer_element = __ms_pad_get_peer_element(src_pad); if (!gst_pad_is_linked(src_pad)) { /* Check compatibility of previous element and unlinked found element */ found_sink_pad = gst_element_get_compatible_pad(found_element, src_pad, NULL); if (found_sink_pad) { - elements_linked = gst_element_link_pads_filtered(previous_element, GST_PAD_NAME(src_pad), found_element, GST_PAD_NAME(found_sink_pad), NULL); - if (elements_linked) + elements_linked = gst_element_link_pads(previous_element, GST_PAD_NAME(src_pad), found_element, GST_PAD_NAME(found_sink_pad)); + if (elements_linked) { + g_value_reset(&src_pad_value); + MS_SAFE_UNREF(peer_element); break; + } } - } else if (__ms_pad_get_peer_element(src_pad) == found_element) { + } else if (peer_element == found_element) { elements_linked = TRUE; } + MS_SAFE_UNREF(peer_element); g_value_reset(&src_pad_value); } g_value_unset(&src_pad_value); @@ -320,10 +327,10 @@ gboolean __ms_link_two_elements(GstElement *previous_element, GstPad *prev_elem_ ms_info("Succeeded to link [%s] -> [%s]", GST_ELEMENT_NAME(previous_element), GST_ELEMENT_NAME(found_element)); else ms_debug("Failed to link [%s] and [%s]", GST_ELEMENT_NAME(previous_element), GST_ELEMENT_NAME(found_element)); - } else { - ms_info("Element [%s] has no free pad to be connected with [%s] or linked", GST_ELEMENT_NAME(found_element), GST_ELEMENT_NAME(previous_element)); - } + } else + ms_info("Element [%s] has no free compatible pad to be connected with [%s] or linked", GST_ELEMENT_NAME(found_element), GST_ELEMENT_NAME(previous_element)); + MS_SAFE_UNREF(found_sink_pad); return elements_linked; } @@ -343,6 +350,8 @@ static GstElement *__ms_bin_find_element_by_type(GstElement *previous_element, G ms_info("Found element by type [%s]", GST_ELEMENT_NAME(found_element)); if (__ms_link_two_elements(previous_element, prev_elem_src_pad, found_element)) { elements_linked = TRUE; + g_value_reset(&element_value); + g_object_ref(found_element); break; } } @@ -432,13 +441,13 @@ GstElement *__ms_combine_next_element(GstElement *previous_element, GstPad *prev if (!found_element) { /* Create Node type information for a New element */ - GstPad *src_pad = NULL; if (prev_elem_src_pad) prev_caps = gst_pad_query_caps(prev_elem_src_pad, 0); else { - src_pad = gst_element_get_static_pad(previous_element, "src"); + GstPad *src_pad = gst_element_get_static_pad(previous_element, "src"); if (src_pad) prev_caps = gst_pad_query_caps(src_pad, 0); + MS_SAFE_UNREF(src_pad); } node_plug_s plug_info = {node_klass_type, NULL, prev_caps, NULL}; @@ -448,20 +457,21 @@ GstElement *__ms_combine_next_element(GstElement *previous_element, GstPad *prev ms_info("New Element [%s] is created ", GST_ELEMENT_NAME(found_element)); /* Add created element */ - if (__ms_bin_add_element(bin_to_find_in, found_element, FALSE)) { + if (__ms_bin_add_element(bin_to_find_in, found_element, TRUE)) { gst_element_sync_state_with_parent(found_element); __ms_link_two_elements(previous_element, prev_elem_src_pad, found_element); __ms_generate_dots(bin_to_find_in, GST_ELEMENT_NAME(found_element)); } else { ms_error("Element [%s] was not added into [%s] bin", GST_ELEMENT_NAME(found_element), GST_ELEMENT_NAME(bin_to_find_in)); MS_SAFE_UNREF(found_element); - found_element = NULL; } } else ms_info("New Element is not created "); } else ms_info("Next element is not combined"); + MS_SAFE_UNREF(previous_element); + return found_element; } @@ -532,17 +542,12 @@ static void __decodebin_newpad_cb(GstElement * decodebin, GstPad * new_pad, gpoi static void __decodebin_nomore_pads_combine(GstPad *src_pad, media_streamer_s *ms_streamer, gboolean is_server_part) { - GstElement *found_element = NULL; - GstElement *parent_element = gst_pad_get_parent_element(src_pad); + GstElement *found_element = gst_pad_get_parent_element(src_pad); const gchar *new_pad_type = __ms_get_pad_type(src_pad); - if (MS_ELEMENT_IS_VIDEO(new_pad_type)) { - found_element = __ms_bin_find_element_by_type(parent_element, src_pad, ms_streamer->topology_bin, __ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY)); - if (found_element) { - ms_info(" Overlay Element [%s]", GST_ELEMENT_NAME(found_element)); + if (__ms_bin_find_element_by_type(found_element, src_pad, ms_streamer->topology_bin, __ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY))) { + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY); src_pad = NULL; - } else { - found_element = parent_element; } if (is_server_part) { found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER); @@ -554,19 +559,19 @@ static void __decodebin_nomore_pads_combine(GstPad *src_pad, media_streamer_s *m } } else if (MS_ELEMENT_IS_AUDIO(new_pad_type)) { if (is_server_part) { - found_element = __ms_combine_next_element(parent_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_PAY); found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_RTP); } else { - found_element = __ms_combine_next_element(parent_element, src_pad, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } } else if (MS_ELEMENT_IS_TEXT(new_pad_type)) { - found_element = __ms_combine_next_element(parent_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY); } else { ms_error("Unsupported pad type [%s]!", new_pad_type); - return; } __ms_generate_dots(ms_streamer->pipeline, "after_sink_linked"); + gst_object_unref(found_element); } static void __decodebin_nomore_pads_cb(GstElement *decodebin, gpointer user_data) @@ -604,7 +609,7 @@ GstElement *__ms_decodebin_create(media_streamer_s * ms_streamer) ms_retvm_if(!ms_streamer, NULL, "Handle is NULL"); GstElement *decodebin = __ms_element_create(DEFAULT_DECODEBIN, NULL); - __ms_bin_add_element(ms_streamer->topology_bin, decodebin, FALSE); + __ms_bin_add_element(ms_streamer->topology_bin, decodebin, TRUE); gst_element_sync_state_with_parent(decodebin); __ms_signal_create(&ms_streamer->autoplug_sig_list, decodebin, "pad-added", G_CALLBACK(__decodebin_newpad_cb), ms_streamer); @@ -616,36 +621,42 @@ GstElement *__ms_decodebin_create(media_streamer_s * ms_streamer) static gboolean __ms_sink_bin_prepare(media_streamer_s * ms_streamer, GstPad * source_pad, const gchar * src_pad_type) { + GstElement *decoder_element = NULL; GstElement *found_element = NULL; - GstElement *previous_element = NULL; /* Getting Depayloader */ GstElement *parent_rtp_element = gst_pad_get_parent_element(source_pad); if (MS_ELEMENT_IS_VIDEO(src_pad_type)) { - previous_element = __ms_combine_next_element(parent_rtp_element, source_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DEPAY); - found_element = __ms_combine_next_element(previous_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER); + gst_object_ref(parent_rtp_element); + found_element = __ms_combine_next_element(parent_rtp_element, source_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DEPAY); + decoder_element = __ms_bin_find_element_by_type(found_element, NULL, ms_streamer->topology_bin, __ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER)); - if (!found_element) { + if (!decoder_element) { if (ms_streamer->ini.use_decodebin) { - found_element = __ms_decodebin_create(ms_streamer); - __ms_link_two_elements(previous_element, NULL, found_element); + decoder_element = __ms_decodebin_create(ms_streamer); + gst_object_ref(found_element); + __ms_link_two_elements(found_element, NULL, decoder_element); + MS_SAFE_UNREF(decoder_element); return TRUE; } else { - previous_element = __ms_combine_next_element(previous_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER); - previous_element = __ms_combine_next_element(previous_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); + gst_object_ref(found_element); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } } else { - __ms_link_two_elements(previous_element, NULL, found_element); - previous_element = __ms_combine_next_element(found_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); + __ms_link_two_elements(found_element, NULL, decoder_element); + found_element = __ms_combine_next_element(decoder_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } } else if (MS_ELEMENT_IS_AUDIO(src_pad_type)) { - previous_element = __ms_combine_next_element(parent_rtp_element, source_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DEPAY); - previous_element = __ms_combine_next_element(previous_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DECODER); - previous_element = __ms_combine_next_element(previous_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); + gst_object_ref(parent_rtp_element); + found_element = __ms_combine_next_element(parent_rtp_element, source_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DEPAY); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DECODER); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } else { ms_info("Unknown media type received from rtp element!"); } + MS_SAFE_UNREF(found_element); MS_SAFE_UNREF(parent_rtp_element); return TRUE; @@ -1069,10 +1080,10 @@ GstElement *__ms_rtp_element_create(void) __ms_add_no_target_ghostpad(rtp_container, MS_RTP_PAD_AUDIO_IN"_rtp", GST_PAD_SINK); /* Add RTP node parameters as GObject data with destroy function */ - MS_SET_INT_RTP_PARAM(rtp_container, MEDIA_STREAMER_PARAM_VIDEO_IN_PORT, RTP_STREAM_DISABLED); - MS_SET_INT_RTP_PARAM(rtp_container, MEDIA_STREAMER_PARAM_AUDIO_IN_PORT, RTP_STREAM_DISABLED); - MS_SET_INT_RTP_PARAM(rtp_container, MEDIA_STREAMER_PARAM_VIDEO_OUT_PORT, RTP_STREAM_DISABLED); - MS_SET_INT_RTP_PARAM(rtp_container, MEDIA_STREAMER_PARAM_AUDIO_OUT_PORT, RTP_STREAM_DISABLED); + MS_SET_INT_PARAM(rtp_container, MEDIA_STREAMER_PARAM_VIDEO_IN_PORT, RTP_STREAM_DISABLED); + MS_SET_INT_PARAM(rtp_container, MEDIA_STREAMER_PARAM_AUDIO_IN_PORT, RTP_STREAM_DISABLED); + MS_SET_INT_PARAM(rtp_container, MEDIA_STREAMER_PARAM_VIDEO_OUT_PORT, RTP_STREAM_DISABLED); + MS_SET_INT_PARAM(rtp_container, MEDIA_STREAMER_PARAM_AUDIO_OUT_PORT, RTP_STREAM_DISABLED); MS_SET_INT_STATIC_STRING_PARAM(rtp_container, MEDIA_STREAMER_PARAM_HOST, "localhost"); MS_SET_INT_CAPS_PARAM(rtp_container, MEDIA_STREAMER_PARAM_VIDEO_IN_FORMAT, gst_caps_new_any()); MS_SET_INT_CAPS_PARAM(rtp_container, MEDIA_STREAMER_PARAM_AUDIO_IN_FORMAT, gst_caps_new_any()); @@ -1098,7 +1109,7 @@ gboolean __ms_rtp_element_prepare(media_streamer_node_s *ms_node) GstElement *rtcp_el = NULL; GValue *val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), MEDIA_STREAMER_PARAM_HOST); - const gchar *host = g_value_get_string(val); + const char *host = g_value_get_string(val); val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), MEDIA_STREAMER_PARAM_VIDEO_IN_PORT); if (g_value_get_int(val) > RTP_STREAM_DISABLED) { @@ -1145,6 +1156,7 @@ gboolean __ms_rtp_element_prepare(media_streamer_node_s *ms_node) __ms_bin_add_element(ms_node->gst_element, video_filter, FALSE); GstCaps *video_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_VIDEO_RTP_FORMAT); g_object_set(G_OBJECT(video_filter), "caps", video_caps, NULL); + gst_caps_unref(video_caps); gst_element_link_pads(video_filter, "src", rtpbin, "send_rtp_sink_0"); GstGhostPad *ghost_pad = (GstGhostPad *)gst_element_get_static_pad(ms_node->gst_element, MS_RTP_PAD_VIDEO_IN); @@ -1282,15 +1294,8 @@ void __ms_element_lock_state(const GValue *item, gpointer user_data) GstPad *sink_pad = gst_element_get_static_pad(sink_element, "sink"); if (!gst_pad_is_blocked(sink_pad)) { int probe_id = gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, __ms_element_event_probe, NULL, NULL); - - GValue *val = g_malloc0(sizeof(GValue)); - g_value_init(val, G_TYPE_INT); - g_value_set_int(val, probe_id); - g_object_set_data(G_OBJECT(sink_element), "pad_sink", (gpointer)val); - - val = (GValue *) g_object_get_data(G_OBJECT(sink_element), "pad_sink"); - if (val) - ms_info("Added locking probe [%d] on pad [%s] of element [%s]", g_value_get_int(val), GST_PAD_NAME(sink_pad), GST_ELEMENT_NAME(sink_element)); + MS_SET_INT_PARAM(sink_element, "pad_sink", probe_id); + ms_info("Added locking probe [%d] on pad [%s] of element [%s]", probe_id, GST_PAD_NAME(sink_pad), GST_ELEMENT_NAME(sink_element)); } else { ms_info("Pad [%s] of element [%s] is already locked", GST_PAD_NAME(sink_pad), GST_ELEMENT_NAME(sink_element)); } @@ -1311,6 +1316,7 @@ void __ms_element_unlock_state(const GValue *item, gpointer user_data) } else { ms_info("No locking Probe on pad [%s] of element [%s]", GST_PAD_NAME(sink_pad), GST_ELEMENT_NAME(sink_element)); } + MS_SAFE_UNREF(sink_pad); } } @@ -1353,8 +1359,7 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) MS_SAFE_GFREE(state_transition_name); media_streamer_state_e old_state = ms_streamer->state; - if (state_new >= GST_STATE_PAUSED) - { + if (state_new >= GST_STATE_PAUSED) { if ((old_state == MEDIA_STREAMER_STATE_PLAYING) && (state_new <= GST_STATE_PAUSED)) ms_streamer->pend_state = MEDIA_STREAMER_STATE_PAUSED; @@ -1597,7 +1602,9 @@ int __ms_element_pad_names(GstElement *gst_element, GstPadDirection pad_type, ch break; } - pad_names[pad_number] = gst_pad_get_name(pad); + gchar *pad_name = gst_pad_get_name(pad); + pad_names[pad_number] = pad_name; + g_free(pad_name); ++pad_number; g_value_reset(&elem); @@ -1609,6 +1616,8 @@ int __ms_element_pad_names(GstElement *gst_element, GstPadDirection pad_type, ch *pad_name_array = pad_names; *pads_count = pad_number; + MS_SAFE_FREE(pad_names); + return ret; } @@ -1681,6 +1690,8 @@ int __ms_element_set_fmt(media_streamer_node_s *node, const char *pad_name, medi ms_info("Pad [%s] of node [%s] was set with given format", pad_name, node->name); } + MS_SAFE_UNREF(node_pad); + return MEDIA_STREAMER_ERROR_NONE; } diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index 03ecab8..2305e34 100755 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -89,7 +89,7 @@ void __ms_get_state(media_streamer_s *ms_streamer) ms_error("Couldn`t get state for [%s]", GST_ELEMENT_NAME(ms_streamer->pipeline)); } -static gboolean __ms_rtp_node_has_property(media_streamer_node_s *ms_node, const gchar *param_name) +static gboolean __ms_rtp_node_has_property(media_streamer_node_s *ms_node, const char *param_name) { ms_retvm_if(!ms_node || !ms_node->gst_element, FALSE, "Error: empty node"); ms_retvm_if(!param_name, FALSE, "Error: invalid property parameter"); @@ -146,7 +146,7 @@ static int __ms_rtp_node_set_property(media_streamer_node_s *ms_node, param_s *p } else if (!strcmp(param->param_name, MEDIA_STREAMER_PARAM_HOST)) { g_value_unset(val); g_value_init(val, G_TYPE_STRING); - g_value_take_string(val, g_strdup(param_value)); + g_value_set_string(val, param_value); } else if (!strcmp(param->param_name, MEDIA_STREAMER_PARAM_VIDEO_IN_FORMAT) || !strcmp(param->param_name, MEDIA_STREAMER_PARAM_AUDIO_IN_FORMAT)) { GstCaps *caps = gst_caps_from_string(param_value); @@ -434,7 +434,7 @@ node_info_s * __ms_node_get_klass_by_its_type(media_streamer_node_type_e element int it_klass; for (it_klass = 0; nodes_info[it_klass].klass_name != NULL; it_klass++) { if (it_klass == element_type) { - ms_info(" Node`s type klass is [%s]", nodes_info[it_klass].klass_name); + ms_info("Next node`s type klass is [%s]", nodes_info[it_klass].klass_name); break; } } @@ -446,6 +446,7 @@ static void _src_node_prepare(const GValue *item, gpointer user_data) { media_streamer_s *ms_streamer = (media_streamer_s *) user_data; GstElement *src_element = GST_ELEMENT(g_value_get_object(item)); + g_object_ref(src_element); media_streamer_node_s *found_node = (media_streamer_node_s *) g_hash_table_lookup(ms_streamer->nodes_table, GST_ELEMENT_NAME(src_element)); if (!found_node) @@ -460,13 +461,17 @@ static void _src_node_prepare(const GValue *item, gpointer user_data) if (__ms_src_need_typefind(src_pad)) { found_element = __ms_decodebin_create(ms_streamer); __ms_link_two_elements(src_element, src_pad, found_element); + MS_SAFE_UNREF(src_element); } else { /* Check the source element`s pad type */ const gchar *new_pad_type = __ms_get_pad_type(src_pad); + /* If SRC Element linked by user, don`t consider the following nodes` managing */ if (gst_pad_is_linked(src_pad)) { MS_SAFE_UNREF(src_pad); + MS_SAFE_UNREF(src_element); return; } + /* It is media streamer Server part */ if (MS_ELEMENT_IS_VIDEO(new_pad_type) || MS_ELEMENT_IS_IMAGE(new_pad_type)) { found_element = __ms_combine_next_element(src_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_FILTER); GstCaps *videoCaps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_CAMERA_FORMAT); @@ -483,6 +488,7 @@ static void _src_node_prepare(const GValue *item, gpointer user_data) found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_RTP); } __ms_generate_dots(ms_streamer->pipeline, "after_connecting_rtp"); + MS_SAFE_UNREF(found_element); } MS_SAFE_UNREF(src_pad); } @@ -497,12 +503,12 @@ int __ms_pipeline_prepare(media_streamer_s *ms_streamer) ret = __ms_rtp_element_prepare(rtp_node) ? MEDIA_STREAMER_ERROR_NONE : MEDIA_STREAMER_ERROR_INVALID_PARAMETER; } else { GstBin *nodes_bin = GST_BIN(ms_streamer->src_bin); - if(nodes_bin->numchildren == 0) { + if (nodes_bin->numchildren == 0) { ms_debug(" No any node is added to [%s]", GST_ELEMENT_NAME(ms_streamer->src_bin)); return MEDIA_STREAMER_ERROR_INVALID_PARAMETER; } nodes_bin = GST_BIN(ms_streamer->sink_bin); - if(nodes_bin->numchildren == 0) { + if (nodes_bin->numchildren == 0) { ms_debug(" No any node is added to [%s]", GST_ELEMENT_NAME(ms_streamer->sink_bin)); return MEDIA_STREAMER_ERROR_INVALID_PARAMETER; } @@ -614,6 +620,7 @@ int __ms_node_set_params_from_bundle(media_streamer_node_s *node, bundle *param_ written_count++; } } + g_list_free(p_list); ms_info("Set [%d] parameters of [%d]", written_count, bundle_get_count(param_list)); if (written_count == 0) @@ -635,10 +642,14 @@ int __ms_node_write_params_into_bundle(media_streamer_node_s *node, bundle *para for (list_iter = p_list; list_iter != NULL; list_iter = list_iter->next) { param = (param_s *)list_iter->data; - if (__ms_node_get_param_value(node, param, &string_val) == MEDIA_STREAMER_ERROR_NONE) + if (__ms_node_get_param_value(node, param, &string_val) == MEDIA_STREAMER_ERROR_NONE) { bundle_add_str(param_list, param->param_name, string_val); + MS_SAFE_FREE(string_val); + } } } + g_list_free(p_list); + return ret; } @@ -752,6 +763,8 @@ int __ms_node_get_param_value(media_streamer_node_s *node, param_s *param, char string_val = g_value_dup_string(&value); *string_value = string_val; + + g_value_reset(&value); g_value_unset(&value); return ret; } @@ -774,7 +787,7 @@ int __ms_node_set_param_value(media_streamer_node_s *ms_node, param_s *param, co /* v4l2src have string property 'device' with value /dev/video[0-n]. */ gchar *camera_device_str = g_strdup_printf("/dev/video%d", camera_id); g_object_set(ms_node->gst_element, param->origin_name, camera_device_str, NULL); - MS_SAFE_FREE(camera_device_str); + MS_SAFE_GFREE(camera_device_str); } else g_object_set(ms_node->gst_element, param->origin_name, camera_id, NULL); } else if (!g_strcmp0(param->param_name, MEDIA_STREAMER_PARAM_CAPTURE_WIDTH)) diff --git a/src/media_streamer_util.c b/src/media_streamer_util.c index 8f9a11f..dcb1d60 100644 --- a/src/media_streamer_util.c +++ b/src/media_streamer_util.c @@ -266,14 +266,16 @@ void __ms_signal_destroy(void *data) MS_SAFE_GFREE(sig_data); } -void __ms_rtp_param_value_destroy(gpointer data) +void __ms_param_value_destroy(gpointer data) { GValue *val = (GValue *)data; ms_retm_if(!data, "Empty object data!"); - if (GST_VALUE_HOLDS_CAPS(val)) + if (GST_VALUE_HOLDS_CAPS(val)) { gst_caps_unref(GST_CAPS(gst_value_get_caps(val))); - g_value_unset(val); + g_value_reset(val); + g_value_unset(val); + } MS_SAFE_GFREE(val); } diff --git a/test/media_streamer_test.c b/test/media_streamer_test.c index 09c6b1b..bf6aad6 100644 --- a/test/media_streamer_test.c +++ b/test/media_streamer_test.c @@ -1285,9 +1285,9 @@ void _interpret_autoplug_menu(char *cmd) { if (strlen(cmd) == 1) { if (cmd[0] == '2') - g_autoplug_mode = true; + g_autoplug_mode = TRUE; else - g_autoplug_mode = false; + g_autoplug_mode = FALSE; } else { g_print("Invalid input. Default autoplug mode will be used\n"); }