22#include "config_components.h"
50#define DEFAULT_USER_AGENT "Lavf/" AV_STRINGIFY(LIBAVFORMAT_VERSION)
51#define CURL_DEFAULT_BUFFER_SIZE (4 << 20)
55#define CURL_WAIT_US 100000
58#define ICY_MAX_HEADERS 65536
61#define ICY_MAX_BLOCK (255 * 16)
66#define CURL_RETRY_BASE_US 1000000
67#define CURL_RETRY_MAX_US 60000000
202 case CURLE_OK:
return 0;
203 case CURLE_URL_MALFORMAT:
204 case CURLE_UNSUPPORTED_PROTOCOL:
205 case CURLE_BAD_FUNCTION_ARGUMENT:
return AVERROR(EINVAL);
206 case CURLE_UNKNOWN_OPTION:
207 case CURLE_NOT_BUILT_IN:
return AVERROR(ENOSYS);
208 case CURLE_COULDNT_RESOLVE_PROXY:
209 case CURLE_COULDNT_RESOLVE_HOST:
return AVERROR(EHOSTUNREACH);
210 case CURLE_COULDNT_CONNECT:
return AVERROR(ECONNREFUSED);
211 case CURLE_OPERATION_TIMEDOUT:
return AVERROR(ETIMEDOUT);
212 case CURLE_LOGIN_DENIED:
213 case CURLE_REMOTE_ACCESS_DENIED:
return AVERROR(EACCES);
214 case CURLE_OUT_OF_MEMORY:
return AVERROR(ENOMEM);
215 case CURLE_PEER_FAILED_VERIFICATION:
223 if (
code == CURLE_OK)
234 case CURLM_OK:
return 0;
235 case CURLM_UNKNOWN_OPTION:
return AVERROR(EINVAL);
236 case CURLM_OUT_OF_MEMORY:
return AVERROR(ENOMEM);
244 case CURLM_OK:
return CURLE_OK;
245 case CURLM_UNKNOWN_OPTION:
return CURLE_UNKNOWN_OPTION;
246 case CURLM_OUT_OF_MEMORY:
return CURLE_OUT_OF_MEMORY;
247 case CURLM_ABORTED_BY_CALLBACK:
return CURLE_ABORTED_BY_CALLBACK;
248 case CURLM_UNRECOVERABLE_POLL:
return CURLE_UNRECOVERABLE_POLL;
249 default:
return CURLE_FAILED_INIT;
256 case CURLE_RECV_ERROR:
257 case CURLE_SEND_ERROR:
258 case CURLE_PARTIAL_FILE:
259 case CURLE_OPERATION_TIMEDOUT:
260 case CURLE_GOT_NOTHING:
261 case CURLE_COULDNT_CONNECT:
262 case CURLE_COULDNT_RESOLVE_HOST:
264 case CURLE_HTTP2_STREAM:
281 c->curl_status =
code;
287 size_t bytes =
size * nmemb;
292 if (
c->aborted || !
c->stream_ok) {
294 return CURL_WRITEFUNC_ERROR;
297 if (
c->seek_queued) {
303 if (bytes > INT64_MAX -
c->request_start -
c->request_received) {
305 "at offset %"PRId64
"\n",
c->request_start);
306 c->loop->num_errors++;
312 return CURL_WRITEFUNC_ERROR;
320 return CURL_WRITEFUNC_PAUSE;
325 c->request_received += bytes;
352 int64_t start = -1, end = -1, total = -1;
374 if (v[0] || (total < 0 && start < 0))
378 c->hdr_content_start = start;
379 c->hdr_content_end = end;
380 c->hdr_content_total = total;
397 if (v > (
max - d) / 10)
415 const char *colon = memchr(ptr,
':',
len);
416 const char *
val, *end = ptr +
len;
425 while (end >
val && (end[-1] ==
'\r' || end[-1] ==
'\n'))
456 c->icy_metadata_headers =
NULL;
463 if (start < 0 || start != c->request_start) {
465 "with offset %"PRId64
" (expected %"PRId64
")\n",
466 start,
c->request_start);
470 if (end >= 0 && end < start) {
472 "%"PRId64
"-%"PRId64
"\n", start, end);
477 if (
c->no_body && !total && end < 0)
480 if (total >= 0 && (start >= total || end >= total)) {
482 "%"PRId64
"-%"PRId64
" that exceeds the total size "
483 "%"PRId64
"\n", start, end, total);
487 if (
c->hdr_content_length >= 0 && end >= 0 &&
488 (
c->hdr_content_length - 1 > INT64_MAX - start ||
489 start + (
c->hdr_content_length - 1) != end))
492 "%"PRId64
"-%"PRId64
" that doesn't match the content length "
493 "%"PRId64
"\n", start, end,
c->hdr_content_length);
511 c->hdr_accept_ranges = 0;
512 c->hdr_compressed = 0;
513 c->hdr_content_start = -1;
514 c->hdr_content_end = -1;
515 c->hdr_content_total = -1;
516 c->hdr_content_length = -1;
517 c->hdr_icy_metaint = -1;
522 c->hdr_accept_ranges = !!
av_stristr(ptr + 14,
"bytes");
526 c->hdr_compressed = !
av_stristr(ptr + 17,
"identity");
554 while (n && (ptr[n - 1] ==
'\r' || ptr[n - 1] ==
'\n'))
559 curl_easy_getinfo(
c->easy, CURLINFO_RESPONSE_CODE, &status);
563 if (status < 200 || (status >= 300 && status < 400))
568 if (curl_easy_getinfo(
c->easy, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &cl) == CURLE_OK &&
570 c->hdr_content_length = cl;
573 if (status >= 200 && status < 300) {
574 int64_t content_start = status == 206 ?
c->hdr_content_start : 0;
575 int64_t content_end = status == 206 ?
c->hdr_content_end : -1;
576 int64_t content_total = status == 206 ?
c->hdr_content_total :
c->hdr_content_length;
580 if (content_end < 0 && content_total > 0)
581 content_end = content_total - 1;
584 c->loop->num_errors++;
592 keep_size = !
c->hdr_compressed ||
c->no_body;
595 if (keep_size && content_total >= 0)
596 c->content_size = content_total;
600 if (total < 0 && status != 206)
601 total =
c->hdr_content_length;
604 c->content_size = total;
606 content_end =
c->content_size > 0 ?
c->content_size - 1 : -1;
610 c->request_end = keep_size ? content_end : -1;
614 const char *eff =
NULL;
615 if (curl_easy_getinfo(
c->easy, CURLINFO_EFFECTIVE_URL, &eff) == CURLE_OK
629 c->seekable = !
c->hdr_compressed &&
630 (status == 206 ||
c->hdr_accept_ranges);
633 if (
c->seekable_opt >= 0)
634 c->seekable =
c->seekable_opt;
637 if (
c->hdr_icy_metaint > 0) {
638 c->icy_metaint =
c->hdr_icy_metaint;
639 if (
c->seekable_opt > 0)
641 "reply carries in-band ICY metadata\n");
647 c->content_size = -1;
649 }
else if (status == 416 &&
c->probed &&
c->content_size < 0 &&
650 (
c->hdr_content_total < 0 ||
651 c->hdr_content_total <=
c->request_start)) {
654 c->content_size =
c->hdr_content_total;
658 c->loop->num_errors++;
663 c->probe_ok =
c->stream_ok;
673 curl_off_t ultotal, curl_off_t ulnow)
678 aborted =
c->aborted;
688 const char *range_value =
NULL;
693 if (
c->probed &&
c->seekable &&
694 ((
c->content_size >= 0 &&
c->request_start >=
c->content_size) ||
695 (
c->end_off > 0 &&
c->request_start >=
c->end_off))) {
703 if (!
c->no_body && (!
c->probed ||
c->seekable)) {
706 if (
c->is_initial &&
c->initial_request_size > 0)
712 if (
c->content_size > 0)
713 end =
FFMIN(end,
c->content_size - 1);
715 end =
FFMIN(end,
c->end_off - 1);
716 snprintf(
range,
sizeof(
range),
"%"PRId64
"-%"PRId64, start, end);
718 snprintf(
range,
sizeof(
range),
"%"PRId64
"-", start);
722 cc = curl_easy_setopt(
c->easy, CURLOPT_RANGE, range_value);
724 c->loop->num_errors++;
731 c->loop->num_requests++;
732 c->request_received = 0;
735 CURLMcode res = curl_multi_add_handle(
c->loop->multi,
c->easy);
736 if (res != CURLM_OK) {
738 curl_multi_strerror(res));
752 curl_off_t recv = 0, time = 0;
753 curl_easy_getinfo(e, CURLINFO_SIZE_DOWNLOAD_T, &recv);
754 curl_easy_getinfo(e, CURLINFO_TOTAL_TIME_T, &time);
760 loop->total_bytes += recv;
761 loop->total_time_us += time;
764 long num_conns = 0, num_redirs = 0;
765 curl_easy_getinfo(e, CURLINFO_NUM_CONNECTS, &num_conns);
766 curl_easy_getinfo(e, CURLINFO_REDIRECT_COUNT, &num_redirs);
767 loop->num_connections += (int) num_conns;
768 loop->num_redirects += (int) num_redirs;
778 aborted =
c->aborted;
779 received =
c->request_received;
781 if (received > INT64_MAX -
c->request_start) {
787 c->request_start += received;
788 c->request_received = 0;
797 c->loop->num_errors++;
812 if (
code == CURLE_OK &&
c->stream_ok) {
814 c->curl_status = CURLE_OK;
815 }
else if (!
c->status) {
816 c->loop->num_errors++;
825 if (
c->seek_queued) {
832 if (
code == CURLE_OK &&
c->stream_ok) {
833 int64_t file_end =
c->content_size >= 0 ?
c->content_size - 1 : INT64_MAX;
835 file_end =
FFMIN(file_end,
c->end_off - 1);
836 if (
c->seekable &&
c->request_end >= 0 &&
c->request_end < file_end) {
839 "%"PRId64
"\n",
c->request_start);
840 c->loop->num_errors++;
853 c->curl_status = CURLE_OK;
861 c->loop->num_errors++;
880 if (
c->short_seek_size <= 0 ||
884 const int64_t last =
c->request_end -
c->request_start;
885 return last -
c->request_received <
c->short_seek_size;
898 curl_multi_remove_handle(
loop->multi,
c->easy);
907 curl_easy_pause(
c->easy, CURLPAUSE_CONT);
912 }
else if (
c->active) {
913 curl_multi_remove_handle(
loop->multi,
c->easy);
918 const int was_paused =
c->paused;
924 c->request_start = cmd->pos;
925 c->request_received = 0;
929 curl_easy_pause(
c->easy, CURLPAUSE_CONT);
946 cmd =
loop->cmd_head;
948 loop->cmd_head = cmd->next;
971 curl_multi_perform(
loop->multi, &running);
973 while ((msg = curl_multi_info_read(
loop->multi, &
left))) {
975 if (msg->msg != CURLMSG_DONE)
977 curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &
c);
978 curl_multi_remove_handle(
loop->multi, msg->easy_handle);
1009 loop->cmd_tail->next = cmd;
1011 loop->cmd_head = cmd;
1012 loop->cmd_tail = cmd;
1013 curl_multi_wakeup(
loop->multi);
1024 curl_lock_access access,
void *userdata)
1052 if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
1055 loop->multi = curl_multi_init();
1058 if (curl_multi_setopt(
loop->multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX) != CURLM_OK)
1061 loop->share = curl_share_init();
1064 if (curl_share_setopt(
loop->share, CURLSHOPT_USERDATA,
loop) != CURLSHE_OK ||
1068 res = curl_share_setopt(
loop->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
1069 if (res != CURLSHE_OK && res != CURLSHE_NOT_BUILT_IN)
1071 loop->has_cookies = res == CURLSHE_OK;
1072 res = curl_share_setopt(
loop->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS);
1073 if (res != CURLSHE_OK && res != CURLSHE_NOT_BUILT_IN)
1082 curl_multi_cleanup(
loop->multi);
1083 curl_share_cleanup(
loop->share);
1084 curl_global_cleanup();
1097 if (
loop->total_bytes) {
1098 double time =
loop->total_time_us / 1000000.0;
1099 double avg = time ?
loop->total_bytes / time : 0;
1101 "libcurl: Overall %"PRId64
" bytes received in %.0f ms = %.0f kB/s\n",
1102 loop->total_bytes, time * 1e3,
avg / 1e3);
1105 if (
loop->num_connections ||
loop->num_errors) {
1107 "libcurl: %d connections, %d redirects, %d requests, %d errors\n",
1108 loop->num_connections,
loop->num_redirects,
loop->num_requests,
1117 curl_multi_wakeup(
loop->multi);
1123 curl_multi_cleanup(
loop->multi);
1124 curl_share_cleanup(
loop->share);
1130 curl_global_cleanup();
1141 c->private_loop = 1;
1142 return c->loop ? 0 :
AVERROR(ENOMEM);
1153 return c->loop ? 0 :
AVERROR(ENOMEM);
1171 size_t size,
void *userdata)
1177 case CURLINFO_TEXT:
prefix =
"* ";
break;
1178 case CURLINFO_HEADER_IN:
prefix =
"< ";
break;
1179 case CURLINFO_HEADER_OUT:
prefix =
"> ";
break;
1185 const char *nl = memchr(p,
'\n', end - p);
1186 size_t len = (nl ? nl : end) - p;
1187 while (
len && p[
len - 1] ==
'\r')
1199 struct curl_slist *
tmp = curl_slist_append(*
list, str);
1209 int user_set_icy = 0,
ret = 0;
1211 if (
c->referer &&
c->referer[0]) {
1220 if (
c->headers &&
c->headers[0]) {
1237 if (
c->icy && !user_set_icy)
1244 const char *wl =
c->h->protocol_whitelist;
1245 const char *bl =
c->h->protocol_blacklist;
1253 curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
1254 for (
const char *
const *p = info->protocols; *p; p++) {
1255 const char *proto = *p;
1279 curl_easy_setopt(
c->easy, CURLOPT_PROTOCOLS_STR, bp.str));
1282 curl_easy_setopt(
c->easy, CURLOPT_REDIR_PROTOCOLS_STR, bp.str));
1290 unsigned flags = curl_version_info(CURLVERSION_NOW)->features & CURL_VERSION_IDN ? CURLU_PUNYCODE : 0;
1291 CURLU *
u = curl_url();
1292 char *curl_host =
NULL;
1298 uc = curl_url_set(
u, CURLUPART_URL, url, 0);
1299 if (uc == CURLUE_OK)
1300 uc = curl_url_get(
u, CURLUPART_HOST, &curl_host,
flags);
1301 if (uc == CURLUE_OK) {
1302 size_t len = strlen(curl_host);
1303 int brackets =
len >= 2 && curl_host[0] ==
'[' && curl_host[
len - 1] ==
']';
1304 len -= 2 * brackets;
1310 curl_free(curl_host);
1311 curl_url_cleanup(
u);
1333 if (host_only && !domain)
1334 domain = host_only->
value;
1337 if (!domain || strchr(
".#", *domain) ||
av_stristart(domain,
"Set-Cookie:",
NULL) ||
1338 strchr(pair->
key,
'\t') || strchr(pair->
value,
'\t') || strchr(domain,
'\t') ||
1339 (
path && strchr(
path->value,
'\t')))
1353#define CURL_SETOPT(opt, val) \
1355 int ret_ = curl_setopt_checked(c, #opt, \
1356 curl_easy_setopt(e, opt, val)); \
1363 const curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
1367 const char *url =
c->h->filename;
1393 CURL_SETOPT(CURLOPT_MAXREDIRS, (
long)
c->max_redirects);
1394 CURL_SETOPT(CURLOPT_HTTP_VERSION, (
long)
c->http_version);
1395 CURL_SETOPT(CURLOPT_TCP_KEEPALIVE,
c->multiple_requests ? 1L : 0
L);
1396 CURL_SETOPT(CURLOPT_FORBID_REUSE,
c->multiple_requests ? 0
L : 1L);
1397 if (info->features & CURL_VERSION_HSTS)
1398 CURL_SETOPT(CURLOPT_HSTS_CTRL, (
long)CURLHSTS_ENABLE);
1400 c->off > 0 ||
c->end_off > 0 ?
"identity" :
"");
1401 if (
c->connect_timeout > 0)
1403 (
long)
c->connect_timeout * 1000);
1405 if (
c->user_agent &&
c->user_agent[0])
1407 if (
c->method &&
c->method[0]) {
1408 if (!strcmp(
c->method,
"HEAD")) {
1418 if (
c->http_proxy &&
c->http_proxy[0])
1421 if (info->features & CURL_VERSION_SSL)
1422 CURL_SETOPT(CURLOPT_SSL_OPTIONS, (
long)CURLSSLOPT_NATIVE_CA);
1423 CURL_SETOPT(CURLOPT_SSL_VERIFYPEER,
c->tls_verify ? 1L : 0
L);
1424 CURL_SETOPT(CURLOPT_SSL_VERIFYHOST,
c->tls_verify ? 2L : 0
L);
1432 if (
c->loop->has_cookies) {
1434 }
else if (
c->cookies &&
c->cookies[0]) {
1438 if (
c->cookies &&
c->cookies[0]) {
1457 cc = curl_easy_setopt(e, CURLOPT_COOKIELIST, sc);
1474 if (
c->icy_status) {
1488 struct timespec ts = { .tv_sec = t / 1000000,
1489 .tv_nsec = (t % 1000000) * 1000 };
1501 while (!
c->probed && !
c->status) {
1530 const int status =
c->status;
1531 const CURLcode
code =
c->curl_status;
1534 if (!
c->retry_time) {
1535 if (
c->retry_count >=
c->max_retries) {
1546 "after: %s (%s)\n",
c->retry_count,
c->logical_pos,
1548 curl_easy_strerror(
code));
1552 if (sleep_us > 0 && !nonblock) {
1554 }
else if (sleep_us <= 0) {
1575 curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
1576 if (!(info->features & CURL_VERSION_THREADSAFE))
1580 const char *eff_url =
h->filename;
1584 c->content_size = -1;
1585 c->request_start =
c->off;
1586 c->request_end = -1;
1587 c->logical_pos =
c->off;
1589 c->icy_block_len = -1;
1615 c->easy = curl_easy_init();
1638 h->is_streamed = !
c->seekable;
1652 c->icy_metadata_packet =
av_strdup((
char *)
c->icy_block);
1653 if (!
c->icy_metadata_packet)
1669 if (
c->icy_block_len < 0) {
1672 c->icy_block_len = units * 16;
1673 c->icy_block_filled = 0;
1675 if (!
c->icy_block_len) {
1676 c->icy_block_len = -1;
1677 c->icy_data_read = 0;
1683 n =
FFMIN(avail, (
size_t)(
c->icy_block_len -
c->icy_block_filled));
1685 c->icy_block_filled += n;
1686 if (
c->icy_block_filled <
c->icy_block_len)
1689 c->icy_block[
c->icy_block_len] = 0;
1690 c->icy_block_len = -1;
1691 c->icy_data_read = 0;
1709 if (
c->icy_metaint > 0 &&
c->icy_data_read ==
c->icy_metaint &&
1714 if (
c->icy_metaint > 0)
1715 avail =
FFMIN(avail, (
size_t)(
c->icy_metaint -
c->icy_data_read));
1720 c->icy_data_read +=
ret;
1721 c->logical_pos +=
ret;
1732 "Stream ended inside an ICY metadata block\n");
1761 const int64_t content_size =
c->content_size;
1762 const int seekable =
c->seekable;
1766 return content_size >= 0 ? content_size :
AVERROR(ENOSYS);
1776 if (
pos > INT64_MAX -
c->logical_pos)
1778 newpos =
c->logical_pos +
pos;
1781 if (content_size < 0)
1783 if (
pos > INT64_MAX - content_size)
1785 newpos = content_size +
pos;
1793 if (newpos ==
c->logical_pos)
1799 c->logical_pos = newpos;
1814 curl_easy_cleanup(
c->easy);
1818 if (
c->private_loop)
1824 curl_slist_free_all(
c->header_list);
1826 curl_slist_free_all(
c->alias_list);
1838 if (
c->short_seek_size >= 1)
1839 return FFMIN(
c->short_seek_size, INT_MAX);
1843#define OFFSET(x) offsetof(CurlContext, x)
1844#define D AV_OPT_FLAG_DECODING_PARAM
1845#define E AV_OPT_FLAG_ENCODING_PARAM
1850 {
"headers",
"set custom HTTP headers, can override built in default headers",
OFFSET(headers),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D |
E },
1852 {
"cookies",
"set cookies to be sent in applicable future requests, use newline delimited Set-Cookie HTTP field value syntax",
OFFSET(
cookies),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D },
1855 {
"end_offset",
"try to limit the request to bytes preceding this offset",
OFFSET(end_off),
AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX,
D },
1856 {
"seekable",
"control seekability of connection",
OFFSET(seekable_opt),
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
D },
1857 {
"tls_verify",
"verify the peer certificate and hostname",
OFFSET(tls_verify),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
D |
E },
1861 {
"connect_timeout",
"connection timeout in seconds (0 = libcurl default)",
OFFSET(connect_timeout),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX / 1000,
D |
E },
1862 {
"max_redirects",
"maximum number of redirects to follow",
OFFSET(max_redirects),
AV_OPT_TYPE_INT, { .i64 = 16 }, 0, INT_MAX,
D },
1863 {
"multiple_requests",
"reuse the connection across requests (HTTP keep-alive)",
OFFSET(multiple_requests),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
D |
E },
1864 {
"max_retries",
"maximum number of retries after a recoverable error",
OFFSET(max_retries),
AV_OPT_TYPE_INT, { .i64 = 5 }, 0, INT_MAX,
D },
1866 {
"icy_status",
"accept legacy Shoutcast \"ICY 200 OK\" status lines",
OFFSET(icy_status),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
D },
1871 {
"request_size",
"split a transfer into ranged requests of at most this many bytes (0 = unlimited)",
OFFSET(
request_size),
AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX,
D },
1872 {
"initial_request_size",
"size (in bytes) of initial requests made during probing / header parsing",
OFFSET(initial_request_size),
AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX,
D },
1873 {
"http_version",
"HTTP version to use",
OFFSET(http_version),
AV_OPT_TYPE_INT, { .i64 = CURL_HTTP_VERSION_NONE }, 0, INT_MAX,
D, .unit =
"http_version" },
1874 {
"auto",
"negotiate the best supported version", 0,
AV_OPT_TYPE_CONST, { .i64 = CURL_HTTP_VERSION_NONE }, 0, 0,
D, .unit =
"http_version" },
1875 {
"1.0",
"HTTP/1.0", 0,
AV_OPT_TYPE_CONST, { .i64 = CURL_HTTP_VERSION_1_0 }, 0, 0,
D, .unit =
"http_version" },
1876 {
"1.1",
"HTTP/1.1", 0,
AV_OPT_TYPE_CONST, { .i64 = CURL_HTTP_VERSION_1_1 }, 0, 0,
D, .unit =
"http_version" },
1877 {
"2",
"HTTP/2", 0,
AV_OPT_TYPE_CONST, { .i64 = CURL_HTTP_VERSION_2 }, 0, 0,
D, .unit =
"http_version" },
1878 {
"2tls",
"HTTP/2 over TLS only", 0,
AV_OPT_TYPE_CONST, { .i64 = CURL_HTTP_VERSION_2TLS }, 0, 0,
D, .unit =
"http_version" },
1879 {
"2-prior-knowledge",
"HTTP/2 without an upgrade handshake", 0,
AV_OPT_TYPE_CONST, { .i64 = CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE }, 0, 0,
D, .unit =
"http_version" },
1880 {
"3",
"HTTP/3, fall back to earlier versions", 0,
AV_OPT_TYPE_CONST, { .i64 = CURL_HTTP_VERSION_3 }, 0, 0,
D, .unit =
"http_version" },
1881 {
"3only",
"HTTP/3 only", 0,
AV_OPT_TYPE_CONST, { .i64 = CURL_HTTP_VERSION_3ONLY }, 0, 0,
D, .unit =
"http_version" },
1882 {
"short_seek_size",
"threshold to favor readahead over seek",
OFFSET(short_seek_size),
AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX,
D },
1887 .class_name =
"libcurl",
1903 .default_whitelist =
"http,https,libcurl",
static double val(void *priv, double ch)
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
char * av_asprintf(const char *fmt,...)
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_AUTOMATIC
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static void do_exit(VideoState *is)
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
void av_fifo_reset2(AVFifo *f)
size_t av_fifo_can_write(const AVFifo *f)
size_t av_fifo_can_read(const AVFifo *f)
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_log_get_level(void)
Get the current log level.
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
int av_stristart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str independent of case.
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
#define LIBAVUTIL_VERSION_INT
static uint64_t request_size(URLContext *h)
#define DEFAULT_USER_AGENT
static void ff_http_parse_icy_packet(void *logctx, AVDictionary **metadata, char *data)
Split an in-band ICY metadata packet into its "Key='Value';" pairs.
const char * ff_http_cookie_domain(const AVDictionary *cookie_params)
int ff_http_host_is_ip_literal(const char *host)
static int ff_http_averror(int status_code, int default_averror)
int64_t ff_http_cookie_expiry(const AVDictionary *attributes)
int ff_http_parse_set_cookie(const char *set_cookie, AVDictionary **cookie, AVDictionary **attributes)
Parse a Set-Cookie style line.
int ff_http_bind_cookies_to_host(char **cookies, const char *host)
Restrict the cookies without a Domain to host.
#define u(width, name, range_min, range_max)
static const int factor[16]
#define AV_MUTEX_INITIALIZER
static int ff_thread_setname(const char *name)
#define CURL_DEFAULT_BUFFER_SIZE
static int setup_protocols(CurlContext *c)
static int curl_setopt_checked(CurlContext *c, const char *name, CURLcode code)
const URLProtocol ff_libcurl_protocol
#define CURL_RETRY_MAX_US
static void execute_command(CurlLoop *loop, CurlCmd *cmd)
static void share_unlock_callback(CURL *handle, curl_lock_data data, void *userdata)
static int curl_loop_attach(CurlContext *c, AVFormatContext *avfc)
static int curlmcode_to_curlcode(CURLMcode code)
static void print_statistics(CurlLoop *loop)
static int wait_for_probe(CurlContext *c)
static int curlmcode_to_averror(CURLMcode code)
static int slist_append(struct curl_slist **list, const char *str)
static void share_lock_callback(CURL *handle, curl_lock_data data, curl_lock_access access, void *userdata)
static void update_statistics(CurlContext *c)
static int is_recoverable(CURLcode code)
static void start_request(CurlContext *c)
static int verify_content_range(CurlContext *c, int64_t start, int64_t end, int64_t total)
static int drain_icy_block(CurlContext *c)
#define CURL_RETRY_BASE_US
static int cookie_list_line(char **line, const char *cookie)
static const AVClass libcurl_context_class
static int xferinfo_callback(void *userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
#define CURL_SETOPT(opt, val)
static int debug_callback(CURL *easy, curl_infotype type, char *data, size_t size, void *userdata)
static int libcurl_open(URLContext *h, const char *url, int flags, AVDictionary **options)
static int64_t retry_delay(CurlContext *c)
static void curl_loop_destroy(CurlLoop *loop)
static void curl_cond_wait(CurlContext *c)
static void update_status_locked(CurlContext *c, int status, CURLcode code)
static int parse_offset(const char *str, int64_t *out, const char **ptr)
static int libcurl_close(URLContext *h)
static void store_icy_header(AVDictionary **dict, const char *ptr, size_t len)
void ff_curl_loop_free(struct CurlLoop **loop)
Release a libcurl event loop and set *loop to NULL.
static int curl_url_host(char *host, size_t host_size, const char *url)
static AVMutex curl_loop_lock
static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
static void parse_content_range(CurlContext *c, const char *v)
static void on_done(CurlContext *c, CURLcode code)
static void commit_icy_headers(CurlContext *c)
static int retry_request_locked(URLContext *h, int nonblock)
static int test_short_seek(CurlContext *c)
static int libcurl_get_short_seek(URLContext *h)
static int build_headers(CurlContext *c)
static CurlLoop * curl_loop_create(AVFormatContext *avfc)
static int64_t parse_header_uint(const char *p, size_t len, int64_t max)
static size_t header_callback(char *ptr, size_t size, size_t nitems, void *userdata)
static void * curl_worker(void *arg)
static int libcurl_read(URLContext *h, unsigned char *buf, int size)
static int64_t libcurl_seek(URLContext *h, int64_t pos, int whence)
static int update_icy_metadata(CurlContext *c)
static int curl_dispatch(CurlLoop *loop, enum cmd_kind kind, CurlContext *c, int64_t pos, int sync)
static int setup_curl(CurlContext *c)
static int curlcode_to_averror(CURLcode code)
Utility Preprocessor macros.
Memory handling functions.
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
static av_always_inline int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
Describe the class of an AVClass context structure.
char * icy_metadata_headers
struct curl_slist * header_list
int64_t initial_request_size
uint8_t icy_block[ICY_MAX_BLOCK+1]
char * icy_metadata_packet
int64_t hdr_content_total
int64_t hdr_content_start
struct curl_slist * alias_list
int64_t hdr_content_length
struct CurlLoop * curl_loop
Shared libcurl event loop, created on demand on the first use.
static const char *const cookies[]
int av_usleep(unsigned usec)
Sleep for a period of time.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
int64_t av_gettime(void)
Get the current time in microseconds.
unbuffered private I/O API
#define URL_PROTOCOL_FLAG_NETWORK
static void copy(const float *p1, float *p2, const int length)