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

Declarations for audio capture and encoding. More...

#include "platform/common.h"
#include "thread_safe.h"
#include "utility.h"
#include <bitset>
Include dependency graph for audio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  audio::audio_ctx_t
 Shared audio device state used while streams are active. More...
 
struct  audio::config_t
 Audio capture and encoder settings for a stream. More...
 
struct  audio::opus_stream_config_t
 Static Opus encoder layout for one advertised audio mode. More...
 
struct  audio::stream_params_t
 Custom Opus channel layout supplied by configuration. More...
 

Typedefs

using audio::audio_ctx_ref_t = safe::shared_t<audio_ctx_t>::ptr_t
 Shared mailbox reference to the global audio context.
 
using audio::buffer_t = util::buffer_t<std::uint8_t>
 Byte buffer used for encoded audio packet payloads.
 
using audio::packet_t = std::pair<void *, buffer_t>
 Encoded audio packet paired with platform channel metadata.
 

Enumerations

enum  audio::stream_config_e : int {
  audio::STEREO , audio::HIGH_STEREO , audio::SURROUND51 , audio::HIGH_SURROUND51 ,
  audio::SURROUND71 , audio::HIGH_SURROUND71 , audio::MAX_STREAM_CONFIG
}
 Supported Opus channel layouts advertised to Moonlight clients. More...
 

Functions

void audio::capture (safe::mail_t mail, config_t config, void *channel_data)
 Run the capture loop for this backend.
 
audio_ctx_ref_t audio::get_audio_ctx_ref ()
 Get the reference to the audio context.
 
bool audio::is_audio_ctx_sink_available (const audio_ctx_t &ctx)
 Check if the audio sink held by audio context is available.
 

Detailed Description

Declarations for audio capture and encoding.

Enumeration Type Documentation

◆ stream_config_e

Supported Opus channel layouts advertised to Moonlight clients.

Enumerator
STEREO 

Stereo.

HIGH_STEREO 

High stereo.

SURROUND51 

Surround 5.1.

HIGH_SURROUND51 

High surround 5.1.

SURROUND71 

Surround 7.1.

HIGH_SURROUND71 

High surround 7.1.

MAX_STREAM_CONFIG 

Maximum audio stream configuration.

Function Documentation

◆ capture()

void audio::capture ( safe::mail_t mail,
config_t config,
void * channel_data )

Run the capture loop for this backend.

Capture, encode, and publish audio packets for a stream.

Parameters
mailMailbox used to publish encoded audio packets.
configAudio capture and encoder settings.
channel_dataPlatform-specific capture channel pointer.

◆ get_audio_ctx_ref()

audio_ctx_ref_t audio::get_audio_ctx_ref ( )

Get the reference to the audio context.

Returns
A shared pointer reference to audio context.
Note
Aside from the configuration purposes, it can be used to extend the audio sink lifetime to capture sink earlier and restore it later.

*Examples**

audio_ctx_ref_t audio = get_audio_ctx_ref()

◆ is_audio_ctx_sink_available()

bool audio::is_audio_ctx_sink_available ( const audio_ctx_t & ctx)

Check if the audio sink held by audio context is available.

Returns
True if available (and can probably be restored), false otherwise.
Note
Useful for delaying the release of audio context shared pointer (which tries to restore original sink).

*Examples**

audio_ctx_ref_t audio = get_audio_ctx_ref()
if (audio.get()) {
return is_audio_ctx_sink_available(*audio.get());
}
return false;
Parameters
ctxNative context object used by the operation or callback.