webrtc_test: Add 'quick start' test case 99/319599/1 accepted/tizen/unified/20241031.084333
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 09:21:12 +0000 (18:21 +0900)
qs. Quick start - 2 peers (AV sender - AV receiver)

[Version] 1.1.40
[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 2171033092485ac4771cffb98d4732f3789e5fbd..5c2cb735893aebe348b54350397829aad6114f97 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    1.1.39
+Version:    1.1.40
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index fdb7c0317c0f9f2448e6cfa910bf54c9c1d43b68..8eb26adef3876a67648782bf4733da2609ed14d8 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
@@ -1257,6 +1261,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)
@@ -1265,6 +1275,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)
@@ -1356,7 +1372,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);
 
@@ -1866,6 +1882,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);
        }
 }
 
@@ -1881,6 +1900,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);
@@ -1908,6 +1932,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);
        }
 }
 
@@ -4143,6 +4169,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)
@@ -4171,6 +4232,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 97574d7573fdc5da3b3d1c5da36304a2f8f630ff..16b2d17fc88a9dfa44c4bf608a852547fbdc2a87 100644 (file)
@@ -129,6 +129,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 },
 };
 
@@ -308,6 +310,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 80775e0d8c939569b7ade6abae01c526142a2c21..00e6a750591e2bf81861b44c74a2868d290cbc15 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,
@@ -168,6 +169,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 {
@@ -266,6 +269,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 {