| 796 | } |
| 797 | |
| 798 | static int parse_adaptation_sets(AVFormatContext *s) |
| 799 | { |
| 800 | DASHContext *c = s->priv_data; |
| 801 | const char *p = c->adaptation_sets; |
| 802 | enum { new_set, parse_default, parsing_streams, parse_seg_duration, parse_frag_duration } state; |
| 803 | AdaptationSet *as; |
| 804 | int i, n, ret; |
| 805 | |
| 806 | // default: one AdaptationSet for each stream |
| 807 | if (!p) { |
| 808 | for (i = 0; i < s->nb_streams; i++) { |
| 809 | if ((ret = add_adaptation_set(s, &as, s->streams[i]->codecpar->codec_type)) < 0) |
| 810 | return ret; |
| 811 | as->id = i; |
| 812 | |
| 813 | c->streams[i].as_idx = c->nb_as; |
| 814 | ++as->nb_streams; |
| 815 | } |
| 816 | goto end; |
| 817 | } |
| 818 | |
| 819 | // syntax id=0,streams=0,1,2 id=1,streams=3,4 and so on |
| 820 | // option id=0,descriptor=descriptor_str,streams=0,1,2 and so on |
| 821 | // option id=0,seg_duration=2.5,frag_duration=0.5,streams=0,1,2 |
| 822 | // id=1,trick_id=0,seg_duration=10,frag_type=none,streams=3 and so on |
| 823 | // descriptor is useful to the scheme defined by ISO/IEC 23009-1:2014/Amd.2:2015 |
| 824 | // descriptor_str should be a self-closing xml tag. |
| 825 | // seg_duration and frag_duration have the same syntax as the global options of |
| 826 | // the same name, and the former have precedence over them if set. |
| 827 | state = new_set; |
| 828 | while (*p) { |
| 829 | if (*p == ' ') { |
| 830 | p++; |
| 831 | continue; |
| 832 | } else if (state == new_set && av_strstart(p, "id=", &p)) { |
| 833 | char id_str[10], *end_str; |
| 834 | |
| 835 | n = strcspn(p, ","); |
| 836 | snprintf(id_str, sizeof(id_str), "%.*s", n, p); |
| 837 | |
| 838 | i = strtol(id_str, &end_str, 10); |
| 839 | if (id_str == end_str || i < 0 || i > c->nb_as) { |
| 840 | av_log(s, AV_LOG_ERROR, "\"%s\" is not a valid value for an AdaptationSet id\n", id_str); |
| 841 | return AVERROR(EINVAL); |
| 842 | } |
| 843 | |
| 844 | if ((ret = add_adaptation_set(s, &as, AVMEDIA_TYPE_UNKNOWN)) < 0) |
| 845 | return ret; |
| 846 | as->id = i; |
| 847 | |
| 848 | p += n; |
| 849 | if (*p) |
| 850 | p++; |
| 851 | state = parse_default; |
| 852 | } else if (state != new_set && av_strstart(p, "seg_duration=", &p)) { |
| 853 | state = parse_seg_duration; |
| 854 | } else if (state != new_set && av_strstart(p, "frag_duration=", &p)) { |
| 855 | state = parse_frag_duration; |
no test coverage detected