| 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
|
|---|