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.

176 lines
6.1KB

  1. /*
  2. *
  3. * This file is part of FFmpeg.
  4. *
  5. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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. #if !FF_API_OLD_AVIO
  28. #define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
  29. extern int (*url_interrupt_cb)(void);
  30. typedef struct URLContext {
  31. const AVClass *av_class; /**< information for av_log(). Set by url_open(). */
  32. struct URLProtocol *prot;
  33. void *priv_data;
  34. char *filename; /**< specified URL */
  35. int flags;
  36. int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
  37. int is_streamed; /**< true if streamed (no seek possible), default = false */
  38. int is_connected;
  39. } URLContext;
  40. typedef struct URLProtocol {
  41. const char *name;
  42. int (*url_open)( URLContext *h, const char *url, int flags);
  43. int (*url_read)( URLContext *h, unsigned char *buf, int size);
  44. int (*url_write)(URLContext *h, const unsigned char *buf, int size);
  45. int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);
  46. int (*url_close)(URLContext *h);
  47. struct URLProtocol *next;
  48. int (*url_read_pause)(URLContext *h, int pause);
  49. int64_t (*url_read_seek)(URLContext *h, int stream_index,
  50. int64_t timestamp, int flags);
  51. int (*url_get_file_handle)(URLContext *h);
  52. int priv_data_size;
  53. const AVClass *priv_data_class;
  54. int flags;
  55. } URLProtocol;
  56. #endif
  57. /**
  58. * Create a URLContext for accessing to the resource indicated by
  59. * url, but do not initiate the connection yet.
  60. *
  61. * @param puc pointer to the location where, in case of success, the
  62. * function puts the pointer to the created URLContext
  63. * @param flags flags which control how the resource indicated by url
  64. * is to be opened
  65. * @return 0 in case of success, a negative value corresponding to an
  66. * AVERROR code in case of failure
  67. */
  68. int ffurl_alloc(URLContext **h, const char *url, int flags);
  69. /**
  70. * Connect an URLContext that has been allocated by ffurl_alloc
  71. */
  72. int ffurl_connect(URLContext *h);
  73. /**
  74. * Create an URLContext for accessing to the resource indicated by
  75. * url, and open it.
  76. *
  77. * @param puc pointer to the location where, in case of success, the
  78. * function puts the pointer to the created URLContext
  79. * @param flags flags which control how the resource indicated by url
  80. * is to be opened
  81. * @return 0 in case of success, a negative value corresponding to an
  82. * AVERROR code in case of failure
  83. */
  84. int ffurl_open(URLContext **h, const char *url, int flags);
  85. /**
  86. * Read up to size bytes from the resource accessed by h, and store
  87. * the read bytes in buf.
  88. *
  89. * @return The number of bytes actually read, or a negative value
  90. * corresponding to an AVERROR code in case of error. A value of zero
  91. * indicates that it is not possible to read more from the accessed
  92. * resource (except if the value of the size argument is also zero).
  93. */
  94. int ffurl_read(URLContext *h, unsigned char *buf, int size);
  95. /**
  96. * Read as many bytes as possible (up to size), calling the
  97. * read function multiple times if necessary.
  98. * This makes special short-read handling in applications
  99. * unnecessary, if the return value is < size then it is
  100. * certain there was either an error or the end of file was reached.
  101. */
  102. int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
  103. /**
  104. * Write size bytes from buf to the resource accessed by h.
  105. *
  106. * @return the number of bytes actually written, or a negative value
  107. * corresponding to an AVERROR code in case of failure
  108. */
  109. int ffurl_write(URLContext *h, const unsigned char *buf, int size);
  110. /**
  111. * Change the position that will be used by the next read/write
  112. * operation on the resource accessed by h.
  113. *
  114. * @param pos specifies the new position to set
  115. * @param whence specifies how pos should be interpreted, it must be
  116. * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
  117. * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
  118. * (return the filesize of the requested resource, pos is ignored).
  119. * @return a negative value corresponding to an AVERROR code in case
  120. * of failure, or the resulting file position, measured in bytes from
  121. * the beginning of the file. You can use this feature together with
  122. * SEEK_CUR to read the current file position.
  123. */
  124. int64_t ffurl_seek(URLContext *h, int64_t pos, int whence);
  125. /**
  126. * Close the resource accessed by the URLContext h, and free the
  127. * memory used by it.
  128. *
  129. * @return a negative value if an error condition occurred, 0
  130. * otherwise
  131. */
  132. int ffurl_close(URLContext *h);
  133. /**
  134. * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
  135. * if the operation is not supported by h, or another negative value
  136. * corresponding to an AVERROR error code in case of failure.
  137. */
  138. int64_t ffurl_size(URLContext *h);
  139. /**
  140. * Return the file descriptor associated with this URL. For RTP, this
  141. * will return only the RTP file descriptor, not the RTCP file descriptor.
  142. *
  143. * @return the file descriptor associated with this URL, or <0 on error.
  144. */
  145. int ffurl_get_file_handle(URLContext *h);
  146. /**
  147. * Register the URLProtocol protocol.
  148. *
  149. * @param size the size of the URLProtocol struct referenced
  150. */
  151. int ffurl_register_protocol(URLProtocol *protocol, int size);
  152. /* udp.c */
  153. int ff_udp_set_remote_url(URLContext *h, const char *uri);
  154. int ff_udp_get_local_port(URLContext *h);
  155. #endif //AVFORMAT_URL_H