mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-10-29 05:40:27 -04: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
				
			
		|  | @ -867,10 +867,9 @@ static const struct chmap_info chmap_info[] = { | ||||||
| 
 | 
 | ||||||
| static enum snd_pcm_chmap_position channel_to_chmap(enum spa_audio_channel channel) | static enum snd_pcm_chmap_position channel_to_chmap(enum spa_audio_channel channel) | ||||||
| { | { | ||||||
| 	uint32_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(chmap_info, info) | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(chmap_info); i++) | 		if (info->channel == channel) | ||||||
| 		if (chmap_info[i].channel == channel) | 			return info->pos; | ||||||
| 			return chmap_info[i].pos; |  | ||||||
| 	return SND_CHMAP_UNKNOWN; | 	return SND_CHMAP_UNKNOWN; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -913,23 +913,19 @@ static const struct format_info format_info[] = { | ||||||
| static const struct format_info *format_info_from_media_type(uint32_t type, | static const struct format_info *format_info_from_media_type(uint32_t type, | ||||||
| 		uint32_t subtype, uint32_t format) | 		uint32_t subtype, uint32_t format) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(format_info, i) | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) { | 		if ((i->media_type == type) && | ||||||
| 		if ((format_info[i].media_type == type) && | 		    (i->media_subtype == subtype) && | ||||||
| 		    (format_info[i].media_subtype == subtype) && | 		    (format == 0 || i->format == format)) | ||||||
| 		    (format == 0 || format_info[i].format == format)) | 			return i; | ||||||
| 			return &format_info[i]; |  | ||||||
| 	} |  | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static const struct format_info *format_info_from_fourcc(uint32_t fourcc) | static const struct format_info *format_info_from_fourcc(uint32_t fourcc) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(format_info, i) | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) { | 		if (i->fourcc == fourcc) | ||||||
| 		if (format_info[i].fourcc == fourcc) | 			return i; | ||||||
| 			return &format_info[i]; |  | ||||||
| 	} |  | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -141,6 +141,9 @@ struct spa_fraction { | ||||||
| #define SPA_FOR_EACH_ELEMENT(arr, ptr) \ | #define SPA_FOR_EACH_ELEMENT(arr, ptr) \ | ||||||
| 	for ((ptr) = arr; (void*)(ptr) < SPA_PTROFF(arr, sizeof(arr), void); (ptr)++) | 	for ((ptr) = arr; (void*)(ptr) < SPA_PTROFF(arr, sizeof(arr), void); (ptr)++) | ||||||
| 
 | 
 | ||||||
|  | #define SPA_FOR_EACH_ELEMENT_VAR(arr, var) \ | ||||||
|  | 	for (__typeof__((arr)[0])* (var) = arr; (void*)(var) < SPA_PTROFF(arr, sizeof(arr), void); (var)++) | ||||||
|  | 
 | ||||||
| #define SPA_ABS(a)			\ | #define SPA_ABS(a)			\ | ||||||
| ({					\ | ({					\ | ||||||
| 	__typeof__(a) _a = (a);		\ | 	__typeof__(a) _a = (a);		\ | ||||||
|  |  | ||||||
|  | @ -216,7 +216,7 @@ static int emit_info(struct impl *this, bool full) | ||||||
| { | { | ||||||
| 	int err = 0; | 	int err = 0; | ||||||
| 	struct spa_dict_item *items; | 	struct spa_dict_item *items; | ||||||
| 	uint32_t i, n_items; | 	uint32_t n_items; | ||||||
| 	const struct acp_dict_item *it; | 	const struct acp_dict_item *it; | ||||||
| 	struct acp_card *card = this->card; | 	struct acp_card *card = this->card; | ||||||
| 	char path[128]; | 	char path[128]; | ||||||
|  | @ -241,10 +241,10 @@ static int emit_info(struct impl *this, bool full) | ||||||
| #undef ADD_ITEM | #undef ADD_ITEM | ||||||
| 
 | 
 | ||||||
| 		if (this->info.change_mask & SPA_DEVICE_CHANGE_MASK_PARAMS) { | 		if (this->info.change_mask & SPA_DEVICE_CHANGE_MASK_PARAMS) { | ||||||
| 			for (i = 0; i < SPA_N_ELEMENTS(this->params); i++) { | 			SPA_FOR_EACH_ELEMENT_VAR(this->params, p) { | ||||||
| 				if (this->params[i].user > 0) { | 				if (p->user > 0) { | ||||||
| 					this->params[i].flags ^= SPA_PARAM_INFO_SERIAL; | 					p->flags ^= SPA_PARAM_INFO_SERIAL; | ||||||
| 					this->params[i].user = 0; | 					p->user = 0; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -638,12 +638,10 @@ static const struct format_info format_info[] = { | ||||||
| 
 | 
 | ||||||
| static snd_pcm_format_t spa_format_to_alsa(uint32_t format, bool *planar) | static snd_pcm_format_t spa_format_to_alsa(uint32_t format, bool *planar) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(format_info, i) { | ||||||
| 
 | 		*planar = i->spa_pformat == format; | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) { | 		if (i->spa_format == format || *planar) | ||||||
| 		*planar = format_info[i].spa_pformat == format; | 			return i->format; | ||||||
| 		if (format_info[i].spa_format == format || *planar) |  | ||||||
| 			return format_info[i].format; |  | ||||||
| 	} | 	} | ||||||
| 	return SND_PCM_FORMAT_UNKNOWN; | 	return SND_PCM_FORMAT_UNKNOWN; | ||||||
| } | } | ||||||
|  | @ -969,7 +967,7 @@ static int enum_pcm_formats(struct state *state, uint32_t index, uint32_t *next, | ||||||
| 		struct spa_pod **result, struct spa_pod_builder *b) | 		struct spa_pod **result, struct spa_pod_builder *b) | ||||||
| { | { | ||||||
| 	int res, err; | 	int res, err; | ||||||
| 	size_t i, j; | 	size_t j; | ||||||
| 	snd_pcm_t *hndl; | 	snd_pcm_t *hndl; | ||||||
| 	snd_pcm_hw_params_t *params; | 	snd_pcm_hw_params_t *params; | ||||||
| 	struct spa_pod_frame f[2]; | 	struct spa_pod_frame f[2]; | ||||||
|  | @ -1020,8 +1018,10 @@ static int enum_pcm_formats(struct state *state, uint32_t index, uint32_t *next, | ||||||
| 	spa_pod_builder_push_choice(b, &f[1], SPA_CHOICE_None, 0); | 	spa_pod_builder_push_choice(b, &f[1], SPA_CHOICE_None, 0); | ||||||
| 	choice = (struct spa_pod_choice*)spa_pod_builder_frame(b, &f[1]); | 	choice = (struct spa_pod_choice*)spa_pod_builder_frame(b, &f[1]); | ||||||
| 
 | 
 | ||||||
| 	for (i = 1, j = 0; i < SPA_N_ELEMENTS(format_info); i++) { | 	j = 0; | ||||||
| 		const struct format_info *fi = &format_info[i]; | 	SPA_FOR_EACH_ELEMENT_VAR(format_info, fi) { | ||||||
|  | 		if (fi->format == SND_PCM_FORMAT_UNKNOWN) | ||||||
|  | 			continue; | ||||||
| 
 | 
 | ||||||
| 		if (snd_pcm_format_mask_test(fmask, fi->format)) { | 		if (snd_pcm_format_mask_test(fmask, fi->format)) { | ||||||
| 			if ((snd_pcm_access_mask_test(amask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED) || | 			if ((snd_pcm_access_mask_test(amask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED) || | ||||||
|  |  | ||||||
|  | @ -241,16 +241,15 @@ static void set_volume(struct impl *this); | ||||||
| static void emit_node_info(struct impl *this, bool full) | static void emit_node_info(struct impl *this, bool full) | ||||||
| { | { | ||||||
| 	uint64_t old = full ? this->info.change_mask : 0; | 	uint64_t old = full ? this->info.change_mask : 0; | ||||||
| 	uint32_t i; |  | ||||||
| 
 | 
 | ||||||
| 	if (full) | 	if (full) | ||||||
| 		this->info.change_mask = this->info_all; | 		this->info.change_mask = this->info_all; | ||||||
| 	if (this->info.change_mask) { | 	if (this->info.change_mask) { | ||||||
| 		if (this->info.change_mask & SPA_NODE_CHANGE_MASK_PARAMS) { | 		if (this->info.change_mask & SPA_NODE_CHANGE_MASK_PARAMS) { | ||||||
| 			for (i = 0; i < SPA_N_ELEMENTS(this->params); i++) { | 			SPA_FOR_EACH_ELEMENT_VAR(this->params, p) { | ||||||
| 				if (this->params[i].user > 0) { | 				if (p->user > 0) { | ||||||
| 					this->params[i].flags ^= SPA_PARAM_INFO_SERIAL; | 					p->flags ^= SPA_PARAM_INFO_SERIAL; | ||||||
| 					this->params[i].user = 0; | 					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) | static void emit_port_info(struct impl *this, struct port *port, bool full) | ||||||
| { | { | ||||||
| 	uint64_t old = full ? port->info.change_mask : 0; | 	uint64_t old = full ? port->info.change_mask : 0; | ||||||
| 	uint32_t i; |  | ||||||
| 
 | 
 | ||||||
| 	if (full) | 	if (full) | ||||||
| 		port->info.change_mask = port->info_all; | 		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); | 		port->info.props = &SPA_DICT_INIT(items, n_items); | ||||||
| 
 | 
 | ||||||
| 		if (port->info.change_mask & SPA_PORT_CHANGE_MASK_PARAMS) { | 		if (port->info.change_mask & SPA_PORT_CHANGE_MASK_PARAMS) { | ||||||
| 			for (i = 0; i < SPA_N_ELEMENTS(port->params); i++) { | 			SPA_FOR_EACH_ELEMENT_VAR(port->params, p) { | ||||||
| 				if (port->params[i].user > 0) { | 				if (p->user > 0) { | ||||||
| 					port->params[i].flags ^= SPA_PARAM_INFO_SERIAL; | 					p->flags ^= SPA_PARAM_INFO_SERIAL; | ||||||
| 					port->params[i].user = 0; | 					p->user = 0; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | @ -432,7 +430,6 @@ static int impl_node_enum_params(void *object, int seq, | ||||||
| 	{ | 	{ | ||||||
| 		struct props *p = &this->props; | 		struct props *p = &this->props; | ||||||
| 		struct spa_pod_frame f[2]; | 		struct spa_pod_frame f[2]; | ||||||
| 		uint32_t i; |  | ||||||
| 
 | 
 | ||||||
| 		switch (result.index) { | 		switch (result.index) { | ||||||
| 		case 0: | 		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_prop(&b, SPA_PROP_INFO_labels, 0); | ||||||
| 			spa_pod_builder_push_struct(&b, &f[1]); | 			spa_pod_builder_push_struct(&b, &f[1]); | ||||||
| 			for (i = 0; i < SPA_N_ELEMENTS(channelmix_upmix_info); i++) { | 			SPA_FOR_EACH_ELEMENT_VAR(channelmix_upmix_info, i) { | ||||||
| 				spa_pod_builder_string(&b, channelmix_upmix_info[i].label); | 				spa_pod_builder_string(&b, i->label); | ||||||
| 				spa_pod_builder_string(&b, channelmix_upmix_info[i].description); | 				spa_pod_builder_string(&b, i->description); | ||||||
| 			} | 			} | ||||||
| 			spa_pod_builder_pop(&b, &f[1]); | 			spa_pod_builder_pop(&b, &f[1]); | ||||||
| 			param = spa_pod_builder_pop(&b, &f[0]); | 			param = spa_pod_builder_pop(&b, &f[0]); | ||||||
|  | @ -646,9 +643,9 @@ static int impl_node_enum_params(void *object, int seq, | ||||||
| 				0); | 				0); | ||||||
| 			spa_pod_builder_prop(&b, SPA_PROP_INFO_labels, 0); | 			spa_pod_builder_prop(&b, SPA_PROP_INFO_labels, 0); | ||||||
| 			spa_pod_builder_push_struct(&b, &f[1]); | 			spa_pod_builder_push_struct(&b, &f[1]); | ||||||
| 			for (i = 0; i < SPA_N_ELEMENTS(dither_method_info); i++) { | 			SPA_FOR_EACH_ELEMENT_VAR(dither_method_info, i) { | ||||||
| 				spa_pod_builder_string(&b, dither_method_info[i].label); | 				spa_pod_builder_string(&b, i->label); | ||||||
| 				spa_pod_builder_string(&b, dither_method_info[i].description); | 				spa_pod_builder_string(&b, i->description); | ||||||
| 			} | 			} | ||||||
| 			spa_pod_builder_pop(&b, &f[1]); | 			spa_pod_builder_pop(&b, &f[1]); | ||||||
| 			param = spa_pod_builder_pop(&b, &f[0]); | 			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, | static void run_testc(const char *name, const char *impl, bool in_packed, bool out_packed, convert_func_t func, | ||||||
| 		int channel_count) | 		int channel_count) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(sample_sizes, s) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(sample_sizes); i++) { |  | ||||||
| 		run_test1(name, impl, in_packed, out_packed, func, channel_count, | 		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) | static void run_test(const char *name, const char *impl, bool in_packed, bool out_packed, convert_func_t func) | ||||||
| { | { | ||||||
| 	size_t i, j; | 	SPA_FOR_EACH_ELEMENT_VAR(sample_sizes, s) { | ||||||
| 
 | 		SPA_FOR_EACH_ELEMENT_VAR(channel_counts, c) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(sample_sizes); i++) { | 			run_test1(name, impl, in_packed, out_packed, func, *c, (*s + (*c -1)) / *c); | ||||||
| 		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]); |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -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, | 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) | 		uint32_t dst_chan, uint64_t dst_mask, uint32_t cpu_flags) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(channelmix_table, info) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(channelmix_table); i++) { | 		if (!MATCH_CPU_FLAGS(info->cpu_flags, cpu_flags)) | ||||||
| 		if (!MATCH_CPU_FLAGS(channelmix_table[i].cpu_flags, cpu_flags)) |  | ||||||
| 			continue; | 			continue; | ||||||
| 
 | 
 | ||||||
| 		if (src_chan == dst_chan && src_mask == dst_mask) | 		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) && | 		if (MATCH_CHAN(info->src_chan, src_chan) && | ||||||
| 		    MATCH_CHAN(channelmix_table[i].dst_chan, dst_chan) && | 		    MATCH_CHAN(info->dst_chan, dst_chan) && | ||||||
| 		    MATCH_MASK(channelmix_table[i].src_mask, src_mask) && | 		    MATCH_MASK(info->src_mask, src_mask) && | ||||||
| 		    MATCH_MASK(channelmix_table[i].dst_mask, dst_mask)) | 		    MATCH_MASK(info->dst_mask, dst_mask)) | ||||||
| 			return &channelmix_table[i]; | 			return info; | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	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, | 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) | 		uint32_t n_channels, uint32_t cpu_flags, uint32_t conv_flags) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(conv_table, c) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(conv_table); i++) { | 		if (c->src_fmt == src_fmt && | ||||||
| 		if (conv_table[i].src_fmt == src_fmt && | 		    c->dst_fmt == dst_fmt && | ||||||
| 		    conv_table[i].dst_fmt == dst_fmt && | 		    MATCH_CHAN(c->n_channels, n_channels) && | ||||||
| 		    MATCH_CHAN(conv_table[i].n_channels, n_channels) && | 		    MATCH_CPU_FLAGS(c->cpu_flags, cpu_flags) && | ||||||
| 		    MATCH_CPU_FLAGS(conv_table[i].cpu_flags, cpu_flags) && | 		    MATCH_DITHER(c->conv_flags, conv_flags)) | ||||||
| 		    MATCH_DITHER(conv_table[i].conv_flags, conv_flags)) | 			return c; | ||||||
| 			return &conv_table[i]; |  | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  | @ -403,11 +402,10 @@ static struct noise_info noise_table[] = | ||||||
| static const struct noise_info *find_noise_info(uint32_t method, | static const struct noise_info *find_noise_info(uint32_t method, | ||||||
| 		uint32_t cpu_flags) | 		uint32_t cpu_flags) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(noise_table, t) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(noise_table); i++) { | 		if (t->method == method && | ||||||
| 		if (noise_table[i].method == method && | 		    MATCH_CPU_FLAGS(t->cpu_flags, cpu_flags)) | ||||||
| 		    MATCH_CPU_FLAGS(noise_table[i].cpu_flags, cpu_flags)) | 			return t; | ||||||
| 			return &noise_table[i]; |  | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	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) | static const struct dither_info *find_dither_info(uint32_t method, uint32_t rate) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(dither_info, di) { | ||||||
| 
 |  | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(dither_info); i++) { |  | ||||||
| 		const struct dither_info *di = &dither_info[i]; |  | ||||||
| 		if (di->method != method) | 		if (di->method != method) | ||||||
| 			continue; | 			continue; | ||||||
| 		/* don't use shaped for too low rates, it moves the noise to
 | 		/* don't use shaped for too low rates, it moves the noise to
 | ||||||
| 		 * audible ranges */ | 		 * audible ranges */ | ||||||
| 		if (di->ns != NULL && rate < di->rate * 3 / 4) | 		if (di->ns != NULL && rate < di->rate * 3 / 4) | ||||||
| 			return find_dither_info(DITHER_METHOD_TRIANGULAR_HF, rate); | 			return find_dither_info(DITHER_METHOD_TRIANGULAR_HF, rate); | ||||||
| 		return &dither_info[i]; | 		return di; | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -271,10 +271,9 @@ static const struct dither_method_info { | ||||||
| 
 | 
 | ||||||
| static inline uint32_t dither_method_from_label(const char *label) | static inline uint32_t dither_method_from_label(const char *label) | ||||||
| { | { | ||||||
| 	uint32_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(dither_method_info, i) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(dither_method_info); i++) { | 		if (spa_streq(i->label, label)) | ||||||
| 		if (spa_streq(dither_method_info[i].label, label)) | 			return i->method; | ||||||
| 			return dither_method_info[i].method; |  | ||||||
| 	} | 	} | ||||||
| 	return DITHER_METHOD_NONE; | 	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) | static const struct peaks_info *find_peaks_info(uint32_t cpu_flags) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(peaks_table, t) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(peaks_table); i++) { | 		if (MATCH_CPU_FLAGS(t->cpu_flags, cpu_flags)) | ||||||
| 		if (!MATCH_CPU_FLAGS(peaks_table[i].cpu_flags, cpu_flags)) | 			return t; | ||||||
| 			continue; |  | ||||||
| 		return &peaks_table[i]; |  | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -125,11 +125,10 @@ static struct resample_info resample_table[] = | ||||||
| #define MATCH_CPU_FLAGS(a,b)	((a) == 0 || ((a) & (b)) == a) | #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) | static const struct resample_info *find_resample_info(uint32_t format, uint32_t cpu_flags) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(resample_table, t) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(resample_table); i++) { | 		if (t->format == format && | ||||||
| 		if (resample_table[i].format == format && | 		    MATCH_CPU_FLAGS(t->cpu_flags, cpu_flags)) | ||||||
| 		    MATCH_CPU_FLAGS(resample_table[i].cpu_flags, cpu_flags)) | 			return t; | ||||||
| 			return &resample_table[i]; |  | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -56,11 +56,9 @@ static const struct volume_info { | ||||||
| 
 | 
 | ||||||
| static const struct volume_info *find_volume_info(uint32_t cpu_flags) | static const struct volume_info *find_volume_info(uint32_t cpu_flags) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(volume_table, t) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(volume_table); i++) { | 		if (MATCH_CPU_FLAGS(t->cpu_flags, cpu_flags)) | ||||||
| 		if (!MATCH_CPU_FLAGS(volume_table[i].cpu_flags, cpu_flags)) | 			return t; | ||||||
| 			continue; |  | ||||||
| 		return &volume_table[i]; |  | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -98,13 +98,11 @@ static struct mix_info mix_table[] = | ||||||
| static const struct mix_info *find_mix_info(uint32_t fmt, | static const struct mix_info *find_mix_info(uint32_t fmt, | ||||||
| 		uint32_t n_channels, uint32_t cpu_flags) | 		uint32_t n_channels, uint32_t cpu_flags) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(mix_table, t) { | ||||||
| 
 | 		if (t->fmt == fmt && | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(mix_table); i++) { | 		    MATCH_CHAN(t->n_channels, n_channels) && | ||||||
| 		if (mix_table[i].fmt == fmt && | 		    MATCH_CPU_FLAGS(t->cpu_flags, cpu_flags)) | ||||||
| 		    MATCH_CHAN(mix_table[i].n_channels, n_channels) && | 			return t; | ||||||
| 		    MATCH_CPU_FLAGS(mix_table[i].cpu_flags, cpu_flags)) |  | ||||||
| 			return &mix_table[i]; |  | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -206,11 +206,11 @@ static int codec_enum_config(const struct media_codec *codec, uint32_t flags, | ||||||
| 	spa_pod_builder_push_choice(b, &f[1], SPA_CHOICE_None, 0); | 	spa_pod_builder_push_choice(b, &f[1], SPA_CHOICE_None, 0); | ||||||
| 	choice = (struct spa_pod_choice*)spa_pod_builder_frame(b, &f[1]); | 	choice = (struct spa_pod_choice*)spa_pod_builder_frame(b, &f[1]); | ||||||
| 	i = 0; | 	i = 0; | ||||||
| 	for (size_t j = 0; j < SPA_N_ELEMENTS(aac_frequencies); j++) { | 	SPA_FOR_EACH_ELEMENT_VAR(aac_frequencies, f) { | ||||||
| 		if (AAC_GET_FREQUENCY(conf) & aac_frequencies[j].config) { | 		if (AAC_GET_FREQUENCY(conf) & f->config) { | ||||||
| 			if (i++ == 0) | 			if (i++ == 0) | ||||||
| 				spa_pod_builder_int(b, aac_frequencies[j].value); | 				spa_pod_builder_int(b, f->value); | ||||||
| 			spa_pod_builder_int(b, aac_frequencies[j].value); | 			spa_pod_builder_int(b, f->value); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if (i == 0) | 	if (i == 0) | ||||||
|  | @ -272,14 +272,15 @@ static int codec_validate_config(const struct media_codec *codec, uint32_t flags | ||||||
| 	if (!(conf.object_type & (AAC_OBJECT_TYPE_MPEG2_AAC_LC | | 	if (!(conf.object_type & (AAC_OBJECT_TYPE_MPEG2_AAC_LC | | ||||||
| 					AAC_OBJECT_TYPE_MPEG4_AAC_LC))) | 					AAC_OBJECT_TYPE_MPEG4_AAC_LC))) | ||||||
| 		return -EINVAL; | 		return -EINVAL; | ||||||
| 
 | 	j = 0; | ||||||
| 	for (j = 0; j < SPA_N_ELEMENTS(aac_frequencies); ++j) { | 	SPA_FOR_EACH_ELEMENT_VAR(aac_frequencies, f) { | ||||||
| 		if (AAC_GET_FREQUENCY(conf) & aac_frequencies[j].config) { | 		if (AAC_GET_FREQUENCY(conf) & f->config) { | ||||||
| 			info->info.raw.rate = aac_frequencies[j].value; | 			info->info.raw.rate = f->value; | ||||||
|  | 			j++; | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if (j == SPA_N_ELEMENTS(aac_frequencies)) | 	if (j == 0) | ||||||
| 		return -EINVAL; | 		return -EINVAL; | ||||||
| 
 | 
 | ||||||
| 	if (conf.channels & AAC_CHANNELS_2) { | 	if (conf.channels & AAC_CHANNELS_2) { | ||||||
|  |  | ||||||
|  | @ -37,12 +37,9 @@ static const struct extension extensions[] = { | ||||||
| 
 | 
 | ||||||
| const struct extension *extension_find(uint32_t index, const char *name) | const struct extension *extension_find(uint32_t index, const char *name) | ||||||
| { | { | ||||||
| 	const struct extension *ext; | 	SPA_FOR_EACH_ELEMENT_VAR(extensions, ext) { | ||||||
| 
 |  | ||||||
| 	SPA_FOR_EACH_ELEMENT(extensions, ext) { |  | ||||||
| 		if (index == ext->index || spa_streq(name, ext->name)) | 		if (index == ext->index || spa_streq(name, ext->name)) | ||||||
| 			return ext; | 			return ext; | ||||||
| 	} | 	} | ||||||
| 
 |  | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -380,8 +380,7 @@ static AvahiStringList *get_service_txt(const struct service *s) | ||||||
| 	txt = avahi_string_list_add_pair(txt, "channel_map", channel_map_snprint(cm, sizeof(cm), &s->cm)); | 	txt = avahi_string_list_add_pair(txt, "channel_map", channel_map_snprint(cm, sizeof(cm), &s->cm)); | ||||||
| 	txt = avahi_string_list_add_pair(txt, "subtype", subtype_text[s->subtype]); | 	txt = avahi_string_list_add_pair(txt, "subtype", subtype_text[s->subtype]); | ||||||
| 
 | 
 | ||||||
| 	const struct mapping *m; | 	SPA_FOR_EACH_ELEMENT_VAR(mappings, m) { | ||||||
| 	SPA_FOR_EACH_ELEMENT(mappings, m) { |  | ||||||
| 		const char *value = pw_properties_get(s->props, m->pw_key); | 		const char *value = pw_properties_get(s->props, m->pw_key); | ||||||
| 		if (value != NULL) | 		if (value != NULL) | ||||||
| 			txt = avahi_string_list_add_pair(txt, m->txt_key, value); | 			txt = avahi_string_list_add_pair(txt, m->txt_key, value); | ||||||
|  |  | ||||||
|  | @ -262,14 +262,11 @@ static bool do_quit(struct data *data, const char *cmd, char *args, char **error | ||||||
| 
 | 
 | ||||||
| static bool do_help(struct data *data, const char *cmd, char *args, char **error) | static bool do_help(struct data *data, const char *cmd, char *args, char **error) | ||||||
| { | { | ||||||
| 	size_t i; |  | ||||||
| 
 |  | ||||||
| 	printf("Available commands:\n"); | 	printf("Available commands:\n"); | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(command_list); i++) { | 	SPA_FOR_EACH_ELEMENT_VAR(command_list, c) { | ||||||
| 		char cmd[256]; | 		char cmd[256]; | ||||||
| 		snprintf(cmd, sizeof(cmd), "%s | %s", | 		snprintf(cmd, sizeof(cmd), "%s | %s", c->name, c->alias); | ||||||
| 				command_list[i].name, command_list[i].alias); | 		printf("\t%-20.20s\t%s\n", cmd, c->description); | ||||||
| 		printf("\t%-20.20s\t%s\n", cmd, command_list[i].description); |  | ||||||
| 	} | 	} | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  | @ -1312,11 +1309,10 @@ static const struct class *classes[] = | ||||||
| 
 | 
 | ||||||
| static const struct class *find_class(const char *type, uint32_t version) | static const struct class *find_class(const char *type, uint32_t version) | ||||||
| { | { | ||||||
| 	size_t i; | 	SPA_FOR_EACH_ELEMENT_VAR(classes, c) { | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(classes); i++) { | 		if (spa_streq((*c)->type, type) && | ||||||
| 		if (spa_streq(classes[i]->type, type) && | 		    (*c)->version <= version) | ||||||
| 		    classes[i]->version <= version) | 			return *c; | ||||||
| 			return classes[i]; |  | ||||||
| 	} | 	} | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  | @ -2110,7 +2106,6 @@ static bool parse(struct data *data, char *buf, char **error) | ||||||
| { | { | ||||||
| 	char *a[2]; | 	char *a[2]; | ||||||
| 	int n; | 	int n; | ||||||
| 	size_t i; |  | ||||||
| 	char *p, *cmd, *args; | 	char *p, *cmd, *args; | ||||||
| 
 | 
 | ||||||
| 	if ((p = strchr(buf, '#'))) | 	if ((p = strchr(buf, '#'))) | ||||||
|  | @ -2128,10 +2123,10 @@ static bool parse(struct data *data, char *buf, char **error) | ||||||
| 	cmd = a[0]; | 	cmd = a[0]; | ||||||
| 	args = n > 1 ? a[1] : ""; | 	args = n > 1 ? a[1] : ""; | ||||||
| 
 | 
 | ||||||
| 	for (i = 0; i < SPA_N_ELEMENTS(command_list); i++) { | 	SPA_FOR_EACH_ELEMENT_VAR(command_list, c) { | ||||||
| 		if (spa_streq(command_list[i].name, cmd) || | 		if (spa_streq(c->name, cmd) || | ||||||
| 		    spa_streq(command_list[i].alias, cmd)) { | 		    spa_streq(c->alias, cmd)) { | ||||||
| 			return command_list[i].func(data, cmd, args, error); | 			return c->func(data, cmd, args, error); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|         *error = spa_aprintf("Command \"%s\" does not exist. Type 'help' for usage.", cmd); |         *error = spa_aprintf("Command \"%s\" does not exist. Type 'help' for usage.", cmd); | ||||||
|  |  | ||||||
|  | @ -358,16 +358,13 @@ pwtest_spa_plugin_new(void) | ||||||
| void | void | ||||||
| pwtest_spa_plugin_destroy(struct pwtest_spa_plugin *plugin) | pwtest_spa_plugin_destroy(struct pwtest_spa_plugin *plugin) | ||||||
| { | { | ||||||
| 	void **dll; | 	SPA_FOR_EACH_ELEMENT_VAR(plugin->handles, hnd) { | ||||||
| 	struct spa_handle **hnd; |  | ||||||
| 
 |  | ||||||
| 	SPA_FOR_EACH_ELEMENT(plugin->handles, hnd) { |  | ||||||
| 		if (*hnd) { | 		if (*hnd) { | ||||||
| 			spa_handle_clear(*hnd); | 			spa_handle_clear(*hnd); | ||||||
| 			free(*hnd); | 			free(*hnd); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	SPA_FOR_EACH_ELEMENT(plugin->dlls, dll) { | 	SPA_FOR_EACH_ELEMENT_VAR(plugin->dlls, dll) { | ||||||
| 		if (*dll) | 		if (*dll) | ||||||
| 			dlclose(*dll); | 			dlclose(*dll); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -184,9 +184,8 @@ PWTEST(utils_macros) | ||||||
| 
 | 
 | ||||||
| #define check_traversal(array_) \ | #define check_traversal(array_) \ | ||||||
| 	{ \ | 	{ \ | ||||||
| 		__typeof__(array_[0]) *it; \ |  | ||||||
| 		int count = 0; \ | 		int count = 0; \ | ||||||
| 		SPA_FOR_EACH_ELEMENT(array_, it) \ | 		SPA_FOR_EACH_ELEMENT_VAR(array_, it) \ | ||||||
| 			*it = count++; \ | 			*it = count++; \ | ||||||
| 		for (size_t i = 0; i < SPA_N_ELEMENTS(array_); i++) \ | 		for (size_t i = 0; i < SPA_N_ELEMENTS(array_); i++) \ | ||||||
| 			pwtest_int_eq(array_[i], i); \ | 			pwtest_int_eq(array_[i], i); \ | ||||||
|  |  | ||||||
|  | @ -172,9 +172,7 @@ static void test__pw_split_walk(void) | ||||||
| 		}, | 		}, | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	const struct test_case *tc; | 	SPA_FOR_EACH_ELEMENT_VAR(test_cases, tc) { | ||||||
| 
 |  | ||||||
| 	SPA_FOR_EACH_ELEMENT(test_cases, tc) { |  | ||||||
| 		const char *str = tc->input, *s; | 		const char *str = tc->input, *s; | ||||||
| 		const char *state = NULL; | 		const char *state = NULL; | ||||||
| 		size_t j = 0, len; | 		size_t j = 0, len; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Wim Taymans
						Wim Taymans