bluez5: media-sink: fix bitpool increase

The free buffer check must happen before writing to check for leftover data in buffers. In case data is left over from previous submission, bitpool mustn't be increased.
Also improved logging by adding bitpool to the log message.
This commit is contained in:
Dmitry Sharshakov 2022-11-07 18:03:17 +03:00 committed by Wim Taymans
parent 79b95e083a
commit 1bea58c20b

View file

@ -718,13 +718,15 @@ again:
return 0;
}
// This should be the same as buffer size to increase bitpool
// Bitpool shouldn't be increased when data is left over in the buffer
int unused_buffer = get_transport_unused_size(this);
written = flush_buffer(this);
if (written == -EAGAIN) {
spa_log_trace(this->log, "%p: fail flush", this);
if (now_time - this->last_error > SPA_NSEC_PER_SEC / 2) {
spa_log_trace(this->log, "%p: reduce bitpool", this);
this->codec->reduce_bitpool(this->codec_data);
spa_log_debug(this->log, "%p: reduce bitpool: %i", this, this->codec->reduce_bitpool(this->codec_data));
this->last_error = now_time;
}
@ -791,9 +793,8 @@ again:
}
if (now_time - this->last_error > SPA_NSEC_PER_SEC) {
if (get_transport_unused_size(this) == (int)this->fd_buffer_size) {
spa_log_trace(this->log, "%p: increase bitpool", this);
this->codec->increase_bitpool(this->codec_data);
if (unused_buffer == (int)this->fd_buffer_size) {
spa_log_debug(this->log, "%p: increase bitpool: %i", this, this->codec->increase_bitpool(this->codec_data));
}
this->last_error = now_time;
}