MCPcopy Create free account
hub / github.com/ClassicOldSong/Apollo / capture

Function capture

src/audio.cpp:130–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128 }
129
130 void capture(safe::mail_t mail, config_t config, void *channel_data) {
131 auto shutdown_event = mail->event<bool>(mail::shutdown);
132 if (!config::audio.stream || config.input_only) {
133 shutdown_event->view();
134 return;
135 }
136 auto stream = stream_configs[map_stream(config.channels, config.flags[config_t::HIGH_QUALITY])];
137 if (config.flags[config_t::CUSTOM_SURROUND_PARAMS]) {
138 apply_surround_params(stream, config.customStreamParams);
139 }
140
141 auto ref = get_audio_ctx_ref();
142 if (!ref) {
143 return;
144 }
145
146 auto init_failure_fg = util::fail_guard([&shutdown_event]() {
147 BOOST_LOG(error) << "Unable to initialize audio capture. The stream will not have audio."sv;
148
149 // Wait for shutdown to be signalled if we fail init.
150 // This allows streaming to continue without audio.
151 shutdown_event->view();
152 return;
153 });
154
155 auto &control = ref->control;
156 if (!control) {
157 return;
158 }
159
160 // Order of priority:
161 // 1. Virtual sink
162 // 2. Audio sink
163 // 3. Host
164 std::string *sink = &ref->sink.host;
165 if (!config::audio.sink.empty()) {
166 sink = &config::audio.sink;
167 }
168
169 // Prefer the virtual sink if host playback is disabled or there's no other sink
170 if (ref->sink.null && (!config.flags[config_t::HOST_AUDIO] || sink->empty())) {
171 auto &null = *ref->sink.null;
172 switch (stream.channelCount) {
173 case 2:
174 sink = &null.stereo;
175 break;
176 case 6:
177 sink = &null.surround51;
178 break;
179 case 8:
180 sink = &null.surround71;
181 break;
182 }
183 }
184
185 BOOST_LOG(info) << "Selected audio sink: "sv << *sink;
186
187 // Only the first to start a session may change the default sink

Callers

nothing calls this directly

Calls 15

map_streamFunction · 0.85
apply_surround_paramsFunction · 0.85
get_audio_ctx_refFunction · 0.85
fail_guardFunction · 0.85
moveFunction · 0.85
viewMethod · 0.80
disableMethod · 0.80
joinMethod · 0.80
adjust_thread_priorityFunction · 0.50
set_sinkMethod · 0.45
microphoneMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected