* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/* needed for usleep() */
-#define _XOPEN_SOURCE 600
-#include <unistd.h>
#include "libavutil/crc.h"
#include "libavutil/intreadwrite.h"
#include "avformat.h"
*/
#define SHORT_SEEK_THRESHOLD 4096
-static void fill_buffer(ByteIOContext *s);
+static void fill_buffer(AVIOContext *s);
#if !FF_API_URL_RESETBUF
-static int url_resetbuf(ByteIOContext *s, int flags);
+static int url_resetbuf(AVIOContext *s, int flags);
#endif
-int init_put_byte(ByteIOContext *s,
+int init_put_byte(AVIOContext *s,
unsigned char *buffer,
int buffer_size,
int write_flag,
return 0;
}
-ByteIOContext *av_alloc_put_byte(
+AVIOContext *av_alloc_put_byte(
unsigned char *buffer,
int buffer_size,
int write_flag,
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
int64_t (*seek)(void *opaque, int64_t offset, int whence))
{
- ByteIOContext *s = av_mallocz(sizeof(ByteIOContext));
+ AVIOContext *s = av_mallocz(sizeof(AVIOContext));
init_put_byte(s, buffer, buffer_size, write_flag, opaque,
read_packet, write_packet, seek);
return s;
}
-static inline int retry_transfer_wrapper(void *opaque, unsigned char *buf,
- int size,
- int (*transfer_func)(void *, unsigned char *, int)) {
- int fast_retries = 5;
- while (1) {
- int ret = transfer_func(opaque, buf, size);
- if (ret == AVERROR(EAGAIN)) {
- if (fast_retries)
- fast_retries--;
- else
- usleep(1000);
- } else
- return ret;
- }
-}
-
-static void flush_buffer(ByteIOContext *s)
+static void flush_buffer(AVIOContext *s)
{
if (s->buf_ptr > s->buffer) {
if (s->write_packet && !s->error){
- int ret= retry_transfer_wrapper(s->opaque, s->buffer,
- s->buf_ptr - s->buffer,
- s->write_packet);
+ int ret= s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
if(ret < 0){
s->error = ret;
}
s->buf_ptr = s->buffer;
}
-void put_byte(ByteIOContext *s, int b)
+void put_byte(AVIOContext *s, int b)
{
*(s->buf_ptr)++ = b;
if (s->buf_ptr >= s->buf_end)
flush_buffer(s);
}
-void put_nbyte(ByteIOContext *s, int b, int count)
+void put_nbyte(AVIOContext *s, int b, int count)
{
while (count > 0) {
int len = FFMIN(s->buf_end - s->buf_ptr, count);
}
}
-void put_buffer(ByteIOContext *s, const unsigned char *buf, int size)
+void put_buffer(AVIOContext *s, const unsigned char *buf, int size)
{
while (size > 0) {
int len = FFMIN(s->buf_end - s->buf_ptr, size);
}
}
-void put_flush_packet(ByteIOContext *s)
+void put_flush_packet(AVIOContext *s)
{
flush_buffer(s);
s->must_flush = 0;
}
-int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence)
+int64_t url_fseek(AVIOContext *s, int64_t offset, int whence)
{
int64_t offset1;
int64_t pos;
return offset;
}
-int url_fskip(ByteIOContext *s, int64_t offset)
+int url_fskip(AVIOContext *s, int64_t offset)
{
int64_t ret = url_fseek(s, offset, SEEK_CUR);
return ret < 0 ? ret : 0;
}
-int64_t url_ftell(ByteIOContext *s)
+int64_t url_ftell(AVIOContext *s)
{
return url_fseek(s, 0, SEEK_CUR);
}
-int64_t url_fsize(ByteIOContext *s)
+int64_t url_fsize(AVIOContext *s)
{
int64_t size;
return size;
}
-int url_feof(ByteIOContext *s)
+int url_feof(AVIOContext *s)
{
if(!s)
return 0;
return s->eof_reached;
}
-int url_ferror(ByteIOContext *s)
+int url_ferror(AVIOContext *s)
{
if(!s)
return 0;
return s->error;
}
-void put_le32(ByteIOContext *s, unsigned int val)
+void put_le32(AVIOContext *s, unsigned int val)
{
put_byte(s, val);
put_byte(s, val >> 8);
put_byte(s, val >> 24);
}
-void put_be32(ByteIOContext *s, unsigned int val)
+void put_be32(AVIOContext *s, unsigned int val)
{
put_byte(s, val >> 24);
put_byte(s, val >> 16);
put_byte(s, val);
}
-void put_strz(ByteIOContext *s, const char *str)
+#if FF_API_OLD_AVIO
+void put_strz(AVIOContext *s, const char *str)
{
- if (str)
- put_buffer(s, (const unsigned char *) str, strlen(str) + 1);
- else
+ avio_put_str(s, str);
+}
+#endif
+
+int avio_put_str(AVIOContext *s, const char *str)
+{
+ int len = 1;
+ if (str) {
+ len += strlen(str);
+ put_buffer(s, (const unsigned char *) str, len);
+ } else
put_byte(s, 0);
+ return len;
+}
+
+int avio_put_str16le(AVIOContext *s, const char *str)
+{
+ const uint8_t *q = str;
+ int ret = 0;
+
+ while (*q) {
+ uint32_t ch;
+ uint16_t tmp;
+
+ GET_UTF8(ch, *q++, break;)
+ PUT_UTF16(ch, tmp, put_le16(s, tmp);ret += 2;)
+ }
+ put_le16(s, 0);
+ ret += 2;
+ return ret;
}
int ff_get_v_length(uint64_t val){
return i;
}
-void ff_put_v(ByteIOContext *bc, uint64_t val){
+void ff_put_v(AVIOContext *bc, uint64_t val){
int i= ff_get_v_length(val);
while(--i>0)
put_byte(bc, val&127);
}
-void put_le64(ByteIOContext *s, uint64_t val)
+void put_le64(AVIOContext *s, uint64_t val)
{
put_le32(s, (uint32_t)(val & 0xffffffff));
put_le32(s, (uint32_t)(val >> 32));
}
-void put_be64(ByteIOContext *s, uint64_t val)
+void put_be64(AVIOContext *s, uint64_t val)
{
put_be32(s, (uint32_t)(val >> 32));
put_be32(s, (uint32_t)(val & 0xffffffff));
}
-void put_le16(ByteIOContext *s, unsigned int val)
+void put_le16(AVIOContext *s, unsigned int val)
{
put_byte(s, val);
put_byte(s, val >> 8);
}
-void put_be16(ByteIOContext *s, unsigned int val)
+void put_be16(AVIOContext *s, unsigned int val)
{
put_byte(s, val >> 8);
put_byte(s, val);
}
-void put_le24(ByteIOContext *s, unsigned int val)
+void put_le24(AVIOContext *s, unsigned int val)
{
put_le16(s, val & 0xffff);
put_byte(s, val >> 16);
}
-void put_be24(ByteIOContext *s, unsigned int val)
+void put_be24(AVIOContext *s, unsigned int val)
{
put_be16(s, val >> 8);
put_byte(s, val);
}
-void put_tag(ByteIOContext *s, const char *tag)
+void put_tag(AVIOContext *s, const char *tag)
{
while (*tag) {
put_byte(s, *tag++);
/* Input stream */
-static void fill_buffer(ByteIOContext *s)
+static void fill_buffer(AVIOContext *s)
{
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);
}
if(s->read_packet)
- len = retry_transfer_wrapper(s->opaque, dst, len, s->read_packet);
+ len = s->read_packet(s->opaque, dst, len);
else
len = 0;
if (len <= 0) {
return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len);
}
-unsigned long get_checksum(ByteIOContext *s)
+unsigned long get_checksum(AVIOContext *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,
+void init_checksum(AVIOContext *s,
unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
unsigned long checksum)
{
}
/* XXX: put an inline version */
-int get_byte(ByteIOContext *s)
+int get_byte(AVIOContext *s)
{
if (s->buf_ptr >= s->buf_end)
fill_buffer(s);
return 0;
}
-int url_fgetc(ByteIOContext *s)
+int url_fgetc(AVIOContext *s)
{
if (s->buf_ptr >= s->buf_end)
fill_buffer(s);
return URL_EOF;
}
-int get_buffer(ByteIOContext *s, unsigned char *buf, int size)
+int get_buffer(AVIOContext *s, unsigned char *buf, int size)
{
int len, size1;
if (len == 0) {
if(size > s->buffer_size && !s->update_checksum){
if(s->read_packet)
- len = retry_transfer_wrapper(s->opaque, buf, size,
- s->read_packet);
+ len = s->read_packet(s->opaque, buf, size);
if (len <= 0) {
/* do not modify buffer if EOF reached so that a seek back can
be done without rereading data */
return size1 - size;
}
-int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size)
+int get_partial_buffer(AVIOContext *s, unsigned char *buf, int size)
{
int len;
return len;
}
-unsigned int get_le16(ByteIOContext *s)
+unsigned int get_le16(AVIOContext *s)
{
unsigned int val;
val = get_byte(s);
return val;
}
-unsigned int get_le24(ByteIOContext *s)
+unsigned int get_le24(AVIOContext *s)
{
unsigned int val;
val = get_le16(s);
return val;
}
-unsigned int get_le32(ByteIOContext *s)
+unsigned int get_le32(AVIOContext *s)
{
unsigned int val;
val = get_le16(s);
return val;
}
-uint64_t get_le64(ByteIOContext *s)
+uint64_t get_le64(AVIOContext *s)
{
uint64_t val;
val = (uint64_t)get_le32(s);
return val;
}
-unsigned int get_be16(ByteIOContext *s)
+unsigned int get_be16(AVIOContext *s)
{
unsigned int val;
val = get_byte(s) << 8;
return val;
}
-unsigned int get_be24(ByteIOContext *s)
+unsigned int get_be24(AVIOContext *s)
{
unsigned int val;
val = get_be16(s) << 8;
val |= get_byte(s);
return val;
}
-unsigned int get_be32(ByteIOContext *s)
+unsigned int get_be32(AVIOContext *s)
{
unsigned int val;
val = get_be16(s) << 16;
return val;
}
-char *get_strz(ByteIOContext *s, char *buf, int maxlen)
+char *get_strz(AVIOContext *s, char *buf, int maxlen)
{
int i = 0;
char c;
return buf;
}
-int ff_get_line(ByteIOContext *s, char *buf, int maxlen)
+int ff_get_line(AVIOContext *s, char *buf, int maxlen)
{
int i = 0;
char c;
return i;
}
-uint64_t get_be64(ByteIOContext *s)
+#define GET_STR16(type, read) \
+ int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
+{\
+ char* q = buf;\
+ int ret = 0;\
+ while (ret + 1 < maxlen) {\
+ uint8_t tmp;\
+ uint32_t ch;\
+ GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
+ if (!ch)\
+ break;\
+ PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
+ }\
+ *q = 0;\
+ return ret;\
+}\
+
+GET_STR16(le, get_le16)
+GET_STR16(be, get_be16)
+
+#undef GET_STR16
+
+uint64_t get_be64(AVIOContext *s)
{
uint64_t val;
val = (uint64_t)get_be32(s) << 32;
return val;
}
-uint64_t ff_get_v(ByteIOContext *bc){
+uint64_t ff_get_v(AVIOContext *bc){
uint64_t val = 0;
int tmp;
return val;
}
-int url_fdopen(ByteIOContext **s, URLContext *h)
+int url_fdopen(AVIOContext **s, URLContext *h)
{
uint8_t *buffer;
int buffer_size, max_packet_size;
if (!buffer)
return AVERROR(ENOMEM);
- *s = av_mallocz(sizeof(ByteIOContext));
+ *s = av_mallocz(sizeof(AVIOContext));
if(!*s) {
av_free(buffer);
return AVERROR(ENOMEM);
return 0;
}
-int url_setbufsize(ByteIOContext *s, int buf_size)
+int url_setbufsize(AVIOContext *s, int buf_size)
{
uint8_t *buffer;
buffer = av_malloc(buf_size);
}
#if FF_API_URL_RESETBUF
-int url_resetbuf(ByteIOContext *s, int flags)
+int url_resetbuf(AVIOContext *s, int flags)
#else
-static int url_resetbuf(ByteIOContext *s, int flags)
+static int url_resetbuf(AVIOContext *s, int flags)
#endif
{
#if FF_API_URL_RESETBUF
return 0;
}
-int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size)
+int ff_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size)
{
int64_t buffer_start;
int buffer_size;
return 0;
}
-int url_fopen(ByteIOContext **s, const char *filename, int flags)
+int url_fopen(AVIOContext **s, const char *filename, int flags)
{
URLContext *h;
int err;
return 0;
}
-int url_fclose(ByteIOContext *s)
+int url_fclose(AVIOContext *s)
{
URLContext *h = s->opaque;
return url_close(h);
}
-URLContext *url_fileno(ByteIOContext *s)
+URLContext *url_fileno(AVIOContext *s)
{
return s->opaque;
}
#if CONFIG_MUXERS
-int url_fprintf(ByteIOContext *s, const char *fmt, ...)
+int url_fprintf(AVIOContext *s, const char *fmt, ...)
{
va_list ap;
char buf[4096];
}
#endif //CONFIG_MUXERS
-char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
+char *url_fgets(AVIOContext *s, char *buf, int buf_size)
{
int c;
char *q;
return buf;
}
-int url_fget_max_packet_size(ByteIOContext *s)
+int url_fget_max_packet_size(AVIOContext *s)
{
return s->max_packet_size;
}
-int av_url_read_fpause(ByteIOContext *s, int pause)
+int av_url_read_fpause(AVIOContext *s, int pause)
{
if (!s->read_pause)
return AVERROR(ENOSYS);
return s->read_pause(s->opaque, pause);
}
-int64_t av_url_read_fseek(ByteIOContext *s, int stream_index,
+int64_t av_url_read_fseek(AVIOContext *s, int stream_index,
int64_t timestamp, int flags)
{
URLContext *h = s->opaque;
* 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)
+int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags)
{
int ret;
- *s = av_mallocz(sizeof(ByteIOContext));
+ *s = av_mallocz(sizeof(AVIOContext));
if(!*s)
return AVERROR(ENOMEM);
ret = init_put_byte(*s, buf, buf_size,
return ret;
}
-int url_close_buf(ByteIOContext *s)
+int url_close_buf(AVIOContext *s)
{
put_flush_packet(s);
return s->buf_ptr - s->buffer;
return 0;
}
-static int url_open_dyn_buf_internal(ByteIOContext **s, int max_packet_size)
+static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
{
DynBuffer *d;
int ret;
d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
if (!d)
return AVERROR(ENOMEM);
- *s = av_mallocz(sizeof(ByteIOContext));
+ *s = av_mallocz(sizeof(AVIOContext));
if(!*s) {
av_free(d);
return AVERROR(ENOMEM);
return ret;
}
-int url_open_dyn_buf(ByteIOContext **s)
+int url_open_dyn_buf(AVIOContext **s)
{
return url_open_dyn_buf_internal(s, 0);
}
-int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size)
+int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
{
if (max_packet_size <= 0)
return -1;
return url_open_dyn_buf_internal(s, max_packet_size);
}
-int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
+int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
{
DynBuffer *d = s->opaque;
int size;