*/
#include "libavutil/crc.h"
+#include "libavutil/intreadwrite.h"
#include "avformat.h"
#include "avio.h"
#include <stdarg.h>
s->buffer = buffer;
s->buffer_size = buffer_size;
s->buf_ptr = buffer;
- url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY);
s->opaque = opaque;
+ url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY);
s->write_packet = write_packet;
s->read_packet = read_packet;
s->seek = seek;
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);
} else {
int64_t res = AVERROR(EPIPE);
-#if defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK)
+#if CONFIG_MUXERS || CONFIG_NETWORK
if (s->write_flag) {
flush_buffer(s);
s->must_flush = 1;
}
-#endif /* defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK) */
+#endif /* CONFIG_MUXERS || CONFIG_NETWORK */
if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
return res;
if (!s->write_flag)
static void fill_buffer(ByteIOContext *s)
{
- uint8_t *dst= s->buf_end - s->buffer < s->buffer_size ? s->buf_ptr : s->buffer;
+ 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);
}
}
-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->opaque;
}
-#ifdef CONFIG_MUXERS
+#if CONFIG_MUXERS
int url_fprintf(ByteIOContext *s, const char *fmt, ...)
{
va_list ap;
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;
}
/* url_open_dyn_buf and url_close_dyn_buf are used in rtp.c to send a response
- * back to the server even if CONFIG_MUXERS is not set. */
-#if defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK)
+ * back to the server even if CONFIG_MUXERS is false. */
+#if CONFIG_MUXERS || CONFIG_NETWORK
/* buffer handling */
int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags)
{
if (new_allocated_size > d->allocated_size) {
d->buffer = av_realloc(d->buffer, new_allocated_size);
if(d->buffer == NULL)
- return -1234;
+ return AVERROR(ENOMEM);
d->allocated_size = new_allocated_size;
}
memcpy(d->buffer + d->pos, buf, buf_size);
int ret;
/* packetized write: output the header */
- buf1[0] = (buf_size >> 24);
- buf1[1] = (buf_size >> 16);
- buf1[2] = (buf_size >> 8);
- buf1[3] = (buf_size);
+ AV_WB32(buf1, buf_size);
ret= dyn_buf_write(opaque, buf1, 4);
if(ret < 0)
return ret;
static int url_open_dyn_buf_internal(ByteIOContext **s, int max_packet_size)
{
DynBuffer *d;
- int io_buffer_size, ret;
-
- if (max_packet_size)
- io_buffer_size = max_packet_size;
- else
- io_buffer_size = 1024;
+ int ret;
+ unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
return -1;
- d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
+ d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
if (!d)
- return -1;
+ return AVERROR(ENOMEM);
*s = av_mallocz(sizeof(ByteIOContext));
if(!*s) {
av_free(d);
return AVERROR(ENOMEM);
}
d->io_buffer_size = io_buffer_size;
- d->buffer = NULL;
- d->pos = 0;
- d->size = 0;
- d->allocated_size = 0;
ret = init_put_byte(*s, d->io_buffer, io_buffer_size,
1, d, NULL,
max_packet_size ? dyn_packet_buf_write : dyn_buf_write,