mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
2df6f0e87f
The center of this is now an ABuffer class in LibAudio. ABuffer contains ASample, which has two channels (left/right) in floating point for mixing purposes, in 44100hz. This means that the loaders (AWavLoader in this case) needs to do some manipulation to get things in the right format, but that we don't need to care after format loading is done. While we're at it, do some correctness fixes. PCM data is unsigned if it's 8 bit, but 16 bit is signed. And /dev/audio also wants signed 16 bit audio, so give it what it wants. On top of this, AudioServer now accepts requests to play a buffer. The IPC mechanism here is pretty much a 1:1 copy-paste from LibGUI/WindowServer. It can be generalized more in the future, but for now I want to get AudioServer working decently first :) Additionally, add a little "aplay" tool to load and play a WAV file. It will break with large WAVs (run out of memory, heh...) but it's a start. Future work needs to make AudioServer block buffer submission from clients until it has played the buffer they are requesting to play.
84 lines
1.8 KiB
C++
84 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <LibCore/CObject.h>
|
|
#include <LibCore/CEvent.h>
|
|
#include <LibCore/CIODevice.h>
|
|
#include <LibCore/CNotifier.h>
|
|
|
|
struct ASAPI_ServerMessage;
|
|
struct ASAPI_ClientMessage;
|
|
|
|
class ASEvent : public CEvent {
|
|
public:
|
|
enum Type {
|
|
Invalid = 2000,
|
|
WM_ClientDisconnected,
|
|
};
|
|
ASEvent() {}
|
|
explicit ASEvent(Type type)
|
|
: CEvent(type)
|
|
{
|
|
}
|
|
};
|
|
|
|
class ASClientDisconnectedNotification : public ASEvent {
|
|
public:
|
|
explicit ASClientDisconnectedNotification(int client_id)
|
|
: ASEvent(WM_ClientDisconnected)
|
|
, m_client_id(client_id)
|
|
{
|
|
}
|
|
|
|
int client_id() const { return m_client_id; }
|
|
|
|
private:
|
|
int m_client_id { 0 };
|
|
};
|
|
|
|
class ASMixer;
|
|
|
|
class ASClientConnection : public CObject
|
|
{
|
|
public:
|
|
ASClientConnection(int fd, int client_id, ASMixer& mixer);
|
|
~ASClientConnection();
|
|
|
|
void post_message(const ASAPI_ServerMessage&, const ByteBuffer& = {});
|
|
bool handle_message(const ASAPI_ClientMessage&, const ByteBuffer& = {});
|
|
|
|
void drain_client();
|
|
|
|
void did_misbehave();
|
|
|
|
const char* class_name() const override { return "ASClientConnection"; }
|
|
|
|
protected:
|
|
void event(CEvent& event) override;
|
|
private:
|
|
// TODO: A way to create some kind of CIODevice with an open FD would be nice.
|
|
class ASOpenedSocket : public CIODevice
|
|
{
|
|
public:
|
|
const char* class_name() const override { return "ASOpenedSocket"; }
|
|
ASOpenedSocket(int fd)
|
|
{
|
|
set_fd(fd);
|
|
set_mode(CIODevice::OpenMode::ReadWrite);
|
|
}
|
|
|
|
bool open(CIODevice::OpenMode) override
|
|
{
|
|
ASSERT_NOT_REACHED();
|
|
return true;
|
|
};
|
|
|
|
int fd() const { return CIODevice::fd(); }
|
|
};
|
|
|
|
ASOpenedSocket m_socket;
|
|
CNotifier m_notifier;
|
|
int m_client_id;
|
|
int m_pid;
|
|
ASMixer& m_mixer;
|
|
};
|
|
|