From: Sangchul Lee Date: Tue, 31 Aug 2021 08:57:45 +0000 (+0900) Subject: webrtc_test: Add menu for creating offer/answer asynchronously X-Git-Tag: submit/tizen/20210906.055733~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cd5339a3f64a98d05cf164bf9f3e1406c357ef0a;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_test: Add menu for creating offer/answer asynchronously [Version] 0.2.92 [Issue Type] New feature Change-Id: I2b30064c4731d82c38786913ff0ddc0f866144f4 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index aa4de3bf..c518f9e7 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.2.91 +Version: 0.2.92 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/test/webrtc_test.c b/test/webrtc_test.c index c38e9175..6cce4113 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -1071,7 +1071,23 @@ static void _webrtc_media_source_set_mute(int index, unsigned int source_id, web g_print("webrtc_media_source_get_mute() success, source_id[%d], mute_status[%d]\n", source_id, mute_status); } -static void _webrtc_create_offer(connection_s *conn) +static void __offer_created_cb(webrtc_h webrtc, const char *description, void *user_data) +{ + connection_s *conn = (connection_s *)user_data; + g_print("__offer_created_cb() is called, description[%s], user_data[%p]\n", description, user_data); + + conn->offer = strdup(description); +} + +static void __answer_created_cb(webrtc_h webrtc, const char *description, void *user_data) +{ + connection_s *conn = (connection_s *)user_data; + g_print("__answer_created_cb() is called, description[%s], user_data[%p]\n", description, user_data); + + conn->answer = strdup(description); +} + +static void _webrtc_create_offer(connection_s *conn, bool async) { int ret = WEBRTC_ERROR_NONE; @@ -1082,13 +1098,20 @@ static void _webrtc_create_offer(connection_s *conn) conn->offer = NULL; } - ret = webrtc_create_offer(conn->webrtc, NULL, &conn->offer); - RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret); + if (!async) { + ret = webrtc_create_offer(conn->webrtc, NULL, &conn->offer); + RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret); - g_print("webrtc_create_offer() success\noffer:\n%s\n", conn->offer); + g_print("webrtc_create_offer() success\noffer:\n%s\n", conn->offer); + } else { + ret = webrtc_create_offer_async(conn->webrtc, NULL, __offer_created_cb, conn); + RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret); + + g_print("webrtc_create_offer_async() success\n"); + } } -static void _webrtc_create_answer(connection_s *conn) +static void _webrtc_create_answer(connection_s *conn, bool async) { int ret = WEBRTC_ERROR_NONE; @@ -1099,10 +1122,17 @@ static void _webrtc_create_answer(connection_s *conn) conn->answer = NULL; } - ret = webrtc_create_answer(conn->webrtc, NULL, &conn->answer); - RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret); + if (!async) { + ret = webrtc_create_answer(conn->webrtc, NULL, &conn->answer); + RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret); - g_print("webrtc_create_answer() success\nanswer:\n%s\n", conn->answer); + g_print("webrtc_create_answer() success\nanswer:\n%s\n", conn->answer); + } else { + ret = webrtc_create_answer_async(conn->webrtc, NULL, __answer_created_cb, conn); + RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret); + + g_print("webrtc_create_answer_async() success\n"); + } } static void _webrtc_set_local_description(connection_s *conn, bool is_offer) @@ -1511,7 +1541,7 @@ static void __state_changed_cb(webrtc_h webrtc, webrtc_state_e previous, webrtc_ if (conn->is_for_room && current == WEBRTC_STATE_NEGOTIATING) { if (conn->is_offer) { - _webrtc_create_offer(conn); + _webrtc_create_offer(conn, false); _webrtc_set_local_description(conn, true); _websocket_connection_send_text_for_room(conn, conn->remote_peer_id, conn->offer); } else { @@ -1698,7 +1728,7 @@ static void __signaling_state_change_cb(webrtc_h webrtc, webrtc_signaling_state_ g_print("__signaling_state_change_cb() is invoked, state[%d]\n", state); if (conn->is_for_room && state == WEBRTC_SIGNALING_STATE_HAVE_REMOTE_OFFER) { - _webrtc_create_answer(conn); + _webrtc_create_answer(conn, false); _webrtc_set_local_description(conn, false); _websocket_connection_send_text_for_room(conn, conn->remote_peer_id, conn->answer); } @@ -3582,10 +3612,10 @@ void _interpret_main_menu(char *cmd) g_conns[g_conn_index].menu_state = CURRENT_STATUS_MEDIA_PACKET_SOURCE_UNSET_BUFFER_STATE_CHANGED_CB; } else if (strncmp(cmd, "co", 2) == 0) { - _webrtc_create_offer(&g_conns[g_conn_index]); + _webrtc_create_offer(&g_conns[g_conn_index], false); } else if (strncmp(cmd, "ca", 2) == 0) { - _webrtc_create_answer(&g_conns[g_conn_index]); + _webrtc_create_answer(&g_conns[g_conn_index], false); } else if (strncmp(cmd, "sl", 2) == 0) { g_conns[g_conn_index].menu_state = CURRENT_STATUS_SET_LOCAL_DESCRIPTION; @@ -3668,6 +3698,12 @@ void _interpret_main_menu(char *cmd) } else if (strncmp(cmd, "gan", 3) == 0) { _webrtc_get_all_negotiation_states(g_conn_index); + } else if (strncmp(cmd, "coa", 3) == 0) { + _webrtc_create_offer(&g_conns[g_conn_index], true); + + } else if (strncmp(cmd, "caa", 3) == 0) { + _webrtc_create_answer(&g_conns[g_conn_index], true); + } else if (strncmp(cmd, "stp", 3) == 0) { g_conns[g_conn_index].menu_state = CURRENT_STATUS_SET_ICE_TRANSPORT_POLICY; @@ -3821,6 +3857,8 @@ void display_sub_basic() g_print("gtp. Get ICE transport policy\n"); g_print("co. Create offer\t"); g_print("ca. Create answer\n"); + g_print("coa. Create offer(async)\t"); + g_print("caa. Create answer(async)\n"); g_print("sl. Set local description\t"); g_print("sr. Set remote description\n"); g_print("ac. Add ICE candidate\n");