00001
00002
00003
00004
00005 #ifndef AVIO_H
00006 #define AVIO_H
00007
00008 typedef int64_t offset_t;
00009
00010 struct URLContext {
00011 struct URLProtocol *prot;
00012 int flags;
00013 int is_streamed;
00014 int max_packet_size;
00015 void *priv_data;
00016 #if LIBAVFORMAT_VERSION_INT >= (52<<16)
00017 char *filename;
00018 #else
00019 char filename[1];
00020 #endif
00021 };
00022
00023 typedef struct URLContext URLContext;
00024
00025 typedef struct URLPollEntry {
00026 URLContext *handle;
00027 int events;
00028 int revents;
00029 } URLPollEntry;
00030
00031 #define URL_RDONLY 0
00032 #define URL_WRONLY 1
00033 #define URL_RDWR 2
00034
00035 typedef int URLInterruptCB(void);
00036
00037 int url_open(URLContext **h, const char *filename, int flags);
00038 int url_read(URLContext *h, unsigned char *buf, int size);
00039 int url_write(URLContext *h, unsigned char *buf, int size);
00040 offset_t url_seek(URLContext *h, offset_t pos, int whence);
00041 int url_close(URLContext *h);
00042 int url_exist(const char *filename);
00043 offset_t url_filesize(URLContext *h);
00044 int url_get_max_packet_size(URLContext *h);
00045 void url_get_filename(URLContext *h, char *buf, int buf_size);
00046
00047 void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
00048
00049 int url_poll(URLPollEntry *poll_table, int n, int timeout);
00050
00051 #define AVSEEK_SIZE 0x10000
00052
00053 typedef struct URLProtocol {
00054 const char *name;
00055 int (*url_open)(URLContext *h, const char *filename, int flags);
00056 int (*url_read)(URLContext *h, unsigned char *buf, int size);
00057 int (*url_write)(URLContext *h, unsigned char *buf, int size);
00058 offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
00059 int (*url_close)(URLContext *h);
00060 struct URLProtocol *next;
00061 } URLProtocol;
00062
00063 extern URLProtocol *first_protocol;
00064 extern URLInterruptCB *url_interrupt_cb;
00065
00066 int register_protocol(URLProtocol *protocol);
00067
00068 typedef struct {
00069 unsigned char *buffer;
00070 int buffer_size;
00071 unsigned char *buf_ptr, *buf_end;
00072 void *opaque;
00073 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
00074 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
00075 offset_t (*seek)(void *opaque, offset_t offset, int whence);
00076 offset_t pos;
00077 int must_flush;
00078 int eof_reached;
00079 int write_flag;
00080 int is_streamed;
00081 int max_packet_size;
00082 unsigned long checksum;
00083 unsigned char *checksum_ptr;
00084 unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
00085 int error;
00086 } ByteIOContext;
00087
00088 int init_put_byte(ByteIOContext *s,
00089 unsigned char *buffer,
00090 int buffer_size,
00091 int write_flag,
00092 void *opaque,
00093 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
00094 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
00095 offset_t (*seek)(void *opaque, offset_t offset, int whence));
00096
00097 void put_byte(ByteIOContext *s, int b);
00098 void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
00099 void put_le64(ByteIOContext *s, uint64_t val);
00100 void put_be64(ByteIOContext *s, uint64_t val);
00101 void put_le32(ByteIOContext *s, unsigned int val);
00102 void put_be32(ByteIOContext *s, unsigned int val);
00103 void put_le24(ByteIOContext *s, unsigned int val);
00104 void put_be24(ByteIOContext *s, unsigned int val);
00105 void put_le16(ByteIOContext *s, unsigned int val);
00106 void put_be16(ByteIOContext *s, unsigned int val);
00107 void put_tag(ByteIOContext *s, const char *tag);
00108
00109 void put_strz(ByteIOContext *s, const char *buf);
00110
00111 offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
00112 void url_fskip(ByteIOContext *s, offset_t offset);
00113 offset_t url_ftell(ByteIOContext *s);
00114 offset_t url_fsize(ByteIOContext *s);
00115 int url_feof(ByteIOContext *s);
00116 int url_ferror(ByteIOContext *s);
00117
00118 #define URL_EOF (-1)
00119 int url_fgetc(ByteIOContext *s);
00120 #ifdef __GNUC__
00121 int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
00122 #else
00123 int url_fprintf(ByteIOContext *s, const char *fmt, ...);
00124 #endif
00125 char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
00126
00127 void put_flush_packet(ByteIOContext *s);
00128
00129 int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
00130 int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
00131 int get_byte(ByteIOContext *s);
00132 unsigned int get_le24(ByteIOContext *s);
00133 unsigned int get_le32(ByteIOContext *s);
00134 uint64_t get_le64(ByteIOContext *s);
00135 unsigned int get_le16(ByteIOContext *s);
00136
00137 char *get_strz(ByteIOContext *s, char *buf, int maxlen);
00138 unsigned int get_be16(ByteIOContext *s);
00139 unsigned int get_be24(ByteIOContext *s);
00140 unsigned int get_be32(ByteIOContext *s);
00141 uint64_t get_be64(ByteIOContext *s);
00142
00143 static inline int url_is_streamed(ByteIOContext *s)
00144 {
00145 return s->is_streamed;
00146 }
00147
00148 int url_fdopen(ByteIOContext *s, URLContext *h);
00149 int url_setbufsize(ByteIOContext *s, int buf_size);
00150 int url_fopen(ByteIOContext *s, const char *filename, int flags);
00151 int url_fclose(ByteIOContext *s);
00152 URLContext *url_fileno(ByteIOContext *s);
00153 int url_fget_max_packet_size(ByteIOContext *s);
00154
00155 int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags);
00156 int url_close_buf(ByteIOContext *s);
00157
00158 int url_open_dyn_buf(ByteIOContext *s);
00159 int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
00160 int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
00161
00162 unsigned long get_checksum(ByteIOContext *s);
00163 void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum);
00164
00165 extern URLProtocol file_protocol;
00166 extern URLProtocol pipe_protocol;
00167
00168 extern URLProtocol udp_protocol;
00169 int udp_set_remote_url(URLContext *h, const char *uri);
00170 int udp_get_local_port(URLContext *h);
00171 int udp_get_file_handle(URLContext *h);
00172
00173 extern URLProtocol tcp_protocol;
00174
00175 extern URLProtocol http_protocol;
00176
00177 #endif
00178