|
7 | 7 | #include "DspHost.h" |
8 | 8 | #include "PwDevice.h" |
9 | 9 | #include "Utils.h" |
10 | | -#include "config/AppConfig.h" |
11 | 10 |
|
12 | 11 | #include <QDebug> |
13 | 12 |
|
@@ -37,19 +36,84 @@ PipewireAudioService::PipewireAudioService() |
37 | 36 | }); |
38 | 37 |
|
39 | 38 | mgr.get()->device_output_route_changed.connect([&](DeviceInfo device) { |
40 | | - if (device.output_route_available == SPA_PARAM_AVAILABILITY_no) { |
| 39 | + if (device.output_route_available == SPA_PARAM_AVAILABILITY_no) |
| 40 | + { |
41 | 41 | return; |
42 | 42 | } |
43 | 43 |
|
44 | | - util::debug(log_tag + "device " + device.name + " has changed its output route to: " + device.output_route_name); |
| 44 | + NodeInfo target_node; |
| 45 | + for (const auto& [ts, node] : mgr.get()->node_map) |
| 46 | + { |
| 47 | + target_node = node; |
| 48 | + |
| 49 | + if (node.device_id == device.id && node.media_class == "Audio/Sink") |
| 50 | + { |
| 51 | + target_node = node; |
| 52 | + break; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + if (target_node.id != SPA_ID_INVALID) |
| 57 | + { |
| 58 | + emit outputDeviceChanged(QString::fromStdString(target_node.name), QString::fromStdString(device.output_route_name)); |
| 59 | + } |
| 60 | + else |
| 61 | + { |
| 62 | + util::debug(log_tag + "device_output_route_changed: could not find target node"); |
| 63 | + } |
45 | 64 | }); |
| 65 | + |
| 66 | + connect(&AppConfig::instance(), &AppConfig::updated, this, &PipewireAudioService::onAppConfigUpdated); |
46 | 67 | } |
47 | 68 |
|
48 | 69 | PipewireAudioService::~PipewireAudioService() |
49 | 70 | { |
50 | 71 | delete plugin; |
51 | 72 | } |
52 | 73 |
|
| 74 | +void PipewireAudioService::onAppConfigUpdated(const AppConfig::Key &key, const QVariant &value) |
| 75 | +{ |
| 76 | + switch (key) { |
| 77 | + case AppConfig::AudioOutputDevice: { |
| 78 | + const auto name = value.toString(); |
| 79 | + |
| 80 | + if (name.isEmpty()) |
| 81 | + { |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + uint device_id = SPA_ID_INVALID; |
| 86 | + for (const auto& [ts, node2] : mgr.get()->node_map) |
| 87 | + { |
| 88 | + if (node2.name == name.toStdString()) |
| 89 | + { |
| 90 | + device_id = node2.device_id; |
| 91 | + break; |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + if (device_id != SPA_ID_INVALID) |
| 96 | + { |
| 97 | + for (const auto& device : mgr.get()->list_devices) |
| 98 | + { |
| 99 | + if (device.id == device_id) |
| 100 | + { |
| 101 | + emit outputDeviceChanged(name, QString::fromStdString(device.output_route_name)); |
| 102 | + break; |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + else |
| 107 | + { |
| 108 | + util::debug(log_tag + "AudioOutputDevice changed: could not find target node"); |
| 109 | + } |
| 110 | + break; |
| 111 | + } |
| 112 | + default: |
| 113 | + break; |
| 114 | + } |
| 115 | +} |
| 116 | + |
53 | 117 | void PipewireAudioService::update(DspConfig *config) |
54 | 118 | { |
55 | 119 | auto* ptr = plugin->host(); |
@@ -105,6 +169,8 @@ DspStatus PipewireAudioService::status() |
105 | 169 | } |
106 | 170 |
|
107 | 171 | #include <iostream> |
| 172 | + |
| 173 | +#include <config/AppConfig.h> |
108 | 174 | void PipewireAudioService::enumerateLiveprogVariables() |
109 | 175 | { |
110 | 176 |
|
|
0 commit comments