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);
00435 #endif
00436
00437 AVIOContext *avio_alloc_context(
00438 unsigned char *buffer,
00439 int buffer_size,
00440 int write_flag,
00441 void *opaque,
00442 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
00443 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
00444 int64_t (*seek)(void *opaque, int64_t offset, int whence));
00445
00446 void avio_w8(AVIOContext *s, int b);
00447 void avio_write(AVIOContext *s, const unsigned char *buf, int size);
00448 void avio_wl64(AVIOContext *s, uint64_t val);
00449 void avio_wb64(AVIOContext *s, uint64_t val);
00450 void avio_wl32(AVIOContext *s, unsigned int val);
00451 void avio_wb32(AVIOContext *s, unsigned int val);
00452 void avio_wl24(AVIOContext *s, unsigned int val);
00453 void avio_wb24(AVIOContext *s, unsigned int val);
00454 void avio_wl16(AVIOContext *s, unsigned int val);
00455 void avio_wb16(AVIOContext *s, unsigned int val);
00456
00457 #if FF_API_OLD_AVIO
00458 attribute_deprecated void put_strz(AVIOContext *s, const char *buf);
00459 #endif
00460
00465 int avio_put_str(AVIOContext *s, const char *str);
00466
00471 int avio_put_str16le(AVIOContext *s, const char *str);
00472
00477 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
00478
00483 #define avio_skip(s, offset) avio_seek(s, offset, SEEK_CUR)
00484
00489 #define avio_tell(s) avio_seek((s), 0, SEEK_CUR)
00490
00495 int64_t avio_size(AVIOContext *s);
00496
00501 int url_feof(AVIOContext *s);
00502
00503 int url_ferror(AVIOContext *s);
00504
00505 int av_url_read_fpause(AVIOContext *h, int pause);
00506 int64_t av_url_read_fseek(AVIOContext *h, int stream_index,
00507 int64_t timestamp, int flags);
00508
00510 #ifdef __GNUC__
00511 int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
00512 #else
00513 int url_fprintf(AVIOContext *s, const char *fmt, ...);
00514 #endif
00515
00516 #if FF_API_OLD_AVIO
00517
00519 attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
00520 #endif
00521
00522 void put_flush_packet(AVIOContext *s);
00523
00524
00529 int avio_read(AVIOContext *s, unsigned char *buf, int size);
00530
00533 int avio_r8 (AVIOContext *s);
00534 unsigned int avio_rl16(AVIOContext *s);
00535 unsigned int avio_rl24(AVIOContext *s);
00536 unsigned int avio_rl32(AVIOContext *s);
00537 uint64_t avio_rl64(AVIOContext *s);
00538
00551 int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
00552
00559 int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
00560 int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
00561
00562 #if FF_API_OLD_AVIO
00563
00566 attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
00567 #endif
00568 unsigned int avio_rb16(AVIOContext *s);
00569 unsigned int avio_rb24(AVIOContext *s);
00570 unsigned int avio_rb32(AVIOContext *s);
00571 uint64_t avio_rb64(AVIOContext *s);
00572
00573 uint64_t ff_get_v(AVIOContext *bc);
00574
00575 static inline int url_is_streamed(AVIOContext *s)
00576 {
00577 return s->is_streamed;
00578 }
00579
00591 int url_fdopen(AVIOContext **s, URLContext *h);
00592
00594 int url_setbufsize(AVIOContext *s, int buf_size);
00595 #if FF_API_URL_RESETBUF
00596
00600 int url_resetbuf(AVIOContext *s, int flags);
00601 #endif
00602
00616 int avio_open(AVIOContext **s, const char *url, int flags);
00617
00618 int avio_close(AVIOContext *s);
00619 URLContext *url_fileno(AVIOContext *s);
00620
00621 #if FF_API_OLD_AVIO
00622
00625 attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
00626 #endif
00627
00628 int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags);
00629
00631 int url_close_buf(AVIOContext *s);
00632
00639 int url_open_dyn_buf(AVIOContext **s);
00640
00650 int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
00651
00662 int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
00663
00664 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
00665 unsigned int len);
00666 unsigned long get_checksum(AVIOContext *s);
00667 void init_checksum(AVIOContext *s,
00668 unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
00669 unsigned long checksum);
00670
00671
00672 int udp_set_remote_url(URLContext *h, const char *uri);
00673 int udp_get_local_port(URLContext *h);
00674 #if FF_API_UDP_GET_FILE
00675 int udp_get_file_handle(URLContext *h);
00676 #endif
00677
00678 #endif