From ec8c0eb3c2149a8e86a7f9986caecf135969e2a2 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 18 Nov 2016 19:23:35 -0800 Subject: [PATCH] Fix FPS setting and crash in reapplying settings. --- src/SourceImpl.cpp | 5 +++-- src/USBCameraImpl.cpp | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/SourceImpl.cpp b/src/SourceImpl.cpp index 3bc2c596d2..d5db1f9604 100644 --- a/src/SourceImpl.cpp +++ b/src/SourceImpl.cpp @@ -88,8 +88,9 @@ llvm::ArrayRef SourceImpl::EnumerateProperties( if (!m_properties_cached && !CacheProperties(status)) return llvm::ArrayRef{}; std::lock_guard lock(m_mutex); - for (int i = 0; i < static_cast(m_propertyData.size()); ++i) - vec.push_back(i + 1); + for (int i = 0; i < static_cast(m_propertyData.size()); ++i) { + if (m_propertyData[i]) vec.push_back(i + 1); + } return vec; } diff --git a/src/USBCameraImpl.cpp b/src/USBCameraImpl.cpp index b41ce5fa23..28dd07d229 100644 --- a/src/USBCameraImpl.cpp +++ b/src/USBCameraImpl.cpp @@ -636,7 +636,7 @@ void USBCameraImpl::DeviceConnect() { std::unique_lock lock2(m_mutex); for (std::size_t i = 0; i < m_propertyData.size(); ++i) { const auto& prop = m_propertyData[i]; - if (!prop->valueSet) continue; + if (!prop || !prop->valueSet) continue; if (!DeviceSetProperty(lock2, static_cast(*prop))) WARNING("USB " << m_path << ": failed to set property " << prop->name); } @@ -786,7 +786,11 @@ void USBCameraImpl::DeviceProcessCommands() { } else if (newMode.fps != m_mode.fps) { m_mode = newMode; lock.unlock(); + // Need to stop streaming to set FPS + bool wasStreaming = m_streaming; + if (wasStreaming) DeviceStreamOff(); DeviceSetFPS(); + if (wasStreaming) DeviceStreamOn(); Notifier::GetInstance().NotifySource(*this, CS_SOURCE_VIDEOMODE_CHANGED); lock.lock();