From ea1adf1a24a5248ca6f0b625d180144b6feb44ab Mon Sep 17 00:00:00 2001 From: Hyunil Date: Fri, 10 Nov 2017 10:34:23 +0900 Subject: [PATCH 01/16] Replace videosink from waylandsink to tizenwlsink Change-Id: I391a1d10e24c752eca71bbe25193b78749a9b2ff Signed-off-by: Hyunil --- include/media_streamer_util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/media_streamer_util.h b/include/media_streamer_util.h index 5c85853..22d09f0 100644 --- a/include/media_streamer_util.h +++ b/include/media_streamer_util.h @@ -153,7 +153,7 @@ typedef struct { #define DEFAULT_VIDEO_SOURCE "ximagesrc" #define DEFAULT_APP_SOURCE "appsrc" #define DEFAULT_AUDIO_SINK "pulsesink" -#define DEFAULT_VIDEO_SINK "waylandsink" +#define DEFAULT_VIDEO_SINK "tizenwlsink" #define DEFAULT_VIDEO_SCALE "videoscale" #define DEFAULT_VIDEO_CONVERT "videoconvert" #define DEFAULT_VIDEO_RATE "videorate" -- 2.7.4 From bbaeab91d1451fcc9895b481776f6b45d01e5a62 Mon Sep 17 00:00:00 2001 From: Vadym Sachenko Date: Wed, 8 Nov 2017 13:24:33 +0200 Subject: [PATCH 02/16] mm-resource-manager integration patch Change-Id: Ic87dc5efc00765e511b143d357a5550db8cb51c1 Signed-off-by: Vadym Sachenko --- CMakeLists.txt | 4 +- include/media_streamer_node_resources.h | 5 +- include/media_streamer_priv.h | 7 +- include/media_streamer_resource.h | 84 ----- packaging/capi-media-streamer.spec | 3 +- src/media_streamer_gst.c | 22 +- src/media_streamer_node.c | 56 +--- src/media_streamer_node_resources.c | 240 +++----------- src/media_streamer_priv.c | 62 ++-- src/media_streamer_resource.c | 557 -------------------------------- 10 files changed, 120 insertions(+), 920 deletions(-) delete mode 100644 include/media_streamer_resource.h delete mode 100644 src/media_streamer_resource.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 649690e..3867ff6 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 murphy-resource murphy-glib 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 murphy-resource murphy-glib 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 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") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) diff --git a/include/media_streamer_node_resources.h b/include/media_streamer_node_resources.h index 2f4dd12..e13aed3 100644 --- a/include/media_streamer_node_resources.h +++ b/include/media_streamer_node_resources.h @@ -18,15 +18,12 @@ #define __MEDIA_STREAMER_NODE_RESOURCE_H__ #include -#include #ifdef __cplusplus extern "C" { #endif -int __ms_node_resouces_init(media_streamer_node_s *node); -int __ms_node_resouces_deinit(media_streamer_node_s *node); -int _ms_node_resource_aquire(media_streamer_node_s *node); +int _ms_node_resource_acquire(media_streamer_node_s *node); int _ms_node_resource_release(media_streamer_node_s *node); #ifdef __cplusplus diff --git a/include/media_streamer_priv.h b/include/media_streamer_priv.h index 9ba66a0..6d2e889 100644 --- a/include/media_streamer_priv.h +++ b/include/media_streamer_priv.h @@ -28,7 +28,7 @@ extern "C" { #include #include -#include +#include #include struct media_streamer_node_s; @@ -116,7 +116,8 @@ typedef struct { media_streamer_callback_s interrupted_cb; gboolean is_interrupted; - media_streamer_resource_manager_s resource_manager; + mm_resource_manager_h resource_manager; + mm_resource_manager_res_h video_decoder_resource; media_streamer_http_server_h http_server; } media_streamer_s; @@ -140,7 +141,7 @@ typedef struct { void *callbacks_structure; - media_streamer_resource_manager_s resource_manager; + mm_resource_manager_res_h resource; device_policy_manager_h dpm_handle; int policy_changed_cb_id; } media_streamer_node_s; diff --git a/include/media_streamer_resource.h b/include/media_streamer_resource.h deleted file mode 100644 index 2cefdc8..0000000 --- a/include/media_streamer_resource.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __MEDIA_STREAMER_RESOURCE_H__ -#define __MEDIA_STREAMER_RESOURCE_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MEDIA_STREAMER_RESOURCE_TIMEOUT 5 - -#define MEDIA_STREAMER_GET_RESOURCE_LOCK(rm) (&((media_streamer_resource_manager_s *)rm)->lock) -#define MEDIA_STREAMER_RESOURCE_LOCK(rm) (g_mutex_lock(MEDIA_STREAMER_GET_RESOURCE_LOCK(rm))) -#define MEDIA_STREAMER_RESOURCE_UNLOCK(rm) (g_mutex_unlock(MEDIA_STREAMER_GET_RESOURCE_LOCK(rm))) - -#define MEDIA_STREAMER_GET_RESOURCE_COND(rm) (&((media_streamer_resource_manager_s *)rm)->cond) -#define MEDIA_STREAMER_RESOURCE_WAIT(rm) g_cond_wait(MEDIA_STREAMER_GET_RESOURCE_COND(rm), MEDIA_STREAMER_GET_RESOURCE_LOCK(rm) -#define MEDIA_STREAMER_RESOURCE_WAIT_UNTIL(rm, end_time) \ - g_cond_wait_until(MEDIA_STREAMER_GET_RESOURCE_COND(rm), MEDIA_STREAMER_GET_RESOURCE_LOCK(rm), end_time) -#define MEDIA_STREAMER_RESOURCE_SIGNAL(rm) g_cond_signal(MEDIA_STREAMER_GET_RESOURCE_COND(rm)); - -typedef enum { - RESOURCE_TYPE_NONE, - RESOURCE_TYPE_VIDEO_DECODER, - RESOURCE_TYPE_CAMERA, - RESOURCE_TYPE_VIDEO_OVERLAY, -} media_streamer_resource_type_e; - -typedef enum { - RESOURCE_STATE_ERROR = -1, - RESOURCE_STATE_NONE, - RESOURCE_STATE_INITIALIZED, - RESOURCE_STATE_PREPARED, - RESOURCE_STATE_ACQUIRED, - RESOURCE_STATE_MAX, -} media_streamer_resource_state_e; - -typedef struct _media_streamer_resource_manager_s media_streamer_resource_manager_s; -typedef gboolean (*resource_relese_cb)(media_streamer_resource_manager_s *resource_manager, void *user_data); - -struct _media_streamer_resource_manager_s { - mrp_mainloop_t *mloop; - mrp_res_context_t *context; - mrp_res_resource_set_t *rset; - media_streamer_resource_state_e state; - bool is_connected; - void *user_data; - bool by_rm_cb; - GCond cond; - GMutex lock; - - /* Release cb */ - resource_relese_cb release_cb; -}; - -int _ms_resource_manager_init(media_streamer_resource_manager_s *resource_manager, resource_relese_cb release_cb, void *user_data); -int _ms_resource_manager_prepare(media_streamer_resource_manager_s *resource_manager, media_streamer_resource_type_e resource_type); -int _ms_resource_manager_acquire(media_streamer_resource_manager_s *resource_manager); -int _ms_resource_manager_release(media_streamer_resource_manager_s *resource_manager); -int _ms_resource_manager_unprepare(media_streamer_resource_manager_s *resource_manager); -int _ms_resource_manager_deinit(media_streamer_resource_manager_s *resource_manager); -int _ms_resource_manager_get_state(media_streamer_resource_manager_s *resource_manager, media_streamer_resource_state_e *state); - -#ifdef __cplusplus -} -#endif - -#endif /* __MEDIA_STREAMER_RESOURCE_H__ */ diff --git a/packaging/capi-media-streamer.spec b/packaging/capi-media-streamer.spec index 3a73e2b..a562ad4 100644 --- a/packaging/capi-media-streamer.spec +++ b/packaging/capi-media-streamer.spec @@ -29,8 +29,7 @@ BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(evas) BuildRequires: pkgconfig(ecore-wayland) BuildRequires: pkgconfig(appcore-efl) -BuildRequires: pkgconfig(murphy-resource) -BuildRequires: pkgconfig(murphy-glib) +BuildRequires: pkgconfig(mm-resource-manager) BuildRequires: pkgconfig(dpm) BuildRequires: pkgconfig(libsoup-2.4) BuildRequires: pkgconfig(capi-content-mime-type) diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index b61fbda..5a8c6ce 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -466,21 +466,31 @@ static gint __decodebin_autoplug_select_cb(GstElement * bin, GstPad * pad, GstCa } if (ms_streamer->ini.resource_required_elem_names) { - /* Try to acuire resources before adding element */ + /* Try to acquire resources before adding element */ int index = 0; for ( ; 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); - if (MEDIA_STREAMER_ERROR_NONE != - _ms_resource_manager_prepare(&ms_streamer->resource_manager, RESOURCE_TYPE_VIDEO_DECODER)) { - ms_error("Failed to prepare resources for [%s] element", factory_name); + if (MM_RESOURCE_MANAGER_ERROR_NONE != + mm_resource_manager_mark_for_acquire(ms_streamer->resource_manager, + MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_DECODER, + MM_RESOURCE_MANAGER_RES_VOLUME_FULL, + &ms_streamer->video_decoder_resource)) { + ms_error("Failed to mark resources for acquire in [%s] element", factory_name); return GST_AUTOPLUG_SELECT_SKIP; } - if (MEDIA_STREAMER_ERROR_NONE != - _ms_resource_manager_acquire(&ms_streamer->resource_manager)) { + if (MM_RESOURCE_MANAGER_ERROR_NONE != + mm_resource_manager_commit(ms_streamer->resource_manager)) { ms_error("Failed to acquire resources for [%s] element", factory_name); + + if (MM_RESOURCE_MANAGER_ERROR_NONE != + mm_resource_manager_mark_for_release( + ms_streamer->resource_manager, + ms_streamer->video_decoder_resource)) + ms_error("Failed to mark resources for release in [%s] element", factory_name); + return GST_AUTOPLUG_SELECT_SKIP; } } diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index 1c5a0fb..d7018b4 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -266,12 +266,6 @@ int __ms_node_create(media_streamer_node_s *node, media_format_h in_fmt, media_f if (sink_caps) gst_caps_unref(sink_caps); - ret = __ms_node_resouces_init(node); - if (MEDIA_STREAMER_ERROR_NONE != ret) { - ms_error("Failed to init resources for node [%s]", node->name); - return ret; - } - return ret; } @@ -582,12 +576,6 @@ int __ms_src_node_create(media_streamer_node_s *node) else node->name = gst_element_get_name(node->gst_element); - ret = __ms_node_resouces_init(node); - if (MEDIA_STREAMER_ERROR_NONE != ret) { - ms_error("Failed to init resources for node [%s]", node->name); - return ret; - } - ret = __ms_node_policy_init(node); if (MEDIA_STREAMER_ERROR_NONE != ret) { ms_error("Failed to init policy for node [%s]", node->name); @@ -702,12 +690,6 @@ int __ms_sink_node_create(media_streamer_node_s *node) else node->name = gst_element_get_name(node->gst_element); - ret = __ms_node_resouces_init(node); - if (MEDIA_STREAMER_ERROR_NONE != ret) { - ms_error("Failed to init resources for node [%s]", node->name); - return ret; - } - return ret; } @@ -722,10 +704,6 @@ void __ms_node_destroy(media_streamer_node_s *node) if (MEDIA_STREAMER_ERROR_NONE != __ms_node_policy_deinit(node)) ms_error("Failed to deinitialize policy manager"); - /* Deinitialize resource manager */ - if (MEDIA_STREAMER_ERROR_NONE != __ms_node_resouces_deinit(node)) - ms_error("Failed to deinitialize resource manager"); - MS_SAFE_UNREF(node->gst_element); MS_SAFE_FREE(node->name); MS_SAFE_FREE(node->callbacks_structure); @@ -1026,31 +1004,21 @@ int __ms_pipeline_unprepare(media_streamer_s *ms_streamer) ms_error("Failed to unprepare pipeline"); if (!ms_streamer->is_interrupted) { - media_streamer_resource_state_e res_state = RESOURCE_STATE_ERROR; - ret = _ms_resource_manager_get_state(&ms_streamer->resource_manager, - &res_state); - if (ret != MEDIA_STREAMER_ERROR_NONE) - ms_error("Failed to get state of resource manager"); - - if (RESOURCE_STATE_ACQUIRED == res_state) { - ret = _ms_resource_manager_release(&ms_streamer->resource_manager); - if (ret != MEDIA_STREAMER_ERROR_NONE) - ms_error("Failed to release resources"); - } + /* Unprepare resources in case of failure */ + __ms_release_resources(ms_streamer); - ret = _ms_resource_manager_get_state(&ms_streamer->resource_manager, - &res_state); - if (ret != MEDIA_STREAMER_ERROR_NONE) - ms_error("Failed to get state of resource manager"); + if (ms_streamer->video_decoder_resource != NULL) { + ret = mm_resource_manager_mark_for_release(ms_streamer->resource_manager, + ms_streamer->video_decoder_resource); + if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) + ms_error("Failed to mark resources for release"); - if (RESOURCE_STATE_PREPARED == res_state) { - ret = _ms_resource_manager_unprepare(&ms_streamer->resource_manager); + ret = mm_resource_manager_commit(ms_streamer->resource_manager); if (ret != MEDIA_STREAMER_ERROR_NONE) - ms_error("Failed to unprepare resources"); + ms_error("Failed to release resources"); + else + ms_streamer->video_decoder_resource = NULL; } - - /* Unprepare resources in case of failure */ - __ms_release_resources(ms_streamer); } /* Disconnects and clean all autoplug signals */ @@ -1633,7 +1601,7 @@ gboolean _ms_node_resouces_acquire_iter(const GValue *item, GValue *ret, gpointe return TRUE; } - if (MEDIA_STREAMER_ERROR_NONE != _ms_node_resource_aquire(node)) { + if (MEDIA_STREAMER_ERROR_NONE != _ms_node_resource_acquire(node)) { ms_error("Failed to acquire resource for node [%s]", node->name); g_object_unref(element); return FALSE; diff --git a/src/media_streamer_node_resources.c b/src/media_streamer_node_resources.c index dbf8c54..98bdfdd 100644 --- a/src/media_streamer_node_resources.c +++ b/src/media_streamer_node_resources.c @@ -22,46 +22,7 @@ #include #include #include -#include - -static gboolean __ms_resource_relese_cb( - media_streamer_resource_manager_s *resource_manager, - void *user_data) -{ - ms_retvm_if(user_data == NULL, FALSE, "user_data is NULL"); - - media_streamer_node_s *node = (media_streamer_node_s *) user_data; - media_streamer_s *streamer = (media_streamer_s *) node->parent_streamer; - ms_info("Received resource_release_cb from node [%s]", node->name); - - /* Here we perform action to release resources relases that - were previoursly acquired. Basically what we need to do is - to unprepare media streamer. Whithout calling release function - on every acquired resource. */ - g_mutex_lock(&streamer->mutex_lock); - streamer->is_interrupted = TRUE; - if (MEDIA_STREAMER_ERROR_NONE != - __ms_pipeline_unprepare(streamer)) { - ms_error("Failed to unprepare streamer"); - streamer->is_interrupted = FALSE; - g_mutex_unlock(&streamer->mutex_lock); - return FALSE; - } - streamer->is_interrupted = FALSE; - - /* Call interrupted_cb with appropriate code */ - media_streamer_interrupted_cb interrupted_cb = - (media_streamer_interrupted_cb) streamer->interrupted_cb.callback; - if (interrupted_cb) { - interrupted_cb(MEDIA_STREAMER_INTERRUPTED_BY_RESOURCE_CONFLICT, - streamer->interrupted_cb.user_data); - } else { - ms_info("Interuption will not be handled because interrupted_cb is NULL"); - } - g_mutex_unlock(&streamer->mutex_lock); - - return TRUE; -} +#include static gboolean __ms_node_resources_is_needed_by_platform(media_streamer_node_s *node) { @@ -109,8 +70,8 @@ static gboolean __ms_node_resources_is_needed_by_platform(media_streamer_node_s return ret; } -static void __ms_node_get_resources_needed(media_streamer_node_s *node, - media_streamer_resource_type_e *resource) { +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; @@ -121,138 +82,34 @@ static void __ms_node_get_resources_needed(media_streamer_node_s *node, case MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER: break; case MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER: - *resource = RESOURCE_TYPE_VIDEO_DECODER; - break; + *resource = MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_DECODER; + return TRUE; case MEDIA_STREAMER_NODE_TYPE_SRC: - if (MEDIA_STREAMER_NODE_SRC_TYPE_CAMERA == subtype) - *resource = RESOURCE_TYPE_CAMERA; + if (MEDIA_STREAMER_NODE_SRC_TYPE_CAMERA == subtype) { + *resource = MM_RESOURCE_MANAGER_RES_TYPE_CAMERA; + return TRUE; + } break; case MEDIA_STREAMER_NODE_TYPE_SINK: - if (MEDIA_STREAMER_NODE_SINK_TYPE_OVERLAY == subtype) - *resource = RESOURCE_TYPE_VIDEO_OVERLAY; + if (MEDIA_STREAMER_NODE_SINK_TYPE_OVERLAY == subtype) { + *resource = MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_OVERLAY; + return TRUE; + } break; default: break; } -} - -int __ms_node_resouces_init(media_streamer_node_s *node) -{ - media_streamer_resource_type_e resource = RESOURCE_TYPE_NONE; - int ret = MEDIA_STREAMER_ERROR_NONE; - - /* Check if node require resource manager */ - __ms_node_get_resources_needed(node, &resource); - if (RESOURCE_TYPE_NONE == resource) { - ms_info("No resource is needed for %p node type [%d] subtype [%d]", - node, node->type, node->subtype); - return MEDIA_STREAMER_ERROR_NONE; - } - - /* Check if platform requires resource (e.g. Emulator) */ - if (!__ms_node_resources_is_needed_by_platform(node)) { - ms_info("Platform doesn't require resource for %p node type [%d] subtype [%d]", - node, node->type, node->subtype); - return MEDIA_STREAMER_ERROR_NONE; - } - - /* Initialize resource manager */ - ret = _ms_resource_manager_init(&node->resource_manager, - __ms_resource_relese_cb, node); - if (ret != MEDIA_STREAMER_ERROR_NONE) { - ms_error("Failed to initialize resource manager for Node"); - return ret; - } - - return ret; -} - -int __ms_node_resouces_deinit(media_streamer_node_s *node) -{ - media_streamer_resource_type_e resource = RESOURCE_TYPE_NONE; - int ret = MEDIA_STREAMER_ERROR_NONE; - - /* Check if node require resource manager */ - __ms_node_get_resources_needed(node, &resource); - if (RESOURCE_TYPE_NONE == resource) { - ms_info("No resource is needed for %p node type [%d] subtype [%d]", - node, node->type, node->subtype); - return MEDIA_STREAMER_ERROR_NONE; - } - - /* Check if platform requires resource (e.g. Emulator) */ - if (!__ms_node_resources_is_needed_by_platform(node)) { - ms_info("Platform doesn't require resource for %p node type [%d] subtype [%d]", - node, node->type, node->subtype); - return MEDIA_STREAMER_ERROR_NONE; - } - - /* Deinitialize resource manager */ - ret = _ms_resource_manager_deinit(&node->resource_manager); - if (ret != MEDIA_STREAMER_ERROR_NONE) { - ms_error("Failed to deinitialize resource manager for Src Node"); - return ret; - } - - return ret; -} - -int __ms_node_resouces_prepare(media_streamer_node_s *node, media_streamer_resource_type_e resource) -{ - media_streamer_resource_state_e resource_state = RESOURCE_STATE_NONE; - int ret = MEDIA_STREAMER_ERROR_NONE; - - ret = _ms_resource_manager_get_state(&node->resource_manager, &resource_state); - if (ret != MEDIA_STREAMER_ERROR_NONE) { - ms_error("Failed to get state from resource menager"); - return ret; - } else { - if (RESOURCE_STATE_NONE == resource_state || - RESOURCE_STATE_ERROR == resource_state) { - ms_error("Wrong resource manager state %d", resource_state); - return MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } else if (RESOURCE_STATE_INITIALIZED == resource_state) { - /* For every node we should call resource manager function to resource */ - ret = _ms_resource_manager_prepare(&node->resource_manager, resource); - } else { - ms_info("Resource state is %d. No need to prepare", resource_state); - return MEDIA_STREAMER_ERROR_NONE; - } - } - - return ret; -} - -int __ms_node_resouces_unprepare(media_streamer_node_s *node, media_streamer_resource_type_e resource) -{ - media_streamer_resource_state_e resource_state = RESOURCE_STATE_NONE; - int ret = MEDIA_STREAMER_ERROR_NONE; - - ret = _ms_resource_manager_get_state(&node->resource_manager, &resource_state); - if (ret != MEDIA_STREAMER_ERROR_NONE) { - ms_error("Failed to get state from resource menager"); - return ret; - } else { - if (RESOURCE_STATE_PREPARED == resource_state) { - /* For every node we should call resource manager function to resource */ - ret = _ms_resource_manager_unprepare(&node->resource_manager); - } else { - ms_error("Wrong resource manager state %d", resource_state); - return MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } - } - return ret; + return FALSE; } -int _ms_node_resource_aquire(media_streamer_node_s *node) +int _ms_node_resource_acquire(media_streamer_node_s *node) { - media_streamer_resource_state_e resource_state = RESOURCE_STATE_NONE; - media_streamer_resource_type_e resource = RESOURCE_TYPE_NONE; + mm_resource_manager_res_type_e resource; + mm_resource_manager_h resource_manager = node->parent_streamer->resource_manager; /* Check if node require resource manager */ - __ms_node_get_resources_needed(node, &resource); - if (RESOURCE_TYPE_NONE == resource) { + if (!__ms_node_get_resources_needed(node, &resource)) { ms_info("No resource is needed for %p node type [%d] subtype [%d]", node, node->type, node->subtype); return MEDIA_STREAMER_ERROR_NONE; @@ -265,29 +122,30 @@ int _ms_node_resource_aquire(media_streamer_node_s *node) return MEDIA_STREAMER_ERROR_NONE; } - if (MEDIA_STREAMER_ERROR_NONE != __ms_node_resouces_prepare(node, resource)) { - ms_error("Failed to prepare resources for Node [%p]", node); + if (node->resource != NULL) { + ms_error("Resource handle is not NULL for Node [%p]", node); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } - if (MEDIA_STREAMER_ERROR_NONE != - _ms_resource_manager_get_state(&node->resource_manager, &resource_state)) { - ms_error("Failed to get state from resource menager"); + if (MM_RESOURCE_MANAGER_ERROR_NONE != mm_resource_manager_mark_for_acquire( + resource_manager, resource, MM_RESOURCE_MANAGER_RES_VOLUME_FULL, + &node->resource)) { + ms_error("Failed to mark resources for acquire in Node [%p]", node); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } else { - ms_debug("Resource manager state %d", resource_state); } ms_debug("Acquire resource for node [%s]", node->name); - if (RESOURCE_STATE_PREPARED != resource_state) { - ms_debug("Resources were not prepared %d. Skipping...", resource_state); - return MEDIA_STREAMER_ERROR_NONE; - } - - if (MEDIA_STREAMER_ERROR_NONE != - _ms_resource_manager_acquire(&node->resource_manager)) { + if (MM_RESOURCE_MANAGER_ERROR_NONE != + mm_resource_manager_commit(resource_manager)) { ms_error("Failed to acquire resources for node [%s]", node->name); + + if (MM_RESOURCE_MANAGER_ERROR_NONE != + mm_resource_manager_mark_for_release( + resource_manager, + node->resource)) + ms_error("Failed to mark resources for release in Node [%p]", node); + return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } @@ -296,42 +154,28 @@ int _ms_node_resource_aquire(media_streamer_node_s *node) int _ms_node_resource_release(media_streamer_node_s *node) { - media_streamer_resource_state_e resource_state = RESOURCE_STATE_NONE; - media_streamer_resource_type_e resource = RESOURCE_TYPE_NONE; + mm_resource_manager_h resource_manager = node->parent_streamer->resource_manager; - /* Check if node require resource manager */ - __ms_node_get_resources_needed(node, &resource); - if (RESOURCE_TYPE_NONE == resource) { - ms_info("No resource is needed for %p node type [%d] subtype [%d]", - node, node->type, node->subtype); + if (node->resource == NULL) { + ms_error("Resources were not acquired for Node [%p]. Skipping...", node); return MEDIA_STREAMER_ERROR_NONE; } - if (MEDIA_STREAMER_ERROR_NONE != - _ms_resource_manager_get_state(&node->resource_manager, &resource_state)) { - ms_error("Failed to get state from resource menager"); - return MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } else { - ms_debug("Resource manager state %d", resource_state); - } - ms_debug("Release resources for node [%s]", node->name); - if (RESOURCE_STATE_ACQUIRED != resource_state) { - ms_debug("Resources were not acquired %d. Skipping...", resource_state); - return MEDIA_STREAMER_ERROR_NONE; + if (MEDIA_STREAMER_ERROR_NONE != mm_resource_manager_mark_for_release( + resource_manager, node->resource)) { + ms_error("Failed to mark resources for release in Node [%p]", node); + return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } if (MEDIA_STREAMER_ERROR_NONE != - _ms_resource_manager_release(&node->resource_manager)) { + mm_resource_manager_commit(resource_manager)) { ms_error("Failed to release resources for node [%s]", node->name); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } - if (MEDIA_STREAMER_ERROR_NONE != __ms_node_resouces_unprepare(node, resource)) { - ms_error("Failed to unprepare resources for Node [%p]", node); - return MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } + node->resource = NULL; return MEDIA_STREAMER_ERROR_NONE; } diff --git a/src/media_streamer_priv.c b/src/media_streamer_priv.c index c3825dc..e0efc4e 100644 --- a/src/media_streamer_priv.c +++ b/src/media_streamer_priv.c @@ -18,13 +18,15 @@ #include "media_streamer_util.h" #include "media_streamer_node.h" #include "media_streamer_gst.h" -#include "media_streamer_resource.h" +#include #define GST_TIME_TO_MSEC(t) (t == GST_CLOCK_TIME_NONE ? t : (int)(((GstClockTime)(t)) / GST_MSECOND)) int __ms_change_resources_state(media_streamer_s *ms_streamer, media_streamer_state_e state); int __ms_change_policy_state(media_streamer_s *ms_streamer, media_streamer_state_e state); -static gboolean media_streamer_resource_relese_cb(media_streamer_resource_manager_s *resource_manager, void *user_data); +static gboolean __ms_resource_node_find(gpointer key, gpointer value, gpointer user_data); +static int __ms_resource_release_cb(mm_resource_manager_h rm, + mm_resource_manager_res_h resource_h, void *user_data); int __ms_state_change(media_streamer_s *ms_streamer, media_streamer_state_e state) { @@ -99,10 +101,11 @@ int __ms_create(media_streamer_s *ms_streamer) ret = __ms_pipeline_create(ms_streamer); - if (MEDIA_STREAMER_ERROR_NONE != _ms_resource_manager_init( - &ms_streamer->resource_manager, - media_streamer_resource_relese_cb, - ms_streamer)) { + if (MM_RESOURCE_MANAGER_ERROR_NONE != mm_resource_manager_create( + MM_RESOURCE_MANAGER_APP_CLASS_MEDIA, + __ms_resource_release_cb, + ms_streamer, + &ms_streamer->resource_manager)) { ms_error("Failed to init resource manager for media streamer"); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; } @@ -189,8 +192,8 @@ int __ms_streamer_destroy(media_streamer_s *ms_streamer) if (ms_streamer->ini.resource_required_elem_names) g_strfreev(ms_streamer->ini.resource_required_elem_names); - if (MEDIA_STREAMER_ERROR_NONE != - _ms_resource_manager_deinit(&ms_streamer->resource_manager)) { + if (MM_RESOURCE_MANAGER_ERROR_NONE != + mm_resource_manager_destroy(ms_streamer->resource_manager)) { ms_error("Failed to deinit resource manager for media streamer"); g_mutex_unlock(&ms_streamer->mutex_lock); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; @@ -203,7 +206,7 @@ int __ms_streamer_destroy(media_streamer_s *ms_streamer) return ret; } -int __ms_aquire_resources(media_streamer_s *ms_streamer) +int __ms_acquire_resources(media_streamer_s *ms_streamer) { int ret = MEDIA_STREAMER_ERROR_NONE; @@ -295,7 +298,7 @@ int __ms_change_resources_state(media_streamer_s *ms_streamer, media_streamer_st switch (ms_streamer->pend_state) { case MEDIA_STREAMER_STATE_IDLE: /* After prepare function */ - ret = __ms_aquire_resources(ms_streamer); + ret = __ms_acquire_resources(ms_streamer); break; case MEDIA_STREAMER_STATE_PAUSED: case MEDIA_STREAMER_STATE_PLAYING: @@ -311,20 +314,39 @@ int __ms_change_resources_state(media_streamer_s *ms_streamer, media_streamer_st return ret; } -static gboolean media_streamer_resource_relese_cb( - media_streamer_resource_manager_s *resource_manager, - void *user_data) +static gboolean __ms_resource_node_find(gpointer key, gpointer value, gpointer user_data) +{ + return ((media_streamer_node_s *)value)->resource == + (mm_resource_manager_res_h)user_data; +} + +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; - ms_info("Reseived release_cb for streamer %p", streamer); + media_streamer_node_s *node; + ms_info("Received release_cb for streamer %p", streamer); - /* Here we perform action to release resources relases that - were previoursly acquired (dynamically created case). - Basically what we need to do is to unprepare media streamer. - Whithout calling release function on every acquired resource. */ + /* Here we perform action to release resources that + were previously acquired (dynamically created case). + Basically what we need to do is to unprepare media streamer + without calling release function on every acquired resource. */ g_mutex_lock(&streamer->mutex_lock); + + /* Clear handle of released resource */ + if (resource_h == streamer->video_decoder_resource) { + streamer->video_decoder_resource = NULL; + } else { + node = (media_streamer_node_s *)g_hash_table_find(streamer->nodes_table, + (GHRFunc)__ms_resource_node_find, resource_h); + if (node == NULL) + ms_error("Failed to find released resource"); + else + node->resource = NULL; + } + streamer->is_interrupted = TRUE; if (MEDIA_STREAMER_ERROR_NONE != __ms_pipeline_unprepare(streamer)) { @@ -342,11 +364,11 @@ static gboolean media_streamer_resource_relese_cb( interrupted_cb(MEDIA_STREAMER_INTERRUPTED_BY_RESOURCE_CONFLICT, streamer->interrupted_cb.user_data); } else { - ms_info("Interuption will not be handled because interrupted_cb is NULL"); + ms_info("Interruption will not be handled because interrupted_cb is NULL"); } g_mutex_unlock(&streamer->mutex_lock); - return TRUE; + return FALSE; } int __ms_check_policy(media_streamer_s *ms_streamer) diff --git a/src/media_streamer_resource.c b/src/media_streamer_resource.c deleted file mode 100644 index bce054d..0000000 --- a/src/media_streamer_resource.c +++ /dev/null @@ -1,557 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "media_streamer_util.h" -#include "media_streamer_resource.h" -#include "media_streamer_priv.h" -#include - -#define MRP_APP_CLASS_FOR_MSTREAMER "media" -#define MRP_RESOURCE_TYPE_MANDATORY TRUE -#define MRP_RESOURCE_TYPE_EXCLUSIVE FALSE - -enum { - MRP_RESOURCE_FOR_VIDEO_OVERLAY, - MRP_RESOURCE_FOR_CAMERA, - MRP_RESOURCE_FOR_VIDEO_DECODER, - MRP_RESOURCE_MAX, -}; -const char* resource_str[MRP_RESOURCE_MAX] = { - "video_overlay", - "camera", - "video_decoder", -}; - -#define MEDIA_STREAMER_WAIT_CONNECTION_TIMEOUT 5 - -#define MEDIA_STREAMER_CHECK_RESOURCE_MANAGER_INSTANCE(x_ms_resource_manager) \ -do { \ - if (!x_ms_resource_manager) { \ - ms_error("no resource manager instance");\ - return MEDIA_STREAMER_ERROR_INVALID_PARAMETER; \ - } \ -} while (0); - -static int __ms_resource_manager_wait_connection(media_streamer_resource_manager_s *resource_manager) -{ - MEDIA_STREAMER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager); - - MEDIA_STREAMER_RESOURCE_LOCK(resource_manager); - - if (resource_manager->is_connected) { - ms_debug("Already connected to resource server"); - } else { - gint64 end_time = g_get_monotonic_time() + MEDIA_STREAMER_RESOURCE_TIMEOUT*G_TIME_SPAN_SECOND; - - ms_debug("Not connected to resource server yet. Waiting..."); - - if (!g_cond_wait_until(&resource_manager->cond, - &resource_manager->lock, end_time)) { - ms_error("Could not connect to resource server"); - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - return MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } else { - if (resource_manager->is_connected) { - ms_debug("Successfully connected to resource server!"); - } else { - ms_error("Failed to connect to resource server"); - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - return MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } - } - } - - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - return MEDIA_STREAMER_ERROR_NONE; -} - -static char *state_to_str(mrp_res_resource_state_t st) -{ - char *state = "unknown"; - switch (st) { - case MRP_RES_RESOURCE_ACQUIRED: - state = "acquired"; - break; - case MRP_RES_RESOURCE_LOST: - state = "lost"; - break; - case MRP_RES_RESOURCE_AVAILABLE: - state = "available"; - break; - case MRP_RES_RESOURCE_PENDING: - state = "pending"; - break; - case MRP_RES_RESOURCE_ABOUT_TO_LOOSE: - state = "about to loose"; - break; - } - return state; -} - -static void mrp_state_callback(mrp_res_context_t *context, mrp_res_error_t err, void *user_data) -{ - int i = 0; - const mrp_res_resource_set_t *rset; - mrp_res_resource_t *resource; - media_streamer_resource_manager_s* resource_manager = NULL; - - if (user_data == NULL) { - ms_error(" - user data is null"); - return; - } - resource_manager = (media_streamer_resource_manager_s *) user_data; - - MEDIA_STREAMER_RESOURCE_LOCK(resource_manager); - - if (err != MRP_RES_ERROR_NONE) { - ms_error(" - error message received from Murphy, err(0x%x)", err); - g_cond_signal(&resource_manager->cond); - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - return; - } - - switch (context->state) { - case MRP_RES_CONNECTED: - ms_debug(" - connected to Murphy"); - if ((rset = mrp_res_list_resources(context)) != NULL) { - mrp_res_string_array_t *resource_names; - resource_names = mrp_res_list_resource_names(rset); - if (!resource_names) { - ms_error(" - no resources available"); - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - return; - } - for (i = 0; i < resource_names->num_strings; i++) { - resource = mrp_res_get_resource_by_name(rset, resource_names->strings[i]); - if (resource) - ms_debug(" - available resource: %s", resource->name); - } - mrp_res_free_string_array(resource_names); - } - resource_manager->is_connected = TRUE; - g_cond_signal(&resource_manager->cond); - break; - case MRP_RES_DISCONNECTED: - ms_debug(" - disconnected from Murphy"); - if (resource_manager->rset) { - mrp_res_delete_resource_set(resource_manager->rset); - resource_manager->rset = NULL; - } - mrp_res_destroy(resource_manager->context); - resource_manager->context = NULL; - resource_manager->is_connected = FALSE; - g_cond_signal(&resource_manager->cond); - break; - } - - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - - return; -} - -static void mrp_rset_state_callback(mrp_res_context_t *cx, const mrp_res_resource_set_t *rs, void *user_data) -{ - int i = 0; - media_streamer_resource_manager_s *resource_manager = (media_streamer_resource_manager_s *)user_data; - mrp_res_resource_t *res; - - MEDIA_STREAMER_RESOURCE_LOCK(resource_manager); - - if (!mrp_res_equal_resource_set(rs, resource_manager->rset)) { - ms_info("- resource set(%p) is not same as this resource_manager handle's(%p)", rs, resource_manager->rset); - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - return; - } - - ms_debug(" - resource set state of resource_manager(%p) is changed to [%s]", resource_manager, state_to_str(rs->state)); - for (i = 0; i < MRP_RESOURCE_MAX; i++) { - res = mrp_res_get_resource_by_name(rs, resource_str[i]); - if (res == NULL) - ms_info(" -- %s not present in resource set", resource_str[i]); - else - ms_info(" -- resource name [%s] -> [%s]'", res->name, state_to_str(res->state)); - } - - mrp_res_delete_resource_set(resource_manager->rset); - resource_manager->rset = mrp_res_copy_resource_set(rs); - - if (rs->state == MRP_RES_RESOURCE_ACQUIRED) { - ms_debug(" - resource set is acquired"); - resource_manager->state = RESOURCE_STATE_ACQUIRED; - MEDIA_STREAMER_RESOURCE_SIGNAL(resource_manager); - } else if ((resource_manager->state >= RESOURCE_STATE_ACQUIRED) && - (rs->state == MRP_RES_RESOURCE_AVAILABLE)) { - ms_debug(" - resource set is released"); - resource_manager->state = RESOURCE_STATE_PREPARED; - MEDIA_STREAMER_RESOURCE_SIGNAL(resource_manager); - } - - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); -} - - -static void mrp_resource_release_cb(mrp_res_context_t *cx, const mrp_res_resource_set_t *rs, void *user_data) -{ - int i = 0; - media_streamer_resource_manager_s *resource_manager = NULL; - mrp_res_resource_t *res; - - if (user_data == NULL) { - ms_error("- user_data is null"); - return; - } - resource_manager = (media_streamer_resource_manager_s *) user_data; - - MEDIA_STREAMER_RESOURCE_LOCK(resource_manager); - - if (!mrp_res_equal_resource_set(rs, resource_manager->rset)) { - ms_info("- resource set(%p) is not same as this resource_manager handle's(%p)", - rs, resource_manager->rset); - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - return; - } - - ms_debug(" - resource set state of resource manager (%p) is changed to [%s]", - resource_manager, state_to_str(rs->state)); - for (i = 0; i < MRP_RESOURCE_MAX; i++) { - res = mrp_res_get_resource_by_name(rs, resource_str[i]); - if (res == NULL) - ms_info(" -- %s not present in resource set", resource_str[i]); - else - ms_debug(" -- resource name [%s] -> [%s] %d'", res->name, - state_to_str(res->state), res->state); - } - - if (resource_manager->release_cb) { - if (!resource_manager->release_cb(resource_manager, resource_manager->user_data)) - ms_error("release_cb failed"); - else - ms_info("release_cb is fine"); - } else { - ms_error("release cb is NULL. Something wrong happens..."); - } - - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - - return; -} - -static int create_rset(media_streamer_resource_manager_s *resource_manager) -{ - if (resource_manager->rset) { - ms_error(" - resource set was already created"); - return MEDIA_STREAMER_ERROR_INVALID_STATE; - } - - resource_manager->rset = - mrp_res_create_resource_set(resource_manager->context, - MRP_APP_CLASS_FOR_MSTREAMER, - mrp_rset_state_callback, - (void*)resource_manager); - if (resource_manager->rset == NULL) { - ms_error(" - could not create resource set"); - return MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } - - if (!mrp_res_set_autorelease(TRUE, resource_manager->rset)) - ms_info(" - could not set autorelease flag!"); - - return MEDIA_STREAMER_ERROR_NONE; -} - -static int include_resource(media_streamer_resource_manager_s *resource_manager, const char *resource_name) -{ - mrp_res_resource_t *resource = NULL; - resource = mrp_res_create_resource(resource_manager->rset, - resource_name, - MRP_RESOURCE_TYPE_MANDATORY, - MRP_RESOURCE_TYPE_EXCLUSIVE); - if (resource == NULL) { - ms_error(" - could not include resource[%s]", resource_name); - return MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } - - ms_debug(" - include resource[%s]", resource_name); - - return MEDIA_STREAMER_ERROR_NONE; -} - -static int set_resource_release_cb(media_streamer_resource_manager_s *resource_manager) -{ - int ret = MEDIA_STREAMER_ERROR_NONE; - bool mrp_ret = FALSE; - - if (resource_manager->rset) { - if (MRP_RES_RESOURCE_PENDING == resource_manager->rset->state) { - /* FIXME: This workarond is only temporary solution. - When resource set is acquired again after lost the state is 'available' - and no 'pending'. Thus we skip setting reelease callback as it already - was set. */ - mrp_ret = mrp_res_set_release_callback(resource_manager->rset, mrp_resource_release_cb, resource_manager); - if (!mrp_ret) { - ms_error(" - could not set release callback"); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } - } - } else { - ms_error(" - resource set is null"); - ret = MEDIA_STREAMER_ERROR_INVALID_STATE; - } - - return ret; -} - -int _ms_resource_manager_init(media_streamer_resource_manager_s *resource_manager, - resource_relese_cb release_cb, void *user_data) -{ - int ret = MEDIA_STREAMER_ERROR_NONE; - MEDIA_STREAMER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager); - ms_retvm_if(release_cb == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, - "release_cb is NULL"); - - g_mutex_init(&resource_manager->lock); - g_cond_init(&resource_manager->cond); - - MEDIA_STREAMER_RESOURCE_LOCK(resource_manager); - - GMainContext *mrp_ctx = g_main_context_new(); - if (!mrp_ctx) { - ms_error("- could not create main context for resource manager"); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - goto EXIT; - } - - GMainLoop *mrp_loop = g_main_loop_new(mrp_ctx, TRUE); - g_main_context_unref(mrp_ctx); - if (!mrp_loop) { - ms_error("- could not create glib mainloop for resource manager"); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - goto EXIT; - } - - resource_manager->mloop = mrp_mainloop_glib_get(mrp_loop); - g_main_loop_unref(mrp_loop); - if (resource_manager->mloop) { - resource_manager->context = mrp_res_create(resource_manager->mloop, - mrp_state_callback, resource_manager); - - if (resource_manager->context == NULL) { - ms_error(" - could not get context for resource manager"); - mrp_mainloop_destroy(resource_manager->mloop); - resource_manager->mloop = NULL; - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - goto EXIT; - } - resource_manager->user_data = user_data; - } else { - ms_error("- could not get mainloop for resource manager"); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - goto EXIT; - } - - resource_manager->release_cb = release_cb; - resource_manager->state = RESOURCE_STATE_INITIALIZED; - -EXIT: - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - - return ret; -} - -int _ms_resource_manager_prepare(media_streamer_resource_manager_s *resource_manager, media_streamer_resource_type_e resource_type) -{ - int ret = MEDIA_STREAMER_ERROR_NONE; - MEDIA_STREAMER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager); - __ms_resource_manager_wait_connection(resource_manager); - - if (!resource_manager->rset) - ret = create_rset(resource_manager); - - if (ret == MEDIA_STREAMER_ERROR_NONE) { - switch (resource_type) { - case RESOURCE_TYPE_VIDEO_OVERLAY: - ret = include_resource(resource_manager, resource_str[MRP_RESOURCE_FOR_VIDEO_OVERLAY]); - break; - case RESOURCE_TYPE_VIDEO_DECODER: - ret = include_resource(resource_manager, resource_str[MRP_RESOURCE_FOR_VIDEO_DECODER]); - break; - case RESOURCE_TYPE_CAMERA: - ret = include_resource(resource_manager, resource_str[MRP_RESOURCE_FOR_CAMERA]); - break; - case RESOURCE_TYPE_NONE: - default: - ms_error("Wrong resource type %d", resource_type); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - break; - } - } - - if (MEDIA_STREAMER_ERROR_NONE == ret) - resource_manager->state = RESOURCE_STATE_PREPARED; - else - resource_manager->state = RESOURCE_STATE_ERROR; - - return ret; -} - -int _ms_resource_manager_acquire(media_streamer_resource_manager_s *resource_manager) -{ - int ret = MEDIA_STREAMER_ERROR_NONE; - MEDIA_STREAMER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager); - __ms_resource_manager_wait_connection(resource_manager); - - if (resource_manager->rset == NULL) { - ms_error("- could not acquire resource, resource set is null"); - ret = MEDIA_STREAMER_ERROR_INVALID_STATE; - } else { - ret = set_resource_release_cb(resource_manager); - if (ret) { - ms_error("- could not set resource release cb, ret(%d)", ret); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } else { - MEDIA_STREAMER_RESOURCE_LOCK(resource_manager); - - ret = mrp_res_acquire_resource_set(resource_manager->rset); - if (ret) { - ms_error("- could not acquire resource, ret(%d)", ret); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } else { - gint64 end_time = g_get_monotonic_time() + MEDIA_STREAMER_RESOURCE_TIMEOUT*G_TIME_SPAN_SECOND; - - ms_debug("- acquire resource waiting..%p till %lld", resource_manager, end_time); - if (!MEDIA_STREAMER_RESOURCE_WAIT_UNTIL(resource_manager, end_time)) { - ms_error("- could not acquire resource"); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } else { - ms_debug("- resources are acquired"); - } - } - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - } - } - - return ret; -} - -int _ms_resource_manager_release(media_streamer_resource_manager_s *resource_manager) -{ - int ret = MEDIA_STREAMER_ERROR_NONE; - MEDIA_STREAMER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager); - __ms_resource_manager_wait_connection(resource_manager); - - if (resource_manager->rset == NULL) { - ms_error("- could not release resource, resource set is null"); - ret = MEDIA_STREAMER_ERROR_INVALID_STATE; - } else { - if (resource_manager->rset->state != MRP_RES_RESOURCE_ACQUIRED) { - ms_error("- could not release resource, resource set state is [%s]", state_to_str(resource_manager->rset->state)); - ret = MEDIA_STREAMER_ERROR_INVALID_STATE; - } else { - MEDIA_STREAMER_RESOURCE_LOCK(resource_manager); - ret = mrp_res_release_resource_set(resource_manager->rset); - if (ret) { - ms_error("- could not release resource, ret(%d)", ret); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } else { - gint64 end_time = g_get_monotonic_time() + MEDIA_STREAMER_RESOURCE_TIMEOUT*G_TIME_SPAN_SECOND; - - ms_debug("- release resource waiting..%p till %lld", resource_manager, end_time); - if (!MEDIA_STREAMER_RESOURCE_WAIT_UNTIL(resource_manager, end_time)) { - ms_info("- could not release resource in time"); - ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; - } else { - ms_debug("- resources are released"); - } - } - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - } - } - - return ret; -} - -int _ms_resource_manager_unprepare(media_streamer_resource_manager_s *resource_manager) -{ - int ret = MEDIA_STREAMER_ERROR_NONE; - MEDIA_STREAMER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager); - __ms_resource_manager_wait_connection(resource_manager); - - if (resource_manager->rset == NULL) { - ms_error("- could not unprepare for resource_manager, _ms_resource_manager_prepare() first"); - ret = MEDIA_STREAMER_ERROR_INVALID_STATE; - } else { - MEDIA_STREAMER_RESOURCE_LOCK(resource_manager); - mrp_res_delete_resource_set(resource_manager->rset); - resource_manager->rset = NULL; - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - } - - resource_manager->state = RESOURCE_STATE_INITIALIZED; - - return ret; -} - -int _ms_resource_manager_deinit(media_streamer_resource_manager_s *resource_manager) -{ - MEDIA_STREAMER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager); - __ms_resource_manager_wait_connection(resource_manager); - - MEDIA_STREAMER_RESOURCE_LOCK(resource_manager); - - if (resource_manager->rset) { - if (resource_manager->rset->state == MRP_RES_RESOURCE_ACQUIRED) { - if (mrp_res_release_resource_set(resource_manager->rset)) - ms_error("- could not release resource"); - } - mrp_res_delete_resource_set(resource_manager->rset); - resource_manager->rset = NULL; - } - - if (resource_manager->context) { - mrp_res_destroy(resource_manager->context); - resource_manager->context = NULL; - } - - if (resource_manager->mloop) { - mrp_mainloop_quit(resource_manager->mloop, 0); - mrp_mainloop_destroy(resource_manager->mloop); - resource_manager->mloop = NULL; - } - - resource_manager->release_cb = NULL; - - resource_manager->state = RESOURCE_STATE_NONE; - - MEDIA_STREAMER_RESOURCE_UNLOCK(resource_manager); - - g_mutex_clear(&resource_manager->lock); - g_cond_clear(&resource_manager->cond); - - return MEDIA_STREAMER_ERROR_NONE; -} - -int _ms_resource_manager_get_state(media_streamer_resource_manager_s *resource_manager, media_streamer_resource_state_e *state) -{ - MEDIA_STREAMER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager); - ms_retvm_if(state == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, - "state is NULL"); - - ms_debug("resource_state is %d", resource_manager->state); - - *state = resource_manager->state; - - return MEDIA_STREAMER_ERROR_NONE; -} -- 2.7.4 From 6e3d29e30aa6d5fe5fbfd8017bbdebd6d5ab54f7 Mon Sep 17 00:00:00 2001 From: Volodymyr Brynza Date: Tue, 21 Nov 2017 13:41:50 +0200 Subject: [PATCH 03/16] Change obsolete ximagesrc to videotestsrc Change-Id: I6ee40a52e506c702315aa113eca4d7691d5bf40b Signed-off-by: Volodymyr Brynza --- include/media_streamer_util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/media_streamer_util.h b/include/media_streamer_util.h index 22d09f0..1003fd0 100644 --- a/include/media_streamer_util.h +++ b/include/media_streamer_util.h @@ -150,7 +150,7 @@ typedef struct { #define DEFAULT_DECODEBIN "decodebin" #define DEFAULT_AUDIO_SOURCE "pulsesrc" #define DEFAULT_CAMERA_SOURCE "v4l2src" -#define DEFAULT_VIDEO_SOURCE "ximagesrc" +#define DEFAULT_VIDEO_SOURCE "videotestsrc" #define DEFAULT_APP_SOURCE "appsrc" #define DEFAULT_AUDIO_SINK "pulsesink" #define DEFAULT_VIDEO_SINK "tizenwlsink" -- 2.7.4 From fa95599b2dd63bce4cb03aa71b90d827d0927740 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Tue, 30 Jan 2018 16:41:37 +0900 Subject: [PATCH 04/16] Fix doxygen error, note and question in Native API header file Change-Id: Ifbb38ed9830e7c824e75154a5ad58ebde1827586 Signed-off-by: Hyunil --- include/media_streamer.h | 358 +++++++++++++++++++------------------ packaging/capi-media-streamer.spec | 2 +- 2 files changed, 183 insertions(+), 177 deletions(-) diff --git a/include/media_streamer.h b/include/media_streamer.h index c4bff23..fa3d24b 100644 --- a/include/media_streamer.h +++ b/include/media_streamer.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __TIZEN_MEDIASTREAMER_H__ -#define __TIZEN_MEDIASTREAMER_H__ +#ifndef __TIZEN_MULTIMEDIA_MEDIA_STREAMER_H__ +#define __TIZEN_MULTIMEDIA_MEDIA_STREAMER_H__ #include #include @@ -156,7 +156,7 @@ typedef enum { } media_streamer_error_e; /** - * @brief Enumeration of media streamer buffer status of custom src + * @brief Enumeration of media streamer buffer status of custom src. * * @since_tizen 3.0 */ @@ -176,7 +176,7 @@ typedef enum { } media_streamer_interrupted_code_e; /** - * @brief Definition for "camera-id" parameter of source node. + * @brief Definition for camera-id parameter of source node. * @details Index number of camera to activate. * Data type is integer and default value is 0. * @since_tizen 3.0 @@ -185,7 +185,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_CAMERA_ID "camera-id" /** - * @brief Definition for capture parameter of source node. + * @brief Definition for capture-width parameter of source node. * @details Width for camera size to capture. * Data type is integer and default value is 1600. * @since_tizen 3.0 @@ -194,7 +194,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_CAPTURE_WIDTH "capture-width" /** - * @brief Definition for capture parameter of source node. + * @brief Definition for capture-height parameter of source node. * @details Height for camera size to capture. * Data type is integer and default value is 1200. * @since_tizen 3.0 @@ -213,7 +213,7 @@ typedef enum { /** * @brief Definition for uri parameter of source node. - * @details Uri to read from + * @details URI to read from * Data type is string. * @since_tizen 3.0 * @see media_streamer_node_get_params @@ -221,7 +221,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_URI "uri" /** - * @brief Definition for user-agent parameter of source node + * @brief Definition for user-agent parameter of source node. * @details Value of the User-Agent HTTP request header field. * Data type is string. * @since_tizen 3.0 @@ -230,7 +230,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_USER_AGENT "user-agent" /** - * @brief Definition for stream type parameter of source node + * @brief Definition for stream type parameter of source node. * @details The type of the push data stream. * 0:stream, 1:seekable, 2:random-access (default:0) * @since_tizen 3.0 @@ -239,7 +239,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_STREAM_TYPE "stream-type" /** - * @brief Definition for port parameter of source or sink node + * @brief Definition for port parameter of source or sink node. * @details The port to receive the packets from. * Data type is integer and default value is 5004. * @since_tizen 3.0 @@ -248,7 +248,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_PORT "port" /** - * @brief Definition for video port parameter of source node + * @brief Definition for video port parameter of source node. * @details The port to receive the video packets from. * Data type is integer. * @since_tizen 3.0 @@ -257,7 +257,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_VIDEO_IN_PORT "video_in_port" /** - * @brief Definition for audio port parameter of source node + * @brief Definition for audio port parameter of source node. * @details The port to receive the audio packets from. * Data type is integer. * @since_tizen 3.0 @@ -266,7 +266,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_AUDIO_IN_PORT "audio_in_port" /** - * @brief Definition for video port parameter of sink node + * @brief Definition for video port parameter of sink node. * @details The port to send the video packets to. * Data type is integer. * @since_tizen 3.0 @@ -275,7 +275,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_VIDEO_OUT_PORT "video_out_port" /** - * @brief Definition for audio port parameter of sink node + * @brief Definition for audio port parameter of sink node. * @details The port to send the audio packets to. * Data type is integer. * @since_tizen 3.0 @@ -284,7 +284,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_AUDIO_OUT_PORT "audio_out_port" /** - * @brief Definition for IP address parameter of source node + * @brief Definition for IP address parameter of source node. * @details IP address to send/receive packets for. * Data type is string and default value is "0.0.0.0". * @since_tizen 3.0 @@ -293,7 +293,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_IP_ADDRESS "address" /** - * @brief Definition for audio device name parameter of source or sink node + * @brief Definition for audio device name parameter of source or sink node. * @details ALSA device, as defined in an asound configuration file. * ex) "hw:0,0", "hw:0,1" * Data type is string and default value is "default". @@ -303,7 +303,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_AUDIO_DEVICE "audio_device" /** - * @brief Definition for sync parameter of sink node + * @brief Definition for sync parameter of sink node. * @details Synchronize on the clock * Data type is boolean and default value is true. * @since_tizen 3.0 @@ -312,7 +312,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_CLOCK_SYNCHRONIZED "sync" /** - * @brief Definition for rotate parameter of sink node + * @brief Definition for rotate parameter of sink node. * @details Rotate angle of display output. * 0:none/1:rotate 90 degree/2:rotate 180 degree/3:rotate 270 degree * Default value is 3(rotate 270 degree). @@ -322,7 +322,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_ROTATE "rotate" /** - * @brief Definition for flip parameter of sink node + * @brief Definition for flip parameter of sink node. * @details Flip for display. * 0:none, 1:horizontal, 2:vertical, 3:both * Default value is 0. @@ -332,7 +332,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_FLIP "flip" /** - * @brief Definition for display geometry method parameter of sink node + * @brief Definition for display geometry method parameter of sink node. * @details Geometrical method for display. * 0:Letter box * 1:Original size @@ -357,7 +357,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_DISPLAY "display" /** - * @brief Definition for visible parameter of sink node + * @brief Definition for visible parameter of sink node. * @details Draws screen or blacks out. * Data type is boolean and default value is true(visible). * @since_tizen 3.0 @@ -366,7 +366,7 @@ typedef enum { #define MEDIA_STREAMER_PARAM_VISIBLE "visible" /** - * @brief Definition for host parameter of sink node + * @brief Definition for host parameter of sink node. * @details The host/IP/Multicast group to send the packets to. * Data type is string and default value is "localhost". * @since_tizen 3.0 @@ -393,18 +393,18 @@ typedef enum { /** * @brief Called when error occurs in media streamer. - * @details Following error codes can be delivered. + * @since_tizen 3.0 + * @remarks Following error codes can be delivered. * #MEDIA_STREAMER_ERROR_INVALID_OPERATION, * #MEDIA_STREAMER_ERROR_FILE_NO_SPACE_ON_DEVICE, * #MEDIA_STREAMER_ERROR_NOT_SUPPORTED, * #MEDIA_STREAMER_ERROR_CONNECTION_FAILED, * #MEDIA_STREAMER_ERROR_RESOURCE_CONFLICT - * @since_tizen 3.0 - * @param [in] streamer Media streamer handle - * @param [in] error The error that occurred in media steamer - * @param [in] user_data The user data passed from the code where - * media_streamer_set_error_cb() was invoked - * This data will be accessible from @a media_streamer_error_cb + * @param[in] streamer Media streamer handle + * @param[in] error The error that occurred in media steamer + * @param[in] user_data The user data passed from the code where + * media_streamer_set_error_cb() was invoked + * This data will be accessible from media_streamer_error_cb * @pre Create media streamer handle by calling media_streamer_create() function * @see media_streamer_set_error_cb() * @see media_streamer_unset_error_cb() @@ -415,12 +415,12 @@ typedef void (*media_streamer_error_cb)(media_streamer_h streamer, /** * @brief Called when media streamer state is changed. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle - * @param [in] previous_state The previous state of the media streamer - * @param [in] current_state The current state of media streamer - * @param [in] user_data The user data passed from the code where - * media_streamer_set_state_changed_cb() was invoked - * This data will be accessible from @a media_streamer_state_changed_cb + * @param[in] streamer Media streamer handle + * @param[in] previous_state The previous state of the media streamer + * @param[in] current_state The current state of media streamer + * @param[in] user_data The user data passed from the code where + * media_streamer_set_state_changed_cb() was invoked + * This data will be accessible from media_streamer_state_changed_cb * @pre Create media streamer handle by calling media_streamer_create() function * @see media_streamer_set_state_change_cb() * @see media_streamer_unset_state_change_cb() @@ -434,8 +434,9 @@ typedef void (*media_streamer_state_changed_cb)(media_streamer_h streamer, * or no free space in custom source buffer. * @since_tizen 3.0 * @remarks Callback can be applied only for MEDIA_STREAMER_NODE_SRC_TYPE_CUSTOM source type - * @param [in] node Media streamer source node handle - * @param [in] user_data The user data passed from the callback registration function + * @param[in] node Media streamer source node handle + * @param[in] status Media streamer custom buffer status + * @param[in] user_data The user data passed from the callback registration function * @see media_streamer_src_set_buffer_status_cb() * @see media_streamer_node_get_param() * @see media_streamer_node_set_param() @@ -447,10 +448,10 @@ typedef void (*media_streamer_custom_buffer_status_cb)(media_streamer_node_h nod * @brief Called when new data is available from custom sink. * @details This callback can be applied only to MEDIA_STREAMER_NODE_SINK_TYPE_CUSTOM sink type * @since_tizen 3.0 - * @param [in] node Media streamer sink node handle - * @param [in] user_data The user data passed from the code where + * @param[in] node Media streamer sink node handle + * @param[in] user_data The user data passed from the code where * media_streamer_sink_set_data_ready_cb() was invoked - * This data will be accessible from @a media_streamer_sink_data_ready_cb + * This data will be accessible from media_streamer_sink_data_ready_cb * @pre media_streamer_sink_set_data_ready_cb() * @see MEDIA_STREAMER_NODE_SINK_TYPE_CUSTOM * @see media_streamer_sink_set_data_ready_cb() @@ -462,10 +463,10 @@ typedef void (*media_streamer_sink_data_ready_cb)(media_streamer_node_h node, vo * @brief Called when the end-of-stream has been reached. * @details This callback can be applied only to MEDIA_STREAMER_NODE_SINK_TYPE_CUSTOM sink type * @since_tizen 3.0 - * @param [in] node Media streamer sink node handle - * @param [in] user_data The user data passed from the code where + * @param[in] node Media streamer sink node handle + * @param[in] user_data The user data passed from the code where * media_streamer_sink_set_eos_cb() was invoked - * This data will be accessible from @a media_streamer_sink_eos_cb + * This data will be accessible from media_streamer_sink_eos_cb * @pre media_streamer_sink_set_eos_cb() * @see MEDIA_STREAMER_NODE_SINK_TYPE_CUSTOM * @see media_streamer_sink_set_eos_cb() @@ -484,15 +485,15 @@ typedef void (*media_streamer_position_changed_cb)(void *user_data); /** * @brief Called when the media streamer is interrupted. * @since_tizen 3.0 - * @param[in] error_code The interrupted error code - * @param[in] user_data The user data passed from the callback registration function + * @param[in] code The interrupted error code + * @param[in] user_data The user data passed from the callback registration function * @see media_streamer_set_interrupted_cb() * @see media_streamer_unset_interrupted_cb() */ typedef void (*media_streamer_interrupted_cb)(media_streamer_interrupted_code_e code, void *user_data); /** - * @brief Registers a error callback function to be invoked when an error occurs. + * @brief Sets a error callback function to be invoked when an error occurs. * @details Following error codes can be delivered by error callback. * #MEDIA_STREAMER_ERROR_INVALID_OPERATION, * #MEDIA_STREAMER_ERROR_FILE_NO_SPACE_ON_DEVICE, @@ -500,11 +501,11 @@ typedef void (*media_streamer_interrupted_cb)(media_streamer_interrupted_code_e * #MEDIA_STREAMER_ERROR_CONNECTION_FAILED, * #MEDIA_STREAMER_ERROR_RESOURCE_CONFLICT * @since_tizen 3.0 - * @param [in] streamer Media streamer handle - * @param [in] callback Callback function pointer - * @param [in] user_data The user data passed from the code where - * media_streamer_set_error_cb() was invoked - * This data will be accessible from @a media_streamer_error_cb + * @param[in] streamer Media streamer handle + * @param[in] callback Callback function pointer + * @param[in] user_data The user data passed from the code where + * media_streamer_set_error_cb() was invoked + * This data will be accessible from media_streamer_error_cb * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -518,9 +519,9 @@ typedef void (*media_streamer_interrupted_cb)(media_streamer_interrupted_code_e int media_streamer_set_error_cb(media_streamer_h streamer, media_streamer_error_cb callback, void *user_data); /** - * @brief Unregisters the error callback function. + * @brief Unsets the error callback function. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle + * @param[in] streamer Media streamer handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -531,13 +532,13 @@ int media_streamer_set_error_cb(media_streamer_h streamer, media_streamer_error_ int media_streamer_unset_error_cb(media_streamer_h streamer); /** - * @brief Registers a callback that will be triggered after media streamer state is changed. + * @brief Sets a callback that will be triggered after media streamer state is changed. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle - * @param [in] callback Callback function pointer - * @param [in] user_data The user data passed from the code - * where media_streamer_set_state_change_cb() was invoked - * This data will be accessible from @a media_streamer_state_changed_cb + * @param[in] streamer Media streamer handle + * @param[in] callback Callback function pointer + * @param[in] user_data The user data passed from the code + * where media_streamer_set_state_change_cb() was invoked + * This data will be accessible from media_streamer_state_changed_cb * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -551,9 +552,9 @@ int media_streamer_unset_error_cb(media_streamer_h streamer); int media_streamer_set_state_change_cb(media_streamer_h streamer, media_streamer_state_changed_cb callback, void *user_data); /** - * @brief Unregisters the state changed callback function. + * @brief Unsets the state changed callback function. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle + * @param[in] streamer Media streamer handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -564,11 +565,11 @@ int media_streamer_set_state_change_cb(media_streamer_h streamer, media_streamer int media_streamer_unset_state_change_cb(media_streamer_h streamer); /** - * @brief Registers a callback function to be invoked when the media streamer is interrupted. + * @brief Sets a callback function to be invoked when the media streamer is interrupted. * @since_tizen 3.0 - * @param[in] streamer Media streamer handle - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function + * @param[in] streamer Media streamer handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -581,7 +582,7 @@ int media_streamer_unset_state_change_cb(media_streamer_h streamer); int media_streamer_set_interrupted_cb(media_streamer_h streamer, media_streamer_interrupted_cb callback, void *user_data); /** - * @brief Unregisters the callback function. + * @brief Unsets the callback function. * @since_tizen 3.0 * @param[in] streamer Media streamer handle * @return @c 0 on success, @@ -594,17 +595,17 @@ int media_streamer_set_interrupted_cb(media_streamer_h streamer, media_streamer_ int media_streamer_unset_interrupted_cb(media_streamer_h streamer); /** - * @brief Registers a callback function to be invoked when buffer underrun or overflow is occurred. + * @brief Sets a callback function to be invoked when buffer underrun or overflow is occurred. * @details This function can be called only for MEDIA_STREAMER_NODE_SRC_TYPE_CUSTOM source type * @since_tizen 3.0 - * @remarks This API is used for media stream playback only. - * @param [in] source Media streamer source node handle - * @param [in] callback The buffer status callback function to register - * @param [in] user_data The user data passed from the code where + * @remarks This function is used for media stream playback only. + * @param[in] source Media streamer source node handle + * @param[in] callback The buffer status callback function to register + * @param[in] user_data The user data passed from the code where * media_streamer_src_set_buffer_status_cb() was invoked - * This data will be accessible from @a media_streamer_custom_buffer_status_cb() + * This data will be accessible from media_streamer_custom_buffer_status_cb() * @return @c 0 on success, - * otherwise a negative error value + * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful * @retval #MEDIA_STREAMER_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_STREAMER_ERROR_INVALID_OPERATION Invalid operation @@ -617,9 +618,9 @@ int media_streamer_unset_interrupted_cb(media_streamer_h streamer); int media_streamer_src_set_buffer_status_cb(media_streamer_node_h source, media_streamer_custom_buffer_status_cb callback, void *user_data); /** - * @brief Unregisters the src buffer status callback function. + * @brief Unsets the src buffer status callback function. * @since_tizen 3.0 - * @param [in] source Media streamer source node handle + * @param[in] source Media streamer source node handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -630,14 +631,14 @@ int media_streamer_src_set_buffer_status_cb(media_streamer_node_h source, media_ int media_streamer_src_unset_buffer_status_cb(media_streamer_node_h source); /** - * @brief Registers a callback function to be called when the custom sink is ready for data processing. + * @brief Sets a callback function to be called when the custom sink is ready for data processing. * @details This function can be called only for MEDIA_STREAMER_NODE_SINK_TYPE_CUSTOM sink type * @since_tizen 3.0 - * @param [in] sink Media streamer sink node handle - * @param [in] callback Callback function pointer - * @param [in] user_data The user data passed from the code where + * @param[in] sink Media streamer sink node handle + * @param[in] callback Callback function pointer + * @param[in] user_data The user data passed from the code where * media_streamer_sink_set_data_ready_cb() was invoked - * This data will be accessible from @a media_streamer_sink_data_ready_cb + * This data will be accessible from media_streamer_sink_data_ready_cb * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -652,9 +653,9 @@ int media_streamer_src_unset_buffer_status_cb(media_streamer_node_h source); int media_streamer_sink_set_data_ready_cb(media_streamer_node_h sink, media_streamer_sink_data_ready_cb callback, void *user_data); /** - * @brief Unregisters the sink data ready callback function. + * @brief Unsets the sink data ready callback function. * @since_tizen 3.0 - * @param [in] sink Media streamer sink node handle + * @param[in] sink Media streamer sink node handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -665,13 +666,13 @@ int media_streamer_sink_set_data_ready_cb(media_streamer_node_h sink, media_stre int media_streamer_sink_unset_data_ready_cb(media_streamer_node_h sink); /** - * @brief Registers a callback function to be called when custom sink detect the end-of-stream. + * @brief Sets a callback function to be called when custom sink detect the end-of-stream. * @since_tizen 3.0 - * @param [in] sink Media streamer sink node handle - * @param [in] callback Callback function pointer - * @param [in] user_data The user data passed from the code where + * @param[in] sink Media streamer sink node handle + * @param[in] callback Callback function pointer + * @param[in] user_data The user data passed from the code where * media_streamer_sink_set_eos_cb() was invoked. - * This data will be accessible from @a media_streamer_sink_eos_cb + * This data will be accessible from media_streamer_sink_eos_cb * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -686,9 +687,9 @@ int media_streamer_sink_unset_data_ready_cb(media_streamer_node_h sink); int media_streamer_sink_set_eos_cb(media_streamer_node_h sink, media_streamer_sink_eos_cb callback, void *user_data); /** - * @brief Unregisters the sink end-of-stream callback function. + * @brief Unsets the sink end-of-stream callback function. * @since_tizen 3.0 - * @param [in] sink Media streamer sink node handle + * @param[in] sink Media streamer sink node handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -703,7 +704,7 @@ int media_streamer_sink_unset_eos_cb(media_streamer_node_h sink); * passes the handle to the caller. * @since_tizen 3.0 * @remarks You must release @a streamer using media_streamer_destroy() - * @param [out] streamer Media streamer handle + * @param[out] streamer Media streamer handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -717,14 +718,14 @@ int media_streamer_create(media_streamer_h *streamer); /** * @brief Sets media streamer state to MEDIA_STREAMER_STATE_READY. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle + * @param[in] streamer Media streamer handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful * @retval #MEDIA_STREAMER_ERROR_INVALID_STATE Invalid state * @retval #MEDIA_STREAMER_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_STREAMER_ERROR_INVALID_OPERATION Invalid operation - * @pre The media streamer state must be set to #MEDIA_STREAMER_STATE_IDLE + * @pre The media streamer state must be set to MEDIA_STREAMER_STATE_IDLE * by calling media_streamer_create() or media_streamer_unprepare(). * @pre At least one src and one sink should be added and linked in the streamer * by calling media_streamer_node_create_src(), media_streamer_node_create_sink() and media_streamer_node_link(). @@ -738,7 +739,7 @@ int media_streamer_prepare(media_streamer_h streamer); * @brief Sets media streamer state to MEDIA_STREAMER_STATE_IDLE. * @details The most recently used media is reset and no longer associated with the media streamer. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle + * @param[in] streamer Media streamer handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -755,7 +756,7 @@ int media_streamer_unprepare(media_streamer_h streamer); * @brief Sets media streamer state to MEDIA_STREAMER_STATE_PLAYING. * @details Start running the current streamer, or resumes it if paused. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle + * @param[in] streamer Media streamer handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -774,7 +775,7 @@ int media_streamer_play(media_streamer_h streamer); /** * @brief Pauses the media streamer. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle + * @param[in] streamer Media streamer handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -791,7 +792,7 @@ int media_streamer_pause(media_streamer_h streamer); /** * @brief Stops the media streamer. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle + * @param[in] streamer Media streamer handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -810,12 +811,12 @@ int media_streamer_stop(media_streamer_h streamer); /** * @brief Destroys media streamer. * @since_tizen 3.0 - * @remark Nodes in streamer will be removed automatically. - * Don't need to remove nodes by calling media_streamer_node_remove(). - * If you want to change the node without destroying streamer handle, - * you can call the media_streamer_node_remove() function - * after setting the streamer state to MEDIA_STREAMER_STATE_IDLE state. - * @param [in] streamer Media streamer handle + * @remarks Nodes in streamer will be removed automatically. + * Don't need to remove nodes by calling media_streamer_node_remove(). + * If you want to change the node without destroying streamer handle, + * you can call the media_streamer_node_remove() function + * after setting the streamer state to MEDIA_STREAMER_STATE_IDLE state. + * @param[in] streamer Media streamer handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -831,12 +832,12 @@ int media_streamer_destroy(media_streamer_h streamer); /** * @brief Changes playback position to the defined time value, asynchronously. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle - * @param [in] time Time in millisecond - * @param [in] accurate If @c true, it will seek to the accurate position, but this might be considerably slower for some formats, - * otherwise @c false, it will seek to the nearest keyframe. - * @param [in] callback The callback function to register - * @param [in] user_data The user data to be passed to the callback function + * @param[in] streamer Media streamer handle + * @param[in] time Time in millisecond + * @param[in] accurate If @c true, it will seek to the accurate position, but this might be considerably slower for some formats, + * otherwise @c false, it will seek to the nearest keyframe + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -854,8 +855,8 @@ int media_streamer_set_play_position(media_streamer_h streamer, int time, /** * @brief Gets the current position in milliseconds. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle - * @param [out] time The current position in milliseconds + * @param[in] streamer Media streamer handle + * @param[out] time The current position in milliseconds * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -872,8 +873,8 @@ int media_streamer_get_play_position(media_streamer_h streamer, int *time); * @since_tizen 3.0 * @remarks The streamer's src node type should be MEDIA_STREAMER_NODE_SRC_TYPE_FILE or MEDIA_STREAMER_NODE_SRC_TYPE_HTTP. * If not, return value will be MEDIA_STREAMER_ERROR_NONE and duration will be -1. - * @param [in] streamer Media streamer handle - * @param [out] duration The duration in milliseconds + * @param[in] streamer Media streamer handle + * @param[out] duration The duration in milliseconds * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -887,8 +888,8 @@ int media_streamer_get_duration(media_streamer_h streamer, int *duration); /** * @brief Gets media streamer state. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle - * @param [out] state Media streamer state + * @param[in] streamer Media streamer handle + * @param[out] state Media streamer state * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -902,12 +903,15 @@ int media_streamer_get_state(media_streamer_h streamer, media_streamer_state_e * /** * @brief Creates media streamer source node. * @since_tizen 3.0 + * @privilege http://tizen.org/privilege/internet + * http://tizen.org/privilege/camera + * http://tizen.org/privilege/recorder * @remarks The internet privilege(http://tizen.org/privilege/internet) should be added if any URIs are used to play from network. * The camera privilege(http://tizen.org/privilege/camera) should be added if the src node handle the camera device. * The recorder privilege(http://tizen.org/privilege/recorder) should be added if the src node handle the recorder device. - * You can release @a source node using media_streamer_node_destroy() function. - * @param [in] type Media streamer source node type - * @param [out] src Media streamer source node handle + * You can release source node using media_streamer_node_destroy() function. + * @param[in] type Media streamer source node type + * @param[out] src Media streamer source node handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -924,17 +928,15 @@ int media_streamer_node_create_src(media_streamer_node_src_type_e type, media_st * @brief Pushes packet into custom source node. * @details This function can be called only for MEDIA_STREAMER_NODE_SRC_TYPE_CUSTOM. * @since_tizen 3.0 - * @param [in] src Media streamer source node handle - * @param [in] packet Media packet handle + * @param[in] src Media streamer source node handle + * @param[in] packet Media packet handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful - * @retval #MEDIA_STREAMER_ERROR_INVALID_STATE Invalid state * @retval #MEDIA_STREAMER_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_STREAMER_ERROR_INVALID_OPERATION Invalid operation - * @retval #MEDIA_STREAMER_ERROR_PERMISSION_DENIED Permission denied * @pre Create a source node handle by calling media_streamer_node_create_src() function - * @pre The media streamer state must be set to #MEDIA_STREAMER_STATE_IDLE at least. + * @pre The media streamer state must be set to #MEDIA_STREAMER_STATE_IDLE at least. * @see #media_packet_h */ int media_streamer_node_push_packet(media_streamer_node_h src, media_packet_h packet); @@ -942,12 +944,13 @@ int media_streamer_node_push_packet(media_streamer_node_h src, media_packet_h pa /** * @brief Creates media streamer sink node. * @since_tizen 3.0 + * @privilege http://tizen.org/privilege/internet * @remarks The internet privilege(http://tizen.org/privilege/internet) should be added if any URIs are used to transmit the output data. * You can release @a sink node using media_streamer_node_destroy() * @remarks If @a type is #MEDIA_STREAMER_NODE_SINK_TYPE_ADAPTIVE, the HTTP server will be started and the server will be able to transmit the output data to the other device. * The application must have an authentication responsibility between a server and client because the data transmission is not secure. - * @param [in] type Type of sink node to be created - * @param [out] sink Media streamer sink node handle + * @param[in] type Type of sink node to be created + * @param[out] sink Media streamer sink node handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -964,8 +967,8 @@ int media_streamer_node_create_sink(media_streamer_node_sink_type_e type, media_ * @brief Pulls packet from custom sink node. * @details This function can be called only for MEDIA_STREAMER_NODE_SINK_TYPE_CUSTOM * @since_tizen 3.0 - * @param [in] sink Media streamer sink node handle - * @param [out] packet Media packet handle + * @param[in] sink Media streamer sink node handle + * @param[out] packet Media packet handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -987,10 +990,10 @@ int media_streamer_node_pull_packet(media_streamer_node_h sink, media_packet_h * * @remarks The node type should not be MEDIA_STREAMER_NODE_TYPE_SRC and MEDIA_STREAMER_NODE_TYPE_SINK. * To create src/sink type node, media_streamer_node_create_src()/media_streamer_node_create_sink() should be called. * You can release @a node using media_streamer_node_destroy() function - * @param [in] type Created node type - * @param [in] in_fmt Media format handle for input data - * @param [in] out_fmt Media format handle for output data - * @param [out] node Media streamer node handle to be created + * @param[in] type Created node type + * @param[in] in_fmt Media format handle for input data + * @param[in] out_fmt Media format handle for output data + * @param[out] node Media streamer node handle to be created * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1006,8 +1009,8 @@ int media_streamer_node_create(media_streamer_node_type_e type, media_format_h i /** * @brief Adds node to media streamer. * @since_tizen 3.0 - * @param [in] streamer Media streamer handle - * @param [in] node Media streamer node handle to be added + * @param[in] streamer Media streamer handle + * @param[in] node Media streamer node handle to be added * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1026,7 +1029,7 @@ int media_streamer_node_add(media_streamer_h streamer, media_streamer_node_h nod /** * @brief Destroys media streamer node. * @since_tizen 3.0 - * @param [in] node Media streamer node handle + * @param[in] node Media streamer node handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1047,8 +1050,8 @@ int media_streamer_node_destroy(media_streamer_node_h node); * @since_tizen 3.0 * @remarks To remove node without error posting, the state of streamer should be MEDIA_STREAMER_STATE_IDLE. * If the node is linked, it will be unlinked before removing. - * @param [in] streamer Media streamer handle - * @param [in] node Media streamer node handle + * @param[in] streamer Media streamer handle + * @param[in] node Media streamer node handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1063,18 +1066,18 @@ int media_streamer_node_remove(media_streamer_h streamer, media_streamer_node_h /** * @brief Links two media streamer nodes. * @since_tizen 3.0 - * @remark Pads are node's input and output, where you can connect other nodes. - * (src_node) - (sink_node) - * src_node and sink_node is determined relatively. - * In case of (A)-(B)-(C), - * (B) can be sink_node with (A) or (B) can be src_node with (C). - * However, src type node is always src node and sink type node is always sink node. - * (A) is src node and can not be sink node at all. - * (C) is sink node and can not be src node at all. - * @param [in] src_node Media streamer node handle - * @param [in] src_pad_name The name of the source pad of the source node - * @param [in] dest_node The destination media streamer node handle - * @param [in] sink_pad_name The name of the sink pad of the destination node + * @remarks Pads are node's input and output, where you can connect other nodes. + * (src_node) - (sink_node) + * src_node and sink_node is determined relatively. + * In case of (A)-(B)-(C), + * (B) can be sink_node with (A) or (B) can be src_node with (C). + * However, src type node is always src node and sink type node is always sink node. + * (A) is src node and can not be sink node at all. + * (C) is sink node and can not be src node at all. + * @param[in] src_node Media streamer node handle + * @param[in] src_pad_name The name of the source pad of the source node + * @param[in] dest_node The destination media streamer node handle + * @param[in] sink_pad_name The name of the sink pad of the destination node * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1093,9 +1096,9 @@ int media_streamer_node_link(media_streamer_node_h src_node, const char *src_pad /** * @brief Sets media format for pad of media streamer node. * @since_tizen 3.0 - * @param [in] node Media streamer node handle - * @param [in] pad_name Pad name - * @param [in] fmt Media format handle + * @param[in] node Media streamer node handle + * @param[in] pad_name Pad name + * @param[in] fmt Media format handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1111,9 +1114,9 @@ int media_streamer_node_set_pad_format(media_streamer_node_h node, const char *p /** * @brief Gets media format for pad of media streamer node. * @since_tizen 3.0 - * @param [in] node Media streamer node handle - * @param [in] pad_name Pad name - * @param [out] fmt Media format handle + * @param[in] node Media streamer node handle + * @param[in] pad_name Pad name + * @param[out] fmt Media format handle * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1129,15 +1132,15 @@ int media_streamer_node_get_pad_format(media_streamer_node_h node, const char *p /** * @brief Gets name of node pads. * @since_tizen 3.0 - * @remark After using the src_pad_name and sink_pad_name, it have to be free. - * src_pad_name or sink_pad_name can be null according to the node type. - * In case of src type node, sink_pad_name will be null. - * In case of sink type node, src_pad_name will be null. - * @param [in] node Media streamer node handle - * @param [out] src_pad_name Array of source pad name - * @param [out] src_pad_num The number of source pads - * @param [out] sink_pad_name Array of sink pad name - * @param [out] sink_pad_num The number of sink pads + * @remarks After using the src_pad_name and sink_pad_name, it have to be free. + * src_pad_name or sink_pad_name can be null according to the node type. + * In case of src type node, sink_pad_name will be null. + * In case of sink type node, src_pad_name will be null. + * @param[in] node Media streamer node handle + * @param[out] src_pad_name Array of source pad name + * @param[out] src_pad_num The number of source pads + * @param[out] sink_pad_name Array of sink pad name + * @param[out] sink_pad_num The number of sink pads * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1151,15 +1154,16 @@ int media_streamer_node_get_pad_format(media_streamer_node_h node, const char *p int media_streamer_node_get_pad_name(media_streamer_node_h node, char ***src_pad_name, int *src_pad_num, char ***sink_pad_name, int *sink_pad_num); - /** * @brief Sets parameters of node. * @details Many parameters can be set at one time all together by using bundle. * @since_tizen 3.0 + * @privilege http://tizen.org/privilege/mediastorage + * http://tizen.org/privilege/externalstorage * @remarks The mediastorage privilege(http://tizen.org/privilege/mediastorage) should be added if any video/audio files are written in the internal storage devices. * The externalstorage privilege(http://tizen.org/privilege/externalstorage) should be added if any video/audio files are written in the external storage devices. - * @param [in] node Media streamer node handle - * @param [in] param_list Key value array of media streamer node parameters + * @param[in] node Media streamer node handle + * @param[in] param_list Key value array of media streamer node parameters * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1178,10 +1182,10 @@ int media_streamer_node_set_params(media_streamer_node_h node, bundle *param_lis /** * @brief Gets node parameter list. * @since_tizen 3.0 - * @remark After using param_list, it have to be free by calling bundle_free() in bundle.h - * Refer to the "Parameter information of node" in this file to get info. - * @param [in] node Media streamer node handle - * @param [out] param_list Key value array of media streamer node parameters + * @remarks After using param_list, it have to be free by calling bundle_free() in bundle.h + * Refer to the "Parameter information of node" in this file to get info. + * @param[in] node Media streamer node handle + * @param[out] param_list Key value array of media streamer node parameters * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1202,11 +1206,13 @@ int media_streamer_node_get_params(media_streamer_node_h node, bundle **param_li * @brief Sets single parameter of node. * @details Sets parameter one by one without creating param bundle. * @since_tizen 3.0 + * @privilege http://tizen.org/privilege/mediastorage + * http://tizen.org/privilege/externalstorage * @remarks The mediastorage privilege(http://tizen.org/privilege/mediastorage) should be added if any video/audio files are written in the internal storage devices. * The externalstorage privilege(http://tizen.org/privilege/externalstorage) should be added if any video/audio files are written in the external storage devices. - * @param [in] node Media streamer node handle - * @param [in] param_name Param name of node - * @param [in] param_value Param value of node + * @param[in] node Media streamer node handle + * @param[in] param_name Param name of node + * @param[in] param_value Param value of node * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1230,9 +1236,9 @@ int media_streamer_node_set_param(media_streamer_node_h node, * @brief Gets value of parameter. * @details Gets parameter one by one without creating param bundle. * @since_tizen 3.0 - * @param [in] node Media streamer node handle - * @param [in] param_name Param name of node - * @param [out] param_value Param value of node + * @param[in] node Media streamer node handle + * @param[in] param_name Param name of node + * @param[out] param_value Param value of node * @return @c 0 on success, * otherwise a negative error value * @retval #MEDIA_STREAMER_ERROR_NONE Successful @@ -1258,4 +1264,4 @@ int media_streamer_node_get_param(media_streamer_node_h node, } #endif /* __cplusplus */ -#endif /* __TIZEN_MEDIASTREAMER_H__ */ +#endif /* __TIZEN_MULTIMEDIA_MEDIA_STREAMER_H__ */ diff --git a/packaging/capi-media-streamer.spec b/packaging/capi-media-streamer.spec index a562ad4..c5e2b77 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.20 +Version: 0.1.21 Release: 0 Group: Multimedia/API License: Apache-2.0 -- 2.7.4 From f791e0c1fa62cda9005a217c8de3f4b1dbfb3461 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Thu, 1 Feb 2018 13:34:58 +0900 Subject: [PATCH 05/16] Change the name of the toplogy_bin to transform_bin Topology is a term of MediaSession, the components of MediaSession include Source Node,Transform Node, Output Node and Tee Node. I want to change the name of the TopologyBin to TransformBin because Toppology is the same as GstBin or GstPipeline of Gstreamer, then leves are correct and we don't need to use the term of MediaSession. Change-Id: I174322f3d4041e3aa4ea5faea4168a4de2762c20 Signed-off-by: Hyunil --- include/media_streamer_gst.h | 4 +-- include/media_streamer_priv.h | 2 +- src/media_streamer_gst.c | 64 +++++++++++++++++++++---------------------- src/media_streamer_node.c | 18 ++++++------ src/media_streamer_priv.c | 12 ++++---- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/include/media_streamer_gst.h b/include/media_streamer_gst.h index 11b1da8..69e7c68 100644 --- a/include/media_streamer_gst.h +++ b/include/media_streamer_gst.h @@ -23,7 +23,7 @@ #define MEDIA_STREAMER_PIPELINE_NAME "media-streamer-pipeline" #define MEDIA_STREAMER_SRC_BIN_NAME "streamer_src" #define MEDIA_STREAMER_SINK_BIN_NAME "streamer_sink" -#define MEDIA_STREAMER_TOPOLOGY_BIN_NAME "streamer_topology" +#define MEDIA_STREAMER_TRANSFORM_BIN_NAME "streamer_transform" #define MEDIA_STREAMER_PAYLOADER_KLASS "Codec/Payloader/Network/RTP" #define MEDIA_STREAMER_RTP_KLASS "Filter/Network/RTP" @@ -192,7 +192,7 @@ gboolean __ms_element_lock_state(const GValue *item, GValue *ret, gpointer user_ gboolean __ms_element_unlock_state(const GValue *item, GValue *ret, gpointer user_data); /** - * @brief Creates pipeline, bus and src/sink/topology bins. + * @brief Creates pipeline, bus and src/sink/transform bins. * * @since_tizen 3.0 */ diff --git a/include/media_streamer_priv.h b/include/media_streamer_priv.h index 6d2e889..ad6df63 100644 --- a/include/media_streamer_priv.h +++ b/include/media_streamer_priv.h @@ -96,7 +96,7 @@ typedef struct { GstElement *src_bin; GstElement *sink_bin; - GstElement *topology_bin; + GstElement *transform_bin; GHashTable *nodes_table; GMutex mutex_lock; diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index 5a8c6ce..502ec4e 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -535,36 +535,36 @@ static void __decodebin_nomore_pads_combine(GstPad *src_pad, media_streamer_s *m const gchar *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->topology_bin, __ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY))) { - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY); + 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))) { + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY); src_pad = NULL; } if (sink_bin_type == MEDIA_STREAMER_SINK_BIN_RTP_SERVER) { - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_PAY); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_RTP); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_PAY); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_RTP); } else if (sink_bin_type == MEDIA_STREAMER_SINK_BIN_ADAPTIVE) { - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_MUXER); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_MUXER); found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } else { - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_CONVERTER); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_CONVERTER); found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } } else if (MS_ELEMENT_IS_AUDIO(new_pad_type)) { if (sink_bin_type == MEDIA_STREAMER_SINK_BIN_RTP_SERVER) { - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_PAY); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_RTP); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_PAY); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_RTP); } else if (sink_bin_type == MEDIA_STREAMER_SINK_BIN_ADAPTIVE) { - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_MUXER); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_MUXER); found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } else { found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } } else if (MS_ELEMENT_IS_TEXT(new_pad_type)) { - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY); } else { ms_error("Unsupported pad type [%s]!", new_pad_type); } @@ -621,7 +621,7 @@ GstElement *__ms_decodebin_create(media_streamer_s * ms_streamer, char * name) ms_retvm_if(!ms_streamer, NULL, "Handle is NULL"); GstElement *decodebin = __ms_element_create(DEFAULT_DECODEBIN, name); - __ms_bin_add_element(ms_streamer->topology_bin, decodebin, TRUE); + __ms_bin_add_element(ms_streamer->transform_bin, decodebin, TRUE); gst_element_sync_state_with_parent(decodebin); __ms_signal_create(&ms_streamer->autoplug_sig_list, decodebin, "pad-added", G_CALLBACK(__decodebin_newpad_cb), ms_streamer); @@ -641,8 +641,8 @@ static gboolean __ms_sink_bin_prepare(media_streamer_s * ms_streamer, GstPad * s if (MS_ELEMENT_IS_VIDEO(src_pad_type)) { gst_object_ref(parent_rtp_element); - found_element = __ms_combine_next_element(parent_rtp_element, source_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DEPAY); - decoder_element = __ms_bin_find_element_by_type(found_element, NULL, ms_streamer->topology_bin, __ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER)); + found_element = __ms_combine_next_element(parent_rtp_element, source_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DEPAY); + decoder_element = __ms_bin_find_element_by_type(found_element, NULL, ms_streamer->transform_bin, __ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER)); if (!decoder_element) { if (ms_streamer->ini.use_decodebin) { @@ -653,7 +653,7 @@ static gboolean __ms_sink_bin_prepare(media_streamer_s * ms_streamer, GstPad * s return TRUE; } else { gst_object_ref(found_element); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER); found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } } else { @@ -662,8 +662,8 @@ static gboolean __ms_sink_bin_prepare(media_streamer_s * ms_streamer, GstPad * s } } else if (MS_ELEMENT_IS_AUDIO(src_pad_type)) { gst_object_ref(parent_rtp_element); - found_element = __ms_combine_next_element(parent_rtp_element, source_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DEPAY); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DECODER); + found_element = __ms_combine_next_element(parent_rtp_element, source_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DEPAY); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DECODER); found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->sink_bin, MEDIA_STREAMER_NODE_TYPE_SINK); } else { ms_info("Unknown media type received from rtp element!"); @@ -776,11 +776,11 @@ static int __ms_adaptive_sink_prepare(media_streamer_s * ms_streamer) 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); - __ms_bin_add_element(ms_streamer->topology_bin, muxer, FALSE); + __ms_bin_add_element(ms_streamer->transform_bin, muxer, FALSE); gst_element_sync_state_with_parent(muxer); - __ms_bin_add_element(ms_streamer->topology_bin, video_enc, FALSE); + __ms_bin_add_element(ms_streamer->transform_bin, video_enc, FALSE); gst_element_sync_state_with_parent(video_enc); - __ms_bin_add_element(ms_streamer->topology_bin, audio_enc, FALSE); + __ms_bin_add_element(ms_streamer->transform_bin, audio_enc, FALSE); gst_element_sync_state_with_parent(audio_enc); return MEDIA_STREAMER_ERROR_NONE; @@ -1584,8 +1584,8 @@ int __ms_add_node_into_bin(media_streamer_s *ms_streamer, media_streamer_node_s bin = ms_streamer->sink_bin; break; default: - /* Another elements will be add into topology bin */ - bin = ms_streamer->topology_bin; + /* Another elements will be add into transform bin */ + bin = ms_streamer->transform_bin; break; } @@ -1863,10 +1863,10 @@ int __ms_pipeline_create(media_streamer_s *ms_streamer) ms_streamer->sink_bin = gst_bin_new(MEDIA_STREAMER_SINK_BIN_NAME); ms_retvm_if(ms_streamer->sink_bin == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error creating Sink bin"); - ms_streamer->topology_bin = gst_bin_new(MEDIA_STREAMER_TOPOLOGY_BIN_NAME); - ms_retvm_if(ms_streamer->topology_bin == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error creating Topology bin"); + ms_streamer->transform_bin = gst_bin_new(MEDIA_STREAMER_TRANSFORM_BIN_NAME); + ms_retvm_if(ms_streamer->transform_bin == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error creating Transform bin"); - gst_bin_add_many(GST_BIN(ms_streamer->pipeline), ms_streamer->src_bin, ms_streamer->sink_bin, ms_streamer->topology_bin, NULL); + 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."); return ret; @@ -2222,11 +2222,11 @@ static void __demux_nomore_pads_combine(GstPad *src_pad, media_streamer_s *ms_st GstElement *found_element = gst_pad_get_parent_element(src_pad); const gchar *new_pad_type = __ms_get_pad_type(src_pad); if (MS_ELEMENT_IS_VIDEO(new_pad_type)) - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_DECODER); + 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)) - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DECODER); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_DECODER); else if (MS_ELEMENT_IS_TEXT(new_pad_type)) - found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY); + found_element = __ms_combine_next_element(found_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_TEXT_OVERLAY); else ms_error("Unsupported pad type [%s]!", new_pad_type); @@ -2291,7 +2291,7 @@ int __ms_find_type(media_streamer_s *ms_streamer, GstElement *src_element) ms_retvm_if(typefind == NULL, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Error creating element [typefind]"); - __ms_bin_add_element(ms_streamer->topology_bin, typefind, TRUE); + __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); diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index d7018b4..ff7563a 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -807,19 +807,19 @@ static gboolean _src_node_prepare(const GValue *item, GValue *ret, gpointer user } /* It is media streamer Server part */ if (MS_ELEMENT_IS_VIDEO(new_pad_type) || MS_ELEMENT_IS_IMAGE(new_pad_type)) { - found_element = __ms_combine_next_element(src_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_FILTER); + found_element = __ms_combine_next_element(src_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_FILTER); GstCaps *videoCaps = gst_caps_from_string(MEDIA_STREAMER_DEFAULT_CAMERA_FORMAT); g_object_set(G_OBJECT(found_element), "caps", videoCaps, NULL); gst_caps_unref(videoCaps); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_PAY); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_RTP); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_ENCODER); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_VIDEO_PAY); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_RTP); } if (MS_ELEMENT_IS_AUDIO(new_pad_type)) { - found_element = __ms_combine_next_element(src_element, src_pad, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_PAY); - found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->topology_bin, MEDIA_STREAMER_NODE_TYPE_RTP); + found_element = __ms_combine_next_element(src_element, src_pad, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_ENCODER); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_AUDIO_PAY); + found_element = __ms_combine_next_element(found_element, NULL, ms_streamer->transform_bin, MEDIA_STREAMER_NODE_TYPE_RTP); } __ms_generate_dots(ms_streamer->pipeline, "after_connecting_rtp"); MS_SAFE_UNREF(found_element); @@ -913,7 +913,7 @@ int __ms_pipeline_prepare(media_streamer_s *ms_streamer) } if (adaptive_src) { - if (GST_BIN(ms_streamer->topology_bin)->numchildren == 0) + if (GST_BIN(ms_streamer->transform_bin)->numchildren == 0) ret = __ms_adaptive_element_prepare(adaptive_src, true); else ret = __ms_adaptive_element_prepare(adaptive_src, false); @@ -1037,7 +1037,7 @@ int __ms_pipeline_unprepare(media_streamer_s *ms_streamer) } MS_BIN_UNPREPARE(ms_streamer->src_bin); - MS_BIN_UNPREPARE(ms_streamer->topology_bin); + MS_BIN_UNPREPARE(ms_streamer->transform_bin); MS_BIN_UNPREPARE(ms_streamer->sink_bin); return ret; diff --git a/src/media_streamer_priv.c b/src/media_streamer_priv.c index e0efc4e..30f2908 100644 --- a/src/media_streamer_priv.c +++ b/src/media_streamer_priv.c @@ -218,14 +218,14 @@ int __ms_acquire_resources(media_streamer_s *ms_streamer) return ret; } - /* Acquire resources for topology bin. If user doesn't + /* Acquire resources for transform bin. If user doesn't add nodes explicitly they will be acquired later. For example when decodebin is used resources are quired when 'autoplug-select' signal is triggered for new GstElement. */ - ret = __ms_bin_foreach_elements(GST_BIN(ms_streamer->topology_bin), + ret = __ms_bin_foreach_elements(GST_BIN(ms_streamer->transform_bin), _ms_node_resouces_acquire_iter, ms_streamer); if (MEDIA_STREAMER_ERROR_NONE != ret) { - ms_error("Failed to acquire resources for topology bin"); + ms_error("Failed to acquire resources for transform bin"); return ret; } @@ -252,13 +252,13 @@ int __ms_release_resources(media_streamer_s *ms_streamer) return ret; } - /* Release resources for topology bin. Here we also consider + /* Release resources for transform bin. Here we also consider nodes that were not added by user explicitly (e.g. decodebin was used). */ - ret = __ms_bin_foreach_elements(GST_BIN(ms_streamer->topology_bin), + ret = __ms_bin_foreach_elements(GST_BIN(ms_streamer->transform_bin), _ms_node_resouces_release_iter, ms_streamer); if (MEDIA_STREAMER_ERROR_NONE != ret) { - ms_error("Failed to release resources for topology bin"); + ms_error("Failed to release resources for trannsform bin"); return ret; } -- 2.7.4 From 3e62b300ce1b80274b44da74d94dd71373844e56 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Thu, 8 Feb 2018 11:10:17 +0900 Subject: [PATCH 06/16] Remove setting render rectangle Videosink set full screen without setting the window size of the application Change-Id: Ib9462a01425b630cab19a3b1ce1e6cbcc4294b6b Signed-off-by: Hyunil --- include/media_streamer_priv.h | 5 ----- src/media_streamer_node.c | 31 +------------------------------ 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/include/media_streamer_priv.h b/include/media_streamer_priv.h index ad6df63..a2a49ce 100644 --- a/include/media_streamer_priv.h +++ b/include/media_streamer_priv.h @@ -148,11 +148,6 @@ typedef struct { typedef struct _media_streamer_wl_info_s { int parent_id; - int window_x; - int window_y; - int window_width; - int window_height; - void *evas_obj; } media_streamer_wl_info_s; /* Private functions definition */ diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index ff7563a..3be4629 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -1379,34 +1379,7 @@ int _media_streamer_get_wl_info(Evas_Object *obj, media_streamer_wl_info_s *wl_i wl_display_roundtrip_queue(display, queue); if (wl_info->parent_id > 0) { - int rotation = 0; - Ecore_Evas *ecore_evas = NULL; - ret = MEDIA_STREAMER_ERROR_NONE; - - wl_info->evas_obj = obj; - - evas_object_geometry_get(obj, &wl_info->window_x, &wl_info->window_y, - &wl_info->window_width, &wl_info->window_height); - - ecore_evas = ecore_evas_ecore_evas_get(evas_object_evas_get(obj)); - if (ecore_evas) { - rotation = ecore_evas_rotation_get(ecore_evas); - if (rotation == 90 || rotation == 270) { - int temp = wl_info->window_width; - - LOGD("swap width and height %d, %d", wl_info->window_width, wl_info->window_height); - - wl_info->window_width = wl_info->window_height; - wl_info->window_height = temp; - } - } else { - LOGW("failed to get ecore_evas.. skip rotation check"); - } - - LOGD("evas object : %p, rotation : %d, parent id : %u, window : %d,%d,%dx%d", - wl_info->evas_obj, rotation, wl_info->parent_id, - wl_info->window_x, wl_info->window_y, - wl_info->window_width, wl_info->window_height); + LOGD("parent id : %u", wl_info->parent_id); } else { ret = MEDIA_STREAMER_ERROR_INVALID_OPERATION; LOGE("failed to get parent id"); @@ -1463,8 +1436,6 @@ int __ms_node_set_display(media_streamer_node_s *ms_node, const char *param_valu LOGD("wayland global surface id : %d", wl_info.parent_id); gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(ms_node->gst_element), (guintptr)wl_info.parent_id); - gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(ms_node->gst_element), - wl_info.window_x, wl_info.window_y, wl_info.window_width, wl_info.window_height); return ret; } -- 2.7.4 From 72513c69037af22e33ed860a64988bc81a8b193f Mon Sep 17 00:00:00 2001 From: Hyunil Date: Mon, 12 Feb 2018 11:13:03 +0900 Subject: [PATCH 07/16] Check return value of __ms_adaptive_sink_http_server_prepare() Change-Id: Id260a37fbedabd6c5bcc1669e566b16e827487d9 Signed-off-by: Hyunil --- src/media_streamer_node.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index 3be4629..f13824b 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -920,7 +920,7 @@ int __ms_pipeline_prepare(media_streamer_s *ms_streamer) } if (adaptive_sink) - __ms_adaptive_sink_http_server_prepare(ms_streamer, adaptive_sink); + ret = __ms_adaptive_sink_http_server_prepare(ms_streamer, adaptive_sink); if (ret != MEDIA_STREAMER_ERROR_NONE) goto prepare_fail; -- 2.7.4 From 95071b0dc7e2841f1284f822de8d8c3a03bc496b Mon Sep 17 00:00:00 2001 From: Hyunil Date: Wed, 14 Feb 2018 16:29:04 +0900 Subject: [PATCH 08/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 09/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 10/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 11/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 12/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 13/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 14/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 15/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 16/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