diff mbox series

[FFmpeg-devel,v3,1/6] avformat/rtspdec: add network init to listen mode

Message ID 20201012203609.41647-1-andriy.gelman@gmail.com
State Accepted
Commit 423d06e0e22d3c1c62124420532206542488b10f
Headers show
Series [FFmpeg-devel,v3,1/6] avformat/rtspdec: add network init to listen mode
Related show

Checks

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

Commit Message

Andriy Gelman Oct. 12, 2020, 8:36 p.m. UTC
From: Andriy Gelman <andriy.gelman@gmail.com>

As per the docs network initialization is required before ff_url_join().
Furthermore, because the ff_network_init() was skipped, this makes
one additional call to ff_network_close() if the stream exits without
errors.

The was forgotten in the origin commit of the listen mode:
a8ad6ffafe89e3a83f343f69249338e8245816f7

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
---
 libavformat/rtspdec.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Andriy Gelman Nov. 20, 2020, 3:06 a.m. UTC | #1
On Mon, 12. Oct 16:36, Andriy Gelman wrote:
> From: Andriy Gelman <andriy.gelman@gmail.com>
> 
> As per the docs network initialization is required before ff_url_join().
> Furthermore, because the ff_network_init() was skipped, this makes
> one additional call to ff_network_close() if the stream exits without
> errors.
> 
> The was forgotten in the origin commit of the listen mode:
> a8ad6ffafe89e3a83f343f69249338e8245816f7
> 
> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
> ---
>  libavformat/rtspdec.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
> index ef084a8b2b..1ff84cdd56 100644
> --- a/libavformat/rtspdec.c
> +++ b/libavformat/rtspdec.c
> @@ -640,6 +640,9 @@ static int rtsp_listen(AVFormatContext *s)
>      int ret;
>      enum RTSPMethod methodcode;
>  
> +    if (!ff_network_init())
> +        return AVERROR(EIO);
> +
>      /* extract hostname and port */
>      av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host),
>                   &port, path, sizeof(path), s->url);
> @@ -664,19 +667,19 @@ static int rtsp_listen(AVFormatContext *s)
>                                     &s->interrupt_callback, NULL,
>                                     s->protocol_whitelist, s->protocol_blacklist, NULL)) {
>          av_log(s, AV_LOG_ERROR, "Unable to open RTSP for listening\n");
> -        return ret;
> +        goto fail;
>      }
>      rt->state       = RTSP_STATE_IDLE;
>      rt->rtsp_hd_out = rt->rtsp_hd;
>      for (;;) { /* Wait for incoming RTSP messages */
>          ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen);
>          if (ret < 0)
> -            return ret;
> +            goto fail;
>          ret = parse_command_line(s, rbuf, rbuflen, uri, sizeof(uri), method,
>                                   sizeof(method), &methodcode);
>          if (ret) {
>              av_log(s, AV_LOG_ERROR, "RTSP: Unexpected Command\n");
> -            return ret;
> +            goto fail;
>          }
>  
>          if (methodcode == ANNOUNCE) {
> @@ -692,9 +695,13 @@ static int rtsp_listen(AVFormatContext *s)
>              ret = rtsp_read_setup(s, host, uri);
>          if (ret) {
>              ffurl_close(rt->rtsp_hd);
> -            return AVERROR_INVALIDDATA;
> +            ret = AVERROR_INVALIDDATA;
> +            goto fail;
>          }
>      }
> +fail:
> +    ff_network_close();
> +    return ret;
>  }
>  
>  static int rtsp_probe(const AVProbeData *p)
> -- 
> 2.28.0
> 

ping for series.
Martin Storsjö Nov. 20, 2020, 8:22 a.m. UTC | #2
On Mon, 12 Oct 2020, Andriy Gelman wrote:

> From: Andriy Gelman <andriy.gelman@gmail.com>
>
> As per the docs network initialization is required before ff_url_join().
> Furthermore, because the ff_network_init() was skipped, this makes
> one additional call to ff_network_close() if the stream exits without
> errors.
>
> The was forgotten in the origin commit of the listen mode:
> a8ad6ffafe89e3a83f343f69249338e8245816f7
>
> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
> ---
> libavformat/rtspdec.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
> index ef084a8b2b..1ff84cdd56 100644
> --- a/libavformat/rtspdec.c
> +++ b/libavformat/rtspdec.c
> @@ -640,6 +640,9 @@ static int rtsp_listen(AVFormatContext *s)
>     int ret;
>     enum RTSPMethod methodcode;
> 
> +    if (!ff_network_init())
> +        return AVERROR(EIO);
> +
>     /* extract hostname and port */
>     av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host),
>                  &port, path, sizeof(path), s->url);
> @@ -664,19 +667,19 @@ static int rtsp_listen(AVFormatContext *s)
>                                    &s->interrupt_callback, NULL,
>                                    s->protocol_whitelist, s->protocol_blacklist, NULL)) {
>         av_log(s, AV_LOG_ERROR, "Unable to open RTSP for listening\n");
> -        return ret;
> +        goto fail;
>     }
>     rt->state       = RTSP_STATE_IDLE;
>     rt->rtsp_hd_out = rt->rtsp_hd;
>     for (;;) { /* Wait for incoming RTSP messages */
>         ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen);
>         if (ret < 0)
> -            return ret;
> +            goto fail;
>         ret = parse_command_line(s, rbuf, rbuflen, uri, sizeof(uri), method,
>                                  sizeof(method), &methodcode);
>         if (ret) {
>             av_log(s, AV_LOG_ERROR, "RTSP: Unexpected Command\n");
> -            return ret;
> +            goto fail;
>         }
>
>         if (methodcode == ANNOUNCE) {
> @@ -692,9 +695,13 @@ static int rtsp_listen(AVFormatContext *s)
>             ret = rtsp_read_setup(s, host, uri);
>         if (ret) {
>             ffurl_close(rt->rtsp_hd);
> -            return AVERROR_INVALIDDATA;
> +            ret = AVERROR_INVALIDDATA;
> +            goto fail;
>         }
>     }
> +fail:
> +    ff_network_close();
> +    return ret;
> }
> 
> static int rtsp_probe(const AVProbeData *p)
> -- 
> 2.28.0

Looks ok given the analysis and investigation from the commit message.

I presume nobody has tested the rtsp listen mode on windows, because iirc 
that's where the lack of network init before ff_url_join is noticable.

// Martin
diff mbox series

Patch

diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index ef084a8b2b..1ff84cdd56 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -640,6 +640,9 @@  static int rtsp_listen(AVFormatContext *s)
     int ret;
     enum RTSPMethod methodcode;
 
+    if (!ff_network_init())
+        return AVERROR(EIO);
+
     /* extract hostname and port */
     av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host),
                  &port, path, sizeof(path), s->url);
@@ -664,19 +667,19 @@  static int rtsp_listen(AVFormatContext *s)
                                    &s->interrupt_callback, NULL,
                                    s->protocol_whitelist, s->protocol_blacklist, NULL)) {
         av_log(s, AV_LOG_ERROR, "Unable to open RTSP for listening\n");
-        return ret;
+        goto fail;
     }
     rt->state       = RTSP_STATE_IDLE;
     rt->rtsp_hd_out = rt->rtsp_hd;
     for (;;) { /* Wait for incoming RTSP messages */
         ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen);
         if (ret < 0)
-            return ret;
+            goto fail;
         ret = parse_command_line(s, rbuf, rbuflen, uri, sizeof(uri), method,
                                  sizeof(method), &methodcode);
         if (ret) {
             av_log(s, AV_LOG_ERROR, "RTSP: Unexpected Command\n");
-            return ret;
+            goto fail;
         }
 
         if (methodcode == ANNOUNCE) {
@@ -692,9 +695,13 @@  static int rtsp_listen(AVFormatContext *s)
             ret = rtsp_read_setup(s, host, uri);
         if (ret) {
             ffurl_close(rt->rtsp_hd);
-            return AVERROR_INVALIDDATA;
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
         }
     }
+fail:
+    ff_network_close();
+    return ret;
 }
 
 static int rtsp_probe(const AVProbeData *p)