mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
audioconvert: don't use uninitialized max_out
Move the calculation of the expected max output size before collecting the buffers and doing the monitor ports so that we can get the size correct.
This commit is contained in:
parent
e53eefef0d
commit
a1fac201e3
1 changed files with 45 additions and 42 deletions
|
|
@ -2246,6 +2246,33 @@ static int impl_node_process(void *object)
|
|||
struct spa_io_buffers *io, *ctrlio = NULL;
|
||||
const struct spa_pod_sequence *ctrl = NULL;
|
||||
|
||||
/* calculate quantum scale, this is how many samples we need to produce or
|
||||
* consume. Also update the rate scale, this is sent to the resampler to adjust
|
||||
* the rate, either when the graph clock changed or when the user adjusted the
|
||||
* rate. */
|
||||
if (SPA_LIKELY(this->io_position)) {
|
||||
double r = this->rate_scale;
|
||||
|
||||
quant_samples = this->io_position->clock.duration;
|
||||
if (this->direction == SPA_DIRECTION_INPUT) {
|
||||
if (this->io_position->clock.rate.denom != this->resample.o_rate)
|
||||
r = (double) this->io_position->clock.rate.denom / this->resample.o_rate;
|
||||
else
|
||||
r = 1.0;
|
||||
} else {
|
||||
if (this->io_position->clock.rate.denom != this->resample.i_rate)
|
||||
r = (double) this->resample.i_rate / this->io_position->clock.rate.denom;
|
||||
else
|
||||
r = 1.0;
|
||||
}
|
||||
if (this->rate_scale != r) {
|
||||
spa_log_info(this->log, "scale %f->%f", this->rate_scale, r);
|
||||
this->rate_scale = r;
|
||||
}
|
||||
}
|
||||
else
|
||||
quant_samples = this->quantum_limit;
|
||||
|
||||
dir = &this->dir[SPA_DIRECTION_INPUT];
|
||||
in_passthrough = dir->conv.is_passthrough;
|
||||
max_in = UINT32_MAX;
|
||||
|
|
@ -2335,6 +2362,19 @@ static int impl_node_process(void *object)
|
|||
}
|
||||
}
|
||||
|
||||
/* calculate how many samples we are going to produce. */
|
||||
if (this->direction == SPA_DIRECTION_INPUT) {
|
||||
/* in split mode we need to output exactly the size of the
|
||||
* duration so we don't try to flush early */
|
||||
max_out = quant_samples;
|
||||
flush_out = false;
|
||||
} else {
|
||||
/* in merge mode we consume one duration of samples and
|
||||
* always output the resulting data */
|
||||
max_out = this->quantum_limit;
|
||||
flush_out = true;
|
||||
}
|
||||
|
||||
dir = &this->dir[SPA_DIRECTION_OUTPUT];
|
||||
/* collect output ports and monitor ports data */
|
||||
for (i = 0; i < dir->n_ports; i++) {
|
||||
|
|
@ -2414,33 +2454,6 @@ static int impl_node_process(void *object)
|
|||
}
|
||||
}
|
||||
|
||||
/* calculate quantum scale, this is how many samples we need to produce or
|
||||
* consume. Also update the rate scale, this is sent to the resampler to adjust
|
||||
* the rate, either when the graph clock changed or when the user adjusted the
|
||||
* rate. */
|
||||
if (SPA_LIKELY(this->io_position)) {
|
||||
double r = this->rate_scale;
|
||||
|
||||
quant_samples = this->io_position->clock.duration;
|
||||
if (this->direction == SPA_DIRECTION_INPUT) {
|
||||
if (this->io_position->clock.rate.denom != this->resample.o_rate)
|
||||
r = (double) this->io_position->clock.rate.denom / this->resample.o_rate;
|
||||
else
|
||||
r = 1.0;
|
||||
} else {
|
||||
if (this->io_position->clock.rate.denom != this->resample.i_rate)
|
||||
r = (double) this->resample.i_rate / this->io_position->clock.rate.denom;
|
||||
else
|
||||
r = 1.0;
|
||||
}
|
||||
if (this->rate_scale != r) {
|
||||
spa_log_info(this->log, "scale %f->%f", this->rate_scale, r);
|
||||
this->rate_scale = r;
|
||||
}
|
||||
}
|
||||
else
|
||||
quant_samples = this->quantum_limit;
|
||||
|
||||
|
||||
/* calculate how many samples at most we are going to consume. If we're
|
||||
* draining, we consume as much as we can. Otherwise we consume what is
|
||||
|
|
@ -2450,21 +2463,14 @@ static int impl_node_process(void *object)
|
|||
else {
|
||||
n_samples = max_in - SPA_MIN(max_in, this->in_offset);
|
||||
}
|
||||
/* we only need to output the remaining samples */
|
||||
n_out = max_out - SPA_MIN(max_out, this->out_offset);
|
||||
|
||||
resample_passthrough = resample_is_passthrough(this);
|
||||
|
||||
/* calculate how many samples we are going to produce. */
|
||||
/* calculate how many samples we are going to consume. */
|
||||
if (this->direction == SPA_DIRECTION_INPUT) {
|
||||
uint32_t n_in;
|
||||
|
||||
/* in split mode we need to output exactly the size of the
|
||||
* duration so we don't try to flush early */
|
||||
max_out = SPA_MIN(max_out, quant_samples);
|
||||
flush_out = false;
|
||||
|
||||
/* we only need to output the remaining of those samples */
|
||||
n_out = max_out - SPA_MIN(max_out, this->out_offset);
|
||||
|
||||
/* then figure out how much input samples we need to consume */
|
||||
n_in = resample_update_rate_match(this, resample_passthrough, n_out, 0);
|
||||
if (!in_avail || this->drained) {
|
||||
|
|
@ -2475,12 +2481,9 @@ static int impl_node_process(void *object)
|
|||
}
|
||||
n_samples = SPA_MIN(n_samples, n_in);
|
||||
} else {
|
||||
/* in merge mode we consume one duration of samples and
|
||||
* always output the resulting data */
|
||||
/* in merge mode we consume one duration of samples */
|
||||
n_samples = SPA_MIN(n_samples, quant_samples);
|
||||
max_out = SPA_MIN(max_out, this->quantum_limit);
|
||||
n_out = max_out - SPA_MIN(max_out, this->out_offset);
|
||||
flush_out = flush_in = true;
|
||||
flush_in = true;
|
||||
}
|
||||
|
||||
mix_passthrough = SPA_FLAG_IS_SET(this->mix.flags, CHANNELMIX_FLAG_IDENTITY) &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue