reading name of device

test16bit
Steffen Pohle 4 years ago
parent 053d0e7568
commit 3799771e0a

@ -0,0 +1,37 @@
/***************************************************************************************
*
* video.cc is part of SimpleSkyCam.
*
*****************************************************************************************/
#include <list>
#include <string>
#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<std::string> devlist;
std::list<std::string>::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);
}
}
}

@ -0,0 +1,40 @@
/***************************************************************************************
*
* video.h is part of SimpleSkyCam.
*
***************************************************************************************/
#ifndef _VIDEO_H_
#define _VIDEO_H_
#include <string>
#include <list>
#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<std::string> *list);
int GetStatus() { return status; };
};
#endif // _VIDEO_H_

@ -0,0 +1,75 @@
/***************************************************************************************
*
* videodev.cc is part of SimpleSkyCam.
*
*****************************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <list>
#include <string>
#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<std::string> *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;
}
Loading…
Cancel
Save