diff mbox series

[FFmpeg-devel,3/5] avutil/channel_layout: add av_channel_layout_from_custom()

Message ID 20240129232755.9622-3-cus@passwd.hu
State New
Headers show
Series [FFmpeg-devel,1/5] avformat/mov_chan: do not assume channels are in native order | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Marton Balint Jan. 29, 2024, 11:27 p.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 doc/APIchanges             |  3 +++
 libavutil/channel_layout.c | 20 ++++++++++++++++++++
 libavutil/channel_layout.h | 13 +++++++++++++
 libavutil/version.h        |  4 ++--
 4 files changed, 38 insertions(+), 2 deletions(-)

Comments

Anton Khirnov Feb. 1, 2024, 8:56 a.m. UTC | #1
Quoting Marton Balint (2024-01-30 00:27:53)
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  doc/APIchanges             |  3 +++
>  libavutil/channel_layout.c | 20 ++++++++++++++++++++
>  libavutil/channel_layout.h | 13 +++++++++++++
>  libavutil/version.h        |  4 ++--
>  4 files changed, 38 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index e477ed78e0..8e8498f803 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
>  
>  API changes, most recent first:
>  
> +2024-02-xx - xxxxxxxxxx - lavu 58.37.100 - channel_layout.h
> +  Add av_channel_layout_from_custom().

The name seems misleading to me, there is no 'custom' from which a
channel layout is derived.

It should be something like av_channel_layout_custom_init() instead.

> +/**
> + * Initialize a custom channel layout with the specified number of channels.
> + * The designation of all channels will be unknown.
> + *
> + * @param channel_layout the layout structure to be initialized
> + * @param nb_channels the number of channels
> + *
> + * @return 0 on success
> + *         AVERROR(EINVAL) if the number of channels <= 0
> + *         AVERROR(ENOMEM) if the channel map could not be allocated
> + */

It should say that this is a convenience helper, so people don't think
this is the only way to build custom layouts.
It should also explicitly say it allocates the channel map array.
Marton Balint Feb. 1, 2024, 8:01 p.m. UTC | #2
On Thu, 1 Feb 2024, Anton Khirnov wrote:

> Quoting Marton Balint (2024-01-30 00:27:53)
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>>  doc/APIchanges             |  3 +++
>>  libavutil/channel_layout.c | 20 ++++++++++++++++++++
>>  libavutil/channel_layout.h | 13 +++++++++++++
>>  libavutil/version.h        |  4 ++--
>>  4 files changed, 38 insertions(+), 2 deletions(-)
>>
>> diff --git a/doc/APIchanges b/doc/APIchanges
>> index e477ed78e0..8e8498f803 100644
>> --- a/doc/APIchanges
>> +++ b/doc/APIchanges
>> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
>>
>>  API changes, most recent first:
>>
>> +2024-02-xx - xxxxxxxxxx - lavu 58.37.100 - channel_layout.h
>> +  Add av_channel_layout_from_custom().
>
> The name seems misleading to me, there is no 'custom' from which a
> channel layout is derived.
>
> It should be something like av_channel_layout_custom_init() instead.

The other initializer functions follow the av_channel_layout_from_* 
pattern. But I can rename of course if that is preferred.

>
>> +/**
>> + * Initialize a custom channel layout with the specified number of channels.
>> + * The designation of all channels will be unknown.
>> + *
>> + * @param channel_layout the layout structure to be initialized
>> + * @param nb_channels the number of channels
>> + *
>> + * @return 0 on success
>> + *         AVERROR(EINVAL) if the number of channels <= 0
>> + *         AVERROR(ENOMEM) if the channel map could not be allocated
>> + */
>
> It should say that this is a convenience helper, so people don't think
> this is the only way to build custom layouts.
> It should also explicitly say it allocates the channel map array.

Ok, will send v2.

Thanks,
Marton
Anton Khirnov Feb. 2, 2024, 4:42 a.m. UTC | #3
Quoting Marton Balint (2024-02-01 21:01:37)
> 
> 
> On Thu, 1 Feb 2024, Anton Khirnov wrote:
> 
> > Quoting Marton Balint (2024-01-30 00:27:53)
> >> Signed-off-by: Marton Balint <cus@passwd.hu>
> >> ---
> >>  doc/APIchanges             |  3 +++
> >>  libavutil/channel_layout.c | 20 ++++++++++++++++++++
> >>  libavutil/channel_layout.h | 13 +++++++++++++
> >>  libavutil/version.h        |  4 ++--
> >>  4 files changed, 38 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/doc/APIchanges b/doc/APIchanges
> >> index e477ed78e0..8e8498f803 100644
> >> --- a/doc/APIchanges
> >> +++ b/doc/APIchanges
> >> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
> >>
> >>  API changes, most recent first:
> >>
> >> +2024-02-xx - xxxxxxxxxx - lavu 58.37.100 - channel_layout.h
> >> +  Add av_channel_layout_from_custom().
> >
> > The name seems misleading to me, there is no 'custom' from which a
> > channel layout is derived.
> >
> > It should be something like av_channel_layout_custom_init() instead.
> 
> The other initializer functions follow the av_channel_layout_from_* 
> pattern. But I can rename of course if that is preferred.

All av_foo_from_x() take x and build foo from it, but this function does
not.
diff mbox series

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index e477ed78e0..8e8498f803 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@  The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2024-02-xx - xxxxxxxxxx - lavu 58.37.100 - channel_layout.h
+  Add av_channel_layout_from_custom().
+
 2023-11-xx - xxxxxxxxxx - lavfi 9.16.100 - buffersink.h buffersrc.h
   Add av_buffersink_get_colorspace and av_buffersink_get_color_range.
   Add AVBufferSrcParameters.color_space and AVBufferSrcParameters.color_range.
diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index b59d798f29..0810d32bf6 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -398,6 +398,26 @@  int av_get_standard_channel_layout(unsigned index, uint64_t *layout,
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
+int av_channel_layout_from_custom(AVChannelLayout *channel_layout, int nb_channels)
+{
+    AVChannelCustom *map;
+
+    if (nb_channels <= 0)
+        return AVERROR(EINVAL);
+
+    map = av_calloc(nb_channels, sizeof(*channel_layout->u.map));
+    if (!map)
+        return AVERROR(ENOMEM);
+    for (int i = 0; i < nb_channels; i++)
+        map[i].id = AV_CHAN_UNKNOWN;
+
+    channel_layout->order       = AV_CHANNEL_ORDER_CUSTOM;
+    channel_layout->nb_channels = nb_channels;
+    channel_layout->u.map       = map;
+
+    return 0;
+}
+
 int av_channel_layout_from_mask(AVChannelLayout *channel_layout,
                                 uint64_t mask)
 {
diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h
index 8dc1a91401..37629ab5d2 100644
--- a/libavutil/channel_layout.h
+++ b/libavutil/channel_layout.h
@@ -617,6 +617,19 @@  void av_channel_description_bprint(struct AVBPrint *bp, enum AVChannel channel_i
  */
 enum AVChannel av_channel_from_string(const char *name);
 
+/**
+ * Initialize a custom channel layout with the specified number of channels.
+ * The designation of all channels will be unknown.
+ *
+ * @param channel_layout the layout structure to be initialized
+ * @param nb_channels the number of channels
+ *
+ * @return 0 on success
+ *         AVERROR(EINVAL) if the number of channels <= 0
+ *         AVERROR(ENOMEM) if the channel map could not be allocated
+ */
+int av_channel_layout_from_custom(AVChannelLayout *channel_layout, int nb_channels);
+
 /**
  * Initialize a native channel layout from a bitmask indicating which channels
  * are present.
diff --git a/libavutil/version.h b/libavutil/version.h
index 772c4e209c..3b38f8f5da 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,8 +79,8 @@ 
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  58
-#define LIBAVUTIL_VERSION_MINOR  36
-#define LIBAVUTIL_VERSION_MICRO 101
+#define LIBAVUTIL_VERSION_MINOR  37
+#define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \