From 8123adadbd856e13a8870400fa5852eb3702e7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= Date: Sun, 12 Jun 2022 23:26:22 +0300 Subject: audio/chmap: add mp_iterate_builtin_layouts Mostly useful for unit tests in order to access the channel layouts from chmap which have mapped channels. --- audio/chmap.c | 17 +++++++++++++++++ audio/chmap.h | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/audio/chmap.c b/audio/chmap.c index edbe83eb68..cd8c767c47 100644 --- a/audio/chmap.c +++ b/audio/chmap.c @@ -470,6 +470,23 @@ char *mp_chmap_to_str_hr_buf(char *buf, size_t buf_size, const struct mp_chmap * return mp_chmap_to_str_buf(buf, buf_size, &map); } +mp_ch_layout_tuple *mp_iterate_builtin_layouts(void **opaque) +{ + uintptr_t i = (uintptr_t)*opaque; + + if (i >= MP_ARRAY_SIZE(std_layout_names) || + !std_layout_names[i][0]) + return NULL; + + *opaque = (void *)(i + 1); + + if (std_layout_names[i][1][0] == '\0') { + return mp_iterate_builtin_layouts(opaque); + } + + return &std_layout_names[i]; +} + void mp_chmap_print_help(struct mp_log *log) { mp_info(log, "Speakers:\n"); diff --git a/audio/chmap.h b/audio/chmap.h index dff69336d6..6fbb60d025 100644 --- a/audio/chmap.h +++ b/audio/chmap.h @@ -75,6 +75,8 @@ struct mp_chmap { uint8_t speaker[MP_NUM_CHANNELS]; }; +typedef const char * const (mp_ch_layout_tuple)[2]; + #define MP_SP(speaker) MP_SPEAKER_ID_ ## speaker #define MP_CHMAP2(a, b) \ @@ -129,6 +131,19 @@ char *mp_chmap_to_str_hr_buf(char *buf, size_t buf_size, const struct mp_chmap * bool mp_chmap_from_str(struct mp_chmap *dst, bstr src); +/** + * Iterate over all built-in channel layouts which have mapped channels. + * + * @param opaque a pointer where the iteration state is stored. Must point + * to nullptr to start the iteration. + * + * @return nullptr when the iteration is finished. + * Otherwise a pointer to an array of two char pointers. + * - [0] being the human-readable layout name. + * - [1] being the string representation of the layout. + */ +mp_ch_layout_tuple *mp_iterate_builtin_layouts(void **opaque); + struct mp_log; void mp_chmap_print_help(struct mp_log *log); -- cgit v1.2.3