* @brief Set output device */
| 157 | * @brief Set output device |
| 158 | */ |
| 159 | API::CommandResponse API::Handlers::AudioHandler::setOutputDevice(const QString& id, |
| 160 | const QJsonObject& params) |
| 161 | { |
| 162 | if (!params.contains(QStringLiteral("deviceIndex"))) { |
| 163 | return CommandResponse::makeError( |
| 164 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: deviceIndex")); |
| 165 | } |
| 166 | |
| 167 | const int device_index = params.value(QStringLiteral("deviceIndex")).toInt(); |
| 168 | |
| 169 | const auto& devices = IO::ConnectionManager::instance().audio()->outputDeviceList(); |
| 170 | if (device_index < 0 || device_index >= devices.count()) { |
| 171 | return CommandResponse::makeError( |
| 172 | id, |
| 173 | ErrorCode::InvalidParam, |
| 174 | QString(QStringLiteral("Invalid deviceIndex: %1. Valid range: 0-%2")) |
| 175 | .arg(device_index) |
| 176 | .arg(devices.count() - 1)); |
| 177 | } |
| 178 | |
| 179 | IO::ConnectionManager::instance().audio()->setSelectedOutputDevice(device_index); |
| 180 | |
| 181 | QJsonObject result; |
| 182 | result[QStringLiteral("deviceIndex")] = device_index; |
| 183 | result[QStringLiteral("deviceName")] = devices.at(device_index); |
| 184 | return CommandResponse::makeSuccess(id, result); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * @brief Set sample rate |
nothing calls this directly
no test coverage detected