Re: [FFmpeg-devel] [PATCH v2] avformat: introduce AVStreamGroup

2023-10-30 Thread Tomas Härdin
ons 2023-10-25 klockan 16:40 -0300 skrev James Almer:
> On 10/25/2023 4:25 PM, Tomas Härdin wrote:
> > >   
> > > +enum AVStreamGroupParamsType {
> > > +    AV_STREAM_GROUP_PARAMS_NONE,
> > 
> > Maybe AV_STREAM_GROUP_PARAMS_NUM on the end?
> 
> For what purpose? Usually, when we add those values they are not part
> of 
> the API and exist for some internal iteration.

Perhaps more importantly, it would be a symbol that would have to
become versioned. So, objection retracted :)

/Tomas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2] avformat: introduce AVStreamGroup

2023-10-25 Thread James Almer

On 10/25/2023 4:25 PM, Tomas Härdin wrote:
  
+enum AVStreamGroupParamsType {

+    AV_STREAM_GROUP_PARAMS_NONE,


Maybe AV_STREAM_GROUP_PARAMS_NUM on the end?


For what purpose? Usually, when we add those values they are not part of 
the API and exist for some internal iteration.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2] avformat: introduce AVStreamGroup

2023-10-25 Thread Tomas Härdin
>  
> +enum AVStreamGroupParamsType {
> +    AV_STREAM_GROUP_PARAMS_NONE,

Maybe AV_STREAM_GROUP_PARAMS_NUM on the end?

/Tomas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v2] avformat: introduce AVStreamGroup

2023-10-23 Thread James Almer
Signed-off-by: James Almer 
---
Changes since the first version:

- The union will now hold pointers to Group type specific structs
- The array of elements in the group is now of pointers to the streams
  rather than index values.
- Simplified the helpers
- Changed field type for idx and id
- Added an AVDictionary to hold metadata

 libavformat/avformat.c |  30 +
 libavformat/avformat.h | 138 +
 libavformat/internal.h |  33 ++
 libavformat/options.c  |  62 ++
 4 files changed, 263 insertions(+)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 5b8bb7879e..99cda56c2f 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -80,6 +80,24 @@ FF_ENABLE_DEPRECATION_WARNINGS
 av_freep(pst);
 }
 
+void ff_free_stream_group(AVStreamGroup **pstg)
+{
+AVStreamGroup *stg = *pstg;
+
+if (!stg)
+return;
+
+av_freep(>streams);
+av_freep(>priv_data);
+switch (stg->type) {
+// Structs in the union are freed here
+default:
+break;
+}
+
+av_freep(pstg);
+}
+
 void ff_remove_stream(AVFormatContext *s, AVStream *st)
 {
 av_assert0(s->nb_streams>0);
@@ -88,6 +106,14 @@ void ff_remove_stream(AVFormatContext *s, AVStream *st)
 ff_free_stream(>streams[ --s->nb_streams ]);
 }
 
+void ff_remove_stream_group(AVFormatContext *s, AVStreamGroup *stg)
+{
+av_assert0(s->nb_stream_groups > 0);
+av_assert0(s->stream_groups[ s->nb_stream_groups - 1 ] == stg);
+
+ff_free_stream_group(>stream_groups[ --s->nb_stream_groups ]);
+}
+
 /* XXX: suppress the packet queue */
 void ff_flush_packet_queue(AVFormatContext *s)
 {
@@ -118,6 +144,9 @@ void avformat_free_context(AVFormatContext *s)
 
 for (unsigned i = 0; i < s->nb_streams; i++)
 ff_free_stream(>streams[i]);
+for (unsigned i = 0; i < s->nb_stream_groups; i++)
+ff_free_stream_group(>stream_groups[i]);
+s->nb_stream_groups = 0;
 s->nb_streams = 0;
 
 for (unsigned i = 0; i < s->nb_programs; i++) {
@@ -138,6 +167,7 @@ void avformat_free_context(AVFormatContext *s)
 av_dict_free(>id3v2_meta);
 av_packet_free(>pkt);
 av_packet_free(>parse_pkt);
+av_freep(>stream_groups);
 av_freep(>streams);
 ff_flush_packet_queue(s);
 av_freep(>url);
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 9e7eca007e..f045084c8d 100644
--- 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 on group creation.
+ */
+const AVClass *av_class;
+
+void *priv_data;
+
+/**
+ * Group index in AVFormatContext.
+ */
+unsigned int index;
+
+/**
+ * Group-specific group ID.
+ *
+ * decoding: set by libavformat
+ * encoding: set by the user, replaced by libavformat if left unset
+ */
+int64_t id;
+
+/**
+ * Group-specific type
+ *
+ * decoding: set by libavformat on group creation
+ * encoding: set by the user on group creation
+ */
+enum AVStreamGroupParamsType type;
+
+/**
+ * Group-specific type parameters
+ */
+union {
+uintptr_t dummy; // Placeholder
+} params;
+
+/**
+ * Metadata that applies to the whole file.
+ *
+ * - demuxing: set by libavformat in avformat_open_input()
+ * - muxing: may be set by the caller before avformat_write_header()
+ *
+ * Freed by libavformat in avformat_free_context().
+ */
+AVDictionary *metadata;
+
+/**
+ * Number of elements in AVStreamGroup.streams.
+ *
+ * Set by avformat_stream_group_add_stream() must not be modified by any 
other code.
+ */
+unsigned int nb_streams;
+
+/**
+ * A list of streams in the group. New entries are created with
+ * avformat_stream_group_add_stream().
+ *
+ * - demuxing: entries are created by libavformat in avformat_open_input().
+ * If AVFMTCTX_NOHEADER is set in ctx_flags, then new entries 
may also
+ * appear in av_read_frame().
+ * - muxing: entries are created by the user before 
avformat_write_header().
+ *
+ * Freed by libavformat in avformat_free_context().
+ */
+const AVStream **streams;
+} AVStreamGroup;
+
 struct AVCodecParserContext *av_stream_get_parser(const AVStream *s);
 
 #if FF_API_GET_END_PTS
@@ -1726,6 +1797,26 @@ typedef struct AVFormatContext {
  * @return 0 on success, a negative AVERROR code on failure
  */
 int (*io_close2)(struct AVFormatContext *s, AVIOContext *pb);
+
+/**
+ * Number of elements in AVFormatContext.stream_groups.
+ *
+ * Set by avformat_stream_group_create(), must not be modified by any 
other code.
+ */
+unsigned int nb_stream_groups;
+
+/**
+ *