Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Marton Balint <cus@passwd.hu>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 1/5] avformat: introduce AVStreamGroup
Date: Tue, 21 Nov 2023 22:57:46 +0100 (CET)
Message-ID: <aaa7062-7eb5-6e58-c133-fa6221527fe6@passwd.hu> (raw)
In-Reply-To: <20231121211442.8723-2-jamrial@gmail.com>



On Tue, 21 Nov 2023, James Almer wrote:

> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavformat/avformat.c | 178 +++++++++++++++++++++++++++++++++++++++--
> libavformat/avformat.h | 163 +++++++++++++++++++++++++++++++++++++
> libavformat/dump.c     |  33 ++++++--
> libavformat/internal.h |  33 ++++++++
> libavformat/options.c  |  90 +++++++++++++++++++++
> 5 files changed, 486 insertions(+), 11 deletions(-)
>
> diff --git a/libavformat/avformat.c b/libavformat/avformat.c
> index 5b8bb7879e..4e31924c71 100644
> --- a/libavformat/avformat.c
> +++ b/libavformat/avformat.c

[...]

> @@ -493,6 +524,46 @@ static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
>                 match = 0;
>             if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
>                 match = 0;
> +        } else if (*spec == 'g' && *(spec + 1) == ':') {
> +            int64_t group_idx = -1, group_id = -1;
> +            int found = 0;
> +            char *endptr;
> +            spec += 2;
> +            if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) {
> +                spec += 1 + (*spec == 'i');
> +                group_id = strtol(spec, &endptr, 0);
> +                if (spec == endptr || (*endptr && *endptr++ != ':'))
> +                    return AVERROR(EINVAL);
> +                spec = endptr;
> +            } else {
> +                group_idx = strtol(spec, &endptr, 0);
> +                /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
> +                if (spec == endptr || (*endptr && *endptr++ != ':'))
> +                    return AVERROR(EINVAL);
> +                spec = endptr;
> +            }
> +            if (match) {
> +                if (group_id > 0) {
> +                    for (unsigned i = 0; i < s->nb_stream_groups; i++) {
> +                        if (group_id == s->stream_groups[i]->id) {
> +                            group_idx = i;
> +                            break;
> +                        }
> +                    }
> +			    }
> +                if (group_idx < 0 || group_idx > s->nb_stream_groups)
> +                    return AVERROR(EINVAL);
> +                for (unsigned j = 0; j < s->stream_groups[group_idx]->nb_streams; j++) {
> +                    if (st->index == s->stream_groups[group_idx]->streams[j]->index) {
> +                        found = 1;
> +                        if (g)
> +                            *g = s->stream_groups[group_idx];
> +                        break;
> +                    }
> +                }
> +            }
> +            if (!found)
> +                match = 0;

The documentation for the stream specifier changes are missing from
doc/fftools-common-opts.texi. You should update relevant docs preferably
in this patch...

[...]

> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -1018,6 +1018,77 @@ typedef struct AVStream {
>     int pts_wrap_bits;
> } AVStream;
>
> +enum AVStreamGroupParamsType {
> +    AV_STREAM_GROUP_PARAMS_NONE,
> +};
> +
> +typedef struct AVStreamGroup {
> +    /**
> +     * A class for @ref avoptions. Set by avformat_stream_group_create().
> +     */
> +    const AVClass *av_class;
> +
> +    void *priv_data;
> +
> +    /**
> +     * Group index in AVFormatContext.
> +     */
> +    unsigned int index;
> +
> +    /**
> +     * Group type-specific group ID.
> +     *
> +     * decoding: set by libavformat
> +     * encoding: may set by the user, replaced by libavformat if left unset
> +     */
> +    int64_t id;

I don't quite get the encoding case where libavformat replaces the unset 
ID... Also, what is unset? 0 or -1? Because as far as I see 0 is the 
default, maybe -1 is better if unset has some special meaning?

[...]

> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 7702986c9c..c6181683ef 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -202,6 +202,7 @@ typedef struct FFStream {
>      */
>     AVStream pub;
>
> +    AVFormatContext *fmtctx;
>     /**
>      * Set to 1 if the codec allows reordering, so pts can be different
>      * from dts.
> @@ -427,6 +428,26 @@ static av_always_inline const FFStream *cffstream(const AVStream *st)
>     return (const FFStream*)st;
> }
>
> +typedef struct FFStreamGroup {
> +    /**
> +     * The public context.
> +     */
> +    AVStreamGroup pub;
> +
> +    AVFormatContext *fmtctx;

If the only purpose of storing this is sanity checking if the user calls 
API with matching stream and stream group, then maybe better to make it 
ptrdiff_t, so nobody will try to misuse this to access the format context 
or do logging, etc...

Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2023-11-21 21:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 21:14 [FFmpeg-devel] [PATCH v4 0/5] " James Almer
2023-11-21 21:14 ` [FFmpeg-devel] [PATCH 1/5] " James Almer
2023-11-21 21:57   ` Marton Balint [this message]
2023-11-25 15:37     ` James Almer
2023-11-21 21:14 ` [FFmpeg-devel] [PATCH 2/5] avutil/mem: add av_dynarray2_add_nofree James Almer
2023-11-21 21:14 ` [FFmpeg-devel] [PATCH 3/5] avformat: Immersive Audio Model and Formats demuxer James Almer
2023-11-21 21:14 ` [FFmpeg-devel] [PATCH 4/5] avformat: Immersive Audio Model and Formats muxer James Almer
2023-11-21 21:14 ` [FFmpeg-devel] [PATCH 5/5] ffmpeg: add support for muxing AVStreamGroups James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aaa7062-7eb5-6e58-c133-fa6221527fe6@passwd.hu \
    --to=cus@passwd.hu \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git