[FFmpeg-devel] [FFmpeg-cvslog] avformat/rtsp: support for listen_timeout option for sdp

Andriy Gelman andriy.gelman at gmail.com
Tue Nov 3 06:57:47 EET 2020


On Thu, 22. Oct 14:21, Limin Wang wrote:
> ffmpeg | branch: master | Limin Wang <lance.lmwang at gmail.com> | Sat Oct 10 21:30:21 2020 +0800| [92c40ef882be115e72d2aa02f9032b7ce88f8537] | committer: Limin Wang
> 
> avformat/rtsp: support for listen_timeout option for sdp
> 
> Now the listen timeout is hardcoded(10s).
> How to test(30s timeout):
> ./ffprobe  -listen_timeout 30 -protocol_whitelist rtp,udp,file -i test.sdp
> 
> Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=92c40ef882be115e72d2aa02f9032b7ce88f8537
> ---
> 
>  libavformat/rtsp.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> index e9fca034b4..4ecd702780 100644
> --- a/libavformat/rtsp.c
> +++ b/libavformat/rtsp.c
> @@ -55,7 +55,6 @@
>   * and read_packet(), in seconds  */
>  #define POLL_TIMEOUT_MS 100
>  #define READ_PACKET_TIMEOUT_S 10
> -#define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / POLL_TIMEOUT_MS
>  #define SDP_MAX_SIZE 16384
>  #define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH
>  #define DEFAULT_REORDERING_DELAY 100000
> @@ -115,6 +114,7 @@ static const AVOption sdp_options[] = {
>      RTSP_FLAG_OPTS("sdp_flags", "SDP flags"),
>      { "custom_io", "use custom I/O", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_CUSTOM_IO}, 0, 0, DEC, "rtsp_flags" },
>      { "rtcp_to_source", "send RTCP packets to the source address of received packets", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_RTCP_TO_SOURCE}, 0, 0, DEC, "rtsp_flags" },
> +    { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = READ_PACKET_TIMEOUT_S}, INT_MIN, INT_MAX, DEC },
>      RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
>      COMMON_OPTS(),
>      { NULL },
> @@ -122,6 +122,8 @@ static const AVOption sdp_options[] = {
>  
>  static const AVOption rtp_options[] = {
>      RTSP_FLAG_OPTS("rtp_flags", "set RTP flags"),
> +    { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = READ_PACKET_TIMEOUT_S}, INT_MIN, INT_MAX, DEC },
> +    RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
>      COMMON_OPTS(),
>      { NULL },
>  };
> @@ -1985,9 +1987,10 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
>  {
>      RTSPState *rt = s->priv_data;
>      RTSPStream *rtsp_st;
> -    int n, i, ret, timeout_cnt = 0;
> +    int n, i, ret;
>      struct pollfd *p = rt->p;
>      int *fds = NULL, fdsnum, fdsidx;

> +    int runs = rt->initial_timeout * 1000LL / POLL_TIMEOUT_MS;

This is not correct for rtsp. Default value for for rt->initial_timeout in rtsp is -1.

Setting rt->intial_timeout in rtsp is also used to infer listen mode in
rtsp_read_header().

>  
>      if (!p) {
>          p = rt->p = av_malloc_array(2 * rt->nb_rtsp_streams + 1, sizeof(struct pollfd));
> @@ -2028,7 +2031,6 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
>          n = poll(p, rt->max_p, POLL_TIMEOUT_MS);
>          if (n > 0) {
>              int j = rt->rtsp_hd ? 1 : 0;
> -            timeout_cnt = 0;
>              for (i = 0; i < rt->nb_rtsp_streams; i++) {
>                  rtsp_st = rt->rtsp_streams[i];
>                  if (rtsp_st->rtp_handle) {
> @@ -2049,7 +2051,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
>                  }
>              }
>  #endif
> -        } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
> +        } else if (n == 0 && --runs <= 0) {
>              return AVERROR(ETIMEDOUT);
>          } else if (n < 0 && errno != EINTR)
>              return AVERROR(errno);
> 
> _______________________________________________
> ffmpeg-cvslog mailing list
> ffmpeg-cvslog at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
> 
> To unsubscribe, visit link above, or email
> ffmpeg-cvslog-request at ffmpeg.org with subject "unsubscribe".

-- 
Andriy


More information about the ffmpeg-devel mailing list