aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2024-01-29 21:35:41 +0100
committerMarton Balint <cus@passwd.hu>2024-02-12 21:03:45 +0100
commit4569b861322671dae4de2b48bdf455ea353a570f (patch)
tree135cb2bfcfd050c4ba49053f1c98510e93cf23a7
parent0748d2bbc79a77abb7ea49cdc3ef55ac2605eaa0 (diff)
downloadffmpeg-4569b861322671dae4de2b48bdf455ea353a570f.tar.gz
avutil/channel_layout: add av_channel_layout_custom_init()
Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r--doc/APIchanges3
-rw-r--r--libavutil/channel_layout.c20
-rw-r--r--libavutil/channel_layout.h17
-rw-r--r--libavutil/version.h4
4 files changed, 42 insertions, 2 deletions
diff --git a/doc/APIchanges b/doc/APIchanges
index 1f5724324a..cdb9b6a458 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_custom_init().
+
2024-02-04 - xxxxxxxxxx - lavc 60.39.100 - packet.h
Add AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT.
diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index b59d798f29..40e31e9d12 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_custom_init(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..dcc320cbfe 100644
--- a/libavutil/channel_layout.h
+++ b/libavutil/channel_layout.h
@@ -618,6 +618,23 @@ 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 channel map will be allocated and the designation of all channels will
+ * be set to AV_CHAN_UNKNOWN.
+ *
+ * This is only a convenience helper function, a custom channel layout can also
+ * be constructed without using this.
+ *
+ * @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_custom_init(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, \