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.

181 lines
6.1KB

  1. #ifndef AVIO_H
  2. #define AVIO_H
  3. /* output byte stream handling */
  4. typedef int64_t offset_t;
  5. /* unbuffered I/O */
  6. struct URLContext {
  7. struct URLProtocol *prot;
  8. int flags;
  9. int is_streamed; /* true if streamed (no seek possible), default = false */
  10. int max_packet_size; /* if non zero, the stream is packetized with this max packet size */
  11. void *priv_data;
  12. char filename[1]; /* specified filename */
  13. };
  14. typedef struct URLContext URLContext;
  15. typedef struct URLPollEntry {
  16. URLContext *handle;
  17. int events;
  18. int revents;
  19. } URLPollEntry;
  20. #define URL_RDONLY 0
  21. #define URL_WRONLY 1
  22. #define URL_RDWR 2
  23. typedef int URLInterruptCB(void);
  24. int url_open(URLContext **h, const char *filename, int flags);
  25. int url_read(URLContext *h, unsigned char *buf, int size);
  26. int url_write(URLContext *h, unsigned char *buf, int size);
  27. offset_t url_seek(URLContext *h, offset_t pos, int whence);
  28. int url_close(URLContext *h);
  29. int url_exist(const char *filename);
  30. offset_t url_filesize(URLContext *h);
  31. int url_get_max_packet_size(URLContext *h);
  32. void url_get_filename(URLContext *h, char *buf, int buf_size);
  33. /* the callback is called in blocking functions to test regulary if
  34. asynchronous interruption is needed. -EINTR is returned in this
  35. case by the interrupted function. 'NULL' means no interrupt
  36. callback is given. */
  37. void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
  38. /* not implemented */
  39. int url_poll(URLPollEntry *poll_table, int n, int timeout);
  40. typedef struct URLProtocol {
  41. const char *name;
  42. int (*url_open)(URLContext *h, const char *filename, int flags);
  43. int (*url_read)(URLContext *h, unsigned char *buf, int size);
  44. int (*url_write)(URLContext *h, unsigned char *buf, int size);
  45. offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
  46. int (*url_close)(URLContext *h);
  47. struct URLProtocol *next;
  48. } URLProtocol;
  49. extern URLProtocol *first_protocol;
  50. extern URLInterruptCB *url_interrupt_cb;
  51. int register_protocol(URLProtocol *protocol);
  52. typedef struct {
  53. unsigned char *buffer;
  54. int buffer_size;
  55. unsigned char *buf_ptr, *buf_end;
  56. void *opaque;
  57. int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
  58. int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
  59. offset_t (*seek)(void *opaque, offset_t offset, int whence);
  60. offset_t pos; /* position in the file of the current buffer */
  61. int must_flush; /* true if the next seek should flush */
  62. int eof_reached; /* true if eof reached */
  63. int write_flag; /* true if open for writing */
  64. int is_streamed;
  65. int max_packet_size;
  66. unsigned long checksum;
  67. unsigned char *checksum_ptr;
  68. unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
  69. int error; ///< contains the error code or 0 if no error happened
  70. } ByteIOContext;
  71. int init_put_byte(ByteIOContext *s,
  72. unsigned char *buffer,
  73. int buffer_size,
  74. int write_flag,
  75. void *opaque,
  76. int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
  77. int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
  78. offset_t (*seek)(void *opaque, offset_t offset, int whence));
  79. void put_byte(ByteIOContext *s, int b);
  80. void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
  81. void put_le64(ByteIOContext *s, uint64_t val);
  82. void put_be64(ByteIOContext *s, uint64_t val);
  83. void put_le32(ByteIOContext *s, unsigned int val);
  84. void put_be32(ByteIOContext *s, unsigned int val);
  85. void put_le16(ByteIOContext *s, unsigned int val);
  86. void put_be16(ByteIOContext *s, unsigned int val);
  87. void put_tag(ByteIOContext *s, const char *tag);
  88. void put_be64_double(ByteIOContext *s, double val);
  89. void put_strz(ByteIOContext *s, const char *buf);
  90. offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
  91. void url_fskip(ByteIOContext *s, offset_t offset);
  92. offset_t url_ftell(ByteIOContext *s);
  93. offset_t url_fsize(ByteIOContext *s);
  94. int url_feof(ByteIOContext *s);
  95. int url_ferror(ByteIOContext *s);
  96. #define URL_EOF (-1)
  97. int url_fgetc(ByteIOContext *s);
  98. #ifdef __GNUC__
  99. int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
  100. #else
  101. int url_fprintf(ByteIOContext *s, const char *fmt, ...);
  102. #endif
  103. char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
  104. void put_flush_packet(ByteIOContext *s);
  105. int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
  106. int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
  107. int get_byte(ByteIOContext *s);
  108. unsigned int get_le32(ByteIOContext *s);
  109. uint64_t get_le64(ByteIOContext *s);
  110. unsigned int get_le16(ByteIOContext *s);
  111. double get_be64_double(ByteIOContext *s);
  112. char *get_strz(ByteIOContext *s, char *buf, int maxlen);
  113. unsigned int get_be16(ByteIOContext *s);
  114. unsigned int get_be32(ByteIOContext *s);
  115. uint64_t get_be64(ByteIOContext *s);
  116. static inline int url_is_streamed(ByteIOContext *s)
  117. {
  118. return s->is_streamed;
  119. }
  120. int url_fdopen(ByteIOContext *s, URLContext *h);
  121. int url_setbufsize(ByteIOContext *s, int buf_size);
  122. int url_fopen(ByteIOContext *s, const char *filename, int flags);
  123. int url_fclose(ByteIOContext *s);
  124. URLContext *url_fileno(ByteIOContext *s);
  125. int url_fget_max_packet_size(ByteIOContext *s);
  126. int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags);
  127. int url_close_buf(ByteIOContext *s);
  128. int url_open_dyn_buf(ByteIOContext *s);
  129. int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
  130. int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
  131. unsigned long get_checksum(ByteIOContext *s);
  132. void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum);
  133. unsigned long update_adler32(unsigned long adler, const uint8_t *buf, unsigned int len);
  134. /* file.c */
  135. extern URLProtocol file_protocol;
  136. extern URLProtocol pipe_protocol;
  137. /* udp.c */
  138. extern URLProtocol udp_protocol;
  139. int udp_set_remote_url(URLContext *h, const char *uri);
  140. int udp_get_local_port(URLContext *h);
  141. int udp_get_file_handle(URLContext *h);
  142. /* tcp.c */
  143. extern URLProtocol tcp_protocol;
  144. /* http.c */
  145. extern URLProtocol http_protocol;
  146. #endif