Sunshine master
Self-hosted game stream host for Moonlight.
platf::audio::audio_control_t Class Reference

Platform audio controller that manages sinks and microphone capture. More...

Inheritance diagram for platf::audio::audio_control_t:
[legend]
Collaboration diagram for platf::audio::audio_control_t:
[legend]

Public Types

enum class  match_field_e { device_id , device_friendly_name , adapter_friendly_name , device_description }
 Enumerates supported match field options. More...
 
using match_fields_list_t = std::vector<std::pair<match_field_e, std::wstring>>
 List of format fields used to compare audio formats.
 
using matched_field_t = std::pair<match_field_e, std::wstring>
 One matched audio-format field and its expected value.
 

Public Member Functions

std::optional< std::pair< std::wstring, std::reference_wrapper< const format_t > > > extract_virtual_sink_info (const std::string &sink)
 Extract virtual audio sink information possibly encoded in the sink name.
 
std::optional< matched_field_tfind_device_id (const match_fields_list_t &match_list)
 Search for currently present audio device_id using multiple match fields.
 
int init ()
 Initialize Windows audio policy interfaces.
 
bool install_steam_audio_drivers ()
 Installs the Steam Streaming Speakers driver, if present.
 
bool is_sink_available (const std::string &sink) override
 Check if the audio sink is available in the system.
 
audio_control_t::match_fields_list_t match_all_fields (const std::wstring &name)
 Build matching fields that all contain the same endpoint name.
 
audio_control_t::match_fields_list_t match_steam_speakers ()
 Build matching fields for Steam Streaming Speakers.
 
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.
 
void reset_default_device ()
 Resets the default audio device from Steam Streaming Speakers.
 
std::optional< std::wstring > set_format (const std::string &sink)
 
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.
 
 ~audio_control_t () override
 Destroy the Windows audio control.
 
- Public Member Functions inherited from platf::audio_control_t

Public Attributes

std::string assigned_sink
 Virtual sink assigned while Sunshine captures host audio.
 
audio::device_enum_t device_enum
 Device enumerator used to query and watch audio endpoints.
 
policy_t policy
 Windows policy configuration interface used to switch default audio devices.
 

Detailed Description

Platform audio controller that manages sinks and microphone capture.

Member Enumeration Documentation

◆ match_field_e

Enumerates supported match field options.

Enumerator
device_id 

Match device_id.

device_friendly_name 

Match endpoint friendly name.

adapter_friendly_name 

Match adapter friendly name.

device_description 

Match endpoint description.

Constructor & Destructor Documentation

◆ ~audio_control_t()

platf::audio::audio_control_t::~audio_control_t ( )
inlineoverridevirtual

Destroy the Windows audio control.

Reimplemented from platf::audio_control_t.

Member Function Documentation

◆ extract_virtual_sink_info()

std::optional< std::pair< std::wstring, std::reference_wrapper< const format_t > > > platf::audio::audio_control_t::extract_virtual_sink_info ( const std::string & sink)
inline

Extract virtual audio sink information possibly encoded in the sink name.

Parameters
sinkThe sink name
Returns
A pair of device_id and format reference if the sink name matches our naming scheme for virtual audio sinks, std::nullopt otherwise.

◆ find_device_id()

std::optional< matched_field_t > platf::audio::audio_control_t::find_device_id ( const match_fields_list_t & match_list)
inline

Search for currently present audio device_id using multiple match fields.

Parameters
match_listPairs of match fields and values
Returns
Optional pair of matched field and device_id

◆ init()

int platf::audio::audio_control_t::init ( )
inline

Initialize Windows audio policy interfaces.

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

◆ install_steam_audio_drivers()

bool platf::audio::audio_control_t::install_steam_audio_drivers ( )
inline

Installs the Steam Streaming Speakers driver, if present.

Returns
true if installation was successful.

◆ is_sink_available()

bool platf::audio::audio_control_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.

◆ match_all_fields()

audio_control_t::match_fields_list_t platf::audio::audio_control_t::match_all_fields ( const std::wstring & name)
inline

Build matching fields that all contain the same endpoint name.

Parameters
nameEndpoint name or identifier to match across all fields.
Returns
Field list requiring every supported endpoint field to match the name.

◆ match_steam_speakers()

audio_control_t::match_fields_list_t platf::audio::audio_control_t::match_steam_speakers ( )
inline

Build matching fields for Steam Streaming Speakers.

Returns
Field list used to identify Steam's virtual speaker endpoint.

◆ microphone()

std::unique_ptr< mic_t > platf::audio::audio_control_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_format()

std::optional< std::wstring > platf::audio::audio_control_t::set_format ( const std::string & sink)
inline

If the requested sink is a virtual sink, meaning no speakers attached to the host, then we can seamlessly set the format to stereo and surround sound.

Any virtual sink detected will be prefixed by: virtual-(format name) If it doesn't contain that prefix, then the format will not be changed

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

◆ set_sink()

int platf::audio::audio_control_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::audio::audio_control_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.


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