int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
int64_t (*seek)(void *opaque, int64_t offset, int whence))
{
- s->buffer = buffer;
+ s->buffer = buffer;
s->buffer_size = buffer_size;
- s->buf_ptr = buffer;
- s->opaque = opaque;
- s->direct = 0;
+ s->buf_ptr = buffer;
+ s->opaque = opaque;
+ s->direct = 0;
+
url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
- s->write_packet = write_packet;
- s->read_packet = read_packet;
- s->seek = seek;
- s->pos = 0;
- s->must_flush = 0;
- s->eof_reached = 0;
- s->error = 0;
- s->seekable = AVIO_SEEKABLE_NORMAL;
+
+ s->write_packet = write_packet;
+ s->read_packet = read_packet;
+ s->seek = seek;
+ s->pos = 0;
+ s->must_flush = 0;
+ s->eof_reached = 0;
+ s->error = 0;
+ s->seekable = AVIO_SEEKABLE_NORMAL;
s->max_packet_size = 0;
- s->update_checksum= NULL;
- if(!read_packet && !write_flag){
- s->pos = buffer_size;
+ s->update_checksum = NULL;
+
+ if (!read_packet && !write_flag) {
+ s->pos = buffer_size;
s->buf_end = s->buffer + buffer_size;
}
s->read_pause = NULL;
s->read_seek = NULL;
+
return 0;
}
static void writeout(AVIOContext *s, const uint8_t *data, int len)
{
- if (s->write_packet && !s->error){
- int ret= s->write_packet(s->opaque, (uint8_t *)data, len);
- if(ret < 0){
+ if (s->write_packet && !s->error) {
+ int ret = s->write_packet(s->opaque, (uint8_t *)data, len);
+ if (ret < 0) {
s->error = ret;
}
}
{
if (s->buf_ptr > s->buffer) {
writeout(s, s->buffer, s->buf_ptr - s->buffer);
- if(s->update_checksum){
- s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
- s->checksum_ptr= s->buffer;
+ if (s->update_checksum) {
+ s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
+ s->buf_ptr - s->checksum_ptr);
+ s->checksum_ptr = s->buffer;
}
}
s->buf_ptr = s->buffer;
{
int64_t size;
- if(!s)
+ if (!s)
return AVERROR(EINVAL);
if (!s->seek)
return AVERROR(ENOSYS);
size = s->seek(s->opaque, 0, AVSEEK_SIZE);
- if(size<0){
+ if (size < 0) {
if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
return size;
size++;
uint16_t tmp;
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);
ret += 2;
return ret;
}
-int ff_get_v_length(uint64_t val){
- int i=1;
+int ff_get_v_length(uint64_t val)
+{
+ int i = 1;
- while(val>>=7)
+ while (val >>= 7)
i++;
return i;
}
-void ff_put_v(AVIOContext *bc, uint64_t val){
- int i= ff_get_v_length(val);
+void ff_put_v(AVIOContext *bc, uint64_t val)
+{
+ int i = ff_get_v_length(val);
- while(--i>0)
- avio_w8(bc, 128 | (uint8_t)(val>>(7*i)));
+ while (--i > 0)
+ avio_w8(bc, 128 | (uint8_t)(val >> (7*i)));
- avio_w8(bc, val&127);
+ avio_w8(bc, val & 127);
}
void avio_wl64(AVIOContext *s, uint64_t val)
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;
- int len= s->buffer_size - (dst - s->buffer);
- int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE;
+ uint8_t *dst = !s->max_packet_size &&
+ s->buf_end - s->buffer < s->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 appropriate */
if (!s->read_packet && s->buf_ptr >= s->buf_end)
if (s->eof_reached)
return;
- if(s->update_checksum && dst == s->buffer){
- 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_ptr= s->buffer;
+ if (s->update_checksum && dst == s->buffer) {
+ 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_ptr = s->buffer;
}
/* make buffer smaller in case it ended up large after probing */
len = s->buffer_size;
}
- if(s->read_packet)
+ if (s->read_packet)
len = s->read_packet(s->opaque, dst, len);
else
len = 0;
/* do not modify buffer if EOF reached so that a seek back can
be done without rereading data */
s->eof_reached = 1;
- if(len<0)
- s->error= len;
+ if (len < 0)
+ s->error = len;
} else {
s->pos += len;
s->buf_ptr = dst;
unsigned long ffio_get_checksum(AVIOContext *s)
{
- s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
- s->update_checksum= NULL;
+ s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
+ s->buf_ptr - s->checksum_ptr);
+ s->update_checksum = NULL;
return s->checksum;
}
unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
unsigned long checksum)
{
- s->update_checksum= update_checksum;
- if(s->update_checksum){
- s->checksum= checksum;
- s->checksum_ptr= s->buf_ptr;
+ s->update_checksum = update_checksum;
+ if (s->update_checksum) {
+ s->checksum = checksum;
+ s->checksum_ptr = s->buf_ptr;
}
}
s->buf_ptr = s->buffer;
s->buf_end = s->buffer/* + len*/;
}
- }else{
+ } else {
fill_buffer(s);
len = s->buf_end - s->buf_ptr;
if (len == 0)
{
int len;
- if(size<0)
+ if (size < 0)
return -1;
len = s->buf_end - s->buf_ptr;
if (!s->read_seek)
return AVERROR(ENOSYS);
ret = s->read_seek(h, stream_index, timestamp, flags);
- if(ret >= 0) {
+ if (ret >= 0) {
int64_t pos;
s->buf_ptr = s->buf_end; // Flush buffer
pos = s->seek(h, 0, SEEK_CUR);
/* reallocate buffer if needed */
new_size = d->pos + buf_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;
while (new_size > new_allocated_size) {
if (!new_allocated_size)
/* packetized write: output the header */
AV_WB32(buf1, buf_size);
- ret= dyn_buf_write(opaque, buf1, 4);
- if(ret < 0)
+ ret = dyn_buf_write(opaque, buf1, 4);
+ if (ret < 0)
return ret;
/* then the data */
DynBuffer *d;
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;
d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
if (!d)