() 10l
[libav.git] / libavformat / avio.h
CommitLineData
04d7f601
DB
1/*
2 * unbuffered io for ffmpeg system
3 * copyright (c) 2001 Fabrice Bellard
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
f031df23
FB
19#ifndef AVIO_H
20#define AVIO_H
21
de6d9b64
FB
22/* output byte stream handling */
23
0c1a9eda 24typedef int64_t offset_t;
de6d9b64
FB
25
26/* unbuffered I/O */
27
28struct URLContext {
29 struct URLProtocol *prot;
115329f1 30 int flags;
de6d9b64 31 int is_streamed; /* true if streamed (no seek possible), default = false */
f031df23 32 int max_packet_size; /* if non zero, the stream is packetized with this max packet size */
de6d9b64 33 void *priv_data;
f746a046 34 char filename[1]; /* specified filename */
de6d9b64
FB
35};
36
de6d9b64
FB
37typedef struct URLContext URLContext;
38
39typedef struct URLPollEntry {
40 URLContext *handle;
41 int events;
42 int revents;
43} URLPollEntry;
44
45#define URL_RDONLY 0
46#define URL_WRONLY 1
f031df23
FB
47#define URL_RDWR 2
48
019ac05a
FB
49typedef int URLInterruptCB(void);
50
de6d9b64
FB
51int url_open(URLContext **h, const char *filename, int flags);
52int url_read(URLContext *h, unsigned char *buf, int size);
53int url_write(URLContext *h, unsigned char *buf, int size);
54offset_t url_seek(URLContext *h, offset_t pos, int whence);
de6d9b64
FB
55int url_close(URLContext *h);
56int url_exist(const char *filename);
57offset_t url_filesize(URLContext *h);
f031df23 58int url_get_max_packet_size(URLContext *h);
f746a046
FB
59void url_get_filename(URLContext *h, char *buf, int buf_size);
60
019ac05a
FB
61/* the callback is called in blocking functions to test regulary if
62 asynchronous interruption is needed. -EINTR is returned in this
63 case by the interrupted function. 'NULL' means no interrupt
64 callback is given. */
65void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
66
de6d9b64
FB
67/* not implemented */
68int url_poll(URLPollEntry *poll_table, int n, int timeout);
69
70typedef struct URLProtocol {
71 const char *name;
72 int (*url_open)(URLContext *h, const char *filename, int flags);
73 int (*url_read)(URLContext *h, unsigned char *buf, int size);
74 int (*url_write)(URLContext *h, unsigned char *buf, int size);
75 offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
76 int (*url_close)(URLContext *h);
de6d9b64
FB
77 struct URLProtocol *next;
78} URLProtocol;
79
80extern URLProtocol *first_protocol;
019ac05a 81extern URLInterruptCB *url_interrupt_cb;
de6d9b64
FB
82
83int register_protocol(URLProtocol *protocol);
84
85typedef struct {
86 unsigned char *buffer;
87 int buffer_size;
88 unsigned char *buf_ptr, *buf_end;
89 void *opaque;
0c1a9eda 90 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
576ae256 91 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
536ffa59 92 offset_t (*seek)(void *opaque, offset_t offset, int whence);
de6d9b64
FB
93 offset_t pos; /* position in the file of the current buffer */
94 int must_flush; /* true if the next seek should flush */
95 int eof_reached; /* true if eof reached */
96 int write_flag; /* true if open for writing */
97 int is_streamed;
f031df23 98 int max_packet_size;
ee9f36a8
MN
99 unsigned long checksum;
100 unsigned char *checksum_ptr;
101 unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
576ae256 102 int error; ///< contains the error code or 0 if no error happened
de6d9b64
FB
103} ByteIOContext;
104
105int init_put_byte(ByteIOContext *s,
106 unsigned char *buffer,
107 int buffer_size,
108 int write_flag,
109 void *opaque,
0c1a9eda 110 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
576ae256 111 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
536ffa59 112 offset_t (*seek)(void *opaque, offset_t offset, int whence));
de6d9b64
FB
113
114void put_byte(ByteIOContext *s, int b);
75bdb984 115void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
0c1a9eda
ZK
116void put_le64(ByteIOContext *s, uint64_t val);
117void put_be64(ByteIOContext *s, uint64_t val);
de6d9b64
FB
118void put_le32(ByteIOContext *s, unsigned int val);
119void put_be32(ByteIOContext *s, unsigned int val);
ea395e8c 120void put_le24(ByteIOContext *s, unsigned int val);
a254c574 121void put_be24(ByteIOContext *s, unsigned int val);
de6d9b64
FB
122void put_le16(ByteIOContext *s, unsigned int val);
123void put_be16(ByteIOContext *s, unsigned int val);
0570bf06 124void put_tag(ByteIOContext *s, const char *tag);
de6d9b64 125
3b4b29dc 126void put_strz(ByteIOContext *s, const char *buf);
75bdb984 127
de6d9b64
FB
128offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
129void url_fskip(ByteIOContext *s, offset_t offset);
130offset_t url_ftell(ByteIOContext *s);
a965c478 131offset_t url_fsize(ByteIOContext *s);
de6d9b64 132int url_feof(ByteIOContext *s);
576ae256 133int url_ferror(ByteIOContext *s);
de6d9b64 134
f031df23
FB
135#define URL_EOF (-1)
136int url_fgetc(ByteIOContext *s);
572f992e 137#ifdef __GNUC__
08f29f82 138int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
572f992e
MN
139#else
140int url_fprintf(ByteIOContext *s, const char *fmt, ...);
141#endif
f031df23
FB
142char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
143
de6d9b64
FB
144void put_flush_packet(ByteIOContext *s);
145
146int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
e15dec10 147int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
de6d9b64 148int get_byte(ByteIOContext *s);
ea395e8c 149unsigned int get_le24(ByteIOContext *s);
de6d9b64 150unsigned int get_le32(ByteIOContext *s);
0c1a9eda 151uint64_t get_le64(ByteIOContext *s);
de6d9b64
FB
152unsigned int get_le16(ByteIOContext *s);
153
3b4b29dc 154char *get_strz(ByteIOContext *s, char *buf, int maxlen);
de6d9b64 155unsigned int get_be16(ByteIOContext *s);
a254c574 156unsigned int get_be24(ByteIOContext *s);
de6d9b64 157unsigned int get_be32(ByteIOContext *s);
0c1a9eda 158uint64_t get_be64(ByteIOContext *s);
de6d9b64 159
7ac13f0c 160static inline int url_is_streamed(ByteIOContext *s)
de6d9b64
FB
161{
162 return s->is_streamed;
163}
de6d9b64
FB
164
165int url_fdopen(ByteIOContext *s, URLContext *h);
166int url_setbufsize(ByteIOContext *s, int buf_size);
167int url_fopen(ByteIOContext *s, const char *filename, int flags);
168int url_fclose(ByteIOContext *s);
169URLContext *url_fileno(ByteIOContext *s);
f031df23 170int url_fget_max_packet_size(ByteIOContext *s);
de6d9b64 171
0c1a9eda 172int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags);
de6d9b64
FB
173int url_close_buf(ByteIOContext *s);
174
f031df23
FB
175int url_open_dyn_buf(ByteIOContext *s);
176int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
0c1a9eda 177int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
f031df23 178
ee9f36a8
MN
179unsigned long get_checksum(ByteIOContext *s);
180void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum);
ee9f36a8 181
de6d9b64
FB
182/* file.c */
183extern URLProtocol file_protocol;
184extern URLProtocol pipe_protocol;
185
186/* udp.c */
187extern URLProtocol udp_protocol;
f031df23
FB
188int udp_set_remote_url(URLContext *h, const char *uri);
189int udp_get_local_port(URLContext *h);
190int udp_get_file_handle(URLContext *h);
191
192/* tcp.c */
193extern URLProtocol tcp_protocol;
de6d9b64
FB
194
195/* http.c */
196extern URLProtocol http_protocol;
f031df23
FB
197
198#endif
199