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.

227 lines
5.8KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "libavutil/avstring.h"
  20. #include "libavutil/mem.h"
  21. #include "url.h"
  22. extern const URLProtocol ff_concat_protocol;
  23. extern const URLProtocol ff_crypto_protocol;
  24. extern const URLProtocol ff_ffrtmpcrypt_protocol;
  25. extern const URLProtocol ff_ffrtmphttp_protocol;
  26. extern const URLProtocol ff_file_protocol;
  27. extern const URLProtocol ff_gopher_protocol;
  28. extern const URLProtocol ff_hls_protocol;
  29. extern const URLProtocol ff_http_protocol;
  30. extern const URLProtocol ff_httpproxy_protocol;
  31. extern const URLProtocol ff_https_protocol;
  32. extern const URLProtocol ff_icecast_protocol;
  33. extern const URLProtocol ff_mmsh_protocol;
  34. extern const URLProtocol ff_mmst_protocol;
  35. extern const URLProtocol ff_md5_protocol;
  36. extern const URLProtocol ff_pipe_protocol;
  37. extern const URLProtocol ff_rtmp_protocol;
  38. extern const URLProtocol ff_rtmpe_protocol;
  39. extern const URLProtocol ff_rtmps_protocol;
  40. extern const URLProtocol ff_rtmpt_protocol;
  41. extern const URLProtocol ff_rtmpte_protocol;
  42. extern const URLProtocol ff_rtmpts_protocol;
  43. extern const URLProtocol ff_rtp_protocol;
  44. extern const URLProtocol ff_sctp_protocol;
  45. extern const URLProtocol ff_srtp_protocol;
  46. extern const URLProtocol ff_tcp_protocol;
  47. extern const URLProtocol ff_tls_gnutls_protocol;
  48. extern const URLProtocol ff_tls_openssl_protocol;
  49. extern const URLProtocol ff_udp_protocol;
  50. extern const URLProtocol ff_unix_protocol;
  51. extern const URLProtocol ff_librtmp_protocol;
  52. extern const URLProtocol ff_librtmpe_protocol;
  53. extern const URLProtocol ff_librtmps_protocol;
  54. extern const URLProtocol ff_librtmpt_protocol;
  55. extern const URLProtocol ff_librtmpte_protocol;
  56. static const URLProtocol *url_protocols[] = {
  57. #if CONFIG_CONCAT_PROTOCOL
  58. &ff_concat_protocol,
  59. #endif
  60. #if CONFIG_CRYPTO_PROTOCOL
  61. &ff_crypto_protocol,
  62. #endif
  63. #if CONFIG_FFRTMPCRYPT_PROTOCOL
  64. &ff_ffrtmpcrypt_protocol,
  65. #endif
  66. #if CONFIG_FFRTMPHTTP_PROTOCOL
  67. &ff_ffrtmphttp_protocol,
  68. #endif
  69. #if CONFIG_FILE_PROTOCOL
  70. &ff_file_protocol,
  71. #endif
  72. #if CONFIG_GOPHER_PROTOCOL
  73. &ff_gopher_protocol,
  74. #endif
  75. #if CONFIG_HLS_PROTOCOL
  76. &ff_hls_protocol,
  77. #endif
  78. #if CONFIG_HTTP_PROTOCOL
  79. &ff_http_protocol,
  80. #endif
  81. #if CONFIG_HTTPPROXY_PROTOCOL
  82. &ff_httpproxy_protocol,
  83. #endif
  84. #if CONFIG_HTTPS_PROTOCOL
  85. &ff_https_protocol,
  86. #endif
  87. #if CONFIG_ICECAST_PROTOCOL
  88. &ff_icecast_protocol,
  89. #endif
  90. #if CONFIG_MMSH_PROTOCOL
  91. &ff_mmsh_protocol,
  92. #endif
  93. #if CONFIG_MMST_PROTOCOL
  94. &ff_mmst_protocol,
  95. #endif
  96. #if CONFIG_MD5_PROTOCOL
  97. &ff_md5_protocol,
  98. #endif
  99. #if CONFIG_PIPE_PROTOCOL
  100. &ff_pipe_protocol,
  101. #endif
  102. #if CONFIG_RTMP_PROTOCOL
  103. &ff_rtmp_protocol,
  104. #endif
  105. #if CONFIG_RTMPE_PROTOCOL
  106. &ff_rtmpe_protocol,
  107. #endif
  108. #if CONFIG_RTMPS_PROTOCOL
  109. &ff_rtmps_protocol,
  110. #endif
  111. #if CONFIG_RTMPT_PROTOCOL
  112. &ff_rtmpt_protocol,
  113. #endif
  114. #if CONFIG_RTMPTE_PROTOCOL
  115. &ff_rtmpte_protocol,
  116. #endif
  117. #if CONFIG_RTMPTS_PROTOCOL
  118. &ff_rtmpts_protocol,
  119. #endif
  120. #if CONFIG_RTP_PROTOCOL
  121. &ff_rtp_protocol,
  122. #endif
  123. #if CONFIG_SCTP_PROTOCOL
  124. &ff_sctp_protocol,
  125. #endif
  126. #if CONFIG_SRTP_PROTOCOL
  127. &ff_srtp_protocol,
  128. #endif
  129. #if CONFIG_TCP_PROTOCOL
  130. &ff_tcp_protocol,
  131. #endif
  132. #if CONFIG_TLS_GNUTLS_PROTOCOL
  133. &ff_tls_gnutls_protocol,
  134. #endif
  135. #if CONFIG_TLS_OPENSSL_PROTOCOL
  136. &ff_tls_openssl_protocol,
  137. #endif
  138. #if CONFIG_UDP_PROTOCOL
  139. &ff_udp_protocol,
  140. #endif
  141. #if CONFIG_UNIX_PROTOCOL
  142. &ff_unix_protocol,
  143. #endif
  144. /* external libraries */
  145. #if CONFIG_LIBRTMP_PROTOCOL
  146. &ff_librtmp_protocol,
  147. #endif
  148. #if CONFIG_LIBRTMPE_PROTOCOL
  149. &ff_librtmpe_protocol,
  150. #endif
  151. #if CONFIG_LIBRTMPS_PROTOCOL
  152. &ff_librtmps_protocol,
  153. #endif
  154. #if CONFIG_LIBRTMPT_PROTOCOL
  155. &ff_librtmpt_protocol,
  156. #endif
  157. #if CONFIG_LIBRTMPTE_PROTOCOL
  158. &ff_librtmpte_protocol,
  159. #endif
  160. NULL,
  161. };
  162. const AVClass *ff_urlcontext_child_class_next(const AVClass *prev)
  163. {
  164. int i;
  165. /* find the protocol that corresponds to prev */
  166. for (i = 0; url_protocols[i]; i++) {
  167. if (url_protocols[i]->priv_data_class == prev) {
  168. i++;
  169. break;
  170. }
  171. }
  172. /* find next protocol with priv options */
  173. for (; url_protocols[i]; i++)
  174. if (url_protocols[i]->priv_data_class)
  175. return url_protocols[i]->priv_data_class;
  176. return NULL;
  177. }
  178. const char *avio_enum_protocols(void **opaque, int output)
  179. {
  180. const URLProtocol **p = *opaque;
  181. p = p ? p + 1 : url_protocols;
  182. *opaque = p;
  183. if (!*p) {
  184. *opaque = NULL;
  185. return NULL;
  186. }
  187. if ((output && (*p)->url_write) || (!output && (*p)->url_read))
  188. return (*p)->name;
  189. return avio_enum_protocols(opaque, output);
  190. }
  191. const URLProtocol **ffurl_get_protocols(const char *whitelist,
  192. const char *blacklist)
  193. {
  194. const URLProtocol **ret;
  195. int i, ret_idx = 0;
  196. ret = av_mallocz_array(FF_ARRAY_ELEMS(url_protocols), sizeof(*ret));
  197. if (!ret)
  198. return NULL;
  199. for (i = 0; url_protocols[i]; i++) {
  200. const URLProtocol *up = url_protocols[i];
  201. if (whitelist && *whitelist && !av_match_name(up->name, whitelist))
  202. continue;
  203. if (blacklist && *blacklist && av_match_name(up->name, blacklist))
  204. continue;
  205. ret[ret_idx++] = up;
  206. }
  207. return ret;
  208. }