mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-24 08:12:44 +00:00
avformat/rtsp: Fix timeout option
92c40ef882
added a listen_timeout option for sdp. This allowed a user to set variable timeout which was originally hard coded to 10 seconds. The commit used the initial_timeout variable to store the value. But this variable is shared with rtsp where it's used to infer a "listen" mode. Thus, the timeout value could not be set in rtsp, and the default value (initial_timeout = -1) would give 100ms timeout. This was attempted to be fixed inc8101aabee
, which changed the meaning of initial_timeout = -1 to be an infinite timeout. However, it did not address the issue that the timeout could still not be set. Being able to set the timeout is useful because it allows to automatically reconfigure from a udp to tcp connection in the lower transport. In this commit this is fixed by using the stimeout variable to store the timeout value. Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
This commit is contained in:
parent
041267b558
commit
8257d6dda6
@ -94,7 +94,7 @@ const AVOption ff_rtsp_options[] = {
|
|||||||
{ "min_port", "set minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
|
{ "min_port", "set minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
|
||||||
{ "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
|
{ "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
|
||||||
{ "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections (-1 is infinite, imply flag listen)", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC },
|
{ "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections (-1 is infinite, imply flag listen)", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC },
|
||||||
{ "timeout", "set timeout (in microseconds) of socket TCP I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC },
|
{ "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT64, {.i64 = 0}, INT_MIN, INT64_MAX, DEC },
|
||||||
COMMON_OPTS(),
|
COMMON_OPTS(),
|
||||||
{ "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, DEC },
|
{ "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, DEC },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
@ -104,7 +104,7 @@ static const AVOption sdp_options[] = {
|
|||||||
RTSP_FLAG_OPTS("sdp_flags", "SDP flags"),
|
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" },
|
{ "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" },
|
{ "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 },
|
{ "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(stimeout), AV_OPT_TYPE_DURATION, {.i64 = READ_PACKET_TIMEOUT_S*1000000}, INT_MIN, INT64_MAX, DEC },
|
||||||
RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
|
RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
|
||||||
COMMON_OPTS(),
|
COMMON_OPTS(),
|
||||||
{ NULL },
|
{ NULL },
|
||||||
@ -112,7 +112,7 @@ static const AVOption sdp_options[] = {
|
|||||||
|
|
||||||
static const AVOption rtp_options[] = {
|
static const AVOption rtp_options[] = {
|
||||||
RTSP_FLAG_OPTS("rtp_flags", "set RTP flags"),
|
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 },
|
{ "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(stimeout), AV_OPT_TYPE_DURATION, {.i64 = READ_PACKET_TIMEOUT_S*1000000}, INT_MIN, INT64_MAX, DEC },
|
||||||
RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
|
RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
|
||||||
COMMON_OPTS(),
|
COMMON_OPTS(),
|
||||||
{ NULL },
|
{ NULL },
|
||||||
@ -1874,7 +1874,7 @@ redirect:
|
|||||||
/* open the tcp connection */
|
/* open the tcp connection */
|
||||||
ff_url_join(tcpname, sizeof(tcpname), lower_rtsp_proto, NULL,
|
ff_url_join(tcpname, sizeof(tcpname), lower_rtsp_proto, NULL,
|
||||||
host, port,
|
host, port,
|
||||||
"?timeout=%d", rt->stimeout);
|
"?timeout=%"PRId64, rt->stimeout);
|
||||||
if ((ret = ffurl_open_whitelist(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
|
if ((ret = ffurl_open_whitelist(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
|
||||||
&s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL)) < 0) {
|
&s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL)) < 0) {
|
||||||
err = ret;
|
err = ret;
|
||||||
@ -2027,7 +2027,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
|
|||||||
int n, i, ret;
|
int n, i, ret;
|
||||||
struct pollfd *p = rt->p;
|
struct pollfd *p = rt->p;
|
||||||
int *fds = NULL, fdsnum, fdsidx;
|
int *fds = NULL, fdsnum, fdsidx;
|
||||||
int runs = rt->initial_timeout * 1000LL / POLLING_TIME;
|
int64_t runs = rt->stimeout / POLLING_TIME / 1000;
|
||||||
|
|
||||||
if (!p) {
|
if (!p) {
|
||||||
p = rt->p = av_malloc_array(2 * rt->nb_rtsp_streams + 1, sizeof(*p));
|
p = rt->p = av_malloc_array(2 * rt->nb_rtsp_streams + 1, sizeof(*p));
|
||||||
@ -2088,7 +2088,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (n == 0 && rt->initial_timeout > 0 && --runs <= 0) {
|
} else if (n == 0 && rt->stimeout > 0 && --runs <= 0) {
|
||||||
return AVERROR(ETIMEDOUT);
|
return AVERROR(ETIMEDOUT);
|
||||||
} else if (n < 0 && errno != EINTR)
|
} else if (n < 0 && errno != EINTR)
|
||||||
return AVERROR(errno);
|
return AVERROR(errno);
|
||||||
|
@ -404,7 +404,7 @@ typedef struct RTSPState {
|
|||||||
/**
|
/**
|
||||||
* timeout of socket i/o operations.
|
* timeout of socket i/o operations.
|
||||||
*/
|
*/
|
||||||
int stimeout;
|
int64_t stimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of RTP packet reordering queue.
|
* Size of RTP packet reordering queue.
|
||||||
|
Loading…
Reference in New Issue
Block a user