rtsp: Lazily set up the pollfd array once

This commit is contained in:
Luca Barbato 2017-02-20 02:16:28 +01:00
parent d8f36a6aa3
commit 79331df362
2 changed files with 27 additions and 27 deletions

View File

@ -1913,7 +1913,6 @@ 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, tcp_fd, timeout_cnt = 0; int n, i, ret, tcp_fd, timeout_cnt = 0;
int max_p = 0;
struct pollfd *p = rt->p; struct pollfd *p = rt->p;
int *fds = NULL, fdsnum, fdsidx; int *fds = NULL, fdsnum, fdsidx;
@ -1921,12 +1920,11 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
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));
if (!p) if (!p)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
}
if (rt->rtsp_hd) { if (rt->rtsp_hd) {
tcp_fd = ffurl_get_file_handle(rt->rtsp_hd); tcp_fd = ffurl_get_file_handle(rt->rtsp_hd);
p[max_p].fd = tcp_fd; p[rt->max_p].fd = tcp_fd;
p[max_p++].events = POLLIN; p[rt->max_p++].events = POLLIN;
} else { } else {
tcp_fd = -1; tcp_fd = -1;
} }
@ -1944,19 +1942,20 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
for (fdsidx = 0; fdsidx < fdsnum; fdsidx++) { for (fdsidx = 0; fdsidx < fdsnum; fdsidx++) {
p[max_p].fd = fds[fdsidx]; p[rt->max_p].fd = fds[fdsidx];
p[max_p++].events = POLLIN; p[rt->max_p++].events = POLLIN;
} }
av_free(fds); av_free(fds);
} }
} }
}
for (;;) { for (;;) {
if (ff_check_interrupt(&s->interrupt_callback)) if (ff_check_interrupt(&s->interrupt_callback))
return AVERROR_EXIT; return AVERROR_EXIT;
if (wait_end && wait_end - av_gettime_relative() < 0) if (wait_end && wait_end - av_gettime_relative() < 0)
return AVERROR(EAGAIN); return AVERROR(EAGAIN);
n = poll(p, max_p, POLL_TIMEOUT_MS); n = poll(p, rt->max_p, POLL_TIMEOUT_MS);
if (n > 0) { if (n > 0) {
int j = 1 - (tcp_fd == -1); int j = 1 - (tcp_fd == -1);
timeout_cnt = 0; timeout_cnt = 0;

View File

@ -352,6 +352,7 @@ typedef struct RTSPState {
* Polling array for udp * Polling array for udp
*/ */
struct pollfd *p; struct pollfd *p;
int max_p;
/** /**
* Whether the server supports the GET_PARAMETER method. * Whether the server supports the GET_PARAMETER method.