From 41f9abc733b5a397e0af2f979fee3b3a91c767f9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 16 Sep 2024 13:27:17 +0200 Subject: [PATCH] types: add function to convert audio channel short name to type Move some functions around for this --- spa/include/spa/debug/types.h | 5 +---- spa/include/spa/param/audio/raw-types.h | 12 ++++++++++++ spa/include/spa/utils/type-info.h | 4 ---- spa/include/spa/utils/type.h | 13 +++++++++++++ src/tools/pw-cat.c | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/spa/include/spa/debug/types.h b/spa/include/spa/debug/types.h index 6e53a547c..1c9ff51a2 100644 --- a/spa/include/spa/debug/types.h +++ b/spa/include/spa/debug/types.h @@ -39,10 +39,7 @@ static inline const struct spa_type_info *spa_debug_type_find(const struct spa_t static inline const char *spa_debug_type_short_name(const char *name) { - const char *h; - if ((h = strrchr(name, ':')) != NULL) - name = h + 1; - return name; + return spa_type_short_name(name); } static inline const char *spa_debug_type_find_name(const struct spa_type_info *info, uint32_t type) diff --git a/spa/include/spa/param/audio/raw-types.h b/spa/include/spa/param/audio/raw-types.h index 5dd65d777..640198fc5 100644 --- a/spa/include/spa/param/audio/raw-types.h +++ b/spa/include/spa/param/audio/raw-types.h @@ -15,6 +15,7 @@ extern "C" { */ #include +#include #include #define SPA_TYPE_INFO_AudioFormat SPA_TYPE_INFO_ENUM_BASE "AudioFormat" @@ -247,6 +248,17 @@ static const struct spa_type_info spa_type_audio_channel[] = { { 0, 0, NULL, NULL }, }; +static inline uint32_t spa_type_audio_channel_from_short_name(const char *name) +{ + int i; + for (i = 0; spa_type_audio_channel[i].name; i++) { + if (spa_streq(name, spa_type_short_name(spa_type_audio_channel[i].name))) + return spa_type_audio_channel[i].type; + } + return SPA_AUDIO_CHANNEL_UNKNOWN; +} + + /** * \} */ diff --git a/spa/include/spa/utils/type-info.h b/spa/include/spa/utils/type-info.h index 1d9cd29b7..9ee2f3abc 100644 --- a/spa/include/spa/utils/type-info.h +++ b/spa/include/spa/utils/type-info.h @@ -20,10 +20,6 @@ extern "C" { #define SPA_TYPE_ROOT spa_types #endif -static inline bool spa_type_is_a(const char *type, const char *parent) -{ - return type != NULL && parent != NULL && strncmp(type, parent, strlen(parent)) == 0; -} #include #include diff --git a/spa/include/spa/utils/type.h b/spa/include/spa/utils/type.h index 65610c11e..328600433 100644 --- a/spa/include/spa/utils/type.h +++ b/spa/include/spa/utils/type.h @@ -123,6 +123,19 @@ struct spa_type_info { const struct spa_type_info *values; }; +static inline bool spa_type_is_a(const char *type, const char *parent) +{ + return type != NULL && parent != NULL && strncmp(type, parent, strlen(parent)) == 0; +} + +static inline const char *spa_type_short_name(const char *name) +{ + const char *h; + if ((h = strrchr(name, ':')) != NULL) + name = h + 1; + return name; +} + /** * \} */ diff --git a/src/tools/pw-cat.c b/src/tools/pw-cat.c index 4372a3fa8..fe1b3cc1e 100644 --- a/src/tools/pw-cat.c +++ b/src/tools/pw-cat.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include