| 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 |
nothing calls this directly
no test coverage detected