better UDP support - added preliminary multicast support (untested)
[libav.git] / libav / avio.h
CommitLineData
de6d9b64
FB
1/* output byte stream handling */
2
8be1c656 3typedef INT64 offset_t;
de6d9b64
FB
4
5/* unbuffered I/O */
6
7struct URLContext {
8 struct URLProtocol *prot;
9 int flags;
10 int is_streamed; /* true if streamed (no seek possible), default = false */
11 int packet_size;
12 void *priv_data;
13};
14
de6d9b64
FB
15typedef struct URLContext URLContext;
16
17typedef struct URLPollEntry {
18 URLContext *handle;
19 int events;
20 int revents;
21} URLPollEntry;
22
23#define URL_RDONLY 0
24#define URL_WRONLY 1
25int url_open(URLContext **h, const char *filename, int flags);
26int url_read(URLContext *h, unsigned char *buf, int size);
27int url_write(URLContext *h, unsigned char *buf, int size);
28offset_t url_seek(URLContext *h, offset_t pos, int whence);
de6d9b64
FB
29int url_close(URLContext *h);
30int url_exist(const char *filename);
31offset_t url_filesize(URLContext *h);
32/* not implemented */
33int url_poll(URLPollEntry *poll_table, int n, int timeout);
34
35typedef struct URLProtocol {
36 const char *name;
37 int (*url_open)(URLContext *h, const char *filename, int flags);
38 int (*url_read)(URLContext *h, unsigned char *buf, int size);
39 int (*url_write)(URLContext *h, unsigned char *buf, int size);
40 offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
41 int (*url_close)(URLContext *h);
de6d9b64
FB
42 struct URLProtocol *next;
43} URLProtocol;
44
45extern URLProtocol *first_protocol;
46
47int register_protocol(URLProtocol *protocol);
48
49typedef struct {
50 unsigned char *buffer;
51 int buffer_size;
52 unsigned char *buf_ptr, *buf_end;
53 void *opaque;
54 int (*read_packet)(void *opaque, UINT8 *buf, int buf_size);
55 void (*write_packet)(void *opaque, UINT8 *buf, int buf_size);
56 int (*seek)(void *opaque, offset_t offset, int whence);
57 offset_t pos; /* position in the file of the current buffer */
58 int must_flush; /* true if the next seek should flush */
59 int eof_reached; /* true if eof reached */
60 int write_flag; /* true if open for writing */
61 int is_streamed;
62 int packet_size;
63} ByteIOContext;
64
65int init_put_byte(ByteIOContext *s,
66 unsigned char *buffer,
67 int buffer_size,
68 int write_flag,
69 void *opaque,
70 int (*read_packet)(void *opaque, UINT8 *buf, int buf_size),
71 void (*write_packet)(void *opaque, UINT8 *buf, int buf_size),
72 int (*seek)(void *opaque, offset_t offset, int whence));
73
74void put_byte(ByteIOContext *s, int b);
75void put_buffer(ByteIOContext *s, unsigned char *buf, int size);
8be1c656
FB
76void put_le64(ByteIOContext *s, UINT64 val);
77void put_be64(ByteIOContext *s, UINT64 val);
de6d9b64
FB
78void put_le32(ByteIOContext *s, unsigned int val);
79void put_be32(ByteIOContext *s, unsigned int val);
80void put_le16(ByteIOContext *s, unsigned int val);
81void put_be16(ByteIOContext *s, unsigned int val);
82void put_tag(ByteIOContext *s, char *tag);
83
84offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
85void url_fskip(ByteIOContext *s, offset_t offset);
86offset_t url_ftell(ByteIOContext *s);
87int url_feof(ByteIOContext *s);
88
89void put_flush_packet(ByteIOContext *s);
90
91int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
92int get_byte(ByteIOContext *s);
93unsigned int get_le32(ByteIOContext *s);
8be1c656 94UINT64 get_le64(ByteIOContext *s);
de6d9b64
FB
95unsigned int get_le16(ByteIOContext *s);
96
97unsigned int get_be16(ByteIOContext *s);
98unsigned int get_be32(ByteIOContext *s);
8be1c656 99UINT64 get_be64(ByteIOContext *s);
de6d9b64 100
7ac13f0c 101static inline int url_is_streamed(ByteIOContext *s)
de6d9b64
FB
102{
103 return s->is_streamed;
104}
105/* get the prefered packet size of the device. All I/Os should be done
106 by multiple of this size */
7ac13f0c 107static inline int url_get_packet_size(ByteIOContext *s)
de6d9b64
FB
108{
109 return s->packet_size;
110}
111
112int url_fdopen(ByteIOContext *s, URLContext *h);
113int url_setbufsize(ByteIOContext *s, int buf_size);
114int url_fopen(ByteIOContext *s, const char *filename, int flags);
115int url_fclose(ByteIOContext *s);
116URLContext *url_fileno(ByteIOContext *s);
117
118int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags);
119int url_close_buf(ByteIOContext *s);
120
121/* file.c */
122extern URLProtocol file_protocol;
123extern URLProtocol pipe_protocol;
124
125/* udp.c */
126extern URLProtocol udp_protocol;
127
128/* http.c */
129extern URLProtocol http_protocol;