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.
128 lines
2.2 KiB
128 lines
2.2 KiB
/***************************************************************************************
|
|
*
|
|
* video.h is part of SimpleSkyCam.
|
|
*
|
|
***************************************************************************************/
|
|
|
|
#ifndef _VIDEO_H_
|
|
#define _VIDEO_H_
|
|
|
|
#include <string>
|
|
#include <list>
|
|
#include <jpeglib.h>
|
|
#include <linux/videodev2.h>
|
|
#include <setjmp.h>
|
|
|
|
|
|
#include "gui.h"
|
|
#include "config.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 size;
|
|
unsigned char* data;
|
|
} typedef VideoInBuffer;
|
|
|
|
|
|
struct {
|
|
int w;
|
|
int h;
|
|
uint32_t size;
|
|
unsigned char *data;
|
|
} typedef VideoFrame;
|
|
|
|
#define VDEV_INBUFFERS 2
|
|
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;
|
|
|
|
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 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 IsRunning() { return running; };
|
|
|
|
void PrintCaps (uint32_t caps);
|
|
void PrintFmt(struct v4l2_format *f);
|
|
|
|
void LockMutex();
|
|
void UnLockMutex();
|
|
};
|
|
|
|
|
|
extern VideoDev videodev;
|
|
|
|
|
|
#endif // _VIDEO_H_
|
|
|