Don't use SPA_AUDIO_MAX_CHANNELS directly

Make a MAX_CHANNELS define and use that one in code. This makes it
easier to change the constant later.
This commit is contained in:
Wim Taymans 2025-10-20 15:33:17 +02:00
parent eb096bfb62
commit 13b8c23767
30 changed files with 136 additions and 108 deletions

View file

@ -231,9 +231,9 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
"( stream.props=<properties> ) " \
"( stream.rules=<properties> ) "
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define DELAYBUF_MAX_SIZE (20 * sizeof(float) * 96000)
static const struct spa_dict_item module_props[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
{ PW_KEY_MODULE_DESCRIPTION, "Combine multiple streams into a single stream" },
@ -312,10 +312,10 @@ struct stream {
struct spa_latency_info latency;
struct spa_audio_info_raw info;
uint32_t remap[SPA_AUDIO_MAX_CHANNELS];
uint32_t remap[MAX_CHANNELS];
void *delaybuf;
struct ringbuffer delay[SPA_AUDIO_MAX_CHANNELS];
struct ringbuffer delay[MAX_CHANNELS];
int64_t delay_samples; /* for main loop */
int64_t data_delay_samples; /* for data loop */
@ -509,7 +509,7 @@ static void update_latency(struct impl *impl)
struct replace_delay_info {
struct stream *stream;
void *buf;
struct ringbuffer delay[SPA_AUDIO_MAX_CHANNELS];
struct ringbuffer delay[MAX_CHANNELS];
};
static int do_replace_delay(struct spa_loop *loop, bool async, uint32_t seq,
@ -1228,7 +1228,7 @@ static void combine_output_process(void *d)
struct pw_buffer *in, *out;
struct stream *s;
bool delay_changed = false;
bool mix[SPA_AUDIO_MAX_CHANNELS];
bool mix[MAX_CHANNELS];
if ((out = pw_stream_dequeue_buffer(impl->combine)) == NULL) {
pw_log_debug("%p: out of output buffers: %m", impl);

View file

@ -154,6 +154,7 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define DEFAULT_RATE 48000
#define DEFAULT_POSITION "[ FL FR ]"
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
/* Hopefully this is enough for any combination of AEC engine and resampler
* input requirement for rate matching */
@ -203,7 +204,7 @@ struct impl {
struct spa_hook source_listener;
struct spa_audio_info_raw source_info;
void *rec_buffer[SPA_AUDIO_MAX_CHANNELS];
void *rec_buffer[MAX_CHANNELS];
uint32_t rec_ringsize;
struct spa_ringbuffer rec_ring;
@ -215,13 +216,13 @@ struct impl {
struct pw_properties *sink_props;
struct pw_stream *sink;
struct spa_hook sink_listener;
void *play_buffer[SPA_AUDIO_MAX_CHANNELS];
void *play_buffer[MAX_CHANNELS];
uint32_t play_ringsize;
struct spa_ringbuffer play_ring;
struct spa_ringbuffer play_delayed_ring;
struct spa_audio_info_raw sink_info;
void *out_buffer[SPA_AUDIO_MAX_CHANNELS];
void *out_buffer[MAX_CHANNELS];
uint32_t out_ringsize;
struct spa_ringbuffer out_ring;

View file

@ -112,6 +112,7 @@
PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define PW_LOG_TOPIC_DEFAULT mod_topic
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define MAX_PORTS 128
#define FFADO_RT_PRIORITY_PACKETIZER_RELATIVE 5
@ -179,7 +180,7 @@ struct port {
struct volume {
bool mute;
uint32_t n_volumes;
float volumes[SPA_AUDIO_MAX_CHANNELS];
float volumes[MAX_CHANNELS];
};
struct stream {
@ -760,7 +761,7 @@ static int make_stream_ports(struct stream *s)
struct port *port = s->ports[i];
char channel[32];
snprintf(channel, sizeof(channel), "AUX%u", n_channels % SPA_AUDIO_MAX_CHANNELS);
snprintf(channel, sizeof(channel), "AUX%u", n_channels % MAX_CHANNELS);
switch (port->stream_type) {
case ffado_stream_type_audio:
@ -873,7 +874,7 @@ static void parse_props(struct stream *s, const struct spa_pod *param)
case SPA_PROP_channelVolumes:
{
uint32_t n;
float vols[SPA_AUDIO_MAX_CHANNELS];
float vols[MAX_CHANNELS];
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
s->volume.n_volumes = n;
@ -1228,7 +1229,7 @@ static int probe_ffado_device(struct impl *impl)
}
if (impl->source.info.channels != n_channels) {
impl->source.info.channels = n_channels;
for (i = 0; i < SPA_MIN(impl->source.info.channels, SPA_AUDIO_MAX_CHANNELS); i++)
for (i = 0; i < SPA_MIN(impl->source.info.channels, MAX_CHANNELS); i++)
impl->source.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
}
@ -1254,7 +1255,7 @@ static int probe_ffado_device(struct impl *impl)
}
if (impl->sink.info.channels != n_channels) {
impl->sink.info.channels = n_channels;
for (i = 0; i < SPA_MIN(impl->sink.info.channels, SPA_AUDIO_MAX_CHANNELS); i++)
for (i = 0; i < SPA_MIN(impl->sink.info.channels, MAX_CHANNELS); i++)
impl->sink.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
}

View file

@ -115,6 +115,7 @@
PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define PW_LOG_TOPIC_DEFAULT mod_topic
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define MAX_PORTS 128
#define DEFAULT_CLIENT_NAME "PipeWire"
@ -157,7 +158,7 @@ struct port {
struct volume {
bool mute;
uint32_t n_volumes;
float volumes[SPA_AUDIO_MAX_CHANNELS];
float volumes[MAX_CHANNELS];
};
struct stream {
@ -624,7 +625,7 @@ static void parse_props(struct stream *s, const struct spa_pod *param)
case SPA_PROP_channelVolumes:
{
uint32_t n;
float vols[SPA_AUDIO_MAX_CHANNELS];
float vols[MAX_CHANNELS];
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
s->volume.n_volumes = n;

View file

@ -512,7 +512,7 @@ static void parse_props(struct stream *s, const struct spa_pod *param)
case SPA_PROP_channelVolumes:
{
uint32_t n;
float vols[SPA_AUDIO_MAX_CHANNELS];
float vols[MAX_CHANNELS];
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
s->volume.n_volumes = n;

View file

@ -677,7 +677,7 @@ static void parse_props(struct stream *s, const struct spa_pod *param)
case SPA_PROP_channelVolumes:
{
uint32_t n;
float vols[SPA_AUDIO_MAX_CHANNELS];
float vols[MAX_CHANNELS];
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
s->volume.n_volumes = n;

View file

@ -7,10 +7,12 @@
#include <opus/opus_custom.h>
#endif
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
struct volume {
bool mute;
uint32_t n_volumes;
float volumes[SPA_AUDIO_MAX_CHANNELS];
float volumes[MAX_CHANNELS];
};
static inline float bswap_f32(float f)

View file

@ -12,6 +12,8 @@
#include "format.h"
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
static const struct format audio_formats[] = {
[SAMPLE_U8] = { SAMPLE_U8, SPA_AUDIO_FORMAT_U8, "u8", 1 },
[SAMPLE_ALAW] = { SAMPLE_ALAW, SPA_AUDIO_FORMAT_ALAW, "alaw", 1 },

View file

@ -117,6 +117,8 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define DEFAULT_CHANNELS 2
#define DEFAULT_POSITION "[ FL FR ]"
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define MODULE_USAGE "( remote.name=<remote> ] " \
"( node.latency=<latency as fraction> ] " \
"( node.name=<name of the nodes> ] " \
@ -295,7 +297,7 @@ static void stream_param_changed(void *d, uint32_t id, const struct spa_pod *par
{
struct pa_cvolume volume;
uint32_t n;
float vols[SPA_AUDIO_MAX_CHANNELS];
float vols[MAX_CHANNELS];
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
@ -832,10 +834,10 @@ do_stream_sync_volumes(struct spa_loop *loop,
struct spa_pod_frame f[1];
struct spa_pod *param;
uint32_t i, channels;
float vols[SPA_AUDIO_MAX_CHANNELS];
float soft_vols[SPA_AUDIO_MAX_CHANNELS];
float vols[MAX_CHANNELS];
float soft_vols[MAX_CHANNELS];
channels = SPA_MIN(impl->volume.channels, SPA_AUDIO_MAX_CHANNELS);
channels = SPA_MIN(impl->volume.channels, MAX_CHANNELS);
for (i = 0; i < channels; i++) {
vols[i] = (float)pa_sw_volume_to_linear(impl->volume.values[i]);
soft_vols[i] = 1.0f;

View file

@ -158,6 +158,7 @@ PW_LOG_TOPIC(mod_topic, "mod." NAME);
#define RAOP_LATENCY_MS 250
#define DEFAULT_LATENCY_MS 1500
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define VOLUME_MAX 0.0
#define VOLUME_MIN -30.0
#define VOLUME_MUTE -144.0
@ -1612,8 +1613,8 @@ static void stream_props_changed(struct impl *impl, uint32_t id, const struct sp
case SPA_PROP_channelVolumes:
{
uint32_t i, n_vols;
float vols[SPA_AUDIO_MAX_CHANNELS], volume;
float soft_vols[SPA_AUDIO_MAX_CHANNELS];
float vols[MAX_CHANNELS], volume;
float soft_vols[MAX_CHANNELS];
if ((n_vols = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {

View file

@ -156,6 +156,7 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define DEFAULT_LOOP false
#define MAX_SDP 2048
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define USAGE "( local.ifname=<local interface name to use> ) " \
"( sap.ip=<SAP IP address to send announce, default:"DEFAULT_SAP_IP"> ) " \
@ -1404,7 +1405,7 @@ static int parse_sdp_i(struct impl *impl, char *c, struct sdp_info *info)
c[strcspn(c, " ")] = '\0';
uint32_t channels;
if (sscanf(c, "%u", &channels) != 1 || channels <= 0 || channels > SPA_AUDIO_MAX_CHANNELS)
if (sscanf(c, "%u", &channels) != 1 || channels <= 0 || channels > MAX_CHANNELS)
return 0;
c += strcspn(c, "\0");

View file

@ -70,6 +70,8 @@
#define DEFAULT_VOLUME 1.0
#define DEFAULT_QUALITY 4
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
enum mode {
mode_none,
mode_playback,
@ -91,7 +93,7 @@ typedef int (*fill_fn)(struct data *d, void *dest, unsigned int n_frames, bool *
struct channelmap {
uint32_t n_channels;
uint32_t channels[SPA_AUDIO_MAX_CHANNELS];
uint32_t channels[MAX_CHANNELS];
};
struct data {