url.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. int (*url_check)(URLContext *h, int mask);
  56. } URLProtocol;
  57. #endif
  58. /**
  59. * Create a URLContext for accessing to the resource indicated by
  60. * url, but do not initiate the connection yet.
  61. *
  62. * @param puc pointer to the location where, in case of success, the
  63. * function puts the pointer to the created URLContext
  64. * @param flags flags which control how the resource indicated by url
  65. * is to be opened
  66. * @return 0 in case of success, a negative value corresponding to an
  67. * AVERROR code in case of failure
  68. */
  69. int ffurl_alloc(URLContext **puc, const char *filename, int flags);
  70. /**
  71. * Connect an URLContext that has been allocated by ffurl_alloc
  72. */
  73. int ffurl_connect(URLContext *uc);
  74. /**
  75. * Create an URLContext for accessing to the resource indicated by
  76. * url, and open it.
  77. *
  78. * @param puc pointer to the location where, in case of success, the
  79. * function puts the pointer to the created URLContext
  80. * @param flags flags which control how the resource indicated by url
  81. * is to be opened
  82. * @return 0 in case of success, a negative value corresponding to an
  83. * AVERROR code in case of failure
  84. */
  85. int ffurl_open(URLContext **puc, const char *filename, int flags);
  86. /**
  87. * Read up to size bytes from the resource accessed by h, and store
  88. * the read bytes in buf.
  89. *
  90. * @return The number of bytes actually read, or a negative value
  91. * corresponding to an AVERROR code in case of error. A value of zero
  92. * indicates that it is not possible to read more from the accessed
  93. * resource (except if the value of the size argument is also zero).
  94. */
  95. int ffurl_read(URLContext *h, unsigned char *buf, int size);
  96. /**
  97. * Read as many bytes as possible (up to size), calling the
  98. * read function multiple times if necessary.
  99. * This makes special short-read handling in applications
  100. * unnecessary, if the return value is < size then it is
  101. * certain there was either an error or the end of file was reached.
  102. */
  103. int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
  104. /**
  105. * Write size bytes from buf to the resource accessed by h.
  106. *
  107. * @return the number of bytes actually written, or a negative value
  108. * corresponding to an AVERROR code in case of failure
  109. */
  110. int ffurl_write(URLContext *h, const unsigned char *buf, int size);
  111. /**
  112. * Change the position that will be used by the next read/write
  113. * operation on the resource accessed by h.
  114. *
  115. * @param pos specifies the new position to set
  116. * @param whence specifies how pos should be interpreted, it must be
  117. * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
  118. * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
  119. * (return the filesize of the requested resource, pos is ignored).
  120. * @return a negative value corresponding to an AVERROR code in case
  121. * of failure, or the resulting file position, measured in bytes from
  122. * the beginning of the file. You can use this feature together with
  123. * SEEK_CUR to read the current file position.
  124. */
  125. int64_t ffurl_seek(URLContext *h, int64_t pos, int whence);
  126. /**
  127. * Close the resource accessed by the URLContext h, and free the
  128. * memory used by it.
  129. *
  130. * @return a negative value if an error condition occurred, 0
  131. * otherwise
  132. */
  133. int ffurl_close(URLContext *h);
  134. /**
  135. * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
  136. * if the operation is not supported by h, or another negative value
  137. * corresponding to an AVERROR error code in case of failure.
  138. */
  139. int64_t ffurl_size(URLContext *h);
  140. /**
  141. * Return the file descriptor associated with this URL. For RTP, this
  142. * will return only the RTP file descriptor, not the RTCP file descriptor.
  143. *
  144. * @return the file descriptor associated with this URL, or <0 on error.
  145. */
  146. int ffurl_get_file_handle(URLContext *h);
  147. /**
  148. * Register the URLProtocol protocol.
  149. *
  150. * @param size the size of the URLProtocol struct referenced
  151. */
  152. int ffurl_register_protocol(URLProtocol *protocol, int size);
  153. /* udp.c */
  154. int ff_udp_set_remote_url(URLContext *h, const char *uri);
  155. int ff_udp_get_local_port(URLContext *h);
  156. #endif /* AVFORMAT_URL_H */