Skip to content

Commit

Permalink
More efficient backlog managment
Browse files Browse the repository at this point in the history
removed fullscreen from keyboard help
  • Loading branch information
Mattk70 committed Oct 13, 2024
1 parent 48d5a73 commit 73df344
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
4 changes: 0 additions & 4 deletions Help/keyboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@
<td><b>Ctrl-T</b></td>
<td>Toggle between Timecode and Time of Day</td>
</tr>
<tr>
<td><b>Ctrl-F</b></td>
<td>Toggle Fullscreen mode</td>
</tr>
<tr>
<td colspan="2" class="text-center text-bg-light"><h5>Records</h5></td>
</tr>
Expand Down
21 changes: 7 additions & 14 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ const DEBUG = false;
// Function to join Buffers and not use Buffer.concat() which leads to detached ArrayBuffers
function joinBuffers(buffer1, buffer2) {
// Create a new buffer with the combined length
const combinedBuffer = Buffer.alloc(buffer1.length + buffer2.length);

// Copy buffer1 into the new buffer
const combinedBuffer = Buffer.allocUnsafe(buffer1.length + buffer2.length);
buffer1.copy(combinedBuffer, 0);

// Copy buffer2 into the new buffer, starting from the end of buffer1
buffer2.copy(combinedBuffer, buffer1.length);
return combinedBuffer;
}
Expand Down Expand Up @@ -1294,24 +1290,21 @@ function setupCtx(audio, rate, destination, file) {


function checkBacklog(stream) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
const backlog = sumObjectValues(predictionsRequested) - sumObjectValues(predictionsReceived);
DEBUG && console.log('backlog:', backlog);

if (backlog >= predictWorkers.length * 4) {
// If queued value is above 100, wait and check again
if (backlog >= predictWorkers.length * 2) {
// If backlog is too high, check again after a short delay
setTimeout(() => {
checkBacklog(stream)
.then(resolve) // Resolve the promise when backlog is within limit
.catch(reject);
}, 500); // Check every 0.5 seconds
resolve(checkBacklog(stream)); // Recursively call until backlog is within limits
}, 50);
} else {
resolve(stream.read()); // backlog ok then read the stream data
resolve(stream.read()); // Backlog ok, read the stream data
}
});
}


/**
*
* @param file
Expand Down

0 comments on commit 73df344

Please sign in to comment.