#define TEST_DATA_CHANNEL_LABEL "test data channel"
#define TEST_STRING_DATA "test string"
#define TEST_BUFFER_SIZE 16
+char g_test_buffer[TEST_BUFFER_SIZE] = {'t', 'e', 's', 't', 'b', 'u', 'f', '\0', };
+
#include "ITs-webrtc-common.h"
#include <Elementary.h>
static Evas_Object *g_win = NULL;
callback_data *cb_data = (callback_data *)user_data;
FPRINTF("[Line : %d][%s] Callback webrtcStateChangedCB called\\n", __LINE__, API_NAMESPACE);
+ dlog_print(DLOG_DEBUG, "NativeTCT", "[%s(%d)] webrtc[%p], state[%d -> %d]", __FUNCTION__, __LINE__, webrtc, previous, current);
if (!cb_data)
return;
callback_data *cb_data = (callback_data *)user_data;
FPRINTF("[Line : %d][%s] Callback webrtcTrackAddedCB called\\n", __LINE__, API_NAMESPACE);
+ dlog_print(DLOG_DEBUG, "NativeTCT", "[%s(%d)] webrtc[%p], track_id[%u]", __FUNCTION__, __LINE__, webrtc, track_id);
if (!cb_data)
return;
callback_data *cb_data = (callback_data *)user_data;
FPRINTF("[Line : %d][%s] Callback webrtcSignalingStateChangeCB called\\n", __LINE__, API_NAMESPACE);
+ dlog_print(DLOG_DEBUG, "NativeTCT", "[%s(%d)] webrtc[%p], state[%d]", __FUNCTION__, __LINE__, webrtc, state);
if (!cb_data || state != WEBRTC_SIGNALING_STATE_HAVE_REMOTE_OFFER)
return;
QUIT_LOOP(cb_data->mainloop);
}
+/**
+* @function webrtcDataChannelOpenCB
+* @parameter webrtc_data_channel_h channel, void *user_data
+* @return NA
+*/
+static void webrtcDataChannelOpenCB(webrtc_data_channel_h channel, void *user_data)
+{
+ callback_data *cb_data = (callback_data *)user_data;
+
+ FPRINTF("[Line : %d][%s] Callback webrtcDataChannelOpenCB called\\n", __LINE__, API_NAMESPACE);
+ dlog_print(DLOG_DEBUG, "NativeTCT", "[%s(%d)] channel[%p]", __FUNCTION__, __LINE__, channel);
+
+ if (!cb_data)
+ return;
+ cb_data->is_invoked = true;
+ QUIT_LOOP(cb_data->mainloop);
+}
+
+/**
+* @function webrtcDataChannelMessageCB
+* @parameter webrtc_data_channel_h channel, webrtc_data_channel_type_e type, void *message, void *user_data
+* @return NA
+*/
+static void webrtcDataChannelMessageCB(webrtc_data_channel_h channel, webrtc_data_channel_type_e type, void *message, void *user_data)
+{
+ callback_data *cb_data = (callback_data *)user_data;
+
+ FPRINTF("[Line : %d][%s] Callback webrtcDataChannelMessageCB called\\n", __LINE__, API_NAMESPACE);
+ dlog_print(DLOG_DEBUG, "NativeTCT", "[%s(%d)] channel[%p], type[%d], message[%p]", __FUNCTION__, __LINE__, channel, type, message);
+
+ if (!cb_data || !message)
+ return;
+
+ if (type == WEBRTC_DATA_CHANNEL_TYPE_STRING) {
+ dlog_print(DLOG_DEBUG, "NativeTCT", "[%s(%d)] channel[%p], received string message[%s]", __FUNCTION__, __LINE__, channel, (const char *)message);
+ if (!strcmp(TEST_STRING_DATA, message)) {
+ cb_data->is_invoked = true;
+ QUIT_LOOP(cb_data->mainloop);
+ }
+ } else if (type == WEBRTC_DATA_CHANNEL_TYPE_BYTES) {
+ webrtc_bytes_data_h *data = message;
+ const char *data_p;
+ unsigned long size;
+ int nRet = webrtc_get_data(data, &data_p, &size);
+ PRINT_RESULT_NORETURN(WEBRTC_ERROR_NONE, nRet, "webrtc_get_data", WebRtcGetError(nRet));
+
+ dlog_print(DLOG_DEBUG, "NativeTCT", "[%s(%d)] channel[%p], received bytes message[%s] size[%lu]", __FUNCTION__, __LINE__, channel, data_p, size);
+ if (!memcmp(g_test_buffer, data_p, TEST_BUFFER_SIZE)) {
+ cb_data->is_invoked = true;
+ QUIT_LOOP(cb_data->mainloop);
+ }
+ }
+}
+
+/**
+* @function webrtcDataChannelCB
+* @parameter webrtc_h webrtc, webrtc_data_channel_h channel, void *user_data
+* @return NA
+*/
+static void webrtcDataChannelCB(webrtc_h webrtc, webrtc_data_channel_h channel, void *user_data)
+{
+ int nRet;
+
+ FPRINTF("[Line : %d][%s] Callback webrtcDataChannelCB called\\n", __LINE__, API_NAMESPACE);
+ dlog_print(DLOG_DEBUG, "NativeTCT", "[%s(%d)] webrtc[%p], channel[%p]", __FUNCTION__, __LINE__, webrtc, channel);
+
+ nRet = webrtc_data_channel_set_open_cb(channel, webrtcDataChannelOpenCB, user_data);
+ PRINT_RESULT_NORETURN(WEBRTC_ERROR_NONE, nRet, "webrtc_data_channel_set_open_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_data_channel_set_message_cb(channel, webrtcDataChannelMessageCB, user_data);
+ PRINT_RESULT_NORETURN(WEBRTC_ERROR_NONE, nRet, "webrtc_data_channel_set_message_cb", WebRtcGetError(nRet));
+}
+
/**
* @function webrtcTurnServerCB
* @parameter const char *turn_server, void *user_data
return 0;
}
-
//& purpose: Gets the buffered amount of the data channel.
//& type: auto
/**
return 0;
}
+
+//& purpose: Sends and receives data via data channel between two handles.
+//& type: auto
+/**
+* @testcase ITc_media_webrtc_data_channel_send_and_receive_p
+* @since_tizen 7.0
+* @author SR(sc11.lee)
+* @reviewer SR(seungbae.shin)
+* @type auto
+* @description Sends and receives data via data channel between two handles.
+* @scenario Sends and receives data via data channel between two handles.
+* @apicovered webrtc_start,webrtc_create_offer,webrtc_create_answer,webrtc_data_channel_send_string,webrtc_data_channel_send_bytes
+* @passcase If webrtc_start,webrtc_create_offer,webrtc_create_answer,webrtc_data_channel_send_string,webrtc_data_channel_send_bytes is successful
+* @failcase If webrtc_start,webrtc_create_offer,webrtc_create_answer,webrtc_data_channel_send_string,webrtc_data_channel_send_bytes fails
+* @precondition NA
+* @postcondition NA
+*/
+int ITc_media_webrtc_data_channel_send_and_receive_p(void)
+{
+ webrtc_h webrtcOfferer;
+ webrtc_h webrtcAnswerer;
+ webrtc_data_channel_h datachannelOfferer;
+ int nRet;
+ char *offerSDP;
+ char *answerSDP;
+ GList *offerICECandidates = NULL;
+ GList *answerICECandidates = NULL;
+ callback_data cb_data = { .mainloop = NULL, .is_invoked = false };
+ callback_data cb_data2 = { .mainloop = NULL, .is_invoked = false };
+
+ START_TEST;
+
+ /* initialize and start offerer */
+ nRet = webrtc_create(&webrtcOfferer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_create", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_ice_candidate_cb(webrtcOfferer, webrtcIceCandidateCB, &offerICECandidates);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_ice_candidate_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_state_changed_cb(webrtcOfferer, webrtcStateChangedCB, &cb_data);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_state_changed_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_signaling_state_change_cb(webrtcOfferer, webrtcSignalingStateChangeCB, NULL);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_signaling_state_change_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_ice_gathering_state_change_cb(webrtcOfferer, webrtcIceGatheringStateChangeCB, &cb_data);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_ice_gathering_state_change_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_create_data_channel(webrtcOfferer, TEST_DATA_CHANNEL_LABEL, NULL, &datachannelOfferer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_create_data_channel", WebRtcGetError(nRet));
+
+ nRet = webrtc_start(webrtcOfferer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_start", WebRtcGetError(nRet));
+
+ RUN_POLLING_LOOP(cb_data.mainloop, cb_data.is_invoked);
+ if (!cb_data.is_invoked) {
+ FPRINTF("[Line : %d][%s] Callback webrtcStateChangedCB not invoked\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ cb_data.is_invoked = false;
+
+ /* initialize and start answerer */
+ nRet = webrtc_create(&webrtcAnswerer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_create", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_ice_candidate_cb(webrtcAnswerer, webrtcIceCandidateCB, &answerICECandidates);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_ice_candidate_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_state_changed_cb(webrtcAnswerer, webrtcStateChangedCB, &cb_data);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_state_changed_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_signaling_state_change_cb(webrtcAnswerer, webrtcSignalingStateChangeCB, &cb_data);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_signaling_state_change_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_ice_gathering_state_change_cb(webrtcAnswerer, webrtcIceGatheringStateChangeCB, &cb_data);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_ice_gathering_state_change_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_data_channel_cb(webrtcAnswerer, webrtcDataChannelCB, &cb_data2);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_data_channel_cb", WebRtcGetError(nRet));
+
+ nRet = webrtc_start(webrtcAnswerer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_start", WebRtcGetError(nRet));
+ RUN_POLLING_LOOP(cb_data.mainloop, cb_data.is_invoked);
+ if (!cb_data.is_invoked) {
+ FPRINTF("[Line : %d][%s] Callback webrtcStateChangedCB not invoked\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ cb_data.is_invoked = false;
+
+ /* do negotiate */
+ nRet = webrtc_create_offer(webrtcOfferer, NULL, &offerSDP);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_create_offer", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_local_description(webrtcOfferer, offerSDP);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_local_description", WebRtcGetError(nRet));
+
+ RUN_POLLING_LOOP(cb_data.mainloop, cb_data.is_invoked);
+ if (!cb_data.is_invoked) {
+ FPRINTF("[Line : %d][%s] Callback webrtcIceGatheringStateChangeCB not invoked\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ cb_data.is_invoked = false;
+
+ nRet = webrtc_set_remote_description(webrtcAnswerer, offerSDP);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_remote_description", WebRtcGetError(nRet));
+ FREE_MEMORY(offerSDP);
+
+ RUN_POLLING_LOOP(cb_data.mainloop, cb_data.is_invoked);
+ if (!cb_data.is_invoked) {
+ FPRINTF("[Line : %d][%s] Callback webrtcSignalingStateChangeCB not invoked\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ cb_data.is_invoked = false;
+
+ nRet = webrtc_create_answer(webrtcAnswerer, NULL, &answerSDP);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_create_answer", WebRtcGetError(nRet));
+
+ nRet = webrtc_set_local_description(webrtcAnswerer, answerSDP);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_local_description", WebRtcGetError(nRet));
+
+ RUN_POLLING_LOOP(cb_data.mainloop, cb_data.is_invoked);
+ if (!cb_data.is_invoked) {
+ FPRINTF("[Line : %d][%s] Callback webrtcIceGatheringStateChangeCB not invoked\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+
+ g_list_foreach(offerICECandidates, __foreach_ice_candidate, webrtcAnswerer);
+ g_list_foreach(answerICECandidates, __foreach_ice_candidate, webrtcOfferer);
+
+ nRet = webrtc_set_remote_description(webrtcOfferer, answerSDP);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_set_remote_description", WebRtcGetError(nRet));
+ FREE_MEMORY(answerSDP);
+
+ /* wait for channel open of answerer */
+ RUN_POLLING_LOOP(cb_data2.mainloop, cb_data2.is_invoked);
+ if (!cb_data2.is_invoked) {
+ FPRINTF("[Line : %d][%s] Callback webrtcDataChannelOpenCB not invoked\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ cb_data2.is_invoked = false;
+
+ /* send data to answerer */
+ nRet = webrtc_data_channel_send_string(datachannelOfferer, TEST_STRING_DATA);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_data_channel_send_string", WebRtcGetError(nRet));
+
+ RUN_POLLING_LOOP(cb_data2.mainloop, cb_data2.is_invoked);
+ if (!cb_data2.is_invoked) {
+ FPRINTF("[Line : %d][%s] Callback webrtcDataChannelMessageCB not invoked\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ cb_data2.is_invoked = false;
+
+ nRet = webrtc_data_channel_send_bytes(datachannelOfferer, g_test_buffer, TEST_BUFFER_SIZE);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_data_channel_send_bytes", WebRtcGetError(nRet));
+
+ RUN_POLLING_LOOP(cb_data2.mainloop, cb_data2.is_invoked);
+ if (!cb_data2.is_invoked) {
+ FPRINTF("[Line : %d][%s] Callback webrtcDataChannelMessageCB not invoked\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+
+ /* Stop and de-initialize the both handles */
+ nRet = webrtc_stop(webrtcOfferer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_stop", WebRtcGetError(nRet));
+
+ nRet = webrtc_destroy_data_channel(datachannelOfferer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_destroy_data_channel", WebRtcGetError(nRet));
+
+ nRet = webrtc_destroy(webrtcOfferer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_destroy", WebRtcGetError(nRet));
+
+ nRet = webrtc_stop(webrtcAnswerer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_stop", WebRtcGetError(nRet));
+
+ nRet = webrtc_destroy(webrtcAnswerer);
+ PRINT_RESULT(WEBRTC_ERROR_NONE, nRet, "webrtc_destroy", WebRtcGetError(nRet));
+
+ g_list_free_full(offerICECandidates, free);
+ g_list_free_full(answerICECandidates, free);
+
+ return 0;
+}
/** @} */
/** @} */