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