MythTV  master
cardutil.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 #ifndef CARDUTIL_H
3 #define CARDUTIL_H
4 
5 // C++ headers
6 #include <chrono>
7 #include <cstdint>
8 #include <vector>
9 
10 // Qt headers
11 #include <QList>
12 #include <QStringList>
13 #include <QMap>
14 #include <QMetaEnum>
15 
16 // MythTV headers
17 #include "mythtvexp.h"
18 #include "dtvconfparserhelpers.h"
19 
20 class InputInfo;
21 class CardInput;
22 using InputNames = QMap<int,QString>;
23 
24 MTV_PUBLIC QString get_on_input(const QString &to_get, uint inputid);
25 
26 MTV_PUBLIC bool set_on_input(const QString &to_set, uint inputid, const QString &value);
27 
28 enum dvb_dev_type_t : std::uint8_t
29 {
36 };
37 
41 class MTV_PUBLIC CardUtil : public QObject
42 {
43  Q_OBJECT
44 
45  public:
46  using InputTypes = QMap<QString, QString>;
47 
49  enum INPUT_TYPES : std::uint8_t
50  {
51  ERROR_OPEN = 0,
52  ERROR_UNKNOWN = 1,
53  ERROR_PROBE = 2,
54 #pragma clang diagnostic push
55 #pragma clang diagnostic ignored "-Wshadow"
56  // QPSK is defined in /usr/include/linux/dvb/frontend.h
57  QPSK = 3, DVBS = 3,
58 #pragma clang diagnostic pop
59  QAM = 4, DVBC = 4,
60  OFDM = 5, DVBT = 5,
61  ATSC = 6,
62  V4L = 7,
63  MPEG = 8,
64  FIREWIRE = 9,
65  HDHOMERUN = 10,
66  FREEBOX = 11,
67  HDPVR = 12,
68  DVBS2 = 13,
69  IMPORT = 14,
70  DEMO = 15,
71  ASI = 16,
72  CETON = 17,
73  EXTERNAL = 18,
74  VBOX = 19,
75  DVBT2 = 20,
76  V4L2ENC = 21,
77  SATIP = 22
78  };
79 
80  Q_ENUM(INPUT_TYPES)
81 
82  static enum INPUT_TYPES toInputType(const QString &name)
83  {
84  if ("ERROR_OPEN" == name)
85  return ERROR_OPEN;
86  if ("ERROR_UNKNOWN" == name)
87  return ERROR_UNKNOWN;
88  if ("ERROR_PROBE" == name)
89  return ERROR_PROBE;
90  if ("QPSK" == name)
91  return QPSK;
92  if ("DVBS" == name)
93  return DVBS;
94  if ("QAM" == name)
95  return QAM;
96  if ("DVBC" == name)
97  return DVBC;
98  if ("OFDM" == name)
99  return OFDM;
100  if ("DVBT" == name)
101  return DVBT;
102  if ("ATSC" == name)
103  return ATSC;
104  if ("V4L" == name)
105  return V4L;
106  if ("MPEG" == name)
107  return MPEG;
108  if ("FIREWIRE" == name)
109  return FIREWIRE;
110  if ("HDHOMERUN" == name)
111  return HDHOMERUN;
112  if ("FREEBOX" == name)
113  return FREEBOX;
114  if ("HDPVR" == name)
115  return HDPVR;
116  if ("DVB_S2" == name)
117  return DVBS2;
118  if ("IMPORT" == name)
119  return IMPORT;
120  if ("DEMO" == name)
121  return DEMO;
122  if ("ASI" == name)
123  return ASI;
124  if ("CETON" == name)
125  return CETON;
126  if ("EXTERNAL" == name)
127  return EXTERNAL;
128  if ("VBOX" == name)
129  return VBOX;
130  if ("DVB_T2" == name)
131  return DVBT2;
132  if ("V4L2ENC" == name)
133  return V4L2ENC;
134  if ("SATIP" == name)
135  return SATIP;
136  return ERROR_UNKNOWN;
137  }
138 
139  static bool IsEncoder(const QString &rawtype)
140  {
141  return
142  (rawtype != "DVB") && (rawtype != "FIREWIRE") &&
143  (rawtype != "HDHOMERUN") && (rawtype != "FREEBOX") &&
144  (rawtype != "IMPORT") && (rawtype != "DEMO") &&
145  (rawtype != "ASI") && (rawtype != "CETON") &&
146  (rawtype != "VBOX") && (rawtype != "SATIP");
147  }
148 
149  static bool IsV4L(const QString &rawtype)
150  {
151  return (rawtype == "V4L" || rawtype == "MPEG" ||
152  rawtype == "HDPVR" || rawtype == "GO7007" ||
153  rawtype == "MJPEG" || rawtype == "V4L2ENC");
154  }
155 
156  static bool IsChannelChangeDiscontinuous(const QString &rawtype)
157  {
158  return (!IsEncoder(rawtype) || rawtype == "HDPVR" ||
159  rawtype == "EXTERNAL");
160  }
161 
162  static bool IsUnscanable(const QString &rawtype)
163  {
164  return
165  (rawtype == "FIREWIRE") || (rawtype == "HDPVR") ||
166  (rawtype == "IMPORT") || (rawtype == "DEMO") ||
167  (rawtype == "GO7007") || (rawtype == "MJPEG");
168  }
169  static QString GetScanableInputTypes(void);
170 
171  static bool IsCableCardPresent(uint inputid,
172  const QString &inputType);
173 
174  static bool IsEITCapable(const QString &rawtype)
175  {
176  return
177  (rawtype == "DVB") || (rawtype == "HDHOMERUN") ||
178  (rawtype == "SATIP");
179  }
180 
181  static bool IsTunerSharingCapable(const QString &rawtype)
182  {
183  return
184  (rawtype == "DVB") || (rawtype == "HDHOMERUN") ||
185  (rawtype == "ASI") || (rawtype == "FREEBOX") ||
186  (rawtype == "CETON") || (rawtype == "EXTERNAL") ||
187  (rawtype == "VBOX") || (rawtype == "V4L2ENC") ||
188  (rawtype == "SATIP");
189  }
190 
191  static bool HasTuner(const QString &rawtype, const QString & device);
192  static bool IsTunerShared(uint inputidA, uint inputidB);
193 
194  static bool IsTuningDigital(const QString &rawtype)
195  {
196  return
197  (rawtype == "DVB") || (rawtype == "HDHOMERUN") ||
198  (rawtype == "ASI") || (rawtype == "CETON") ||
199  (rawtype == "EXTERNAL") || (rawtype == "SATIP");
200  }
201 
202  static bool IsTuningAnalog(const QString &rawtype)
203  {
204  return
205  (rawtype == "V4L") || (rawtype == "V4L2ENC" ||
206  rawtype == "MPEG");
207  }
208 
209  static bool IsTuningVirtual(const QString &rawtype)
210  {
211  return
212  (rawtype == "FIREWIRE") || (rawtype == "HDPVR") ||
213  (rawtype == "EXTERNAL") || (rawtype == "V4L2ENC");
214  }
215 
216  static bool IsSingleInputType(const QString &rawtype)
217  {
218  return
219  (rawtype == "FIREWIRE") || (rawtype == "HDHOMERUN") ||
220  (rawtype == "FREEBOX") || (rawtype == "ASI") ||
221  (rawtype == "IMPORT") || (rawtype == "DEMO") ||
222  (rawtype == "CETON") || (rawtype == "EXTERNAL") ||
223  (rawtype == "VBOX") || (rawtype == "SATIP");
224  }
225 
226  static bool IsChannelReusable(const QString &rawtype)
227  {
228  return !(rawtype == "FREEBOX" || rawtype == "VBOX");
229  }
230 
231 #ifdef USING_VBOX
232  static bool IsVBoxPresent(uint inputid);
233 #endif
234 #ifdef USING_SATIP
235  static bool IsSatIPPresent(uint inputid);
236 #endif
237 
238  // Card creation and deletion
239 
240  static int CreateCaptureCard(const QString &videodevice,
241  const QString &audiodevice,
242  const QString &vbidevice,
243  const QString &inputtype,
244  uint audioratelimit,
245  const QString &hostname,
246  uint dvb_swfilter,
247  uint dvb_sat_type,
248  bool dvb_wait_for_seqstart,
249  bool skipbtaudio,
250  bool dvb_on_demand,
251  uint dvb_diseqc_type,
252  uint firewire_speed,
253  const QString &firewire_model,
254  uint firewire_connection,
255  std::chrono::milliseconds signal_timeout,
256  std::chrono::milliseconds channel_timeout,
257  uint dvb_tuning_delay,
258  uint contrast,
259  uint brightness,
260  uint colour,
261  uint hue,
262  uint diseqcid,
263  bool dvb_eitscan);
264 
265  static bool DeleteInput(uint inputid);
266  static bool DeleteAllInputs(void);
267  static std::vector<uint> GetInputList(void);
268  static std::vector<uint> GetSchedInputList(void);
269  static std::vector<uint> GetLiveTVInputList(void);
270 
272  static uint GetFirstInputID(const QString &videodevice)
273  {
274  std::vector<uint> list = GetInputIDs(videodevice);
275  if (list.empty())
276  return 0;
277  return list[0];
278  }
279 
280  static std::vector<uint> GetInputIDs(const QString& videodevice = QString(),
281  const QString& rawtype = QString(),
282  const QString& inputname = QString(),
283  QString hostname = QString());
284 
285  static uint GetChildInputCount(uint inputid);
286  static std::vector<uint> GetChildInputIDs(uint inputid);
287 
288  static bool IsInputTypePresent(const QString &rawtype,
289  QString hostname = QString());
290  static InputTypes GetInputTypes(void); // input types on ALL hosts
291  static QStringList GetInputTypeNames(uint sourceid); // input types for a given source id
292 
293  static QStringList GetVideoDevices(const QString &rawtype,
294  QString hostname = QString());
295 
296  static QString GetRawInputType(uint inputid)
297  { return get_on_input("cardtype", inputid).toUpper(); }
298  static QString GetVideoDevice(uint inputid)
299  { return get_on_input("videodevice", inputid); }
300  static QString GetAudioDevice(uint inputid)
301  { return get_on_input("audiodevice", inputid); }
302  static QString GetVBIDevice(uint inputid)
303  { return get_on_input("vbidevice", inputid); }
304  static QString GetDeliverySystemFromDB(uint inputid)
305  { return get_on_input("inputname", inputid); } // use capturecard/inputname for now
306  static QString GetDiSEqCPosition(uint inputid)
307  { return get_on_input("dvb_diseqc_type", inputid); } // use capturecard/dvb_diseqc_type for now
308 
309  static QString GetHostname(uint inputid)
310  { return get_on_input("hostname", inputid); }
311 
312  static int GetValueInt(const QString &col, uint inputid)
313  { return get_on_input(col, inputid).toInt(); }
314  static bool SetValue(const QString &col, uint inputid,
315  int val)
316  { return set_on_input(col, inputid, QString::number(val)); }
317  static bool SetValue(const QString &col, uint inputid,
318  const QString &val)
319  { return set_on_input(col, inputid, val); }
320 
321  static bool SetStartChannel(uint inputid,
322  const QString &channum);
323 
324  // Input creation and deletion
325  static int CreateCardInput(uint inputid,
326  uint sourceid,
327  const QString &inputname,
328  const QString &externalcommand,
329  const QString &changer_device,
330  const QString &changer_model,
331  const QString &hostname,
332  const QString &tunechan,
333  const QString &startchan,
334  const QString &displayname,
335  bool dishnet_eit,
336  uint recpriority,
337  uint quicktune,
338  uint schedorder,
339  uint livetvorder);
340 
341  // Other input functions
342 
343  static std::vector<uint> GetInputIDs(uint sourceid);
344  static bool GetInputInfo(InputInfo &input,
345  std::vector<uint> *groupids = nullptr);
346  static QList<InputInfo> GetAllInputInfo(bool virtTuners);
347  static QString GetInputName(uint inputid);
348  static QString GetStartChannel(uint inputid);
349  static QString GetDisplayName(uint inputid);
350  static bool IsUniqueDisplayName(const QString &name,
351  uint exclude_inputid);
352  static uint GetSourceID(uint inputid);
353 
354  // Input Groups
355  static uint CreateInputGroup(const QString &name);
356  static uint CreateDeviceInputGroup(uint inputid,
357  const QString &type,
358  const QString &host,
359  const QString &device);
360  static uint GetDeviceInputGroup(uint inputid);
361  static bool LinkInputGroup(uint inputid, uint inputgroupid);
362  static bool UnlinkInputGroup(uint inputid, uint inputgroupid);
363  static std::vector<uint> GetInputGroups(uint inputid);
364  static std::vector<uint> GetGroupInputIDs(uint inputgroupid);
365  static std::vector<uint> GetConflictingInputs(uint inputid);
366 
367  static QString GetDeviceLabel(const QString &inputtype,
368  const QString &videodevice);
369  static QString GetDeviceLabel(uint inputid);
370 
371  static QString ProbeSubTypeName(uint inputid);
372 
373  static QStringList ProbeVideoInputs(const QString& device,
374  const QString& inputtype = QString());
375  static QStringList ProbeAudioInputs(const QString& device,
376  const QString& inputtype = QString());
377  static void GetDeviceInputNames(const QString &device,
378  const QString &inputtype,
379  QStringList &inputs);
380 
381  // General info from OS
382  static QStringList ProbeVideoDevices(const QString &rawtype);
383  static void ClearVideoDeviceCache();
384 
385  // Other
386  static uint CloneCard(uint src_inputid, uint dst_inputid);
387  static bool InputSetMaxRecordings(uint parentid,
388  uint max_recordings);
389  static uint AddChildInput(uint parentid);
390  static QString GetFirewireChangerNode(uint inputid);
391  static QString GetFirewireChangerModel(uint inputid);
392 
393  // DTV info
394  static bool GetTimeouts(uint inputid,
395  std::chrono::milliseconds &signal_timeout,
396  std::chrono::milliseconds &channel_timeout);
397  static bool IgnoreEncrypted(uint inputid,
398  const QString &inputname);
399  static bool TVOnly(uint inputid, const QString &inputname);
400  static bool IsInNeedOfExternalInputConf(uint inputid);
401  static uint GetQuickTuning(uint inputid, const QString &input_name);
402 
403  // DVB info
405  static bool IsDVB(uint inputid)
406  { return "DVB" == GetRawInputType(inputid); }
407  static bool IsDVBInputType(const QString &inputType);
408  static QStringList ProbeDeliverySystems(const QString &device);
409  static QStringList ProbeDeliverySystems(int fd_frontend);
410  static QString ProbeDefaultDeliverySystem(const QString &device);
411  static QString ProbeDVBType(const QString &device);
412  static QString ProbeDVBFrontendName(const QString &device);
413  static bool HasDVBCRCBug(const QString &device);
414  static std::chrono::milliseconds GetMinSignalMonitoringDelay(const QString &device);
415  static DTVTunerType ConvertToTunerType(DTVModulationSystem delsys);
416  static DTVTunerType GetTunerType(uint inputid);
417  static DTVTunerType ProbeTunerType(int fd_frontend);
418  static DTVTunerType ProbeTunerType(const QString &device);
419  static DTVTunerType GetTunerTypeFromMultiplex(uint mplexid);
420  static DTVModulationSystem GetDeliverySystem(uint inputid);
421  static DTVModulationSystem ProbeCurrentDeliverySystem(const QString &device);
422  static DTVModulationSystem ProbeCurrentDeliverySystem(int fd_frontend);
423  static DTVModulationSystem ProbeBestDeliverySystem(int fd);
424  static DTVModulationSystem GetOrProbeDeliverySystem(uint inputid, int fd);
425  static int SetDefaultDeliverySystem(uint inputid, int fd);
426  static int SetDeliverySystem(uint inputid);
427  static int SetDeliverySystem(uint inputid, DTVModulationSystem delsys);
428  static int SetDeliverySystem(uint inputid, int fd);
429  static int SetDeliverySystem(uint inputid, DTVModulationSystem delsys, int fd);
430  static int OpenVideoDevice(int inputid);
431  static int OpenVideoDevice(const QString &device);
432  static QString GetDeviceName(dvb_dev_type_t type, const QString &device);
433  static InputNames GetConfiguredDVBInputs(const QString &device);
434  static QStringList CapabilitiesToString(uint64_t capabilities);
435 
436  // V4L info
437  static bool hasV4L2(int videofd);
438  static bool GetV4LInfo(int videofd, QString &input, QString &driver,
439  uint32_t &version, uint32_t &capabilities);
440  static bool GetV4LInfo(int videofd, QString &input, QString &driver)
441  {
442  uint32_t d1 = 0;
443  uint32_t d2 = 0;
444  return GetV4LInfo(videofd, input, driver, d1, d2);
445  }
446  static InputNames ProbeV4LVideoInputs(int videofd, bool &ok);
447  static InputNames ProbeV4LAudioInputs(int videofd, bool &ok);
448 
449  // HDHomeRun info
450  static bool HDHRdoesDVB(const QString &device);
451  static bool HDHRdoesDVBC(const QString &device);
452  static QString GetHDHRdesc(const QString &device);
453 
454  // VBox info
455  static QString GetVBoxdesc(const QString &id, const QString &ip,
456  const QString &tunerNo, const QString &tunerType);
457 
458  // ASI info
459  static int GetASIDeviceNumber(const QString &device,
460  QString *error = nullptr);
461 
462  static uint GetASIBufferSize(uint device_num,
463  QString *error = nullptr);
464  static uint GetASINumBuffers(uint device_num,
465  QString *error = nullptr);
466  static int GetASIMode(uint device_num,
467  QString *error = nullptr);
468  static bool SetASIMode(uint device_num, uint mode,
469  QString *error = nullptr);
470 
471  private:
472  static QStringList ProbeV4LVideoInputs(const QString& device);
473  static QStringList ProbeV4LAudioInputs(const QString& device);
474  static QStringList ProbeDVBInputs(const QString& device);
475  static QMap <QString,QStringList> s_videoDeviceCache;
476 };
477 
478 #endif //CARDUTIL_H
CardUtil::SetValue
static bool SetValue(const QString &col, uint inputid, const QString &val)
Definition: cardutil.h:317
CardUtil::s_videoDeviceCache
static QMap< QString, QStringList > s_videoDeviceCache
Definition: cardutil.h:475
DVB_DEV_AUDIO
@ DVB_DEV_AUDIO
Definition: cardutil.h:34
CardUtil::IsDVB
static bool IsDVB(uint inputid)
Returns true if the input is a DVB input.
Definition: cardutil.h:405
CardUtil::IsTuningVirtual
static bool IsTuningVirtual(const QString &rawtype)
Definition: cardutil.h:209
error
static void error(const char *str,...)
Definition: vbi.cpp:37
CardUtil::GetV4LInfo
static bool GetV4LInfo(int videofd, QString &input, QString &driver)
Definition: cardutil.h:440
mythtvexp.h
CardUtil::GetFirstInputID
static uint GetFirstInputID(const QString &videodevice)
Convenience function for GetInputIDs()
Definition: cardutil.h:272
DTVTunerType
Definition: dtvconfparserhelpers.h:76
CardUtil::IsTuningDigital
static bool IsTuningDigital(const QString &rawtype)
Definition: cardutil.h:194
CardUtil::SetValue
static bool SetValue(const QString &col, uint inputid, int val)
Definition: cardutil.h:314
CardUtil::IsChannelChangeDiscontinuous
static bool IsChannelChangeDiscontinuous(const QString &rawtype)
Definition: cardutil.h:156
CardUtil::IsEncoder
static bool IsEncoder(const QString &rawtype)
Definition: cardutil.h:139
CardUtil::IsSingleInputType
static bool IsSingleInputType(const QString &rawtype)
Definition: cardutil.h:216
CardUtil::GetAudioDevice
static QString GetAudioDevice(uint inputid)
Definition: cardutil.h:300
CardUtil::GetDeliverySystemFromDB
static QString GetDeliverySystemFromDB(uint inputid)
Definition: cardutil.h:304
CardUtil
Collection of helper utilities for input DB use.
Definition: cardutil.h:41
CardUtil::GetValueInt
static int GetValueInt(const QString &col, uint inputid)
Definition: cardutil.h:312
CardUtil::IsV4L
static bool IsV4L(const QString &rawtype)
Definition: cardutil.h:149
DVB_DEV_DEMUX
@ DVB_DEV_DEMUX
Definition: cardutil.h:32
set_on_input
MTV_PUBLIC bool set_on_input(const QString &to_set, uint inputid, const QString &value)
Definition: cardutil.cpp:1273
CardInput
Definition: videosource.h:895
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
CardUtil::GetRawInputType
static QString GetRawInputType(uint inputid)
Definition: cardutil.h:296
DVB_DEV_CA
@ DVB_DEV_CA
Definition: cardutil.h:33
CardUtil::InputTypes
QMap< QString, QString > InputTypes
Definition: cardutil.h:46
DTVModulationSystem
Definition: dtvconfparserhelpers.h:644
dvb_dev_type_t
dvb_dev_type_t
Definition: cardutil.h:28
InputInfo
Definition: inputinfo.h:14
CardUtil::IsTunerSharingCapable
static bool IsTunerSharingCapable(const QString &rawtype)
Definition: cardutil.h:181
CardUtil::GetVBIDevice
static QString GetVBIDevice(uint inputid)
Definition: cardutil.h:302
InputNames
QMap< int, QString > InputNames
Definition: cardutil.h:22
CardUtil::IsEITCapable
static bool IsEITCapable(const QString &rawtype)
Definition: cardutil.h:174
musicbrainzngs.caa.hostname
string hostname
Definition: caa.py:17
CardUtil::INPUT_TYPES
INPUT_TYPES
all the different inputs
Definition: cardutil.h:49
CardUtil::GetHostname
static QString GetHostname(uint inputid)
Definition: cardutil.h:309
CardUtil::GetDiSEqCPosition
static QString GetDiSEqCPosition(uint inputid)
Definition: cardutil.h:306
CardUtil::IsTuningAnalog
static bool IsTuningAnalog(const QString &rawtype)
Definition: cardutil.h:202
CardUtil::IsUnscanable
static bool IsUnscanable(const QString &rawtype)
Definition: cardutil.h:162
DVB_DEV_VIDEO
@ DVB_DEV_VIDEO
Definition: cardutil.h:35
CardUtil::IsChannelReusable
static bool IsChannelReusable(const QString &rawtype)
Definition: cardutil.h:226
nv_python_libs.bbciplayer.bbciplayer_api.version
string version
Definition: bbciplayer_api.py:77
DVB_DEV_DVR
@ DVB_DEV_DVR
Definition: cardutil.h:31
dtvconfparserhelpers.h
get_on_input
MTV_PUBLIC QString get_on_input(const QString &to_get, uint inputid)
Definition: cardutil.cpp:1256
CardUtil::GetVideoDevice
static QString GetVideoDevice(uint inputid)
Definition: cardutil.h:298
uint
unsigned int uint
Definition: freesurround.h:24
DVB_DEV_FRONTEND
@ DVB_DEV_FRONTEND
Definition: cardutil.h:30