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