FFmpeg
Loading...
Searching...
No Matches
dashdec.c
Go to the documentation of this file.
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 <time.h>
24#include "libavutil/avassert.h"
25#include "libavutil/bprint.h"
26#include "libavutil/mem.h"
27#include "libavutil/opt.h"
28#include "libavutil/time.h"
30#include "internal.h"
31#include "avio_internal.h"
32#include "dash.h"
33#include "demux.h"
34#include "url.h"
35
36#define INITIAL_BUFFER_SIZE 32768
37#define MAX_TIMELINE_SEGMENTS (1 << 24)
38
44
45/*
46 * reference to : ISO_IEC_23009-1-DASH-2012
47 * Section: 5.3.9.6.2
48 * Table: Table 17 — Semantics of SegmentTimeline element
49 * */
50struct timeline {
51 /* starttime: Element or Attribute Name
52 * specifies the MPD start time, in @timescale units,
53 * the first Segment in the series starts relative to the beginning of the Period.
54 * The value of this attribute must be equal to or greater than the sum of the previous S
55 * element earliest presentation time and the sum of the contiguous Segment durations.
56 * If the value of the attribute is greater than what is expressed by the previous S element,
57 * it expresses discontinuities in the timeline.
58 * If not present then the value shall be assumed to be zero for the first S element
59 * and for the subsequent S elements, the value shall be assumed to be the sum of
60 * the previous S element's earliest presentation time and contiguous duration
61 * (i.e. previous S@starttime + @duration * (@repeat + 1)).
62 * */
64 /* repeat: Element or Attribute Name
65 * specifies the repeat count of the number of following contiguous Segments with
66 * the same duration expressed by the value of @duration. This value is zero-based
67 * (e.g. a value of three means four Segments in the contiguous series).
68 * */
70 /* duration: Element or Attribute Name
71 * specifies the Segment duration, in units of the value of the @timescale.
72 * */
74};
75
76/*
77 * Each playlist has its own demuxer. If it is currently active,
78 * it has an opened AVIOContext too, and potentially an AVPacket
79 * containing the next packet from this stream.
80 */
89
90 char *id;
91 char *lang;
94 char *codecs;
96 AVStream **assoc_stream; /* demuxer streams associated with this representation */
98
100 struct fragment **fragments; /* VOD list of fragment for profile */
101
104
107 int64_t start_number; /* used in case when we have dynamic list of segment to know which segments are new one*/
108
111
113
118 int n_open_failures; /* consecutive open_input failures since last good read */
119
120 /* Currently active Media Initialization Section */
122 uint8_t *init_sec_buf;
128};
129
173
174static int ishttp(const char *url)
175{
176 const char *proto_name = avio_find_protocol_name(url);
177 return proto_name && av_strstart(proto_name, "http", NULL);
178}
179
180static int add_url_size(int *url_size, uint64_t len)
181{
182 if (len > INT_MAX - 0x3F - *url_size)
183 return AVERROR(ERANGE);
184 *url_size = FFALIGN(*url_size + len, 64);
185 return 0;
186}
187
189{
190 return av_gettime() / 1000000;
191}
192
193static int64_t get_utc_date_time_insec(AVFormatContext *s, const char *datetime)
194{
195 struct tm timeinfo;
196 int year = 0;
197 int month = 0;
198 int day = 0;
199 int hour = 0;
200 int minute = 0;
201 int ret = 0;
202 float second = 0.0;
203
204 /* ISO-8601 date parser */
205 if (!datetime)
206 return 0;
207
208 ret = sscanf(datetime, "%d-%d-%dT%d:%d:%fZ", &year, &month, &day, &hour, &minute, &second);
209 /* year, month, day, hour, minute, second 6 arguments */
210 if (ret != 6) {
211 av_log(s, AV_LOG_WARNING, "get_utc_date_time_insec get a wrong time format\n");
212 }
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;
219
220 return av_timegm(&timeinfo);
221}
222
223static uint32_t get_duration_insec(AVFormatContext *s, const char *duration)
224{
225 /* ISO-8601 duration parser */
226 uint32_t days = 0;
227 uint32_t hours = 0;
228 uint32_t mins = 0;
229 uint32_t secs = 0;
230 int size = 0;
231 float value = 0;
232 char type = '\0';
233 const char *ptr = duration;
234
235 while (*ptr) {
236 if (*ptr == 'P' || *ptr == 'T') {
237 ptr++;
238 continue;
239 }
240
241 if (sscanf(ptr, "%f%c%n", &value, &type, &size) != 2) {
242 av_log(s, AV_LOG_WARNING, "get_duration_insec get a wrong time format\n");
243 return 0; /* parser error */
244 }
245 switch (type) {
246 case 'D':
247 days = (uint32_t)value;
248 break;
249 case 'H':
250 hours = (uint32_t)value;
251 break;
252 case 'M':
253 mins = (uint32_t)value;
254 break;
255 case 'S':
256 secs = (uint32_t)value;
257 break;
258 default:
259 // handle invalid type
260 break;
261 }
262 ptr += size;
263 }
264 return ((days * 24 + hours) * 60 + mins) * 60 + secs;
265}
266
268{
270 int64_t i = 0;
271 int64_t j = 0;
272 int64_t num = 0;
273
274 cur_seq_no -= pls->first_seq_no;
275 if (pls->n_timelines) {
276 for (i = 0; i < pls->n_timelines; i++) {
277 if (pls->timelines[i]->starttime > 0) {
279 }
280 if (num == cur_seq_no)
281 goto finish;
282
283 start_time += pls->timelines[i]->duration;
284
285 if (pls->timelines[i]->repeat == -1) {
286 start_time = pls->timelines[i]->duration * cur_seq_no;
287 goto finish;
288 }
289
290 for (j = 0; j < pls->timelines[i]->repeat; j++) {
291 num++;
292 if (num == cur_seq_no)
293 goto finish;
294 start_time += pls->timelines[i]->duration;
295 }
296 num++;
297 }
298 }
299finish:
300 return start_time;
301}
302
304{
305 int64_t i = 0;
306 int64_t j = 0;
307 int64_t num = 0;
309
310 for (i = 0; i < pls->n_timelines; i++) {
311 if (pls->timelines[i]->starttime > 0) {
313 }
314 if (start_time > cur_time)
315 goto finish;
316
317 start_time += pls->timelines[i]->duration;
318 for (j = 0; j < pls->timelines[i]->repeat; j++) {
319 num++;
320 if (start_time > cur_time)
321 goto finish;
322 start_time += pls->timelines[i]->duration;
323 }
324 num++;
325 }
326
327 return -1;
328
329finish:
330 return num + pls->first_seq_no;
331}
332
333static void free_fragment(struct fragment **seg)
334{
335 if (!(*seg)) {
336 return;
337 }
338 av_freep(&(*seg)->url);
339 av_freep(seg);
340}
341
342static void free_fragment_list(struct representation *pls)
343{
344 int i;
345
346 for (i = 0; i < pls->n_fragments; i++) {
347 free_fragment(&pls->fragments[i]);
348 }
349 av_freep(&pls->fragments);
350 pls->n_fragments = 0;
351}
352
353static void free_timelines_list(struct representation *pls)
354{
355 int i;
356
357 for (i = 0; i < pls->n_timelines; i++) {
358 av_freep(&pls->timelines[i]);
359 }
360 av_freep(&pls->timelines);
361 pls->n_timelines = 0;
362}
363
364static void free_representation(struct representation *pls)
365{
368 free_fragment(&pls->cur_seg);
370 av_freep(&pls->init_sec_buf);
371 av_freep(&pls->pb.pub.buffer);
372 ff_format_io_close(pls->parent, &pls->input);
373 if (pls->ctx) {
374 pls->ctx->pb = NULL;
376 }
377
378 av_freep(&pls->assoc_stream);
379 av_freep(&pls->url_template);
380 av_freep(&pls->lang);
381 av_freep(&pls->dependencyid);
382 av_freep(&pls->codecs);
383 av_freep(&pls->id);
384 av_freep(&pls);
385}
386
388{
389 int i;
390 for (i = 0; i < c->n_videos; i++) {
391 struct representation *pls = c->videos[i];
393 }
394 av_freep(&c->videos);
395 c->n_videos = 0;
396}
397
399{
400 int i;
401 for (i = 0; i < c->n_audios; i++) {
402 struct representation *pls = c->audios[i];
404 }
405 av_freep(&c->audios);
406 c->n_audios = 0;
407}
408
410{
411 int i;
412 for (i = 0; i < c->n_subtitles; i++) {
413 struct representation *pls = c->subtitles[i];
415 }
416 av_freep(&c->subtitles);
417 c->n_subtitles = 0;
418}
419
420static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
421 AVDictionary **opts, AVDictionary *opts2, int *is_http)
422{
423 DASHContext *c = s->priv_data;
425 const char *proto_name = NULL;
426 int proto_name_len;
427 int ret;
428
429 if (av_strstart(url, "crypto", NULL)) {
430 if (url[6] == '+' || url[6] == ':')
431 proto_name = avio_find_protocol_name(url + 7);
432 }
433
434 if (!proto_name)
435 proto_name = avio_find_protocol_name(url);
436
437 if (!proto_name)
438 return AVERROR_INVALIDDATA;
439
440 proto_name_len = strlen(proto_name);
441 // only http(s) & file are allowed
442 if (av_strstart(proto_name, "file", NULL)) {
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",
447 url);
448 return AVERROR_INVALIDDATA;
449 }
450 } else if (av_strstart(proto_name, "http", NULL)) {
451 ;
452 } else
453 return AVERROR_INVALIDDATA;
454
455 if (!strncmp(proto_name, url, proto_name_len) && url[proto_name_len] == ':')
456 ;
457 else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, proto_name_len) && url[7 + proto_name_len] == ':')
458 ;
459 else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
460 return AVERROR_INVALIDDATA;
461
462 av_freep(pb);
463 av_dict_copy(&tmp, *opts, 0);
464 av_dict_copy(&tmp, opts2, 0);
465 ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);
466 if (ret >= 0) {
467 // update cookies on http response with setcookies.
468 char *new_cookies = NULL;
469
470 if (!(s->flags & AVFMT_FLAG_CUSTOM_IO))
471 av_opt_get(*pb, "cookies", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&new_cookies);
472
473 if (new_cookies) {
474 av_dict_set(opts, "cookies", new_cookies, AV_DICT_DONT_STRDUP_VAL);
475 }
476
477 }
478
480
481 if (is_http)
482 *is_http = av_strstart(proto_name, "http", NULL);
483
484 return ret;
485}
486
487static char *get_content_url(xmlNodePtr *baseurl_nodes,
488 int n_baseurl_nodes,
489 int max_url_size,
490 char *rep_id_val,
491 char *rep_bandwidth_val,
492 char *val)
493{
494 int i;
495 char *text;
496 char *url = NULL;
497 char *tmp_str = av_mallocz(max_url_size);
498
499 if (!tmp_str)
500 return NULL;
501
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);
507 if (text) {
508 memset(tmp_str, 0, max_url_size);
509 ff_make_absolute_url(tmp_str, max_url_size, "", text);
510 xmlFree(text);
511 }
512 }
513 }
514
515 if (val)
516 ff_make_absolute_url(tmp_str, max_url_size, tmp_str, val);
517
518 if (rep_id_val) {
519 url = av_strireplace(tmp_str, "$RepresentationID$", rep_id_val);
520 if (!url) {
521 goto end;
522 }
523 av_strlcpy(tmp_str, url, max_url_size);
524 }
525 if (rep_bandwidth_val && tmp_str[0] != '\0') {
526 // free any previously assigned url before reassigning
527 av_free(url);
528 url = av_strireplace(tmp_str, "$Bandwidth$", rep_bandwidth_val);
529 if (!url) {
530 goto end;
531 }
532 }
533end:
534 av_free(tmp_str);
535 return url;
536}
537
538static char *get_val_from_nodes_tab(xmlNodePtr *nodes, const int n_nodes, const char *attrname)
539{
540 int i;
541 char *val;
542
543 for (i = 0; i < n_nodes; ++i) {
544 if (nodes[i]) {
545 val = xmlGetProp(nodes[i], attrname);
546 if (val)
547 return val;
548 }
549 }
550
551 return NULL;
552}
553
554static xmlNodePtr find_child_node_by_name(xmlNodePtr rootnode, const char *nodename)
555{
556 xmlNodePtr node = rootnode;
557 if (!node) {
558 return NULL;
559 }
560
561 node = xmlFirstElementChild(node);
562 while (node) {
563 if (!av_strcasecmp(node->name, nodename)) {
564 return node;
565 }
566 node = xmlNextElementSibling(node);
567 }
568 return NULL;
569}
570
571static enum AVMediaType get_content_type(xmlNodePtr node)
572{
574 int i = 0;
575 const char *attr;
576 char *val = NULL;
577
578 if (node) {
579 for (i = 0; i < 2; i++) {
580 attr = i ? "mimeType" : "contentType";
581 val = xmlGetProp(node, attr);
582 if (val) {
583 if (av_stristr(val, "video")) {
585 } else if (av_stristr(val, "audio")) {
587 } else if (av_stristr(val, "text")) {
589 }
590 xmlFree(val);
591 }
592 }
593 }
594 return type;
595}
596
598{
599 struct fragment *seg = av_mallocz(sizeof(struct fragment));
600
601 if (!seg)
602 return NULL;
603
604 seg->size = -1;
605 if (range) {
606 char *str_end_offset;
607 char *str_offset = av_strtok(range, "-", &str_end_offset);
608 if (!str_offset || !str_end_offset) {
609 av_log(s, AV_LOG_WARNING, "%s will get invalid range\n", range);
610 av_freep(&seg);
611 return NULL;
612 }
613 seg->url_offset = strtoll(str_offset, NULL, 10);
614 seg->size = strtoll(str_end_offset, NULL, 10) - seg->url_offset + 1;
615 }
616
617 return seg;
618}
619
621 xmlNodePtr fragmenturl_node,
622 xmlNodePtr *baseurl_nodes,
623 char *rep_id_val,
624 char *rep_bandwidth_val)
625{
626 DASHContext *c = s->priv_data;
627 char *initialization_val = NULL;
628 char *media_val = NULL;
629 char *range_val = NULL;
630 int max_url_size = c ? c->max_url_size: MAX_URL_SIZE;
631 int err;
632
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) {
638 rep->init_section = get_fragment(s, range_val);
639 xmlFree(range_val);
640 if (!rep->init_section) {
641 xmlFree(initialization_val);
642 return AVERROR(ENOMEM);
643 }
644 rep->init_section->url = get_content_url(baseurl_nodes, 4,
645 max_url_size,
646 rep_id_val,
647 rep_bandwidth_val,
648 initialization_val);
649 xmlFree(initialization_val);
650 if (!rep->init_section->url) {
651 av_freep(&rep->init_section);
652 return AVERROR(ENOMEM);
653 }
654 }
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) {
659 struct fragment *seg = get_fragment(s, range_val);
660 xmlFree(range_val);
661 if (!seg) {
662 xmlFree(media_val);
663 return AVERROR(ENOMEM);
664 }
665 seg->url = get_content_url(baseurl_nodes, 4,
666 max_url_size,
667 rep_id_val,
668 rep_bandwidth_val,
669 media_val);
670 xmlFree(media_val);
671 if (!seg->url) {
672 av_free(seg);
673 return AVERROR(ENOMEM);
674 }
675 err = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg);
676 if (err < 0) {
677 free_fragment(&seg);
678 return err;
679 }
680 }
681 }
682
683 return 0;
684}
685
687 xmlNodePtr fragment_timeline_node)
688{
689 xmlAttrPtr attr = NULL;
690 char *val = NULL;
691 int err;
692
693 if (!av_strcasecmp(fragment_timeline_node->name, "S")) {
694 struct timeline *tml = av_mallocz(sizeof(struct timeline));
695 if (!tml) {
696 return AVERROR(ENOMEM);
697 }
698 attr = fragment_timeline_node->properties;
699 while (attr) {
700 val = xmlGetProp(fragment_timeline_node, attr->name);
701
702 if (!val) {
703 av_free(tml);
704 return AVERROR(ENOMEM);
705 }
706
707 if (!av_strcasecmp(attr->name, "t")) {
708 tml->starttime = (int64_t)strtoll(val, NULL, 10);
709 } else if (!av_strcasecmp(attr->name, "r")) {
710 tml->repeat =(int64_t) strtoll(val, NULL, 10);
711 } else if (!av_strcasecmp(attr->name, "d")) {
712 tml->duration = (int64_t)strtoll(val, NULL, 10);
713 }
714 attr = attr->next;
715 xmlFree(val);
716 }
717 err = av_dynarray_add_nofree(&rep->timelines, &rep->n_timelines, tml);
718 if (err < 0) {
719 av_free(tml);
720 return err;
721 }
722 }
723
724 return 0;
725}
726
727static int resolve_content_path(AVFormatContext *s, const char *url, int *max_url_size, xmlNodePtr *baseurl_nodes, int n_baseurl_nodes)
728{
729 char *tmp_str = NULL;
730 char *path = NULL;
731 xmlNodePtr node = NULL;
732 char *baseurl = NULL;
733 char *root_url = NULL;
734 char *text = NULL;
735 char *tmp = NULL;
736 int isRootHttp = 0;
737 char token ='/';
738 int start = 0;
739 int rootId = 0;
740 int updated = 0;
741 int size = 0;
742 int i;
743 int tmp_max_url_size = 0;
744 uint64_t url_len = strlen(url);
745
746 for (i = n_baseurl_nodes-1; i >= 0 ; i--) {
747 text = xmlNodeGetContent(baseurl_nodes[i]);
748 if (!text)
749 continue;
750 url_len += strlen(text);
751 if (ishttp(text)) {
752 xmlFree(text);
753 break;
754 }
755 xmlFree(text);
756 }
757
758 updated = add_url_size(&tmp_max_url_size, url_len);
759 if (updated < 0)
760 goto end;
761 path = av_mallocz(tmp_max_url_size + 2);
762 tmp_str = av_mallocz(tmp_max_url_size + 2);
763 if (!tmp_str || !path) {
764 updated = AVERROR(ENOMEM);
765 goto end;
766 }
767
768 if (ishttp(url)) {
769 const char *colon = strchr(url, ':');
770 if (colon && colon[1] == '/' && colon[2] == '/') {
771 updated = ff_make_absolute_url(path, tmp_max_url_size + 2, url, ".");
772 if (updated < 0)
773 goto end;
774 }
775 }
776 for (rootId = n_baseurl_nodes - 1; rootId > 0; rootId --) {
777 if (!(node = baseurl_nodes[rootId])) {
778 continue;
779 }
780 text = xmlNodeGetContent(node);
781 if (!text) {
782 updated = AVERROR(ENOMEM);
783 goto end;
784 }
785 if (ishttp(text)) {
786 xmlFree(text);
787 break;
788 }
789 xmlFree(text);
790 }
791
792 node = baseurl_nodes[rootId];
793 baseurl = xmlNodeGetContent(node);
794 if (baseurl)
795 tmp = xmlRealloc(baseurl, xmlStrlen(baseurl) + 2);
796 if (!tmp) {
797 updated = AVERROR(ENOMEM);
798 goto end;
799 }
800 baseurl = tmp;
801 root_url = (av_strcasecmp(baseurl, "")) ? baseurl : path;
802 if (node) {
803 xmlChar *escaped = xmlEncodeSpecialChars(NULL, root_url);
804 if (!escaped) {
805 updated = AVERROR(ENOMEM);
806 goto end;
807 }
808 xmlNodeSetContent(node, escaped);
809 xmlFree(escaped);
810 updated = 1;
811 }
812
813 size = strlen(root_url);
814 isRootHttp = ishttp(root_url);
815
816 if (size > 0 && root_url[size - 1] != token) {
817 av_strlcat(root_url, "/", size + 2);
818 }
819
820 for (i = 0; i < n_baseurl_nodes; ++i) {
821 if (i == rootId) {
822 continue;
823 }
824 text = xmlNodeGetContent(baseurl_nodes[i]);
825 if (text && !av_strstart(text, "/", NULL)) {
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);
829 }
830 start = (text[0] == token);
831 if (start && av_stristr(tmp_str, text)) {
832 char *p = tmp_str;
833 if (!av_strncasecmp(tmp_str, "http://", 7)) {
834 p += 7;
835 } else if (!av_strncasecmp(tmp_str, "https://", 8)) {
836 p += 8;
837 }
838 p = strchr(p, '/');
839 memset(p + 1, 0, strlen(p));
840 }
841 av_strlcat(tmp_str, text + start, tmp_max_url_size + 2);
842 xmlFree(text);
843 xmlChar* escaped = xmlEncodeSpecialChars(NULL, tmp_str);
844 if (!escaped) {
845 updated = AVERROR(ENOMEM);
846 goto end;
847 }
848 xmlNodeSetContent(baseurl_nodes[i], escaped);
849 updated = 1;
850 xmlFree(escaped);
851 } else {
852 xmlFree(text);
853 }
854 }
855
856end:
857 if (tmp_max_url_size > *max_url_size) {
858 *max_url_size = tmp_max_url_size;
859 }
860 av_free(path);
861 av_free(tmp_str);
862 xmlFree(baseurl);
863 return updated;
864
865}
866
867#define SET_REPRESENTATION_SEQUENCE_BASE_INFO(arg, cnt) { \
868 val = get_val_from_nodes_tab((arg), (cnt), "duration"); \
869 if (val) { \
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; \
874 } \
875 rep->fragment_duration = fragment_duration; \
876 av_log(s, AV_LOG_TRACE, "rep->fragment_duration = [%"PRId64"]\n", rep->fragment_duration); \
877 xmlFree(val); \
878 } \
879 val = get_val_from_nodes_tab((arg), (cnt), "timescale"); \
880 if (val) { \
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; \
885 } \
886 rep->fragment_timescale = fragment_timescale; \
887 av_log(s, AV_LOG_TRACE, "rep->fragment_timescale = [%"PRId64"]\n", rep->fragment_timescale); \
888 xmlFree(val); \
889 } \
890 val = get_val_from_nodes_tab((arg), (cnt), "startNumber"); \
891 if (val) { \
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"); \
895 start_number = 0; \
896 } \
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); \
899 xmlFree(val); \
900 } \
901 }
902
903
905 xmlNodePtr node,
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)
916{
917 int32_t ret = 0;
918 DASHContext *c = s->priv_data;
919 struct representation *rep = NULL;
920 struct fragment *seg = NULL;
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];
927 char *val = NULL;
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;
934
935 // try get information from representation
937 type = get_content_type(representation_node);
938 // try get information from contentComponen
940 type = get_content_type(content_component_node);
941 // try get information from adaption set
943 type = get_content_type(adaptionset_node);
946 av_log(s, AV_LOG_VERBOSE, "Parsing '%s' - skip not supported representation type\n", url);
947 return 0;
948 }
949
950 // convert selected representation to our internal struct
951 rep = av_mallocz(sizeof(struct representation));
952 if (!rep)
953 return AVERROR(ENOMEM);
954 if (c->adaptionset_lang) {
955 rep->lang = av_strdup(c->adaptionset_lang);
956 if (!rep->lang) {
957 av_log(s, AV_LOG_ERROR, "alloc language memory failure\n");
958 av_freep(&rep);
959 return AVERROR(ENOMEM);
960 }
961 }
962 rep->parent = s;
963 representation_segmenttemplate_node = find_child_node_by_name(representation_node, "SegmentTemplate");
964 representation_baseurl_node = find_child_node_by_name(representation_node, "BaseURL");
965 representation_segmentlist_node = find_child_node_by_name(representation_node, "SegmentList");
966 rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth");
967 rep_dependencyid_val = xmlGetProp(representation_node, "dependencyId");
968 rep_codecs_val = xmlGetProp(representation_node, "codecs");
969 if (!rep_codecs_val)
970 rep_codecs_val = xmlGetProp(adaptionset_node, "codecs");
971 val = xmlGetProp(representation_node, "id");
972 if (val) {
973 rep->id = av_strdup(val);
974 xmlFree(val);
975 if (!rep->id)
976 goto enomem;
977 }
978
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;
983
984 ret = resolve_content_path(s, url, &c->max_url_size, baseurl_nodes, 4);
985 if (ret <= 0)
986 goto free;
987 ret = add_url_size(&c->max_url_size,
988 (rep->id ? strlen(rep->id) : 0) +
989 (rep_bandwidth_val ? strlen(rep_bandwidth_val) : 0));
990 if (ret < 0)
991 goto free;
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;
999
1000 val = get_val_from_nodes_tab(fragment_templates_tab, 4, "initialization");
1001 if (val) {
1002 rep->init_section = av_mallocz(sizeof(struct fragment));
1003 if (!rep->init_section) {
1004 xmlFree(val);
1005 goto enomem;
1006 }
1007 ret = add_url_size(&c->max_url_size, strlen(val));
1008 if (ret < 0) {
1009 xmlFree(val);
1010 goto free;
1011 }
1012 rep->init_section->url = get_content_url(baseurl_nodes, 4,
1013 c->max_url_size, rep->id,
1014 rep_bandwidth_val, val);
1015 xmlFree(val);
1016 if (!rep->init_section->url)
1017 goto enomem;
1018 rep->init_section->size = -1;
1019 }
1020 val = get_val_from_nodes_tab(fragment_templates_tab, 4, "media");
1021 if (val) {
1022 ret = add_url_size(&c->max_url_size, strlen(val));
1023 if (ret < 0) {
1024 xmlFree(val);
1025 goto free;
1026 }
1027 rep->url_template = get_content_url(baseurl_nodes, 4,
1028 c->max_url_size, rep->id,
1029 rep_bandwidth_val, val);
1030 xmlFree(val);
1031 }
1032 val = get_val_from_nodes_tab(fragment_templates_tab, 4, "presentationTimeOffset");
1033 if (val) {
1034 int64_t presentation_timeoffset = (int64_t) strtoll(val, NULL, 10);
1035 if (presentation_timeoffset < 0) {
1036 av_log(s, AV_LOG_WARNING, "presentationTimeOffset invalid, autochanged to 0.\n");
1037 presentation_timeoffset = 0;
1038 }
1039 rep->presentation_timeoffset = presentation_timeoffset;
1040 av_log(s, AV_LOG_TRACE, "rep->presentation_timeoffset = [%"PRId64"]\n", rep->presentation_timeoffset);
1041 xmlFree(val);
1042 }
1043
1044 SET_REPRESENTATION_SEQUENCE_BASE_INFO(fragment_templates_tab, 4);
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");
1052 if (!val) {
1053 av_log(s, AV_LOG_ERROR, "Missing value attribute in adaptionset_supplementalproperty_node\n");
1054 } else {
1055 rep->last_seq_no = (int64_t)strtoll(val, NULL, 10) - 1;
1056 xmlFree(val);
1057 }
1058 }
1059 }
1060 }
1061
1062 fragment_timeline_node = find_child_node_by_name(representation_segmenttemplate_node, "SegmentTimeline");
1063
1064 if (!fragment_timeline_node)
1065 fragment_timeline_node = find_child_node_by_name(fragment_template_node, "SegmentTimeline");
1066 if (!fragment_timeline_node)
1067 fragment_timeline_node = find_child_node_by_name(adaptionset_segmentlist_node, "SegmentTimeline");
1068 if (!fragment_timeline_node)
1069 fragment_timeline_node = find_child_node_by_name(period_segmentlist_node, "SegmentTimeline");
1070 if (fragment_timeline_node) {
1071 fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node);
1072 while (fragment_timeline_node) {
1073 ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node);
1074 if (ret < 0)
1075 goto free;
1076 fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node);
1077 }
1078 }
1079 } else if (representation_baseurl_node && !representation_segmentlist_node) {
1080 seg = av_mallocz(sizeof(struct fragment));
1081 if (!seg)
1082 goto enomem;
1083 ret = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg);
1084 if (ret < 0) {
1085 av_free(seg);
1086 goto free;
1087 }
1088 seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size,
1089 rep->id, rep_bandwidth_val, NULL);
1090 if (!seg->url)
1091 goto enomem;
1092 seg->size = -1;
1093 } else if (representation_segmentlist_node) {
1094 // TODO: https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html
1095 // http://www-itec.uni-klu.ac.at/dash/ddash/mpdGenerator.php?fragmentlength=15&type=full
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;
1100
1101 SET_REPRESENTATION_SEQUENCE_BASE_INFO(segmentlists_tab, 3)
1102 fragmenturl_node = xmlFirstElementChild(representation_segmentlist_node);
1103 while (fragmenturl_node) {
1104 ret = parse_manifest_segmenturlnode(s, rep, fragmenturl_node,
1105 baseurl_nodes, rep->id,
1106 rep_bandwidth_val);
1107 if (ret < 0)
1108 goto free;
1109 fragmenturl_node = xmlNextElementSibling(fragmenturl_node);
1110 }
1111
1112 fragment_timeline_node = find_child_node_by_name(adaptionset_segmentlist_node, "SegmentTimeline");
1113 if (!fragment_timeline_node)
1114 fragment_timeline_node = find_child_node_by_name(period_segmentlist_node, "SegmentTimeline");
1115 if (fragment_timeline_node) {
1116 fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node);
1117 while (fragment_timeline_node) {
1118 ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node);
1119 if (ret < 0)
1120 goto free;
1121 fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node);
1122 }
1123 }
1124 } else {
1125 av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id '%s' \n",
1126 rep->id ? rep->id : "");
1127 goto free;
1128 }
1129
1130 int64_t nb_timeline_segments = 0;
1131 for (int i = 0; i < rep->n_timelines; i++) {
1132 nb_timeline_segments += av_clip64(rep->timelines[i]->repeat, 0, INT_MAX) + 1;
1133 if (nb_timeline_segments > MAX_TIMELINE_SEGMENTS) {
1134 av_log(s, AV_LOG_ERROR, "Too many segments in SegmentTimeline\n");
1136 goto free;
1137 }
1138 }
1139
1140 if (rep->fragment_duration > 0 && !rep->fragment_timescale)
1141 rep->fragment_timescale = 1;
1142 rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0;
1143 if (rep_dependencyid_val) {
1144 rep->dependencyid = av_strdup(rep_dependencyid_val);
1145 if (!rep->dependencyid) {
1146 xmlFree(rep_dependencyid_val);
1147 goto enomem;
1148 }
1149 }
1150 if (rep_codecs_val) {
1151 rep->codecs = av_strdup(rep_codecs_val);
1152 if (!rep->codecs) {
1153 xmlFree(rep_codecs_val);
1154 goto enomem;
1155 }
1156 }
1157 rep->framerate = av_make_q(0, 0);
1158 if (type == AVMEDIA_TYPE_VIDEO) {
1159 char *rep_framerate_val = xmlGetProp(representation_node, "frameRate");
1160 if (rep_framerate_val) {
1161 ret = av_parse_video_rate(&rep->framerate, rep_framerate_val);
1162 if (ret < 0)
1163 av_log(s, AV_LOG_VERBOSE, "Ignoring invalid frame rate '%s'\n", rep_framerate_val);
1164 xmlFree(rep_framerate_val);
1165 }
1166 }
1167
1168 rep->type = type;
1169 switch (type) {
1170 case AVMEDIA_TYPE_VIDEO:
1171 ret = av_dynarray_add_nofree(&c->videos, &c->n_videos, rep);
1172 break;
1173 case AVMEDIA_TYPE_AUDIO:
1174 ret = av_dynarray_add_nofree(&c->audios, &c->n_audios, rep);
1175 break;
1177 ret = av_dynarray_add_nofree(&c->subtitles, &c->n_subtitles, rep);
1178 break;
1179 }
1180 if (ret < 0)
1181 goto free;
1182
1183end:
1184 if (rep_bandwidth_val)
1185 xmlFree(rep_bandwidth_val);
1186 if (rep_dependencyid_val)
1187 xmlFree(rep_dependencyid_val);
1188 if (rep_codecs_val)
1189 xmlFree(rep_codecs_val);
1190
1191 return ret;
1192enomem:
1193 ret = AVERROR(ENOMEM);
1194free:
1196 goto end;
1197}
1198
1199static int parse_manifest_adaptationset_attr(AVFormatContext *s, xmlNodePtr adaptionset_node)
1200{
1201 DASHContext *c = s->priv_data;
1202
1203 if (!adaptionset_node) {
1204 av_log(s, AV_LOG_WARNING, "Cannot get AdaptionSet\n");
1205 return AVERROR(EINVAL);
1206 }
1207 c->adaptionset_lang = xmlGetProp(adaptionset_node, "lang");
1208
1209 return 0;
1210}
1211
1213 xmlNodePtr adaptionset_node,
1214 xmlNodePtr mpd_baseurl_node,
1215 xmlNodePtr period_baseurl_node,
1216 xmlNodePtr period_segmenttemplate_node,
1217 xmlNodePtr period_segmentlist_node)
1218{
1219 int ret = 0;
1220 DASHContext *c = s->priv_data;
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;
1227
1228 ret = parse_manifest_adaptationset_attr(s, adaptionset_node);
1229 if (ret < 0)
1230 return ret;
1231
1232 node = xmlFirstElementChild(adaptionset_node);
1233 while (node) {
1234 if (!av_strcasecmp(node->name, "SegmentTemplate")) {
1235 fragment_template_node = node;
1236 } else if (!av_strcasecmp(node->name, "ContentComponent")) {
1237 content_component_node = node;
1238 } else if (!av_strcasecmp(node->name, "BaseURL")) {
1239 adaptionset_baseurl_node = node;
1240 } else if (!av_strcasecmp(node->name, "SegmentList")) {
1241 adaptionset_segmentlist_node = node;
1242 } else if (!av_strcasecmp(node->name, "SupplementalProperty")) {
1243 adaptionset_supplementalproperty_node = node;
1244 } else if (!av_strcasecmp(node->name, "Representation")) {
1246 adaptionset_node,
1247 mpd_baseurl_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);
1256 if (ret < 0)
1257 goto err;
1258 }
1259 node = xmlNextElementSibling(node);
1260 }
1261
1262err:
1263 xmlFree(c->adaptionset_lang);
1264 c->adaptionset_lang = NULL;
1265 return ret;
1266}
1267
1268static int parse_programinformation(AVFormatContext *s, xmlNodePtr node)
1269{
1270 xmlChar *val = NULL;
1271
1272 node = xmlFirstElementChild(node);
1273 while (node) {
1274 if (!av_strcasecmp(node->name, "Title")) {
1275 val = xmlNodeGetContent(node);
1276 if (val) {
1277 av_dict_set(&s->metadata, "Title", val, 0);
1278 }
1279 } else if (!av_strcasecmp(node->name, "Source")) {
1280 val = xmlNodeGetContent(node);
1281 if (val) {
1282 av_dict_set(&s->metadata, "Source", val, 0);
1283 }
1284 } else if (!av_strcasecmp(node->name, "Copyright")) {
1285 val = xmlNodeGetContent(node);
1286 if (val) {
1287 av_dict_set(&s->metadata, "Copyright", val, 0);
1288 }
1289 }
1290 node = xmlNextElementSibling(node);
1291 xmlFree(val);
1292 val = NULL;
1293 }
1294 return 0;
1295}
1296
1297static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
1298{
1299 DASHContext *c = s->priv_data;
1300 int ret = 0;
1301 int close_in = 0;
1302 AVBPrint buf;
1304 xmlDoc *doc = NULL;
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;
1315 char *val = NULL;
1316 uint32_t period_duration_sec = 0;
1317 uint32_t period_start_sec = 0;
1318
1319 if (!in) {
1320 close_in = 1;
1321
1322 av_dict_copy(&opts, c->avio_opts, 0);
1323 ret = s->io_open(s, &in, url, AVIO_FLAG_READ, &opts);
1325 if (ret < 0)
1326 return ret;
1327 }
1328
1329 if (av_opt_get(in, "location", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&c->base_url) < 0)
1330 c->base_url = av_strdup(url);
1331 if (!c->base_url) {
1332 if (close_in)
1333 ff_format_io_close(s, &in);
1334 return AVERROR(ENOMEM);
1335 }
1336 url = c->base_url;
1337
1338 av_bprint_init(&buf, 0, INT_MAX); // xmlReadMemory uses integer bufsize
1339
1340 if ((ret = avio_read_to_bprint(in, &buf, SIZE_MAX)) < 0 ||
1341 !avio_feof(in)) {
1342 av_log(s, AV_LOG_ERROR, "Unable to read to manifest '%s'\n", url);
1343 if (ret == 0)
1345 } else {
1346 LIBXML_TEST_VERSION
1347
1348 doc = xmlReadMemory(buf.str, buf.len, c->base_url, NULL, 0);
1349 root_element = xmlDocGetRootElement(doc);
1350 node = root_element;
1351
1352 if (!node) {
1354 av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - missing root node\n", url);
1355 goto cleanup;
1356 }
1357
1358 if (node->type != XML_ELEMENT_NODE ||
1359 av_strcasecmp(node->name, "MPD")) {
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);
1362 goto cleanup;
1363 }
1364
1365 val = xmlGetProp(node, "type");
1366 if (!val) {
1367 av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - missing type attrib\n", url);
1369 goto cleanup;
1370 }
1371 if (!av_strcasecmp(val, "dynamic"))
1372 c->is_live = 1;
1373 xmlFree(val);
1374
1375 c->minimum_update_period = -1;
1376
1377 attr = node->properties;
1378 while (attr) {
1379 val = xmlGetProp(node, attr->name);
1380 if (!val) {
1381 ret = AVERROR(ENOMEM);
1382 goto cleanup;
1383 }
1384
1385 if (!av_strcasecmp(attr->name, "availabilityStartTime")) {
1386 c->availability_start_time = get_utc_date_time_insec(s, val);
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")) {
1389 c->availability_end_time = get_utc_date_time_insec(s, val);
1390 av_log(s, AV_LOG_TRACE, "c->availability_end_time = [%"PRId64"]\n", c->availability_end_time);
1391 } else if (!av_strcasecmp(attr->name, "publishTime")) {
1392 c->publish_time = get_utc_date_time_insec(s, val);
1393 av_log(s, AV_LOG_TRACE, "c->publish_time = [%"PRId64"]\n", c->publish_time);
1394 } else if (!av_strcasecmp(attr->name, "minimumUpdatePeriod")) {
1395 c->minimum_update_period = get_duration_insec(s, val);
1396 av_log(s, AV_LOG_TRACE, "c->minimum_update_period = [%"PRId64"]\n", c->minimum_update_period);
1397 } else if (!av_strcasecmp(attr->name, "timeShiftBufferDepth")) {
1398 c->time_shift_buffer_depth = get_duration_insec(s, val);
1399 av_log(s, AV_LOG_TRACE, "c->time_shift_buffer_depth = [%"PRId64"]\n", c->time_shift_buffer_depth);
1400 } else if (!av_strcasecmp(attr->name, "minBufferTime")) {
1401 c->min_buffer_time = get_duration_insec(s, val);
1402 av_log(s, AV_LOG_TRACE, "c->min_buffer_time = [%"PRId64"]\n", c->min_buffer_time);
1403 } else if (!av_strcasecmp(attr->name, "suggestedPresentationDelay")) {
1404 c->suggested_presentation_delay = get_duration_insec(s, val);
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")) {
1407 c->media_presentation_duration = get_duration_insec(s, val);
1408 av_log(s, AV_LOG_TRACE, "c->media_presentation_duration = [%"PRId64"]\n", c->media_presentation_duration);
1409 }
1410 attr = attr->next;
1411 xmlFree(val);
1412 }
1413
1414 tmp_node = find_child_node_by_name(node, "BaseURL");
1415 if (tmp_node) {
1416 mpd_baseurl_node = xmlCopyNode(tmp_node,1);
1417 } else {
1418 mpd_baseurl_node = xmlNewNode(NULL, "BaseURL");
1419 }
1420
1421 // at now we can handle only one period, with the longest duration
1422 node = xmlFirstElementChild(node);
1423 while (node) {
1424 if (!av_strcasecmp(node->name, "Period")) {
1425 period_duration_sec = 0;
1426 period_start_sec = 0;
1427 attr = node->properties;
1428 while (attr) {
1429 val = xmlGetProp(node, attr->name);
1430 if (!val) {
1431 ret = AVERROR(ENOMEM);
1432 goto cleanup;
1433 }
1434 if (!av_strcasecmp(attr->name, "duration")) {
1435 period_duration_sec = get_duration_insec(s, val);
1436 } else if (!av_strcasecmp(attr->name, "start")) {
1437 period_start_sec = get_duration_insec(s, val);
1438 }
1439 attr = attr->next;
1440 xmlFree(val);
1441 }
1442 if ((period_duration_sec) >= (c->period_duration)) {
1443 period_node = node;
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;
1448 }
1449 } else if (!av_strcasecmp(node->name, "ProgramInformation")) {
1451 }
1452 node = xmlNextElementSibling(node);
1453 }
1454 if (!period_node) {
1455 av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - missing Period node\n", url);
1457 goto cleanup;
1458 }
1459
1460 adaptionset_node = xmlFirstElementChild(period_node);
1461 while (adaptionset_node) {
1462 if (!av_strcasecmp(adaptionset_node->name, "BaseURL")) {
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")) {
1469 parse_manifest_adaptationset(s, url, adaptionset_node, mpd_baseurl_node, period_baseurl_node, period_segmenttemplate_node, period_segmentlist_node);
1470 }
1471 adaptionset_node = xmlNextElementSibling(adaptionset_node);
1472 }
1473cleanup:
1474 /*free the document */
1475 xmlFreeDoc(doc);
1476 xmlCleanupParser();
1477 xmlFreeNode(mpd_baseurl_node);
1478 }
1479
1480 av_bprint_finalize(&buf, NULL);
1481 if (close_in) {
1482 ff_format_io_close(s, &in);
1483 }
1484 return ret;
1485}
1486
1488{
1489 DASHContext *c = s->priv_data;
1490 int64_t num = 0;
1491 int64_t start_time_offset = 0;
1492
1493 if (c->is_live) {
1494 if (pls->n_fragments) {
1495 av_log(s, AV_LOG_TRACE, "in n_fragments mode\n");
1496 num = pls->first_seq_no;
1497 } else if (pls->n_timelines) {
1498 av_log(s, AV_LOG_TRACE, "in n_timelines mode\n");
1499 start_time_offset = get_segment_start_time_based_on_timeline(pls, 0xFFFFFFFF) - 60 * pls->fragment_timescale; // 60 seconds before end
1500 num = calc_next_seg_no_from_timelines(pls, start_time_offset);
1501 if (num == -1)
1502 num = pls->first_seq_no;
1503 } else if (pls->fragment_duration){
1504 av_log(s, AV_LOG_TRACE, "in fragment_duration mode fragment_timescale = %"PRId64", presentation_timeoffset = %"PRId64"\n", pls->fragment_timescale, pls->presentation_timeoffset);
1505 if (pls->presentation_timeoffset) {
1506 num = pls->first_seq_no + ((get_current_time_in_sec() - c->availability_start_time) * pls->fragment_timescale) / pls->fragment_duration - c->min_buffer_time;
1507 } else if (c->publish_time > 0 && !c->availability_start_time) {
1508 if (c->min_buffer_time) {
1509 num = pls->first_seq_no + (((c->publish_time + pls->fragment_duration) - c->suggested_presentation_delay) * pls->fragment_timescale) / pls->fragment_duration - c->min_buffer_time;
1510 } else {
1511 num = pls->first_seq_no + (((c->publish_time - c->time_shift_buffer_depth + pls->fragment_duration) - c->suggested_presentation_delay) * pls->fragment_timescale) / pls->fragment_duration;
1512 }
1513 } else {
1514 num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time) - c->suggested_presentation_delay) * pls->fragment_timescale) / pls->fragment_duration;
1515 }
1516 }
1517 } else {
1518 num = pls->first_seq_no;
1519 }
1520 return num;
1521}
1522
1524{
1525 DASHContext *c = s->priv_data;
1526 int64_t num = 0;
1527
1528 if (c->is_live && pls->fragment_duration) {
1529 av_log(s, AV_LOG_TRACE, "in live mode\n");
1530 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;
1531 } else {
1532 num = pls->first_seq_no;
1533 }
1534 return num;
1535}
1536
1538{
1539 int64_t num = 0;
1540
1541 if (pls->n_fragments) {
1542 num = pls->first_seq_no + pls->n_fragments - 1;
1543 } else if (pls->n_timelines) {
1544 int i = 0;
1545 num = pls->first_seq_no + pls->n_timelines - 1;
1546 for (i = 0; i < pls->n_timelines; i++) {
1547 if (pls->timelines[i]->repeat == -1) {
1548 num = pls->timelines[i]->duration ? av_rescale(c->period_duration, pls->fragment_timescale, pls->timelines[i]->duration) : pls->first_seq_no;
1549 } else {
1550 num += pls->timelines[i]->repeat;
1551 }
1552 }
1553 } else if (c->is_live && pls->fragment_duration) {
1554 num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time)) * pls->fragment_timescale) / pls->fragment_duration;
1555 } else if (pls->fragment_duration) {
1556 num = pls->first_seq_no + av_rescale_rnd(1, c->media_presentation_duration * pls->fragment_timescale, pls->fragment_duration, AV_ROUND_UP);
1557 }
1558
1559 return num;
1560}
1561
1562static void move_timelines(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
1563{
1564 if (rep_dest && rep_src ) {
1565 free_timelines_list(rep_dest);
1566 rep_dest->timelines = rep_src->timelines;
1567 rep_dest->n_timelines = rep_src->n_timelines;
1568 rep_dest->first_seq_no = rep_src->first_seq_no;
1569 rep_dest->last_seq_no = calc_max_seg_no(rep_dest, c);
1570 rep_src->timelines = NULL;
1571 rep_src->n_timelines = 0;
1572 rep_dest->cur_seq_no = rep_src->cur_seq_no;
1573 }
1574}
1575
1576static void move_segments(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
1577{
1578 if (rep_dest && rep_src ) {
1579 free_fragment_list(rep_dest);
1580 if (rep_src->start_number > (rep_dest->start_number + rep_dest->n_fragments))
1581 rep_dest->cur_seq_no = 0;
1582 else {
1583 rep_dest->cur_seq_no += rep_src->start_number - rep_dest->start_number;
1584 if (rep_dest->cur_seq_no < 0)
1585 rep_dest->cur_seq_no = 0;
1586 }
1587 rep_dest->fragments = rep_src->fragments;
1588 rep_dest->n_fragments = rep_src->n_fragments;
1589 rep_dest->parent = rep_src->parent;
1590 rep_dest->last_seq_no = calc_max_seg_no(rep_dest, c);
1591 rep_src->fragments = NULL;
1592 rep_src->n_fragments = 0;
1593 }
1594}
1595
1596
1598{
1599 int ret = 0, i;
1600 DASHContext *c = s->priv_data;
1601 // save current context
1602 int n_videos = c->n_videos;
1603 struct representation **videos = c->videos;
1604 int n_audios = c->n_audios;
1605 struct representation **audios = c->audios;
1606 int n_subtitles = c->n_subtitles;
1607 struct representation **subtitles = c->subtitles;
1608 char *base_url = c->base_url;
1609 int64_t minimum_update_period = c->minimum_update_period;
1610
1611 c->base_url = NULL;
1612 c->n_videos = 0;
1613 c->videos = NULL;
1614 c->n_audios = 0;
1615 c->audios = NULL;
1616 c->n_subtitles = 0;
1617 c->subtitles = NULL;
1618 c->minimum_update_period = -1;
1619 ret = parse_manifest(s, s->url, NULL);
1620 if (ret)
1621 goto finish;
1622
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);
1627 return AVERROR_INVALIDDATA;
1628 }
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);
1633 return AVERROR_INVALIDDATA;
1634 }
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);
1639 return AVERROR_INVALIDDATA;
1640 }
1641
1642 for (i = 0; i < n_videos; i++) {
1643 struct representation *cur_video = videos[i];
1644 struct representation *ccur_video = c->videos[i];
1645 if (cur_video->timelines && cur_video->fragment_timescale > 0) {
1646 // calc current time
1647 int64_t currentTime = get_segment_start_time_based_on_timeline(cur_video, cur_video->cur_seq_no);
1648 // update segments
1649 ccur_video->cur_seq_no = calc_next_seg_no_from_timelines(ccur_video, currentTime - 1);
1650 if (ccur_video->cur_seq_no >= 0) {
1651 move_timelines(ccur_video, cur_video, c);
1652 }
1653 }
1654 if (cur_video->fragments) {
1655 move_segments(ccur_video, cur_video, c);
1656 }
1657 }
1658 for (i = 0; i < n_audios; i++) {
1659 struct representation *cur_audio = audios[i];
1660 struct representation *ccur_audio = c->audios[i];
1661 if (cur_audio->timelines && cur_audio->fragment_timescale > 0) {
1662 // calc current time
1663 int64_t currentTime = get_segment_start_time_based_on_timeline(cur_audio, cur_audio->cur_seq_no);
1664 // update segments
1665 ccur_audio->cur_seq_no = calc_next_seg_no_from_timelines(ccur_audio, currentTime - 1);
1666 if (ccur_audio->cur_seq_no >= 0) {
1667 move_timelines(ccur_audio, cur_audio, c);
1668 }
1669 }
1670 if (cur_audio->fragments) {
1671 move_segments(ccur_audio, cur_audio, c);
1672 }
1673 }
1674
1675finish:
1676 // restore context
1677 if (c->base_url)
1678 av_free(base_url);
1679 else
1680 c->base_url = base_url;
1681 if (ret)
1682 c->minimum_update_period = minimum_update_period;
1683
1684 if (c->subtitles)
1686 if (c->audios)
1688 if (c->videos)
1690
1691 c->n_subtitles = n_subtitles;
1692 c->subtitles = subtitles;
1693 c->n_audios = n_audios;
1694 c->audios = audios;
1695 c->n_videos = n_videos;
1696 c->videos = videos;
1697 return ret;
1698}
1699
1701{
1702 int64_t min_seq_no = 0;
1703 int64_t max_seq_no = 0;
1704 struct fragment *seg = NULL;
1705 struct fragment *seg_ptr = NULL;
1706 DASHContext *c = pls->parent->priv_data;
1707 int reload_count = 0;
1708
1709 while (( !ff_check_interrupt(c->interrupt_callback)&& pls->n_fragments > 0)) {
1710 if (pls->cur_seq_no >= 0 && pls->cur_seq_no < pls->n_fragments) {
1711 seg_ptr = pls->fragments[pls->cur_seq_no];
1712 seg = av_mallocz(sizeof(struct fragment));
1713 if (!seg) {
1714 return NULL;
1715 }
1716 seg->url = av_strdup(seg_ptr->url);
1717 if (!seg->url) {
1718 av_free(seg);
1719 return NULL;
1720 }
1721 seg->size = seg_ptr->size;
1722 seg->url_offset = seg_ptr->url_offset;
1723 return seg;
1724 } else if (c->is_live) {
1725 if (reload_count++ >= c->max_reload) {
1727 "Reached max manifest reloads (%d) at seq %"PRId64"\n",
1728 c->max_reload, pls->cur_seq_no);
1729 return NULL;
1730 }
1732 } else {
1733 break;
1734 }
1735 }
1736 if (c->is_live) {
1737 int64_t reload_interval;
1738 int64_t last_load;
1739 int can_refresh;
1740reload:
1741 can_refresh = pls->timelines || pls->fragments;
1742 if (can_refresh) {
1744 }
1745 min_seq_no = calc_min_seg_no(pls->parent, pls);
1746 max_seq_no = calc_max_seg_no(pls, c);
1747
1748 if (pls->cur_seq_no < min_seq_no) {
1749 av_log(pls->parent, AV_LOG_VERBOSE, "old fragment: cur[%"PRId64"] min[%"PRId64"] max[%"PRId64"]\n", (int64_t)pls->cur_seq_no, min_seq_no, max_seq_no);
1750 pls->cur_seq_no = calc_cur_seg_no(pls->parent, pls);
1751 } else if (pls->cur_seq_no > max_seq_no) {
1752 av_log(pls->parent, AV_LOG_VERBOSE, "new fragment: min[%"PRId64"] max[%"PRId64"]\n", min_seq_no, max_seq_no);
1753
1754 int has_negative_repeat = 0;
1755 for (int i = 0; i < pls->n_timelines; i++)
1756 has_negative_repeat |= pls->timelines[i]->repeat < 0;
1757
1758 /* Only wait if refresh can reveal new segments or finalisation:
1759 * can_refresh/minimum_update_period: manifest is dynamic and still updating
1760 * type: subtitles must not block audio/video
1761 * n_timelines: SegmentTimeline tells us where the end is
1762 * has_negative_repeat: max_seq_no cannot be derived with negative repeats
1763 * fragment_timescale: needed to compute poll interval */
1764 if (
1765 can_refresh &&
1766 c->minimum_update_period != -1 &&
1767 pls->type != AVMEDIA_TYPE_SUBTITLE &&
1768 pls->n_timelines &&
1769 !has_negative_repeat &&
1770 pls->fragment_timescale > 0
1771 ) {
1772 reload_count++;
1773 if (reload_count > c->max_reload) {
1775 "Reached max manifest reloads (%d) at seq %"PRId64"\n",
1776 c->max_reload, pls->cur_seq_no);
1777 return NULL;
1778 }
1779
1780 /* Poll at half a segment duration, falling back to the
1781 * update period, with a floor to avoid busy-looping. */
1782 int64_t duration = pls->fragment_duration <= 0 ?
1783 pls->timelines[pls->n_timelines - 1]->duration :
1784 pls->fragment_duration;
1785 reload_interval = duration > 0 ?
1787 c->minimum_update_period * AV_TIME_BASE;
1788 reload_interval = FFMAX(reload_interval / 2, 100 * 1000);
1789 if (c->minimum_update_period > 0)
1790 reload_interval = FFMIN(reload_interval,
1791 c->minimum_update_period * AV_TIME_BASE);
1792
1793 last_load = av_gettime_relative();
1794 while (av_gettime_relative() - last_load < reload_interval) {
1795 if (ff_check_interrupt(c->interrupt_callback))
1796 return NULL;
1797 av_usleep(100*1000);
1798 }
1799 goto reload;
1800 }
1801 }
1802 seg = av_mallocz(sizeof(struct fragment));
1803 if (!seg) {
1804 return NULL;
1805 }
1806 } else if (pls->cur_seq_no <= pls->last_seq_no) {
1807 seg = av_mallocz(sizeof(struct fragment));
1808 if (!seg) {
1809 return NULL;
1810 }
1811 }
1812 if (seg) {
1813 char *tmpfilename;
1814 if (!pls->url_template) {
1815 av_log(pls->parent, AV_LOG_ERROR, "Cannot get fragment, missing template URL\n");
1816 av_free(seg);
1817 return NULL;
1818 }
1819 tmpfilename = av_mallocz(c->max_url_size);
1820 if (!tmpfilename) {
1821 av_free(seg);
1822 return NULL;
1823 }
1824 ff_dash_fill_tmpl_params(tmpfilename, c->max_url_size, pls->url_template, 0, pls->cur_seq_no, 0, get_segment_start_time_based_on_timeline(pls, pls->cur_seq_no));
1825 seg->url = av_strireplace(pls->url_template, pls->url_template, tmpfilename);
1826 if (!seg->url) {
1827 av_log(pls->parent, AV_LOG_WARNING, "Unable to resolve template url '%s', try to use origin template\n", pls->url_template);
1828 seg->url = av_strdup(pls->url_template);
1829 if (!seg->url) {
1830 av_log(pls->parent, AV_LOG_ERROR, "Cannot resolve template url '%s'\n", pls->url_template);
1831 av_free(tmpfilename);
1832 av_free(seg);
1833 return NULL;
1834 }
1835 }
1836 av_free(tmpfilename);
1837 seg->size = -1;
1838 }
1839
1840 return seg;
1841}
1842
1843static int read_from_url(struct representation *pls, struct fragment *seg,
1844 uint8_t *buf, int buf_size)
1845{
1846 int ret;
1847
1848 /* limit read if the fragment was only a part of a file */
1849 if (seg->size >= 0) {
1850 buf_size = FFMIN(buf_size, pls->cur_seg_size - pls->cur_seg_offset);
1851 if (buf_size <= 0)
1852 return AVERROR_EOF;
1853 }
1854
1855 ret = avio_read(pls->input, buf, buf_size);
1856 if (ret > 0)
1857 pls->cur_seg_offset += ret;
1858
1859 return ret;
1860}
1861
1862static int open_input(DASHContext *c, struct representation *pls, struct fragment *seg)
1863{
1865 char *url = NULL;
1866 int ret = 0;
1867
1868 url = av_mallocz(c->max_url_size);
1869 if (!url) {
1870 ret = AVERROR(ENOMEM);
1871 goto cleanup;
1872 }
1873
1874 if (seg->size >= 0) {
1875 /* try to restrict the HTTP request to the part we want
1876 * (if this is in fact a HTTP request) */
1877 av_dict_set_int(&opts, "offset", seg->url_offset, 0);
1878 av_dict_set_int(&opts, "end_offset", seg->url_offset + seg->size, 0);
1879 }
1880
1881 ff_make_absolute_url(url, c->max_url_size, c->base_url, seg->url);
1882 av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset %"PRId64"\n",
1883 url, seg->url_offset);
1884 ret = open_url(pls->parent, &pls->input, url, &c->avio_opts, opts, NULL);
1885
1886cleanup:
1887 av_free(url);
1889 pls->cur_seg_offset = 0;
1890 pls->cur_seg_size = seg->size;
1891 return ret;
1892}
1893
1895{
1896 static const int max_init_section_size = 1024 * 1024;
1897 DASHContext *c = pls->parent->priv_data;
1898 int64_t sec_size;
1899 int64_t urlsize;
1900 int ret;
1901
1902 if (!pls->init_section || pls->init_sec_buf)
1903 return 0;
1904
1905 ret = open_input(c, pls, pls->init_section);
1906 if (ret < 0) {
1908 "Failed to open an initialization section\n");
1909 return ret;
1910 }
1911
1912 if (pls->init_section->size >= 0)
1913 sec_size = pls->init_section->size;
1914 else if ((urlsize = avio_size(pls->input)) >= 0)
1915 sec_size = urlsize;
1916 else
1917 sec_size = max_init_section_size;
1918
1920 "Downloading an initialization section of size %"PRId64"\n",
1921 sec_size);
1922
1923 sec_size = FFMIN(sec_size, max_init_section_size);
1924
1925 av_fast_malloc(&pls->init_sec_buf, &pls->init_sec_buf_size, sec_size);
1926
1927 ret = read_from_url(pls, pls->init_section, pls->init_sec_buf,
1928 pls->init_sec_buf_size);
1929 ff_format_io_close(pls->parent, &pls->input);
1930
1931 if (ret < 0)
1932 return ret;
1933
1934 pls->init_sec_data_len = ret;
1935 pls->init_sec_buf_read_offset = 0;
1936
1937 return 0;
1938}
1939
1940static int64_t seek_data(void *opaque, int64_t offset, int whence)
1941{
1942 struct representation *v = opaque;
1943 if (v->n_fragments && !v->init_sec_data_len) {
1944 return avio_seek(v->input, offset, whence);
1945 }
1946
1947 return AVERROR(ENOSYS);
1948}
1949
1950static int read_data(void *opaque, uint8_t *buf, int buf_size)
1951{
1952 int ret = 0;
1953 struct representation *v = opaque;
1955
1956restart:
1957 if (!v->input) {
1960 if (!v->cur_seg) {
1961 ret = ff_check_interrupt(c->interrupt_callback) ? AVERROR_EXIT : AVERROR_EOF;
1962 goto end;
1963 }
1964
1965 /* load/update Media Initialization Section, if any */
1967 if (ret)
1968 goto end;
1969
1970 ret = open_input(c, v, v->cur_seg);
1971 if (ret < 0) {
1972 if (ff_check_interrupt(c->interrupt_callback)) {
1973 ret = AVERROR_EXIT;
1974 goto end;
1975 }
1976 av_log(v->parent, AV_LOG_WARNING, "Failed to open fragment of playlist\n");
1977 if (++v->n_open_failures > c->max_reload) {
1979 "Reached max consecutive fragment open failures (%d), giving up\n",
1980 c->max_reload);
1981 ret = AVERROR_EOF;
1982 goto end;
1983 }
1984 v->cur_seq_no++;
1985 goto restart;
1986 }
1987 v->n_open_failures = 0;
1988 }
1989
1991 /* Push init section out first before first actual fragment */
1992 int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size);
1993 memcpy(buf, v->init_sec_buf + v->init_sec_buf_read_offset, copy_size);
1994 v->init_sec_buf_read_offset += copy_size;
1995 ret = copy_size;
1996 goto end;
1997 }
1998
1999 /* check the v->cur_seg, if it is null, get current and double check if the new v->cur_seg*/
2000 if (!v->cur_seg) {
2002 }
2003 if (!v->cur_seg) {
2004 ret = ff_check_interrupt(c->interrupt_callback) ? AVERROR_EXIT : AVERROR_EOF;
2005 goto end;
2006 }
2007 ret = read_from_url(v, v->cur_seg, buf, buf_size);
2008 if (ret > 0)
2009 goto end;
2010
2011 if (c->is_live || v->cur_seq_no < v->last_seq_no) {
2012 if (!v->is_restart_needed)
2013 v->cur_seq_no++;
2014 v->is_restart_needed = 1;
2015 }
2016
2017end:
2018 return ret;
2019}
2020
2021static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url,
2022 int flags, AVDictionary **opts)
2023{
2025 "A DASH playlist item '%s' referred to an external file '%s'. "
2026 "Opening this file was forbidden for security reasons\n",
2027 s->url, url);
2028 return AVERROR(EPERM);
2029}
2030
2032{
2033 /* note: the internal buffer could have changed */
2034 av_freep(&pls->pb.pub.buffer);
2035 memset(&pls->pb, 0x00, sizeof(pls->pb));
2036 pls->ctx->pb = NULL;
2038}
2039
2041{
2042 DASHContext *c = s->priv_data;
2043 const AVInputFormat *in_fmt = NULL;
2044 AVDictionary *in_fmt_opts = NULL;
2045 uint8_t *avio_ctx_buffer = NULL;
2046 int ret = 0, i;
2047
2048 if (pls->ctx) {
2050 }
2051
2052 if (ff_check_interrupt(&s->interrupt_callback)) {
2053 ret = AVERROR_EXIT;
2054 goto fail;
2055 }
2056
2057 if (!(pls->ctx = avformat_alloc_context())) {
2058 ret = AVERROR(ENOMEM);
2059 goto fail;
2060 }
2061
2062 avio_ctx_buffer = av_malloc(INITIAL_BUFFER_SIZE);
2063 if (!avio_ctx_buffer ) {
2064 ret = AVERROR(ENOMEM);
2066 pls->ctx = NULL;
2067 goto fail;
2068 }
2069 av_freep(&pls->pb.pub.buffer);
2070 ffio_init_context(&pls->pb, avio_ctx_buffer, INITIAL_BUFFER_SIZE, 0,
2071 pls, read_data, NULL, c->is_live ? NULL : seek_data);
2072 pls->pb.pub.seekable = 0;
2073
2074 if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0) {
2076 pls->ctx = NULL;
2077 goto fail;
2078 }
2079
2081 pls->ctx->probesize = s->probesize > 0 ? s->probesize : 1024 * 4;
2082 pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? s->max_analyze_duration : 4 * AV_TIME_BASE;
2083 pls->ctx->interrupt_callback = s->interrupt_callback;
2084 ret = av_probe_input_buffer(&pls->pb.pub, &in_fmt, "", NULL, 0, 0);
2085 if (ret < 0) {
2086 av_log(s, AV_LOG_ERROR, "Error when loading first fragment of playlist\n");
2088 pls->ctx = NULL;
2089 goto fail;
2090 }
2091
2092 pls->ctx->pb = &pls->pb.pub;
2093 pls->ctx->io_open = nested_io_open;
2094
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);
2099
2100 // provide additional information from mpd if available
2101 ret = avformat_open_input(&pls->ctx, "", in_fmt, &in_fmt_opts); //pls->init_section->url
2102 av_dict_free(&in_fmt_opts);
2103 if (ret < 0)
2104 goto fail;
2105 if (pls->n_fragments) {
2106#if FF_API_R_FRAME_RATE
2107 if (pls->framerate.den) {
2108 for (i = 0; i < pls->ctx->nb_streams; i++)
2109 pls->ctx->streams[i]->r_frame_rate = pls->framerate;
2110 }
2111#endif
2113 if (ret < 0)
2114 goto fail;
2115 }
2116
2117fail:
2118 return ret;
2119}
2120
2122{
2123 int ret = 0;
2124 int i;
2125
2126 pls->parent = s;
2127 pls->cur_seq_no = calc_cur_seg_no(s, pls);
2128
2129 if (!pls->last_seq_no)
2130 pls->last_seq_no = calc_max_seg_no(pls, s->priv_data);
2131
2133 if (ret < 0)
2134 return ret;
2135
2136 for (i = 0; i < pls->ctx->nb_streams; i++) {
2138 FFStream *sti = ffstream(st);
2139 const AVStream *ist = pls->ctx->streams[i];
2140 const FFStream *isti = cffstream(ist);
2141 if (!st)
2142 return AVERROR(ENOMEM);
2143
2144 st->id = i + pls->stream_index;
2145
2147 if (ret < 0)
2148 return ret;
2149
2151
2152 // copy disposition
2153 st->disposition = ist->disposition;
2154 sti->need_parsing = isti->need_parsing;
2155 }
2156
2157 for (i = 0; i < pls->ctx->nb_stream_groups; i++) {
2158 AVStreamGroup *istg = pls->ctx->stream_groups[i];
2159 AVStreamGroup *stg;
2160
2162 continue;
2163
2164 stg = avformat_stream_group_create(s, istg->type, NULL);
2165 if (!stg)
2166 return AVERROR(ENOMEM);
2167
2168 stg->id = s->nb_stream_groups;
2169
2170 for (int j = 0; j < istg->nb_entries; j++) {
2171 AVStream *ist = istg->entries[j]->stream;
2172 AVStream *st = s->streams[ist->index + pls->stream_index];
2174 if (ret < 0)
2175 return ret;
2176 }
2177
2178 switch (stg->type) {
2182 ret = av_opt_copy(lcevc, ilcevc);
2183 if (ret < 0)
2184 return ret;
2185 break;
2186 }
2187 default:
2188 av_unreachable("Unsupported Stream Group type should have been checked above");
2189 }
2190
2191 // copy disposition
2192 stg->disposition = istg->disposition;
2193 }
2194
2195 return 0;
2196}
2197
2198static int is_common_init_section_exist(struct representation **pls, int n_pls)
2199{
2200 struct fragment *first_init_section = pls[0]->init_section;
2201 char *url =NULL;
2202 int64_t url_offset = -1;
2203 int64_t size = -1;
2204 int i = 0;
2205
2206 if (first_init_section == NULL || n_pls == 0)
2207 return 0;
2208
2209 url = first_init_section->url;
2210 url_offset = first_init_section->url_offset;
2211 size = pls[0]->init_section->size;
2212 for (i=0;i<n_pls;i++) {
2213 if (!pls[i]->init_section)
2214 continue;
2215
2216 if (av_strcasecmp(pls[i]->init_section->url, url) ||
2217 pls[i]->init_section->url_offset != url_offset ||
2218 pls[i]->init_section->size != size) {
2219 return 0;
2220 }
2221 }
2222 return 1;
2223}
2224
2225static int copy_init_section(struct representation *rep_dest, struct representation *rep_src)
2226{
2227 rep_dest->init_sec_buf = av_mallocz(rep_src->init_sec_buf_size);
2228 if (!rep_dest->init_sec_buf) {
2229 av_log(rep_dest->ctx, AV_LOG_WARNING, "Cannot alloc memory for init_sec_buf\n");
2230 return AVERROR(ENOMEM);
2231 }
2232 memcpy(rep_dest->init_sec_buf, rep_src->init_sec_buf, rep_src->init_sec_data_len);
2233 rep_dest->init_sec_buf_size = rep_src->init_sec_buf_size;
2234 rep_dest->init_sec_data_len = rep_src->init_sec_data_len;
2235 rep_dest->cur_timestamp = rep_src->cur_timestamp;
2236
2237 return 0;
2238}
2239
2240static void move_metadata(AVStream *st, const char *key, char **value)
2241{
2242 if (*value) {
2244 *value = NULL;
2245 }
2246}
2247
2249{
2250 DASHContext *c = s->priv_data;
2251 struct representation *rep;
2252 AVProgram *program;
2253 int ret = 0;
2254 int stream_index = 0;
2255 int i, j;
2256
2257 c->interrupt_callback = &s->interrupt_callback;
2258
2259 if ((ret = ffio_copy_url_options(s->pb, &c->avio_opts)) < 0)
2260 return ret;
2261
2262 if ((ret = parse_manifest(s, s->url, s->pb)) < 0)
2263 return ret;
2264
2265 /* If this isn't a live stream, fill the total duration of the
2266 * stream. */
2267 if (!c->is_live) {
2268 s->duration = (int64_t) c->media_presentation_duration * AV_TIME_BASE;
2269 } else {
2270 av_dict_set(&c->avio_opts, "seekable", "0", 0);
2271 }
2272
2273 if(c->n_videos)
2274 c->is_init_section_common_video = is_common_init_section_exist(c->videos, c->n_videos);
2275
2276 /* Open the demuxer for video and audio components if available */
2277 for (i = 0; i < c->n_videos; i++) {
2278 rep = c->videos[i];
2279 if (i > 0 && c->is_init_section_common_video) {
2280 ret = copy_init_section(rep, c->videos[0]);
2281 if (ret < 0)
2282 return ret;
2283 }
2286
2287 if (ret)
2288 return ret;
2289 if (rep->ctx->nb_streams == 0)
2290 return AVERROR_PATCHWELCOME;
2291 stream_index += rep->ctx->nb_streams;
2292 }
2293
2294 if(c->n_audios)
2295 c->is_init_section_common_audio = is_common_init_section_exist(c->audios, c->n_audios);
2296
2297 for (i = 0; i < c->n_audios; i++) {
2298 rep = c->audios[i];
2299 if (i > 0 && c->is_init_section_common_audio) {
2300 ret = copy_init_section(rep, c->audios[0]);
2301 if (ret < 0)
2302 return ret;
2303 }
2306
2307 if (ret)
2308 return ret;
2309 if (rep->ctx->nb_streams == 0)
2310 return AVERROR_PATCHWELCOME;
2311 stream_index += rep->ctx->nb_streams;
2312 }
2313
2314 if (c->n_subtitles)
2315 c->is_init_section_common_subtitle = is_common_init_section_exist(c->subtitles, c->n_subtitles);
2316
2317 for (i = 0; i < c->n_subtitles; i++) {
2318 rep = c->subtitles[i];
2319 if (i > 0 && c->is_init_section_common_subtitle) {
2320 ret = copy_init_section(rep, c->subtitles[0]);
2321 if (ret < 0)
2322 return ret;
2323 }
2326
2327 if (ret)
2328 return ret;
2329 if (rep->ctx->nb_streams == 0)
2330 return AVERROR_PATCHWELCOME;
2331 stream_index += rep->ctx->nb_streams;
2332 }
2333
2334 if (!stream_index)
2335 return AVERROR_INVALIDDATA;
2336
2337 /* Create a program */
2338 program = av_new_program(s, 0);
2339 if (!program)
2340 return AVERROR(ENOMEM);
2341
2342 for (i = 0; i < c->n_videos; i++) {
2343 rep = c->videos[i];
2344 rep->assoc_stream = av_malloc_array(rep->ctx->nb_streams, sizeof(*rep->assoc_stream));
2345 if (!rep->assoc_stream)
2346 return AVERROR(ENOMEM);
2347 rep->nb_assoc_stream = rep->ctx->nb_streams;
2348 for (int j = 0; j < rep->ctx->nb_streams; j++) {
2350 rep->assoc_stream[j] = s->streams[rep->stream_index + j];
2351 }
2352 if (rep->bandwidth > 0)
2353 av_dict_set_int(&rep->assoc_stream[0]->metadata, "variant_bitrate", rep->bandwidth, 0);
2354 move_metadata(rep->assoc_stream[0], "id", &rep->id);
2355 }
2356 for (i = 0; i < c->n_audios; i++) {
2357 rep = c->audios[i];
2358 rep->assoc_stream = av_malloc_array(rep->ctx->nb_streams, sizeof(*rep->assoc_stream));
2359 if (!rep->assoc_stream)
2360 return AVERROR(ENOMEM);
2361 rep->nb_assoc_stream = rep->ctx->nb_streams;
2362 for (int j = 0; j < rep->ctx->nb_streams; j++) {
2364 rep->assoc_stream[j] = s->streams[rep->stream_index + j];
2365 }
2366 if (rep->bandwidth > 0)
2367 av_dict_set_int(&rep->assoc_stream[0]->metadata, "variant_bitrate", rep->bandwidth, 0);
2368 move_metadata(rep->assoc_stream[0], "id", &rep->id);
2369 move_metadata(rep->assoc_stream[0], "language", &rep->lang);
2370 }
2371 for (i = 0; i < c->n_subtitles; i++) {
2372 rep = c->subtitles[i];
2373 rep->assoc_stream = av_malloc_array(rep->ctx->nb_streams, sizeof(*rep->assoc_stream));
2374 if (!rep->assoc_stream)
2375 return AVERROR(ENOMEM);
2376 rep->nb_assoc_stream = rep->ctx->nb_streams;
2377 for (int j = 0; j < rep->ctx->nb_streams; j++) {
2379 rep->assoc_stream[j] = s->streams[rep->stream_index + j];
2380 }
2381 move_metadata(rep->assoc_stream[0], "id", &rep->id);
2382 move_metadata(rep->assoc_stream[0], "language", &rep->lang);
2383 }
2384
2385 /* Create stream groups if needed */
2386 for (i = 0; i < c->n_videos; i++) {
2387 struct representation *ref;
2388 rep = c->videos[i];
2389 if (!rep->dependencyid || !rep->codecs || !rep->nb_assoc_stream)
2390 continue;
2391 for (j = 0; j < c->n_videos; j++) {
2392 if (j == i)
2393 continue;
2394 ref = c->videos[j];
2395 if (!ref->nb_assoc_stream)
2396 continue;
2397 const AVDictionaryEntry *id = av_dict_get(ref->assoc_stream[0]->metadata, "id", NULL, AV_DICT_MATCH_CASE);
2398 if (id && !strcmp(rep->dependencyid, id->value))
2399 break;
2400 }
2401 if (j >= c->n_videos || !av_strstart(rep->codecs, "lvc1", NULL) ||
2403 continue;
2405 if (!stg)
2406 return AVERROR(ENOMEM);
2409 ret = avformat_stream_group_add_stream(stg, ref->assoc_stream[0]);
2410 if (ret < 0)
2411 return ret;
2413 if (ret < 0)
2414 return ret;
2415 stg->id = stg->index;
2416 stg->params.layered_video->el_index = stg->nb_entries - 1;
2417 }
2418
2419 return 0;
2420}
2421
2423{
2424 int i, j;
2425
2426 for (i = 0; i < n; i++) {
2427 struct representation *pls = p[i];
2428 int needed = !pls->nb_assoc_stream;
2429
2430 for (int j = 0; j < pls->nb_assoc_stream; j++)
2431 needed |= pls->assoc_stream[j]->discard < AVDISCARD_ALL;
2432
2433 if (needed && !pls->ctx) {
2434 pls->cur_seg_offset = 0;
2435 pls->init_sec_buf_read_offset = 0;
2436 /* Catch up */
2437 for (j = 0; j < n; j++) {
2438 pls->cur_seq_no = FFMAX(pls->cur_seq_no, p[j]->cur_seq_no);
2439 }
2441 av_log(s, AV_LOG_INFO, "Now receiving stream_index %d\n", pls->stream_index);
2442 } else if (!needed && pls->ctx) {
2444 ff_format_io_close(pls->parent, &pls->input);
2445 av_log(s, AV_LOG_INFO, "No longer receiving stream_index %d\n", pls->stream_index);
2446 }
2447 }
2448}
2449
2451{
2452 DASHContext *c = s->priv_data;
2453 int ret = 0, i;
2454 int64_t mints = 0;
2455 struct representation *cur = NULL;
2456 struct representation *rep = NULL;
2457
2458 recheck_discard_flags(s, c->videos, c->n_videos);
2459 recheck_discard_flags(s, c->audios, c->n_audios);
2460 recheck_discard_flags(s, c->subtitles, c->n_subtitles);
2461
2462 for (i = 0; i < c->n_videos; i++) {
2463 rep = c->videos[i];
2464 if (!rep->ctx)
2465 continue;
2466 if (!cur || rep->cur_timestamp < mints) {
2467 cur = rep;
2468 mints = rep->cur_timestamp;
2469 }
2470 }
2471 for (i = 0; i < c->n_audios; i++) {
2472 rep = c->audios[i];
2473 if (!rep->ctx)
2474 continue;
2475 if (!cur || rep->cur_timestamp < mints) {
2476 cur = rep;
2477 mints = rep->cur_timestamp;
2478 }
2479 }
2480
2481 for (i = 0; i < c->n_subtitles; i++) {
2482 rep = c->subtitles[i];
2483 if (!rep->ctx)
2484 continue;
2485 if (!cur || rep->cur_timestamp < mints) {
2486 cur = rep;
2487 mints = rep->cur_timestamp;
2488 }
2489 }
2490
2491 if (!cur) {
2492 return AVERROR_EOF;
2493 }
2494 while (!ff_check_interrupt(c->interrupt_callback) && !ret) {
2495 ret = av_read_frame(cur->ctx, pkt);
2496 if (ret >= 0) {
2497 /* If we got a packet, return it */
2498 cur->cur_timestamp = av_rescale(pkt->pts, (int64_t)cur->ctx->streams[0]->time_base.num * 90000, cur->ctx->streams[0]->time_base.den);
2499 pkt->stream_index += cur->stream_index;
2500 return 0;
2501 }
2502 if (cur->is_restart_needed) {
2503 cur->cur_seg_offset = 0;
2504 cur->init_sec_buf_read_offset = 0;
2505 cur->is_restart_needed = 0;
2506 ff_format_io_close(cur->parent, &cur->input);
2508 } else if (ret == AVERROR_EOF) {
2510 ff_format_io_close(cur->parent, &cur->input);
2511 av_log(s, AV_LOG_DEBUG, "EOF on stream_index %d\n", cur->stream_index);
2512 // prevent recheck_discard_flags() from re-enabling the component
2513 for (int i = 0; i < cur->nb_assoc_stream; i++)
2515 return FFERROR_REDO;
2516 }
2517 }
2518 return ret;
2519}
2520
2522{
2523 DASHContext *c = s->priv_data;
2527 av_dict_free(&c->avio_opts);
2528 av_freep(&c->base_url);
2529 return 0;
2530}
2531
2532static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t seek_pos_msec, int flags, int dry_run)
2533{
2534 int ret = 0;
2535 int i = 0;
2536 int j = 0;
2537 int64_t duration = 0;
2538
2539 av_log(pls->parent, AV_LOG_VERBOSE, "DASH seek pos[%"PRId64"ms] %s\n",
2540 seek_pos_msec, dry_run ? " (dry)" : "");
2541
2542 // single fragment mode
2543 if (pls->n_fragments == 1) {
2544 pls->cur_timestamp = 0;
2545 pls->cur_seg_offset = 0;
2546 if (dry_run)
2547 return 0;
2549 return av_seek_frame(pls->ctx, -1, seek_pos_msec * 1000, flags);
2550 }
2551
2552 ff_format_io_close(pls->parent, &pls->input);
2553
2554 // find the nearest fragment
2555 if (pls->n_timelines > 0 && pls->fragment_timescale > 0) {
2556 int64_t num = pls->first_seq_no;
2557 av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline start n_timelines[%d] "
2558 "last_seq_no[%"PRId64"].\n",
2559 (int)pls->n_timelines, (int64_t)pls->last_seq_no);
2560 for (i = 0; i < pls->n_timelines; i++) {
2561 if (pls->timelines[i]->starttime > 0) {
2562 duration = pls->timelines[i]->starttime;
2563 }
2564 duration += pls->timelines[i]->duration;
2565 if (seek_pos_msec < ((duration * 1000) / pls->fragment_timescale)) {
2566 goto set_seq_num;
2567 }
2568 for (j = 0; j < pls->timelines[i]->repeat; j++) {
2569 duration += pls->timelines[i]->duration;
2570 num++;
2571 if (seek_pos_msec < ((duration * 1000) / pls->fragment_timescale)) {
2572 goto set_seq_num;
2573 }
2574 }
2575 num++;
2576 }
2577
2578set_seq_num:
2579 pls->cur_seq_no = num > pls->last_seq_no ? pls->last_seq_no : num;
2580 av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline end cur_seq_no[%"PRId64"].\n",
2581 (int64_t)pls->cur_seq_no);
2582 } else if (pls->fragment_duration > 0) {
2583 pls->cur_seq_no = pls->first_seq_no + ((seek_pos_msec * pls->fragment_timescale) / pls->fragment_duration) / 1000;
2584 pls->cur_seq_no = FFMAX(pls->cur_seq_no, pls->first_seq_no);
2585 } else {
2586 av_log(pls->parent, AV_LOG_ERROR, "dash_seek missing timeline or fragment_duration\n");
2587 pls->cur_seq_no = pls->first_seq_no;
2588 }
2589 pls->cur_timestamp = 0;
2590 pls->cur_seg_offset = 0;
2591 pls->init_sec_buf_read_offset = 0;
2592 pls->is_restart_needed = 0;
2593 ret = dry_run ? 0 : reopen_demux_for_component(s, pls);
2594
2595 return ret;
2596}
2597
2599{
2600 int ret = 0, i;
2601 DASHContext *c = s->priv_data;
2602 int64_t seek_pos_msec = av_rescale_rnd(timestamp, 1000,
2603 s->streams[stream_index]->time_base.den,
2606 if ((flags & AVSEEK_FLAG_BYTE) || c->is_live)
2607 return AVERROR(ENOSYS);
2608
2609 /* Seek in discarded streams with dry_run=1 to avoid reopening them */
2610 for (i = 0; i < c->n_videos; i++) {
2611 if (!ret)
2612 ret = dash_seek(s, c->videos[i], seek_pos_msec, flags, !c->videos[i]->ctx);
2613 }
2614 for (i = 0; i < c->n_audios; i++) {
2615 if (!ret)
2616 ret = dash_seek(s, c->audios[i], seek_pos_msec, flags, !c->audios[i]->ctx);
2617 }
2618 for (i = 0; i < c->n_subtitles; i++) {
2619 if (!ret)
2620 ret = dash_seek(s, c->subtitles[i], seek_pos_msec, flags, !c->subtitles[i]->ctx);
2621 }
2622
2623 return ret;
2624}
2625
2626static int dash_probe(const AVProbeData *p)
2627{
2628 if (!av_stristr(p->buf, "<MPD"))
2629 return 0;
2630
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")) {
2636 return AVPROBE_SCORE_MAX;
2637 }
2638 if (av_stristr(p->buf, "dash:profile")) {
2639 return AVPROBE_SCORE_MAX;
2640 }
2641
2642 return 0;
2643}
2644
2645#define OFFSET(x) offsetof(DASHContext, x)
2646#define FLAGS AV_OPT_FLAG_DECODING_PARAM
2647static const AVOption dash_options[] = {
2648 {"allowed_extensions", "List of file extensions that dash is allowed to access",
2649 OFFSET(allowed_extensions), AV_OPT_TYPE_STRING,
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",
2655 OFFSET(max_reload), AV_OPT_TYPE_INT, { .i64 = 100 }, 0, INT_MAX, FLAGS },
2656 {NULL}
2657};
2658
2659static const AVClass dash_class = {
2660 .class_name = "dash",
2661 .item_name = av_default_item_name,
2662 .option = dash_options,
2663 .version = LIBAVUTIL_VERSION_INT,
2664};
2665
2667 .p.name = "dash",
2668 .p.long_name = NULL_IF_CONFIG_SMALL("Dynamic Adaptive Streaming over HTTP"),
2669 .p.priv_class = &dash_class,
2670 .p.flags = AVFMT_NO_BYTE_SEEK,
2671 .priv_data_size = sizeof(DASHContext),
2672 .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
2678};
static double val(void *priv, double ch)
Definition aeval.c:77
const FFInputFormat ff_dash_demuxer
Definition dashdec.c:2666
static void finish(void)
static AVDictionary * opts
int32_t
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.
Definition avassert.h:109
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition avformat.c:992
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition avformat.c:910
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:865
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition avformat.c:367
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:485
@ AV_STREAM_GROUP_PARAMS_LCEVC
Definition avformat.h:1162
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition avformat.h:508
#define AVSEEK_FLAG_BYTE
seeking based on position in bytes
Definition avformat.h:2748
#define AVFMT_FLAG_CUSTOM_IO
The caller has supplied a custom AVIOContext, don't avio_close() it.
Definition avformat.h:1561
#define AVSEEK_FLAG_BACKWARD
seek backward
Definition avformat.h:2747
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition avio.c:935
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
Definition avio.c:733
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
#define AVIO_FLAG_READ
read-only
Definition avio.h:630
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition aviobuf.c:326
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:620
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.
Definition aviobuf.c:1222
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))
Definition aviobuf.c:50
int ffio_copy_url_options(AVIOContext *pb, AVDictionary **avio_opts)
Read url related dictionary options from the AVIOContext and write to the given dictionary.
Definition aviobuf.c:962
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
AVBPrint public header.
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
#define FLAGS
Definition cmdutils.c:596
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Definition codec_par.c:107
#define av_clip64
Definition common.h:103
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
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)
Definition dash.c:95
static int dash_read_header(AVFormatContext *s)
Definition dashdec.c:2248
#define SET_REPRESENTATION_SEQUENCE_BASE_INFO(arg, cnt)
Definition dashdec.c:867
static enum AVMediaType get_content_type(xmlNodePtr node)
Definition dashdec.c:571
static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, AVDictionary **opts, AVDictionary *opts2, int *is_http)
Definition dashdec.c:420
#define INITIAL_BUFFER_SIZE
Definition dashdec.c:36
static int is_common_init_section_exist(struct representation **pls, int n_pls)
Definition dashdec.c:2198
static const AVOption dash_options[]
Definition dashdec.c:2647
static struct fragment * get_current_fragment(struct representation *pls)
Definition dashdec.c:1700
static int update_init_section(struct representation *pls)
Definition dashdec.c:1894
static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t seek_pos_msec, int flags, int dry_run)
Definition dashdec.c:2532
static int read_data(void *opaque, uint8_t *buf, int buf_size)
Definition dashdec.c:1950
static int open_demux_for_component(AVFormatContext *s, struct representation *pls)
Definition dashdec.c:2121
static int parse_manifest_adaptationset_attr(AVFormatContext *s, xmlNodePtr adaptionset_node)
Definition dashdec.c:1199
static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representation *rep, xmlNodePtr fragmenturl_node, xmlNodePtr *baseurl_nodes, char *rep_id_val, char *rep_bandwidth_val)
Definition dashdec.c:620
static int64_t get_utc_date_time_insec(AVFormatContext *s, const char *datetime)
Definition dashdec.c:193
static void recheck_discard_flags(AVFormatContext *s, struct representation **p, int n)
Definition dashdec.c:2422
static void move_metadata(AVStream *st, const char *key, char **value)
Definition dashdec.c:2240
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)
Definition dashdec.c:904
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)
Definition dashdec.c:487
static int copy_init_section(struct representation *rep_dest, struct representation *rep_src)
Definition dashdec.c:2225
static const AVClass dash_class
Definition dashdec.c:2659
static int64_t get_segment_start_time_based_on_timeline(struct representation *pls, int64_t cur_seq_no)
Definition dashdec.c:267
static int reopen_demux_for_component(AVFormatContext *s, struct representation *pls)
Definition dashdec.c:2040
static int dash_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition dashdec.c:2450
static int64_t calc_min_seg_no(AVFormatContext *s, struct representation *pls)
Definition dashdec.c:1523
static int64_t get_current_time_in_sec(void)
Definition dashdec.c:188
static int ishttp(const char *url)
Definition dashdec.c:174
static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **opts)
Definition dashdec.c:2021
static void free_representation(struct representation *pls)
Definition dashdec.c:364
static void free_audio_list(DASHContext *c)
Definition dashdec.c:398
static uint32_t get_duration_insec(AVFormatContext *s, const char *duration)
Definition dashdec.c:223
static void move_timelines(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
Definition dashdec.c:1562
static int64_t calc_cur_seg_no(AVFormatContext *s, struct representation *pls)
Definition dashdec.c:1487
#define MAX_TIMELINE_SEGMENTS
Definition dashdec.c:37
static void free_subtitle_list(DASHContext *c)
Definition dashdec.c:409
static int dash_close(AVFormatContext *s)
Definition dashdec.c:2521
static void close_demux_for_component(struct representation *pls)
Definition dashdec.c:2031
static int add_url_size(int *url_size, uint64_t len)
Definition dashdec.c:180
static int64_t seek_data(void *opaque, int64_t offset, int whence)
Definition dashdec.c:1940
static int dash_probe(const AVProbeData *p)
Definition dashdec.c:2626
static int open_input(DASHContext *c, struct representation *pls, struct fragment *seg)
Definition dashdec.c:1862
static xmlNodePtr find_child_node_by_name(xmlNodePtr rootnode, const char *nodename)
Definition dashdec.c:554
static int refresh_manifest(AVFormatContext *s)
Definition dashdec.c:1597
static struct fragment * get_fragment(AVFormatContext *s, char *range)
Definition dashdec.c:597
static int64_t calc_next_seg_no_from_timelines(struct representation *pls, int64_t cur_time)
Definition dashdec.c:303
static void free_fragment(struct fragment **seg)
Definition dashdec.c:333
static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
Definition dashdec.c:1297
static void move_segments(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
Definition dashdec.c:1576
#define OFFSET(x)
Definition dashdec.c:2645
static int64_t calc_max_seg_no(struct representation *pls, DASHContext *c)
Definition dashdec.c:1537
static int read_from_url(struct representation *pls, struct fragment *seg, uint8_t *buf, int buf_size)
Definition dashdec.c:1843
static int parse_programinformation(AVFormatContext *s, xmlNodePtr node)
Definition dashdec.c:1268
static char * get_val_from_nodes_tab(xmlNodePtr *nodes, const int n_nodes, const char *attrname)
Definition dashdec.c:538
static int dash_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition dashdec.c:2598
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)
Definition dashdec.c:1212
static void free_fragment_list(struct representation *pls)
Definition dashdec.c:342
static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representation *rep, xmlNodePtr fragment_timeline_node)
Definition dashdec.c:686
static void free_timelines_list(struct representation *pls)
Definition dashdec.c:353
static void free_video_list(DASHContext *c)
Definition dashdec.c:387
static int resolve_content_path(AVFormatContext *s, const char *url, int *max_url_size, xmlNodePtr *baseurl_nodes, int n_baseurl_nodes)
Definition dashdec.c:727
#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...
Definition demux.h:35
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
Definition seek.c:835
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
Definition demux.h:234
static AVPacket * pkt
enum AVCodecID id
Definition dts2pts.c:612
double value
Definition eval.c:102
const char * key
static int64_t duration
Definition ffplay.c:359
char * path
Definition ffplay.c:385
int ret
Definition ffplay.c:391
static int64_t start_time
Definition ffplay.c:358
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:580
static av_cold void cleanup(FlashSV2Context *s)
#define fail
Definition test.h:479
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ 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...
Definition opt.h:275
@ AV_CODEC_ID_LCEVC
Definition codec_id.h:615
@ AVDISCARD_ALL
discard all
Definition defs.h:248
AVProgram * av_new_program(AVFormatContext *ac, int id)
Definition avformat.c:299
AVStreamGroup * avformat_stream_group_create(AVFormatContext *s, enum AVStreamGroupParamsType type, AVDictionary **options)
Add a new empty stream group to a media file.
Definition options.c:474
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.
Definition options.c:589
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition options.c:165
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition avformat.c:165
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition demux.c:1662
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.
Definition format.c:373
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
Definition seek.c:714
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition demux.c:231
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition demux.c:2690
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition demux.c:400
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.
Definition format.c:41
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:234
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:236
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition dict.c:61
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition dict.c:250
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition dict.h:79
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:87
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition dict.h:74
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.
Definition dict.c:180
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition error.h:58
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
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.
Definition mathematics.c:58
@ 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.
Definition mem.c:419
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition mem.c:661
AVMediaType
Definition avutil.h:198
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition avutil.h:199
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,...
Definition avstring.c:95
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle.
Definition avstring.c:58
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().
Definition avstring.c:179
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition avstring.c:208
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition avstring.c:36
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.
Definition avstring.c:85
char * av_strireplace(const char *str, const char *from, const char *to)
Locale-independent strings replace.
Definition avstring.c:230
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
Definition avstring.c:218
#define AV_TIME_BASE
Internal time base represented as integer.
Definition avutil.h:253
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition opt.c:1304
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition opt.h:604
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition opt.c:2239
enum MPFType type
Definition jpegmpfenc.c:55
unsigned offset
Definition libaomenc.c:812
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:392
static av_always_inline const FFStream * cffstream(const AVStream *st)
Definition internal.h:397
#define MAX_URL_SIZE
Definition internal.h:30
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
static av_cold int read_close(AVFormatContext *ctx)
Definition libcdio.c:143
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition libcdio.c:151
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
enum AVColorRange range
Memory handling functions.
#define av_strdup(s)
Definition ops_static.c:55
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition parseutils.c:181
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.
Definition parseutils.c:573
misc parsing utilities
Describe the class of an AVClass context structure.
Definition log.h:76
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1401
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition avformat.h:1457
AVStreamGroup ** stream_groups
A list of all stream groups in the file.
Definition avformat.h:1489
AVIOContext * pb
I/O context.
Definition avformat.h:1443
int flags
Flags modifying the (de)muxer behaviour.
Definition avformat.h:1553
int64_t max_analyze_duration
Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info().
Definition avformat.h:1609
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition avformat.h:1687
unsigned int nb_stream_groups
Number of elements in AVFormatContext.stream_groups.
Definition avformat.h:1476
void * priv_data
Format private data.
Definition avformat.h:1429
int64_t probesize
Maximum number of bytes read from input in order to determine stream properties.
Definition avformat.h:1601
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1469
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
Definition avformat.h:2027
Bytestream IO Context.
Definition avio.h:160
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition avio.h:261
unsigned char * buffer
Start of the buffer.
Definition avio.h:225
Callback for checking whether to abort blocking functions.
Definition avio.h:59
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
This structure contains the data a format has to probe a file.
Definition avformat.h:473
New fields can be added to the end with minor version bumps.
Definition avformat.h:1325
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
AVStream * stream
Definition avformat.h:1180
AVStreamGroupLayeredVideo is meant to define the relation between a base layer video stream and a sep...
Definition avformat.h:1104
int height
Height of the final image for presentation.
Definition avformat.h:1129
unsigned int el_index
Index of the enhancement layer stream in AVStreamGroup.
Definition avformat.h:1113
int width
Width of the final stream for presentation.
Definition avformat.h:1125
unsigned int nb_entries
Number of elements in AVStreamGroup.entries.
Definition avformat.h:1286
enum AVStreamGroupParamsType type
Group type.
Definition avformat.h:1212
AVStreamGroupEntry ** entries
A list of streams or child groups in the group.
Definition avformat.h:1299
unsigned int index
Group index in AVFormatContext.
Definition avformat.h:1196
union AVStreamGroup::@313244315204024013007202273061153315146016101155 params
Group type-specific parameters.
int disposition
Stream group disposition - a combination of AV_DISPOSITION_* flags.
Definition avformat.h:1278
int64_t id
Group type-specific group ID.
Definition avformat.h:1204
struct AVStreamGroupLayeredVideo * layered_video
Definition avformat.h:1221
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition avformat.h:839
AVDictionary * metadata
Definition avformat.h:848
int id
Format-specific stream ID.
Definition avformat.h:780
int index
stream index in AVFormatContext
Definition avformat.h:774
int pts_wrap_bits
Number of bits in timestamps.
Definition avformat.h:911
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:807
AVRational r_frame_rate
Real base framerate of the stream.
Definition avformat.h:902
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition avformat.h:837
int is_init_section_common_video
Definition dashdec.c:168
int64_t availability_end_time
Definition dashdec.c:145
int max_url_size
Definition dashdec.c:162
char * adaptionset_lang
Definition dashdec.c:156
int64_t minimum_update_period
Definition dashdec.c:147
int is_init_section_common_audio
Definition dashdec.c:169
int64_t media_presentation_duration
Definition dashdec.c:142
int64_t suggested_presentation_delay
Definition dashdec.c:143
AVDictionary * avio_opts
Definition dashdec.c:161
char * cenc_decryption_key
Definition dashdec.c:164
int n_subtitles
Definition dashdec.c:138
uint64_t period_start
Definition dashdec.c:153
int64_t publish_time
Definition dashdec.c:146
struct representation ** videos
Definition dashdec.c:135
struct representation ** subtitles
Definition dashdec.c:139
char * base_url
Definition dashdec.c:132
int n_audios
Definition dashdec.c:136
int is_init_section_common_subtitle
Definition dashdec.c:170
char * allowed_extensions
Definition dashdec.c:160
int64_t min_buffer_time
Definition dashdec.c:149
int64_t availability_start_time
Definition dashdec.c:144
int is_live
Definition dashdec.c:158
int64_t time_shift_buffer_depth
Definition dashdec.c:148
int n_videos
Definition dashdec.c:134
AVIOInterruptCB * interrupt_callback
Definition dashdec.c:159
char * cenc_decryption_keys
Definition dashdec.c:165
uint64_t period_duration
Definition dashdec.c:152
int max_reload
Definition dashdec.c:163
struct representation ** audios
Definition dashdec.c:137
AVIOContext pub
enum AVStreamParseType need_parsing
Definition internal.h:346
char * url
Definition dashdec.c:42
int64_t url_offset
Definition dashdec.c:40
int64_t size
Definition dashdec.c:41
char * url_template
Definition dashdec.c:82
int n_open_failures
Definition dashdec.c:118
char * lang
Definition dashdec.c:91
int64_t last_seq_no
Definition dashdec.c:106
char * codecs
Definition dashdec.c:94
AVRational framerate
Definition dashdec.c:95
uint32_t init_sec_data_len
Definition dashdec.c:124
int64_t cur_seg_offset
Definition dashdec.c:115
AVIOContext * input
Definition dashdec.c:84
struct timeline ** timelines
Definition dashdec.c:103
struct fragment * cur_seg
Definition dashdec.c:117
char * dependencyid
Definition dashdec.c:93
int64_t first_seq_no
Definition dashdec.c:105
FFIOContext pb
Definition dashdec.c:83
char * id
Definition dashdec.c:90
uint32_t init_sec_buf_size
Definition dashdec.c:123
int64_t cur_timestamp
Definition dashdec.c:126
uint32_t init_sec_buf_read_offset
Definition dashdec.c:125
enum AVMediaType type
Definition dashdec.c:88
int64_t presentation_timeoffset
Definition dashdec.c:112
int n_fragments
Definition dashdec.c:99
int64_t cur_seg_size
Definition dashdec.c:116
AVStream ** assoc_stream
Definition dashdec.c:96
struct fragment ** fragments
Definition dashdec.c:100
int64_t fragment_timescale
Definition dashdec.c:110
struct fragment * init_section
Definition dashdec.c:121
int stream_index
Definition dashdec.c:87
uint8_t * init_sec_buf
Definition dashdec.c:122
int64_t start_number
Definition dashdec.c:107
AVFormatContext * ctx
Definition dashdec.c:86
int is_restart_needed
Definition dashdec.c:127
int nb_assoc_stream
Definition dashdec.c:97
AVFormatContext * parent
Definition dashdec.c:85
int64_t fragment_duration
Definition dashdec.c:109
int64_t cur_seq_no
Definition dashdec.c:114
int64_t repeat
Definition dashdec.c:69
int64_t starttime
Definition dashdec.c:63
int64_t duration
Definition dashdec.c:73
#define av_free(p)
#define av_malloc_array(a, b)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
int num
Definition error.c:23
static int ref[MAX_W *MAX_W]
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition time.c:93
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition time.c:57
int64_t av_gettime(void)
Get the current time in microseconds.
Definition time.c:40
int size
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.
Definition url.c:321
unbuffered private I/O API
int len
static double c[64]