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.

157 lines
3.6 KiB

#ifndef _VIDEO_H_
#define _VIDEO_H_
#include <stdint.h>
#include <setjmp.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include <list>
#include <string>
#include "convert.h"
#include "inmemoryfile.h"
#include "miniwebcam.h"
#include "videoframe.h"
#define VDEV_INBUFFERS 3
enum {
IOMODE_READ,
IOMODE_MMAP
};
//
// 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;
struct {
unsigned int id;
int min;
int max;
int value;
std::string name;
} typedef VideoDevCtrl;
struct {
unsigned int size;
unsigned char* data;
} typedef VideoInBuffer;
#include "convert.h"
class VideoDevice {
private:
protected:
std::list<VideoDevCtrl> vidctrls;
std::string conf_videodev;
uint32_t conf_videofmt;
int conf_width;
int conf_height;
int conf_iomode;
ConvertData cdata;
public:
VideoDevice();
virtual ~VideoDevice();
virtual int SetDevice(std::string newdevice, int nwidth, int nheight, uint32_t pixfmt) { debug (""); return 0; };
virtual int SetIOMode(int newiomode) { debug (""); return 0; };
virtual int Start() { debug (""); return 0; };
virtual int Stop() { debug (""); return 0; };
virtual int GetFrame (VideoFrame *destframe) { debug (""); return 0; };
virtual int SetDevCtrl(unsigned int id, int value) { debug (""); return 0; };
virtual int GetDevCtrl(unsigned int id, int *value) { debug (""); return 0; };
};
class VideoDevice_V4L2 : public VideoDevice {
private:
int inbuffer_idx;
VideoInBuffer inbuffer[VDEV_INBUFFERS];
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
struct v4l2_format fmt;
int fd; // filedescriptor to the video device file
int Open();
int Close();
int UnInit();
int InitMMap();
int xioctl(int fd, int request, void *arg);
protected:
public:
VideoDevice_V4L2();
~VideoDevice_V4L2();
int SetDevice(std::string newdevice, int nwidth, int nheight, uint32_t pixfmt);
int SetIOMode(int newiomode);
int Start();
int Stop();
int GetFrame (VideoFrame *destframe);
int SetDevCtrl(unsigned int id, int value);
int GetDevCtrl(unsigned int id, int *value);
void PrintCaps(uint32_t caps);
void PrintFmt(struct v4l2_format *f);
};
class VideoDevice_Dump : public VideoDevice {
private:
int fd;
uint32_t w;
uint32_t h;
uint32_t pixformat;
off_t filesize;
off_t filepos;
struct timeval starttv;
unsigned char *inframe;
uint32_t inframe_nexttime;
int inframe_maxsize;
int inframe_size;
int fixedframesize;
int Open();
int Close();
int ReadFrame();
protected:
public:
VideoDevice_Dump();
~VideoDevice_Dump();
int SetDevice(std::string newdevice, int nwidth, int nheight, uint32_t pixfmt) { config.vdev_device = newdevice; return 1; };
int SetIOMode(int newiomode) { return 1; };
int Start();
int Stop();
int GetFrame (VideoFrame *destframe);
int SetDevCtrl(unsigned int id, int value);
int GetDevCtrl(unsigned int id, int *value);
};
#endif