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