From 95071b0dc7e2841f1284f822de8d8c3a03bc496b Mon Sep 17 00:00:00 2001 From: Hyunil Date: Wed, 14 Feb 2018 16:29:04 +0900 Subject: [PATCH 01/16] Change the location of variable declarations and add dlog for call stack Change-Id: I38a61bbbbf2e6483a17ed811c320c1337511bbc9 Signed-off-by: Hyunil --- src/media_streamer_gst.c | 717 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 563 insertions(+), 154 deletions(-) diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index 502ec4e..d323c5f 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -51,9 +51,13 @@ void __ms_generate_dots(GstElement *bin, gchar *name_tag) static int __ms_add_no_target_ghostpad(GstElement *gst_bin, const char *ghost_pad_name, GstPadDirection pad_direction) { int ret = MEDIA_STREAMER_ERROR_NONE; + gchar *bin_name = NULL; + GstPad *ghost_pad = NULL; + + ms_debug_fenter(); - gchar *bin_name = gst_element_get_name(gst_bin); - GstPad *ghost_pad = gst_ghost_pad_new_no_target(ghost_pad_name, pad_direction); + bin_name = gst_element_get_name(gst_bin); + ghost_pad = gst_ghost_pad_new_no_target(ghost_pad_name, pad_direction); if (gst_element_add_pad(GST_ELEMENT(gst_bin), ghost_pad)) { gst_pad_set_active(ghost_pad, TRUE); ms_info("Added [%s] empty ghostpad into [%s]", ghost_pad_name, bin_name); @@ -63,17 +67,23 @@ static int __ms_add_no_target_ghostpad(GstElement *gst_bin, const char *ghost_pa } MS_SAFE_GFREE(bin_name); + + ms_debug_fleave(); + return ret; } static gboolean __ms_add_ghostpad(GstElement *gst_element, const char *pad_name, GstElement *gst_bin, const char *ghost_pad_name) { - ms_retvm_if(!gst_element || !pad_name || !ghost_pad_name || !gst_bin, FALSE, "Handle is NULL"); - gboolean ret = FALSE; - GstPad *ghost_pad = NULL; - GstPad *element_pad = gst_element_get_static_pad(gst_element, pad_name); + GstPad *element_pad = NULL; + + ms_debug_fenter(); + + ms_retvm_if(!gst_element || !pad_name || !ghost_pad_name || !gst_bin, FALSE, "Handle is NULL"); + + element_pad = gst_element_get_static_pad(gst_element, pad_name); /* Check, if pad is not static, get it by request */ if (element_pad == NULL) @@ -90,17 +100,24 @@ static gboolean __ms_add_ghostpad(GstElement *gst_element, const char *pad_name, ms_error("Error: element [%s] does not have valid [%s] pad for adding into [%s] bin", GST_ELEMENT_NAME(gst_element), pad_name, GST_ELEMENT_NAME(gst_bin)); MS_SAFE_UNREF(element_pad); + + ms_debug_fleave(); + return ret; } /* This unlinks from its peer and ghostpads on its way */ static gboolean __ms_pad_peer_unlink(GstPad *pad) { + gboolean ret = TRUE; + GstPad *peer_pad = NULL; + + ms_debug_fenter(); + if (!gst_pad_is_linked(pad)) return TRUE; - gboolean ret = TRUE; - GstPad *peer_pad = gst_pad_get_peer(pad); + peer_pad = gst_pad_get_peer(pad); ms_retvm_if(!peer_pad, FALSE, "Fail to get peer pad"); if (GST_IS_PROXY_PAD(peer_pad)) { @@ -135,20 +152,27 @@ static gboolean __ms_pad_peer_unlink(GstPad *pad) MS_SAFE_UNREF(peer_pad); + ms_debug_fleave(); + return ret; } static GstElement *__ms_pad_get_peer_element(GstPad *pad) { + GstPad *peer_pad = NULL; + GstElement *ret = NULL; + + ms_debug_fenter(); + if (!gst_pad_is_linked(pad)) { ms_info("Pad [%s:%s] is not linked yet", GST_DEBUG_PAD_NAME(pad)); return NULL; } - GstPad *peer_pad = gst_pad_get_peer(pad); + peer_pad = gst_pad_get_peer(pad); ms_retvm_if(!peer_pad, FALSE, "Fail to get peer pad"); - GstElement *ret = gst_pad_get_parent_element(peer_pad); + ret = gst_pad_get_parent_element(peer_pad); if (!ret) { if (GST_IS_PROXY_PAD(peer_pad)) { GstPad *ghost_pad = GST_PAD(gst_pad_get_parent(peer_pad)); @@ -174,6 +198,9 @@ static GstElement *__ms_pad_get_peer_element(GstPad *pad) } } MS_SAFE_UNREF(peer_pad); + + ms_debug_fleave(); + return ret; } @@ -182,8 +209,11 @@ gboolean __ms_element_unlink(GstElement *element) gboolean ret = TRUE; GstPad *pad = NULL; GValue elem = G_VALUE_INIT; + GstIterator *pad_iterator = NULL; - GstIterator *pad_iterator = gst_element_iterate_pads(element); + ms_debug_fenter(); + + pad_iterator = gst_element_iterate_pads(element); while (GST_ITERATOR_OK == gst_iterator_next(pad_iterator, &elem)) { pad = (GstPad *) g_value_get_object(&elem); ret = ret && __ms_pad_peer_unlink(pad); @@ -192,14 +222,20 @@ gboolean __ms_element_unlink(GstElement *element) g_value_unset(&elem); gst_iterator_free(pad_iterator); + ms_debug_fleave(); + return ret; } gboolean __ms_bin_remove_element(GstElement *element) { - GstElement *parent = (GstElement *) gst_element_get_parent(element); + GstElement *parent = NULL; gboolean ret = FALSE; + ms_debug_fenter(); + + parent = (GstElement *) gst_element_get_parent(element); + /* Remove node's element from bin that decreases ref count */ if (parent != NULL) { ret = gst_bin_remove(GST_BIN(parent), element); @@ -208,14 +244,21 @@ gboolean __ms_bin_remove_element(GstElement *element) } MS_SAFE_UNREF(parent); + + ms_debug_fleave(); + return ret; } gboolean __ms_bin_add_element(GstElement *bin, GstElement *element, gboolean do_ref) { - GstElement *parent = (GstElement *) gst_element_get_parent(element); + GstElement *parent = NULL; gboolean ret = FALSE; + ms_debug_fenter(); + + parent = (GstElement *) gst_element_get_parent(element); + /* Add node's element into bin and increases ref count if needed */ if (parent == NULL) { ret = gst_bin_add(GST_BIN(bin), element); @@ -226,15 +269,25 @@ gboolean __ms_bin_add_element(GstElement *bin, GstElement *element, gboolean do_ } MS_SAFE_UNREF(parent); + + ms_debug_fleave(); + return ret; } const gchar *__ms_get_pad_type(GstPad *element_pad) { const gchar *pad_type = NULL; - GstCaps *pad_caps = gst_pad_query_caps(element_pad, 0); + GstCaps *pad_caps = NULL; + + ms_debug_fenter(); + + pad_caps = gst_pad_query_caps(element_pad, 0); MS_GET_CAPS_TYPE(pad_caps, pad_type); gst_caps_unref(pad_caps); + + ms_debug_fleave(); + return pad_type; } @@ -245,6 +298,8 @@ static GstElement *__ms_find_peer_element_by_type(GstElement *previous_element, GValue src_pad_value = G_VALUE_INIT; const gchar *found_klass = NULL; + ms_debug_fenter(); + if (prev_elem_src_pad) { /* Check if previous element`s source pad is connected with element */ @@ -281,6 +336,8 @@ static GstElement *__ms_find_peer_element_by_type(GstElement *previous_element, if (!peer_element) ms_info(" Element [%s] is not connected", GST_ELEMENT_NAME(previous_element)); + ms_debug_fleave(); + return peer_element; } @@ -289,9 +346,14 @@ gboolean __ms_link_two_elements(GstElement *previous_element, GstPad *prev_elem_ GValue src_pad_value = G_VALUE_INIT; gboolean elements_linked = FALSE; GstPad * found_sink_pad = NULL; + GstElement *peer_element = NULL; + GstIterator *src_pad_iterator = NULL; + GstPad *src_pad = NULL; + + ms_debug_fenter(); if (prev_elem_src_pad) { - GstElement *peer_element = __ms_pad_get_peer_element(prev_elem_src_pad); + 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 */ @@ -305,9 +367,9 @@ gboolean __ms_link_two_elements(GstElement *previous_element, GstPad *prev_elem_ } else { /* Check if previous element has any unlinked src pad */ - GstIterator *src_pad_iterator = gst_element_iterate_src_pads(previous_element); + 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); + 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)) { @@ -340,6 +402,9 @@ gboolean __ms_link_two_elements(GstElement *previous_element, GstPad *prev_elem_ 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); + + ms_debug_fleave(); + return elements_linked; } @@ -348,11 +413,14 @@ static GstElement *__ms_bin_find_element_by_type(GstElement *previous_element, G GValue element_value = G_VALUE_INIT; GstElement *found_element = NULL; gboolean elements_linked = FALSE; + const gchar *found_klass = NULL; + + ms_debug_fenter(); GstIterator *bin_iterator = gst_bin_iterate_sorted(GST_BIN(search_bin)); while (GST_ITERATOR_OK == gst_iterator_next(bin_iterator, &element_value)) { found_element = (GstElement *) g_value_get_object(&element_value); - const gchar *found_klass = gst_element_factory_get_klass(gst_element_get_factory(found_element)); + found_klass = gst_element_factory_get_klass(gst_element_get_factory(found_element)); /* Check if found element is of appropriate needed plugin class */ if (g_strrstr(found_klass, node_klass_type->klass_name) || g_strrstr(GST_ELEMENT_NAME(found_element), node_klass_type->default_name)) { @@ -369,22 +437,30 @@ static GstElement *__ms_bin_find_element_by_type(GstElement *previous_element, G g_value_unset(&element_value); gst_iterator_free(bin_iterator); + ms_debug_fleave(); + return elements_linked ? found_element : NULL; } int __ms_factory_rank_compare(GstPluginFeature * first_feature, GstPluginFeature * second_feature) { + ms_debug_fenter(); + ms_debug_fleave(); return (gst_plugin_feature_get_rank(second_feature) - gst_plugin_feature_get_rank(first_feature)); } GstElement *__ms_combine_next_element(GstElement *previous_element, GstPad *prev_elem_src_pad, GstElement *bin_to_find_in, media_streamer_node_type_e node_type) { + GstCaps *prev_caps = NULL; + GstElement *found_element = NULL; + node_info_s *node_klass_type = NULL; + + ms_debug_fenter(); + if (!previous_element) return NULL; - GstCaps *prev_caps = NULL; - GstElement *found_element = NULL; - node_info_s *node_klass_type = __ms_node_get_klass_by_its_type(node_type); + node_klass_type = __ms_node_get_klass_by_its_type(node_type); /* - 1 - If previous element is linked - check for peer element */ found_element = __ms_find_peer_element_by_type(GST_ELEMENT(previous_element), prev_elem_src_pad, node_klass_type); @@ -428,6 +504,8 @@ GstElement *__ms_combine_next_element(GstElement *previous_element, GstPad *prev MS_SAFE_UNREF(previous_element); + ms_debug_fleave(); + return found_element; } @@ -439,14 +517,16 @@ static gint __decodebin_autoplug_select_cb(GstElement * bin, GstPad * pad, GstCa GST_AUTOPLUG_SELECT_EXPOSE, GST_AUTOPLUG_SELECT_SKIP } GstAutoplugSelectResult; - - media_streamer_s *ms_streamer = (media_streamer_s *) data; - ms_retvm_if(!ms_streamer, GST_AUTOPLUG_SELECT_TRY, "Handle is NULL"); - + media_streamer_s *ms_streamer = NULL; gchar *factory_name = NULL; const gchar *klass = NULL; GstAutoplugSelectResult result = GST_AUTOPLUG_SELECT_TRY; + ms_debug_fenter(); + + ms_streamer = (media_streamer_s *) data; + ms_retvm_if(!ms_streamer, GST_AUTOPLUG_SELECT_TRY, "Handle is NULL"); + factory_name = GST_OBJECT_NAME(factory); klass = gst_element_factory_get_metadata(factory, GST_ELEMENT_METADATA_KLASS); @@ -459,6 +539,8 @@ static gint __decodebin_autoplug_select_cb(GstElement * bin, GstPad * pad, GstCa for ( ; ms_streamer->ini.exclude_elem_names[index]; ++index) { if (g_strrstr(factory_name, ms_streamer->ini.exclude_elem_names[index])) { ms_debug("Decodebin: skipping [%s] as excluded", factory_name); + ms_debug_fleave(); + return GST_AUTOPLUG_SELECT_SKIP; } } @@ -497,16 +579,27 @@ static gint __decodebin_autoplug_select_cb(GstElement * bin, GstPad * pad, GstCa } } + ms_debug_fleave(); + return result; } static gint __pad_type_compare(gconstpointer a, gconstpointer b) { - GstPad *a_pad = GST_PAD(a); - GstPad *b_pad = GST_PAD(b); + GstPad *a_pad = NULL; + GstPad *b_pad = NULL; + const gchar *a_pad_type = NULL; + const gchar *b_pad_type = NULL; + + ms_debug_fenter(); + + a_pad = GST_PAD(a); + b_pad = GST_PAD(b); + + a_pad_type = __ms_get_pad_type(a_pad); + b_pad_type = __ms_get_pad_type(b_pad); - const gchar *a_pad_type = __ms_get_pad_type(a_pad); - const gchar *b_pad_type = __ms_get_pad_type(b_pad); + ms_debug_fleave(); if (MS_ELEMENT_IS_TEXT(a_pad_type)) return -1; @@ -518,7 +611,11 @@ static gint __pad_type_compare(gconstpointer a, gconstpointer b) static void __decodebin_newpad_cb(GstElement * decodebin, GstPad * new_pad, gpointer user_data) { - media_streamer_s *ms_streamer = (media_streamer_s *) user_data; + media_streamer_s *ms_streamer = NULL; + + ms_debug_fenter(); + + ms_streamer = (media_streamer_s *) user_data; ms_retm_if(ms_streamer == NULL, "Handle is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -527,12 +624,19 @@ static void __decodebin_newpad_cb(GstElement * decodebin, GstPad * new_pad, gpoi ms_streamer->pads_types_list = g_list_insert_sorted(ms_streamer->pads_types_list, new_pad, __pad_type_compare); g_mutex_unlock(&ms_streamer->mutex_lock); + + ms_debug_fleave(); } static void __decodebin_nomore_pads_combine(GstPad *src_pad, media_streamer_s *ms_streamer, media_streamer_sink_bin_type_e sink_bin_type) { - GstElement *found_element = gst_pad_get_parent_element(src_pad); - const gchar *new_pad_type = __ms_get_pad_type(src_pad); + GstElement *found_element = NULL; + const gchar *new_pad_type = NULL; + + ms_debug_fenter(); + + found_element = gst_pad_get_parent_element(src_pad); + new_pad_type = __ms_get_pad_type(src_pad); if (MS_ELEMENT_IS_VIDEO(new_pad_type)) { if (__ms_bin_find_element_by_type(found_element, src_pad, ms_streamer->transform_bin, __ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY))) { @@ -571,21 +675,33 @@ static void __decodebin_nomore_pads_combine(GstPad *src_pad, media_streamer_s *m __ms_generate_dots(ms_streamer->pipeline, "after_sink_linked"); gst_object_unref(found_element); + + ms_debug_fleave(); } static void __decodebin_nomore_pads_cb(GstElement *decodebin, gpointer user_data) { - media_streamer_s *ms_streamer = (media_streamer_s *) user_data; + media_streamer_s *ms_streamer = NULL; + media_streamer_sink_bin_type_e sink_bin_type = MEDIA_STREAMER_SINK_BIN_NORMAL; + media_streamer_node_s *rtp_node = NULL; + media_streamer_node_s *adaptive_sink = NULL; + char *decodebin_name = NULL; + char *param_value = NULL; + GList *iterator = NULL; + GList *list = NULL; + GstPad *src_pad = NULL; + + ms_debug_fenter(); + + ms_streamer = (media_streamer_s *) user_data; ms_retm_if(ms_streamer == NULL, "Handle is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); - media_streamer_sink_bin_type_e sink_bin_type = MEDIA_STREAMER_SINK_BIN_NORMAL; - media_streamer_node_s *rtp_node = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "rtp_container"); - media_streamer_node_s *adaptive_sink = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_sink"); + rtp_node = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "rtp_container"); + adaptive_sink = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_sink"); if (rtp_node) { - char *decodebin_name = NULL; g_object_get(G_OBJECT(decodebin), "name", &decodebin_name, NULL); /* FIXME: This case may be not general */ @@ -594,7 +710,6 @@ static void __decodebin_nomore_pads_cb(GstElement *decodebin, gpointer user_data MS_SAFE_FREE(decodebin_name); } else { /* It`s server part of Streaming Scenario*/ - char *param_value = NULL; media_streamer_node_get_param(rtp_node, MEDIA_STREAMER_PARAM_VIDEO_OUT_PORT, ¶m_value); if (param_value && (strtol(param_value, NULL, 10) > 0)) sink_bin_type = MEDIA_STREAMER_SINK_BIN_RTP_SERVER; @@ -606,21 +721,27 @@ static void __decodebin_nomore_pads_cb(GstElement *decodebin, gpointer user_data sink_bin_type = MEDIA_STREAMER_SINK_BIN_ADAPTIVE; } - GList *iterator = NULL; - GList *list = ms_streamer->pads_types_list; + iterator = NULL; + list = ms_streamer->pads_types_list; for (iterator = list; iterator; iterator = iterator->next) { - GstPad *src_pad = GST_PAD(iterator->data); + src_pad = GST_PAD(iterator->data); __decodebin_nomore_pads_combine(src_pad, ms_streamer, sink_bin_type); } g_mutex_unlock(&ms_streamer->mutex_lock); + + ms_debug_fleave(); } GstElement *__ms_decodebin_create(media_streamer_s * ms_streamer, char * name) { + GstElement *decodebin = NULL; + + ms_debug_fenter(); + ms_retvm_if(!ms_streamer, NULL, "Handle is NULL"); - GstElement *decodebin = __ms_element_create(DEFAULT_DECODEBIN, name); + decodebin = __ms_element_create(DEFAULT_DECODEBIN, name); __ms_bin_add_element(ms_streamer->transform_bin, decodebin, TRUE); gst_element_sync_state_with_parent(decodebin); @@ -628,6 +749,8 @@ GstElement *__ms_decodebin_create(media_streamer_s * ms_streamer, char * name) __ms_signal_create(&ms_streamer->autoplug_sig_list, decodebin, "autoplug-select", G_CALLBACK(__decodebin_autoplug_select_cb), ms_streamer); __ms_signal_create(&ms_streamer->autoplug_sig_list, decodebin, "no-more-pads", G_CALLBACK(__decodebin_nomore_pads_cb), ms_streamer); + ms_debug_fleave(); + return decodebin; } @@ -635,9 +758,12 @@ static gboolean __ms_sink_bin_prepare(media_streamer_s * ms_streamer, GstPad * s { GstElement *decoder_element = NULL; GstElement *found_element = NULL; + GstElement *parent_rtp_element = NULL; + + ms_debug_fenter(); /* Getting Depayloader */ - GstElement *parent_rtp_element = gst_pad_get_parent_element(source_pad); + parent_rtp_element = gst_pad_get_parent_element(source_pad); if (MS_ELEMENT_IS_VIDEO(src_pad_type)) { gst_object_ref(parent_rtp_element); @@ -650,6 +776,9 @@ static gboolean __ms_sink_bin_prepare(media_streamer_s * ms_streamer, GstPad * s gst_object_ref(found_element); __ms_link_two_elements(found_element, NULL, decoder_element); MS_SAFE_UNREF(decoder_element); + + ms_debug_fleave(); + return TRUE; } else { gst_object_ref(found_element); @@ -671,14 +800,20 @@ static gboolean __ms_sink_bin_prepare(media_streamer_s * ms_streamer, GstPad * s MS_SAFE_UNREF(found_element); MS_SAFE_UNREF(parent_rtp_element); + ms_debug_fleave(); + return TRUE; } static void __ms_rtpbin_pad_added_cb(GstElement * src, GstPad * new_pad, gpointer user_data) { + media_streamer_node_s *ms_node = NULL; + + ms_debug_fenter(); + ms_debug("Pad [%s] added on [%s]", GST_PAD_NAME(new_pad), GST_ELEMENT_NAME(src)); - media_streamer_node_s *ms_node = (media_streamer_node_s *) user_data; + ms_node = (media_streamer_node_s *) user_data; ms_retm_if(ms_node == NULL, "Handle is NULL"); if (g_str_has_prefix(GST_PAD_NAME(new_pad), "recv_rtp_src")) { @@ -721,37 +856,58 @@ static void __ms_rtpbin_pad_added_cb(GstElement * src, GstPad * new_pad, gpointe gst_caps_unref(src_pad_caps); MS_SAFE_UNREF(target_pad); } + + ms_debug_fleave(); } int __ms_element_set_state(GstElement * gst_element, GstState gst_state) { - ms_retvm_if(gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - GstStateChangeReturn ret_state; + ms_debug_fenter(); + + ms_retvm_if(gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ret_state = gst_element_set_state(gst_element, gst_state); + if (ret_state == GST_STATE_CHANGE_FAILURE) { ms_error("Failed to set element [%s] into %s state", GST_ELEMENT_NAME(gst_element), gst_element_state_get_name(gst_state)); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } GstElement *__ms_element_create(const char *plugin_name, const char *name) { GstElement *plugin_elem = NULL; + + ms_debug_fenter(); + ms_retvm_if(plugin_name == NULL, (GstElement *) NULL, "Error empty plugin name"); + ms_info("Creating [%s] element", plugin_name); + plugin_elem = gst_element_factory_make(plugin_name, name); ms_retvm_if(plugin_elem == NULL, (GstElement *) NULL, "Error creating element [%s]", plugin_name); + + ms_debug_fleave(); + return plugin_elem; } static void __hlsdemux_pad_added_cb(GstElement *demux, GstPad *pad, gpointer data) { - GstPad *gp = GST_PAD(data); + GstPad *gp = NULL; + + ms_debug_fenter(); + + gp = GST_PAD(data); gst_ghost_pad_set_target(GST_GHOST_PAD(gp), pad); + + ms_debug_fleave(); } static int __ms_adaptive_sink_prepare(media_streamer_s * ms_streamer) @@ -761,20 +917,38 @@ static int __ms_adaptive_sink_prepare(media_streamer_s * ms_streamer) {"Codec/Encoder/Audio", "audio_encoder"}, /* MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER */ {"Codec/Muxer", "mpegtsmux"}, /* MEDIA_STREAMER_NODE_TYPE_MUXER */ }; - - GstCaps *video_enc_src_caps = gst_caps_new_simple("video/mpeg", "mpegversion", G_TYPE_INT, 4, NULL); - GstCaps *video_enc_sink_caps = gst_caps_new_empty_simple("video/x-raw"); - node_plug_s video_enc_plug_info = {&(nodes_info[0]), video_enc_src_caps, video_enc_sink_caps, NULL}; - GstElement *video_enc = __ms_node_element_create(&video_enc_plug_info, MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER); - - GstCaps *audio_enc_src_caps = gst_caps_new_simple("audio/mpeg", "mpegversion", G_TYPE_INT, 4, NULL); - GstCaps *audio_enc_sink_caps = gst_caps_new_empty_simple("audio/x-raw"); - node_plug_s audio_enc_plug_info = {&(nodes_info[1]), audio_enc_src_caps, audio_enc_sink_caps, NULL}; - GstElement *audio_enc = __ms_node_element_create(&audio_enc_plug_info, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); - - GstCaps *muxer_src_caps = gst_caps_new_empty_simple("video/mpegts"); - node_plug_s mux_plug_info = {&(nodes_info[2]), muxer_src_caps, NULL, NULL}; - GstElement *muxer = __ms_node_element_create(&mux_plug_info, MEDIA_STREAMER_NODE_TYPE_MUXER); + GstCaps *video_enc_src_caps = NULL; + GstCaps *video_enc_sink_caps = NULL; + GstCaps *audio_enc_src_caps = NULL; + GstCaps *audio_enc_sink_caps = NULL; + GstElement *audio_enc = NULL; + GstElement *video_enc = NULL; + GstCaps *muxer_src_caps = NULL; + GstElement *muxer = NULL; + node_plug_s video_enc_plug_info = {0, }; + node_plug_s audio_enc_plug_info = {0, }; + node_plug_s mux_plug_info = {0, }; + + ms_debug_fenter(); + + video_enc_src_caps = gst_caps_new_simple("video/mpeg", "mpegversion", G_TYPE_INT, 4, NULL); + video_enc_sink_caps = gst_caps_new_empty_simple("video/x-raw"); + video_enc_plug_info.info = &(nodes_info[0]); + video_enc_plug_info.src_caps = video_enc_src_caps; + video_enc_plug_info.sink_caps = video_enc_sink_caps; + video_enc = __ms_node_element_create(&video_enc_plug_info, MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER); + + audio_enc_src_caps = gst_caps_new_simple("audio/mpeg", "mpegversion", G_TYPE_INT, 4, NULL); + audio_enc_sink_caps = gst_caps_new_empty_simple("audio/x-raw"); + audio_enc_plug_info.info = &(nodes_info[1]); + audio_enc_plug_info.src_caps = audio_enc_src_caps; + audio_enc_plug_info.sink_caps = audio_enc_sink_caps; + audio_enc = __ms_node_element_create(&audio_enc_plug_info, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); + + muxer_src_caps = gst_caps_new_empty_simple("video/mpegts"); + mux_plug_info.info = &(nodes_info[2]); + mux_plug_info.src_caps = muxer_src_caps; + muxer = __ms_node_element_create(&mux_plug_info, MEDIA_STREAMER_NODE_TYPE_MUXER); __ms_bin_add_element(ms_streamer->transform_bin, muxer, FALSE); gst_element_sync_state_with_parent(muxer); @@ -783,12 +957,18 @@ static int __ms_adaptive_sink_prepare(media_streamer_s * ms_streamer) __ms_bin_add_element(ms_streamer->transform_bin, audio_enc, FALSE); gst_element_sync_state_with_parent(audio_enc); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } GstElement *__ms_adaptive_element_create(void) { - GstElement *adaptive_bin = gst_bin_new("adaptive_src"); + GstElement *adaptive_bin = NULL; + + ms_debug_fenter(); + + adaptive_bin = gst_bin_new("adaptive_src"); ms_retvm_if(!adaptive_bin, (GstElement *) NULL, "Error: creating elements for adaptive source"); __ms_add_no_target_ghostpad(adaptive_bin, "src", GST_PAD_SRC); @@ -796,6 +976,8 @@ GstElement *__ms_adaptive_element_create(void) /* Add adaptive node parameters as GObject data with destroy function */ MS_SET_INT_STATIC_STRING_PARAM(adaptive_bin, MEDIA_STREAMER_PARAM_URI, "http://localhost"); + ms_debug_fleave(); + return adaptive_bin; } @@ -804,10 +986,15 @@ static GstElement *__ms_manifest_src_create(media_streamer_node_s *ms_node) char *manifest_src_name = NULL; gchar *location = NULL; GstElement *manifest_src = NULL; + GValue *val = NULL; + const char *uri = NULL; + gchar *protocol = NULL; + + ms_debug_fenter(); - GValue *val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), MEDIA_STREAMER_PARAM_URI); - const char *uri = g_value_get_string(val); - gchar *protocol = gst_uri_is_valid(uri) ? gst_uri_get_protocol(uri) : NULL; + val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), MEDIA_STREAMER_PARAM_URI); + uri = g_value_get_string(val); + protocol = gst_uri_is_valid(uri) ? gst_uri_get_protocol(uri) : NULL; if (protocol && g_strrstr(protocol, "http")) { manifest_src_name = __ms_ini_get_string("node type 1:http", DEFAULT_HTTP_SOURCE); @@ -846,6 +1033,8 @@ static GstElement *__ms_manifest_src_create(media_streamer_node_s *ms_node) g_object_set(manifest_src, "location", location, NULL); g_free(location); + ms_debug_fleave(); + return manifest_src; } @@ -857,6 +1046,8 @@ int __ms_adaptive_element_prepare(media_streamer_node_s *ms_node, bool auto_plug gboolean res = FALSE; GstPad *gp = NULL; + ms_debug_fenter(); + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); if (!auto_plug) { @@ -899,21 +1090,29 @@ int __ms_adaptive_element_prepare(media_streamer_node_s *ms_node, bool auto_plug gst_ghost_pad_set_target(GST_GHOST_PAD(gp), manifest_src_pad); } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } static gboolean __ms_feature_node_filter(GstPluginFeature *feature, gpointer data) { - node_plug_s *plug_info = (node_plug_s*)data; + node_plug_s *plug_info = NULL; + gboolean can_accept = FALSE; + gboolean src_can_accept = FALSE; + gboolean sink_can_accept = FALSE; + GstElementFactory *factory = NULL; + const gchar *factory_klass = NULL; + + ms_debug_fenter(); + + plug_info = (node_plug_s*)data; if (!GST_IS_ELEMENT_FACTORY(feature)) return FALSE; - gboolean can_accept = FALSE; - gboolean src_can_accept = FALSE; - gboolean sink_can_accept = FALSE; - GstElementFactory *factory = GST_ELEMENT_FACTORY(feature); - const gchar *factory_klass = gst_element_factory_get_klass(factory); + factory = GST_ELEMENT_FACTORY(feature); + factory_klass = gst_element_factory_get_klass(factory); if (plug_info && g_strrstr(factory_klass, plug_info->info->klass_name)) { if (GST_IS_CAPS(plug_info->src_caps)) @@ -944,6 +1143,8 @@ static gboolean __ms_feature_node_filter(GstPluginFeature *feature, gpointer dat } + ms_debug_fleave(); + return FALSE; } @@ -951,13 +1152,16 @@ static GstElement *__ms_element_create_from_ini(node_plug_s *plug_info, media_st { const gchar *src_type, *sink_type; const gchar *format_type; + GstElement *gst_element = NULL; + gchar conf_key[INI_MAX_STRLEN] = {0,}; + gchar *plugin_name = NULL; + + ms_debug_fenter(); MS_GET_CAPS_TYPE(plug_info->src_caps, src_type); MS_GET_CAPS_TYPE(plug_info->sink_caps, sink_type); - GstElement *gst_element = NULL; ms_info("Specified node formats types: in[%s] - out[%s]", sink_type, src_type); - gchar conf_key[INI_MAX_STRLEN] = {0,}; if (type == MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER) { format_type = src_type; @@ -982,30 +1186,40 @@ static GstElement *__ms_element_create_from_ini(node_plug_s *plug_info, media_st ms_error("Failed to generate config field name, size >= %d", INI_MAX_STRLEN); return NULL; } - gchar *plugin_name = __ms_ini_get_string(conf_key, NULL); + + plugin_name = __ms_ini_get_string(conf_key, NULL); if (plugin_name) { gst_element = __ms_element_create(plugin_name, NULL); MS_SAFE_GFREE(plugin_name); } + + ms_debug_fleave(); + return gst_element; } static GstElement *__ms_element_create_by_registry(node_plug_s *plug_info, media_streamer_node_type_e type) { GstElement *gst_element = NULL; - const gchar *src_type, *sink_type; + const gchar *src_type = NULL; + const gchar *sink_type = NULL; + GList *factories = NULL; + GstElementFactory *factory = NULL; + + ms_debug_fenter(); + MS_GET_CAPS_TYPE(plug_info->src_caps, src_type); MS_GET_CAPS_TYPE(plug_info->sink_caps, sink_type); __ms_ini_read_list("general:exclude elements", &plug_info->exclude_names); - GList *factories = gst_registry_feature_filter(gst_registry_get(), + factories = gst_registry_feature_filter(gst_registry_get(), __ms_feature_node_filter, FALSE, plug_info); factories = g_list_sort(factories, (GCompareFunc) __ms_factory_rank_compare); if (factories) { - GstElementFactory *factory = GST_ELEMENT_FACTORY(factories->data); + factory = GST_ELEMENT_FACTORY(factories->data); gst_element = __ms_element_create(GST_OBJECT_NAME(factory), NULL); } else { ms_debug("Could not find any compatible element for node [%d]: in[%s] - out[%s]", @@ -1015,14 +1229,18 @@ static GstElement *__ms_element_create_by_registry(node_plug_s *plug_info, media g_strfreev(plug_info->exclude_names); gst_plugin_list_free(factories); + ms_debug_fleave(); + return gst_element; } GstElement *__ms_node_element_create(node_plug_s *plug_info, media_streamer_node_type_e type) { GstElement *gst_element = NULL; + const gchar *src_type = NULL; + const gchar *sink_type = NULL; - const gchar *src_type, *sink_type; + ms_debug_fenter(); MS_GET_CAPS_TYPE(plug_info->src_caps, src_type); MS_GET_CAPS_TYPE(plug_info->sink_caps, sink_type); @@ -1060,6 +1278,8 @@ GstElement *__ms_node_element_create(node_plug_s *plug_info, media_streamer_node gst_element = __ms_element_create_by_registry(plug_info, type); } + ms_debug_fleave(); + return gst_element; } @@ -1076,8 +1296,11 @@ GstElement *__ms_video_encoder_element_create(node_plug_s *plug_info, media_stre node_plug_s parser_info = {0,}; node_info_s node_info = {MEDIA_STREAMER_PARSER_KLASS, DEFAULT_VIDEO_PARSER}; media_format_mimetype_e encoder_type = MEDIA_FORMAT_MAX; + GstCaps *enc_caps = NULL; + + ms_debug_fenter(); - GstCaps *enc_caps = plug_info->src_caps; + enc_caps = plug_info->src_caps; if (!enc_caps) { enc_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_VIDEO_FORMAT); ms_debug("No Video encoding format is set! Deafault will be: [%s]", MEDIA_STREAMER_DEFAULT_VIDEO_FORMAT); @@ -1138,6 +1361,8 @@ GstElement *__ms_video_encoder_element_create(node_plug_s *plug_info, media_stre __ms_add_ghostpad(encoder_parser, "src", encoder_bin, "src"); __ms_add_ghostpad(video_convert, "sink", encoder_bin, "sink"); + ms_debug_fleave(); + return encoder_bin; ERROR: @@ -1148,6 +1373,8 @@ ERROR: MS_SAFE_UNREF(encoder_parser); MS_SAFE_UNREF(encoder_bin); + ms_debug_fleave(); + return NULL; } @@ -1167,8 +1394,11 @@ GstElement *__ms_video_decoder_element_create(node_plug_s *plug_info, media_stre media_format_mimetype_e decoder_type = MEDIA_FORMAT_MAX; gboolean gst_ret = FALSE; const gchar *sink_type = NULL; + GstCaps *dec_caps = NULL; - GstCaps *dec_caps = plug_info->sink_caps; + ms_debug_fenter(); + + dec_caps = plug_info->sink_caps; if (!dec_caps) { dec_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_VIDEO_FORMAT); ms_debug("No Video decoding format is set! Deafault will be: [%s]", MEDIA_STREAMER_DEFAULT_VIDEO_FORMAT); @@ -1220,6 +1450,7 @@ GstElement *__ms_video_decoder_element_create(node_plug_s *plug_info, media_stre MS_SAFE_UNREF(decoder_bin); return NULL; } + last_elem = decoder_elem; if (!is_hw_codec) { @@ -1243,6 +1474,8 @@ GstElement *__ms_video_decoder_element_create(node_plug_s *plug_info, media_stre __ms_add_ghostpad(last_elem, "src", decoder_bin, "src"); __ms_add_ghostpad(decoder_queue, "sink", decoder_bin, "sink"); + ms_debug_fleave(); + return decoder_bin; ERROR: @@ -1254,6 +1487,8 @@ ERROR: MS_SAFE_UNREF(video_scale); MS_SAFE_UNREF(decoder_bin); + ms_debug_fleave(); + return NULL; } @@ -1269,8 +1504,11 @@ GstElement *__ms_audio_encoder_element_create(node_plug_s *plug_info, media_stre node_plug_s plug_info_encoder = {0,}; gchar *encoder_name = NULL; GstCaps *audioCaps = NULL; + GstCaps *enc_caps = NULL; + + ms_debug_fenter(); - GstCaps *enc_caps = plug_info->src_caps; + enc_caps = plug_info->src_caps; if (!enc_caps) { enc_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_AUDIO_FORMAT); ms_debug("No Audio encoding format is set! Deafault will be: [%s]", MEDIA_STREAMER_DEFAULT_AUDIO_FORMAT); @@ -1319,7 +1557,10 @@ GstElement *__ms_audio_encoder_element_create(node_plug_s *plug_info, media_stre __ms_add_ghostpad(audio_encoder, "src", audio_enc_bin, "src"); __ms_add_ghostpad(audio_convert, "sink", audio_enc_bin, "sink"); + ms_debug_fleave(); + return audio_enc_bin; + ERROR: MS_SAFE_UNREF(audio_convert); @@ -1329,6 +1570,8 @@ ERROR: MS_SAFE_UNREF(audio_encoder); MS_SAFE_UNREF(audio_enc_bin); + ms_debug_fleave(); + return NULL; } @@ -1345,8 +1588,11 @@ GstElement *__ms_audio_decoder_element_create(node_plug_s *plug_info, media_stre node_plug_s decoder_info = {0,}; node_plug_s parser_info = {0,}; node_info_s nodes_info = {MEDIA_STREAMER_PARSER_KLASS, DEFAULT_AUDIO_PARSER}; + GstCaps *dec_caps = NULL; + + ms_debug_fenter(); - GstCaps *dec_caps = plug_info->sink_caps; + dec_caps = plug_info->sink_caps; if (!dec_caps) { dec_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_AUDIO_FORMAT); ms_debug("No Audio decoding format is set! Deafault will be: [%s]", MEDIA_STREAMER_DEFAULT_AUDIO_FORMAT); @@ -1407,7 +1653,10 @@ GstElement *__ms_audio_decoder_element_create(node_plug_s *plug_info, media_stre __ms_add_ghostpad(audio_resample, "src", decoder_bin, "src"); __ms_add_ghostpad(decoder_queue, "sink", decoder_bin, "sink"); + ms_debug_fleave(); + return decoder_bin; + ERROR: MS_SAFE_UNREF(decoder_elem); @@ -1417,12 +1666,18 @@ ERROR: MS_SAFE_UNREF(audio_resample); MS_SAFE_UNREF(decoder_bin); + ms_debug_fleave(); + return NULL; } GstElement *__ms_rtp_element_create(void) { - GstElement *rtp_container = gst_bin_new("rtp_container"); + GstElement *rtp_container = NULL; + + ms_debug_fenter(); + + rtp_container = gst_bin_new("rtp_container"); ms_retvm_if(!rtp_container, (GstElement *) NULL, "Error: creating elements for rtp container"); __ms_add_no_target_ghostpad(rtp_container, MS_RTP_PAD_VIDEO_OUT, GST_PAD_SRC); @@ -1442,33 +1697,47 @@ GstElement *__ms_rtp_element_create(void) 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()); + ms_debug_fleave(); + return rtp_container; } gboolean __ms_rtp_element_prepare(media_streamer_node_s *ms_node) { + GstElement *rtpbin = NULL; + gboolean ret = TRUE; + GstElement *rtp_el = NULL; + GstElement *rtcp_el = NULL; + GValue *val = NULL; + const char *host = NULL; + GstElement *video_filter = NULL; + GstCaps *video_caps = NULL; + GstGhostPad *ghost_pad = NULL; + GstElement *audio_filter = NULL; + GstCaps *audio_caps = NULL; + + ms_debug_fenter(); + ms_retvm_if(!ms_node, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Handle is NULL"); - GstElement *rtpbin = __ms_element_create("rtpbin", "rtpbin"); + rtpbin = __ms_element_create("rtpbin", "rtpbin"); ms_retvm_if(!rtpbin, FALSE, "Error: creating elements for rtp container"); if (!__ms_bin_add_element(ms_node->gst_element, rtpbin, FALSE)) { MS_SAFE_UNREF(rtpbin); return FALSE; } - __ms_signal_create(&ms_node->sig_list, rtpbin, "pad-added", G_CALLBACK(__ms_rtpbin_pad_added_cb), ms_node); - gboolean ret = TRUE; - GstElement *rtp_el = NULL; - GstElement *rtcp_el = NULL; + __ms_signal_create(&ms_node->sig_list, rtpbin, "pad-added", G_CALLBACK(__ms_rtpbin_pad_added_cb), ms_node); - GValue *val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), MEDIA_STREAMER_PARAM_HOST); - const char *host = g_value_get_string(val); + val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), MEDIA_STREAMER_PARAM_HOST); + 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) { rtp_el = __ms_element_create("udpsrc", MS_RTP_PAD_VIDEO_IN"_rtp"); __ms_bin_add_element(ms_node->gst_element, rtp_el, FALSE); + rtcp_el = __ms_element_create("udpsrc", MS_RTP_PAD_VIDEO_IN"_rctp"); __ms_bin_add_element(ms_node->gst_element, rtcp_el, FALSE); @@ -1486,6 +1755,7 @@ gboolean __ms_rtp_element_prepare(media_streamer_node_s *ms_node) if (g_value_get_int(val) > RTP_STREAM_DISABLED) { rtp_el = __ms_element_create("udpsrc", MS_RTP_PAD_AUDIO_IN"_rtp"); __ms_bin_add_element(ms_node->gst_element, rtp_el, FALSE); + rtcp_el = __ms_element_create("udpsrc", MS_RTP_PAD_AUDIO_IN"_rctp"); __ms_bin_add_element(ms_node->gst_element, rtcp_el, FALSE); @@ -1503,17 +1773,20 @@ gboolean __ms_rtp_element_prepare(media_streamer_node_s *ms_node) if (g_value_get_int(val) > RTP_STREAM_DISABLED) { rtp_el = __ms_element_create("udpsink", MS_RTP_PAD_VIDEO_OUT"_rtp"); __ms_bin_add_element(ms_node->gst_element, rtp_el, FALSE); + rtcp_el = __ms_element_create("udpsink", MS_RTP_PAD_VIDEO_OUT"_rctp"); __ms_bin_add_element(ms_node->gst_element, rtcp_el, FALSE); - GstElement *video_filter = __ms_element_create("capsfilter", NULL); + video_filter = __ms_element_create("capsfilter", NULL); __ms_bin_add_element(ms_node->gst_element, video_filter, FALSE); - GstCaps *video_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_VIDEO_RTP_FORMAT); + + 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); + ghost_pad = (GstGhostPad *)gst_element_get_static_pad(ms_node->gst_element, MS_RTP_PAD_VIDEO_IN); if (ghost_pad) { if (gst_ghost_pad_set_target(ghost_pad, gst_element_get_static_pad(video_filter, "sink"))) ms_info(" Capsfilter for [%s] in RTP is set and linked", MS_RTP_PAD_VIDEO_IN); @@ -1534,23 +1807,24 @@ gboolean __ms_rtp_element_prepare(media_streamer_node_s *ms_node) if (g_value_get_int(val) > RTP_STREAM_DISABLED) { rtp_el = __ms_element_create("udpsink", MS_RTP_PAD_AUDIO_OUT"_rtp"); __ms_bin_add_element(ms_node->gst_element, rtp_el, FALSE); + rtcp_el = __ms_element_create("udpsink", MS_RTP_PAD_AUDIO_OUT"_rctp"); __ms_bin_add_element(ms_node->gst_element, rtcp_el, FALSE); - GstElement *audio_filter = __ms_element_create("capsfilter", NULL); + audio_filter = __ms_element_create("capsfilter", NULL); __ms_bin_add_element(ms_node->gst_element, audio_filter, FALSE); - GstCaps *audio_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_AUDIO_RTP_FORMAT); + + audio_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_AUDIO_RTP_FORMAT); g_object_set(G_OBJECT(audio_filter), "caps", audio_caps, NULL); + gst_element_link_pads(audio_filter, "src", rtpbin, "send_rtp_sink_1"); - GstGhostPad *ghost_pad = (GstGhostPad *)gst_element_get_static_pad(ms_node->gst_element, MS_RTP_PAD_AUDIO_IN); + ghost_pad = (GstGhostPad *)gst_element_get_static_pad(ms_node->gst_element, MS_RTP_PAD_AUDIO_IN); if (ghost_pad) { if (gst_ghost_pad_set_target(ghost_pad, gst_element_get_static_pad(audio_filter, "sink"))) ms_info(" Capsfilter for [%s] in RTP is set and linked", MS_RTP_PAD_AUDIO_IN); } - - ret = ret && gst_element_link_pads(rtpbin, "send_rtp_src_1", rtp_el, "sink"); ret = ret && gst_element_link_pads(rtpbin, "send_rtcp_src_1", rtcp_el, "sink"); @@ -1563,19 +1837,24 @@ gboolean __ms_rtp_element_prepare(media_streamer_node_s *ms_node) } __ms_generate_dots(ms_node->gst_element, "rtp_prepared"); + + ms_debug_fleave(); + return ret; } int __ms_add_node_into_bin(media_streamer_s *ms_streamer, media_streamer_node_s *ms_node) { int ret = MEDIA_STREAMER_ERROR_NONE; + GstElement *bin = NULL; + + ms_debug_fenter(); + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Handle is NULL"); ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Handle is NULL"); ms_info("Try to add [%s] node into streamer, node type/subtype [%d/%d]", ms_node->name, ms_node->type, ms_node->subtype); - GstElement *bin = NULL; - switch (ms_node->type) { case MEDIA_STREAMER_NODE_TYPE_SRC: bin = ms_streamer->src_bin; @@ -1594,16 +1873,21 @@ int __ms_add_node_into_bin(media_streamer_s *ms_streamer, media_streamer_node_s ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; } + ms_debug_fleave(); + return ret; } static gboolean __ms_parse_gst_error(media_streamer_s *ms_streamer, GstMessage *message, GError *error) { + media_streamer_error_e ret_error = MEDIA_STREAMER_ERROR_NONE; + + ms_debug_fenter(); + ms_retvm_if(!ms_streamer, FALSE, "Error: invalid Media Streamer handle."); ms_retvm_if(!error, FALSE, "Error: invalid error handle."); ms_retvm_if(!message, FALSE, "Error: invalid bus message handle."); - media_streamer_error_e ret_error = MEDIA_STREAMER_ERROR_NONE; if (error->domain == GST_CORE_ERROR) ret_error = MEDIA_STREAMER_ERROR_INVALID_OPERATION; else if (error->domain == GST_LIBRARY_ERROR) @@ -1621,19 +1905,26 @@ static gboolean __ms_parse_gst_error(media_streamer_s *ms_streamer, GstMessage * error_cb((media_streamer_h) ms_streamer, ret_error, ms_streamer->error_cb.user_data); } + ms_debug_fleave(); + return TRUE; } static GstPadProbeReturn __ms_element_event_probe(GstPad * pad, GstPadProbeInfo *info, gpointer user_data) { - GstElement *parent_element = gst_pad_get_parent_element(pad); - GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info); + GstElement *parent_element = NULL; + GstEvent *event = NULL; + + ms_debug_fenter(); + parent_element = gst_pad_get_parent_element(pad); if (!parent_element) { ms_error("filed to get parent_elem"); return GST_PAD_PROBE_PASS; } + event = GST_PAD_PROBE_INFO_EVENT(info); + if (GST_PAD_PROBE_INFO_TYPE(info) & GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM) { if (GST_EVENT_TYPE(event) == GST_EVENT_BUFFERSIZE) { GValue *val_ = (GValue *) g_object_get_data(G_OBJECT(parent_element), "pad_sink"); @@ -1642,23 +1933,34 @@ static GstPadProbeReturn __ms_element_event_probe(GstPad * pad, GstPadProbeInfo return GST_PAD_PROBE_OK; } } + MS_SAFE_UNREF(parent_element); + + ms_debug_fleave(); + return GST_PAD_PROBE_PASS; } gboolean __ms_element_lock_state(const GValue *item, GValue *ret, gpointer user_data) { - GstElement *sink_element = GST_ELEMENT(g_value_get_object(item)); - g_value_set_boolean(ret, FALSE); + GstElement *sink_element = NULL; + GstPad *sink_pad = NULL; + int probe_id = 0; + + ms_debug_fenter(); + + sink_element = GST_ELEMENT(g_value_get_object(item)); ms_retvm_if(!sink_element, FALSE, "Handle is NULL"); - GstPad *sink_pad = gst_element_get_static_pad(sink_element, "sink"); + g_value_set_boolean(ret, FALSE); + + sink_pad = gst_element_get_static_pad(sink_element, "sink"); if (!sink_pad) { ms_info("Failed to get static pad of element [%s]", GST_ELEMENT_NAME(sink_element)); return FALSE; } 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); + probe_id = gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, __ms_element_event_probe, NULL, NULL); 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 { @@ -1668,18 +1970,26 @@ gboolean __ms_element_lock_state(const GValue *item, GValue *ret, gpointer user_ g_value_set_boolean(ret, TRUE); + ms_debug_fleave(); + return TRUE; } gboolean __ms_element_unlock_state(const GValue *item, GValue *ret, gpointer user_data) { - GstElement *sink_element = GST_ELEMENT(g_value_get_object(item)); + GstElement *sink_element = NULL; + GValue *val = NULL; + GstPad *sink_pad = NULL; + + ms_debug_fenter(); + g_value_set_boolean(ret, FALSE); + sink_element = GST_ELEMENT(g_value_get_object(item)); ms_retvm_if(!sink_element, FALSE, "Handle is NULL"); - GValue *val = (GValue *) g_object_get_data(G_OBJECT(sink_element), "pad_sink"); + val = (GValue *) g_object_get_data(G_OBJECT(sink_element), "pad_sink"); if (val) { - GstPad *sink_pad = gst_element_get_static_pad(sink_element, "sink"); + sink_pad = gst_element_get_static_pad(sink_element, "sink"); if (!sink_pad) { ms_info("Failed to get static pad of element [%s]", GST_ELEMENT_NAME(sink_element)); return FALSE; @@ -1695,13 +2005,23 @@ gboolean __ms_element_unlock_state(const GValue *item, GValue *ret, gpointer use g_value_set_boolean(ret, TRUE); + ms_debug_fleave(); + return TRUE; } static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) { int ret = MEDIA_STREAMER_ERROR_NONE; - media_streamer_s *ms_streamer = (media_streamer_s *) userdata; + media_streamer_s *ms_streamer = NULL; + GError *err = NULL; + gchar *debug = NULL; + gchar *state_transition_name = NULL; + GstState state_old = 0, state_new = 0, state_pending = 0; + + ms_debug_fenter(); + + ms_streamer = (media_streamer_s *) userdata; ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); ms_retvm_if(ms_streamer->pipeline == NULL, MEDIA_STREAMER_ERROR_INVALID_STATE, "Pipeline doesn`t exist"); @@ -1709,8 +2029,6 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) if (message != NULL) { switch (GST_MESSAGE_TYPE(message)) { case GST_MESSAGE_ERROR:{ - GError *err = NULL; - gchar *debug = NULL; gst_message_parse_error(message, &err, &debug); /* Transform gst error code to media streamer error code. @@ -1726,9 +2044,6 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) case GST_MESSAGE_STATE_CHANGED:{ if (GST_MESSAGE_SRC(message) == GST_OBJECT(ms_streamer->pipeline)) { - GstState state_old, state_new, state_pending; - gchar *state_transition_name; - gst_message_parse_state_changed(message, &state_old, &state_new, &state_pending); state_transition_name = g_strdup_printf("Old_[%s]_New_[%s]_Pending_[%s]", gst_element_state_get_name(state_old), gst_element_state_get_name(state_new), gst_element_state_get_name(state_pending)); @@ -1793,18 +2108,25 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) break; } } + + ms_debug_fleave(); + return TRUE; } int __ms_pipeline_create(media_streamer_s *ms_streamer) { - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - GError *err = NULL; int ret = MEDIA_STREAMER_ERROR_NONE; - - int *argc = (int *)malloc(sizeof(int)); + int *argc = NULL; char **argv = NULL; + gboolean gst_ret = 0; + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + argc = (int *)malloc(sizeof(int)); if (!argc) { ms_error("Error allocation memory"); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; @@ -1835,7 +2157,7 @@ int __ms_pipeline_create(media_streamer_s *ms_streamer) } } - gboolean gst_ret = gst_init_check(argc, &argv, &err); + gst_ret = gst_init_check(argc, &argv, &err); /* Clean memory of gstreamer arguments*/ g_strfreev(ms_streamer->ini.gst_args); ms_streamer->ini.gst_args = NULL; @@ -1869,6 +2191,8 @@ int __ms_pipeline_create(media_streamer_s *ms_streamer) gst_bin_add_many(GST_BIN(ms_streamer->pipeline), ms_streamer->src_bin, ms_streamer->sink_bin, ms_streamer->transform_bin, NULL); ms_info("Media streamer pipeline created successfully."); + ms_debug_fleave(); + return ret; } @@ -1879,6 +2203,8 @@ GstCaps *__ms_create_caps_from_fmt(media_format_h fmt) media_format_mimetype_e mime; int width, height, avg_bps, max_bps, channel, samplerate, bit; + ms_debug_fenter(); + if (!media_format_get_audio_info(fmt, &mime, &channel, &samplerate, &bit, &avg_bps)) { if (MEDIA_FORMAT_RAW == (mime & MEDIA_FORMAT_RAW)) caps = gst_caps_new_simple("audio/x-raw", "channels", G_TYPE_INT, channel, "format", @@ -1913,6 +2239,9 @@ GstCaps *__ms_create_caps_from_fmt(media_format_h fmt) ms_error("Error getting media format information"); MS_SAFE_GFREE(caps_name); + + ms_debug_fleave(); + return caps; } @@ -1920,6 +2249,14 @@ media_format_h __ms_create_fmt_from_caps(GstCaps *caps) { media_format_h fmt; GstStructure *pad_struct; + int fmt_ret = MEDIA_FORMAT_ERROR_NONE; + const gchar *pad_type = NULL; + const gchar *pad_format = NULL; + int channels = 0, bps = 0; + int width = 0, height = 0, avg_bps = 0, max_bps = 0; + + ms_debug_fenter(); + ms_retvm_if(caps == NULL, NULL, "Error: empty caps!"); if (gst_caps_is_any(caps)) { @@ -1927,23 +2264,20 @@ media_format_h __ms_create_fmt_from_caps(GstCaps *caps) return NULL; } - int fmt_ret = MEDIA_FORMAT_ERROR_NONE; - fmt_ret = media_format_create(&fmt); ms_retvm_if(fmt_ret != MEDIA_FORMAT_ERROR_NONE, NULL, "Error: while creating media format object, err[%d]!", fmt_ret); pad_struct = gst_caps_get_structure(caps, 0); - const gchar *pad_type = gst_structure_get_name(pad_struct); - const gchar *pad_format = pad_type; + pad_type = gst_structure_get_name(pad_struct); + pad_format = pad_type; /* Got raw format type if needed */ if (g_strrstr(pad_type, "/x-raw")) pad_format = gst_structure_get_string(pad_struct, "format"); ms_debug("Pad type is [%s], format: [%s]", pad_type, pad_format); - if (MS_ELEMENT_IS_VIDEO(pad_type)) { - int width, height, avg_bps, max_bps; + if (MS_ELEMENT_IS_VIDEO(pad_type)) { gst_structure_get_int(pad_struct, "width", &width); gst_structure_get_fraction(pad_struct, "framerate", &max_bps, &avg_bps); gst_structure_get_int(pad_struct, "height", &height); @@ -1954,7 +2288,6 @@ media_format_h __ms_create_fmt_from_caps(GstCaps *caps) media_format_set_video_avg_bps(fmt, avg_bps); media_format_set_video_max_bps(fmt, max_bps); } else if (MS_ELEMENT_IS_AUDIO(pad_type)) { - int channels, bps; media_format_set_audio_mime(fmt, __ms_convert_string_format_to_media_format(pad_format)); gst_structure_get_int(pad_struct, "channels", &channels); media_format_set_audio_channel(fmt, channels); @@ -1962,18 +2295,22 @@ media_format_h __ms_create_fmt_from_caps(GstCaps *caps) media_format_set_audio_avg_bps(fmt, bps); } + ms_debug_fleave(); + return fmt; } int __ms_element_pad_names(GstElement *gst_element, GstPadDirection pad_type, char ***pad_name_array, int *pads_count) { int ret = MEDIA_STREAMER_ERROR_NONE; - int pad_number = 0; GValue elem = G_VALUE_INIT; GstPad *pad = NULL; char **pad_names = NULL; GstIterator *pad_iterator = NULL; + gchar *pad_name = NULL; + + ms_debug_fenter(); if (pad_type == GST_PAD_SRC) { pad_iterator = gst_element_iterate_src_pads(gst_element); @@ -1996,7 +2333,7 @@ int __ms_element_pad_names(GstElement *gst_element, GstPadDirection pad_type, ch break; } - gchar *pad_name = gst_pad_get_name(pad); + pad_name = gst_pad_get_name(pad); pad_names[pad_number] = pad_name; g_free(pad_name); ++pad_number; @@ -2012,6 +2349,8 @@ int __ms_element_pad_names(GstElement *gst_element, GstPadDirection pad_type, ch MS_SAFE_FREE(pad_names); + ms_debug_fleave(); + return ret; } @@ -2019,19 +2358,23 @@ int __ms_element_get_pad_fmt(GstElement *gst_element, const char *pad_name, medi { GstCaps *allowed_caps = NULL; GstCaps *format_caps = NULL; + GstPad *pad = NULL; + GValue *value = NULL; + int ret = MEDIA_STREAMER_ERROR_NONE; + + ms_debug_fenter(); ms_retvm_if(gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Element handle is NULL"); - GstPad *pad = gst_element_get_static_pad(gst_element, pad_name); + pad = gst_element_get_static_pad(gst_element, pad_name); ms_retvm_if(pad == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Fail to get pad [%s] from element [%s].", pad_name, GST_ELEMENT_NAME(gst_element)); - GValue *value = (GValue *) g_object_get_data(G_OBJECT(gst_element), pad_name); + value = (GValue *) g_object_get_data(G_OBJECT(gst_element), pad_name); if (value) format_caps = GST_CAPS(gst_value_get_caps(value)); else ms_info(" No any format is set for pad [%s]", pad_name); - int ret = MEDIA_STREAMER_ERROR_NONE; allowed_caps = gst_pad_get_allowed_caps(pad); if (allowed_caps) { if (gst_caps_is_empty(allowed_caps) || gst_caps_is_any(allowed_caps)) { @@ -2053,19 +2396,28 @@ int __ms_element_get_pad_fmt(GstElement *gst_element, const char *pad_name, medi gst_caps_unref(allowed_caps); MS_SAFE_UNREF(pad); + + ms_debug_fleave(); + return ret; } int __ms_element_set_fmt(media_streamer_node_s *node, const char *pad_name, media_format_h fmt) { - ms_retvm_if(!node || !pad_name || !fmt, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); gboolean can_accept = FALSE; + GstCaps *fmt_caps = NULL; + GstElementFactory *factory = NULL; + GstPad *node_pad = NULL; + + ms_debug_fenter(); - GstCaps *fmt_caps = __ms_create_caps_from_fmt(fmt); + ms_retvm_if(!node || !pad_name || !fmt, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + fmt_caps = __ms_create_caps_from_fmt(fmt); ms_retvm_if(!fmt_caps, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Can't convert fmt into Caps"); - GstElementFactory *factory = gst_element_get_factory(node->gst_element); - GstPad *node_pad = gst_element_get_static_pad(node->gst_element, pad_name); + factory = gst_element_get_factory(node->gst_element); + node_pad = gst_element_get_static_pad(node->gst_element, pad_name); if (node_pad && GST_PAD_IS_SRC(node_pad)) can_accept = gst_element_factory_can_src_any_caps(factory, fmt_caps); @@ -2086,21 +2438,28 @@ int __ms_element_set_fmt(media_streamer_node_s *node, const char *pad_name, medi MS_SAFE_UNREF(node_pad); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } gboolean __ms_gst_seek(GstElement *element, gint64 g_time, GstSeekFlags seek_flag) { gboolean result = FALSE; + GstEvent *event = NULL; + + ms_debug_fenter(); ms_retvm_if(element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Element is NULL"); - GstEvent *event = gst_event_new_seek(1.0, GST_FORMAT_TIME, seek_flag, - GST_SEEK_TYPE_SET, g_time, - GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE); + event = gst_event_new_seek(1.0, GST_FORMAT_TIME, seek_flag, + GST_SEEK_TYPE_SET, g_time, + GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE); if (event) result = gst_element_send_event(element, event); + ms_debug_fleave(); + return result; } @@ -2110,6 +2469,8 @@ int __ms_element_push_packet(GstElement *src_element, media_packet_h packet) GstFlowReturn gst_ret = GST_FLOW_OK; guchar *buffer_data = NULL; + ms_debug_fenter(); + ms_retvm_if(src_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); if (packet == NULL) { @@ -2155,6 +2516,8 @@ int __ms_element_push_packet(GstElement *src_element, media_packet_h packet) if (gst_ret != GST_FLOW_OK) return MEDIA_STREAMER_ERROR_INVALID_OPERATION; + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -2163,6 +2526,11 @@ int __ms_element_pull_packet(GstElement *sink_element, media_packet_h *packet) GstSample *sample = NULL; media_format_h fmt = NULL; int ret = MEDIA_STREAMER_ERROR_NONE; + guint8 *buffer_res = NULL; + GstMapInfo map = {0,}; + GstBuffer *buffer = NULL; + + ms_debug_fenter(); ms_retvm_if(sink_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); ms_retvm_if(packet == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); @@ -2173,9 +2541,7 @@ int __ms_element_pull_packet(GstElement *sink_element, media_packet_h *packet) ret = __ms_element_get_pad_fmt(sink_element, "sink", &fmt); if (ret == MEDIA_STREAMER_ERROR_NONE) { - GstMapInfo map; - guint8 *buffer_res = NULL; - GstBuffer *buffer = gst_sample_get_buffer(sample); + buffer = gst_sample_get_buffer(sample); if (!buffer) { ms_error("Failed to get buffer from sample"); media_format_unref(fmt); @@ -2201,12 +2567,19 @@ int __ms_element_pull_packet(GstElement *sink_element, media_packet_h *packet) media_format_unref(fmt); gst_sample_unref(sample); + + ms_debug_fleave(); + return ret; } static void __demux_newpad_cb(GstElement * demux, GstPad * new_pad, gpointer user_data) { - media_streamer_s *ms_streamer = (media_streamer_s *) user_data; + media_streamer_s *ms_streamer = NULL; + + ms_debug_fenter(); + + ms_streamer = (media_streamer_s *) user_data; ms_retm_if(ms_streamer == NULL, "Handle is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -2215,12 +2588,20 @@ static void __demux_newpad_cb(GstElement * demux, GstPad * new_pad, gpointer use ms_streamer->pads_types_list = g_list_insert_sorted(ms_streamer->pads_types_list, new_pad, __pad_type_compare); g_mutex_unlock(&ms_streamer->mutex_lock); + + ms_debug_fleave(); } static void __demux_nomore_pads_combine(GstPad *src_pad, media_streamer_s *ms_streamer) { - GstElement *found_element = gst_pad_get_parent_element(src_pad); - const gchar *new_pad_type = __ms_get_pad_type(src_pad); + GstElement *found_element = NULL; + const gchar *new_pad_type = NULL; + + ms_debug_fenter(); + + found_element = gst_pad_get_parent_element(src_pad); + new_pad_type = __ms_get_pad_type(src_pad); + if (MS_ELEMENT_IS_VIDEO(new_pad_type)) found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER); else if (MS_ELEMENT_IS_AUDIO(new_pad_type)) @@ -2232,43 +2613,62 @@ static void __demux_nomore_pads_combine(GstPad *src_pad, media_streamer_s *ms_st __ms_generate_dots(ms_streamer->pipeline, "after_demux_linked"); gst_object_unref(found_element); + + ms_debug_fleave(); } static void __demux_nomore_pads_cb(GstElement *demux, gpointer user_data) { - media_streamer_s *ms_streamer = (media_streamer_s *) user_data; + media_streamer_s *ms_streamer = NULL; + GList *iterator = NULL; + GList *list = NULL; + + ms_debug_fenter(); + + ms_streamer = (media_streamer_s *) user_data; ms_retm_if(ms_streamer == NULL, "Handle is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); - GList *iterator = NULL; - GList *list = ms_streamer->pads_types_list; + list = ms_streamer->pads_types_list; for (iterator = list; iterator; iterator = iterator->next) { GstPad *src_pad = GST_PAD(iterator->data); __demux_nomore_pads_combine(src_pad, ms_streamer); } g_mutex_unlock(&ms_streamer->mutex_lock); + + ms_debug_fleave(); } int __ms_demux_element_prepare(media_streamer_s * ms_streamer, media_streamer_node_s *demux_node) { + ms_debug_fenter(); + ms_retvm_if(!ms_streamer, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); ms_retvm_if(!demux_node, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); __ms_signal_create(&ms_streamer->autoplug_sig_list, demux_node->gst_element, "pad-added", G_CALLBACK(__demux_newpad_cb), ms_streamer); __ms_signal_create(&ms_streamer->autoplug_sig_list, demux_node->gst_element, "no-more-pads", G_CALLBACK(__demux_nomore_pads_cb), ms_streamer); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } static void __ms_typefound_cb(GstElement *typefind, guint probability, GstCaps *caps, gpointer data) { GstElement *decodebin = NULL; - media_streamer_s *ms_streamer = (media_streamer_s *) data; - media_streamer_node_s *adaptive_sink = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_sink"); - gchar *type; - GstPad *src_pad = gst_element_get_static_pad(typefind, "src"); + media_streamer_s *ms_streamer = NULL; + media_streamer_node_s *adaptive_sink = NULL; + gchar *type = NULL; + GstPad *src_pad = NULL; + + ms_debug_fenter(); + + ms_streamer = (media_streamer_s *) data; + adaptive_sink = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_sink"); + src_pad = gst_element_get_static_pad(typefind, "src"); type = gst_caps_to_string(caps); if (g_strrstr(type, "video/mpegts") && adaptive_sink) { @@ -2280,18 +2680,25 @@ static void __ms_typefound_cb(GstElement *typefind, guint probability, GstCaps * MS_SAFE_UNREF(src_pad); g_free(type); + + ms_debug_fleave(); } int __ms_find_type(media_streamer_s *ms_streamer, GstElement *src_element) { GstElement *typefind = NULL; - GstPad *src_pad = gst_element_get_static_pad(src_element, "src"); + GstPad *src_pad = NULL; + + ms_debug_fenter(); + + src_pad = gst_element_get_static_pad(src_element, "src"); typefind = gst_element_factory_make("typefind", "typefinder"); ms_retvm_if(typefind == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error creating element [typefind]"); __ms_bin_add_element(ms_streamer->transform_bin, typefind, TRUE); + gst_element_sync_state_with_parent(typefind); g_signal_connect(typefind, "have-type", G_CALLBACK(__ms_typefound_cb), ms_streamer); @@ -2300,5 +2707,7 @@ int __ms_find_type(media_streamer_s *ms_streamer, GstElement *src_element) MS_SAFE_UNREF(src_pad); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } -- 2.7.4 From 1a301e8793cadf82d6d21a61a06bd02adcf736fe Mon Sep 17 00:00:00 2001 From: Hyunil Date: Mon, 19 Feb 2018 17:28:07 +0900 Subject: [PATCH 02/16] Release argv used for gst_init_check() Change-Id: Ifa9e3493bd230c186234e178215a8ee3acb55180 Signed-off-by: Hyunil --- src/media_streamer_gst.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index d323c5f..33fa1b6 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -2116,11 +2116,12 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) int __ms_pipeline_create(media_streamer_s *ms_streamer) { - GError *err = NULL; int ret = MEDIA_STREAMER_ERROR_NONE; int *argc = NULL; char **argv = NULL; + GError *err = NULL; gboolean gst_ret = 0; + int i = 0; ms_debug_fenter(); @@ -2132,9 +2133,10 @@ int __ms_pipeline_create(media_streamer_s *ms_streamer) return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } + /* get argc(number of command line option), argc is always one widthout option */ *argc = 1; if (ms_streamer->ini.gst_args) - (*argc) += g_strv_length(ms_streamer->ini.gst_args); + (*argc) += g_strv_length(ms_streamer->ini.gst_args); /* default is "--gst-debug = 2 */ argv = (char **)calloc(*argc, sizeof(char*)); if (!argv) { @@ -2146,7 +2148,6 @@ int __ms_pipeline_create(media_streamer_s *ms_streamer) argv[0] = g_strdup("MediaStreamer"); if (ms_streamer->ini.gst_args) { - int i = 0; for ( ; ms_streamer->ini.gst_args[i]; ++i) { if (*argc <= i+1) { ms_error("need to check, prevent overrun"); @@ -2158,10 +2159,15 @@ int __ms_pipeline_create(media_streamer_s *ms_streamer) } gst_ret = gst_init_check(argc, &argv, &err); + /* Clean memory of gstreamer arguments*/ g_strfreev(ms_streamer->ini.gst_args); ms_streamer->ini.gst_args = NULL; - MS_SAFE_FREE(argv[0]); + + for (i = 1; i < *argc; i++) + argv[i] = NULL; + + MS_SAFE_GFREE(argv[0]); MS_SAFE_FREE(argv); MS_SAFE_FREE(argc); -- 2.7.4 From cba571befbf362bf7bdcb8b7a30be513634fb82b Mon Sep 17 00:00:00 2001 From: Hyunil Date: Wed, 21 Feb 2018 10:23:48 +0900 Subject: [PATCH 03/16] Separate gstreamer initializaton into function Change-Id: I6165b4fa9b322a066f34300c7bbe59ac3efaec4c Signed-off-by: Hyunil --- src/media_streamer_gst.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index 33fa1b6..303e3ae 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -2114,7 +2114,7 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) return TRUE; } -int __ms_pipeline_create(media_streamer_s *ms_streamer) +static int __ms_gstreamer_init(media_streamer_s *ms_streamer) { int ret = MEDIA_STREAMER_ERROR_NONE; int *argc = NULL; @@ -2177,6 +2177,24 @@ int __ms_pipeline_create(media_streamer_s *ms_streamer) return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } + ms_debug_fleave(); + + return ret; +} + +int __ms_pipeline_create(media_streamer_s *ms_streamer) +{ + int ret = MEDIA_STREAMER_ERROR_NONE; + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + /* initialize gstreamer with configured parameter */ + ret = __ms_gstreamer_init(ms_streamer); + if (ret != MEDIA_STREAMER_ERROR_NONE) + return ret; + ms_streamer->pipeline = gst_pipeline_new(MEDIA_STREAMER_PIPELINE_NAME); ms_retvm_if(ms_streamer->pipeline == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error creating pipeline"); -- 2.7.4 From 05b8efe3b84058c368d932ae8d39a9d43205cd27 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Wed, 21 Feb 2018 17:09:08 +0900 Subject: [PATCH 04/16] Relocate variable declaration and add log Change-Id: I00d764e29243a263998665ebdf04cd49abc60b8a Signed-off-by: Hyunil --- src/media_streamer.c | 392 ++++++++++++++++++++++++++++++++++------------- src/media_streamer_gst.c | 66 ++++---- 2 files changed, 319 insertions(+), 139 deletions(-) diff --git a/src/media_streamer.c b/src/media_streamer.c index a2eb3ff..1c7f75f 100644 --- a/src/media_streamer.c +++ b/src/media_streamer.c @@ -31,9 +31,11 @@ int media_streamer_node_create_src(media_streamer_node_src_type_e type, media_streamer_node_h *src) { int ret = MEDIA_STREAMER_ERROR_NONE; + media_streamer_node_s *ms_src = NULL; - media_streamer_node_s *ms_src = (media_streamer_node_s *) src; - ms_retvm_if(ms_src == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + + ms_retvm_if(src == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "src is NULL"); ms_src = (media_streamer_node_s *) calloc(1, sizeof(media_streamer_node_s)); ms_retvm_if(ms_src == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error allocation memory"); @@ -51,15 +53,19 @@ int media_streamer_node_create_src(media_streamer_node_src_type_e type, media_st ms_info("Source node [%s] created", ms_src->name); *src = (media_streamer_node_h) ms_src; + ms_debug_fleave(); + return ret; } int media_streamer_node_create_sink(media_streamer_node_sink_type_e type, media_streamer_node_h *sink) { int ret = MEDIA_STREAMER_ERROR_NONE; + media_streamer_node_s *ms_sink = NULL; - media_streamer_node_s *ms_sink = (media_streamer_node_s *) sink; - ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + + ms_retvm_if(sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink is NULL"); ms_sink = (media_streamer_node_s *) calloc(1, sizeof(media_streamer_node_s)); ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error allocation memory"); @@ -77,15 +83,19 @@ int media_streamer_node_create_sink(media_streamer_node_sink_type_e type, media_ ms_info("Sink node [%s] created", ms_sink->name); *sink = (media_streamer_node_h) ms_sink; + ms_debug_fleave(); + return ret; } int media_streamer_node_create(media_streamer_node_type_e type, media_format_h in_fmt, media_format_h out_fmt, media_streamer_node_h *node) { int ret = MEDIA_STREAMER_ERROR_NONE; + media_streamer_node_s *ms_node = NULL; - media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); ms_node = (media_streamer_node_s *) calloc(1, sizeof(media_streamer_node_s)); ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error allocation memory"); @@ -104,13 +114,18 @@ int media_streamer_node_create(media_streamer_node_type_e type, media_format_h i *node = (media_streamer_node_h) ms_node; + ms_debug_fleave(); + return ret; } int media_streamer_node_destroy(media_streamer_node_h node) { media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); if (ms_node->parent_streamer == NULL) { /* This node was not added into any media streamer */ @@ -120,22 +135,24 @@ int media_streamer_node_destroy(media_streamer_node_h node) return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_node_remove(media_streamer_h streamer, media_streamer_node_h node) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_node_s *ms_node = (media_streamer_node_s *) node; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); ms_retvm_if(ms_streamer->state > MEDIA_STREAMER_STATE_IDLE, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be in IDLE state"); - ms_retvm_if(ms_streamer != ms_node->parent_streamer, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Node [%s] added into another Media Streamer object", ms_node->name); - int ret = MEDIA_STREAMER_ERROR_NONE; g_mutex_lock(&ms_streamer->mutex_lock); if (g_hash_table_remove(ms_streamer->nodes_table, (gpointer) ms_node->name)) { @@ -147,21 +164,22 @@ int media_streamer_node_remove(media_streamer_h streamer, media_streamer_node_h g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return ret; } int media_streamer_node_add(media_streamer_h streamer, media_streamer_node_h node) { int ret = MEDIA_STREAMER_ERROR_NONE; - media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(ms_streamer->state > MEDIA_STREAMER_STATE_IDLE, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be in IDLE state"); + ms_debug_fenter(); + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(ms_streamer->state > MEDIA_STREAMER_STATE_IDLE, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be in IDLE state"); + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); ms_retvm_if(ms_node->parent_streamer != NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Node [%s] already added into Media Streamer object", ms_node->name); g_mutex_lock(&ms_streamer->mutex_lock); @@ -174,16 +192,21 @@ int media_streamer_node_add(media_streamer_h streamer, media_streamer_node_h nod g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return ret; } int media_streamer_prepare(media_streamer_h streamer) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); ms_retvm_if(ms_streamer->state > MEDIA_STREAMER_STATE_IDLE, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer already prepared"); - int ret = MEDIA_STREAMER_ERROR_NONE; g_mutex_lock(&ms_streamer->mutex_lock); __ms_generate_dots(ms_streamer->pipeline, "before_prepare"); @@ -196,16 +219,20 @@ int media_streamer_prepare(media_streamer_h streamer) __ms_get_state(ms_streamer); + ms_debug_fleave(); + return ret; } int media_streamer_unprepare(media_streamer_h streamer) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(ms_streamer->state < MEDIA_STREAMER_STATE_READY, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be prepared first!"); - int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(ms_streamer->state < MEDIA_STREAMER_STATE_READY, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be prepared first!"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -219,16 +246,20 @@ int media_streamer_unprepare(media_streamer_h streamer) g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return ret; } int media_streamer_play(media_streamer_h streamer) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(ms_streamer->state < MEDIA_STREAMER_STATE_READY, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be prepared first!"); - int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(ms_streamer->state < MEDIA_STREAMER_STATE_READY, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be prepared first!"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -238,17 +269,22 @@ int media_streamer_play(media_streamer_h streamer) __ms_get_state(ms_streamer); + ms_debug_fleave(); + return ret; } int media_streamer_create(media_streamer_h *streamer) { - ms_retvm_if(streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + int ret = MEDIA_STREAMER_ERROR_NONE; + media_streamer_s *ms_streamer = NULL; - media_streamer_s *ms_streamer = (media_streamer_s *) calloc(1, sizeof(media_streamer_s)); - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error allocation memory"); + ms_debug_fenter(); - int ret = MEDIA_STREAMER_ERROR_NONE; + ms_retvm_if(streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + + ms_streamer = (media_streamer_s *) calloc(1, sizeof(media_streamer_s)); + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error allocation memory"); /* create streamer lock */ g_mutex_init(&ms_streamer->mutex_lock); @@ -271,23 +307,37 @@ int media_streamer_create(media_streamer_h *streamer) g_mutex_unlock(&ms_streamer->mutex_lock); ms_info("Media Streamer created successfully"); + + ms_debug_fleave(); + return ret; } int media_streamer_destroy(media_streamer_h streamer) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); ms_retvm_if(ms_streamer->state > MEDIA_STREAMER_STATE_IDLE, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be unprepared before destroying!"); - return __ms_streamer_destroy(ms_streamer); + ret = __ms_streamer_destroy(ms_streamer); + + ms_debug_fleave(); + + return ret; } int media_streamer_set_error_cb(media_streamer_h streamer, media_streamer_error_cb callback, void *data) { media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(callback == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Callback is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(callback == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "callback is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -296,13 +346,18 @@ int media_streamer_set_error_cb(media_streamer_h streamer, media_streamer_error_ g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_unset_error_cb(media_streamer_h streamer) { media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -311,14 +366,19 @@ int media_streamer_unset_error_cb(media_streamer_h streamer) g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_set_state_change_cb(media_streamer_h streamer, media_streamer_state_changed_cb callback, void *data) { media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(callback == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Callback is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(callback == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "callback is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -327,13 +387,18 @@ int media_streamer_set_state_change_cb(media_streamer_h streamer, media_streamer g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_unset_state_change_cb(media_streamer_h streamer) { media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -342,6 +407,8 @@ int media_streamer_unset_state_change_cb(media_streamer_h streamer) g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -349,7 +416,10 @@ int media_streamer_src_set_buffer_status_cb(media_streamer_node_h source, media_ { media_streamer_node_s *ms_src = (media_streamer_node_s *) source; media_streamer_callback_s *src_callback = NULL; - ms_retvm_if(ms_src == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_src == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "source is NULL"); if (!ms_src->callbacks_structure) { src_callback = (media_streamer_callback_s *) calloc(1, sizeof(media_streamer_callback_s)); @@ -362,27 +432,39 @@ int media_streamer_src_set_buffer_status_cb(media_streamer_node_h source, media_ src_callback->user_data = user_data; ms_src->callbacks_structure = (void *)src_callback; + + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_src_unset_buffer_status_cb(media_streamer_node_h source) { media_streamer_node_s *ms_src = (media_streamer_node_s *) source; - ms_retvm_if(ms_src == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_src == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "source is NULL"); media_streamer_callback_s *src_callback = (media_streamer_callback_s *) ms_src->callbacks_structure; src_callback->callback = NULL; src_callback->user_data = NULL; + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_sink_set_data_ready_cb(media_streamer_node_h sink, media_streamer_sink_data_ready_cb callback, void *data) { media_streamer_node_s *ms_sink = (media_streamer_node_s *) sink; - ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + media_streamer_sink_callbacks_s *sink_callbacks = NULL; + + ms_debug_fenter(); - media_streamer_sink_callbacks_s *sink_callbacks = ms_sink->callbacks_structure; + ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink is NULL"); + + sink_callbacks = ms_sink->callbacks_structure; if (!sink_callbacks) { sink_callbacks = (media_streamer_sink_callbacks_s *) calloc(1, sizeof(media_streamer_sink_callbacks_s)); ms_retvm_if(sink_callbacks == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error allocation memory"); @@ -392,30 +474,44 @@ int media_streamer_sink_set_data_ready_cb(media_streamer_node_h sink, media_stre sink_callbacks->data_ready_cb.user_data = data; ms_sink->callbacks_structure = (void *)sink_callbacks; + + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_sink_unset_data_ready_cb(media_streamer_node_h sink) { media_streamer_node_s *ms_sink = (media_streamer_node_s *) sink; - ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + media_streamer_sink_callbacks_s *sink_callbacks = NULL; + + ms_debug_fenter(); + + ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink is NULL"); - media_streamer_sink_callbacks_s *sink_callbacks = ms_sink->callbacks_structure; + sink_callbacks = ms_sink->callbacks_structure; ms_retvm_if(sink_callbacks == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Callback didn't set yet"); sink_callbacks->data_ready_cb.callback = NULL; sink_callbacks->data_ready_cb.user_data = NULL; ms_sink->callbacks_structure = (void *)sink_callbacks; + + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_sink_set_eos_cb(media_streamer_node_h sink, media_streamer_sink_eos_cb callback, void *data) { media_streamer_node_s *ms_sink = (media_streamer_node_s *) sink; - ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + media_streamer_sink_callbacks_s *sink_callbacks = NULL; + + ms_debug_fenter(); + + ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink is NULL"); - media_streamer_sink_callbacks_s *sink_callbacks = ms_sink->callbacks_structure; + sink_callbacks = ms_sink->callbacks_structure; if (!sink_callbacks) { sink_callbacks = (media_streamer_sink_callbacks_s *) calloc(1, sizeof(media_streamer_sink_callbacks_s)); ms_retvm_if(sink_callbacks == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error allocation memory"); @@ -425,31 +521,44 @@ int media_streamer_sink_set_eos_cb(media_streamer_node_h sink, media_streamer_si sink_callbacks->eos_cb.user_data = data; ms_sink->callbacks_structure = (void *)sink_callbacks; + + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_sink_unset_eos_cb(media_streamer_node_h sink) { media_streamer_node_s *ms_sink = (media_streamer_node_s *) sink; - ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + media_streamer_sink_callbacks_s *sink_callbacks = NULL; + + ms_debug_fenter(); - media_streamer_sink_callbacks_s *sink_callbacks = ms_sink->callbacks_structure; + ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink is NULL"); + + sink_callbacks = ms_sink->callbacks_structure; ms_retvm_if(sink_callbacks == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Callback didn't set yet"); sink_callbacks->data_ready_cb.callback = NULL; sink_callbacks->data_ready_cb.user_data = NULL; ms_sink->callbacks_structure = (void *)sink_callbacks; + + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_pause(media_streamer_h streamer) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); ms_retvm_if(ms_streamer->state != MEDIA_STREAMER_STATE_PLAYING, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be in PLAYING state."); - int ret = MEDIA_STREAMER_ERROR_NONE; g_mutex_lock(&ms_streamer->mutex_lock); @@ -459,16 +568,20 @@ int media_streamer_pause(media_streamer_h streamer) __ms_get_state(ms_streamer); + ms_debug_fleave(); + return ret; } int media_streamer_stop(media_streamer_h streamer) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(!(ms_streamer->state == MEDIA_STREAMER_STATE_PLAYING || ms_streamer->state == MEDIA_STREAMER_STATE_PAUSED), MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be in PLAYING or PAUSED state."); - int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(!(ms_streamer->state == MEDIA_STREAMER_STATE_PLAYING || ms_streamer->state == MEDIA_STREAMER_STATE_PAUSED), MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be in PLAYING or PAUSED state."); g_mutex_lock(&ms_streamer->mutex_lock); @@ -485,32 +598,40 @@ int media_streamer_stop(media_streamer_h streamer) __ms_get_state(ms_streamer); + ms_debug_fleave(); + return ret; } int media_streamer_get_state(media_streamer_h streamer, media_streamer_state_e *state) { media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(state == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "state is NULL"); *state = ms_streamer->state; + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_set_play_position(media_streamer_h streamer, int time, bool accurate, media_streamer_position_changed_cb callback, void *user_data) { + int ret = MEDIA_STREAMER_ERROR_NONE; + int duration = MS_TIME_NONE; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(ms_streamer->state < MEDIA_STREAMER_STATE_PLAYING || ms_streamer->state > MEDIA_STREAMER_STATE_PAUSED, MEDIA_STREAMER_ERROR_INVALID_STATE, "The media streamer state is not in the appropriate state"); + ms_debug_fenter(); + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(ms_streamer->state < MEDIA_STREAMER_STATE_PLAYING || ms_streamer->state > MEDIA_STREAMER_STATE_PAUSED, MEDIA_STREAMER_ERROR_INVALID_STATE, "The media streamer state is not in the appropriate state"); /* Notify: the seeking must be reseted while streamer got ASYNC_DONE message */ ms_retvm_if(ms_streamer->is_seeking, MEDIA_STREAMER_ERROR_INVALID_STATE, "Media streamer is seeking"); - int ret = MEDIA_STREAMER_ERROR_NONE; - int duration = MS_TIME_NONE; - g_mutex_lock(&ms_streamer->mutex_lock); /* if query duration failed or returns duration value MS_TIME_NONE, @@ -526,64 +647,82 @@ int media_streamer_set_play_position(media_streamer_h streamer, int time, bool a g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return ret; } int media_streamer_get_play_position(media_streamer_h streamer, int *time) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); ms_retvm_if(ms_streamer->state < MEDIA_STREAMER_STATE_PLAYING || ms_streamer->state > MEDIA_STREAMER_STATE_PAUSED, MEDIA_STREAMER_ERROR_INVALID_STATE, "The media streamer state is not in the appropriate state"); - int ret = MEDIA_STREAMER_ERROR_NONE; g_mutex_lock(&ms_streamer->mutex_lock); ret = __ms_get_position(streamer, time); g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return ret; } int media_streamer_get_duration(media_streamer_h streamer, int *duration) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); ms_retvm_if(ms_streamer->state < MEDIA_STREAMER_STATE_PLAYING || ms_streamer->state > MEDIA_STREAMER_STATE_PAUSED, MEDIA_STREAMER_ERROR_INVALID_STATE, "The media streamer state is not in the appropriate state"); - int ret = MEDIA_STREAMER_ERROR_NONE; g_mutex_lock(&ms_streamer->mutex_lock); ret = __ms_get_duration(streamer, duration); g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return ret; } int media_streamer_node_push_packet(media_streamer_node_h src, media_packet_h packet) { media_streamer_node_s *ms_node = (media_streamer_node_s *) src; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "src is NULL"); ms_retvm_if(ms_node->type != MEDIA_STREAMER_NODE_TYPE_SRC, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Node type must be Src type for pushing packets."); ms_retvm_if(ms_node->subtype != MEDIA_STREAMER_NODE_SRC_TYPE_CUSTOM, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Source Node must be a custom type for pushing packets."); + ms_debug_fleave(); + return __ms_element_push_packet(ms_node->gst_element, packet); } int media_streamer_node_pull_packet(media_streamer_node_h sink, media_packet_h *packet) { media_streamer_node_s *ms_node = (media_streamer_node_s *) sink; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(packet == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Media packet is NULL"); - ms_retvm_if(ms_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink is NULL"); + ms_retvm_if(packet == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "packet is NULL"); + ms_retvm_if(ms_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "gst_element is NULL"); ms_retvm_if(ms_node->type != MEDIA_STREAMER_NODE_TYPE_SINK, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Node type must be Sink type for pulling packets."); ms_retvm_if(ms_node->subtype != MEDIA_STREAMER_NODE_SINK_TYPE_CUSTOM, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Sink Node must be a custom type for pulling packets."); + ms_debug_fleave(); + return __ms_element_pull_packet(ms_node->gst_element, packet); } @@ -591,15 +730,17 @@ int media_streamer_node_link(media_streamer_node_h src_node, const char *src_pad { int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_node_s *ms_src_node = (media_streamer_node_s *) src_node; - ms_retvm_if(ms_src_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - media_streamer_node_s *ms_dest_node = (media_streamer_node_s *) dest_node; - ms_retvm_if(ms_dest_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + gboolean link_ret = FALSE; + + ms_debug_fenter(); - 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"); + ms_retvm_if(ms_src_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "src_node is NULL"); + ms_retvm_if(ms_dest_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "dest_node is NULL"); + ms_retvm_if(src_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "src_pad_name is NULL"); + ms_retvm_if(sink_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "sink_pad_name is NULL"); - gboolean link_ret = gst_element_link_pads(ms_src_node->gst_element, src_pad_name, ms_dest_node->gst_element, sink_pad_name); + link_ret = gst_element_link_pads(ms_src_node->gst_element, src_pad_name, ms_dest_node->gst_element, sink_pad_name); 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); @@ -610,14 +751,21 @@ int media_streamer_node_link(media_streamer_node_h src_node, const char *src_pad ms_dest_node->linked_by_user = TRUE; } + ms_debug_fleave(); + return ret; } int media_streamer_node_set_pad_format(media_streamer_node_h node, const char *pad_name, media_format_h fmt) { media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Format is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "fmt is NULL"); + + ms_debug_fleave(); /* By default it sets format to object's property 'caps' */ return __ms_node_set_pad_format(node, pad_name, fmt); @@ -626,9 +774,14 @@ int media_streamer_node_set_pad_format(media_streamer_node_h node, const char *p int media_streamer_node_get_pad_format(media_streamer_node_h node, const char *pad_name, media_format_h *fmt) { media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Empty pad name"); - ms_retvm_if(fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Format is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "pad_name is NULL"); + ms_retvm_if(fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "fmt is NULL"); + + ms_debug_fleave(); return __ms_element_get_pad_fmt(ms_node->gst_element, pad_name, fmt); } @@ -638,12 +791,14 @@ int media_streamer_node_get_pad_name(media_streamer_node_h node, char ***src_pad int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(src_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Empty src pad name"); - ms_retvm_if(src_pad_num == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Number of src_pads is NULL"); - ms_retvm_if(sink_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Empty sink pad name"); - ms_retvm_if(sink_pad_num == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Number of sink_pads is NULL"); - ms_retvm_if(ms_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(src_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "src_pad_name is NULL"); + ms_retvm_if(src_pad_num == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "src_pad_num is NULL"); + ms_retvm_if(sink_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink_pad_name is NULL"); + ms_retvm_if(sink_pad_num == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink_pad_num is NULL"); + ms_retvm_if(ms_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "gst_element is NULL"); ret = __ms_element_pad_names(ms_node->gst_element, GST_PAD_SRC, src_pad_name, src_pad_num); ms_retvm_if(ret, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error iterating src pads"); @@ -651,33 +806,42 @@ int media_streamer_node_get_pad_name(media_streamer_node_h node, char ***src_pad ret = __ms_element_pad_names(ms_node->gst_element, GST_PAD_SINK, sink_pad_name, sink_pad_num); ms_retvm_if(ret, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error iterating sink pads"); + ms_debug_fleave(); + return ret; } int media_streamer_node_set_params(media_streamer_node_h node, bundle *param_list) { int ret = MEDIA_STREAMER_ERROR_NONE; - media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(ms_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(param_list == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Parameters list is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(ms_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "gst_element is NULL"); + ms_retvm_if(param_list == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_list is NULL"); ret = __ms_node_set_params_from_bundle(ms_node, param_list); + ms_debug_fleave(); + return ret; } int media_streamer_node_get_params(media_streamer_node_h node, bundle **param_list) { + int ret = MEDIA_STREAMER_ERROR_NONE; media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(param_list == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Param list pionter is NULL"); + bundle *ms_params = NULL; - int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(param_list == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_list pionter is NULL"); - bundle *ms_params = bundle_create(); - ms_retvm_if(ms_params == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Error creating new params object"); + ms_params = bundle_create(); + ms_retvm_if(ms_params == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error creating new params object"); ret = __ms_node_write_params_into_bundle(ms_node, ms_params); if (ret == MEDIA_STREAMER_ERROR_NONE) @@ -685,48 +849,61 @@ int media_streamer_node_get_params(media_streamer_node_h node, bundle **param_li else bundle_free(ms_params); + ms_debug_fleave(); + return ret; } int media_streamer_node_set_param(media_streamer_node_h node, const char *param_name, const char *param_value) { - media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(ms_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(param_name == NULL || param_value == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Parameters name or value is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; + media_streamer_node_s *ms_node = (media_streamer_node_s *) node; param_s *param = NULL; + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(ms_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "gst_element is NULL"); + ms_retvm_if(param_name == NULL || param_value == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Parameters name or value is NULL"); + ret = __ms_node_get_param(node, param_name, ¶m); if (ret == MEDIA_STREAMER_ERROR_NONE) ret = __ms_node_set_param_value(node, param, param_value); + ms_debug_fleave(); + return ret; } int media_streamer_node_get_param(media_streamer_node_h node, const char *param_name, char **param_value) { - media_streamer_node_s *ms_node = (media_streamer_node_s *) node; - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(param_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Param name is NULL"); - ms_retvm_if(param_value == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Param value is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; + media_streamer_node_s *ms_node = (media_streamer_node_s *) node; param_s *param = NULL; + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(param_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_name is NULL"); + ms_retvm_if(param_value == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_value is NULL"); + ret = __ms_node_get_param(ms_node, param_name, ¶m); if (ret == MEDIA_STREAMER_ERROR_NONE) ret = __ms_node_get_param_value(ms_node, param, param_value); + ms_debug_fleave(); + return ret; } int media_streamer_set_interrupted_cb(media_streamer_h streamer, media_streamer_interrupted_cb callback, void *user_data) { media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(callback == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Callback is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(callback == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "callback is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -735,13 +912,18 @@ int media_streamer_set_interrupted_cb(media_streamer_h streamer, media_streamer_ g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int media_streamer_unset_interrupted_cb(media_streamer_h streamer) { media_streamer_s *ms_streamer = (media_streamer_s *) streamer; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -750,5 +932,7 @@ int media_streamer_unset_interrupted_cb(media_streamer_h streamer) g_mutex_unlock(&ms_streamer->mutex_lock); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index 303e3ae..29e508c 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -517,14 +517,15 @@ static gint __decodebin_autoplug_select_cb(GstElement * bin, GstPad * pad, GstCa GST_AUTOPLUG_SELECT_EXPOSE, GST_AUTOPLUG_SELECT_SKIP } GstAutoplugSelectResult; - media_streamer_s *ms_streamer = NULL; + + int index = 0; gchar *factory_name = NULL; const gchar *klass = NULL; GstAutoplugSelectResult result = GST_AUTOPLUG_SELECT_TRY; + media_streamer_s *ms_streamer = (media_streamer_s *) data; ms_debug_fenter(); - ms_streamer = (media_streamer_s *) data; ms_retvm_if(!ms_streamer, GST_AUTOPLUG_SELECT_TRY, "Handle is NULL"); factory_name = GST_OBJECT_NAME(factory); @@ -534,9 +535,7 @@ static gint __decodebin_autoplug_select_cb(GstElement * bin, GstPad * pad, GstCa if (ms_streamer->ini.exclude_elem_names) { /* Search if such plugin must be excluded */ - - int index = 0; - for ( ; ms_streamer->ini.exclude_elem_names[index]; ++index) { + for (index = 0; ms_streamer->ini.exclude_elem_names[index]; ++index) { if (g_strrstr(factory_name, ms_streamer->ini.exclude_elem_names[index])) { ms_debug("Decodebin: skipping [%s] as excluded", factory_name); ms_debug_fleave(); @@ -549,8 +548,7 @@ static gint __decodebin_autoplug_select_cb(GstElement * bin, GstPad * pad, GstCa if (ms_streamer->ini.resource_required_elem_names) { /* Try to acquire resources before adding element */ - int index = 0; - for ( ; ms_streamer->ini.resource_required_elem_names[index]; ++index) { + for (index = 0; ms_streamer->ini.resource_required_elem_names[index]; ++index) { if (g_strrstr(factory_name, ms_streamer->ini.resource_required_elem_names[index])) { ms_debug("Decodebin: trying to acquire resource for [%s] element", factory_name); @@ -611,16 +609,16 @@ static gint __pad_type_compare(gconstpointer a, gconstpointer b) static void __decodebin_newpad_cb(GstElement * decodebin, GstPad * new_pad, gpointer user_data) { - media_streamer_s *ms_streamer = NULL; + media_streamer_s *ms_streamer = (media_streamer_s *) user_data; ms_debug_fenter(); - ms_streamer = (media_streamer_s *) user_data; ms_retm_if(ms_streamer == NULL, "Handle is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); g_object_ref(new_pad); + ms_streamer->pads_types_list = g_list_insert_sorted(ms_streamer->pads_types_list, new_pad, __pad_type_compare); g_mutex_unlock(&ms_streamer->mutex_lock); @@ -681,7 +679,7 @@ static void __decodebin_nomore_pads_combine(GstPad *src_pad, media_streamer_s *m static void __decodebin_nomore_pads_cb(GstElement *decodebin, gpointer user_data) { - media_streamer_s *ms_streamer = NULL; + media_streamer_s *ms_streamer = (media_streamer_s *) user_data; media_streamer_sink_bin_type_e sink_bin_type = MEDIA_STREAMER_SINK_BIN_NORMAL; media_streamer_node_s *rtp_node = NULL; media_streamer_node_s *adaptive_sink = NULL; @@ -693,7 +691,6 @@ static void __decodebin_nomore_pads_cb(GstElement *decodebin, gpointer user_data ms_debug_fenter(); - ms_streamer = (media_streamer_s *) user_data; ms_retm_if(ms_streamer == NULL, "Handle is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -807,29 +804,31 @@ static gboolean __ms_sink_bin_prepare(media_streamer_s * ms_streamer, GstPad * s static void __ms_rtpbin_pad_added_cb(GstElement * src, GstPad * new_pad, gpointer user_data) { - media_streamer_node_s *ms_node = NULL; + media_streamer_s *ms_streamer = NULL; + GstPad *target_pad = NULL; + GstCaps *src_pad_caps = NULL; + gchar *source_pad_name = NULL; + GstStructure *src_pad_struct = NULL; + const gchar *src_pad_type = NULL; + GstPad *source_pad = NULL; + media_streamer_node_s *ms_node = (media_streamer_node_s *) user_data; ms_debug_fenter(); - ms_debug("Pad [%s] added on [%s]", GST_PAD_NAME(new_pad), GST_ELEMENT_NAME(src)); - - ms_node = (media_streamer_node_s *) user_data; ms_retm_if(ms_node == NULL, "Handle is NULL"); + ms_debug("Pad [%s] added on [%s]", GST_PAD_NAME(new_pad), GST_ELEMENT_NAME(src)); if (g_str_has_prefix(GST_PAD_NAME(new_pad), "recv_rtp_src")) { - media_streamer_s *ms_streamer = ms_node->parent_streamer; + ms_streamer = ms_node->parent_streamer; ms_retm_if(ms_streamer == NULL, "Node's parent streamer handle is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); - GstPad *target_pad = gst_ghost_pad_get_target(GST_GHOST_PAD(new_pad)); - GstCaps *src_pad_caps = gst_pad_query_caps(target_pad, NULL); - - gchar *source_pad_name = NULL; - GstStructure *src_pad_struct = NULL; + target_pad = gst_ghost_pad_get_target(GST_GHOST_PAD(new_pad)); + src_pad_caps = gst_pad_query_caps(target_pad, NULL); src_pad_struct = gst_caps_get_structure(src_pad_caps, 0); - - const gchar *src_pad_type = gst_structure_get_string(src_pad_struct, "media"); + src_pad_type = gst_structure_get_string(src_pad_struct, "media"); ms_debug("type is [%s]", src_pad_type); + if (MS_ELEMENT_IS_VIDEO(src_pad_type)) source_pad_name = g_strdup_printf("%s_out", "video"); else if (MS_ELEMENT_IS_AUDIO(src_pad_type)) @@ -837,7 +836,7 @@ static void __ms_rtpbin_pad_added_cb(GstElement * src, GstPad * new_pad, gpointe if (source_pad_name != NULL) { - GstPad *source_pad = gst_element_get_static_pad(ms_node->gst_element, source_pad_name); + source_pad = gst_element_get_static_pad(ms_node->gst_element, source_pad_name); if (source_pad) gst_ghost_pad_set_target(GST_GHOST_PAD(source_pad), new_pad); @@ -917,6 +916,7 @@ static int __ms_adaptive_sink_prepare(media_streamer_s * ms_streamer) {"Codec/Encoder/Audio", "audio_encoder"}, /* MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER */ {"Codec/Muxer", "mpegtsmux"}, /* MEDIA_STREAMER_NODE_TYPE_MUXER */ }; + GstCaps *video_enc_src_caps = NULL; GstCaps *video_enc_sink_caps = NULL; GstCaps *audio_enc_src_caps = NULL; @@ -1097,7 +1097,7 @@ int __ms_adaptive_element_prepare(media_streamer_node_s *ms_node, bool auto_plug static gboolean __ms_feature_node_filter(GstPluginFeature *feature, gpointer data) { - node_plug_s *plug_info = NULL; + node_plug_s *plug_info = (node_plug_s*)data; gboolean can_accept = FALSE; gboolean src_can_accept = FALSE; gboolean sink_can_accept = FALSE; @@ -1106,8 +1106,6 @@ static gboolean __ms_feature_node_filter(GstPluginFeature *feature, gpointer dat ms_debug_fenter(); - plug_info = (node_plug_s*)data; - if (!GST_IS_ELEMENT_FACTORY(feature)) return FALSE; @@ -2380,11 +2378,11 @@ int __ms_element_pad_names(GstElement *gst_element, GstPadDirection pad_type, ch int __ms_element_get_pad_fmt(GstElement *gst_element, const char *pad_name, media_format_h *fmt) { + int ret = MEDIA_STREAMER_ERROR_NONE; GstCaps *allowed_caps = NULL; GstCaps *format_caps = NULL; GstPad *pad = NULL; GValue *value = NULL; - int ret = MEDIA_STREAMER_ERROR_NONE; ms_debug_fenter(); @@ -2547,9 +2545,9 @@ int __ms_element_push_packet(GstElement *src_element, media_packet_h packet) int __ms_element_pull_packet(GstElement *sink_element, media_packet_h *packet) { + int ret = MEDIA_STREAMER_ERROR_NONE; GstSample *sample = NULL; media_format_h fmt = NULL; - int ret = MEDIA_STREAMER_ERROR_NONE; guint8 *buffer_res = NULL; GstMapInfo map = {0,}; GstBuffer *buffer = NULL; @@ -2599,16 +2597,16 @@ int __ms_element_pull_packet(GstElement *sink_element, media_packet_h *packet) static void __demux_newpad_cb(GstElement * demux, GstPad * new_pad, gpointer user_data) { - media_streamer_s *ms_streamer = NULL; + media_streamer_s *ms_streamer = (media_streamer_s *) user_data; ms_debug_fenter(); - ms_streamer = (media_streamer_s *) user_data; ms_retm_if(ms_streamer == NULL, "Handle is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); g_object_ref(new_pad); + ms_streamer->pads_types_list = g_list_insert_sorted(ms_streamer->pads_types_list, new_pad, __pad_type_compare); g_mutex_unlock(&ms_streamer->mutex_lock); @@ -2643,13 +2641,12 @@ static void __demux_nomore_pads_combine(GstPad *src_pad, media_streamer_s *ms_st static void __demux_nomore_pads_cb(GstElement *demux, gpointer user_data) { - media_streamer_s *ms_streamer = NULL; + media_streamer_s *ms_streamer = (media_streamer_s *) user_data; GList *iterator = NULL; GList *list = NULL; ms_debug_fenter(); - ms_streamer = (media_streamer_s *) user_data; ms_retm_if(ms_streamer == NULL, "Handle is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -2682,15 +2679,14 @@ int __ms_demux_element_prepare(media_streamer_s * ms_streamer, media_streamer_no static void __ms_typefound_cb(GstElement *typefind, guint probability, GstCaps *caps, gpointer data) { + media_streamer_s *ms_streamer = (media_streamer_s *) data; GstElement *decodebin = NULL; - media_streamer_s *ms_streamer = NULL; media_streamer_node_s *adaptive_sink = NULL; gchar *type = NULL; GstPad *src_pad = NULL; ms_debug_fenter(); - ms_streamer = (media_streamer_s *) data; adaptive_sink = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_sink"); src_pad = gst_element_get_static_pad(typefind, "src"); -- 2.7.4 From 5be1b6491e7df3535dca4ffaf2ab0cb9c019f3c1 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Mon, 26 Feb 2018 13:36:41 +0900 Subject: [PATCH 05/16] Add checking null point and log Change-Id: Ida65ee996b54407a82f5fe20bc11a9629de15205 Signed-off-by: Hyunil --- src/media_streamer_node.c | 428 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 356 insertions(+), 72 deletions(-) diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index f13824b..949f613 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -96,35 +96,56 @@ node_info_s nodes_info[] = { void __ms_get_state(media_streamer_s *ms_streamer) { - GstState state_old, state_new; - GstStateChangeReturn ret_state = gst_element_get_state(ms_streamer->pipeline, &state_old, &state_new, GST_CLOCK_TIME_NONE); + GstState state_old = GST_STATE_NULL, state_new = GST_STATE_NULL; + GstStateChangeReturn ret_state = -1; + + ms_debug_fenter(); + + ms_retm_if(ms_streamer == NULL, "ms_streamer is NULL"); + ms_retm_if(ms_streamer->pipeline == NULL, "ms_streamer->pipeline is NULL"); + + ret_state = gst_element_get_state(ms_streamer->pipeline, &state_old, &state_new, GST_CLOCK_TIME_NONE); if (ret_state == GST_STATE_CHANGE_SUCCESS) ms_info("Got state for [%s]: old [%s], new [%s]", GST_ELEMENT_NAME(ms_streamer->pipeline), gst_element_state_get_name(state_old), gst_element_state_get_name(state_new)); else ms_error("Couldn`t get state for [%s]", GST_ELEMENT_NAME(ms_streamer->pipeline)); + + ms_debug_fleave(); } static gboolean __ms_rtp_node_has_property(media_streamer_node_s *ms_node, const char *param_name) { + GValue *val = NULL; + + ms_debug_fenter(); + ms_retvm_if(!ms_node || !ms_node->gst_element, FALSE, "Error: empty node"); ms_retvm_if(!param_name, FALSE, "Error: invalid property parameter"); if (ms_node->type != MEDIA_STREAMER_NODE_TYPE_RTP) return FALSE; - GValue *val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param_name); + val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param_name); + + ms_debug_fleave(); + return val ? TRUE : FALSE; } static int __ms_rtp_node_get_property(media_streamer_node_s *ms_node, param_s *param, GValue *value) { + int ret = MEDIA_STREAMER_ERROR_NONE; + GValue *val = NULL; + + ms_debug_fenter(); + ms_retvm_if(!ms_node || !ms_node->gst_element, FALSE, "Error: empty node"); ms_retvm_if(ms_node->type != MEDIA_STREAMER_NODE_TYPE_RTP, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Invalid node type"); ms_retvm_if(!param, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Error: invalid property parameter"); + ms_retvm_if(!value, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "value is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; - GValue *val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param->param_name); + val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param->param_name); if (!strcmp(param->param_name, MEDIA_STREAMER_PARAM_VIDEO_IN_PORT) || !strcmp(param->param_name, MEDIA_STREAMER_PARAM_AUDIO_IN_PORT) || !strcmp(param->param_name, MEDIA_STREAMER_PARAM_VIDEO_OUT_PORT) || @@ -136,18 +157,25 @@ static int __ms_rtp_node_get_property(media_streamer_node_s *ms_node, param_s *p ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER; g_value_copy(val, value); + + ms_debug_fleave(); + return ret; } static int __ms_rtp_node_set_property(media_streamer_node_s *ms_node, param_s *param, const char *param_value) { + int ret = MEDIA_STREAMER_ERROR_NONE; + GValue *val = NULL; + + ms_debug_fenter(); + ms_retvm_if(!ms_node || !ms_node->gst_element, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error: empty node"); ms_retvm_if(ms_node->type != MEDIA_STREAMER_NODE_TYPE_RTP, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Invalid node type"); ms_retvm_if(!param, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Error: invalid property parameter"); + ms_retvm_if(!param_value, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_value is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; - - GValue *val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param->param_name); + val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param->param_name); if (!val) { ms_error("fail to get [%s] val from [%s]", param->param_name, GST_ELEMENT_NAME(ms_node->gst_element)); return MEDIA_STREAMER_ERROR_INVALID_PARAMETER; @@ -178,52 +206,74 @@ static int __ms_rtp_node_set_property(media_streamer_node_s *ms_node, param_s *p ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER; } + ms_debug_fleave(); + return ret; } static gboolean __ms_adaptive_src_node_has_property(media_streamer_node_s *ms_node, const char * param_name) { + GValue *val = NULL; + + ms_debug_fenter(); + ms_retvm_if(!ms_node || !ms_node->gst_element, FALSE, "Error: empty node"); ms_retvm_if(!param_name, FALSE, "Error: invalid property parameter"); if (ms_node->type == MEDIA_STREAMER_NODE_TYPE_SRC && ms_node->subtype == MEDIA_STREAMER_NODE_SRC_TYPE_ADAPTIVE) { - GValue *val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param_name); + val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param_name); + + ms_debug_fleave(); + return val ? TRUE : FALSE; } + ms_debug_fleave(); + return FALSE; } static int __ms_adaptive_src_node_get_property(media_streamer_node_s *ms_node, param_s *param, GValue *value) { + int ret = MEDIA_STREAMER_ERROR_NONE; + GValue *val = NULL; + + ms_debug_fenter(); + ms_retvm_if(!ms_node || !ms_node->gst_element, FALSE, "Error: empty node"); ms_retvm_if(ms_node->type != MEDIA_STREAMER_NODE_TYPE_SRC && ms_node->subtype != MEDIA_STREAMER_NODE_SRC_TYPE_ADAPTIVE, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Invalid node type"); ms_retvm_if(!param, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Error: invalid property parameter"); + ms_retvm_if(!value, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "value is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; - - GValue *val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param->param_name); + val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param->param_name); if (!strcmp(param->param_name, MEDIA_STREAMER_PARAM_URI)) g_value_init(value, G_TYPE_STRING); else ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER; g_value_copy(val, value); + + ms_debug_fleave(); + return ret; } static int __ms_adaptive_src_node_set_property(media_streamer_node_s *ms_node, param_s *param, const char *param_value) { + int ret = MEDIA_STREAMER_ERROR_NONE; + GValue *val = NULL; + + ms_debug_fenter(); + ms_retvm_if(!ms_node || !ms_node->gst_element, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error: empty node"); ms_retvm_if(ms_node->type != MEDIA_STREAMER_NODE_TYPE_SRC && ms_node->subtype != MEDIA_STREAMER_NODE_SRC_TYPE_ADAPTIVE, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Invalid node type"); ms_retvm_if(!param, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Error: invalid property parameter"); + ms_retvm_if(!param_value, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_value is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; - - GValue *val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param->param_name); + val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), param->param_name); if (!val) { ms_error("fail to get [%s] val from [%s]", param->param_name, GST_ELEMENT_NAME(ms_node->gst_element)); return MEDIA_STREAMER_ERROR_INVALID_PARAMETER; @@ -237,17 +287,24 @@ static int __ms_adaptive_src_node_set_property(media_streamer_node_s *ms_node, p ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER; } + ms_debug_fleave(); + return ret; } int __ms_node_create(media_streamer_node_s *node, media_format_h in_fmt, media_format_h out_fmt) { - ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; + GstCaps *sink_caps = NULL; + GstCaps *src_caps = NULL; - GstCaps *sink_caps = in_fmt ? __ms_create_caps_from_fmt(in_fmt) : NULL; - GstCaps *src_caps = out_fmt ? __ms_create_caps_from_fmt(out_fmt) : NULL; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(out_fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "out_fmt is NULL"); + + sink_caps = in_fmt ? __ms_create_caps_from_fmt(in_fmt) : NULL; + src_caps = out_fmt ? __ms_create_caps_from_fmt(out_fmt) : NULL; node_plug_s plug_info = {&(nodes_info[node->type]), src_caps, sink_caps, NULL}; @@ -266,6 +323,8 @@ int __ms_node_create(media_streamer_node_s *node, media_format_h in_fmt, media_f if (sink_caps) gst_caps_unref(sink_caps); + ms_debug_fleave(); + return ret; } @@ -274,13 +333,21 @@ int __ms_node_create(media_streamer_node_s *node, media_format_h in_fmt, media_f static void __ms_src_start_feed_cb(GstElement *pipeline, guint size, gpointer data) { media_streamer_node_s *ms_src = (media_streamer_node_s *) data; - ms_retm_if(ms_src == NULL, "Handle is NULL"); + media_streamer_callback_s *src_callback = NULL; + media_streamer_custom_buffer_status_cb buffer_status_cb = NULL; + + ms_debug_fenter(); + + ms_retm_if(ms_src == NULL, "data is NULL"); + ms_retm_if(pipeline == NULL, "pipeline is NULL"); if (ms_src->callbacks_structure != NULL) { - media_streamer_callback_s *src_callback = (media_streamer_callback_s *) ms_src->callbacks_structure; - media_streamer_custom_buffer_status_cb buffer_status_cb = (media_streamer_custom_buffer_status_cb) src_callback->callback; + src_callback = (media_streamer_callback_s *) ms_src->callbacks_structure; + buffer_status_cb = (media_streamer_custom_buffer_status_cb) src_callback->callback; buffer_status_cb((media_streamer_node_h) ms_src, MEDIA_STREAMER_CUSTOM_BUFFER_UNDERRUN, src_callback->user_data); } + + ms_debug_fleave(); } /* This callback is called when appsrc has enough data and we can stop sending. @@ -288,13 +355,21 @@ static void __ms_src_start_feed_cb(GstElement *pipeline, guint size, gpointer da static void __ms_src_stop_feed_cb(GstElement *pipeline, gpointer data) { media_streamer_node_s *ms_src = (media_streamer_node_s *) data; - ms_retm_if(ms_src == NULL, "Handle is NULL"); + media_streamer_callback_s *src_callback = NULL; + media_streamer_custom_buffer_status_cb buffer_status_cb = NULL; + + ms_debug_fenter(); + + ms_retm_if(ms_src == NULL, "data is NULL"); + ms_retm_if(pipeline == NULL, "pipeline is NULL"); if (ms_src->callbacks_structure != NULL) { - media_streamer_callback_s *src_callback = (media_streamer_callback_s *) ms_src->callbacks_structure; - media_streamer_custom_buffer_status_cb buffer_status_cb = (media_streamer_custom_buffer_status_cb) src_callback->callback; + src_callback = (media_streamer_callback_s *) ms_src->callbacks_structure; + buffer_status_cb = (media_streamer_custom_buffer_status_cb) src_callback->callback; buffer_status_cb((media_streamer_node_h) ms_src, MEDIA_STREAMER_CUSTOM_BUFFER_OVERFLOW, src_callback->user_data); } + + ms_debug_fleave(); } static int __ms_node_check_priveleges(media_streamer_node_s *node) @@ -302,6 +377,14 @@ static int __ms_node_check_priveleges(media_streamer_node_s *node) int ret = MEDIA_STREAMER_ERROR_NONE; int ret_val = 0; char *privilege = NULL; + FILE* opened_file; + char smackLabel[SMACK_LABEL_LEN + 1]; + char uid[10]; + cynara *cynara_h = NULL; + + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); if (node->type == MEDIA_STREAMER_NODE_TYPE_SRC) { switch (node->subtype) { @@ -341,12 +424,6 @@ static int __ms_node_check_priveleges(media_streamer_node_s *node) if (privilege == NULL) return ret; - FILE* opened_file; - - char smackLabel[SMACK_LABEL_LEN + 1]; - char uid[10]; - cynara *cynara_h = NULL; - if (CYNARA_API_SUCCESS != cynara_initialize(&cynara_h, NULL)) { ms_error("Failed to initialize cynara structure\n"); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; @@ -387,6 +464,9 @@ static int __ms_node_check_priveleges(media_streamer_node_s *node) } cynara_finish(cynara_h); + + ms_debug_fleave(); + return ret; } @@ -402,6 +482,10 @@ static int __ms_node_check_feature(media_streamer_node_s *node) bool enabled = FALSE; bool supported = FALSE; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + if (node->type == MEDIA_STREAMER_NODE_TYPE_SRC) { switch (node->subtype) { case MEDIA_STREAMER_NODE_SRC_TYPE_HTTP: @@ -499,16 +583,20 @@ static int __ms_node_check_feature(media_streamer_node_s *node) } } + ms_debug_fleave(); + return ret; } int __ms_src_node_create(media_streamer_node_s *node) { - ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; char *plugin_name = NULL; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ret = __ms_node_check_priveleges(node); if (ret != MEDIA_STREAMER_ERROR_NONE) { ms_error("Error getting privileges for Src Node"); @@ -582,6 +670,8 @@ int __ms_src_node_create(media_streamer_node_s *node) return ret; } + ms_debug_fleave(); + return ret; } @@ -589,39 +679,55 @@ int __ms_src_node_create(media_streamer_node_s *node) static void __ms_sink_new_buffer_cb(GstElement *sink, gpointer *data) { media_streamer_node_s *ms_sink = (media_streamer_node_s *) data; - ms_retm_if(ms_sink == NULL, "Handle is NULL"); + media_streamer_sink_callbacks_s *sink_callbacks = NULL; + media_streamer_sink_data_ready_cb data_ready_cb = NULL; + + ms_debug_fenter(); + + ms_retm_if(ms_sink == NULL, "data is NULL"); if (ms_sink->callbacks_structure != NULL) { - media_streamer_sink_callbacks_s *sink_callbacks = (media_streamer_sink_callbacks_s *) ms_sink->callbacks_structure; - media_streamer_sink_data_ready_cb data_ready_cb = (media_streamer_sink_data_ready_cb) sink_callbacks->data_ready_cb.callback; + sink_callbacks = (media_streamer_sink_callbacks_s *) ms_sink->callbacks_structure; + data_ready_cb = (media_streamer_sink_data_ready_cb) sink_callbacks->data_ready_cb.callback; if (data_ready_cb) data_ready_cb((media_streamer_node_h) ms_sink, sink_callbacks->data_ready_cb.user_data); } + + ms_debug_fleave(); } /* The appsink has got eos */ static void sink_eos(GstElement *sink, gpointer *data) { media_streamer_node_s *ms_sink = (media_streamer_node_s *) data; - ms_retm_if(ms_sink == NULL, "Handle is NULL"); + media_streamer_sink_callbacks_s *sink_callbacks = NULL; + media_streamer_sink_eos_cb eos_cb = NULL; + + ms_debug_fenter(); + + ms_retm_if(ms_sink == NULL, "data is NULL"); if (ms_sink->callbacks_structure != NULL) { - media_streamer_sink_callbacks_s *sink_callbacks = (media_streamer_sink_callbacks_s *) ms_sink->callbacks_structure; - media_streamer_sink_eos_cb eos_cb = (media_streamer_sink_eos_cb) sink_callbacks->eos_cb.callback; + sink_callbacks = (media_streamer_sink_callbacks_s *) ms_sink->callbacks_structure; + eos_cb = (media_streamer_sink_eos_cb) sink_callbacks->eos_cb.callback; if (eos_cb) eos_cb((media_streamer_node_h) ms_sink, sink_callbacks->eos_cb.user_data); } + + ms_debug_fleave(); } int __ms_sink_node_create(media_streamer_node_s *node) { - ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; char *plugin_name = NULL; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ret = __ms_node_check_priveleges(node); if (ret != MEDIA_STREAMER_ERROR_NONE) { ms_error("Error getting privileges for Sink Node"); @@ -690,12 +796,19 @@ int __ms_sink_node_create(media_streamer_node_s *node) else node->name = gst_element_get_name(node->gst_element); + ms_debug_fleave(); + return ret; } void __ms_node_destroy(media_streamer_node_s *node) { - gchar *node_name = g_strdup(node->name); + gchar *node_name = NULL; + + ms_debug_fenter(); + + ms_retm_if(node == NULL, "node is NULL"); + node_name = g_strdup(node->name); /* Disconnects and clean all node signals */ g_list_free_full(node->sig_list, __ms_signal_destroy); @@ -711,10 +824,17 @@ void __ms_node_destroy(media_streamer_node_s *node) ms_info("Node [%s] has been destroyed", node_name); MS_SAFE_GFREE(node_name); + + ms_debug_fleave(); } int __ms_node_insert_into_table(GHashTable *nodes_table, media_streamer_node_s *ms_node) { + ms_debug_fenter(); + + ms_retvm_if(nodes_table == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "nodes_table is NULL"); + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_node is NULL"); + if (g_hash_table_contains(nodes_table, ms_node->name)) { ms_debug("Current Node [%s] already added into Media Streamer", ms_node->name); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; @@ -725,13 +845,19 @@ int __ms_node_insert_into_table(GHashTable *nodes_table, media_streamer_node_s * } ms_info("Node [%s] added into streamer, node type/subtype [%d/%d]", ms_node->name, ms_node->type, ms_node->subtype); + + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } void __ms_node_remove_from_table(void *data) { media_streamer_node_s *ms_node = (media_streamer_node_s *) data; - ms_retm_if(ms_node == NULL, "Handle is NULL"); + + ms_debug_fenter(); + + ms_retm_if(ms_node == NULL, "data is NULL"); if (__ms_element_unlink(ms_node->gst_element)) { ms_node->linked_by_user = FALSE; @@ -741,12 +867,17 @@ void __ms_node_remove_from_table(void *data) } else { ms_error("Error: Node [%s] remove failed", ms_node->name); } + + ms_debug_fleave(); + } static gboolean __ms_src_need_typefind(GstPad *src_pad) { gboolean ret = FALSE; + ms_debug_fenter(); + if (!src_pad || gst_pad_is_linked(src_pad)) return FALSE; @@ -755,12 +886,18 @@ static gboolean __ms_src_need_typefind(GstPad *src_pad) ret = TRUE; gst_caps_unref(src_caps); + + ms_debug_fleave(); + return ret; } node_info_s * __ms_node_get_klass_by_its_type(media_streamer_node_type_e element_type) { int it_klass; + + ms_debug_fenter(); + for (it_klass = 0; nodes_info[it_klass].klass_name != NULL; it_klass++) { if (it_klass == element_type) { ms_info("Next node`s type klass is [%s]", nodes_info[it_klass].klass_name); @@ -768,17 +905,30 @@ node_info_s * __ms_node_get_klass_by_its_type(media_streamer_node_type_e element } } + ms_debug_fleave(); + return &nodes_info[it_klass]; } static gboolean _src_node_prepare(const GValue *item, GValue *ret, gpointer user_data) { media_streamer_s *ms_streamer = (media_streamer_s *) user_data; - GstElement *src_element = GST_ELEMENT(g_value_get_object(item)); + GstElement *src_element = NULL; + GstElement *found_element = NULL; + media_streamer_node_s *found_node = NULL; + GstPad *src_pad = NULL; + + ms_debug_fenter(); + + ms_retvm_if(item == NULL, FALSE, "item is NULL"); + ms_retvm_if(ret == NULL, FALSE, "ret is NULL"); + ms_retvm_if(ms_streamer == NULL, FALSE, "user_data is NULL"); + + src_element = GST_ELEMENT(g_value_get_object(item)); g_object_ref(src_element); g_value_set_boolean(ret, FALSE); - media_streamer_node_s *found_node = (media_streamer_node_s *) g_hash_table_lookup(ms_streamer->nodes_table, GST_ELEMENT_NAME(src_element)); + found_node = (media_streamer_node_s *) g_hash_table_lookup(ms_streamer->nodes_table, GST_ELEMENT_NAME(src_element)); if (!found_node) { /* If we fail to found corresonding node inside streamer then apprently this element doesn't require resources. */ @@ -789,8 +939,7 @@ static gboolean _src_node_prepare(const GValue *item, GValue *ret, gpointer user ms_debug("Autoplug: found src element [%s]", GST_ELEMENT_NAME(src_element)); - GstPad *src_pad = gst_element_get_static_pad(src_element, "src"); - GstElement *found_element = NULL; + src_pad = gst_element_get_static_pad(src_element, "src"); if (__ms_src_need_typefind(src_pad)) { __ms_find_type(ms_streamer, src_element); @@ -828,12 +977,26 @@ static gboolean _src_node_prepare(const GValue *item, GValue *ret, gpointer user g_value_set_boolean(ret, TRUE); + ms_debug_fleave(); + return TRUE; } -static gboolean _sink_node_prepare(const GValue *item, GValue *ret, gpointer user_data) +static gboolean _sink_node_prepare(const GValue *item, GValue *g_ret, gpointer user_data) { - return __ms_element_lock_state(item, ret, user_data); + gboolean ret = FALSE; + + ms_retvm_if(item == NULL, FALSE, "item is NULL"); + ms_retvm_if(g_ret == NULL, FALSE, "ret is NULL"); + ms_retvm_if(user_data == NULL, FALSE, "user_data is NULL"); + + ms_debug_fenter(); + + ret = __ms_element_lock_state(item, g_ret, user_data); + + ms_debug_fleave(); + + return ret; } static gboolean demux_find(gpointer key, gpointer value, gpointer user_data) @@ -848,6 +1011,11 @@ static int __ms_adaptive_sink_http_server_prepare(media_streamer_s * ms_streamer char *playlist_dir = NULL; char *split = NULL; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + /* Create and start http server */ err_code = __ms_http_server_create(&ms_streamer->http_server, NULL, DEFAULT_HTTP_PORT); if (MEDIA_STREAMER_ERROR_NONE != err_code) { @@ -881,18 +1049,28 @@ static int __ms_adaptive_sink_http_server_prepare(media_streamer_s * ms_streamer _DONE: + ms_debug_fleave(); + return err_code; } int __ms_pipeline_prepare(media_streamer_s *ms_streamer) { + int ret = MEDIA_STREAMER_ERROR_NONE; + media_streamer_node_s *rtp_node = NULL; + media_streamer_node_s *demux = NULL; + media_streamer_node_s *adaptive_src = NULL; + media_streamer_node_s *adaptive_sink = NULL; + + ms_debug_fenter(); + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; - media_streamer_node_s *rtp_node = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "rtp_container"); - media_streamer_node_s *demux = (media_streamer_node_s *)g_hash_table_find(ms_streamer->nodes_table, (GHRFunc)demux_find, NULL); - media_streamer_node_s *adaptive_src = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_src"); - media_streamer_node_s *adaptive_sink = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_sink"); + rtp_node = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "rtp_container"); + demux = (media_streamer_node_s *)g_hash_table_find(ms_streamer->nodes_table, (GHRFunc)demux_find, NULL); + adaptive_src = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_src"); + adaptive_sink = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_sink"); + if (rtp_node) { ret = __ms_rtp_element_prepare(rtp_node) ? MEDIA_STREAMER_ERROR_NONE : MEDIA_STREAMER_ERROR_INVALID_PARAMETER; } else if (demux) { @@ -941,6 +1119,8 @@ int __ms_pipeline_prepare(media_streamer_s *ms_streamer) if (ret != MEDIA_STREAMER_ERROR_NONE) goto prepare_fail; + ms_debug_fleave(); + return ret; prepare_fail: @@ -951,18 +1131,25 @@ prepare_fail: static gboolean __ms_bin_remove_elements(media_streamer_s *ms_streamer, GstElement *bin) { GValue element = G_VALUE_INIT; - GstIterator *bin_iterator = gst_bin_iterate_elements(GST_BIN(bin)); + GstIterator *bin_iterator = NULL; + gboolean ret = TRUE; /* If Bin doesn't have any elements function returns TRUE */ + GstElement *found_element = NULL; + GstIteratorResult it_res = GST_ITERATOR_ERROR; + media_streamer_node_s *found_node = NULL; - /* If Bin doesn't have any elements function returns TRUE */ - gboolean ret = TRUE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, FALSE, "ms_streamer is NULL"); + ms_retvm_if(bin == NULL, FALSE, "bin is NULL"); + + bin_iterator = gst_bin_iterate_elements(GST_BIN(bin)); + it_res = gst_iterator_next(bin_iterator, &element); - GstElement *found_element = NULL; - GstIteratorResult it_res = gst_iterator_next(bin_iterator, &element); while (GST_ITERATOR_OK == it_res) { found_element = (GstElement *) g_value_get_object(&element); /* Get node of this element if it appears as node */ - media_streamer_node_s *found_node = (media_streamer_node_s *) g_hash_table_lookup(ms_streamer->nodes_table, GST_ELEMENT_NAME(found_element)); + found_node = (media_streamer_node_s *) g_hash_table_lookup(ms_streamer->nodes_table, GST_ELEMENT_NAME(found_element)); if (found_node) { if (!found_node->linked_by_user) ret = ret && __ms_element_unlink(found_element); @@ -985,20 +1172,33 @@ static gboolean __ms_bin_remove_elements(media_streamer_s *ms_streamer, GstEleme g_value_unset(&element); gst_iterator_free(bin_iterator); + ms_debug_fleave(); + return ret; } static void __ms_pending_pads_remove(void *data) { - GstPad *pad = GST_PAD(data); + GstPad *pad = NULL; + + ms_debug_fenter(); + + ms_retm_if(data == NULL, "data is NULL"); + + pad = GST_PAD(data); MS_SAFE_UNREF(pad); + + ms_debug_fleave(); } int __ms_pipeline_unprepare(media_streamer_s *ms_streamer) { - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ret = __ms_state_change(ms_streamer, MEDIA_STREAMER_STATE_IDLE); if (ret != MEDIA_STREAMER_ERROR_NONE) ms_error("Failed to unprepare pipeline"); @@ -1040,6 +1240,8 @@ int __ms_pipeline_unprepare(media_streamer_s *ms_streamer) MS_BIN_UNPREPARE(ms_streamer->transform_bin); MS_BIN_UNPREPARE(ms_streamer->sink_bin); + ms_debug_fleave(); + return ret; } @@ -1048,12 +1250,17 @@ int __ms_node_set_params_from_bundle(media_streamer_node_s *node, bundle *param_ int ret = MEDIA_STREAMER_ERROR_NONE; GList *p_list = NULL; int written_count = 0; + param_s *param = NULL; + GList *list_iter = NULL; + char *string_val = NULL; + + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(param_list == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_list is NULL"); ret = __ms_node_get_param_list(node, &p_list); if (ret == MEDIA_STREAMER_ERROR_NONE) { - param_s *param = NULL; - GList *list_iter = NULL; - char *string_val = NULL; for (list_iter = p_list; list_iter != NULL; list_iter = list_iter->next) { param = (param_s *)list_iter->data; if (bundle_get_str(param_list, param->param_name, &string_val) != BUNDLE_ERROR_KEY_NOT_AVAILABLE) { @@ -1073,6 +1280,8 @@ int __ms_node_set_params_from_bundle(media_streamer_node_s *node, bundle *param_ if (ret == MEDIA_STREAMER_ERROR_NONE && written_count == 0) ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER; + ms_debug_fleave(); + return ret; } @@ -1080,12 +1289,17 @@ int __ms_node_write_params_into_bundle(media_streamer_node_s *node, bundle *para { int ret = MEDIA_STREAMER_ERROR_NONE; GList *p_list = NULL; + param_s *param = NULL; + GList *list_iter = NULL; + char *string_val = NULL; + + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(param_list == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_list is NULL"); ret = __ms_node_get_param_list(node, &p_list); if (ret == MEDIA_STREAMER_ERROR_NONE) { - param_s *param = NULL; - GList *list_iter = NULL; - char *string_val = NULL; for (list_iter = p_list; list_iter != NULL; list_iter = list_iter->next) { param = (param_s *)list_iter->data; @@ -1098,6 +1312,8 @@ int __ms_node_write_params_into_bundle(media_streamer_node_s *node, bundle *para if (p_list) g_list_free(p_list); + ms_debug_fleave(); + return ret; } @@ -1107,6 +1323,12 @@ int __ms_node_get_param(media_streamer_node_s *node, const char *param_name, par gboolean found_param = FALSE; int it_param; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(param_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_name is NULL"); + ms_retvm_if(param == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param is NULL"); + for (it_param = 0; param_table[it_param].param_name != NULL; it_param++) { if (!g_strcmp0(param_name, param_table[it_param].param_name)) { param_spec = g_object_class_find_property(G_OBJECT_GET_CLASS(node->gst_element), param_table[it_param].origin_name); @@ -1120,6 +1342,9 @@ int __ms_node_get_param(media_streamer_node_s *node, const char *param_name, par } } ms_retvm_if(!found_param, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Node [%s] doesn't have param [%s].", node->name, param_name); + + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -1128,6 +1353,11 @@ int __ms_node_get_param_list(media_streamer_node_s *node, GList **param_list) GParamSpec *param_spec; int it_param; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(param_list == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_list is NULL"); + for (it_param = 0; param_table[it_param].param_name != NULL; it_param++) { param_spec = g_object_class_find_property(G_OBJECT_GET_CLASS(node->gst_element), param_table[it_param].origin_name); if (param_spec || __ms_rtp_node_has_property(node, param_table[it_param].origin_name) || @@ -1137,16 +1367,24 @@ int __ms_node_get_param_list(media_streamer_node_s *node, GList **param_list) } } ms_retvm_if(!(*param_list), MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Node [%s] doesn't have any params.", node->name); + + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int __ms_node_get_param_value(media_streamer_node_s *node, param_s *param, char **string_value) { + int ret = MEDIA_STREAMER_ERROR_NONE; char *string_val = NULL; GParamSpec *param_spec = NULL; GValue value = G_VALUE_INIT; - int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(param == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param is NULL"); + ms_retvm_if(string_value == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "string_value is NULL"); if (node->type == MEDIA_STREAMER_NODE_TYPE_RTP) ret = __ms_rtp_node_get_property(node, param, &value); @@ -1227,6 +1465,9 @@ int __ms_node_get_param_value(media_streamer_node_s *node, param_s *param, char g_value_reset(&value); g_value_unset(&value); + + ms_debug_fleave(); + return ret; } @@ -1442,18 +1683,25 @@ int __ms_node_set_display(media_streamer_node_s *ms_node, const char *param_valu int __ms_node_set_param_value(media_streamer_node_s *ms_node, param_s *param, const char *param_value) { - ms_retvm_if(!ms_node || !param || !param_value, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_node is NULL"); + ms_retvm_if(param == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param is NULL"); + ms_retvm_if(param_value == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "param_value is NULL"); + if (ms_node->type == MEDIA_STREAMER_NODE_TYPE_RTP) { ret = __ms_rtp_node_set_property(ms_node, param, param_value); + ms_debug_fleave(); return ret; } if (ms_node->type == MEDIA_STREAMER_NODE_TYPE_SRC && ms_node->subtype == MEDIA_STREAMER_NODE_SRC_TYPE_ADAPTIVE) { ret = __ms_adaptive_src_node_set_property(ms_node, param, param_value); + ms_debug_fleave(); return ret; } @@ -1513,14 +1761,21 @@ int __ms_node_set_param_value(media_streamer_node_s *ms_node, param_s *param, co ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER; } + ms_debug_fleave(); + return ret; } int __ms_node_set_pad_format(media_streamer_node_s *node, const char *pad_name, media_format_h fmt) { - ms_retvm_if(!node || !pad_name || !fmt, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - int ret = MEDIA_STREAMER_ERROR_NONE; + + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "pad_name is NULL"); + ms_retvm_if(fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "fmt is NULL"); + if (node->type == MEDIA_STREAMER_NODE_TYPE_RTP) { media_format_mimetype_e mime; gchar *rtp_caps_str = NULL; @@ -1548,6 +1803,8 @@ int __ms_node_set_pad_format(media_streamer_node_s *node, const char *pad_name, ret = __ms_element_set_fmt(node, pad_name, fmt); } + ms_debug_fleave(); + return ret; } @@ -1556,6 +1813,13 @@ gboolean _ms_node_resouces_acquire_iter(const GValue *item, GValue *ret, gpointe media_streamer_s *ms_streamer = (media_streamer_s *) user_data; media_streamer_node_s *node = NULL; GstElement *element = NULL; + + ms_debug_fenter(); + + ms_retvm_if(item == NULL, FALSE, "item is NULL"); + ms_retvm_if(ms_streamer == NULL, FALSE, "ms_streamer is NULL"); + ms_retvm_if(ret == NULL, FALSE, "ret is NULL"); + g_value_set_boolean(ret, FALSE); element = GST_ELEMENT(g_value_get_object(item)); @@ -1582,6 +1846,8 @@ gboolean _ms_node_resouces_acquire_iter(const GValue *item, GValue *ret, gpointe g_object_unref(element); + ms_debug_fleave(); + return TRUE; } @@ -1590,6 +1856,13 @@ gboolean _ms_node_resouces_release_iter(const GValue *item, GValue *ret, gpointe media_streamer_s *ms_streamer = (media_streamer_s *) user_data; media_streamer_node_s *node = NULL; GstElement *element = NULL; + + ms_debug_fenter(); + + ms_retvm_if(item == NULL, FALSE, "item is NULL"); + ms_retvm_if(ms_streamer == NULL, FALSE, "ms_streamer is NULL"); + ms_retvm_if(ret == NULL, FALSE, "ret is NULL"); + g_value_set_boolean(ret, FALSE); element = GST_ELEMENT(g_value_get_object(item)); @@ -1616,6 +1889,8 @@ gboolean _ms_node_resouces_release_iter(const GValue *item, GValue *ret, gpointe g_object_unref(element); + ms_debug_fleave(); + return TRUE; } @@ -1624,6 +1899,13 @@ gboolean _ms_node_policy_check_iter(const GValue *item, GValue *ret, gpointer us media_streamer_s *ms_streamer = (media_streamer_s *) user_data; media_streamer_node_s *node = NULL; GstElement *element = NULL; + + ms_debug_fenter(); + + ms_retvm_if(item == NULL, FALSE, "item is NULL"); + ms_retvm_if(ms_streamer == NULL, FALSE, "ms_streamer is NULL"); + ms_retvm_if(ret == NULL, FALSE, "ret is NULL"); + g_value_set_boolean(ret, FALSE); element = GST_ELEMENT(g_value_get_object(item)); @@ -1650,5 +1932,7 @@ gboolean _ms_node_policy_check_iter(const GValue *item, GValue *ret, gpointer us g_object_unref(element); + ms_debug_fleave(); + return TRUE; } -- 2.7.4 From fe5d2a027272b3d94ca1b47366a470d9f2549ea2 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Tue, 6 Mar 2018 16:33:52 +0900 Subject: [PATCH 06/16] Verify input argument of function Change-Id: Idac372a58d6c69c5cb436ca5eda30eee17a2ae7b Signed-off-by: Hyunil --- src/media_streamer.c | 7 +- src/media_streamer_gst.c | 141 +++++++++++++++++++++++++++--------- src/media_streamer_http_server.c | 98 ++++++++++++++++++------- src/media_streamer_node.c | 12 ++- src/media_streamer_node_policy.c | 53 +++++++++++--- src/media_streamer_node_resources.c | 51 +++++++++++-- src/media_streamer_priv.c | 92 ++++++++++++++++++++--- src/media_streamer_util.c | 66 ++++++++++++++++- 8 files changed, 426 insertions(+), 94 deletions(-) diff --git a/src/media_streamer.c b/src/media_streamer.c index 1c7f75f..f728561 100644 --- a/src/media_streamer.c +++ b/src/media_streamer.c @@ -150,6 +150,7 @@ int media_streamer_node_remove(media_streamer_h streamer, media_streamer_node_h ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(ms_streamer->nodes_table == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer->nodes_table is NULL"); ms_retvm_if(ms_streamer->state > MEDIA_STREAMER_STATE_IDLE, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be in IDLE state"); ms_retvm_if(ms_streamer != ms_node->parent_streamer, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Node [%s] added into another Media Streamer object", ms_node->name); @@ -178,6 +179,7 @@ int media_streamer_node_add(media_streamer_h streamer, media_streamer_node_h nod ms_debug_fenter(); ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer is NULL"); + ms_retvm_if(ms_streamer->nodes_table == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "streamer->nodes_table is NULL"); ms_retvm_if(ms_streamer->state > MEDIA_STREAMER_STATE_IDLE, MEDIA_STREAMER_ERROR_INVALID_STATE, "Error: Media streamer must be in IDLE state"); ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); ms_retvm_if(ms_node->parent_streamer != NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Node [%s] already added into Media Streamer object", ms_node->name); @@ -420,6 +422,7 @@ int media_streamer_src_set_buffer_status_cb(media_streamer_node_h source, media_ ms_debug_fenter(); ms_retvm_if(ms_src == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "source is NULL"); + ms_retvm_if(callback == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "callback is NULL"); if (!ms_src->callbacks_structure) { src_callback = (media_streamer_callback_s *) calloc(1, sizeof(media_streamer_callback_s)); @@ -463,6 +466,7 @@ int media_streamer_sink_set_data_ready_cb(media_streamer_node_h sink, media_stre ms_debug_fenter(); ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink is NULL"); + ms_retvm_if(callback == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "callback is NULL"); sink_callbacks = ms_sink->callbacks_structure; if (!sink_callbacks) { @@ -510,6 +514,7 @@ int media_streamer_sink_set_eos_cb(media_streamer_node_h sink, media_streamer_si ms_debug_fenter(); ms_retvm_if(ms_sink == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sink is NULL"); + ms_retvm_if(callback == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "callback is NULL"); sink_callbacks = ms_sink->callbacks_structure; if (!sink_callbacks) { @@ -737,8 +742,6 @@ int media_streamer_node_link(media_streamer_node_h src_node, const char *src_pad ms_retvm_if(ms_src_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "src_node is NULL"); ms_retvm_if(ms_dest_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "dest_node is NULL"); - ms_retvm_if(src_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "src_pad_name is NULL"); - ms_retvm_if(sink_pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "sink_pad_name is NULL"); link_ret = gst_element_link_pads(ms_src_node->gst_element, src_pad_name, ms_dest_node->gst_element, sink_pad_name); diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index 29e508c..0007ffb 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -36,7 +36,7 @@ static int __ms_adaptive_sink_prepare(media_streamer_s * ms_streamer); void __ms_generate_dots(GstElement *bin, gchar *name_tag) { gchar *dot_name; - ms_retm_if(bin == NULL, "Handle is NULL"); + ms_retm_if(bin == NULL, "bin is NULL"); if (!name_tag) dot_name = g_strdup(DOT_FILE_NAME); @@ -56,6 +56,8 @@ static int __ms_add_no_target_ghostpad(GstElement *gst_bin, const char *ghost_pa ms_debug_fenter(); + ms_retvm_if(gst_bin == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "gst_bin is NULL"); + bin_name = gst_element_get_name(gst_bin); ghost_pad = gst_ghost_pad_new_no_target(ghost_pad_name, pad_direction); if (gst_element_add_pad(GST_ELEMENT(gst_bin), ghost_pad)) { @@ -81,7 +83,9 @@ static gboolean __ms_add_ghostpad(GstElement *gst_element, const char *pad_name, ms_debug_fenter(); - ms_retvm_if(!gst_element || !pad_name || !ghost_pad_name || !gst_bin, FALSE, "Handle is NULL"); + ms_retvm_if(!gst_element, FALSE, "gst_element is NULL"); + ms_retvm_if(!pad_name, FALSE, "pad_name is NULL"); + ms_retvm_if(!gst_bin, FALSE, "gst_bin is NULL"); element_pad = gst_element_get_static_pad(gst_element, pad_name); @@ -90,6 +94,8 @@ static gboolean __ms_add_ghostpad(GstElement *gst_element, const char *pad_name, element_pad = gst_element_get_request_pad(gst_element, pad_name); ghost_pad = gst_ghost_pad_new(ghost_pad_name, element_pad); + ms_retvm_if(!ghost_pad, FALSE, "ghost_pad is NULL"); + gst_pad_set_active(ghost_pad, TRUE); ret = gst_element_add_pad(GST_ELEMENT(gst_bin), ghost_pad); @@ -114,6 +120,8 @@ static gboolean __ms_pad_peer_unlink(GstPad *pad) ms_debug_fenter(); + ms_retvm_if(!pad, FALSE, "pad is NULL"); + if (!gst_pad_is_linked(pad)) return TRUE; @@ -164,13 +172,15 @@ static GstElement *__ms_pad_get_peer_element(GstPad *pad) ms_debug_fenter(); + ms_retvm_if(!pad, NULL, "pad is NULL"); + if (!gst_pad_is_linked(pad)) { ms_info("Pad [%s:%s] is not linked yet", GST_DEBUG_PAD_NAME(pad)); return NULL; } peer_pad = gst_pad_get_peer(pad); - ms_retvm_if(!peer_pad, FALSE, "Fail to get peer pad"); + ms_retvm_if(!peer_pad, NULL, "Fail to get peer pad"); ret = gst_pad_get_parent_element(peer_pad); if (!ret) { @@ -213,6 +223,8 @@ gboolean __ms_element_unlink(GstElement *element) ms_debug_fenter(); + ms_retvm_if(!element, FALSE, "element is NULL"); + pad_iterator = gst_element_iterate_pads(element); while (GST_ITERATOR_OK == gst_iterator_next(pad_iterator, &elem)) { pad = (GstPad *) g_value_get_object(&elem); @@ -234,6 +246,8 @@ gboolean __ms_bin_remove_element(GstElement *element) ms_debug_fenter(); + ms_retvm_if(!element, FALSE, "element is NULL"); + parent = (GstElement *) gst_element_get_parent(element); /* Remove node's element from bin that decreases ref count */ @@ -257,6 +271,9 @@ gboolean __ms_bin_add_element(GstElement *bin, GstElement *element, gboolean do_ ms_debug_fenter(); + ms_retvm_if(!bin, FALSE, "bin is NULL"); + ms_retvm_if(!element, FALSE, "element is NULL"); + parent = (GstElement *) gst_element_get_parent(element); /* Add node's element into bin and increases ref count if needed */ @@ -282,6 +299,8 @@ const gchar *__ms_get_pad_type(GstPad *element_pad) ms_debug_fenter(); + ms_retvm_if(!element_pad, NULL, "element_pad is NULL"); + pad_caps = gst_pad_query_caps(element_pad, 0); MS_GET_CAPS_TYPE(pad_caps, pad_type); gst_caps_unref(pad_caps); @@ -300,6 +319,11 @@ static GstElement *__ms_find_peer_element_by_type(GstElement *previous_element, ms_debug_fenter(); + ms_retvm_if(!previous_element, NULL, "previous_element is NULL"); + ms_retvm_if(!node_klass_type, NULL, "node_klass_type is NULL"); + ms_retvm_if(!node_klass_type->klass_name, NULL, "node_klass_type->klass_name is NULL"); + ms_retvm_if(!node_klass_type->default_name, NULL, "node_klass_type->default_name is NULL"); + if (prev_elem_src_pad) { /* Check if previous element`s source pad is connected with element */ @@ -352,6 +376,9 @@ gboolean __ms_link_two_elements(GstElement *previous_element, GstPad *prev_elem_ ms_debug_fenter(); + ms_retvm_if(!previous_element, FALSE, "previous_element is NULL"); + ms_retvm_if(!found_element, FALSE, "found_element is NULL"); + if (prev_elem_src_pad) { peer_element = __ms_pad_get_peer_element(prev_elem_src_pad); if (!gst_pad_is_linked(prev_elem_src_pad)) { @@ -414,10 +441,17 @@ static GstElement *__ms_bin_find_element_by_type(GstElement *previous_element, G GstElement *found_element = NULL; gboolean elements_linked = FALSE; const gchar *found_klass = NULL; + GstIterator *bin_iterator = NULL; ms_debug_fenter(); - GstIterator *bin_iterator = gst_bin_iterate_sorted(GST_BIN(search_bin)); + ms_retvm_if(!previous_element, NULL, "previous_element is NULL"); + ms_retvm_if(!search_bin, NULL, "search_bin is NULL"); + ms_retvm_if(!node_klass_type, NULL, "node_klass_type is NULL"); + ms_retvm_if(!node_klass_type->default_name, NULL, "node_klass_type->default_name is NULL"); + + bin_iterator = gst_bin_iterate_sorted(GST_BIN(search_bin)); + while (GST_ITERATOR_OK == gst_iterator_next(bin_iterator, &element_value)) { found_element = (GstElement *) g_value_get_object(&element_value); found_klass = gst_element_factory_get_klass(gst_element_get_factory(found_element)); @@ -434,6 +468,7 @@ static GstElement *__ms_bin_find_element_by_type(GstElement *previous_element, G } g_value_reset(&element_value); } + g_value_unset(&element_value); gst_iterator_free(bin_iterator); @@ -442,9 +477,13 @@ static GstElement *__ms_bin_find_element_by_type(GstElement *previous_element, G return elements_linked ? found_element : NULL; } -int __ms_factory_rank_compare(GstPluginFeature * first_feature, GstPluginFeature * second_feature) +int __ms_factory_rank_compare(GstPluginFeature *first_feature, GstPluginFeature *second_feature) { ms_debug_fenter(); + + ms_retvm_if(!first_feature, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "first_feature is NULL"); + ms_retvm_if(!second_feature, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "second_feature is NULL"); + ms_debug_fleave(); return (gst_plugin_feature_get_rank(second_feature) - gst_plugin_feature_get_rank(first_feature)); } @@ -455,10 +494,10 @@ GstElement *__ms_combine_next_element(GstElement *previous_element, GstPad *prev GstElement *found_element = NULL; node_info_s *node_klass_type = NULL; - ms_debug_fenter(); + ms_retvm_if(!previous_element, NULL, "previous_element is NULL"); + ms_retvm_if(!bin_to_find_in, NULL, "bin_to_find_in is NULL"); - if (!previous_element) - return NULL; + ms_debug_fenter(); node_klass_type = __ms_node_get_klass_by_its_type(node_type); @@ -526,7 +565,8 @@ static gint __decodebin_autoplug_select_cb(GstElement * bin, GstPad * pad, GstCa ms_debug_fenter(); - ms_retvm_if(!ms_streamer, GST_AUTOPLUG_SELECT_TRY, "Handle is NULL"); + ms_retvm_if(!factory, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "factory is NULL"); + ms_retvm_if(!ms_streamer, GST_AUTOPLUG_SELECT_TRY, "data is NULL"); factory_name = GST_OBJECT_NAME(factory); klass = gst_element_factory_get_metadata(factory, GST_ELEMENT_METADATA_KLASS); @@ -591,6 +631,9 @@ static gint __pad_type_compare(gconstpointer a, gconstpointer b) ms_debug_fenter(); + ms_retvm_if(!a, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "a is NULL"); + ms_retvm_if(!b, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "b is NULL"); + a_pad = GST_PAD(a); b_pad = GST_PAD(b); @@ -613,7 +656,8 @@ static void __decodebin_newpad_cb(GstElement * decodebin, GstPad * new_pad, gpoi ms_debug_fenter(); - ms_retm_if(ms_streamer == NULL, "Handle is NULL"); + ms_retm_if(new_pad == NULL, "new_pad is NULL"); + ms_retm_if(ms_streamer == NULL, "user_data is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -633,6 +677,9 @@ static void __decodebin_nomore_pads_combine(GstPad *src_pad, media_streamer_s *m ms_debug_fenter(); + ms_retm_if(src_pad == NULL, "src_pad is NULL"); + ms_retm_if(ms_streamer == NULL, "ms_streamer is NULL"); + found_element = gst_pad_get_parent_element(src_pad); new_pad_type = __ms_get_pad_type(src_pad); @@ -691,7 +738,8 @@ static void __decodebin_nomore_pads_cb(GstElement *decodebin, gpointer user_data ms_debug_fenter(); - ms_retm_if(ms_streamer == NULL, "Handle is NULL"); + ms_retm_if(decodebin == NULL, "decodebin is NULL"); + ms_retm_if(ms_streamer == NULL, "user_data is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -736,7 +784,7 @@ GstElement *__ms_decodebin_create(media_streamer_s * ms_streamer, char * name) ms_debug_fenter(); - ms_retvm_if(!ms_streamer, NULL, "Handle is NULL"); + ms_retvm_if(!ms_streamer, NULL, "ms_streamer is NULL"); decodebin = __ms_element_create(DEFAULT_DECODEBIN, name); __ms_bin_add_element(ms_streamer->transform_bin, decodebin, TRUE); @@ -759,6 +807,9 @@ static gboolean __ms_sink_bin_prepare(media_streamer_s * ms_streamer, GstPad * s ms_debug_fenter(); + ms_retvm_if(!ms_streamer, FALSE, "ms_streamer is NULL"); + ms_retvm_if(!source_pad, FALSE, "source_pad is NULL"); + /* Getting Depayloader */ parent_rtp_element = gst_pad_get_parent_element(source_pad); @@ -815,7 +866,8 @@ static void __ms_rtpbin_pad_added_cb(GstElement * src, GstPad * new_pad, gpointe ms_debug_fenter(); - ms_retm_if(ms_node == NULL, "Handle is NULL"); + ms_retm_if(new_pad == NULL, "new_pad is NULL"); + ms_retm_if(ms_node == NULL, "ms_node is NULL"); ms_debug("Pad [%s] added on [%s]", GST_PAD_NAME(new_pad), GST_ELEMENT_NAME(src)); if (g_str_has_prefix(GST_PAD_NAME(new_pad), "recv_rtp_src")) { @@ -865,7 +917,7 @@ int __ms_element_set_state(GstElement * gst_element, GstState gst_state) ms_debug_fenter(); - ms_retvm_if(gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_retvm_if(gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "gst_element is NULL"); ret_state = gst_element_set_state(gst_element, gst_state); @@ -931,6 +983,8 @@ static int __ms_adaptive_sink_prepare(media_streamer_s * ms_streamer) ms_debug_fenter(); + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + video_enc_src_caps = gst_caps_new_simple("video/mpeg", "mpegversion", G_TYPE_INT, 4, NULL); video_enc_sink_caps = gst_caps_new_empty_simple("video/x-raw"); video_enc_plug_info.info = &(nodes_info[0]); @@ -992,6 +1046,8 @@ static GstElement *__ms_manifest_src_create(media_streamer_node_s *ms_node) ms_debug_fenter(); + ms_retvm_if(!ms_node, NULL, "ms_node is NULL"); + val = (GValue *)g_object_get_data(G_OBJECT(ms_node->gst_element), MEDIA_STREAMER_PARAM_URI); uri = g_value_get_string(val); protocol = gst_uri_is_valid(uri) ? gst_uri_get_protocol(uri) : NULL; @@ -1048,7 +1104,7 @@ int __ms_adaptive_element_prepare(media_streamer_node_s *ms_node, bool auto_plug ms_debug_fenter(); - ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_node is NULL"); if (!auto_plug) { plugin_name = __ms_ini_get_string("node type 1:adaptive", DEFAULT_ADAPTIVE_SOURCE); @@ -1104,8 +1160,6 @@ static gboolean __ms_feature_node_filter(GstPluginFeature *feature, gpointer dat GstElementFactory *factory = NULL; const gchar *factory_klass = NULL; - ms_debug_fenter(); - if (!GST_IS_ELEMENT_FACTORY(feature)) return FALSE; @@ -1141,8 +1195,6 @@ static gboolean __ms_feature_node_filter(GstPluginFeature *feature, gpointer dat } - ms_debug_fleave(); - return FALSE; } @@ -1156,6 +1208,8 @@ static GstElement *__ms_element_create_from_ini(node_plug_s *plug_info, media_st ms_debug_fenter(); + ms_retvm_if(plug_info == NULL, NULL, "plug_info is NULL"); + MS_GET_CAPS_TYPE(plug_info->src_caps, src_type); MS_GET_CAPS_TYPE(plug_info->sink_caps, sink_type); @@ -1207,6 +1261,8 @@ static GstElement *__ms_element_create_by_registry(node_plug_s *plug_info, media ms_debug_fenter(); + ms_retvm_if(plug_info == NULL, NULL, "plug_info is NULL"); + MS_GET_CAPS_TYPE(plug_info->src_caps, src_type); MS_GET_CAPS_TYPE(plug_info->sink_caps, sink_type); @@ -1240,6 +1296,8 @@ GstElement *__ms_node_element_create(node_plug_s *plug_info, media_streamer_node ms_debug_fenter(); + ms_retvm_if(plug_info == NULL, NULL, "plug_info is NULL"); + MS_GET_CAPS_TYPE(plug_info->src_caps, src_type); MS_GET_CAPS_TYPE(plug_info->sink_caps, sink_type); @@ -1298,6 +1356,8 @@ GstElement *__ms_video_encoder_element_create(node_plug_s *plug_info, media_stre ms_debug_fenter(); + ms_retvm_if(plug_info == NULL, NULL, "plug_info is NULL"); + enc_caps = plug_info->src_caps; if (!enc_caps) { enc_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_VIDEO_FORMAT); @@ -1396,6 +1456,8 @@ GstElement *__ms_video_decoder_element_create(node_plug_s *plug_info, media_stre ms_debug_fenter(); + ms_retvm_if(plug_info == NULL, NULL, "plug_info is NULL"); + dec_caps = plug_info->sink_caps; if (!dec_caps) { dec_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_VIDEO_FORMAT); @@ -1506,6 +1568,8 @@ GstElement *__ms_audio_encoder_element_create(node_plug_s *plug_info, media_stre ms_debug_fenter(); + ms_retvm_if(plug_info == NULL, NULL, "plug_info is NULL"); + enc_caps = plug_info->src_caps; if (!enc_caps) { enc_caps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_AUDIO_FORMAT); @@ -1716,7 +1780,7 @@ gboolean __ms_rtp_element_prepare(media_streamer_node_s *ms_node) ms_debug_fenter(); - ms_retvm_if(!ms_node, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Handle is NULL"); + ms_retvm_if(!ms_node, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "ms_node is NULL"); rtpbin = __ms_element_create("rtpbin", "rtpbin"); ms_retvm_if(!rtpbin, FALSE, "Error: creating elements for rtp container"); @@ -1883,8 +1947,8 @@ static gboolean __ms_parse_gst_error(media_streamer_s *ms_streamer, GstMessage * ms_debug_fenter(); ms_retvm_if(!ms_streamer, FALSE, "Error: invalid Media Streamer handle."); - ms_retvm_if(!error, FALSE, "Error: invalid error handle."); ms_retvm_if(!message, FALSE, "Error: invalid bus message handle."); + ms_retvm_if(!error, FALSE, "Error: invalid error handle."); if (error->domain == GST_CORE_ERROR) ret_error = MEDIA_STREAMER_ERROR_INVALID_OPERATION; @@ -1913,8 +1977,6 @@ static GstPadProbeReturn __ms_element_event_probe(GstPad * pad, GstPadProbeInfo GstElement *parent_element = NULL; GstEvent *event = NULL; - ms_debug_fenter(); - parent_element = gst_pad_get_parent_element(pad); if (!parent_element) { ms_error("filed to get parent_elem"); @@ -1934,8 +1996,6 @@ static GstPadProbeReturn __ms_element_event_probe(GstPad * pad, GstPadProbeInfo MS_SAFE_UNREF(parent_element); - ms_debug_fleave(); - return GST_PAD_PROBE_PASS; } @@ -2017,8 +2077,6 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) gchar *state_transition_name = NULL; GstState state_old = 0, state_new = 0, state_pending = 0; - ms_debug_fenter(); - ms_streamer = (media_streamer_s *) userdata; ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); ms_retvm_if(ms_streamer->pipeline == NULL, MEDIA_STREAMER_ERROR_INVALID_STATE, "Pipeline doesn`t exist"); @@ -2072,6 +2130,7 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) } case GST_MESSAGE_ASYNC_DONE:{ + ms_debug("GST_MESSAGE_ASYNC_DONE"); if (GST_MESSAGE_SRC(message) == GST_OBJECT(ms_streamer->pipeline) && ms_streamer->is_seeking) { @@ -2107,8 +2166,6 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) } } - ms_debug_fleave(); - return TRUE; } @@ -2186,7 +2243,7 @@ int __ms_pipeline_create(media_streamer_s *ms_streamer) ms_debug_fenter(); - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); /* initialize gstreamer with configured parameter */ ret = __ms_gstreamer_init(ms_streamer); @@ -2334,6 +2391,10 @@ int __ms_element_pad_names(GstElement *gst_element, GstPadDirection pad_type, ch ms_debug_fenter(); + ms_retvm_if(gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "gst_element is NULL"); + ms_retvm_if(pad_name_array == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "pad_name_array is NULL"); + ms_retvm_if(pads_count == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "pads_count is NULL"); + if (pad_type == GST_PAD_SRC) { pad_iterator = gst_element_iterate_src_pads(gst_element); } else if (pad_type == GST_PAD_SINK) { @@ -2386,7 +2447,10 @@ int __ms_element_get_pad_fmt(GstElement *gst_element, const char *pad_name, medi ms_debug_fenter(); - ms_retvm_if(gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Element handle is NULL"); + ms_retvm_if(gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "gst_element is NULL"); + ms_retvm_if(pad_name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "pad_name is NULL"); + ms_retvm_if(fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "fmt is NULL"); + pad = gst_element_get_static_pad(gst_element, pad_name); ms_retvm_if(pad == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Fail to get pad [%s] from element [%s].", pad_name, GST_ELEMENT_NAME(gst_element)); @@ -2601,7 +2665,8 @@ static void __demux_newpad_cb(GstElement * demux, GstPad * new_pad, gpointer use ms_debug_fenter(); - ms_retm_if(ms_streamer == NULL, "Handle is NULL"); + ms_retm_if(ms_streamer == NULL, "user_data is NULL"); + ms_retm_if(new_pad == NULL, "new_pad is NULL"); g_mutex_lock(&ms_streamer->mutex_lock); @@ -2666,8 +2731,8 @@ int __ms_demux_element_prepare(media_streamer_s * ms_streamer, media_streamer_no { ms_debug_fenter(); - ms_retvm_if(!ms_streamer, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(!demux_node, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_retvm_if(!ms_streamer, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + ms_retvm_if(!demux_node, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "demux_node is NULL"); __ms_signal_create(&ms_streamer->autoplug_sig_list, demux_node->gst_element, "pad-added", G_CALLBACK(__demux_newpad_cb), ms_streamer); __ms_signal_create(&ms_streamer->autoplug_sig_list, demux_node->gst_element, "no-more-pads", G_CALLBACK(__demux_nomore_pads_cb), ms_streamer); @@ -2687,6 +2752,9 @@ static void __ms_typefound_cb(GstElement *typefind, guint probability, GstCaps * ms_debug_fenter(); + ms_retm_if(!typefind, "typefind is NULL"); + ms_retm_if(!ms_streamer, "data is NULL"); + adaptive_sink = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "adaptive_sink"); src_pad = gst_element_get_static_pad(typefind, "src"); @@ -2711,7 +2779,12 @@ int __ms_find_type(media_streamer_s *ms_streamer, GstElement *src_element) ms_debug_fenter(); + ms_retvm_if(!ms_streamer, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + ms_retvm_if(!src_element, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "src_element is NULL"); + src_pad = gst_element_get_static_pad(src_element, "src"); + ms_retvm_if(src_pad == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, + "Error getting static_pad [src_pad]"); typefind = gst_element_factory_make("typefind", "typefinder"); ms_retvm_if(typefind == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, diff --git a/src/media_streamer_http_server.c b/src/media_streamer_http_server.c index fa60577..7f1bb08 100644 --- a/src/media_streamer_http_server.c +++ b/src/media_streamer_http_server.c @@ -41,14 +41,18 @@ static void __ms_http_server_connection_handle_cb(SoupServer *server, SoupMessag int __ms_http_server_create(media_streamer_http_server_h *server, char *ip_address, char *port) { - ms_retvm_if(server == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - //ms_retvm_if(ip_address == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "IP address is NULL"); + _ms_http_server_s *ms_server; + int iport; + + ms_debug_fenter(); + + ms_retvm_if(server == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "server is NULL"); ms_retvm_if(port == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Port is NULL"); - _ms_http_server_s *ms_server = (_ms_http_server_s *) calloc(1, sizeof(_ms_http_server_s)); + ms_server = (_ms_http_server_s *) calloc(1, sizeof(_ms_http_server_s)); ms_retvm_if(ms_server == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error allocation memory"); - const int iport = atoi(port); + iport = atoi(port); ms_server->server = soup_server_new(SOUP_SERVER_PORT, iport, NULL); if (!ms_server->server) { @@ -69,59 +73,83 @@ int __ms_http_server_create(media_streamer_http_server_h *server, char *ip_addre ms_info("http server created successfully"); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int __ms_http_server_destroy(media_streamer_http_server_h server) { - ms_retvm_if(server == NULL, MEDIA_STREAMER_ERROR_NONE, "Handle is NULL"); _ms_http_server_s *hserver = (_ms_http_server_s *) server; + ms_debug_fenter(); + + ms_retvm_if(hserver == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "server is NULL"); + /* Stop server first */ __ms_http_server_stop(server); /* Destroy URIs hash table */ - g_hash_table_destroy(hserver->uri_table); + if (hserver->uri_table) { + g_hash_table_destroy(hserver->uri_table); + } else { + ms_error("uri_table is NULL"); + } if (hserver->server) g_object_unref(hserver->server); MS_SAFE_GFREE(hserver); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int __ms_http_server_start(media_streamer_http_server_h server) { - ms_retvm_if(server == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - _ms_http_server_s *hserver = (_ms_http_server_s *) server; + ms_debug_fenter(); + + ms_retvm_if(hserver == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "server is NULL"); + ms_retvm_if(hserver->server == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "hserver->server is NULL"); + soup_server_add_handler(hserver->server, NULL, __ms_http_server_connection_handle_cb, hserver, NULL); soup_server_run_async(hserver->server); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int __ms_http_server_stop(media_streamer_http_server_h server) { - ms_retvm_if(server == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); _ms_http_server_s *hserver = (_ms_http_server_s *) server; + ms_debug_fenter(); + + ms_retvm_if(hserver == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "server is NULL"); + ms_retvm_if(hserver->server == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "hserver->server is NULL"); + soup_server_disconnect(hserver->server); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int __ms_http_server_register_uri(media_streamer_http_server_h server, char *uri, char *file_path) { - ms_retvm_if(server == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + _ms_http_server_s *hserver = (_ms_http_server_s *) server; + + ms_retvm_if(hserver == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "server is NULL"); ms_retvm_if(uri == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "URI address is NULL"); ms_retvm_if(file_path == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "File path is NULL"); - _ms_http_server_s *hserver = (_ms_http_server_s *) server; + ms_debug_fenter(); if (!hserver->uri_table) { ms_error("Failed to register URI. Table is NULL"); @@ -130,16 +158,20 @@ int __ms_http_server_register_uri(media_streamer_http_server_h server, char *uri g_hash_table_insert(hserver->uri_table, uri, file_path); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int __ms_http_server_unregister_uri(media_streamer_http_server_h server, char *uri) { - ms_retvm_if(server == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(uri == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "URI address is NULL"); - _ms_http_server_s *hserver = (_ms_http_server_s *) server; + ms_debug_fenter(); + + ms_retvm_if(hserver == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "server is NULL"); + ms_retvm_if(uri == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "URI address is NULL"); + if (!hserver->uri_table) { ms_error("Failed to unregister URI. Table is NULL"); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; @@ -154,6 +186,8 @@ int __ms_http_server_unregister_uri(media_streamer_http_server_h server, char *u return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -171,6 +205,11 @@ static int __ms_http_server_file_read_contents(const char *file_path, char **con struct stat stat_results = {0, }; int file_open = 0; + ms_debug_fenter(); + + ms_retvm_if(content == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "content is NULL"); + ms_retvm_if(size == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "size is NULL"); + if (!file_path || !strlen(file_path)) return MEDIA_STREAMER_ERROR_INVALID_PARAMETER; @@ -206,6 +245,8 @@ static int __ms_http_server_file_read_contents(const char *file_path, char **con close(file_open); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -213,31 +254,35 @@ static void __ms_http_server_connection_handle_cb(SoupServer *server, SoupMessag const char *path, GHashTable *query, SoupClientContext *client, gpointer user_data) { _ms_http_server_s *hserver = (_ms_http_server_s *) user_data; - - /* Close connetion if handle is NULL */ - ms_retm_if(hserver == NULL, "Handle is NULL"); - SoupMessageHeadersIter iter; const char *name, *value; + char *content = NULL; + gsize size = 0; + char *mime_type = NULL; + char *fs_dir = NULL; + char *file_path = NULL; + const char *extension = NULL; + + /* Close connetion if handle is NULL */ + ms_retm_if(hserver == NULL, "server is NULL"); + ms_retm_if(msg == NULL || msg->method == NULL || msg->request_headers == NULL, "msg is NULL"); + ms_retm_if(path == NULL, "path is NULL"); ms_debug("%s %s HTTP/1.%d", msg->method, path, soup_message_get_http_version(msg)); soup_message_headers_iter_init(&iter, msg->request_headers); while (soup_message_headers_iter_next(&iter, &name, &value)) ms_debug("%s: %s", name, value); - if (msg->request_body->length) + if (msg->request_body->length && msg->request_body->data) ms_debug("%s", msg->request_body->data); if (msg->method == SOUP_METHOD_GET || msg->method == SOUP_METHOD_HEAD) { ms_info("Received read event"); /* Extract file path with URI. First symbol is '/' */ - char *fs_dir = (char *)g_hash_table_lookup(hserver->uri_table, "adaptive_path"); - char *file_path = g_strjoin(NULL, fs_dir, path+1, NULL); - const char *extension = get_filename_ext(path+1); - char *content = NULL; - gsize size = 0; - char *mime_type = NULL; + fs_dir = (char *)g_hash_table_lookup(hserver->uri_table, "adaptive_path"); + file_path = g_strjoin(NULL, fs_dir, path+1, NULL); + extension = get_filename_ext(path+1); mime_type_get_mime_type(extension, &mime_type); @@ -260,4 +305,7 @@ static void __ms_http_server_connection_handle_cb(SoupServer *server, SoupMessag soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); soup_message_set_status(msg, SOUP_STATUS_OK); } + + ms_debug_fleave(); + } diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index 949f613..1723c00 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -301,7 +301,6 @@ int __ms_node_create(media_streamer_node_s *node, media_format_h in_fmt, media_f ms_debug_fenter(); ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); - ms_retvm_if(out_fmt == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "out_fmt is NULL"); sink_caps = in_fmt ? __ms_create_caps_from_fmt(in_fmt) : NULL; src_caps = out_fmt ? __ms_create_caps_from_fmt(out_fmt) : NULL; @@ -834,6 +833,7 @@ int __ms_node_insert_into_table(GHashTable *nodes_table, media_streamer_node_s * ms_retvm_if(nodes_table == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "nodes_table is NULL"); ms_retvm_if(ms_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_node is NULL"); + ms_retvm_if(ms_node->name == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_node->name is NULL"); if (g_hash_table_contains(nodes_table, ms_node->name)) { ms_debug("Current Node [%s] already added into Media Streamer", ms_node->name); @@ -988,7 +988,6 @@ static gboolean _sink_node_prepare(const GValue *item, GValue *g_ret, gpointer u ms_retvm_if(item == NULL, FALSE, "item is NULL"); ms_retvm_if(g_ret == NULL, FALSE, "ret is NULL"); - ms_retvm_if(user_data == NULL, FALSE, "user_data is NULL"); ms_debug_fenter(); @@ -1015,6 +1014,7 @@ static int __ms_adaptive_sink_http_server_prepare(media_streamer_s * ms_streamer ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + ms_retvm_if(node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node->gst_element is NULL"); /* Create and start http server */ err_code = __ms_http_server_create(&ms_streamer->http_server, NULL, DEFAULT_HTTP_PORT); @@ -1064,7 +1064,10 @@ int __ms_pipeline_prepare(media_streamer_s *ms_streamer) ms_debug_fenter(); - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + ms_retvm_if(ms_streamer->nodes_table == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer->nodes_table is NULL"); + ms_retvm_if(ms_streamer->src_bin == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer->src_bin is NULL"); + ms_retvm_if(ms_streamer->transform_bin == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer->transform_bin is NULL"); rtp_node = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "rtp_container"); demux = (media_streamer_node_s *)g_hash_table_find(ms_streamer->nodes_table, (GHRFunc)demux_find, NULL); @@ -1141,6 +1144,7 @@ static gboolean __ms_bin_remove_elements(media_streamer_s *ms_streamer, GstEleme ms_retvm_if(ms_streamer == NULL, FALSE, "ms_streamer is NULL"); ms_retvm_if(bin == NULL, FALSE, "bin is NULL"); + ms_retvm_if(ms_streamer->nodes_table == NULL, FALSE, "ms_streamer->nodes_table is NULL"); bin_iterator = gst_bin_iterate_elements(GST_BIN(bin)); it_res = gst_iterator_next(bin_iterator, &element); @@ -1198,6 +1202,7 @@ int __ms_pipeline_unprepare(media_streamer_s *ms_streamer) ms_debug_fenter(); ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_retvm_if(ms_streamer->nodes_table == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer->nodes_table is NULL"); ret = __ms_state_change(ms_streamer, MEDIA_STREAMER_STATE_IDLE); if (ret != MEDIA_STREAMER_ERROR_NONE) @@ -1904,6 +1909,7 @@ gboolean _ms_node_policy_check_iter(const GValue *item, GValue *ret, gpointer us ms_retvm_if(item == NULL, FALSE, "item is NULL"); ms_retvm_if(ms_streamer == NULL, FALSE, "ms_streamer is NULL"); + ms_retvm_if(ms_streamer->nodes_table == NULL, FALSE, "ms_streamer->nodes_table is NULL"); ms_retvm_if(ret == NULL, FALSE, "ret is NULL"); g_value_set_boolean(ret, FALSE); diff --git a/src/media_streamer_node_policy.c b/src/media_streamer_node_policy.c index 3c4f6ec..45cfcc2 100644 --- a/src/media_streamer_node_policy.c +++ b/src/media_streamer_node_policy.c @@ -35,9 +35,16 @@ const char* policy_str[DPM_POLICY_MAX] = { "microphone", }; -static void __ms_node_get_dpm_check_needed(media_streamer_node_s *node, - media_streamer_policy_type_e *policy) { - int subtype = node->subtype; +static void __ms_node_get_dpm_check_needed(media_streamer_node_s *node, media_streamer_policy_type_e *policy) +{ + int subtype; + + ms_debug_fenter(); + + ms_retm_if(node == NULL, "node is NULL"); + ms_retm_if(policy == NULL, "policy is NULL"); + + subtype = node->subtype; ms_debug("Checking policy for node type %d, subtype %d", node->type, subtype); @@ -45,23 +52,30 @@ static void __ms_node_get_dpm_check_needed(media_streamer_node_s *node, switch (subtype) { case MEDIA_STREAMER_NODE_SRC_TYPE_CAMERA: case MEDIA_STREAMER_NODE_SRC_TYPE_VIDEO_CAPTURE: - *policy = POLICY_TYPE_CAMERA; + *policy = POLICY_TYPE_CAMERA; break; case MEDIA_STREAMER_NODE_SRC_TYPE_AUDIO_CAPTURE: - *policy = POLICY_TYPE_MIC; + *policy = POLICY_TYPE_MIC; break; default: break; } + + ms_debug_fleave(); + } static void __ms_node_policy_changed_cb(const char *name, const char *value, void *user_data) { - if (user_data == NULL) - return; + media_streamer_node_s *node; + media_streamer_s *streamer; + + ms_debug_fenter(); - media_streamer_node_s *node = (media_streamer_node_s *) user_data; - media_streamer_s *streamer = (media_streamer_s *) node->parent_streamer; + ms_retm_if(user_data == NULL, "user_data is NULL"); + + node = (media_streamer_node_s *) user_data; + streamer = (media_streamer_s *) node->parent_streamer; ms_info("Received policy_changed_cb from node [%s]", node->name); /* Here we perform action to release resources relases that @@ -88,6 +102,9 @@ static void __ms_node_policy_changed_cb(const char *name, const char *value, voi ms_info("Interuption will not be handled because interrupted_cb is NULL"); } g_mutex_unlock(&streamer->mutex_lock); + + ms_debug_fleave(); + } int __ms_node_policy_init(media_streamer_node_s *node) @@ -96,6 +113,10 @@ int __ms_node_policy_init(media_streamer_node_s *node) int ret = MEDIA_STREAMER_ERROR_NONE; const char *policy_name = NULL; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + /* Check if node require policy manager */ __ms_node_get_dpm_check_needed(node, &policy); if (POLICY_TYPE_NONE == policy) { @@ -128,6 +149,8 @@ int __ms_node_policy_init(media_streamer_node_s *node) ms_debug("DPM initialized"); } + ms_debug_fleave(); + return ret; } @@ -136,6 +159,10 @@ int __ms_node_policy_deinit(media_streamer_node_s *node) media_streamer_policy_type_e policy = POLICY_TYPE_NONE; int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + /* Check if node require policy manager */ __ms_node_get_dpm_check_needed(node, &policy); if (POLICY_TYPE_NONE == policy) { @@ -156,6 +183,8 @@ int __ms_node_policy_deinit(media_streamer_node_s *node) dpm_manager_destroy(node->dpm_handle); node->dpm_handle = NULL; + ms_debug_fleave(); + return ret; } @@ -166,6 +195,10 @@ int _ms_node_policy_check(media_streamer_node_s *node) int dpm_state = DPM_ALLOWED; int dpm_ret = DPM_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + /* Check if node require policy manager */ __ms_node_get_dpm_check_needed(node, &policy); if (POLICY_TYPE_NONE == policy) { @@ -200,5 +233,7 @@ int _ms_node_policy_check(media_streamer_node_s *node) ms_info("get DPM state failed, continue too work"); } + ms_debug_fleave(); + return ret; } diff --git a/src/media_streamer_node_resources.c b/src/media_streamer_node_resources.c index 98bdfdd..f74b598 100644 --- a/src/media_streamer_node_resources.c +++ b/src/media_streamer_node_resources.c @@ -26,10 +26,17 @@ static gboolean __ms_node_resources_is_needed_by_platform(media_streamer_node_s *node) { - media_streamer_node_type_e type = node->type; - int subtype = node->subtype; char *model_name, *platform_processor; gboolean ret = FALSE; + media_streamer_node_type_e type; + int subtype; + + ms_debug_fenter(); + + ms_retvm_if(node == NULL, FALSE, "node is NULL"); + + type = node->type; + subtype = node->subtype; /* Checking for model_name and processor because some resources are platform dependent */ @@ -67,13 +74,23 @@ static gboolean __ms_node_resources_is_needed_by_platform(media_streamer_node_s MS_SAFE_FREE(model_name); MS_SAFE_FREE(platform_processor); + ms_debug_fleave(); + return ret; } -static gboolean __ms_node_get_resources_needed(media_streamer_node_s *node, - mm_resource_manager_res_type_e *resource) { - media_streamer_node_type_e type = node->type; - int subtype = node->subtype; +static gboolean __ms_node_get_resources_needed(media_streamer_node_s *node, mm_resource_manager_res_type_e *resource) +{ + media_streamer_node_type_e type; + int subtype; + + ms_debug_fenter(); + + ms_retvm_if(node == NULL, FALSE, "node is NULL"); + ms_retvm_if(resource == NULL, FALSE, "resource is NULL"); + + type = node->type; + subtype = node->subtype; ms_debug("Checking resources for node type %d, subtype %d", type, subtype); @@ -100,13 +117,21 @@ static gboolean __ms_node_get_resources_needed(media_streamer_node_s *node, break; } + ms_debug_fleave(); + return FALSE; } int _ms_node_resource_acquire(media_streamer_node_s *node) { mm_resource_manager_res_type_e resource; - mm_resource_manager_h resource_manager = node->parent_streamer->resource_manager; + mm_resource_manager_h resource_manager; + + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + + resource_manager = node->parent_streamer->resource_manager; /* Check if node require resource manager */ if (!__ms_node_get_resources_needed(node, &resource)) { @@ -149,12 +174,20 @@ int _ms_node_resource_acquire(media_streamer_node_s *node) return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int _ms_node_resource_release(media_streamer_node_s *node) { - mm_resource_manager_h resource_manager = node->parent_streamer->resource_manager; + mm_resource_manager_h resource_manager; + + ms_debug_fenter(); + + ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL"); + + resource_manager = node->parent_streamer->resource_manager; if (node->resource == NULL) { ms_error("Resources were not acquired for Node [%p]. Skipping...", node); @@ -177,5 +210,7 @@ int _ms_node_resource_release(media_streamer_node_s *node) node->resource = NULL; + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } diff --git a/src/media_streamer_priv.c b/src/media_streamer_priv.c index 30f2908..3fe5ded 100644 --- a/src/media_streamer_priv.c +++ b/src/media_streamer_priv.c @@ -32,7 +32,9 @@ int __ms_state_change(media_streamer_s *ms_streamer, media_streamer_state_e stat { int ret = MEDIA_STREAMER_ERROR_NONE; - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); ms_retvm_if(ms_streamer->state == state, MEDIA_STREAMER_ERROR_NONE, "Media streamer already in this state"); if (!ms_streamer->is_interrupted) { @@ -88,12 +90,19 @@ int __ms_state_change(media_streamer_s *ms_streamer, media_streamer_state_e stat } } + ms_debug_fleave(); + return ret; } int __ms_create(media_streamer_s *ms_streamer) { int ret = MEDIA_STREAMER_ERROR_NONE; + + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + __ms_load_ini_settings(&ms_streamer->ini); ms_streamer->nodes_table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __ms_node_remove_from_table); @@ -110,16 +119,20 @@ int __ms_create(media_streamer_s *ms_streamer) return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } + ms_debug_fleave(); + return ret; } int __ms_get_position(media_streamer_s *ms_streamer, int *time) { - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(time == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Return value is NULL"); - gint64 current = GST_CLOCK_TIME_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + ms_retvm_if(time == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Return value is NULL"); + if (!gst_element_query_position(ms_streamer->pipeline, GST_FORMAT_TIME, ¤t)) { ms_error("Could not query current position."); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; @@ -128,16 +141,18 @@ int __ms_get_position(media_streamer_s *ms_streamer, int *time) ms_info("Media streamer queried position at [%d] msec successfully.", *time); } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int __ms_get_duration(media_streamer_s *ms_streamer, int *time) { - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - ms_retvm_if(time == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Return value is NULL"); - gint64 duration = GST_CLOCK_TIME_NONE; + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + ms_retvm_if(time == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Return value is NULL"); + if (!gst_element_query_duration(ms_streamer->pipeline, GST_FORMAT_TIME, &duration)) { ms_error("Could not query current duration."); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; @@ -146,15 +161,19 @@ int __ms_get_duration(media_streamer_s *ms_streamer, int *time) ms_info("Media streamer queried duration [%d] msec successfully.", *time); } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } int __ms_streamer_seek(media_streamer_s *ms_streamer, int g_time, bool flag) { - ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - GstSeekFlags seek_flag; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + if (flag) seek_flag = GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE; else @@ -169,6 +188,8 @@ int __ms_streamer_seek(media_streamer_s *ms_streamer, int g_time, bool flag) ms_info("Media streamer pipeline seeked successfully to [%d] position", g_time); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -176,6 +197,10 @@ int __ms_streamer_destroy(media_streamer_s *ms_streamer) { int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + g_mutex_lock(&ms_streamer->mutex_lock); ret = __ms_state_change(ms_streamer, MEDIA_STREAMER_STATE_NONE); @@ -203,6 +228,8 @@ int __ms_streamer_destroy(media_streamer_s *ms_streamer) g_mutex_clear(&ms_streamer->mutex_lock); MS_SAFE_FREE(ms_streamer); + ms_debug_fleave(); + return ret; } @@ -210,6 +237,10 @@ int __ms_acquire_resources(media_streamer_s *ms_streamer) { int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + /* Acquire resources for src bin */ ret = __ms_bin_foreach_elements(GST_BIN(ms_streamer->src_bin), _ms_node_resouces_acquire_iter, ms_streamer); @@ -237,6 +268,8 @@ int __ms_acquire_resources(media_streamer_s *ms_streamer) return ret; } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -244,6 +277,10 @@ int __ms_release_resources(media_streamer_s *ms_streamer) { int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + /* Release resources for src bin */ ret = __ms_bin_foreach_elements(GST_BIN(ms_streamer->src_bin), _ms_node_resouces_release_iter, ms_streamer); @@ -270,6 +307,8 @@ int __ms_release_resources(media_streamer_s *ms_streamer) return ret; } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -277,6 +316,10 @@ int __ms_change_resources_state(media_streamer_s *ms_streamer, media_streamer_st { int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + /* According to state graph we need to handle only this two states * and different transotions into them */ if (state == MEDIA_STREAMER_STATE_IDLE) { @@ -311,11 +354,20 @@ int __ms_change_resources_state(media_streamer_s *ms_streamer, media_streamer_st ms_debug("Ignoring state for resource managements"); } + ms_debug_fleave(); + return ret; } static gboolean __ms_resource_node_find(gpointer key, gpointer value, gpointer user_data) { + ms_debug_fenter(); + + ms_retvm_if(key == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "key is NULL"); + ms_retvm_if(value == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "value is NULL"); + + ms_debug_fleave(); + return ((media_streamer_node_s *)value)->resource == (mm_resource_manager_res_h)user_data; } @@ -323,10 +375,14 @@ static gboolean __ms_resource_node_find(gpointer key, gpointer value, gpointer u static int __ms_resource_release_cb(mm_resource_manager_h rm, mm_resource_manager_res_h resource_h, void *user_data) { - ms_retvm_if(user_data == NULL, FALSE, "user_data is NULL"); - media_streamer_s *streamer = (media_streamer_s *) user_data; media_streamer_node_s *node; + + ms_debug_fenter(); + + ms_retvm_if(resource_h == NULL, FALSE, "resource_h is NULL"); + ms_retvm_if(streamer == NULL, FALSE, "user_data is NULL"); + ms_info("Received release_cb for streamer %p", streamer); /* Here we perform action to release resources that @@ -368,6 +424,8 @@ static int __ms_resource_release_cb(mm_resource_manager_h rm, } g_mutex_unlock(&streamer->mutex_lock); + ms_debug_fleave(); + return FALSE; } @@ -375,6 +433,10 @@ int __ms_check_policy(media_streamer_s *ms_streamer) { int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + /* Acquire resources for src bin */ ret = __ms_bin_foreach_elements(GST_BIN(ms_streamer->src_bin), _ms_node_policy_check_iter, ms_streamer); @@ -383,6 +445,8 @@ int __ms_check_policy(media_streamer_s *ms_streamer) return ret; } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -390,6 +454,10 @@ int __ms_change_policy_state(media_streamer_s *ms_streamer, media_streamer_state { int ret = MEDIA_STREAMER_ERROR_NONE; + ms_debug_fenter(); + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + /* According to state graph we need to handle only this state * and different transotions into them */ if (state == MEDIA_STREAMER_STATE_READY) { @@ -409,5 +477,7 @@ int __ms_change_policy_state(media_streamer_s *ms_streamer, media_streamer_state ms_debug("Ignoring state for policy managements"); } + ms_debug_fleave(); + return ret; } diff --git a/src/media_streamer_util.c b/src/media_streamer_util.c index 7f55672..3ad8754 100644 --- a/src/media_streamer_util.c +++ b/src/media_streamer_util.c @@ -93,6 +93,8 @@ gchar *__ms_ini_get_string(const char *ini_path, char *default_str) { gchar *result_str = NULL; + ms_debug_fenter(); + ms_retvm_if(ini_path == NULL, NULL, "Invalid ini path"); if (__ms_get_ini_instance() == NULL) { @@ -105,12 +107,18 @@ gchar *__ms_ini_get_string(const char *ini_path, char *default_str) else result_str = default_str; } + + ms_debug_fleave(); + return result_str ? g_strdup(result_str) : NULL; } dictionary *__ms_get_ini_instance(void) { static dictionary *instance = NULL; + + ms_debug_fenter(); + if (NULL == instance) { dictionary *ms_dict = NULL; __ms_check_ini_status(); @@ -125,15 +133,21 @@ dictionary *__ms_get_ini_instance(void) instance = ms_dict; } + ms_debug_fleave(); + return instance; } void __ms_ini_read_list(const char *key, gchar ***list) { + char *str; + + ms_debug_fenter(); + ms_retm_if(!__ms_get_ini_instance() || !list || !key, "Handle is NULL"); /* Read exclude elements list */ - gchar *str = iniparser_getstring(__ms_get_ini_instance(), key, NULL); + str = iniparser_getstring(__ms_get_ini_instance(), key, NULL); if (str && strlen(str) > 0) { gchar *strtmp = g_strdup(str); g_strstrip(strtmp); @@ -141,10 +155,16 @@ void __ms_ini_read_list(const char *key, gchar ***list) *list = g_strsplit(strtmp, ",", 10); MS_SAFE_FREE(strtmp); } + + ms_debug_fleave(); + } void __ms_load_ini_settings(media_streamer_ini_t *ini) { + + ms_debug_fenter(); + /* get ini values */ memset(ini, 0, sizeof(media_streamer_ini_t)); @@ -175,6 +195,9 @@ void __ms_load_ini_settings(media_streamer_ini_t *ini) /* general */ ms_debug("Media Streamer param [generate_dot] : %d", ini->generate_dot); ms_debug("Media Streamer param [use_decodebin] : %d", ini->use_decodebin); + + ms_debug_fleave(); + } static void __ms_check_ini_status(void) @@ -183,6 +206,8 @@ static void __ms_check_ini_status(void) int file_size = 0; int status = 0; + ms_debug_fenter(); + if (fp == NULL) { ms_debug("Failed to get media streamer ini file."); } else { @@ -196,12 +221,18 @@ static void __ms_check_ini_status(void) ms_error("failed to delete corrupted ini"); } } + + ms_debug_fleave(); + } const gchar *__ms_convert_mime_to_string_format(media_format_mimetype_e mime) { gchar *format_name = NULL; int it_format; + + ms_debug_fenter(); + for (it_format = 0; format_table[it_format].format != MEDIA_FORMAT_MAX; it_format++) { if (mime == format_table[it_format].format) { format_name = format_table[it_format].format_name; @@ -209,6 +240,8 @@ const gchar *__ms_convert_mime_to_string_format(media_format_mimetype_e mime) } } + ms_debug_fleave(); + return format_name; } @@ -236,6 +269,9 @@ media_format_mimetype_e __ms_convert_string_format_to_media_format(const char *f { media_format_mimetype_e mime = MEDIA_FORMAT_NATIVE_VIDEO; int it_format; + + ms_debug_fenter(); + for (it_format = 0; format_table[it_format].format != MEDIA_FORMAT_MAX; it_format++) { if (g_strrstr(format_type, format_table[it_format].format_name)) { mime = format_table[it_format].format; @@ -243,14 +279,20 @@ media_format_mimetype_e __ms_convert_string_format_to_media_format(const char *f } } + ms_debug_fleave(); + return mime; } void __ms_signal_create(GList **sig_list, GstElement *obj, const char *sig_name, GCallback cb, gpointer user_data) { + media_streamer_signal_s *sig_data; + + ms_debug_fenter(); + ms_retm_if(!sig_list || !obj || !sig_name, "Empty signal data!"); - media_streamer_signal_s *sig_data = (media_streamer_signal_s *) g_try_malloc(sizeof(media_streamer_signal_s)); + sig_data = (media_streamer_signal_s *) g_try_malloc(sizeof(media_streamer_signal_s)); if (!sig_data) { ms_error("Failed to create signal [%s] for object [%s]", sig_name, GST_OBJECT_NAME(obj)); return; @@ -266,11 +308,16 @@ void __ms_signal_create(GList **sig_list, GstElement *obj, const char *sig_name, ms_error("Failed to connect signal [%s] for object [%s]", sig_name, GST_OBJECT_NAME(obj)); MS_SAFE_GFREE(sig_data); } + + ms_debug_fleave(); } void __ms_signal_destroy(void *data) { media_streamer_signal_s *sig_data = (media_streamer_signal_s *) data; + + ms_debug_fenter(); + ms_retm_if(!sig_data, "Empty signal data!"); if (sig_data->obj && GST_IS_ELEMENT(sig_data->obj)) { @@ -280,11 +327,16 @@ void __ms_signal_destroy(void *data) } } MS_SAFE_GFREE(sig_data); + + ms_debug_fleave(); } void __ms_param_value_destroy(gpointer data) { GValue *val = (GValue *)data; + + ms_debug_fenter(); + ms_retm_if(!data, "Empty object data!"); if (GST_VALUE_HOLDS_CAPS(val)) { @@ -294,6 +346,8 @@ void __ms_param_value_destroy(gpointer data) g_value_unset(val); } MS_SAFE_GFREE(val); + + ms_debug_fleave(); } int __ms_util_uri_path_check(const char *file_uri) @@ -301,6 +355,8 @@ int __ms_util_uri_path_check(const char *file_uri) struct stat stat_results = {0, }; int file_open = 0; + ms_debug_fenter(); + if (!file_uri || !strlen(file_uri)) return MEDIA_STREAMER_ERROR_INVALID_PARAMETER; @@ -328,6 +384,8 @@ int __ms_util_uri_path_check(const char *file_uri) close(file_open); + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } @@ -335,6 +393,8 @@ int __ms_bin_foreach_elements(GstBin *bin, GstIteratorFoldFunction func, void *u { media_streamer_s *streamer = (media_streamer_s *) user_data; + ms_debug_fenter(); + if (!GST_BIN_NUMCHILDREN(bin)) { ms_debug("No elements were added to bin [%s]. Skipping... ", GST_ELEMENT_NAME(bin)); @@ -368,5 +428,7 @@ int __ms_bin_foreach_elements(GstBin *bin, GstIteratorFoldFunction func, void *u break; } + ms_debug_fleave(); + return MEDIA_STREAMER_ERROR_NONE; } -- 2.7.4 From 41dd5bfd5a6c4be827066562320ee19af27ca67c Mon Sep 17 00:00:00 2001 From: Hyunil Date: Tue, 6 Feb 2018 17:00:40 +0900 Subject: [PATCH 07/16] Apply ecore-wl2 instead of ecore-wayland Change-Id: I1f3545e93acf6e9001d8b1764eaa9a0029f00212 Signed-off-by: Hyunil --- CMakeLists.txt | 4 ++-- packaging/capi-media-streamer.spec | 8 ++++---- src/media_streamer_node.c | 42 ++++++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3867ff6..658ab0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,8 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog glib-2.0 mm-common capi-media-tool iniparser bundle libtbm gstreamer-1.0 gstreamer-plugins-base-1.0 gstreamer-app-1.0 gstreamer-video-1.0 cynara-client capi-system-info ecore elementary mm-resource-manager dpm capi-content-mime-type libsoup-2.4") -SET(pc_dependents "capi-base-common capi-media-tool gstreamer-1.0 gstreamer-plugins-base-1.0 gstreamer-app-1.0 gstreamer-video-1.0 cynara-client capi-system-info ecore evas elementary mm-resource-manager dpm capi-system-info capi-content-mime-type libsoup-2.4") +SET(dependents "dlog glib-2.0 mm-common capi-media-tool iniparser bundle libtbm gstreamer-1.0 gstreamer-plugins-base-1.0 gstreamer-app-1.0 gstreamer-video-1.0 cynara-client capi-system-info ecore-evas evas ecore-wl2 mm-resource-manager dpm capi-content-mime-type libsoup-2.4") +SET(pc_dependents "capi-base-common capi-media-tool bundle") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) diff --git a/packaging/capi-media-streamer.spec b/packaging/capi-media-streamer.spec index c5e2b77..9006e8c 100644 --- a/packaging/capi-media-streamer.spec +++ b/packaging/capi-media-streamer.spec @@ -1,6 +1,6 @@ Name: capi-media-streamer Summary: A Media Streamer API -Version: 0.1.21 +Version: 0.1.22 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -22,12 +22,12 @@ BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(capi-system-info) -#BuildRequires: pkgconfig(libtbm) BuildRequires: pkgconfig(tizen-extension-client) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(evas) -BuildRequires: pkgconfig(ecore-wayland) +BuildRequires: pkgconfig(ecore-wl2) +BuildRequires: pkgconfig(ecore-evas) BuildRequires: pkgconfig(appcore-efl) BuildRequires: pkgconfig(mm-resource-manager) BuildRequires: pkgconfig(dpm) @@ -52,7 +52,7 @@ cp %{SOURCE1001} . %define ini_path %{_sysconfdir}/multimedia/mmfw_media_streamer.ini %build -flags="-DMEDIA_STREAMER_INI_PATH=\\\"%{ini_path}\\\" -D_FILE_OFFSET_BITS=64" +flags="-DMEDIA_STREAMER_INI_PATH=\\\"%{ini_path}\\\" -D_FILE_OFFSET_BITS=64 -DEFL_BETA_API_SUPPORT" %if 0%{?sec_build_binary_debug_enable} flags="$flags -DTIZEN_DEBUG_ENABLE" diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index 1723c00..409e33e 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -21,9 +21,9 @@ #include #include #include -#include #include -#include +#include +#include #include #include @@ -1538,7 +1538,10 @@ static const struct tizen_resource_listener _media_streamer_tz_resource_listener int _media_streamer_get_wl_info(Evas_Object *obj, media_streamer_wl_info_s *wl_info) { int ret = MEDIA_STREAMER_ERROR_NONE; - Ecore_Wl_Window *window = NULL; + Ecore_Wl2_Window *window = NULL; + Ecore_Evas *ee = NULL; + Ecore_Wl2_Display *e_wl2_display = NULL; + Evas *e = NULL; struct wl_display *display = NULL; struct wl_display *display_wrapper = NULL; struct wl_surface *surface = NULL; @@ -1552,30 +1555,51 @@ int _media_streamer_get_wl_info(Evas_Object *obj, media_streamer_wl_info_s *wl_i return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } - window = elm_win_wl_window_get(obj); + e = evas_object_evas_get(obj); + if (!e) { + LOGE("failed to get evas object"); + ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; + goto _DONE; + } + + ee = ecore_evas_ecore_evas_get(e); + if (!ee) { + LOGE("failed to get ecore evas object"); + ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; + goto _DONE; + } + + window = ecore_evas_wayland2_window_get(ee); if (!window) { LOGE("failed to get wayland window"); ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; goto _DONE; } - surface = (struct wl_surface *)ecore_wl_window_surface_get(window); + /* set video_has flag to a video application window */ + ecore_wl2_window_video_has(window, EINA_TRUE); + + surface = (struct wl_surface *)ecore_wl2_window_surface_get(window); if (!surface) { LOGE("failed to get wayland surface"); ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; goto _DONE; } - display = (struct wl_display *)ecore_wl_display_get(); + e_wl2_display = ecore_wl2_connected_display_get(NULL); + if (!e_wl2_display) { + LOGE("failed to get ecore wl2 display"); + ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; + goto _DONE; + } + + display = (struct wl_display *)ecore_wl2_display_get(e_wl2_display); if (!display) { LOGE("failed to get wayland display"); ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; goto _DONE; } - /* set video_has flag to a video application window */ - ecore_wl_window_video_has(window, EINA_TRUE); - display_wrapper = wl_proxy_create_wrapper(display); if (!display_wrapper) { LOGE("failed to create wl display wrapper"); -- 2.7.4 From e83a4a3a06bc1c8f4651df0bcf596f56d14bae70 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Mon, 23 Apr 2018 17:08:53 +0900 Subject: [PATCH 08/16] replace ecore to ecore-wl2 Change-Id: Ibcedfd37cd0c01be7ae4b062ddcc438943525512 Signed-off-by: Hyunil --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e6a8af0..d816bb4 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES(../include) link_directories(${CMAKE_SOURCE_DIR}/../) INCLUDE(FindPkgConfig) -pkg_check_modules(${fw_test} REQUIRED glib-2.0 elementary evas ecore appcore-efl) +pkg_check_modules(${fw_test} REQUIRED glib-2.0 elementary evas ecore-wl2 appcore-efl) FOREACH(flag ${${fw_test}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -- 2.7.4 From 63a1e35bbf792233c615004891adf622fe49582c Mon Sep 17 00:00:00 2001 From: Hyunil Date: Tue, 19 Jun 2018 16:56:29 +0900 Subject: [PATCH 09/16] Change setting and getting camera_id for v4l2src and remove device property Change-Id: I443fddb3a1ddb0032d925de78ed53b7522e3b274 Signed-off-by: Hyunil --- src/media_streamer_node.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index 409e33e..e7e78e8 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -33,7 +33,6 @@ param_s param_table[] = { {MEDIA_STREAMER_PARAM_CAMERA_ID, "camera-id"}, - {MEDIA_STREAMER_PARAM_CAMERA_ID, "device"}, {MEDIA_STREAMER_PARAM_CAPTURE_WIDTH, "capture-width"}, {MEDIA_STREAMER_PARAM_CAPTURE_HEIGHT, "capture-height"}, {MEDIA_STREAMER_PARAM_IS_LIVE_STREAM, "is-live"}, @@ -1410,19 +1409,10 @@ int __ms_node_get_param_value(media_streamer_node_s *node, param_s *param, char } if (!g_strcmp0(param->param_name, MEDIA_STREAMER_PARAM_CAMERA_ID)) - if (G_VALUE_HOLDS_STRING(&value)) { - /* v4l2src have string property 'device' with value /dev/video[0-n]. - * Try to get index from it. */ - const char *str_val = g_value_get_string(&value); - if (str_val && g_str_has_prefix(str_val, "/dev/video")) { - string_val = g_strdup(str_val + strlen("/dev/video")); - } else { - ms_info("Parameter [%s] was got not for MEDIA_STREAMER_NODE_SRC_TYPE_CAMERA type of nodes", param->param_name); - ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER; - } - } else { + if (G_VALUE_HOLDS_INT(&value)) string_val = g_strdup_printf("%d", g_value_get_int(&value)); - } + else + string_val = g_strdup_printf("%u", g_value_get_uint(&value)); else if (!g_strcmp0(param->param_name, MEDIA_STREAMER_PARAM_CAPTURE_WIDTH)) string_val = g_strdup_printf("%d", g_value_get_int(&value)); else if (!g_strcmp0(param->param_name, MEDIA_STREAMER_PARAM_CAPTURE_HEIGHT)) @@ -1737,13 +1727,7 @@ int __ms_node_set_param_value(media_streamer_node_s *ms_node, param_s *param, co if (!g_strcmp0(param->param_name, MEDIA_STREAMER_PARAM_CAMERA_ID)) { int camera_id = (int)strtol(param_value, NULL, 10); ms_retvm_if(camera_id == -1, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Invalid %s value", param->param_name); - if (g_str_has_prefix(ms_node->name, "v4l2src")) { - /* 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_GFREE(camera_device_str); - } else - g_object_set(ms_node->gst_element, param->origin_name, camera_id, NULL); + 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)) g_object_set(ms_node->gst_element, param->origin_name, (int)strtol(param_value, NULL, 10), NULL); else if (!g_strcmp0(param->param_name, MEDIA_STREAMER_PARAM_CAPTURE_HEIGHT)) -- 2.7.4 From 1756acd27fe64d2ca6527187225c9a8c1c98db5a Mon Sep 17 00:00:00 2001 From: Hyunil Date: Fri, 13 Jul 2018 17:58:16 +0900 Subject: [PATCH 10/16] Modify capi-media-streamer.pc for setting includedir and libdir path Change-Id: Ia3db39935a40b776d67958a3066772fdd9c73976 Signed-off-by: Hyunil --- capi-media-streamer.pc.in | 23 +++++++++++++---------- packaging/capi-media-streamer.spec | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) mode change 100755 => 100644 capi-media-streamer.pc.in diff --git a/capi-media-streamer.pc.in b/capi-media-streamer.pc.in old mode 100755 new mode 100644 index 0488d8e..cde0c80 --- a/capi-media-streamer.pc.in +++ b/capi-media-streamer.pc.in @@ -1,11 +1,14 @@ -prefix = @prefix@ -exec_prefix=@exec_prefix@ -libdir = @libdir@ -includedir = @includedir@ -Name : mediastreamer -Description : Multimedia Framework MediaStreamer Library -Requires : mm-common -Version : @VERSION@ -Libs : -L${libdir} -lcapi-media-streamer -Cflags : -I${includedir}/media +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=@LIB_INSTALL_DIR@ +includedir=/usr/include/media + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} diff --git a/packaging/capi-media-streamer.spec b/packaging/capi-media-streamer.spec index 9006e8c..589049b 100644 --- a/packaging/capi-media-streamer.spec +++ b/packaging/capi-media-streamer.spec @@ -1,6 +1,6 @@ Name: capi-media-streamer Summary: A Media Streamer API -Version: 0.1.22 +Version: 0.1.23 Release: 0 Group: Multimedia/API License: Apache-2.0 -- 2.7.4 From 6f3033369ef82a4f586affa879dda21b6e9f3d1a Mon Sep 17 00:00:00 2001 From: Hyunil Date: Wed, 1 Aug 2018 14:37:47 +0900 Subject: [PATCH 11/16] Apply correct memory release function Change-Id: Ibce6ef8f1420a14fe9fae45fdb09ab0627607343 Signed-off-by: Hyunil --- src/media_streamer_gst.c | 4 ++-- src/media_streamer_http_server.c | 2 +- src/media_streamer_node.c | 2 +- src/media_streamer_util.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index 0007ffb..f6ad624 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -2094,7 +2094,7 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) ms_error("[Source: %s] Error: %s", GST_OBJECT_NAME(GST_OBJECT_CAST(GST_ELEMENT(GST_MESSAGE_SRC(message)))), err->message); g_error_free(err); - MS_SAFE_FREE(debug); + MS_SAFE_GFREE(debug); break; } @@ -2222,7 +2222,7 @@ static int __ms_gstreamer_init(media_streamer_s *ms_streamer) for (i = 1; i < *argc; i++) argv[i] = NULL; - MS_SAFE_GFREE(argv[0]); + MS_SAFE_FREE(argv[0]); MS_SAFE_FREE(argv); MS_SAFE_FREE(argc); diff --git a/src/media_streamer_http_server.c b/src/media_streamer_http_server.c index 7f1bb08..f8f6f6e 100644 --- a/src/media_streamer_http_server.c +++ b/src/media_streamer_http_server.c @@ -99,7 +99,7 @@ int __ms_http_server_destroy(media_streamer_http_server_h server) if (hserver->server) g_object_unref(hserver->server); - MS_SAFE_GFREE(hserver); + MS_SAFE_FREE(hserver); ms_debug_fleave(); diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index e7e78e8..49a047c 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -1005,7 +1005,7 @@ static gboolean demux_find(gpointer key, gpointer value, gpointer user_data) static int __ms_adaptive_sink_http_server_prepare(media_streamer_s * ms_streamer, media_streamer_node_s *node) { int err_code = MEDIA_STREAMER_ERROR_NONE; - char *playlist_location = NULL; + gchar *playlist_location = NULL; char *playlist_dir = NULL; char *split = NULL; diff --git a/src/media_streamer_util.c b/src/media_streamer_util.c index 3ad8754..7b62507 100644 --- a/src/media_streamer_util.c +++ b/src/media_streamer_util.c @@ -153,7 +153,7 @@ void __ms_ini_read_list(const char *key, gchar ***list) g_strstrip(strtmp); *list = g_strsplit(strtmp, ",", 10); - MS_SAFE_FREE(strtmp); + MS_SAFE_GFREE(strtmp); } ms_debug_fleave(); -- 2.7.4 From a8b0d51c1f0359e092b99dba5d4a746464e01b6d Mon Sep 17 00:00:00 2001 From: Hyunil Date: Tue, 28 Aug 2018 13:33:01 +0900 Subject: [PATCH 12/16] Fix typo in document Change-Id: I3563c75db78cff043665cf5989a853a82c0280a6 Signed-off-by: Hyunil --- doc/mediastreamer_doc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/mediastreamer_doc.h b/doc/mediastreamer_doc.h index e97184c..4b43219 100755 --- a/doc/mediastreamer_doc.h +++ b/doc/mediastreamer_doc.h @@ -32,7 +32,7 @@ * * @section CAPI_MEDIA_STREAMER_MODULE_OVERVIEW Overview * The Media Streamer API allows application developers to construct the custom player. - * It includes provides a way to handle media content by user speicific player. + * It includes provides a way to handle media content by user specific player. * * MEDIASTREAMER allows : * - Application can decide input type of media source. -- 2.7.4 From 0acd1426fd5cb2e03a04a29664beb4a2e0bb9c56 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Thu, 20 Dec 2018 16:50:38 +0900 Subject: [PATCH 13/16] Avoid changing errnum of strerror_r by dlog Change-Id: Iec86bc156b2dbb701d4ebcab38dc0e2727f579c7 Signed-off-by: Hyunil --- src/media_streamer_util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/media_streamer_util.c b/src/media_streamer_util.c index 7b62507..147b160 100644 --- a/src/media_streamer_util.c +++ b/src/media_streamer_util.c @@ -354,6 +354,8 @@ int __ms_util_uri_path_check(const char *file_uri) { struct stat stat_results = {0, }; int file_open = 0; + char mes_error[256]; + int errnum = 0; ms_debug_fenter(); @@ -362,11 +364,11 @@ int __ms_util_uri_path_check(const char *file_uri) file_open = open(file_uri, O_RDONLY); if (file_open < 0) { - char mes_error[256]; - strerror_r(errno, mes_error, sizeof(mes_error)); - ms_error("Couldn`t open file [%s] according to [%s]. Error N [%d]", file_uri, mes_error, errno); + errnum = errno; + strerror_r(errnum, mes_error, sizeof(mes_error)); + ms_error("Couldn`t open file [%s] according to [%s]. Error N [%d]", file_uri, mes_error, errnum); - if (EACCES == errno) + if (EACCES == errnum) return MEDIA_STREAMER_ERROR_PERMISSION_DENIED; return MEDIA_STREAMER_ERROR_INVALID_PARAMETER; -- 2.7.4 From cfb60932d74b599eda470e83df82c76f0aa0e4a8 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Mon, 25 Mar 2019 16:04:38 +0900 Subject: [PATCH 14/16] Avoid confusion about fakesink and fakesrc when using media_streamer_node_create Change-Id: Ic2535382f487a5b97370d146b8e19cc6f10d9f5a Signed-off-by: Hyunil --- src/media_streamer_node.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index 49a047c..beda130 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -62,8 +62,8 @@ param_s param_table[] = { node_info_s nodes_info[] = { {"Generic", "none"}, /* MEDIA_STREAMER_NODE_TYPE_NONE */ - {"Source", "fakesrc"}, /* MEDIA_STREAMER_NODE_TYPE_SRC */ - {"Sink", "fakesink"}, /* MEDIA_STREAMER_NODE_TYPE_SINK */ + {"Source", "source"}, /* MEDIA_STREAMER_NODE_TYPE_SRC */ + {"Sink", "sink"}, /* MEDIA_STREAMER_NODE_TYPE_SINK */ {"Codec/Encoder/Video", "video_encoder"}, /* MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER */ {"Codec/Decoder/Video", "video_decoder"}, /* MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER */ {"Codec/Encoder/Audio", "audio_encoder"}, /* MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER */ -- 2.7.4 From cd809c19718faeebb8e8d6411523ee0a3bd9c949 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Tue, 26 Mar 2019 17:49:42 +0900 Subject: [PATCH 15/16] fix that mpegaudioparse node is not create with parse node type and mp3 media_format Change-Id: I401ba603608e753337ad203be67797ad4571e9d2 Signed-off-by: Hyunil --- src/media_streamer_gst.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index f6ad624..3c98be4 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -2289,10 +2289,10 @@ GstCaps *__ms_create_caps_from_fmt(media_format_h fmt) caps = gst_caps_new_simple("audio/x-raw", "channels", G_TYPE_INT, channel, "format", G_TYPE_STRING, __ms_convert_mime_to_string_format(mime), "rate", G_TYPE_INT, samplerate, NULL); else if (MEDIA_FORMAT_ENCODED == (mime & MEDIA_FORMAT_ENCODED)) { - if (mime & MEDIA_FORMAT_AAC) + if (mime == MEDIA_FORMAT_AAC) caps = gst_caps_new_simple(__ms_convert_mime_to_string_format(mime), "mpegversion", G_TYPE_INT, 4, NULL); - else if (mime & MEDIA_FORMAT_MP3) - caps = gst_caps_new_simple(__ms_convert_mime_to_string_format(mime), "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL); + else if (mime == MEDIA_FORMAT_MP3) + caps = gst_caps_new_simple(__ms_convert_mime_to_string_format(mime), "mpegversion", G_TYPE_INT, 1, NULL); else caps = gst_caps_new_simple(__ms_convert_mime_to_string_format(mime), "channels", G_TYPE_INT, channel, "rate", G_TYPE_INT, samplerate, NULL); } -- 2.7.4 From 569393c4bb3307a573dbb75255fa2860bfee2960 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Fri, 29 Mar 2019 13:23:31 +0900 Subject: [PATCH 16/16] Remove channel and rate from creating caps to generate correct caps for RAW format Change-Id: I3180f026c1e44626694b849ba1d63c04830cec33 Signed-off-by: Hyunil --- src/media_streamer_gst.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index 3c98be4..63e5999 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -2285,10 +2285,9 @@ GstCaps *__ms_create_caps_from_fmt(media_format_h fmt) ms_debug_fenter(); if (!media_format_get_audio_info(fmt, &mime, &channel, &samplerate, &bit, &avg_bps)) { - if (MEDIA_FORMAT_RAW == (mime & MEDIA_FORMAT_RAW)) - caps = gst_caps_new_simple("audio/x-raw", "channels", G_TYPE_INT, channel, "format", - G_TYPE_STRING, __ms_convert_mime_to_string_format(mime), "rate", G_TYPE_INT, samplerate, NULL); - else if (MEDIA_FORMAT_ENCODED == (mime & MEDIA_FORMAT_ENCODED)) { + if (MEDIA_FORMAT_RAW == (mime & MEDIA_FORMAT_RAW)) { + caps = gst_caps_new_simple("audio/x-raw", "format", G_TYPE_STRING, __ms_convert_mime_to_string_format(mime), NULL); + } else if (MEDIA_FORMAT_ENCODED == (mime & MEDIA_FORMAT_ENCODED)) { if (mime == MEDIA_FORMAT_AAC) caps = gst_caps_new_simple(__ms_convert_mime_to_string_format(mime), "mpegversion", G_TYPE_INT, 4, NULL); else if (mime == MEDIA_FORMAT_MP3) -- 2.7.4