added url_get_filename()
[libav.git] / libavformat / avio.h
1 #ifndef AVIO_H
2 #define AVIO_H
3
4 /* output byte stream handling */
5
6 typedef INT64 offset_t;
7
8 /* unbuffered I/O */
9
10 struct URLContext {
11 struct URLProtocol *prot;
12 int flags;
13 int is_streamed; /* true if streamed (no seek possible), default = false */
14 int max_packet_size; /* if non zero, the stream is packetized with this max packet size */
15 void *priv_data;
16 char filename[1]; /* specified filename */
17 };
18
19 typedef struct URLContext URLContext;
20
21 typedef struct URLPollEntry {
22 URLContext *handle;
23 int events;
24 int revents;
25 } URLPollEntry;
26
27 #define URL_RDONLY 0
28 #define URL_WRONLY 1
29 #define URL_RDWR 2
30
31 int url_open(URLContext **h, const char *filename, int flags);
32 int url_read(URLContext *h, unsigned char *buf, int size);
33 int url_write(URLContext *h, unsigned char *buf, int size);
34 offset_t url_seek(URLContext *h, offset_t pos, int whence);
35 int url_close(URLContext *h);
36 int url_exist(const char *filename);
37 offset_t url_filesize(URLContext *h);
38 int url_get_max_packet_size(URLContext *h);
39 void url_get_filename(URLContext *h, char *buf, int buf_size);
40
41 /* not implemented */
42 int url_poll(URLPollEntry *poll_table, int n, int timeout);
43
44 typedef struct URLProtocol {
45 const char *name;
46 int (*url_open)(URLContext *h, const char *filename, int flags);
47 int (*url_read)(URLContext *h, unsigned char *buf, int size);
48 int (*url_write)(URLContext *h, unsigned char *buf, int size);
49 offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
50 int (*url_close)(URLContext *h);
51 struct URLProtocol *next;
52 } URLProtocol;
53
54 extern URLProtocol *first_protocol;
55
56 int register_protocol(URLProtocol *protocol);
57
58 typedef struct {
59 unsigned char *buffer;
60 int buffer_size;
61 unsigned char *buf_ptr, *buf_end;
62 void *opaque;
63 int (*read_packet)(void *opaque, UINT8 *buf, int buf_size);
64 void (*write_packet)(void *opaque, UINT8 *buf, int buf_size);
65 int (*seek)(void *opaque, offset_t offset, int whence);
66 offset_t pos; /* position in the file of the current buffer */
67 int must_flush; /* true if the next seek should flush */
68 int eof_reached; /* true if eof reached */
69 int write_flag; /* true if open for writing */
70 int is_streamed;
71 int max_packet_size;
72 } ByteIOContext;
73
74 int init_put_byte(ByteIOContext *s,
75 unsigned char *buffer,
76 int buffer_size,
77 int write_flag,
78 void *opaque,
79 int (*read_packet)(void *opaque, UINT8 *buf, int buf_size),
80 void (*write_packet)(void *opaque, UINT8 *buf, int buf_size),
81 int (*seek)(void *opaque, offset_t offset, int whence));
82
83 void put_byte(ByteIOContext *s, int b);
84 void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
85 void put_le64(ByteIOContext *s, UINT64 val);
86 void put_be64(ByteIOContext *s, UINT64 val);
87 void put_le32(ByteIOContext *s, unsigned int val);
88 void put_be32(ByteIOContext *s, unsigned int val);
89 void put_le16(ByteIOContext *s, unsigned int val);
90 void put_be16(ByteIOContext *s, unsigned int val);
91 void put_tag(ByteIOContext *s, const char *tag);
92
93 void put_be64_double(ByteIOContext *s, double val);
94 void put_strz(ByteIOContext *s, const char *buf);
95
96 offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
97 void url_fskip(ByteIOContext *s, offset_t offset);
98 offset_t url_ftell(ByteIOContext *s);
99 int url_feof(ByteIOContext *s);
100
101 #define URL_EOF (-1)
102 int url_fgetc(ByteIOContext *s);
103 int url_fprintf(ByteIOContext *s, const char *fmt, ...);
104 char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
105
106 void put_flush_packet(ByteIOContext *s);
107
108 int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
109 int get_byte(ByteIOContext *s);
110 unsigned int get_le32(ByteIOContext *s);
111 UINT64 get_le64(ByteIOContext *s);
112 unsigned int get_le16(ByteIOContext *s);
113
114 double get_be64_double(ByteIOContext *s);
115 char *get_strz(ByteIOContext *s, char *buf, int maxlen);
116 unsigned int get_be16(ByteIOContext *s);
117 unsigned int get_be32(ByteIOContext *s);
118 UINT64 get_be64(ByteIOContext *s);
119
120 static inline int url_is_streamed(ByteIOContext *s)
121 {
122 return s->is_streamed;
123 }
124
125 int url_fdopen(ByteIOContext *s, URLContext *h);
126 int url_setbufsize(ByteIOContext *s, int buf_size);
127 int url_fopen(ByteIOContext *s, const char *filename, int flags);
128 int url_fclose(ByteIOContext *s);
129 URLContext *url_fileno(ByteIOContext *s);
130 int url_fget_max_packet_size(ByteIOContext *s);
131
132 int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags);
133 int url_close_buf(ByteIOContext *s);
134
135 int url_open_dyn_buf(ByteIOContext *s);
136 int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
137 int url_close_dyn_buf(ByteIOContext *s, UINT8 **pbuffer);
138
139 /* file.c */
140 extern URLProtocol file_protocol;
141 extern URLProtocol pipe_protocol;
142
143 /* udp.c */
144 extern URLProtocol udp_protocol;
145 int udp_set_remote_url(URLContext *h, const char *uri);
146 int udp_get_local_port(URLContext *h);
147 int udp_get_file_handle(URLContext *h);
148
149 /* tcp.c */
150 extern URLProtocol tcp_protocol;
151
152 /* http.c */
153 extern URLProtocol http_protocol;
154
155 #endif
156