Add API set for error callback 54/243254/9
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 4 Sep 2020 08:01:44 +0000 (17:01 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 11 Sep 2020 05:20:24 +0000 (14:20 +0900)
Functions are added as below.
 - webrtc_set_error_cb()
 - webrtc_unset_error_cb()

Test cases for these functions are added to webrtc_test.

[Version] 0.1.12
[Issue Type] API

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

index 84b30d018eaa772ab3ecda9a15dc907a3dd97f33..cfcaea91048552383a22b96e2519a343385ef475 100644 (file)
@@ -80,15 +80,27 @@ typedef enum {
        WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST
 } webrtc_media_source_type_e;
 
+/**
+ * @brief Called when an error occurs.
+ * @since_tizen 6.0
+ * @remarks The @a webrtc is the same object for which the callback was set.
+ * @param [in] webrtc     WebRTC handle
+ * @param [in] error      The error code
+ * @param [in] state      The current state of the WebRTC handle
+ * @param [in] user_data  The user data passed from the callback registration function
+ * @see webrtc_set_error_cb()
+ * @see webrtc_unset_error_cb()
+ */
+typedef void (*webrtc_error_cb)(webrtc_h webrtc, webrtc_error_e error, webrtc_state_e state, void *user_data);
 
 /**
  * @brief Called when the WebRTC state is changed.
  * @since_tizen 6.0
  * @remarks The @a webrtc is the same object for which the callback was set.
- * @param[in] webrtc     WebRTC handle
- * @param[in] previous   The previous state of the WebRTC handle
- * @param[in] current    The current state of the WebRTC handle
- * @param[in] user_data  The user data passed from the callback registration function
+ * @param [in] webrtc     WebRTC handle
+ * @param [in] previous   The previous state of the WebRTC handle
+ * @param [in] current    The current state of the WebRTC handle
+ * @param [in] user_data  The user data passed from the callback registration function
  * @see webrtc_set_state_changed_cb()
  * @see webrtc_unset_state_changed_cb()
  */
@@ -97,13 +109,42 @@ typedef void (*webrtc_state_changed_cb)(webrtc_h webrtc, webrtc_state_e previous
 /**
  * @brief Called when the WebRTC needs session negotiation.
  * @since_tizen 6.0
- * @param[in] webrtc     WebRTC handle
- * @param[in] user_data  The user data passed from the callback registration function
+ * @param [in] webrtc     WebRTC handle
+ * @param [in] user_data  The user data passed from the callback registration function
  * @see webrtc_set_negotiation_needed_cb()
  * @see webrtc_unset_negotiation_needed_cb()
  */
 typedef void (*webrtc_negotiation_needed_cb)(webrtc_h webrtc, void *user_data);
 
+/**
+ * @brief Sets a callback function to be invoked when an asynchronous operation error occurs.
+ * @since_tizen 6.0
+ * @param [in] webrtc      WebRTC handle
+ * @param [in] callback    Callback function pointer
+ * @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 #WEBRTC_ERROR_NONE    Successful
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post webrtc_error_cb() will be invoked.
+ * @see webrtc_unset_error_cb()
+ * @see webrtc_error_cb()
+ */
+int webrtc_set_error_cb(webrtc_h webrtc, webrtc_error_cb callback, void *user_data);
+
+/**
+ * @brief Unsets the error callback function.
+ * @since_tizen 6.0
+ * @param [in] webrtc      WebRTC handle
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WEBRTC_ERROR_NONE    Successful
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation
+ * @see webrtc_set_error_cb()
+ */
+int webrtc_unset_error_cb(webrtc_h webrtc);
+
 /**
  * @brief Sets a callback function to be invoked when the WebRTC state is changed.
  * @since_tizen 6.0
index e96fa1540ed4a2ce66b850cdcd46d5fb9237a7dc..424c437e0793c6503fb0ecd61a3220bcf5db2baa 100644 (file)
@@ -149,6 +149,7 @@ typedef struct _webrtc_s {
 
        GList *signals;
 
+       webrtc_callbacks_s error_cb;
        webrtc_callbacks_s state_changed_cb;
        webrtc_callbacks_s negotiation_needed_cb;
 } webrtc_s;
index f691a8d9f2eb2798b0918b0bf8fba7fd95990a86..7ad2646c04da972e9166d5d5333c2402cffb55a4 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.1.11
+Version:    0.1.12
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index d6ca56075c86ad9ce3b90482b5d9c69860e0a8d3..f4d86fb81d88d6c3057140254d34e45a3aeae73c 100644 (file)
 #include "webrtc.h"
 #include "webrtc_private.h"
 
+int webrtc_set_error_cb(webrtc_h webrtc, webrtc_error_cb callback, void *user_data)
+{
+       webrtc_s *_webrtc = (webrtc_s*)webrtc;
+
+       RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(callback == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "callback is NULL");
+
+       g_mutex_lock(&_webrtc->mutex);
+
+       _webrtc->error_cb.callback = callback;
+       _webrtc->error_cb.user_data = user_data;
+
+       LOG_INFO("callback[%p] user_data[%p]", callback, user_data);
+
+       g_mutex_unlock(&_webrtc->mutex);
+
+       return WEBRTC_ERROR_NONE;
+}
+
+int webrtc_unset_error_cb(webrtc_h webrtc)
+{
+       webrtc_s *_webrtc = (webrtc_s*)webrtc;
+
+       RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+
+       g_mutex_lock(&_webrtc->mutex);
+
+       RET_VAL_WITH_UNLOCK_IF(_webrtc->error_cb.callback == NULL, WEBRTC_ERROR_INVALID_OPERATION, &_webrtc->mutex, "callback was not set");
+
+       LOG_INFO("callback[%p] user_data[%p] is reset to NULL",
+               _webrtc->error_cb.callback, _webrtc->error_cb.user_data);
+
+       _webrtc->error_cb.callback = NULL;
+       _webrtc->error_cb.user_data = NULL;
+
+       g_mutex_unlock(&_webrtc->mutex);
+
+       return WEBRTC_ERROR_NONE;
+}
+
 int webrtc_set_state_changed_cb(webrtc_h webrtc, webrtc_state_changed_cb callback, void *user_data)
 {
        webrtc_s *_webrtc = (webrtc_s*)webrtc;
index 856a9f2d1bbc8ed8183d68e2eb8cbf3eafd3dcc4..0ed7b0748fbff57a550af57e8ec964e73431c437 100644 (file)
@@ -147,7 +147,19 @@ static gboolean __bus_watch_cb(GstBus *bus, GstMessage *message, gpointer user_d
                gst_message_parse_error(message, &err, NULL);
 
                LOG_ERROR("Error from [%s]: %s", GST_OBJECT_NAME(GST_OBJECT_CAST(GST_ELEMENT(GST_MESSAGE_SRC(message)))), err->message);
-               /* FIXME : invoke error cb */
+
+               if (webrtc->error_cb.callback) {
+                       webrtc_error_e error = WEBRTC_ERROR_INVALID_OPERATION;
+                       if (err->domain == GST_RESOURCE_ERROR)
+                               error = WEBRTC_ERROR_RESOURCE_CONFLICT;
+                       else if (err->domain == GST_STREAM_ERROR)
+                               error = WEBRTC_ERROR_CONNECTION_FAILED;
+
+                       LOG_DEBUG(">>> invoke error_cb[%p], user_data[%p]",
+                               webrtc->error_cb.callback, webrtc->error_cb.user_data);
+                       ((webrtc_error_cb)(webrtc->error_cb.callback))((webrtc_h)webrtc, error, webrtc->state, webrtc->error_cb.user_data);
+                       LOG_DEBUG("<<< end of the callback");
+               }
 
                g_error_free(err);
                break;
index 828cae7f36005eed935efe7a709a87a8ee8d1d50..d048f097cd0393a466e7b297cefc9fb378eb758b 100644 (file)
@@ -315,9 +315,37 @@ static void _webrtc_set_stun_server(char *uri)
                g_print("webrtc_set_stun_server() success, uri[%s]\n", g_stun_server);
 }
 
+static void __error_cb(webrtc_h webrtc, webrtc_error_e error, webrtc_state_e state, void *user_data)
+{
+       g_print("__error_cb() is invoked, webrtc[%p], error[0x%x], state[%d], user_data[%p]\n",
+               webrtc, error, state, user_data);
+}
+
+static void _webrtc_set_error_cb()
+{
+       int ret = WEBRTC_ERROR_NONE;
+
+       ret = webrtc_set_error_cb(g_webrtc, __error_cb, g_webrtc);
+       if (ret != WEBRTC_ERROR_NONE)
+               g_print("failed to webrtc_set_error_cb()\n");
+       else
+               g_print("webrtc_set_error_cb() success\n");
+}
+
+static void _webrtc_unset_error_cb()
+{
+       int ret = WEBRTC_ERROR_NONE;
+
+       ret = webrtc_unset_error_cb(g_webrtc);
+       if (ret != WEBRTC_ERROR_NONE)
+               g_print("failed to webrtc_unset_error_cb()\n");
+       else
+               g_print("webrtc_unset_error_cb() success\n");
+}
+
 static void __state_changed_cb(webrtc_h webrtc, webrtc_state_e previous, webrtc_state_e current, void *user_data)
 {
-       g_print("__state_changed_cb() is invoked, webrtc[%p], previous(%d) -> current(%d), user_data[%p]\n",
+       g_print("__state_changed_cb() is invoked, webrtc[%p], prev[%d] -> curr[%d], user_data[%p]\n",
                webrtc, previous, current, user_data);
 }
 
@@ -497,6 +525,12 @@ void _interpret_main_menu(char *cmd)
                } else if (strncmp(cmd, "px", 2) == 0) {
                        g_menu_state = CURRENT_STATUS_SETTING_PROXY;
 
+               } else if (strncmp(cmd, "se", 2) == 0) {
+                       _webrtc_set_error_cb();
+
+               } else if (strncmp(cmd, "ue", 2) == 0) {
+                       _webrtc_unset_error_cb();
+
                } else if (strncmp(cmd, "sc", 2) == 0) {
                        _webrtc_set_state_changed_cb();
 
@@ -543,6 +577,8 @@ void display_sub_basic()
        g_print("g. Get state\n");
        g_print("a. Add media source\t");
        g_print("r. Remove media source\n");
+       g_print("se. Set error callback\t");
+       g_print("ue. Unset error callback\n");
        g_print("sc. Set state changed callback\t");
        g_print("us. Unset state changed callback\n");
        g_print("sn. Set negotiation needed callback\t");