MythTV  master
v4l2util.h
Go to the documentation of this file.
1 #ifndef _V4L2_util_h_
2 #define _V4L2_util_h_
3 
4 #ifdef USING_V4L2
5 #include "videodev2.h" // our copy
6 #endif
7 
8 #include "tv.h"
9 #include "mythtvexp.h"
10 
11 #include <QStringList>
12 #include "driveroption.h"
13 
14 struct DriverOption;
15 
17 {
18  public:
19  V4L2util(void) = default;
20  explicit V4L2util(const QString& dev_name);
21  V4L2util(const QString& dev_name, const QString& vbi_dev_name);
22  ~V4L2util(void);
23 
24  bool Open(const QString& dev_name, const QString& vbi_dev_name = "");
25  void Close(void);
26  int FD(void) const { return m_fd; }
27 
28  bool operator!(void) const { return m_fd < 0; }
29  bool IsOpen(void) const { return m_fd >= 0; }
30 
31  bool GetOptions(DriverOption::Options& options);
32  int GetOptionValue(DriverOption::category_t cat, const QString& desc);
33  bool GetFormats(QStringList& formats);
34  bool GetVideoStandard(QString& name) const;
35  int GetSignalStrength(void) const;
36  bool GetResolution(int& width, int& height) const;
37 
38  bool HasTuner(void) const;
39  bool HasAudioSupport(void) const;
40  bool HasStreaming(void) const;
41  bool HasSlicedVBI(void) const;
42  bool IsEncoder(void) const;
43  bool UserAdjustableResolution(void) const;
44 
45  QString DriverName(void) const { return m_driverName; }
46  QString CardName(void) const { return m_cardName; }
47  QString ProfileName(void) const { return "V4L2:" + m_driverName; }
48 
49  int GetStreamType(void) const;
50  bool SetStreamType(int value);
51  // Video controls
52  bool SetVideoAspect(int value);
53  bool SetVideoBitrateMode(int value);
54  bool SetVideoBitrate(int value);
55  bool SetVideoBitratePeak(int value);
56  bool SetResolution(uint32_t width, uint32_t height);
57  // Audio controls
58  bool SetAudioInput(int value);
59  bool SetAudioCodec(int value);
60  bool SetVolume(int volume);
61  bool SetLanguageMode(int mode);
62  bool SetAudioSamplingRate(int value);
63  bool SetAudioBitrateL2(int value);
64 
65  // Actions
66  bool StartEncoding(void);
67  bool StopEncoding(void);
68  bool PauseEncoding(void);
69  bool ResumeEncoding(void);
70 
71  static QString StreamTypeDesc(int value);
72 
73  protected:
74  // VBI
75  bool OpenVBI(const QString& vbi_dev_name);
76  bool SetSlicedVBI(const VBIMode::vbimode_t& vbimode);
77 
78  int GetExtControl(int request, const QString& ctrl_desc = "") const;
79  bool SetExtControl(int request, int value, const QString& ctrl_desc,
80  const QString& value_desc);
81  bool SetEncoderState(int mode, const QString& desc);
82  void SetDefaultOptions(DriverOption::Options& options);
83 
84  static void bitmask_toString(QString& result, uint32_t flags,
85  uint32_t mask, const QString& desc);
86  static QString ctrlflags_toString(uint32_t flags);
87  static QString queryctrl_toString(int type);
88 
89  void log_qctrl(struct v4l2_queryctrl& queryctrl, DriverOption& drv_opt,
90  QString& msg);
91  bool log_control(struct v4l2_queryctrl& qctrl, DriverOption& drv_opt,
92  QString& msg);
93  void log_controls(bool show_menus);
94 
95  private:
96  int m_fd {-1};
97  int m_vbiFd {-1};
99  QString m_deviceName;
100  QString m_driverName;
101  QString m_cardName;
102  int m_version {0};
103  uint32_t m_capabilities {0};
104  bool m_haveQueryExtCtrl {false};
105 };
106 
107 #endif
QMap< category_t, DriverOption > Options
Definition: driveroption.h:20
vbimode
Definition: vbilut.h:20
DriverOption::Options m_options
Definition: v4l2util.h:98
QString m_driverName
Definition: v4l2util.h:100
bool IsOpen(void) const
Definition: v4l2util.h:29
QString ProfileName(void) const
Definition: v4l2util.h:47
const char * formats[8]
Definition: vbilut.cpp:190
bool operator!(void) const
Definition: v4l2util.h:28
#define MTV_PUBLIC
Definition: mythtvexp.h:15
vbimode_t
Definition: tv.h:9
const char * name
Definition: ParseText.cpp:328
QString m_cardName
Definition: v4l2util.h:101
int FD(void) const
Definition: v4l2util.h:26
QString m_deviceName
Definition: v4l2util.h:99
QString DriverName(void) const
Definition: v4l2util.h:45
QString CardName(void) const
Definition: v4l2util.h:46