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
324 RTPContext *s = h->priv_data;324 RTPContext *s = h->priv_data;
325 struct sockaddr_storage from;325 struct sockaddr_storage from;
326 socklen_t from_len;326 socklen_t from_len;
327 int len, n;327 int len, n, i;
328 struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}};328 struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}};
329 int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : 100;329 int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : 100;
330 330
@@ -333,25 +333,12 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) · 2 unmodified lines
333 return AVERROR_EXIT;333 return AVERROR_EXIT;
334 n = poll(p, 2, poll_delay);334 n = poll(p, 2, poll_delay);
335 if (n > 0) {335 if (n > 0) {
336 /* first try RTCP */336 /* first try RTCP, then RTP */
337 if (p[1].revents & POLLIN) {337 for (i = 1; i >= 0; i--) {
338 from_len = sizeof(from);338 if (!(p[i].revents & POLLIN))
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))
348 continue;339 continue;
349 break;
350 }
351 /* then RTP */
352 if (p[0].revents & POLLIN) {
353 from_len = sizeof(from);340 from_len = sizeof(from);
354 len = recvfrom (s->rtp_fd, buf, size, 0,341 len = recvfrom(p[i].fd, buf, size, 0,
355 (struct sockaddr *)&from, &from_len);342 (struct sockaddr *)&from, &from_len);
356 if (len < 0) {343 if (len < 0) {
357 if (ff_neterrno() == AVERROR(EAGAIN) ||344 if (ff_neterrno() == AVERROR(EAGAIN) ||
@@ -361,7 +348,7 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) · 3 unmodified lines
361 }348 }
362 if (rtp_check_source_lists(s, &from))349 if (rtp_check_source_lists(s, &from))
363 continue;350 continue;
364 break;351 return len;
365 }352 }
366 } else if (n < 0) {353 } else if (n < 0) {
367 if (ff_neterrno() == AVERROR(EINTR))354 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