6#include <pipewire/pipewire.h>
7#include <spa/param/audio/format-utils.h>
8#include <spa/param/props.h>
33 unsigned int output_node_id,
34 unsigned int input_node_id,
36 void* user_data)
override;
42#ifdef PIPEWIRE_BACKEND
43 [[nodiscard]] pw_main_loop* loop()
const {
return m_loop; }
44 [[nodiscard]] pw_context* context()
const {
return m_context; }
45 [[nodiscard]] pw_core* core()
const {
return m_core; }
49#ifdef PIPEWIRE_BACKEND
50 pw_main_loop* m_loop =
nullptr;
51 pw_context* m_context =
nullptr;
52 pw_core* m_core =
nullptr;
53 PipewireDevice* m_device_manager =
nullptr;
72#ifdef PIPEWIRE_BACKEND
73 explicit PipewireDevice(pw_main_loop* loop, pw_context* ctx, pw_core* core);
96#ifdef PIPEWIRE_BACKEND
97 void enumerate(pw_main_loop* loop, pw_context* ctx, pw_core* core);
122#ifdef PIPEWIRE_BACKEND
124 uint32_t output_node_id,
125 uint32_t input_node_id,
129 [[nodiscard]] pw_time get_stream_time()
const;
145 std::function<
int(
void*,
void*,
unsigned int)> cb)
override;
148#ifdef PIPEWIRE_BACKEND
149 static void on_output_process(
void* userdata);
150 static void on_input_process(
void* userdata);
152 static void on_param_changed(
void* userdata, uint32_t
id,
const struct spa_pod* param);
153 static void on_state_changed(
155 enum pw_stream_state old_state,
156 enum pw_stream_state new_state,
159 static void on_io_changed(
void* userdata, uint32_t
id,
void* area, uint32_t size);
161 void build_output_format_params(uint8_t* buf, uint32_t buf_size,
162 const struct spa_pod** params, uint32_t& n_params);
164 void build_input_format_params(uint8_t* buf, uint32_t buf_size,
165 const struct spa_pod** params, uint32_t& n_params);
167 pw_thread_loop* m_thread_loop =
nullptr;
169 pw_stream* m_output_stream =
nullptr;
170 pw_stream* m_input_stream =
nullptr;
172 pw_stream_events m_output_stream_events {};
173 pw_stream_events m_input_stream_events {};
175 uint32_t m_output_node_id;
176 uint32_t m_input_node_id;
178 spa_io_rate_match* m_rate_match =
nullptr;
180 std::vector<double> m_input_staging;
181 std::atomic<bool> m_input_ready {
false };
184 std::atomic<uint32_t> m_negotiated_frames { 0 };
Manages audio endpoint discovery and enumeration.
Manages digital audio data flow between the engine and hardware.
Interface for audio system abstraction layer.
void cleanup() override
Releases all resources held by the backend.
std::unique_ptr< AudioStream > create_stream(unsigned int output_node_id, unsigned int input_node_id, GlobalStreamInfo &stream_info, void *user_data) override
Creates an audio stream for a specific device.
~PipewireBackend() override
std::unique_ptr< AudioDevice > create_device_manager() override
Creates a device manager for audio endpoint discovery.
std::string get_version_string() const override
Retrieves the backend implementation version.
PipeWire native implementation of the audio backend interface.
unsigned int get_default_input_device() const override
Gets the system's primary input device identifier.
std::vector< NodeEntry > m_nodes
std::vector< DeviceInfo > get_output_devices() const override
Retrieves information about all available output devices.
std::vector< DeviceInfo > get_input_devices() const override
Retrieves information about all available input devices.
uint32_t m_default_output_id
unsigned int get_default_output_device() const override
Gets the system's primary output device identifier.
uint32_t m_default_input_id
uint32_t find_input_node_id(std::string_view name) const
uint32_t find_output_node_id(std::string_view name) const
PipeWire implementation of the audio device interface.
GlobalStreamInfo & m_stream_info
std::atomic< bool > m_is_running
~PipewireStream() override
bool is_running() const override
Checks if the stream is actively processing audio data.
void resume() override
Resumes audio processing after a pause.
std::atomic< bool > m_is_paused
void close() override
Terminates the audio stream and releases all resources.
bool is_open() const override
Checks if the stream is initialized and ready for activation.
std::atomic< bool > m_is_open
std::function< int(void *, void *, unsigned int)> m_process_callback
void open() override
Initializes the audio stream and allocates required resources.
void set_process_callback(std::function< int(void *, void *, unsigned int)> cb) override
Sets the function to process audio data.
void stop() override
Deactivates the audio stream and halts data transfer.
void pause() override
Temporarily suspends audio processing without releasing resources.
void start() override
Activates the audio stream and begins data transfer.
PipeWire implementation of the audio stream interface.
Contains digital audio device configuration parameters.
Comprehensive configuration for digital audio stream processing.
uint32_t priority_session