This avoids having duplicate code where only the fd parameter differs.
Unified · Split
| @@ -324,7 +324,7 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) · 323 unmodified lines | ||
| 324 | 324 | RTPContext *s = h->priv_data; |
| 325 | 325 | struct sockaddr_storage from; |
| 326 | 326 | socklen_t from_len; |
| 327 | − int len, n; | |
| 327 | + int len, n, i; | |
| 328 | 328 | struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}}; |
| 329 | 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 | 333 | return AVERROR_EXIT; |
| 334 | 334 | n = poll(p, 2, poll_delay); |
| 335 | 335 | 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)) | |
| 348 | 339 | continue; |
| 349 | − break; | |
| 350 | − } | |
| 351 | − /* then RTP */ | |
| 352 | − if (p[0].revents & POLLIN) { | |
| 353 | 340 | from_len = sizeof(from); |
| 354 | − len = recvfrom (s->rtp_fd, buf, size, 0, | |
| 341 | + len = recvfrom(p[i].fd, buf, size, 0, | |
| 355 | 342 | (struct sockaddr *)&from, &from_len); |
| 356 | 343 | if (len < 0) { |
| 357 | 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 | 349 | if (rtp_check_source_lists(s, &from)) |
| 363 | 350 | continue; |
| 364 | − break; | |
| 351 | + return len; | |
| 365 | 352 | } |
| 366 | 353 | } else if (n < 0) { |
| 367 | 354 | if (ff_neterrno() == AVERROR(EINTR)) |