Sunshine master
Self-hosted game stream host for Moonlight.
audio.cpp File Reference

Definitions for Windows audio capture. More...

#include <format>
#include <Audioclient.h>
#include <avrt.h>
#include <mmdeviceapi.h>
#include <newdev.h>
#include <roapi.h>
#include <synchapi.h>
#include "src/config.h"
#include "src/logging.h"
#include "src/platform/common.h"
#include "utf_utils.h"
#include "PolicyConfig.h"
Include dependency graph for audio.cpp:

Classes

class  platf::audio::audio_control_t
 Platform audio controller that manages sinks and microphone capture. More...
 
class  platf::audio::audio_notification_t
 Windows audio endpoint notification callback registered with MMDevice. More...
 
class  platf::audio::co_init_t
 Initializes COM for the current thread and uninitializes it on exit. More...
 
struct  platf::audio::format_t
 Windows audio format details selected for capture. More...
 
class  platf::audio::mic_wasapi_t
 WASAPI microphone capture stream and endpoint notification state. More...
 
class  platf::audio::prop_var_t
 RAII wrapper that initializes and clears a Windows PROPVARIANT. More...
 

Typedefs

using platf::audio::audio_capture_t = util::safe_ptr<IAudioCaptureClient, Release<IAudioCaptureClient>>
 COM pointer to the WASAPI capture client interface.
 
using platf::audio::audio_client_t = util::safe_ptr<IAudioClient, Release<IAudioClient>>
 COM pointer to the WASAPI audio client interface.
 
using platf::audio::collection_t = util::safe_ptr<IMMDeviceCollection, Release<IMMDeviceCollection>>
 COM pointer to a collection of Windows audio endpoint devices.
 
using platf::audio::device_enum_t = util::safe_ptr<IMMDeviceEnumerator, Release<IMMDeviceEnumerator>>
 COM device enumerator pointer for WASAPI endpoint discovery.
 
using platf::audio::device_t = util::safe_ptr<IMMDevice, Release<IMMDevice>>
 COM pointer to a Windows audio endpoint device.
 
using platf::audio::handle_t = util::safe_ptr_v2<void, BOOL, CloseHandle>
 Windows HANDLE wrapper closed with CloseHandle.
 
using platf::audio::policy_t = util::safe_ptr<IPolicyConfig, Release<IPolicyConfig>>
 COM pointer to the Windows policy configuration interface.
 
using platf::audio::prop_t = util::safe_ptr<IPropertyStore, Release<IPropertyStore>>
 COM pointer to a Windows property store.
 
using platf::audio::wave_format_t = util::safe_ptr<WAVEFORMATEX, co_task_free<WAVEFORMATEX>>
 CoTaskMem-allocated WAVEFORMATEX pointer.
 
using platf::audio::wstring_t = util::safe_ptr<WCHAR, co_task_free<WCHAR>>
 CoTaskMem-allocated wide string pointer.
 

Functions

std::unique_ptr< audio_control_tplatf::audio_control ()
 Create the platform audio controller.
 
template<class T >
void platf::audio::co_task_free (T *p)
 Free memory allocated by COM task APIs.
 
device_t platf::audio::default_device (device_enum_t &device_enum)
 Query the default Windows render endpoint.
 
int platf::dxgi::init ()
 Initialize the Windows audio-control backend.
 
std::unique_ptr< deinit_tplatf::init ()
 Initialize the platform-specific high precision timer.
 
audio_client_t platf::audio::make_audio_client (device_t &device, const format_t &format)
 Create audio client.
 
template<class T >
void platf::audio::Release (T *p)
 Release the COM or platform reference owned by the pointer.
 

Variables

const std::array< const format_t, 3 > platf::audio::formats
 Formats.
 
const PROPERTYKEY PKEY_Device_DeviceDesc
 Property key for a device description.
 
const PROPERTYKEY PKEY_Device_FriendlyName
 Property key for a device friendly name.
 
const PROPERTYKEY PKEY_DeviceInterface_FriendlyName
 Property key for a device interface friendly name.
 

Detailed Description

Definitions for Windows audio capture.

Function Documentation

◆ audio_control()

std::unique_ptr< audio_control_t > platf::audio_control ( )

Create the platform audio controller.

Returns
Platform audio controller, or nullptr when audio control is unavailable.

◆ co_task_free()

template<class T >
void platf::audio::co_task_free ( T * p)

Free memory allocated by COM task APIs.

Parameters
pPointer passed to the deleter or conversion helper.

◆ default_device()

device_t platf::audio::default_device ( device_enum_t & device_enum)

Query the default Windows render endpoint.

Parameters
device_enumWindows multimedia device enumerator.
Returns
Default render endpoint, or an empty handle if lookup fails.

◆ init() [1/2]

int platf::dxgi::init ( )

Initialize the Windows audio-control backend.

Initialize global D3D11 desktop duplication support.

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

◆ init() [2/2]

std::unique_ptr< deinit_t > platf::init ( )
nodiscard

Initialize the platform-specific high precision timer.

Initialize the Linux high-precision timer file descriptor.

Returns
Cleanup handle for initialized platform resources, or null if none are needed.

◆ make_audio_client()

audio_client_t platf::audio::make_audio_client ( device_t & device,
const format_t & format )

Create audio client.

Parameters
deviceD3D, audio, or platform device used by the operation.
formatPixel, audio, or protocol format being converted.
Returns
Constructed audio client object.

◆ Release()

template<class T >
void platf::audio::Release ( T * p)

Release the COM or platform reference owned by the pointer.

Parameters
pPointer passed to the deleter or conversion helper.

Variable Documentation

◆ formats

const std::array<const format_t, 3> platf::audio::formats
Initial value:
= {
format_t {
2,
"Stereo",
waveformat_mask_stereo,
create_virtual_sink_waveformats<2>(),
},
6,
"Surround 5.1",
waveformat_mask_surround51_with_backspeakers,
create_virtual_sink_waveformats<6>(),
},
format_t {
8,
"Surround 7.1",
waveformat_mask_surround71,
create_virtual_sink_waveformats<8>(),
},
}
Windows audio format details selected for capture.
Definition audio.cpp:315

Formats.