mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	settings: add default.clock.quantum-floor property
Remove some of the hardcoded values (the absolute smallest buffer size, independent on the sample rate) to a config option. Set it to the default value of 4, like what it was before. Change the hardcoded absolute lowest limit to 1 because anything else does not make sense. Enforce the quantum-floor when calculating the final graph quantum. Fixes #3908
This commit is contained in:
		
							parent
							
								
									d801654836
								
							
						
					
					
						commit
						436bd37342
					
				
					 6 changed files with 28 additions and 13 deletions
				
			
		| 
						 | 
					@ -177,7 +177,8 @@ the quantums.
 | 
				
			||||||
It is possible to specify up to 32 alternative sample rates. The graph
 | 
					It is possible to specify up to 32 alternative sample rates. The graph
 | 
				
			||||||
sample rate will be switched when devices are idle. Note that this is
 | 
					sample rate will be switched when devices are idle. Note that this is
 | 
				
			||||||
not enabled by default for now because of various kernel and Bluetooth
 | 
					not enabled by default for now because of various kernel and Bluetooth
 | 
				
			||||||
issues.
 | 
					issues. Note that the min/max/default quantum values are scaled when
 | 
				
			||||||
 | 
					the samplerate changes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@PAR@ pipewire.conf  default.clock.min-quantum = 32
 | 
					@PAR@ pipewire.conf  default.clock.min-quantum = 32
 | 
				
			||||||
Default minimum quantum.
 | 
					Default minimum quantum.
 | 
				
			||||||
| 
						 | 
					@ -189,7 +190,12 @@ Default maximum quantum.
 | 
				
			||||||
Default quantum used when no client specifies one.
 | 
					Default quantum used when no client specifies one.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@PAR@ pipewire.conf  default.clock.quantum-limit = 8192
 | 
					@PAR@ pipewire.conf  default.clock.quantum-limit = 8192
 | 
				
			||||||
Maximum quantum to reserve space for.
 | 
					Maximum quantum to reserve space for. This is the maximum buffer size used
 | 
				
			||||||
 | 
					in the graph, regardless of the samplerate.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@PAR@ pipewire.conf  default.clock.quantum-floor = 4
 | 
				
			||||||
 | 
					Minimum quantum to reserve space for. This is the minimum buffer size used
 | 
				
			||||||
 | 
					in the graph, regardless of the samplerate.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@PAR@ pipewire.conf  default.video.width
 | 
					@PAR@ pipewire.conf  default.video.width
 | 
				
			||||||
Default video width
 | 
					Default video width
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,6 +32,7 @@ context.properties = {
 | 
				
			||||||
    #default.clock.min-quantum   = 32
 | 
					    #default.clock.min-quantum   = 32
 | 
				
			||||||
    #default.clock.max-quantum   = 2048
 | 
					    #default.clock.max-quantum   = 2048
 | 
				
			||||||
    #default.clock.quantum-limit = 8192
 | 
					    #default.clock.quantum-limit = 8192
 | 
				
			||||||
 | 
					    #default.clock.quantum-floor = 4
 | 
				
			||||||
    #default.video.width         = 640
 | 
					    #default.video.width         = 640
 | 
				
			||||||
    #default.video.height        = 480
 | 
					    #default.video.height        = 480
 | 
				
			||||||
    #default.video.rate.num      = 25
 | 
					    #default.video.rate.num      = 25
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,6 +32,7 @@ context.properties = {
 | 
				
			||||||
    #default.clock.min-quantum   = 32
 | 
					    #default.clock.min-quantum   = 32
 | 
				
			||||||
    #default.clock.max-quantum   = 2048
 | 
					    #default.clock.max-quantum   = 2048
 | 
				
			||||||
    #default.clock.quantum-limit = 8192
 | 
					    #default.clock.quantum-limit = 8192
 | 
				
			||||||
 | 
					    #default.clock.quantum-floor = 4
 | 
				
			||||||
    #default.video.width         = 640
 | 
					    #default.video.width         = 640
 | 
				
			||||||
    #default.video.height        = 480
 | 
					    #default.video.height        = 480
 | 
				
			||||||
    #default.video.rate.num      = 25
 | 
					    #default.video.rate.num      = 25
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -994,7 +994,7 @@ static void remove_from_driver(struct pw_context *context, struct spa_list *node
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline void get_quantums(struct pw_context *context, uint32_t *def,
 | 
					static inline void get_quantums(struct pw_context *context, uint32_t *def,
 | 
				
			||||||
		uint32_t *min, uint32_t *max, uint32_t *limit, uint32_t *rate)
 | 
							uint32_t *min, uint32_t *max, uint32_t *rate, uint32_t *floor, uint32_t *ceil)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct settings *s = &context->settings;
 | 
						struct settings *s = &context->settings;
 | 
				
			||||||
	if (s->clock_force_quantum != 0) {
 | 
						if (s->clock_force_quantum != 0) {
 | 
				
			||||||
| 
						 | 
					@ -1006,7 +1006,8 @@ static inline void get_quantums(struct pw_context *context, uint32_t *def,
 | 
				
			||||||
		*max = s->clock_max_quantum;
 | 
							*max = s->clock_max_quantum;
 | 
				
			||||||
		*rate = s->clock_rate;
 | 
							*rate = s->clock_rate;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	*limit = s->clock_quantum_limit;
 | 
						*floor = s->clock_quantum_floor;
 | 
				
			||||||
 | 
						*ceil = s->clock_quantum_limit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline const uint32_t *get_rates(struct pw_context *context, uint32_t *def, uint32_t *n_rates,
 | 
					static inline const uint32_t *get_rates(struct pw_context *context, uint32_t *def, uint32_t *n_rates,
 | 
				
			||||||
| 
						 | 
					@ -1199,7 +1200,7 @@ int pw_context_recalc_graph(struct pw_context *context, const char *reason)
 | 
				
			||||||
	struct settings *settings = &context->settings;
 | 
						struct settings *settings = &context->settings;
 | 
				
			||||||
	struct pw_impl_node *n, *s, *target, *fallback;
 | 
						struct pw_impl_node *n, *s, *target, *fallback;
 | 
				
			||||||
	const uint32_t *rates;
 | 
						const uint32_t *rates;
 | 
				
			||||||
	uint32_t max_quantum, min_quantum, def_quantum, lim_quantum, rate_quantum;
 | 
						uint32_t max_quantum, min_quantum, def_quantum, rate_quantum, floor_quantum, ceil_quantum;
 | 
				
			||||||
	uint32_t n_rates, def_rate;
 | 
						uint32_t n_rates, def_rate;
 | 
				
			||||||
	bool freewheel = false, global_force_rate, global_force_quantum;
 | 
						bool freewheel = false, global_force_rate, global_force_quantum;
 | 
				
			||||||
	struct spa_list collect;
 | 
						struct spa_list collect;
 | 
				
			||||||
| 
						 | 
					@ -1221,7 +1222,8 @@ again:
 | 
				
			||||||
		n->runnable = n->always_process && n->active;
 | 
							n->runnable = n->always_process && n->active;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	get_quantums(context, &def_quantum, &min_quantum, &max_quantum, &lim_quantum, &rate_quantum);
 | 
						get_quantums(context, &def_quantum, &min_quantum, &max_quantum, &rate_quantum,
 | 
				
			||||||
 | 
								&floor_quantum, &ceil_quantum);
 | 
				
			||||||
	rates = get_rates(context, &def_rate, &n_rates, &global_force_rate);
 | 
						rates = get_rates(context, &def_rate, &n_rates, &global_force_rate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	global_force_quantum = rate_quantum == 0;
 | 
						global_force_quantum = rate_quantum == 0;
 | 
				
			||||||
| 
						 | 
					@ -1500,7 +1502,7 @@ again:
 | 
				
			||||||
			if (latency.denom != 0)
 | 
								if (latency.denom != 0)
 | 
				
			||||||
				target_quantum = (latency.num * current_rate / latency.denom);
 | 
									target_quantum = (latency.num * current_rate / latency.denom);
 | 
				
			||||||
			target_quantum = SPA_CLAMP(target_quantum, node_min_quantum, node_max_quantum);
 | 
								target_quantum = SPA_CLAMP(target_quantum, node_min_quantum, node_max_quantum);
 | 
				
			||||||
			target_quantum = SPA_MIN(target_quantum, lim_quantum);
 | 
								target_quantum = SPA_CLAMP(target_quantum, floor_quantum, ceil_quantum);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (settings->clock_power_of_two_quantum && !force_quantum)
 | 
								if (settings->clock_power_of_two_quantum && !force_quantum)
 | 
				
			||||||
				target_quantum = flp2(target_quantum);
 | 
									target_quantum = flp2(target_quantum);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,8 +28,8 @@ struct ucred {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAX_RATES				32u
 | 
					#define MAX_RATES				32u
 | 
				
			||||||
#define CLOCK_MIN_QUANTUM			4u
 | 
					#define CLOCK_QUANTUM_FLOOR			1u
 | 
				
			||||||
#define CLOCK_MAX_QUANTUM			65536u
 | 
					#define CLOCK_QUANTUM_LIMIT			65536u
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct settings {
 | 
					struct settings {
 | 
				
			||||||
	uint32_t log_level;
 | 
						uint32_t log_level;
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,8 @@ struct settings {
 | 
				
			||||||
	uint32_t clock_quantum;			/* default quantum */
 | 
						uint32_t clock_quantum;			/* default quantum */
 | 
				
			||||||
	uint32_t clock_min_quantum;		/* min quantum */
 | 
						uint32_t clock_min_quantum;		/* min quantum */
 | 
				
			||||||
	uint32_t clock_max_quantum;		/* max quantum */
 | 
						uint32_t clock_max_quantum;		/* max quantum */
 | 
				
			||||||
	uint32_t clock_quantum_limit;		/* quantum limit */
 | 
						uint32_t clock_quantum_limit;		/* quantum limit (upper bound) */
 | 
				
			||||||
 | 
						uint32_t clock_quantum_floor;		/* quantum floor (lower bound) */
 | 
				
			||||||
	struct spa_rectangle video_size;
 | 
						struct spa_rectangle video_size;
 | 
				
			||||||
	struct spa_fraction video_rate;
 | 
						struct spa_fraction video_rate;
 | 
				
			||||||
	uint32_t link_max_buffers;
 | 
						uint32_t link_max_buffers;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,7 @@
 | 
				
			||||||
#define DEFAULT_CLOCK_MIN_QUANTUM		32u
 | 
					#define DEFAULT_CLOCK_MIN_QUANTUM		32u
 | 
				
			||||||
#define DEFAULT_CLOCK_MAX_QUANTUM		2048u
 | 
					#define DEFAULT_CLOCK_MAX_QUANTUM		2048u
 | 
				
			||||||
#define DEFAULT_CLOCK_QUANTUM_LIMIT		8192u
 | 
					#define DEFAULT_CLOCK_QUANTUM_LIMIT		8192u
 | 
				
			||||||
 | 
					#define DEFAULT_CLOCK_QUANTUM_FLOOR		4u
 | 
				
			||||||
#define DEFAULT_CLOCK_POWER_OF_TWO_QUANTUM	true
 | 
					#define DEFAULT_CLOCK_POWER_OF_TWO_QUANTUM	true
 | 
				
			||||||
#define DEFAULT_VIDEO_WIDTH			640
 | 
					#define DEFAULT_VIDEO_WIDTH			640
 | 
				
			||||||
#define DEFAULT_VIDEO_HEIGHT			480
 | 
					#define DEFAULT_VIDEO_HEIGHT			480
 | 
				
			||||||
| 
						 | 
					@ -212,6 +213,7 @@ void pw_settings_init(struct pw_context *this)
 | 
				
			||||||
	d->clock_min_quantum = get_default_int(p, "default.clock.min-quantum", DEFAULT_CLOCK_MIN_QUANTUM);
 | 
						d->clock_min_quantum = get_default_int(p, "default.clock.min-quantum", DEFAULT_CLOCK_MIN_QUANTUM);
 | 
				
			||||||
	d->clock_max_quantum = get_default_int(p, "default.clock.max-quantum", DEFAULT_CLOCK_MAX_QUANTUM);
 | 
						d->clock_max_quantum = get_default_int(p, "default.clock.max-quantum", DEFAULT_CLOCK_MAX_QUANTUM);
 | 
				
			||||||
	d->clock_quantum_limit = get_default_int(p, "default.clock.quantum-limit", DEFAULT_CLOCK_QUANTUM_LIMIT);
 | 
						d->clock_quantum_limit = get_default_int(p, "default.clock.quantum-limit", DEFAULT_CLOCK_QUANTUM_LIMIT);
 | 
				
			||||||
 | 
						d->clock_quantum_floor = get_default_int(p, "default.clock.quantum-floor", DEFAULT_CLOCK_QUANTUM_FLOOR);
 | 
				
			||||||
	d->video_size.width = get_default_int(p, "default.video.width", DEFAULT_VIDEO_WIDTH);
 | 
						d->video_size.width = get_default_int(p, "default.video.width", DEFAULT_VIDEO_WIDTH);
 | 
				
			||||||
	d->video_size.height = get_default_int(p, "default.video.height", DEFAULT_VIDEO_HEIGHT);
 | 
						d->video_size.height = get_default_int(p, "default.video.height", DEFAULT_VIDEO_HEIGHT);
 | 
				
			||||||
	d->video_rate.num = get_default_int(p, "default.video.rate.num", DEFAULT_VIDEO_RATE_NUM);
 | 
						d->video_rate.num = get_default_int(p, "default.video.rate.num", DEFAULT_VIDEO_RATE_NUM);
 | 
				
			||||||
| 
						 | 
					@ -228,11 +230,13 @@ void pw_settings_init(struct pw_context *this)
 | 
				
			||||||
	d->check_rate = get_default_bool(p, "settings.check-rate", DEFAULT_CHECK_RATE);
 | 
						d->check_rate = get_default_bool(p, "settings.check-rate", DEFAULT_CHECK_RATE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	d->clock_quantum_limit = SPA_CLAMP(d->clock_quantum_limit,
 | 
						d->clock_quantum_limit = SPA_CLAMP(d->clock_quantum_limit,
 | 
				
			||||||
			CLOCK_MIN_QUANTUM, CLOCK_MAX_QUANTUM);
 | 
								CLOCK_QUANTUM_FLOOR, CLOCK_QUANTUM_LIMIT);
 | 
				
			||||||
 | 
						d->clock_quantum_floor = SPA_CLAMP(d->clock_quantum_floor,
 | 
				
			||||||
 | 
								CLOCK_QUANTUM_FLOOR, d->clock_quantum_limit);
 | 
				
			||||||
	d->clock_max_quantum = SPA_CLAMP(d->clock_max_quantum,
 | 
						d->clock_max_quantum = SPA_CLAMP(d->clock_max_quantum,
 | 
				
			||||||
			CLOCK_MIN_QUANTUM, d->clock_quantum_limit);
 | 
								d->clock_quantum_floor, d->clock_quantum_limit);
 | 
				
			||||||
	d->clock_min_quantum = SPA_CLAMP(d->clock_min_quantum,
 | 
						d->clock_min_quantum = SPA_CLAMP(d->clock_min_quantum,
 | 
				
			||||||
			CLOCK_MIN_QUANTUM, d->clock_max_quantum);
 | 
								d->clock_quantum_floor, d->clock_max_quantum);
 | 
				
			||||||
	d->clock_quantum = SPA_CLAMP(d->clock_quantum,
 | 
						d->clock_quantum = SPA_CLAMP(d->clock_quantum,
 | 
				
			||||||
			d->clock_min_quantum, d->clock_max_quantum);
 | 
								d->clock_min_quantum, d->clock_max_quantum);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue