FACT++  1.0
MVideo.h
Go to the documentation of this file.
1 #ifndef MARS_MVideo
2 #define MARS_MVideo
3 
4 #ifndef MAGIC_MAGIC
5 #include "MAGIC.h"
6 #endif
7 
8 #ifndef __CINT__
9 #ifndef __LINUX_VIDEODEV_H
10 #include "videodev.h" // video4linux
11 #endif
12 #ifndef __LINUX_VIDEODEV2_H
13 #include <linux/videodev2.h> // video4linux2
14 #endif
15 #endif
16 
17 #include <vector>
18 
19 struct v4l2_queryctrl;
20 struct v4l2_input;
21 struct v4l2_standard;
22 struct v4l2_buffer;
23 
24 class TEnv;
25 
26 class MVideoCtrl : public TObject
27 {
28  friend class MVideo;
29 private:
30  UInt_t fId;
31  //enum v4l2_ctrl_type type;
32  TString fName;
33  Int_t fMinimum;
34  Int_t fMaximum;
35  Int_t fStep;
36  Int_t fDefault;
37  UInt_t fFlags;
38 
39  UInt_t fValue;
40 
41 public:
42  MVideoCtrl(const v4l2_queryctrl &ctrl);
43  const char *GetName() const { return fName; }
44  const char *GetTitle() const { return Form("Range=[%d;%d] Step=%d Def=%d", fMinimum, fMaximum, fStep, fDefault); }
45 
46  //ClassDef(MVideoCtrl, 0) // Helper class to enumare device controls
47 };
48 
49 class MVideo
50 {
51 private:
52  TString fPath; // Device path
53 
54  int fFileDesc; // File descriptor
55 
56  unsigned char *fMapBuffer;
57 
58 protected:
59  struct video_capability fCaps; // Device capabilities
60  struct video_channel fChannel; // Channel information
61  //struct video_mbuf fBuffer; // Buffer information
62  struct video_picture fProp; // Picture properties
63  struct video_tuner fAbil; // Tuner abilities
64 
65  ULong64_t fVideoStandard;
66 
67  std::vector<v4l2_input> fInputs;
68  std::vector<v4l2_standard> fStandards;
69  std::vector<std::pair<v4l2_buffer, void*> > fBuffers;
70 
71  TList fControls;
72 
73 private:
74  int Ioctl(int req, void *opt, bool allowirq=true, bool force=false) const;
75 
76  void Reset();
77 
78  Bool_t EnumerateControls(UInt_t id);
79  Bool_t EnumerateControls();
80  Bool_t GetCapabilities();
81  Bool_t GetProperties();
82  Bool_t GetTunerAbilities();
83  Bool_t GetVideoStandard();
84  Bool_t Init(Int_t channel);
85 
86  template<class S>
87  Bool_t Enumerate(std::vector<S> &s, int request);
88 
89  void PrintInputs() const;
90  void PrintStandards() const;
91 
92  // Conversion functions
93  TString GetDevType(int type) const;
94  TString GetChannelFlags(Int_t flags) const;
95  TString GetChannelType(Int_t type) const;
96  TString GetTunerFlags(Int_t type) const;
97  TString GetTunerMode(Int_t type) const;
98  TString GetPalette(Int_t pal) const;
99 
100 public:
101  MVideo(const char *path="/dev/video0");
102  virtual ~MVideo() { Close(); }
103 
104  // Getter
105  Bool_t IsOpen() const { return fFileDesc>0 && fBuffers.size()>0; }
106  Bool_t CanCapture() const;
107  Bool_t HasTuner() const;
108  Int_t GetNumBuffers() const;
109 
110  Int_t GetWidth() const;
111  Int_t GetHeight() const;
112 
113  // Control
114  Bool_t Open(Int_t channel=0);
115  Int_t Close();
116 
117  Int_t SetChannel(Int_t chan);
118  Bool_t ReadControl(MVideoCtrl &vctrl) const;
119  Bool_t WriteControl(MVideoCtrl &vctrl, Int_t val) const;
120  Bool_t SetControls(TEnv &env) const;
121  Bool_t ResetControl(MVideoCtrl &vctrl) const;
122  Bool_t ResetControls() const;
123 
124  // Image capture
125  Bool_t CaptureStart(unsigned int frame) const;
126  Int_t CaptureWait(unsigned int frame, unsigned char **ptr=0) const;
127  Bool_t Start();
128 
129  // Support
130  void Print() const;
131 
132  // hardware features
133  //void SetPicPar(int bright, int hue, int contrast);
134  //void GetPicPar(int *bright, int *hue, int *contrast);
135 
136  //ClassDef(MVideo, 0) // Interface to Video4Linux at a simple level
137 
138 };
139 
140 #endif
TString fName
Definition: MVideo.h:32
Int_t fMaximum
Definition: MVideo.h:34
__u32 flags
Definition: videodev.h:90
int fFileDesc
Definition: MVideo.h:54
std::vector< v4l2_standard > fStandards
Definition: MVideo.h:68
TString fPath
Definition: MVideo.h:52
UInt_t fFlags
Definition: MVideo.h:37
const char * GetTitle() const
Definition: MVideo.h:44
Bool_t IsOpen() const
Definition: MVideo.h:105
Int_t fStep
Definition: MVideo.h:35
virtual ~MVideo()
Definition: MVideo.h:102
const char * GetName() const
Definition: MVideo.h:43
TList fControls
Definition: MVideo.h:71
int type
friend class MVideo
Definition: MVideo.h:28
ULong64_t fVideoStandard
Definition: MVideo.h:65
UInt_t fId
Definition: MVideo.h:30
std::string Form(const char *fmt,...)
Definition: tools.cc:45
void Print(std::ostream &out, const char *title, const bool &val, const char *t="enabled", const char *f="disabled")
std::vector< std::pair< v4l2_buffer, void * > > fBuffers
Definition: MVideo.h:69
Definition: MVideo.h:49
unsigned char * fMapBuffer
Definition: MVideo.h:56
UInt_t fValue
Definition: MVideo.h:39
Int_t fDefault
Definition: MVideo.h:36
MVideoCtrl(const v4l2_queryctrl &ctrl)
Definition: MVideo.cc:61
std::vector< v4l2_input > fInputs
Definition: MVideo.h:67
Int_t fMinimum
Definition: MVideo.h:33