avio.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * copyright (c) 2001 Fabrice Bellard
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVFORMAT_AVIO_H
  21. #define AVFORMAT_AVIO_H
  22. /**
  23. * @file
  24. * unbuffered I/O operations
  25. *
  26. * @warning This file has to be considered an internal but installed
  27. * header, so it should not be directly included in your projects.
  28. */
  29. #include <stdint.h>
  30. #include "libavutil/common.h"
  31. #include "libavutil/log.h"
  32. #include "libavformat/version.h"
  33. /* unbuffered I/O */
  34. /**
  35. * URL Context.
  36. * New fields can be added to the end with minor version bumps.
  37. * Removal, reordering and changes to existing fields require a major
  38. * version bump.
  39. * sizeof(URLContext) must not be used outside libav*.
  40. */
  41. typedef struct URLContext {
  42. #if FF_API_URL_CLASS
  43. const AVClass *av_class; ///< information for av_log(). Set by url_open().
  44. #endif
  45. struct URLProtocol *prot;
  46. int flags;
  47. int is_streamed; /**< true if streamed (no seek possible), default = false */
  48. int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
  49. void *priv_data;
  50. char *filename; /**< specified URL */
  51. int is_connected;
  52. } URLContext;
  53. typedef struct URLPollEntry {
  54. URLContext *handle;
  55. int events;
  56. int revents;
  57. } URLPollEntry;
  58. /**
  59. * @defgroup open_modes URL open modes
  60. * The flags argument to url_open and cosins must be one of the following
  61. * constants, optionally ORed with other flags.
  62. * @{
  63. */
  64. #define URL_RDONLY 0 /**< read-only */
  65. #define URL_WRONLY 1 /**< write-only */
  66. #define URL_RDWR 2 /**< read-write */
  67. /**
  68. * @}
  69. */
  70. /**
  71. * Use non-blocking mode.
  72. * If this flag is set, operations on the context will return
  73. * AVERROR(EAGAIN) if they can not be performed immediately.
  74. * If this flag is not set, operations on the context will never return
  75. * AVERROR(EAGAIN).
  76. * Note that this flag does not affect the opening/connecting of the
  77. * context. Connecting a protocol will always block if necessary (e.g. on
  78. * network protocols) but never hang (e.g. on busy devices).
  79. * Warning: non-blocking protocols is work-in-progress; this flag may be
  80. * silently ignored.
  81. */
  82. #define URL_FLAG_NONBLOCK 4
  83. typedef int URLInterruptCB(void);
  84. /**
  85. * Create a URLContext for accessing to the resource indicated by
  86. * url, and open it using the URLProtocol up.
  87. *
  88. * @param puc pointer to the location where, in case of success, the
  89. * function puts the pointer to the created URLContext
  90. * @param flags flags which control how the resource indicated by url
  91. * is to be opened
  92. * @return 0 in case of success, a negative value corresponding to an
  93. * AVERROR code in case of failure
  94. */
  95. int url_open_protocol (URLContext **puc, struct URLProtocol *up,
  96. const char *url, int flags);
  97. /**
  98. * Create a URLContext for accessing to the resource indicated by
  99. * url, but do not initiate the connection yet.
  100. *
  101. * @param puc pointer to the location where, in case of success, the
  102. * function puts the pointer to the created URLContext
  103. * @param flags flags which control how the resource indicated by url
  104. * is to be opened
  105. * @return 0 in case of success, a negative value corresponding to an
  106. * AVERROR code in case of failure
  107. */
  108. int url_alloc(URLContext **h, const char *url, int flags);
  109. /**
  110. * Connect an URLContext that has been allocated by url_alloc
  111. */
  112. int url_connect(URLContext *h);
  113. /**
  114. * Create an URLContext for accessing to the resource indicated by
  115. * url, and open it.
  116. *
  117. * @param puc pointer to the location where, in case of success, the
  118. * function puts the pointer to the created URLContext
  119. * @param flags flags which control how the resource indicated by url
  120. * is to be opened
  121. * @return 0 in case of success, a negative value corresponding to an
  122. * AVERROR code in case of failure
  123. */
  124. int url_open(URLContext **h, const char *url, int flags);
  125. /**
  126. * Read up to size bytes from the resource accessed by h, and store
  127. * the read bytes in buf.
  128. *
  129. * @return The number of bytes actually read, or a negative value
  130. * corresponding to an AVERROR code in case of error. A value of zero
  131. * indicates that it is not possible to read more from the accessed
  132. * resource (except if the value of the size argument is also zero).
  133. */
  134. int url_read(URLContext *h, unsigned char *buf, int size);
  135. /**
  136. * Read as many bytes as possible (up to size), calling the
  137. * read function multiple times if necessary.
  138. * This makes special short-read handling in applications
  139. * unnecessary, if the return value is < size then it is
  140. * certain there was either an error or the end of file was reached.
  141. */
  142. int url_read_complete(URLContext *h, unsigned char *buf, int size);
  143. /**
  144. * Write size bytes from buf to the resource accessed by h.
  145. *
  146. * @return the number of bytes actually written, or a negative value
  147. * corresponding to an AVERROR code in case of failure
  148. */
  149. int url_write(URLContext *h, const unsigned char *buf, int size);
  150. /**
  151. * Passing this as the "whence" parameter to a seek function causes it to
  152. * return the filesize without seeking anywhere. Supporting this is optional.
  153. * If it is not supported then the seek function will return <0.
  154. */
  155. #define AVSEEK_SIZE 0x10000
  156. /**
  157. * Change the position that will be used by the next read/write
  158. * operation on the resource accessed by h.
  159. *
  160. * @param pos specifies the new position to set
  161. * @param whence specifies how pos should be interpreted, it must be
  162. * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
  163. * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
  164. * (return the filesize of the requested resource, pos is ignored).
  165. * @return a negative value corresponding to an AVERROR code in case
  166. * of failure, or the resulting file position, measured in bytes from
  167. * the beginning of the file. You can use this feature together with
  168. * SEEK_CUR to read the current file position.
  169. */
  170. int64_t url_seek(URLContext *h, int64_t pos, int whence);
  171. /**
  172. * Close the resource accessed by the URLContext h, and free the
  173. * memory used by it.
  174. *
  175. * @return a negative value if an error condition occurred, 0
  176. * otherwise
  177. */
  178. int url_close(URLContext *h);
  179. /**
  180. * Return a non-zero value if the resource indicated by url
  181. * exists, 0 otherwise.
  182. */
  183. int url_exist(const char *url);
  184. /**
  185. * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
  186. * if the operation is not supported by h, or another negative value
  187. * corresponding to an AVERROR error code in case of failure.
  188. */
  189. int64_t url_filesize(URLContext *h);
  190. /**
  191. * Return the file descriptor associated with this URL. For RTP, this
  192. * will return only the RTP file descriptor, not the RTCP file descriptor.
  193. *
  194. * @return the file descriptor associated with this URL, or <0 on error.
  195. */
  196. int url_get_file_handle(URLContext *h);
  197. /**
  198. * Return the maximum packet size associated to packetized file
  199. * handle. If the file is not packetized (stream like HTTP or file on
  200. * disk), then 0 is returned.
  201. *
  202. * @param h file handle
  203. * @return maximum packet size in bytes
  204. */
  205. int url_get_max_packet_size(URLContext *h);
  206. /**
  207. * Copy the filename of the resource accessed by h to buf.
  208. *
  209. * @param buf_size size in bytes of buf
  210. */
  211. void url_get_filename(URLContext *h, char *buf, int buf_size);
  212. /**
  213. * The callback is called in blocking functions to test regulary if
  214. * asynchronous interruption is needed. AVERROR_EXIT is returned
  215. * in this case by the interrupted function. 'NULL' means no interrupt
  216. * callback is given.
  217. */
  218. void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
  219. /* not implemented */
  220. int url_poll(URLPollEntry *poll_table, int n, int timeout);
  221. /**
  222. * Pause and resume playing - only meaningful if using a network streaming
  223. * protocol (e.g. MMS).
  224. * @param pause 1 for pause, 0 for resume
  225. */
  226. int av_url_read_pause(URLContext *h, int pause);
  227. /**
  228. * Seek to a given timestamp relative to some component stream.
  229. * Only meaningful if using a network streaming protocol (e.g. MMS.).
  230. * @param stream_index The stream index that the timestamp is relative to.
  231. * If stream_index is (-1) the timestamp should be in AV_TIME_BASE
  232. * units from the beginning of the presentation.
  233. * If a stream_index >= 0 is used and the protocol does not support
  234. * seeking based on component streams, the call will fail with ENOTSUP.
  235. * @param timestamp timestamp in AVStream.time_base units
  236. * or if there is no stream specified then in AV_TIME_BASE units.
  237. * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE
  238. * and AVSEEK_FLAG_ANY. The protocol may silently ignore
  239. * AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will
  240. * fail with ENOTSUP if used and not supported.
  241. * @return >= 0 on success
  242. * @see AVInputFormat::read_seek
  243. */
  244. int64_t av_url_read_seek(URLContext *h, int stream_index,
  245. int64_t timestamp, int flags);
  246. /**
  247. * Oring this flag as into the "whence" parameter to a seek function causes it to
  248. * seek by any means (like reopening and linear reading) or other normally unreasonble
  249. * means that can be extreemly slow.
  250. * This may be ignored by the seek code.
  251. */
  252. #define AVSEEK_FORCE 0x20000
  253. #define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
  254. typedef struct URLProtocol {
  255. const char *name;
  256. int (*url_open)(URLContext *h, const char *url, int flags);
  257. int (*url_read)(URLContext *h, unsigned char *buf, int size);
  258. int (*url_write)(URLContext *h, const unsigned char *buf, int size);
  259. int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
  260. int (*url_close)(URLContext *h);
  261. struct URLProtocol *next;
  262. int (*url_read_pause)(URLContext *h, int pause);
  263. int64_t (*url_read_seek)(URLContext *h, int stream_index,
  264. int64_t timestamp, int flags);
  265. int (*url_get_file_handle)(URLContext *h);
  266. int priv_data_size;
  267. const AVClass *priv_data_class;
  268. int flags;
  269. } URLProtocol;
  270. #if FF_API_REGISTER_PROTOCOL
  271. extern URLProtocol *first_protocol;
  272. #endif
  273. extern URLInterruptCB *url_interrupt_cb;
  274. /**
  275. * If protocol is NULL, returns the first registered protocol,
  276. * if protocol is non-NULL, returns the next registered protocol after protocol,
  277. * or NULL if protocol is the last one.
  278. */
  279. URLProtocol *av_protocol_next(URLProtocol *p);
  280. #if FF_API_REGISTER_PROTOCOL
  281. /**
  282. * @deprecated Use av_register_protocol() instead.
  283. */
  284. attribute_deprecated int register_protocol(URLProtocol *protocol);
  285. /**
  286. * @deprecated Use av_register_protocol2() instead.
  287. */
  288. attribute_deprecated int av_register_protocol(URLProtocol *protocol);
  289. #endif
  290. /**
  291. * Register the URLProtocol protocol.
  292. *
  293. * @param size the size of the URLProtocol struct referenced
  294. */
  295. int av_register_protocol2(URLProtocol *protocol, int size);
  296. /**
  297. * Bytestream IO Context.
  298. * New fields can be added to the end with minor version bumps.
  299. * Removal, reordering and changes to existing fields require a major
  300. * version bump.
  301. * sizeof(AVIOContext) must not be used outside libav*.
  302. */
  303. typedef struct {
  304. unsigned char *buffer;
  305. int buffer_size;
  306. unsigned char *buf_ptr, *buf_end;
  307. void *opaque;
  308. int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
  309. int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
  310. int64_t (*seek)(void *opaque, int64_t offset, int whence);
  311. int64_t pos; /**< position in the file of the current buffer */
  312. int must_flush; /**< true if the next seek should flush */
  313. int eof_reached; /**< true if eof reached */
  314. int write_flag; /**< true if open for writing */
  315. int is_streamed;
  316. int max_packet_size;
  317. unsigned long checksum;
  318. unsigned char *checksum_ptr;
  319. unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
  320. int error; ///< contains the error code or 0 if no error happened
  321. int (*read_pause)(void *opaque, int pause);
  322. int64_t (*read_seek)(void *opaque, int stream_index,
  323. int64_t timestamp, int flags);
  324. } AVIOContext;
  325. #if FF_API_OLD_AVIO
  326. typedef attribute_deprecated AVIOContext ByteIOContext;
  327. attribute_deprecated int init_put_byte(AVIOContext *s,
  328. unsigned char *buffer,
  329. int buffer_size,
  330. int write_flag,
  331. void *opaque,
  332. int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
  333. int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
  334. int64_t (*seek)(void *opaque, int64_t offset, int whence));
  335. attribute_deprecated AVIOContext *av_alloc_put_byte(
  336. unsigned char *buffer,
  337. int buffer_size,
  338. int write_flag,
  339. void *opaque,
  340. int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
  341. int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
  342. int64_t (*seek)(void *opaque, int64_t offset, int whence));
  343. /**
  344. * @defgroup old_avio_funcs Old put_/get_*() functions
  345. * @deprecated use the avio_ -prefixed functions instead.
  346. * @{
  347. */
  348. attribute_deprecated int get_buffer(AVIOContext *s, unsigned char *buf, int size);
  349. attribute_deprecated int get_partial_buffer(AVIOContext *s, unsigned char *buf, int size);
  350. attribute_deprecated int get_byte(AVIOContext *s);
  351. attribute_deprecated unsigned int get_le16(AVIOContext *s);
  352. attribute_deprecated unsigned int get_le24(AVIOContext *s);
  353. attribute_deprecated unsigned int get_le32(AVIOContext *s);
  354. attribute_deprecated uint64_t get_le64(AVIOContext *s);
  355. attribute_deprecated unsigned int get_be16(AVIOContext *s);
  356. attribute_deprecated unsigned int get_be24(AVIOContext *s);
  357. attribute_deprecated unsigned int get_be32(AVIOContext *s);
  358. attribute_deprecated uint64_t get_be64(AVIOContext *s);
  359. attribute_deprecated void put_byte(AVIOContext *s, int b);
  360. attribute_deprecated void put_nbyte(AVIOContext *s, int b, int count);
  361. attribute_deprecated void put_buffer(AVIOContext *s, const unsigned char *buf, int size);
  362. attribute_deprecated void put_le64(AVIOContext *s, uint64_t val);
  363. attribute_deprecated void put_be64(AVIOContext *s, uint64_t val);
  364. attribute_deprecated void put_le32(AVIOContext *s, unsigned int val);
  365. attribute_deprecated void put_be32(AVIOContext *s, unsigned int val);
  366. attribute_deprecated void put_le24(AVIOContext *s, unsigned int val);
  367. attribute_deprecated void put_be24(AVIOContext *s, unsigned int val);
  368. attribute_deprecated void put_le16(AVIOContext *s, unsigned int val);
  369. attribute_deprecated void put_be16(AVIOContext *s, unsigned int val);
  370. attribute_deprecated void put_tag(AVIOContext *s, const char *tag);
  371. /**
  372. * @}
  373. */
  374. attribute_deprecated int av_url_read_fpause(AVIOContext *h, int pause);
  375. attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h, int stream_index,
  376. int64_t timestamp, int flags);
  377. /**
  378. * @defgroup old_url_f_funcs Old url_f* functions
  379. * @deprecated use the avio_ -prefixed functions instead.
  380. * @{
  381. */
  382. attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
  383. attribute_deprecated int url_fclose(AVIOContext *s);
  384. attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence);
  385. attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
  386. attribute_deprecated int64_t url_ftell(AVIOContext *s);
  387. attribute_deprecated int64_t url_fsize(AVIOContext *s);
  388. #define URL_EOF (-1)
  389. attribute_deprecated int url_fgetc(AVIOContext *s);
  390. attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
  391. #ifdef __GNUC__
  392. attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
  393. #else
  394. attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...);
  395. #endif
  396. attribute_deprecated void put_flush_packet(AVIOContext *s);
  397. /**
  398. * @}
  399. */
  400. /**
  401. * @deprecated use AVIOContext.eof_reached
  402. */
  403. attribute_deprecated int url_feof(AVIOContext *s);
  404. attribute_deprecated int url_ferror(AVIOContext *s);
  405. attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri);
  406. attribute_deprecated int udp_get_local_port(URLContext *h);
  407. #endif
  408. AVIOContext *avio_alloc_context(
  409. unsigned char *buffer,
  410. int buffer_size,
  411. int write_flag,
  412. void *opaque,
  413. int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
  414. int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
  415. int64_t (*seek)(void *opaque, int64_t offset, int whence));
  416. void avio_w8(AVIOContext *s, int b);
  417. void avio_write(AVIOContext *s, const unsigned char *buf, int size);
  418. void avio_wl64(AVIOContext *s, uint64_t val);
  419. void avio_wb64(AVIOContext *s, uint64_t val);
  420. void avio_wl32(AVIOContext *s, unsigned int val);
  421. void avio_wb32(AVIOContext *s, unsigned int val);
  422. void avio_wl24(AVIOContext *s, unsigned int val);
  423. void avio_wb24(AVIOContext *s, unsigned int val);
  424. void avio_wl16(AVIOContext *s, unsigned int val);
  425. void avio_wb16(AVIOContext *s, unsigned int val);
  426. #if FF_API_OLD_AVIO
  427. attribute_deprecated void put_strz(AVIOContext *s, const char *buf);
  428. #endif
  429. /**
  430. * Write a NULL-terminated string.
  431. * @return number of bytes written.
  432. */
  433. int avio_put_str(AVIOContext *s, const char *str);
  434. /**
  435. * Convert an UTF-8 string to UTF-16LE and write it.
  436. * @return number of bytes written.
  437. */
  438. int avio_put_str16le(AVIOContext *s, const char *str);
  439. /**
  440. * fseek() equivalent for AVIOContext.
  441. * @return new position or AVERROR.
  442. */
  443. int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
  444. /**
  445. * Skip given number of bytes forward
  446. * @return new position or AVERROR.
  447. */
  448. static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
  449. {
  450. return avio_seek(s, offset, SEEK_CUR);
  451. }
  452. /**
  453. * ftell() equivalent for AVIOContext.
  454. * @return position or AVERROR.
  455. */
  456. static av_always_inline int64_t avio_tell(AVIOContext *s)
  457. {
  458. return avio_seek(s, 0, SEEK_CUR);
  459. }
  460. /**
  461. * Get the filesize.
  462. * @return filesize or AVERROR
  463. */
  464. int64_t avio_size(AVIOContext *s);
  465. /** @warning currently size is limited */
  466. #ifdef __GNUC__
  467. int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
  468. #else
  469. int avio_printf(AVIOContext *s, const char *fmt, ...);
  470. #endif
  471. #if FF_API_OLD_AVIO
  472. /** @note unlike fgets, the EOL character is not returned and a whole
  473. line is parsed. return NULL if first char read was EOF */
  474. attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
  475. #endif
  476. void avio_flush(AVIOContext *s);
  477. /**
  478. * Read size bytes from AVIOContext into buf.
  479. * @return number of bytes read or AVERROR
  480. */
  481. int avio_read(AVIOContext *s, unsigned char *buf, int size);
  482. /** @note return 0 if EOF, so you cannot use it if EOF handling is
  483. necessary */
  484. int avio_r8 (AVIOContext *s);
  485. unsigned int avio_rl16(AVIOContext *s);
  486. unsigned int avio_rl24(AVIOContext *s);
  487. unsigned int avio_rl32(AVIOContext *s);
  488. uint64_t avio_rl64(AVIOContext *s);
  489. /**
  490. * Read a string from pb into buf. The reading will terminate when either
  491. * a NULL character was encountered, maxlen bytes have been read, or nothing
  492. * more can be read from pb. The result is guaranteed to be NULL-terminated, it
  493. * will be truncated if buf is too small.
  494. * Note that the string is not interpreted or validated in any way, it
  495. * might get truncated in the middle of a sequence for multi-byte encodings.
  496. *
  497. * @return number of bytes read (is always <= maxlen).
  498. * If reading ends on EOF or error, the return value will be one more than
  499. * bytes actually read.
  500. */
  501. int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
  502. /**
  503. * Read a UTF-16 string from pb and convert it to UTF-8.
  504. * The reading will terminate when either a null or invalid character was
  505. * encountered or maxlen bytes have been read.
  506. * @return number of bytes read (is always <= maxlen)
  507. */
  508. int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
  509. int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
  510. #if FF_API_OLD_AVIO
  511. /**
  512. * @deprecated use avio_get_str instead
  513. */
  514. attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
  515. #endif
  516. unsigned int avio_rb16(AVIOContext *s);
  517. unsigned int avio_rb24(AVIOContext *s);
  518. unsigned int avio_rb32(AVIOContext *s);
  519. uint64_t avio_rb64(AVIOContext *s);
  520. static inline int url_is_streamed(AVIOContext *s)
  521. {
  522. return s->is_streamed;
  523. }
  524. /**
  525. * Create and initialize a AVIOContext for accessing the
  526. * resource referenced by the URLContext h.
  527. * @note When the URLContext h has been opened in read+write mode, the
  528. * AVIOContext can be used only for writing.
  529. *
  530. * @param s Used to return the pointer to the created AVIOContext.
  531. * In case of failure the pointed to value is set to NULL.
  532. * @return 0 in case of success, a negative value corresponding to an
  533. * AVERROR code in case of failure
  534. */
  535. int url_fdopen(AVIOContext **s, URLContext *h);
  536. #if FF_API_URL_RESETBUF
  537. /** Reset the buffer for reading or writing.
  538. * @note Will drop any data currently in the buffer without transmitting it.
  539. * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY
  540. * to set up the buffer for writing. */
  541. int url_resetbuf(AVIOContext *s, int flags);
  542. #endif
  543. /**
  544. * Create and initialize a AVIOContext for accessing the
  545. * resource indicated by url.
  546. * @note When the resource indicated by url has been opened in
  547. * read+write mode, the AVIOContext can be used only for writing.
  548. *
  549. * @param s Used to return the pointer to the created AVIOContext.
  550. * In case of failure the pointed to value is set to NULL.
  551. * @param flags flags which control how the resource indicated by url
  552. * is to be opened
  553. * @return 0 in case of success, a negative value corresponding to an
  554. * AVERROR code in case of failure
  555. */
  556. int avio_open(AVIOContext **s, const char *url, int flags);
  557. int avio_close(AVIOContext *s);
  558. #if FF_API_OLD_AVIO
  559. attribute_deprecated URLContext *url_fileno(AVIOContext *s);
  560. /**
  561. * @deprecated use AVIOContext.max_packet_size directly.
  562. */
  563. attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
  564. attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags);
  565. /** return the written or read size */
  566. attribute_deprecated int url_close_buf(AVIOContext *s);
  567. #endif
  568. /**
  569. * Open a write only memory stream.
  570. *
  571. * @param s new IO context
  572. * @return zero if no error.
  573. */
  574. int url_open_dyn_buf(AVIOContext **s);
  575. /**
  576. * Open a write only packetized memory stream with a maximum packet
  577. * size of 'max_packet_size'. The stream is stored in a memory buffer
  578. * with a big endian 4 byte header giving the packet size in bytes.
  579. *
  580. * @param s new IO context
  581. * @param max_packet_size maximum packet size (must be > 0)
  582. * @return zero if no error.
  583. */
  584. int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
  585. /**
  586. * Return the written size and a pointer to the buffer. The buffer
  587. * must be freed with av_free(). If the buffer is opened with
  588. * url_open_dyn_buf, then padding of FF_INPUT_BUFFER_PADDING_SIZE is
  589. * added; if opened with url_open_dyn_packet_buf, no padding is added.
  590. *
  591. * @param s IO context
  592. * @param pbuffer pointer to a byte buffer
  593. * @return the length of the byte buffer
  594. */
  595. int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
  596. unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
  597. unsigned int len);
  598. unsigned long get_checksum(AVIOContext *s);
  599. void init_checksum(AVIOContext *s,
  600. unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
  601. unsigned long checksum);
  602. #if FF_API_UDP_GET_FILE
  603. int udp_get_file_handle(URLContext *h);
  604. #endif
  605. #endif /* AVFORMAT_AVIO_H */