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.

213 lines
7.6KB

  1. /*
  2. *
  3. * This file is part of Libav.
  4. *
  5. * Libav is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * Libav is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with Libav; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. /**
  20. * @file
  21. * unbuffered private I/O API
  22. */
  23. #ifndef AVFORMAT_URL_H
  24. #define AVFORMAT_URL_H
  25. #include "avio.h"
  26. #include "libavformat/version.h"
  27. #include "libavutil/dict.h"
  28. #if !FF_API_OLD_AVIO
  29. #define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
  30. extern int (*url_interrupt_cb)(void);
  31. typedef struct URLContext {
  32. const AVClass *av_class; /**< information for av_log(). Set by url_open(). */
  33. struct URLProtocol *prot;
  34. void *priv_data;
  35. char *filename; /**< specified URL */
  36. int flags;
  37. int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
  38. int is_streamed; /**< true if streamed (no seek possible), default = false */
  39. int is_connected;
  40. AVIOInterruptCB interrupt_callback;
  41. } URLContext;
  42. typedef struct URLProtocol {
  43. const char *name;
  44. int (*url_open)( URLContext *h, const char *url, int flags);
  45. /**
  46. * This callback is to be used by protocols which open further nested
  47. * protocols. options are then to be passed to ffurl_open()/ffurl_connect()
  48. * for those nested protocols.
  49. */
  50. int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options);
  51. int (*url_read)( URLContext *h, unsigned char *buf, int size);
  52. int (*url_write)(URLContext *h, const unsigned char *buf, int size);
  53. int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);
  54. int (*url_close)(URLContext *h);
  55. struct URLProtocol *next;
  56. int (*url_read_pause)(URLContext *h, int pause);
  57. int64_t (*url_read_seek)(URLContext *h, int stream_index,
  58. int64_t timestamp, int flags);
  59. int (*url_get_file_handle)(URLContext *h);
  60. int priv_data_size;
  61. const AVClass *priv_data_class;
  62. int flags;
  63. int (*url_check)(URLContext *h, int mask);
  64. } URLProtocol;
  65. #endif
  66. /**
  67. * Create a URLContext for accessing to the resource indicated by
  68. * url, but do not initiate the connection yet.
  69. *
  70. * @param puc pointer to the location where, in case of success, the
  71. * function puts the pointer to the created URLContext
  72. * @param flags flags which control how the resource indicated by url
  73. * is to be opened
  74. * @param int_cb interrupt callback to use for the URLContext, may be
  75. * NULL
  76. * @return 0 in case of success, a negative value corresponding to an
  77. * AVERROR code in case of failure
  78. */
  79. int ffurl_alloc(URLContext **puc, const char *filename, int flags,
  80. const AVIOInterruptCB *int_cb);
  81. /**
  82. * Connect an URLContext that has been allocated by ffurl_alloc
  83. *
  84. * @param options A dictionary filled with options for nested protocols,
  85. * i.e. it will be passed to url_open2() for protocols implementing it.
  86. * This parameter will be destroyed and replaced with a dict containing options
  87. * that were not found. May be NULL.
  88. */
  89. int ffurl_connect(URLContext *uc, AVDictionary **options);
  90. /**
  91. * Create an URLContext for accessing to the resource indicated by
  92. * url, and open it.
  93. *
  94. * @param puc pointer to the location where, in case of success, the
  95. * function puts the pointer to the created URLContext
  96. * @param flags flags which control how the resource indicated by url
  97. * is to be opened
  98. * @param int_cb interrupt callback to use for the URLContext, may be
  99. * NULL
  100. * @param options A dictionary filled with protocol-private options. On return
  101. * this parameter will be destroyed and replaced with a dict containing options
  102. * that were not found. May be NULL.
  103. * @return 0 in case of success, a negative value corresponding to an
  104. * AVERROR code in case of failure
  105. */
  106. int ffurl_open(URLContext **puc, const char *filename, int flags,
  107. const AVIOInterruptCB *int_cb, AVDictionary **options);
  108. /**
  109. * Read up to size bytes from the resource accessed by h, and store
  110. * the read bytes in buf.
  111. *
  112. * @return The number of bytes actually read, or a negative value
  113. * corresponding to an AVERROR code in case of error. A value of zero
  114. * indicates that it is not possible to read more from the accessed
  115. * resource (except if the value of the size argument is also zero).
  116. */
  117. int ffurl_read(URLContext *h, unsigned char *buf, int size);
  118. /**
  119. * Read as many bytes as possible (up to size), calling the
  120. * read function multiple times if necessary.
  121. * This makes special short-read handling in applications
  122. * unnecessary, if the return value is < size then it is
  123. * certain there was either an error or the end of file was reached.
  124. */
  125. int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
  126. /**
  127. * Write size bytes from buf to the resource accessed by h.
  128. *
  129. * @return the number of bytes actually written, or a negative value
  130. * corresponding to an AVERROR code in case of failure
  131. */
  132. int ffurl_write(URLContext *h, const unsigned char *buf, int size);
  133. /**
  134. * Change the position that will be used by the next read/write
  135. * operation on the resource accessed by h.
  136. *
  137. * @param pos specifies the new position to set
  138. * @param whence specifies how pos should be interpreted, it must be
  139. * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
  140. * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
  141. * (return the filesize of the requested resource, pos is ignored).
  142. * @return a negative value corresponding to an AVERROR code in case
  143. * of failure, or the resulting file position, measured in bytes from
  144. * the beginning of the file. You can use this feature together with
  145. * SEEK_CUR to read the current file position.
  146. */
  147. int64_t ffurl_seek(URLContext *h, int64_t pos, int whence);
  148. /**
  149. * Close the resource accessed by the URLContext h, and free the
  150. * memory used by it.
  151. *
  152. * @return a negative value if an error condition occurred, 0
  153. * otherwise
  154. */
  155. int ffurl_close(URLContext *h);
  156. /**
  157. * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
  158. * if the operation is not supported by h, or another negative value
  159. * corresponding to an AVERROR error code in case of failure.
  160. */
  161. int64_t ffurl_size(URLContext *h);
  162. /**
  163. * Return the file descriptor associated with this URL. For RTP, this
  164. * will return only the RTP file descriptor, not the RTCP file descriptor.
  165. *
  166. * @return the file descriptor associated with this URL, or <0 on error.
  167. */
  168. int ffurl_get_file_handle(URLContext *h);
  169. /**
  170. * Register the URLProtocol protocol.
  171. *
  172. * @param size the size of the URLProtocol struct referenced
  173. */
  174. int ffurl_register_protocol(URLProtocol *protocol, int size);
  175. /**
  176. * Check if the user has requested to interrup a blocking function
  177. * associated with cb.
  178. */
  179. int ff_check_interrupt(AVIOInterruptCB *cb);
  180. /**
  181. * Iterate over all available protocols.
  182. *
  183. * @param prev result of the previous call to this functions or NULL.
  184. */
  185. URLProtocol *ffurl_protocol_next(URLProtocol *prev);
  186. /* udp.c */
  187. int ff_udp_set_remote_url(URLContext *h, const char *uri);
  188. int ff_udp_get_local_port(URLContext *h);
  189. #endif /* AVFORMAT_URL_H */