| 1224 | } |
| 1225 | |
| 1226 | unsigned stream_specifier_match(const StreamSpecifier *ss, |
| 1227 | const AVFormatContext *s, const AVStream *st, |
| 1228 | void *logctx) |
| 1229 | { |
| 1230 | const AVStreamGroup *g = NULL; |
| 1231 | const AVProgram *p = NULL; |
| 1232 | int start_stream = 0, nb_streams; |
| 1233 | int nb_matched = 0; |
| 1234 | |
| 1235 | switch (ss->stream_list) { |
| 1236 | case STREAM_LIST_STREAM_ID: |
| 1237 | // <n-th> stream with given ID makes no sense and should be impossible to request |
| 1238 | av_assert0(ss->idx < 0); |
| 1239 | // return early if we know for sure the stream does not match |
| 1240 | if (st->id != ss->list_id) |
| 1241 | return 0; |
| 1242 | start_stream = st->index; |
| 1243 | nb_streams = st->index + 1; |
| 1244 | break; |
| 1245 | case STREAM_LIST_ALL: |
| 1246 | start_stream = ss->idx >= 0 ? 0 : st->index; |
| 1247 | nb_streams = st->index + 1; |
| 1248 | break; |
| 1249 | case STREAM_LIST_PROGRAM: |
| 1250 | for (unsigned i = 0; i < s->nb_programs; i++) { |
| 1251 | if (s->programs[i]->id == ss->list_id) { |
| 1252 | p = s->programs[i]; |
| 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | if (!p) { |
| 1257 | av_log(logctx, AV_LOG_WARNING, "No program with ID %"PRId64" exists," |
| 1258 | " stream specifier can never match\n", ss->list_id); |
| 1259 | return 0; |
| 1260 | } |
| 1261 | nb_streams = p->nb_stream_indexes; |
| 1262 | break; |
| 1263 | case STREAM_LIST_GROUP_ID: |
| 1264 | for (unsigned i = 0; i < s->nb_stream_groups; i++) { |
| 1265 | if (ss->list_id == s->stream_groups[i]->id) { |
| 1266 | g = s->stream_groups[i]; |
| 1267 | break; |
| 1268 | } |
| 1269 | } |
| 1270 | // fall-through |
| 1271 | case STREAM_LIST_GROUP_IDX: |
| 1272 | if (ss->stream_list == STREAM_LIST_GROUP_IDX && |
| 1273 | ss->list_id >= 0 && ss->list_id < s->nb_stream_groups) |
| 1274 | g = s->stream_groups[ss->list_id]; |
| 1275 | |
| 1276 | if (!g) { |
| 1277 | av_log(logctx, AV_LOG_WARNING, "No stream group with group %s %" |
| 1278 | PRId64" exists, stream specifier can never match\n", |
| 1279 | ss->stream_list == STREAM_LIST_GROUP_ID ? "ID" : "index", |
| 1280 | ss->list_id); |
| 1281 | return 0; |
| 1282 | } |
| 1283 | nb_streams = g->nb_streams; |
no test coverage detected