Skip to content

Commit

Permalink
Use AVERROR_EXIT with url_interrupt_cb.
Browse files Browse the repository at this point in the history
Functions interrupted by url_interrupt_cb should not be restarted.
Therefore using AVERROR(EINTR) was wrong, as it did not allow to distinguish
when the underlying system call was interrupted and actually needed to be
restarted.

This fixes roundup issues 2657 and 2659 (ffplay not exiting for streamed
content).

Signed-off-by: Nicolas George <[email protected]>
Signed-off-by: Ronald S. Bultje <[email protected]>
  • Loading branch information
Nicolas George authored and rbultje committed Mar 15, 2011
1 parent bafa4dd commit c76374c
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion libavformat/applehttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static int applehttp_read_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR_EOF;
while (av_gettime() - c->last_load_time < c->target_duration*1000000) {
if (url_interrupt_cb())
return AVERROR(EINTR);
return AVERROR_EXIT;
usleep(100*1000);
}
/* Enough time has elapsed since the last reload */
Expand Down
4 changes: 2 additions & 2 deletions libavformat/applehttpproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static int applehttp_read(URLContext *h, uint8_t *buf, int size)
return AVERROR_EOF;
while (av_gettime() - s->last_load_time < s->target_duration*1000000) {
if (url_interrupt_cb())
return AVERROR(EINTR);
return AVERROR_EXIT;
usleep(100*1000);
}
goto retry;
Expand All @@ -328,7 +328,7 @@ static int applehttp_read(URLContext *h, uint8_t *buf, int size)
ret = url_open(&s->seg_hd, url, URL_RDONLY);
if (ret < 0) {
if (url_interrupt_cb())
return AVERROR(EINTR);
return AVERROR_EXIT;
av_log(NULL, AV_LOG_WARNING, "Unable to open %s\n", url);
s->cur_seq_no++;
goto retry;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/avio.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int
fast_retries = FFMAX(fast_retries, 2);
len += ret;
if (url_interrupt_cb())
return AVERROR(EINTR);
return AVERROR_EXIT;
}
return len;
}
Expand Down
2 changes: 1 addition & 1 deletion libavformat/avio.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void url_get_filename(URLContext *h, char *buf, int buf_size);

/**
* The callback is called in blocking functions to test regulary if
* asynchronous interruption is needed. AVERROR(EINTR) is returned
* asynchronous interruption is needed. AVERROR_EXIT is returned
* in this case by the interrupted function. 'NULL' means no interrupt
* callback is given.
*/
Expand Down
2 changes: 1 addition & 1 deletion libavformat/rtpproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
#else
for(;;) {
if (url_interrupt_cb())
return AVERROR(EINTR);
return AVERROR_EXIT;
/* build fdset to listen to RTP and RTCP packets */
n = poll(p, 2, 100);
if (n > 0) {
Expand Down
2 changes: 1 addition & 1 deletion libavformat/rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,

for (;;) {
if (url_interrupt_cb())
return AVERROR(EINTR);
return AVERROR_EXIT;
if (wait_end && wait_end - av_gettime() < 0)
return AVERROR(EAGAIN);
max_p = 0;
Expand Down
6 changes: 4 additions & 2 deletions libavformat/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
if (ret < 0) {
struct pollfd p = {fd, POLLOUT, 0};
if (ff_neterrno() == AVERROR(EINTR)) {
if (url_interrupt_cb())
if (url_interrupt_cb()) {
ret = AVERROR_EXIT;
goto fail1;
}
goto redo;
}
if (ff_neterrno() != AVERROR(EINPROGRESS) &&
Expand All @@ -84,7 +86,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
/* wait until we are connected or until abort */
for(;;) {
if (url_interrupt_cb()) {
ret = AVERROR(EINTR);
ret = AVERROR_EXIT;
goto fail1;
}
ret = poll(&p, 1, 100);
Expand Down
2 changes: 1 addition & 1 deletion libavformat/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)

for(;;) {
if (url_interrupt_cb())
return AVERROR(EINTR);
return AVERROR_EXIT;
ret = poll(&p, 1, 100);
if (ret < 0) {
if (ff_neterrno() == AVERROR(EINTR))
Expand Down
2 changes: 1 addition & 1 deletion libavformat/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,7 @@ int av_find_stream_info(AVFormatContext *ic)
read_size = 0;
for(;;) {
if(url_interrupt_cb()){
ret= AVERROR(EINTR);
ret= AVERROR_EXIT;
av_log(ic, AV_LOG_DEBUG, "interrupted\n");
break;
}
Expand Down

0 comments on commit c76374c

Please sign in to comment.