void *opaque,
int (*read_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))
+{
ByteIOContext *s = av_mallocz(sizeof(ByteIOContext));
init_put_byte(s, buffer, buffer_size, write_flag, opaque,
read_packet, write_packet, seek);
static void fill_buffer(ByteIOContext *s)
{
- int len=0;
+ uint8_t *dst= !s->max_packet_size && s->buf_end - s->buffer < s->buffer_size ? s->buf_ptr : s->buffer;
+ int len= s->buffer_size - (dst - s->buffer);
+
+ assert(s->buf_ptr == s->buf_end);
/* no need to do anything if EOF already reached */
if (s->eof_reached)
return;
- if(s->update_checksum){
+ 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->read_packet)
- len = s->read_packet(s->opaque, s->buffer, s->buffer_size);
+ len = s->read_packet(s->opaque, dst, len);
+ else
+ len = 0;
if (len <= 0) {
/* do not modify buffer if EOF reached so that a seek back can
be done without rereading data */
s->error= len;
} else {
s->pos += len;
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer + len;
+ s->buf_ptr = dst;
+ s->buf_end = dst + len;
}
}
-unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len){
+unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
+ unsigned int len)
+{
return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len);
}
-unsigned long get_checksum(ByteIOContext *s){
+unsigned long get_checksum(ByteIOContext *s)
+{
s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
s->update_checksum= NULL;
return s->checksum;
}
-void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum){
+void init_checksum(ByteIOContext *s,
+ 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;
return s->read_pause(s->opaque, pause);
}
-int64_t av_url_read_fseek(ByteIOContext *s,
- int stream_index, int64_t timestamp, int flags)
+int64_t av_url_read_fseek(ByteIOContext *s, int stream_index,
+ int64_t timestamp, int flags)
{
URLContext *h = s->opaque;
int64_t ret;
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
{
DynBuffer *d = opaque;
- int new_size, new_allocated_size;
+ unsigned new_size, new_allocated_size;
/* reallocate buffer if needed */
new_size = d->pos + buf_size;