PROP_AGENT,
PROP_ICE_TCP,
PROP_ICE_UDP,
+ PROP_MIN_RTP_PORT,
+ PROP_MAX_RTP_PORT,
};
static guint gst_webrtc_ice_signals[LAST_SIGNAL] = { 0 };
g_object_set_property (G_OBJECT (ice->priv->nice_agent),
"ice-udp", value);
break;
+
+ case PROP_MIN_RTP_PORT:
+ ice->min_rtp_port = g_value_get_uint (value);
+ if (ice->min_rtp_port > ice->max_rtp_port)
+ g_warning ("Set min-rtp-port to %u which is larger than"
+ " max-rtp-port %u", ice->min_rtp_port, ice->max_rtp_port);
+ break;
+
+ case PROP_MAX_RTP_PORT:
+ ice->max_rtp_port = g_value_get_uint (value);
+ if (ice->min_rtp_port > ice->max_rtp_port)
+ g_warning ("Set max-rtp-port to %u which is smaller than"
+ " min-rtp-port %u", ice->max_rtp_port, ice->min_rtp_port);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
g_object_get_property (G_OBJECT (ice->priv->nice_agent),
"ice-udp", value);
break;
+
+ case PROP_MIN_RTP_PORT:
+ g_value_set_uint (value, ice->min_rtp_port);
+ break;
+
+ case PROP_MAX_RTP_PORT:
+ g_value_set_uint (value, ice->max_rtp_port);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
+ * GstWebRTCICE:min-rtp-port:
+ *
+ * Minimum port for local rtp port range.
+ * min-rtp-port must be <= max-rtp-port
+ *
+ * Since: 1.20
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MIN_RTP_PORT,
+ g_param_spec_uint ("min-rtp-port", "ICE RTP candidate min port",
+ "Minimum port for local rtp port range. "
+ "min-rtp-port must be <= max-rtp-port",
+ 0, 65535, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GstWebRTCICE:max-rtp-port:
+ *
+ * Maximum port for local rtp port range.
+ * min-rtp-port must be <= max-rtp-port
+ *
+ * Since: 1.20
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MAX_RTP_PORT,
+ g_param_spec_uint ("max-rtp-port", "ICE RTP candidate max port",
+ "Maximum port for local rtp port range. "
+ "max-rtp-port must be >= min-rtp-port",
+ 0, 65535, 65535,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
+
+ /**
* GstWebRTCICE::add-local-ip-address:
* @object: the #GstWebRTCICE
* @address: The local IP address
{
gboolean gathered;
GList *transports;
+ gboolean gathering_started;
};
#define gst_webrtc_ice_stream_parent_class parent_class
}
g_object_get (stream->ice, "agent", &agent, NULL);
+
+ if (!stream->priv->gathering_started) {
+ if (stream->ice->min_rtp_port != 0 || stream->ice->max_rtp_port != 65535) {
+ if (stream->ice->min_rtp_port > stream->ice->max_rtp_port) {
+ GST_ERROR_OBJECT (stream->ice,
+ "invalid port range: min-rtp-port %d must be <= max-rtp-port %d",
+ stream->ice->min_rtp_port, stream->ice->max_rtp_port);
+ return FALSE;
+ }
+
+ nice_agent_set_port_range (agent, stream->stream_id,
+ NICE_COMPONENT_TYPE_RTP, stream->ice->min_rtp_port,
+ stream->ice->max_rtp_port);
+ }
+ /* mark as gathering started to prevent changing ports again */
+ stream->priv->gathering_started = TRUE;
+ }
+
if (!nice_agent_gather_candidates (agent, stream->stream_id)) {
g_object_unref (agent);
return FALSE;
test_webrtc_wait_for_state_mask (t, states);
}
-#if 0
static void
test_webrtc_wait_for_ice_gathering_complete (struct test_webrtc *t)
{
g_mutex_unlock (&t->lock);
}
+#if 0
static void
test_webrtc_wait_for_ice_connection (struct test_webrtc *t,
GstWebRTCICEConnectionState states)
GST_END_TEST;
+static void
+_check_ice_port_restriction (struct test_webrtc *t, GstElement * element,
+ guint mlineindex, gchar * candidate, GstElement * other, gpointer user_data)
+{
+ GRegex *regex;
+ GMatchInfo *match_info;
+
+ gchar *candidate_port;
+ gchar *candidate_protocol;
+ gchar *candidate_typ;
+ guint port_as_int;
+ guint peer_number;
+
+ regex =
+ g_regex_new ("candidate:(\\d+) (1) (UDP|TCP) (\\d+) ([0-9.]+|[0-9a-f:]+)"
+ " (\\d+) typ ([a-z]+)", 0, 0, NULL);
+
+ g_regex_match (regex, candidate, 0, &match_info);
+ fail_unless (g_match_info_get_match_count (match_info) == 8, candidate);
+
+ candidate_protocol = g_match_info_fetch (match_info, 2);
+ candidate_port = g_match_info_fetch (match_info, 6);
+ candidate_typ = g_match_info_fetch (match_info, 7);
+
+ peer_number = t->webrtc1 == element ? 1 : 2;
+
+ port_as_int = atoi (candidate_port);
+
+ if (!g_strcmp0 (candidate_typ, "host") && port_as_int != 9) {
+ guint expected_min = peer_number * 10000 + 1000;
+ guint expected_max = expected_min + 999;
+
+ fail_unless (port_as_int >= expected_min);
+ fail_unless (port_as_int <= expected_max);
+ }
+
+ g_free (candidate_port);
+ g_free (candidate_protocol);
+ g_free (candidate_typ);
+ g_match_info_free (match_info);
+ g_regex_unref (regex);
+}
+
+GST_START_TEST (test_ice_port_restriction)
+{
+ struct test_webrtc *t = create_audio_test ();
+ GObject *webrtcice;
+
+ VAL_SDP_INIT (offer, _count_num_sdp_media, GUINT_TO_POINTER (1), NULL);
+ VAL_SDP_INIT (answer, _count_num_sdp_media, GUINT_TO_POINTER (1), NULL);
+
+ /*
+ * Ports are defined as follows "{peer}{protocol}000"
+ * - peer number: "1" for t->webrtc1, "2" for t->webrtc2
+ */
+ g_object_get (t->webrtc1, "ice-agent", &webrtcice, NULL);
+ g_object_set (webrtcice, "min-rtp-port", 11000, "max-rtp-port", 11999, NULL);
+ g_object_unref (webrtcice);
+
+ g_object_get (t->webrtc2, "ice-agent", &webrtcice, NULL);
+ g_object_set (webrtcice, "min-rtp-port", 21000, "max-rtp-port", 21999, NULL);
+ g_object_unref (webrtcice);
+
+ t->on_ice_candidate = _check_ice_port_restriction;
+ test_validate_sdp (t, &offer, &answer);
+
+ test_webrtc_wait_for_ice_gathering_complete (t);
+ test_webrtc_free (t);
+}
+
+GST_END_TEST;
+
static struct test_webrtc *
create_audio_video_test (void)
{
tcase_add_test (tc, test_sdp_no_media);
tcase_add_test (tc, test_session_stats);
tcase_add_test (tc, test_audio);
+ tcase_add_test (tc, test_ice_port_restriction);
tcase_add_test (tc, test_audio_video);
tcase_add_test (tc, test_media_direction);
tcase_add_test (tc, test_media_setup);