- os = &c->streams[i];
- if (as->media_type == AVMEDIA_TYPE_UNKNOWN) {
- as->media_type = s->streams[i]->codecpar->codec_type;
- } else if (as->media_type != s->streams[i]->codecpar->codec_type) {
- av_log(s, AV_LOG_ERROR, "Mixing codec types within an AdaptationSet is not allowed\n");
- return AVERROR(EINVAL);
- } else if (os->as_idx) {
- av_log(s, AV_LOG_ERROR, "Assigning a stream to more than one AdaptationSet is not allowed\n");
- return AVERROR(EINVAL);
+ for (i = 0; i < s->nb_streams; i++) {
+ if (s->streams[i]->codecpar->codec_type != type)
+ continue;
+
+ as->media_type = s->streams[i]->codecpar->codec_type;
+
+ if ((ret = adaptation_set_add_stream(s, c->nb_as, i)) < 0)
+ return ret;
+ }
+ } else { // select single stream
+ i = strtol(idx_str, &end_str, 10);
+ if (idx_str == end_str || i < 0 || i >= s->nb_streams) {
+ av_log(s, AV_LOG_ERROR, "Selected stream \"%s\" not found!\n", idx_str);
+ return AVERROR(EINVAL);
+ }
+ av_log(s, AV_LOG_DEBUG, "Map stream %d\n", i);
+
+ if (as->media_type == AVMEDIA_TYPE_UNKNOWN) {
+ as->media_type = s->streams[i]->codecpar->codec_type;
+ }
+
+ if ((ret = adaptation_set_add_stream(s, c->nb_as, i)) < 0)
+ return ret;