Functions are added as below.
- webrtc_set_state_changed_cb()
- webrtc_unset_state_changed_cb()
Test cases for these functions are added to webrtc_test.
[Version] 0.1.11
[Issue Type] API
Change-Id: I384ce3da148cd6181795a998abb33b98855543c2
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST
} webrtc_media_source_type_e;
+
+/**
+ * @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
+ * @see webrtc_set_state_changed_cb()
+ * @see webrtc_unset_state_changed_cb()
+ */
+typedef void (*webrtc_state_changed_cb)(webrtc_h webrtc, webrtc_state_e previous, webrtc_state_e current, void *user_data);
+
/**
* @brief Called when the WebRTC needs session negotiation.
* @since_tizen 6.0
*/
typedef void (*webrtc_negotiation_needed_cb)(webrtc_h webrtc, void *user_data);
+/**
+ * @brief Sets a callback function to be invoked when the WebRTC state is changed.
+ * @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_state_changed_cb() will be invoked.
+ * @see webrtc_unset_state_changed_cb()
+ * @see webrtc_state_changed_cb()
+ */
+int webrtc_set_state_changed_cb(webrtc_h webrtc, webrtc_state_changed_cb callback, void *user_data);
+
+/**
+ * @brief Unsets the state changed 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_state_changed_cb()
+ */
+int webrtc_unset_state_changed_cb(webrtc_h webrtc);
+
/**
* @brief Creates an instance of WebRTC.
* @since_tizen 6.0
GList *signals;
+ 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.10
+Version: 0.1.11
Release: 0
Group: Multimedia/API
License: Apache-2.0
#include "webrtc.h"
#include "webrtc_private.h"
+int webrtc_set_state_changed_cb(webrtc_h webrtc, webrtc_state_changed_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->state_changed_cb.callback = callback;
+ _webrtc->state_changed_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_state_changed_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->state_changed_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->state_changed_cb.callback, _webrtc->state_changed_cb.user_data);
+
+ _webrtc->state_changed_cb.callback = NULL;
+ _webrtc->state_changed_cb.user_data = NULL;
+
+ g_mutex_unlock(&_webrtc->mutex);
+
+ return WEBRTC_ERROR_NONE;
+}
+
int webrtc_create(webrtc_h *webrtc)
{
int ret = WEBRTC_ERROR_NONE;
}
if (__meet_gst_state(webrtc->pend_state, gst_state_new)) {
+ webrtc_state_e old_state = webrtc->state;
+
LOG_INFO("webrtc state is changed [%d] -> [%d]", webrtc->state, webrtc->pend_state);
webrtc->state = webrtc->pend_state;
- /* TODO: trigger state changed cb */
+
+ if (webrtc->state_changed_cb.callback) {
+ LOG_DEBUG(">>> invoke state_changed_cb[%p], user_data[%p]",
+ webrtc->state_changed_cb.callback, webrtc->state_changed_cb.user_data);
+ ((webrtc_state_changed_cb)(webrtc->state_changed_cb.callback))((webrtc_h)webrtc, old_state, webrtc->state, webrtc->state_changed_cb.user_data);
+ LOG_DEBUG("<<< end of the callback");
+ }
}
g_mutex_unlock(&webrtc->mutex);
g_print("webrtc_set_stun_server() success, uri[%s]\n", g_stun_server);
}
+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",
+ webrtc, previous, current, user_data);
+}
+
+static void _webrtc_set_state_changed_cb()
+{
+ int ret = WEBRTC_ERROR_NONE;
+
+ ret = webrtc_set_state_changed_cb(g_webrtc, __state_changed_cb, g_webrtc);
+ if (ret != WEBRTC_ERROR_NONE)
+ g_print("failed to webrtc_set_state_changed_cb()\n");
+ else
+ g_print("webrtc_set_state_changed_cb() success\n");
+}
+
+static void _webrtc_unset_state_changed_cb()
+{
+ int ret = WEBRTC_ERROR_NONE;
+
+ ret = webrtc_unset_state_changed_cb(g_webrtc);
+ if (ret != WEBRTC_ERROR_NONE)
+ g_print("failed to webrtc_unset_state_changed_cb()\n");
+ else
+ g_print("webrtc_unset_state_changed_cb() success\n");
+}
+
static void __negotiation_needed_cb(webrtc_h webrtc, void *user_data)
{
- g_print("__negotiation_needed_cb() is invoked\n");
+ g_print("__negotiation_needed_cb() is invoked, webrtc[%p], user_data[%p]\n", webrtc, user_data);
}
static void _webrtc_set_negotiation_needed_cb()
} else if (strncmp(cmd, "px", 2) == 0) {
g_menu_state = CURRENT_STATUS_SETTING_PROXY;
+ } else if (strncmp(cmd, "sc", 2) == 0) {
+ _webrtc_set_state_changed_cb();
+
+ } else if (strncmp(cmd, "us", 2) == 0) {
+ _webrtc_unset_state_changed_cb();
+
} else if (strncmp(cmd, "sn", 2) == 0) {
_webrtc_set_negotiation_needed_cb();
g_print("g. Get state\n");
g_print("a. Add media source\t");
g_print("r. Remove media source\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");
g_print("un. Unset negotiation needed callback\n");
g_print("co. Create offer\t");