From: Sangchul Lee Date: Thu, 21 Oct 2021 01:06:48 +0000 (+0900) Subject: webrtc_test: Show text message from data channel to the display X-Git-Tag: submit/tizen/20211028.055213~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F10%2F265510%2F4;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_test: Show text message from data channel to the display [Version] 0.2.138 [Issue Type] Improvement Change-Id: I217484ed9bf9d74a1519dee8726afaf8f9b5c4d4 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 75a38075..5e4e1896 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.137 +Version: 0.2.138 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/test/webrtc_test.c b/test/webrtc_test.c index 415d6142..c8bd92ee 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -58,8 +58,8 @@ do { \ #define MAX_CONNECTION_LEN 3 #define MAX_MEDIA_PACKET_SOURCE_LEN 4 #define MAX_EXPECTED_SIZE 1024 * 1024 * 1024 - #define USE_GSTBUFFER_WITHOUT_COPY true +#define FONT_SIZE 30 enum { CURRENT_STATUS_MAINMENU, @@ -144,6 +144,7 @@ static const char* g_webrtc_transceiver_direction_str[] = { /* for video display */ static Evas_Object *g_win_id; static Evas_Object *g_eo_mine; +static Evas_Object *g_text_eo_mine; typedef struct { Evas_Object *win; @@ -176,6 +177,7 @@ typedef struct { } media_packet_source_s; typedef struct _connection_s { + int index; SoupWebsocketConnection *ws_conn; gint32 local_peer_id; int remote_peer_id; @@ -215,6 +217,8 @@ typedef struct _connection_s { sound_stream_info_h stream_info; webrtc_display_type_e display_type; Evas_Object *eo; + Evas_Object *text_eo; + unsigned int loopback_track_id; #ifndef TIZEN_TV esplusplayer_handle espp; #endif @@ -287,7 +291,23 @@ static Evas_Object *create_image_object(Evas_Object *eo_parent) evas = evas_object_evas_get(eo_parent); eo = evas_object_image_add(evas); - g_print("eo[%p]\n", eo); + g_print("image eo[%p]\n", eo); + + return eo; +} + +static Evas_Object *create_text_object(Evas_Object *eo_parent) +{ + Evas_Object *eo = NULL; + Evas *evas; + + if (!eo_parent) + return NULL; + + evas = evas_object_evas_get(eo_parent); + eo = evas_object_text_add(evas); + + g_print("text eo[%p]\n", eo); return eo; } @@ -356,6 +376,56 @@ static int app_create(void *data) return 0; } +static void __render_text_message(Evas_Object **eo, int i, const char *text) +{ + if (*eo) { + evas_object_hide(*eo); + evas_object_del(*eo); + } + + *eo = create_text_object(g_ad.win); + if (!*eo) { + g_print("failed to create evas text object\n"); + return; + } + evas_object_text_style_set(*eo, EVAS_TEXT_STYLE_PLAIN); + evas_object_text_font_set(*eo, "Courier", FONT_SIZE); + evas_object_text_text_set(*eo, text); + evas_object_color_set(*eo, 255, 255, 255, 255); + evas_object_resize(*eo, g_ad.win_width / 2, FONT_SIZE * 2); + evas_object_move(*eo, (i % 2) * (g_ad.win_width / 2), ((i / 2) * (g_ad.win_height / 2)) + ((g_ad.win_height / 2) - (FONT_SIZE * 2))); + evas_object_show(*eo); +} + +typedef struct _idle_userdata { + connection_s *conn; + char *message; +} idle_userdata_s; + +static gboolean __idle_cb(gpointer user_data) +{ + idle_userdata_s *data = (idle_userdata_s*)user_data; + connection_s *conn; + + if (!data) + return G_SOURCE_REMOVE; + + conn = data->conn; + __render_text_message(&conn->render.text_eo, conn->index + 1, data->message); + + free (data->message); + return G_SOURCE_REMOVE; +} + +static void __render_text_message_in_idle(connection_s *conn, const char *text) +{ + idle_userdata_s *data = g_new0(idle_userdata_s, 1); + data->conn = conn; + data->message = strdup(text); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free); +} + static int app_terminate(void *data) { appdata_s *ad = data; @@ -366,6 +436,10 @@ static int app_terminate(void *data) evas_object_del(g_conns[i].render.eo); g_conns[i].render.eo = NULL; } + if (g_conns[i].render.text_eo) { + evas_object_del(g_conns[i].render.text_eo); + g_conns[i].render.text_eo = NULL; + } } if (g_win_id) { @@ -442,6 +516,7 @@ static void _webrtc_create(int index) ret = webrtc_create(&g_conns[index].webrtc); RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret); + g_conns[index].index = index; g_print("webrtc[%p, index:%d] is created\n", g_conns[index].webrtc, index); } @@ -493,6 +568,9 @@ static void _webrtc_destroy(int index) sound_manager_destroy_stream_information(g_conns[index].render.stream_info); g_conns[index].render.stream_info = NULL; } + + g_conns[index].render.loopback_track_id = 0; + #ifndef TIZEN_TV if (g_conns[index].encoded_audio_frame_cb_is_set) g_conns[index].encoded_audio_frame_cb_is_set = false; @@ -981,6 +1059,7 @@ static void _webrtc_media_source_set_video_loopback(int index, unsigned int sour RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret); g_print("webrtc_media_source_set_video_loopback() success, source_id[%u] track_id[%u]\n", source_id, track_id); + g_conns[index].render.loopback_track_id = track_id; } static int __copy_string_arr(gchar *dest_arr, char *string) @@ -1006,34 +1085,48 @@ static void _webrtc_data_channel_send_string(int index, const char *string) { int ret = WEBRTC_ERROR_NONE; int i; + gchar *string_with_peer_id; + string_with_peer_id = g_strdup_printf("[%d] %s", g_conns[index].local_peer_id, string); for (i = 0; i < MAX_CHANNEL_LEN; i++) { if (g_conns[index].channels[i] == NULL) continue; g_print("data_channel[%p], index[%d]: ", g_conns[index].channels[i], i); - ret = webrtc_data_channel_send_string(g_conns[index].channels[i], string); + ret = webrtc_data_channel_send_string(g_conns[index].channels[i], string_with_peer_id); if (ret != WEBRTC_ERROR_NONE) - g_print("failed to webrtc_data_channel_send_string(), string[%s]\n", string); + g_print("failed to webrtc_data_channel_send_string(), string[%s]\n", string_with_peer_id); else - g_print("webrtc_data_channel_send_string() success, string[%s]\n", string); + g_print("webrtc_data_channel_send_string() success, string[%s]\n", string_with_peer_id); } + + if (g_conns[index].render.loopback_track_id > 0) + __render_text_message(&g_text_eo_mine, 0, string_with_peer_id); + + g_free(string_with_peer_id); } static void _webrtc_data_channel_send_string_as_bytes(int index, const char *string) { int ret = WEBRTC_ERROR_NONE; int i; + gchar *string_with_peer_id; + string_with_peer_id = g_strdup_printf("[%d] %s", g_conns[index].local_peer_id, string); for (i = 0; i < MAX_CHANNEL_LEN; i++) { if (g_conns[index].channels[i] == NULL) continue; g_print("data_channel[%p], index[%d]: ", g_conns[index].channels[i], i); - ret = webrtc_data_channel_send_bytes(g_conns[index].channels[i], string, strlen(string)); + ret = webrtc_data_channel_send_bytes(g_conns[index].channels[i], string_with_peer_id, strlen(string_with_peer_id)); if (ret != WEBRTC_ERROR_NONE) - g_print("failed to webrtc_data_channel_send_bytes(), string[%s]\n", string); + g_print("failed to webrtc_data_channel_send_bytes(), string[%s]\n", string_with_peer_id); else - g_print("webrtc_data_channel_send_bytes() success, string[%s]\n", string); + g_print("webrtc_data_channel_send_bytes() success, string[%s]\n", string_with_peer_id); } + + if (g_conns[index].render.loopback_track_id > 0) + __render_text_message(&g_text_eo_mine, 0, string_with_peer_id); + + g_free(string_with_peer_id); } static void _webrtc_data_channel_send_file(int index, const char *file_path) @@ -1435,6 +1528,8 @@ static void __data_channel_message_cb(webrtc_data_channel_h channel, webrtc_data else conn->receive_buffer = (char *)calloc(conn->expected_size, sizeof(char)); } + } else { + __render_text_message_in_idle(conn, message); } if (str_arr) @@ -1477,6 +1572,7 @@ static void __data_channel_message_cb(webrtc_data_channel_h channel, webrtc_data for (i = 0; i < size; i++) g_print("%c", data_p[i]); g_print("\n"); + __render_text_message_in_idle(conn, data_p); } } }