[FFmpeg-trac] #7595(undetermined:new): Cannot use rendezvous mode in SRT protocol

FFmpeg trac at avcodec.org
Fri Dec 7 12:44:56 EET 2018


#7595: Cannot use rendezvous mode in SRT protocol
-------------------------------------+-------------------------------------
             Reporter:  lukezaa      |                    Owner:
                 Type:  defect       |                   Status:  new
             Priority:  normal       |                Component:
              Version:  git-master   |  undetermined
             Keywords:  libsrt       |               Resolution:
             Blocking:               |               Blocked By:
Analyzed by developer:  0            |  Reproduced by developer:  0
-------------------------------------+-------------------------------------

Comment (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);
  }
 }}}

--
Ticket URL: <https://trac.ffmpeg.org/ticket/7595#comment:2>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list