Skip to content
Snippets Groups Projects
Commit ccdd3eba authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6179: VideoV4l2List uses a signed device index to signal an error

Add a method to find a device by its name (to be used later in preferences)
parent 73bc5d46
No related branches found
No related tags found
No related merge requests found
...@@ -41,10 +41,14 @@ using namespace sfl_video; ...@@ -41,10 +41,14 @@ using namespace sfl_video;
int main() int main()
{ {
unsigned idx; int idx;
VideoV4l2List list; VideoV4l2List list;
std::vector<std::string> v = list.getDeviceList(); std::vector<std::string> v = list.getDeviceList();
idx = list.getDeviceIndex(); idx = list.getDeviceIndex();
if (idx < 0) {
cout << "No devices found!" << endl;
return 0;
}
list.setDevice(idx); list.setDevice(idx);
size_t i, n = v.size(); size_t i, n = v.size();
......
...@@ -57,7 +57,7 @@ extern "C" { ...@@ -57,7 +57,7 @@ extern "C" {
namespace sfl_video { namespace sfl_video {
VideoV4l2List::VideoV4l2List() : _currentDevice(0) VideoV4l2List::VideoV4l2List() : _currentDevice(-1)
{ {
#ifdef HAVE_UDEV #ifdef HAVE_UDEV
struct udev *udev; struct udev *udev;
...@@ -196,6 +196,8 @@ bool VideoV4l2List::addDevice(const std::string &dev) ...@@ -196,6 +196,8 @@ bool VideoV4l2List::addDevice(const std::string &dev)
VideoV4l2Device v(fd, s); VideoV4l2Device v(fd, s);
GiveUniqueName(v, devices); GiveUniqueName(v, devices);
devices.push_back(v); devices.push_back(v);
if (_currentDevice < 0)
_currentDevice = 0;
close(fd); close(fd);
return true; return true;
...@@ -230,7 +232,16 @@ std::vector<std::string> VideoV4l2List::getDeviceList(void) ...@@ -230,7 +232,16 @@ std::vector<std::string> VideoV4l2List::getDeviceList(void)
return v; return v;
} }
unsigned VideoV4l2List::getDeviceIndex() int VideoV4l2List::getDeviceIndex(const std::string &name)
{
for (size_t i = 0; i < devices.size(); i++)
if (devices[i].name == name)
return i;
return -1;
}
int VideoV4l2List::getDeviceIndex()
{ {
return _currentDevice; return _currentDevice;
} }
......
...@@ -43,7 +43,8 @@ class VideoV4l2List { ...@@ -43,7 +43,8 @@ class VideoV4l2List {
VideoV4l2List(); VideoV4l2List();
void setDevice(unsigned index); void setDevice(unsigned index);
unsigned getDeviceIndex(void); int getDeviceIndex(void);
int getDeviceIndex(const std::string &name);
std::vector<std::string> getDeviceList(void); std::vector<std::string> getDeviceList(void);
VideoV4l2Device &getDevice(void); VideoV4l2Device &getDevice(void);
...@@ -53,7 +54,7 @@ class VideoV4l2List { ...@@ -53,7 +54,7 @@ class VideoV4l2List {
*/ */
bool addDevice(const std::string &dev); bool addDevice(const std::string &dev);
std::vector<VideoV4l2Device> devices; std::vector<VideoV4l2Device> devices;
unsigned _currentDevice; int _currentDevice;
}; };
} // namespace sfl_video } // namespace sfl_video
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment