FFmpeg  4.4.7
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 "libavutil/intreadwrite.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/time.h"
26 #include "libavutil/parseutils.h"
27 #include "internal.h"
28 #include "avio_internal.h"
29 #include "dash.h"
30 
31 #define INITIAL_BUFFER_SIZE 32768
32 #define MAX_BPRINT_READ_SIZE (UINT_MAX - 1)
33 #define DEFAULT_MANIFEST_SIZE 8 * 1024
34 
35 struct fragment {
38  char *url;
39 };
40 
41 /*
42  * reference to : ISO_IEC_23009-1-DASH-2012
43  * Section: 5.3.9.6.2
44  * Table: Table 17 — Semantics of SegmentTimeline element
45  * */
46 struct timeline {
47  /* starttime: Element or Attribute Name
48  * specifies the MPD start time, in @timescale units,
49  * the first Segment in the series starts relative to the beginning of the Period.
50  * The value of this attribute must be equal to or greater than the sum of the previous S
51  * element earliest presentation time and the sum of the contiguous Segment durations.
52  * If the value of the attribute is greater than what is expressed by the previous S element,
53  * it expresses discontinuities in the timeline.
54  * If not present then the value shall be assumed to be zero for the first S element
55  * and for the subsequent S elements, the value shall be assumed to be the sum of
56  * the previous S element's earliest presentation time and contiguous duration
57  * (i.e. previous S@starttime + @duration * (@repeat + 1)).
58  * */
60  /* repeat: Element or Attribute Name
61  * specifies the repeat count of the number of following contiguous Segments with
62  * the same duration expressed by the value of @duration. This value is zero-based
63  * (e.g. a value of three means four Segments in the contiguous series).
64  * */
66  /* duration: Element or Attribute Name
67  * specifies the Segment duration, in units of the value of the @timescale.
68  * */
70 };
71 
72 /*
73  * Each playlist has its own demuxer. If it is currently active,
74  * it has an opened AVIOContext too, and potentially an AVPacket
75  * containing the next packet from this stream.
76  */
78  char *url_template;
84 
85  char *id;
86  char *lang;
87  int bandwidth;
89  AVStream *assoc_stream; /* demuxer stream associated with this representation */
90 
92  struct fragment **fragments; /* VOD list of fragment for profile */
93 
95  struct timeline **timelines;
96 
99  int64_t start_number; /* used in case when we have dynamic list of segment to know which segments are new one*/
100 
103 
105 
109  struct fragment *cur_seg;
110 
111  /* Currently active Media Initialization Section */
119 };
120 
121 typedef struct DASHContext {
122  const AVClass *class;
123  char *base_url;
124 
125  int n_videos;
127  int n_audios;
131 
132  /* MediaPresentationDescription Attribute */
137  uint64_t publish_time;
140  uint64_t min_buffer_time;
141 
142  /* Period Attribute */
143  uint64_t period_duration;
144  uint64_t period_start;
145 
146  /* AdaptationSet Attribute */
148 
149  int is_live;
154 
155  /* Flags for init section*/
159 
160 } DASHContext;
161 
162 static int ishttp(char *url)
163 {
164  const char *proto_name = avio_find_protocol_name(url);
165  return proto_name && av_strstart(proto_name, "http", NULL);
166 }
167 
168 static int aligned(int val)
169 {
170  return ((val + 0x3F) >> 6) << 6;
171 }
172 
173 static uint64_t get_current_time_in_sec(void)
174 {
175  return av_gettime() / 1000000;
176 }
177 
178 static uint64_t get_utc_date_time_insec(AVFormatContext *s, const char *datetime)
179 {
180  struct tm timeinfo;
181  int year = 0;
182  int month = 0;
183  int day = 0;
184  int hour = 0;
185  int minute = 0;
186  int ret = 0;
187  float second = 0.0;
188 
189  /* ISO-8601 date parser */
190  if (!datetime)
191  return 0;
192 
193  ret = sscanf(datetime, "%d-%d-%dT%d:%d:%fZ", &year, &month, &day, &hour, &minute, &second);
194  /* year, month, day, hour, minute, second 6 arguments */
195  if (ret != 6) {
196  av_log(s, AV_LOG_WARNING, "get_utc_date_time_insec get a wrong time format\n");
197  }
198  timeinfo.tm_year = year - 1900;
199  timeinfo.tm_mon = month - 1;
200  timeinfo.tm_mday = day;
201  timeinfo.tm_hour = hour;
202  timeinfo.tm_min = minute;
203  timeinfo.tm_sec = (int)second;
204 
205  return av_timegm(&timeinfo);
206 }
207 
208 static uint32_t get_duration_insec(AVFormatContext *s, const char *duration)
209 {
210  /* ISO-8601 duration parser */
211  uint32_t days = 0;
212  uint32_t hours = 0;
213  uint32_t mins = 0;
214  uint32_t secs = 0;
215  int size = 0;
216  float value = 0;
217  char type = '\0';
218  const char *ptr = duration;
219 
220  while (*ptr) {
221  if (*ptr == 'P' || *ptr == 'T') {
222  ptr++;
223  continue;
224  }
225 
226  if (sscanf(ptr, "%f%c%n", &value, &type, &size) != 2) {
227  av_log(s, AV_LOG_WARNING, "get_duration_insec get a wrong time format\n");
228  return 0; /* parser error */
229  }
230  switch (type) {
231  case 'D':
232  days = (uint32_t)value;
233  break;
234  case 'H':
235  hours = (uint32_t)value;
236  break;
237  case 'M':
238  mins = (uint32_t)value;
239  break;
240  case 'S':
241  secs = (uint32_t)value;
242  break;
243  default:
244  // handle invalid type
245  break;
246  }
247  ptr += size;
248  }
249  return ((days * 24 + hours) * 60 + mins) * 60 + secs;
250 }
251 
253 {
254  int64_t start_time = 0;
255  int64_t i = 0;
256  int64_t j = 0;
257  int64_t num = 0;
258 
259  if (pls->n_timelines) {
260  for (i = 0; i < pls->n_timelines; i++) {
261  if (pls->timelines[i]->starttime > 0) {
262  start_time = pls->timelines[i]->starttime;
263  }
264  if (num == cur_seq_no)
265  goto finish;
266 
267  start_time += pls->timelines[i]->duration;
268 
269  if (pls->timelines[i]->repeat == -1) {
270  start_time = pls->timelines[i]->duration * cur_seq_no;
271  goto finish;
272  }
273 
274  for (j = 0; j < pls->timelines[i]->repeat; j++) {
275  num++;
276  if (num == cur_seq_no)
277  goto finish;
278  start_time += pls->timelines[i]->duration;
279  }
280  num++;
281  }
282  }
283 finish:
284  return start_time;
285 }
286 
288 {
289  int64_t i = 0;
290  int64_t j = 0;
291  int64_t num = 0;
292  int64_t start_time = 0;
293 
294  for (i = 0; i < pls->n_timelines; i++) {
295  if (pls->timelines[i]->starttime > 0) {
296  start_time = pls->timelines[i]->starttime;
297  }
298  if (start_time > cur_time)
299  goto finish;
300 
301  start_time += pls->timelines[i]->duration;
302  for (j = 0; j < pls->timelines[i]->repeat; j++) {
303  num++;
304  if (start_time > cur_time)
305  goto finish;
306  start_time += pls->timelines[i]->duration;
307  }
308  num++;
309  }
310 
311  return -1;
312 
313 finish:
314  return num;
315 }
316 
317 static void free_fragment(struct fragment **seg)
318 {
319  if (!(*seg)) {
320  return;
321  }
322  av_freep(&(*seg)->url);
323  av_freep(seg);
324 }
325 
326 static void free_fragment_list(struct representation *pls)
327 {
328  int i;
329 
330  for (i = 0; i < pls->n_fragments; i++) {
331  free_fragment(&pls->fragments[i]);
332  }
333  av_freep(&pls->fragments);
334  pls->n_fragments = 0;
335 }
336 
337 static void free_timelines_list(struct representation *pls)
338 {
339  int i;
340 
341  for (i = 0; i < pls->n_timelines; i++) {
342  av_freep(&pls->timelines[i]);
343  }
344  av_freep(&pls->timelines);
345  pls->n_timelines = 0;
346 }
347 
348 static void free_representation(struct representation *pls)
349 {
350  free_fragment_list(pls);
351  free_timelines_list(pls);
352  free_fragment(&pls->cur_seg);
354  av_freep(&pls->init_sec_buf);
355  av_freep(&pls->pb.buffer);
356  ff_format_io_close(pls->parent, &pls->input);
357  if (pls->ctx) {
358  pls->ctx->pb = NULL;
359  avformat_close_input(&pls->ctx);
360  }
361 
362  av_freep(&pls->url_template);
363  av_freep(&pls->lang);
364  av_freep(&pls->id);
365  av_freep(&pls);
366 }
367 
369 {
370  int i;
371  for (i = 0; i < c->n_videos; i++) {
372  struct representation *pls = c->videos[i];
373  free_representation(pls);
374  }
375  av_freep(&c->videos);
376  c->n_videos = 0;
377 }
378 
380 {
381  int i;
382  for (i = 0; i < c->n_audios; i++) {
383  struct representation *pls = c->audios[i];
384  free_representation(pls);
385  }
386  av_freep(&c->audios);
387  c->n_audios = 0;
388 }
389 
391 {
392  int i;
393  for (i = 0; i < c->n_subtitles; i++) {
394  struct representation *pls = c->subtitles[i];
395  free_representation(pls);
396  }
397  av_freep(&c->subtitles);
398  c->n_subtitles = 0;
399 }
400 
401 static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
402  AVDictionary **opts, AVDictionary *opts2, int *is_http)
403 {
404  DASHContext *c = s->priv_data;
405  AVDictionary *tmp = NULL;
406  const char *proto_name = NULL;
407  int ret;
408 
409  if (av_strstart(url, "crypto", NULL)) {
410  if (url[6] == '+' || url[6] == ':')
411  proto_name = avio_find_protocol_name(url + 7);
412  }
413 
414  if (!proto_name)
415  proto_name = avio_find_protocol_name(url);
416 
417  if (!proto_name)
418  return AVERROR_INVALIDDATA;
419 
420  // only http(s) & file are allowed
421  if (av_strstart(proto_name, "file", NULL)) {
422  if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, c->allowed_extensions)) {
424  "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n"
425  "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",
426  url);
427  return AVERROR_INVALIDDATA;
428  }
429  } else if (av_strstart(proto_name, "http", NULL)) {
430  ;
431  } else
432  return AVERROR_INVALIDDATA;
433 
434  if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')
435  ;
436  else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')
437  ;
438  else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
439  return AVERROR_INVALIDDATA;
440 
441  av_freep(pb);
442  av_dict_copy(&tmp, *opts, 0);
443  av_dict_copy(&tmp, opts2, 0);
444  ret = ffio_open_whitelist(pb, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp, s->protocol_whitelist, s->protocol_blacklist);
445  if (ret >= 0) {
446  // update cookies on http response with setcookies.
447  char *new_cookies = NULL;
448 
449  if (!(s->flags & AVFMT_FLAG_CUSTOM_IO))
450  av_opt_get(*pb, "cookies", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&new_cookies);
451 
452  if (new_cookies) {
453  av_dict_set(opts, "cookies", new_cookies, AV_DICT_DONT_STRDUP_VAL);
454  }
455 
456  }
457 
458  av_dict_free(&tmp);
459 
460  if (is_http)
461  *is_http = av_strstart(proto_name, "http", NULL);
462 
463  return ret;
464 }
465 
466 static char *get_content_url(xmlNodePtr *baseurl_nodes,
467  int n_baseurl_nodes,
468  int max_url_size,
469  char *rep_id_val,
470  char *rep_bandwidth_val,
471  char *val)
472 {
473  int i;
474  char *text;
475  char *url = NULL;
476  char *tmp_str = av_mallocz(max_url_size);
477 
478  if (!tmp_str)
479  return NULL;
480 
481  for (i = 0; i < n_baseurl_nodes; ++i) {
482  if (baseurl_nodes[i] &&
483  baseurl_nodes[i]->children &&
484  baseurl_nodes[i]->children->type == XML_TEXT_NODE) {
485  text = xmlNodeGetContent(baseurl_nodes[i]->children);
486  if (text) {
487  memset(tmp_str, 0, max_url_size);
488  ff_make_absolute_url(tmp_str, max_url_size, "", text);
489  xmlFree(text);
490  }
491  }
492  }
493 
494  if (val)
495  ff_make_absolute_url(tmp_str, max_url_size, tmp_str, val);
496 
497  if (rep_id_val) {
498  url = av_strireplace(tmp_str, "$RepresentationID$", rep_id_val);
499  if (!url) {
500  goto end;
501  }
502  av_strlcpy(tmp_str, url, max_url_size);
503  }
504  if (rep_bandwidth_val && tmp_str[0] != '\0') {
505  // free any previously assigned url before reassigning
506  av_free(url);
507  url = av_strireplace(tmp_str, "$Bandwidth$", rep_bandwidth_val);
508  if (!url) {
509  goto end;
510  }
511  }
512 end:
513  av_free(tmp_str);
514  return url;
515 }
516 
517 static char *get_val_from_nodes_tab(xmlNodePtr *nodes, const int n_nodes, const char *attrname)
518 {
519  int i;
520  char *val;
521 
522  for (i = 0; i < n_nodes; ++i) {
523  if (nodes[i]) {
524  val = xmlGetProp(nodes[i], attrname);
525  if (val)
526  return val;
527  }
528  }
529 
530  return NULL;
531 }
532 
533 static xmlNodePtr find_child_node_by_name(xmlNodePtr rootnode, const char *nodename)
534 {
535  xmlNodePtr node = rootnode;
536  if (!node) {
537  return NULL;
538  }
539 
540  node = xmlFirstElementChild(node);
541  while (node) {
542  if (!av_strcasecmp(node->name, nodename)) {
543  return node;
544  }
545  node = xmlNextElementSibling(node);
546  }
547  return NULL;
548 }
549 
550 static enum AVMediaType get_content_type(xmlNodePtr node)
551 {
553  int i = 0;
554  const char *attr;
555  char *val = NULL;
556 
557  if (node) {
558  for (i = 0; i < 2; i++) {
559  attr = i ? "mimeType" : "contentType";
560  val = xmlGetProp(node, attr);
561  if (val) {
562  if (av_stristr(val, "video")) {
564  } else if (av_stristr(val, "audio")) {
566  } else if (av_stristr(val, "text")) {
568  }
569  xmlFree(val);
570  }
571  }
572  }
573  return type;
574 }
575 
576 static struct fragment * get_Fragment(char *range)
577 {
578  struct fragment * seg = av_mallocz(sizeof(struct fragment));
579 
580  if (!seg)
581  return NULL;
582 
583  seg->size = -1;
584  if (range) {
585  char *str_end_offset;
586  char *str_offset = av_strtok(range, "-", &str_end_offset);
587  seg->url_offset = strtoll(str_offset, NULL, 10);
588  seg->size = strtoll(str_end_offset, NULL, 10) - seg->url_offset + 1;
589  }
590 
591  return seg;
592 }
593 
595  xmlNodePtr fragmenturl_node,
596  xmlNodePtr *baseurl_nodes,
597  char *rep_id_val,
598  char *rep_bandwidth_val)
599 {
600  DASHContext *c = s->priv_data;
601  char *initialization_val = NULL;
602  char *media_val = NULL;
603  char *range_val = NULL;
604  int max_url_size = c ? c->max_url_size: MAX_URL_SIZE;
605  int err;
606 
607  if (!av_strcasecmp(fragmenturl_node->name, "Initialization")) {
608  initialization_val = xmlGetProp(fragmenturl_node, "sourceURL");
609  range_val = xmlGetProp(fragmenturl_node, "range");
610  if (initialization_val || range_val) {
612  rep->init_section = get_Fragment(range_val);
613  xmlFree(range_val);
614  if (!rep->init_section) {
615  xmlFree(initialization_val);
616  return AVERROR(ENOMEM);
617  }
618  rep->init_section->url = get_content_url(baseurl_nodes, 4,
619  max_url_size,
620  rep_id_val,
621  rep_bandwidth_val,
622  initialization_val);
623  xmlFree(initialization_val);
624  if (!rep->init_section->url) {
625  av_freep(&rep->init_section);
626  return AVERROR(ENOMEM);
627  }
628  }
629  } else if (!av_strcasecmp(fragmenturl_node->name, "SegmentURL")) {
630  media_val = xmlGetProp(fragmenturl_node, "media");
631  range_val = xmlGetProp(fragmenturl_node, "mediaRange");
632  if (media_val || range_val) {
633  struct fragment *seg = get_Fragment(range_val);
634  xmlFree(range_val);
635  if (!seg) {
636  xmlFree(media_val);
637  return AVERROR(ENOMEM);
638  }
639  seg->url = get_content_url(baseurl_nodes, 4,
640  max_url_size,
641  rep_id_val,
642  rep_bandwidth_val,
643  media_val);
644  xmlFree(media_val);
645  if (!seg->url) {
646  av_free(seg);
647  return AVERROR(ENOMEM);
648  }
649  err = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg);
650  if (err < 0) {
651  free_fragment(&seg);
652  return err;
653  }
654  }
655  }
656 
657  return 0;
658 }
659 
661  xmlNodePtr fragment_timeline_node)
662 {
663  xmlAttrPtr attr = NULL;
664  char *val = NULL;
665  int err;
666 
667  if (!av_strcasecmp(fragment_timeline_node->name, "S")) {
668  struct timeline *tml = av_mallocz(sizeof(struct timeline));
669  if (!tml) {
670  return AVERROR(ENOMEM);
671  }
672  attr = fragment_timeline_node->properties;
673  while (attr) {
674  val = xmlGetProp(fragment_timeline_node, attr->name);
675 
676  if (!val) {
677  av_log(s, AV_LOG_WARNING, "parse_manifest_segmenttimeline attr->name = %s val is NULL\n", attr->name);
678  continue;
679  }
680 
681  if (!av_strcasecmp(attr->name, "t")) {
682  tml->starttime = (int64_t)strtoll(val, NULL, 10);
683  } else if (!av_strcasecmp(attr->name, "r")) {
684  tml->repeat =(int64_t) strtoll(val, NULL, 10);
685  } else if (!av_strcasecmp(attr->name, "d")) {
686  tml->duration = (int64_t)strtoll(val, NULL, 10);
687  }
688  attr = attr->next;
689  xmlFree(val);
690  }
691  err = av_dynarray_add_nofree(&rep->timelines, &rep->n_timelines, tml);
692  if (err < 0) {
693  av_free(tml);
694  return err;
695  }
696  }
697 
698  return 0;
699 }
700 
701 static int resolve_content_path(AVFormatContext *s, const char *url, int *max_url_size, xmlNodePtr *baseurl_nodes, int n_baseurl_nodes)
702 {
703  char *tmp_str = NULL;
704  char *path = NULL;
705  char *mpdName = NULL;
706  xmlNodePtr node = NULL;
707  char *baseurl = NULL;
708  char *root_url = NULL;
709  char *text = NULL;
710  char *tmp = NULL;
711  int isRootHttp = 0;
712  char token ='/';
713  int start = 0;
714  int rootId = 0;
715  int updated = 0;
716  int size = 0;
717  int i;
718  int tmp_max_url_size = strlen(url);
719 
720  for (i = n_baseurl_nodes-1; i >= 0 ; i--) {
721  text = xmlNodeGetContent(baseurl_nodes[i]);
722  if (!text)
723  continue;
724  tmp_max_url_size += strlen(text);
725  if (ishttp(text)) {
726  xmlFree(text);
727  break;
728  }
729  xmlFree(text);
730  }
731 
732  tmp_max_url_size = aligned(tmp_max_url_size);
733  text = av_mallocz(tmp_max_url_size + 1);
734  if (!text) {
735  updated = AVERROR(ENOMEM);
736  goto end;
737  }
738  av_strlcpy(text, url, strlen(url)+1);
739  tmp = text;
740  while (mpdName = av_strtok(tmp, "/", &tmp)) {
741  size = strlen(mpdName);
742  }
743  av_free(text);
744 
745  path = av_mallocz(tmp_max_url_size + 2);
746  tmp_str = av_mallocz(tmp_max_url_size);
747  if (!tmp_str || !path) {
748  updated = AVERROR(ENOMEM);
749  goto end;
750  }
751 
752  av_strlcpy (path, url, strlen(url) - size + 1);
753  for (rootId = n_baseurl_nodes - 1; rootId > 0; rootId --) {
754  if (!(node = baseurl_nodes[rootId])) {
755  continue;
756  }
757  text = xmlNodeGetContent(node);
758  if (ishttp(text)) {
759  xmlFree(text);
760  break;
761  }
762  xmlFree(text);
763  }
764 
765  node = baseurl_nodes[rootId];
766  baseurl = xmlNodeGetContent(node);
767  if (baseurl) {
768  size_t len = xmlStrlen(baseurl)+2;
769  char *tmp = xmlRealloc(baseurl, len);
770  if (!tmp) {
771  updated = AVERROR(ENOMEM);
772  goto end;
773  }
774  baseurl = tmp;
775  }
776  root_url = (av_strcasecmp(baseurl, "")) ? baseurl : path;
777  if (node) {
778  xmlNodeSetContent(node, root_url);
779  updated = 1;
780  }
781 
782  size = strlen(root_url);
783  isRootHttp = ishttp(root_url);
784 
785  if (size > 0 && root_url[size - 1] != token) {
786  av_strlcat(root_url, "/", size + 2);
787  size += 2;
788  }
789 
790  for (i = 0; i < n_baseurl_nodes; ++i) {
791  if (i == rootId) {
792  continue;
793  }
794  text = xmlNodeGetContent(baseurl_nodes[i]);
795  if (text && !av_strstart(text, "/", NULL)) {
796  memset(tmp_str, 0, strlen(tmp_str));
797  if (!ishttp(text) && isRootHttp) {
798  av_strlcpy(tmp_str, root_url, size + 1);
799  }
800  start = (text[0] == token);
801  if (start && av_stristr(tmp_str, text)) {
802  char *p = tmp_str;
803  if (!av_strncasecmp(tmp_str, "http://", 7)) {
804  p += 7;
805  } else if (!av_strncasecmp(tmp_str, "https://", 8)) {
806  p += 8;
807  }
808  p = strchr(p, '/');
809  memset(p + 1, 0, strlen(p));
810  }
811  av_strlcat(tmp_str, text + start, tmp_max_url_size);
812  xmlNodeSetContent(baseurl_nodes[i], tmp_str);
813  updated = 1;
814  xmlFree(text);
815  }
816  }
817 
818 end:
819  if (tmp_max_url_size > *max_url_size) {
820  *max_url_size = tmp_max_url_size;
821  }
822  av_free(path);
823  av_free(tmp_str);
824  xmlFree(baseurl);
825  return updated;
826 
827 }
828 
829 #define SET_REPRESENTATION_SEQUENCE_BASE_INFO(arg, cnt) { \
830  val = get_val_from_nodes_tab((arg), (cnt), "duration"); \
831  if (val) { \
832  int64_t fragment_duration = (int64_t) strtoll(val, NULL, 10); \
833  if (fragment_duration < 0) { \
834  av_log(s, AV_LOG_WARNING, "duration invalid, autochanged to 0.\n"); \
835  fragment_duration = 0; \
836  } \
837  rep->fragment_duration = fragment_duration; \
838  av_log(s, AV_LOG_TRACE, "rep->fragment_duration = [%"PRId64"]\n", rep->fragment_duration); \
839  xmlFree(val); \
840  } \
841  val = get_val_from_nodes_tab((arg), (cnt), "timescale"); \
842  if (val) { \
843  int64_t fragment_timescale = (int64_t) strtoll(val, NULL, 10); \
844  if (fragment_timescale < 0) { \
845  av_log(s, AV_LOG_WARNING, "timescale invalid, autochanged to 0.\n"); \
846  fragment_timescale = 0; \
847  } \
848  rep->fragment_timescale = fragment_timescale; \
849  av_log(s, AV_LOG_TRACE, "rep->fragment_timescale = [%"PRId64"]\n", rep->fragment_timescale); \
850  xmlFree(val); \
851  } \
852  val = get_val_from_nodes_tab((arg), (cnt), "startNumber"); \
853  if (val) { \
854  int64_t start_number = (int64_t) strtoll(val, NULL, 10); \
855  if (start_number < 0) { \
856  av_log(s, AV_LOG_WARNING, "startNumber invalid, autochanged to 0.\n"); \
857  start_number = 0; \
858  } \
859  rep->start_number = rep->first_seq_no = start_number; \
860  av_log(s, AV_LOG_TRACE, "rep->first_seq_no = [%"PRId64"]\n", rep->first_seq_no); \
861  xmlFree(val); \
862  } \
863  }
864 
865 
866 static int parse_manifest_representation(AVFormatContext *s, const char *url,
867  xmlNodePtr node,
868  xmlNodePtr adaptionset_node,
869  xmlNodePtr mpd_baseurl_node,
870  xmlNodePtr period_baseurl_node,
871  xmlNodePtr period_segmenttemplate_node,
872  xmlNodePtr period_segmentlist_node,
873  xmlNodePtr fragment_template_node,
874  xmlNodePtr content_component_node,
875  xmlNodePtr adaptionset_baseurl_node,
876  xmlNodePtr adaptionset_segmentlist_node,
877  xmlNodePtr adaptionset_supplementalproperty_node)
878 {
879  int32_t ret = 0;
880  DASHContext *c = s->priv_data;
881  struct representation *rep = NULL;
882  struct fragment *seg = NULL;
883  xmlNodePtr representation_segmenttemplate_node = NULL;
884  xmlNodePtr representation_baseurl_node = NULL;
885  xmlNodePtr representation_segmentlist_node = NULL;
886  xmlNodePtr segmentlists_tab[3];
887  xmlNodePtr fragment_timeline_node = NULL;
888  xmlNodePtr fragment_templates_tab[5];
889  char *val = NULL;
890  xmlNodePtr baseurl_nodes[4];
891  xmlNodePtr representation_node = node;
892  char *rep_bandwidth_val;
894 
895  // try get information from representation
896  if (type == AVMEDIA_TYPE_UNKNOWN)
897  type = get_content_type(representation_node);
898  // try get information from contentComponen
899  if (type == AVMEDIA_TYPE_UNKNOWN)
900  type = get_content_type(content_component_node);
901  // try get information from adaption set
902  if (type == AVMEDIA_TYPE_UNKNOWN)
903  type = get_content_type(adaptionset_node);
906  av_log(s, AV_LOG_VERBOSE, "Parsing '%s' - skipp not supported representation type\n", url);
907  return 0;
908  }
909 
910  // convert selected representation to our internal struct
911  rep = av_mallocz(sizeof(struct representation));
912  if (!rep)
913  return AVERROR(ENOMEM);
914  if (c->adaptionset_lang) {
915  rep->lang = av_strdup(c->adaptionset_lang);
916  if (!rep->lang) {
917  av_log(s, AV_LOG_ERROR, "alloc language memory failure\n");
918  av_freep(&rep);
919  return AVERROR(ENOMEM);
920  }
921  }
922  rep->parent = s;
923  representation_segmenttemplate_node = find_child_node_by_name(representation_node, "SegmentTemplate");
924  representation_baseurl_node = find_child_node_by_name(representation_node, "BaseURL");
925  representation_segmentlist_node = find_child_node_by_name(representation_node, "SegmentList");
926  rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth");
927  val = xmlGetProp(representation_node, "id");
928  if (val) {
929  rep->id = av_strdup(val);
930  xmlFree(val);
931  if (!rep->id)
932  goto enomem;
933  }
934 
935  baseurl_nodes[0] = mpd_baseurl_node;
936  baseurl_nodes[1] = period_baseurl_node;
937  baseurl_nodes[2] = adaptionset_baseurl_node;
938  baseurl_nodes[3] = representation_baseurl_node;
939 
940  ret = resolve_content_path(s, url, &c->max_url_size, baseurl_nodes, 4);
941  c->max_url_size = aligned(c->max_url_size
942  + (rep->id ? strlen(rep->id) : 0)
943  + (rep_bandwidth_val ? strlen(rep_bandwidth_val) : 0));
944  if (ret == AVERROR(ENOMEM) || ret == 0)
945  goto free;
946  if (representation_segmenttemplate_node || fragment_template_node || period_segmenttemplate_node) {
947  fragment_timeline_node = NULL;
948  fragment_templates_tab[0] = representation_segmenttemplate_node;
949  fragment_templates_tab[1] = adaptionset_segmentlist_node;
950  fragment_templates_tab[2] = fragment_template_node;
951  fragment_templates_tab[3] = period_segmenttemplate_node;
952  fragment_templates_tab[4] = period_segmentlist_node;
953 
954  val = get_val_from_nodes_tab(fragment_templates_tab, 4, "initialization");
955  if (val) {
956  rep->init_section = av_mallocz(sizeof(struct fragment));
957  if (!rep->init_section) {
958  xmlFree(val);
959  goto enomem;
960  }
961  c->max_url_size = aligned(c->max_url_size + strlen(val));
962  rep->init_section->url = get_content_url(baseurl_nodes, 4,
963  c->max_url_size, rep->id,
964  rep_bandwidth_val, val);
965  xmlFree(val);
966  if (!rep->init_section->url)
967  goto enomem;
968  rep->init_section->size = -1;
969  }
970  val = get_val_from_nodes_tab(fragment_templates_tab, 4, "media");
971  if (val) {
972  c->max_url_size = aligned(c->max_url_size + strlen(val));
973  rep->url_template = get_content_url(baseurl_nodes, 4,
974  c->max_url_size, rep->id,
975  rep_bandwidth_val, val);
976  xmlFree(val);
977  }
978  val = get_val_from_nodes_tab(fragment_templates_tab, 4, "presentationTimeOffset");
979  if (val) {
980  int64_t presentation_timeoffset = (int64_t) strtoll(val, NULL, 10);
981  if (presentation_timeoffset < 0) {
982  av_log(s, AV_LOG_WARNING, "presentationTimeOffset invalid, autochanged to 0.\n");
983  presentation_timeoffset = 0;
984  }
985  rep->presentation_timeoffset = presentation_timeoffset;
986  av_log(s, AV_LOG_TRACE, "rep->presentation_timeoffset = [%"PRId64"]\n", rep->presentation_timeoffset);
987  xmlFree(val);
988  }
989 
990  SET_REPRESENTATION_SEQUENCE_BASE_INFO(fragment_templates_tab, 4);
991  if (adaptionset_supplementalproperty_node) {
992  if (!av_strcasecmp(xmlGetProp(adaptionset_supplementalproperty_node,"schemeIdUri"), "http://dashif.org/guidelines/last-segment-number")) {
993  val = xmlGetProp(adaptionset_supplementalproperty_node,"value");
994  if (!val) {
995  av_log(s, AV_LOG_ERROR, "Missing value attribute in adaptionset_supplementalproperty_node\n");
996  } else {
997  rep->last_seq_no =(int64_t) strtoll(val, NULL, 10) - 1;
998  xmlFree(val);
999  }
1000  }
1001  }
1002 
1003  fragment_timeline_node = find_child_node_by_name(representation_segmenttemplate_node, "SegmentTimeline");
1004 
1005  if (!fragment_timeline_node)
1006  fragment_timeline_node = find_child_node_by_name(fragment_template_node, "SegmentTimeline");
1007  if (!fragment_timeline_node)
1008  fragment_timeline_node = find_child_node_by_name(adaptionset_segmentlist_node, "SegmentTimeline");
1009  if (!fragment_timeline_node)
1010  fragment_timeline_node = find_child_node_by_name(period_segmentlist_node, "SegmentTimeline");
1011  if (fragment_timeline_node) {
1012  fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node);
1013  while (fragment_timeline_node) {
1014  ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node);
1015  if (ret < 0)
1016  goto free;
1017  fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node);
1018  }
1019  }
1020  } else if (representation_baseurl_node && !representation_segmentlist_node) {
1021  seg = av_mallocz(sizeof(struct fragment));
1022  if (!seg)
1023  goto enomem;
1024  ret = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg);
1025  if (ret < 0) {
1026  av_free(seg);
1027  goto free;
1028  }
1029  seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size,
1030  rep->id, rep_bandwidth_val, NULL);
1031  if (!seg->url)
1032  goto enomem;
1033  seg->size = -1;
1034  } else if (representation_segmentlist_node) {
1035  // TODO: https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html
1036  // http://www-itec.uni-klu.ac.at/dash/ddash/mpdGenerator.php?fragmentlength=15&type=full
1037  xmlNodePtr fragmenturl_node = NULL;
1038  segmentlists_tab[0] = representation_segmentlist_node;
1039  segmentlists_tab[1] = adaptionset_segmentlist_node;
1040  segmentlists_tab[2] = period_segmentlist_node;
1041 
1042  SET_REPRESENTATION_SEQUENCE_BASE_INFO(segmentlists_tab, 3)
1043  fragmenturl_node = xmlFirstElementChild(representation_segmentlist_node);
1044  while (fragmenturl_node) {
1045  ret = parse_manifest_segmenturlnode(s, rep, fragmenturl_node,
1046  baseurl_nodes, rep->id,
1047  rep_bandwidth_val);
1048  if (ret < 0)
1049  goto free;
1050  fragmenturl_node = xmlNextElementSibling(fragmenturl_node);
1051  }
1052 
1053  fragment_timeline_node = find_child_node_by_name(adaptionset_segmentlist_node, "SegmentTimeline");
1054  if (!fragment_timeline_node)
1055  fragment_timeline_node = find_child_node_by_name(period_segmentlist_node, "SegmentTimeline");
1056  if (fragment_timeline_node) {
1057  fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node);
1058  while (fragment_timeline_node) {
1059  ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node);
1060  if (ret < 0)
1061  goto free;
1062  fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node);
1063  }
1064  }
1065  } else {
1066  av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id '%s' \n",
1067  rep->id ? rep->id : "");
1068  goto free;
1069  }
1070 
1071  if (rep->fragment_duration > 0 && !rep->fragment_timescale)
1072  rep->fragment_timescale = 1;
1073  rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0;
1074  rep->framerate = av_make_q(0, 0);
1075  if (type == AVMEDIA_TYPE_VIDEO) {
1076  char *rep_framerate_val = xmlGetProp(representation_node, "frameRate");
1077  if (rep_framerate_val) {
1078  ret = av_parse_video_rate(&rep->framerate, rep_framerate_val);
1079  if (ret < 0)
1080  av_log(s, AV_LOG_VERBOSE, "Ignoring invalid frame rate '%s'\n", rep_framerate_val);
1081  xmlFree(rep_framerate_val);
1082  }
1083  }
1084 
1085  switch (type) {
1086  case AVMEDIA_TYPE_VIDEO:
1087  ret = av_dynarray_add_nofree(&c->videos, &c->n_videos, rep);
1088  break;
1089  case AVMEDIA_TYPE_AUDIO:
1090  ret = av_dynarray_add_nofree(&c->audios, &c->n_audios, rep);
1091  break;
1092  case AVMEDIA_TYPE_SUBTITLE:
1093  ret = av_dynarray_add_nofree(&c->subtitles, &c->n_subtitles, rep);
1094  break;
1095  }
1096  if (ret < 0)
1097  goto free;
1098 
1099 end:
1100  if (rep_bandwidth_val)
1101  xmlFree(rep_bandwidth_val);
1102 
1103  return ret;
1104 enomem:
1105  ret = AVERROR(ENOMEM);
1106 free:
1107  free_representation(rep);
1108  goto end;
1109 }
1110 
1111 static int parse_manifest_adaptationset_attr(AVFormatContext *s, xmlNodePtr adaptionset_node)
1112 {
1113  DASHContext *c = s->priv_data;
1114 
1115  if (!adaptionset_node) {
1116  av_log(s, AV_LOG_WARNING, "Cannot get AdaptionSet\n");
1117  return AVERROR(EINVAL);
1118  }
1119  c->adaptionset_lang = xmlGetProp(adaptionset_node, "lang");
1120 
1121  return 0;
1122 }
1123 
1125  xmlNodePtr adaptionset_node,
1126  xmlNodePtr mpd_baseurl_node,
1127  xmlNodePtr period_baseurl_node,
1128  xmlNodePtr period_segmenttemplate_node,
1129  xmlNodePtr period_segmentlist_node)
1130 {
1131  int ret = 0;
1132  DASHContext *c = s->priv_data;
1133  xmlNodePtr fragment_template_node = NULL;
1134  xmlNodePtr content_component_node = NULL;
1135  xmlNodePtr adaptionset_baseurl_node = NULL;
1136  xmlNodePtr adaptionset_segmentlist_node = NULL;
1137  xmlNodePtr adaptionset_supplementalproperty_node = NULL;
1138  xmlNodePtr node = NULL;
1139 
1140  ret = parse_manifest_adaptationset_attr(s, adaptionset_node);
1141  if (ret < 0)
1142  return ret;
1143 
1144  node = xmlFirstElementChild(adaptionset_node);
1145  while (node) {
1146  if (!av_strcasecmp(node->name, "SegmentTemplate")) {
1147  fragment_template_node = node;
1148  } else if (!av_strcasecmp(node->name, "ContentComponent")) {
1149  content_component_node = node;
1150  } else if (!av_strcasecmp(node->name, "BaseURL")) {
1151  adaptionset_baseurl_node = node;
1152  } else if (!av_strcasecmp(node->name, "SegmentList")) {
1153  adaptionset_segmentlist_node = node;
1154  } else if (!av_strcasecmp(node->name, "SupplementalProperty")) {
1155  adaptionset_supplementalproperty_node = node;
1156  } else if (!av_strcasecmp(node->name, "Representation")) {
1157  ret = parse_manifest_representation(s, url, node,
1158  adaptionset_node,
1159  mpd_baseurl_node,
1160  period_baseurl_node,
1161  period_segmenttemplate_node,
1162  period_segmentlist_node,
1163  fragment_template_node,
1164  content_component_node,
1165  adaptionset_baseurl_node,
1166  adaptionset_segmentlist_node,
1167  adaptionset_supplementalproperty_node);
1168  if (ret < 0)
1169  goto err;
1170  }
1171  node = xmlNextElementSibling(node);
1172  }
1173 
1174 err:
1175  xmlFree(c->adaptionset_lang);
1176  c->adaptionset_lang = NULL;
1177  return ret;
1178 }
1179 
1180 static int parse_programinformation(AVFormatContext *s, xmlNodePtr node)
1181 {
1182  xmlChar *val = NULL;
1183 
1184  node = xmlFirstElementChild(node);
1185  while (node) {
1186  if (!av_strcasecmp(node->name, "Title")) {
1187  val = xmlNodeGetContent(node);
1188  if (val) {
1189  av_dict_set(&s->metadata, "Title", val, 0);
1190  }
1191  } else if (!av_strcasecmp(node->name, "Source")) {
1192  val = xmlNodeGetContent(node);
1193  if (val) {
1194  av_dict_set(&s->metadata, "Source", val, 0);
1195  }
1196  } else if (!av_strcasecmp(node->name, "Copyright")) {
1197  val = xmlNodeGetContent(node);
1198  if (val) {
1199  av_dict_set(&s->metadata, "Copyright", val, 0);
1200  }
1201  }
1202  node = xmlNextElementSibling(node);
1203  xmlFree(val);
1204  val = NULL;
1205  }
1206  return 0;
1207 }
1208 
1209 static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
1210 {
1211  DASHContext *c = s->priv_data;
1212  int ret = 0;
1213  int close_in = 0;
1214  int64_t filesize = 0;
1215  AVBPrint buf;
1216  AVDictionary *opts = NULL;
1217  xmlDoc *doc = NULL;
1218  xmlNodePtr root_element = NULL;
1219  xmlNodePtr node = NULL;
1220  xmlNodePtr period_node = NULL;
1221  xmlNodePtr tmp_node = NULL;
1222  xmlNodePtr mpd_baseurl_node = NULL;
1223  xmlNodePtr period_baseurl_node = NULL;
1224  xmlNodePtr period_segmenttemplate_node = NULL;
1225  xmlNodePtr period_segmentlist_node = NULL;
1226  xmlNodePtr adaptionset_node = NULL;
1227  xmlAttrPtr attr = NULL;
1228  char *val = NULL;
1229  uint32_t period_duration_sec = 0;
1230  uint32_t period_start_sec = 0;
1231 
1232  if (!in) {
1233  close_in = 1;
1234 
1235  av_dict_copy(&opts, c->avio_opts, 0);
1236  ret = ffio_open_whitelist(&in, url, AVIO_FLAG_READ, c->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist);
1237  av_dict_free(&opts);
1238  if (ret < 0)
1239  return ret;
1240  }
1241 
1242  if (av_opt_get(in, "location", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&c->base_url) < 0)
1243  c->base_url = av_strdup(url);
1244 
1245  filesize = avio_size(in);
1246  filesize = filesize > 0 ? filesize : DEFAULT_MANIFEST_SIZE;
1247 
1248  if (filesize > MAX_BPRINT_READ_SIZE) {
1249  av_log(s, AV_LOG_ERROR, "Manifest too large: %"PRId64"\n", filesize);
1250  return AVERROR_INVALIDDATA;
1251  }
1252 
1253  av_bprint_init(&buf, filesize + 1, AV_BPRINT_SIZE_UNLIMITED);
1254 
1255  if ((ret = avio_read_to_bprint(in, &buf, MAX_BPRINT_READ_SIZE)) < 0 ||
1256  !avio_feof(in) ||
1257  (filesize = buf.len) == 0) {
1258  av_log(s, AV_LOG_ERROR, "Unable to read to manifest '%s'\n", url);
1259  if (ret == 0)
1260  ret = AVERROR_INVALIDDATA;
1261  } else {
1262  LIBXML_TEST_VERSION
1263 
1264  doc = xmlReadMemory(buf.str, filesize, c->base_url, NULL, 0);
1265  root_element = xmlDocGetRootElement(doc);
1266  node = root_element;
1267 
1268  if (!node) {
1269  ret = AVERROR_INVALIDDATA;
1270  av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - missing root node\n", url);
1271  goto cleanup;
1272  }
1273 
1274  if (node->type != XML_ELEMENT_NODE ||
1275  av_strcasecmp(node->name, "MPD")) {
1276  ret = AVERROR_INVALIDDATA;
1277  av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - wrong root node name[%s] type[%d]\n", url, node->name, (int)node->type);
1278  goto cleanup;
1279  }
1280 
1281  val = xmlGetProp(node, "type");
1282  if (!val) {
1283  av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - missing type attrib\n", url);
1284  ret = AVERROR_INVALIDDATA;
1285  goto cleanup;
1286  }
1287  if (!av_strcasecmp(val, "dynamic"))
1288  c->is_live = 1;
1289  xmlFree(val);
1290 
1291  attr = node->properties;
1292  while (attr) {
1293  val = xmlGetProp(node, attr->name);
1294 
1295  if (!av_strcasecmp(attr->name, "availabilityStartTime")) {
1296  c->availability_start_time = get_utc_date_time_insec(s, val);
1297  av_log(s, AV_LOG_TRACE, "c->availability_start_time = [%"PRId64"]\n", c->availability_start_time);
1298  } else if (!av_strcasecmp(attr->name, "availabilityEndTime")) {
1299  c->availability_end_time = get_utc_date_time_insec(s, val);
1300  av_log(s, AV_LOG_TRACE, "c->availability_end_time = [%"PRId64"]\n", c->availability_end_time);
1301  } else if (!av_strcasecmp(attr->name, "publishTime")) {
1302  c->publish_time = get_utc_date_time_insec(s, val);
1303  av_log(s, AV_LOG_TRACE, "c->publish_time = [%"PRId64"]\n", c->publish_time);
1304  } else if (!av_strcasecmp(attr->name, "minimumUpdatePeriod")) {
1305  c->minimum_update_period = get_duration_insec(s, val);
1306  av_log(s, AV_LOG_TRACE, "c->minimum_update_period = [%"PRId64"]\n", c->minimum_update_period);
1307  } else if (!av_strcasecmp(attr->name, "timeShiftBufferDepth")) {
1308  c->time_shift_buffer_depth = get_duration_insec(s, val);
1309  av_log(s, AV_LOG_TRACE, "c->time_shift_buffer_depth = [%"PRId64"]\n", c->time_shift_buffer_depth);
1310  } else if (!av_strcasecmp(attr->name, "minBufferTime")) {
1311  c->min_buffer_time = get_duration_insec(s, val);
1312  av_log(s, AV_LOG_TRACE, "c->min_buffer_time = [%"PRId64"]\n", c->min_buffer_time);
1313  } else if (!av_strcasecmp(attr->name, "suggestedPresentationDelay")) {
1314  c->suggested_presentation_delay = get_duration_insec(s, val);
1315  av_log(s, AV_LOG_TRACE, "c->suggested_presentation_delay = [%"PRId64"]\n", c->suggested_presentation_delay);
1316  } else if (!av_strcasecmp(attr->name, "mediaPresentationDuration")) {
1317  c->media_presentation_duration = get_duration_insec(s, val);
1318  av_log(s, AV_LOG_TRACE, "c->media_presentation_duration = [%"PRId64"]\n", c->media_presentation_duration);
1319  }
1320  attr = attr->next;
1321  xmlFree(val);
1322  }
1323 
1324  tmp_node = find_child_node_by_name(node, "BaseURL");
1325  if (tmp_node) {
1326  mpd_baseurl_node = xmlCopyNode(tmp_node,1);
1327  } else {
1328  mpd_baseurl_node = xmlNewNode(NULL, "BaseURL");
1329  }
1330 
1331  // at now we can handle only one period, with the longest duration
1332  node = xmlFirstElementChild(node);
1333  while (node) {
1334  if (!av_strcasecmp(node->name, "Period")) {
1335  period_duration_sec = 0;
1336  period_start_sec = 0;
1337  attr = node->properties;
1338  while (attr) {
1339  val = xmlGetProp(node, attr->name);
1340  if (!av_strcasecmp(attr->name, "duration")) {
1341  period_duration_sec = get_duration_insec(s, val);
1342  } else if (!av_strcasecmp(attr->name, "start")) {
1343  period_start_sec = get_duration_insec(s, val);
1344  }
1345  attr = attr->next;
1346  xmlFree(val);
1347  }
1348  if ((period_duration_sec) >= (c->period_duration)) {
1349  period_node = node;
1350  c->period_duration = period_duration_sec;
1351  c->period_start = period_start_sec;
1352  if (c->period_start > 0)
1353  c->media_presentation_duration = c->period_duration;
1354  }
1355  } else if (!av_strcasecmp(node->name, "ProgramInformation")) {
1356  parse_programinformation(s, node);
1357  }
1358  node = xmlNextElementSibling(node);
1359  }
1360  if (!period_node) {
1361  av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - missing Period node\n", url);
1362  ret = AVERROR_INVALIDDATA;
1363  goto cleanup;
1364  }
1365 
1366  adaptionset_node = xmlFirstElementChild(period_node);
1367  while (adaptionset_node) {
1368  if (!av_strcasecmp(adaptionset_node->name, "BaseURL")) {
1369  period_baseurl_node = adaptionset_node;
1370  } else if (!av_strcasecmp(adaptionset_node->name, "SegmentTemplate")) {
1371  period_segmenttemplate_node = adaptionset_node;
1372  } else if (!av_strcasecmp(adaptionset_node->name, "SegmentList")) {
1373  period_segmentlist_node = adaptionset_node;
1374  } else if (!av_strcasecmp(adaptionset_node->name, "AdaptationSet")) {
1375  parse_manifest_adaptationset(s, url, adaptionset_node, mpd_baseurl_node, period_baseurl_node, period_segmenttemplate_node, period_segmentlist_node);
1376  }
1377  adaptionset_node = xmlNextElementSibling(adaptionset_node);
1378  }
1379 cleanup:
1380  /*free the document */
1381  xmlFreeDoc(doc);
1382  xmlCleanupParser();
1383  xmlFreeNode(mpd_baseurl_node);
1384  }
1385 
1386  av_bprint_finalize(&buf, NULL);
1387  if (close_in) {
1388  avio_close(in);
1389  }
1390  return ret;
1391 }
1392 
1394 {
1395  DASHContext *c = s->priv_data;
1396  int64_t num = 0;
1397  int64_t start_time_offset = 0;
1398 
1399  if (c->is_live) {
1400  if (pls->n_fragments) {
1401  av_log(s, AV_LOG_TRACE, "in n_fragments mode\n");
1402  num = pls->first_seq_no;
1403  } else if (pls->n_timelines) {
1404  av_log(s, AV_LOG_TRACE, "in n_timelines mode\n");
1405  start_time_offset = get_segment_start_time_based_on_timeline(pls, 0xFFFFFFFF) - 60 * pls->fragment_timescale; // 60 seconds before end
1406  num = calc_next_seg_no_from_timelines(pls, start_time_offset);
1407  if (num == -1)
1408  num = pls->first_seq_no;
1409  else
1410  num += pls->first_seq_no;
1411  } else if (pls->fragment_duration){
1412  av_log(s, AV_LOG_TRACE, "in fragment_duration mode fragment_timescale = %"PRId64", presentation_timeoffset = %"PRId64"\n", pls->fragment_timescale, pls->presentation_timeoffset);
1413  if (pls->presentation_timeoffset) {
1414  num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time) * pls->fragment_timescale)-pls->presentation_timeoffset) / pls->fragment_duration - c->min_buffer_time;
1415  } else if (c->publish_time > 0 && !c->availability_start_time) {
1416  if (c->min_buffer_time) {
1417  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;
1418  } else {
1419  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;
1420  }
1421  } else {
1422  num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time) - c->suggested_presentation_delay) * pls->fragment_timescale) / pls->fragment_duration;
1423  }
1424  }
1425  } else {
1426  num = pls->first_seq_no;
1427  }
1428  return num;
1429 }
1430 
1432 {
1433  DASHContext *c = s->priv_data;
1434  int64_t num = 0;
1435 
1436  if (c->is_live && pls->fragment_duration) {
1437  av_log(s, AV_LOG_TRACE, "in live mode\n");
1438  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;
1439  } else {
1440  num = pls->first_seq_no;
1441  }
1442  return num;
1443 }
1444 
1446 {
1447  int64_t num = 0;
1448 
1449  if (pls->n_fragments) {
1450  num = pls->first_seq_no + pls->n_fragments - 1;
1451  } else if (pls->n_timelines) {
1452  int i = 0;
1453  num = pls->first_seq_no + pls->n_timelines - 1;
1454  for (i = 0; i < pls->n_timelines; i++) {
1455  if (pls->timelines[i]->repeat == -1) {
1456  int length_of_each_segment = pls->timelines[i]->duration / pls->fragment_timescale;
1457  num = c->period_duration / length_of_each_segment;
1458  } else {
1459  num += pls->timelines[i]->repeat;
1460  }
1461  }
1462  } else if (c->is_live && pls->fragment_duration) {
1463  num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time)) * pls->fragment_timescale) / pls->fragment_duration;
1464  } else if (pls->fragment_duration) {
1465  num = pls->first_seq_no + (c->media_presentation_duration * pls->fragment_timescale) / pls->fragment_duration;
1466  }
1467 
1468  return num;
1469 }
1470 
1471 static void move_timelines(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
1472 {
1473  if (rep_dest && rep_src ) {
1474  free_timelines_list(rep_dest);
1475  rep_dest->timelines = rep_src->timelines;
1476  rep_dest->n_timelines = rep_src->n_timelines;
1477  rep_dest->first_seq_no = rep_src->first_seq_no;
1478  rep_dest->last_seq_no = calc_max_seg_no(rep_dest, c);
1479  rep_src->timelines = NULL;
1480  rep_src->n_timelines = 0;
1481  rep_dest->cur_seq_no = rep_src->cur_seq_no;
1482  }
1483 }
1484 
1485 static void move_segments(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
1486 {
1487  if (rep_dest && rep_src ) {
1488  free_fragment_list(rep_dest);
1489  if (rep_src->start_number > (rep_dest->start_number + rep_dest->n_fragments))
1490  rep_dest->cur_seq_no = 0;
1491  else
1492  rep_dest->cur_seq_no += rep_src->start_number - rep_dest->start_number;
1493  rep_dest->fragments = rep_src->fragments;
1494  rep_dest->n_fragments = rep_src->n_fragments;
1495  rep_dest->parent = rep_src->parent;
1496  rep_dest->last_seq_no = calc_max_seg_no(rep_dest, c);
1497  rep_src->fragments = NULL;
1498  rep_src->n_fragments = 0;
1499  }
1500 }
1501 
1502 
1504 {
1505  int ret = 0, i;
1506  DASHContext *c = s->priv_data;
1507  // save current context
1508  int n_videos = c->n_videos;
1509  struct representation **videos = c->videos;
1510  int n_audios = c->n_audios;
1511  struct representation **audios = c->audios;
1512  int n_subtitles = c->n_subtitles;
1513  struct representation **subtitles = c->subtitles;
1514  char *base_url = c->base_url;
1515 
1516  c->base_url = NULL;
1517  c->n_videos = 0;
1518  c->videos = NULL;
1519  c->n_audios = 0;
1520  c->audios = NULL;
1521  c->n_subtitles = 0;
1522  c->subtitles = NULL;
1523  ret = parse_manifest(s, s->url, NULL);
1524  if (ret)
1525  goto finish;
1526 
1527  if (c->n_videos != n_videos) {
1529  "new manifest has mismatched no. of video representations, %d -> %d\n",
1530  n_videos, c->n_videos);
1531  return AVERROR_INVALIDDATA;
1532  }
1533  if (c->n_audios != n_audios) {
1535  "new manifest has mismatched no. of audio representations, %d -> %d\n",
1536  n_audios, c->n_audios);
1537  return AVERROR_INVALIDDATA;
1538  }
1539  if (c->n_subtitles != n_subtitles) {
1541  "new manifest has mismatched no. of subtitles representations, %d -> %d\n",
1542  n_subtitles, c->n_subtitles);
1543  return AVERROR_INVALIDDATA;
1544  }
1545 
1546  for (i = 0; i < n_videos; i++) {
1547  struct representation *cur_video = videos[i];
1548  struct representation *ccur_video = c->videos[i];
1549  if (cur_video->timelines) {
1550  // calc current time
1551  int64_t currentTime = get_segment_start_time_based_on_timeline(cur_video, cur_video->cur_seq_no) / cur_video->fragment_timescale;
1552  // update segments
1553  ccur_video->cur_seq_no = calc_next_seg_no_from_timelines(ccur_video, currentTime * cur_video->fragment_timescale - 1);
1554  if (ccur_video->cur_seq_no >= 0) {
1555  move_timelines(ccur_video, cur_video, c);
1556  }
1557  }
1558  if (cur_video->fragments) {
1559  move_segments(ccur_video, cur_video, c);
1560  }
1561  }
1562  for (i = 0; i < n_audios; i++) {
1563  struct representation *cur_audio = audios[i];
1564  struct representation *ccur_audio = c->audios[i];
1565  if (cur_audio->timelines) {
1566  // calc current time
1567  int64_t currentTime = get_segment_start_time_based_on_timeline(cur_audio, cur_audio->cur_seq_no) / cur_audio->fragment_timescale;
1568  // update segments
1569  ccur_audio->cur_seq_no = calc_next_seg_no_from_timelines(ccur_audio, currentTime * cur_audio->fragment_timescale - 1);
1570  if (ccur_audio->cur_seq_no >= 0) {
1571  move_timelines(ccur_audio, cur_audio, c);
1572  }
1573  }
1574  if (cur_audio->fragments) {
1575  move_segments(ccur_audio, cur_audio, c);
1576  }
1577  }
1578 
1579 finish:
1580  // restore context
1581  if (c->base_url)
1582  av_free(base_url);
1583  else
1584  c->base_url = base_url;
1585 
1586  if (c->subtitles)
1588  if (c->audios)
1589  free_audio_list(c);
1590  if (c->videos)
1591  free_video_list(c);
1592 
1593  c->n_subtitles = n_subtitles;
1594  c->subtitles = subtitles;
1595  c->n_audios = n_audios;
1596  c->audios = audios;
1597  c->n_videos = n_videos;
1598  c->videos = videos;
1599  return ret;
1600 }
1601 
1602 static struct fragment *get_current_fragment(struct representation *pls)
1603 {
1604  int64_t min_seq_no = 0;
1605  int64_t max_seq_no = 0;
1606  struct fragment *seg = NULL;
1607  struct fragment *seg_ptr = NULL;
1608  DASHContext *c = pls->parent->priv_data;
1609 
1610  while (( !ff_check_interrupt(c->interrupt_callback)&& pls->n_fragments > 0)) {
1611  if (pls->cur_seq_no < pls->n_fragments) {
1612  seg_ptr = pls->fragments[pls->cur_seq_no];
1613  seg = av_mallocz(sizeof(struct fragment));
1614  if (!seg) {
1615  return NULL;
1616  }
1617  seg->url = av_strdup(seg_ptr->url);
1618  if (!seg->url) {
1619  av_free(seg);
1620  return NULL;
1621  }
1622  seg->size = seg_ptr->size;
1623  seg->url_offset = seg_ptr->url_offset;
1624  return seg;
1625  } else if (c->is_live) {
1626  refresh_manifest(pls->parent);
1627  } else {
1628  break;
1629  }
1630  }
1631  if (c->is_live) {
1632  min_seq_no = calc_min_seg_no(pls->parent, pls);
1633  max_seq_no = calc_max_seg_no(pls, c);
1634 
1635  if (pls->timelines || pls->fragments) {
1636  refresh_manifest(pls->parent);
1637  }
1638  if (pls->cur_seq_no <= min_seq_no) {
1639  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);
1640  pls->cur_seq_no = calc_cur_seg_no(pls->parent, pls);
1641  } else if (pls->cur_seq_no > max_seq_no) {
1642  av_log(pls->parent, AV_LOG_VERBOSE, "new fragment: min[%"PRId64"] max[%"PRId64"]\n", min_seq_no, max_seq_no);
1643  }
1644  seg = av_mallocz(sizeof(struct fragment));
1645  if (!seg) {
1646  return NULL;
1647  }
1648  } else if (pls->cur_seq_no <= pls->last_seq_no) {
1649  seg = av_mallocz(sizeof(struct fragment));
1650  if (!seg) {
1651  return NULL;
1652  }
1653  }
1654  if (seg) {
1655  char *tmpfilename;
1656  if (!pls->url_template) {
1657  av_log(pls->parent, AV_LOG_ERROR, "Cannot get fragment, missing template URL\n");
1658  av_free(seg);
1659  return NULL;
1660  }
1661  tmpfilename = av_mallocz(c->max_url_size);
1662  if (!tmpfilename) {
1663  av_free(seg);
1664  return NULL;
1665  }
1666  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));
1667  seg->url = av_strireplace(pls->url_template, pls->url_template, tmpfilename);
1668  if (!seg->url) {
1669  av_log(pls->parent, AV_LOG_WARNING, "Unable to resolve template url '%s', try to use origin template\n", pls->url_template);
1670  seg->url = av_strdup(pls->url_template);
1671  if (!seg->url) {
1672  av_log(pls->parent, AV_LOG_ERROR, "Cannot resolve template url '%s'\n", pls->url_template);
1673  av_free(tmpfilename);
1674  av_free(seg);
1675  return NULL;
1676  }
1677  }
1678  av_free(tmpfilename);
1679  seg->size = -1;
1680  }
1681 
1682  return seg;
1683 }
1684 
1685 static int read_from_url(struct representation *pls, struct fragment *seg,
1686  uint8_t *buf, int buf_size)
1687 {
1688  int ret;
1689 
1690  /* limit read if the fragment was only a part of a file */
1691  if (seg->size >= 0)
1692  buf_size = FFMIN(buf_size, pls->cur_seg_size - pls->cur_seg_offset);
1693 
1694  ret = avio_read(pls->input, buf, buf_size);
1695  if (ret > 0)
1696  pls->cur_seg_offset += ret;
1697 
1698  return ret;
1699 }
1700 
1701 static int open_input(DASHContext *c, struct representation *pls, struct fragment *seg)
1702 {
1703  AVDictionary *opts = NULL;
1704  char *url = NULL;
1705  int ret = 0;
1706 
1707  url = av_mallocz(c->max_url_size);
1708  if (!url) {
1709  ret = AVERROR(ENOMEM);
1710  goto cleanup;
1711  }
1712 
1713  if (seg->size >= 0) {
1714  /* try to restrict the HTTP request to the part we want
1715  * (if this is in fact a HTTP request) */
1716  av_dict_set_int(&opts, "offset", seg->url_offset, 0);
1717  av_dict_set_int(&opts, "end_offset", seg->url_offset + seg->size, 0);
1718  }
1719 
1720  ff_make_absolute_url(url, c->max_url_size, c->base_url, seg->url);
1721  av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset %"PRId64"\n",
1722  url, seg->url_offset);
1723  ret = open_url(pls->parent, &pls->input, url, &c->avio_opts, opts, NULL);
1724 
1725 cleanup:
1726  av_free(url);
1727  av_dict_free(&opts);
1728  pls->cur_seg_offset = 0;
1729  pls->cur_seg_size = seg->size;
1730  return ret;
1731 }
1732 
1733 static int update_init_section(struct representation *pls)
1734 {
1735  static const int max_init_section_size = 1024 * 1024;
1736  DASHContext *c = pls->parent->priv_data;
1737  int64_t sec_size;
1738  int64_t urlsize;
1739  int ret;
1740 
1741  if (!pls->init_section || pls->init_sec_buf)
1742  return 0;
1743 
1744  ret = open_input(c, pls, pls->init_section);
1745  if (ret < 0) {
1747  "Failed to open an initialization section\n");
1748  return ret;
1749  }
1750 
1751  if (pls->init_section->size >= 0)
1752  sec_size = pls->init_section->size;
1753  else if ((urlsize = avio_size(pls->input)) >= 0)
1754  sec_size = urlsize;
1755  else
1756  sec_size = max_init_section_size;
1757 
1758  av_log(pls->parent, AV_LOG_DEBUG,
1759  "Downloading an initialization section of size %"PRId64"\n",
1760  sec_size);
1761 
1762  sec_size = FFMIN(sec_size, max_init_section_size);
1763 
1764  av_fast_malloc(&pls->init_sec_buf, &pls->init_sec_buf_size, sec_size);
1765 
1766  ret = read_from_url(pls, pls->init_section, pls->init_sec_buf,
1767  pls->init_sec_buf_size);
1768  ff_format_io_close(pls->parent, &pls->input);
1769 
1770  if (ret < 0)
1771  return ret;
1772 
1773  pls->init_sec_data_len = ret;
1774  pls->init_sec_buf_read_offset = 0;
1775 
1776  return 0;
1777 }
1778 
1779 static int64_t seek_data(void *opaque, int64_t offset, int whence)
1780 {
1781  struct representation *v = opaque;
1782  if (v->n_fragments && !v->init_sec_data_len) {
1783  return avio_seek(v->input, offset, whence);
1784  }
1785 
1786  return AVERROR(ENOSYS);
1787 }
1788 
1789 static int read_data(void *opaque, uint8_t *buf, int buf_size)
1790 {
1791  int ret = 0;
1792  struct representation *v = opaque;
1793  DASHContext *c = v->parent->priv_data;
1794 
1795 restart:
1796  if (!v->input) {
1797  free_fragment(&v->cur_seg);
1798  v->cur_seg = get_current_fragment(v);
1799  if (!v->cur_seg) {
1800  ret = AVERROR_EOF;
1801  goto end;
1802  }
1803 
1804  /* load/update Media Initialization Section, if any */
1805  ret = update_init_section(v);
1806  if (ret)
1807  goto end;
1808 
1809  ret = open_input(c, v, v->cur_seg);
1810  if (ret < 0) {
1811  if (ff_check_interrupt(c->interrupt_callback)) {
1812  ret = AVERROR_EXIT;
1813  goto end;
1814  }
1815  av_log(v->parent, AV_LOG_WARNING, "Failed to open fragment of playlist\n");
1816  v->cur_seq_no++;
1817  goto restart;
1818  }
1819  }
1820 
1822  /* Push init section out first before first actual fragment */
1823  int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size);
1824  memcpy(buf, v->init_sec_buf, copy_size);
1825  v->init_sec_buf_read_offset += copy_size;
1826  ret = copy_size;
1827  goto end;
1828  }
1829 
1830  /* check the v->cur_seg, if it is null, get current and double check if the new v->cur_seg*/
1831  if (!v->cur_seg) {
1832  v->cur_seg = get_current_fragment(v);
1833  }
1834  if (!v->cur_seg) {
1835  ret = AVERROR_EOF;
1836  goto end;
1837  }
1838  ret = read_from_url(v, v->cur_seg, buf, buf_size);
1839  if (ret > 0)
1840  goto end;
1841 
1842  if (c->is_live || v->cur_seq_no < v->last_seq_no) {
1843  if (!v->is_restart_needed)
1844  v->cur_seq_no++;
1845  v->is_restart_needed = 1;
1846  }
1847 
1848 end:
1849  return ret;
1850 }
1851 
1853 {
1854  DASHContext *c = s->priv_data;
1855  const char *opts[] = {
1856  "headers", "user_agent", "cookies", "http_proxy", "referer", "rw_timeout", "icy", NULL };
1857  const char **opt = opts;
1858  uint8_t *buf = NULL;
1859  int ret = 0;
1860 
1861  while (*opt) {
1862  if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
1863  if (buf[0] != '\0') {
1864  ret = av_dict_set(&c->avio_opts, *opt, buf, AV_DICT_DONT_STRDUP_VAL);
1865  if (ret < 0)
1866  return ret;
1867  } else {
1868  av_freep(&buf);
1869  }
1870  }
1871  opt++;
1872  }
1873 
1874  return ret;
1875 }
1876 
1877 static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url,
1878  int flags, AVDictionary **opts)
1879 {
1881  "A DASH playlist item '%s' referred to an external file '%s'. "
1882  "Opening this file was forbidden for security reasons\n",
1883  s->url, url);
1884  return AVERROR(EPERM);
1885 }
1886 
1888 {
1889  /* note: the internal buffer could have changed */
1890  av_freep(&pls->pb.buffer);
1891  memset(&pls->pb, 0x00, sizeof(AVIOContext));
1892  pls->ctx->pb = NULL;
1893  avformat_close_input(&pls->ctx);
1894 }
1895 
1897 {
1898  DASHContext *c = s->priv_data;
1899  ff_const59 AVInputFormat *in_fmt = NULL;
1900  AVDictionary *in_fmt_opts = NULL;
1901  uint8_t *avio_ctx_buffer = NULL;
1902  int ret = 0, i;
1903 
1904  if (pls->ctx) {
1906  }
1907 
1908  if (ff_check_interrupt(&s->interrupt_callback)) {
1909  ret = AVERROR_EXIT;
1910  goto fail;
1911  }
1912 
1913  if (!(pls->ctx = avformat_alloc_context())) {
1914  ret = AVERROR(ENOMEM);
1915  goto fail;
1916  }
1917 
1918  avio_ctx_buffer = av_malloc(INITIAL_BUFFER_SIZE);
1919  if (!avio_ctx_buffer ) {
1920  ret = AVERROR(ENOMEM);
1921  avformat_free_context(pls->ctx);
1922  pls->ctx = NULL;
1923  goto fail;
1924  }
1925  ffio_init_context(&pls->pb, avio_ctx_buffer, INITIAL_BUFFER_SIZE, 0,
1926  pls, read_data, NULL, c->is_live ? NULL : seek_data);
1927  pls->pb.seekable = 0;
1928 
1929  if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0)
1930  goto fail;
1931 
1932  pls->ctx->flags = AVFMT_FLAG_CUSTOM_IO;
1933  pls->ctx->probesize = s->probesize > 0 ? s->probesize : 1024 * 4;
1934  pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? s->max_analyze_duration : 4 * AV_TIME_BASE;
1935  pls->ctx->interrupt_callback = s->interrupt_callback;
1936  ret = av_probe_input_buffer(&pls->pb, &in_fmt, "", NULL, 0, 0);
1937  if (ret < 0) {
1938  av_log(s, AV_LOG_ERROR, "Error when loading first fragment of playlist\n");
1939  avformat_free_context(pls->ctx);
1940  pls->ctx = NULL;
1941  goto fail;
1942  }
1943 
1944  pls->ctx->pb = &pls->pb;
1945  pls->ctx->io_open = nested_io_open;
1946 
1947  // provide additional information from mpd if available
1948  ret = avformat_open_input(&pls->ctx, "", in_fmt, &in_fmt_opts); //pls->init_section->url
1949  av_dict_free(&in_fmt_opts);
1950  if (ret < 0)
1951  goto fail;
1952  if (pls->n_fragments) {
1953 #if FF_API_R_FRAME_RATE
1954  if (pls->framerate.den) {
1955  for (i = 0; i < pls->ctx->nb_streams; i++)
1956  pls->ctx->streams[i]->r_frame_rate = pls->framerate;
1957  }
1958 #endif
1959  ret = avformat_find_stream_info(pls->ctx, NULL);
1960  if (ret < 0)
1961  goto fail;
1962  }
1963 
1964 fail:
1965  return ret;
1966 }
1967 
1969 {
1970  int ret = 0;
1971  int i;
1972 
1973  pls->parent = s;
1974  pls->cur_seq_no = calc_cur_seg_no(s, pls);
1975 
1976  if (!pls->last_seq_no) {
1977  pls->last_seq_no = calc_max_seg_no(pls, s->priv_data);
1978  }
1979 
1980  ret = reopen_demux_for_component(s, pls);
1981  if (ret < 0) {
1982  goto fail;
1983  }
1984  for (i = 0; i < pls->ctx->nb_streams; i++) {
1986  AVStream *ist = pls->ctx->streams[i];
1987  if (!st) {
1988  ret = AVERROR(ENOMEM);
1989  goto fail;
1990  }
1991  st->id = i;
1994 
1995  // copy disposition
1996  st->disposition = ist->disposition;
1997 
1998  // copy side data
1999  for (int i = 0; i < ist->nb_side_data; i++) {
2000  const AVPacketSideData *sd_src = &ist->side_data[i];
2001  uint8_t *dst_data;
2002 
2003  dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size);
2004  if (!dst_data)
2005  return AVERROR(ENOMEM);
2006  memcpy(dst_data, sd_src->data, sd_src->size);
2007  }
2008  }
2009 
2010  return 0;
2011 fail:
2012  return ret;
2013 }
2014 
2015 static int is_common_init_section_exist(struct representation **pls, int n_pls)
2016 {
2017  struct fragment *first_init_section = pls[0]->init_section;
2018  char *url =NULL;
2019  int64_t url_offset = -1;
2020  int64_t size = -1;
2021  int i = 0;
2022 
2023  if (first_init_section == NULL || n_pls == 0)
2024  return 0;
2025 
2026  url = first_init_section->url;
2027  url_offset = first_init_section->url_offset;
2028  size = pls[0]->init_section->size;
2029  for (i=0;i<n_pls;i++) {
2030  if (!pls[i]->init_section)
2031  continue;
2032 
2033  if (av_strcasecmp(pls[i]->init_section->url, url) ||
2034  pls[i]->init_section->url_offset != url_offset ||
2035  pls[i]->init_section->size != size) {
2036  return 0;
2037  }
2038  }
2039  return 1;
2040 }
2041 
2042 static int copy_init_section(struct representation *rep_dest, struct representation *rep_src)
2043 {
2044  rep_dest->init_sec_buf = av_mallocz(rep_src->init_sec_buf_size);
2045  if (!rep_dest->init_sec_buf) {
2046  av_log(rep_dest->ctx, AV_LOG_WARNING, "Cannot alloc memory for init_sec_buf\n");
2047  return AVERROR(ENOMEM);
2048  }
2049  memcpy(rep_dest->init_sec_buf, rep_src->init_sec_buf, rep_src->init_sec_data_len);
2050  rep_dest->init_sec_buf_size = rep_src->init_sec_buf_size;
2051  rep_dest->init_sec_data_len = rep_src->init_sec_data_len;
2052  rep_dest->cur_timestamp = rep_src->cur_timestamp;
2053 
2054  return 0;
2055 }
2056 
2057 static int dash_close(AVFormatContext *s);
2058 
2059 static void move_metadata(AVStream *st, const char *key, char **value)
2060 {
2061  if (*value) {
2063  *value = NULL;
2064  }
2065 }
2066 
2068 {
2069  DASHContext *c = s->priv_data;
2070  struct representation *rep;
2071  AVProgram *program;
2072  int ret = 0;
2073  int stream_index = 0;
2074  int i;
2075 
2076  c->interrupt_callback = &s->interrupt_callback;
2077 
2078  if ((ret = save_avio_options(s)) < 0)
2079  goto fail;
2080 
2081  if ((ret = parse_manifest(s, s->url, s->pb)) < 0)
2082  goto fail;
2083 
2084  /* If this isn't a live stream, fill the total duration of the
2085  * stream. */
2086  if (!c->is_live) {
2087  s->duration = (int64_t) c->media_presentation_duration * AV_TIME_BASE;
2088  } else {
2089  av_dict_set(&c->avio_opts, "seekable", "0", 0);
2090  }
2091 
2092  if(c->n_videos)
2093  c->is_init_section_common_video = is_common_init_section_exist(c->videos, c->n_videos);
2094 
2095  /* Open the demuxer for video and audio components if available */
2096  for (i = 0; i < c->n_videos; i++) {
2097  rep = c->videos[i];
2098  if (i > 0 && c->is_init_section_common_video) {
2099  ret = copy_init_section(rep, c->videos[0]);
2100  if (ret < 0)
2101  goto fail;
2102  }
2103  ret = open_demux_for_component(s, rep);
2104 
2105  if (ret)
2106  goto fail;
2107  rep->stream_index = stream_index;
2108  ++stream_index;
2109  }
2110 
2111  if(c->n_audios)
2112  c->is_init_section_common_audio = is_common_init_section_exist(c->audios, c->n_audios);
2113 
2114  for (i = 0; i < c->n_audios; i++) {
2115  rep = c->audios[i];
2116  if (i > 0 && c->is_init_section_common_audio) {
2117  ret = copy_init_section(rep, c->audios[0]);
2118  if (ret < 0)
2119  goto fail;
2120  }
2121  ret = open_demux_for_component(s, rep);
2122 
2123  if (ret)
2124  goto fail;
2125  rep->stream_index = stream_index;
2126  ++stream_index;
2127  }
2128 
2129  if (c->n_subtitles)
2130  c->is_init_section_common_subtitle = is_common_init_section_exist(c->subtitles, c->n_subtitles);
2131 
2132  for (i = 0; i < c->n_subtitles; i++) {
2133  rep = c->subtitles[i];
2134  if (i > 0 && c->is_init_section_common_subtitle) {
2135  ret = copy_init_section(rep, c->subtitles[0]);
2136  if (ret < 0)
2137  goto fail;
2138  }
2139  ret = open_demux_for_component(s, rep);
2140 
2141  if (ret)
2142  goto fail;
2143  rep->stream_index = stream_index;
2144  ++stream_index;
2145  }
2146 
2147  if (!stream_index) {
2148  ret = AVERROR_INVALIDDATA;
2149  goto fail;
2150  }
2151 
2152  /* Create a program */
2153  program = av_new_program(s, 0);
2154  if (!program) {
2155  ret = AVERROR(ENOMEM);
2156  goto fail;
2157  }
2158 
2159  for (i = 0; i < c->n_videos; i++) {
2160  rep = c->videos[i];
2162  rep->assoc_stream = s->streams[rep->stream_index];
2163  if (rep->bandwidth > 0)
2164  av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0);
2165  move_metadata(rep->assoc_stream, "id", &rep->id);
2166  }
2167  for (i = 0; i < c->n_audios; i++) {
2168  rep = c->audios[i];
2170  rep->assoc_stream = s->streams[rep->stream_index];
2171  if (rep->bandwidth > 0)
2172  av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0);
2173  move_metadata(rep->assoc_stream, "id", &rep->id);
2174  move_metadata(rep->assoc_stream, "language", &rep->lang);
2175  }
2176  for (i = 0; i < c->n_subtitles; i++) {
2177  rep = c->subtitles[i];
2179  rep->assoc_stream = s->streams[rep->stream_index];
2180  move_metadata(rep->assoc_stream, "id", &rep->id);
2181  move_metadata(rep->assoc_stream, "language", &rep->lang);
2182  }
2183 
2184  return 0;
2185 fail:
2186  dash_close(s);
2187  return ret;
2188 }
2189 
2190 static void recheck_discard_flags(AVFormatContext *s, struct representation **p, int n)
2191 {
2192  int i, j;
2193 
2194  for (i = 0; i < n; i++) {
2195  struct representation *pls = p[i];
2196  int needed = !pls->assoc_stream || pls->assoc_stream->discard < AVDISCARD_ALL;
2197 
2198  if (needed && !pls->ctx) {
2199  pls->cur_seg_offset = 0;
2200  pls->init_sec_buf_read_offset = 0;
2201  /* Catch up */
2202  for (j = 0; j < n; j++) {
2203  pls->cur_seq_no = FFMAX(pls->cur_seq_no, p[j]->cur_seq_no);
2204  }
2206  av_log(s, AV_LOG_INFO, "Now receiving stream_index %d\n", pls->stream_index);
2207  } else if (!needed && pls->ctx) {
2209  ff_format_io_close(pls->parent, &pls->input);
2210  av_log(s, AV_LOG_INFO, "No longer receiving stream_index %d\n", pls->stream_index);
2211  }
2212  }
2213 }
2214 
2216 {
2217  DASHContext *c = s->priv_data;
2218  int ret = 0, i;
2219  int64_t mints = 0;
2220  struct representation *cur = NULL;
2221  struct representation *rep = NULL;
2222 
2223  recheck_discard_flags(s, c->videos, c->n_videos);
2224  recheck_discard_flags(s, c->audios, c->n_audios);
2225  recheck_discard_flags(s, c->subtitles, c->n_subtitles);
2226 
2227  for (i = 0; i < c->n_videos; i++) {
2228  rep = c->videos[i];
2229  if (!rep->ctx)
2230  continue;
2231  if (!cur || rep->cur_timestamp < mints) {
2232  cur = rep;
2233  mints = rep->cur_timestamp;
2234  }
2235  }
2236  for (i = 0; i < c->n_audios; i++) {
2237  rep = c->audios[i];
2238  if (!rep->ctx)
2239  continue;
2240  if (!cur || rep->cur_timestamp < mints) {
2241  cur = rep;
2242  mints = rep->cur_timestamp;
2243  }
2244  }
2245 
2246  for (i = 0; i < c->n_subtitles; i++) {
2247  rep = c->subtitles[i];
2248  if (!rep->ctx)
2249  continue;
2250  if (!cur || rep->cur_timestamp < mints) {
2251  cur = rep;
2252  mints = rep->cur_timestamp;
2253  }
2254  }
2255 
2256  if (!cur) {
2257  return AVERROR_INVALIDDATA;
2258  }
2259  while (!ff_check_interrupt(c->interrupt_callback) && !ret) {
2260  ret = av_read_frame(cur->ctx, pkt);
2261  if (ret >= 0) {
2262  /* If we got a packet, return it */
2263  cur->cur_timestamp = av_rescale(pkt->pts, (int64_t)cur->ctx->streams[0]->time_base.num * 90000, cur->ctx->streams[0]->time_base.den);
2264  pkt->stream_index = cur->stream_index;
2265  return 0;
2266  }
2267  if (cur->is_restart_needed) {
2268  cur->cur_seg_offset = 0;
2269  cur->init_sec_buf_read_offset = 0;
2270  ff_format_io_close(cur->parent, &cur->input);
2271  ret = reopen_demux_for_component(s, cur);
2272  cur->is_restart_needed = 0;
2273  }
2274  }
2275  return AVERROR_EOF;
2276 }
2277 
2279 {
2280  DASHContext *c = s->priv_data;
2281  free_audio_list(c);
2282  free_video_list(c);
2284  av_dict_free(&c->avio_opts);
2285  av_freep(&c->base_url);
2286  return 0;
2287 }
2288 
2289 static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t seek_pos_msec, int flags, int dry_run)
2290 {
2291  int ret = 0;
2292  int i = 0;
2293  int j = 0;
2294  int64_t duration = 0;
2295 
2296  av_log(pls->parent, AV_LOG_VERBOSE, "DASH seek pos[%"PRId64"ms] %s\n",
2297  seek_pos_msec, dry_run ? " (dry)" : "");
2298 
2299  // single fragment mode
2300  if (pls->n_fragments == 1) {
2301  pls->cur_timestamp = 0;
2302  pls->cur_seg_offset = 0;
2303  if (dry_run)
2304  return 0;
2305  ff_read_frame_flush(pls->ctx);
2306  return av_seek_frame(pls->ctx, -1, seek_pos_msec * 1000, flags);
2307  }
2308 
2309  ff_format_io_close(pls->parent, &pls->input);
2310 
2311  // find the nearest fragment
2312  if (pls->n_timelines > 0 && pls->fragment_timescale > 0) {
2313  int64_t num = pls->first_seq_no;
2314  av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline start n_timelines[%d] "
2315  "last_seq_no[%"PRId64"].\n",
2316  (int)pls->n_timelines, (int64_t)pls->last_seq_no);
2317  for (i = 0; i < pls->n_timelines; i++) {
2318  if (pls->timelines[i]->starttime > 0) {
2319  duration = pls->timelines[i]->starttime;
2320  }
2321  duration += pls->timelines[i]->duration;
2322  if (seek_pos_msec < ((duration * 1000) / pls->fragment_timescale)) {
2323  goto set_seq_num;
2324  }
2325  for (j = 0; j < pls->timelines[i]->repeat; j++) {
2326  duration += pls->timelines[i]->duration;
2327  num++;
2328  if (seek_pos_msec < ((duration * 1000) / pls->fragment_timescale)) {
2329  goto set_seq_num;
2330  }
2331  }
2332  num++;
2333  }
2334 
2335 set_seq_num:
2336  pls->cur_seq_no = num > pls->last_seq_no ? pls->last_seq_no : num;
2337  av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline end cur_seq_no[%"PRId64"].\n",
2338  (int64_t)pls->cur_seq_no);
2339  } else if (pls->fragment_duration > 0) {
2340  pls->cur_seq_no = pls->first_seq_no + ((seek_pos_msec * pls->fragment_timescale) / pls->fragment_duration) / 1000;
2341  } else {
2342  av_log(pls->parent, AV_LOG_ERROR, "dash_seek missing timeline or fragment_duration\n");
2343  pls->cur_seq_no = pls->first_seq_no;
2344  }
2345  pls->cur_timestamp = 0;
2346  pls->cur_seg_offset = 0;
2347  pls->init_sec_buf_read_offset = 0;
2348  ret = dry_run ? 0 : reopen_demux_for_component(s, pls);
2349 
2350  return ret;
2351 }
2352 
2353 static int dash_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
2354 {
2355  int ret = 0, i;
2356  DASHContext *c = s->priv_data;
2357  int64_t seek_pos_msec = av_rescale_rnd(timestamp, 1000,
2358  s->streams[stream_index]->time_base.den,
2361  if ((flags & AVSEEK_FLAG_BYTE) || c->is_live)
2362  return AVERROR(ENOSYS);
2363 
2364  /* Seek in discarded streams with dry_run=1 to avoid reopening them */
2365  for (i = 0; i < c->n_videos; i++) {
2366  if (!ret)
2367  ret = dash_seek(s, c->videos[i], seek_pos_msec, flags, !c->videos[i]->ctx);
2368  }
2369  for (i = 0; i < c->n_audios; i++) {
2370  if (!ret)
2371  ret = dash_seek(s, c->audios[i], seek_pos_msec, flags, !c->audios[i]->ctx);
2372  }
2373  for (i = 0; i < c->n_subtitles; i++) {
2374  if (!ret)
2375  ret = dash_seek(s, c->subtitles[i], seek_pos_msec, flags, !c->subtitles[i]->ctx);
2376  }
2377 
2378  return ret;
2379 }
2380 
2381 static int dash_probe(const AVProbeData *p)
2382 {
2383  if (!av_stristr(p->buf, "<MPD"))
2384  return 0;
2385 
2386  if (av_stristr(p->buf, "dash:profile:isoff-on-demand:2011") ||
2387  av_stristr(p->buf, "dash:profile:isoff-live:2011") ||
2388  av_stristr(p->buf, "dash:profile:isoff-live:2012") ||
2389  av_stristr(p->buf, "dash:profile:isoff-main:2011") ||
2390  av_stristr(p->buf, "3GPP:PSS:profile:DASH1")) {
2391  return AVPROBE_SCORE_MAX;
2392  }
2393  if (av_stristr(p->buf, "dash:profile")) {
2394  return AVPROBE_SCORE_MAX;
2395  }
2396 
2397  return 0;
2398 }
2399 
2400 #define OFFSET(x) offsetof(DASHContext, x)
2401 #define FLAGS AV_OPT_FLAG_DECODING_PARAM
2402 static const AVOption dash_options[] = {
2403  {"allowed_extensions", "List of file extensions that dash is allowed to access",
2404  OFFSET(allowed_extensions), AV_OPT_TYPE_STRING,
2405  {.str = "aac,m4a,m4s,m4v,mov,mp4,webm,ts"},
2406  INT_MIN, INT_MAX, FLAGS},
2407  {NULL}
2408 };
2409 
2410 static const AVClass dash_class = {
2411  .class_name = "dash",
2412  .item_name = av_default_item_name,
2413  .option = dash_options,
2414  .version = LIBAVUTIL_VERSION_INT,
2415 };
2416 
2418  .name = "dash",
2419  .long_name = NULL_IF_CONFIG_SMALL("Dynamic Adaptive Streaming over HTTP"),
2420  .priv_class = &dash_class,
2421  .priv_data_size = sizeof(DASHContext),
2428 };
static double val(void *priv, double ch)
Definition: aeval.c:76
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
uint8_t
int32_t
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:453
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition: avformat.h:470
#define AVSEEK_FLAG_BYTE
seeking based on position in bytes
Definition: avformat.h:2416
#define ff_const59
The ff_const59 define is not part of the public API and will be removed without further warning.
Definition: avformat.h:533
#define AVFMT_FLAG_CUSTOM_IO
The caller has supplied a custom AVIOContext, don't avio_close() it.
Definition: avformat.h:1371
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2415
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition: avio.c:661
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
Definition: avio.c:470
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:253
#define AVIO_FLAG_READ
read-only
Definition: avio.h:674
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:342
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:364
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:633
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1172
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:1253
int ffio_open_whitelist(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist)
Definition: aviobuf.c:1145
int ffio_init_context(AVIOContext *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, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:88
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
#define AV_BPRINT_SIZE_UNLIMITED
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
#define fail()
Definition: checkasm.h:133
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:72
#define FFMIN(a, b)
Definition: common.h:105
#define FFMAX(a, b)
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:96
static int dash_read_header(AVFormatContext *s)
Definition: dashdec.c:2067
#define SET_REPRESENTATION_SEQUENCE_BASE_INFO(arg, cnt)
Definition: dashdec.c:829
static enum AVMediaType get_content_type(xmlNodePtr node)
Definition: dashdec.c:550
static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, AVDictionary **opts, AVDictionary *opts2, int *is_http)
Definition: dashdec.c:401
#define MAX_BPRINT_READ_SIZE
Definition: dashdec.c:32
#define INITIAL_BUFFER_SIZE
Definition: dashdec.c:31
static int is_common_init_section_exist(struct representation **pls, int n_pls)
Definition: dashdec.c:2015
static const AVOption dash_options[]
Definition: dashdec.c:2402
static int ishttp(char *url)
Definition: dashdec.c:162
static int update_init_section(struct representation *pls)
Definition: dashdec.c:1733
static struct fragment * get_current_fragment(struct representation *pls)
Definition: dashdec.c:1602
AVInputFormat ff_dash_demuxer
Definition: dashdec.c:2417
static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t seek_pos_msec, int flags, int dry_run)
Definition: dashdec.c:2289
static int read_data(void *opaque, uint8_t *buf, int buf_size)
Definition: dashdec.c:1789
static int open_demux_for_component(AVFormatContext *s, struct representation *pls)
Definition: dashdec.c:1968
static int parse_manifest_adaptationset_attr(AVFormatContext *s, xmlNodePtr adaptionset_node)
Definition: dashdec.c:1111
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:594
static void recheck_discard_flags(AVFormatContext *s, struct representation **p, int n)
Definition: dashdec.c:2190
static void move_metadata(AVStream *st, const char *key, char **value)
Definition: dashdec.c:2059
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:866
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:466
static int copy_init_section(struct representation *rep_dest, struct representation *rep_src)
Definition: dashdec.c:2042
static const AVClass dash_class
Definition: dashdec.c:2410
static int64_t get_segment_start_time_based_on_timeline(struct representation *pls, int64_t cur_seq_no)
Definition: dashdec.c:252
static int aligned(int val)
Definition: dashdec.c:168
static uint64_t get_current_time_in_sec(void)
Definition: dashdec.c:173
static struct fragment * get_Fragment(char *range)
Definition: dashdec.c:576
static int reopen_demux_for_component(AVFormatContext *s, struct representation *pls)
Definition: dashdec.c:1896
#define FLAGS
Definition: dashdec.c:2401
static int dash_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: dashdec.c:2215
static int64_t calc_min_seg_no(AVFormatContext *s, struct representation *pls)
Definition: dashdec.c:1431
static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **opts)
Definition: dashdec.c:1877
static void free_representation(struct representation *pls)
Definition: dashdec.c:348
static void free_audio_list(DASHContext *c)
Definition: dashdec.c:379
static uint32_t get_duration_insec(AVFormatContext *s, const char *duration)
Definition: dashdec.c:208
static void move_timelines(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
Definition: dashdec.c:1471
static int64_t calc_cur_seg_no(AVFormatContext *s, struct representation *pls)
Definition: dashdec.c:1393
static void free_subtitle_list(DASHContext *c)
Definition: dashdec.c:390
static int dash_close(AVFormatContext *s)
Definition: dashdec.c:2278
static void close_demux_for_component(struct representation *pls)
Definition: dashdec.c:1887
static int64_t seek_data(void *opaque, int64_t offset, int whence)
Definition: dashdec.c:1779
static int dash_probe(const AVProbeData *p)
Definition: dashdec.c:2381
static char * get_val_from_nodes_tab(xmlNodePtr *nodes, const int n_nodes, const char *attrname)
Definition: dashdec.c:517
static int open_input(DASHContext *c, struct representation *pls, struct fragment *seg)
Definition: dashdec.c:1701
static xmlNodePtr find_child_node_by_name(xmlNodePtr rootnode, const char *nodename)
Definition: dashdec.c:533
static int refresh_manifest(AVFormatContext *s)
Definition: dashdec.c:1503
static int save_avio_options(AVFormatContext *s)
Definition: dashdec.c:1852
static int64_t calc_next_seg_no_from_timelines(struct representation *pls, int64_t cur_time)
Definition: dashdec.c:287
static void free_fragment(struct fragment **seg)
Definition: dashdec.c:317
static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
Definition: dashdec.c:1209
static void move_segments(struct representation *rep_src, struct representation *rep_dest, DASHContext *c)
Definition: dashdec.c:1485
static uint64_t get_utc_date_time_insec(AVFormatContext *s, const char *datetime)
Definition: dashdec.c:178
#define OFFSET(x)
Definition: dashdec.c:2400
static int64_t calc_max_seg_no(struct representation *pls, DASHContext *c)
Definition: dashdec.c:1445
static int read_from_url(struct representation *pls, struct fragment *seg, uint8_t *buf, int buf_size)
Definition: dashdec.c:1685
#define DEFAULT_MANIFEST_SIZE
Definition: dashdec.c:33
static int parse_programinformation(AVFormatContext *s, xmlNodePtr node)
Definition: dashdec.c:1180
static int dash_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: dashdec.c:2353
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:1124
static void free_fragment_list(struct representation *pls)
Definition: dashdec.c:326
static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representation *rep, xmlNodePtr fragment_timeline_node)
Definition: dashdec.c:660
static void free_timelines_list(struct representation *pls)
Definition: dashdec.c:337
static void free_video_list(DASHContext *c)
Definition: dashdec.c:368
static int resolve_content_path(AVFormatContext *s, const char *url, int *max_url_size, xmlNodePtr *baseurl_nodes, int n_baseurl_nodes)
Definition: dashdec.c:701
double value
Definition: eval.c:100
int
static int64_t start_time
Definition: ffplay.c:332
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:550
static av_cold void cleanup(FlashSV2Context *s)
Definition: flashsv2enc.c:127
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:560
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
@ AVDISCARD_ALL
discard all
Definition: avcodec.h:236
uint8_t * av_stream_new_side_data(AVStream *stream, enum AVPacketSideDataType type, size_t size)
Allocate new information from stream.
AVProgram * av_new_program(AVFormatContext *s, int id)
Definition: utils.c:4607
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:4436
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:211
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4509
int av_probe_input_buffer(AVIOContext *pb, ff_const59 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:339
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: utils.c:1741
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
Definition: utils.c:2489
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx)
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: utils.c:3602
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: utils.c:4481
int avformat_open_input(AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: utils.c:512
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:38
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:203
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
#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:74
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:70
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:147
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:56
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:220
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
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.
Definition: mathematics.c:129
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.
Definition: mathematics.h:82
@ AV_ROUND_UP
Round toward +infinity.
Definition: mathematics.h:83
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:296
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:502
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
AVMediaType
Definition: avutil.h:199
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
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:93
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:186
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:56
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:215
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:34
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:83
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
Definition: avstring.c:225
char * av_strireplace(const char *str, const char *from, const char *to)
Locale-independent strings replace.
Definition: avstring.c:237
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
#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:779
cl_device_type type
const char * key
int i
Definition: input.c:407
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition: utils.c:160
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4945
#define MAX_URL_SIZE
Definition: internal.h:30
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
Definition: utils.c:1892
void ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: utils.c:5692
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
AVOptions.
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:179
time_t av_timegm(struct tm *tm)
Convert the decomposed UTC time in tm to a time_t value.
Definition: parseutils.c:568
misc parsing utilities
Describe the class of an AVClass context structure.
Definition: log.h:67
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
Format I/O context.
Definition: avformat.h:1232
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1288
AVIOContext * pb
I/O context.
Definition: avformat.h:1274
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1363
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:1408
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1512
void * priv_data
Format private data.
Definition: avformat.h:1260
int64_t probesize
Maximum size of the data read from input for determining the input container format.
Definition: avformat.h:1400
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1300
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:1828
Bytestream IO Context.
Definition: avio.h:161
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
unsigned char * buffer
Start of the buffer.
Definition: avio.h:226
Callback for checking whether to abort blocking functions.
Definition: avio.h:58
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:645
AVOption.
Definition: opt.h:248
uint8_t * data
Definition: packet.h:307
enum AVPacketSideDataType type
Definition: packet.h:313
size_t size
Definition: packet.h:311
This structure stores compressed data.
Definition: packet.h:346
int stream_index
Definition: packet.h:371
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
This structure contains the data a format has to probe a file.
Definition: avformat.h:441
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:443
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1150
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
Stream structure.
Definition: avformat.h:873
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
Definition: avformat.h:975
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1038
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:928
AVDictionary * metadata
Definition: avformat.h:937
int id
Format-specific stream ID.
Definition: avformat.h:880
int pts_wrap_bits
number of bits in pts (used for wrapping control)
Definition: avformat.h:1055
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:902
int nb_side_data
The number of elements in the AVStream.side_data array.
Definition: avformat.h:979
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1015
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:926
int is_init_section_common_video
Definition: dashdec.c:156
int max_url_size
Definition: dashdec.c:153
char * adaptionset_lang
Definition: dashdec.c:147
int is_init_section_common_audio
Definition: dashdec.c:157
uint64_t availability_end_time
Definition: dashdec.c:136
AVDictionary * avio_opts
Definition: dashdec.c:152
int n_subtitles
Definition: dashdec.c:129
uint64_t period_start
Definition: dashdec.c:144
struct representation ** videos
Definition: dashdec.c:126
struct representation ** subtitles
Definition: dashdec.c:130
uint64_t time_shift_buffer_depth
Definition: dashdec.c:139
char * base_url
Definition: dashdec.c:123
int n_audios
Definition: dashdec.c:127
uint64_t media_presentation_duration
Definition: dashdec.c:133
uint64_t min_buffer_time
Definition: dashdec.c:140
int is_init_section_common_subtitle
Definition: dashdec.c:158
uint64_t suggested_presentation_delay
Definition: dashdec.c:134
uint64_t minimum_update_period
Definition: dashdec.c:138
char * allowed_extensions
Definition: dashdec.c:151
int is_live
Definition: dashdec.c:149
uint64_t publish_time
Definition: dashdec.c:137
int n_videos
Definition: dashdec.c:125
AVIOInterruptCB * interrupt_callback
Definition: dashdec.c:150
uint64_t availability_start_time
Definition: dashdec.c:135
uint64_t period_duration
Definition: dashdec.c:143
struct representation ** audios
Definition: dashdec.c:128
char * url
Definition: dashdec.c:38
int64_t url_offset
Definition: dashdec.c:36
int64_t size
Definition: dashdec.c:37
char * url_template
Definition: dashdec.c:78
char * lang
Definition: dashdec.c:86
AVStream * assoc_stream
Definition: dashdec.c:89
int64_t last_seq_no
Definition: dashdec.c:98
AVIOContext pb
Definition: dashdec.c:79
AVRational framerate
Definition: dashdec.c:88
uint32_t init_sec_data_len
Definition: dashdec.c:115
int64_t cur_seg_offset
Definition: dashdec.c:107
AVIOContext * input
Definition: dashdec.c:80
struct timeline ** timelines
Definition: dashdec.c:95
int bandwidth
Definition: dashdec.c:87
struct fragment * cur_seg
Definition: dashdec.c:109
int64_t first_seq_no
Definition: dashdec.c:97
char * id
Definition: dashdec.c:85
uint32_t init_sec_buf_size
Definition: dashdec.c:114
int64_t cur_timestamp
Definition: dashdec.c:117
uint32_t init_sec_buf_read_offset
Definition: dashdec.c:116
int64_t presentation_timeoffset
Definition: dashdec.c:104
int n_fragments
Definition: dashdec.c:91
int64_t cur_seg_size
Definition: dashdec.c:108
struct fragment ** fragments
Definition: dashdec.c:92
int64_t fragment_timescale
Definition: dashdec.c:102
struct fragment * init_section
Definition: dashdec.c:112
int stream_index
Definition: dashdec.c:83
uint8_t * init_sec_buf
Definition: dashdec.c:113
int n_timelines
Definition: dashdec.c:94
int64_t start_number
Definition: dashdec.c:99
AVFormatContext * ctx
Definition: dashdec.c:82
int is_restart_needed
Definition: dashdec.c:118
AVFormatContext * parent
Definition: dashdec.c:81
int64_t fragment_duration
Definition: dashdec.c:101
int64_t cur_seq_no
Definition: dashdec.c:106
int64_t repeat
Definition: dashdec.c:65
int64_t starttime
Definition: dashdec.c:59
int64_t duration
Definition: dashdec.c:69
#define av_free(p)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
static uint8_t tmp[11]
Definition: aes_ctr.c:27
int64_t duration
Definition: movenc.c:64
AVPacket * pkt
Definition: movenc.c:59
static void finish(void)
Definition: movenc.c:342
AVDictionary * opts
Definition: movenc.c:50
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
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:319
static const uint8_t offset[127][2]
Definition: vf_spp.c:107
int len
static double c[64]