aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/utils.c
diff options
context:
space:
mode:
authorNicolas George <nicolas.george@normalesup.org>2012-07-18 11:41:13 +0200
committerNicolas George <nicolas.george@normalesup.org>2012-07-20 13:16:23 +0200
commitb0629366a26628f19245ea2c06a6e366cb70f92f (patch)
tree488668607910fb323808a03d7979c65544a6343d /libavformat/utils.c
parent3bd3e46c918005ab5b0fdfd36911373a6e94df9b (diff)
downloadffmpeg-b0629366a26628f19245ea2c06a6e366cb70f92f.tar.gz
lavf: make cmdutils's check_stream_specifier public.
The new function is called avformat_match_stream_specifier() and does not include logging the error message.
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r--libavformat/utils.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index cfa9e82f3f..c437866d68 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4509,3 +4509,64 @@ AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *strea
else
return frame_sample_aspect_ratio;
}
+
+int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
+ const char *spec)
+{
+ if (*spec <= '9' && *spec >= '0') /* opt:index */
+ return strtol(spec, NULL, 0) == st->index;
+ else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
+ *spec == 't') { /* opt:[vasdt] */
+ enum AVMediaType type;
+
+ switch (*spec++) {
+ case 'v': type = AVMEDIA_TYPE_VIDEO; break;
+ case 'a': type = AVMEDIA_TYPE_AUDIO; break;
+ case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
+ case 'd': type = AVMEDIA_TYPE_DATA; break;
+ case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
+ default: av_assert0(0);
+ }
+ if (type != st->codec->codec_type)
+ return 0;
+ if (*spec++ == ':') { /* possibly followed by :index */
+ int i, index = strtol(spec, NULL, 0);
+ for (i = 0; i < s->nb_streams; i++)
+ if (s->streams[i]->codec->codec_type == type && index-- == 0)
+ return i == st->index;
+ return 0;
+ }
+ return 1;
+ } else if (*spec == 'p' && *(spec + 1) == ':') {
+ int prog_id, i, j;
+ char *endptr;
+ spec += 2;
+ prog_id = strtol(spec, &endptr, 0);
+ for (i = 0; i < s->nb_programs; i++) {
+ if (s->programs[i]->id != prog_id)
+ continue;
+
+ if (*endptr++ == ':') {
+ int stream_idx = strtol(endptr, NULL, 0);
+ return stream_idx >= 0 &&
+ stream_idx < s->programs[i]->nb_stream_indexes &&
+ st->index == s->programs[i]->stream_index[stream_idx];
+ }
+
+ for (j = 0; j < s->programs[i]->nb_stream_indexes; j++)
+ if (st->index == s->programs[i]->stream_index[j])
+ return 1;
+ }
+ return 0;
+ } else if (*spec == '#') {
+ int sid;
+ char *endptr;
+ sid = strtol(spec + 1, &endptr, 0);
+ if (!*endptr)
+ return st->id == sid;
+ } else if (!*spec) /* empty specifier, matches everything */
+ return 1;
+
+ av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
+ return AVERROR(EINVAL);
+}