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: 1a5514e5cf ("module-vban: create streams per stream_name")
This commit is contained in:
Barnabás Pőcze 2024-12-14 22:43:25 +01:00
parent a4e2d9cbb0
commit 705c2a652b
3 changed files with 59 additions and 7 deletions

View file

@ -101,6 +101,7 @@ common_flags = [
'-Wunused-result',
'-Werror=return-type',
'-Werror=float-conversion',
'-Werror=constant-conversion',
]
cc_flags = common_flags + [

View file

@ -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;

View file

@ -5,6 +5,10 @@
#ifndef PIPEWIRE_VBAN_H
#define PIPEWIRE_VBAN_H
#include <stdint.h>
#include <spa/utils/defs.h>
#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