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

Definitions for audio capture and encoding. More...

#include <thread>
#include <opus/opus_multistream.h>
#include "audio.h"
#include "config.h"
#include "globals.h"
#include "logging.h"
#include "platform/common.h"
#include "thread_safe.h"
#include "utility.h"
Include dependency graph for audio.cpp:

Typedefs

using audio::opus_t = util::safe_ptr<OpusMSEncoder, opus_multistream_encoder_destroy>
 
using audio::sample_queue_t = std::shared_ptr<safe::queue_t<std::vector<float>>>
 

Functions

void audio::capture (safe::mail_t mail, config_t config, void *channel_data)
 
void audio::encodeThread (sample_queue_t samples, config_t config, void *channel_data)
 
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.
 
int audio::map_stream (int channels, bool quality)
 

Variables

constexpr auto audio::SAMPLE_RATE = 48000
 
opus_stream_config_t audio::stream_configs [MAX_STREAM_CONFIG]
 

Detailed Description

Definitions for audio capture and encoding.

Function Documentation

◆ 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;