summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Große <pegro@friiks.de>2017-01-29 15:26:28 +0100
committerMartin Storsjö <martin@martin.st>2017-01-31 00:24:14 +0200
commitefd2fc41b3f0749f9715d50b581f22bbaa8c5b99 (patch)
treed413708d034087d56512f59a5769c16638b097b0
parent3d23a5f96ad72961c14ba3a0c2add8f2ab374b61 (diff)
dashenc: allow assigning all streams of a media type to an AdaptationSet
Using the characters "v" or "a" instead of stream index numbers for assigning streams in the adaption_set option, all streams matching that given type will be added to the AdaptationSet. Signed-off-by: Peter Große <pegro@friiks.de> Signed-off-by: Martin Storsjö <martin@martin.st>
-rw-r--r--libavformat/dashenc.c61
1 files changed, 45 insertions, 16 deletions
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index e69e63e9ab..12e6f9b5d9 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -499,6 +499,24 @@ static int add_adaptation_set(AVFormatContext *s, AdaptationSet **as, enum AVMed
return 0;
}
+static int adaptation_set_add_stream(AVFormatContext *s, int as_idx, int i)
+{
+ DASHContext *c = s->priv_data;
+ AdaptationSet *as = &c->as[as_idx - 1];
+ OutputStream *os = &c->streams[i];
+
+ if (as->media_type != s->streams[i]->codecpar->codec_type) {
+ av_log(s, AV_LOG_ERROR, "Codec type of stream %d doesn't match AdaptationSet's media type\n", i);
+ return AVERROR(EINVAL);
+ } else if (os->as_idx) {
+ av_log(s, AV_LOG_ERROR, "Stream %d is already assigned to an AdaptationSet\n", i);
+ return AVERROR(EINVAL);
+ }
+ os->as_idx = as_idx;
+
+ return 0;
+}
+
static int parse_adaptation_sets(AVFormatContext *s)
{
DASHContext *c = s->priv_data;
@@ -552,30 +570,41 @@ static int parse_adaptation_sets(AVFormatContext *s)
state = parsing_streams;
} else if (state == parsing_streams) {
AdaptationSet *as = &c->as[c->nb_as - 1];
- OutputStream *os;
char idx_str[8], *end_str;
n = strcspn(p, " ,");
snprintf(idx_str, sizeof(idx_str), "%.*s", n, p);
p += n;
- 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);
- }
+ // if value is "a" or "v", map all streams of that type
+ if (as->media_type == AVMEDIA_TYPE_UNKNOWN && (idx_str[0] == 'v' || idx_str[0] == 'a')) {
+ enum AVMediaType type = (idx_str[0] == 'v') ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO;
+ av_log(s, AV_LOG_DEBUG, "Map all streams of type %s\n", idx_str);
+
+ 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;
+ }
- 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);
+ if ((ret = adaptation_set_add_stream(s, c->nb_as, i)) < 0)
+ return ret;
}
- os->as_idx = c->nb_as;
if (*p == ' ')
state = new_set;