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  uint32_t GetCapabilities(void) const;
38  QString GetDeviceName(void) const;
39  QString GetDriverName(void) const;
40 
41  bool HasTuner(void) const;
42  bool HasAudioSupport(void) const;
43  bool HasStreaming(void) const;
44  bool HasSlicedVBI(void) const;
45  bool IsEncoder(void) const;
46  bool UserAdjustableResolution(void) const;
47 
48  QString DriverName(void) const { return m_driverName; }
49  QString CardName(void) const { return m_cardName; }
50  QString ProfileName(void) const { return "V4L2:" + m_driverName; }
51 
52  int GetStreamType(void) const;
53  bool SetStreamType(int value);
54  // Video controls
55  bool SetVideoAspect(int value);
56  bool SetVideoBitrateMode(int value);
57  bool SetVideoBitrate(int value);
58  bool SetVideoBitratePeak(int value);
59  bool SetResolution(uint32_t width, uint32_t height);
60  // Audio controls
61  bool SetAudioInput(int value);
62  bool SetAudioCodec(int value);
63  bool SetVolume(int volume);
64  bool SetLanguageMode(int mode);
65  bool SetAudioSamplingRate(int value);
66  bool SetAudioBitrateL2(int value);
67 
68  // Actions
69  bool StartEncoding(void);
70  bool StopEncoding(void);
71  bool PauseEncoding(void);
72  bool ResumeEncoding(void);
73 
74  static QString StreamTypeDesc(int value);
75 
76  protected:
77  // VBI
78  static bool OpenVBI(const QString& vbi_dev_name);
79  bool SetSlicedVBI(const VBIMode::vbimode_t& vbimode);
80 
81  int GetExtControl(int request, const QString& ctrl_desc = "") const;
82  bool SetExtControl(int request, int value, const QString& ctrl_desc,
83  const QString& value_desc);
84  bool SetEncoderState(int mode, const QString& desc);
85  void SetDefaultOptions(DriverOption::Options& options);
86 
87  static void bitmask_toString(QString& result, uint32_t flags,
88  uint32_t mask, const QString& desc);
89  static QString ctrlflags_toString(uint32_t flags);
90  static QString queryctrl_toString(int type);
91 
92  void log_qctrl(struct v4l2_queryctrl& queryctrl, DriverOption& drv_opt,
93  QString& msg);
94  bool log_control(struct v4l2_queryctrl& qctrl, DriverOption& drv_opt,
95  QString& msg);
96  void log_controls(bool show_menus);
97 
98  private:
99  int m_fd {-1};
100  int m_vbiFd {-1};
102  QString m_deviceName;
103  QString m_driverName;
104  QString m_cardName;
105  int m_version {0};
106  uint32_t m_capabilities {0};
107  bool m_haveQueryExtCtrl {false};
108 };
109 
110 #endif
vbimode
Definition: vbilut.h:20
DriverOption::Options m_options
Definition: v4l2util.h:101
QString m_driverName
Definition: v4l2util.h:103
bool IsOpen(void) const
Definition: v4l2util.h:29
QString ProfileName(void) const
Definition: v4l2util.h:50
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
QMap< category_t, DriverOption > Options
Definition: driveroption.h:20
QString m_cardName
Definition: v4l2util.h:104
int FD(void) const
Definition: v4l2util.h:26
QString m_deviceName
Definition: v4l2util.h:102
QString DriverName(void) const
Definition: v4l2util.h:48
QString CardName(void) const
Definition: v4l2util.h:49