Revision c66f53cf libavformat/aviobuf.c

View differences:

libavformat/aviobuf.c
19 19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 20
 */
21 21

  
22
/* needed for usleep() */
23
#define _XOPEN_SOURCE 600
24
#include <unistd.h>
25 22
#include "libavutil/crc.h"
26 23
#include "libavutil/intreadwrite.h"
27 24
#include "avformat.h"
......
91 88
    return s;
92 89
}
93 90

  
94
static inline int retry_transfer_wrapper(void *opaque, unsigned char *buf,
95
                                         int size,
96
                                         int (*transfer_func)(void *, unsigned char *, int)) {
97
    int fast_retries = 5;
98
    while (1) {
99
        int ret = transfer_func(opaque, buf, size);
100
        if (ret == AVERROR(EAGAIN)) {
101
            if (fast_retries)
102
                fast_retries--;
103
            else
104
                usleep(1000);
105
        } else
106
            return ret;
107
    }
108
}
109

  
110 91
static void flush_buffer(ByteIOContext *s)
111 92
{
112 93
    if (s->buf_ptr > s->buffer) {
113 94
        if (s->write_packet && !s->error){
114
            int ret= retry_transfer_wrapper(s->opaque, s->buffer,
115
                                            s->buf_ptr - s->buffer,
116
                                            s->write_packet);
95
            int ret= s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
117 96
            if(ret < 0){
118 97
                s->error = ret;
119 98
            }
......
382 361
    }
383 362

  
384 363
    if(s->read_packet)
385
        len = retry_transfer_wrapper(s->opaque, dst, len, s->read_packet);
364
        len = s->read_packet(s->opaque, dst, len);
386 365
    else
387 366
        len = 0;
388 367
    if (len <= 0) {
......
453 432
        if (len == 0) {
454 433
            if(size > s->buffer_size && !s->update_checksum){
455 434
                if(s->read_packet)
456
                    len = retry_transfer_wrapper(s->opaque, buf, size,
457
                                                 s->read_packet);
435
                    len = s->read_packet(s->opaque, buf, size);
458 436
                if (len <= 0) {
459 437
                    /* do not modify buffer if EOF reached so that a seek back can
460 438
                    be done without rereading data */

Also available in: Unified diff