ms_debug_fleave();
}
-int ms_webrtcbin_set_remote_session_description(media_streamer_node_s *node, const char *sdp_msg)
+int ms_webrtcbin_set_remote_session_description(media_streamer_node_s *webrtc_node, const char *sdp_msg)
{
GstSDPMessage *gst_sdp;
gchar *sdp;
GstElement *webrtcbin;
int ret = MEDIA_STREAMER_ERROR_NONE;
- ms_retvm_if(node == NULL || node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Error: empty webrtcbin");
+ ms_retvm_if(webrtc_node == NULL || webrtc_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Error: empty webrtcbin");
ms_retvm_if(sdp_msg == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sdp_msg is NULL");
ms_debug_fenter();
node_klass_type = ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_WEBRTC);
- if (!(webrtcbin = ms_find_element_in_bin_by_type(node->gst_element, node_klass_type))) {
+ if (!(webrtcbin = ms_find_element_in_bin_by_type(webrtc_node->gst_element, node_klass_type))) {
ms_error("Could not find webrtcbin by type[%s, %s]", node_klass_type->klass_name, node_klass_type->default_name);
return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
}
__ms_webrtcbin_set_session_description(webrtcbin, offer, TRUE);
gst_webrtc_session_description_free(offer);
- ms_webrtcbin_on_negotiation_process_answer(webrtcbin, node);
+ ms_webrtcbin_on_negotiation_process_answer(webrtcbin, webrtc_node);
} else {
ms_error("type is %s, it is not a answer or offer", type);
}
return ret;
}
-int ms_webrtcbin_add_ice_candidate(media_streamer_node_s *node, const char *ice_msg)
+int ms_webrtcbin_add_ice_candidate(media_streamer_node_s *webrtc_node, const char *ice_msg)
{
gchar *candidate;
gint sdpmlineindex;
GstElement *webrtcbin;
int ret;
- ms_retvm_if(node == NULL || node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Error: empty webrtcbin");
+ ms_retvm_if(webrtc_node == NULL || webrtc_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Error: empty webrtcbin");
ms_retvm_if(ice_msg == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ice_msg is NULL");
ms_debug_fenter();
node_klass_type = ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_WEBRTC);
- if (!(webrtcbin = ms_find_element_in_bin_by_type(node->gst_element, node_klass_type))) {
+ if (!(webrtcbin = ms_find_element_in_bin_by_type(webrtc_node->gst_element, node_klass_type))) {
ms_error("Could not find webrtcbin by type[%s, %s]", node_klass_type->klass_name, node_klass_type->default_name);
return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
}
return MEDIA_STREAMER_ERROR_NONE;
}
+int ms_webrtcbin_set_stun_server(media_streamer_node_s *webrtc_node, const char *stun_server_url)
+{
+ node_info_s *node_klass_type;
+ GstElement *webrtcbin;
+ GValue *val;
+ const gchar *stun_server = NULL;
+
+ ms_retvm_if(webrtc_node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL");
+ ms_retvm_if(webrtc_node->gst_element == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "webrtc_container is NULL");
+ ms_retvm_if(stun_server_url == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "stun_server_url is NULL");
+
+ node_klass_type = ms_node_get_klass_by_its_type(MEDIA_STREAMER_NODE_TYPE_WEBRTC);
+ if (!(webrtcbin = ms_find_element_in_bin_by_type(webrtc_node->gst_element, node_klass_type))) {
+ ms_error("Could not find webrtcbin by type[%s, %s]", node_klass_type->klass_name, node_klass_type->default_name);
+ return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+ }
+
+ val = (GValue *)g_object_get_data(G_OBJECT(webrtc_node->gst_element), MEDIA_STREAMER_PARAM_WEBRTC_STUN_SERVER);
+ if (!val) {
+ ms_error("Failed to get [%s] val from [%s]", MEDIA_STREAMER_PARAM_WEBRTC_STUN_SERVER, GST_ELEMENT_NAME(webrtc_node->gst_element));
+ return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+ }
+
+ if (!(stun_server = g_value_get_string(val))) {
+ ms_error("Failed to g_value_get_string()");
+ return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+ }
+
+ g_object_set(G_OBJECT(webrtcbin), "stun-server", stun_server, NULL);
+
+ ms_info("STUN server: %s", stun_server);
+
+ return MEDIA_STREAMER_ERROR_NONE;
+}
+
void ms_webrtcbin_on_negotiation_process_answer(GstElement *webrtcbin, media_streamer_node_s *webrtc_node)
{
GstPromise *promise;
ms_add_no_target_ghostpad(webrtc_container, MS_RTP_PAD_VIDEO_IN, GST_PAD_SINK);
MS_SET_INT_STATIC_STRING_PARAM(webrtc_container, MEDIA_STREAMER_PARAM_WEBRTC_PEER_TYPE, DEFAULT_WEBRTC_PEER);
+ MS_SET_INT_STATIC_STRING_PARAM(webrtc_container, MEDIA_STREAMER_PARAM_WEBRTC_STUN_SERVER, DEFAULT_WEBRTC_STUN_SERVER);
MS_SET_INT_STATIC_STRING_PARAM(webrtc_container, MEDIA_STREAMER_PARAM_WEBRTC_REMOTE_SESSION_DESCRIPTION, NULL);
MS_SET_INT_STATIC_STRING_PARAM(webrtc_container, MEDIA_STREAMER_PARAM_WEBRTC_ADD_ICE_CANDIDATE, NULL);
return NULL;
}
- /* FIXME: these should be set from user */
+ g_object_set(G_OBJECT(webrtcbin), "stun-server", DEFAULT_WEBRTC_STUN_SERVER, NULL);
+
+ /* FIXME: should it be set by user? */
g_object_set(G_OBJECT(webrtcbin), "bundle-policy", 3, NULL); // 3:max-bundle
- g_object_set(G_OBJECT(webrtcbin), "stun-server", "stun://stun.l.google.com:19302", NULL);
ms_bin_add_element(webrtc_container, webrtcbin, FALSE);
{MEDIA_STREAMER_PARAM_AUDIO_OUT_PORT, "audio_out_port"},
{MEDIA_STREAMER_PARAM_IP_ADDRESS, "address"},
{MEDIA_STREAMER_PARAM_WEBRTC_PEER_TYPE, "webrtc-peer-type"},
+ {MEDIA_STREAMER_PARAM_WEBRTC_STUN_SERVER, "webrtc-stun-server"},
{MEDIA_STREAMER_PARAM_WEBRTC_REMOTE_SESSION_DESCRIPTION, "webrtc-remote-session-description"},
{MEDIA_STREAMER_PARAM_WEBRTC_ADD_ICE_CANDIDATE, "webrtc-add-ice-candidate"},
{MEDIA_STREAMER_PARAM_AUDIO_DEVICE, "audio_device"},
g_value_unset(val);
g_value_init(val, G_TYPE_STRING);
g_value_set_string(val, param_value);
+
+ } else if (!strcmp(param->param_name, MEDIA_STREAMER_PARAM_WEBRTC_STUN_SERVER)) {
+ ret = ms_webrtcbin_set_stun_server(node, param_value);
+ if (ret != MEDIA_STREAMER_ERROR_NONE) {
+ ms_error("failed to set STUN server: %s", param_value);
+ return ret;
+ }
+ g_value_unset(val);
+ g_value_init(val, G_TYPE_STRING);
+ g_value_set_string(val, param_value);
+
} else if (!strcmp(param->param_name, MEDIA_STREAMER_PARAM_WEBRTC_REMOTE_SESSION_DESCRIPTION)) {
ret = ms_webrtcbin_set_remote_session_description(node, param_value);
if (ret != MEDIA_STREAMER_ERROR_NONE) {
- ms_error("failed to set remote session description\n%s", param_value);
+ ms_error("failed to set remote session description:\n%s", param_value);
return ret;
}
g_value_unset(val);
g_value_init(val, G_TYPE_STRING);
g_value_set_string(val, param_value);
+
} else if (!strcmp(param->param_name, MEDIA_STREAMER_PARAM_WEBRTC_ADD_ICE_CANDIDATE)) {
ret = ms_webrtcbin_add_ice_candidate(node, param_value);
if (ret != MEDIA_STREAMER_ERROR_NONE) {
- ms_error("failed to add ICE candidate\n%s", param_value);
+ ms_error("failed to add ICE candidate: %s", param_value);
return ret;
}
+
} else {
ms_error("failed to set property, undefined param name[%s]", param->param_name);
return MEDIA_STREAMER_ERROR_INVALID_PARAMETER;