webrtc_test: Add 'quick start' test case 17/319617/1 accepted/tizen/8.0/unified/20241030.154748
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 28 Oct 2024 09:18:56 +0000 (18:18 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 28 Oct 2024 23:44:14 +0000 (08:44 +0900)
qs. Quick start - 2 peers (AV sender - AV receiver)

[Version] 0.4.72
[Issue Type] Test application

Change-Id: Ic83d16b3aa36b102e4bda8cb8701e3bc1d12618f
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
test/webrtc_test.c
test/webrtc_test_menu.c
test/webrtc_test_priv.h

index 46b3653a6ba2fa63414c8fed0d3153768347e1b1..e9e3d3f1cb7c22a4a07290ea35eeebc245caa569 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.4.71
+Version:    0.4.72
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 8cfc334847997e451347eb5ad882ced08d5241ea..4da5dea10eb16b0bb47eecba317ecef7b095c8c9 100644 (file)
@@ -79,6 +79,7 @@ static const char *g_webrtc_stats_type_str[] = {
 
 static appdata_s g_ad;
 
+static void _webrtc_set_local_description(connection_s *conn, bool is_offer);
 static void _stop_pushing_packet(int index, int source_id);
 static void __file_dump(const gchar *file_name, void *src_buffer, int size);
 
@@ -243,6 +244,9 @@ void _webrtc_destroy(int index)
        g_ad.conns[index].encoded_audio_frame_cb_is_set = false;
        g_ad.conns[index].encoded_video_frame_cb_is_set = false;
 
+       g_ad.conns[index].quick_start = false;
+       g_ad.conns[index].remote_conn = NULL;
+
 #ifdef TIZEN_FEATURE_ESPP
        _espp_deinit(index);
 #endif
@@ -1235,6 +1239,12 @@ static void __offer_created_cb(webrtc_h webrtc, const char *description, void *u
        g_print("__offer_created_cb() is called, description[%s], user_data[%p]\n", description, user_data);
 
        conn->offer = strdup(description);
+
+       if (conn->quick_start && conn->remote_conn) {
+               _webrtc_set_local_description(conn, true);
+               conn->remote_conn->remote_desc = strdup(description);
+               _webrtc_set_remote_description(conn->remote_conn);
+       }
 }
 
 static void __answer_created_cb(webrtc_h webrtc, const char *description, void *user_data)
@@ -1243,6 +1253,12 @@ static void __answer_created_cb(webrtc_h webrtc, const char *description, void *
        g_print("__answer_created_cb() is called, description[%s], user_data[%p]\n", description, user_data);
 
        conn->answer = strdup(description);
+
+       if (conn->quick_start && conn->remote_conn) {
+               _webrtc_set_local_description(conn, false);
+               conn->remote_conn->remote_desc = strdup(description);
+               _webrtc_set_remote_description(conn->remote_conn);
+       }
 }
 
 static void _webrtc_create_offer(connection_s *conn, bool async)
@@ -1334,7 +1350,7 @@ void _webrtc_add_ice_candidate(connection_s *conn, const gchar *candidate)
 {
        RET_IF(!conn, "conn is NULL");
 
-       if (conn->is_for_room && candidate) {
+       if ((conn->is_for_room || conn->quick_start) && candidate) {
                int ret = webrtc_add_ice_candidate(conn->webrtc, (const char *)candidate);
                RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
 
@@ -1849,6 +1865,9 @@ static void __state_changed_cb(webrtc_h webrtc, webrtc_state_e previous, webrtc_
                        if (conn->ice_candidates)
                                _webrtc_add_ice_candidate(conn, NULL);
                }
+       } else if (conn->quick_start && current == WEBRTC_STATE_NEGOTIATING) {
+               if (conn->is_offer)
+                       _webrtc_create_offer(conn, true);
        }
 }
 
@@ -1864,6 +1883,11 @@ static void __ice_candidate_cb(webrtc_h webrtc, const char *candidate, void *use
        g_print("__ice_candidate_cb() is invoked, conn[%p]\n", conn);
        RET_IF(!conn, "conn is NULL");
 
+       if (conn->quick_start) {
+               _webrtc_add_ice_candidate(conn->remote_conn, candidate);
+               return;
+       }
+
        g_print("\n[to SERVER > ICE]\n%s\n", candidate);
 
        _send_ice_candidate(conn, candidate);
@@ -1891,6 +1915,8 @@ static void __signaling_state_change_cb(webrtc_h webrtc, webrtc_signaling_state_
                _webrtc_create_answer(conn, false);
                _webrtc_set_local_description(conn, false);
                _websocket_send_text_for_room(conn, conn->remote_peer_id, conn->answer);
+       } else if (conn->quick_start && state == WEBRTC_SIGNALING_STATE_HAVE_REMOTE_OFFER) {
+               _webrtc_create_answer(conn, true);
        }
 }
 
@@ -4081,6 +4107,41 @@ static void app_setting_and_signaling(char *cmd)
        reset_menu_state();
 }
 
+static void app_quick_start(char *cmd)
+{
+       switch (g_ad.menu_status) {
+       case CURRENT_STATUS_APP_QUICK_START_ONE_ON_ONE: {
+               unsigned int a_nullsrc_id;
+               unsigned int v_nullsrc_id;
+
+               /* sender */
+               g_ad.conns[0].quick_start = true;
+               g_ad.conns[0].is_offer = true;
+               g_ad.conns[0].remote_conn = &g_ad.conns[1];
+               _webrtc_create(0);
+               _webrtc_set_all_cbs(0);
+               _webrtc_add_media_source(0, WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST, NULL);
+               _webrtc_add_media_source(0, WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST, NULL);
+               _webrtc_start(0);
+
+               /* receiver */
+               g_ad.conns[1].quick_start = true;
+               g_ad.conns[1].remote_conn = &g_ad.conns[0];
+               _webrtc_create(1);
+               _webrtc_set_all_cbs(1);
+               _webrtc_add_media_source(1, WEBRTC_MEDIA_SOURCE_TYPE_NULL, &a_nullsrc_id);
+               _webrtc_add_media_source(1, WEBRTC_MEDIA_SOURCE_TYPE_NULL, &v_nullsrc_id);
+               _webrtc_media_source_set_transceiver_codec(1, a_nullsrc_id, WEBRTC_MEDIA_TYPE_AUDIO, 3); /* 3 for OPUS */
+               _webrtc_media_source_set_transceiver_codec(1, v_nullsrc_id, WEBRTC_MEDIA_TYPE_VIDEO, 4); /* 4 for VP8 */
+               _webrtc_start(1);
+
+               break;
+       }
+       }
+
+       reset_menu_state();
+}
+
 static void interpret(char *cmd)
 {
        if (!cmd)
@@ -4109,6 +4170,9 @@ static void interpret(char *cmd)
        else if (g_ad.menu_status & TEST_MENU_APP_SIGNALING)
                app_setting_and_signaling(cmd);
 
+       else if (g_ad.menu_status & TEST_MENU_APP_QUICK_START)
+               app_quick_start(cmd);
+
        else if (g_ad.menu_status == CURRENT_STATUS_QUIT)
                quit_program();
 
index f83e35cd245965bc4b1ae0fb31f5839e639654b6..e8114ea4ae9f2da2b389a3f6f1b4aa396726367b 100644 (file)
@@ -127,6 +127,8 @@ menu_info_s g_menu_infos[] = {
        { "sst", CURRENT_STATUS_PRIVATE_SIGNALING_SERVER_STOP, false },
        { "scc", CURRENT_STATUS_PRIVATE_SIGNALING_SERVER_CONNECT, true },
        { "scd", CURRENT_STATUS_PRIVATE_SIGNALING_SERVER_DISCONNECT, false },
+       /* quick start */
+       { "qs", CURRENT_STATUS_APP_QUICK_START_ONE_ON_ONE, false },
        { NULL, -1, false },
 };
 
@@ -304,6 +306,8 @@ void display_menu_main(void)
        g_print("sst. *Stop signaling server\n");
        g_print("scc. *Connect to signaling server\t");
        g_print("scd. *Disconnect from signaling server\n");
+       g_print("---------------------------------- App. quick start -------------------------------------\n");
+       g_print("qs. Quick start - 2 peers (AV sender - AV receiver)\n");
        g_print("-----------------------------------------------------------------------------------------\n");
        g_print("=========================================================================================\n");
        g_print(" >>> ");
index 2073eb2ceccf2365495572015fd6a64af6ce210d..126ccb2df4ae66addd5fdb5355006ccf74a414b1 100644 (file)
@@ -54,6 +54,7 @@ do { \
 #define TEST_MENU_WEBRTC_DATA_CHANNEL   0x00008000
 #define TEST_MENU_WEBRTC_STATS          0x00010000
 #define TEST_MENU_APP_SIGNALING         0x00020000
+#define TEST_MENU_APP_QUICK_START       0x00040000
 
 enum {
        CURRENT_STATUS_MAINMENU,
@@ -166,6 +167,8 @@ enum {
        CURRENT_STATUS_PRIVATE_SIGNALING_SERVER_STOP = TEST_MENU_APP_SIGNALING | 0x09,
        CURRENT_STATUS_PRIVATE_SIGNALING_SERVER_CONNECT = TEST_MENU_APP_SIGNALING | 0x0A,
        CURRENT_STATUS_PRIVATE_SIGNALING_SERVER_DISCONNECT = TEST_MENU_APP_SIGNALING | 0x0B,
+       /* quick start */
+       CURRENT_STATUS_APP_QUICK_START_ONE_ON_ONE = TEST_MENU_APP_QUICK_START | 0x01,
 };
 
 enum {
@@ -264,6 +267,9 @@ typedef struct _connection_s {
        GstElement *video_render_pipeline;
        GstElement *appsrc_for_audio;
        GstElement *appsrc_for_video;
+
+       bool quick_start;
+       struct _connection_s* remote_conn;
 } connection_s;
 
 typedef struct {