mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
clean up some more array iterations
This commit is contained in:
parent
0b98614bea
commit
9b6e504c19
14 changed files with 88 additions and 114 deletions
|
|
@ -109,10 +109,9 @@ static const struct channelmix_upmix_info {
|
|||
|
||||
static inline uint32_t channelmix_upmix_from_label(const char *label)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(channelmix_upmix_info); i++) {
|
||||
if (spa_streq(channelmix_upmix_info[i].label, label))
|
||||
return channelmix_upmix_info[i].upmix;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(channelmix_upmix_info, i) {
|
||||
if (spa_streq(i->label, label))
|
||||
return i->upmix;
|
||||
}
|
||||
return CHANNELMIX_UPMIX_NONE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,10 +88,9 @@ static enum spa_bt_feature parse_feature(const char *str)
|
|||
{ "faststream", SPA_BT_FEATURE_FASTSTREAM },
|
||||
{ "a2dp-duplex", SPA_BT_FEATURE_A2DP_DUPLEX },
|
||||
};
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(feature_keys); ++i) {
|
||||
if (spa_streq(str, feature_keys[i].key))
|
||||
return feature_keys[i].value;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(feature_keys, f) {
|
||||
if (spa_streq(str, f->key))
|
||||
return f->value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,19 +171,18 @@ impl_cpu_get_vm_type(void *object)
|
|||
/* https://wiki.freebsd.org/bhyve */
|
||||
{ "BHYVE", SPA_CPU_VM_BHYVE },
|
||||
};
|
||||
uint32_t i, j;
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS(dmi_vendors); i++) {
|
||||
SPA_FOR_EACH_ELEMENT_VAR(dmi_vendors, dv) {
|
||||
char buffer[256], *s;
|
||||
|
||||
if ((s = read_file(dmi_vendors[i], buffer, sizeof(buffer))) == NULL)
|
||||
if ((s = read_file(*dv, buffer, sizeof(buffer))) == NULL)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < SPA_N_ELEMENTS(dmi_vendor_table); j++) {
|
||||
if (spa_strstartswith(s, dmi_vendor_table[j].vendor)) {
|
||||
SPA_FOR_EACH_ELEMENT_VAR(dmi_vendor_table, t) {
|
||||
if (spa_strstartswith(s, t->vendor)) {
|
||||
spa_log_debug(impl->log, "Virtualization %s found in DMI (%s)",
|
||||
s, dmi_vendors[i]);
|
||||
impl->vm_type = dmi_vendor_table[j].id;
|
||||
s, *dv);
|
||||
impl->vm_type = t->id;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -351,11 +351,9 @@ static const struct format_info format_info[] = {
|
|||
|
||||
static const struct format_info *fourcc_to_format_info(uint32_t fourcc)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) {
|
||||
if (format_info[i].fourcc == fourcc)
|
||||
return &format_info[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(format_info, i) {
|
||||
if (i->fourcc == fourcc)
|
||||
return i;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -363,11 +361,9 @@ static const struct format_info *fourcc_to_format_info(uint32_t fourcc)
|
|||
#if 0
|
||||
static const struct format_info *video_format_to_format_info(uint32_t format)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) {
|
||||
if (format_info[i].format == format)
|
||||
return &format_info[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(format_info, i) {
|
||||
if (i->format == format)
|
||||
return i;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -381,10 +377,11 @@ static const struct format_info *find_format_info_by_media_type(uint32_t type,
|
|||
size_t i;
|
||||
|
||||
for (i = startidx; i < SPA_N_ELEMENTS(format_info); i++) {
|
||||
if ((format_info[i].media_type == type) &&
|
||||
(format_info[i].media_subtype == subtype) &&
|
||||
(format == 0 || format_info[i].format == format))
|
||||
return &format_info[i];
|
||||
const struct format_info *fi = &format_info[i];
|
||||
if ((fi->media_type == type) &&
|
||||
(fi->media_subtype == subtype) &&
|
||||
(format == 0 || fi->format == format))
|
||||
return fi;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,25 +130,22 @@ static struct {
|
|||
|
||||
static inline uint32_t sdl_format_to_id(Uint32 format)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(sdl_video_formats); i++) {
|
||||
if (sdl_video_formats[i].format == format)
|
||||
return sdl_video_formats[i].id;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(sdl_video_formats, f) {
|
||||
if (f->format == format)
|
||||
return f->id;
|
||||
}
|
||||
return SPA_VIDEO_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
static inline Uint32 id_to_sdl_format(uint32_t id)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(sdl_video_formats); i++) {
|
||||
if (sdl_video_formats[i].id == id)
|
||||
return sdl_video_formats[i].format;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(sdl_video_formats, f) {
|
||||
if (f->id == id)
|
||||
return f->format;
|
||||
}
|
||||
return SDL_PIXELFORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
static inline struct spa_pod *sdl_build_formats(SDL_RendererInfo *info, struct spa_pod_builder *b)
|
||||
{
|
||||
uint32_t i, c;
|
||||
|
|
@ -178,8 +175,8 @@ static inline struct spa_pod *sdl_build_formats(SDL_RendererInfo *info, struct s
|
|||
spa_pod_builder_id(b, id);
|
||||
}
|
||||
/* then all the other ones SDL can convert from/to */
|
||||
for (i = 0; i < SPA_N_ELEMENTS(sdl_video_formats); i++) {
|
||||
uint32_t id = sdl_video_formats[i].id;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(sdl_video_formats, f) {
|
||||
uint32_t id = f->id;
|
||||
if (id != SPA_VIDEO_FORMAT_UNKNOWN)
|
||||
spa_pod_builder_id(b, id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -345,11 +345,10 @@ static const struct msg_info msg_info[] = {
|
|||
|
||||
static inline const struct msg_info *find_msg_info(uint16_t type, const char *name)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(msg_info); i++) {
|
||||
if ((name == NULL && type == msg_info[i].type) ||
|
||||
(name != NULL && spa_streq(name, msg_info[i].name)))
|
||||
return &msg_info[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(msg_info, i) {
|
||||
if ((name == NULL && type == i->type) ||
|
||||
(name != NULL && spa_streq(name, i->name)))
|
||||
return i;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,11 +250,10 @@ static const struct cmd_info cmd_info[] = {
|
|||
|
||||
static inline const struct cmd_info *find_cmd_info(uint16_t type, const char *name)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(cmd_info); i++) {
|
||||
if ((name == NULL && type == cmd_info[i].type) ||
|
||||
(name != NULL && spa_streq(name, cmd_info[i].name)))
|
||||
return &cmd_info[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(cmd_info, i) {
|
||||
if ((name == NULL && type == i->type) ||
|
||||
(name != NULL && spa_streq(name, i->name)))
|
||||
return i;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,11 +67,10 @@ static const struct msg_info msg_info[] = {
|
|||
|
||||
static inline const struct msg_info *find_msg_info(uint16_t type, const char *name)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(msg_info); i++) {
|
||||
if ((name == NULL && type == msg_info[i].type) ||
|
||||
(name != NULL && spa_streq(name, msg_info[i].name)))
|
||||
return &msg_info[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(msg_info, i) {
|
||||
if ((name == NULL && type == i->type) ||
|
||||
(name != NULL && spa_streq(name, i->name)))
|
||||
return i;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1333,13 +1333,12 @@ static void convert_properties(struct pw_properties *properties)
|
|||
{ "pipewire.target.node", PW_KEY_NODE_TARGET, }
|
||||
};
|
||||
|
||||
uint32_t i;
|
||||
const char *str;
|
||||
|
||||
for(i = 0; i < SPA_N_ELEMENTS(props); i++) {
|
||||
if ((str = pw_properties_get(properties, props[i].from)) != NULL) {
|
||||
pw_properties_set(properties, props[i].to, str);
|
||||
pw_properties_set(properties, props[i].from, NULL);
|
||||
SPA_FOR_EACH_ELEMENT_VAR(props, p) {
|
||||
if ((str = pw_properties_get(properties, p->from)) != NULL) {
|
||||
pw_properties_set(properties, p->to, str);
|
||||
pw_properties_set(properties, p->from, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,32 +159,28 @@ uint32_t format_name2id(const char *name)
|
|||
|
||||
uint32_t format_paname2id(const char *name, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(audio_formats); i++) {
|
||||
if (audio_formats[i].name != NULL &&
|
||||
strncmp(name, audio_formats[i].name, size) == 0)
|
||||
return audio_formats[i].id;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(audio_formats, f) {
|
||||
if (f->name != NULL &&
|
||||
strncmp(name, f->name, size) == 0)
|
||||
return f->id;
|
||||
}
|
||||
return SPA_AUDIO_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
enum sample_format format_id2pa(uint32_t id)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(audio_formats); i++) {
|
||||
if (id == audio_formats[i].id)
|
||||
return audio_formats[i].pa;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(audio_formats, f) {
|
||||
if (id == f->id)
|
||||
return f->pa;
|
||||
}
|
||||
return SAMPLE_INVALID;
|
||||
}
|
||||
|
||||
const char *format_id2paname(uint32_t id)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(audio_formats); i++) {
|
||||
if (id == audio_formats[i].id &&
|
||||
audio_formats[i].name != NULL)
|
||||
return audio_formats[i].name;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(audio_formats, f) {
|
||||
if (id == f->id && f->name != NULL)
|
||||
return f->name;
|
||||
}
|
||||
return "invalid";
|
||||
}
|
||||
|
|
@ -266,21 +262,18 @@ enum channel_position channel_id2pa(uint32_t id, uint32_t *aux)
|
|||
|
||||
const char *channel_id2paname(uint32_t id, uint32_t *aux)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(audio_channels); i++) {
|
||||
if (id == audio_channels[i].channel &&
|
||||
audio_channels[i].name != NULL)
|
||||
return audio_channels[i].name;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(audio_channels, i) {
|
||||
if (id == i->channel && i->name != NULL)
|
||||
return i->name;
|
||||
}
|
||||
return audio_channels[CHANNEL_POSITION_AUX0 + ((*aux)++ & 31)].name;
|
||||
}
|
||||
|
||||
uint32_t channel_paname2id(const char *name, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(audio_channels); i++) {
|
||||
if (strncmp(name, audio_channels[i].name, size) == 0)
|
||||
return audio_channels[i].channel;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(audio_channels, i) {
|
||||
if (strncmp(name, i->name, size) == 0)
|
||||
return i->channel;
|
||||
}
|
||||
return SPA_AUDIO_CHANNEL_UNKNOWN;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -553,11 +553,10 @@ static const struct object_info *objects[] =
|
|||
|
||||
static const struct object_info *find_info(const char *type, uint32_t version)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(objects); i++) {
|
||||
if (spa_streq(objects[i]->type, type) &&
|
||||
objects[i]->version <= version)
|
||||
return objects[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(objects, i) {
|
||||
if (spa_streq((*i)->type, type) &&
|
||||
(*i)->version <= version)
|
||||
return *i;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,10 +38,9 @@ static uint64_t parse_quirks(const char *str)
|
|||
{ "force-s16-info", QUIRK_FORCE_S16_FORMAT },
|
||||
{ "remove-capture-dont-move", QUIRK_REMOVE_CAPTURE_DONT_MOVE },
|
||||
};
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(quirk_keys); ++i) {
|
||||
if (spa_streq(str, quirk_keys[i].key))
|
||||
return quirk_keys[i].value;
|
||||
SPA_FOR_EACH_ELEMENT_VAR(quirk_keys, i) {
|
||||
if (spa_streq(str, i->key))
|
||||
return i->value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,20 +174,18 @@ static const struct format_info {
|
|||
|
||||
static const struct format_info *format_info_by_name(const char *str)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(format_info); i++)
|
||||
if (spa_streq(str, format_info[i].name))
|
||||
return &format_info[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(format_info, i)
|
||||
if (spa_streq(str, i->name))
|
||||
return i;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const struct format_info *format_info_by_sf_format(int format)
|
||||
{
|
||||
uint32_t i;
|
||||
int sub_type = (format & SF_FORMAT_SUBMASK);
|
||||
for (i = 0; i < SPA_N_ELEMENTS(format_info); i++)
|
||||
if (format_info[i].sf_format == sub_type)
|
||||
return &format_info[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(format_info, i)
|
||||
if (i->sf_format == sub_type)
|
||||
return i;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -431,10 +429,10 @@ static int parse_channelmap(const char *channel_map, struct channelmap *map)
|
|||
int i, nch;
|
||||
char **ch;
|
||||
|
||||
for (i = 0; i < (int) SPA_N_ELEMENTS(maps); i++) {
|
||||
if (spa_streq(maps[i].name, channel_map)) {
|
||||
map->n_channels = maps[i].channels;
|
||||
spa_memcpy(map->channels, &maps[i].values,
|
||||
SPA_FOR_EACH_ELEMENT_VAR(maps, m) {
|
||||
if (spa_streq(m->name, channel_map)) {
|
||||
map->n_channels = m->channels;
|
||||
spa_memcpy(map->channels, &m->values,
|
||||
map->n_channels * sizeof(unsigned int));
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1589,17 +1587,16 @@ int main(int argc, char *argv[])
|
|||
case TYPE_DSD:
|
||||
{
|
||||
struct spa_audio_info_dsd info;
|
||||
size_t i;
|
||||
|
||||
spa_zero(info);
|
||||
info.channels = data.dsf.info.channels;
|
||||
info.rate = data.dsf.info.rate / 8;
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS(dsd_layouts); i++) {
|
||||
if (dsd_layouts[i].type != data.dsf.info.channel_type)
|
||||
SPA_FOR_EACH_ELEMENT_VAR(dsd_layouts, i) {
|
||||
if (i->type != data.dsf.info.channel_type)
|
||||
continue;
|
||||
info.channels = dsd_layouts[i].info.n_channels;
|
||||
memcpy(info.position, dsd_layouts[i].info.position,
|
||||
info.channels = i->info.n_channels;
|
||||
memcpy(info.position, i->info.position,
|
||||
info.channels * sizeof(uint32_t));
|
||||
}
|
||||
params[0] = spa_format_audio_dsd_build(&b, SPA_PARAM_EnumFormat, &info);
|
||||
|
|
|
|||
|
|
@ -1241,11 +1241,10 @@ static const struct class *classes[] =
|
|||
|
||||
static const struct class *find_class(const char *type, uint32_t version)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(classes); i++) {
|
||||
if (spa_streq(classes[i]->type, type) &&
|
||||
classes[i]->version <= version)
|
||||
return classes[i];
|
||||
SPA_FOR_EACH_ELEMENT_VAR(classes, c) {
|
||||
if (spa_streq((*c)->type, type) &&
|
||||
(*c)->version <= version)
|
||||
return *c;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue