Commit d0f8b94b authored by Vincent Bernat's avatar Vincent Bernat Committed by Michael Niedermayer

avformat/rtpproto: Allow to specify DSCP class

By appending `?dscp=26` to the URL, IP packets will be classified as
AF31 (assured forwarding for multimedia flows with low probability of
loss). On congested network, this allows a user to assign priorities to
flows.
Signed-off-by: 's avatarVincent Bernat <vincent@bernat.im>
parent 5269cef4
...@@ -192,6 +192,7 @@ static void build_udp_url(char *buf, int buf_size, ...@@ -192,6 +192,7 @@ static void build_udp_url(char *buf, int buf_size,
const char *hostname, int port, const char *hostname, int port,
int local_port, int ttl, int local_port, int ttl,
int max_packet_size, int connect, int max_packet_size, int connect,
int dscp,
const char *include_sources, const char *include_sources,
const char *exclude_sources) const char *exclude_sources)
{ {
...@@ -204,6 +205,8 @@ static void build_udp_url(char *buf, int buf_size, ...@@ -204,6 +205,8 @@ static void build_udp_url(char *buf, int buf_size,
url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size); url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size);
if (connect) if (connect)
url_add_option(buf, buf_size, "connect=1"); 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"); url_add_option(buf, buf_size, "fifo_size=0");
if (include_sources && include_sources[0]) if (include_sources && include_sources[0])
url_add_option(buf, buf_size, "sources=%s", include_sources); url_add_option(buf, buf_size, "sources=%s", include_sources);
...@@ -264,6 +267,7 @@ static void rtp_parse_addr_list(URLContext *h, char *buf, ...@@ -264,6 +267,7 @@ static void rtp_parse_addr_list(URLContext *h, char *buf,
* 'sources=ip[,ip]' : list allowed source IP addresses * 'sources=ip[,ip]' : list allowed source IP addresses
* 'block=ip[,ip]' : list disallowed 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 * '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: * deprecated option:
* 'localport=n' : set the local port to n * 'localport=n' : set the local port to n
* *
...@@ -278,7 +282,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ...@@ -278,7 +282,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
RTPContext *s = h->priv_data; RTPContext *s = h->priv_data;
int rtp_port, rtcp_port, int rtp_port, rtcp_port,
ttl, connect, 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 hostname[256], include_sources[1024] = "", exclude_sources[1024] = "";
char buf[1024]; char buf[1024];
char path[1024]; char path[1024];
...@@ -294,6 +298,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ...@@ -294,6 +298,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
local_rtcp_port = -1; local_rtcp_port = -1;
max_packet_size = -1; max_packet_size = -1;
connect = 0; connect = 0;
dscp = -1;
p = strchr(uri, '?'); p = strchr(uri, '?');
if (p) { if (p) {
...@@ -321,6 +326,9 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ...@@ -321,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)) { if (av_find_info_tag(buf, sizeof(buf), "write_to_source", p)) {
s->write_to_source = strtol(buf, NULL, 10); 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)) { if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
av_strlcpy(include_sources, buf, sizeof(include_sources)); av_strlcpy(include_sources, buf, sizeof(include_sources));
rtp_parse_addr_list(h, buf, &s->ssm_include_addrs, &s->nb_ssm_include_addrs); rtp_parse_addr_list(h, buf, &s->ssm_include_addrs, &s->nb_ssm_include_addrs);
...@@ -334,7 +342,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ...@@ -334,7 +342,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
for (i = 0;i < max_retry_count;i++) { for (i = 0;i < max_retry_count;i++) {
build_udp_url(buf, sizeof(buf), build_udp_url(buf, sizeof(buf),
hostname, rtp_port, local_rtp_port, ttl, max_packet_size, hostname, rtp_port, local_rtp_port, ttl, max_packet_size,
connect, include_sources, exclude_sources); connect, dscp, include_sources, exclude_sources);
if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL) < 0)
goto fail; goto fail;
local_rtp_port = ff_udp_get_local_port(s->rtp_hd); local_rtp_port = ff_udp_get_local_port(s->rtp_hd);
...@@ -346,7 +354,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ...@@ -346,7 +354,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
local_rtcp_port = local_rtp_port + 1; local_rtcp_port = local_rtp_port + 1;
build_udp_url(buf, sizeof(buf), build_udp_url(buf, sizeof(buf),
hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size, hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size,
connect, include_sources, exclude_sources); connect, dscp, include_sources, exclude_sources);
if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) { if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) {
local_rtp_port = local_rtcp_port = -1; local_rtp_port = local_rtcp_port = -1;
continue; continue;
...@@ -355,7 +363,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ...@@ -355,7 +363,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
} }
build_udp_url(buf, sizeof(buf), build_udp_url(buf, sizeof(buf),
hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size, hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size,
connect, include_sources, exclude_sources); connect, dscp, include_sources, exclude_sources);
if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0)
goto fail; goto fail;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment