ladybird/Meta
kleines Filmröllchen 49b087f3cd LibAudio+Userland: Use new audio queue in client-server communication
Previously, we were sending Buffers to the server whenever we had new
audio data for it. This meant that for every audio enqueue action, we
needed to create a new shared memory anonymous buffer, send that
buffer's file descriptor over IPC (+recfd on the other side) and then
map the buffer into the audio server's memory to be able to play it.
This was fine for sending large chunks of audio data, like when playing
existing audio files. However, in the future we want to move to
real-time audio in some applications like Piano. This means that the
size of buffers that are sent need to be very small, as just the size of
a buffer itself is part of the audio latency. If we were to try
real-time audio with the existing system, we would run into problems
really quickly. Dealing with a continuous stream of new anonymous files
like the current audio system is rather expensive, as we need Kernel
help in multiple places. Additionally, every enqueue incurs an IPC call,
which are not optimized for >1000 calls/second (which would be needed
for real-time audio with buffer sizes of ~40 samples). So a fundamental
change in how we handle audio sending in userspace is necessary.

This commit moves the audio sending system onto a shared single producer
circular queue (SSPCQ) (introduced with one of the previous commits).
This queue is intended to live in shared memory and be accessed by
multiple processes at the same time. It was specifically written to
support the audio sending case, so e.g. it only supports a single
producer (the audio client). Now, audio sending follows these general
steps:
- The audio client connects to the audio server.
- The audio client creates a SSPCQ in shared memory.
- The audio client sends the SSPCQ's file descriptor to the audio server
  with the set_buffer() IPC call.
- The audio server receives the SSPCQ and maps it.
- The audio client signals start of playback with start_playback().
- At the same time:
  - The audio client writes its audio data into the shared-memory queue.
  - The audio server reads audio data from the shared-memory queue(s).
  Both sides have additional before-queue/after-queue buffers, depending
  on the exact application.
- Pausing playback is just an IPC call, nothing happens to the buffer
  except that the server stops reading from it until playback is
  resumed.
- Muting has nothing to do with whether audio data is read or not.
- When the connection closes, the queues are unmapped on both sides.

This should already improve audio playback performance in a bunch of
places.

Implementation & commit notes:
- Audio loaders don't create LegacyBuffers anymore. LegacyBuffer is kept
  for WavLoader, see previous commit message.
- Most intra-process audio data passing is done with FixedArray<Sample>
  or Vector<Sample>.
- Improvements to most audio-enqueuing applications. (If necessary I can
  try to extract some of the aplay improvements.)
- New APIs on LibAudio/ClientConnection which allows non-realtime
  applications to enqueue audio in big chunks like before.
- Removal of status APIs from the audio server connection for
  information that can be directly obtained from the shared queue.
- Split the pause playback API into two APIs with more intuitive names.

I know this is a large commit, and you can kinda tell from the commit
message. It's basically impossible to break this up without hacks, so
please forgive me. These are some of the best changes to the audio
subsystem and I hope that that makes up for this :yaktangle: commit.

:yakring:
2022-04-21 13:55:00 +02:00
..
Azure Meta: Switch to clang-format-14 as the standard formatter 2022-04-01 21:24:45 +01:00
CMake LibCore: Introduce SharedSingleProducerCircularQueue 2022-04-21 13:55:00 +02:00
HeaderCheck Meta: Remove obsolete HeaderCheck .gitignore 2022-03-24 20:11:39 -07:00
Lagom LibAudio+Userland: Use new audio queue in client-server communication 2022-04-21 13:55:00 +02:00
Screenshots Meta: Move screenshots into subdir 2022-04-03 13:14:15 +01:00
ShellCompletions/zsh Meta: Add copy-src to commands in ZSH autocomplete script 2022-03-14 22:20:35 +00:00
Websites Everywhere: Use title case for man section titles 2022-02-25 12:06:31 -05:00
bochsrc Meta: Add SSE3, SMAP and SMEP to our bochsrc 2021-12-28 11:51:50 +01:00
build-image-extlinux.sh Meta: Fix syslinux detection on Arch Linux 2021-07-20 15:12:19 +02:00
build-image-grub.sh Meta: Run 'du' with '--apparent-size', except on macOS 2021-05-16 22:50:46 +01:00
build-image-limine.sh Meta: Bump Limine version to 2.78.2 2022-02-14 11:52:07 +01:00
build-image-qemu.sh Meta: Fix e2fsck variable on macOS in build-image-qemu.sh 2022-03-30 01:57:51 -07:00
build-manpages-website.sh Meta: Title case 'File Formats' on man.serenityos.org 2022-02-24 23:04:22 +00:00
build-native-partition.sh Meta: Add install-native-partition CMake target installing to a real FS 2022-02-04 12:44:50 +01:00
build-root-filesystem.sh Meta: Keep timestamps of manually copied toolchain output 2022-04-17 10:53:31 -07:00
check-ak-test-files.sh Meta: Remove unnecessary -i 2021-11-02 12:23:30 +01:00
check-debug-flags.sh Kernel: Support all Intel-defined CPUID feature flags for EAX=1 2022-03-27 18:54:56 +02:00
check-markdown.sh Utilities+Meta: Check icons in markdown-check 2022-02-26 20:05:06 +02:00
check-newlines-at-eof.py Tests: Add regression tests for the LibCpp preprocessor 2021-08-14 12:40:55 +02:00
check-style.py LibC: Allow multiple includes of <assert.h> 2021-12-23 17:53:46 -08:00
check-symbols.sh Meta: Make check-symbols.sh use the correct build directory 2022-01-15 17:51:40 +01:00
check-syscall-lists.sh Meta: Use grep -E/F, not grep -P 2021-11-02 12:23:30 +01:00
convert-markdown-links.lua Meta: Add icons to online man pages 2022-01-17 02:22:33 -08:00
debug-kernel.sh Meta: Allow setting a host IP address to bind to 2022-04-20 14:12:34 +02:00
export-argsparser-manpages.sh Meta: Check auto-generated manpages for completeness on CI 2021-11-01 21:12:58 +01:00
extlinux.conf Kernel: Separate framebuffers from bootmode 2021-10-25 23:38:28 +02:00
generate-embedded-resource-assembly.sh Meta: Get building on NixOS (#5005) 2021-01-22 17:44:05 +01:00
generate-libwasm-spec-test.py Meta: Skip wasm tests whose modules cannot be loaded 2022-03-20 10:44:32 +03:30
generate-libwasm-spec-test.sh Meta: Run the Wasm spec tests in CI 2021-05-27 17:28:41 +04:30
grub-ebr.cfg Kernel: Separate framebuffers from bootmode 2021-10-25 23:38:28 +02:00
grub-gpt.cfg Kernel: Separate framebuffers from bootmode 2021-10-25 23:38:28 +02:00
grub-mbr.cfg Kernel: Separate framebuffers from bootmode 2021-10-25 23:38:28 +02:00
install-ports-tree.sh Everywhere: Replace SERENITY_ROOT with SERENITY_SOURCE_DIR 2021-04-20 15:27:52 +02:00
limine.cfg Meta: Add support for the Limine bootloader 2022-02-14 11:52:07 +01:00
lint-ci.sh Meta+Userland: Run the GML formatter on CI and pre-commit 2022-02-07 18:39:50 +01:00
lint-clang-format.sh Meta: Switch to clang-format-14 as the standard formatter 2022-04-01 21:24:45 +01:00
lint-commit.sh CI: Require a blank line between commit titles and bodies 2022-01-11 23:45:14 +02:00
lint-executable-resources.sh Meta: Add special case for macOS 2021-11-02 12:23:30 +01:00
lint-gml-format.sh Meta+Userland: Run the GML formatter on CI and pre-commit 2022-02-07 18:39:50 +01:00
lint-keymaps.py Everywhere: "file name" => "filename" 2021-04-29 22:16:18 +02:00
lint-missing-resources.sh Meta: Use grep -E/F, not grep -P 2021-11-02 12:23:30 +01:00
lint-ports.py Ports/pt2-clone: Update pt2-clone to version 1.43 2022-04-11 19:43:56 -07:00
lint-prettier.sh LibJS: Implement ImportCall and HostImportModuleDynamically 2022-01-22 01:21:18 +00:00
lint-python.sh Meta: Get building on NixOS (#5005) 2021-01-22 17:44:05 +01:00
lint-shell-scripts.sh Base: Add some default completions to shellrc 2022-04-18 19:53:10 +04:30
new-project.sh Meta: Add new-project.sh :^) 2021-08-13 21:12:17 +04:30
refresh-serenity-qtcreator.sh Meta: Make QtCreator aware of all CMake files 2021-09-15 20:21:19 +00:00
run.sh Meta: Allow setting a host IP address to bind to 2022-04-20 14:12:34 +02:00
serenity_gdb.py Meta: Avoid showing elements in extremely large vectors in gdb 2022-04-01 21:41:41 +01:00
serenity.sh Meta: Fix path to GCC's addr2line in serenity.sh 2022-03-27 18:54:56 +02:00
text-to-cpp-string.sh Meta: Use a bash shebang for text-to-cpp-string.sh 2021-01-22 18:41:08 +01:00
tweet-commits.js Meta: Ensure long messages fit in commit tweet 2021-06-18 13:34:17 +01:00