diff options
author | Limin Wang <lance.lmwang@gmail.com> | 2021-11-26 16:55:08 +0800 |
---|---|---|
committer | Limin Wang <lance.lmwang@gmail.com> | 2021-11-27 11:21:17 +0800 |
commit | 7bf4c06809296820f084fd5b3e362621ac99c3f4 (patch) | |
tree | 0c6511d68f11483c54eaed94168e6cbe300262aa /libavformat/rtpproto.c | |
parent | 57adb26d058490daf2c5d6ddd3cf0cf2d2212256 (diff) | |
download | ffmpeg-7bf4c06809296820f084fd5b3e362621ac99c3f4.tar.gz |
avformat/rtp: add localaddr for network interface selection
Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
Diffstat (limited to 'libavformat/rtpproto.c')
-rw-r--r-- | libavformat/rtpproto.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index 7dd6042158..c92cda63bb 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -61,6 +61,7 @@ typedef struct RTPContext { char *block; char *fec_options_str; int64_t rw_timeout; + char *localaddr; } RTPContext; #define OFFSET(x) offsetof(RTPContext, x) @@ -80,6 +81,7 @@ static const AVOption options[] = { { "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 }, { "fec", "FEC", OFFSET(fec_options_str), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = E }, + { "localaddr", "Local address", OFFSET(localaddr), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, { NULL } }; @@ -173,6 +175,7 @@ static av_printf_format(3, 4) void url_add_option(char *buf, int buf_size, const static void build_udp_url(RTPContext *s, char *buf, int buf_size, const char *hostname, + const char *localaddr, int port, int local_port, const char *include_sources, const char *exclude_sources) @@ -195,6 +198,8 @@ static void build_udp_url(RTPContext *s, url_add_option(buf, buf_size, "sources=%s", include_sources); if (exclude_sources && exclude_sources[0]) url_add_option(buf, buf_size, "block=%s", exclude_sources); + if (localaddr && localaddr[0]) + url_add_option(buf, buf_size, "localaddr=%s", localaddr); } /** @@ -284,6 +289,12 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ff_ip_parse_blocks(h, s->block, &s->filters); block = s->block; } + if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) { + av_freep(&s->localaddr); + s->localaddr = av_strdup(buf); + if (!s->localaddr) + goto fail; + } } if (s->rw_timeout >= 0) h->rw_timeout = s->rw_timeout; @@ -314,7 +325,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) for (i = 0; i < max_retry_count; i++) { build_udp_url(s, buf, sizeof(buf), - hostname, rtp_port, s->local_rtpport, + hostname, s->localaddr, 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) @@ -328,7 +339,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) 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, + hostname, s->localaddr, s->rtcp_port, s->local_rtcpport, sources, block); if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, &h->interrupt_callback, NULL, @@ -339,7 +350,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) break; } build_udp_url(s, buf, sizeof(buf), - hostname, s->rtcp_port, s->local_rtcpport, + hostname, s->localaddr, 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) |