mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	node: update the duration/rate from the target
Before scheduling the graph from the driver, update the duration and rate with the new targets.
This commit is contained in:
		
							parent
							
								
									1bdd5eee69
								
							
						
					
					
						commit
						6e8625cf96
					
				
					 13 changed files with 87 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -702,6 +702,10 @@ static void on_driver_timeout(struct spa_source *source)
 | 
			
		|||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (SPA_LIKELY(this->node_position_io != NULL)) {
 | 
			
		||||
		this->node_position_io->clock.duration = this->node_position_io->clock.target_duration;
 | 
			
		||||
		this->node_position_io->clock.rate = this->node_position_io->clock.target_rate;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	check_position_and_clock_config(this);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -682,9 +682,18 @@ static int process_write(struct seq_state *state)
 | 
			
		|||
	return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void update_target(struct seq_state *state)
 | 
			
		||||
{
 | 
			
		||||
	if (SPA_LIKELY(state->position)) {
 | 
			
		||||
		struct spa_io_clock *clock = &state->position->clock;
 | 
			
		||||
		clock->duration = clock->target_duration;
 | 
			
		||||
		clock->rate = clock->target_rate;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void update_position(struct seq_state *state)
 | 
			
		||||
{
 | 
			
		||||
	if (state->position) {
 | 
			
		||||
	if (SPA_LIKELY(state->position)) {
 | 
			
		||||
		struct spa_io_clock *clock = &state->position->clock;
 | 
			
		||||
		state->rate = clock->rate;
 | 
			
		||||
		if (state->rate.num == 0 || state->rate.denom == 0)
 | 
			
		||||
| 
						 | 
				
			
			@ -789,6 +798,8 @@ static void alsa_on_timeout_event(struct spa_source *source)
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	update_target(state);
 | 
			
		||||
 | 
			
		||||
	state->current_time = state->next_time;
 | 
			
		||||
 | 
			
		||||
	spa_log_trace(state->log, "timeout %"PRIu64, state->current_time);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -345,6 +345,14 @@ static int read_timer(struct impl *this)
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void update_target(struct impl *this)
 | 
			
		||||
{
 | 
			
		||||
	if (this->position) {
 | 
			
		||||
		this->position->clock.duration = this->position->clock.target_duration;
 | 
			
		||||
		this->position->clock.rate = this->position->clock.target_rate;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int make_buffer(struct impl *this)
 | 
			
		||||
{
 | 
			
		||||
	struct buffer *b;
 | 
			
		||||
| 
						 | 
				
			
			@ -424,6 +432,8 @@ static void on_output(struct spa_source *source)
 | 
			
		|||
	struct impl *this = source->data;
 | 
			
		||||
	int res;
 | 
			
		||||
 | 
			
		||||
	update_target(this);
 | 
			
		||||
 | 
			
		||||
	res = make_buffer(this);
 | 
			
		||||
 | 
			
		||||
	if (res == SPA_STATUS_HAVE_DATA)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1042,6 +1042,9 @@ static void avb_on_timeout_event(struct spa_source *source)
 | 
			
		|||
 | 
			
		||||
	current_time = state->next_time;
 | 
			
		||||
	if (SPA_LIKELY(state->position)) {
 | 
			
		||||
		state->position->clock.duration = state->position->clock.target_duration;
 | 
			
		||||
		state->position->clock.rate = state->position->clock.target_rate;
 | 
			
		||||
 | 
			
		||||
		duration = state->position->clock.duration;
 | 
			
		||||
		rate = state->position->clock.rate.denom;
 | 
			
		||||
	} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -989,6 +989,9 @@ static void media_on_timeout(struct spa_source *source)
 | 
			
		|||
			now_time, now_time - prev_time);
 | 
			
		||||
 | 
			
		||||
	if (SPA_LIKELY(this->position)) {
 | 
			
		||||
		this->position->clock.duration = this->position->clock.target_duration;
 | 
			
		||||
		this->position->clock.rate = this->position->clock.target_rate;
 | 
			
		||||
 | 
			
		||||
		duration = this->position->clock.duration;
 | 
			
		||||
		rate = this->position->clock.rate.denom;
 | 
			
		||||
	} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -612,6 +612,9 @@ static void media_on_timeout(struct spa_source *source)
 | 
			
		|||
			now_time, now_time - prev_time);
 | 
			
		||||
 | 
			
		||||
	if (SPA_LIKELY(this->position)) {
 | 
			
		||||
		this->position->clock.duration = this->position->clock.target_duration;
 | 
			
		||||
		this->position->clock.rate = this->position->clock.target_rate;
 | 
			
		||||
 | 
			
		||||
		duration = this->position->clock.duration;
 | 
			
		||||
		rate = this->position->clock.rate.denom;
 | 
			
		||||
	} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -838,6 +838,14 @@ static int process_input(struct impl *this)
 | 
			
		|||
	return SPA_STATUS_HAVE_DATA;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void update_target(struct impl *this)
 | 
			
		||||
{
 | 
			
		||||
	if (SPA_LIKELY(this->position)) {
 | 
			
		||||
		this->position->clock.duration = this->position->clock.target_duration;
 | 
			
		||||
		this->position->clock.rate = this->position->clock.target_rate;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void update_position(struct impl *this)
 | 
			
		||||
{
 | 
			
		||||
	if (SPA_LIKELY(this->position)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -868,6 +876,8 @@ static void on_timeout(struct spa_source *source)
 | 
			
		|||
	spa_log_trace(this->log, "%p: timer %"PRIu64" %"PRIu64"", this,
 | 
			
		||||
			now_time, now_time - prev_time);
 | 
			
		||||
 | 
			
		||||
	update_target(this);
 | 
			
		||||
 | 
			
		||||
	update_position(this);
 | 
			
		||||
 | 
			
		||||
	this->next_time = now_time + this->duration * SPA_NSEC_PER_SEC / this->rate;
 | 
			
		||||
| 
						 | 
				
			
			@ -1161,6 +1171,9 @@ static int do_start(struct impl *this)
 | 
			
		|||
 | 
			
		||||
	this->following = is_following(this);
 | 
			
		||||
 | 
			
		||||
	if (!this->following)
 | 
			
		||||
		update_target(this);
 | 
			
		||||
 | 
			
		||||
	update_position(this);
 | 
			
		||||
 | 
			
		||||
	spa_log_debug(this->log, "%p: start following:%d",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -603,6 +603,9 @@ static void sco_on_timeout(struct spa_source *source)
 | 
			
		|||
			now_time, now_time - prev_time);
 | 
			
		||||
 | 
			
		||||
	if (SPA_LIKELY(this->position)) {
 | 
			
		||||
		this->position->clock.duration = this->position->clock.target_duration;
 | 
			
		||||
		this->position->clock.rate = this->position->clock.target_rate;
 | 
			
		||||
 | 
			
		||||
		duration = this->position->clock.duration;
 | 
			
		||||
		rate = this->position->clock.rate.denom;
 | 
			
		||||
	} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -611,6 +611,9 @@ static void sco_on_timeout(struct spa_source *source)
 | 
			
		|||
			now_time, now_time - prev_time);
 | 
			
		||||
 | 
			
		||||
	if (SPA_LIKELY(this->position)) {
 | 
			
		||||
		this->position->clock.duration = this->position->clock.target_duration;
 | 
			
		||||
		this->position->clock.rate = this->position->clock.target_rate;
 | 
			
		||||
 | 
			
		||||
		duration = this->position->clock.duration;
 | 
			
		||||
		rate = this->position->clock.rate.denom;
 | 
			
		||||
	} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -247,6 +247,9 @@ static void on_timeout(struct spa_source *source)
 | 
			
		|||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	if (SPA_LIKELY(this->position)) {
 | 
			
		||||
		this->position->clock.duration = this->position->clock.target_duration;
 | 
			
		||||
		this->position->clock.rate = this->position->clock.target_rate;
 | 
			
		||||
 | 
			
		||||
		duration = this->position->clock.duration;
 | 
			
		||||
		rate = this->position->clock.rate.denom;
 | 
			
		||||
	} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -280,6 +280,9 @@ static void on_timeout(struct spa_source *source)
 | 
			
		|||
	nsec = this->next_time;
 | 
			
		||||
 | 
			
		||||
	if (SPA_LIKELY(this->position)) {
 | 
			
		||||
		this->position->clock.duration = this->position->clock.target_duration;
 | 
			
		||||
		this->position->clock.rate = this->position->clock.target_rate;
 | 
			
		||||
 | 
			
		||||
		duration = this->position->clock.duration;
 | 
			
		||||
		rate = this->position->clock.rate.denom;
 | 
			
		||||
	} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue