[FFmpeg-devel] [PATCH] avformat/libsrt: log streamid in listener mode

Anton Khirnov anton at khirnov.net
Mon May 31 12:05:36 EEST 2021


Quoting Zhao Zhili (2021-05-27 17:34:55)
> It's useful for test client which pass streamid to ffmpeg/ffplay.
> For example, use ffmpeg to test streamid support in VLC:
> ./ffmpeg -v info -re -i foo.mp4 -c copy -f mpegts -mode listener srt://127.0.0.1:9000
> ./vlc srt://127.0.0.1:9000?streamid=foobar
> ---
>  libavformat/libsrt.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
> index c1e96f700e..6ea6c35c53 100644
> --- a/libavformat/libsrt.c
> +++ b/libavformat/libsrt.c
> @@ -143,6 +143,8 @@ static const AVOption libsrt_options[] = {
>      { NULL }
>  };
>  
> +static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char * optnamestr, void * optval, int * optlen);

Forward declarations should be avoided, when possible. Just move the
function declaration higher up.

> +
>  static int libsrt_neterrno(URLContext *h)
>  {
>      int os_errno;
> @@ -224,6 +226,8 @@ static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t
>  {
>      int ret;
>      int reuse = 1;
> +    char streamid[512] = {};
> +    int streamid_len = sizeof(streamid);
>      if (srt_setsockopt(fd, SOL_SOCKET, SRTO_REUSEADDR, &reuse, sizeof(reuse))) {
>          av_log(h, AV_LOG_WARNING, "setsockopt(SRTO_REUSEADDR) failed\n");
>      }
> @@ -242,6 +246,8 @@ static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t
>          return libsrt_neterrno(h);
>      if (libsrt_socket_nonblock(ret, 1) < 0)
>          av_log(h, AV_LOG_DEBUG, "libsrt_socket_nonblock failed\n");
> +    if (!libsrt_getsockopt(h, ret, SRTO_STREAMID, "SRTO_STREAMID", streamid, &streamid_len))
> +        av_log(h, AV_LOG_INFO, "accept streamid [%s], length %d\n", streamid, streamid_len);

This should be verbose or debug.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list