1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2026-01-13 01:31:00 +00:00
serenity/Userland/Applications
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
..
3DFileViewer Userland: Always construct Application with try_create() 2022-04-18 12:57:34 +02:00
About About: Port to LibMain 2021-12-17 13:09:54 -08:00
AnalogClock AnalogClock: Keep default alpha hit threshold 2022-04-06 11:36:15 +02:00
Assistant AK: Add FuzzyMatch header 2022-04-20 18:34:09 +02:00
Browser Userland: Always construct Application with try_create() 2022-04-18 12:57:34 +02:00
BrowserSettings LibCore+Everywhere: Make Core::Stream read_line() return StringView 2022-04-16 13:27:51 -04:00
Calculator LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
Calendar LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
CharacterMap LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
ClockSettings ClockSettings: Add 'show seconds' toggle to time format settings 2022-04-15 08:24:20 -04:00
CrashReporter CrashReporter: Don't display an error when cancelling backtrace saving 2022-04-20 12:01:49 +02:00
Debugger Applications: Use default execpromises parameter to pledge(..) 2022-04-03 17:13:51 -07:00
DisplaySettings WindowServer: Add the screen mode property in the screen configuration 2022-04-21 13:41:55 +02:00
FileManager LibCore+Everywhere: Make Core::Stream read_line() return StringView 2022-04-16 13:27:51 -04:00
FontEditor LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
Help LaunchServer+Help: Open help urls with Help 2022-04-21 09:12:37 +04:30
HexEditor HexEditor: Show endianness in the value inspector 2022-04-18 09:25:38 +04:30
ImageViewer Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
KeyboardMapper Userland: Always construct Application with try_create() 2022-04-18 12:57:34 +02:00
KeyboardSettings LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
Magnifier Userland: Always construct Application with try_create() 2022-04-18 12:57:34 +02:00
Mail Userland: Always construct Application with try_create() 2022-04-18 12:57:34 +02:00
MailSettings LibConfig: Rename pledge_domains(String) => pledge_domain(String) 2022-02-11 18:06:39 +01:00
MouseSettings LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
PDFViewer LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
Piano LibAudio+Userland: Use new audio queue in client-server communication 2022-04-21 13:55:00 +02:00
PixelPaint Userland: Always construct Application with try_create() 2022-04-18 12:57:34 +02:00
Run Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Settings Everywhere: Use default execpromises argument for Core::System::pledge 2021-11-28 08:04:57 +01:00
SoundPlayer LibAudio+Userland: Use new audio queue in client-server communication 2022-04-21 13:55:00 +02:00
SpaceAnalyzer Userland: Always construct Application with try_create() 2022-04-18 12:57:34 +02:00
Spreadsheet Spreadsheet: Sort functions by name in the help window 2022-04-18 17:36:34 +02:00
SystemMonitor SystemMonitor: Remove MakeInspectable::Yes from constructor 2022-04-18 12:57:34 +02:00
Terminal Terminal: Use Core::System::exec() 2022-04-11 21:09:42 +02:00
TerminalSettings LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
TextEditor LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
ThemeEditor ThemeEditor: Remove unused model classes 2022-04-18 12:58:23 +02:00
VideoPlayer Userland: Rename IPC ClientConnection => ConnectionFromClient 2022-02-25 22:35:12 +01:00
Welcome LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
CMakeLists.txt ClockSettings: Add a GUI application to set the system time zone 2022-01-23 12:48:26 +00:00