You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
6.9KB

  1. /*
  2. * unbuffered io for ffmpeg system
  3. * copyright (c) 2001 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVIO_H
  22. #define AVIO_H
  23. /* output byte stream handling */
  24. typedef int64_t offset_t;
  25. /* unbuffered I/O */
  26. struct URLContext {
  27. struct URLProtocol *prot;
  28. int flags;
  29. int is_streamed; /* true if streamed (no seek possible), default = false */
  30. int max_packet_size; /* if non zero, the stream is packetized with this max packet size */
  31. void *priv_data;
  32. char filename[1]; /* specified filename */
  33. };
  34. typedef struct URLContext URLContext;
  35. typedef struct URLPollEntry {
  36. URLContext *handle;
  37. int events;
  38. int revents;
  39. } URLPollEntry;
  40. #define URL_RDONLY 0
  41. #define URL_WRONLY 1
  42. #define URL_RDWR 2
  43. typedef int URLInterruptCB(void);
  44. int url_open(URLContext **h, const char *filename, int flags);
  45. int url_read(URLContext *h, unsigned char *buf, int size);
  46. int url_write(URLContext *h, unsigned char *buf, int size);
  47. offset_t url_seek(URLContext *h, offset_t pos, int whence);
  48. int url_close(URLContext *h);
  49. int url_exist(const char *filename);
  50. offset_t url_filesize(URLContext *h);
  51. int url_get_max_packet_size(URLContext *h);
  52. void url_get_filename(URLContext *h, char *buf, int buf_size);
  53. /* the callback is called in blocking functions to test regulary if
  54. asynchronous interruption is needed. -EINTR is returned in this
  55. case by the interrupted function. 'NULL' means no interrupt
  56. callback is given. */
  57. void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
  58. /* not implemented */
  59. int url_poll(URLPollEntry *poll_table, int n, int timeout);
  60. typedef struct URLProtocol {
  61. const char *name;
  62. int (*url_open)(URLContext *h, const char *filename, int flags);
  63. int (*url_read)(URLContext *h, unsigned char *buf, int size);
  64. int (*url_write)(URLContext *h, unsigned char *buf, int size);
  65. offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
  66. int (*url_close)(URLContext *h);
  67. struct URLProtocol *next;
  68. } URLProtocol;
  69. extern URLProtocol *first_protocol;
  70. extern URLInterruptCB *url_interrupt_cb;
  71. int register_protocol(URLProtocol *protocol);
  72. typedef struct {
  73. unsigned char *buffer;
  74. int buffer_size;
  75. unsigned char *buf_ptr, *buf_end;
  76. void *opaque;
  77. int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
  78. int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
  79. offset_t (*seek)(void *opaque, offset_t offset, int whence);
  80. offset_t pos; /* position in the file of the current buffer */
  81. int must_flush; /* true if the next seek should flush */
  82. int eof_reached; /* true if eof reached */
  83. int write_flag; /* true if open for writing */
  84. int is_streamed;
  85. int max_packet_size;
  86. unsigned long checksum;
  87. unsigned char *checksum_ptr;
  88. unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
  89. int error; ///< contains the error code or 0 if no error happened
  90. } ByteIOContext;
  91. int init_put_byte(ByteIOContext *s,
  92. unsigned char *buffer,
  93. int buffer_size,
  94. int write_flag,
  95. void *opaque,
  96. int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
  97. int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
  98. offset_t (*seek)(void *opaque, offset_t offset, int whence));
  99. void put_byte(ByteIOContext *s, int b);
  100. void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
  101. void put_le64(ByteIOContext *s, uint64_t val);
  102. void put_be64(ByteIOContext *s, uint64_t val);
  103. void put_le32(ByteIOContext *s, unsigned int val);
  104. void put_be32(ByteIOContext *s, unsigned int val);
  105. void put_le24(ByteIOContext *s, unsigned int val);
  106. void put_be24(ByteIOContext *s, unsigned int val);
  107. void put_le16(ByteIOContext *s, unsigned int val);
  108. void put_be16(ByteIOContext *s, unsigned int val);
  109. void put_tag(ByteIOContext *s, const char *tag);
  110. void put_strz(ByteIOContext *s, const char *buf);
  111. offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
  112. void url_fskip(ByteIOContext *s, offset_t offset);
  113. offset_t url_ftell(ByteIOContext *s);
  114. offset_t url_fsize(ByteIOContext *s);
  115. int url_feof(ByteIOContext *s);
  116. int url_ferror(ByteIOContext *s);
  117. #define URL_EOF (-1)
  118. int url_fgetc(ByteIOContext *s);
  119. #ifdef __GNUC__
  120. int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
  121. #else
  122. int url_fprintf(ByteIOContext *s, const char *fmt, ...);
  123. #endif
  124. char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
  125. void put_flush_packet(ByteIOContext *s);
  126. int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
  127. int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
  128. int get_byte(ByteIOContext *s);
  129. unsigned int get_le24(ByteIOContext *s);
  130. unsigned int get_le32(ByteIOContext *s);
  131. uint64_t get_le64(ByteIOContext *s);
  132. unsigned int get_le16(ByteIOContext *s);
  133. char *get_strz(ByteIOContext *s, char *buf, int maxlen);
  134. unsigned int get_be16(ByteIOContext *s);
  135. unsigned int get_be24(ByteIOContext *s);
  136. unsigned int get_be32(ByteIOContext *s);
  137. uint64_t get_be64(ByteIOContext *s);
  138. static inline int url_is_streamed(ByteIOContext *s)
  139. {
  140. return s->is_streamed;
  141. }
  142. int url_fdopen(ByteIOContext *s, URLContext *h);
  143. int url_setbufsize(ByteIOContext *s, int buf_size);
  144. int url_fopen(ByteIOContext *s, const char *filename, int flags);
  145. int url_fclose(ByteIOContext *s);
  146. URLContext *url_fileno(ByteIOContext *s);
  147. int url_fget_max_packet_size(ByteIOContext *s);
  148. int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags);
  149. int url_close_buf(ByteIOContext *s);
  150. int url_open_dyn_buf(ByteIOContext *s);
  151. int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
  152. int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
  153. unsigned long get_checksum(ByteIOContext *s);
  154. void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum);
  155. /* file.c */
  156. extern URLProtocol file_protocol;
  157. extern URLProtocol pipe_protocol;
  158. /* udp.c */
  159. extern URLProtocol udp_protocol;
  160. int udp_set_remote_url(URLContext *h, const char *uri);
  161. int udp_get_local_port(URLContext *h);
  162. int udp_get_file_handle(URLContext *h);
  163. /* tcp.c */
  164. extern URLProtocol tcp_protocol;
  165. /* http.c */
  166. extern URLProtocol http_protocol;
  167. #endif