AudioServer: Handle multiple audio devices with multiple pins
This makes audio server configurable during runtime!
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <BAN/ScopeGuard.h>
|
||||
|
||||
#include <LibAudio/Audio.h>
|
||||
#include <LibAudio/Protocol.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
@@ -121,10 +122,15 @@ namespace LibAudio
|
||||
{
|
||||
ASSERT(m_server_fd != -1);
|
||||
|
||||
const ssize_t nsend = send(m_server_fd, &m_smo_key, sizeof(m_smo_key), 0);
|
||||
LibAudio::Packet packet {
|
||||
.type = LibAudio::Packet::RegisterBuffer,
|
||||
.parameter = static_cast<uint64_t>(m_smo_key),
|
||||
};
|
||||
|
||||
const ssize_t nsend = send(m_server_fd, &packet, sizeof(packet), 0);
|
||||
if (nsend == -1)
|
||||
return BAN::Error::from_errno(errno);
|
||||
ASSERT(nsend == sizeof(m_smo_key));
|
||||
ASSERT(nsend == sizeof(packet));
|
||||
|
||||
return {};
|
||||
}
|
||||
@@ -137,8 +143,12 @@ namespace LibAudio
|
||||
return;
|
||||
m_audio_buffer->paused = paused;
|
||||
|
||||
long dummy = 0;
|
||||
send(m_server_fd, &dummy, sizeof(dummy), 0);
|
||||
LibAudio::Packet packet {
|
||||
.type = LibAudio::Packet::Notify,
|
||||
.parameter = 0,
|
||||
};
|
||||
|
||||
send(m_server_fd, &packet, sizeof(packet), 0);
|
||||
}
|
||||
|
||||
size_t Audio::queue_samples(BAN::Span<const AudioBuffer::sample_t> samples)
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
namespace LibAudio
|
||||
{
|
||||
|
||||
static constexpr BAN::StringView s_audio_server_socket = "/tmp/audio-server.socket"_sv;
|
||||
|
||||
struct AudioBuffer
|
||||
{
|
||||
using sample_t = double;
|
||||
|
||||
50
userspace/libraries/LibAudio/include/LibAudio/Protocol.h
Normal file
50
userspace/libraries/LibAudio/include/LibAudio/Protocol.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/StringView.h>
|
||||
|
||||
namespace LibAudio
|
||||
{
|
||||
|
||||
struct Packet
|
||||
{
|
||||
enum : uint8_t
|
||||
{
|
||||
Notify, // parameter: ignored
|
||||
// response: nothing
|
||||
// server refereshes buffered data
|
||||
|
||||
RegisterBuffer, // paramenter: smo key
|
||||
// response: nothing
|
||||
// register audio buffer to server
|
||||
|
||||
QueryDevices, // parameter: ignored
|
||||
// response: (uint32_t)
|
||||
// query the number of devices available
|
||||
|
||||
QueryPins, // parameter: sink number
|
||||
// response: (uint32_t)
|
||||
// query the number of pins the sink has
|
||||
|
||||
GetDevice, // parameter: ignored
|
||||
// reponse: (uint32_t)
|
||||
// get the currently active device
|
||||
|
||||
SetDevice, // parameter: device number
|
||||
// reponse: nothing
|
||||
// set the currently active device
|
||||
|
||||
GetPin, // parameter: ignored
|
||||
// response: nothing
|
||||
// get the active pin of the current device
|
||||
|
||||
SetPin, // parameter: pin number
|
||||
// response: nothing
|
||||
// set the active pin of the current device
|
||||
} type;
|
||||
|
||||
uint64_t parameter;
|
||||
};
|
||||
|
||||
static constexpr BAN::StringView s_audio_server_socket = "/tmp/audio-server.socket"_sv;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user