mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
spa: add macro to simplify array iterations some more
uint32_t i; for (i = 0; i < SPA_N_ELEMENTS(some_array); i++) .. stuff with some_array[i].foo ... becomes: SPA_FOR_EACH_ELEMENT_VAR(some_array, p) .. stuff with p->foo ..
This commit is contained in:
parent
365ebcda9b
commit
d22feab92a
21 changed files with 113 additions and 150 deletions
|
|
@ -241,16 +241,15 @@ static void set_volume(struct impl *this);
|
|||
static void emit_node_info(struct impl *this, bool full)
|
||||
{
|
||||
uint64_t old = full ? this->info.change_mask : 0;
|
||||
uint32_t i;
|
||||
|
||||
if (full)
|
||||
this->info.change_mask = this->info_all;
|
||||
if (this->info.change_mask) {
|
||||
if (this->info.change_mask & SPA_NODE_CHANGE_MASK_PARAMS) {
|
||||
for (i = 0; i < SPA_N_ELEMENTS(this->params); i++) {
|
||||
if (this->params[i].user > 0) {
|
||||
this->params[i].flags ^= SPA_PARAM_INFO_SERIAL;
|
||||
this->params[i].user = 0;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(this->params, p) {
|
||||
if (p->user > 0) {
|
||||
p->flags ^= SPA_PARAM_INFO_SERIAL;
|
||||
p->user = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -262,7 +261,6 @@ static void emit_node_info(struct impl *this, bool full)
|
|||
static void emit_port_info(struct impl *this, struct port *port, bool full)
|
||||
{
|
||||
uint64_t old = full ? port->info.change_mask : 0;
|
||||
uint32_t i;
|
||||
|
||||
if (full)
|
||||
port->info.change_mask = port->info_all;
|
||||
|
|
@ -282,10 +280,10 @@ static void emit_port_info(struct impl *this, struct port *port, bool full)
|
|||
port->info.props = &SPA_DICT_INIT(items, n_items);
|
||||
|
||||
if (port->info.change_mask & SPA_PORT_CHANGE_MASK_PARAMS) {
|
||||
for (i = 0; i < SPA_N_ELEMENTS(port->params); i++) {
|
||||
if (port->params[i].user > 0) {
|
||||
port->params[i].flags ^= SPA_PARAM_INFO_SERIAL;
|
||||
port->params[i].user = 0;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(port->params, p) {
|
||||
if (p->user > 0) {
|
||||
p->flags ^= SPA_PARAM_INFO_SERIAL;
|
||||
p->user = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -432,7 +430,6 @@ static int impl_node_enum_params(void *object, int seq,
|
|||
{
|
||||
struct props *p = &this->props;
|
||||
struct spa_pod_frame f[2];
|
||||
uint32_t i;
|
||||
|
||||
switch (result.index) {
|
||||
case 0:
|
||||
|
|
@ -596,9 +593,9 @@ static int impl_node_enum_params(void *object, int seq,
|
|||
|
||||
spa_pod_builder_prop(&b, SPA_PROP_INFO_labels, 0);
|
||||
spa_pod_builder_push_struct(&b, &f[1]);
|
||||
for (i = 0; i < SPA_N_ELEMENTS(channelmix_upmix_info); i++) {
|
||||
spa_pod_builder_string(&b, channelmix_upmix_info[i].label);
|
||||
spa_pod_builder_string(&b, channelmix_upmix_info[i].description);
|
||||
SPA_FOR_EACH_ELEMENT_VAR(channelmix_upmix_info, i) {
|
||||
spa_pod_builder_string(&b, i->label);
|
||||
spa_pod_builder_string(&b, i->description);
|
||||
}
|
||||
spa_pod_builder_pop(&b, &f[1]);
|
||||
param = spa_pod_builder_pop(&b, &f[0]);
|
||||
|
|
@ -646,9 +643,9 @@ static int impl_node_enum_params(void *object, int seq,
|
|||
0);
|
||||
spa_pod_builder_prop(&b, SPA_PROP_INFO_labels, 0);
|
||||
spa_pod_builder_push_struct(&b, &f[1]);
|
||||
for (i = 0; i < SPA_N_ELEMENTS(dither_method_info); i++) {
|
||||
spa_pod_builder_string(&b, dither_method_info[i].label);
|
||||
spa_pod_builder_string(&b, dither_method_info[i].description);
|
||||
SPA_FOR_EACH_ELEMENT_VAR(dither_method_info, i) {
|
||||
spa_pod_builder_string(&b, i->label);
|
||||
spa_pod_builder_string(&b, i->description);
|
||||
}
|
||||
spa_pod_builder_pop(&b, &f[1]);
|
||||
param = spa_pod_builder_pop(&b, &f[0]);
|
||||
|
|
|
|||
|
|
@ -105,21 +105,17 @@ static void run_test1(const char *name, const char *impl, bool in_packed, bool o
|
|||
static void run_testc(const char *name, const char *impl, bool in_packed, bool out_packed, convert_func_t func,
|
||||
int channel_count)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(sample_sizes); i++) {
|
||||
SPA_FOR_EACH_ELEMENT_VAR(sample_sizes, s) {
|
||||
run_test1(name, impl, in_packed, out_packed, func, channel_count,
|
||||
(sample_sizes[i] + (channel_count -1)) / channel_count);
|
||||
(*s + (channel_count -1)) / channel_count);
|
||||
}
|
||||
}
|
||||
|
||||
static void run_test(const char *name, const char *impl, bool in_packed, bool out_packed, convert_func_t func)
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS(sample_sizes); i++) {
|
||||
for (j = 0; j < SPA_N_ELEMENTS(channel_counts); j++) {
|
||||
run_test1(name, impl, in_packed, out_packed, func, channel_counts[j],
|
||||
(sample_sizes[i] + (channel_counts[j] -1)) / channel_counts[j]);
|
||||
SPA_FOR_EACH_ELEMENT_VAR(sample_sizes, s) {
|
||||
SPA_FOR_EACH_ELEMENT_VAR(channel_counts, c) {
|
||||
run_test1(name, impl, in_packed, out_packed, func, *c, (*s + (*c -1)) / *c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,19 +108,18 @@ static const struct channelmix_info {
|
|||
static const struct channelmix_info *find_channelmix_info(uint32_t src_chan, uint64_t src_mask,
|
||||
uint32_t dst_chan, uint64_t dst_mask, uint32_t cpu_flags)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(channelmix_table); i++) {
|
||||
if (!MATCH_CPU_FLAGS(channelmix_table[i].cpu_flags, cpu_flags))
|
||||
SPA_FOR_EACH_ELEMENT_VAR(channelmix_table, info) {
|
||||
if (!MATCH_CPU_FLAGS(info->cpu_flags, cpu_flags))
|
||||
continue;
|
||||
|
||||
if (src_chan == dst_chan && src_mask == dst_mask)
|
||||
return &channelmix_table[i];
|
||||
return info;
|
||||
|
||||
if (MATCH_CHAN(channelmix_table[i].src_chan, src_chan) &&
|
||||
MATCH_CHAN(channelmix_table[i].dst_chan, dst_chan) &&
|
||||
MATCH_MASK(channelmix_table[i].src_mask, src_mask) &&
|
||||
MATCH_MASK(channelmix_table[i].dst_mask, dst_mask))
|
||||
return &channelmix_table[i];
|
||||
if (MATCH_CHAN(info->src_chan, src_chan) &&
|
||||
MATCH_CHAN(info->dst_chan, dst_chan) &&
|
||||
MATCH_MASK(info->src_mask, src_mask) &&
|
||||
MATCH_MASK(info->dst_mask, dst_mask))
|
||||
return info;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -359,14 +359,13 @@ static struct conv_info conv_table[] =
|
|||
static const struct conv_info *find_conv_info(uint32_t src_fmt, uint32_t dst_fmt,
|
||||
uint32_t n_channels, uint32_t cpu_flags, uint32_t conv_flags)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(conv_table); i++) {
|
||||
if (conv_table[i].src_fmt == src_fmt &&
|
||||
conv_table[i].dst_fmt == dst_fmt &&
|
||||
MATCH_CHAN(conv_table[i].n_channels, n_channels) &&
|
||||
MATCH_CPU_FLAGS(conv_table[i].cpu_flags, cpu_flags) &&
|
||||
MATCH_DITHER(conv_table[i].conv_flags, conv_flags))
|
||||
return &conv_table[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(conv_table, c) {
|
||||
if (c->src_fmt == src_fmt &&
|
||||
c->dst_fmt == dst_fmt &&
|
||||
MATCH_CHAN(c->n_channels, n_channels) &&
|
||||
MATCH_CPU_FLAGS(c->cpu_flags, cpu_flags) &&
|
||||
MATCH_DITHER(c->conv_flags, conv_flags))
|
||||
return c;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -403,11 +402,10 @@ static struct noise_info noise_table[] =
|
|||
static const struct noise_info *find_noise_info(uint32_t method,
|
||||
uint32_t cpu_flags)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(noise_table); i++) {
|
||||
if (noise_table[i].method == method &&
|
||||
MATCH_CPU_FLAGS(noise_table[i].cpu_flags, cpu_flags))
|
||||
return &noise_table[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(noise_table, t) {
|
||||
if (t->method == method &&
|
||||
MATCH_CPU_FLAGS(t->cpu_flags, cpu_flags))
|
||||
return t;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -471,17 +469,14 @@ static const struct dither_info {
|
|||
|
||||
static const struct dither_info *find_dither_info(uint32_t method, uint32_t rate)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS(dither_info); i++) {
|
||||
const struct dither_info *di = &dither_info[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(dither_info, di) {
|
||||
if (di->method != method)
|
||||
continue;
|
||||
/* don't use shaped for too low rates, it moves the noise to
|
||||
* audible ranges */
|
||||
if (di->ns != NULL && rate < di->rate * 3 / 4)
|
||||
return find_dither_info(DITHER_METHOD_TRIANGULAR_HF, rate);
|
||||
return &dither_info[i];
|
||||
return di;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -271,10 +271,9 @@ static const struct dither_method_info {
|
|||
|
||||
static inline uint32_t dither_method_from_label(const char *label)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(dither_method_info); i++) {
|
||||
if (spa_streq(dither_method_info[i].label, label))
|
||||
return dither_method_info[i].method;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(dither_method_info, i) {
|
||||
if (spa_streq(i->label, label))
|
||||
return i->method;
|
||||
}
|
||||
return DITHER_METHOD_NONE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,11 +59,9 @@ static const struct peaks_info {
|
|||
|
||||
static const struct peaks_info *find_peaks_info(uint32_t cpu_flags)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(peaks_table); i++) {
|
||||
if (!MATCH_CPU_FLAGS(peaks_table[i].cpu_flags, cpu_flags))
|
||||
continue;
|
||||
return &peaks_table[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(peaks_table, t) {
|
||||
if (MATCH_CPU_FLAGS(t->cpu_flags, cpu_flags))
|
||||
return t;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,11 +125,10 @@ static struct resample_info resample_table[] =
|
|||
#define MATCH_CPU_FLAGS(a,b) ((a) == 0 || ((a) & (b)) == a)
|
||||
static const struct resample_info *find_resample_info(uint32_t format, uint32_t cpu_flags)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(resample_table); i++) {
|
||||
if (resample_table[i].format == format &&
|
||||
MATCH_CPU_FLAGS(resample_table[i].cpu_flags, cpu_flags))
|
||||
return &resample_table[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(resample_table, t) {
|
||||
if (t->format == format &&
|
||||
MATCH_CPU_FLAGS(t->cpu_flags, cpu_flags))
|
||||
return t;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,9 @@ static const struct volume_info {
|
|||
|
||||
static const struct volume_info *find_volume_info(uint32_t cpu_flags)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(volume_table); i++) {
|
||||
if (!MATCH_CPU_FLAGS(volume_table[i].cpu_flags, cpu_flags))
|
||||
continue;
|
||||
return &volume_table[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(volume_table, t) {
|
||||
if (MATCH_CPU_FLAGS(t->cpu_flags, cpu_flags))
|
||||
return t;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue