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