You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SimpleSkyCam/video.h

142 lines
2.8 KiB

/***************************************************************************************
*
* video.h is part of SimpleSkyCam.
*
***************************************************************************************/
#ifndef _VIDEO_H_
#define _VIDEO_H_
#include <string>
#include <list>
#include <stdint.h>
#include <jpeglib.h>
#include <linux/videodev2.h>
#include <setjmp.h>
#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<VideoDevCtrl> 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<std::string> *list);
int GetCtrlList(std::list<std::string> *list);
int GetCtrlMinMaxValue(std::string name, int *min, int *max, int *value);
list<VideoDevCtrl> 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_