Revision 576ae256

View differences:

libavformat/avformat.h
5 5
extern "C" {
6 6
#endif
7 7

  
8
#define LIBAVFORMAT_BUILD       4617
8
#define LIBAVFORMAT_BUILD       4618
9 9

  
10 10
#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
11 11
#define LIBAVFORMAT_VERSION     FFMPEG_VERSION
libavformat/avio.h
70 70
    unsigned char *buf_ptr, *buf_end;
71 71
    void *opaque;
72 72
    int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
73
    void (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
73
    int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
74 74
    int (*seek)(void *opaque, offset_t offset, int whence);
75 75
    offset_t pos; /* position in the file of the current buffer */
76 76
    int must_flush; /* true if the next seek should flush */
......
81 81
    unsigned long checksum;
82 82
    unsigned char *checksum_ptr;
83 83
    unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
84
    int error;         ///< contains the error code or 0 if no error happened
84 85
} ByteIOContext;
85 86

  
86 87
int init_put_byte(ByteIOContext *s,
......
89 90
                  int write_flag,
90 91
                  void *opaque,
91 92
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
92
                  void (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
93
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
93 94
                  int (*seek)(void *opaque, offset_t offset, int whence));
94 95

  
95 96
void put_byte(ByteIOContext *s, int b);
......
109 110
void url_fskip(ByteIOContext *s, offset_t offset);
110 111
offset_t url_ftell(ByteIOContext *s);
111 112
int url_feof(ByteIOContext *s);
113
int url_ferror(ByteIOContext *s);
112 114

  
113 115
#define URL_EOF (-1)
114 116
int url_fgetc(ByteIOContext *s);
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)
libavformat/utils.c
1996 1996
 */
1997 1997
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
1998 1998
{
1999
    int ret;
2000

  
1999 2001
    compute_pkt_fields2(s->streams[pkt->stream_index], pkt);
2000 2002
    
2001 2003
    truncate_ts(s->streams[pkt->stream_index], pkt);
2002 2004

  
2003
    return s->oformat->write_packet(s, pkt);
2005
    ret= s->oformat->write_packet(s, pkt);
2006
    if(!ret)
2007
        ret= url_ferror(&s->pb);
2008
    return ret;
2004 2009
}
2005 2010

  
2006 2011
/**
......
2111 2116
        
2112 2117
        if(ret<0)
2113 2118
            return ret;
2119
        if(url_ferror(&s->pb))
2120
            return url_ferror(&s->pb);
2114 2121
    }
2115 2122
}
2116 2123

  
......
2139 2146
        
2140 2147
        if(ret<0)
2141 2148
            goto fail;
2149
        if(url_ferror(&s->pb))
2150
            goto fail;
2142 2151
    }
2143 2152

  
2144 2153
    ret = s->oformat->write_trailer(s);
2145 2154
fail:
2155
    if(ret == 0)
2156
       ret=url_ferror(&s->pb);
2146 2157
    for(i=0;i<s->nb_streams;i++)
2147 2158
        av_freep(&s->streams[i]->priv_data);
2148 2159
    av_freep(&s->priv_data);

Also available in: Unified diff