Add webrtcbin element to pipeline and add _gst_destroy_pipeline() sub-function 20/242620/5
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 28 Aug 2020 08:45:44 +0000 (17:45 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 4 Sep 2020 02:56:46 +0000 (11:56 +0900)
[Version] 0.1.2
[Issue Type] Improvement

Change-Id: I324a02b04453eb9dfebe4105241e55036ee14c64
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_private.c

index 6de5cf9fe347232a8fe689bfd6d86090a82fca86..5a7fc2444964bffaa389bab37d4a7067c4b8c111 100644 (file)
@@ -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
 }
index 701f3b871cc1cd217c4a34192ef8f41876aa2691..95e1e2433ef61172ff8ee5687d64a424c88655be 100644 (file)
@@ -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
index 1a624711241bfb42dc52c467c52f13f4878f229e..6ee3ce4865b459ac872ac2182f41d1f73724ab04 100644 (file)
@@ -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);
index 2c1dc30b25065e5d11335cce1bbec400e26c8596..8b400d12a870daa27204cb032576af2b5eb8ff59 100644 (file)
@@ -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;
+       }
 }
+