22#include <libxml/parser.h>
36#define INITIAL_BUFFER_SIZE 32768
37#define MAX_TIMELINE_SEGMENTS (1 << 24)
182 if (
len > INT_MAX - 0x3F - *url_size)
208 ret = sscanf(datetime,
"%d-%d-%dT%d:%d:%fZ", &year, &month, &day, &hour, &minute, &second);
213 timeinfo.tm_year = year - 1900;
214 timeinfo.tm_mon = month - 1;
215 timeinfo.tm_mday = day;
216 timeinfo.tm_hour = hour;
217 timeinfo.tm_min = minute;
218 timeinfo.tm_sec = (int)second;
236 if (*ptr ==
'P' || *ptr ==
'T') {
247 days = (uint32_t)
value;
250 hours = (uint32_t)
value;
253 mins = (uint32_t)
value;
256 secs = (uint32_t)
value;
264 return ((days * 24 + hours) * 60 + mins) * 60 + secs;
280 if (
num == cur_seq_no)
292 if (
num == cur_seq_no)
390 for (
i = 0;
i <
c->n_videos;
i++) {
401 for (
i = 0;
i <
c->n_audios;
i++) {
412 for (
i = 0;
i <
c->n_subtitles;
i++) {
425 const char *proto_name =
NULL;
430 if (url[6] ==
'+' || url[6] ==
':')
440 proto_name_len = strlen(proto_name);
443 if (strcmp(
c->allowed_extensions,
"ALL") && !
av_match_ext(url,
c->allowed_extensions)) {
445 "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n"
446 "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",
455 if (!strncmp(proto_name, url, proto_name_len) && url[proto_name_len] ==
':')
457 else if (
av_strstart(url,
"crypto",
NULL) && !strncmp(proto_name, url + 7, proto_name_len) && url[7 + proto_name_len] ==
':')
459 else if (strcmp(proto_name,
"file") || !strncmp(url,
"file,", 5))
468 char *new_cookies =
NULL;
491 char *rep_bandwidth_val,
502 for (
i = 0;
i < n_baseurl_nodes; ++
i) {
503 if (baseurl_nodes[
i] &&
504 baseurl_nodes[
i]->children &&
505 baseurl_nodes[
i]->children->type == XML_TEXT_NODE) {
506 text = xmlNodeGetContent(baseurl_nodes[
i]->children);
508 memset(tmp_str, 0, max_url_size);
525 if (rep_bandwidth_val && tmp_str[0] !=
'\0') {
543 for (
i = 0;
i < n_nodes; ++
i) {
545 val = xmlGetProp(nodes[
i], attrname);
556 xmlNodePtr node = rootnode;
561 node = xmlFirstElementChild(node);
566 node = xmlNextElementSibling(node);
579 for (
i = 0;
i < 2;
i++) {
580 attr =
i ?
"mimeType" :
"contentType";
581 val = xmlGetProp(node, attr);
606 char *str_end_offset;
608 if (!str_offset || !str_end_offset) {
621 xmlNodePtr fragmenturl_node,
622 xmlNodePtr *baseurl_nodes,
624 char *rep_bandwidth_val)
627 char *initialization_val =
NULL;
628 char *media_val =
NULL;
629 char *range_val =
NULL;
633 if (!
av_strcasecmp(fragmenturl_node->name,
"Initialization")) {
634 initialization_val = xmlGetProp(fragmenturl_node,
"sourceURL");
635 range_val = xmlGetProp(fragmenturl_node,
"range");
636 if (initialization_val || range_val) {
641 xmlFree(initialization_val);
649 xmlFree(initialization_val);
655 }
else if (!
av_strcasecmp(fragmenturl_node->name,
"SegmentURL")) {
656 media_val = xmlGetProp(fragmenturl_node,
"media");
657 range_val = xmlGetProp(fragmenturl_node,
"mediaRange");
658 if (media_val || range_val) {
687 xmlNodePtr fragment_timeline_node)
689 xmlAttrPtr attr =
NULL;
698 attr = fragment_timeline_node->properties;
700 val = xmlGetProp(fragment_timeline_node, attr->name);
729 char *tmp_str =
NULL;
731 xmlNodePtr node =
NULL;
732 char *baseurl =
NULL;
733 char *root_url =
NULL;
743 int tmp_max_url_size = 0;
744 uint64_t url_len = strlen(url);
746 for (
i = n_baseurl_nodes-1;
i >= 0 ;
i--) {
747 text = xmlNodeGetContent(baseurl_nodes[
i]);
750 url_len += strlen(text);
763 if (!tmp_str || !
path) {
769 const char *colon = strchr(url,
':');
770 if (colon && colon[1] ==
'/' && colon[2] ==
'/') {
776 for (rootId = n_baseurl_nodes - 1; rootId > 0; rootId --) {
777 if (!(node = baseurl_nodes[rootId])) {
780 text = xmlNodeGetContent(node);
792 node = baseurl_nodes[rootId];
793 baseurl = xmlNodeGetContent(node);
795 tmp = xmlRealloc(baseurl, xmlStrlen(baseurl) + 2);
803 xmlChar *escaped = xmlEncodeSpecialChars(
NULL, root_url);
808 xmlNodeSetContent(node, escaped);
813 size = strlen(root_url);
814 isRootHttp =
ishttp(root_url);
816 if (
size > 0 && root_url[
size - 1] != token) {
820 for (
i = 0;
i < n_baseurl_nodes; ++
i) {
824 text = xmlNodeGetContent(baseurl_nodes[
i]);
826 memset(tmp_str, 0, strlen(tmp_str));
827 if (!
ishttp(text) && isRootHttp) {
828 av_strlcpy(tmp_str, root_url, tmp_max_url_size + 2);
830 start = (text[0] == token);
839 memset(p + 1, 0, strlen(p));
841 av_strlcat(tmp_str, text + start, tmp_max_url_size + 2);
843 xmlChar* escaped = xmlEncodeSpecialChars(
NULL, tmp_str);
848 xmlNodeSetContent(baseurl_nodes[
i], escaped);
857 if (tmp_max_url_size > *max_url_size) {
858 *max_url_size = tmp_max_url_size;
867#define SET_REPRESENTATION_SEQUENCE_BASE_INFO(arg, cnt) { \
868 val = get_val_from_nodes_tab((arg), (cnt), "duration"); \
870 int64_t fragment_duration = (int64_t) strtoll(val, NULL, 10); \
871 if (fragment_duration < 0) { \
872 av_log(s, AV_LOG_WARNING, "duration invalid, autochanged to 0.\n"); \
873 fragment_duration = 0; \
875 rep->fragment_duration = fragment_duration; \
876 av_log(s, AV_LOG_TRACE, "rep->fragment_duration = [%"PRId64"]\n", rep->fragment_duration); \
879 val = get_val_from_nodes_tab((arg), (cnt), "timescale"); \
881 int64_t fragment_timescale = (int64_t) strtoll(val, NULL, 10); \
882 if (fragment_timescale < 0) { \
883 av_log(s, AV_LOG_WARNING, "timescale invalid, autochanged to 0.\n"); \
884 fragment_timescale = 0; \
886 rep->fragment_timescale = fragment_timescale; \
887 av_log(s, AV_LOG_TRACE, "rep->fragment_timescale = [%"PRId64"]\n", rep->fragment_timescale); \
890 val = get_val_from_nodes_tab((arg), (cnt), "startNumber"); \
892 int64_t start_number = (int64_t) strtoll(val, NULL, 10); \
893 if (start_number < 0) { \
894 av_log(s, AV_LOG_WARNING, "startNumber invalid, autochanged to 0.\n"); \
897 rep->start_number = rep->first_seq_no = start_number; \
898 av_log(s, AV_LOG_TRACE, "rep->first_seq_no = [%"PRId64"]\n", rep->first_seq_no); \
906 xmlNodePtr adaptionset_node,
907 xmlNodePtr mpd_baseurl_node,
908 xmlNodePtr period_baseurl_node,
909 xmlNodePtr period_segmenttemplate_node,
910 xmlNodePtr period_segmentlist_node,
911 xmlNodePtr fragment_template_node,
912 xmlNodePtr content_component_node,
913 xmlNodePtr adaptionset_baseurl_node,
914 xmlNodePtr adaptionset_segmentlist_node,
915 xmlNodePtr adaptionset_supplementalproperty_node)
921 xmlNodePtr representation_segmenttemplate_node =
NULL;
922 xmlNodePtr representation_baseurl_node =
NULL;
923 xmlNodePtr representation_segmentlist_node =
NULL;
924 xmlNodePtr segmentlists_tab[3];
925 xmlNodePtr fragment_timeline_node =
NULL;
926 xmlNodePtr fragment_templates_tab[5];
928 xmlNodePtr baseurl_nodes[4];
929 xmlNodePtr representation_node = node;
930 char *rep_bandwidth_val;
931 char *rep_codecs_val;
932 char *rep_dependencyid_val;
954 if (
c->adaptionset_lang) {
966 rep_bandwidth_val = xmlGetProp(representation_node,
"bandwidth");
967 rep_dependencyid_val = xmlGetProp(representation_node,
"dependencyId");
968 rep_codecs_val = xmlGetProp(representation_node,
"codecs");
970 rep_codecs_val = xmlGetProp(adaptionset_node,
"codecs");
971 val = xmlGetProp(representation_node,
"id");
979 baseurl_nodes[0] = mpd_baseurl_node;
980 baseurl_nodes[1] = period_baseurl_node;
981 baseurl_nodes[2] = adaptionset_baseurl_node;
982 baseurl_nodes[3] = representation_baseurl_node;
988 (rep->
id ? strlen(rep->
id) : 0) +
989 (rep_bandwidth_val ? strlen(rep_bandwidth_val) : 0));
992 if (representation_segmenttemplate_node || fragment_template_node || period_segmenttemplate_node) {
993 fragment_timeline_node =
NULL;
994 fragment_templates_tab[0] = representation_segmenttemplate_node;
995 fragment_templates_tab[1] = adaptionset_segmentlist_node;
996 fragment_templates_tab[2] = fragment_template_node;
997 fragment_templates_tab[3] = period_segmenttemplate_node;
998 fragment_templates_tab[4] = period_segmentlist_node;
1013 c->max_url_size, rep->
id,
1014 rep_bandwidth_val,
val);
1028 c->max_url_size, rep->
id,
1029 rep_bandwidth_val,
val);
1035 if (presentation_timeoffset < 0) {
1037 presentation_timeoffset = 0;
1045 if (adaptionset_supplementalproperty_node) {
1046 char *scheme_id_uri = xmlGetProp(adaptionset_supplementalproperty_node,
"schemeIdUri");
1047 if (scheme_id_uri) {
1048 int is_last_segment_number = !
av_strcasecmp(scheme_id_uri,
"http://dashif.org/guidelines/last-segment-number");
1049 xmlFree(scheme_id_uri);
1050 if (is_last_segment_number) {
1051 val = xmlGetProp(adaptionset_supplementalproperty_node,
"value");
1053 av_log(
s,
AV_LOG_ERROR,
"Missing value attribute in adaptionset_supplementalproperty_node\n");
1064 if (!fragment_timeline_node)
1066 if (!fragment_timeline_node)
1068 if (!fragment_timeline_node)
1070 if (fragment_timeline_node) {
1071 fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node);
1072 while (fragment_timeline_node) {
1076 fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node);
1079 }
else if (representation_baseurl_node && !representation_segmentlist_node) {
1089 rep->
id, rep_bandwidth_val,
NULL);
1093 }
else if (representation_segmentlist_node) {
1096 xmlNodePtr fragmenturl_node =
NULL;
1097 segmentlists_tab[0] = representation_segmentlist_node;
1098 segmentlists_tab[1] = adaptionset_segmentlist_node;
1099 segmentlists_tab[2] = period_segmentlist_node;
1102 fragmenturl_node = xmlFirstElementChild(representation_segmentlist_node);
1103 while (fragmenturl_node) {
1105 baseurl_nodes, rep->
id,
1109 fragmenturl_node = xmlNextElementSibling(fragmenturl_node);
1113 if (!fragment_timeline_node)
1115 if (fragment_timeline_node) {
1116 fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node);
1117 while (fragment_timeline_node) {
1121 fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node);
1126 rep->
id ? rep->
id :
"");
1130 int64_t nb_timeline_segments = 0;
1142 rep->
bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0;
1143 if (rep_dependencyid_val) {
1146 xmlFree(rep_dependencyid_val);
1150 if (rep_codecs_val) {
1153 xmlFree(rep_codecs_val);
1159 char *rep_framerate_val = xmlGetProp(representation_node,
"frameRate");
1160 if (rep_framerate_val) {
1164 xmlFree(rep_framerate_val);
1184 if (rep_bandwidth_val)
1185 xmlFree(rep_bandwidth_val);
1186 if (rep_dependencyid_val)
1187 xmlFree(rep_dependencyid_val);
1189 xmlFree(rep_codecs_val);
1203 if (!adaptionset_node) {
1207 c->adaptionset_lang = xmlGetProp(adaptionset_node,
"lang");
1213 xmlNodePtr adaptionset_node,
1214 xmlNodePtr mpd_baseurl_node,
1215 xmlNodePtr period_baseurl_node,
1216 xmlNodePtr period_segmenttemplate_node,
1217 xmlNodePtr period_segmentlist_node)
1221 xmlNodePtr fragment_template_node =
NULL;
1222 xmlNodePtr content_component_node =
NULL;
1223 xmlNodePtr adaptionset_baseurl_node =
NULL;
1224 xmlNodePtr adaptionset_segmentlist_node =
NULL;
1225 xmlNodePtr adaptionset_supplementalproperty_node =
NULL;
1226 xmlNodePtr node =
NULL;
1232 node = xmlFirstElementChild(adaptionset_node);
1235 fragment_template_node = node;
1236 }
else if (!
av_strcasecmp(node->name,
"ContentComponent")) {
1237 content_component_node = node;
1239 adaptionset_baseurl_node = node;
1241 adaptionset_segmentlist_node = node;
1242 }
else if (!
av_strcasecmp(node->name,
"SupplementalProperty")) {
1243 adaptionset_supplementalproperty_node = node;
1248 period_baseurl_node,
1249 period_segmenttemplate_node,
1250 period_segmentlist_node,
1251 fragment_template_node,
1252 content_component_node,
1253 adaptionset_baseurl_node,
1254 adaptionset_segmentlist_node,
1255 adaptionset_supplementalproperty_node);
1259 node = xmlNextElementSibling(node);
1263 xmlFree(
c->adaptionset_lang);
1264 c->adaptionset_lang =
NULL;
1272 node = xmlFirstElementChild(node);
1275 val = xmlNodeGetContent(node);
1280 val = xmlNodeGetContent(node);
1285 val = xmlNodeGetContent(node);
1290 node = xmlNextElementSibling(node);
1305 xmlNodePtr root_element =
NULL;
1306 xmlNodePtr node =
NULL;
1307 xmlNodePtr period_node =
NULL;
1308 xmlNodePtr tmp_node =
NULL;
1309 xmlNodePtr mpd_baseurl_node =
NULL;
1310 xmlNodePtr period_baseurl_node =
NULL;
1311 xmlNodePtr period_segmenttemplate_node =
NULL;
1312 xmlNodePtr period_segmentlist_node =
NULL;
1313 xmlNodePtr adaptionset_node =
NULL;
1314 xmlAttrPtr attr =
NULL;
1316 uint32_t period_duration_sec = 0;
1317 uint32_t period_start_sec = 0;
1348 doc = xmlReadMemory(buf.str, buf.len,
c->base_url,
NULL, 0);
1349 root_element = xmlDocGetRootElement(doc);
1350 node = root_element;
1358 if (node->type != XML_ELEMENT_NODE ||
1361 av_log(
s,
AV_LOG_ERROR,
"Unable to parse '%s' - wrong root node name[%s] type[%d]\n",
url, node->name, (
int)node->type);
1365 val = xmlGetProp(node,
"type");
1375 c->minimum_update_period = -1;
1377 attr = node->properties;
1379 val = xmlGetProp(node, attr->name);
1387 av_log(
s,
AV_LOG_TRACE,
"c->availability_start_time = [%"PRId64
"]\n",
c->availability_start_time);
1388 }
else if (!
av_strcasecmp(attr->name,
"availabilityEndTime")) {
1394 }
else if (!
av_strcasecmp(attr->name,
"minimumUpdatePeriod")) {
1397 }
else if (!
av_strcasecmp(attr->name,
"timeShiftBufferDepth")) {
1399 av_log(
s,
AV_LOG_TRACE,
"c->time_shift_buffer_depth = [%"PRId64
"]\n",
c->time_shift_buffer_depth);
1403 }
else if (!
av_strcasecmp(attr->name,
"suggestedPresentationDelay")) {
1405 av_log(
s,
AV_LOG_TRACE,
"c->suggested_presentation_delay = [%"PRId64
"]\n",
c->suggested_presentation_delay);
1406 }
else if (!
av_strcasecmp(attr->name,
"mediaPresentationDuration")) {
1408 av_log(
s,
AV_LOG_TRACE,
"c->media_presentation_duration = [%"PRId64
"]\n",
c->media_presentation_duration);
1416 mpd_baseurl_node = xmlCopyNode(tmp_node,1);
1418 mpd_baseurl_node = xmlNewNode(
NULL,
"BaseURL");
1422 node = xmlFirstElementChild(node);
1425 period_duration_sec = 0;
1426 period_start_sec = 0;
1427 attr = node->properties;
1429 val = xmlGetProp(node, attr->name);
1442 if ((period_duration_sec) >= (
c->period_duration)) {
1444 c->period_duration = period_duration_sec;
1445 c->period_start = period_start_sec;
1446 if (
c->period_start > 0)
1447 c->media_presentation_duration =
c->period_duration;
1449 }
else if (!
av_strcasecmp(node->name,
"ProgramInformation")) {
1452 node = xmlNextElementSibling(node);
1460 adaptionset_node = xmlFirstElementChild(period_node);
1461 while (adaptionset_node) {
1463 period_baseurl_node = adaptionset_node;
1464 }
else if (!
av_strcasecmp(adaptionset_node->name,
"SegmentTemplate")) {
1465 period_segmenttemplate_node = adaptionset_node;
1466 }
else if (!
av_strcasecmp(adaptionset_node->name,
"SegmentList")) {
1467 period_segmentlist_node = adaptionset_node;
1468 }
else if (!
av_strcasecmp(adaptionset_node->name,
"AdaptationSet")) {
1471 adaptionset_node = xmlNextElementSibling(adaptionset_node);
1477 xmlFreeNode(mpd_baseurl_node);
1491 int64_t start_time_offset = 0;
1507 }
else if (
c->publish_time > 0 && !
c->availability_start_time) {
1508 if (
c->min_buffer_time) {
1564 if (rep_dest && rep_src ) {
1578 if (rep_dest && rep_src ) {
1602 int n_videos =
c->n_videos;
1604 int n_audios =
c->n_audios;
1606 int n_subtitles =
c->n_subtitles;
1608 char *base_url =
c->base_url;
1609 int64_t minimum_update_period =
c->minimum_update_period;
1617 c->subtitles =
NULL;
1618 c->minimum_update_period = -1;
1623 if (
c->n_videos != n_videos) {
1625 "new manifest has mismatched no. of video representations, %d -> %d\n",
1626 n_videos,
c->n_videos);
1629 if (
c->n_audios != n_audios) {
1631 "new manifest has mismatched no. of audio representations, %d -> %d\n",
1632 n_audios,
c->n_audios);
1635 if (
c->n_subtitles != n_subtitles) {
1637 "new manifest has mismatched no. of subtitles representations, %d -> %d\n",
1638 n_subtitles,
c->n_subtitles);
1642 for (
i = 0;
i < n_videos;
i++) {
1658 for (
i = 0;
i < n_audios;
i++) {
1680 c->base_url = base_url;
1682 c->minimum_update_period = minimum_update_period;
1691 c->n_subtitles = n_subtitles;
1692 c->subtitles = subtitles;
1693 c->n_audios = n_audios;
1695 c->n_videos = n_videos;
1707 int reload_count = 0;
1724 }
else if (
c->is_live) {
1725 if (reload_count++ >=
c->max_reload) {
1727 "Reached max manifest reloads (%d) at seq %"PRId64
"\n",
1754 int has_negative_repeat = 0;
1766 c->minimum_update_period != -1 &&
1769 !has_negative_repeat &&
1773 if (reload_count >
c->max_reload) {
1775 "Reached max manifest reloads (%d) at seq %"PRId64
"\n",
1788 reload_interval =
FFMAX(reload_interval / 2, 100 * 1000);
1789 if (
c->minimum_update_period > 0)
1790 reload_interval =
FFMIN(reload_interval,
1844 uint8_t *buf,
int buf_size)
1849 if (seg->
size >= 0) {
1874 if (seg->
size >= 0) {
1896 static const int max_init_section_size = 1024 * 1024;
1908 "Failed to open an initialization section\n");
1917 sec_size = max_init_section_size;
1920 "Downloading an initialization section of size %"PRId64
"\n",
1923 sec_size =
FFMIN(sec_size, max_init_section_size);
1950static int read_data(
void *opaque, uint8_t *buf,
int buf_size)
1979 "Reached max consecutive fragment open failures (%d), giving up\n",
2025 "A DASH playlist item '%s' referred to an external file '%s'. "
2026 "Opening this file was forbidden for security reasons\n",
2035 memset(&pls->
pb, 0x00,
sizeof(pls->
pb));
2045 uint8_t *avio_ctx_buffer =
NULL;
2063 if (!avio_ctx_buffer ) {
2081 pls->
ctx->
probesize =
s->probesize > 0 ?
s->probesize : 1024 * 4;
2095 if (
c->cenc_decryption_key)
2096 av_dict_set(&in_fmt_opts,
"decryption_key",
c->cenc_decryption_key, 0);
2097 if (
c->cenc_decryption_keys)
2098 av_dict_set(&in_fmt_opts,
"decryption_keys",
c->cenc_decryption_keys, 0);
2106#if FF_API_R_FRAME_RATE
2168 stg->
id =
s->nb_stream_groups;
2178 switch (stg->
type) {
2188 av_unreachable(
"Unsupported Stream Group type should have been checked above");
2206 if (first_init_section ==
NULL || n_pls == 0)
2209 url = first_init_section->
url;
2212 for (
i=0;
i<n_pls;
i++) {
2213 if (!pls[
i]->init_section)
2257 c->interrupt_callback = &
s->interrupt_callback;
2277 for (
i = 0;
i <
c->n_videos;
i++) {
2279 if (
i > 0 &&
c->is_init_section_common_video) {
2297 for (
i = 0;
i <
c->n_audios;
i++) {
2299 if (
i > 0 &&
c->is_init_section_common_audio) {
2317 for (
i = 0;
i <
c->n_subtitles;
i++) {
2318 rep =
c->subtitles[
i];
2319 if (
i > 0 &&
c->is_init_section_common_subtitle) {
2342 for (
i = 0;
i <
c->n_videos;
i++) {
2356 for (
i = 0;
i <
c->n_audios;
i++) {
2371 for (
i = 0;
i <
c->n_subtitles;
i++) {
2372 rep =
c->subtitles[
i];
2386 for (
i = 0;
i <
c->n_videos;
i++) {
2391 for (j = 0; j <
c->n_videos; j++) {
2395 if (!
ref->nb_assoc_stream)
2426 for (
i = 0;
i < n;
i++) {
2433 if (needed && !pls->
ctx) {
2437 for (j = 0; j < n; j++) {
2442 }
else if (!needed && pls->
ctx) {
2462 for (
i = 0;
i <
c->n_videos;
i++) {
2471 for (
i = 0;
i <
c->n_audios;
i++) {
2481 for (
i = 0;
i <
c->n_subtitles;
i++) {
2482 rep =
c->subtitles[
i];
2540 seek_pos_msec, dry_run ?
" (dry)" :
"");
2558 "last_seq_no[%"PRId64
"].\n",
2610 for (
i = 0;
i <
c->n_videos;
i++) {
2614 for (
i = 0;
i <
c->n_audios;
i++) {
2618 for (
i = 0;
i <
c->n_subtitles;
i++) {
2631 if (
av_stristr(p->buf,
"dash:profile:isoff-on-demand:2011") ||
2632 av_stristr(p->buf,
"dash:profile:isoff-live:2011") ||
2633 av_stristr(p->buf,
"dash:profile:isoff-live:2012") ||
2634 av_stristr(p->buf,
"dash:profile:isoff-main:2011") ||
2635 av_stristr(p->buf,
"3GPP:PSS:profile:DASH1")) {
2645#define OFFSET(x) offsetof(DASHContext, x)
2646#define FLAGS AV_OPT_FLAG_DECODING_PARAM
2648 {
"allowed_extensions",
"List of file extensions that dash is allowed to access",
2650 {.str =
"aac,m4a,m4s,m4v,mov,mp4,webm,ts"},
2651 INT_MIN, INT_MAX,
FLAGS},
2652 {
"cenc_decryption_key",
"Media default decryption key (hex)",
OFFSET(cenc_decryption_key),
AV_OPT_TYPE_STRING, {.str =
NULL}, INT_MIN, INT_MAX, .flags =
FLAGS },
2653 {
"cenc_decryption_keys",
"Media decryption keys by KID (hex)",
OFFSET(cenc_decryption_keys),
AV_OPT_TYPE_STRING, {.str =
NULL}, INT_MIN, INT_MAX, .flags =
FLAGS },
2654 {
"max_reload",
"Maximum number of manifest reloads in get_current_fragment() before giving up",
2660 .class_name =
"dash",
static double val(void *priv, double ch)
static AVDictionary * opts
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_FLAG_READ
read-only
int64_t avio_size(AVIOContext *s)
Get the filesize.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int avio_read_to_bprint(AVIOContext *h, struct AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
void ffio_init_context(FFIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, const uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
int ffio_copy_url_options(AVIOContext *pb, AVDictionary **avio_opts)
Read url related dictionary options from the AVIOContext and write to the given dictionary.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
void ff_dash_fill_tmpl_params(char *dst, size_t buffer_size, const char *template, int rep_id, int number, int bit_rate, int64_t time)
static int dash_read_header(AVFormatContext *s)
#define SET_REPRESENTATION_SEQUENCE_BASE_INFO(arg, cnt)
static enum AVMediaType get_content_type(xmlNodePtr node)
static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, AVDictionary **opts, AVDictionary *opts2, int *is_http)
#define INITIAL_BUFFER_SIZE
static int is_common_init_section_exist(struct representation **pls, int n_pls)
static const AVOption dash_options[]
static struct fragment * get_current_fragment(struct representation *pls)
static int update_init_section(struct representation *pls)
static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t seek_pos_msec, int flags, int dry_run)
static int read_data(void *opaque, uint8_t *buf, int buf_size)
static int open_demux_for_component(AVFormatContext *s, struct representation *pls)
static int parse_manifest_adaptationset_attr(AVFormatContext *s, xmlNodePtr adaptionset_node)
static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representation *rep, xmlNodePtr fragmenturl_node, xmlNodePtr *baseurl_nodes, char *rep_id_val, char *rep_bandwidth_val)
static int64_t get_utc_date_time_insec(AVFormatContext *s, const char *datetime)
static void recheck_discard_flags(AVFormatContext *s, struct representation **p, int n)
static void move_metadata(AVStream *st, const char *key, char **value)
static int parse_manifest_representation(AVFormatContext *s, const char *url, xmlNodePtr node, xmlNodePtr adaptionset_node, xmlNodePtr mpd_baseurl_node, xmlNodePtr period_baseurl_node, xmlNodePtr period_segmenttemplate_node, xmlNodePtr period_segmentlist_node, xmlNodePtr fragment_template_node, xmlNodePtr content_component_node, xmlNodePtr adaptionset_baseurl_node, xmlNodePtr adaptionset_segmentlist_node, xmlNodePtr adaptionset_supplementalproperty_node)
static char * get_content_url(xmlNodePtr *baseurl_nodes, int n_baseurl_nodes, int max_url_size, char *rep_id_val, char *rep_bandwidth_val, char *val)
static int copy_init_section(struct representation *rep_dest, struct representation *rep_src)
static const AVClass dash_class
static int64_t get_segment_start_time_based_on_timeline(struct representation *pls, int64_t cur_seq_no)
static int reopen_demux_for_component(AVFormatContext *s, struct representation *pls)
static int dash_read_packet(AVFormatContext *s, AVPacket *pkt)
static int64_t calc_min_seg_no(AVFormatContext *s, struct representation *pls)
static int64_t get_current_time_in_sec(void)
static int ishttp(const char *url)
static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **opts)
static void free_representation(struct representation *pls)
static void free_audio_list(DASHContext *c)
static uint32_t get_duration_insec(AVFormatContext *s, const char *duration)
static void move_timelines(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
static int64_t calc_cur_seg_no(AVFormatContext *s, struct representation *pls)
#define MAX_TIMELINE_SEGMENTS
static void free_subtitle_list(DASHContext *c)
static int dash_close(AVFormatContext *s)
static void close_demux_for_component(struct representation *pls)
static int add_url_size(int *url_size, uint64_t len)
static int64_t seek_data(void *opaque, int64_t offset, int whence)
static int dash_probe(const AVProbeData *p)
static int open_input(DASHContext *c, struct representation *pls, struct fragment *seg)
static xmlNodePtr find_child_node_by_name(xmlNodePtr rootnode, const char *nodename)
static int refresh_manifest(AVFormatContext *s)
static struct fragment * get_fragment(AVFormatContext *s, char *range)
static int64_t calc_next_seg_no_from_timelines(struct representation *pls, int64_t cur_time)
static void free_fragment(struct fragment **seg)
static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
static void move_segments(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
static int64_t calc_max_seg_no(struct representation *pls, DASHContext *c)
static int read_from_url(struct representation *pls, struct fragment *seg, uint8_t *buf, int buf_size)
static int parse_programinformation(AVFormatContext *s, xmlNodePtr node)
static char * get_val_from_nodes_tab(xmlNodePtr *nodes, const int n_nodes, const char *attrname)
static int dash_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, xmlNodePtr adaptionset_node, xmlNodePtr mpd_baseurl_node, xmlNodePtr period_baseurl_node, xmlNodePtr period_segmenttemplate_node, xmlNodePtr period_segmentlist_node)
static void free_fragment_list(struct representation *pls)
static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representation *rep, xmlNodePtr fragment_timeline_node)
static void free_timelines_list(struct representation *pls)
static void free_video_list(DASHContext *c)
static int resolve_content_path(AVFormatContext *s, const char *url, int *max_url_size, xmlNodePtr *baseurl_nodes, int n_baseurl_nodes)
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
static int64_t start_time
static int read_header(FFV1Context *f, RangeCoder *c)
static av_cold void cleanup(FlashSV2Context *s)
@ AV_OPT_TYPE_INT
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...
@ AVDISCARD_ALL
discard all
AVProgram * av_new_program(AVFormatContext *ac, int id)
AVStreamGroup * avformat_stream_group_create(AVFormatContext *s, enum AVStreamGroupParamsType type, AVDictionary **options)
Add a new empty stream group to a media file.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
int avformat_stream_group_add_stream(AVStreamGroup *stg, AVStream *st)
Add an already allocated stream to a stream group.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int av_probe_input_buffer(AVIOContext *pb, const AVInputFormat **fmt, const char *url, void *logctx, unsigned int offset, unsigned int max_probe_size)
Like av_probe_input_buffer2() but returns 0 on success.
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
int av_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
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.
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_MATCH_CASE
Only get an entry with exact-case key match.
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#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_INFO
Standard 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.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
@ AV_ROUND_DOWN
Round toward -infinity.
@ AV_ROUND_UP
Round toward +infinity.
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
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.
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.
char * av_strireplace(const char *str, const char *from, const char *to)
Locale-independent strings replace.
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
#define AV_TIME_BASE
Internal time base represented as integer.
#define LIBAVUTIL_VERSION_INT
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Memory handling functions.
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
time_t av_timegm(struct tm *tm)
Convert the decomposed UTC time in tm to a time_t value, saturated to the range of time_t.
Describe the class of an AVClass context structure.
int height
The height of the video frame in pixels.
int width
The width of the video frame in pixels.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVStreamGroup ** stream_groups
A list of all stream groups in the file.
AVIOContext * pb
I/O context.
int flags
Flags modifying the (de)muxer behaviour.
int64_t max_analyze_duration
Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info().
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
unsigned int nb_stream_groups
Number of elements in AVFormatContext.stream_groups.
void * priv_data
Format private data.
int64_t probesize
Maximum number of bytes read from input in order to determine stream properties.
AVStream ** streams
A list of all streams in the file.
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
unsigned char * buffer
Start of the buffer.
Callback for checking whether to abort blocking functions.
This structure stores compressed data.
This structure contains the data a format has to probe a file.
New fields can be added to the end with minor version bumps.
Rational number (pair of numerator and denominator).
AVStreamGroupLayeredVideo is meant to define the relation between a base layer video stream and a sep...
int height
Height of the final image for presentation.
unsigned int el_index
Index of the enhancement layer stream in AVStreamGroup.
int width
Width of the final stream for presentation.
unsigned int nb_entries
Number of elements in AVStreamGroup.entries.
enum AVStreamGroupParamsType type
Group type.
AVStreamGroupEntry ** entries
A list of streams or child groups in the group.
unsigned int index
Group index in AVFormatContext.
union AVStreamGroup::@313244315204024013007202273061153315146016101155 params
Group type-specific parameters.
int disposition
Stream group disposition - a combination of AV_DISPOSITION_* flags.
int64_t id
Group type-specific group ID.
struct AVStreamGroupLayeredVideo * layered_video
AVCodecParameters * codecpar
Codec parameters associated with this stream.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int id
Format-specific stream ID.
int index
stream index in AVFormatContext
int pts_wrap_bits
Number of bits in timestamps.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
AVRational r_frame_rate
Real base framerate of the stream.
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
int is_init_section_common_video
int64_t availability_end_time
int64_t minimum_update_period
int is_init_section_common_audio
int64_t media_presentation_duration
int64_t suggested_presentation_delay
char * cenc_decryption_key
struct representation ** videos
struct representation ** subtitles
int is_init_section_common_subtitle
char * allowed_extensions
int64_t availability_start_time
int64_t time_shift_buffer_depth
AVIOInterruptCB * interrupt_callback
char * cenc_decryption_keys
struct representation ** audios
enum AVStreamParseType need_parsing
uint32_t init_sec_data_len
struct timeline ** timelines
struct fragment * cur_seg
uint32_t init_sec_buf_size
uint32_t init_sec_buf_read_offset
int64_t presentation_timeoffset
struct fragment ** fragments
int64_t fragment_timescale
struct fragment * init_section
int64_t fragment_duration
#define av_malloc_array(a, b)
static int ref[MAX_W *MAX_W]
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.
int ff_make_absolute_url(char *buf, int size, const char *base, const char *rel)
Convert a relative url into an absolute url, given a base url.
unbuffered private I/O API