mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	module-eq: format floats as JSON floats
Don't use %f to serialize floats to JSON but use the json formatter because in some locales, the decimal point becomes a , which does not parse as a float anymore. Also reformat some lines. Fixes #4418
This commit is contained in:
		
							parent
							
								
									d2857c2129
								
							
						
					
					
						commit
						5a492c2265
					
				
					 1 changed files with 15 additions and 5 deletions
				
			
		| 
						 | 
					@ -8,6 +8,7 @@
 | 
				
			||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <spa/utils/result.h>
 | 
					#include <spa/utils/result.h>
 | 
				
			||||||
 | 
					#include <spa/utils/json.h>
 | 
				
			||||||
#include <spa/param/audio/raw.h>
 | 
					#include <spa/param/audio/raw.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <pipewire/impl.h>
 | 
					#include <pipewire/impl.h>
 | 
				
			||||||
| 
						 | 
					@ -147,7 +148,8 @@ static const struct pw_impl_module_events filter_chain_module_events = {
 | 
				
			||||||
	.destroy = filter_chain_module_destroy,
 | 
						.destroy = filter_chain_module_destroy,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void init_eq_node(FILE *f, const char *node_desc) {
 | 
					void init_eq_node(FILE *f, const char *node_desc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	fprintf(f, "{\n");
 | 
						fprintf(f, "{\n");
 | 
				
			||||||
	fprintf(f, "node.description = \"%s\"\n", node_desc);
 | 
						fprintf(f, "node.description = \"%s\"\n", node_desc);
 | 
				
			||||||
	fprintf(f, "media.name = \"%s\"\n", node_desc);
 | 
						fprintf(f, "media.name = \"%s\"\n", node_desc);
 | 
				
			||||||
| 
						 | 
					@ -155,7 +157,10 @@ void init_eq_node(FILE *f, const char *node_desc) {
 | 
				
			||||||
	fprintf(f, "nodes = [\n");
 | 
						fprintf(f, "nodes = [\n");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void add_eq_node(FILE *f, struct eq_node_param *param, uint32_t eq_band_idx) {
 | 
					void add_eq_node(FILE *f, struct eq_node_param *param, uint32_t eq_band_idx)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char str1[64], str2[64];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(f, "{\n");
 | 
						fprintf(f, "{\n");
 | 
				
			||||||
	fprintf(f, "type = builtin\n");
 | 
						fprintf(f, "type = builtin\n");
 | 
				
			||||||
	fprintf(f, "name = eq_band_%d\n", eq_band_idx);
 | 
						fprintf(f, "name = eq_band_%d\n", eq_band_idx);
 | 
				
			||||||
| 
						 | 
					@ -170,12 +175,15 @@ void add_eq_node(FILE *f, struct eq_node_param *param, uint32_t eq_band_idx) {
 | 
				
			||||||
		fprintf(f, "label = bq_peaking\n");
 | 
							fprintf(f, "label = bq_peaking\n");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(f, "control = { \"Freq\" = %d \"Q\" = %f \"Gain\" = %f }\n", param->freq, param->q_fact, param->gain);
 | 
						fprintf(f, "control = { \"Freq\" = %d \"Q\" = %s \"Gain\" = %s }\n", param->freq,
 | 
				
			||||||
 | 
								spa_json_format_float(str1, sizeof(str1), param->q_fact),
 | 
				
			||||||
 | 
								spa_json_format_float(str2, sizeof(str2), param->gain));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(f, "}\n");
 | 
						fprintf(f, "}\n");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void end_eq_node(struct impl *impl, FILE *f, uint32_t number_of_nodes) {
 | 
					void end_eq_node(struct impl *impl, FILE *f, uint32_t number_of_nodes)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	fprintf(f, "]\n");
 | 
						fprintf(f, "]\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(f, "links = [\n");
 | 
						fprintf(f, "links = [\n");
 | 
				
			||||||
| 
						 | 
					@ -266,7 +274,9 @@ int32_t parse_eq_filter_file(struct impl *impl, FILE *f)
 | 
				
			||||||
		 * Use a field width of 6 for gain and Q to account for any
 | 
							 * Use a field width of 6 for gain and Q to account for any
 | 
				
			||||||
		 * possible zeros.
 | 
							 * possible zeros.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (sscanf(line, "%*s %*d: %3s %3s %*s %5d %*s %*s %6f %*s %*c %6f", eq_param.filter, eq_param.filter_type, &eq_param.freq, &eq_param.gain, &eq_param.q_fact) == 5) {
 | 
							if (sscanf(line, "%*s %*d: %3s %3s %*s %5d %*s %*s %6f %*s %*c %6f",
 | 
				
			||||||
 | 
										eq_param.filter, eq_param.filter_type, &eq_param.freq,
 | 
				
			||||||
 | 
										&eq_param.gain, &eq_param.q_fact) == 5) {
 | 
				
			||||||
			if (strcmp(eq_param.filter, "ON") == 0) {
 | 
								if (strcmp(eq_param.filter, "ON") == 0) {
 | 
				
			||||||
				add_eq_node(memstream, &eq_param, eq_band_idx);
 | 
									add_eq_node(memstream, &eq_param, eq_band_idx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue