diff mbox series

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

Message ID tencent_AE6202C169367CFAACEE39D9C15DB4A8690A@qq.com
State Accepted
Commit fc9832f2557be0633e08963b8372d1cf7f4d6aea
Headers show
Series [FFmpeg-devel,v3] avformat/libsrt: log streamid in listener mode | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Zhao Zhili June 10, 2021, 3:58 a.m. UTC
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
---
v3:
Don't zero out streamid.
Fix streamid array size (512 -> 513).

v2:
Avoid forward declaration.
Use AV_LOG_VERBOSE.

 libavformat/libsrt.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

Comments

Zhao Zhili June 18, 2021, 2:43 p.m. UTC | #1
Ping for review, thanks!

> On Jun 10, 2021, at 11:58 AM, Zhao Zhili <quinkblack@foxmail.com> wrote:
> 
> 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
> ---
> v3:
> Don't zero out streamid.
> Fix streamid array size (512 -> 513).
> 
> v2:
> Avoid forward declaration.
> Use AV_LOG_VERBOSE.
> 
> libavformat/libsrt.c | 24 +++++++++++++++---------
> 1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
> index 8dee6aa3f3..a4285ca294 100644
> --- a/libavformat/libsrt.c
> +++ b/libavformat/libsrt.c
> @@ -156,6 +156,15 @@ static int libsrt_neterrno(URLContext *h)
>     return os_errno ? AVERROR(os_errno) : AVERROR_UNKNOWN;
> }
> 
> +static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char * optnamestr, void * optval, int * optlen)
> +{
> +    if (srt_getsockopt(fd, 0, optname, optval, optlen) < 0) {
> +        av_log(h, AV_LOG_ERROR, "failed to get option %s on socket: %s\n", optnamestr, srt_getlasterror_str());
> +        return AVERROR(EIO);
> +    }
> +    return 0;
> +}
> +
> static int libsrt_socket_nonblock(int socket, int enable)
> {
>     int ret, blocking = enable ? 0 : 1;
> @@ -227,6 +236,9 @@ static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t
> {
>     int ret;
>     int reuse = 1;
> +    /* Max streamid length plus an extra space for the terminating null character */
> +    char streamid[513];
> +    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");
>     }
> @@ -245,6 +257,9 @@ 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))
> +        /* Note: returned streamid_len doesn't count the terminating null character */
> +        av_log(h, AV_LOG_VERBOSE, "accept streamid [%s], length %d\n", streamid, streamid_len);
> 
>     return ret;
> }
> @@ -279,15 +294,6 @@ static int libsrt_setsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const c
>     return 0;
> }
> 
> -static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char * optnamestr, void * optval, int * optlen)
> -{
> -    if (srt_getsockopt(fd, 0, optname, optval, optlen) < 0) {
> -        av_log(h, AV_LOG_ERROR, "failed to get option %s on socket: %s\n", optnamestr, srt_getlasterror_str());
> -        return AVERROR(EIO);
> -    }
> -    return 0;
> -}
> -
> /* - The "POST" options can be altered any time on a connected socket.
>      They MAY have also some meaning when set prior to connecting; such
>      option is SRTO_RCVSYN, which makes connect/accept call asynchronous.
> -- 
> 2.31.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Marton Balint Sept. 18, 2021, 7:50 p.m. UTC | #2
On Fri, 18 Jun 2021, "zhilizhao(赵志立)" wrote:

> Ping for review, thanks!

Thanks, applied.

Regards,
Marton

>
>> On Jun 10, 2021, at 11:58 AM, Zhao Zhili <quinkblack@foxmail.com> wrote:
>>
>> 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
>> ---
>> v3:
>> Don't zero out streamid.
>> Fix streamid array size (512 -> 513).
>>
>> v2:
>> Avoid forward declaration.
>> Use AV_LOG_VERBOSE.
>>
>> libavformat/libsrt.c | 24 +++++++++++++++---------
>> 1 file changed, 15 insertions(+), 9 deletions(-)
>>
>> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
>> index 8dee6aa3f3..a4285ca294 100644
>> --- a/libavformat/libsrt.c
>> +++ b/libavformat/libsrt.c
>> @@ -156,6 +156,15 @@ static int libsrt_neterrno(URLContext *h)
>>     return os_errno ? AVERROR(os_errno) : AVERROR_UNKNOWN;
>> }
>>
>> +static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char * optnamestr, void * optval, int * optlen)
>> +{
>> +    if (srt_getsockopt(fd, 0, optname, optval, optlen) < 0) {
>> +        av_log(h, AV_LOG_ERROR, "failed to get option %s on socket: %s\n", optnamestr, srt_getlasterror_str());
>> +        return AVERROR(EIO);
>> +    }
>> +    return 0;
>> +}
>> +
>> static int libsrt_socket_nonblock(int socket, int enable)
>> {
>>     int ret, blocking = enable ? 0 : 1;
>> @@ -227,6 +236,9 @@ static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t
>> {
>>     int ret;
>>     int reuse = 1;
>> +    /* Max streamid length plus an extra space for the terminating null character */
>> +    char streamid[513];
>> +    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");
>>     }
>> @@ -245,6 +257,9 @@ 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))
>> +        /* Note: returned streamid_len doesn't count the terminating null character */
>> +        av_log(h, AV_LOG_VERBOSE, "accept streamid [%s], length %d\n", streamid, streamid_len);
>>
>>     return ret;
>> }
>> @@ -279,15 +294,6 @@ static int libsrt_setsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const c
>>     return 0;
>> }
>>
>> -static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char * optnamestr, void * optval, int * optlen)
>> -{
>> -    if (srt_getsockopt(fd, 0, optname, optval, optlen) < 0) {
>> -        av_log(h, AV_LOG_ERROR, "failed to get option %s on socket: %s\n", optnamestr, srt_getlasterror_str());
>> -        return AVERROR(EIO);
>> -    }
>> -    return 0;
>> -}
>> -
>> /* - The "POST" options can be altered any time on a connected socket.
>>      They MAY have also some meaning when set prior to connecting; such
>>      option is SRTO_RCVSYN, which makes connect/accept call asynchronous.
>> --
>> 2.31.1
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
diff mbox series

Patch

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index 8dee6aa3f3..a4285ca294 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -156,6 +156,15 @@  static int libsrt_neterrno(URLContext *h)
     return os_errno ? AVERROR(os_errno) : AVERROR_UNKNOWN;
 }
 
+static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char * optnamestr, void * optval, int * optlen)
+{
+    if (srt_getsockopt(fd, 0, optname, optval, optlen) < 0) {
+        av_log(h, AV_LOG_ERROR, "failed to get option %s on socket: %s\n", optnamestr, srt_getlasterror_str());
+        return AVERROR(EIO);
+    }
+    return 0;
+}
+
 static int libsrt_socket_nonblock(int socket, int enable)
 {
     int ret, blocking = enable ? 0 : 1;
@@ -227,6 +236,9 @@  static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t
 {
     int ret;
     int reuse = 1;
+    /* Max streamid length plus an extra space for the terminating null character */
+    char streamid[513];
+    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");
     }
@@ -245,6 +257,9 @@  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))
+        /* Note: returned streamid_len doesn't count the terminating null character */
+        av_log(h, AV_LOG_VERBOSE, "accept streamid [%s], length %d\n", streamid, streamid_len);
 
     return ret;
 }
@@ -279,15 +294,6 @@  static int libsrt_setsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const c
     return 0;
 }
 
-static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char * optnamestr, void * optval, int * optlen)
-{
-    if (srt_getsockopt(fd, 0, optname, optval, optlen) < 0) {
-        av_log(h, AV_LOG_ERROR, "failed to get option %s on socket: %s\n", optnamestr, srt_getlasterror_str());
-        return AVERROR(EIO);
-    }
-    return 0;
-}
-
 /* - The "POST" options can be altered any time on a connected socket.
      They MAY have also some meaning when set prior to connecting; such
      option is SRTO_RCVSYN, which makes connect/accept call asynchronous.