mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
plugins: simplify target_ handling
Drivers should only read the target_ values in the timeout, update the timeout with the new duration and then update the position. For the position we simply need to add the previous duration to the position and then set the new duration + rate. Otherwise, everything else should read the duration/rate and not use the target_ values.
This commit is contained in:
parent
f309543810
commit
7b6680ba57
13 changed files with 132 additions and 154 deletions
|
|
@ -989,11 +989,8 @@ 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;
|
||||
duration = this->position->clock.target_duration;
|
||||
rate = this->position->clock.target_rate.denom;
|
||||
} else {
|
||||
duration = 1024;
|
||||
rate = 48000;
|
||||
|
|
@ -1005,7 +1002,8 @@ static void media_on_timeout(struct spa_source *source)
|
|||
int64_t delay_nsec = 0;
|
||||
|
||||
this->clock->nsec = now_time;
|
||||
this->clock->position += duration;
|
||||
this->clock->rate = this->clock->target_rate;
|
||||
this->clock->position += this->clock->duration;
|
||||
this->clock->duration = duration;
|
||||
this->clock->rate_diff = 1.0f;
|
||||
this->clock->next_nsec = this->next_time;
|
||||
|
|
|
|||
|
|
@ -612,28 +612,26 @@ 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;
|
||||
duration = this->position->clock.target_duration;
|
||||
rate = this->position->clock.target_rate.denom;
|
||||
} else {
|
||||
duration = 1024;
|
||||
rate = 48000;
|
||||
}
|
||||
|
||||
setup_matching(this);
|
||||
|
||||
this->next_time = now_time + duration * SPA_NSEC_PER_SEC / port->buffer.corr / rate;
|
||||
|
||||
if (SPA_LIKELY(this->clock)) {
|
||||
this->clock->nsec = now_time;
|
||||
this->clock->position += duration;
|
||||
this->clock->rate = this->clock->target_rate;
|
||||
this->clock->position += this->clock->duration;
|
||||
this->clock->duration = duration;
|
||||
this->clock->rate_diff = port->buffer.corr;
|
||||
this->clock->next_nsec = this->next_time;
|
||||
}
|
||||
|
||||
setup_matching(this);
|
||||
|
||||
if (port->io) {
|
||||
int io_status = port->io->status;
|
||||
int status = produce_buffer(this);
|
||||
|
|
@ -1326,30 +1324,27 @@ static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t
|
|||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t get_samples(struct impl *this, uint32_t *duration)
|
||||
static uint32_t get_samples(struct impl *this, uint32_t *result_duration)
|
||||
{
|
||||
struct port *port = &this->port;
|
||||
uint32_t samples;
|
||||
uint32_t samples, rate_denom;
|
||||
uint64_t duration;
|
||||
|
||||
if (SPA_LIKELY(this->position)) {
|
||||
duration = this->position->clock.duration;
|
||||
rate_denom = this->position->clock.rate.denom;
|
||||
} else {
|
||||
duration = 1024;
|
||||
rate_denom = port->current_format.info.raw.rate;
|
||||
}
|
||||
|
||||
*result_duration = duration * port->current_format.info.raw.rate / rate_denom;
|
||||
|
||||
if (SPA_LIKELY(port->rate_match) && this->resampling) {
|
||||
samples = port->rate_match->size;
|
||||
} else {
|
||||
if (SPA_LIKELY(this->position))
|
||||
samples = this->position->clock.duration * port->current_format.info.raw.rate
|
||||
/ this->position->clock.rate.denom;
|
||||
else
|
||||
samples = 1024;
|
||||
samples = *result_duration;
|
||||
}
|
||||
|
||||
if (SPA_LIKELY(this->position))
|
||||
*duration = this->position->clock.duration * port->current_format.info.raw.rate
|
||||
/ this->position->clock.rate.denom;
|
||||
else if (SPA_LIKELY(this->clock))
|
||||
*duration = this->clock->duration * port->current_format.info.raw.rate
|
||||
/ this->clock->rate.denom;
|
||||
else
|
||||
*duration = 1024 * port->current_format.info.raw.rate / 48000;
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -838,14 +838,6 @@ 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)) {
|
||||
|
|
@ -876,15 +868,20 @@ 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);
|
||||
if (SPA_LIKELY(this->position)) {
|
||||
this->duration = this->position->clock.target_duration;
|
||||
this->rate = this->position->clock.target_rate.denom;
|
||||
} else {
|
||||
this->duration = 1024;
|
||||
this->rate = 48000;
|
||||
}
|
||||
|
||||
this->next_time = now_time + this->duration * SPA_NSEC_PER_SEC / this->rate;
|
||||
|
||||
if (SPA_LIKELY(this->clock)) {
|
||||
this->clock->nsec = now_time;
|
||||
this->clock->position += this->duration;
|
||||
this->clock->rate = this->clock->target_rate;
|
||||
this->clock->position += this->clock->duration;
|
||||
this->clock->duration = this->duration;
|
||||
this->clock->rate_diff = 1.0f;
|
||||
this->clock->next_nsec = this->next_time;
|
||||
|
|
@ -1171,9 +1168,6 @@ 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,11 +603,8 @@ 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;
|
||||
duration = this->position->clock.target_duration;
|
||||
rate = this->position->clock.target_rate.denom;
|
||||
} else {
|
||||
duration = 1024;
|
||||
rate = 48000;
|
||||
|
|
@ -617,7 +614,8 @@ static void sco_on_timeout(struct spa_source *source)
|
|||
|
||||
if (SPA_LIKELY(this->clock)) {
|
||||
this->clock->nsec = now_time;
|
||||
this->clock->position += duration;
|
||||
this->clock->rate = this->clock->target_rate;
|
||||
this->clock->position += this->clock->duration;
|
||||
this->clock->duration = duration;
|
||||
this->clock->rate_diff = 1.0f;
|
||||
this->clock->next_nsec = this->next_time;
|
||||
|
|
|
|||
|
|
@ -611,28 +611,26 @@ 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;
|
||||
duration = this->position->clock.target_duration;
|
||||
rate = this->position->clock.target_rate.denom;
|
||||
} else {
|
||||
duration = 1024;
|
||||
rate = 48000;
|
||||
}
|
||||
|
||||
setup_matching(this);
|
||||
|
||||
this->next_time = now_time + duration * SPA_NSEC_PER_SEC / port->buffer.corr / rate;
|
||||
|
||||
if (SPA_LIKELY(this->clock)) {
|
||||
this->clock->nsec = now_time;
|
||||
this->clock->position += duration;
|
||||
this->clock->rate = this->clock->target_rate;
|
||||
this->clock->position += this->clock->duration;
|
||||
this->clock->duration = duration;
|
||||
this->clock->rate_diff = port->buffer.corr;
|
||||
this->clock->next_nsec = this->next_time;
|
||||
}
|
||||
|
||||
setup_matching(this);
|
||||
|
||||
if (port->io) {
|
||||
int io_status = port->io->status;
|
||||
int status = produce_buffer(this);
|
||||
|
|
@ -1281,29 +1279,26 @@ static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t
|
|||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t get_samples(struct impl *this, uint32_t *duration)
|
||||
static uint32_t get_samples(struct impl *this, uint32_t *result_duration)
|
||||
{
|
||||
struct port *port = &this->port;
|
||||
uint32_t samples;
|
||||
uint32_t samples, rate_denom;
|
||||
uint64_t duration;
|
||||
|
||||
if (SPA_LIKELY(port->rate_match) && this->resampling) {
|
||||
samples = port->rate_match->size;
|
||||
if (SPA_LIKELY(this->position)) {
|
||||
duration = this->position->clock.duration;
|
||||
rate_denom = this->position->clock.rate.denom;
|
||||
} else {
|
||||
if (SPA_LIKELY(this->position))
|
||||
samples = this->position->clock.duration * port->current_format.info.raw.rate
|
||||
/ this->position->clock.rate.denom;
|
||||
else
|
||||
samples = 1024;
|
||||
duration = 1024;
|
||||
rate_denom = port->current_format.info.raw.rate;
|
||||
}
|
||||
|
||||
if (SPA_LIKELY(this->position))
|
||||
*duration = this->position->clock.duration * port->current_format.info.raw.rate
|
||||
/ this->position->clock.rate.denom;
|
||||
else if (SPA_LIKELY(this->clock))
|
||||
*duration = this->clock->duration * port->current_format.info.raw.rate
|
||||
/ this->clock->rate.denom;
|
||||
*result_duration = duration * port->current_format.info.raw.rate / rate_denom;
|
||||
|
||||
if (SPA_LIKELY(port->rate_match) && this->resampling)
|
||||
samples = port->rate_match->size;
|
||||
else
|
||||
*duration = 1024 * port->current_format.info.raw.rate / 48000;
|
||||
samples = *result_duration;
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue