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
00037
00045 typedef struct URLContext {
00046 #if FF_API_URL_CLASS
00047 const AVClass *av_class;
00048 #endif
00049 struct URLProtocol *prot;
00050 int flags;
00051 int is_streamed;
00052 int max_packet_size;
00053 void *priv_data;
00054 char *filename;
00055 int is_connected;
00056 } URLContext;
00057
00058 typedef struct URLPollEntry {
00059 URLContext *handle;
00060 int events;
00061 int revents;
00062 } URLPollEntry;
00063
00064 #define URL_RDONLY 0
00065 #define URL_WRONLY 1
00066 #define URL_RDWR 2
00067
00068 typedef int URLInterruptCB(void);
00069
00081 int url_open_protocol (URLContext **puc, struct URLProtocol *up,
00082 const char *url, int flags);
00083
00095 int url_alloc(URLContext **h, const char *url, int flags);
00096
00100 int url_connect(URLContext *h);
00101
00113 int url_open(URLContext **h, const char *url, int flags);
00114
00124 int url_read(URLContext *h, unsigned char *buf, int size);
00125
00134 int url_read_complete(URLContext *h, unsigned char *buf, int size);
00135
00142 int url_write(URLContext *h, const unsigned char *buf, int size);
00143
00149 #define AVSEEK_SIZE 0x10000
00150
00165 int64_t url_seek(URLContext *h, int64_t pos, int whence);
00166
00174 int url_close(URLContext *h);
00175
00180 int url_exist(const char *url);
00181
00187 int64_t url_filesize(URLContext *h);
00188
00195 int url_get_file_handle(URLContext *h);
00196
00205 int url_get_max_packet_size(URLContext *h);
00206
00212 void url_get_filename(URLContext *h, char *buf, int buf_size);
00213
00220 void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
00221
00222
00223 int url_poll(URLPollEntry *poll_table, int n, int timeout);
00224
00230 int av_url_read_pause(URLContext *h, int pause);
00231
00249 int64_t av_url_read_seek(URLContext *h, int stream_index,
00250 int64_t timestamp, int flags);
00251
00258 #define AVSEEK_FORCE 0x20000
00259
00260 typedef struct URLProtocol {
00261 const char *name;
00262 int (*url_open)(URLContext *h, const char *url, int flags);
00263 int (*url_read)(URLContext *h, unsigned char *buf, int size);
00264 int (*url_write)(URLContext *h, const unsigned char *buf, int size);
00265 int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
00266 int (*url_close)(URLContext *h);
00267 struct URLProtocol *next;
00268 int (*url_read_pause)(URLContext *h, int pause);
00269 int64_t (*url_read_seek)(URLContext *h, int stream_index,
00270 int64_t timestamp, int flags);
00271 int (*url_get_file_handle)(URLContext *h);
00272 int priv_data_size;
00273 const AVClass *priv_data_class;
00274 } URLProtocol;
00275
00276 #if FF_API_REGISTER_PROTOCOL
00277 extern URLProtocol *first_protocol;
00278 #endif
00279
00280 extern URLInterruptCB *url_interrupt_cb;
00281
00287 URLProtocol *av_protocol_next(URLProtocol *p);
00288
00289 #if FF_API_REGISTER_PROTOCOL
00290
00293 attribute_deprecated int register_protocol(URLProtocol *protocol);
00294
00298 attribute_deprecated int av_register_protocol(URLProtocol *protocol);
00299 #endif
00300
00306 int av_register_protocol2(URLProtocol *protocol, int size);
00307
00315 typedef struct {
00316 unsigned char *buffer;
00317 int buffer_size;
00318 unsigned char *buf_ptr, *buf_end;
00319 void *opaque;
00320 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
00321 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
00322 int64_t (*seek)(void *opaque, int64_t offset, int whence);
00323 int64_t pos;
00324 int must_flush;
00325 int eof_reached;
00326 int write_flag;
00327 int is_streamed;
00328 int max_packet_size;
00329 unsigned long checksum;
00330 unsigned char *checksum_ptr;
00331 unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
00332 int error;
00333 int (*read_pause)(void *opaque, int pause);
00334 int64_t (*read_seek)(void *opaque, int stream_index,
00335 int64_t timestamp, int flags);
00336 } ByteIOContext;
00337
00338 int init_put_byte(ByteIOContext *s,
00339 unsigned char *buffer,
00340 int buffer_size,
00341 int write_flag,
00342 void *opaque,
00343 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
00344 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
00345 int64_t (*seek)(void *opaque, int64_t offset, int whence));
00346 ByteIOContext *av_alloc_put_byte(
00347 unsigned char *buffer,
00348 int buffer_size,
00349 int write_flag,
00350 void *opaque,
00351 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
00352 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
00353 int64_t (*seek)(void *opaque, int64_t offset, int whence));
00354
00355 void put_byte(ByteIOContext *s, int b);
00356 void put_nbyte(ByteIOContext *s, int b, int count);
00357 void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
00358 void put_le64(ByteIOContext *s, uint64_t val);
00359 void put_be64(ByteIOContext *s, uint64_t val);
00360 void put_le32(ByteIOContext *s, unsigned int val);
00361 void put_be32(ByteIOContext *s, unsigned int val);
00362 void put_le24(ByteIOContext *s, unsigned int val);
00363 void put_be24(ByteIOContext *s, unsigned int val);
00364 void put_le16(ByteIOContext *s, unsigned int val);
00365 void put_be16(ByteIOContext *s, unsigned int val);
00366 void put_tag(ByteIOContext *s, const char *tag);
00367
00368 void put_strz(ByteIOContext *s, const char *buf);
00369
00374 int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence);
00375
00381 int url_fskip(ByteIOContext *s, int64_t offset);
00382
00387 int64_t url_ftell(ByteIOContext *s);
00388
00393 int64_t url_fsize(ByteIOContext *s);
00394
00399 int url_feof(ByteIOContext *s);
00400
00401 int url_ferror(ByteIOContext *s);
00402
00403 int av_url_read_fpause(ByteIOContext *h, int pause);
00404 int64_t av_url_read_fseek(ByteIOContext *h, int stream_index,
00405 int64_t timestamp, int flags);
00406
00407 #define URL_EOF (-1)
00408
00409 int url_fgetc(ByteIOContext *s);
00410
00412 #ifdef __GNUC__
00413 int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
00414 #else
00415 int url_fprintf(ByteIOContext *s, const char *fmt, ...);
00416 #endif
00417
00420 char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
00421
00422 void put_flush_packet(ByteIOContext *s);
00423
00424
00429 int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
00430
00437 int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
00438
00441 int get_byte(ByteIOContext *s);
00442 unsigned int get_le24(ByteIOContext *s);
00443 unsigned int get_le32(ByteIOContext *s);
00444 uint64_t get_le64(ByteIOContext *s);
00445 unsigned int get_le16(ByteIOContext *s);
00446
00447 char *get_strz(ByteIOContext *s, char *buf, int maxlen);
00448 unsigned int get_be16(ByteIOContext *s);
00449 unsigned int get_be24(ByteIOContext *s);
00450 unsigned int get_be32(ByteIOContext *s);
00451 uint64_t get_be64(ByteIOContext *s);
00452
00453 uint64_t ff_get_v(ByteIOContext *bc);
00454
00455 static inline int url_is_streamed(ByteIOContext *s)
00456 {
00457 return s->is_streamed;
00458 }
00459
00471 int url_fdopen(ByteIOContext **s, URLContext *h);
00472
00474 int url_setbufsize(ByteIOContext *s, int buf_size);
00475 #if FF_API_URL_RESETBUF
00476
00480 int url_resetbuf(ByteIOContext *s, int flags);
00481 #endif
00482
00496 int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size);
00497
00511 int url_fopen(ByteIOContext **s, const char *url, int flags);
00512
00513 int url_fclose(ByteIOContext *s);
00514 URLContext *url_fileno(ByteIOContext *s);
00515
00524 int url_fget_max_packet_size(ByteIOContext *s);
00525
00526 int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags);
00527
00529 int url_close_buf(ByteIOContext *s);
00530
00537 int url_open_dyn_buf(ByteIOContext **s);
00538
00548 int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size);
00549
00560 int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
00561
00562 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
00563 unsigned int len);
00564 unsigned long get_checksum(ByteIOContext *s);
00565 void init_checksum(ByteIOContext *s,
00566 unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
00567 unsigned long checksum);
00568
00569
00570 int udp_set_remote_url(URLContext *h, const char *uri);
00571 int udp_get_local_port(URLContext *h);
00572 #if FF_API_UDP_GET_FILE
00573 int udp_get_file_handle(URLContext *h);
00574 #endif
00575
00576 #endif