-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' || *spec == 'V') { /* opt:[vasdtV] */
- enum AVMediaType type;
- int nopic = 0;
-
- 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;
- case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
- default: av_assert0(0);
- }
-#if FF_API_LAVF_AVCTX
-FF_DISABLE_DEPRECATION_WARNINGS
- if (type != st->codecpar->codec_type
- && (st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN || st->codec->codec_type != type))
- return 0;
-FF_ENABLE_DEPRECATION_WARNINGS
-#else
- if (type != st->codecpar->codec_type)
- return 0;
-#endif
- if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
- return 0;
- if (*spec++ == ':') { /* possibly followed by :index */
- int i, index = strtol(spec, NULL, 0);
- for (i = 0; i < s->nb_streams; i++) {
-#if FF_API_LAVF_AVCTX
-FF_DISABLE_DEPRECATION_WARNINGS
- if ((s->streams[i]->codecpar->codec_type == type
- || s->streams[i]->codec->codec_type == type
- ) &&
- !(nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC)) &&
- index-- == 0)
- return i == st->index;
-FF_ENABLE_DEPRECATION_WARNINGS
-#else
- if ((s->streams[i]->codecpar->codec_type == type) &&
- !(nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC)) &&
- index-- == 0)
- return i == st->index;
-#endif
+/**
+ * Matches a stream specifier (but ignores requested index).
+ *
+ * @param indexptr set to point to the requested stream index if there is one
+ *
+ * @return <0 on error
+ * 0 if st is NOT a matching stream
+ * >0 if st is a matching stream
+ */
+static int match_stream_specifier(AVFormatContext *s, AVStream *st,
+ const char *spec, const char **indexptr)
+{
+ int match = 1; /* Stores if the specifier matches so far. */
+ while (*spec) {
+ if (*spec <= '9' && *spec >= '0') { /* opt:index */
+ if (indexptr)
+ *indexptr = spec;
+ return match;
+ } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
+ *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
+ enum AVMediaType type;
+ int nopic = 0;
+
+ 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;
+ case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
+ default: av_assert0(0);