From 2fa97daa24cac839ac23783450a06bc6bb8876dd Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 24 Oct 2019 12:35:00 +0200 Subject: [PATCH] add some constants for max samples --- spa/plugins/alsa/alsa-pcm-sink.c | 4 ++-- spa/plugins/alsa/alsa-pcm-source.c | 4 ++-- spa/plugins/alsa/alsa-pcm.h | 3 +++ spa/plugins/audioconvert/channelmix.c | 5 +++-- spa/plugins/audioconvert/fmtconvert.c | 8 +++++--- spa/plugins/audioconvert/merger.c | 11 ++++++----- spa/plugins/audioconvert/resample.c | 5 +++-- spa/plugins/audioconvert/splitter.c | 13 +++++++------ 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm-sink.c b/spa/plugins/alsa/alsa-pcm-sink.c index b0f6a012f..dc77b1609 100644 --- a/spa/plugins/alsa/alsa-pcm-sink.c +++ b/spa/plugins/alsa/alsa-pcm-sink.c @@ -42,8 +42,8 @@ #define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) == 0) static const char default_device[] = "hw:0"; -static const uint32_t default_min_latency = 16; -static const uint32_t default_max_latency = 1024; +static const uint32_t default_min_latency = MIN_LATENCY; +static const uint32_t default_max_latency = MAX_LATENCY; static void reset_props(struct props *props) { diff --git a/spa/plugins/alsa/alsa-pcm-source.c b/spa/plugins/alsa/alsa-pcm-source.c index 07726b114..cf71cf6e7 100644 --- a/spa/plugins/alsa/alsa-pcm-source.c +++ b/spa/plugins/alsa/alsa-pcm-source.c @@ -42,8 +42,8 @@ #define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0) static const char default_device[] = "hw:0"; -static const uint32_t default_min_latency = 64; -static const uint32_t default_max_latency = 1024; +static const uint32_t default_min_latency = MIN_LATENCY; +static const uint32_t default_max_latency = MAX_LATENCY; static void reset_props(struct props *props) { diff --git a/spa/plugins/alsa/alsa-pcm.h b/spa/plugins/alsa/alsa-pcm.h index 987e005e3..180639830 100644 --- a/spa/plugins/alsa/alsa-pcm.h +++ b/spa/plugins/alsa/alsa-pcm.h @@ -44,6 +44,9 @@ extern "C" { #include #include +#define MIN_LATENCY 16 +#define MAX_LATENCY 1024 + #define DEFAULT_RATE 48000u #define DEFAULT_CHANNELS 2u diff --git a/spa/plugins/audioconvert/channelmix.c b/spa/plugins/audioconvert/channelmix.c index 9db8a3635..d590979e4 100644 --- a/spa/plugins/audioconvert/channelmix.c +++ b/spa/plugins/audioconvert/channelmix.c @@ -45,6 +45,7 @@ #define DEFAULT_RATE 44100 #define DEFAULT_CHANNELS 2 +#define MAX_SAMPLES 1024 #define MAX_BUFFERS 32 #define MAX_DATAS 32 @@ -569,7 +570,7 @@ impl_node_port_enum_params(void *object, int seq, size = other->size / other->stride; } else { buffers = 1; - size = port->format.info.raw.rate * 1024 / DEFAULT_RATE; + size = MAX_SAMPLES; } param = spa_pod_builder_add_object(&b, @@ -579,7 +580,7 @@ impl_node_port_enum_params(void *object, int seq, SPA_PARAM_BUFFERS_size, SPA_POD_CHOICE_RANGE_Int( size * port->stride, 16 * port->stride, - INT32_MAX / port->stride), + INT32_MAX), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->stride), SPA_PARAM_BUFFERS_align, SPA_POD_Int(16)); break; diff --git a/spa/plugins/audioconvert/fmtconvert.c b/spa/plugins/audioconvert/fmtconvert.c index 078900f7a..7e6fa6167 100644 --- a/spa/plugins/audioconvert/fmtconvert.c +++ b/spa/plugins/audioconvert/fmtconvert.c @@ -47,7 +47,9 @@ #define DEFAULT_RATE 48000 #define DEFAULT_CHANNELS 2 +#define MAX_SAMPLES 1024 #define MAX_BUFFERS 64 +#define MAX_ALIGN 16 #define MAX_DATAS 32 #define MAX_PORTS 128 @@ -473,9 +475,9 @@ impl_node_port_enum_params(void *object, int seq, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(port->blocks), SPA_PARAM_BUFFERS_size, SPA_POD_CHOICE_RANGE_Int( - 2048 * port->stride, + MAX_SAMPLES * 2 * port->stride, 16 * port->stride, - INT32_MAX / port->stride), + INT32_MAX), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->stride), SPA_PARAM_BUFFERS_align, SPA_POD_Int(16)); } @@ -698,7 +700,7 @@ impl_node_port_use_buffers(void *object, this, j, i); return -EINVAL; } - if (!SPA_IS_ALIGNED(d[j].data, 16)) { + if (!SPA_IS_ALIGNED(d[j].data, MAX_ALIGN)) { spa_log_warn(this->log, NAME " %p: memory %d on buffer %d not aligned", this, j, i); } diff --git a/spa/plugins/audioconvert/merger.c b/spa/plugins/audioconvert/merger.c index 8a181e1bc..f3f8d98af 100644 --- a/spa/plugins/audioconvert/merger.c +++ b/spa/plugins/audioconvert/merger.c @@ -48,7 +48,8 @@ #define DEFAULT_RATE 48000 #define DEFAULT_CHANNELS 2 -#define MAX_SAMPLES 2048 +#define MAX_SAMPLES 1024 +#define MAX_ALIGN 16 #define MAX_BUFFERS 64 #define MAX_DATAS 32 #define MAX_PORTS 128 @@ -110,7 +111,7 @@ struct impl { unsigned int monitor:1; unsigned int have_profile:1; - float empty[MAX_SAMPLES + 15]; + float empty[MAX_SAMPLES*2 + MAX_ALIGN]; }; #define CHECK_IN_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) < this->port_count) @@ -490,7 +491,7 @@ impl_node_port_enum_params(void *object, int seq, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(port->blocks), SPA_PARAM_BUFFERS_size, SPA_POD_CHOICE_RANGE_Int( - 1024 * port->stride, + MAX_SAMPLES * port->stride, 16 * port->stride, MAX_SAMPLES * port->stride), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->stride), @@ -793,7 +794,7 @@ impl_node_port_use_buffers(void *object, this, j, i, d[j].type, d[j].data); return -EINVAL; } - if (!SPA_IS_ALIGNED(d[j].data, 16)) { + if (!SPA_IS_ALIGNED(d[j].data, MAX_ALIGN)) { spa_log_warn(this->log, NAME " %p: memory %d on buffer %d not aligned", this, j, i); } @@ -962,7 +963,7 @@ static int impl_node_process(void *object) struct port *inport = GET_IN_PORT(this, i); if (get_in_buffer(this, inport, &sbuf) < 0) { - src_datas[n_src_datas++] = SPA_PTR_ALIGN(this->empty, 16, void); + src_datas[n_src_datas++] = SPA_PTR_ALIGN(this->empty, MAX_ALIGN, void); continue; } diff --git a/spa/plugins/audioconvert/resample.c b/spa/plugins/audioconvert/resample.c index 113f829cc..d8ad14f06 100644 --- a/spa/plugins/audioconvert/resample.c +++ b/spa/plugins/audioconvert/resample.c @@ -47,6 +47,7 @@ #define DEFAULT_RATE 44100 #define DEFAULT_CHANNELS 2 +#define MAX_SAMPLES 1024 #define MAX_BUFFERS 32 struct impl; @@ -425,7 +426,7 @@ impl_node_port_enum_params(void *object, int seq, } else { buffers = 1; - size = 2048 * other->stride; + size = MAX_SAMPLES * 2 * other->stride; } param = spa_pod_builder_add_object(&b, @@ -755,7 +756,7 @@ static int impl_node_process(void *object) if (this->io_position) { max = this->io_position->clock.duration; } else { - max = 1024; + max = maxsize / sizeof(float); } switch (this->mode) { diff --git a/spa/plugins/audioconvert/splitter.c b/spa/plugins/audioconvert/splitter.c index 10d83eed6..cd4d715df 100644 --- a/spa/plugins/audioconvert/splitter.c +++ b/spa/plugins/audioconvert/splitter.c @@ -49,7 +49,8 @@ #define DEFAULT_CHANNELS 2 #define DEFAULT_MASK (1LL << SPA_AUDIO_CHANNEL_FL) | (1LL << SPA_AUDIO_CHANNEL_FR) -#define MAX_SAMPLES 2048 +#define MAX_SAMPLES 1024 +#define MAX_ALIGN 16 #define MAX_BUFFERS 64 #define MAX_DATAS 32 #define MAX_PORTS 128 @@ -112,7 +113,7 @@ struct impl { bool have_profile; - float empty[MAX_SAMPLES + 15]; + float empty[MAX_SAMPLES*2 + MAX_ALIGN]; }; #define CHECK_OUT_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < this->port_count) @@ -473,7 +474,7 @@ impl_node_port_enum_params(void *object, int seq, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(port->blocks), SPA_PARAM_BUFFERS_size, SPA_POD_CHOICE_RANGE_Int( - 1024 * port->stride, + MAX_SAMPLES * port->stride, 16 * port->stride, MAX_SAMPLES * port->stride), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->stride), @@ -751,7 +752,7 @@ impl_node_port_use_buffers(void *object, this, j, i, d[j].type, d[j].data); return -EINVAL; } - if (!SPA_IS_ALIGNED(d[j].data, 16)) { + if (!SPA_IS_ALIGNED(d[j].data, MAX_ALIGN)) { spa_log_warn(this->log, NAME " %p: memory %d on buffer %d not aligned", this, j, i); } @@ -878,7 +879,7 @@ static int impl_node_process(void *object) outio->status = -EPIPE; empty: spa_log_trace_fp(this->log, NAME" %p: %d skip output", this, i); - dst_datas[n_dst_datas++] = SPA_PTR_ALIGN(this->empty, 16, void); + dst_datas[n_dst_datas++] = SPA_PTR_ALIGN(this->empty, MAX_ALIGN, void); continue; } @@ -902,7 +903,7 @@ static int impl_node_process(void *object) } while (n_dst_datas < this->port_count) { spa_log_trace_fp(this->log, NAME" %p: %d fill output", this, n_dst_datas); - dst_datas[n_dst_datas++] = SPA_PTR_ALIGN(this->empty, 16, void); + dst_datas[n_dst_datas++] = SPA_PTR_ALIGN(this->empty, MAX_ALIGN, void); } spa_log_trace_fp(this->log, NAME " %p: n_src:%d n_dst:%d n_samples:%d max:%d stride:%d p:%d", this,