Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1
5#pragma once
6
7// local includes
8#include "platform/common.h"
9#include "thread_safe.h"
10#include "utility.h"
11
12#include <bitset>
13#include <memory>
14#include <optional>
15#include <string>
16
17#include <opus/opus.h>
18
19namespace audio {
29
31 std::int32_t sampleRate;
32 int channelCount;
33 int streams;
34 int coupledStreams;
35 const std::uint8_t *mapping;
36 int bitrate;
37 };
38
40 int channelCount;
41 int streams;
42 int coupledStreams;
43 std::uint8_t mapping[8];
44 };
45
46 extern opus_stream_config_t stream_configs[MAX_STREAM_CONFIG];
47
48 struct config_t {
55
56 int packetDuration;
57 int channels;
58 int mask;
59
60 stream_params_t customStreamParams;
61
62 std::bitset<MAX_FLAGS> flags;
63
64 // Who TF knows what Sunshine did
65 // putting input_only at the end of flags will always be over written to true
66 uint64_t __padding;
67
68 bool input_only;
69
81 std::string session_sink;
82
84 std::string session_server;
85 };
86
87 struct audio_ctx_t {
88 // We want to change the sink for the first stream only
89 std::unique_ptr<std::atomic_bool> sink_flag;
90
91 std::unique_ptr<platf::audio_control_t> control;
92
93 bool restore_sink;
94 platf::sink_t sink;
95 };
96
97 using buffer_t = util::buffer_t<std::uint8_t>;
98 using packet_t = std::pair<void *, buffer_t>;
99 using audio_ctx_ref_t = safe::shared_t<audio_ctx_t>::ptr_t;
100
101 void capture(safe::mail_t mail, config_t config, void *channel_data);
102
111 bool create_session_sink(const std::string &name, int channels);
112
117 void remove_session_sink(const std::string &name);
118
120 class client_mic_t {
121 public:
122 client_mic_t(std::unique_ptr<platf::mic_writer_t> writer);
123
125 void write(std::uint16_t sequence, const std::uint8_t *data, std::size_t size);
126
127 private:
128 util::safe_ptr<OpusDecoder, opus_decoder_destroy> decoder;
129 std::unique_ptr<platf::mic_writer_t> writer;
130 std::optional<std::uint16_t> last_sequence;
131 };
132
134 std::unique_ptr<client_mic_t> open_client_mic(const std::string &source);
135
146 audio_ctx_ref_t get_audio_ctx_ref();
147
163
174 bool host_sink_restore_pending(const audio_ctx_t &ctx);
175
193 void hold_host_sink();
194
213 void release_host_sink();
214} // namespace audio
bool is_audio_ctx_sink_available(const audio_ctx_t &ctx)
Check if the audio sink held by audio context is available.
Definition audio.cpp:554
bool host_sink_restore_pending(const audio_ctx_t &ctx)
Whether releasing the host sink still has something to wait for.
Definition audio.cpp:320
void release_host_sink()
Let go of a hold_host_sink() hold and restore the sink it recorded.
Definition audio.cpp:461
std::unique_ptr< client_mic_t > open_client_mic(const std::string &source)
nullptr if the session mic cannot be opened.
Definition audio.cpp:547
void hold_host_sink()
Record the host's default sink before a display change can move it.
Definition audio.cpp:435
void 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.
Definition audio.cpp:496
audio_ctx_ref_t get_audio_ctx_ref()
Get the reference to the audio context.
Definition audio.cpp:315
bool create_session_sink(const std::string &name, int channels)
Create the sink an isolated session records, and its own alone.
Definition audio.cpp:483
stream_config_e
Definition audio.h:20
@ HIGH_STEREO
High stereo.
Definition audio.h:22
@ SURROUND51
Surround 5.1.
Definition audio.h:23
@ STEREO
Stereo.
Definition audio.h:21
@ HIGH_SURROUND71
High surround 7.1.
Definition audio.h:26
@ HIGH_SURROUND51
High surround 5.1.
Definition audio.h:24
@ SURROUND71
Surround 7.1.
Definition audio.h:25
@ MAX_STREAM_CONFIG
Maximum audio stream configuration.
Definition audio.h:27
void write(std::uint16_t sequence, const std::uint8_t *data, std::size_t size)
Packets older than the last one are dropped; lost ones are concealed.
Definition audio.cpp:514
Declarations for common platform specific utilities.
Handles process-wide communication.
Definition globals.h:25
@ HIGH_QUALITY
High quality audio.
Definition audio.h:50
@ MAX_FLAGS
Maximum number of flags.
Definition audio.h:53
@ CUSTOM_SURROUND_PARAMS
Custom surround parameters.
Definition audio.h:52
@ HOST_AUDIO
Host audio.
Definition audio.h:51
std::string session_sink
Definition audio.h:81
std::string session_server
The audio server session_sink lives in, where the session has its own.
Definition audio.h:84
Declarations for thread-safe data structures.
Declarations for utility functions.