diff options
Diffstat (limited to 'libavformat/rtpproto.c')
-rw-r--r-- | libavformat/rtpproto.c | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index 5bff00ed7a..b6b89247e7 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -2,20 +2,20 @@ * RTP network protocol * Copyright (c) 2002 Fabrice Bellard * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -192,6 +192,7 @@ static void build_udp_url(char *buf, int buf_size, const char *hostname, int port, int local_port, int ttl, int max_packet_size, int connect, + int dscp, const char *include_sources, const char *exclude_sources) { @@ -204,6 +205,9 @@ static void build_udp_url(char *buf, int buf_size, url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size); if (connect) url_add_option(buf, buf_size, "connect=1"); + if (dscp >= 0) + url_add_option(buf, buf_size, "dscp=%d", dscp); + url_add_option(buf, buf_size, "fifo_size=0"); if (include_sources && include_sources[0]) url_add_option(buf, buf_size, "sources=%s", include_sources); if (exclude_sources && exclude_sources[0]) @@ -263,6 +267,7 @@ static void rtp_parse_addr_list(URLContext *h, char *buf, * 'sources=ip[,ip]' : list allowed source IP addresses * 'block=ip[,ip]' : list disallowed source IP addresses * 'write_to_source=0/1' : send packets to the source address of the latest received packet + * 'dscp=n' : set DSCP value to n (QoS) * deprecated option: * 'localport=n' : set the local port to n * @@ -277,11 +282,12 @@ static int rtp_open(URLContext *h, const char *uri, int flags) RTPContext *s = h->priv_data; int rtp_port, rtcp_port, ttl, connect, - local_rtp_port, local_rtcp_port, max_packet_size; + local_rtp_port, local_rtcp_port, max_packet_size, dscp; char hostname[256], include_sources[1024] = "", exclude_sources[1024] = ""; char buf[1024]; char path[1024]; const char *p; + int i, max_retry_count = 3; av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port, path, sizeof(path), uri); @@ -292,6 +298,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) local_rtcp_port = -1; max_packet_size = -1; connect = 0; + dscp = -1; p = strchr(uri, '?'); if (p) { @@ -319,6 +326,9 @@ static int rtp_open(URLContext *h, const char *uri, int flags) if (av_find_info_tag(buf, sizeof(buf), "write_to_source", p)) { s->write_to_source = strtol(buf, NULL, 10); } + if (av_find_info_tag(buf, sizeof(buf), "dscp", p)) { + dscp = strtol(buf, NULL, 10); + } if (av_find_info_tag(buf, sizeof(buf), "sources", p)) { av_strlcpy(include_sources, buf, sizeof(include_sources)); rtp_parse_addr_list(h, buf, &s->ssm_include_addrs, &s->nb_ssm_include_addrs); @@ -329,19 +339,35 @@ static int rtp_open(URLContext *h, const char *uri, int flags) } } - build_udp_url(buf, sizeof(buf), - hostname, rtp_port, local_rtp_port, ttl, max_packet_size, - connect, include_sources, exclude_sources); - if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) - goto fail; - if (local_rtp_port>=0 && local_rtcp_port<0) - local_rtcp_port = ff_udp_get_local_port(s->rtp_hd) + 1; - - build_udp_url(buf, sizeof(buf), - hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size, - connect, include_sources, exclude_sources); - if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) - goto fail; + for (i = 0;i < max_retry_count;i++) { + build_udp_url(buf, sizeof(buf), + hostname, rtp_port, local_rtp_port, ttl, max_packet_size, + connect, dscp, include_sources, exclude_sources); + if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) + goto fail; + local_rtp_port = ff_udp_get_local_port(s->rtp_hd); + if(local_rtp_port == 65535) { + local_rtp_port = -1; + continue; + } + if (local_rtcp_port<0) { + local_rtcp_port = local_rtp_port + 1; + build_udp_url(buf, sizeof(buf), + hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size, + connect, dscp, include_sources, exclude_sources); + if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) { + local_rtp_port = local_rtcp_port = -1; + continue; + } + break; + } + build_udp_url(buf, sizeof(buf), + hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size, + connect, dscp, include_sources, exclude_sources); + if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) + goto fail; + break; + } /* just to ease handle access. XXX: need to suppress direct handle access */ @@ -484,10 +510,10 @@ static int rtp_close(URLContext *h) int i; for (i = 0; i < s->nb_ssm_include_addrs; i++) - av_free(s->ssm_include_addrs[i]); + av_freep(&s->ssm_include_addrs[i]); av_freep(&s->ssm_include_addrs); for (i = 0; i < s->nb_ssm_exclude_addrs; i++) - av_free(s->ssm_exclude_addrs[i]); + av_freep(&s->ssm_exclude_addrs[i]); av_freep(&s->ssm_exclude_addrs); ffurl_close(s->rtp_hd); |