From 705c2a652bf1f0aab195b5452fb164538deffd15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sat, 14 Dec 2024 22:43:25 +0100 Subject: [PATCH] pipewire: module-vban: fix vban serial header The expression `VBAN_PROTOCOL_SERIAL | vban_BPSList[14]` is assigned to an 8 bit field of the header, but, `vban_BPSList[14]` being 115200, it does not fit. Instead, its index, 14, should be placed in the header. In addition to fixing the issue, add `-Werror=constant-conversion`, and clang diagnostic that catches such issues. Fixes: 1a5514e5cf4062 ("module-vban: create streams per stream_name") --- meson.build | 1 + src/modules/module-vban/stream.c | 2 +- src/modules/module-vban/vban.h | 63 +++++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index d6a0364e8..1f57cc568 100644 --- a/meson.build +++ b/meson.build @@ -101,6 +101,7 @@ common_flags = [ '-Wunused-result', '-Werror=return-type', '-Werror=float-conversion', + '-Werror=constant-conversion', ] cc_flags = common_flags + [ diff --git a/src/modules/module-vban/stream.c b/src/modules/module-vban/stream.c index 93bc4a597..efa5af370 100644 --- a/src/modules/module-vban/stream.c +++ b/src/modules/module-vban/stream.c @@ -313,7 +313,7 @@ struct vban_stream *vban_stream_new(struct pw_core *core, if (impl->rate == 0) impl->rate = 10000; - impl->header.format_SR = VBAN_PROTOCOL_SERIAL | vban_BPSList[14]; /* 115200 */ + impl->header.format_SR = VBAN_PROTOCOL_SERIAL | VBAN_BPS_115200; impl->header.format_nbs = 0; impl->header.format_nbc = 0; impl->header.format_bit = impl->format_info->format_bit; diff --git a/src/modules/module-vban/vban.h b/src/modules/module-vban/vban.h index 7557de23f..efcfaf405 100644 --- a/src/modules/module-vban/vban.h +++ b/src/modules/module-vban/vban.h @@ -5,6 +5,10 @@ #ifndef PIPEWIRE_VBAN_H #define PIPEWIRE_VBAN_H +#include + +#include + #ifdef __cplusplus extern "C" { #endif @@ -70,14 +74,61 @@ static inline uint8_t vban_sr_index(uint32_t rate) #define VBAN_CODEC_UNDEFINED_12 0xE0 #define VBAN_CODEC_USER 0xF0 -#define VBAN_BPS_MAXNUMBER 25 +#define VBAN_BPS_0 0 +#define VBAN_BPS_110 1 +#define VBAN_BPS_150 2 +#define VBAN_BPS_300 3 +#define VBAN_BPS_600 4 +#define VBAN_BPS_1200 5 +#define VBAN_BPS_2400 6 +#define VBAN_BPS_4800 7 +#define VBAN_BPS_9600 8 +#define VBAN_BPS_14400 9 +#define VBAN_BPS_19200 10 +#define VBAN_BPS_31250 11 +#define VBAN_BPS_38400 12 +#define VBAN_BPS_57600 13 +#define VBAN_BPS_115200 14 +#define VBAN_BPS_128000 15 +#define VBAN_BPS_230400 16 +#define VBAN_BPS_250000 17 +#define VBAN_BPS_256000 18 +#define VBAN_BPS_460800 19 +#define VBAN_BPS_921600 20 +#define VBAN_BPS_1000000 21 +#define VBAN_BPS_1500000 22 +#define VBAN_BPS_2000000 23 +#define VBAN_BPS_3000000 24 +#define VBAN_BPS_MAXNUMBER 25 -static const long vban_BPSList[32] = { - 0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, - 14400, 19200, 31250, 38400, 57600, 115200, 128000, - 230400, 250000, 256000, 460800, 921600, 1000000, - 1500000, 2000000, 3000000 +static const int vban_BPSList[] = { + [VBAN_BPS_0] = 0, + [VBAN_BPS_110] = 110, + [VBAN_BPS_150] = 150, + [VBAN_BPS_300] = 300, + [VBAN_BPS_600] = 600, + [VBAN_BPS_1200] = 1200, + [VBAN_BPS_2400] = 2400, + [VBAN_BPS_4800] = 4800, + [VBAN_BPS_9600] = 9600, + [VBAN_BPS_14400] = 14400, + [VBAN_BPS_19200] = 19200, + [VBAN_BPS_31250] = 31250, + [VBAN_BPS_38400] = 38400, + [VBAN_BPS_57600] = 57600, + [VBAN_BPS_115200] = 115200, + [VBAN_BPS_128000] = 128000, + [VBAN_BPS_230400] = 230400, + [VBAN_BPS_250000] = 250000, + [VBAN_BPS_256000] = 256000, + [VBAN_BPS_460800] = 460800, + [VBAN_BPS_921600] = 921600, + [VBAN_BPS_1000000] = 1000000, + [VBAN_BPS_1500000] = 1500000, + [VBAN_BPS_2000000] = 2000000, + [VBAN_BPS_3000000] = 3000000, }; +SPA_STATIC_ASSERT(SPA_N_ELEMENTS(vban_BPSList) == VBAN_BPS_MAXNUMBER); #define VBAN_SERIAL_GENERIC 0x00 #define VBAN_SERIAL_MIDI 0x10