Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: colekas via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: colekas <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] libavformat/libsrt: Allow for specifying different port and adapter in SRT Rendezvous mode. (PR #21415)
Date: Thu, 08 Jan 2026 20:57:42 -0000
Message-ID: <176790586357.25.14246101184594857677@4457048688e7> (raw)

PR #21415 opened by colekas
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21415
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21415.patch

According to https://github.com/Haivision/srt/blob/master/docs/apps/srt-live-transmit.md#medium-srt a local port and adapter can be specified to allow for NAT traversal when setting up a Rendezvous mode connection.

Slight re-working from this patch from 2018 - https://patchwork.ffmpeg.org/project/ffmpeg/patch/DB8PR09MB29692763876CD366A90BC048C5AA0@DB8PR09MB2969.eurprd09.prod.outlook.com/


>From ced2f184d9b38fd854992a740101461a32bc5886 Mon Sep 17 00:00:00 2001
From: Christopher Olekas <chris.olekas@ssimwave.com>
Date: Thu, 8 Jan 2026 15:47:53 -0500
Subject: [PATCH] libavformat/libsrt: Allow for specifying different port and
 adapter in SRT Rendezvous mode.

According to https://github.com/Haivision/srt/blob/master/docs/apps/srt-live-transmit.md#medium-srt
a local port and adapter can be specified to allow for NAT traversal when setting up a
Rendezvous mode connection.
---
 libavformat/libsrt.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index ba04d9f782..d490244efc 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -93,6 +93,8 @@ typedef struct SRTContext {
     SRT_TRANSTYPE transtype;
     int linger;
     int tsbpd;
+    char *adapter;
+    int port;
 } SRTContext;
 
 #define D AV_OPT_FLAG_DECODING_PARAM
@@ -146,6 +148,8 @@ static const AVOption libsrt_options[] = {
     { "file",           NULL, 0, AV_OPT_TYPE_CONST,  { .i64 = SRTT_FILE }, INT_MIN, INT_MAX, .flags = D|E, .unit = "transtype" },
     { "linger",         "Number of seconds that the socket waits for unsent data when closing", OFFSET(linger),           AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
     { "tsbpd",          "Timestamp-based packet delivery",                                      OFFSET(tsbpd),            AV_OPT_TYPE_BOOL,     { .i64 = -1 }, -1, 1,         .flags = D|E },
+    { "adapter",        "IP address of network card to use in rendezvous mode",                 OFFSET(adapter),          AV_OPT_TYPE_STRING,   { .str = NULL },              .flags = D|E },
+    { "port",           "Local port to use in rendezvous mode",                                 OFFSET(port),             AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, 65535,     .flags = D|E },
     { NULL }
 };
 
@@ -384,13 +388,14 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
 static int libsrt_setup(URLContext *h, const char *uri, int flags)
 {
     struct addrinfo hints = { 0 }, *ai, *cur_ai;
-    int port, fd;
+    int port, fd = -1;
     SRTContext *s = h->priv_data;
     int ret;
     char hostname[1024],proto[1024],path[1024];
     char portstr[10];
     int64_t open_timeout = 0;
     int eid;
+    struct sockaddr_in la = { 0 };
 
     av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
         &port, path, sizeof(path), uri);
@@ -418,6 +423,22 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
 
     cur_ai = ai;
 
+    if (s->mode == SRT_MODE_RENDEZVOUS) {
+        // Copy remote port to local address struct in case port is not set
+        if (cur_ai->ai_family == AF_INET) {
+            struct sockaddr_in *sin = (struct sockaddr_in *)cur_ai->ai_addr;
+            la.sin_family = AF_INET;
+            la.sin_port = sin->sin_port;
+        }
+
+        if (s->port != -1) {
+            la.sin_port = htons(s->port);
+        }
+        if (s->adapter != NULL) {
+            la.sin_addr.s_addr = inet_addr(s->adapter);
+        }
+    }
+
  restart:
 
 #if SRT_VERSION_VALUE >= 0x010401
@@ -461,7 +482,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
         if (ret < 0)
             goto fail1;
         if (s->mode == SRT_MODE_RENDEZVOUS) {
-            if (srt_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen)) {
+            if (srt_bind(fd, (struct sockaddr *)&la, sizeof(struct sockaddr_in))) {
                 ret = libsrt_neterrno(h);
                 srt_epoll_release(write_eid);
                 goto fail1;
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2026-01-08 20:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176790586357.25.14246101184594857677@4457048688e7 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git