You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
rtpproto: Simplify the rtp_read function by looping over the fds
This avoids having duplicate code where only the fd parameter differs. Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
@@ -324,7 +324,7 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
RTPContext *s = h->priv_data;
|
RTPContext *s = h->priv_data;
|
||||||
struct sockaddr_storage from;
|
struct sockaddr_storage from;
|
||||||
socklen_t from_len;
|
socklen_t from_len;
|
||||||
int len, n;
|
int len, n, i;
|
||||||
struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}};
|
struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}};
|
||||||
int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : 100;
|
int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : 100;
|
||||||
|
|
||||||
@@ -333,10 +333,12 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
return AVERROR_EXIT;
|
return AVERROR_EXIT;
|
||||||
n = poll(p, 2, poll_delay);
|
n = poll(p, 2, poll_delay);
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
/* first try RTCP */
|
/* first try RTCP, then RTP */
|
||||||
if (p[1].revents & POLLIN) {
|
for (i = 1; i >= 0; i--) {
|
||||||
|
if (!(p[i].revents & POLLIN))
|
||||||
|
continue;
|
||||||
from_len = sizeof(from);
|
from_len = sizeof(from);
|
||||||
len = recvfrom (s->rtcp_fd, buf, size, 0,
|
len = recvfrom(p[i].fd, buf, size, 0,
|
||||||
(struct sockaddr *)&from, &from_len);
|
(struct sockaddr *)&from, &from_len);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() == AVERROR(EAGAIN) ||
|
if (ff_neterrno() == AVERROR(EAGAIN) ||
|
||||||
@@ -346,22 +348,7 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
}
|
}
|
||||||
if (rtp_check_source_lists(s, &from))
|
if (rtp_check_source_lists(s, &from))
|
||||||
continue;
|
continue;
|
||||||
break;
|
return len;
|
||||||
}
|
|
||||||
/* then RTP */
|
|
||||||
if (p[0].revents & POLLIN) {
|
|
||||||
from_len = sizeof(from);
|
|
||||||
len = recvfrom (s->rtp_fd, buf, size, 0,
|
|
||||||
(struct sockaddr *)&from, &from_len);
|
|
||||||
if (len < 0) {
|
|
||||||
if (ff_neterrno() == AVERROR(EAGAIN) ||
|
|
||||||
ff_neterrno() == AVERROR(EINTR))
|
|
||||||
continue;
|
|
||||||
return AVERROR(EIO);
|
|
||||||
}
|
|
||||||
if (rtp_check_source_lists(s, &from))
|
|
||||||
continue;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else if (n < 0) {
|
} else if (n < 0) {
|
||||||
if (ff_neterrno() == AVERROR(EINTR))
|
if (ff_neterrno() == AVERROR(EINTR))
|
||||||
|
Reference in New Issue
Block a user