summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2010-03-16 18:37:18 +0100
committerWim Taymans <wim.taymans@collabora.co.uk>2010-03-16 18:37:18 +0100
commite866345f15291f60ece13bca98e36373810541a4 (patch)
treeb6d5a6b8002f9bdcebf75640f07a69532798acd6
parent4eccdd9dd7b7484cffafc9f2b9df0d18e2cb7ef7 (diff)
rtsp: keep track of server ip and ipv6
Keep track of how the client connected to the server and setup the udp ports with the same protocol. Copy the server ip address in the SDP so that clients can send RTCP back to us.
-rw-r--r--gst/rtsp-server/rtsp-client.h3
-rw-r--r--gst/rtsp-server/rtsp-media.c6
-rw-r--r--gst/rtsp-server/rtsp-media.h1
-rw-r--r--gst/rtsp-server/rtsp-sdp.c31
-rw-r--r--gst/rtsp-server/rtsp-sdp.h7
-rw-r--r--gst/rtsp-server/rtsp-server.c10
6 files changed, 29 insertions, 29 deletions
diff --git a/gst/rtsp-server/rtsp-client.h b/gst/rtsp-server/rtsp-client.h
index ab124c0..b29e218 100644
--- a/gst/rtsp-server/rtsp-client.h
+++ b/gst/rtsp-server/rtsp-client.h
@@ -61,6 +61,7 @@ typedef struct _GstRTSPClientClass GstRTSPClientClass;
* @connection: the connection object handling the client request.
* @watch: watch for the connection
* @watchid: id of the watch
+ * @ip: ip address used by the client to connect to us
* @session_pool: handle to the session pool used by the client.
* @media_mapping: handle to the media mapping used by the client.
* @uri: cached uri
@@ -76,6 +77,8 @@ struct _GstRTSPClient {
GstRTSPConnection *connection;
GstRTSPWatch *watch;
guint watchid;
+ gchar *server_ip;
+ gboolean is_ipv6;
GstRTSPSessionPool *session_pool;
GstRTSPMediaMapping *media_mapping;
diff --git a/gst/rtsp-server/rtsp-media.c b/gst/rtsp-server/rtsp-media.c
index bee6dff..c4f824b 100644
--- a/gst/rtsp-server/rtsp-media.c
+++ b/gst/rtsp-server/rtsp-media.c
@@ -539,7 +539,7 @@ gst_rtsp_media_stream_rtcp (GstRTSPMediaStream * stream, GstBuffer * buffer)
/* Allocate the udp ports and sockets */
static gboolean
-alloc_udp_ports (GstRTSPMediaStream * stream, gboolean is_ipv6)
+alloc_udp_ports (GstRTSPMedia * media, GstRTSPMediaStream * stream)
{
GstStateChangeReturn ret;
GstElement *udpsrc0, *udpsrc1;
@@ -558,7 +558,7 @@ alloc_udp_ports (GstRTSPMediaStream * stream, gboolean is_ipv6)
/* Start with random port */
tmp_rtp = 0;
- if (is_ipv6)
+ if (media->is_ipv6)
host = "udp://[::0]";
else
host = "udp://0.0.0.0";
@@ -922,7 +922,7 @@ setup_stream (GstRTSPMediaStream * stream, guint idx, GstRTSPMedia * media)
/* allocate udp ports, we will have 4 of them, 2 for receiving RTP/RTCP and 2
* for sending RTP/RTCP. The sender and receiver ports are shared between the
* elements */
- if (!alloc_udp_ports (stream, FALSE))
+ if (!alloc_udp_ports (media, stream))
return FALSE;
/* add the ports to the pipeline */
diff --git a/gst/rtsp-server/rtsp-media.h b/gst/rtsp-server/rtsp-media.h
index e873c04..8abf05f 100644
--- a/gst/rtsp-server/rtsp-media.h
+++ b/gst/rtsp-server/rtsp-media.h
@@ -191,6 +191,7 @@ struct _GstRTSPMedia {
gboolean shared;
gboolean reusable;
gboolean reused;
+ gboolean is_ipv6;
GstElement *element;
GArray *streams;
diff --git a/gst/rtsp-server/rtsp-sdp.c b/gst/rtsp-server/rtsp-sdp.c
index 7c1744b..56ca719 100644
--- a/gst/rtsp-server/rtsp-sdp.c
+++ b/gst/rtsp-server/rtsp-sdp.c
@@ -22,16 +22,18 @@
/**
* gst_rtsp_sdp_from_media:
+ * @sdp: a #GstSDPessage
+ * @info: info
* @media: a #GstRTSPMedia
*
- * Create a new sdp message for @media.
+ * Add @media specific info to @sdp. @info is used to configure the connection
+ * information in the SDP.
*
- * Returns: a new sdp message for @media. gst_sdp_message_free() after usage.
+ * Returns: TRUE on success.
*/
-GstSDPMessage *
-gst_rtsp_sdp_from_media (GstRTSPMedia * media)
+gboolean
+gst_rtsp_sdp_from_media (GstSDPMessage *sdp, GstSDPInfo *info, GstRTSPMedia * media)
{
- GstSDPMessage *sdp;
guint i, n_streams;
gchar *rangestr;
@@ -40,19 +42,6 @@ gst_rtsp_sdp_from_media (GstRTSPMedia * media)
n_streams = gst_rtsp_media_n_streams (media);
- gst_sdp_message_new (&sdp);
-
- /* some standard things first */
- gst_sdp_message_set_version (sdp, "0");
-
- gst_sdp_message_set_origin (sdp, "-", "1188340656180883", "1", "IN", "IP4",
- "127.0.0.1");
- gst_sdp_message_set_session_name (sdp, "Session streamed with GStreamer");
- gst_sdp_message_set_information (sdp, "rtsp-server");
- gst_sdp_message_add_time (sdp, "0", "0", NULL);
- gst_sdp_message_add_attribute (sdp, "tool", "GStreamer");
- gst_sdp_message_add_attribute (sdp, "type", "broadcast");
- gst_sdp_message_add_attribute (sdp, "control", "*");
rangestr = gst_rtsp_range_to_string (&media->range);
gst_sdp_message_add_attribute (sdp, "range", rangestr);
g_free (rangestr);
@@ -96,7 +85,7 @@ gst_rtsp_sdp_from_media (GstRTSPMedia * media)
gst_sdp_media_set_proto (smedia, "RTP/AVP");
/* for the c= line */
- gst_sdp_media_add_connection (smedia, "IN", "IP4", "127.0.0.1", 0, 0);
+ gst_sdp_media_add_connection (smedia, "IN", info->server_proto, info->server_ip, 0, 0);
/* get clock-rate, media type and params for the rtpmap attribute */
gst_structure_get_int (s, "clock-rate", &caps_rate);
@@ -163,12 +152,12 @@ gst_rtsp_sdp_from_media (GstRTSPMedia * media)
gst_sdp_media_free (smedia);
}
- return sdp;
+ return TRUE;
/* ERRORS */
not_prepared:
{
GST_ERROR ("media %p is not prepared", media);
- return NULL;
+ return FALSE;
}
}
diff --git a/gst/rtsp-server/rtsp-sdp.h b/gst/rtsp-server/rtsp-sdp.h
index 4016eda..6c4c005 100644
--- a/gst/rtsp-server/rtsp-sdp.h
+++ b/gst/rtsp-server/rtsp-sdp.h
@@ -27,8 +27,13 @@
G_BEGIN_DECLS
+typedef struct {
+ const gchar *server_proto;
+ const gchar *server_ip;
+} GstSDPInfo;
+
/* creating SDP */
-GstSDPMessage * gst_rtsp_sdp_from_media (GstRTSPMedia *media);
+gboolean gst_rtsp_sdp_from_media (GstSDPMessage *sdp, GstSDPInfo *info, GstRTSPMedia * media);
G_END_DECLS
diff --git a/gst/rtsp-server/rtsp-server.c b/gst/rtsp-server/rtsp-server.c
index 1e302d5..7f54798 100644
--- a/gst/rtsp-server/rtsp-server.c
+++ b/gst/rtsp-server/rtsp-server.c
@@ -425,7 +425,7 @@ gst_rtsp_server_sink_init_send (GstRTSPServer * server)
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM; /* stream socket */
- hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
+ hints.ai_flags = AI_PASSIVE | AI_CANONNAME; /* For wildcard IP address */
hints.ai_protocol = 0; /* Any protocol */
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
@@ -446,8 +446,10 @@ gst_rtsp_server_sink_init_send (GstRTSPServer * server)
continue;
}
- if (bind (sockfd, rp->ai_addr, rp->ai_addrlen) == 0)
+ if (bind (sockfd, rp->ai_addr, rp->ai_addrlen) == 0) {
+ GST_DEBUG_OBJECT (server, "bind on %s", rp->ai_canonname);
break;
+ }
GST_DEBUG_OBJECT (server, "failed to bind socket (%s), try next", g_strerror (errno));
close (sockfd);
@@ -654,7 +656,7 @@ gst_rtsp_server_create_watch (GstRTSPServer *server)
channel = gst_rtsp_server_get_io_channel (server);
if (channel == NULL)
goto no_channel;
-
+
/* create a watch for reads (new connections) and possible errors */
server->io_watch = g_io_create_watch (channel, G_IO_IN |
G_IO_ERR | G_IO_HUP | G_IO_NVAL);
@@ -682,7 +684,7 @@ no_channel:
* This function should be called when the server properties and urls are fully
* configured and the server is ready to start.
*
- * Returns: the ID (greater than 0) for the source within the GMainContext.
+ * Returns: the ID (greater than 0) for the source within the GMainContext.
*/
guint
gst_rtsp_server_attach (GstRTSPServer *server, GMainContext *context)