From aaf6a2abd66cf9006edc39ad1b2753f62e77eb77 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Wed, 16 Apr 2014 17:14:57 -0400 Subject: [PATCH] video: don't assume that v4l lists are populated Refs #45484 --- daemon/src/video/video_v4l2.cpp | 2 ++ daemon/src/video/video_v4l2_list.cpp | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/daemon/src/video/video_v4l2.cpp b/daemon/src/video/video_v4l2.cpp index 62c04eb829..b0daf86fe0 100644 --- a/daemon/src/video/video_v4l2.cpp +++ b/daemon/src/video/video_v4l2.cpp @@ -29,6 +29,7 @@ */ #include <string> +#include <cassert> #include <algorithm> #include <vector> #include <climits> @@ -366,6 +367,7 @@ VideoV4l2Device::getChannel(const string &name) const if (item.name == name) return item; + assert(not channels_.empty()); return channels_.back(); } diff --git a/daemon/src/video/video_v4l2_list.cpp b/daemon/src/video/video_v4l2_list.cpp index 3dd59aa159..430a55997d 100644 --- a/daemon/src/video/video_v4l2_list.cpp +++ b/daemon/src/video/video_v4l2_list.cpp @@ -213,14 +213,34 @@ VideoV4l2ListThread::~VideoV4l2ListThread() void VideoV4l2ListThread::updateDefault() { + if (devices_.empty()) { + ERROR("No devices"); + return; + } + const std::string &name = devices_.back().name; auto controls = Manager::instance().getVideoControls(); controls->setActiveDevice(name); - const auto channel = devices_.back().getChannelList()[0]; + + const auto channelList = devices_.back().getChannelList(); + if (channelList.empty()) { + ERROR("No channel list present"); + return; + } + + const auto channel = channelList[0]; controls->setActiveDeviceChannel(channel); - const auto size = devices_.back().getChannel(name).getSizeList()[0]; + + const auto sizeList = devices_.back().getChannel(name).getSizeList(); + if (sizeList.empty()) { + ERROR("No size list present"); + return; + } + + const auto size = sizeList[0]; controls->setActiveDeviceSize(size); const auto rateList(controls->getDeviceRateList(name, channel, size)); + // compare by integer value const auto highest = std::max_element(rateList.begin(), rateList.end(), [] (const std::string &l, const std::string &r) { -- GitLab