Libav 0.7.1
|
00001 /* 00002 * copyright (c) 2001 Fabrice Bellard 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 #ifndef AVFORMAT_AVIO_H 00021 #define AVFORMAT_AVIO_H 00022 00028 #include <stdint.h> 00029 00030 #include "libavutil/common.h" 00031 #include "libavutil/log.h" 00032 00033 #include "libavformat/version.h" 00034 00035 00036 #define AVIO_SEEKABLE_NORMAL 0x0001 00050 typedef struct { 00051 unsigned char *buffer; 00052 int buffer_size; 00053 unsigned char *buf_ptr; 00054 unsigned char *buf_end; 00058 void *opaque; 00060 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size); 00061 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size); 00062 int64_t (*seek)(void *opaque, int64_t offset, int whence); 00063 int64_t pos; 00064 int must_flush; 00065 int eof_reached; 00066 int write_flag; 00067 #if FF_API_OLD_AVIO 00068 attribute_deprecated int is_streamed; 00069 #endif 00070 int max_packet_size; 00071 unsigned long checksum; 00072 unsigned char *checksum_ptr; 00073 unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size); 00074 int error; 00078 int (*read_pause)(void *opaque, int pause); 00084 int64_t (*read_seek)(void *opaque, int stream_index, 00085 int64_t timestamp, int flags); 00089 int seekable; 00090 } AVIOContext; 00091 00092 /* unbuffered I/O */ 00093 00094 #if FF_API_OLD_AVIO 00095 00103 typedef struct URLContext { 00104 const AVClass *av_class; 00105 struct URLProtocol *prot; 00106 int flags; 00107 int is_streamed; 00108 int max_packet_size; 00109 void *priv_data; 00110 char *filename; 00111 int is_connected; 00112 } URLContext; 00113 00114 #define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */ 00115 00120 typedef struct URLProtocol { 00121 const char *name; 00122 int (*url_open)(URLContext *h, const char *url, int flags); 00123 int (*url_read)(URLContext *h, unsigned char *buf, int size); 00124 int (*url_write)(URLContext *h, const unsigned char *buf, int size); 00125 int64_t (*url_seek)(URLContext *h, int64_t pos, int whence); 00126 int (*url_close)(URLContext *h); 00127 struct URLProtocol *next; 00128 int (*url_read_pause)(URLContext *h, int pause); 00129 int64_t (*url_read_seek)(URLContext *h, int stream_index, 00130 int64_t timestamp, int flags); 00131 int (*url_get_file_handle)(URLContext *h); 00132 int priv_data_size; 00133 const AVClass *priv_data_class; 00134 int flags; 00135 int (*url_check)(URLContext *h, int mask); 00136 } URLProtocol; 00137 00138 typedef struct URLPollEntry { 00139 URLContext *handle; 00140 int events; 00141 int revents; 00142 } URLPollEntry; 00143 00144 /* not implemented */ 00145 attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout); 00146 00153 #define URL_RDONLY 1 00154 #define URL_WRONLY 2 00155 #define URL_RDWR (URL_RDONLY|URL_WRONLY) 00172 #define URL_FLAG_NONBLOCK 4 00173 00174 typedef int URLInterruptCB(void); 00175 extern URLInterruptCB *url_interrupt_cb; 00176 00182 attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol *up, 00183 const char *url, int flags); 00184 attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags); 00185 attribute_deprecated int url_connect(URLContext *h); 00186 attribute_deprecated int url_open(URLContext **h, const char *url, int flags); 00187 attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size); 00188 attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size); 00189 attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size); 00190 attribute_deprecated int64_t url_seek(URLContext *h, int64_t pos, int whence); 00191 attribute_deprecated int url_close(URLContext *h); 00192 attribute_deprecated int64_t url_filesize(URLContext *h); 00193 attribute_deprecated int url_get_file_handle(URLContext *h); 00194 attribute_deprecated int url_get_max_packet_size(URLContext *h); 00195 attribute_deprecated void url_get_filename(URLContext *h, char *buf, int buf_size); 00196 attribute_deprecated int av_url_read_pause(URLContext *h, int pause); 00197 attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index, 00198 int64_t timestamp, int flags); 00199 attribute_deprecated void url_set_interrupt_cb(int (*interrupt_cb)(void)); 00205 attribute_deprecated URLProtocol *av_protocol_next(URLProtocol *p); 00211 attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size); 00217 typedef attribute_deprecated AVIOContext ByteIOContext; 00218 00219 attribute_deprecated int init_put_byte(AVIOContext *s, 00220 unsigned char *buffer, 00221 int buffer_size, 00222 int write_flag, 00223 void *opaque, 00224 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), 00225 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), 00226 int64_t (*seek)(void *opaque, int64_t offset, int whence)); 00227 attribute_deprecated AVIOContext *av_alloc_put_byte( 00228 unsigned char *buffer, 00229 int buffer_size, 00230 int write_flag, 00231 void *opaque, 00232 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), 00233 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), 00234 int64_t (*seek)(void *opaque, int64_t offset, int whence)); 00235 00241 attribute_deprecated int get_buffer(AVIOContext *s, unsigned char *buf, int size); 00242 attribute_deprecated int get_partial_buffer(AVIOContext *s, unsigned char *buf, int size); 00243 attribute_deprecated int get_byte(AVIOContext *s); 00244 attribute_deprecated unsigned int get_le16(AVIOContext *s); 00245 attribute_deprecated unsigned int get_le24(AVIOContext *s); 00246 attribute_deprecated unsigned int get_le32(AVIOContext *s); 00247 attribute_deprecated uint64_t get_le64(AVIOContext *s); 00248 attribute_deprecated unsigned int get_be16(AVIOContext *s); 00249 attribute_deprecated unsigned int get_be24(AVIOContext *s); 00250 attribute_deprecated unsigned int get_be32(AVIOContext *s); 00251 attribute_deprecated uint64_t get_be64(AVIOContext *s); 00252 00253 attribute_deprecated void put_byte(AVIOContext *s, int b); 00254 attribute_deprecated void put_nbyte(AVIOContext *s, int b, int count); 00255 attribute_deprecated void put_buffer(AVIOContext *s, const unsigned char *buf, int size); 00256 attribute_deprecated void put_le64(AVIOContext *s, uint64_t val); 00257 attribute_deprecated void put_be64(AVIOContext *s, uint64_t val); 00258 attribute_deprecated void put_le32(AVIOContext *s, unsigned int val); 00259 attribute_deprecated void put_be32(AVIOContext *s, unsigned int val); 00260 attribute_deprecated void put_le24(AVIOContext *s, unsigned int val); 00261 attribute_deprecated void put_be24(AVIOContext *s, unsigned int val); 00262 attribute_deprecated void put_le16(AVIOContext *s, unsigned int val); 00263 attribute_deprecated void put_be16(AVIOContext *s, unsigned int val); 00264 attribute_deprecated void put_tag(AVIOContext *s, const char *tag); 00269 attribute_deprecated int av_url_read_fpause(AVIOContext *h, int pause); 00270 attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h, int stream_index, 00271 int64_t timestamp, int flags); 00272 00278 attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags); 00279 attribute_deprecated int url_fclose(AVIOContext *s); 00280 attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence); 00281 attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset); 00282 attribute_deprecated int64_t url_ftell(AVIOContext *s); 00283 attribute_deprecated int64_t url_fsize(AVIOContext *s); 00284 #define URL_EOF (-1) 00285 attribute_deprecated int url_fgetc(AVIOContext *s); 00286 attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size); 00287 #ifdef __GNUC__ 00288 attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); 00289 #else 00290 attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...); 00291 #endif 00292 attribute_deprecated void put_flush_packet(AVIOContext *s); 00293 attribute_deprecated int url_open_dyn_buf(AVIOContext **s); 00294 attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size); 00295 attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer); 00296 attribute_deprecated int url_fdopen(AVIOContext **s, URLContext *h); 00304 attribute_deprecated int url_feof(AVIOContext *s); 00305 attribute_deprecated int url_ferror(AVIOContext *s); 00306 00307 attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri); 00308 attribute_deprecated int udp_get_local_port(URLContext *h); 00309 00310 attribute_deprecated void init_checksum(AVIOContext *s, 00311 unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), 00312 unsigned long checksum); 00313 attribute_deprecated unsigned long get_checksum(AVIOContext *s); 00314 attribute_deprecated void put_strz(AVIOContext *s, const char *buf); 00317 attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size); 00321 attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen); 00325 attribute_deprecated static inline int url_is_streamed(AVIOContext *s) 00326 { 00327 return !s->seekable; 00328 } 00329 attribute_deprecated URLContext *url_fileno(AVIOContext *s); 00330 00334 attribute_deprecated int url_fget_max_packet_size(AVIOContext *s); 00335 00336 attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags); 00337 00339 attribute_deprecated int url_close_buf(AVIOContext *s); 00340 00346 attribute_deprecated int url_exist(const char *url); 00347 #endif // FF_API_OLD_AVIO 00348 00361 int avio_check(const char *url, int flags); 00362 00369 void avio_set_interrupt_cb(int (*interrupt_cb)(void)); 00370 00388 AVIOContext *avio_alloc_context( 00389 unsigned char *buffer, 00390 int buffer_size, 00391 int write_flag, 00392 void *opaque, 00393 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), 00394 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), 00395 int64_t (*seek)(void *opaque, int64_t offset, int whence)); 00396 00397 void avio_w8(AVIOContext *s, int b); 00398 void avio_write(AVIOContext *s, const unsigned char *buf, int size); 00399 void avio_wl64(AVIOContext *s, uint64_t val); 00400 void avio_wb64(AVIOContext *s, uint64_t val); 00401 void avio_wl32(AVIOContext *s, unsigned int val); 00402 void avio_wb32(AVIOContext *s, unsigned int val); 00403 void avio_wl24(AVIOContext *s, unsigned int val); 00404 void avio_wb24(AVIOContext *s, unsigned int val); 00405 void avio_wl16(AVIOContext *s, unsigned int val); 00406 void avio_wb16(AVIOContext *s, unsigned int val); 00407 00412 int avio_put_str(AVIOContext *s, const char *str); 00413 00418 int avio_put_str16le(AVIOContext *s, const char *str); 00419 00425 #define AVSEEK_SIZE 0x10000 00426 00433 #define AVSEEK_FORCE 0x20000 00434 00439 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence); 00440 00445 static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset) 00446 { 00447 return avio_seek(s, offset, SEEK_CUR); 00448 } 00449 00454 static av_always_inline int64_t avio_tell(AVIOContext *s) 00455 { 00456 return avio_seek(s, 0, SEEK_CUR); 00457 } 00458 00463 int64_t avio_size(AVIOContext *s); 00464 00466 #ifdef __GNUC__ 00467 int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); 00468 #else 00469 int avio_printf(AVIOContext *s, const char *fmt, ...); 00470 #endif 00471 00472 void avio_flush(AVIOContext *s); 00473 00474 00479 int avio_read(AVIOContext *s, unsigned char *buf, int size); 00480 00488 int avio_r8 (AVIOContext *s); 00489 unsigned int avio_rl16(AVIOContext *s); 00490 unsigned int avio_rl24(AVIOContext *s); 00491 unsigned int avio_rl32(AVIOContext *s); 00492 uint64_t avio_rl64(AVIOContext *s); 00493 unsigned int avio_rb16(AVIOContext *s); 00494 unsigned int avio_rb24(AVIOContext *s); 00495 unsigned int avio_rb32(AVIOContext *s); 00496 uint64_t avio_rb64(AVIOContext *s); 00513 int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen); 00514 00521 int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen); 00522 int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen); 00523 00524 00531 #define AVIO_FLAG_READ 1 00532 #define AVIO_FLAG_WRITE 2 00533 #define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE) 00550 #define AVIO_FLAG_NONBLOCK 8 00551 00565 int avio_open(AVIOContext **s, const char *url, int flags); 00566 00573 int avio_close(AVIOContext *s); 00574 00581 int avio_open_dyn_buf(AVIOContext **s); 00582 00592 int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer); 00593 00605 const char *avio_enum_protocols(void **opaque, int output); 00606 00612 int avio_pause(AVIOContext *h, int pause); 00613 00631 int64_t avio_seek_time(AVIOContext *h, int stream_index, 00632 int64_t timestamp, int flags); 00633 00634 #endif /* AVFORMAT_AVIO_H */