module-vban: create streams per stream_name

Always listen on the receive socket. Find the stream with the given
stream_name of the packet and create it if it doesn't exist.

Also take the sample-rate, channels and format from the packet
parameters instead of the config.

Fixes #4400
This commit is contained in:
Wim Taymans 2024-11-13 16:47:34 +01:00
parent 567b484386
commit 1a5514e5cf
6 changed files with 284 additions and 153 deletions

View file

@ -92,12 +92,7 @@ static int vban_audio_receive(struct impl *impl, uint8_t *buffer, ssize_t len)
uint32_t stride = impl->stride;
int32_t filled;
if (len < VBAN_HEADER_SIZE)
goto short_packet;
hdr = (struct vban_header*)buffer;
if (strncmp(hdr->vban, "VBAN", 3))
goto invalid_version;
impl->receiving = true;
@ -155,14 +150,6 @@ static int vban_audio_receive(struct impl *impl, uint8_t *buffer, ssize_t len)
spa_ringbuffer_write_update(&impl->ring, write);
}
return 0;
short_packet:
pw_log_warn("short packet received");
return -EINVAL;
invalid_version:
pw_log_warn("invalid VBAN version");
spa_debug_log_mem(pw_log_get(), SPA_LOG_LEVEL_INFO, 0, buffer, len);
return -EPROTO;
}
static inline void

View file

@ -201,13 +201,7 @@ static int vban_midi_receive(struct impl *impl, uint8_t *buffer, ssize_t len)
ssize_t hlen;
uint32_t n_frames;
if (len < VBAN_HEADER_SIZE)
goto short_packet;
hdr = (struct vban_header*)buffer;
if (strncmp(hdr->vban, "VBAN", 3))
goto invalid_version;
hlen = VBAN_HEADER_SIZE;
n_frames = hdr->n_frames;
@ -221,14 +215,6 @@ static int vban_midi_receive(struct impl *impl, uint8_t *buffer, ssize_t len)
impl->receiving = true;
return vban_midi_receive_midi(impl, buffer, hlen, len);
short_packet:
pw_log_warn("short packet received");
return -EINVAL;
invalid_version:
pw_log_warn("invalid RTP version");
spa_debug_log_mem(pw_log_get(), SPA_LOG_LEVEL_INFO, 0, buffer, len);
return -EPROTO;
}
static void vban_midi_flush_packets(struct impl *impl,

View file

@ -94,13 +94,13 @@ struct format_info {
};
static const struct format_info audio_format_info[] = {
{ SPA_MEDIA_SUBTYPE_raw, SPA_AUDIO_FORMAT_U8, 1, VBAN_DATATYPE_U8, },
{ SPA_MEDIA_SUBTYPE_raw, SPA_AUDIO_FORMAT_U8, 1, VBAN_DATATYPE_BYTE8, },
{ SPA_MEDIA_SUBTYPE_raw, SPA_AUDIO_FORMAT_S16_LE, 2, VBAN_DATATYPE_INT16, },
{ SPA_MEDIA_SUBTYPE_raw, SPA_AUDIO_FORMAT_S24_LE, 3, VBAN_DATATYPE_INT24, },
{ SPA_MEDIA_SUBTYPE_raw, SPA_AUDIO_FORMAT_S32_LE, 4, VBAN_DATATYPE_INT32, },
{ SPA_MEDIA_SUBTYPE_raw, SPA_AUDIO_FORMAT_F32_LE, 4, VBAN_DATATYPE_FLOAT32, },
{ SPA_MEDIA_SUBTYPE_raw, SPA_AUDIO_FORMAT_F64_LE, 8, VBAN_DATATYPE_FLOAT64, },
{ SPA_MEDIA_SUBTYPE_control, 0, 1, VBAN_SERIAL_MIDI | VBAN_DATATYPE_U8, },
{ SPA_MEDIA_SUBTYPE_control, 0, 1, VBAN_SERIAL_MIDI | VBAN_DATATYPE_BYTE8, },
};
static void stream_io_changed(void *data, uint32_t id, void *area, uint32_t size)
@ -290,7 +290,7 @@ struct vban_stream *vban_stream_new(struct pw_core *core,
if (impl->rate == 0)
impl->rate = 10000;
impl->header.format_SR = (0x1 << 5) | 14; /* 115200 */
impl->header.format_SR = VBAN_PROTOCOL_SERIAL | vban_BPSList[14]; /* 115200 */
impl->header.format_nbs = 0;
impl->header.format_nbc = 0;
impl->header.format_bit = impl->format_info->format_bit;

View file

@ -17,21 +17,30 @@ extern "C" {
#define VBAN_SAMPLES_MAX_NB 256
struct vban_header {
char vban[4]; /* contains 'V' 'B', 'A', 'N' */
uint8_t format_SR; /* SR index */
uint8_t format_nbs; /* nb sample per frame (1 to 256) */
uint8_t format_nbc; /* nb channel (1 to 256) */
uint8_t format_bit; /* bit format */
char vban[4]; /* contains 'V' 'B', 'A', 'N' */
uint8_t format_SR; /* SR index */
uint8_t format_nbs; /* nb sample per frame (1 to 256) */
uint8_t format_nbc; /* nb channel (1 to 256) */
uint8_t format_bit; /* bit format */
char stream_name[VBAN_STREAM_NAME_SIZE]; /* stream name */
uint32_t n_frames; /* growing frame number. */
uint32_t n_frames; /* growing frame number. */
} __attribute__ ((packed));
#define VBAN_PROTOCOL_AUDIO 0x00
#define VBAN_PROTOCOL_SERIAL 0x20
#define VBAN_PROTOCOL_TXT 0x40
#define VBAN_PROTOCOL_SERVICE 0x60
#define VBAN_PROTOCOL_UNDEFINED_1 0x80
#define VBAN_PROTOCOL_UNDEFINED_2 0xA0
#define VBAN_PROTOCOL_UNDEFINED_3 0xC0
#define VBAN_PROTOCOL_USER 0xE0
#define VBAN_SR_MAXNUMBER 21
static uint32_t const vban_SR[VBAN_SR_MAXNUMBER] = {
6000, 12000, 24000, 48000, 96000, 192000, 384000,
8000, 16000, 32000, 64000, 128000, 256000, 512000,
11025, 22050, 44100, 88200, 176400, 352800, 705600
static uint32_t const vban_SR[32] = {
6000, 12000, 24000, 48000, 96000, 192000, 384000,
8000, 16000, 32000, 64000, 128000, 256000, 512000,
11025, 22050, 44100, 88200, 176400, 352800, 705600
};
static inline uint8_t vban_sr_index(uint32_t rate)
@ -44,7 +53,37 @@ static inline uint8_t vban_sr_index(uint32_t rate)
return VBAN_SR_MAXNUMBER;
}
#define VBAN_DATATYPE_U8 0x00
#define VBAN_CODEC_PCM 0x00
#define VBAN_CODEC_VBCA 0x10 //VB-AUDIO AOIP CODEC
#define VBAN_CODEC_VBCV 0x20 //VB-AUDIO VOIP CODEC
#define VBAN_CODEC_UNDEFINED_1 0x30
#define VBAN_CODEC_UNDEFINED_2 0x40
#define VBAN_CODEC_UNDEFINED_3 0x50
#define VBAN_CODEC_UNDEFINED_4 0x60
#define VBAN_CODEC_UNDEFINED_5 0x70
#define VBAN_CODEC_UNDEFINED_6 0x80
#define VBAN_CODEC_UNDEFINED_7 0x90
#define VBAN_CODEC_UNDEFINED_8 0xA0
#define VBAN_CODEC_UNDEFINED_9 0xB0
#define VBAN_CODEC_UNDEFINED_10 0xC0
#define VBAN_CODEC_UNDEFINED_11 0xD0
#define VBAN_CODEC_UNDEFINED_12 0xE0
#define VBAN_CODEC_USER 0xF0
#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
};
#define VBAN_SERIAL_GENERIC 0x00
#define VBAN_SERIAL_MIDI 0x10
#define VBAN_SERIAL_USER 0xf0
#define VBAN_DATATYPE_BYTE8 0x00
#define VBAN_DATATYPE_INT16 0x01
#define VBAN_DATATYPE_INT24 0x02
#define VBAN_DATATYPE_INT32 0x03
@ -53,10 +92,6 @@ static inline uint8_t vban_sr_index(uint32_t rate)
#define VBAN_DATATYPE_12BITS 0x06
#define VBAN_DATATYPE_10BITS 0x07
#define VBAN_SERIAL_GENERIC 0x00
#define VBAN_SERIAL_MIDI 0x10
#define VBAN_SERIAL_USER 0xf0
#ifdef __cplusplus
}
#endif