avio: K&R cosmetic formatting

This commit is contained in:
Luca Barbato 2012-12-09 04:15:45 +01:00
parent 91ac403b13
commit 1dd1c1c884

View File

@ -76,27 +76,31 @@ int ffio_init_context(AVIOContext *s,
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
int64_t (*seek)(void *opaque, int64_t offset, int whence)) int64_t (*seek)(void *opaque, int64_t offset, int whence))
{ {
s->buffer = buffer; s->buffer = buffer;
s->buffer_size = buffer_size; s->buffer_size = buffer_size;
s->buf_ptr = buffer; s->buf_ptr = buffer;
s->opaque = opaque; s->opaque = opaque;
url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ); url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
s->write_packet = write_packet;
s->read_packet = read_packet; s->write_packet = write_packet;
s->seek = seek; s->read_packet = read_packet;
s->pos = 0; s->seek = seek;
s->must_flush = 0; s->pos = 0;
s->eof_reached = 0; s->must_flush = 0;
s->error = 0; s->eof_reached = 0;
s->seekable = AVIO_SEEKABLE_NORMAL; s->error = 0;
s->seekable = AVIO_SEEKABLE_NORMAL;
s->max_packet_size = 0; s->max_packet_size = 0;
s->update_checksum= NULL; s->update_checksum = NULL;
if(!read_packet && !write_flag){
s->pos = buffer_size; if (!read_packet && !write_flag) {
s->pos = buffer_size;
s->buf_end = s->buffer + buffer_size; s->buf_end = s->buffer + buffer_size;
} }
s->read_pause = NULL; s->read_pause = NULL;
s->read_seek = NULL; s->read_seek = NULL;
return 0; return 0;
} }
@ -120,15 +124,17 @@ AVIOContext *avio_alloc_context(
static void flush_buffer(AVIOContext *s) static void flush_buffer(AVIOContext *s)
{ {
if (s->buf_ptr > s->buffer) { if (s->buf_ptr > s->buffer) {
if (s->write_packet && !s->error){ if (s->write_packet && !s->error) {
int ret= s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer); int ret = s->write_packet(s->opaque, s->buffer,
if(ret < 0){ s->buf_ptr - s->buffer);
if (ret < 0) {
s->error = ret; s->error = ret;
} }
} }
if(s->update_checksum){ if (s->update_checksum) {
s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr); s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
s->checksum_ptr= s->buffer; s->buf_ptr - s->checksum_ptr);
s->checksum_ptr = s->buffer;
} }
s->pos += s->buf_ptr - s->buffer; s->pos += s->buf_ptr - s->buffer;
} }
@ -236,13 +242,13 @@ int64_t avio_size(AVIOContext *s)
{ {
int64_t size; int64_t size;
if(!s) if (!s)
return AVERROR(EINVAL); return AVERROR(EINVAL);
if (!s->seek) if (!s->seek)
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
size = s->seek(s->opaque, 0, AVSEEK_SIZE); size = s->seek(s->opaque, 0, AVSEEK_SIZE);
if(size<0){ if (size < 0) {
if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0) if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
return size; return size;
size++; size++;
@ -288,29 +294,31 @@ int avio_put_str16le(AVIOContext *s, const char *str)
uint16_t tmp; uint16_t tmp;
GET_UTF8(ch, *q++, break;) GET_UTF8(ch, *q++, break;)
PUT_UTF16(ch, tmp, avio_wl16(s, tmp);ret += 2;) PUT_UTF16(ch, tmp, avio_wl16(s, tmp); ret += 2;)
} }
avio_wl16(s, 0); avio_wl16(s, 0);
ret += 2; ret += 2;
return ret; return ret;
} }
int ff_get_v_length(uint64_t val){ int ff_get_v_length(uint64_t val)
int i=1; {
int i = 1;
while(val>>=7) while (val >>= 7)
i++; i++;
return i; return i;
} }
void ff_put_v(AVIOContext *bc, uint64_t val){ void ff_put_v(AVIOContext *bc, uint64_t val)
int i= ff_get_v_length(val); {
int i = ff_get_v_length(val);
while(--i>0) while (--i > 0)
avio_w8(bc, 128 | (val>>(7*i))); avio_w8(bc, 128 | (val >> (7 * i)));
avio_w8(bc, val&127); avio_w8(bc, val & 127);
} }
void avio_wl64(AVIOContext *s, uint64_t val) void avio_wl64(AVIOContext *s, uint64_t val)
@ -353,9 +361,12 @@ void avio_wb24(AVIOContext *s, unsigned int val)
static void fill_buffer(AVIOContext *s) static void fill_buffer(AVIOContext *s)
{ {
uint8_t *dst= !s->max_packet_size && s->buf_end - s->buffer < s->buffer_size ? s->buf_end : s->buffer; uint8_t *dst = !s->max_packet_size &&
int len= s->buffer_size - (dst - s->buffer); s->buf_end - s->buffer < s->buffer_size ?
int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE; s->buf_end : s->buffer;
int len = s->buffer_size - (dst - s->buffer);
int max_buffer_size = s->max_packet_size ?
s->max_packet_size : IO_BUFFER_SIZE;
/* can't fill the buffer without read_packet, just set EOF if appropiate */ /* can't fill the buffer without read_packet, just set EOF if appropiate */
if (!s->read_packet && s->buf_ptr >= s->buf_end) if (!s->read_packet && s->buf_ptr >= s->buf_end)
@ -365,10 +376,11 @@ static void fill_buffer(AVIOContext *s)
if (s->eof_reached) if (s->eof_reached)
return; return;
if(s->update_checksum && dst == s->buffer){ if (s->update_checksum && dst == s->buffer) {
if(s->buf_end > s->checksum_ptr) if (s->buf_end > s->checksum_ptr)
s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_end - s->checksum_ptr); s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
s->checksum_ptr= s->buffer; s->buf_end - s->checksum_ptr);
s->checksum_ptr = s->buffer;
} }
/* make buffer smaller in case it ended up large after probing */ /* make buffer smaller in case it ended up large after probing */
@ -379,7 +391,7 @@ static void fill_buffer(AVIOContext *s)
len = s->buffer_size; len = s->buffer_size;
} }
if(s->read_packet) if (s->read_packet)
len = s->read_packet(s->opaque, dst, len); len = s->read_packet(s->opaque, dst, len);
else else
len = 0; len = 0;
@ -387,8 +399,8 @@ static void fill_buffer(AVIOContext *s)
/* do not modify buffer if EOF reached so that a seek back can /* do not modify buffer if EOF reached so that a seek back can
be done without rereading data */ be done without rereading data */
s->eof_reached = 1; s->eof_reached = 1;
if(len<0) if (len < 0)
s->error= len; s->error = len;
} else { } else {
s->pos += len; s->pos += len;
s->buf_ptr = dst; s->buf_ptr = dst;
@ -404,8 +416,9 @@ unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
unsigned long ffio_get_checksum(AVIOContext *s) unsigned long ffio_get_checksum(AVIOContext *s)
{ {
s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr); s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
s->update_checksum= NULL; s->buf_ptr - s->checksum_ptr);
s->update_checksum = NULL;
return s->checksum; return s->checksum;
} }
@ -413,10 +426,10 @@ void ffio_init_checksum(AVIOContext *s,
unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
unsigned long checksum) unsigned long checksum)
{ {
s->update_checksum= update_checksum; s->update_checksum = update_checksum;
if(s->update_checksum){ if (s->update_checksum) {
s->checksum= checksum; s->checksum = checksum;
s->checksum_ptr= s->buf_ptr; s->checksum_ptr = s->buf_ptr;
} }
} }
@ -457,7 +470,7 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size)
s->buf_ptr = s->buffer; s->buf_ptr = s->buffer;
s->buf_end = s->buffer/* + len*/; s->buf_end = s->buffer/* + len*/;
} }
}else{ } else {
fill_buffer(s); fill_buffer(s);
len = s->buf_end - s->buf_ptr; len = s->buf_end - s->buf_ptr;
if (len == 0) if (len == 0)
@ -481,7 +494,7 @@ int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
{ {
int len; int len;
if(size<0) if (size < 0)
return -1; return -1;
len = s->buf_end - s->buf_ptr; len = s->buf_end - s->buf_ptr;
@ -801,7 +814,7 @@ int64_t avio_seek_time(AVIOContext *s, int stream_index,
if (!s->read_seek) if (!s->read_seek)
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
ret = s->read_seek(h, stream_index, timestamp, flags); ret = s->read_seek(h, stream_index, timestamp, flags);
if(ret >= 0) { if (ret >= 0) {
int64_t pos; int64_t pos;
s->buf_ptr = s->buf_end; // Flush buffer s->buf_ptr = s->buf_end; // Flush buffer
pos = s->seek(h, 0, SEEK_CUR); pos = s->seek(h, 0, SEEK_CUR);
@ -830,7 +843,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
/* reallocate buffer if needed */ /* reallocate buffer if needed */
new_size = d->pos + buf_size; new_size = d->pos + buf_size;
new_allocated_size = d->allocated_size; new_allocated_size = d->allocated_size;
if(new_size < d->pos || new_size > INT_MAX/2) if (new_size < d->pos || new_size > INT_MAX/2)
return -1; return -1;
while (new_size > new_allocated_size) { while (new_size > new_allocated_size) {
if (!new_allocated_size) if (!new_allocated_size)
@ -859,8 +872,8 @@ static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
/* packetized write: output the header */ /* packetized write: output the header */
AV_WB32(buf1, buf_size); AV_WB32(buf1, buf_size);
ret= dyn_buf_write(opaque, buf1, 4); ret = dyn_buf_write(opaque, buf1, 4);
if(ret < 0) if (ret < 0)
return ret; return ret;
/* then the data */ /* then the data */
@ -886,7 +899,7 @@ static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
DynBuffer *d; DynBuffer *d;
unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024; unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size) if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
return -1; return -1;
d = av_mallocz(sizeof(DynBuffer) + io_buffer_size); d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
if (!d) if (!d)