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.

157 lines
5.0KB

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