/*************************************************************************************** * * video.h is part of SimpleSkyCam. * ***************************************************************************************/ #ifndef _VIDEO_H_ #define _VIDEO_H_ #include #include #include #include #include #include #include "json.h" #include "gui.h" #include "config.h" #include "videoframe.h" enum { IOMODE_READ, IOMODE_MMAP }; enum { VDEV_STATUS_UNKNOWN, VDEV_STATUS_OK, VDEV_STATUS_AGAIN, VDEV_STATUS_ERROR }; // // jpeg error handling // struct jpg_error_mgr { struct jpeg_error_mgr pub; /* "public" fields */ jmp_buf setjmp_buffer; /* for return to caller */ }; typedef struct jpg_error_mgr *jpg_error_ptr; // callback status enum { VDEV_CBSTATUS_NOTHING = 1, VDEV_CBSTATUS_NEWFRAME, VDEV_CBSTATUS_ERROR }; struct { unsigned int id; int min; int max; int value; std::string name; } typedef VideoDevCtrl; struct { unsigned int size; unsigned char* data; } typedef VideoInBuffer; #define VDEV_INBUFFERS 3 class VideoDev { private: std::string conf_device; std::string conf_devicename; gboolean (*callback)(gpointer data); int running; GMutex mutex; GThread *thread; int inbuffer_idx; VideoInBuffer inbuffer[VDEV_INBUFFERS]; struct v4l2_cropcap cropcap; struct v4l2_crop crop; struct v4l2_format fmt; VideoFrame vf; std::list vidctrls; struct jpg_error_mgr jerr; struct jpeg_decompress_struct cinfo; int vf_rec; int vf_get; int io; // IO Mode int fd; int InitMMap(); int InitUserPtr(); int CaptureStart(); int CaptureStop(); int UnInit(); int Convert (VideoFrame *dest, unsigned char *ptrsrc, int srcsize, uint32_t pixelformat, int srcw, int srch); int OpenInit (); int Close (); int Grab(VideoFrame *vf); int SetDevCtrl(unsigned int id, int value); int GetDevCtrl(unsigned int id, int *value); int xioctl (int fd, int request, void *arg); public: VideoDev(); ~VideoDev(); void Thread(); 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 GetCtrlList(std::list *list); int GetCtrlMinMaxValue(std::string name, int *min, int *max, int *value); list GetCtrlsMinMaxValue(); int SetCtrlValue(std::string name, int value); int IsRunning() { return running; }; void PrintCaps (uint32_t caps); void PrintFmt(struct v4l2_format *f); void LockMutex() { g_mutex_lock(&mutex); }; void UnLockMutex() { g_mutex_unlock(&mutex); }; std::string GetDevice() { return conf_device; }; }; extern VideoDev videodev; extern void videoframe_to_pixbuf(GdkPixbuf* dest, VideoFrame *src); #endif // _VIDEO_H_