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