mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
bluez5: media-source: allow using bigger A2DP receive buffers
The maximum receive buffer target of 6 packets may be too small when there's huge jitter in reception. Increase it so that we may use all buffer available if needed (2*quantum_limit = 370 ms @ 44100). For SCO, explicitly set maximum buffer to 40 ms, so that latency cannot grow too large there. For A2DP duplex, set it to 80 ms for same reason. These are close to the old 6*packet limit.
This commit is contained in:
parent
d28990af34
commit
15e4b3d500
3 changed files with 26 additions and 5 deletions
|
|
@ -48,8 +48,8 @@
|
|||
* The spike is the long-window maximum difference
|
||||
* between minimum and average buffer level.
|
||||
*/
|
||||
#define BUFFERING_TARGET(spike,packet_size) \
|
||||
SPA_CLAMP((spike)*3/2, (packet_size), 6*(packet_size))
|
||||
#define BUFFERING_TARGET(spike,packet_size,max_buf) \
|
||||
SPA_CLAMP((spike)*3/2, (packet_size), (max_buf) - 2*(packet_size))
|
||||
|
||||
/**
|
||||
* Rate controller.
|
||||
|
|
@ -217,7 +217,8 @@ struct spa_bt_decode_buffer
|
|||
uint32_t underrun;
|
||||
uint32_t pos;
|
||||
|
||||
uint32_t target; /**< target buffer (0: automatic) */
|
||||
int32_t target; /**< target buffer (0: automatic) */
|
||||
int32_t max_target;
|
||||
|
||||
uint8_t received:1;
|
||||
uint8_t buffering:1;
|
||||
|
|
@ -270,6 +271,7 @@ static int spa_bt_decode_buffer_init(struct spa_bt_decode_buffer *this, struct s
|
|||
this->corr = 1.0;
|
||||
this->target = 0;
|
||||
this->buffering = true;
|
||||
this->max_target = INT32_MAX;
|
||||
|
||||
spa_bt_rate_control_init(&this->ctl, 0);
|
||||
|
||||
|
|
@ -370,11 +372,17 @@ static void spa_bt_decode_buffer_recover(struct spa_bt_decode_buffer *this)
|
|||
}
|
||||
|
||||
static SPA_UNUSED
|
||||
void spa_bt_decode_buffer_set_target_latency(struct spa_bt_decode_buffer *this, uint32_t samples)
|
||||
void spa_bt_decode_buffer_set_target_latency(struct spa_bt_decode_buffer *this, int32_t samples)
|
||||
{
|
||||
this->target = samples;
|
||||
}
|
||||
|
||||
static SPA_UNUSED
|
||||
void spa_bt_decode_buffer_set_max_latency(struct spa_bt_decode_buffer *this, int32_t samples)
|
||||
{
|
||||
this->max_target = samples;
|
||||
}
|
||||
|
||||
static void spa_bt_decode_buffer_process(struct spa_bt_decode_buffer *this, uint32_t samples, uint32_t duration)
|
||||
{
|
||||
const uint32_t data_size = samples * this->frame_size;
|
||||
|
|
@ -408,6 +416,7 @@ static void spa_bt_decode_buffer_process(struct spa_bt_decode_buffer *this, uint
|
|||
|
||||
if (this->received) {
|
||||
const uint32_t avg_period = (uint64_t)this->rate * BUFFERING_SHORT_MSEC / 1000;
|
||||
const int32_t max_buf = (this->buffer_size - this->buffer_reserve) / this->frame_size;
|
||||
int32_t level, target;
|
||||
|
||||
/* Track buffer level */
|
||||
|
|
@ -421,7 +430,9 @@ static void spa_bt_decode_buffer_process(struct spa_bt_decode_buffer *this, uint
|
|||
if (this->target)
|
||||
target = this->target;
|
||||
else
|
||||
target = BUFFERING_TARGET(this->spike.max, packet_size);
|
||||
target = BUFFERING_TARGET(this->spike.max, packet_size, max_buf);
|
||||
|
||||
target = SPA_MIN(target, this->max_target);
|
||||
|
||||
if (level > SPA_MAX(4 * target, 2*(int32_t)duration) &&
|
||||
avail > data_size) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue