My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
frameshit.h
1 #ifndef GCP_GRABBER_FRAMEGRABBER_H
2 #define GCP_GRABBER_FRAMEGRABBER_H
3 
11 #include <string>
12 #include <vector>
13 
14 #if HAVE_VIDEO
15 #include <linux/types.h>
16 #include <linux/videodev.h>
17 #endif
18 
19 // new ones
20 #include <iostream>
21 #include <iomanip>
22 
23 #include <cmath>
24 
25 #include "gcp/program/common/Program.h"
26 
27 #include "gcp/util/common/Angle.h"
28 #include "gcp/util/common/HourAngle.h"
29 #include "gcp/util/common/Declination.h"
30 #include "gcp/util/common/Debug.h"
31 #include "gcp/util/common/Exception.h"
32 #include "gcp/util/common/LogStream.h"
33 
34 #include "gcp/pgutil/common/PgUtil.h"
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <assert.h>
40 
41 #include <getopt.h> /* getopt_long() */
42 
43 #include <fcntl.h> /* low-level i/o */
44 #include <unistd.h>
45 #include <errno.h>
46 #include <sys/stat.h>
47 #include <sys/types.h>
48 #include <sys/time.h>
49 #include <sys/mman.h>
50 #include <sys/ioctl.h>
51 
52 #include <linux/videodev2.h>
53 
54 #define CLEAR(x) memset(&(x), 0, sizeof(x))
55 
56 //end of new ones
57 
58 namespace gcp {
59  namespace grabber {
60 
61  class FrameGrabber {
62  public:
63 
67  FrameGrabber();
68 
72  virtual ~FrameGrabber();
73 
74  // new ones
75  enum io_method {
76  IO_METHOD_READ,
77  IO_METHOD_MMAP,
78  IO_METHOD_USERPTR,
79  };
80 
81  struct buffer {
82  void *start;
83  size_t length;
84  };
85 
86  char *dev_name;
87  static enum io_method io;
88  static int fd;
89  struct buffer *buffers;
90  unsigned int n_buffers;
91  int out_buf;
92  int force_format;
93  static int frame_count;
94  // done with new vars
95  // new functions calls
96 
97  void errno_exit(const char *s);
98  int xioctl(int fh, int request, void *arg);
99  void process_image(const void *p, int size);
100  int read_frame(void);
101  void init_read(unsigned int buffer_size);
102  void stop_capturing(void);
103  void start_capturing(void);
104  void uninit_device(void);
105  void init_mmap(void);
106  void init_userp(unsigned int buffer_size);
107  void init_device(void);
108  void close_device(void);
109  void open_device(void);
110 
111 #if HAVE_VIDEO
112  void setDeviceFileName(std::string devFileName);
113  void initialize();
114 
115  void queryProperties();
116  void printProperties();
117 
118  void queryCapabilities();
119  void printCapabilities();
120 
121  void queryWindow();
122  void printWindow();
123  void setWindow(unsigned short width = defaultWidth_,
124  unsigned short height = defaultHeight_);
125 
126  void queryChannel(unsigned short channel);
127  void printChannel(struct video_channel& cp);
128  void setTunerToPal();
129 
130 #endif
131 
132  void setChannel(unsigned short channel = defaultChannel_);
133  void setImageSize(int width, int height);
134  void getImage(std::vector<char> &theImage);
135 
136 #if HAVE_VIDEO
137  void queryImageBuffer();
138  void printImageBuffer();
139 
140  void queryPicture();
141  void printPicture();
142 
143  void setDepth(int depth=defaultPixelDepth_);
144  void setBrightness(unsigned short brightness = defaultBrightness_);
145  void setContrast(unsigned short contrast = defaultContrast_);
146 
147  void createCaptureBuffer();
148 
149  void queryTuner();
150  void printTuner();
151 
152  private:
153 
154  static std::string defaultDevFileName_;
155  static const unsigned short defaultWidth_ = 512;
156  static const unsigned short defaultHeight_ = 480;
157  static const int defaultPixelDepth_ = 8;
158  static const unsigned short defaultBrightness_ = 32768;
159  static const unsigned short defaultContrast_ = 27648;
160 #endif
161 
162  static const unsigned short defaultChannel_ = 1;
163 
164 #if HAVE_VIDEO
165  int fd_;
166  int width_;
167  int height_;
168  void* imageBuffer_;
169 
170  std::string devFileName_;
171 
172  struct video_capability vc_;
173  struct video_channel cp_;
174  struct video_picture vp_;
175  struct video_window vw_;
176  struct video_mbuf vm_;
177  struct video_mmap vb_;
178  struct video_tuner vt_;
179  struct v4l2_output v4out_;
180 
181  void openFrameGrabber(std::string devFileName);
182 
183  void printImageBuffer(struct video_mbuf& vm);
184  void printCapabilities(struct video_capability& vc);
185  void printWindow(struct video_window& vw);
186  void printPicture(struct video_picture& vp);
187  void printTuner(struct video_tuner& vt);
188 #endif
189 
190  }; // End class FrameGrabber
191 
192  } // End namespace grabber
193 }; // End namespace gcp
194 
195 #endif // End #ifndef GCP_GRABBER_FRAMEGRABBER_H
void queryWindow()
Definition: FrameGrabber.cc:531
int queryChannel()
Definition: FrameGrabber.cc:565
void setBrightness(unsigned short brightness=defaultBrightness_)
Definition: FrameGrabber.cc:674
void createCaptureBuffer()
Definition: FrameGrabber.cc:237
void setChannel(int channel=defaultChannel_)
Definition: FrameGrabber.cc:201
FrameGrabber()
Definition: frameshit.cc:44
virtual ~FrameGrabber()
Definition: FrameGrabber.cc:44
void setImageSize(int width=defaultWidth_, int height=defaultHeight_)
Definition: FrameGrabber.cc:440
void queryCapabilities()
Definition: FrameGrabber.cc:452
void setContrast(unsigned short contrast=defaultContrast_)
Definition: FrameGrabber.cc:700
void setDeviceFileName(std::string devFileName)
Definition: FrameGrabber.cc:57
void queryPicture()
Definition: FrameGrabber.cc:506
Definition: tVideoCapabilitiesEml.cc:67