You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
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@gmail.com>
This commit is contained in:
@@ -55,7 +55,6 @@
|
|||||||
* and read_packet(), in seconds */
|
* and read_packet(), in seconds */
|
||||||
#define POLL_TIMEOUT_MS 100
|
#define POLL_TIMEOUT_MS 100
|
||||||
#define READ_PACKET_TIMEOUT_S 10
|
#define READ_PACKET_TIMEOUT_S 10
|
||||||
#define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / POLL_TIMEOUT_MS
|
|
||||||
#define SDP_MAX_SIZE 16384
|
#define SDP_MAX_SIZE 16384
|
||||||
#define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH
|
#define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH
|
||||||
#define DEFAULT_REORDERING_DELAY 100000
|
#define DEFAULT_REORDERING_DELAY 100000
|
||||||
@@ -115,6 +114,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 },
|
||||||
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 },
|
||||||
@@ -122,6 +122,8 @@ 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 },
|
||||||
|
RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
|
||||||
COMMON_OPTS(),
|
COMMON_OPTS(),
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
@@ -1985,9 +1987,10 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
|
|||||||
{
|
{
|
||||||
RTSPState *rt = s->priv_data;
|
RTSPState *rt = s->priv_data;
|
||||||
RTSPStream *rtsp_st;
|
RTSPStream *rtsp_st;
|
||||||
int n, i, ret, timeout_cnt = 0;
|
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 / POLL_TIMEOUT_MS;
|
||||||
|
|
||||||
if (!p) {
|
if (!p) {
|
||||||
p = rt->p = av_malloc_array(2 * rt->nb_rtsp_streams + 1, sizeof(struct pollfd));
|
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);
|
n = poll(p, rt->max_p, POLL_TIMEOUT_MS);
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
int j = rt->rtsp_hd ? 1 : 0;
|
int j = rt->rtsp_hd ? 1 : 0;
|
||||||
timeout_cnt = 0;
|
|
||||||
for (i = 0; i < rt->nb_rtsp_streams; i++) {
|
for (i = 0; i < rt->nb_rtsp_streams; i++) {
|
||||||
rtsp_st = rt->rtsp_streams[i];
|
rtsp_st = rt->rtsp_streams[i];
|
||||||
if (rtsp_st->rtp_handle) {
|
if (rtsp_st->rtp_handle) {
|
||||||
@@ -2049,7 +2051,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
|
} else if (n == 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);
|
||||||
|
Reference in New Issue
Block a user