2002-07-24 19:49:11 +02:00
|
|
|
#ifndef AVIO_H
|
|
|
|
#define AVIO_H
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
/* output byte stream handling */
|
|
|
|
|
2003-02-11 17:35:48 +01:00
|
|
|
typedef int64_t offset_t;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
/* unbuffered I/O */
|
|
|
|
|
|
|
|
struct URLContext {
|
|
|
|
struct URLProtocol *prot;
|
|
|
|
int flags;
|
|
|
|
int is_streamed; /* true if streamed (no seek possible), default = false */
|
2002-07-24 19:49:11 +02:00
|
|
|
int max_packet_size; /* if non zero, the stream is packetized with this max packet size */
|
2001-07-22 16:18:56 +02:00
|
|
|
void *priv_data;
|
2003-01-11 05:59:17 +01:00
|
|
|
char filename[1]; /* specified filename */
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct URLContext URLContext;
|
|
|
|
|
|
|
|
typedef struct URLPollEntry {
|
|
|
|
URLContext *handle;
|
|
|
|
int events;
|
|
|
|
int revents;
|
|
|
|
} URLPollEntry;
|
|
|
|
|
|
|
|
#define URL_RDONLY 0
|
|
|
|
#define URL_WRONLY 1
|
2002-07-24 19:49:11 +02:00
|
|
|
#define URL_RDWR 2
|
|
|
|
|
2003-07-17 12:25:36 +02:00
|
|
|
typedef int URLInterruptCB(void);
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
int url_open(URLContext **h, const char *filename, int flags);
|
|
|
|
int url_read(URLContext *h, unsigned char *buf, int size);
|
|
|
|
int url_write(URLContext *h, unsigned char *buf, int size);
|
|
|
|
offset_t url_seek(URLContext *h, offset_t pos, int whence);
|
|
|
|
int url_close(URLContext *h);
|
|
|
|
int url_exist(const char *filename);
|
|
|
|
offset_t url_filesize(URLContext *h);
|
2002-07-24 19:49:11 +02:00
|
|
|
int url_get_max_packet_size(URLContext *h);
|
2003-01-11 05:59:17 +01:00
|
|
|
void url_get_filename(URLContext *h, char *buf, int buf_size);
|
|
|
|
|
2003-07-17 12:25:36 +02:00
|
|
|
/* the callback is called in blocking functions to test regulary if
|
|
|
|
asynchronous interruption is needed. -EINTR is returned in this
|
|
|
|
case by the interrupted function. 'NULL' means no interrupt
|
|
|
|
callback is given. */
|
|
|
|
void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
/* not implemented */
|
|
|
|
int url_poll(URLPollEntry *poll_table, int n, int timeout);
|
|
|
|
|
|
|
|
typedef struct URLProtocol {
|
|
|
|
const char *name;
|
|
|
|
int (*url_open)(URLContext *h, const char *filename, int flags);
|
|
|
|
int (*url_read)(URLContext *h, unsigned char *buf, int size);
|
|
|
|
int (*url_write)(URLContext *h, unsigned char *buf, int size);
|
|
|
|
offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
|
|
|
|
int (*url_close)(URLContext *h);
|
|
|
|
struct URLProtocol *next;
|
|
|
|
} URLProtocol;
|
|
|
|
|
|
|
|
extern URLProtocol *first_protocol;
|
2003-07-17 12:25:36 +02:00
|
|
|
extern URLInterruptCB *url_interrupt_cb;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
int register_protocol(URLProtocol *protocol);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned char *buffer;
|
|
|
|
int buffer_size;
|
|
|
|
unsigned char *buf_ptr, *buf_end;
|
|
|
|
void *opaque;
|
2003-02-11 17:35:48 +01:00
|
|
|
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
|
|
|
|
void (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
|
2001-07-22 16:18:56 +02:00
|
|
|
int (*seek)(void *opaque, offset_t offset, int whence);
|
|
|
|
offset_t pos; /* position in the file of the current buffer */
|
|
|
|
int must_flush; /* true if the next seek should flush */
|
|
|
|
int eof_reached; /* true if eof reached */
|
|
|
|
int write_flag; /* true if open for writing */
|
|
|
|
int is_streamed;
|
2002-07-24 19:49:11 +02:00
|
|
|
int max_packet_size;
|
2001-07-22 16:18:56 +02:00
|
|
|
} ByteIOContext;
|
|
|
|
|
|
|
|
int init_put_byte(ByteIOContext *s,
|
|
|
|
unsigned char *buffer,
|
|
|
|
int buffer_size,
|
|
|
|
int write_flag,
|
|
|
|
void *opaque,
|
2003-02-11 17:35:48 +01:00
|
|
|
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
|
|
|
|
void (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
|
2001-07-22 16:18:56 +02:00
|
|
|
int (*seek)(void *opaque, offset_t offset, int whence));
|
|
|
|
|
|
|
|
void put_byte(ByteIOContext *s, int b);
|
2002-09-12 04:26:58 +02:00
|
|
|
void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
|
2003-02-11 17:35:48 +01:00
|
|
|
void put_le64(ByteIOContext *s, uint64_t val);
|
|
|
|
void put_be64(ByteIOContext *s, uint64_t val);
|
2001-07-22 16:18:56 +02:00
|
|
|
void put_le32(ByteIOContext *s, unsigned int val);
|
|
|
|
void put_be32(ByteIOContext *s, unsigned int val);
|
|
|
|
void put_le16(ByteIOContext *s, unsigned int val);
|
|
|
|
void put_be16(ByteIOContext *s, unsigned int val);
|
2002-11-11 10:20:53 +01:00
|
|
|
void put_tag(ByteIOContext *s, const char *tag);
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2002-10-22 11:23:14 +02:00
|
|
|
void put_be64_double(ByteIOContext *s, double val);
|
|
|
|
void put_strz(ByteIOContext *s, const char *buf);
|
2002-09-12 04:26:58 +02:00
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
|
|
|
|
void url_fskip(ByteIOContext *s, offset_t offset);
|
|
|
|
offset_t url_ftell(ByteIOContext *s);
|
|
|
|
int url_feof(ByteIOContext *s);
|
|
|
|
|
2002-07-24 19:49:11 +02:00
|
|
|
#define URL_EOF (-1)
|
|
|
|
int url_fgetc(ByteIOContext *s);
|
2003-08-29 22:33:57 +02:00
|
|
|
#ifdef __GNUC__
|
2003-09-30 19:54:30 +02:00
|
|
|
int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
|
2003-08-29 22:33:57 +02:00
|
|
|
#else
|
|
|
|
int url_fprintf(ByteIOContext *s, const char *fmt, ...);
|
|
|
|
#endif
|
2002-07-24 19:49:11 +02:00
|
|
|
char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
void put_flush_packet(ByteIOContext *s);
|
|
|
|
|
|
|
|
int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
|
|
|
|
int get_byte(ByteIOContext *s);
|
|
|
|
unsigned int get_le32(ByteIOContext *s);
|
2003-02-11 17:35:48 +01:00
|
|
|
uint64_t get_le64(ByteIOContext *s);
|
2001-07-22 16:18:56 +02:00
|
|
|
unsigned int get_le16(ByteIOContext *s);
|
|
|
|
|
2002-10-22 11:23:14 +02:00
|
|
|
double get_be64_double(ByteIOContext *s);
|
|
|
|
char *get_strz(ByteIOContext *s, char *buf, int maxlen);
|
2001-07-22 16:18:56 +02:00
|
|
|
unsigned int get_be16(ByteIOContext *s);
|
|
|
|
unsigned int get_be32(ByteIOContext *s);
|
2003-02-11 17:35:48 +01:00
|
|
|
uint64_t get_be64(ByteIOContext *s);
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2002-05-09 03:16:45 +02:00
|
|
|
static inline int url_is_streamed(ByteIOContext *s)
|
2001-07-22 16:18:56 +02:00
|
|
|
{
|
|
|
|
return s->is_streamed;
|
|
|
|
}
|
|
|
|
|
|
|
|
int url_fdopen(ByteIOContext *s, URLContext *h);
|
|
|
|
int url_setbufsize(ByteIOContext *s, int buf_size);
|
|
|
|
int url_fopen(ByteIOContext *s, const char *filename, int flags);
|
|
|
|
int url_fclose(ByteIOContext *s);
|
|
|
|
URLContext *url_fileno(ByteIOContext *s);
|
2002-07-24 19:49:11 +02:00
|
|
|
int url_fget_max_packet_size(ByteIOContext *s);
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2003-02-11 17:35:48 +01:00
|
|
|
int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags);
|
2001-07-22 16:18:56 +02:00
|
|
|
int url_close_buf(ByteIOContext *s);
|
|
|
|
|
2002-07-24 19:49:11 +02:00
|
|
|
int url_open_dyn_buf(ByteIOContext *s);
|
|
|
|
int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
|
2003-02-11 17:35:48 +01:00
|
|
|
int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
|
2002-07-24 19:49:11 +02:00
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
/* file.c */
|
|
|
|
extern URLProtocol file_protocol;
|
|
|
|
extern URLProtocol pipe_protocol;
|
|
|
|
|
|
|
|
/* udp.c */
|
|
|
|
extern URLProtocol udp_protocol;
|
2002-07-24 19:49:11 +02:00
|
|
|
int udp_set_remote_url(URLContext *h, const char *uri);
|
|
|
|
int udp_get_local_port(URLContext *h);
|
|
|
|
int udp_get_file_handle(URLContext *h);
|
|
|
|
|
|
|
|
/* tcp.c */
|
|
|
|
extern URLProtocol tcp_protocol;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
/* http.c */
|
|
|
|
extern URLProtocol http_protocol;
|
2002-07-24 19:49:11 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|