History

rtpproto: Simplify the rtp_read function by looping over the fds

This avoids having duplicate code where only the fd parameter differs.

Martin Storsjö committed 13 years ago

Commit 892b0be1 parent 75315881 file · +6 −19Browse files

Unified · Split

libavformat/rtpproto.c+6−19
@@ -324,7 +324,7 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) · 323 unmodified lines
324324 RTPContext *s = h->priv_data;
325325 struct sockaddr_storage from;
326326 socklen_t from_len;
327− int len, n;
327+ int len, n, i;
328328 struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}};
329329 int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : 100;
330330
@@ -333,25 +333,12 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) · 2 unmodified lines
333333 return AVERROR_EXIT;
334334 n = poll(p, 2, poll_delay);
335335 if (n > 0) {
336− /* first try RTCP */
337− if (p[1].revents & POLLIN) {
338− from_len = sizeof(from);
339− len = recvfrom (s->rtcp_fd, buf, size, 0,
340− (struct sockaddr *)&from, &from_len);
341− if (len < 0) {
342− if (ff_neterrno() == AVERROR(EAGAIN) ||
343− ff_neterrno() == AVERROR(EINTR))
344− continue;
345− return AVERROR(EIO);
346− }
347− if (rtp_check_source_lists(s, &from))
336+ /* first try RTCP, then RTP */
337+ for (i = 1; i >= 0; i--) {
338+ if (!(p[i].revents & POLLIN))
348339 continue;
349− break;
350− }
351− /* then RTP */
352− if (p[0].revents & POLLIN) {
353340 from_len = sizeof(from);
354− len = recvfrom (s->rtp_fd, buf, size, 0,
341+ len = recvfrom(p[i].fd, buf, size, 0,
355342 (struct sockaddr *)&from, &from_len);
356343 if (len < 0) {
357344 if (ff_neterrno() == AVERROR(EAGAIN) ||
@@ -361,7 +348,7 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) · 3 unmodified lines
361348 }
362349 if (rtp_check_source_lists(s, &from))
363350 continue;
364− break;
351+ return len;
365352 }
366353 } else if (n < 0) {
367354 if (ff_neterrno() == AVERROR(EINTR))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t