36263167a83a68d9aab8204ac0ba66ba782e9a2d
[libav.git] / libav / avio.h
1 /* output byte stream handling */
2
3 typedef INT64 offset_t;
4
5 /* unbuffered I/O */
6
7 struct 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
15 typedef struct URLContext URLContext;
16
17 typedef struct URLPollEntry {
18 URLContext *handle;
19 int events;
20 int revents;
21 } URLPollEntry;
22
23 #define URL_RDONLY 0
24 #define URL_WRONLY 1
25 int url_open(URLContext **h, const char *filename, int flags);
26 int url_read(URLContext *h, unsigned char *buf, int size);
27 int url_write(URLContext *h, unsigned char *buf, int size);
28 offset_t url_seek(URLContext *h, offset_t pos, int whence);
29 int url_close(URLContext *h);
30 int url_exist(const char *filename);
31 offset_t url_filesize(URLContext *h);
32 /* not implemented */
33 int url_poll(URLPollEntry *poll_table, int n, int timeout);
34
35 typedef 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);
42 struct URLProtocol *next;
43 } URLProtocol;
44
45 extern URLProtocol *first_protocol;
46
47 int register_protocol(URLProtocol *protocol);
48
49 typedef 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
65 int 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
74 void put_byte(ByteIOContext *s, int b);
75 void put_buffer(ByteIOContext *s, unsigned char *buf, int size);
76 void put_le64(ByteIOContext *s, UINT64 val);
77 void put_be64(ByteIOContext *s, UINT64 val);
78 void put_le32(ByteIOContext *s, unsigned int val);
79 void put_be32(ByteIOContext *s, unsigned int val);
80 void put_le16(ByteIOContext *s, unsigned int val);
81 void put_be16(ByteIOContext *s, unsigned int val);
82 void put_tag(ByteIOContext *s, char *tag);
83
84 offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
85 void url_fskip(ByteIOContext *s, offset_t offset);
86 offset_t url_ftell(ByteIOContext *s);
87 int url_feof(ByteIOContext *s);
88
89 void put_flush_packet(ByteIOContext *s);
90
91 int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
92 int get_byte(ByteIOContext *s);
93 unsigned int get_le32(ByteIOContext *s);
94 UINT64 get_le64(ByteIOContext *s);
95 unsigned int get_le16(ByteIOContext *s);
96
97 unsigned int get_be16(ByteIOContext *s);
98 unsigned int get_be32(ByteIOContext *s);
99 UINT64 get_be64(ByteIOContext *s);
100
101 static inline int url_is_streamed(ByteIOContext *s)
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 */
107 static inline int url_get_packet_size(ByteIOContext *s)
108 {
109 return s->packet_size;
110 }
111
112 int url_fdopen(ByteIOContext *s, URLContext *h);
113 int url_setbufsize(ByteIOContext *s, int buf_size);
114 int url_fopen(ByteIOContext *s, const char *filename, int flags);
115 int url_fclose(ByteIOContext *s);
116 URLContext *url_fileno(ByteIOContext *s);
117
118 int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags);
119 int url_close_buf(ByteIOContext *s);
120
121 /* file.c */
122 extern URLProtocol file_protocol;
123 extern URLProtocol pipe_protocol;
124
125 /* udp.c */
126 extern URLProtocol udp_protocol;
127
128 /* http.c */
129 extern URLProtocol http_protocol;