You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-11-23 21:54:53 +02:00
fftools/cmdutils: split stream specifier parsing and matching
This approach has the major advantage that only parsing can fail (due to a malformed specifier or memory allocation failure). Since parsing is done generically, while matching is per-option, this will allow to remove substantial amounts of error checking code in following commits. The new code also explicitly allows stream specifiers to be followed by additional characters, which should allow cleaner handling of optional maps, i.e. -map <stream_specifier>?, which is currently implemented in a hacky way that breaks when the stream specifier itself contains the '?' character (this can happen when matching metadata). It will also allow further extending the syntax, which will be useful in following commits. This introduces some minor behaviour changes: * Matching metadata tags now requires the ':' character in keys or values to be escaped. Previously it could not be present in keys, and would be used verbatim in values. The change is required in order to know where the value terminates. * Multiple stream types in a single specifier are now rejected - such a specifier makes no sense. * Non-existent stream group ID or index is now ignored with a warning rather than causing a failure. This is consistent with program handling and is required to make matching fail-free.
This commit is contained in:
@@ -102,6 +102,62 @@ enum OptionType {
|
||||
int parse_number(const char *context, const char *numstr, enum OptionType type,
|
||||
double min, double max, double *dst);
|
||||
|
||||
enum StreamList {
|
||||
STREAM_LIST_ALL,
|
||||
STREAM_LIST_STREAM_ID,
|
||||
STREAM_LIST_PROGRAM,
|
||||
STREAM_LIST_GROUP_ID,
|
||||
STREAM_LIST_GROUP_IDX,
|
||||
};
|
||||
|
||||
typedef struct StreamSpecifier {
|
||||
// trailing stream index - pick idx-th stream that matches
|
||||
// all the other constraints; -1 when not present
|
||||
int idx;
|
||||
|
||||
// which stream list to consider
|
||||
enum StreamList stream_list;
|
||||
|
||||
// STREAM_LIST_STREAM_ID: stream ID
|
||||
// STREAM_LIST_GROUP_IDX: group index
|
||||
// STREAM_LIST_GROUP_ID: group ID
|
||||
// STREAM_LIST_PROGRAM: program ID
|
||||
int64_t list_id;
|
||||
|
||||
// when not AVMEDIA_TYPE_UNKNOWN, consider only streams of this type
|
||||
enum AVMediaType media_type;
|
||||
uint8_t no_apic;
|
||||
|
||||
uint8_t usable_only;
|
||||
|
||||
char *meta_key;
|
||||
char *meta_val;
|
||||
|
||||
char *remainder;
|
||||
} StreamSpecifier;
|
||||
|
||||
/**
|
||||
* Parse a stream specifier string into a form suitable for matching.
|
||||
*
|
||||
* @param ss Parsed specifier will be stored here; must be uninitialized
|
||||
* with stream_specifier_uninit() when no longer needed.
|
||||
* @param spec String containing the stream specifier to be parsed.
|
||||
* @param allow_remainder When 1, the part of spec that is left after parsing
|
||||
* the stream specifier is stored into ss->remainder.
|
||||
* When 0, any remainder will cause parsing to fail.
|
||||
*/
|
||||
int stream_specifier_parse(StreamSpecifier *ss, const char *spec,
|
||||
int allow_remainder, void *logctx);
|
||||
|
||||
/**
|
||||
* @return 1 if st matches the parsed specifier, 0 if it does not
|
||||
*/
|
||||
unsigned stream_specifier_match(const StreamSpecifier *ss,
|
||||
const AVFormatContext *s, const AVStream *st,
|
||||
void *logctx);
|
||||
|
||||
void stream_specifier_uninit(StreamSpecifier *ss);
|
||||
|
||||
typedef struct SpecifierOpt {
|
||||
char *specifier; /**< stream/chapter/program/... specifier */
|
||||
union {
|
||||
|
||||
Reference in New Issue
Block a user