From 3799771e0a972f83d1052fc37e65191e27fed505 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Tue, 7 Sep 2021 00:17:36 +0200 Subject: [PATCH] reading name of device --- video.cc | 37 ++++++++++++++++++++++++++ video.h | 40 ++++++++++++++++++++++++++++ videodev.cc | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 video.cc create mode 100644 video.h create mode 100644 videodev.cc diff --git a/video.cc b/video.cc new file mode 100644 index 0000000..f112426 --- /dev/null +++ b/video.cc @@ -0,0 +1,37 @@ +/*************************************************************************************** + * + * video.cc is part of SimpleSkyCam. + * + *****************************************************************************************/ + +#include +#include +#include "gui.h" +#include "video.h" + +VideoDev videodev; + +void cb_video_refreshlist (GtkWidget *widget, gpointer data) { + GtkWidget *cbox = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cb-videodev")); + GtkListStore *model = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(cbox))); + + std::list devlist; + std::list::iterator iter; + + printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); + + if (model == NULL) { + model = gtk_list_store_new(1, G_TYPE_STRING); + gtk_combo_box_set_model(GTK_COMBO_BOX(cbox),GTK_TREE_MODEL(model)); + } + + gtk_list_store_clear(GTK_LIST_STORE(model)); + + if (videodev.GetDeviceList(&devlist)) { + for (iter = devlist.begin(); iter != devlist.end(); iter++) { + gtk_list_store_insert_with_values(GTK_LIST_STORE(model), NULL, -1, + 0, iter->c_str(), + -1); + } + } +} diff --git a/video.h b/video.h new file mode 100644 index 0000000..b25b6bb --- /dev/null +++ b/video.h @@ -0,0 +1,40 @@ +/*************************************************************************************** + * + * video.h is part of SimpleSkyCam. + * + ***************************************************************************************/ + +#ifndef _VIDEO_H_ +#define _VIDEO_H_ + +#include +#include +#include "gui.h" +#include "config.h" + +enum { + VDEV_STATUS_UNKNOWN, + VDEV_STATUS_OK, + VDEV_STATUS_ERROR +}; + +class VideoDev { +private: + std::string conf_device; + std::string conf_devicename; + gboolean (*callback)(gpointer data); + int status; +public: + VideoDev(); + ~VideoDev(); + + int Start(std::string dev, gboolean (*callback_func)(gpointer data)); // will start a new thread + int Stop(); // stop video processing and stop the pthread + + int GetDeviceList(std::list *list); + + int GetStatus() { return status; }; +}; + +#endif // _VIDEO_H_ + diff --git a/videodev.cc b/videodev.cc new file mode 100644 index 0000000..ee5d643 --- /dev/null +++ b/videodev.cc @@ -0,0 +1,75 @@ +/*************************************************************************************** + * + * videodev.cc is part of SimpleSkyCam. + * + *****************************************************************************************/ + +#include +#include +#include +#include +#include + +#include +#include + +#include "video.h" + + +VideoDev::VideoDev() { + conf_device = ""; + conf_devicename = ""; + status = VDEV_STATUS_OK; + callback = NULL; +}; + + +VideoDev::~VideoDev() { + Stop(); +} + + +// +// return list of devices in form of /dev/videoYY [Name] +int VideoDev::GetDeviceList(std::list *list) { + std::string device; + int devnum; + + if (list == NULL) return 0; + + list->clear(); + for (devnum = 0; devnum < 255; devnum++) { + device = "/dev/video"+std::to_string(devnum); + + if (device.compare (conf_device) != 0) { + int fd; + struct v4l2_capability vcap; + + if((fd = open(device.c_str(), O_RDONLY)) == -1){ + continue; + } + + if(ioctl(fd, VIDIOC_QUERYCAP, &vcap) == -1) + strncpy ((char*)&vcap.card, "unknown", sizeof(vcap.card)); + close(fd); + device += " [" + (std::string) ((char*)vcap.card) + "]"; + } + else { + device += " [" + (std::string) conf_devicename + "]"; + } + + list->push_back(device); + } + + return 1; +} + + +int VideoDev::Start(std::string dev, gboolean (*callback_func)(gpointer data)) { + return VDEV_STATUS_ERROR; +}; + + +int VideoDev::Stop() { + return VDEV_STATUS_OK; +}