1 /*
2  *      videoCapture.h -- Kapture
3  *
4  *      Copyright (C) 2006-2007
5  *          Detlev Casanova (detlev.casanova@gmail.com)
6  *
7  *      This program is free software; you can redistribute it and/or modify
8  *      it under the terms of the GNU General Public License as published by
9  *      the Free Software Foundation; either version 2 of the License, or
10  *      (at your option) any later version.
11  *
12  */
13 
14 #ifndef VIDEOCAPTURE_H
15 #define VIDEOCAPTURE_H
16 
17 #include <QObject>
18 #include <QImage>
19 #include <linux/videodev2.h>
20 #include "appdefs.h"
21 #include <libv4lconvert.h>
22 
23 struct tableFormat
24 {
25   QString description;
26   unsigned int val1;
27   unsigned int val2;
28 };
29 extern tableFormat sizeList[];
30 extern tableFormat fpsList[];
31 
32 
33 class videoCapture : public QObject
34 {
35 	Q_OBJECT
36 
37 public:
38   videoCapture();
39   ~videoCapture();
40 
41 	void close();
42   bool  open(QString videoDev);
43   QList<QString> descripList;
44 
45   bool setFormat(v4l2_format &fmt);
46   bool getFormat(v4l2_format &fmt);
47   int getFrame();
48   int currentWidth(v4l2_format fmt) const;
49   int currentHeight(v4l2_format fmt) const;
50   int currentPixelFormat(v4l2_format fmt) const;
getImage()51   QImage *getImage() {return localImage;}
52   bool captureStart();
53   bool captureStop();
54   bool stopStreaming();
55   bool startSnapshots();
56   bool init(int pixelFormat, int width, int height);
getErrorString()57   QString getErrorString() {return errorString;}
58 
59 private:
60 	int dev;
61   v4l2_format srcFmt;
62   v4l2_format dstFmt;
63 	v4l2_buffer buf;
64 	v4l2_requestbuffers rb;
65 	bool allocated;
66 
67   uchar *mem[4];
68 	size_t bufLength;
69   QImage *localImage;
70   bool opened;
71   bool mmapped;
72   bool streaming;
73   void dumpCaps(v4l2_capability &cap);
74   uint numBuffers;
75   QString pixelFormatStr(int pixelFormat);
76   struct v4lconvert_data *convertData;
77   bool convert(unsigned char *src);
78   enum QImage::Format checkConversionNeeded ();
79   enum QImage::Format qFmt;
80   bool needsConversion;
81   QString videoDevice;
82   int allocateBuffers(uint numBufs);
83   QString errorString;
84 
85 };
86 #endif
87 
88