Revision 576ae256 libavformat/aviobuf.c

View differences:

libavformat/aviobuf.c
28 28
                  int write_flag,
29 29
                  void *opaque,
30 30
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
31
                  void (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
31
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
32 32
                  int (*seek)(void *opaque, offset_t offset, int whence))
33 33
{
34 34
    s->buffer = buffer;
......
46 46
    s->pos = 0;
47 47
    s->must_flush = 0;
48 48
    s->eof_reached = 0;
49
    s->error = 0;
49 50
    s->is_streamed = 0;
50 51
    s->max_packet_size = 0;
51 52
    s->update_checksum= NULL;
......
57 58
static void flush_buffer(ByteIOContext *s)
58 59
{
59 60
    if (s->buf_ptr > s->buffer) {
60
        if (s->write_packet)
61
            s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
61
        if (s->write_packet && !s->error){
62
            int ret= s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
63
            if(ret < 0){
64
                s->error = ret;
65
            }
66
        }
62 67
        if(s->update_checksum){
63 68
            s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
64 69
            s->checksum_ptr= s->buffer;
......
172 177
    return s->eof_reached;
173 178
}
174 179

  
180
int url_ferror(ByteIOContext *s)
181
{
182
    return s->error;
183
}
184

  
175 185
#ifdef CONFIG_ENCODERS
176 186
void put_le32(ByteIOContext *s, unsigned int val)
177 187
{
......
260 270
        /* do not modify buffer if EOF reached so that a seek back can
261 271
           be done without rereading data */
262 272
        s->eof_reached = 1;
273
    if(len<0)
274
        s->error= len;
263 275
    } else {
264 276
        s->pos += len;
265 277
        s->buf_ptr = s->buffer;
......
432 444
/* link with avio functions */
433 445

  
434 446
#ifdef CONFIG_ENCODERS
435
static void url_write_packet(void *opaque, uint8_t *buf, int buf_size)
447
static int url_write_packet(void *opaque, uint8_t *buf, int buf_size)
436 448
{
437 449
    URLContext *h = opaque;
438
    url_write(h, buf, buf_size);
450
    return url_write(h, buf, buf_size);
439 451
}
440 452
#else
441 453
#define	url_write_packet NULL
......
609 621
    uint8_t io_buffer[1];
610 622
} DynBuffer;
611 623

  
612
static void dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
624
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
613 625
{
614 626
    DynBuffer *d = opaque;
615 627
    int new_size, new_allocated_size;
......
627 639
    if (new_allocated_size > d->allocated_size) {
628 640
        d->buffer = av_realloc(d->buffer, new_allocated_size);
629 641
        if(d->buffer == NULL)
630
             return ;
642
             return -1234;
631 643
        d->allocated_size = new_allocated_size;
632 644
    }
633 645
    memcpy(d->buffer + d->pos, buf, buf_size);
634 646
    d->pos = new_size;
635 647
    if (d->pos > d->size)
636 648
        d->size = d->pos;
649
    return buf_size;
637 650
}
638 651

  
639
static void dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
652
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
640 653
{
641 654
    unsigned char buf1[4];
655
    int ret;
642 656

  
643 657
    /* packetized write: output the header */
644 658
    buf1[0] = (buf_size >> 24);
645 659
    buf1[1] = (buf_size >> 16);
646 660
    buf1[2] = (buf_size >> 8);
647 661
    buf1[3] = (buf_size);
648
    dyn_buf_write(opaque, buf1, 4);
662
    ret= dyn_buf_write(opaque, buf1, 4);
663
    if(ret < 0)
664
        return ret;
649 665

  
650 666
    /* then the data */
651
    dyn_buf_write(opaque, buf, buf_size);
667
    return dyn_buf_write(opaque, buf, buf_size);
652 668
}
653 669

  
654 670
static int dyn_buf_seek(void *opaque, offset_t offset, int whence)

Also available in: Unified diff