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.

154 lines
4.9KB

  1. #ifndef AVIO_H
  2. #define AVIO_H
  3. /* output byte stream handling */
  4. typedef INT64 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. };
  13. typedef struct URLContext URLContext;
  14. typedef struct URLPollEntry {
  15. URLContext *handle;
  16. int events;
  17. int revents;
  18. } URLPollEntry;
  19. #define URL_RDONLY 0
  20. #define URL_WRONLY 1
  21. #define URL_RDWR 2
  22. int url_open(URLContext **h, const char *filename, int flags);
  23. int url_read(URLContext *h, unsigned char *buf, int size);
  24. int url_write(URLContext *h, unsigned char *buf, int size);
  25. offset_t url_seek(URLContext *h, offset_t pos, int whence);
  26. int url_close(URLContext *h);
  27. int url_exist(const char *filename);
  28. offset_t url_filesize(URLContext *h);
  29. int url_get_max_packet_size(URLContext *h);
  30. /* not implemented */
  31. int url_poll(URLPollEntry *poll_table, int n, int timeout);
  32. typedef struct URLProtocol {
  33. const char *name;
  34. int (*url_open)(URLContext *h, const char *filename, int flags);
  35. int (*url_read)(URLContext *h, unsigned char *buf, int size);
  36. int (*url_write)(URLContext *h, unsigned char *buf, int size);
  37. offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
  38. int (*url_close)(URLContext *h);
  39. struct URLProtocol *next;
  40. } URLProtocol;
  41. extern URLProtocol *first_protocol;
  42. int register_protocol(URLProtocol *protocol);
  43. typedef struct {
  44. unsigned char *buffer;
  45. int buffer_size;
  46. unsigned char *buf_ptr, *buf_end;
  47. void *opaque;
  48. int (*read_packet)(void *opaque, UINT8 *buf, int buf_size);
  49. void (*write_packet)(void *opaque, UINT8 *buf, int buf_size);
  50. int (*seek)(void *opaque, offset_t offset, int whence);
  51. offset_t pos; /* position in the file of the current buffer */
  52. int must_flush; /* true if the next seek should flush */
  53. int eof_reached; /* true if eof reached */
  54. int write_flag; /* true if open for writing */
  55. int is_streamed;
  56. int max_packet_size;
  57. } ByteIOContext;
  58. int init_put_byte(ByteIOContext *s,
  59. unsigned char *buffer,
  60. int buffer_size,
  61. int write_flag,
  62. void *opaque,
  63. int (*read_packet)(void *opaque, UINT8 *buf, int buf_size),
  64. void (*write_packet)(void *opaque, UINT8 *buf, int buf_size),
  65. int (*seek)(void *opaque, offset_t offset, int whence));
  66. void put_byte(ByteIOContext *s, int b);
  67. void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
  68. void put_le64(ByteIOContext *s, UINT64 val);
  69. void put_be64(ByteIOContext *s, UINT64 val);
  70. void put_le32(ByteIOContext *s, unsigned int val);
  71. void put_be32(ByteIOContext *s, unsigned int val);
  72. void put_le16(ByteIOContext *s, unsigned int val);
  73. void put_be16(ByteIOContext *s, unsigned int val);
  74. void put_tag(ByteIOContext *s, const char *tag);
  75. void put_be64_double(ByteIOContext *s, double val);
  76. void put_strz(ByteIOContext *s, const char *buf);
  77. offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
  78. void url_fskip(ByteIOContext *s, offset_t offset);
  79. offset_t url_ftell(ByteIOContext *s);
  80. int url_feof(ByteIOContext *s);
  81. #define URL_EOF (-1)
  82. int url_fgetc(ByteIOContext *s);
  83. int url_fprintf(ByteIOContext *s, const char *fmt, ...);
  84. char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
  85. void put_flush_packet(ByteIOContext *s);
  86. int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
  87. int get_byte(ByteIOContext *s);
  88. unsigned int get_le32(ByteIOContext *s);
  89. UINT64 get_le64(ByteIOContext *s);
  90. unsigned int get_le16(ByteIOContext *s);
  91. double get_be64_double(ByteIOContext *s);
  92. char *get_strz(ByteIOContext *s, char *buf, int maxlen);
  93. unsigned int get_be16(ByteIOContext *s);
  94. unsigned int get_be32(ByteIOContext *s);
  95. UINT64 get_be64(ByteIOContext *s);
  96. static inline int url_is_streamed(ByteIOContext *s)
  97. {
  98. return s->is_streamed;
  99. }
  100. int url_fdopen(ByteIOContext *s, URLContext *h);
  101. int url_setbufsize(ByteIOContext *s, int buf_size);
  102. int url_fopen(ByteIOContext *s, const char *filename, int flags);
  103. int url_fclose(ByteIOContext *s);
  104. URLContext *url_fileno(ByteIOContext *s);
  105. int url_fget_max_packet_size(ByteIOContext *s);
  106. int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags);
  107. int url_close_buf(ByteIOContext *s);
  108. int url_open_dyn_buf(ByteIOContext *s);
  109. int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
  110. int url_close_dyn_buf(ByteIOContext *s, UINT8 **pbuffer);
  111. /* file.c */
  112. extern URLProtocol file_protocol;
  113. extern URLProtocol pipe_protocol;
  114. /* udp.c */
  115. extern URLProtocol udp_protocol;
  116. int udp_set_remote_url(URLContext *h, const char *uri);
  117. int udp_get_local_port(URLContext *h);
  118. int udp_get_file_handle(URLContext *h);
  119. /* tcp.c */
  120. extern URLProtocol tcp_protocol;
  121. /* http.c */
  122. extern URLProtocol http_protocol;
  123. #endif