[FFmpeg-devel] [PATCH 1/5] lavf: make cmdutils's check_stream_specifier public.

Stefano Sabatini stefasab at gmail.com
Fri Jul 20 12:38:11 CEST 2012


On date Thursday 2012-07-19 14:47:42 +0200, Nicolas George encoded:
> The new function is called avformat_match_stream_specifier()
> and does not include logging the error message.
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  cmdutils.c             |   60 ++++-------------------------------------------
>  libavformat/avformat.h |   15 ++++++++++++
>  libavformat/utils.c    |   61 ++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 80 insertions(+), 56 deletions(-)

Reminder: minor bump + APIchanges entry.

> 
> diff --git a/cmdutils.c b/cmdutils.c
> index e90a9ee..d03cd6a 100644
> --- a/cmdutils.c
> +++ b/cmdutils.c
> @@ -1087,62 +1087,10 @@ FILE *get_preset_file(char *filename, size_t filename_size,
>  
>  int check_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);
> +    int ret = avformat_match_stream_specifier(s, st, spec);
> +    if (ret < 0)
> +        av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
> +    return ret;
>  }
>  
>  AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id,
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 3bbc683..42d5b48 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -1972,6 +1972,21 @@ const struct AVCodecTag *avformat_get_riff_audio_tags(void);
>  AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame);
>  
>  /**
> + * Match a stream against a stream specififier.

specififier -> specifier

Also maybe more clear:
Check if the stream st contained in s is matched by the stream specifier spec.

> + *
> + * See the "strem specifiers" chapter in the documentation for the syntax of

strem -> stream

> + * spec.

Note: I think that since this is going into the lib having it
documented in avtools-common-opts.texi is not a good idea.

Also a "Stream specifiers" chapter really doesn't belong to a file
named "common options", maybe doc/syntax.texi would be a better place.

Also I don't know if we should document it in the lib doxy anyway (but
don't consider this blocking, just maybe add a TODO or FIXME).

[...]

Should be good otherwise.
-- 
FFmpeg = Fabulous & Funny Mortal Purposeless Excellent Genius


More information about the ffmpeg-devel mailing list