mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
rtspsrc: refactor collecting the transport info
Make a method to collect the ports and destination address.
This commit is contained in:
parent
05352d7ea8
commit
4e1ced0a77
1 changed files with 68 additions and 42 deletions
|
@ -2377,12 +2377,56 @@ gst_rtspsrc_stream_configure_tcp (GstRTSPSrc * src, GstRTSPStream * stream,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_rtspsrc_get_transport_info (GstRTSPSrc * src, GstRTSPStream * stream,
|
||||||
|
GstRTSPTransport * transport, const gchar ** destination, gint * min,
|
||||||
|
gint * max, guint * ttl)
|
||||||
|
{
|
||||||
|
if (transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
|
||||||
|
if (destination) {
|
||||||
|
if (!(*destination = transport->destination))
|
||||||
|
*destination = stream->destination;
|
||||||
|
}
|
||||||
|
if (min && max) {
|
||||||
|
/* transport first */
|
||||||
|
*min = transport->port.min;
|
||||||
|
*max = transport->port.max;
|
||||||
|
if (*min == -1 && *max == -1) {
|
||||||
|
/* then try from SDP */
|
||||||
|
}
|
||||||
|
if (*min == -1 && *max == -1) {
|
||||||
|
/* some bad servers use the server_port attribute for multicast, try to handle
|
||||||
|
* those cases too here */
|
||||||
|
*min = transport->server_port.min;
|
||||||
|
*max = transport->server_port.max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ttl) {
|
||||||
|
if (!(*ttl = transport->ttl))
|
||||||
|
*ttl = stream->ttl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (destination) {
|
||||||
|
/* first take the source, then the endpoint to figure out where to send
|
||||||
|
* the RTCP. */
|
||||||
|
if (!(*destination = transport->source))
|
||||||
|
*destination = gst_rtsp_connection_get_ip (src->connection);
|
||||||
|
}
|
||||||
|
if (min && max) {
|
||||||
|
*min = transport->server_port.min;
|
||||||
|
*max = transport->server_port.max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* For multicast create UDP sources and join the multicast group. */
|
/* For multicast create UDP sources and join the multicast group. */
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_rtspsrc_stream_configure_mcast (GstRTSPSrc * src, GstRTSPStream * stream,
|
gst_rtspsrc_stream_configure_mcast (GstRTSPSrc * src, GstRTSPStream * stream,
|
||||||
GstRTSPTransport * transport, GstPad ** outpad)
|
GstRTSPTransport * transport, GstPad ** outpad)
|
||||||
{
|
{
|
||||||
gchar *uri, *destination;
|
gchar *uri;
|
||||||
|
const gchar *destination;
|
||||||
gint min, max;
|
gint min, max;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (src, "creating UDP sources for multicast");
|
GST_DEBUG_OBJECT (src, "creating UDP sources for multicast");
|
||||||
|
@ -2390,29 +2434,20 @@ gst_rtspsrc_stream_configure_mcast (GstRTSPSrc * src, GstRTSPStream * stream,
|
||||||
/* we can remove the allocated UDP ports now */
|
/* we can remove the allocated UDP ports now */
|
||||||
gst_rtspsrc_stream_free_udp (stream);
|
gst_rtspsrc_stream_free_udp (stream);
|
||||||
|
|
||||||
|
gst_rtspsrc_get_transport_info (src, stream, transport, &destination, &min,
|
||||||
|
&max, NULL);
|
||||||
|
|
||||||
/* we need a destination now */
|
/* we need a destination now */
|
||||||
if (!(destination = transport->destination)) {
|
if (destination == NULL)
|
||||||
if (!(destination = stream->destination))
|
goto no_destination;
|
||||||
goto no_destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
min = transport->port.min;
|
|
||||||
max = transport->port.max;
|
|
||||||
/* some bad servers use the server_port attribute for multicast, try to handle
|
|
||||||
* those cases too here */
|
|
||||||
if (min == -1 && max == -1) {
|
|
||||||
GST_DEBUG_OBJECT (src, "no port attribute set, fallback to server_port");
|
|
||||||
min = transport->server_port.min;
|
|
||||||
max = transport->server_port.max;
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (src, "have destination '%s' and ports (%d)-(%d)",
|
|
||||||
destination, min, max);
|
|
||||||
|
|
||||||
/* we really need ports now or we won't be able to receive anything at all */
|
/* we really need ports now or we won't be able to receive anything at all */
|
||||||
if (min == -1 && max == -1)
|
if (min == -1 && max == -1)
|
||||||
goto no_ports;
|
goto no_ports;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (src, "have destination '%s' and ports (%d)-(%d)",
|
||||||
|
destination, min, max);
|
||||||
|
|
||||||
/* creating UDP source for RTP */
|
/* creating UDP source for RTP */
|
||||||
if (min != -1) {
|
if (min != -1) {
|
||||||
uri = g_strdup_printf ("udp://%s:%d", destination, min);
|
uri = g_strdup_printf ("udp://%s:%d", destination, min);
|
||||||
|
@ -2532,35 +2567,28 @@ gst_rtspsrc_stream_configure_udp_sinks (GstRTSPSrc * src,
|
||||||
{
|
{
|
||||||
GstPad *pad;
|
GstPad *pad;
|
||||||
gint rtp_port, rtcp_port, sockfd = -1;
|
gint rtp_port, rtcp_port, sockfd = -1;
|
||||||
|
gboolean do_rtp, do_rtcp;
|
||||||
const gchar *destination;
|
const gchar *destination;
|
||||||
gchar *uri, *name;
|
gchar *uri, *name;
|
||||||
guint ttl = 0;
|
guint ttl = 0;
|
||||||
|
|
||||||
/* get host and port */
|
/* get transport info */
|
||||||
if (transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
|
gst_rtspsrc_get_transport_info (src, stream, transport, &destination,
|
||||||
rtp_port = transport->port.min;
|
&rtp_port, &rtcp_port, &ttl);
|
||||||
rtcp_port = transport->port.max;
|
|
||||||
/* multicast destination */
|
/* see what we need to do */
|
||||||
if (!(destination = transport->destination))
|
do_rtp = (rtp_port != -1);
|
||||||
destination = stream->destination;
|
/* it's possible that the server does not want us to send RTCP in which case
|
||||||
/* get ttl */
|
* the port is -1 */
|
||||||
if (!(ttl = transport->ttl))
|
do_rtcp = (rtcp_port != -1 && src->session != NULL && src->do_rtcp);
|
||||||
ttl = stream->ttl;
|
|
||||||
} else {
|
/* we need a destination when we have RTP or RTCP ports */
|
||||||
rtp_port = transport->server_port.min;
|
if (destination == NULL && (do_rtp || do_rtcp))
|
||||||
rtcp_port = transport->server_port.max;
|
|
||||||
/* first take the source, then the endpoint to figure out where to send
|
|
||||||
* the RTCP. */
|
|
||||||
destination = transport->source;
|
|
||||||
if (destination == NULL)
|
|
||||||
destination = gst_rtsp_connection_get_ip (src->connection);
|
|
||||||
}
|
|
||||||
if (destination == NULL)
|
|
||||||
goto no_destination;
|
goto no_destination;
|
||||||
|
|
||||||
/* try to construct the fakesrc to the RTP port of the server to open up any
|
/* try to construct the fakesrc to the RTP port of the server to open up any
|
||||||
* NAT firewalls */
|
* NAT firewalls */
|
||||||
if (rtp_port != -1) {
|
if (do_rtp) {
|
||||||
GST_DEBUG_OBJECT (src, "configure RTP UDP sink for %s:%d", destination,
|
GST_DEBUG_OBJECT (src, "configure RTP UDP sink for %s:%d", destination,
|
||||||
rtp_port);
|
rtp_port);
|
||||||
|
|
||||||
|
@ -2615,9 +2643,7 @@ gst_rtspsrc_stream_configure_udp_sinks (GstRTSPSrc * src,
|
||||||
|
|
||||||
gst_element_link (stream->fakesrc, stream->udpsink[0]);
|
gst_element_link (stream->fakesrc, stream->udpsink[0]);
|
||||||
}
|
}
|
||||||
/* it's possible that the server does not want us to send RTCP in which case
|
if (do_rtcp) {
|
||||||
* the port is -1 */
|
|
||||||
if (rtcp_port != -1 && src->session != NULL && src->do_rtcp) {
|
|
||||||
GST_DEBUG_OBJECT (src, "configure RTCP UDP sink for %s:%d", destination,
|
GST_DEBUG_OBJECT (src, "configure RTCP UDP sink for %s:%d", destination,
|
||||||
rtcp_port);
|
rtcp_port);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue