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.

1852 lines
62KB

  1. /*
  2. * Dynamic Adaptive Streaming over HTTP demux
  3. * Copyright (c) 2017 samsamsam@o2.pl based on HLS demux
  4. * Copyright (c) 2017 Steven Liu
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <libxml/parser.h>
  23. #include "libavutil/intreadwrite.h"
  24. #include "libavutil/opt.h"
  25. #include "libavutil/time.h"
  26. #include "libavutil/parseutils.h"
  27. #include "internal.h"
  28. #include "avio_internal.h"
  29. #include "dash.h"
  30. #define INITIAL_BUFFER_SIZE 32768
  31. struct fragment {
  32. int64_t url_offset;
  33. int64_t size;
  34. char *url;
  35. };
  36. /*
  37. * reference to : ISO_IEC_23009-1-DASH-2012
  38. * Section: 5.3.9.6.2
  39. * Table: Table 17 — Semantics of SegmentTimeline element
  40. * */
  41. struct timeline {
  42. /* starttime: Element or Attribute Name
  43. * specifies the MPD start time, in @timescale units,
  44. * the first Segment in the series starts relative to the beginning of the Period.
  45. * The value of this attribute must be equal to or greater than the sum of the previous S
  46. * element earliest presentation time and the sum of the contiguous Segment durations.
  47. * If the value of the attribute is greater than what is expressed by the previous S element,
  48. * it expresses discontinuities in the timeline.
  49. * If not present then the value shall be assumed to be zero for the first S element
  50. * and for the subsequent S elements, the value shall be assumed to be the sum of
  51. * the previous S element's earliest presentation time and contiguous duration
  52. * (i.e. previous S@starttime + @duration * (@repeat + 1)).
  53. * */
  54. int64_t starttime;
  55. /* repeat: Element or Attribute Name
  56. * specifies the repeat count of the number of following contiguous Segments with
  57. * the same duration expressed by the value of @duration. This value is zero-based
  58. * (e.g. a value of three means four Segments in the contiguous series).
  59. * */
  60. int64_t repeat;
  61. /* duration: Element or Attribute Name
  62. * specifies the Segment duration, in units of the value of the @timescale.
  63. * */
  64. int64_t duration;
  65. };
  66. /*
  67. * Each playlist has its own demuxer. If it is currently active,
  68. * it has an opened AVIOContext too, and potentially an AVPacket
  69. * containing the next packet from this stream.
  70. */
  71. struct representation {
  72. char *url_template;
  73. AVIOContext pb;
  74. AVIOContext *input;
  75. AVFormatContext *parent;
  76. AVFormatContext *ctx;
  77. AVPacket pkt;
  78. int rep_idx;
  79. int rep_count;
  80. int stream_index;
  81. enum AVMediaType type;
  82. int n_fragments;
  83. struct fragment **fragments; /* VOD list of fragment for profile */
  84. int n_timelines;
  85. struct timeline **timelines;
  86. int64_t first_seq_no;
  87. int64_t last_seq_no;
  88. int64_t start_number; /* used in case when we have dynamic list of segment to know which segments are new one*/
  89. int64_t fragment_duration;
  90. int64_t fragment_timescale;
  91. int64_t presentation_timeoffset;
  92. int64_t cur_seq_no;
  93. int64_t cur_seg_offset;
  94. int64_t cur_seg_size;
  95. struct fragment *cur_seg;
  96. /* Currently active Media Initialization Section */
  97. struct fragment *init_section;
  98. uint8_t *init_sec_buf;
  99. uint32_t init_sec_buf_size;
  100. uint32_t init_sec_data_len;
  101. uint32_t init_sec_buf_read_offset;
  102. int64_t cur_timestamp;
  103. int is_restart_needed;
  104. };
  105. typedef struct DASHContext {
  106. const AVClass *class;
  107. char *base_url;
  108. struct representation *cur_video;
  109. struct representation *cur_audio;
  110. /* MediaPresentationDescription Attribute */
  111. uint64_t media_presentation_duration;
  112. uint64_t suggested_presentation_delay;
  113. uint64_t availability_start_time;
  114. uint64_t publish_time;
  115. uint64_t minimum_update_period;
  116. uint64_t time_shift_buffer_depth;
  117. uint64_t min_buffer_time;
  118. /* Period Attribute */
  119. uint64_t period_duration;
  120. uint64_t period_start;
  121. int is_live;
  122. AVIOInterruptCB *interrupt_callback;
  123. char *user_agent; ///< holds HTTP user agent set as an AVOption to the HTTP protocol context
  124. char *cookies; ///< holds HTTP cookie values set in either the initial response or as an AVOption to the HTTP protocol context
  125. char *headers; ///< holds HTTP headers set as an AVOption to the HTTP protocol context
  126. char *allowed_extensions;
  127. AVDictionary *avio_opts;
  128. } DASHContext;
  129. static uint64_t get_current_time_in_sec(void)
  130. {
  131. return av_gettime() / 1000000;
  132. }
  133. static uint64_t get_utc_date_time_insec(AVFormatContext *s, const char *datetime)
  134. {
  135. struct tm timeinfo;
  136. int year = 0;
  137. int month = 0;
  138. int day = 0;
  139. int hour = 0;
  140. int minute = 0;
  141. int ret = 0;
  142. float second = 0.0;
  143. /* ISO-8601 date parser */
  144. if (!datetime)
  145. return 0;
  146. ret = sscanf(datetime, "%d-%d-%dT%d:%d:%fZ", &year, &month, &day, &hour, &minute, &second);
  147. /* year, month, day, hour, minute, second 6 arguments */
  148. if (ret != 6) {
  149. av_log(s, AV_LOG_WARNING, "get_utc_date_time_insec get a wrong time format\n");
  150. }
  151. timeinfo.tm_year = year - 1900;
  152. timeinfo.tm_mon = month - 1;
  153. timeinfo.tm_mday = day;
  154. timeinfo.tm_hour = hour;
  155. timeinfo.tm_min = minute;
  156. timeinfo.tm_sec = (int)second;
  157. return av_timegm(&timeinfo);
  158. }
  159. static uint32_t get_duration_insec(AVFormatContext *s, const char *duration)
  160. {
  161. /* ISO-8601 duration parser */
  162. uint32_t days = 0;
  163. uint32_t hours = 0;
  164. uint32_t mins = 0;
  165. uint32_t secs = 0;
  166. int size = 0;
  167. float value = 0;
  168. char type = '\0';
  169. const char *ptr = duration;
  170. while (*ptr) {
  171. if (*ptr == 'P' || *ptr == 'T') {
  172. ptr++;
  173. continue;
  174. }
  175. if (sscanf(ptr, "%f%c%n", &value, &type, &size) != 2) {
  176. av_log(s, AV_LOG_WARNING, "get_duration_insec get a wrong time format\n");
  177. return 0; /* parser error */
  178. }
  179. switch (type) {
  180. case 'D':
  181. days = (uint32_t)value;
  182. break;
  183. case 'H':
  184. hours = (uint32_t)value;
  185. break;
  186. case 'M':
  187. mins = (uint32_t)value;
  188. break;
  189. case 'S':
  190. secs = (uint32_t)value;
  191. break;
  192. default:
  193. // handle invalid type
  194. break;
  195. }
  196. ptr += size;
  197. }
  198. return ((days * 24 + hours) * 60 + mins) * 60 + secs;
  199. }
  200. static int64_t get_segment_start_time_based_on_timeline(struct representation *pls, int64_t cur_seq_no)
  201. {
  202. int64_t start_time = 0;
  203. int64_t i = 0;
  204. int64_t j = 0;
  205. int64_t num = 0;
  206. if (pls->n_timelines) {
  207. for (i = 0; i < pls->n_timelines; i++) {
  208. if (pls->timelines[i]->starttime > 0) {
  209. start_time = pls->timelines[i]->starttime;
  210. }
  211. if (num == cur_seq_no)
  212. goto finish;
  213. start_time += pls->timelines[i]->duration;
  214. for (j = 0; j < pls->timelines[i]->repeat; j++) {
  215. num++;
  216. if (num == cur_seq_no)
  217. goto finish;
  218. start_time += pls->timelines[i]->duration;
  219. }
  220. num++;
  221. }
  222. }
  223. finish:
  224. return start_time;
  225. }
  226. static int64_t calc_next_seg_no_from_timelines(struct representation *pls, int64_t cur_time)
  227. {
  228. int64_t i = 0;
  229. int64_t j = 0;
  230. int64_t num = 0;
  231. int64_t start_time = 0;
  232. for (i = 0; i < pls->n_timelines; i++) {
  233. if (pls->timelines[i]->starttime > 0) {
  234. start_time = pls->timelines[i]->starttime;
  235. }
  236. if (start_time > cur_time)
  237. goto finish;
  238. start_time += pls->timelines[i]->duration;
  239. for (j = 0; j < pls->timelines[i]->repeat; j++) {
  240. num++;
  241. if (start_time > cur_time)
  242. goto finish;
  243. start_time += pls->timelines[i]->duration;
  244. }
  245. num++;
  246. }
  247. return -1;
  248. finish:
  249. return num;
  250. }
  251. static void free_fragment(struct fragment **seg)
  252. {
  253. if (!(*seg)) {
  254. return;
  255. }
  256. av_freep(&(*seg)->url);
  257. av_freep(seg);
  258. }
  259. static void free_fragment_list(struct representation *pls)
  260. {
  261. int i;
  262. for (i = 0; i < pls->n_fragments; i++) {
  263. free_fragment(&pls->fragments[i]);
  264. }
  265. av_freep(&pls->fragments);
  266. pls->n_fragments = 0;
  267. }
  268. static void free_timelines_list(struct representation *pls)
  269. {
  270. int i;
  271. for (i = 0; i < pls->n_timelines; i++) {
  272. av_freep(&pls->timelines[i]);
  273. }
  274. av_freep(&pls->timelines);
  275. pls->n_timelines = 0;
  276. }
  277. static void free_representation(struct representation *pls)
  278. {
  279. free_fragment_list(pls);
  280. free_timelines_list(pls);
  281. free_fragment(&pls->cur_seg);
  282. free_fragment(&pls->init_section);
  283. av_freep(&pls->init_sec_buf);
  284. av_freep(&pls->pb.buffer);
  285. if (pls->input)
  286. ff_format_io_close(pls->parent, &pls->input);
  287. if (pls->ctx) {
  288. pls->ctx->pb = NULL;
  289. avformat_close_input(&pls->ctx);
  290. }
  291. av_freep(&pls->url_template);
  292. av_freep(&pls);
  293. }
  294. static void set_httpheader_options(DASHContext *c, AVDictionary **opts)
  295. {
  296. // broker prior HTTP options that should be consistent across requests
  297. av_dict_set(opts, "user-agent", c->user_agent, 0);
  298. av_dict_set(opts, "cookies", c->cookies, 0);
  299. av_dict_set(opts, "headers", c->headers, 0);
  300. if (c->is_live) {
  301. av_dict_set(opts, "seekable", "0", 0);
  302. }
  303. }
  304. static void update_options(char **dest, const char *name, void *src)
  305. {
  306. av_freep(dest);
  307. av_opt_get(src, name, AV_OPT_SEARCH_CHILDREN, (uint8_t**)dest);
  308. if (*dest)
  309. av_freep(dest);
  310. }
  311. static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
  312. AVDictionary *opts, AVDictionary *opts2, int *is_http)
  313. {
  314. DASHContext *c = s->priv_data;
  315. AVDictionary *tmp = NULL;
  316. const char *proto_name = NULL;
  317. int ret;
  318. av_dict_copy(&tmp, opts, 0);
  319. av_dict_copy(&tmp, opts2, 0);
  320. if (av_strstart(url, "crypto", NULL)) {
  321. if (url[6] == '+' || url[6] == ':')
  322. proto_name = avio_find_protocol_name(url + 7);
  323. }
  324. if (!proto_name)
  325. proto_name = avio_find_protocol_name(url);
  326. if (!proto_name)
  327. return AVERROR_INVALIDDATA;
  328. // only http(s) & file are allowed
  329. if (av_strstart(proto_name, "file", NULL)) {
  330. if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, c->allowed_extensions)) {
  331. av_log(s, AV_LOG_ERROR,
  332. "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n"
  333. "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",
  334. url);
  335. return AVERROR_INVALIDDATA;
  336. }
  337. } else if (av_strstart(proto_name, "http", NULL)) {
  338. ;
  339. } else
  340. return AVERROR_INVALIDDATA;
  341. if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')
  342. ;
  343. else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')
  344. ;
  345. else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
  346. return AVERROR_INVALIDDATA;
  347. ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);
  348. if (ret >= 0) {
  349. // update cookies on http response with setcookies.
  350. char *new_cookies = NULL;
  351. if (!(s->flags & AVFMT_FLAG_CUSTOM_IO))
  352. av_opt_get(*pb, "cookies", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&new_cookies);
  353. if (new_cookies) {
  354. av_free(c->cookies);
  355. c->cookies = new_cookies;
  356. }
  357. av_dict_set(&opts, "cookies", c->cookies, 0);
  358. }
  359. av_dict_free(&tmp);
  360. if (is_http)
  361. *is_http = av_strstart(proto_name, "http", NULL);
  362. return ret;
  363. }
  364. static char *get_content_url(xmlNodePtr *baseurl_nodes,
  365. int n_baseurl_nodes,
  366. char *rep_id_val,
  367. char *rep_bandwidth_val,
  368. char *val)
  369. {
  370. int i;
  371. char *text;
  372. char *url = NULL;
  373. char tmp_str[MAX_URL_SIZE];
  374. char tmp_str_2[MAX_URL_SIZE];
  375. memset(tmp_str, 0, sizeof(tmp_str));
  376. for (i = 0; i < n_baseurl_nodes; ++i) {
  377. if (baseurl_nodes[i] &&
  378. baseurl_nodes[i]->children &&
  379. baseurl_nodes[i]->children->type == XML_TEXT_NODE) {
  380. text = xmlNodeGetContent(baseurl_nodes[i]->children);
  381. if (text) {
  382. memset(tmp_str, 0, sizeof(tmp_str));
  383. memset(tmp_str_2, 0, sizeof(tmp_str_2));
  384. ff_make_absolute_url(tmp_str_2, MAX_URL_SIZE, tmp_str, text);
  385. av_strlcpy(tmp_str, tmp_str_2, sizeof(tmp_str));
  386. xmlFree(text);
  387. }
  388. }
  389. }
  390. if (val)
  391. av_strlcat(tmp_str, (const char*)val, sizeof(tmp_str));
  392. if (rep_id_val) {
  393. url = av_strireplace(tmp_str, "$RepresentationID$", (const char*)rep_id_val);
  394. if (!url) {
  395. return NULL;
  396. }
  397. av_strlcpy(tmp_str, url, sizeof(tmp_str));
  398. av_free(url);
  399. }
  400. if (rep_bandwidth_val && tmp_str[0] != '\0') {
  401. url = av_strireplace(tmp_str, "$Bandwidth$", (const char*)rep_bandwidth_val);
  402. if (!url) {
  403. return NULL;
  404. }
  405. }
  406. return url;
  407. }
  408. static char *get_val_from_nodes_tab(xmlNodePtr *nodes, const int n_nodes, const char *attrname)
  409. {
  410. int i;
  411. char *val;
  412. for (i = 0; i < n_nodes; ++i) {
  413. if (nodes[i]) {
  414. val = xmlGetProp(nodes[i], attrname);
  415. if (val)
  416. return val;
  417. }
  418. }
  419. return NULL;
  420. }
  421. static xmlNodePtr find_child_node_by_name(xmlNodePtr rootnode, const char *nodename)
  422. {
  423. xmlNodePtr node = rootnode;
  424. if (!node) {
  425. return NULL;
  426. }
  427. node = xmlFirstElementChild(node);
  428. while (node) {
  429. if (!av_strcasecmp(node->name, nodename)) {
  430. return node;
  431. }
  432. node = xmlNextElementSibling(node);
  433. }
  434. return NULL;
  435. }
  436. static enum AVMediaType get_content_type(xmlNodePtr node)
  437. {
  438. enum AVMediaType type = AVMEDIA_TYPE_UNKNOWN;
  439. int i = 0;
  440. const char *attr;
  441. char *val = NULL;
  442. if (node) {
  443. for (i = 0; i < 2; i++) {
  444. attr = i ? "mimeType" : "contentType";
  445. val = xmlGetProp(node, attr);
  446. if (val) {
  447. if (av_stristr((const char *)val, "video")) {
  448. type = AVMEDIA_TYPE_VIDEO;
  449. } else if (av_stristr((const char *)val, "audio")) {
  450. type = AVMEDIA_TYPE_AUDIO;
  451. }
  452. xmlFree(val);
  453. }
  454. }
  455. }
  456. return type;
  457. }
  458. static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representation *rep,
  459. xmlNodePtr fragmenturl_node,
  460. xmlNodePtr *baseurl_nodes,
  461. char *rep_id_val,
  462. char *rep_bandwidth_val)
  463. {
  464. char *initialization_val = NULL;
  465. char *media_val = NULL;
  466. if (!av_strcasecmp(fragmenturl_node->name, (const char *)"Initialization")) {
  467. initialization_val = xmlGetProp(fragmenturl_node, "sourceURL");
  468. if (initialization_val) {
  469. rep->init_section = av_mallocz(sizeof(struct fragment));
  470. if (!rep->init_section) {
  471. xmlFree(initialization_val);
  472. return AVERROR(ENOMEM);
  473. }
  474. rep->init_section->url = get_content_url(baseurl_nodes, 4,
  475. rep_id_val,
  476. rep_bandwidth_val,
  477. initialization_val);
  478. if (!rep->init_section->url) {
  479. av_free(rep->init_section);
  480. xmlFree(initialization_val);
  481. return AVERROR(ENOMEM);
  482. }
  483. rep->init_section->size = -1;
  484. xmlFree(initialization_val);
  485. }
  486. } else if (!av_strcasecmp(fragmenturl_node->name, (const char *)"SegmentURL")) {
  487. media_val = xmlGetProp(fragmenturl_node, "media");
  488. if (media_val) {
  489. struct fragment *seg = av_mallocz(sizeof(struct fragment));
  490. if (!seg) {
  491. xmlFree(media_val);
  492. return AVERROR(ENOMEM);
  493. }
  494. seg->url = get_content_url(baseurl_nodes, 4,
  495. rep_id_val,
  496. rep_bandwidth_val,
  497. media_val);
  498. if (!seg->url) {
  499. av_free(seg);
  500. xmlFree(media_val);
  501. return AVERROR(ENOMEM);
  502. }
  503. seg->size = -1;
  504. dynarray_add(&rep->fragments, &rep->n_fragments, seg);
  505. xmlFree(media_val);
  506. }
  507. }
  508. return 0;
  509. }
  510. static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representation *rep,
  511. xmlNodePtr fragment_timeline_node)
  512. {
  513. xmlAttrPtr attr = NULL;
  514. char *val = NULL;
  515. if (!av_strcasecmp(fragment_timeline_node->name, (const char *)"S")) {
  516. struct timeline *tml = av_mallocz(sizeof(struct timeline));
  517. if (!tml) {
  518. return AVERROR(ENOMEM);
  519. }
  520. attr = fragment_timeline_node->properties;
  521. while (attr) {
  522. val = xmlGetProp(fragment_timeline_node, attr->name);
  523. if (!val) {
  524. av_log(s, AV_LOG_WARNING, "parse_manifest_segmenttimeline attr->name = %s val is NULL\n", attr->name);
  525. continue;
  526. }
  527. if (!av_strcasecmp(attr->name, (const char *)"t")) {
  528. tml->starttime = (int64_t)strtoll(val, NULL, 10);
  529. } else if (!av_strcasecmp(attr->name, (const char *)"r")) {
  530. tml->repeat =(int64_t) strtoll(val, NULL, 10);
  531. } else if (!av_strcasecmp(attr->name, (const char *)"d")) {
  532. tml->duration = (int64_t)strtoll(val, NULL, 10);
  533. }
  534. attr = attr->next;
  535. xmlFree(val);
  536. }
  537. dynarray_add(&rep->timelines, &rep->n_timelines, tml);
  538. }
  539. return 0;
  540. }
  541. static int parse_manifest_representation(AVFormatContext *s, const char *url,
  542. xmlNodePtr node,
  543. xmlNodePtr adaptionset_node,
  544. xmlNodePtr mpd_baseurl_node,
  545. xmlNodePtr period_baseurl_node,
  546. xmlNodePtr fragment_template_node,
  547. xmlNodePtr content_component_node,
  548. xmlNodePtr adaptionset_baseurl_node)
  549. {
  550. int32_t ret = 0;
  551. int32_t audio_rep_idx = 0;
  552. int32_t video_rep_idx = 0;
  553. DASHContext *c = s->priv_data;
  554. struct representation *rep = NULL;
  555. struct fragment *seg = NULL;
  556. xmlNodePtr representation_segmenttemplate_node = NULL;
  557. xmlNodePtr representation_baseurl_node = NULL;
  558. xmlNodePtr representation_segmentlist_node = NULL;
  559. xmlNodePtr fragment_timeline_node = NULL;
  560. xmlNodePtr fragment_templates_tab[2];
  561. char *duration_val = NULL;
  562. char *presentation_timeoffset_val = NULL;
  563. char *startnumber_val = NULL;
  564. char *timescale_val = NULL;
  565. char *initialization_val = NULL;
  566. char *media_val = NULL;
  567. xmlNodePtr baseurl_nodes[4];
  568. xmlNodePtr representation_node = node;
  569. char *rep_id_val = xmlGetProp(representation_node, "id");
  570. char *rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth");
  571. enum AVMediaType type = AVMEDIA_TYPE_UNKNOWN;
  572. // try get information from representation
  573. if (type == AVMEDIA_TYPE_UNKNOWN)
  574. type = get_content_type(representation_node);
  575. // try get information from contentComponen
  576. if (type == AVMEDIA_TYPE_UNKNOWN)
  577. type = get_content_type(content_component_node);
  578. // try get information from adaption set
  579. if (type == AVMEDIA_TYPE_UNKNOWN)
  580. type = get_content_type(adaptionset_node);
  581. if (type == AVMEDIA_TYPE_UNKNOWN) {
  582. av_log(s, AV_LOG_VERBOSE, "Parsing '%s' - skipp not supported representation type\n", url);
  583. } else if ((type == AVMEDIA_TYPE_VIDEO && !c->cur_video) || (type == AVMEDIA_TYPE_AUDIO && !c->cur_audio)) {
  584. // convert selected representation to our internal struct
  585. rep = av_mallocz(sizeof(struct representation));
  586. if (!rep) {
  587. ret = AVERROR(ENOMEM);
  588. goto end;
  589. }
  590. representation_segmenttemplate_node = find_child_node_by_name(representation_node, "SegmentTemplate");
  591. representation_baseurl_node = find_child_node_by_name(representation_node, "BaseURL");
  592. representation_segmentlist_node = find_child_node_by_name(representation_node, "SegmentList");
  593. baseurl_nodes[0] = mpd_baseurl_node;
  594. baseurl_nodes[1] = period_baseurl_node;
  595. baseurl_nodes[2] = adaptionset_baseurl_node;
  596. baseurl_nodes[3] = representation_baseurl_node;
  597. if (representation_segmenttemplate_node || fragment_template_node) {
  598. fragment_timeline_node = NULL;
  599. fragment_templates_tab[0] = representation_segmenttemplate_node;
  600. fragment_templates_tab[1] = fragment_template_node;
  601. presentation_timeoffset_val = get_val_from_nodes_tab(fragment_templates_tab, 2, "presentationTimeOffset");
  602. duration_val = get_val_from_nodes_tab(fragment_templates_tab, 2, "duration");
  603. startnumber_val = get_val_from_nodes_tab(fragment_templates_tab, 2, "startNumber");
  604. timescale_val = get_val_from_nodes_tab(fragment_templates_tab, 2, "timescale");
  605. initialization_val = get_val_from_nodes_tab(fragment_templates_tab, 2, "initialization");
  606. media_val = get_val_from_nodes_tab(fragment_templates_tab, 2, "media");
  607. if (initialization_val) {
  608. rep->init_section = av_mallocz(sizeof(struct fragment));
  609. if (!rep->init_section) {
  610. av_free(rep);
  611. ret = AVERROR(ENOMEM);
  612. goto end;
  613. }
  614. rep->init_section->url = get_content_url(baseurl_nodes, 4, rep_id_val, rep_bandwidth_val, initialization_val);
  615. if (!rep->init_section->url) {
  616. av_free(rep->init_section);
  617. av_free(rep);
  618. ret = AVERROR(ENOMEM);
  619. goto end;
  620. }
  621. rep->init_section->size = -1;
  622. xmlFree(initialization_val);
  623. }
  624. if (media_val) {
  625. rep->url_template = get_content_url(baseurl_nodes, 4, rep_id_val, rep_bandwidth_val, media_val);
  626. xmlFree(media_val);
  627. }
  628. if (presentation_timeoffset_val) {
  629. rep->presentation_timeoffset = (int64_t) strtoll(presentation_timeoffset_val, NULL, 10);
  630. xmlFree(presentation_timeoffset_val);
  631. }
  632. if (duration_val) {
  633. rep->fragment_duration = (int64_t) strtoll(duration_val, NULL, 10);
  634. xmlFree(duration_val);
  635. }
  636. if (timescale_val) {
  637. rep->fragment_timescale = (int64_t) strtoll(timescale_val, NULL, 10);
  638. xmlFree(timescale_val);
  639. }
  640. if (startnumber_val) {
  641. rep->first_seq_no = (int64_t) strtoll(startnumber_val, NULL, 10);
  642. xmlFree(startnumber_val);
  643. }
  644. fragment_timeline_node = find_child_node_by_name(representation_segmenttemplate_node, "SegmentTimeline");
  645. if (!fragment_timeline_node)
  646. fragment_timeline_node = find_child_node_by_name(fragment_template_node, "SegmentTimeline");
  647. if (fragment_timeline_node) {
  648. fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node);
  649. while (fragment_timeline_node) {
  650. ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node);
  651. if (ret < 0) {
  652. return ret;
  653. }
  654. fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node);
  655. }
  656. }
  657. } else if (representation_baseurl_node && !representation_segmentlist_node) {
  658. seg = av_mallocz(sizeof(struct fragment));
  659. if (!seg) {
  660. ret = AVERROR(ENOMEM);
  661. goto end;
  662. }
  663. seg->url = get_content_url(baseurl_nodes, 4, rep_id_val, rep_bandwidth_val, NULL);
  664. if (!seg->url) {
  665. av_free(seg);
  666. ret = AVERROR(ENOMEM);
  667. goto end;
  668. }
  669. seg->size = -1;
  670. dynarray_add(&rep->fragments, &rep->n_fragments, seg);
  671. } else if (representation_segmentlist_node) {
  672. // TODO: https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html
  673. // http://www-itec.uni-klu.ac.at/dash/ddash/mpdGenerator.php?fragmentlength=15&type=full
  674. xmlNodePtr fragmenturl_node = NULL;
  675. duration_val = xmlGetProp(representation_segmentlist_node, "duration");
  676. timescale_val = xmlGetProp(representation_segmentlist_node, "timescale");
  677. if (duration_val) {
  678. rep->fragment_duration = (int64_t) strtoll(duration_val, NULL, 10);
  679. xmlFree(duration_val);
  680. }
  681. if (timescale_val) {
  682. rep->fragment_timescale = (int64_t) strtoll(timescale_val, NULL, 10);
  683. xmlFree(timescale_val);
  684. }
  685. fragmenturl_node = xmlFirstElementChild(representation_segmentlist_node);
  686. while (fragmenturl_node) {
  687. ret = parse_manifest_segmenturlnode(s, rep, fragmenturl_node,
  688. baseurl_nodes,
  689. rep_id_val,
  690. rep_bandwidth_val);
  691. if (ret < 0) {
  692. return ret;
  693. }
  694. fragmenturl_node = xmlNextElementSibling(fragmenturl_node);
  695. }
  696. fragment_timeline_node = find_child_node_by_name(representation_segmenttemplate_node, "SegmentTimeline");
  697. if (!fragment_timeline_node)
  698. fragment_timeline_node = find_child_node_by_name(fragment_template_node, "SegmentTimeline");
  699. if (fragment_timeline_node) {
  700. fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node);
  701. while (fragment_timeline_node) {
  702. ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node);
  703. if (ret < 0) {
  704. return ret;
  705. }
  706. fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node);
  707. }
  708. }
  709. } else {
  710. free_representation(rep);
  711. rep = NULL;
  712. av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id[%s] \n", (const char *)rep_id_val);
  713. }
  714. if (rep) {
  715. if (rep->fragment_duration > 0 && !rep->fragment_timescale)
  716. rep->fragment_timescale = 1;
  717. if (type == AVMEDIA_TYPE_VIDEO) {
  718. rep->rep_idx = video_rep_idx;
  719. c->cur_video = rep;
  720. } else {
  721. rep->rep_idx = audio_rep_idx;
  722. c->cur_audio = rep;
  723. }
  724. }
  725. }
  726. video_rep_idx += type == AVMEDIA_TYPE_VIDEO;
  727. audio_rep_idx += type == AVMEDIA_TYPE_AUDIO;
  728. end:
  729. if (rep_id_val)
  730. xmlFree(rep_id_val);
  731. if (rep_bandwidth_val)
  732. xmlFree(rep_bandwidth_val);
  733. return ret;
  734. }
  735. static int parse_manifest_adaptationset(AVFormatContext *s, const char *url,
  736. xmlNodePtr adaptionset_node,
  737. xmlNodePtr mpd_baseurl_node,
  738. xmlNodePtr period_baseurl_node)
  739. {
  740. int ret = 0;
  741. xmlNodePtr fragment_template_node = NULL;
  742. xmlNodePtr content_component_node = NULL;
  743. xmlNodePtr adaptionset_baseurl_node = NULL;
  744. xmlNodePtr node = NULL;
  745. node = xmlFirstElementChild(adaptionset_node);
  746. while (node) {
  747. if (!av_strcasecmp(node->name, (const char *)"SegmentTemplate")) {
  748. fragment_template_node = node;
  749. } else if (!av_strcasecmp(node->name, (const char *)"ContentComponent")) {
  750. content_component_node = node;
  751. } else if (!av_strcasecmp(node->name, (const char *)"BaseURL")) {
  752. adaptionset_baseurl_node = node;
  753. } else if (!av_strcasecmp(node->name, (const char *)"Representation")) {
  754. ret = parse_manifest_representation(s, url, node,
  755. adaptionset_node,
  756. mpd_baseurl_node,
  757. period_baseurl_node,
  758. fragment_template_node,
  759. content_component_node,
  760. adaptionset_baseurl_node);
  761. if (ret < 0) {
  762. return ret;
  763. }
  764. }
  765. node = xmlNextElementSibling(node);
  766. }
  767. return 0;
  768. }
  769. static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
  770. {
  771. DASHContext *c = s->priv_data;
  772. int ret = 0;
  773. int close_in = 0;
  774. uint8_t *new_url = NULL;
  775. int64_t filesize = 0;
  776. char *buffer = NULL;
  777. AVDictionary *opts = NULL;
  778. xmlDoc *doc = NULL;
  779. xmlNodePtr root_element = NULL;
  780. xmlNodePtr node = NULL;
  781. xmlNodePtr period_node = NULL;
  782. xmlNodePtr mpd_baseurl_node = NULL;
  783. xmlNodePtr period_baseurl_node = NULL;
  784. xmlNodePtr adaptionset_node = NULL;
  785. xmlAttrPtr attr = NULL;
  786. char *val = NULL;
  787. uint32_t perdiod_duration_sec = 0;
  788. uint32_t perdiod_start_sec = 0;
  789. int32_t audio_rep_idx = 0;
  790. int32_t video_rep_idx = 0;
  791. if (!in) {
  792. close_in = 1;
  793. set_httpheader_options(c, &opts);
  794. ret = avio_open2(&in, url, AVIO_FLAG_READ, c->interrupt_callback, &opts);
  795. av_dict_free(&opts);
  796. if (ret < 0)
  797. return ret;
  798. }
  799. if (av_opt_get(in, "location", AV_OPT_SEARCH_CHILDREN, &new_url) >= 0) {
  800. c->base_url = av_strdup(new_url);
  801. } else {
  802. c->base_url = av_strdup(url);
  803. }
  804. filesize = avio_size(in);
  805. if (filesize <= 0) {
  806. filesize = 8 * 1024;
  807. }
  808. buffer = av_mallocz(filesize);
  809. if (!buffer) {
  810. av_free(c->base_url);
  811. return AVERROR(ENOMEM);
  812. }
  813. filesize = avio_read(in, buffer, filesize);
  814. if (filesize <= 0) {
  815. av_log(s, AV_LOG_ERROR, "Unable to read to offset '%s'\n", url);
  816. ret = AVERROR_INVALIDDATA;
  817. } else {
  818. LIBXML_TEST_VERSION
  819. doc = xmlReadMemory(buffer, filesize, c->base_url, NULL, 0);
  820. root_element = xmlDocGetRootElement(doc);
  821. node = root_element;
  822. if (!node) {
  823. ret = AVERROR_INVALIDDATA;
  824. av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - missing root node\n", url);
  825. goto cleanup;
  826. }
  827. if (node->type != XML_ELEMENT_NODE ||
  828. av_strcasecmp(node->name, (const char *)"MPD")) {
  829. ret = AVERROR_INVALIDDATA;
  830. av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - wrong root node name[%s] type[%d]\n", url, node->name, (int)node->type);
  831. goto cleanup;
  832. }
  833. val = xmlGetProp(node, "type");
  834. if (!val) {
  835. av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - missing type attrib\n", url);
  836. ret = AVERROR_INVALIDDATA;
  837. goto cleanup;
  838. }
  839. if (!av_strcasecmp(val, (const char *)"dynamic"))
  840. c->is_live = 1;
  841. xmlFree(val);
  842. attr = node->properties;
  843. while (attr) {
  844. val = xmlGetProp(node, attr->name);
  845. if (!av_strcasecmp(attr->name, (const char *)"availabilityStartTime")) {
  846. c->availability_start_time = get_utc_date_time_insec(s, (const char *)val);
  847. } else if (!av_strcasecmp(attr->name, (const char *)"publishTime")) {
  848. c->publish_time = get_utc_date_time_insec(s, (const char *)val);
  849. } else if (!av_strcasecmp(attr->name, (const char *)"minimumUpdatePeriod")) {
  850. c->minimum_update_period = get_duration_insec(s, (const char *)val);
  851. } else if (!av_strcasecmp(attr->name, (const char *)"timeShiftBufferDepth")) {
  852. c->time_shift_buffer_depth = get_duration_insec(s, (const char *)val);
  853. } else if (!av_strcasecmp(attr->name, (const char *)"minBufferTime")) {
  854. c->min_buffer_time = get_duration_insec(s, (const char *)val);
  855. } else if (!av_strcasecmp(attr->name, (const char *)"suggestedPresentationDelay")) {
  856. c->suggested_presentation_delay = get_duration_insec(s, (const char *)val);
  857. } else if (!av_strcasecmp(attr->name, (const char *)"mediaPresentationDuration")) {
  858. c->media_presentation_duration = get_duration_insec(s, (const char *)val);
  859. }
  860. attr = attr->next;
  861. xmlFree(val);
  862. }
  863. mpd_baseurl_node = find_child_node_by_name(node, "BaseURL");
  864. // at now we can handle only one period, with the longest duration
  865. node = xmlFirstElementChild(node);
  866. while (node) {
  867. if (!av_strcasecmp(node->name, (const char *)"Period")) {
  868. perdiod_duration_sec = 0;
  869. perdiod_start_sec = 0;
  870. attr = node->properties;
  871. while (attr) {
  872. val = xmlGetProp(node, attr->name);
  873. if (!av_strcasecmp(attr->name, (const char *)"duration")) {
  874. perdiod_duration_sec = get_duration_insec(s, (const char *)val);
  875. } else if (!av_strcasecmp(attr->name, (const char *)"start")) {
  876. perdiod_start_sec = get_duration_insec(s, (const char *)val);
  877. }
  878. attr = attr->next;
  879. xmlFree(val);
  880. }
  881. if ((perdiod_duration_sec) >= (c->period_duration)) {
  882. period_node = node;
  883. c->period_duration = perdiod_duration_sec;
  884. c->period_start = perdiod_start_sec;
  885. if (c->period_start > 0)
  886. c->media_presentation_duration = c->period_duration;
  887. }
  888. }
  889. node = xmlNextElementSibling(node);
  890. }
  891. if (!period_node) {
  892. av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - missing Period node\n", url);
  893. ret = AVERROR_INVALIDDATA;
  894. goto cleanup;
  895. }
  896. adaptionset_node = xmlFirstElementChild(period_node);
  897. while (adaptionset_node) {
  898. if (!av_strcasecmp(adaptionset_node->name, (const char *)"BaseURL")) {
  899. period_baseurl_node = adaptionset_node;
  900. } else if (!av_strcasecmp(adaptionset_node->name, (const char *)"AdaptationSet")) {
  901. parse_manifest_adaptationset(s, url, adaptionset_node, mpd_baseurl_node, period_baseurl_node);
  902. }
  903. adaptionset_node = xmlNextElementSibling(adaptionset_node);
  904. }
  905. if (c->cur_video) {
  906. c->cur_video->rep_count = video_rep_idx;
  907. av_log(s, AV_LOG_VERBOSE, "rep_idx[%d]\n", (int)c->cur_video->rep_idx);
  908. av_log(s, AV_LOG_VERBOSE, "rep_count[%d]\n", (int)video_rep_idx);
  909. }
  910. if (c->cur_audio) {
  911. c->cur_audio->rep_count = audio_rep_idx;
  912. }
  913. cleanup:
  914. /*free the document */
  915. xmlFreeDoc(doc);
  916. xmlCleanupParser();
  917. }
  918. av_free(new_url);
  919. av_free(buffer);
  920. if (close_in) {
  921. avio_close(in);
  922. }
  923. return ret;
  924. }
  925. static int64_t calc_cur_seg_no(AVFormatContext *s, struct representation *pls)
  926. {
  927. DASHContext *c = s->priv_data;
  928. int64_t num = 0;
  929. int64_t start_time_offset = 0;
  930. if (c->is_live) {
  931. if (pls->n_fragments) {
  932. num = pls->first_seq_no;
  933. } else if (pls->n_timelines) {
  934. start_time_offset = get_segment_start_time_based_on_timeline(pls, 0xFFFFFFFF) - pls->timelines[pls->first_seq_no]->starttime; // total duration of playlist
  935. if (start_time_offset < 60 * pls->fragment_timescale)
  936. start_time_offset = 0;
  937. else
  938. start_time_offset = start_time_offset - 60 * pls->fragment_timescale;
  939. num = calc_next_seg_no_from_timelines(pls, pls->timelines[pls->first_seq_no]->starttime + start_time_offset);
  940. if (num == -1)
  941. num = pls->first_seq_no;
  942. } else if (pls->fragment_duration){
  943. if (pls->presentation_timeoffset) {
  944. num = pls->presentation_timeoffset * pls->fragment_timescale / pls->fragment_duration;
  945. } else if (c->publish_time > 0 && !c->availability_start_time) {
  946. num = pls->first_seq_no + (((c->publish_time - c->availability_start_time) - c->suggested_presentation_delay) * pls->fragment_timescale) / pls->fragment_duration;
  947. } else {
  948. num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time) - c->suggested_presentation_delay) * pls->fragment_timescale) / pls->fragment_duration;
  949. }
  950. }
  951. } else {
  952. num = pls->first_seq_no;
  953. }
  954. return num;
  955. }
  956. static int64_t calc_min_seg_no(AVFormatContext *s, struct representation *pls)
  957. {
  958. DASHContext *c = s->priv_data;
  959. int64_t num = 0;
  960. if (c->is_live && pls->fragment_duration) {
  961. num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time) - c->time_shift_buffer_depth) * pls->fragment_timescale) / pls->fragment_duration;
  962. } else {
  963. num = pls->first_seq_no;
  964. }
  965. return num;
  966. }
  967. static int64_t calc_max_seg_no(struct representation *pls, DASHContext *c)
  968. {
  969. int64_t num = 0;
  970. if (pls->n_fragments) {
  971. num = pls->first_seq_no + pls->n_fragments - 1;
  972. } else if (pls->n_timelines) {
  973. int i = 0;
  974. num = pls->first_seq_no + pls->n_timelines - 1;
  975. for (i = 0; i < pls->n_timelines; i++) {
  976. num += pls->timelines[i]->repeat;
  977. }
  978. } else if (c->is_live && pls->fragment_duration) {
  979. num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time)) * pls->fragment_timescale) / pls->fragment_duration;
  980. } else if (pls->fragment_duration) {
  981. num = pls->first_seq_no + (c->media_presentation_duration * pls->fragment_timescale) / pls->fragment_duration;
  982. }
  983. return num;
  984. }
  985. static void move_timelines(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
  986. {
  987. if (rep_dest && rep_src ) {
  988. free_timelines_list(rep_dest);
  989. rep_dest->timelines = rep_src->timelines;
  990. rep_dest->n_timelines = rep_src->n_timelines;
  991. rep_dest->first_seq_no = rep_src->first_seq_no;
  992. rep_dest->last_seq_no = calc_max_seg_no(rep_dest, c);
  993. rep_src->timelines = NULL;
  994. rep_src->n_timelines = 0;
  995. rep_dest->cur_seq_no = rep_src->cur_seq_no;
  996. }
  997. }
  998. static void move_segments(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
  999. {
  1000. if (rep_dest && rep_src ) {
  1001. free_fragment_list(rep_dest);
  1002. if (rep_src->start_number > (rep_dest->start_number + rep_dest->n_fragments))
  1003. rep_dest->cur_seq_no = 0;
  1004. else
  1005. rep_dest->cur_seq_no += rep_src->start_number - rep_dest->start_number;
  1006. rep_dest->fragments = rep_src->fragments;
  1007. rep_dest->n_fragments = rep_src->n_fragments;
  1008. rep_dest->parent = rep_src->parent;
  1009. rep_dest->last_seq_no = calc_max_seg_no(rep_dest, c);
  1010. rep_src->fragments = NULL;
  1011. rep_src->n_fragments = 0;
  1012. }
  1013. }
  1014. static int refresh_manifest(AVFormatContext *s)
  1015. {
  1016. int ret = 0;
  1017. DASHContext *c = s->priv_data;
  1018. // save current context
  1019. struct representation *cur_video = c->cur_video;
  1020. struct representation *cur_audio = c->cur_audio;
  1021. char *base_url = c->base_url;
  1022. c->base_url = NULL;
  1023. c->cur_video = NULL;
  1024. c->cur_audio = NULL;
  1025. ret = parse_manifest(s, s->filename, NULL);
  1026. if (ret)
  1027. goto finish;
  1028. if (cur_video && cur_video->timelines || cur_audio && cur_audio->timelines) {
  1029. // calc current time
  1030. int64_t currentVideoTime = 0;
  1031. int64_t currentAudioTime = 0;
  1032. if (cur_video && cur_video->timelines)
  1033. currentVideoTime = get_segment_start_time_based_on_timeline(cur_video, cur_video->cur_seq_no) / cur_video->fragment_timescale;
  1034. if (cur_audio && cur_audio->timelines)
  1035. currentAudioTime = get_segment_start_time_based_on_timeline(cur_audio, cur_audio->cur_seq_no) / cur_audio->fragment_timescale;
  1036. // update segments
  1037. if (cur_video && cur_video->timelines) {
  1038. c->cur_video->cur_seq_no = calc_next_seg_no_from_timelines(c->cur_video, currentVideoTime * cur_video->fragment_timescale - 1);
  1039. if (c->cur_video->cur_seq_no >= 0) {
  1040. move_timelines(c->cur_video, cur_video, c);
  1041. }
  1042. }
  1043. if (cur_audio && cur_audio->timelines) {
  1044. c->cur_audio->cur_seq_no = calc_next_seg_no_from_timelines(c->cur_audio, currentAudioTime * cur_audio->fragment_timescale - 1);
  1045. if (c->cur_audio->cur_seq_no >= 0) {
  1046. move_timelines(c->cur_audio, cur_audio, c);
  1047. }
  1048. }
  1049. }
  1050. if (cur_video && cur_video->fragments) {
  1051. move_segments(c->cur_video, cur_video, c);
  1052. }
  1053. if (cur_audio && cur_audio->fragments) {
  1054. move_segments(c->cur_audio, cur_audio, c);
  1055. }
  1056. finish:
  1057. // restore context
  1058. if (c->base_url)
  1059. av_free(base_url);
  1060. else
  1061. c->base_url = base_url;
  1062. if (c->cur_audio)
  1063. free_representation(c->cur_audio);
  1064. if (c->cur_video)
  1065. free_representation(c->cur_video);
  1066. c->cur_audio = cur_audio;
  1067. c->cur_video = cur_video;
  1068. return ret;
  1069. }
  1070. static struct fragment *get_current_fragment(struct representation *pls)
  1071. {
  1072. int64_t min_seq_no = 0;
  1073. int64_t max_seq_no = 0;
  1074. struct fragment *seg = NULL;
  1075. struct fragment *seg_ptr = NULL;
  1076. DASHContext *c = pls->parent->priv_data;
  1077. while (( !ff_check_interrupt(c->interrupt_callback)&& pls->n_fragments > 0)) {
  1078. if (pls->cur_seq_no < pls->n_fragments) {
  1079. seg_ptr = pls->fragments[pls->cur_seq_no];
  1080. seg = av_mallocz(sizeof(struct fragment));
  1081. if (!seg) {
  1082. return NULL;
  1083. }
  1084. seg->url = av_strdup(seg_ptr->url);
  1085. if (!seg->url) {
  1086. av_free(seg);
  1087. return NULL;
  1088. }
  1089. seg->size = seg_ptr->size;
  1090. seg->url_offset = seg_ptr->url_offset;
  1091. return seg;
  1092. } else if (c->is_live) {
  1093. refresh_manifest(pls->parent);
  1094. } else {
  1095. break;
  1096. }
  1097. }
  1098. if (c->is_live) {
  1099. min_seq_no = calc_min_seg_no(pls->parent, pls);
  1100. max_seq_no = calc_max_seg_no(pls, c);
  1101. if (pls->timelines || pls->fragments) {
  1102. refresh_manifest(pls->parent);
  1103. }
  1104. if (pls->cur_seq_no <= min_seq_no) {
  1105. av_log(pls->parent, AV_LOG_VERBOSE, "old fragment: cur[%"PRId64"] min[%"PRId64"] max[%"PRId64"], playlist %d\n", (int64_t)pls->cur_seq_no, min_seq_no, max_seq_no, (int)pls->rep_idx);
  1106. pls->cur_seq_no = calc_cur_seg_no(pls->parent, pls);
  1107. } else if (pls->cur_seq_no > max_seq_no) {
  1108. av_log(pls->parent, AV_LOG_VERBOSE, "new fragment: min[%"PRId64"] max[%"PRId64"], playlist %d\n", min_seq_no, max_seq_no, (int)pls->rep_idx);
  1109. }
  1110. seg = av_mallocz(sizeof(struct fragment));
  1111. if (!seg) {
  1112. return NULL;
  1113. }
  1114. } else if (pls->cur_seq_no <= pls->last_seq_no) {
  1115. seg = av_mallocz(sizeof(struct fragment));
  1116. if (!seg) {
  1117. return NULL;
  1118. }
  1119. }
  1120. if (seg) {
  1121. char tmpfilename[MAX_URL_SIZE];
  1122. ff_dash_fill_tmpl_params(tmpfilename, sizeof(tmpfilename), pls->url_template, 0, pls->cur_seq_no, 0, get_segment_start_time_based_on_timeline(pls, pls->cur_seq_no));
  1123. seg->url = av_strireplace(pls->url_template, pls->url_template, tmpfilename);
  1124. if (!seg->url) {
  1125. av_log(pls->parent, AV_LOG_WARNING, "Unable to resolve template url '%s', try to use origin template\n", pls->url_template);
  1126. seg->url = av_strdup(pls->url_template);
  1127. if (!seg->url) {
  1128. av_log(pls->parent, AV_LOG_ERROR, "Cannot resolve template url '%s'\n", pls->url_template);
  1129. return NULL;
  1130. }
  1131. }
  1132. seg->size = -1;
  1133. }
  1134. return seg;
  1135. }
  1136. enum ReadFromURLMode {
  1137. READ_NORMAL,
  1138. READ_COMPLETE,
  1139. };
  1140. static int read_from_url(struct representation *pls, struct fragment *seg,
  1141. uint8_t *buf, int buf_size,
  1142. enum ReadFromURLMode mode)
  1143. {
  1144. int ret;
  1145. /* limit read if the fragment was only a part of a file */
  1146. if (seg->size >= 0)
  1147. buf_size = FFMIN(buf_size, pls->cur_seg_size - pls->cur_seg_offset);
  1148. if (mode == READ_COMPLETE) {
  1149. ret = avio_read(pls->input, buf, buf_size);
  1150. if (ret < buf_size) {
  1151. av_log(pls->parent, AV_LOG_WARNING, "Could not read complete fragment.\n");
  1152. }
  1153. } else {
  1154. ret = avio_read(pls->input, buf, buf_size);
  1155. }
  1156. if (ret > 0)
  1157. pls->cur_seg_offset += ret;
  1158. return ret;
  1159. }
  1160. static int open_input(DASHContext *c, struct representation *pls, struct fragment *seg)
  1161. {
  1162. AVDictionary *opts = NULL;
  1163. char url[MAX_URL_SIZE];
  1164. int ret;
  1165. set_httpheader_options(c, &opts);
  1166. if (seg->size >= 0) {
  1167. /* try to restrict the HTTP request to the part we want
  1168. * (if this is in fact a HTTP request) */
  1169. av_dict_set_int(&opts, "offset", seg->url_offset, 0);
  1170. av_dict_set_int(&opts, "end_offset", seg->url_offset + seg->size, 0);
  1171. }
  1172. ff_make_absolute_url(url, MAX_URL_SIZE, c->base_url, seg->url);
  1173. av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset %"PRId64", playlist %d\n",
  1174. url, seg->url_offset, pls->rep_idx);
  1175. ret = open_url(pls->parent, &pls->input, url, c->avio_opts, opts, NULL);
  1176. if (ret < 0) {
  1177. goto cleanup;
  1178. }
  1179. /* Seek to the requested position. If this was a HTTP request, the offset
  1180. * should already be where want it to, but this allows e.g. local testing
  1181. * without a HTTP server. */
  1182. if (!ret && seg->url_offset) {
  1183. int64_t seekret = avio_seek(pls->input, seg->url_offset, SEEK_SET);
  1184. if (seekret < 0) {
  1185. av_log(pls->parent, AV_LOG_ERROR, "Unable to seek to offset %"PRId64" of DASH fragment '%s'\n", seg->url_offset, seg->url);
  1186. ret = (int) seekret;
  1187. ff_format_io_close(pls->parent, &pls->input);
  1188. }
  1189. }
  1190. cleanup:
  1191. av_dict_free(&opts);
  1192. pls->cur_seg_offset = 0;
  1193. pls->cur_seg_size = seg->size;
  1194. return ret;
  1195. }
  1196. static int update_init_section(struct representation *pls)
  1197. {
  1198. static const int max_init_section_size = 1024 * 1024;
  1199. DASHContext *c = pls->parent->priv_data;
  1200. int64_t sec_size;
  1201. int64_t urlsize;
  1202. int ret;
  1203. if (!pls->init_section || pls->init_sec_buf)
  1204. return 0;
  1205. ret = open_input(c, pls, pls->init_section);
  1206. if (ret < 0) {
  1207. av_log(pls->parent, AV_LOG_WARNING,
  1208. "Failed to open an initialization section in playlist %d\n",
  1209. pls->rep_idx);
  1210. return ret;
  1211. }
  1212. if (pls->init_section->size >= 0)
  1213. sec_size = pls->init_section->size;
  1214. else if ((urlsize = avio_size(pls->input)) >= 0)
  1215. sec_size = urlsize;
  1216. else
  1217. sec_size = max_init_section_size;
  1218. av_log(pls->parent, AV_LOG_DEBUG,
  1219. "Downloading an initialization section of size %"PRId64"\n",
  1220. sec_size);
  1221. sec_size = FFMIN(sec_size, max_init_section_size);
  1222. av_fast_malloc(&pls->init_sec_buf, &pls->init_sec_buf_size, sec_size);
  1223. ret = read_from_url(pls, pls->init_section, pls->init_sec_buf,
  1224. pls->init_sec_buf_size, READ_COMPLETE);
  1225. ff_format_io_close(pls->parent, &pls->input);
  1226. if (ret < 0)
  1227. return ret;
  1228. pls->init_sec_data_len = ret;
  1229. pls->init_sec_buf_read_offset = 0;
  1230. return 0;
  1231. }
  1232. static int64_t seek_data(void *opaque, int64_t offset, int whence)
  1233. {
  1234. struct representation *v = opaque;
  1235. if (v->n_fragments && !v->init_sec_data_len) {
  1236. return avio_seek(v->input, offset, whence);
  1237. }
  1238. return AVERROR(ENOSYS);
  1239. }
  1240. static int read_data(void *opaque, uint8_t *buf, int buf_size)
  1241. {
  1242. int ret = 0;
  1243. struct representation *v = opaque;
  1244. DASHContext *c = v->parent->priv_data;
  1245. restart:
  1246. if (!v->input) {
  1247. free_fragment(&v->cur_seg);
  1248. v->cur_seg = get_current_fragment(v);
  1249. if (!v->cur_seg) {
  1250. ret = AVERROR_EOF;
  1251. goto end;
  1252. }
  1253. /* load/update Media Initialization Section, if any */
  1254. ret = update_init_section(v);
  1255. if (ret)
  1256. goto end;
  1257. ret = open_input(c, v, v->cur_seg);
  1258. if (ret < 0) {
  1259. if (ff_check_interrupt(c->interrupt_callback)) {
  1260. goto end;
  1261. ret = AVERROR_EXIT;
  1262. }
  1263. av_log(v->parent, AV_LOG_WARNING, "Failed to open fragment of playlist %d\n", v->rep_idx);
  1264. v->cur_seq_no++;
  1265. goto restart;
  1266. }
  1267. }
  1268. if (v->init_sec_buf_read_offset < v->init_sec_data_len) {
  1269. /* Push init section out first before first actual fragment */
  1270. int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size);
  1271. memcpy(buf, v->init_sec_buf, copy_size);
  1272. v->init_sec_buf_read_offset += copy_size;
  1273. ret = copy_size;
  1274. goto end;
  1275. }
  1276. /* check the v->cur_seg, if it is null, get current and double check if the new v->cur_seg*/
  1277. if (!v->cur_seg) {
  1278. v->cur_seg = get_current_fragment(v);
  1279. }
  1280. if (!v->cur_seg) {
  1281. ret = AVERROR_EOF;
  1282. goto end;
  1283. }
  1284. ret = read_from_url(v, v->cur_seg, buf, buf_size, READ_NORMAL);
  1285. if (ret > 0)
  1286. goto end;
  1287. if (!v->is_restart_needed)
  1288. v->cur_seq_no++;
  1289. v->is_restart_needed = 1;
  1290. end:
  1291. return ret;
  1292. }
  1293. static int save_avio_options(AVFormatContext *s)
  1294. {
  1295. DASHContext *c = s->priv_data;
  1296. const char *opts[] = { "headers", "user_agent", "user-agent", "cookies", NULL }, **opt = opts;
  1297. uint8_t *buf = NULL;
  1298. int ret = 0;
  1299. while (*opt) {
  1300. if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
  1301. if (buf[0] != '\0') {
  1302. ret = av_dict_set(&c->avio_opts, *opt, buf, AV_DICT_DONT_STRDUP_VAL);
  1303. if (ret < 0) {
  1304. av_freep(&buf);
  1305. return ret;
  1306. }
  1307. } else {
  1308. av_freep(&buf);
  1309. }
  1310. }
  1311. opt++;
  1312. }
  1313. return ret;
  1314. }
  1315. static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url,
  1316. int flags, AVDictionary **opts)
  1317. {
  1318. av_log(s, AV_LOG_ERROR,
  1319. "A DASH playlist item '%s' referred to an external file '%s'. "
  1320. "Opening this file was forbidden for security reasons\n",
  1321. s->filename, url);
  1322. return AVERROR(EPERM);
  1323. }
  1324. static int reopen_demux_for_component(AVFormatContext *s, struct representation *pls)
  1325. {
  1326. DASHContext *c = s->priv_data;
  1327. AVInputFormat *in_fmt = NULL;
  1328. AVDictionary *in_fmt_opts = NULL;
  1329. uint8_t *avio_ctx_buffer = NULL;
  1330. int ret = 0;
  1331. if (pls->ctx) {
  1332. /* note: the internal buffer could have changed, and be != avio_ctx_buffer */
  1333. av_freep(&pls->pb.buffer);
  1334. memset(&pls->pb, 0x00, sizeof(AVIOContext));
  1335. pls->ctx->pb = NULL;
  1336. avformat_close_input(&pls->ctx);
  1337. pls->ctx = NULL;
  1338. }
  1339. if (!(pls->ctx = avformat_alloc_context())) {
  1340. ret = AVERROR(ENOMEM);
  1341. goto fail;
  1342. }
  1343. avio_ctx_buffer = av_malloc(INITIAL_BUFFER_SIZE);
  1344. if (!avio_ctx_buffer ) {
  1345. ret = AVERROR(ENOMEM);
  1346. avformat_free_context(pls->ctx);
  1347. pls->ctx = NULL;
  1348. goto fail;
  1349. }
  1350. if (c->is_live) {
  1351. ffio_init_context(&pls->pb, avio_ctx_buffer , INITIAL_BUFFER_SIZE, 0, pls, read_data, NULL, NULL);
  1352. } else {
  1353. ffio_init_context(&pls->pb, avio_ctx_buffer , INITIAL_BUFFER_SIZE, 0, pls, read_data, NULL, seek_data);
  1354. }
  1355. pls->pb.seekable = 0;
  1356. if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0)
  1357. goto fail;
  1358. pls->ctx->flags = AVFMT_FLAG_CUSTOM_IO;
  1359. pls->ctx->probesize = 1024 * 4;
  1360. pls->ctx->max_analyze_duration = 4 * AV_TIME_BASE;
  1361. ret = av_probe_input_buffer(&pls->pb, &in_fmt, "", NULL, 0, 0);
  1362. if (ret < 0) {
  1363. av_log(s, AV_LOG_ERROR, "Error when loading first fragment, playlist %d\n", (int)pls->rep_idx);
  1364. avformat_free_context(pls->ctx);
  1365. pls->ctx = NULL;
  1366. goto fail;
  1367. }
  1368. pls->ctx->pb = &pls->pb;
  1369. pls->ctx->io_open = nested_io_open;
  1370. // provide additional information from mpd if available
  1371. ret = avformat_open_input(&pls->ctx, "", in_fmt, &in_fmt_opts); //pls->init_section->url
  1372. av_dict_free(&in_fmt_opts);
  1373. if (ret < 0)
  1374. goto fail;
  1375. if (pls->n_fragments) {
  1376. ret = avformat_find_stream_info(pls->ctx, NULL);
  1377. if (ret < 0)
  1378. goto fail;
  1379. }
  1380. fail:
  1381. return ret;
  1382. }
  1383. static int open_demux_for_component(AVFormatContext *s, struct representation *pls)
  1384. {
  1385. int ret = 0;
  1386. int i;
  1387. pls->parent = s;
  1388. pls->cur_seq_no = calc_cur_seg_no(s, pls);
  1389. pls->last_seq_no = calc_max_seg_no(pls, s->priv_data);
  1390. ret = reopen_demux_for_component(s, pls);
  1391. if (ret < 0) {
  1392. goto fail;
  1393. }
  1394. for (i = 0; i < pls->ctx->nb_streams; i++) {
  1395. AVStream *st = avformat_new_stream(s, NULL);
  1396. AVStream *ist = pls->ctx->streams[i];
  1397. if (!st) {
  1398. ret = AVERROR(ENOMEM);
  1399. goto fail;
  1400. }
  1401. st->id = i;
  1402. avcodec_parameters_copy(st->codecpar, pls->ctx->streams[i]->codecpar);
  1403. avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den);
  1404. }
  1405. return 0;
  1406. fail:
  1407. return ret;
  1408. }
  1409. static int dash_read_header(AVFormatContext *s)
  1410. {
  1411. void *u = (s->flags & AVFMT_FLAG_CUSTOM_IO) ? NULL : s->pb;
  1412. DASHContext *c = s->priv_data;
  1413. int ret = 0;
  1414. int stream_index = 0;
  1415. c->interrupt_callback = &s->interrupt_callback;
  1416. // if the URL context is good, read important options we must broker later
  1417. if (u) {
  1418. update_options(&c->user_agent, "user-agent", u);
  1419. update_options(&c->cookies, "cookies", u);
  1420. update_options(&c->headers, "headers", u);
  1421. }
  1422. if ((ret = parse_manifest(s, s->filename, s->pb)) < 0)
  1423. goto fail;
  1424. if ((ret = save_avio_options(s)) < 0)
  1425. goto fail;
  1426. /* If this isn't a live stream, fill the total duration of the
  1427. * stream. */
  1428. if (!c->is_live) {
  1429. s->duration = (int64_t) c->media_presentation_duration * AV_TIME_BASE;
  1430. }
  1431. /* Open the demuxer for curent video and current audio components if available */
  1432. if (!ret && c->cur_video) {
  1433. ret = open_demux_for_component(s, c->cur_video);
  1434. if (!ret) {
  1435. c->cur_video->stream_index = stream_index;
  1436. ++stream_index;
  1437. } else {
  1438. free_representation(c->cur_video);
  1439. c->cur_video = NULL;
  1440. }
  1441. }
  1442. if (!ret && c->cur_audio) {
  1443. ret = open_demux_for_component(s, c->cur_audio);
  1444. if (!ret) {
  1445. c->cur_audio->stream_index = stream_index;
  1446. ++stream_index;
  1447. } else {
  1448. free_representation(c->cur_audio);
  1449. c->cur_audio = NULL;
  1450. }
  1451. }
  1452. if (!stream_index) {
  1453. ret = AVERROR_INVALIDDATA;
  1454. goto fail;
  1455. }
  1456. /* Create a program */
  1457. if (!ret) {
  1458. AVProgram *program;
  1459. program = av_new_program(s, 0);
  1460. if (!program) {
  1461. goto fail;
  1462. }
  1463. if (c->cur_video) {
  1464. av_program_add_stream_index(s, 0, c->cur_video->stream_index);
  1465. }
  1466. if (c->cur_audio) {
  1467. av_program_add_stream_index(s, 0, c->cur_audio->stream_index);
  1468. }
  1469. }
  1470. return 0;
  1471. fail:
  1472. return ret;
  1473. }
  1474. static int dash_read_packet(AVFormatContext *s, AVPacket *pkt)
  1475. {
  1476. DASHContext *c = s->priv_data;
  1477. int ret = 0;
  1478. struct representation *cur = NULL;
  1479. if (!c->cur_audio && !c->cur_video ) {
  1480. return AVERROR_INVALIDDATA;
  1481. }
  1482. if (c->cur_audio && !c->cur_video) {
  1483. cur = c->cur_audio;
  1484. } else if (!c->cur_audio && c->cur_video) {
  1485. cur = c->cur_video;
  1486. } else if (c->cur_video->cur_timestamp < c->cur_audio->cur_timestamp) {
  1487. cur = c->cur_video;
  1488. } else {
  1489. cur = c->cur_audio;
  1490. }
  1491. if (cur->ctx) {
  1492. while (!ff_check_interrupt(c->interrupt_callback) && !ret) {
  1493. ret = av_read_frame(cur->ctx, pkt);
  1494. if (ret >= 0) {
  1495. /* If we got a packet, return it */
  1496. cur->cur_timestamp = av_rescale(pkt->pts, (int64_t)cur->ctx->streams[0]->time_base.num * 90000, cur->ctx->streams[0]->time_base.den);
  1497. pkt->stream_index = cur->stream_index;
  1498. return 0;
  1499. }
  1500. if (cur->is_restart_needed) {
  1501. cur->cur_seg_offset = 0;
  1502. cur->init_sec_buf_read_offset = 0;
  1503. if (cur->input)
  1504. ff_format_io_close(cur->parent, &cur->input);
  1505. ret = reopen_demux_for_component(s, cur);
  1506. cur->is_restart_needed = 0;
  1507. }
  1508. }
  1509. }
  1510. return AVERROR_EOF;
  1511. }
  1512. static int dash_close(AVFormatContext *s)
  1513. {
  1514. DASHContext *c = s->priv_data;
  1515. if (c->cur_audio) {
  1516. free_representation(c->cur_audio);
  1517. }
  1518. if (c->cur_video) {
  1519. free_representation(c->cur_video);
  1520. }
  1521. av_freep(&c->cookies);
  1522. av_freep(&c->user_agent);
  1523. av_dict_free(&c->avio_opts);
  1524. av_freep(&c->base_url);
  1525. return 0;
  1526. }
  1527. static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t seek_pos_msec, int flags)
  1528. {
  1529. int ret = 0;
  1530. int i = 0;
  1531. int j = 0;
  1532. int64_t duration = 0;
  1533. av_log(pls->parent, AV_LOG_VERBOSE, "DASH seek pos[%"PRId64"ms], playlist %d\n", seek_pos_msec, pls->rep_idx);
  1534. // single fragment mode
  1535. if (pls->n_fragments == 1) {
  1536. pls->cur_timestamp = 0;
  1537. pls->cur_seg_offset = 0;
  1538. ff_read_frame_flush(pls->ctx);
  1539. return av_seek_frame(pls->ctx, -1, seek_pos_msec * 1000, flags);
  1540. }
  1541. if (pls->input)
  1542. ff_format_io_close(pls->parent, &pls->input);
  1543. // find the nearest fragment
  1544. if (pls->n_timelines > 0 && pls->fragment_timescale > 0) {
  1545. int64_t num = pls->first_seq_no;
  1546. av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline start n_timelines[%d] "
  1547. "last_seq_no[%"PRId64"], playlist %d.\n",
  1548. (int)pls->n_timelines, (int64_t)pls->last_seq_no, (int)pls->rep_idx);
  1549. for (i = 0; i < pls->n_timelines; i++) {
  1550. if (pls->timelines[i]->starttime > 0) {
  1551. duration = pls->timelines[i]->starttime;
  1552. }
  1553. duration += pls->timelines[i]->duration;
  1554. if (seek_pos_msec < ((duration * 1000) / pls->fragment_timescale)) {
  1555. goto set_seq_num;
  1556. }
  1557. for (j = 0; j < pls->timelines[i]->repeat; j++) {
  1558. duration += pls->timelines[i]->duration;
  1559. num++;
  1560. if (seek_pos_msec < ((duration * 1000) / pls->fragment_timescale)) {
  1561. goto set_seq_num;
  1562. }
  1563. }
  1564. num++;
  1565. }
  1566. set_seq_num:
  1567. pls->cur_seq_no = num > pls->last_seq_no ? pls->last_seq_no : num;
  1568. av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline end cur_seq_no[%"PRId64"], playlist %d.\n",
  1569. (int64_t)pls->cur_seq_no, (int)pls->rep_idx);
  1570. } else if (pls->fragment_duration > 0) {
  1571. pls->cur_seq_no = pls->first_seq_no + ((seek_pos_msec * pls->fragment_timescale) / pls->fragment_duration) / 1000;
  1572. } else {
  1573. av_log(pls->parent, AV_LOG_ERROR, "dash_seek missing fragment_duration\n");
  1574. pls->cur_seq_no = pls->first_seq_no;
  1575. }
  1576. pls->cur_timestamp = 0;
  1577. pls->cur_seg_offset = 0;
  1578. pls->init_sec_buf_read_offset = 0;
  1579. ret = reopen_demux_for_component(s, pls);
  1580. return ret;
  1581. }
  1582. static int dash_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
  1583. {
  1584. int ret = 0;
  1585. DASHContext *c = s->priv_data;
  1586. int64_t seek_pos_msec = av_rescale_rnd(timestamp, 1000,
  1587. s->streams[stream_index]->time_base.den,
  1588. flags & AVSEEK_FLAG_BACKWARD ?
  1589. AV_ROUND_DOWN : AV_ROUND_UP);
  1590. if ((flags & AVSEEK_FLAG_BYTE) || c->is_live)
  1591. return AVERROR(ENOSYS);
  1592. if (c->cur_audio) {
  1593. ret = dash_seek(s, c->cur_audio, seek_pos_msec, flags);
  1594. }
  1595. if (!ret && c->cur_video) {
  1596. ret = dash_seek(s, c->cur_video, seek_pos_msec, flags);
  1597. }
  1598. return ret;
  1599. }
  1600. static int dash_probe(AVProbeData *p)
  1601. {
  1602. if (!av_stristr(p->buf, "<MPD"))
  1603. return 0;
  1604. if (av_stristr(p->buf, "dash:profile:isoff-on-demand:2011") ||
  1605. av_stristr(p->buf, "dash:profile:isoff-live:2011") ||
  1606. av_stristr(p->buf, "dash:profile:isoff-live:2012") ||
  1607. av_stristr(p->buf, "dash:profile:isoff-main:2011")) {
  1608. return AVPROBE_SCORE_MAX;
  1609. }
  1610. if (av_stristr(p->buf, "dash:profile")) {
  1611. return AVPROBE_SCORE_MAX;
  1612. }
  1613. return 0;
  1614. }
  1615. #define OFFSET(x) offsetof(DASHContext, x)
  1616. #define FLAGS AV_OPT_FLAG_DECODING_PARAM
  1617. static const AVOption dash_options[] = {
  1618. {"allowed_extensions", "List of file extensions that dash is allowed to access",
  1619. OFFSET(allowed_extensions), AV_OPT_TYPE_STRING,
  1620. {.str = "aac,m4a,m4s,m4v,mov,mp4"},
  1621. INT_MIN, INT_MAX, FLAGS},
  1622. {NULL}
  1623. };
  1624. static const AVClass dash_class = {
  1625. .class_name = "dash",
  1626. .item_name = av_default_item_name,
  1627. .option = dash_options,
  1628. .version = LIBAVUTIL_VERSION_INT,
  1629. };
  1630. AVInputFormat ff_dash_demuxer = {
  1631. .name = "dash",
  1632. .long_name = NULL_IF_CONFIG_SMALL("Dynamic Adaptive Streaming over HTTP"),
  1633. .priv_class = &dash_class,
  1634. .priv_data_size = sizeof(DASHContext),
  1635. .read_probe = dash_probe,
  1636. .read_header = dash_read_header,
  1637. .read_packet = dash_read_packet,
  1638. .read_close = dash_close,
  1639. .read_seek = dash_read_seek,
  1640. .flags = AVFMT_NO_BYTE_SEEK,
  1641. };