mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
rtspsrc: add port-range property to rtspsrc
To support setups with firewall/ipsec, it is useful for an rtsp client to be able to set the range of ports that can be used for rtp/rtcp reception. Allows this by adding a "port-range" property to the rtspsrc element. Fixes #625153
This commit is contained in:
parent
e6d7e69844
commit
c6f47c34fb
2 changed files with 64 additions and 3 deletions
|
@ -163,6 +163,7 @@ gst_rtsp_src_buffer_mode_get_type (void)
|
||||||
#define DEFAULT_USER_ID NULL
|
#define DEFAULT_USER_ID NULL
|
||||||
#define DEFAULT_USER_PW NULL
|
#define DEFAULT_USER_PW NULL
|
||||||
#define DEFAULT_BUFFER_MODE 1
|
#define DEFAULT_BUFFER_MODE 1
|
||||||
|
#define DEFAULT_PORT_RANGE NULL
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
@ -182,6 +183,7 @@ enum
|
||||||
PROP_USER_ID,
|
PROP_USER_ID,
|
||||||
PROP_USER_PW,
|
PROP_USER_PW,
|
||||||
PROP_BUFFER_MODE,
|
PROP_BUFFER_MODE,
|
||||||
|
PROP_PORT_RANGE,
|
||||||
PROP_LAST
|
PROP_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -413,6 +415,20 @@ gst_rtspsrc_class_init (GstRTSPSrcClass * klass)
|
||||||
GST_TYPE_RTSP_SRC_BUFFER_MODE, DEFAULT_BUFFER_MODE,
|
GST_TYPE_RTSP_SRC_BUFFER_MODE, DEFAULT_BUFFER_MODE,
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstRTSPSrc::port-range:
|
||||||
|
*
|
||||||
|
* Configure the client port numbers that can be used to recieve RTP and
|
||||||
|
* RTCP.
|
||||||
|
*
|
||||||
|
* Since: 0.10.25
|
||||||
|
*/
|
||||||
|
g_object_class_install_property (gobject_class, PROP_PORT_RANGE,
|
||||||
|
g_param_spec_string ("port-range", "Port range",
|
||||||
|
"Client port range that can be used to receive RTP and RTCP data, "
|
||||||
|
"eg. 3000-3005 (NULL = no restrictions)", DEFAULT_PORT_RANGE,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
gstelement_class->change_state = gst_rtspsrc_change_state;
|
gstelement_class->change_state = gst_rtspsrc_change_state;
|
||||||
|
|
||||||
gstbin_class->handle_message = gst_rtspsrc_handle_message;
|
gstbin_class->handle_message = gst_rtspsrc_handle_message;
|
||||||
|
@ -446,6 +462,8 @@ gst_rtspsrc_init (GstRTSPSrc * src, GstRTSPSrcClass * g_class)
|
||||||
src->user_id = g_strdup (DEFAULT_USER_ID);
|
src->user_id = g_strdup (DEFAULT_USER_ID);
|
||||||
src->user_pw = g_strdup (DEFAULT_USER_PW);
|
src->user_pw = g_strdup (DEFAULT_USER_PW);
|
||||||
src->buffer_mode = DEFAULT_BUFFER_MODE;
|
src->buffer_mode = DEFAULT_BUFFER_MODE;
|
||||||
|
src->client_port_range.min = 0;
|
||||||
|
src->client_port_range.max = 0;
|
||||||
|
|
||||||
/* get a list of all extensions */
|
/* get a list of all extensions */
|
||||||
src->extensions = gst_rtsp_ext_list_get ();
|
src->extensions = gst_rtsp_ext_list_get ();
|
||||||
|
@ -620,6 +638,20 @@ gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value,
|
||||||
case PROP_BUFFER_MODE:
|
case PROP_BUFFER_MODE:
|
||||||
rtspsrc->buffer_mode = g_value_get_enum (value);
|
rtspsrc->buffer_mode = g_value_get_enum (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_PORT_RANGE:
|
||||||
|
{
|
||||||
|
const gchar *str;
|
||||||
|
|
||||||
|
str = g_value_get_string (value);
|
||||||
|
if (str) {
|
||||||
|
sscanf (str, "%u-%u",
|
||||||
|
&rtspsrc->client_port_range.min, &rtspsrc->client_port_range.max);
|
||||||
|
} else {
|
||||||
|
rtspsrc->client_port_range.min = 0;
|
||||||
|
rtspsrc->client_port_range.max = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -696,6 +728,19 @@ gst_rtspsrc_get_property (GObject * object, guint prop_id, GValue * value,
|
||||||
case PROP_BUFFER_MODE:
|
case PROP_BUFFER_MODE:
|
||||||
g_value_set_enum (value, rtspsrc->buffer_mode);
|
g_value_set_enum (value, rtspsrc->buffer_mode);
|
||||||
break;
|
break;
|
||||||
|
case PROP_PORT_RANGE:
|
||||||
|
{
|
||||||
|
gchar *str;
|
||||||
|
|
||||||
|
if (rtspsrc->client_port_range.min != 0) {
|
||||||
|
str = g_strdup_printf ("%u-%u", rtspsrc->client_port_range.min,
|
||||||
|
rtspsrc->client_port_range.max);
|
||||||
|
} else {
|
||||||
|
str = NULL;
|
||||||
|
}
|
||||||
|
g_value_take_string (value, str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -1377,8 +1422,8 @@ gst_rtspsrc_alloc_udp_ports (GstRTSPStream * stream,
|
||||||
udpsrc1 = NULL;
|
udpsrc1 = NULL;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
/* Start with random port */
|
/* Start at next port */
|
||||||
tmp_rtp = 0;
|
tmp_rtp = src->next_port_num;
|
||||||
|
|
||||||
if (stream->is_ipv6)
|
if (stream->is_ipv6)
|
||||||
host = "udp://[::0]";
|
host = "udp://[::0]";
|
||||||
|
@ -1388,6 +1433,11 @@ gst_rtspsrc_alloc_udp_ports (GstRTSPStream * stream,
|
||||||
/* try to allocate 2 UDP ports, the RTP port should be an even
|
/* try to allocate 2 UDP ports, the RTP port should be an even
|
||||||
* number and the RTCP port should be the next (uneven) port */
|
* number and the RTCP port should be the next (uneven) port */
|
||||||
again:
|
again:
|
||||||
|
|
||||||
|
if (tmp_rtp != 0 && src->client_port_range.max > 0 &&
|
||||||
|
tmp_rtp >= src->client_port_range.max)
|
||||||
|
goto no_ports;
|
||||||
|
|
||||||
udpsrc0 = gst_element_make_from_uri (GST_URI_SRC, host, NULL);
|
udpsrc0 = gst_element_make_from_uri (GST_URI_SRC, host, NULL);
|
||||||
if (udpsrc0 == NULL)
|
if (udpsrc0 == NULL)
|
||||||
goto no_udp_protocol;
|
goto no_udp_protocol;
|
||||||
|
@ -1439,13 +1489,15 @@ again:
|
||||||
|
|
||||||
/* set port */
|
/* set port */
|
||||||
tmp_rtcp = tmp_rtp + 1;
|
tmp_rtcp = tmp_rtp + 1;
|
||||||
|
if (src->client_port_range.max > 0 && tmp_rtcp >= src->client_port_range.max)
|
||||||
|
goto no_ports;
|
||||||
|
|
||||||
g_object_set (G_OBJECT (udpsrc1), "port", tmp_rtcp, NULL);
|
g_object_set (G_OBJECT (udpsrc1), "port", tmp_rtcp, NULL);
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (src, "starting RTCP on port %d", tmp_rtcp);
|
GST_DEBUG_OBJECT (src, "starting RTCP on port %d", tmp_rtcp);
|
||||||
ret = gst_element_set_state (udpsrc1, GST_STATE_PAUSED);
|
ret = gst_element_set_state (udpsrc1, GST_STATE_PAUSED);
|
||||||
/* tmp_rtcp port is busy already : retry to make rtp/rtcp pair */
|
/* tmp_rtcp port is busy already : retry to make rtp/rtcp pair */
|
||||||
if (ret == GST_STATE_CHANGE_FAILURE) {
|
if (ret == GST_STATE_CHANGE_FAILURE) {
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTCP port %d", tmp_rtcp);
|
GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTCP port %d", tmp_rtcp);
|
||||||
|
|
||||||
if (++count > src->retry)
|
if (++count > src->retry)
|
||||||
|
@ -1478,6 +1530,11 @@ again:
|
||||||
stream->udpsrc[0] = gst_object_ref (udpsrc0);
|
stream->udpsrc[0] = gst_object_ref (udpsrc0);
|
||||||
stream->udpsrc[1] = gst_object_ref (udpsrc1);
|
stream->udpsrc[1] = gst_object_ref (udpsrc1);
|
||||||
|
|
||||||
|
/* keep track of next available port number when we have a range
|
||||||
|
* configured */
|
||||||
|
if (src->next_port_num != 0)
|
||||||
|
src->next_port_num = tmp_rtcp + 1;
|
||||||
|
|
||||||
/* they are ours now */
|
/* they are ours now */
|
||||||
gst_object_sink (udpsrc0);
|
gst_object_sink (udpsrc0);
|
||||||
gst_object_sink (udpsrc1);
|
gst_object_sink (udpsrc1);
|
||||||
|
@ -4662,6 +4719,8 @@ gst_rtspsrc_setup_streams (GstRTSPSrc * src)
|
||||||
src->free_channel = 0;
|
src->free_channel = 0;
|
||||||
src->interleaved = FALSE;
|
src->interleaved = FALSE;
|
||||||
src->need_activate = FALSE;
|
src->need_activate = FALSE;
|
||||||
|
/* keep track of next port number, 0 is random */
|
||||||
|
src->next_port_num = src->client_port_range.min;
|
||||||
rtpport = rtcpport = 0;
|
rtpport = rtcpport = 0;
|
||||||
|
|
||||||
for (walk = src->streams; walk; walk = g_list_next (walk)) {
|
for (walk = src->streams; walk; walk = g_list_next (walk)) {
|
||||||
|
|
|
@ -212,6 +212,7 @@ struct _GstRTSPSrc {
|
||||||
gchar *user_id;
|
gchar *user_id;
|
||||||
gchar *user_pw;
|
gchar *user_pw;
|
||||||
gint buffer_mode;
|
gint buffer_mode;
|
||||||
|
GstRTSPRange client_port_range;
|
||||||
|
|
||||||
/* state */
|
/* state */
|
||||||
GstRTSPState state;
|
GstRTSPState state;
|
||||||
|
@ -222,6 +223,7 @@ struct _GstRTSPSrc {
|
||||||
gboolean need_redirect;
|
gboolean need_redirect;
|
||||||
GstRTSPTimeRange *range;
|
GstRTSPTimeRange *range;
|
||||||
gchar *control;
|
gchar *control;
|
||||||
|
guint next_port_num;
|
||||||
|
|
||||||
/* supported methods */
|
/* supported methods */
|
||||||
gint methods;
|
gint methods;
|
||||||
|
|
Loading…
Reference in a new issue