Commit Graph

54 Commits

Author SHA1 Message Date
Andreas Kling
fc86460134 AK: Move the userspace SharedBuffer from LibC to AK
This always felt out-of-place in LibC.
2020-01-01 18:53:34 +01:00
joshua stein
b624eaaf78 Build: consider IPCCOMPILER and FORMCOMPILER just for ordering
Build them if they don't exist, but don't care about them being
newer or older than the target.

I believe this is what was causing build loops where IPCCompiler was
being run a second time, rebuilding its .h file, then a library
would depend on that .h file and get re-archived, then an
application would need relinking, and something in that whole
process would trigger IPCCompiler running again touching its .h
file.
2019-12-28 21:09:33 +01:00
Andreas Kling
a089125d0f AudioServer: Block the mixer thread when there's nothing to do
Use a pthread_cond_t to have the ASMixer thread wait until a client has
connected and added a buffer queue to the "pending mixing" vector.

This solves the long-standing issue of the system "idling" at ~8% CPU.
2019-12-25 23:54:07 +01:00
joshua stein
c127d16326 Build: support library and generator dependencies
Instead of directly manipulating LDFLAGS, set LIB_DEPS in each
subdirectory Makefile listing the libraries needed for
building/linking such as "LIB_DEPS = Core GUI Draw IPC Core".

This adds each library as an -L and -l argument in LDFLAGS, but
also adds the library.a file as a link dependency on the current
$(PROGRAM).  This causes the given library to be (re)built before
linking the current $(PROGRAM), but will also re-link any binaries
depending on that library when it is modified, when running make
from the root directory.

Also turn generator tools like IPCCompiler into dependencies on the
files they generate, so they are built on-demand when a particular
directory needs them.

This all allows the root Makefile to just list directories and not
care about the order, as all of the dependency tracking will figure
it out.
2019-12-25 10:11:09 +01:00
Andreas Kling
823ee63095 AudioServer: Remove any pending mixer queues whose client disconnected
We were pumping the sound device full of silence even after the last
audio client disconnected.
2019-12-22 18:30:43 +01:00
joshua stein
ac25438d54 Build: clean up build system, use one shared Makefile
Allow everything to be built from the top level directory with just
'make', cleaned with 'make clean', and installed with 'make
install'.  Also support these in any particular subdirectory.

Specifying 'make VERBOSE=1' will print each ld/g++/etc. command as
it runs.

Kernel and early host tools (IPCCompiler, etc.) are built as
object.host.o so that they don't conflict with other things built
with the cross-compiler.
2019-12-20 20:20:54 +01:00
Andrew Kaster
f67d007864 AudioServer: Set the mixer thread name to "AudioServer[mixer]" 2019-12-08 14:09:29 +01:00
Andreas Kling
20500e2949 AudioServer: Install headers 2019-12-08 11:40:38 +01:00
Andreas Kling
f93c0dc489 LibIPC: Get client/server PIDs using getsockopt(SO_PEERCRED)
Instead of passing the PIDs back and forth in a handshake "Greet"
message, just use getsockopt(SO_PEERCRED) on both sides to get the same
information from the kernel.

This is a nice little simplification of the IPC protocol, although it
does not get rid of the handshake since we still have to pass the
"client ID" from the server to each client so they know how to refer
to themselves. This might not be necessary and we might be able to get
rid of this later on.
2019-12-06 18:39:59 +01:00
Andreas Kling
4a37bec27c LibIPC: Rename base classes to IClientConnection and IServerConnection
This matches what we're already calling the server-side subclasses
better, though we'll probably want to find some better names for the
client-side classes eventually.
2019-12-02 11:11:05 +01:00
Andreas Kling
5d4ee0f58a LibIPC: Move IPC client/server connection templates to LibIPC
Move over the CoreIPC::Server and CoreIPC::Client namespace stuff
into LibIPC where it will soon becomes LibIPC-style things.
2019-12-02 11:11:05 +01:00
Sergey Bugaev
bd55938985 AudioServer: Port to socket takeover 2019-11-26 19:58:25 +01:00
Andreas Kling
84cb91de38 AudioServer: Broadcast muted state changes to all clients 2019-11-23 17:21:12 +01:00
Andreas Kling
630d5b3ffd LibIPC+AudioServer: Allow unsolicited server-to-client IPC messages
Client-side connection objects must now provide both client and server
endpoint types. When a message is received from the server side, we try
to decode it using both endpoint types and then send it to the right
place for handling.

This now makes it possible for AudioServer to send unsolicited messages
to its clients. This opens up a ton of possibilities :^)
2019-11-23 16:50:21 +01:00
Andreas Kling
107011f119 AudioServer: Allow muting the system audio
This patch adds muting to ASMixer, which works by substituting what we
would normally send to the sound card with zero-filled memory instead.
We do it this way to ensure that the queued sample buffers keep getting
played (silently.)

This is obviously not the perfect way of doing this, and in the future
we should improve on this, and also find a way to utilize any hardware
mixing functions in the sound card.
2019-11-22 21:44:02 +01:00
Sergey Bugaev
3df521e2b7 AudioServer: Make all source files depend on generated sources
This fixes race conditions & failures during build.
2019-11-19 20:10:38 +01:00
Andreas Kling
69ca9cfd78 LibPthread: Start working on a POSIX threading library
This patch adds pthread_create() and pthread_exit(), which currently
simply wrap our existing create_thread() and exit_thread() syscalls.

LibThread is also ported to using LibPthread.
2019-11-13 21:49:24 +01:00
Till Mayer
2f13517a1a LibAudio: Added playback control features to audio server
LibAudio now supports pausing playback, clearing the buffer queue,
retrieving the played samples since the last clear and retrieving
the currently playing shared buffer id
2019-11-04 20:55:46 +01:00
Till Mayer
406aabff23 AudioServer: Added ability to get count of samples in the buffer queue
Now the AClientConnection can get the count of samples still in the
buffer queue.
2019-10-19 20:05:13 +02:00
Till Mayer
8bb919d1cc ASMixer: Removed unused variable in ASBufferQueue
The variable m_playing_queued_buffer_id was defined but not used.
2019-10-19 20:05:13 +02:00
Till Mayer
4c8341d080 LibAudio: Fixed stuttery playback of audio
When playing an ABuffer, the count of samples were determined by the
size of the SharedBuffer. This caused small pauses of up to 512
samples during the playback, when the size of the shared buffer was
rounded up to a multiple of 4096. This problem was amplified by the
fact that the AResampleHelper was created every time a new chunk of
audio was to be processed, causing inconsistencies in the playback of
wav files.
2019-10-16 16:25:38 +02:00
Andreas Kling
d6abfbdc5a LibCore: Remove ObjectPtr in favor of RefPtr
Now that CObject is fully ref-counted, just use RefPtr everywhere! :^)
2019-09-22 00:31:54 +02:00
Andreas Kling
bc319d9e88 LibCore: Make CObject reference-counted
Okay, I've spent a whole day on this now, and it finally kinda works!
With this patch, CObject and all of its derived classes are reference
counted instead of tree-owned.

The previous, Qt-like model was nice and familiar, but ultimately also
outdated and difficult to reason about.

CObject-derived types should now be stored in RefPtr/NonnullRefPtr and
each class can be constructed using the forwarding construct() helper:

    auto widget = GWidget::construct(parent_widget);

Note that construct() simply forwards all arguments to an existing
constructor. It is inserted into each class by the C_OBJECT macro,
see CObject.h to understand how that works.

CObject::delete_later() disappears in this patch, as there is no longer
a single logical owner of a CObject.
2019-09-22 00:25:25 +02:00
Andreas Kling
8d550c174e LibCore: Convert CFile to ObjectPtr 2019-09-21 20:50:06 +02:00
Andreas Kling
953cb4e436 LibCore: Convert CLocalServer to ObjectPtr 2019-09-21 15:25:08 +02:00
Andreas Kling
c83da29a9d LibCore: Convert CLocalSocket to ObjectPtr 2019-09-21 15:25:08 +02:00
Sergey Bugaev
3439a479af LibThread: Move CLock to LibThread::Lock
And adapt all the code that uses it.
2019-08-26 11:31:14 +02:00
Sergey Bugaev
1ac7fedefe AudioServer: Port threading to LibThread 2019-08-26 11:31:14 +02:00
Andreas Kling
d5352b87b7 AudioServer: Turn ASMixer into a CObject
It was wrongly inheriting from RefCounted<AudioServer> without using
reference counting. Let's just make it a CObject instead.
2019-08-18 12:56:36 +02:00
Andreas Kling
3100e8dee5 IPCCompiler+AudioServer: Accept "//"-style comments in IPC defintions 2019-08-03 21:29:09 +02:00
Andreas Kling
8e684f0959 AudioServer: Port to the new generated IPC mechanism
Fork the IPC Connection classes into Server:: and Client::ConnectionNG.
The new IPC messages are serialized very snugly instead of using the
same generic data structure for all messages.

Remove ASAPI.h since we now generate all of it from AudioServer.ipc :^)
2019-08-03 19:49:19 +02:00
Andreas Kling
3c1bad99a2 AudioServer: Link against LibIPC
We're not using any of the functionality yet, but soon...
2019-08-03 17:25:54 +02:00
Andreas Kling
4fc15c9e6e AudioServer: The EnqueueBuffer response needs a success boolean
This was already in the current version of the code, I'm just updating
the soon-to-be-current IPC protocol version of it. :^)
2019-08-03 16:41:58 +02:00
Andreas Kling
aa8a3d4a89 IPCCompiler: Start working on a simple IPC definition language
Instead of doing everything manually in C++, let's do some codegen.
This patch adds a crude but effective IPC definition parser, along
with two initial definition files for the AudioServer's client and
server endpoints.
2019-08-03 15:17:41 +02:00
Andreas Kling
e6db1b81b8 AudioServer: Begin work on a new IPC API style.
The goal here is to generate most of this code from IPC protocol
descriptions, but for now I've spelled them all out to get started.

Each message gets a wrapper class in the ASAPI_Client or ASAPI_Server
namespace. They are convertible to and from the old message structs.

The real hotness happens when you want to make a synchronous request
to the other side:

    auto response = send_sync<ASAPI_Client::GetMainMixVolume>();

Each request class knows his corresponding response class, so in the
above example, "response" will be an ASAPI_Server::DidGetMainMixVolume
object, and we can get the volume like so:

    int volume = response.volume();

For posting messages that don't expect a response, you can still use
post_message() since the message classes are convertible:

    post_message(ASAPI_Server::DidGetMainMixVolume(volume));

It's not perfect yet, but I already really like it. :^)
2019-07-29 22:39:20 +02:00
Andreas Kling
15afc88ffe AudioServer: Add a "main mix volume" and a simple program to get/set it
Give the mixer a main volume value (percent) that we scale all the
outgoing samples by (before clipping.)

Also add a simple "avol" program for querying and setting the volume:

- "avol" prints the current volume.
- "avol 200" sets the main mix volume to 200%
2019-07-29 19:06:58 +02:00
Andreas Kling
be31e2232c AudioServer+LibAudio: Make mixing queue-based instead of buffer-based.
Each client connection now sets up an ASBufferQueue, which is basically a
queue of ABuffers. This allows us to immediately start streaming the next
pending buffer whenever our current buffer runs out of samples.

This makes the majority of the skippiness go away for me. :^)

Also get rid of the old PlayBuffer API, since we don't need it anymore.
2019-07-28 21:34:47 +02:00
Andreas Kling
7cabe6433e AudioServer: Add a buffer queue so we can buffer some sound.
The idea here is to keep a small number of sample buffers queued in the
AudioServer so we don't get caught without something to play.
2019-07-28 18:27:32 +02:00
Andreas Kling
6a0319697c AudioServer: Let ASMixer notify ASClientConnection about finished buffers.
Instead of posting a message directly from ASMixer, notify the client via
ASClientConnection::did_finish_playing_buffer().
2019-07-27 21:17:14 +02:00
Andreas Kling
e6eba24405 WindowServer+AudioServer: Add some missing C_OBJECT macros. 2019-07-27 18:43:59 +02:00
Andreas Kling
60a9a232be AudioServer: Remove some outdated comments. 2019-07-27 18:41:24 +02:00
Andreas Kling
5e01dde7b1 Audio: Make ABuffer sit on top of a SharedBuffer.
This allows us to carry the same buffer all the way from the WAV loader
to the AudioServer mixer.

This alleviates some of the stutter, but there's still a noticeable
skip when switching buffers. We're gonna need to do better. :^)
2019-07-27 18:17:17 +02:00
Andreas Kling
b805f112c2 AudioServer: Avoid two heap allocations per mixing iteration. 2019-07-27 17:43:00 +02:00
Andreas Kling
426248098c Audio: Make basic streaming WAV playback work.
I had to solve a bunch of things simultaneously to make this work.
Refactor AWavLoader to be a streaming loader rather than a one-shot one.
The constructor parses the header, and if everything looks good, you can
repeatedly ask the AWavLoader for sample buffers until it runs out.

Also send a message from AudioServer when a buffer has finished playing.
That allows us to implement a blocking variant of play().

Use all of this in aplay to play WAV files chunk-at-a-time.
This is definitely not perfect and it's a little glitchy and skippy,
but I think it's a step in the right direction.
2019-07-27 17:27:05 +02:00
Andreas Kling
fe45f5a6d2 LibCore: Port CoreIPCServer to using CLocalServer.
Use CLocalServer to listen for connections in WindowServer and AudioServer.
This allows us to accept incoming CLocalSocket objects from the CLocalServer
and construct client connections based on those.

Removed COpenedSocket since it's replaced by CLocalSocket.
2019-07-27 10:53:50 +02:00
Andreas Kling
4adbddeb36 AudioServer: Use Vector::append(Vector&&) for pending mix buffers.
Vector::append(Vector&&) is a simple pointer transfer when appending to an
empty Vector. :^)
2019-07-17 20:54:09 +02:00
Robin Burchell
9c8dd836fc Rename new IPC headers & classes
Sticking these in a namespace allows us to use a more generic
("Connection") term without clashing, which is way easier to understand
than to try to come up with unique names for both.
2019-07-17 20:16:44 +02:00
Robin Burchell
6eaa6826fa Port WSClientConnection to CIPCServerSideClient 2019-07-17 20:16:44 +02:00
Robin Burchell
edcbba9e98 Introduce CIPCServerSideClient
As a new base class of IPC connections server-side.
Port ASClientConnection to CIPCServerSideClient.
2019-07-17 20:16:44 +02:00
Robin Burchell
fd6cafaa84 ABuffer: clamp -> clip
More natural term when talking about audio :)
2019-07-17 09:47:52 +02:00