|
Hermes 0.7.0
Linux game streaming host
|
Definitions for audio capture and encoding. More...
#include <algorithm>#include <array>#include <condition_variable>#include <functional>#include <mutex>#include <set>#include <thread>#include <opus/opus_multistream.h>#include "audio.h"#include "config.h"#include "globals.h"#include "logging.h"#include "platform/common.h"#include "platform/linux/session_audio.h"#include "thread_safe.h"#include "utility.h"Go to the source code of this file.
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 | |
| int | audio::map_stream (int channels, bool quality) |
| void | audio::encodeThread (sample_queue_t samples, config_t config, void *channel_data) |
| void | audio::capture (safe::mail_t mail, config_t config, void *channel_data) |
| audio_ctx_ref_t | audio::get_audio_ctx_ref () |
| Get the reference to the audio context. | |
| bool | audio::host_sink_restore_pending (const audio_ctx_t &ctx) |
| Whether releasing the host sink still has something to wait for. | |
| void | audio::hold_host_sink () |
| Record the host's default sink before a display change can move it. | |
| void | audio::release_host_sink () |
| Let go of a hold_host_sink() hold and restore the sink it recorded. | |
| bool | audio::create_session_sink (const std::string &name, int channels) |
| Create the sink an isolated session records, and its own alone. | |
| void | audio::remove_session_sink (const std::string &name) |
| Remove a sink made by create_session_sink(). Removing one that is already gone is not an error. | |
| std::unique_ptr< client_mic_t > | audio::open_client_mic (const std::string &source) |
| nullptr if the session mic cannot be opened. | |
| bool | audio::is_audio_ctx_sink_available (const audio_ctx_t &ctx) |
| Check if the audio sink held by audio context is available. | |
Variables | |
| constexpr auto | audio::SAMPLE_RATE = 48000 |
| opus_stream_config_t | audio::stream_configs [MAX_STREAM_CONFIG] |
Definitions for audio capture and encoding.
Definition in file audio.cpp.
| 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>>> |
| void audio::capture | ( | safe::mail_t | mail, |
| config_t | config, | ||
| void * | channel_data ) |
| bool audio::create_session_sink | ( | const std::string & | name, |
| int | channels ) |
Create the sink an isolated session records, and its own alone.
Named after the session rather than after a channel layout, because there is one per session and its layout is whatever that client negotiated. Nothing is made anyone's default. Returns false where the platform has no virtual sinks, which leaves the caller to fall back to the shared ones.
| 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.
Examples
| void audio::hold_host_sink | ( | ) |
Record the host's default sink before a display change can move it.
A monitor's audio device belongs to the monitor: turn the output off - which is what the exclusive virtual display does to the local screens - and the sound server drops that sink and moves the default onto whatever is left. A session that reads the default after that has already missed the sink the user was listening on, and will faithfully restore the replacement when it ends.
Taking the audio context here reads the default while it is still the user's own, and holds the context open so the restore is timed by release_host_sink() rather than by whenever the last stream happens to end.
Holding a hold that is already held does nothing. A hold that is never released lasts until Hermes exits.
| bool audio::host_sink_restore_pending | ( | const audio_ctx_t & | ctx | ) |
Whether releasing the host sink still has something to wait for.
The question release_host_sink() asks between sleeps. False means restore now - either nothing was recorded to go back to, or what was recorded is present again. True means the recorded sink is still missing, and a restore issued now would name a sink the sound server cannot resolve: which is what happens for the seconds it takes a monitor coming out of an exclusive session to register its audio device again.
| bool audio::is_audio_ctx_sink_available | ( | const audio_ctx_t & | ctx | ) |
Check if the audio sink held by audio context is available.
Examples
| std::unique_ptr< client_mic_t > audio::open_client_mic | ( | const std::string & | source | ) |
| void audio::release_host_sink | ( | ) |
Let go of a hold_host_sink() hold and restore the sink it recorded.
The sink a disabled output took with it does not come back the instant the monitor does, so the restore is not issued until the recorded sink is present again, or until the wait for it runs out after ten seconds. This returns straight away; the waiting is done on a thread of its own.
The wait is bounded that tightly because the host's default is still the virtual sink until it ends. A device that never comes back - a headset unplugged during the session - therefore costs that much quiet and no more, and then leaves the choice of default to the sound server, which is the right answer once the device the user picked is gone.
A hold taken again while that wait is running cancels it and keeps the context, which is what a second session starting before the first one's monitors are back should do.
| void audio::remove_session_sink | ( | const std::string & | name | ) |