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>
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()
*/
/**
* @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
GList *signals;
+ webrtc_callbacks_s error_cb;
webrtc_callbacks_s state_changed_cb;
webrtc_callbacks_s negotiation_needed_cb;
} webrtc_s;
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
#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;
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;
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);
}
} 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();
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");