| @@ -22,10 +22,7 @@ · 21 unmodified lines |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @file |
| 25 | | − * unbuffered I/O operations |
| 26 | | − * |
| 27 | | − * @warning This file has to be considered an internal but installed |
| 28 | | − * header, so it should not be directly included in your projects. |
| 25 | + * Buffered I/O operations |
| 29 | 26 | */ |
| 30 | 27 | |
| 31 | 28 | #include <stdint.h> |
| @@ -35,6 +32,63 @@ · 3 unmodified lines |
| 35 | 32 | |
| 36 | 33 | #include "libavformat/version.h" |
| 37 | 34 | |
| 35 | + |
| 36 | +#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */ |
| 37 | + |
| 38 | +/** |
| 39 | + * Bytestream IO Context. |
| 40 | + * New fields can be added to the end with minor version bumps. |
| 41 | + * Removal, reordering and changes to existing fields require a major |
| 42 | + * version bump. |
| 43 | + * sizeof(AVIOContext) must not be used outside libav*. |
| 44 | + * |
| 45 | + * @note None of the function pointers in AVIOContext should be called |
| 46 | + * directly, they should only be set by the client application |
| 47 | + * when implementing custom I/O. Normally these are set to the |
| 48 | + * function pointers specified in avio_alloc_context() |
| 49 | + */ |
| 50 | +typedef struct { |
| 51 | + unsigned char *buffer; /**< Start of the buffer. */ |
| 52 | + int buffer_size; /**< Maximum buffer size */ |
| 53 | + unsigned char *buf_ptr; /**< Current position in the buffer */ |
| 54 | + unsigned char *buf_end; /**< End of the data, may be less than |
| 55 | + buffer+buffer_size if the read function returned |
| 56 | + less data than requested, e.g. for streams where |
| 57 | + no more data has been received yet. */ |
| 58 | + void *opaque; /**< A private pointer, passed to the read/write/seek/... |
| 59 | + functions. */ |
| 60 | + int (*read_packet)(void *opaque, uint8_t *buf, int buf_size); |
| 61 | + int (*write_packet)(void *opaque, uint8_t *buf, int buf_size); |
| 62 | + int64_t (*seek)(void *opaque, int64_t offset, int whence); |
| 63 | + int64_t pos; /**< position in the file of the current buffer */ |
| 64 | + int must_flush; /**< true if the next seek should flush */ |
| 65 | + int eof_reached; /**< true if eof reached */ |
| 66 | + int write_flag; /**< true if open for writing */ |
| 67 | +#if FF_API_OLD_AVIO |
| 68 | + attribute_deprecated int is_streamed; |
| 69 | +#endif |
| 70 | + int max_packet_size; |
| 71 | + unsigned long checksum; |
| 72 | + unsigned char *checksum_ptr; |
| 73 | + unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size); |
| 74 | + int error; /**< contains the error code or 0 if no error happened */ |
| 75 | + /** |
| 76 | + * Pause or resume playback for network streaming protocols - e.g. MMS. |
| 77 | + */ |
| 78 | + int (*read_pause)(void *opaque, int pause); |
| 79 | + /** |
| 80 | + * Seek to a given timestamp in stream with the specified stream_index. |
| 81 | + * Needed for some network streaming protocols which don't support seeking |
| 82 | + * to byte position. |
| 83 | + */ |
| 84 | + int64_t (*read_seek)(void *opaque, int stream_index, |
| 85 | + int64_t timestamp, int flags); |
| 86 | + /** |
| 87 | + * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable. |
| 88 | + */ |
| 89 | + int seekable; |
| 90 | +} AVIOContext; |
| 91 | + |
| 38 | 92 | /* unbuffered I/O */ |
| 39 | 93 | |
| 40 | 94 | #if FF_API_OLD_AVIO |
| @@ -59,12 +113,38 @@ typedef struct URLContext { · 18 unmodified lines |
| 59 | 113 | int is_connected; |
| 60 | 114 | } URLContext; |
| 61 | 115 | |
| 116 | +#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */ |
| 117 | + |
| 118 | +/** |
| 119 | + * @deprecated This struct is to be made private. Use the higher-level |
| 120 | + * AVIOContext-based API instead. |
| 121 | + */ |
| 122 | +typedef struct URLProtocol { |
| 123 | + const char *name; |
| 124 | + int (*url_open)(URLContext *h, const char *url, int flags); |
| 125 | + int (*url_read)(URLContext *h, unsigned char *buf, int size); |
| 126 | + int (*url_write)(URLContext *h, const unsigned char *buf, int size); |
| 127 | + int64_t (*url_seek)(URLContext *h, int64_t pos, int whence); |
| 128 | + int (*url_close)(URLContext *h); |
| 129 | + struct URLProtocol *next; |
| 130 | + int (*url_read_pause)(URLContext *h, int pause); |
| 131 | + int64_t (*url_read_seek)(URLContext *h, int stream_index, |
| 132 | + int64_t timestamp, int flags); |
| 133 | + int (*url_get_file_handle)(URLContext *h); |
| 134 | + int priv_data_size; |
| 135 | + const AVClass *priv_data_class; |
| 136 | + int flags; |
| 137 | +} URLProtocol; |
| 138 | + |
| 62 | 139 | typedef struct URLPollEntry { |
| 63 | 140 | URLContext *handle; |
| 64 | 141 | int events; |
| 65 | 142 | int revents; |
| 66 | 143 | } URLPollEntry; |
| 67 | 144 | |
| 145 | +/* not implemented */ |
| 146 | +attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout); |
| 147 | + |
| 68 | 148 | /** |
| 69 | 149 | * @defgroup open_modes URL open modes |
| 70 | 150 | * The flags argument to url_open and cosins must be one of the following |
| @@ -93,6 +173,7 @@ typedef struct URLPollEntry { · 22 unmodified lines |
| 93 | 173 | #define URL_FLAG_NONBLOCK 4 |
| 94 | 174 | |
| 95 | 175 | typedef int URLInterruptCB(void); |
| 176 | +extern URLInterruptCB *url_interrupt_cb; |
| 96 | 177 | |
| 97 | 178 | /** |
| 98 | 179 | * @defgroup old_url_funcs Old url_* functions |
| @@ -117,130 +198,24 @@ attribute_deprecated int av_url_read_pause(URLContext *h, int pause); · 18 unmodified lines |
| 117 | 198 | attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index, |
| 118 | 199 | int64_t timestamp, int flags); |
| 119 | 200 | attribute_deprecated void url_set_interrupt_cb(int (*interrupt_cb)(void)); |
| 120 | | −#endif |
| 121 | 201 | |
| 122 | 202 | /** |
| 123 | | − * Return a non-zero value if the resource indicated by url |
| 124 | | − * exists, 0 otherwise. |
| 125 | | − */ |
| 126 | | −int url_exist(const char *url); |
| 127 | | − |
| 128 | | −/** |
| 129 | | − * The callback is called in blocking functions to test regulary if |
| 130 | | − * asynchronous interruption is needed. AVERROR_EXIT is returned |
| 131 | | − * in this case by the interrupted function. 'NULL' means no interrupt |
| 132 | | − * callback is given. |
| 133 | | − */ |
| 134 | | −void avio_set_interrupt_cb(int (*interrupt_cb)(void)); |
| 135 | | − |
| 136 | | −#if FF_API_OLD_AVIO |
| 137 | | −/* not implemented */ |
| 138 | | −attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout); |
| 139 | | − |
| 140 | | − |
| 141 | | −#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */ |
| 142 | | − |
| 143 | | −/** |
| 144 | | − * @deprecated This struct is to be made private. Use the higher-level |
| 145 | | − * AVIOContext-based API instead. |
| 146 | | − */ |
| 147 | | −typedef struct URLProtocol { |
| 148 | | − const char *name; |
| 149 | | − int (*url_open)(URLContext *h, const char *url, int flags); |
| 150 | | − int (*url_read)(URLContext *h, unsigned char *buf, int size); |
| 151 | | − int (*url_write)(URLContext *h, const unsigned char *buf, int size); |
| 152 | | − int64_t (*url_seek)(URLContext *h, int64_t pos, int whence); |
| 153 | | − int (*url_close)(URLContext *h); |
| 154 | | − struct URLProtocol *next; |
| 155 | | − int (*url_read_pause)(URLContext *h, int pause); |
| 156 | | − int64_t (*url_read_seek)(URLContext *h, int stream_index, |
| 157 | | − int64_t timestamp, int flags); |
| 158 | | − int (*url_get_file_handle)(URLContext *h); |
| 159 | | − int priv_data_size; |
| 160 | | − const AVClass *priv_data_class; |
| 161 | | − int flags; |
| 162 | | −} URLProtocol; |
| 163 | | −#endif |
| 164 | | − |
| 165 | | −#if FF_API_REGISTER_PROTOCOL |
| 166 | | −extern URLProtocol *first_protocol; |
| 167 | | −#endif |
| 168 | | − |
| 169 | | −#if FF_API_OLD_AVIO |
| 170 | | −extern URLInterruptCB *url_interrupt_cb; |
| 171 | | −#endif |
| 172 | | − |
| 173 | | −/** |
| 174 | | − * If protocol is NULL, returns the first registered protocol, |
| 175 | | − * if protocol is non-NULL, returns the next registered protocol after protocol, |
| 176 | | − * or NULL if protocol is the last one. |
| 203 | + * returns the next registered protocol after the given protocol (the first if |
| 204 | + * NULL is given), or NULL if protocol is the last one. |
| 177 | 205 | */ |
| 178 | 206 | URLProtocol *av_protocol_next(URLProtocol *p); |
| 179 | 207 | |
| 180 | | −#if FF_API_REGISTER_PROTOCOL |
| 181 | | −/** |
| 182 | | − * @deprecated Use av_register_protocol() instead. |
| 183 | | − */ |
| 184 | | −attribute_deprecated int register_protocol(URLProtocol *protocol); |
| 185 | | − |
| 186 | | −/** |
| 187 | | − * @deprecated Use av_register_protocol2() instead. |
| 188 | | − */ |
| 189 | | −attribute_deprecated int av_register_protocol(URLProtocol *protocol); |
| 190 | | −#endif |
| 191 | | − |
| 192 | | −#if FF_API_OLD_AVIO |
| 193 | 208 | /** |
| 194 | 209 | * Register the URLProtocol protocol. |
| 195 | 210 | * |
| 196 | 211 | * @param size the size of the URLProtocol struct referenced |
| 197 | 212 | */ |
| 198 | 213 | attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size); |
| 199 | | −#endif |
| 200 | | − |
| 201 | | −#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */ |
| 202 | | − |
| 203 | 214 | /** |
| 204 | 215 | * @} |
| 205 | 216 | */ |
| 206 | 217 | |
| 207 | | −/** |
| 208 | | − * Bytestream IO Context. |
| 209 | | − * New fields can be added to the end with minor version bumps. |
| 210 | | − * Removal, reordering and changes to existing fields require a major |
| 211 | | − * version bump. |
| 212 | | − * sizeof(AVIOContext) must not be used outside libav*. |
| 213 | | − */ |
| 214 | | −typedef struct { |
| 215 | | − unsigned char *buffer; |
| 216 | | − int buffer_size; |
| 217 | | − unsigned char *buf_ptr, *buf_end; |
| 218 | | − void *opaque; |
| 219 | | − int (*read_packet)(void *opaque, uint8_t *buf, int buf_size); |
| 220 | | − int (*write_packet)(void *opaque, uint8_t *buf, int buf_size); |
| 221 | | − int64_t (*seek)(void *opaque, int64_t offset, int whence); |
| 222 | | − int64_t pos; /**< position in the file of the current buffer */ |
| 223 | | − int must_flush; /**< true if the next seek should flush */ |
| 224 | | − int eof_reached; /**< true if eof reached */ |
| 225 | | − int write_flag; /**< true if open for writing */ |
| 226 | | −#if FF_API_OLD_AVIO |
| 227 | | − attribute_deprecated int is_streamed; |
| 228 | | −#endif |
| 229 | | − int max_packet_size; |
| 230 | | − unsigned long checksum; |
| 231 | | − unsigned char *checksum_ptr; |
| 232 | | − unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size); |
| 233 | | − int error; ///< contains the error code or 0 if no error happened |
| 234 | | − int (*read_pause)(void *opaque, int pause); |
| 235 | | − int64_t (*read_seek)(void *opaque, int stream_index, |
| 236 | | − int64_t timestamp, int flags); |
| 237 | | − /** |
| 238 | | − * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable. |
| 239 | | − */ |
| 240 | | − int seekable; |
| 241 | | −} AVIOContext; |
| 242 | 218 | |
| 243 | | −#if FF_API_OLD_AVIO |
| 244 | 219 | typedef attribute_deprecated AVIOContext ByteIOContext; |
| 245 | 220 | |
| 246 | 221 | attribute_deprecated int init_put_byte(AVIOContext *s, |
| @@ -334,6 +309,62 @@ attribute_deprecated void init_checksum(AVIOContext *s, · 87 unmodified lines |
| 334 | 309 | unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), |
| 335 | 310 | unsigned long checksum); |
| 336 | 311 | attribute_deprecated unsigned long get_checksum(AVIOContext *s); |
| 312 | +attribute_deprecated void put_strz(AVIOContext *s, const char *buf); |
| 313 | +/** @note unlike fgets, the EOL character is not returned and a whole |
| 314 | + line is parsed. return NULL if first char read was EOF */ |
| 315 | +attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size); |
| 316 | +/** |
| 317 | + * @deprecated use avio_get_str instead |
| 318 | + */ |
| 319 | +attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen); |
| 320 | +/** |
| 321 | + * @deprecated Use AVIOContext.seekable field directly. |
| 322 | + */ |
| 323 | +attribute_deprecated static inline int url_is_streamed(AVIOContext *s) |
| 324 | +{ |
| 325 | + return !s->seekable; |
| 326 | +} |
| 327 | +attribute_deprecated URLContext *url_fileno(AVIOContext *s); |
| 328 | + |
| 329 | +/** |
| 330 | + * @deprecated use AVIOContext.max_packet_size directly. |
| 331 | + */ |
| 332 | +attribute_deprecated int url_fget_max_packet_size(AVIOContext *s); |
| 333 | + |
| 334 | +attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags); |
| 335 | + |
| 336 | +/** return the written or read size */ |
| 337 | +attribute_deprecated int url_close_buf(AVIOContext *s); |
| 338 | +#endif // FF_API_OLD_AVIO |
| 339 | + |
| 340 | +/** |
| 341 | + * Return a non-zero value if the resource indicated by url |
| 342 | + * exists, 0 otherwise. |
| 343 | + */ |
| 344 | +int url_exist(const char *url); |
| 345 | + |
| 346 | +/** |
| 347 | + * The callback is called in blocking functions to test regulary if |
| 348 | + * asynchronous interruption is needed. AVERROR_EXIT is returned |
| 349 | + * in this case by the interrupted function. 'NULL' means no interrupt |
| 350 | + * callback is given. |
| 351 | + */ |
| 352 | +void avio_set_interrupt_cb(int (*interrupt_cb)(void)); |
| 353 | + |
| 354 | +#if FF_API_REGISTER_PROTOCOL |
| 355 | +extern URLProtocol *first_protocol; |
| 356 | +#endif |
| 357 | + |
| 358 | +#if FF_API_REGISTER_PROTOCOL |
| 359 | +/** |
| 360 | + * @deprecated Use av_register_protocol() instead. |
| 361 | + */ |
| 362 | +attribute_deprecated int register_protocol(URLProtocol *protocol); |
| 363 | + |
| 364 | +/** |
| 365 | + * @deprecated Use av_register_protocol2() instead. |
| 366 | + */ |
| 367 | +attribute_deprecated int av_register_protocol(URLProtocol *protocol); |
| 337 | 368 | #endif |
| 338 | 369 | |
| 339 | 370 | /** |
| @@ -372,10 +403,6 @@ void avio_wb24(AVIOContext *s, unsigned int val); · 32 unmodified lines |
| 372 | 403 | void avio_wl16(AVIOContext *s, unsigned int val); |
| 373 | 404 | void avio_wb16(AVIOContext *s, unsigned int val); |
| 374 | 405 | |
| 375 | | −#if FF_API_OLD_AVIO |
| 376 | | −attribute_deprecated void put_strz(AVIOContext *s, const char *buf); |
| 377 | | −#endif |
| 378 | | − |
| 379 | 406 | /** |
| 380 | 407 | * Write a NULL-terminated string. |
| 381 | 408 | * @return number of bytes written. |
| @@ -443,12 +470,6 @@ int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ · 61 unmodified lines |
| 443 | 470 | int avio_printf(AVIOContext *s, const char *fmt, ...); |
| 444 | 471 | #endif |
| 445 | 472 | |
| 446 | | −#if FF_API_OLD_AVIO |
| 447 | | −/** @note unlike fgets, the EOL character is not returned and a whole |
| 448 | | − line is parsed. return NULL if first char read was EOF */ |
| 449 | | −attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size); |
| 450 | | −#endif |
| 451 | | − |
| 452 | 473 | void avio_flush(AVIOContext *s); |
| 453 | 474 | |
| 454 | 475 | |
| @@ -458,13 +479,25 @@ void avio_flush(AVIOContext *s); · 3 unmodified lines |
| 458 | 479 | */ |
| 459 | 480 | int avio_read(AVIOContext *s, unsigned char *buf, int size); |
| 460 | 481 | |
| 461 | | −/** @note return 0 if EOF, so you cannot use it if EOF handling is |
| 462 | | − necessary */ |
| 482 | +/** |
| 483 | + * @defgroup avio_read Functions for reading from AVIOContext. |
| 484 | + * @{ |
| 485 | + * |
| 486 | + * @note return 0 if EOF, so you cannot use it if EOF handling is |
| 487 | + * necessary |
| 488 | + */ |
| 463 | 489 | int avio_r8 (AVIOContext *s); |
| 464 | 490 | unsigned int avio_rl16(AVIOContext *s); |
| 465 | 491 | unsigned int avio_rl24(AVIOContext *s); |
| 466 | 492 | unsigned int avio_rl32(AVIOContext *s); |
| 467 | 493 | uint64_t avio_rl64(AVIOContext *s); |
| 494 | +unsigned int avio_rb16(AVIOContext *s); |
| 495 | +unsigned int avio_rb24(AVIOContext *s); |
| 496 | +unsigned int avio_rb32(AVIOContext *s); |
| 497 | +uint64_t avio_rb64(AVIOContext *s); |
| 498 | +/** |
| 499 | + * @} |
| 500 | + */ |
| 468 | 501 | |
| 469 | 502 | /** |
| 470 | 503 | * Read a string from pb into buf. The reading will terminate when either |
| @@ -489,26 +522,6 @@ int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen); · 18 unmodified lines |
| 489 | 522 | int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen); |
| 490 | 523 | int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen); |
| 491 | 524 | |
| 492 | | −#if FF_API_OLD_AVIO |
| 493 | | −/** |
| 494 | | − * @deprecated use avio_get_str instead |
| 495 | | − */ |
| 496 | | −attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen); |
| 497 | | −#endif |
| 498 | | −unsigned int avio_rb16(AVIOContext *s); |
| 499 | | −unsigned int avio_rb24(AVIOContext *s); |
| 500 | | −unsigned int avio_rb32(AVIOContext *s); |
| 501 | | −uint64_t avio_rb64(AVIOContext *s); |
| 502 | | − |
| 503 | | −#if FF_API_OLD_AVIO |
| 504 | | −/** |
| 505 | | − * @deprecated Use AVIOContext.seekable field directly. |
| 506 | | − */ |
| 507 | | −attribute_deprecated static inline int url_is_streamed(AVIOContext *s) |
| 508 | | −{ |
| 509 | | − return !s->seekable; |
| 510 | | −} |
| 511 | | −#endif |
| 512 | 525 | |
| 513 | 526 | #if FF_API_URL_RESETBUF |
| 514 | 527 | /** Reset the buffer for reading or writing. |
| @@ -560,21 +573,13 @@ int url_resetbuf(AVIOContext *s, int flags); · 45 unmodified lines |
| 560 | 573 | */ |
| 561 | 574 | int avio_open(AVIOContext **s, const char *url, int flags); |
| 562 | 575 | |
| 563 | | −int avio_close(AVIOContext *s); |
| 564 | | − |
| 565 | | −#if FF_API_OLD_AVIO |
| 566 | | −attribute_deprecated URLContext *url_fileno(AVIOContext *s); |
| 567 | | − |
| 568 | 576 | /** |
| 569 | | − * @deprecated use AVIOContext.max_packet_size directly. |
| 577 | + * Close the resource accessed by the AVIOContext s and free it. |
| 578 | + * This function can only be used if s was opened by avio_open(). |
| 579 | + * |
| 580 | + * @return 0 on success, an AVERROR < 0 on error. |
| 570 | 581 | */ |
| 571 | | −attribute_deprecated int url_fget_max_packet_size(AVIOContext *s); |
| 572 | | − |
| 573 | | −attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags); |
| 574 | | − |
| 575 | | −/** return the written or read size */ |
| 576 | | −attribute_deprecated int url_close_buf(AVIOContext *s); |
| 577 | | −#endif |
| 582 | +int avio_close(AVIOContext *s); |
| 578 | 583 | |
| 579 | 584 | /** |
| 580 | 585 | * Open a write only memory stream. |