00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef AVFORMAT_AVIO_H
00021 #define AVFORMAT_AVIO_H
00022
00031 #include <stdint.h>
00032
00033 #include "libavutil/common.h"
00034 #include "libavutil/log.h"
00035
00036 #include "libavformat/version.h"
00037
00038
00039
00047 typedef struct URLContext {
00048 #if FF_API_URL_CLASS
00049 const AVClass *av_class;
00050 #endif
00051 struct URLProtocol *prot;
00052 int flags;
00053 int is_streamed;
00054 int max_packet_size;
00055 void *priv_data;
00056 char *filename;
00057 int is_connected;
00058 } URLContext;
00059
00060 typedef struct URLPollEntry {
00061 URLContext *handle;
00062 int events;
00063 int revents;
00064 } URLPollEntry;
00065
00072 #define URL_RDONLY 0
00073 #define URL_WRONLY 1
00074 #define URL_RDWR 2
00091 #define URL_FLAG_NONBLOCK 4
00092
00093 typedef int URLInterruptCB(void);
00094
00106 int url_open_protocol (URLContext **puc, struct URLProtocol *up,
00107 const char *url, int flags);
00108
00120 int url_alloc(URLContext **h, const char *url, int flags);
00121
00125 int url_connect(URLContext *h);
00126
00138 int url_open(URLContext **h, const char *url, int flags);
00139
00149 int url_read(URLContext *h, unsigned char *buf, int size);
00150
00158 int url_read_complete(URLContext *h, unsigned char *buf, int size);
00159
00166 int url_write(URLContext *h, const unsigned char *buf, int size);
00167
00173 #define AVSEEK_SIZE 0x10000
00174
00189 int64_t url_seek(URLContext *h, int64_t pos, int whence);
00190
00198 int url_close(URLContext *h);
00199
00204 int url_exist(const char *url);
00205
00211 int64_t url_filesize(URLContext *h);
00212
00219 int url_get_file_handle(URLContext *h);
00220
00229 int url_get_max_packet_size(URLContext *h);
00230
00236 void url_get_filename(URLContext *h, char *buf, int buf_size);
00237
00244 void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
00245
00246
00247 int url_poll(URLPollEntry *poll_table, int n, int timeout);
00248
00254 int av_url_read_pause(URLContext *h, int pause);
00255
00273 int64_t av_url_read_seek(URLContext *h, int stream_index,
00274 int64_t timestamp, int flags);
00275
00282 #define AVSEEK_FORCE 0x20000
00283
00284 #define URL_PROTOCOL_FLAG_NESTED_SCHEME 1
00285
00286 typedef struct URLProtocol {
00287 const char *name;
00288 int (*url_open)(URLContext *h, const char *url, int flags);
00289 int (*url_read)(URLContext *h, unsigned char *buf, int size);
00290 int (*url_write)(URLContext *h, const unsigned char *buf, int size);
00291 int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
00292 int (*url_close)(URLContext *h);
00293 struct URLProtocol *next;
00294 int (*url_read_pause)(URLContext *h, int pause);
00295 int64_t (*url_read_seek)(URLContext *h, int stream_index,
00296 int64_t timestamp, int flags);
00297 int (*url_get_file_handle)(URLContext *h);
00298 int priv_data_size;
00299 const AVClass *priv_data_class;
00300 int flags;
00301 } URLProtocol;
00302
00303 #if FF_API_REGISTER_PROTOCOL
00304 extern URLProtocol *first_protocol;
00305 #endif
00306
00307 extern URLInterruptCB *url_interrupt_cb;
00308
00314 URLProtocol *av_protocol_next(URLProtocol *p);
00315
00316 #if FF_API_REGISTER_PROTOCOL
00317
00320 attribute_deprecated int register_protocol(URLProtocol *protocol);
00321
00325 attribute_deprecated int av_register_protocol(URLProtocol *protocol);
00326 #endif
00327
00333 int av_register_protocol2(URLProtocol *protocol, int size);
00334
00342 typedef struct {
00343 unsigned char *buffer;
00344 int buffer_size;
00345 unsigned char *buf_ptr, *buf_end;
00346 void *opaque;
00347 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
00348 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
00349 int64_t (*seek)(void *opaque, int64_t offset, int whence);
00350 int64_t pos;
00351 int must_flush;
00352 int eof_reached;
00353 int write_flag;
00354 int is_streamed;
00355 int max_packet_size;
00356 unsigned long checksum;
00357 unsigned char *checksum_ptr;
00358 unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
00359 int error;
00360 int (*read_pause)(void *opaque, int pause);
00361 int64_t (*read_seek)(void *opaque, int stream_index,
00362 int64_t timestamp, int flags);
00363 } AVIOContext;
00364
00365 #if FF_API_OLD_AVIO
00366 typedef attribute_deprecated AVIOContext ByteIOContext;
00367
00368 attribute_deprecated int init_put_byte(AVIOContext *s,
00369 unsigned char *buffer,
00370 int buffer_size,
00371 int write_flag,
00372 void *opaque,
00373 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
00374 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
00375 int64_t (*seek)(void *opaque, int64_t offset, int whence));
00376 attribute_deprecated AVIOContext *av_alloc_put_byte(
00377 unsigned char *buffer,
00378 int buffer_size,
00379 int write_flag,
00380 void *opaque,
00381 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
00382 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
00383 int64_t (*seek)(void *opaque, int64_t offset, int whence));
00384
00390 attribute_deprecated int get_buffer(AVIOContext *s, unsigned char *buf, int size);
00391 attribute_deprecated int get_partial_buffer(AVIOContext *s, unsigned char *buf, int size);
00392 attribute_deprecated int get_byte(AVIOContext *s);
00393 attribute_deprecated unsigned int get_le16(AVIOContext *s);
00394 attribute_deprecated unsigned int get_le24(AVIOContext *s);
00395 attribute_deprecated unsigned int get_le32(AVIOContext *s);
00396 attribute_deprecated uint64_t get_le64(AVIOContext *s);
00397 attribute_deprecated unsigned int get_be16(AVIOContext *s);
00398 attribute_deprecated unsigned int get_be24(AVIOContext *s);
00399 attribute_deprecated unsigned int get_be32(AVIOContext *s);
00400 attribute_deprecated uint64_t get_be64(AVIOContext *s);
00401
00402 attribute_deprecated void put_byte(AVIOContext *s, int b);
00403 attribute_deprecated void put_nbyte(AVIOContext *s, int b, int count);
00404 attribute_deprecated void put_buffer(AVIOContext *s, const unsigned char *buf, int size);
00405 attribute_deprecated void put_le64(AVIOContext *s, uint64_t val);
00406 attribute_deprecated void put_be64(AVIOContext *s, uint64_t val);
00407 attribute_deprecated void put_le32(AVIOContext *s, unsigned int val);
00408 attribute_deprecated void put_be32(AVIOContext *s, unsigned int val);
00409 attribute_deprecated void put_le24(AVIOContext *s, unsigned int val);
00410 attribute_deprecated void put_be24(AVIOContext *s, unsigned int val);
00411 attribute_deprecated void put_le16(AVIOContext *s, unsigned int val);
00412 attribute_deprecated void put_be16(AVIOContext *s, unsigned int val);
00413 attribute_deprecated void put_tag(AVIOContext *s, const char *tag);
00424 attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
00425 attribute_deprecated int url_fclose(AVIOContext *s);
00426 attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence);
00427 attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
00428 attribute_deprecated int64_t url_ftell(AVIOContext *s);
00429 attribute_deprecated int64_t url_fsize(AVIOContext *s);
00430 #define URL_EOF (-1)
00431 attribute_deprecated int url_fgetc(AVIOContext *s);
00432 attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
00433 #ifdef __GNUC__
00434 attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
00435 #else
00436 attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...);
00437 #endif
00438 attribute_deprecated void put_flush_packet(AVIOContext *s);
00443 attribute_deprecated int url_ferror(AVIOContext *s);
00444 #endif
00445
00446 AVIOContext *avio_alloc_context(
00447 unsigned char *buffer,
00448 int buffer_size,
00449 int write_flag,
00450 void *opaque,
00451 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
00452 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
00453 int64_t (*seek)(void *opaque, int64_t offset, int whence));
00454
00455 void avio_w8(AVIOContext *s, int b);
00456 void avio_write(AVIOContext *s, const unsigned char *buf, int size);
00457 void avio_wl64(AVIOContext *s, uint64_t val);
00458 void avio_wb64(AVIOContext *s, uint64_t val);
00459 void avio_wl32(AVIOContext *s, unsigned int val);
00460 void avio_wb32(AVIOContext *s, unsigned int val);
00461 void avio_wl24(AVIOContext *s, unsigned int val);
00462 void avio_wb24(AVIOContext *s, unsigned int val);
00463 void avio_wl16(AVIOContext *s, unsigned int val);
00464 void avio_wb16(AVIOContext *s, unsigned int val);
00465
00466 #if FF_API_OLD_AVIO
00467 attribute_deprecated void put_strz(AVIOContext *s, const char *buf);
00468 #endif
00469
00474 int avio_put_str(AVIOContext *s, const char *str);
00475
00480 int avio_put_str16le(AVIOContext *s, const char *str);
00481
00486 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
00487
00492 int64_t avio_skip(AVIOContext *s, int64_t offset);
00493
00498 static av_always_inline int64_t avio_tell(AVIOContext *s)
00499 {
00500 return avio_seek(s, 0, SEEK_CUR);
00501 }
00502
00507 int64_t avio_size(AVIOContext *s);
00508
00513 int url_feof(AVIOContext *s);
00514
00515 int av_url_read_fpause(AVIOContext *h, int pause);
00516 int64_t av_url_read_fseek(AVIOContext *h, int stream_index,
00517 int64_t timestamp, int flags);
00518
00520 #ifdef __GNUC__
00521 int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
00522 #else
00523 int avio_printf(AVIOContext *s, const char *fmt, ...);
00524 #endif
00525
00526 #if FF_API_OLD_AVIO
00527
00529 attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
00530 #endif
00531
00532 void avio_flush(AVIOContext *s);
00533
00534
00539 int avio_read(AVIOContext *s, unsigned char *buf, int size);
00540
00543 int avio_r8 (AVIOContext *s);
00544 unsigned int avio_rl16(AVIOContext *s);
00545 unsigned int avio_rl24(AVIOContext *s);
00546 unsigned int avio_rl32(AVIOContext *s);
00547 uint64_t avio_rl64(AVIOContext *s);
00548
00561 int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
00562
00569 int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
00570 int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
00571
00572 #if FF_API_OLD_AVIO
00573
00576 attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
00577 #endif
00578 unsigned int avio_rb16(AVIOContext *s);
00579 unsigned int avio_rb24(AVIOContext *s);
00580 unsigned int avio_rb32(AVIOContext *s);
00581 uint64_t avio_rb64(AVIOContext *s);
00582
00583 static inline int url_is_streamed(AVIOContext *s)
00584 {
00585 return s->is_streamed;
00586 }
00587
00599 int url_fdopen(AVIOContext **s, URLContext *h);
00600
00601 #if FF_API_URL_RESETBUF
00602
00606 int url_resetbuf(AVIOContext *s, int flags);
00607 #endif
00608
00622 int avio_open(AVIOContext **s, const char *url, int flags);
00623
00624 int avio_close(AVIOContext *s);
00625 URLContext *url_fileno(AVIOContext *s);
00626
00627 #if FF_API_OLD_AVIO
00628
00631 attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
00632
00633 attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags);
00634
00636 attribute_deprecated int url_close_buf(AVIOContext *s);
00637 #endif
00638
00645 int url_open_dyn_buf(AVIOContext **s);
00646
00656 int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
00657
00668 int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
00669
00670 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
00671 unsigned int len);
00672 unsigned long get_checksum(AVIOContext *s);
00673 void init_checksum(AVIOContext *s,
00674 unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
00675 unsigned long checksum);
00676
00677
00678 int udp_set_remote_url(URLContext *h, const char *uri);
00679 int udp_get_local_port(URLContext *h);
00680 #if FF_API_UDP_GET_FILE
00681 int udp_get_file_handle(URLContext *h);
00682 #endif
00683
00684 #endif