add 'none' input device

This commit is contained in:
MihailRis
2025-11-21 21:43:29 +03:00
parent 96bc395561
commit 8cfff09c0b
4 changed files with 23 additions and 11 deletions
+17 -10
View File
@@ -23,6 +23,7 @@ namespace {
std::unordered_map<speakerid_t, std::shared_ptr<Stream>> streams;
std::vector<std::unique_ptr<Channel>> channels;
util::ObjectsKeeper objects_keeper {};
std::unique_ptr<InputDevice> input_device = nullptr;
}
Channel::Channel(std::string name) : name(std::move(name)) {
@@ -151,8 +152,6 @@ public:
}
};
static std::unique_ptr<InputDevice> input_device = nullptr;
void audio::initialize(bool enabled, AudioSettings& settings) {
enabled = enabled && settings.enabled.get();
if (enabled) {
@@ -183,9 +182,9 @@ void audio::initialize(bool enabled, AudioSettings& settings) {
}, true));
}
input_device = backend->openInputDevice("", 44100, 1, 16);
if (input_device) {
input_device->startCapture();
::input_device = backend->openInputDevice("", 44100, 1, 16);
if (::input_device) {
::input_device->startCapture();
}
}
@@ -270,18 +269,26 @@ std::vector<std::string> audio::get_output_devices_names() {
}
void audio::set_input_device(const std::string& deviceName) {
logger.info() << "setting input device to " << deviceName;
if (deviceName == audio::DEVICE_NONE) {
if (::input_device) {
::input_device->stopCapture();
}
::input_device = nullptr;
return;
}
auto newDevice = backend->openInputDevice(deviceName, 44100, 1, 16);
if (newDevice == nullptr) {
logger.error() << "could not open input device: " << deviceName;
return;
}
if (input_device) {
input_device->stopCapture();
if (::input_device) {
::input_device->stopCapture();
}
input_device = std::move(newDevice);
if (input_device) {
input_device->startCapture();
::input_device = std::move(newDevice);
if (::input_device) {
::input_device->startCapture();
}
}
+2
View File
@@ -26,6 +26,8 @@ namespace audio {
constexpr inline size_t MAX_INPUT_SAMPLES = 22050;
inline std::string_view DEVICE_NONE = "none";
class Speaker;
/// @brief Audio speaker states