summaryrefslogtreecommitdiff
path: root/libavformat/rtpproto.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavformat/rtpproto.c')
-rw-r--r--libavformat/rtpproto.c74
1 files changed, 53 insertions, 21 deletions
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 6582e4ad76..fa1dcb5570 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
*/
@@ -55,6 +55,7 @@ typedef struct RTPContext {
int rtcp_port, local_rtpport, local_rtcpport;
int connect;
int pkt_size;
+ int dscp;
char *sources;
char *block;
} RTPContext;
@@ -68,9 +69,10 @@ static const AVOption options[] = {
{ "rtcp_port", "Custom rtcp port", OFFSET(rtcp_port), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
{ "local_rtpport", "Local rtp port", OFFSET(local_rtpport), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
{ "local_rtcpport", "Local rtcp port", OFFSET(local_rtcpport), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
- { "connect", "Connect socket", OFFSET(connect), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = D|E },
- { "write_to_source", "Send packets to the source address of the latest received packet", OFFSET(write_to_source), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = D|E },
+ { "connect", "Connect socket", OFFSET(connect), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E },
+ { "write_to_source", "Send packets to the source address of the latest received packet", OFFSET(write_to_source), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E },
{ "pkt_size", "Maximum packet size", OFFSET(pkt_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
+ { "dscp", "DSCP class", OFFSET(dscp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
{ "sources", "Source list", OFFSET(sources), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
{ "block", "Block list", OFFSET(block), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
{ NULL }
@@ -239,6 +241,9 @@ static void build_udp_url(RTPContext *s,
url_add_option(buf, buf_size, "pkt_size=%d", s->pkt_size);
if (s->connect)
url_add_option(buf, buf_size, "connect=1");
+ if (s->dscp >= 0)
+ url_add_option(buf, buf_size, "dscp=%d", s->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])
@@ -298,6 +303,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
*
@@ -316,6 +322,8 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
char buf[1024];
char path[1024];
const char *p;
+ int i, max_retry_count = 3;
+ int rtcpflags;
av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
path, sizeof(path), uri);
@@ -349,6 +357,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)) {
+ s->dscp = strtol(buf, NULL, 10);
+ }
if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
av_strlcpy(include_sources, buf, sizeof(include_sources));
@@ -366,19 +377,40 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
}
}
- build_udp_url(s, buf, sizeof(buf),
- hostname, rtp_port, s->local_rtpport, sources, block);
- if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL,
- h->protocols, h) < 0)
- goto fail;
- if (s->local_rtpport >= 0 && s->local_rtcpport < 0)
- s->local_rtcpport = ff_udp_get_local_port(s->rtp_hd) + 1;
-
- build_udp_url(s, buf, sizeof(buf),
- hostname, s->rtcp_port, s->local_rtcpport, sources, block);
- if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL,
- h->protocols, h) < 0)
- goto fail;
+ for (i = 0; i < max_retry_count; i++) {
+ build_udp_url(s, buf, sizeof(buf),
+ hostname, rtp_port, s->local_rtpport,
+ sources, block);
+ if (ffurl_open_whitelist(&s->rtp_hd, buf, flags, &h->interrupt_callback,
+ NULL, h->protocol_whitelist, h->protocol_blacklist, h) < 0)
+ goto fail;
+ s->local_rtpport = ff_udp_get_local_port(s->rtp_hd);
+ if(s->local_rtpport == 65535) {
+ s->local_rtpport = -1;
+ continue;
+ }
+ rtcpflags = flags | AVIO_FLAG_WRITE;
+ if (s->local_rtcpport < 0) {
+ s->local_rtcpport = s->local_rtpport + 1;
+ build_udp_url(s, buf, sizeof(buf),
+ hostname, s->rtcp_port, s->local_rtcpport,
+ sources, block);
+ if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags,
+ &h->interrupt_callback, NULL,
+ h->protocol_whitelist, h->protocol_blacklist, h) < 0) {
+ s->local_rtpport = s->local_rtcpport = -1;
+ continue;
+ }
+ break;
+ }
+ build_udp_url(s, buf, sizeof(buf),
+ hostname, s->rtcp_port, s->local_rtcpport,
+ sources, block);
+ if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, &h->interrupt_callback,
+ NULL, h->protocol_whitelist, h->protocol_blacklist, h) < 0)
+ goto fail;
+ break;
+ }
/* just to ease handle access. XXX: need to suppress direct handle
access */
@@ -521,10 +553,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);