Skip to content
Snippets Groups Projects
Commit bceb3f15 authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

video settings: only use video device names for display

Change-Id: I7ffc37e8df24d97885ac52ce45145ee0c1f659d0
parent f3567cc4
Branches
No related tags found
No related merge requests found
......@@ -318,7 +318,7 @@ RenderManager::removeDistantRenderer(const std::string& id)
void
RenderManager::slotDeviceEvent()
{
auto defaultDeviceName = avModel_.getDefaultDeviceName();
auto defaultDevice = avModel_.getDefaultDevice();
auto currentCaptureDevice = avModel_.getCurrentVideoCaptureDevice();
// decide whether a device has plugged, unplugged, or nothing has changed
auto deviceList = avModel_.getDevices();
......@@ -342,14 +342,14 @@ RenderManager::slotDeviceEvent()
stopPreviewing();
} else if (deviceEvent == DeviceEvent::RemovedCurrent &&
currentDeviceListSize > 0) {
avModel_.setCurrentVideoCaptureDevice(defaultDeviceName);
avModel_.setCurrentVideoCaptureDevice(defaultDevice);
startPreviewing(true);
} else {
startPreviewing();
}
} else if (deviceEvent == DeviceEvent::Added &&
currentDeviceListSize == 1) {
avModel_.setCurrentVideoCaptureDevice(defaultDeviceName);
avModel_.setCurrentVideoCaptureDevice(defaultDevice);
}
emit videoDeviceListChanged();
......
......@@ -271,7 +271,7 @@ void SettingsWidget::slotAccountListChanged()
} else {
disconnectAccountConnections();
}
auto device = LRCInstance::avModel().getDefaultDeviceName();
auto device = LRCInstance::avModel().getDefaultDevice();
if (LRCInstance::avModel().getCurrentVideoCaptureDevice().empty()) {
LRCInstance::avModel().setCurrentVideoCaptureDevice(device);
}
......@@ -1042,13 +1042,26 @@ void SettingsWidget::slotAudioInputIndexChanged(int index)
void SettingsWidget::slotDeviceBoxCurrentIndexChanged(int index)
{
std::string device = ui->deviceBox->itemData(index, Qt::DisplayRole)
std::string deviceName = ui->deviceBox->itemData(index, Qt::DisplayRole)
.toString()
.toStdString();
LRCInstance::avModel().setCurrentVideoCaptureDevice(device);
LRCInstance::avModel().setDefaultDevice(device);
setFormatListForDevice(device);
auto devices = LRCInstance::avModel().getDevices();
try {
auto iter = std::find_if(devices.begin(), devices.end(),
[deviceName](const std::string& d) {
auto settings = LRCInstance::avModel().getDeviceSettings(d);
return settings.name == deviceName;
});
if (iter == devices.end()) {
qWarning() << "Couldn't find device: " << deviceName.c_str();
return;
}
auto deviceId = *iter;
LRCInstance::avModel().setCurrentVideoCaptureDevice(deviceId);
LRCInstance::avModel().setDefaultDevice(deviceId);
setFormatListForDevice(deviceId);
startPreviewing(true);
} catch (...) {}
}
void SettingsWidget::slotFormatBoxCurrentIndexChanged(int index)
......@@ -1056,8 +1069,12 @@ void SettingsWidget::slotFormatBoxCurrentIndexChanged(int index)
auto resolution = formatIndexList_.at(index).first;
auto rate = formatIndexList_.at(index).second;
auto device = LRCInstance::avModel().getCurrentVideoCaptureDevice();
lrc::api::video::Settings settings {{}, device, rate, resolution};
try {
auto settings = LRCInstance::avModel().getDeviceSettings(device);
settings.rate = rate;
settings.size = resolution;
LRCInstance::avModel().setDeviceSettings(settings);
} catch (...) {}
}
void SettingsWidget::startPreviewing(bool force)
......@@ -1080,6 +1097,7 @@ void SettingsWidget::setFormatListForDevice(const std::string& device)
if (deviceCapabilities.size() == 0) {
return;
}
try {
auto currentSettings = LRCInstance::avModel().getDeviceSettings(device);
auto currentChannel = currentSettings.channel;
currentChannel = currentChannel.empty() ? "default" : currentChannel;
......@@ -1103,6 +1121,9 @@ void SettingsWidget::setFormatListForDevice(const std::string& device)
}
ui->formatBox->blockSignals(false);
} catch(const std::exception& e) {
qWarning() << e.what();
}
}
void SettingsWidget::slotSetHardwareAccel(bool state)
......@@ -1178,7 +1199,10 @@ SettingsWidget::populateVideoSettings()
auto currentCaptureDevice = LRCInstance::avModel().getCurrentVideoCaptureDevice();
auto deviceIndex = Utils::indexInVector(devices, currentCaptureDevice);
for (auto d : devices) {
ui->deviceBox->addItem(QString::fromStdString(d).toUtf8());
try {
auto settings = LRCInstance::avModel().getDeviceSettings(d);
ui->deviceBox->addItem(QString::fromStdString(settings.name).toUtf8());
} catch (...) {}
}
ui->deviceBox->setCurrentIndex(deviceIndex);
setFormatListForDevice(LRCInstance::avModel().getCurrentVideoCaptureDevice());
......
......@@ -435,15 +435,17 @@ VideoView::resetPreview()
} else {
auto device = LRCInstance::avModel().getCurrentVideoCaptureDevice();
if (device.empty()) {
device = LRCInstance::avModel().getDefaultDeviceName();
device = LRCInstance::avModel().getDefaultDevice();
}
if (device.empty()) {
previewWidget_->setVisible(false);
return;
}
try {
auto settings = LRCInstance::avModel().getDeviceSettings(device);
width = QString::fromStdString(settings.size).split("x")[0].toInt();
height = QString::fromStdString(settings.size).split("x")[1].toInt();
} catch (...) {}
}
auto newSize = previewWidget_->getScaledSize(width, height);
previewWidget_->setupGeometry(newSize);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment