Sunshine master
Self-hosted game stream host for Moonlight.
platf::pa::server_t Class Reference

PulseAudio server controller that creates and removes Sunshine sinks. More...

Inheritance diagram for platf::pa::server_t:
[legend]
Collaboration diagram for platf::pa::server_t:
[legend]

Public Member Functions

std::string get_default_sink_name ()
 Get default sink name.
 
std::string get_monitor_name (const std::string &sink_name)
 Get monitor name.
 
int init ()
 Initialize PulseAudio mainloop, context, and Sunshine null sinks.
 
bool is_sink_available (const std::string &sink) override
 Check if the audio sink is available in the system.
 
int load_null (const char *name, const std::uint8_t *channel_mapping, int channels)
 Create a PulseAudio null sink for one channel layout.
 
std::unique_ptr< mic_tmicrophone (const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size, bool continuous_audio, bool host_audio_enabled) override
 Create a microphone capture stream for the requested layout.
 
int set_sink (const std::string &sink) override
 Update the sink value on the backend.
 
std::optional< sink_tsink_info () override
 Query host and virtual sink names available to Sunshine.
 
int unload_null (std::uint32_t i)
 Unload a Sunshine-created PulseAudio null sink.
 
- Public Member Functions inherited from platf::audio_control_t
virtual ~audio_control_t ()=default
 Destroy the audio control.
 

Public Attributes

ctx_t ctx
 PulseAudio threaded mainloop context.
 
std::unique_ptr< safe::event_t< ctx_event_e > > events
 Event queue receiving PulseAudio context state changes.
 
std::unique_ptr< std::function< void(ctx_t::pointer)> > events_cb
 Callback that translates PulseAudio context updates into events.
 
struct { 
 
   std::uint32_t   stereo = PA_INVALID_INDEX 
 
   std::uint32_t   surround51 = PA_INVALID_INDEX 
 
   std::uint32_t   surround71 = PA_INVALID_INDEX 
 
index 
 PulseAudio module indexes for Sunshine-created null sinks.
 
loop_t loop
 PulseAudio threaded mainloop instance.
 
std::string requested_sink
 Requested sink.
 
std::thread worker
 Thread running the PulseAudio mainloop.
 

Detailed Description

PulseAudio server controller that creates and removes Sunshine sinks.

Member Function Documentation

◆ get_default_sink_name()

std::string platf::pa::server_t::get_default_sink_name ( )
inline

Get default sink name.

Returns
PulseAudio name of the current default sink, or an empty string.

◆ get_monitor_name()

std::string platf::pa::server_t::get_monitor_name ( const std::string & sink_name)
inline

Get monitor name.

Parameters
sink_nameSink name.
Returns
PulseAudio monitor source name for the supplied sink, or an empty string.

◆ init()

int platf::pa::server_t::init ( )
inline

Initialize PulseAudio mainloop, context, and Sunshine null sinks.

Returns
0 on success; nonzero or negative platform status on failure.

◆ is_sink_available()

bool platf::pa::server_t::is_sink_available ( const std::string & sink)
inlineoverridevirtual

Check if the audio sink is available in the system.

Parameters
sinkSink to be checked.
Returns
True if available, false otherwise.

Implements platf::audio_control_t.

◆ load_null()

int platf::pa::server_t::load_null ( const char * name,
const std::uint8_t * channel_mapping,
int channels )
inline

Create a PulseAudio null sink for one channel layout.

Parameters
nameHuman-readable name to assign.
channel_mappingChannel mapping.
channelsNumber of audio channels in the stream.
Returns
PulseAudio module index for the new sink, or PA_INVALID_INDEX on failure.

◆ microphone()

std::unique_ptr< mic_t > platf::pa::server_t::microphone ( const std::uint8_t * mapping,
int channels,
std::uint32_t sample_rate,
std::uint32_t frame_size,
bool continuous_audio,
bool host_audio_enabled )
inlineoverridevirtual

Create a microphone capture stream for the requested layout.

Parameters
mappingOpus channel mapping table for the requested layout.
channelsNumber of audio channels in the stream.
sample_rateAudio sample rate in hertz.
frame_sizeNumber of samples captured per audio frame.
continuous_audioContinuous audio.
host_audio_enabledWhether host playback should remain enabled during capture.
Returns
Microphone capture object for the requested audio layout.

Implements platf::audio_control_t.

◆ set_sink()

int platf::pa::server_t::set_sink ( const std::string & sink)
inlineoverridevirtual

Update the sink value on the backend.

Parameters
sinkAudio sink name to route or capture.
Returns
Status from updating sink.

Implements platf::audio_control_t.

◆ sink_info()

std::optional< sink_t > platf::pa::server_t::sink_info ( )
inlineoverridevirtual

Query host and virtual sink names available to Sunshine.

Returns
Host and virtual sink names when the backend can report them.

Implements platf::audio_control_t.

◆ unload_null()

int platf::pa::server_t::unload_null ( std::uint32_t i)
inline

Unload a Sunshine-created PulseAudio null sink.

Parameters
iPulseAudio introspection info supplied to the callback.
Returns
0 when the sink is absent or unloaded; nonzero on PulseAudio failure.

The documentation for this class was generated from the following file: