Initial revision
[libav.git] / libav / avio.h
CommitLineData
de6d9b64
FB
1/* output byte stream handling */
2
3typedef long long offset_t;
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
15typedef struct URLFormat {
16 char format_name[32];
17 int sample_rate;
18 int frame_rate;
19 int channels;
20 int height;
21 int width;
22 int pix_fmt;
23} URLFormat;
24
25typedef struct URLContext URLContext;
26
27typedef struct URLPollEntry {
28 URLContext *handle;
29 int events;
30 int revents;
31} URLPollEntry;
32
33#define URL_RDONLY 0
34#define URL_WRONLY 1
35int url_open(URLContext **h, const char *filename, int flags);
36int url_read(URLContext *h, unsigned char *buf, int size);
37int url_write(URLContext *h, unsigned char *buf, int size);
38offset_t url_seek(URLContext *h, offset_t pos, int whence);
39int url_getformat(URLContext *h, URLFormat *f);
40int url_close(URLContext *h);
41int url_exist(const char *filename);
42offset_t url_filesize(URLContext *h);
43/* not implemented */
44int url_poll(URLPollEntry *poll_table, int n, int timeout);
45
46typedef struct URLProtocol {
47 const char *name;
48 int (*url_open)(URLContext *h, const char *filename, int flags);
49 int (*url_read)(URLContext *h, unsigned char *buf, int size);
50 int (*url_write)(URLContext *h, unsigned char *buf, int size);
51 offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
52 int (*url_close)(URLContext *h);
53 /* get precise information about the format, if available. return
54 -ENODATA if not available */
55 int (*url_getformat)(URLContext *h, URLFormat *f);
56 struct URLProtocol *next;
57} URLProtocol;
58
59extern URLProtocol *first_protocol;
60
61int register_protocol(URLProtocol *protocol);
62
63typedef struct {
64 unsigned char *buffer;
65 int buffer_size;
66 unsigned char *buf_ptr, *buf_end;
67 void *opaque;
68 int (*read_packet)(void *opaque, UINT8 *buf, int buf_size);
69 void (*write_packet)(void *opaque, UINT8 *buf, int buf_size);
70 int (*seek)(void *opaque, offset_t offset, int whence);
71 offset_t pos; /* position in the file of the current buffer */
72 int must_flush; /* true if the next seek should flush */
73 int eof_reached; /* true if eof reached */
74 int write_flag; /* true if open for writing */
75 int is_streamed;
76 int packet_size;
77} ByteIOContext;
78
79int init_put_byte(ByteIOContext *s,
80 unsigned char *buffer,
81 int buffer_size,
82 int write_flag,
83 void *opaque,
84 int (*read_packet)(void *opaque, UINT8 *buf, int buf_size),
85 void (*write_packet)(void *opaque, UINT8 *buf, int buf_size),
86 int (*seek)(void *opaque, offset_t offset, int whence));
87
88void put_byte(ByteIOContext *s, int b);
89void put_buffer(ByteIOContext *s, unsigned char *buf, int size);
90void put_le64(ByteIOContext *s, unsigned long long val);
91void put_be64(ByteIOContext *s, unsigned long long val);
92void put_le32(ByteIOContext *s, unsigned int val);
93void put_be32(ByteIOContext *s, unsigned int val);
94void put_le16(ByteIOContext *s, unsigned int val);
95void put_be16(ByteIOContext *s, unsigned int val);
96void put_tag(ByteIOContext *s, char *tag);
97
98offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
99void url_fskip(ByteIOContext *s, offset_t offset);
100offset_t url_ftell(ByteIOContext *s);
101int url_feof(ByteIOContext *s);
102
103void put_flush_packet(ByteIOContext *s);
104
105int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
106int get_byte(ByteIOContext *s);
107unsigned int get_le32(ByteIOContext *s);
108unsigned long long get_le64(ByteIOContext *s);
109unsigned int get_le16(ByteIOContext *s);
110
111unsigned int get_be16(ByteIOContext *s);
112unsigned int get_be32(ByteIOContext *s);
113unsigned long long get_be64(ByteIOContext *s);
114
115extern inline int url_is_streamed(ByteIOContext *s)
116{
117 return s->is_streamed;
118}
119/* get the prefered packet size of the device. All I/Os should be done
120 by multiple of this size */
121extern inline int url_get_packet_size(ByteIOContext *s)
122{
123 return s->packet_size;
124}
125
126int url_fdopen(ByteIOContext *s, URLContext *h);
127int url_setbufsize(ByteIOContext *s, int buf_size);
128int url_fopen(ByteIOContext *s, const char *filename, int flags);
129int url_fclose(ByteIOContext *s);
130URLContext *url_fileno(ByteIOContext *s);
131
132int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags);
133int url_close_buf(ByteIOContext *s);
134
135/* file.c */
136extern URLProtocol file_protocol;
137extern URLProtocol pipe_protocol;
138
139/* udp.c */
140extern URLProtocol udp_protocol;
141
142/* http.c */
143extern URLProtocol http_protocol;
144
145/* audio.c */
146extern const char *audio_device;
147extern URLProtocol audio_protocol;
148
149/* grab.c */
150extern const char *v4l_device;
151extern URLProtocol video_protocol;