Skip to content

Commit

Permalink
pulse-server: always send at least fragsize data
Browse files Browse the repository at this point in the history
Make sure to never send less than the negotiated fragsize to a client.
Also make sure we don't send too much data in one go. This is more in
line with what pulseaudio does.

Fixes capture from multiple tabs in chrome.

Fixes #2418
  • Loading branch information
wtay committed Jun 1, 2022
1 parent 1245309 commit 0d51f3b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/modules/module-protocol-pulse/pulse-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
#define DEFAULT_POSITION "[ FL FR ]"

#define MAX_FORMATS 32
/* The max amount of data we send in one block when capturing. In PulseAudio this
* size is derived from the mempool PA_MEMPOOL_SLOT_SIZE */
#define MAX_FRAGSIZE (64*1024)

#define TEMPORARY_MOVE_TIMEOUT (SPA_NSEC_PER_SEC)

Expand Down Expand Up @@ -1284,7 +1287,7 @@ do_process_done(struct spa_loop *loop,
pw_log_warn("%p: [%s] underrun read:%u avail:%d",
stream, client->name, index, avail);
} else {
if (avail > (int32_t)stream->attr.maxlength) {
if ((uint32_t)avail > stream->attr.maxlength) {
uint32_t skip = avail - stream->attr.fragsize;
/* overrun, catch up to latest fragment and send it */
pw_log_warn("%p: [%s] overrun recover read:%u avail:%d max:%u skip:%u",
Expand All @@ -1294,10 +1297,8 @@ do_process_done(struct spa_loop *loop,
avail = stream->attr.fragsize;
}

while (avail > 0) {
towrite = avail;
if (towrite > stream->attr.fragsize)
towrite = stream->attr.fragsize;
while ((uint32_t)avail >= stream->attr.fragsize) {
towrite = SPA_MIN(avail, MAX_FRAGSIZE);

msg = message_alloc(impl, stream->channel, towrite);
if (msg == NULL)
Expand Down

0 comments on commit 0d51f3b

Please sign in to comment.