#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,
/* 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;
} media_packet_source_s;
typedef struct _connection_s {
+ int index;
SoupWebsocketConnection *ws_conn;
gint32 local_peer_id;
int remote_peer_id;
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
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;
}
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;
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) {
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);
}
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;
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)
{
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)
else
conn->receive_buffer = (char *)calloc(conn->expected_size, sizeof(char));
}
+ } else {
+ __render_text_message_in_idle(conn, message);
}
if (str_arr)
for (i = 0; i < size; i++)
g_print("%c", data_p[i]);
g_print("\n");
+ __render_text_message_in_idle(conn, data_p);
}
}
}