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 
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 #ifdef USING_VBOX
223  static bool IsVBoxPresent(uint inputid);
224 #endif
225 #ifdef USING_SATIP
226  static bool IsSatIPPresent(uint inputid);
227 #endif
228 
229  // Card creation and deletion
230 
231  static int CreateCaptureCard(const QString &videodevice,
232  const QString &audiodevice,
233  const QString &vbidevice,
234  const QString &inputtype,
235  uint audioratelimit,
236  const QString &hostname,
237  uint dvb_swfilter,
238  uint dvb_sat_type,
239  bool dvb_wait_for_seqstart,
240  bool skipbtaudio,
241  bool dvb_on_demand,
242  uint dvb_diseqc_type,
243  uint firewire_speed,
244  const QString &firewire_model,
245  uint firewire_connection,
246  std::chrono::milliseconds signal_timeout,
247  std::chrono::milliseconds channel_timeout,
248  uint dvb_tuning_delay,
249  uint contrast,
250  uint brightness,
251  uint colour,
252  uint hue,
253  uint diseqcid,
254  bool dvb_eitscan);
255 
256  static bool DeleteInput(uint inputid);
257  static bool DeleteAllInputs(void);
258  static std::vector<uint> GetInputList(void);
259  static std::vector<uint> GetSchedInputList(void);
260  static std::vector<uint> GetLiveTVInputList(void);
261 
263  static uint GetFirstInputID(const QString &videodevice)
264  {
265  std::vector<uint> list = GetInputIDs(videodevice);
266  if (list.empty())
267  return 0;
268  return list[0];
269  }
270 
271  static std::vector<uint> GetInputIDs(const QString& videodevice = QString(),
272  const QString& rawtype = QString(),
273  const QString& inputname = QString(),
274  QString hostname = QString());
275 
276  static uint GetChildInputCount(uint inputid);
277  static std::vector<uint> GetChildInputIDs(uint inputid);
278 
279  static bool IsInputTypePresent(const QString &rawtype,
280  QString hostname = QString());
281  static InputTypes GetInputTypes(void); // input types on ALL hosts
282  static QStringList GetInputTypeNames(uint sourceid); // input types for a given source id
283 
284  static QStringList GetVideoDevices(const QString &rawtype,
285  QString hostname = QString());
286 
287  static QString GetRawInputType(uint inputid)
288  { return get_on_input("cardtype", inputid).toUpper(); }
289  static QString GetVideoDevice(uint inputid)
290  { return get_on_input("videodevice", inputid); }
291  static QString GetAudioDevice(uint inputid)
292  { return get_on_input("audiodevice", inputid); }
293  static QString GetVBIDevice(uint inputid)
294  { return get_on_input("vbidevice", inputid); }
295  static QString GetDeliverySystemFromDB(uint inputid)
296  { return get_on_input("inputname", inputid); } // use capturecard/inputname for now
297 
298  static QString GetHostname(uint inputid)
299  { return get_on_input("hostname", inputid); }
300 
301  static int GetValueInt(const QString &col, uint inputid)
302  { return get_on_input(col, inputid).toInt(); }
303  static bool SetValue(const QString &col, uint inputid,
304  int val)
305  { return set_on_input(col, inputid, QString::number(val)); }
306  static bool SetValue(const QString &col, uint inputid,
307  const QString &val)
308  { return set_on_input(col, inputid, val); }
309 
310  static bool SetStartChannel(uint inputid,
311  const QString &channum);
312 
313  // Input creation and deletion
314  static int CreateCardInput(uint inputid,
315  uint sourceid,
316  const QString &inputname,
317  const QString &externalcommand,
318  const QString &changer_device,
319  const QString &changer_model,
320  const QString &hostname,
321  const QString &tunechan,
322  const QString &startchan,
323  const QString &displayname,
324  bool dishnet_eit,
325  uint recpriority,
326  uint quicktune,
327  uint schedorder,
328  uint livetvorder);
329 
330  // Other input functions
331 
332  static std::vector<uint> GetInputIDs(uint sourceid);
333  static bool GetInputInfo(InputInfo &input,
334  std::vector<uint> *groupids = nullptr);
335  static QList<InputInfo> GetAllInputInfo();
336  static QString GetInputName(uint inputid);
337  static QString GetStartChannel(uint inputid);
338  static QString GetDisplayName(uint inputid);
339  static bool IsUniqueDisplayName(const QString &name,
340  uint exclude_inputid);
341  static uint GetSourceID(uint inputid);
342 
343  // Input Groups
344  static uint CreateInputGroup(const QString &name);
345  static uint CreateDeviceInputGroup(uint inputid,
346  const QString &type,
347  const QString &host,
348  const QString &device);
349  static uint GetDeviceInputGroup(uint inputid);
350  static bool LinkInputGroup(uint inputid, uint inputgroupid);
351  static bool UnlinkInputGroup(uint inputid, uint inputgroupid);
352  static std::vector<uint> GetInputGroups(uint inputid);
353  static std::vector<uint> GetGroupInputIDs(uint inputgroupid);
354  static std::vector<uint> GetConflictingInputs(uint inputid);
355 
356  static QString GetDeviceLabel(const QString &inputtype,
357  const QString &videodevice);
358  static QString GetDeviceLabel(uint inputid);
359 
360  static QString ProbeSubTypeName(uint inputid);
361 
362  static QStringList ProbeVideoInputs(const QString& device,
363  const QString& inputtype = QString());
364  static QStringList ProbeAudioInputs(const QString& device,
365  const QString& inputtype = QString());
366  static void GetDeviceInputNames(const QString &device,
367  const QString &inputtype,
368  QStringList &inputs);
369 
370  // General info from OS
371  static QStringList ProbeVideoDevices(const QString &rawtype);
372  static void ClearVideoDeviceCache();
373 
374  // Other
375  static uint CloneCard(uint src_inputid, uint dst_inputid);
376  static bool InputSetMaxRecordings(uint parentid,
377  uint max_recordings);
378  static uint AddChildInput(uint parentid);
379  static QString GetFirewireChangerNode(uint inputid);
380  static QString GetFirewireChangerModel(uint inputid);
381 
382  // DTV info
383  static bool GetTimeouts(uint inputid,
384  std::chrono::milliseconds &signal_timeout,
385  std::chrono::milliseconds &channel_timeout);
386  static bool IgnoreEncrypted(uint inputid,
387  const QString &inputname);
388  static bool TVOnly(uint inputid, const QString &inputname);
389  static bool IsInNeedOfExternalInputConf(uint inputid);
390  static uint GetQuickTuning(uint inputid, const QString &input_name);
391 
392  // DVB info
394  static bool IsDVB(uint inputid)
395  { return "DVB" == GetRawInputType(inputid); }
396  static bool IsDVBInputType(const QString &inputType);
397  static QStringList ProbeDeliverySystems(const QString &device);
398  static QStringList ProbeDeliverySystems(int fd_frontend);
399  static QString ProbeDefaultDeliverySystem(const QString &device);
400  static QString ProbeDVBType(const QString &device);
401  static QString ProbeDVBFrontendName(const QString &device);
402  static bool HasDVBCRCBug(const QString &device);
403  static std::chrono::milliseconds GetMinSignalMonitoringDelay(const QString &device);
404  static DTVTunerType ConvertToTunerType(DTVModulationSystem delsys);
405  static DTVTunerType GetTunerType(uint inputid);
406  static DTVTunerType ProbeTunerType(int fd_frontend);
407  static DTVTunerType ProbeTunerType(const QString &device);
408  static DTVTunerType GetTunerTypeFromMultiplex(uint mplexid);
409  static DTVModulationSystem GetDeliverySystem(uint inputid);
410  static DTVModulationSystem ProbeCurrentDeliverySystem(const QString &device);
411  static DTVModulationSystem ProbeCurrentDeliverySystem(int fd_frontend);
412  static DTVModulationSystem ProbeBestDeliverySystem(int fd);
413  static DTVModulationSystem GetOrProbeDeliverySystem(uint inputid, int fd);
414  static int SetDefaultDeliverySystem(uint inputid, int fd);
415  static int SetDeliverySystem(uint inputid);
416  static int SetDeliverySystem(uint inputid, DTVModulationSystem delsys);
417  static int SetDeliverySystem(uint inputid, int fd);
418  static int SetDeliverySystem(uint inputid, DTVModulationSystem delsys, int fd);
419  static int OpenVideoDevice(int inputid);
420  static int OpenVideoDevice(const QString &device);
421  static QString GetDeviceName(dvb_dev_type_t type, const QString &device);
422  static InputNames GetConfiguredDVBInputs(const QString &device);
423  static QStringList CapabilitiesToString(uint64_t capabilities);
424 
425  // V4L info
426  static bool hasV4L2(int videofd);
427  static bool GetV4LInfo(int videofd, QString &input, QString &driver,
428  uint32_t &version, uint32_t &capabilities);
429  static bool GetV4LInfo(int videofd, QString &input, QString &driver)
430  {
431  uint32_t d1 = 0;
432  uint32_t d2 = 0;
433  return GetV4LInfo(videofd, input, driver, d1, d2);
434  }
435  static InputNames ProbeV4LVideoInputs(int videofd, bool &ok);
436  static InputNames ProbeV4LAudioInputs(int videofd, bool &ok);
437 
438  // HDHomeRun info
439  static bool HDHRdoesDVB(const QString &device);
440  static bool HDHRdoesDVBC(const QString &device);
441  static QString GetHDHRdesc(const QString &device);
442 
443  // VBox info
444  static QString GetVBoxdesc(const QString &id, const QString &ip,
445  const QString &tunerNo, const QString &tunerType);
446 
447  // ASI info
448  static int GetASIDeviceNumber(const QString &device,
449  QString *error = nullptr);
450 
451  static uint GetASIBufferSize(uint device_num,
452  QString *error = nullptr);
453  static uint GetASINumBuffers(uint device_num,
454  QString *error = nullptr);
455  static int GetASIMode(uint device_num,
456  QString *error = nullptr);
457  static bool SetASIMode(uint device_num, uint mode,
458  QString *error = nullptr);
459 
460  private:
461  static QStringList ProbeV4LVideoInputs(const QString& device);
462  static QStringList ProbeV4LAudioInputs(const QString& device);
463  static QStringList ProbeDVBInputs(const QString& device);
464  static QMap <QString,QStringList> s_videoDeviceCache;
465 };
466 
467 #endif //CARDUTIL_H
CardUtil::SetValue
static bool SetValue(const QString &col, uint inputid, const QString &val)
Definition: cardutil.h:306
CardUtil::s_videoDeviceCache
static QMap< QString, QStringList > s_videoDeviceCache
Definition: cardutil.h:464
CardUtil::IsDVB
static bool IsDVB(uint inputid)
Returns true if the input is a DVB input.
Definition: cardutil.h:394
CardUtil::IsTuningVirtual
static bool IsTuningVirtual(const QString &rawtype)
Definition: cardutil.h:200
error
static void error(const char *str,...)
Definition: vbi.cpp:36
DVB_DEV_VIDEO
@ DVB_DEV_VIDEO
Definition: cardutil.h:34
CardUtil::GetV4LInfo
static bool GetV4LInfo(int videofd, QString &input, QString &driver)
Definition: cardutil.h:429
mythtvexp.h
CardUtil::GetFirstInputID
static uint GetFirstInputID(const QString &videodevice)
Convenience function for GetInputIDs()
Definition: cardutil.h:263
DVB_DEV_CA
@ DVB_DEV_CA
Definition: cardutil.h:32
DTVTunerType
Definition: dtvconfparserhelpers.h:76
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:303
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:291
CardUtil::GetDeliverySystemFromDB
static QString GetDeliverySystemFromDB(uint inputid)
Definition: cardutil.h:295
DVB_DEV_AUDIO
@ DVB_DEV_AUDIO
Definition: cardutil.h:33
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:301
uint
unsigned int uint
Definition: compat.h:79
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:1236
CardInput
Definition: videosource.h:896
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
CardUtil::GetRawInputType
static QString GetRawInputType(uint inputid)
Definition: cardutil.h:287
DVB_DEV_DEMUX
@ DVB_DEV_DEMUX
Definition: cardutil.h:31
CardUtil::InputTypes
QMap< QString, QString > InputTypes
Definition: cardutil.h:43
DTVModulationSystem
Definition: dtvconfparserhelpers.h:644
InputInfo
Definition: inputinfo.h:14
CardUtil::IsTunerSharingCapable
static bool IsTunerSharingCapable(const QString &rawtype)
Definition: cardutil.h:172
CardUtil::GetVBIDevice
static QString GetVBIDevice(uint inputid)
Definition: cardutil.h:293
InputNames
QMap< int, QString > InputNames
Definition: cardutil.h:21
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:298
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:77
dtvconfparserhelpers.h
get_on_input
MTV_PUBLIC QString get_on_input(const QString &to_get, uint inputid)
Definition: cardutil.cpp:1219
CardUtil::GetVideoDevice
static QString GetVideoDevice(uint inputid)
Definition: cardutil.h:289
CardUtil::INPUT_TYPES
INPUT_TYPES
all the different inputs
Definition: cardutil.h:46