From: Sangchul Lee Date: Fri, 28 Aug 2020 08:45:44 +0000 (+0900) Subject: Add webrtcbin element to pipeline and add _gst_destroy_pipeline() sub-function X-Git-Tag: submit/tizen/20210729.023123~240 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=711ae728016b36b2cbe2a137783a04214e666122;p=platform%2Fcore%2Fapi%2Fwebrtc.git Add webrtcbin element to pipeline and add _gst_destroy_pipeline() sub-function [Version] 0.1.2 [Issue Type] Improvement Change-Id: I324a02b04453eb9dfebe4105241e55036ee14c64 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 6de5cf9f..5a7fc244 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -96,6 +96,7 @@ do { \ } while (0) #define SAFE_FREE(src) { if (src) { free(src); src = NULL; } } +#define SAFE_STR(str) (str) ? str : "null" #define SOURCES_MAX 8 @@ -105,12 +106,13 @@ typedef struct _webrtc_ini_s { } webrtc_ini_s; typedef struct _webrtc_gst_src_s { - int source_id; + unsigned int source_id; GstElement *bin; } webrtc_gst_src_s; typedef struct _webrtc_gst_s { GstElement *pipeline; + GstElement *webrtcbin; GstBus *bus; guint bus_watcher; webrtc_gst_src_s *audiosrc[SOURCES_MAX]; @@ -131,6 +133,7 @@ typedef struct _webrtc_s { int _ini_load(webrtc_s *webrtc); int _gst_init(webrtc_s *webrtc); int _gst_build_pipeline(webrtc_s *webrtc); +void _gst_destroy_pipeline(webrtc_s *webrtc); #ifdef __cplusplus } diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 701f3b87..95e1e243 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -1,6 +1,6 @@ Name: capi-media-webrtc Summary: A WebRTC library in Tizen Native API -Version: 0.1.1 +Version: 0.1.2 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index 1a624711..6ee3ce48 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -58,10 +58,7 @@ int webrtc_destroy(webrtc_h webrtc) /* set state to null here */ - if (_webrtc->gst.bus) - gst_object_unref(_webrtc->gst.bus); - if (_webrtc->gst.pipeline) - gst_object_unref(_webrtc->gst.pipeline); + _gst_destroy_pipeline(_webrtc); g_mutex_unlock(&_webrtc->mutex); g_mutex_clear(&_webrtc->mutex); diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 2c1dc30b..8b400d12 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -80,6 +80,20 @@ static gboolean __bus_watch_cb(GstBus *bus, GstMessage *message, gpointer user_d return TRUE; } +static GstElement *__element_create(const char *factory_name, const char *name) +{ + GstElement *element = NULL; + + RET_VAL_IF(!factory_name, NULL, "factory name is NULL"); + + element = gst_element_factory_make(factory_name, name); + RET_VAL_IF(!element, NULL, "element is NULL [%s]", factory_name); + + LOG_DEBUG("created element [%s, %s]", factory_name, SAFE_STR(name)); + + return element; +} + int _ini_load(webrtc_s *webrtc) { RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); @@ -142,19 +156,58 @@ int _gst_init(webrtc_s *webrtc) int _gst_build_pipeline(webrtc_s *webrtc) { - int ret = WEBRTC_ERROR_NONE; - RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); webrtc->gst.pipeline = gst_pipeline_new("native-webrtc-pipeline"); RET_VAL_IF(webrtc->gst.pipeline == NULL, WEBRTC_ERROR_INVALID_OPERATION, "pipeline is NULL"); - webrtc->gst.bus = gst_pipeline_get_bus(GST_PIPELINE(webrtc->gst.pipeline)); - RET_VAL_IF(webrtc->gst.bus == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bus is NULL"); + if (!(webrtc->gst.bus = gst_pipeline_get_bus(GST_PIPELINE(webrtc->gst.pipeline)))) { + LOG_ERROR("failed to gst_pipeline_get_bus()"); + goto error; + } + + if ((webrtc->gst.bus_watcher = gst_bus_add_watch(webrtc->gst.bus, (GstBusFunc) __bus_watch_cb, webrtc)) == 0) { + LOG_ERROR("failed to gst_bus_add_watch()"); + goto error; + } + + if (!(webrtc->gst.webrtcbin = __element_create("webrtcbin", NULL))) { + LOG_ERROR("failed to create webrtcbin"); + goto error; + } + + if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), webrtc->gst.webrtcbin)) { + LOG_ERROR("failed to gst_bin_add(), [%s] -> [%s] pipeline", GST_ELEMENT_NAME(webrtc->gst.webrtcbin), GST_ELEMENT_NAME(webrtc->gst.pipeline)); + goto error; + } - webrtc->gst.bus_watcher = gst_bus_add_watch(webrtc->gst.bus, (GstBusFunc) __bus_watch_cb, webrtc); + return WEBRTC_ERROR_NONE; + +error: + _gst_destroy_pipeline(webrtc); + return WEBRTC_ERROR_INVALID_OPERATION; +} - /* FIXME : initial bin setting */ +void _gst_destroy_pipeline(webrtc_s *webrtc) +{ + if (!webrtc) + return; - return ret; + if (webrtc->gst.bus_watcher > 0) { + gst_bus_remove_watch(webrtc->gst.bus); + webrtc->gst.bus_watcher = 0; + } + if (webrtc->gst.bus) { + gst_object_unref(webrtc->gst.bus); + webrtc->gst.bus = NULL; + } + if (webrtc->gst.webrtcbin) { + gst_bin_remove(GST_BIN(webrtc->gst.pipeline), webrtc->gst.webrtcbin); + webrtc->gst.webrtcbin = NULL; + } + if (webrtc->gst.pipeline) { + gst_object_unref(webrtc->gst.pipeline); + webrtc->gst.pipeline = NULL; + } } +