Opened 8 days ago

Last modified 6 days ago

#7595 new defect

Cannot use rendezvous mode in SRT protocol

Reported by: lukezaa Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords: libsrt
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I cannot use rendezvous mode in SRT protocol. When I run this command on sender machine, I have following output (repeat+level+debug):

[debug] Opening an input file: srt://172.16.30.50:2121?mode=rendezvous.
[NULL @ 0x55d52732b040] [debug] Opening 'srt://172.16.30.50:2121?mode=rendezvous' for reading
[srt @ 0x55d52732b940] [debug] No default whitelist set
[error] srt://172.16.30.50:2121?mode=rendezvous: Operation not permitted
15:08:44.141142/SRT:GC!!FATAL!!: SRT.c: IPE: For socket %320639888 MUXER id=-1 NOT FOUND!

I included report from ffmpeg.

How to reproduce:

Sender (MPEGTS TO SRT):

#!/bin/bash

INPUT="-i udp://239.1.1.2:2137\
?fifo_size=655350\
&overrun_nonfatal=1"

OUTPUT="srt://172.17.30.50:2121\
?mode=rendezvous"

CODECS="-c copy"

MUXER="-f mpegts -mpegts_pmt_start_pid 0x03FF -mpegts_start_pid 0x0400 -metadata service_provider='xxx' -metadata service_name='xxx'"

OPTIONS="-loglevel repeat+level+debug -re -threads 4"

ffmpeg $OPTIONS $INPUT $CODECS $MUXER $OUTPUT

Receiver (SRT TO MPEGTS):

#!/bin/bash

INPUT="-i srt://172.16.30.50:2121\
?mode=rendezvous"

OUTPUT="udp://239.1.1.3:2137\
?ttl=64\
&localaddr=172.17.40.50\
&bitrate=26214400"

CODECS="-c copy -bufsize 32M"

MUXER="-f mpegts -mpegts_pmt_start_pid 0x03FF -mpegts_start_pid 0x0400 -metadata service_provider='xxx' -metadata service_name='xxx'"

OPTIONS="-loglevel repeat+level+debug -re -threads 8"

ffmpeg $OPTIONS $INPUT $CODECS $MUXER $OUTPUT

Attachments (1)

ffmpeg-20181205-151023.log (6.3 KB) - added by lukezaa 8 days ago.

Download all attachments as: .zip

Change History (4)

Changed 8 days ago by lukezaa

comment:1 Changed 8 days ago by cehoyos

  • Component changed from ffmpeg to undetermined
  • Keywords libsrt added; srt rendezvous removed
  • Priority changed from important to normal

comment:2 Changed 6 days ago by lukezaa

Hello,

The bug was in the libsrc.c file in function libstr_setup. I created simple patch which adds two options for choosing source adapter in ramdezvous mode. It works only with IPv4.

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index fe3b312151..3cfab938d1 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -84,6 +84,8 @@ typedef struct SRTContext {
     char *smoother;
     int messageapi;
     SRT_TRANSTYPE transtype;
+	char *localip;
+	char *localport;
 } SRTContext;
 
 #define D AV_OPT_FLAG_DECODING_PARAM
@@ -128,6 +130,8 @@ static const AVOption libsrt_options[] = {
     { "transtype",      "The transmission type for the socket",                                 OFFSET(transtype),        AV_OPT_TYPE_INT,      { .i64 = SRTT_INVALID }, SRTT_LIVE, SRTT_INVALID, .flags = D|E, "transtype" },
     { "live",           NULL, 0, AV_OPT_TYPE_CONST,  { .i64 = SRTT_LIVE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" },
     { "file",           NULL, 0, AV_OPT_TYPE_CONST,  { .i64 = SRTT_FILE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" },
+	{ "localip",     "localip desc",             OFFSET(localip),       AV_OPT_TYPE_STRING,   { .str = NULL },              .flags = D|E },
+	{ "localport",     "localport desc",             OFFSET(localport),       AV_OPT_TYPE_STRING,   { .str = NULL },              .flags = D|E },
     { NULL }
 };
 
@@ -355,6 +359,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
     char portstr[10];
     int open_timeout = 5000000;
     int eid;
+	struct sockaddr_in la;
 
     eid = srt_epoll_create();
     if (eid < 0)
@@ -395,7 +400,25 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
     }
 
     cur_ai = ai;
-
+	
+	//patch
+	if (s->mode == SRT_MODE_RENDEZVOUS) {
+		if(s->localip == NULL || s->localport == NULL) {
+			av_log(h, AV_LOG_ERROR, "Invalid adapter configuration\n");
+			return AVERROR(EIO);
+		}
+		av_log(h, AV_LOG_DEBUG , "Adapter options %s:%s\n", s->localip, s->localport);
+		
+		int lp = strtol(s->localport, NULL, 10);
+		if (lp <= 0 || lp >= 65536) {
+			av_log(h, AV_LOG_ERROR, "Local port missing in uri\n");
+			return AVERROR(EINVAL);
+		}
+		
+		la.sin_family = AF_INET;
+		la.sin_port = htons(port);
+		la.sin_addr.s_addr = inet_addr(s->localip);
+	}
  restart:
 
     fd = srt_socket(cur_ai->ai_family, cur_ai->ai_socktype, 0);
@@ -423,7 +446,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
         fd = ret;
     } else {
         if (s->mode == SRT_MODE_RENDEZVOUS) {
-            ret = srt_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
+            ret = srt_bind(fd, (struct sockaddr *)&la, sizeof(struct sockaddr_in));
             if (ret)
                 goto fail1;
         }
@@ -580,6 +603,12 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
                 return AVERROR(EINVAL);
             }
         }
+		if (av_find_info_tag(buf, sizeof(buf), "localip", p)) {
+            s->localip = av_strndup(buf, strlen(buf));
+        }
+		if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
+            s->localport = av_strndup(buf, strlen(buf));
+        }
     }
     return libsrt_setup(h, uri, flags);
 } 

comment:3 Changed 6 days ago by cehoyos

Please post your patch - made with git format-patch - to the FFmpeg development mailing list, patches are ignored on this bug tracker.

Note: See TracTickets for help on using tickets.