avio.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2001 Fabrice Bellard
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 #ifndef AVFORMAT_AVIO_H
21 #define AVFORMAT_AVIO_H
22 
29 #include <stdint.h>
30 
31 #include "libavutil/common.h"
32 #include "libavutil/dict.h"
33 #include "libavutil/log.h"
34 
35 #include "libavformat/version.h"
36 
37 
38 #define AVIO_SEEKABLE_NORMAL 0x0001
51 typedef struct {
52  int (*callback)(void*);
53  void *opaque;
55 
68 typedef struct {
69 #if !FF_API_OLD_AVIO
70 
83 #endif
84  unsigned char *buffer;
86  unsigned char *buf_ptr;
87  unsigned char *buf_end;
91  void *opaque;
93  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
94  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
95  int64_t (*seek)(void *opaque, int64_t offset, int whence);
96  int64_t pos;
97  int must_flush;
99  int write_flag;
100 #if FF_API_OLD_AVIO
101  attribute_deprecated int is_streamed;
102 #endif
104  unsigned long checksum;
105  unsigned char *checksum_ptr;
106  unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
107  int error;
111  int (*read_pause)(void *opaque, int pause);
117  int64_t (*read_seek)(void *opaque, int stream_index,
118  int64_t timestamp, int flags);
122  int seekable;
123 } AVIOContext;
124 
125 /* unbuffered I/O */
126 
127 #if FF_API_OLD_AVIO
128 
136 typedef struct URLContext {
137  const AVClass *av_class;
138  struct URLProtocol *prot;
139  int flags;
140  int is_streamed;
141  int max_packet_size;
142  void *priv_data;
143  char *filename;
144  int is_connected;
146 } URLContext;
147 
148 #define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
149 #define URL_PROTOCOL_FLAG_NETWORK 2 /*< The protocol uses network */
150 
155 typedef struct URLProtocol {
156  const char *name;
157  int (*url_open)(URLContext *h, const char *url, int flags);
158  int (*url_read)(URLContext *h, unsigned char *buf, int size);
159  int (*url_write)(URLContext *h, const unsigned char *buf, int size);
160  int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
161  int (*url_close)(URLContext *h);
162  struct URLProtocol *next;
163  int (*url_read_pause)(URLContext *h, int pause);
164  int64_t (*url_read_seek)(URLContext *h, int stream_index,
165  int64_t timestamp, int flags);
166  int (*url_get_file_handle)(URLContext *h);
167  int priv_data_size;
168  const AVClass *priv_data_class;
169  int flags;
170  int (*url_check)(URLContext *h, int mask);
171 } URLProtocol;
172 
173 typedef struct URLPollEntry {
174  URLContext *handle;
175  int events;
176  int revents;
177 } URLPollEntry;
178 
179 /* not implemented */
180 attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout);
181 
188 #define URL_RDONLY 1
189 #define URL_WRONLY 2
190 #define URL_RDWR (URL_RDONLY|URL_WRONLY)
207 #define URL_FLAG_NONBLOCK 8
208 
209 typedef int URLInterruptCB(void);
210 extern URLInterruptCB *url_interrupt_cb;
211 
218 attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol *up,
219  const char *url, int flags);
220 attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags);
221 attribute_deprecated int url_connect(URLContext *h);
222 attribute_deprecated int url_open(URLContext **h, const char *url, int flags);
223 attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size);
224 attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size);
225 attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size);
226 attribute_deprecated int64_t url_seek(URLContext *h, int64_t pos, int whence);
227 attribute_deprecated int url_close(URLContext *h);
228 attribute_deprecated int64_t url_filesize(URLContext *h);
229 attribute_deprecated int url_get_file_handle(URLContext *h);
230 attribute_deprecated int url_get_max_packet_size(URLContext *h);
231 attribute_deprecated void url_get_filename(URLContext *h, char *buf, int buf_size);
232 attribute_deprecated int av_url_read_pause(URLContext *h, int pause);
233 attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index,
234  int64_t timestamp, int flags);
235 attribute_deprecated void url_set_interrupt_cb(int (*interrupt_cb)(void));
241 attribute_deprecated URLProtocol *av_protocol_next(URLProtocol *p);
247 attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size);
253 typedef attribute_deprecated AVIOContext ByteIOContext;
254 
255 attribute_deprecated int init_put_byte(AVIOContext *s,
256  unsigned char *buffer,
257  int buffer_size,
258  int write_flag,
259  void *opaque,
260  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
261  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
262  int64_t (*seek)(void *opaque, int64_t offset, int whence));
263 attribute_deprecated AVIOContext *av_alloc_put_byte(
264  unsigned char *buffer,
265  int buffer_size,
266  int write_flag,
267  void *opaque,
268  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
269  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
270  int64_t (*seek)(void *opaque, int64_t offset, int whence));
271 
278 attribute_deprecated int get_buffer(AVIOContext *s, unsigned char *buf, int size);
279 attribute_deprecated int get_partial_buffer(AVIOContext *s, unsigned char *buf, int size);
281 attribute_deprecated unsigned int get_le16(AVIOContext *s);
282 attribute_deprecated unsigned int get_le24(AVIOContext *s);
283 attribute_deprecated unsigned int get_le32(AVIOContext *s);
284 attribute_deprecated uint64_t get_le64(AVIOContext *s);
285 attribute_deprecated unsigned int get_be16(AVIOContext *s);
286 attribute_deprecated unsigned int get_be24(AVIOContext *s);
287 attribute_deprecated unsigned int get_be32(AVIOContext *s);
288 attribute_deprecated uint64_t get_be64(AVIOContext *s);
289 
290 attribute_deprecated void put_byte(AVIOContext *s, int b);
291 attribute_deprecated void put_nbyte(AVIOContext *s, int b, int count);
292 attribute_deprecated void put_buffer(AVIOContext *s, const unsigned char *buf, int size);
293 attribute_deprecated void put_le64(AVIOContext *s, uint64_t val);
294 attribute_deprecated void put_be64(AVIOContext *s, uint64_t val);
295 attribute_deprecated void put_le32(AVIOContext *s, unsigned int val);
296 attribute_deprecated void put_be32(AVIOContext *s, unsigned int val);
297 attribute_deprecated void put_le24(AVIOContext *s, unsigned int val);
298 attribute_deprecated void put_be24(AVIOContext *s, unsigned int val);
299 attribute_deprecated void put_le16(AVIOContext *s, unsigned int val);
300 attribute_deprecated void put_be16(AVIOContext *s, unsigned int val);
301 attribute_deprecated void put_tag(AVIOContext *s, const char *tag);
306 attribute_deprecated int av_url_read_fpause(AVIOContext *h, int pause);
307 attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h, int stream_index,
308  int64_t timestamp, int flags);
309 
316 attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
317 attribute_deprecated int url_fclose(AVIOContext *s);
318 attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence);
319 attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
320 attribute_deprecated int64_t url_ftell(AVIOContext *s);
321 attribute_deprecated int64_t url_fsize(AVIOContext *s);
322 #define URL_EOF (-1)
323 attribute_deprecated int url_fgetc(AVIOContext *s);
324 attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
325 attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
326 attribute_deprecated void put_flush_packet(AVIOContext *s);
327 attribute_deprecated int url_open_dyn_buf(AVIOContext **s);
328 attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
329 attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
330 attribute_deprecated int url_fdopen(AVIOContext **s, URLContext *h);
338 attribute_deprecated int url_feof(AVIOContext *s);
339 attribute_deprecated int url_ferror(AVIOContext *s);
340 
341 attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri);
342 attribute_deprecated int udp_get_local_port(URLContext *h);
343 
344 attribute_deprecated void init_checksum(AVIOContext *s,
345  unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
346  unsigned long checksum);
347 attribute_deprecated unsigned long get_checksum(AVIOContext *s);
348 attribute_deprecated void put_strz(AVIOContext *s, const char *buf);
351 attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
355 attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
359 attribute_deprecated static inline int url_is_streamed(AVIOContext *s)
360 {
361  return !s->seekable;
362 }
364 
368 attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
369 
370 attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags);
371 
373 attribute_deprecated int url_close_buf(AVIOContext *s);
374 
380 attribute_deprecated int url_exist(const char *url);
381 #endif // FF_API_OLD_AVIO
382 
395 int avio_check(const char *url, int flags);
396 
397 #if FF_API_OLD_INTERRUPT_CB
398 
406 attribute_deprecated void avio_set_interrupt_cb(int (*interrupt_cb)(void));
407 #endif
408 
427  unsigned char *buffer,
428  int buffer_size,
429  int write_flag,
430  void *opaque,
431  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
432  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
433  int64_t (*seek)(void *opaque, int64_t offset, int whence));
434 
435 void avio_w8(AVIOContext *s, int b);
436 void avio_write(AVIOContext *s, const unsigned char *buf, int size);
437 void avio_wl64(AVIOContext *s, uint64_t val);
438 void avio_wb64(AVIOContext *s, uint64_t val);
439 void avio_wl32(AVIOContext *s, unsigned int val);
440 void avio_wb32(AVIOContext *s, unsigned int val);
441 void avio_wl24(AVIOContext *s, unsigned int val);
442 void avio_wb24(AVIOContext *s, unsigned int val);
443 void avio_wl16(AVIOContext *s, unsigned int val);
444 void avio_wb16(AVIOContext *s, unsigned int val);
445 
450 int avio_put_str(AVIOContext *s, const char *str);
451 
456 int avio_put_str16le(AVIOContext *s, const char *str);
457 
463 #define AVSEEK_SIZE 0x10000
464 
471 #define AVSEEK_FORCE 0x20000
472 
477 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
478 
483 static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
484 {
485  return avio_seek(s, offset, SEEK_CUR);
486 }
487 
493 {
494  return avio_seek(s, 0, SEEK_CUR);
495 }
496 
501 int64_t avio_size(AVIOContext *s);
502 
504 int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
505 
506 void avio_flush(AVIOContext *s);
507 
508 
513 int avio_read(AVIOContext *s, unsigned char *buf, int size);
514 
522 int avio_r8 (AVIOContext *s);
523 unsigned int avio_rl16(AVIOContext *s);
524 unsigned int avio_rl24(AVIOContext *s);
525 unsigned int avio_rl32(AVIOContext *s);
526 uint64_t avio_rl64(AVIOContext *s);
527 unsigned int avio_rb16(AVIOContext *s);
528 unsigned int avio_rb24(AVIOContext *s);
529 unsigned int avio_rb32(AVIOContext *s);
530 uint64_t avio_rb64(AVIOContext *s);
547 int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
548 
555 int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
556 int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
557 
558 
565 #define AVIO_FLAG_READ 1
566 #define AVIO_FLAG_WRITE 2
567 #define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE)
584 #define AVIO_FLAG_NONBLOCK 8
585 
599 int avio_open(AVIOContext **s, const char *url, int flags);
600 
618 int avio_open2(AVIOContext **s, const char *url, int flags,
620 
627 int avio_close(AVIOContext *s);
628 
636 
646 int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
647 
659 const char *avio_enum_protocols(void **opaque, int output);
660 
666 int avio_pause(AVIOContext *h, int pause);
667 
685 int64_t avio_seek_time(AVIOContext *h, int stream_index,
686  int64_t timestamp, int flags);
687 
688 #endif /* AVFORMAT_AVIO_H */