MythTV  master
cardutil.cpp
Go to the documentation of this file.
1 // Standard UNIX C headers
2 #include <fcntl.h>
3 #include <unistd.h>
4 
5 #include <algorithm>
6 
7 #if defined(USING_V4L2) || defined(USING_DVB)
8 #include <sys/ioctl.h>
9 #endif
10 
11 // Qt headers
12 #include <QMap>
13 #include <QDir>
14 
15 // MythTV headers
16 #include "mythconfig.h"
17 #include "cardutil.h"
18 #include "videosource.h"
19 #include "dvbchannel.h"
20 #include "diseqcsettings.h"
21 #include "sourceutil.h"
22 #include "mythdb.h"
23 #include "mythlogging.h"
24 #include "inputinfo.h"
25 #include "mythmiscutil.h" // for ping()
26 #include "mythdownloadmanager.h"
27 
28 #ifdef USING_DVB
29 #include "dvbtypes.h"
30 #endif
31 
32 #ifdef USING_V4L1
33 #include <linux/videodev.h>
34 #endif
35 
36 #ifdef USING_V4L2
37 #include "v4l2util.h"
38 #endif
39 
40 #ifdef USING_HDHOMERUN
41 #include HDHOMERUN_HEADERFILE
42 #endif
43 
44 #ifdef USING_VBOX
45 #include "vboxutils.h"
46 #include "mythmiscutil.h"
47 #endif
48 
49 #ifdef USING_SATIP
50 #include "satiputils.h"
51 #endif
52 
53 #ifdef USING_ASI
54 #include <sys/types.h>
55 #include <sys/stat.h>
56 #include <dveo/asi.h>
57 #include <dveo/master.h>
58 #endif
59 
60 #define LOC QString("CardUtil: ")
61 
63 {
64  QStringList inputTypes {};
65 
66 #ifdef USING_DVB
67  inputTypes += "'DVB'";
68 #endif // USING_DVB
69 
70 #ifdef USING_V4L2
71  inputTypes += "'V4L'";
72 # ifdef USING_IVTV
73  inputTypes += "'MPEG'";
74 # endif // USING_IVTV
75 #endif // USING_V4L2
76 
77 #ifdef USING_IPTV
78  inputTypes += "'FREEBOX'";
79 #endif // USING_IPTV
80 
81 #ifdef USING_VBOX
82  inputTypes += "'VBOX'";
83 #endif // USING_VBOX
84 
85 #ifdef USING_HDHOMERUN
86  inputTypes += "'HDHOMERUN'";
87 #endif // USING_HDHOMERUN
88 
89 #ifdef USING_SATIP
90  inputTypes += "'SATIP'";
91 #endif // USING_SATIP
92 
93 #ifdef USING_ASI
94  inputTypes += "'ASI'";
95 #endif
96 
97 #ifdef USING_CETON
98  inputTypes += "'CETON'";
99 #endif // USING_CETON
100 
101 #if !defined( USING_MINGW ) && !defined( _MSC_VER )
102  inputTypes += "'EXTERNAL'";
103 #endif
104 
105  if (inputTypes.isEmpty())
106  return "('DUMMY')";
107 
108  return QString("(%1)").arg(inputTypes.join(','));
109 }
110 
112  const QString &inputType)
113 {
114 #if (!USING_HDHOMERUN && !USING_CETON)
115  Q_UNUSED(inputid);
116 #endif
117 
118  if (inputType == "HDHOMERUN")
119  {
120 #ifdef USING_HDHOMERUN
121  hdhomerun_tuner_status_t status {};
122  QString device = GetVideoDevice(inputid);
123  hdhomerun_device_t *hdhr =
124  hdhomerun_device_create_from_str(device.toLatin1(), nullptr);
125  if (!hdhr)
126  return false;
127 
128  int oob = hdhomerun_device_get_oob_status(hdhr, nullptr, &status);
129 
130  // if no OOB tuner, oob will be < 1. If no CC present, OOB
131  // status will be "none."
132  if (oob > 0 && (strncmp(status.channel, "none", 4) != 0))
133  {
134  LOG(VB_GENERAL, LOG_INFO, "Cardutil: HDHomeRun Cablecard Present.");
135  hdhomerun_device_destroy(hdhr);
136  return true;
137  }
138 
139  hdhomerun_device_destroy(hdhr);
140 
141 #endif
142  return false;
143  }
144  if (inputType == "CETON")
145  {
146 #ifdef USING_CETON
147  QString device = GetVideoDevice(inputid);
148 
149  QStringList parts = device.split("-");
150  if (parts.size() != 2)
151  {
152  LOG(VB_GENERAL, LOG_ERR,
153  QString("CardUtil: Ceton invalid device id %1").arg(device));
154  return false;
155  }
156 
157  const QString& ip_address = parts.at(0);
158 
159  QStringList tuner_parts = parts.at(1).split(".");
160  if (tuner_parts.size() != 2)
161  {
162  LOG(VB_GENERAL, LOG_ERR, LOC +
163  QString("CardUtil: Ceton invalid device id %1").arg(device));
164  return false;
165  }
166 
167  uint tuner = tuner_parts.at(1).toUInt();
168 
169  QUrlQuery params;
170  params.addQueryItem("i", QString::number(tuner));
171  params.addQueryItem("s", "cas");
172  params.addQueryItem("v", "CardStatus");
173 
174  QUrl url;
175  url.setScheme("http");
176  url.setHost(ip_address);
177  url.setPath("/get_var.json");
178  url.setQuery(params);
179 
180  auto *request = new QNetworkRequest();
181  request->setAttribute(QNetworkRequest::CacheLoadControlAttribute,
182  QNetworkRequest::AlwaysNetwork);
183  request->setUrl(url);
184 
185  QByteArray data;
187 
188  if (!manager->download(request, &data))
189  {
190  LOG(VB_GENERAL, LOG_ERR,
191  QString("CardUtil: Ceton http request failed %1").arg(device));
192  return false;
193  }
194 
195  QString response = QString(data);
196 
197  static const QRegularExpression regex { "^\\{ \"?result\"?: \"(.*)\" \\}$"};
198  auto match = regex.match(response);
199  if (!match.hasMatch())
200  {
201  LOG(VB_GENERAL, LOG_ERR,
202  QString("CardUtil: Ceton unexpected http response: %1").arg(response));
203  return false;
204  }
205 
206  QString result = match.captured(1);
207 
208  if (result == "Inserted")
209  {
210  LOG(VB_GENERAL, LOG_DEBUG, "Cardutil: Ceton CableCARD present.");
211  return true;
212  }
213 
214  LOG(VB_GENERAL, LOG_DEBUG, "Cardutil: Ceton CableCARD not present.");
215  return false;
216 #else
217  return false;
218 #endif
219  }
220  return false;
221 }
222 
223 bool CardUtil::HasTuner(const QString &rawtype, const QString & device)
224 {
225  if (rawtype == "DVB" || rawtype == "HDHOMERUN" ||
226  rawtype == "FREEBOX" || rawtype == "CETON" ||
227  rawtype == "VBOX" || rawtype == "SATIP")
228  return true;
229 
230 #ifdef USING_V4L2
231  if (rawtype == "V4L2ENC")
232  {
233  V4L2util v4l2(device);
234  return !v4l2 ? false : v4l2.HasTuner();
235  }
236 #else
237  Q_UNUSED(device);
238 #endif
239 
240  if (rawtype == "EXTERNAL")
241  {
242  // TODO: query EXTERNAL for capability
243  return true;
244  }
245 
246  return false;
247 }
248 
249 bool CardUtil::IsTunerShared(uint inputidA, uint inputidB)
250 {
251  LOG(VB_GENERAL, LOG_DEBUG, QString("IsTunerShared(%1,%2)")
252  .arg(inputidA).arg(inputidB));
253 
254  MSqlQuery query(MSqlQuery::InitCon());
255  query.prepare("SELECT videodevice, hostname, cardtype "
256  "FROM capturecard "
257  "WHERE ( (cardid = :INPUTID_A) OR "
258  " (cardid = :INPUTID_B) )");
259  query.bindValue(":INPUTID_A", inputidA);
260  query.bindValue(":INPUTID_B", inputidB);
261 
262  if (!query.exec())
263  {
264  MythDB::DBError("CardUtil::is_tuner_shared()", query);
265  return false;
266  }
267 
268  if (!query.next())
269  return false;
270 
271  const QString vdevice = query.value(0).toString();
272  const QString hostname = query.value(1).toString();
273  const QString inputtype = query.value(2).toString();
274 
275  if (!IsTunerSharingCapable(inputtype.toUpper()))
276  return false;
277 
278  if (!query.next())
279  return false;
280 
281  bool ret = ((vdevice == query.value(0).toString()) &&
282  (hostname == query.value(1).toString()) &&
283  (inputtype == query.value(2).toString()));
284 
285  LOG(VB_RECORD, LOG_DEBUG, QString("IsTunerShared(%1,%2) -> %3")
286  .arg(inputidA).arg(inputidB).arg(ret));
287 
288  return ret;
289 }
290 
296 bool CardUtil::IsInputTypePresent(const QString &rawtype, QString hostname)
297 {
298  if (hostname.isEmpty())
300 
301  MSqlQuery query(MSqlQuery::InitCon());
302  QString qstr =
303  "SELECT count(cardtype) "
304  "FROM capturecard "
305  "WHERE capturecard.hostname = :HOSTNAME ";
306 
307  if (!rawtype.isEmpty())
308  qstr += " AND capturecard.cardtype = :INPUTTYPE";
309 
310  query.prepare(qstr);
311 
312  if (!rawtype.isEmpty())
313  query.bindValue(":INPUTTYPE", rawtype.toUpper());
314 
315  query.bindValue(":HOSTNAME", hostname);
316 
317  if (!query.exec())
318  {
319  MythDB::DBError("CardUtil::IsInputTypePresent()", query);
320  return false;
321  }
322 
323  uint count = 0;
324  if (query.next())
325  count = query.value(0).toUInt();
326 
327  return count > 0;
328 }
329 
331 {
332  InputTypes inputtypes;
333 
334  MSqlQuery query(MSqlQuery::InitCon());
335  query.prepare("SELECT DISTINCT cardtype, videodevice "
336  "FROM capturecard");
337 
338  if (!query.exec())
339  {
340  MythDB::DBError("CardUtil::GetInputTypes()", query);
341  }
342  else
343  {
344  QString cardtype;
345 
346  while (query.next())
347  {
348  cardtype = query.value(0).toString();
349  if (cardtype != "V4L2ENC")
350  {
351  inputtypes[cardtype] = "";
352  }
353 #ifdef USING_V4L2
354  else
355  {
356  V4L2util v4l2(query.value(1).toString());
357  if (v4l2.IsOpen())
358  {
359  QString driver_name = "V4L2:" + v4l2.DriverName();
360  inputtypes[driver_name] = v4l2.CardName();
361  }
362  }
363 #endif
364  }
365  }
366 
367  return inputtypes;
368 }
369 
377 QStringList CardUtil::GetInputTypeNames(uint sourceid)
378 {
379  MSqlQuery query(MSqlQuery::InitCon());
380  query.prepare("SELECT cardtype "
381  "FROM capturecard "
382  "WHERE capturecard.sourceid = :SOURCEID "
383  "GROUP BY cardtype");
384  query.bindValue(":SOURCEID", sourceid);
385 
386  QStringList list;
387  if (!query.exec())
388  {
389  MythDB::DBError("CardUtil::GetInputTypes", query);
390  return list;
391  }
392  while (query.next())
393  list.push_back(query.value(0).toString());
394  return list;
395 }
396 
397 
398 
399 
405 QStringList CardUtil::GetVideoDevices(const QString &rawtype, QString hostname)
406 {
407  QStringList list;
408 
409  if (hostname.isEmpty())
411 
412  MSqlQuery query(MSqlQuery::InitCon());
413  QString qstr =
414  "SELECT videodevice "
415  "FROM capturecard "
416  "WHERE hostname = :HOSTNAME";
417 
418  if (!rawtype.isEmpty())
419  qstr += " AND cardtype = :INPUTTYPE";
420 
421  query.prepare(qstr);
422 
423  if (!rawtype.isEmpty())
424  query.bindValue(":INPUTTYPE", rawtype.toUpper());
425 
426  query.bindValue(":HOSTNAME", hostname);
427 
428  if (!query.exec())
429  {
430  MythDB::DBError("CardUtil::GetVideoDevices", query);
431  return list;
432  }
433 
434  QMap<QString,bool> dup;
435  while (query.next())
436  {
437  QString videodevice = query.value(0).toString();
438  if (dup[videodevice])
439  continue;
440 
441  list.push_back(videodevice);
442  dup[videodevice] = true;
443  }
444 
445  return list;
446 }
447 
448 QMap <QString,QStringList> CardUtil::s_videoDeviceCache;
449 
451 {
452  s_videoDeviceCache.clear();
453 }
454 
455 
456 QStringList CardUtil::ProbeVideoDevices(const QString &rawtype)
457 {
458  if (s_videoDeviceCache.contains(rawtype))
459  return s_videoDeviceCache[rawtype];
460 
461  QStringList devs;
462 
463  if (rawtype.toUpper() == "DVB")
464  {
465  QDir dir("/dev/dvb", "adapter*", QDir::Name, QDir::Dirs);
466  QFileInfoList entries = dir.entryInfoList();
467  for (const auto & it : qAsConst(entries))
468  {
469  QDir subdir(it.filePath(), "frontend*", QDir::Name, QDir::Files | QDir::System);
470  const QFileInfoList subil = subdir.entryInfoList();
471  if (subil.isEmpty())
472  continue;
473 
474  for (const auto & subit : qAsConst(subil))
475  devs.push_back(subit.filePath());
476  }
477  }
478  else if (rawtype.toUpper() == "ASI")
479  {
480  QDir dir("/dev/", "asirx*", QDir::Name, QDir::System);
481  QFileInfoList entries = dir.entryInfoList();
482  for (const auto & it : qAsConst(entries))
483  {
484  if (GetASIDeviceNumber(it.filePath()) >= 0)
485  {
486  devs.push_back(it.filePath());
487  continue;
488  }
489  break;
490  }
491  }
492 #ifdef USING_HDHOMERUN
493  else if (rawtype.toUpper() == "HDHOMERUN")
494  {
495  uint32_t target_ip = 0;
496  uint32_t device_type = HDHOMERUN_DEVICE_TYPE_TUNER;
497  uint32_t device_id = HDHOMERUN_DEVICE_ID_WILDCARD;
498  const int max_count = 50;
499  std::array<hdhomerun_discover_device_t,max_count> result_list {};
500 
501 #ifdef HDHOMERUN_V2
502  int result = hdhomerun_discover_find_devices_custom_v2(
503  target_ip, device_type, device_id, result_list.data(), result_list.size());
504 #else
505  int result = hdhomerun_discover_find_devices_custom(
506  target_ip, device_type, device_id, result_list.data(), result_list.size());
507 #endif
508 
509  if (result == -1)
510  {
511  LOG(VB_GENERAL, LOG_ERR, "Error finding HDHomerun devices");
512  }
513 
514  if (result >= max_count)
515  {
516  LOG(VB_GENERAL, LOG_WARNING,
517  "Warning: may be > 50 HDHomerun devices");
518  }
519 
520  // Return "deviceid ipaddress" pairs
521  for (int i = 0; i < result; i++)
522  {
523  QString id = QString("%1").arg(result_list[i].device_id, 0, 16);
524  QString ip = QString("%1.%2.%3.%4")
525  .arg((result_list[i].ip_addr>>24) & 0xFF)
526  .arg((result_list[i].ip_addr>>16) & 0xFF)
527  .arg((result_list[i].ip_addr>> 8) & 0xFF)
528  .arg((result_list[i].ip_addr>> 0) & 0xFF);
529 
530  QString model = "";
531  hdhomerun_device_t *device = hdhomerun_device_create(
532  result_list[i].device_id, 0, 0, nullptr);
533  if (device)
534  {
535  model = hdhomerun_device_get_model_str(device);
536  hdhomerun_device_destroy(device);
537  }
538 
539  QString hdhrdev = id.toUpper() + " " + ip + " " + model;
540  devs.push_back(hdhrdev);
541  }
542  }
543 #endif // USING_HDHOMERUN
544 #ifdef USING_SATIP
545  else if (rawtype.toUpper() == "SATIP")
546  {
547  devs = SatIP::probeDevices();
548  }
549 #endif // USING_SATIP
550 #ifdef USING_VBOX
551  else if (rawtype.toUpper() == "VBOX")
552  {
553  devs = VBox::probeDevices();
554  }
555 #endif // USING_VBOX
556 #ifdef USING_CETON
557  else if (rawtype.toUpper() == "CETON")
558  {
559  // TODO implement CETON probing.
560  LOG(VB_GENERAL, LOG_INFO, "CardUtil::ProbeVideoDevices: "
561  "TODO Probe Ceton devices");
562  }
563 #endif // USING_CETON
564  else
565  {
566  LOG(VB_GENERAL, LOG_ERR, QString("Raw Type: '%1' is not supported")
567  .arg(rawtype));
568  }
569 
570  s_videoDeviceCache.insert(rawtype,devs);
571  return devs;
572 }
573 
574 // Get the list of delivery systems from the card
575 QStringList CardUtil::ProbeDeliverySystems(const QString &device)
576 {
577  QStringList delsyslist;
578 
579 #ifdef USING_DVB
580  int fd_frontend = OpenVideoDevice(device);
581  if (fd_frontend < 0)
582  {
583  return delsyslist;
584  }
585 
586  struct dtv_property prop = {};
587  struct dtv_properties cmd = {};
588 
589  prop.cmd = DTV_API_VERSION;
590  cmd.num = 1;
591  cmd.props = &prop;
592  if (ioctl(fd_frontend, FE_GET_PROPERTY, &cmd) == 0)
593  {
594  LOG(VB_GENERAL, LOG_DEBUG,
595  QString("CardUtil(%1): ").arg(device) +
596  QString("dvb api version %1.%2").arg((prop.u.data>>8)&0xff).arg((prop.u.data)&0xff));
597  }
598  else
599  {
600  LOG(VB_GENERAL, LOG_ERR,
601  QString("CardUtil(%1) FE_GET_PROPERTY ioctl failed").arg(device) + ENO);
602  close(fd_frontend);
603  return delsyslist;
604  }
605 
606  delsyslist = ProbeDeliverySystems(fd_frontend);
607 
608  QString msg = "Delivery systems:";
609  for (const auto & item : qAsConst(delsyslist))
610  {
611  msg += " ";
612  msg += item;
613  }
614  LOG(VB_GENERAL, LOG_INFO, QString("CardUtil(%1): ").arg(device) + msg);
615 
616  close(fd_frontend);
617 #else
618  Q_UNUSED(device);
619 #endif // USING_DVB
620 
621  return delsyslist;
622 }
623 
624 // Get the list of all supported delivery systems from the card
625 QStringList CardUtil::ProbeDeliverySystems(int fd_frontend)
626 {
627  QStringList delsyslist;
628 
629 #ifdef USING_DVB
630  struct dtv_property prop = {};
631  struct dtv_properties cmd = {};
632 
633  prop.cmd = DTV_ENUM_DELSYS;
634  cmd.num = 1;
635  cmd.props = &prop;
636  if (ioctl(fd_frontend, FE_GET_PROPERTY, &cmd) == 0)
637  {
638  for (unsigned int i = 0; i < prop.u.buffer.len; i++)
639  {
640  delsyslist.push_back(DTVModulationSystem::toString(prop.u.buffer.data[i]));
641  }
642  }
643  else
644  {
645  LOG(VB_GENERAL, LOG_ERR, LOC + "FE_GET_PROPERTY ioctl failed " + ENO);
646  }
647 #else
648  Q_UNUSED(fd_frontend);
649 #endif // USING_DVB
650 
651  return delsyslist;
652 }
653 
654 QString CardUtil::ProbeDefaultDeliverySystem(const QString &device)
655 {
656  DTVModulationSystem delsys;
657 
658 #ifdef USING_DVB
659  int fd = OpenVideoDevice(device);
660  if (fd >= 0)
661  {
662  delsys = ProbeBestDeliverySystem(fd);
663  close(fd);
664  }
665 #else
666  Q_UNUSED(device);
667 #endif // USING_DVB
668 
669  return delsys.toString();
670 }
671 
672 QString CardUtil::ProbeDVBType(const QString &device)
673 {
674  QString ret = "ERROR_UNKNOWN";
675 
676  if (device.isEmpty())
677  return ret;
678 
679 #ifdef USING_DVB
680  DTVTunerType type = ProbeTunerType(device);
681  ret = (type.toString() != "UNKNOWN") ? type.toString().toUpper() : ret;
682 
683  LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("(%1) tuner type:%2 %3")
684  .arg(device).arg(type).arg(ret));
685 #endif // USING_DVB
686 
687  return ret;
688 }
689 
693 QString CardUtil::ProbeDVBFrontendName(const QString &device)
694 {
695  QString ret = "ERROR_UNKNOWN";
696 
697 #ifdef USING_DVB
698  QString dvbdev = CardUtil::GetDeviceName(DVB_DEV_FRONTEND, device);
699  QByteArray dev = dvbdev.toLatin1();
700  int fd_frontend = open(dev.constData(), O_RDWR | O_NONBLOCK);
701  if (fd_frontend < 0)
702  return "ERROR_OPEN";
703 
704  struct dvb_frontend_info info {};
705  int err = ioctl(fd_frontend, FE_GET_INFO, &info);
706  if (err < 0)
707  {
708  close(fd_frontend);
709  return "ERROR_PROBE";
710  }
711 
712  ret = info.name;
713 
714  close(fd_frontend);
715 #else
716  Q_UNUSED(device);
717 #endif // USING_DVB
718 
719  return ret;
720 }
721 
739 bool CardUtil::HasDVBCRCBug(const QString &device)
740 {
741  QString name = ProbeDVBFrontendName(device);
742  return ((name == "VLSI VES1x93 DVB-S") || // munges PMT
743  (name == "ST STV0299 DVB-S")); // munges PAT
744 }
745 
746 std::chrono::milliseconds CardUtil::GetMinSignalMonitoringDelay(const QString &device)
747 {
748  QString name = ProbeDVBFrontendName(device);
749  if (name.indexOf("DVB-S") >= 0)
750  return 300ms;
751  if (name == "DiBcom 3000P/M-C DVB-T")
752  return 100ms;
753  return 25ms;
754 }
755 
757 {
758  DTVTunerType tunertype;
759 
760  switch (delsys)
761  {
763  tunertype = DTVTunerType::kTunerTypeDVBS1;
764  break;
766  tunertype = DTVTunerType::kTunerTypeDVBS2;
767  break;
770  tunertype = DTVTunerType::kTunerTypeDVBC;
771  break;
773  tunertype = DTVTunerType::kTunerTypeDVBT;
774  break;
776  tunertype = DTVTunerType::kTunerTypeDVBT2;
777  break;
779  tunertype = DTVTunerType::kTunerTypeDVBT;
780  break;
783  tunertype = DTVTunerType::kTunerTypeATSC;
784  break;
787  break;
788  default:
789  LOG(VB_GENERAL, LOG_ERR, LOC +
790  QString("TODO Add to switch case delivery system:%2 %3")
791  .arg(delsys).arg(delsys.toString()));
792  break;
793  }
794 
795  return tunertype;
796 }
797 
798 // Get the currently configured tuner type from the database
800 {
801  DTVModulationSystem delsys = GetDeliverySystem(inputid);
802  DTVTunerType tunertype = ConvertToTunerType(delsys);
803  return tunertype;
804 }
805 
806 // Get the currently configured tuner type from the device
808 {
809  DTVModulationSystem delsys = ProbeCurrentDeliverySystem(fd_frontend);
810  DTVTunerType tunertype = ConvertToTunerType(delsys);
811  return tunertype;
812 }
813 
814 // Get the currently configured tuner type from the device
816 {
818  DTVTunerType tunertype = ConvertToTunerType(delsys);
819  return tunertype;
820 }
821 
822 // Get the tuner type from the multiplex
824 {
825  DTVTunerType tuner_type;
826 
827  MSqlQuery query(MSqlQuery::InitCon());
828  query.prepare(
829  "SELECT mod_sys "
830  "FROM dtv_multiplex "
831  "WHERE dtv_multiplex.mplexid = :MPLEXID");
832  query.bindValue(":MPLEXID", mplexid);
833 
834  if (!query.exec())
835  {
836  MythDB::DBError("CardUtil::GetTunerTypeFromMultiplex", query);
837  return tuner_type;
838  }
839 
840  if (!query.next())
841  {
842  LOG(VB_GENERAL, LOG_ERR, LOC +
843  QString("Could not find entry in dtv_multiplex for mplexid %1")
844  .arg(mplexid));
845 
846  return tuner_type;
847  }
848 
849  DTVModulationSystem mod_sys;
850  mod_sys.Parse(query.value(0).toString());
851  tuner_type = CardUtil::ConvertToTunerType(mod_sys);
852 
853  return tuner_type;
854 }
855 
856 // Get the currently configured delivery system from the database
858 {
859  QString ds = GetDeliverySystemFromDB(inputid);
860  DTVModulationSystem delsys;
861  delsys.Parse(ds);
862  return delsys;
863 }
864 
865 // Get the currently configured delivery system from the device
867 {
868  DTVModulationSystem delsys;
869 
870  if (device.isEmpty())
871  {
872  return delsys;
873  }
874 
875 #ifdef USING_DVB
876  int fd_frontend = OpenVideoDevice(device);
877  if (fd_frontend < 0)
878  {
879  LOG(VB_GENERAL, LOG_ERR, LOC +
880  QString("open failed (%1)")
881  .arg(device) + ENO);
882  return delsys;
883  }
884 
885  delsys = ProbeCurrentDeliverySystem(fd_frontend);
886 
887  LOG(VB_GENERAL, LOG_DEBUG, QString("CardUtil(%1): delsys:%2 %3")
888  .arg(device).arg(delsys).arg(delsys.toString()));
889 
890  close(fd_frontend);
891 #else
892  Q_UNUSED(device);
893 #endif
894 
895  return delsys;
896 }
897 
898 // Get the currently configured delivery system from the device
900 {
901  DTVModulationSystem delsys;
902 
903 #ifdef USING_DVB
904  struct dtv_property prop = {};
905  struct dtv_properties cmd = {};
906 
907  prop.cmd = DTV_DELIVERY_SYSTEM;
908  // prop.u.data = delsys;
909  cmd.num = 1;
910  cmd.props = &prop;
911 
912  int ret = ioctl(fd_frontend, FE_GET_PROPERTY, &cmd);
913  if (ret < 0)
914  {
915  LOG(VB_GENERAL, LOG_ERR, LOC +
916  QString("FE_GET_PROPERTY ioctl failed (fd_frontend:%1)")
917  .arg(fd_frontend) + ENO);
918  return delsys;
919  }
920 
921  delsys = prop.u.data;
922 
923 #else
924  Q_UNUSED(fd_frontend);
925 #endif // USING_DVB
926 
927  return delsys;
928 }
929 
930 // Get the delivery system from database table capturecard.
931 // If there is nothing in the database then get the currently
932 // configured delivery system, check for DVB-T/T2 and DVB-S/S2
933 // and update the database.
934 // Configure the tuner.
935 // Return the tuner type corresponding with the modulation system.
937 {
938  QString type = GetRawInputType(inputid);
939  if ("DVB" != type)
940  return type;
941 
942  DTVTunerType tunertype;
943  int fd_frontend = OpenVideoDevice(inputid);
944  if (fd_frontend < 0)
945  return "ERROR_OPEN";
946 
947  DTVModulationSystem delsys = GetDeliverySystem(inputid);
949  {
950  delsys = ProbeBestDeliverySystem(fd_frontend);
952  {
953  // Update database
954  set_on_input("inputname", inputid, delsys.toString()); // Update DB capturecard
955  LOG(VB_GENERAL, LOG_INFO,
956  QString("CardUtil[%1]: ").arg(inputid) +
957  QString("Update capturecard delivery system: %1").arg(delsys.toString()));
958  }
959  else
960  {
961  LOG(VB_GENERAL, LOG_ERR,
962  QString("CardUtil[%1]: Error probing best delivery system").arg(inputid));
963  return "ERROR_UNKNOWN";
964  }
965  }
966  SetDeliverySystem(inputid, delsys, fd_frontend);
967  tunertype = ConvertToTunerType(delsys);
968  close(fd_frontend);
969 
970  QString subtype = "ERROR_UNKNOWN";
971  if (DTVTunerType::kTunerTypeUnknown != tunertype)
972  {
973  subtype = tunertype.toString();
974  }
975 
976  LOG(VB_GENERAL, LOG_DEBUG,
977  QString("CardUtil[%1]: subtype:%2").arg(inputid).arg(subtype));
978 
979  return subtype;
980 }
981 
983 bool CardUtil::IsDVBInputType(const QString &inputType)
984 {
985  QString t = inputType.toUpper();
986  return (t == "DVB") || (t == "QPSK") || (t == "QAM") || (t == "OFDM") ||
987  (t == "ATSC") || (t == "DVB_S2") || (t == "DVB_T2");
988 }
989 
990 // Get the current delivery system from the card
991 // Get all supported delivery systems from the card
992 // If the current delivery system is DVB-T and DVB-T2 is supported then select DVB-T2
993 // If the current delivery system is DVB-S and DVB-S2 is supported then select DVB-S2
994 //
996 {
997  DTVModulationSystem delsys;
998 
999 #ifdef USING_DVB
1000  // Get the current delivery system from the card
1001  delsys = ProbeCurrentDeliverySystem(fd);
1002  LOG(VB_GENERAL, LOG_INFO, LOC +
1003  QString("Current delivery system: %1").arg(delsys.toString()));
1004 
1005  // Get all supported delivery systems from the card
1006  QString msg = "Supported delivery systems:";
1007  QStringList delsyslist = ProbeDeliverySystems(fd);
1008  msg.append(delsyslist.join(" "));
1009  LOG(VB_GENERAL, LOG_DEBUG, LOC + msg);
1010 
1011  // If the current delivery system is DVB-T and DVB-T2 is supported then select DVB-T2
1013  {
1015  if (delsyslist.contains(newdelsys.toString()))
1016  {
1017  LOG(VB_GENERAL, LOG_INFO, LOC +
1018  QString("Changing delivery system from %1 to %2")
1019  .arg(delsys.toString(), newdelsys.toString()));
1020  delsys = newdelsys;
1021  }
1022  }
1023 
1024  // If the current delivery system is DVB-S and DVB-S2 is supported then select DVB-S2
1026  {
1028  if (delsyslist.contains(newdelsys.toString()))
1029  {
1030  LOG(VB_GENERAL, LOG_INFO, LOC +
1031  QString("Changing delivery system from %1 to %2")
1032  .arg(delsys.toString(), newdelsys.toString()));
1033  delsys = newdelsys;
1034  }
1035  }
1036 #else
1037  Q_UNUSED(fd);
1038 #endif
1039 
1040  return delsys;
1041 }
1042 
1043 // Get the delivery system from the database
1044 // If not found then get the best delivery system from the card
1045 //
1047 {
1048  DTVModulationSystem delsys;
1049 #ifdef USING_DVB
1050 
1051  // If there is a valid modulation system in the database
1052  // then we return that and do nothing more.
1053  delsys = GetDeliverySystem(inputid);
1055  {
1056  return delsys;
1057  }
1058 
1059  // Nothing in the database, get default and use that
1060  delsys = ProbeBestDeliverySystem(fd);
1061  LOG(VB_GENERAL, LOG_INFO,
1062  QString("CardUtil[%1]: ").arg(inputid) +
1063  QString("No capturecard delivery system in database, using: %1").arg(delsys.toString()));
1064 
1065 #else
1066  Q_UNUSED(inputid);
1067  Q_UNUSED(fd);
1068 #endif
1069 
1070  return delsys;
1071 }
1072 
1073 // Configure the tuner to use the delivery system from database
1074 // If not found then set to the best delivery system from the card
1075 //
1077 {
1078  int ret = -1;
1079 
1080 #ifdef USING_DVB
1081  DTVModulationSystem delsys = GetOrProbeDeliverySystem(inputid, fd);
1083  {
1084  ret = SetDeliverySystem(inputid, delsys, fd);
1085  }
1086 #else
1087  Q_UNUSED(inputid);
1088  Q_UNUSED(fd);
1089 #endif
1090 
1091  return ret;
1092 }
1093 
1094 // Set delivery system from database
1095 //
1097 {
1098  int ret = -1;
1099 
1100 #ifdef USING_DVB
1101  DTVModulationSystem delsys = GetDeliverySystem(inputid);
1103  {
1104  ret = SetDeliverySystem(inputid, delsys);
1105  }
1106 #else
1107  Q_UNUSED(inputid);
1108 #endif // USING_DVB
1109 
1110  return ret;
1111 }
1112 
1114 {
1115  int ret = -1;
1116 
1117 #ifdef USING_DVB
1118  QString device = GetVideoDevice(inputid);
1119 
1120  if (device.isEmpty())
1121  {
1122  LOG(VB_GENERAL, LOG_DEBUG,
1123  QString("CardUtil[%1]: ").arg(inputid) +
1124  QString("inputid:%1 ").arg(inputid) +
1125  QString("delsys:%1").arg(delsys.toString()));
1126  return ret;
1127  }
1128 
1129  int fd_frontend = OpenVideoDevice(device);
1130  if (fd_frontend < 0)
1131  {
1132  LOG(VB_GENERAL, LOG_ERR,
1133  QString("CardUtil[%1]: ").arg(inputid) +
1134  QString("open failed (%1)").arg(device) + ENO);
1135  return ret;
1136  }
1137  ret = SetDeliverySystem(inputid, delsys, fd_frontend);
1138 
1139  close(fd_frontend);
1140 #else
1141  Q_UNUSED(inputid);
1142  Q_UNUSED(delsys);
1143 #endif // USING_DVB
1144 
1145  return ret;
1146 }
1147 
1148 // Get delivery system from the database and write it to the card
1149 int CardUtil::SetDeliverySystem(uint inputid, int fd)
1150 {
1151  int ret = -1;
1152 
1153 #ifdef USING_DVB
1154  DTVModulationSystem delsys = GetDeliverySystem(inputid);
1156  {
1157  ret = SetDeliverySystem(inputid, delsys, fd);
1158  }
1159 #else
1160  Q_UNUSED(inputid);
1161  Q_UNUSED(fd);
1162 #endif // USING_DVB
1163 
1164  return ret;
1165 }
1166 
1167 // Write the delivery system to the card
1169 {
1170  int ret = -1;
1171 
1172 #ifdef USING_DVB
1173  LOG(VB_GENERAL, LOG_INFO,
1174  QString("CardUtil[%1]: ").arg(inputid) +
1175  QString("Set delivery system: %1").arg(delsys.toString()));
1176 
1177  struct dtv_property prop = {};
1178  struct dtv_properties cmd = {};
1179 
1180  prop.cmd = DTV_DELIVERY_SYSTEM;
1181  prop.u.data = delsys;
1182  cmd.num = 1;
1183  cmd.props = &prop;
1184 
1185  ret = ioctl(fd, FE_SET_PROPERTY, &cmd);
1186  if (ret < 0)
1187  {
1188  LOG(VB_GENERAL, LOG_ERR, LOC +
1189  QString("[%1] FE_SET_PROPERTY ioctl failed")
1190  .arg(inputid) + ENO);
1191  return ret;
1192  }
1193 #else
1194  Q_UNUSED(inputid);
1195  Q_UNUSED(delsys);
1196  Q_UNUSED(fd);
1197 #endif // USING_DVB
1198 
1199  return ret;
1200 }
1201 
1203 {
1204  QString device = GetVideoDevice(inputid);
1205  return OpenVideoDevice(device);
1206 }
1207 
1208 int CardUtil::OpenVideoDevice(const QString &device)
1209 {
1210  if (device.isEmpty())
1211  return -1;
1212 
1213  QString dvbdev = CardUtil::GetDeviceName(DVB_DEV_FRONTEND, device);
1214  QByteArray dev = dvbdev.toLatin1();
1215  int fd_frontend = open(dev.constData(), O_RDWR | O_NONBLOCK);
1216  if (fd_frontend < 0)
1217  {
1218  LOG(VB_GENERAL, LOG_ERR, LOC +
1219  QString("Can't open DVB frontend (%1) for %2.")
1220  .arg(dvbdev, device) + ENO);
1221  }
1222  return fd_frontend;
1223 }
1224 
1225 QString get_on_input(const QString &to_get, uint inputid)
1226 {
1227  MSqlQuery query(MSqlQuery::InitCon());
1228  query.prepare(
1229  QString("SELECT %1 ").arg(to_get) +
1230  "FROM capturecard "
1231  "WHERE capturecard.cardid = :INPUTID");
1232  query.bindValue(":INPUTID", inputid);
1233 
1234  if (!query.exec())
1235  MythDB::DBError("CardUtil::get_on_input", query);
1236  else if (query.next())
1237  return query.value(0).toString();
1238 
1239  return QString();
1240 }
1241 
1242 bool set_on_input(const QString &to_set, uint inputid, const QString &value)
1243 {
1244  QString tmp = get_on_input("capturecard.cardid", inputid);
1245  if (tmp.isEmpty())
1246  return false;
1247 
1248  MSqlQuery query(MSqlQuery::InitCon());
1249  query.prepare(
1250  QString("UPDATE capturecard SET %1 = :VALUE ").arg(to_set) +
1251  "WHERE cardid = :INPUTID");
1252  query.bindValue(":INPUTID", inputid);
1253  query.bindValue(":VALUE", value);
1254 
1255  if (query.exec())
1256  return true;
1257 
1258  MythDB::DBError("CardUtil::set_on_input", query);
1259  return false;
1260 }
1261 
1272 std::vector<uint> CardUtil::GetInputIDs(const QString& videodevice,
1273  const QString& rawtype,
1274  const QString& inputname,
1275  QString hostname)
1276 {
1277  std::vector<uint> list;
1278 
1279  if (hostname.isEmpty())
1281 
1282  MSqlQuery query(MSqlQuery::InitCon());
1283  QString qstr =
1284  "SELECT cardid "
1285  "FROM capturecard "
1286  "WHERE hostname = :HOSTNAME ";
1287  if (!videodevice.isEmpty())
1288  qstr += "AND videodevice = :DEVICE ";
1289  if (!inputname.isEmpty())
1290  qstr += "AND inputname = :INPUTNAME ";
1291  if (!rawtype.isEmpty())
1292  qstr += "AND cardtype = :INPUTTYPE ";
1293  qstr += "ORDER BY cardid";
1294 
1295  query.prepare(qstr);
1296 
1297  query.bindValue(":HOSTNAME", hostname);
1298  if (!videodevice.isEmpty())
1299  query.bindValue(":DEVICE", videodevice);
1300  if (!inputname.isEmpty())
1301  query.bindValue(":INPUTNAME", inputname);
1302  if (!rawtype.isEmpty())
1303  query.bindValue(":INPUTTYPE", rawtype.toUpper());
1304 
1305  if (!query.exec())
1306  MythDB::DBError("CardUtil::GetInputIDs(videodevice...)", query);
1307  else
1308  {
1309  while (query.next())
1310  list.push_back(query.value(0).toUInt());
1311  }
1312 
1313  return list;
1314 }
1315 
1317 {
1318  if (!inputid)
1319  return 0;
1320 
1321  MSqlQuery query(MSqlQuery::InitCon());
1322  QString qstr =
1323  "SELECT COUNT(*) "
1324  "FROM capturecard "
1325  "WHERE parentid = :INPUTID";
1326 
1327  query.prepare(qstr);
1328  query.bindValue(":INPUTID", inputid);
1329 
1330  uint count = 0;
1331 
1332  if (!query.exec())
1333  MythDB::DBError("CardUtil::GetChildInputCount()", query);
1334  else if (query.next())
1335  count = query.value(0).toUInt();
1336 
1337  return count;
1338 }
1339 
1340 std::vector<uint> CardUtil::GetChildInputIDs(uint inputid)
1341 {
1342  std::vector<uint> list;
1343 
1344  if (!inputid)
1345  return list;
1346 
1347  MSqlQuery query(MSqlQuery::InitCon());
1348  QString qstr =
1349  "SELECT cardid "
1350  "FROM capturecard "
1351  "WHERE parentid = :INPUTID "
1352  "ORDER BY cardid";
1353 
1354  query.prepare(qstr);
1355  query.bindValue(":INPUTID", inputid);
1356 
1357  if (!query.exec())
1358  MythDB::DBError("CardUtil::GetChildInputIDs()", query);
1359  else
1360  {
1361  while (query.next())
1362  list.push_back(query.value(0).toUInt());
1363  }
1364 
1365  return list;
1366 }
1367 
1368 static uint clone_capturecard(uint src_inputid, uint orig_dst_inputid)
1369 {
1370  uint dst_inputid = orig_dst_inputid;
1371 
1372  MSqlQuery query(MSqlQuery::InitCon());
1373  if (!dst_inputid)
1374  {
1375  query.prepare(
1376  "DELETE FROM capturecard "
1377  "WHERE videodevice = 'temp_dummy'");
1378 
1379  if (!query.exec())
1380  {
1381  MythDB::DBError("clone_capturecard -- delete temp", query);
1382  return 0;
1383  }
1384 
1385  query.prepare(
1386  "INSERT INTO capturecard "
1387  "SET videodevice = 'temp_dummy'");
1388 
1389  if (!query.exec())
1390  {
1391  MythDB::DBError("clone_capturecard -- insert temp", query);
1392  return 0;
1393  }
1394 
1395  query.prepare(
1396  "SELECT cardid "
1397  "FROM capturecard "
1398  "WHERE videodevice = 'temp_dummy'");
1399 
1400  if (!query.exec())
1401  {
1402  MythDB::DBError("clone_capturecard -- get temp id", query);
1403  return 0;
1404  }
1405 
1406  if (!query.next())
1407  {
1408  LOG(VB_GENERAL, LOG_ERR, "clone_capturecard -- get temp id");
1409  return 0;
1410  }
1411 
1412  dst_inputid = query.value(0).toUInt();
1413  }
1414 
1415  query.prepare(
1416  "SELECT videodevice, audiodevice, vbidevice, "
1417  " cardtype, hostname, signal_timeout, "
1418  " channel_timeout, dvb_wait_for_seqstart, dvb_on_demand, "
1419  " dvb_tuning_delay, dvb_diseqc_type, diseqcid, "
1420  " dvb_eitscan, inputname, sourceid, "
1421  " externalcommand, changer_device, changer_model, "
1422  " tunechan, startchan, displayname, "
1423  " dishnet_eit, recpriority, quicktune, "
1424  " livetvorder, reclimit, "
1425  // See below for special handling of the following.
1426  " schedgroup, schedorder "
1427  "FROM capturecard "
1428  "WHERE cardid = :INPUTID");
1429  query.bindValue(":INPUTID", src_inputid);
1430 
1431  if (!query.exec())
1432  {
1433  MythDB::DBError("clone_capturecard -- get data", query);
1434  return 0;
1435  }
1436  if (!query.next())
1437  {
1438  LOG(VB_GENERAL, LOG_ERR, "clone_cardinput -- get data 2");
1439  return 0;
1440  }
1441 
1442  // Handle schedgroup and schedorder specially. If schedgroup is
1443  // set, schedgroup and schedorder should be false and 0,
1444  // respectively, for all children.
1445  bool schedgroup = query.value(26).toBool();
1446  uint schedorder = query.value(27).toUInt();
1447  if (schedgroup)
1448  {
1449  schedgroup = false;
1450  schedorder = 0;
1451  }
1452 
1453  MSqlQuery query2(MSqlQuery::InitCon());
1454  query2.prepare(
1455  "UPDATE capturecard "
1456  "SET videodevice = :V0, "
1457  " audiodevice = :V1, "
1458  " vbidevice = :V2, "
1459  " cardtype = :V3, "
1460  " hostname = :V4, "
1461  " signal_timeout = :V5, "
1462  " channel_timeout = :V6, "
1463  " dvb_wait_for_seqstart = :V7, "
1464  " dvb_on_demand = :V8, "
1465  " dvb_tuning_delay = :V9, "
1466  " dvb_diseqc_type = :V10, "
1467  " diseqcid = :V11,"
1468  " dvb_eitscan = :V12, "
1469  " inputname = :V13, "
1470  " sourceid = :V14, "
1471  " externalcommand = :V15, "
1472  " changer_device = :V16, "
1473  " changer_model = :V17, "
1474  " tunechan = :V18, "
1475  " startchan = :V19, "
1476  " displayname = :V20, "
1477  " dishnet_eit = :V21, "
1478  " recpriority = :V22, "
1479  " quicktune = :V23, "
1480  " livetvorder = :V24, "
1481  " reclimit = :V25, "
1482  " schedgroup = :SCHEDGROUP, "
1483  " schedorder = :SCHEDORDER, "
1484  " parentid = :PARENTID "
1485  "WHERE cardid = :INPUTID");
1486  for (uint i = 0; i < 26; ++i)
1487  query2.bindValue(QString(":V%1").arg(i), query.value(i).toString());
1488  query2.bindValue(":INPUTID", dst_inputid);
1489  query2.bindValue(":PARENTID", src_inputid);
1490  query2.bindValue(":SCHEDGROUP", schedgroup);
1491  query2.bindValue(":SCHEDORDER", schedorder);
1492 
1493  if (!query2.exec())
1494  {
1495  MythDB::DBError("clone_capturecard -- save data", query2);
1496  if (!orig_dst_inputid)
1497  CardUtil::DeleteInput(dst_inputid);
1498  return 0;
1499  }
1500 
1501  // copy input group linkages
1502  std::vector<uint> src_grps = CardUtil::GetInputGroups(src_inputid);
1503  std::vector<uint> dst_grps = CardUtil::GetInputGroups(dst_inputid);
1504  for (uint dst_grp : dst_grps)
1505  CardUtil::UnlinkInputGroup(dst_inputid, dst_grp);
1506  for (uint src_grp : src_grps)
1507  CardUtil::LinkInputGroup(dst_inputid, src_grp);
1508 
1509  // clone diseqc_config (just points to the same diseqc_tree row)
1510  DiSEqCDevSettings diseqc;
1511  if (diseqc.Load(src_inputid))
1512  diseqc.Store(dst_inputid);
1513 
1514  return dst_inputid;
1515 }
1516 
1517 uint CardUtil::CloneCard(uint src_inputid, uint orig_dst_inputid)
1518 {
1519  QString type = CardUtil::GetRawInputType(src_inputid);
1521  return 0;
1522 
1523  uint dst_inputid = clone_capturecard(src_inputid, orig_dst_inputid);
1524  return dst_inputid;
1525 }
1526 
1528 {
1529  uint inputid = CloneCard(parentid, 0);
1530 
1531  // Update the reclimit for the parent and all children so the new
1532  // child doesn't get removed the next time mythtv-setup is run.
1533  if (inputid)
1534  {
1535  LOG(VB_GENERAL, LOG_INFO, LOC +
1536  QString("Added child input %1 to parent %2")
1537  .arg(inputid).arg(parentid));
1538  MSqlQuery query(MSqlQuery::InitCon());
1539  query.prepare("UPDATE capturecard "
1540  "SET reclimit = reclimit + 1 "
1541  "WHERE cardid = :PARENTID");
1542  query.bindValue(":PARENTID", parentid);
1543  if (!query.exec())
1544  MythDB::DBError("CardUtil::AddChildInput", query);
1545  }
1546  else
1547  {
1548  LOG(VB_GENERAL, LOG_ERR, LOC +
1549  QString("Failed to add child input to parent %1").arg(parentid));
1550  }
1551 
1552  return inputid;
1553 }
1554 
1556 {
1557  QString fwnode;
1558 
1559  MSqlQuery query(MSqlQuery::InitCon());
1560  query.prepare("SELECT changer_device "
1561  "FROM capturecard WHERE cardid = :INPUTID ");
1562  query.bindValue(":INPUTID", inputid);
1563 
1564  if (query.exec() && query.next())
1565  {
1566  fwnode = query.value(0).toString();
1567  }
1568 
1569  return fwnode;
1570 }
1571 
1573 {
1574  QString fwnode;
1575 
1576  MSqlQuery query(MSqlQuery::InitCon());
1577  query.prepare("SELECT changer_model "
1578  "FROM capturecard WHERE cardid = :INPUTID ");
1579  query.bindValue(":INPUTID", inputid);
1580 
1581  if (query.exec() && query.next())
1582  {
1583  fwnode = query.value(0).toString();
1584  }
1585 
1586  return fwnode;
1587 }
1588 
1589 std::vector<uint> CardUtil::GetInputIDs(uint sourceid)
1590 {
1591  MSqlQuery query(MSqlQuery::InitCon());
1592 
1593  query.prepare(
1594  "SELECT DISTINCT cardid "
1595  "FROM capturecard "
1596  "WHERE sourceid = :SOURCEID");
1597  query.bindValue(":SOURCEID", sourceid);
1598 
1599  std::vector<uint> list;
1600 
1601  if (!query.exec())
1602  {
1603  MythDB::DBError("CardUtil::GetInputIDs(sourceid)", query);
1604  return list;
1605  }
1606 
1607  while (query.next())
1608  list.push_back(query.value(0).toUInt());
1609 
1610  return list;
1611 }
1612 
1613 bool CardUtil::SetStartChannel(uint inputid, const QString &channum)
1614 {
1615  MSqlQuery query(MSqlQuery::InitCon());
1616  query.prepare("UPDATE capturecard "
1617  "SET startchan = :CHANNUM "
1618  "WHERE cardid = :INPUTID");
1619  query.bindValue(":CHANNUM", channum);
1620  query.bindValue(":INPUTID", inputid);
1621 
1622  if (!query.exec())
1623  {
1624  MythDB::DBError("CardUtil::SetStartChannel", query);
1625  return false;
1626  }
1627 
1628  return true;
1629 }
1630 
1631 bool CardUtil::GetInputInfo(InputInfo &input, std::vector<uint> *groupids)
1632 {
1633  if (!input.m_inputId)
1634  return false;
1635 
1636  MSqlQuery query(MSqlQuery::InitCon());
1637  query.prepare("SELECT "
1638  "inputname, sourceid, livetvorder, "
1639  "schedorder, displayname, recpriority, quicktune "
1640  "FROM capturecard "
1641  "WHERE cardid = :INPUTID");
1642  query.bindValue(":INPUTID", input.m_inputId);
1643 
1644  if (!query.exec())
1645  {
1646  MythDB::DBError("CardUtil::GetInputInfo()", query);
1647  return false;
1648  }
1649 
1650  if (!query.next())
1651  return false;
1652 
1653  input.m_name = query.value(0).toString();
1654  input.m_sourceId = query.value(1).toUInt();
1655  input.m_liveTvOrder = query.value(2).toUInt();
1656  input.m_scheduleOrder = query.value(3).toUInt();
1657  input.m_displayName = query.value(4).toString();
1658  input.m_recPriority = query.value(5).toInt();
1659  input.m_quickTune = query.value(6).toBool();
1660 
1661  if (groupids)
1662  *groupids = GetInputGroups(input.m_inputId);
1663 
1664  return true;
1665 }
1666 
1667 QList<InputInfo> CardUtil::GetAllInputInfo()
1668 {
1669  QList<InputInfo> infoInputList;
1670 
1671  MSqlQuery query(MSqlQuery::InitCon());
1672  query.prepare("SELECT cardid, "
1673  "inputname, sourceid, livetvorder, "
1674  "schedorder, displayname, recpriority, quicktune "
1675  "FROM capturecard");
1676 
1677  if (!query.exec())
1678  {
1679  MythDB::DBError("CardUtil::GetAllInputInfo()", query);
1680  return infoInputList;
1681  }
1682 
1683  while (query.next())
1684  {
1685  InputInfo input;
1686  input.m_inputId = query.value(0).toUInt();
1687  input.m_name = query.value(1).toString();
1688  input.m_sourceId = query.value(2).toUInt();
1689  input.m_liveTvOrder = query.value(3).toUInt();
1690  input.m_scheduleOrder = query.value(4).toUInt();
1691  input.m_displayName = query.value(5).toString();
1692  input.m_recPriority = query.value(6).toInt();
1693  input.m_quickTune = query.value(7).toBool();
1694 
1695  infoInputList.push_back(input);
1696  }
1697 
1698  return infoInputList;
1699 }
1700 
1702 {
1703  InputInfo info("None", 0, inputid, 0, 0, 0);
1704  GetInputInfo(info);
1705  return info.m_name;
1706 }
1707 
1709 {
1710  MSqlQuery query(MSqlQuery::InitCon());
1711  query.prepare("SELECT startchan "
1712  "FROM capturecard "
1713  "WHERE cardid = :INPUTID");
1714  query.bindValue(":INPUTID", inputid);
1715 
1716  if (!query.exec())
1717  MythDB::DBError("CardUtil::GetStartingChannel(uint)", query);
1718  else if (query.next())
1719  return query.value(0).toString();
1720 
1721  return QString();
1722 }
1723 
1725 {
1726  if (!inputid)
1727  return QString();
1728 
1729  MSqlQuery query(MSqlQuery::InitCon());
1730  query.prepare("SELECT displayname "
1731  "FROM capturecard "
1732  "WHERE cardid = :INPUTID");
1733  query.bindValue(":INPUTID", inputid);
1734 
1735  if (!query.exec())
1736  MythDB::DBError("CardUtil::GetDisplayName(uint)", query);
1737  else if (query.next())
1738  {
1739  QString result = query.value(0).toString();
1740  return result;
1741  }
1742 
1743  return QString();
1744 }
1745 
1746 bool CardUtil::IsUniqueDisplayName(const QString &name, uint exclude_inputid)
1747 {
1748  if (name.isEmpty())
1749  return false;
1750 
1751  MSqlQuery query(MSqlQuery::InitCon());
1752  query.prepare("SELECT cardid "
1753  "FROM capturecard "
1754  "WHERE parentid = 0 "
1755  " AND cardid <> :INPUTID "
1756  " AND right(displayname, 2) = :NAME");
1757  query.bindValue(":NAME", name.right(2));
1758  query.bindValue(":INPUTID", exclude_inputid);
1759 
1760  if (!query.exec())
1761  {
1762  MythDB::DBError("CardUtil::IsUniqueDisplayName()", query);
1763  return false;
1764  }
1765 
1766  // Any result means it's not unique.
1767  return !query.next();
1768 }
1769 
1771 {
1772  MSqlQuery query(MSqlQuery::InitCon());
1773  query.prepare(
1774  "SELECT sourceid "
1775  "FROM capturecard "
1776  "WHERE cardid = :INPUTID");
1777  query.bindValue(":INPUTID", inputid);
1778  if (!query.exec() || !query.isActive())
1779  MythDB::DBError("CardUtil::GetSourceID()", query);
1780  else if (query.next())
1781  return query.value(0).toUInt();
1782 
1783  return 0;
1784 }
1785 
1786 // Is this intentionally leaving out the hostname when updating the
1787 // capturecard table? The hostname value does get set when inserting
1788 // into the capturecard table. (Code written in 2011.)
1790  const uint sourceid,
1791  const QString &inputname,
1792  const QString &externalcommand,
1793  const QString &changer_device,
1794  const QString &changer_model,
1795  const QString &/*hostname*/,
1796  const QString &tunechan,
1797  const QString &startchan,
1798  const QString &displayname,
1799  bool dishnet_eit,
1800  const uint recpriority,
1801  const uint quicktune,
1802  const uint schedorder,
1803  const uint livetvorder)
1804 {
1805  MSqlQuery query(MSqlQuery::InitCon());
1806 
1807  query.prepare(
1808  "UPDATE capturecard "
1809  "SET sourceid = :SOURCEID, "
1810  " inputname = :INPUTNAME, "
1811  " externalcommand = :EXTERNALCOMMAND, "
1812  " changer_device = :CHANGERDEVICE, "
1813  " changer_model = :CHANGERMODEL, "
1814  " tunechan = :TUNECHAN, "
1815  " startchan = :STARTCHAN, "
1816  " displayname = :DISPLAYNAME, "
1817  " dishnet_eit = :DISHNETEIT, "
1818  " recpriority = :RECPRIORITY, "
1819  " quicktune = :QUICKTUNE, "
1820  " schedorder = :SCHEDORDER, "
1821  " livetvorder = :LIVETVORDER "
1822  "WHERE cardid = :INPUTID AND "
1823  " inputname = 'None'");
1824 
1825  query.bindValue(":INPUTID", inputid);
1826  query.bindValue(":SOURCEID", sourceid);
1827  query.bindValue(":INPUTNAME", inputname);
1828  query.bindValue(":EXTERNALCOMMAND", externalcommand);
1829  query.bindValue(":CHANGERDEVICE", changer_device);
1830  query.bindValue(":CHANGERMODEL", changer_model);
1831  query.bindValue(":TUNECHAN", tunechan);
1832  query.bindValue(":STARTCHAN", startchan);
1833  query.bindValue(":DISPLAYNAME", displayname.isNull() ? "" : displayname);
1834  query.bindValue(":DISHNETEIT", dishnet_eit);
1835  query.bindValue(":RECPRIORITY", recpriority);
1836  query.bindValue(":QUICKTUNE", quicktune);
1837  query.bindValue(":SCHEDORDER", schedorder);
1838  query.bindValue(":LIVETVORDER", livetvorder);
1839 
1840  if (!query.exec())
1841  {
1842  MythDB::DBError("CardUtil::CreateCardInput()", query);
1843  return -1;
1844  }
1845 
1846  return inputid;
1847 }
1848 
1849 uint CardUtil::CreateInputGroup(const QString &name)
1850 {
1851  MSqlQuery query(MSqlQuery::InitCon());
1852 
1853  query.prepare("SELECT inputgroupid FROM inputgroup "
1854  "WHERE inputgroupname = :GROUPNAME "
1855  "LIMIT 1");
1856  query.bindValue(":GROUPNAME", name);
1857  if (!query.exec())
1858  {
1859  MythDB::DBError("CardUtil::CreateNewInputGroup 0", query);
1860  return 0;
1861  }
1862 
1863  if (query.next())
1864  return query.value(0).toUInt();
1865 
1866  query.prepare("SELECT MAX(inputgroupid) FROM inputgroup");
1867  if (!query.exec())
1868  {
1869  MythDB::DBError("CardUtil::CreateNewInputGroup 1", query);
1870  return 0;
1871  }
1872 
1873  uint inputgroupid = (query.next()) ? query.value(0).toUInt() + 1 : 1;
1874 
1875  query.prepare(
1876  "INSERT INTO inputgroup "
1877  " (cardinputid, inputgroupid, inputgroupname) "
1878  "VALUES (:INPUTID, :GROUPID, :GROUPNAME ) ");
1879  query.bindValue(":INPUTID", 0);
1880  query.bindValue(":GROUPID", inputgroupid);
1881  query.bindValue(":GROUPNAME", name);
1882  if (!query.exec())
1883  {
1884  MythDB::DBError("CardUtil::CreateNewInputGroup 2", query);
1885  return 0;
1886  }
1887 
1888  return inputgroupid;
1889 }
1890 
1892  const QString &type,
1893  const QString &host,
1894  const QString &device)
1895 {
1896  QString name = host + '|' + device;
1897  if (type == "FREEBOX" || type == "IMPORT" ||
1898  type == "DEMO" || type == "EXTERNAL" ||
1899  type == "HDHOMERUN" || type == "SATIP")
1900  name += QString("|%1").arg(inputid);
1901  return CreateInputGroup(name);
1902 }
1903 
1905 {
1906  MSqlQuery query(MSqlQuery::InitCon());
1907  query.prepare(
1908  "SELECT inputgroupid "
1909  "FROM inputgroup "
1910  "WHERE cardinputid = :INPUTID "
1911  " AND inputgroupname REGEXP '^[a-z_-]*\\\\|'");
1912  query.bindValue(":INPUTID", inputid);
1913 
1914  if (!query.exec())
1915  {
1916  MythDB::DBError("CardUtil::GetDeviceInputGroup()", query);
1917  return 0;
1918  }
1919 
1920  if (query.next())
1921  {
1922  return query.value(0).toUInt();
1923  }
1924 
1925  return 0;
1926 }
1927 
1928 bool CardUtil::LinkInputGroup(uint inputid, uint inputgroupid)
1929 {
1930  MSqlQuery query(MSqlQuery::InitCon());
1931 
1932  query.prepare(
1933  "SELECT cardinputid, inputgroupid, inputgroupname "
1934  "FROM inputgroup "
1935  "WHERE inputgroupid = :GROUPID "
1936  "ORDER BY inputgroupid, cardinputid, inputgroupname");
1937  query.bindValue(":GROUPID", inputgroupid);
1938 
1939  if (!query.exec())
1940  {
1941  MythDB::DBError("CardUtil::CreateInputGroup() 1", query);
1942  return false;
1943  }
1944 
1945  if (!query.next())
1946  return false;
1947 
1948  const QString name = query.value(2).toString();
1949 
1950  query.prepare(
1951  "INSERT INTO inputgroup "
1952  " (cardinputid, inputgroupid, inputgroupname) "
1953  "VALUES (:INPUTID, :GROUPID, :GROUPNAME ) ");
1954 
1955  query.bindValue(":INPUTID", inputid);
1956  query.bindValue(":GROUPID", inputgroupid);
1957  query.bindValue(":GROUPNAME", name);
1958 
1959  if (!query.exec())
1960  {
1961  MythDB::DBError("CardUtil::CreateInputGroup() 2", query);
1962  return false;
1963  }
1964 
1965  return true;
1966 }
1967 
1968 bool CardUtil::UnlinkInputGroup(uint inputid, uint inputgroupid)
1969 {
1970  MSqlQuery query(MSqlQuery::InitCon());
1971 
1972  if (!inputid && !inputgroupid)
1973  {
1974  query.prepare(
1975  "DELETE FROM inputgroup "
1976  "WHERE cardinputid NOT IN "
1977  "( SELECT cardid FROM capturecard )");
1978  }
1979  else
1980  {
1981  query.prepare(
1982  "DELETE FROM inputgroup "
1983  "WHERE cardinputid = :INPUTID AND "
1984  " inputgroupid = :GROUPID ");
1985 
1986  query.bindValue(":INPUTID", inputid);
1987  query.bindValue(":GROUPID", inputgroupid);
1988  }
1989 
1990  if (!query.exec())
1991  {
1992  MythDB::DBError("CardUtil::DeleteInputGroup()", query);
1993  return false;
1994  }
1995 
1996  return true;
1997 }
1998 
1999 std::vector<uint> CardUtil::GetInputGroups(uint inputid)
2000 {
2001  std::vector<uint> list;
2002 
2003  MSqlQuery query(MSqlQuery::InitCon());
2004 
2005  query.prepare(
2006  "SELECT inputgroupid "
2007  "FROM inputgroup "
2008  "WHERE cardinputid = :INPUTID "
2009  "ORDER BY inputgroupid, cardinputid, inputgroupname");
2010 
2011  query.bindValue(":INPUTID", inputid);
2012 
2013  if (!query.exec())
2014  {
2015  MythDB::DBError("CardUtil::GetInputGroups()", query);
2016  return list;
2017  }
2018 
2019  while (query.next())
2020  list.push_back(query.value(0).toUInt());
2021 
2022  return list;
2023 }
2024 
2025 std::vector<uint> CardUtil::GetGroupInputIDs(uint inputgroupid)
2026 {
2027  std::vector<uint> list;
2028 
2029  MSqlQuery query(MSqlQuery::InitCon());
2030 
2031  query.prepare(
2032  "SELECT DISTINCT cardid "
2033  "FROM capturecard, inputgroup "
2034  "WHERE inputgroupid = :GROUPID AND "
2035  " capturecard.cardid = inputgroup.cardinputid "
2036  "ORDER BY cardid");
2037 
2038  query.bindValue(":GROUPID", inputgroupid);
2039 
2040  if (!query.exec())
2041  {
2042  MythDB::DBError("CardUtil::GetGroupInputIDs()", query);
2043  return list;
2044  }
2045 
2046  while (query.next())
2047  list.push_back(query.value(0).toUInt());
2048 
2049  return list;
2050 }
2051 
2052 std::vector<uint> CardUtil::GetConflictingInputs(uint inputid)
2053 {
2054  std::vector<uint> inputids;
2055 
2056  MSqlQuery query(MSqlQuery::InitCon());
2057 
2058  query.prepare(
2059  "SELECT DISTINCT c.cardid "
2060  "FROM ( "
2061  " SELECT inputgroupid "
2062  " FROM inputgroup "
2063  " WHERE cardinputid = :INPUTID1 "
2064  ") g "
2065  "JOIN inputgroup ig ON ig.inputgroupid = g.inputgroupid "
2066  "JOIN capturecard c ON c.cardid = ig.cardinputid "
2067  " AND c.cardid <> :INPUTID2 "
2068  "ORDER BY c.cardid");
2069 
2070  query.bindValue(":INPUTID1", inputid);
2071  query.bindValue(":INPUTID2", inputid);
2072 
2073  if (!query.exec())
2074  {
2075  MythDB::DBError("CardUtil::GetConflictingInputs()", query);
2076  return inputids;
2077  }
2078 
2079  while (query.next())
2080  {
2081  inputids.push_back(query.value(0).toUInt());
2082  }
2083 
2084  if (VERBOSE_LEVEL_CHECK(VB_RECORD, LOG_INFO))
2085  {
2086  QString msg = QString("CardUtil[%1]: GetConflictingInputs(%1) ").arg(inputid);
2087  QStringList ids;
2088  for (auto id : inputids)
2089  {
2090  ids.append(QString::number(id));
2091  }
2092  msg.append(ids.join(','));
2093  LOG(VB_RECORD, LOG_INFO, msg);
2094  }
2095  return inputids;
2096 }
2097 
2099  std::chrono::milliseconds &signal_timeout,
2100  std::chrono::milliseconds &channel_timeout)
2101 {
2102  MSqlQuery query(MSqlQuery::InitCon());
2103  query.prepare(
2104  "SELECT signal_timeout, channel_timeout "
2105  "FROM capturecard "
2106  "WHERE cardid = :INPUTID");
2107  query.bindValue(":INPUTID", inputid);
2108 
2109  if (!query.exec() || !query.isActive())
2110  MythDB::DBError("CardUtil::GetTimeouts()", query);
2111  else if (query.next())
2112  {
2113  signal_timeout = std::max(std::chrono::milliseconds(query.value(0).toInt()), 250ms);
2114  channel_timeout = std::max(std::chrono::milliseconds(query.value(1).toInt()), 500ms);
2115  return true;
2116  }
2117 
2118  return false;
2119 }
2120 
2122 {
2123  DiSEqCDevTree *diseqc_tree = DiSEqCDev::FindTree(inputid);
2124 
2125  bool needsConf = false;
2126  if (diseqc_tree)
2127  needsConf = diseqc_tree->IsInNeedOfConf();
2128 
2129  return needsConf;
2130 }
2131 
2132 uint CardUtil::GetQuickTuning(uint inputid, const QString &input_name)
2133 {
2134  uint quicktune = 0;
2135 
2136  MSqlQuery query(MSqlQuery::InitCon());
2137  query.prepare(
2138  "SELECT quicktune "
2139  "FROM capturecard "
2140  "WHERE cardid = :INPUTID AND "
2141  " inputname = :INPUTNAME");
2142  query.bindValue(":INPUTID", inputid);
2143  query.bindValue(":INPUTNAME", input_name);
2144 
2145  if (!query.exec() || !query.isActive())
2146  MythDB::DBError("CardUtil::GetQuickTuning()", query);
2147  else if (query.next())
2148  quicktune = query.value(0).toUInt();
2149 
2150  return quicktune;
2151 }
2152 
2153 bool CardUtil::hasV4L2(int videofd)
2154 {
2155  (void) videofd;
2156 #ifdef USING_V4L2
2157  struct v4l2_capability vcap {};
2158 
2159  return ((ioctl(videofd, VIDIOC_QUERYCAP, &vcap) >= 0) &&
2160  ((vcap.capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0U));
2161 #else // if !USING_V4L2
2162  return false;
2163 #endif // !USING_V4L2
2164 }
2165 
2167  int videofd, QString &input, QString &driver, uint32_t &version,
2168  uint32_t &capabilities)
2169 {
2170  input.clear();
2171  driver.clear();
2172  version = 0;
2173  capabilities = 0;
2174 
2175  if (videofd < 0)
2176  return false;
2177 
2178 #ifdef USING_V4L2
2179  // First try V4L2 query
2180  struct v4l2_capability capability {};
2181  if (ioctl(videofd, VIDIOC_QUERYCAP, &capability) >= 0)
2182  {
2183  input = QString::fromLatin1((const char*)capability.card);
2184  driver = QString::fromLatin1((const char*)capability.driver);
2185  version = capability.version;
2186  capabilities = capability.capabilities;
2187  }
2188 #ifdef USING_V4L1
2189  else // Fallback to V4L1 query
2190  {
2191  struct video_capability capability2;
2192  if (ioctl(videofd, VIDIOCGCAP, &capability2) >= 0)
2193  input = QString::fromLatin1((const char*)capability2.name);
2194  }
2195 #endif // USING_V4L1
2196 #endif // USING_V4L2
2197 
2198  if (!driver.isEmpty())
2199  driver.remove( QRegularExpression(R"(\[[0-9]\]$)") );
2200 
2201  return !input.isEmpty();
2202 }
2203 
2205 {
2206  (void) videofd;
2207 
2208  InputNames list;
2209  ok = false;
2210 
2211 #ifdef USING_V4L2
2212  bool usingv4l2 = hasV4L2(videofd);
2213 
2214  // V4L v2 query
2215  struct v4l2_input vin {};
2216  while (usingv4l2 && (ioctl(videofd, VIDIOC_ENUMINPUT, &vin) >= 0))
2217  {
2218  QString input((char *)vin.name);
2219  list[vin.index] = input;
2220  vin.index++;
2221  }
2222  if (vin.index)
2223  {
2224  ok = true;
2225  return list;
2226  }
2227 
2228 #ifdef USING_V4L1
2229  // V4L v1 query
2230  struct video_capability vidcap;
2231  memset(&vidcap, 0, sizeof(vidcap));
2232  if (ioctl(videofd, VIDIOCGCAP, &vidcap) != 0)
2233  {
2234  QString msg = QObject::tr("Could not query inputs.");
2235  LOG(VB_GENERAL, LOG_ERR, "ProbeV4LVideoInputs(): Error, " + msg + ENO);
2236  list[-1] = msg;
2237  vidcap.channels = 0;
2238  }
2239 
2240  for (int i = 0; i < vidcap.channels; i++)
2241  {
2242  struct video_channel test;
2243  memset(&test, 0, sizeof(test));
2244  test.channel = i;
2245 
2246  if (ioctl(videofd, VIDIOCGCHAN, &test) != 0)
2247  {
2248  LOG(VB_GENERAL, LOG_ERR, "ProbeV4LVideoInputs(): Error, " +
2249  QString("Could determine name of input #%1"
2250  "\n\t\t\tNot adding it to the list.")
2251  .arg(test.channel) + ENO);
2252  continue;
2253  }
2254 
2255  list[i] = test.name;
2256  }
2257 #endif // USING_V4L1
2258 
2259  // Create an input when none are advertised
2260  if (list.isEmpty())
2261  list[0] = "Television";
2262 
2263  ok = true;
2264 #else // if !USING_V4L2
2265  list[-1] += QObject::tr("ERROR, Compile with V4L support to query inputs");
2266 #endif // !USING_V4L2
2267  return list;
2268 }
2269 
2271 {
2272  (void) videofd;
2273 
2274  InputNames list;
2275  ok = false;
2276 
2277 #ifdef USING_V4L2
2278  bool usingv4l2 = hasV4L2(videofd);
2279 
2280  // V4L v2 query
2281  struct v4l2_audio ain {};
2282  while (usingv4l2 && (ioctl(videofd, VIDIOC_ENUMAUDIO, &ain) >= 0))
2283  {
2284  QString input((char *)ain.name);
2285  list[ain.index] = input;
2286  ain.index++;
2287  }
2288  if (ain.index)
2289  {
2290  ok = true;
2291  return list;
2292  }
2293 
2294  ok = true;
2295 #else // if !USING_V4L2
2296  list[-1] += QObject::tr(
2297  "ERROR, Compile with V4L support to query audio inputs");
2298 #endif // !USING_V4L2
2299  return list;
2300 }
2301 
2303 {
2304  InputNames list;
2305  MSqlQuery query(MSqlQuery::InitCon());
2306  query.prepare(
2307  "SELECT cardid, inputname "
2308  "FROM capturecard "
2309  "WHERE hostname = :HOSTNAME "
2310  " AND videodevice = :DEVICE "
2311  " AND parentid = 0 "
2312  " AND inputname <> 'None'");
2313  query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
2314  query.bindValue(":DEVICE", device);
2315 
2316  if (!query.exec() || !query.isActive())
2317  MythDB::DBError("CardUtil::GetConfiguredDVBInputs", query);
2318  else
2319  {
2320  while (query.next())
2321  list[query.value(0).toUInt()] = query.value(1).toString();
2322  }
2323  return list;
2324 }
2325 
2326 // Convert DVBv5 frontend capabilities from bitmask to string
2327 //
2328 // Source linuxtv.org v4l-utils/lib/libdvbv5/dvb-v5.c
2329 //
2330 QStringList CardUtil::CapabilitiesToString(uint64_t capabilities)
2331 {
2332  QStringList caps;
2333 #ifdef USING_DVB
2334 
2335  struct fe_caps_name {
2336  unsigned idx;
2337  const char *name;
2338  };
2339 
2340  std::array<fe_caps_name,31> fe_caps_name {{
2341  { FE_CAN_2G_MODULATION, "CAN_2G_MODULATION" },
2342  { FE_CAN_8VSB, "CAN_8VSB" },
2343  { FE_CAN_16VSB, "CAN_16VSB" },
2344  { FE_CAN_BANDWIDTH_AUTO, "CAN_BANDWIDTH_AUTO" },
2345  { FE_CAN_FEC_1_2, "CAN_FEC_1_2" },
2346  { FE_CAN_FEC_2_3, "CAN_FEC_2_3" },
2347  { FE_CAN_FEC_3_4, "CAN_FEC_3_4" },
2348  { FE_CAN_FEC_4_5, "CAN_FEC_4_5" },
2349  { FE_CAN_FEC_5_6, "CAN_FEC_5_6" },
2350  { FE_CAN_FEC_6_7, "CAN_FEC_6_7" },
2351  { FE_CAN_FEC_7_8, "CAN_FEC_7_8" },
2352  { FE_CAN_FEC_8_9, "CAN_FEC_8_9" },
2353  { FE_CAN_FEC_AUTO, "CAN_FEC_AUTO" },
2354  { FE_CAN_GUARD_INTERVAL_AUTO, "CAN_GUARD_INTERVAL_AUTO" },
2355  { FE_CAN_HIERARCHY_AUTO, "CAN_HIERARCHY_AUTO" },
2356  { FE_CAN_INVERSION_AUTO, "CAN_INVERSION_AUTO" },
2357  { FE_CAN_MULTISTREAM, "CAN_MULTISTREAM" },
2358  { FE_CAN_MUTE_TS, "CAN_MUTE_TS" },
2359  { FE_CAN_QAM_16, "CAN_QAM_16" },
2360  { FE_CAN_QAM_32, "CAN_QAM_32" },
2361  { FE_CAN_QAM_64, "CAN_QAM_64" },
2362  { FE_CAN_QAM_128, "CAN_QAM_128" },
2363  { FE_CAN_QAM_256, "CAN_QAM_256" },
2364  { FE_CAN_QAM_AUTO, "CAN_QAM_AUTO" },
2365  { FE_CAN_QPSK, "CAN_QPSK" },
2366  { FE_CAN_RECOVER, "CAN_RECOVER" },
2367  { FE_CAN_TRANSMISSION_MODE_AUTO, "CAN_TRANSMISSION_MODE_AUTO" },
2368  { FE_CAN_TURBO_FEC, "CAN_TURBO_FEC" },
2369  { FE_HAS_EXTENDED_CAPS, "HAS_EXTENDED_CAPS" },
2370  { FE_IS_STUPID, "IS_STUPID" },
2371  { FE_NEEDS_BENDING, "NEEDS_BENDING" },
2372  }};
2373 
2374  for (const auto & cap : fe_caps_name)
2375  {
2376  if (capabilities & cap.idx)
2377  caps.append(cap.name);
2378  }
2379 #else
2380  Q_UNUSED(capabilities);
2381 #endif // USING_DVB
2382  return caps;
2383 }
2384 
2385 QStringList CardUtil::ProbeVideoInputs(const QString& device, const QString& inputtype)
2386 {
2387  QStringList ret;
2388 
2389  if (IsSingleInputType(inputtype))
2390  ret += "MPEG2TS";
2391  else if ("DVB" == inputtype)
2392  ret += ProbeDVBInputs(device);
2393  else
2394  ret += ProbeV4LVideoInputs(device);
2395 
2396  return ret;
2397 }
2398 
2399 QStringList CardUtil::ProbeAudioInputs(const QString& device, const QString& inputtype)
2400 {
2401  LOG(VB_GENERAL, LOG_DEBUG, QString("ProbeAudioInputs(%1,%2)")
2402  .arg(device, inputtype));
2403  QStringList ret;
2404 
2405  if ("HDPVR" == inputtype ||
2406  "V4L2" == inputtype)
2407  ret += ProbeV4LAudioInputs(device);
2408 
2409  return ret;
2410 }
2411 
2412 QStringList CardUtil::ProbeV4LVideoInputs(const QString& device)
2413 {
2414  bool ok = false;
2415  QStringList ret;
2416  QByteArray dev = device.toLatin1();
2417  int videofd = open(dev.constData(), O_RDWR);
2418  if (videofd < 0)
2419  {
2420  ret += QObject::tr("Could not open '%1' "
2421  "to probe its inputs.").arg(device);
2422  return ret;
2423  }
2424  InputNames list = CardUtil::ProbeV4LVideoInputs(videofd, ok);
2425  close(videofd);
2426 
2427  if (!ok)
2428  {
2429  ret += list[-1];
2430  return ret;
2431  }
2432 
2433  InputNames::iterator it;
2434  for (it = list.begin(); it != list.end(); ++it)
2435  {
2436  if (it.key() >= 0)
2437  ret += *it;
2438  }
2439 
2440  return ret;
2441 }
2442 
2443 QStringList CardUtil::ProbeV4LAudioInputs(const QString& device)
2444 {
2445  LOG(VB_GENERAL, LOG_DEBUG, QString("ProbeV4LAudioInputs(%1)").arg(device));
2446 
2447  bool ok = false;
2448  QStringList ret;
2449  int videofd = open(device.toLatin1().constData(), O_RDWR);
2450  if (videofd < 0)
2451  {
2452  LOG(VB_GENERAL, LOG_ERR, "ProbeAudioInputs() -> couldn't open device");
2453  ret += QObject::tr("Could not open '%1' to probe its inputs.")
2454  .arg(device);
2455  return ret;
2456  }
2457  InputNames list = CardUtil::ProbeV4LAudioInputs(videofd, ok);
2458  close(videofd);
2459 
2460  if (!ok)
2461  {
2462  ret += list[-1];
2463  return ret;
2464  }
2465 
2466  InputNames::iterator it;
2467  for (it = list.begin(); it != list.end(); ++it)
2468  {
2469  if (it.key() >= 0)
2470  ret += *it;
2471  }
2472 
2473  return ret;
2474 }
2475 
2476 QStringList CardUtil::ProbeDVBInputs(const QString& device)
2477 {
2478  QStringList ret;
2479 
2480 #ifdef USING_DVB
2481  InputNames list = GetConfiguredDVBInputs(device);
2482  InputNames::iterator it;
2483  for (it = list.begin(); it != list.end(); ++it)
2484  {
2485  if (it.key())
2486  ret += *it;
2487  }
2488 #else
2489  (void) device;
2490  ret += QObject::tr("ERROR, Compile with DVB support to query inputs");
2491 #endif
2492 
2493  return ret;
2494 }
2495 
2496 QString CardUtil::GetDeviceLabel(const QString &inputtype,
2497  const QString &videodevice)
2498 {
2499  return QString("[ %1 : %2 ]").arg(inputtype, videodevice);
2500 }
2501 
2503 {
2504  MSqlQuery query(MSqlQuery::InitCon());
2505  query.prepare("SELECT cardtype, videodevice "
2506  "FROM capturecard WHERE cardid = :INPUTID ");
2507  query.bindValue(":INPUTID", inputid);
2508 
2509  if (query.exec() && query.next())
2510  {
2511  return GetDeviceLabel(query.value(0).toString(),
2512  query.value(1).toString());
2513  }
2514 
2515  return "[ UNKNOWN ]";
2516 }
2517 
2519  const QString &device,
2520  const QString &inputtype,
2521  QStringList &inputs)
2522 {
2523  inputs.clear();
2524  if (IsSingleInputType(inputtype))
2525  inputs += "MPEG2TS";
2526  else if (inputtype == "DVB")
2527  inputs += "DVBInput";
2528  else
2529  inputs += ProbeV4LVideoInputs(device);
2530 }
2531 
2532 int CardUtil::CreateCaptureCard(const QString &videodevice,
2533  const QString &audiodevice,
2534  const QString &vbidevice,
2535  const QString &inputtype,
2536  const uint audioratelimit,
2537  const QString &hostname,
2538  const uint dvb_swfilter,
2539  const uint dvb_sat_type,
2540  bool dvb_wait_for_seqstart,
2541  bool skipbtaudio,
2542  bool dvb_on_demand,
2543  const uint dvb_diseqc_type,
2544  const uint firewire_speed,
2545  const QString &firewire_model,
2546  const uint firewire_connection,
2547  const std::chrono::milliseconds signal_timeout,
2548  const std::chrono::milliseconds channel_timeout,
2549  const uint dvb_tuning_delay,
2550  const uint contrast,
2551  const uint brightness,
2552  const uint colour,
2553  const uint hue,
2554  const uint diseqcid,
2555  bool dvb_eitscan)
2556 {
2557  MSqlQuery query(MSqlQuery::InitCon());
2558 
2559  query.prepare(
2560  "INSERT INTO capturecard "
2561  "(videodevice, audiodevice, vbidevice, cardtype, "
2562  "audioratelimit, hostname, dvb_swfilter, dvb_sat_type, "
2563  "dvb_wait_for_seqstart, skipbtaudio, dvb_on_demand, dvb_diseqc_type, "
2564  "firewire_speed, firewire_model, firewire_connection, signal_timeout, "
2565  "channel_timeout, dvb_tuning_delay, contrast, brightness, colour, "
2566  "hue, diseqcid, dvb_eitscan) "
2567  "VALUES (:VIDEODEVICE, :AUDIODEVICE, :VBIDEVICE, :INPUTTYPE, "
2568  ":AUDIORATELIMIT, :HOSTNAME, :DVBSWFILTER, :DVBSATTYPE, "
2569  ":DVBWAITFORSEQSTART, :SKIPBTAUDIO, :DVBONDEMAND, :DVBDISEQCTYPE, "
2570  ":FIREWIRESPEED, :FIREWIREMODEL, :FIREWIRECONNECTION, :SIGNALTIMEOUT, "
2571  ":CHANNELTIMEOUT, :DVBTUNINGDELAY, :CONTRAST, :BRIGHTNESS, :COLOUR, "
2572  ":HUE, :DISEQCID, :DVBEITSCAN ) ");
2573 
2574  query.bindValue(":VIDEODEVICE", videodevice);
2575  query.bindValue(":AUDIODEVICE", audiodevice);
2576  query.bindValue(":VBIDEVICE", vbidevice);
2577  query.bindValue(":INPUTTYPE", inputtype);
2578  query.bindValue(":AUDIORATELIMIT", audioratelimit);
2579  query.bindValue(":HOSTNAME", hostname);
2580  query.bindValue(":DVBSWFILTER", dvb_swfilter);
2581  query.bindValue(":DVBSATTYPE", dvb_sat_type);
2582  query.bindValue(":DVBWAITFORSEQSTART", dvb_wait_for_seqstart);
2583  query.bindValue(":SKIPBTAUDIO", skipbtaudio);
2584  query.bindValue(":DVBONDEMAND", dvb_on_demand);
2585  query.bindValue(":DVBDISEQCTYPE", dvb_diseqc_type);
2586  query.bindValue(":FIREWIRESPEED", firewire_speed);
2587  query.bindValue(":FIREWIREMODEL", firewire_model);
2588  query.bindValue(":FIREWIRECONNECTION", firewire_connection);
2589  query.bindValue(":SIGNALTIMEOUT", static_cast<qint64>(signal_timeout.count()));
2590  query.bindValue(":CHANNELTIMEOUT", static_cast<qint64>(channel_timeout.count()));
2591  query.bindValue(":DVBTUNINGDELAY", dvb_tuning_delay);
2592  query.bindValue(":CONTRAST", contrast);
2593  query.bindValue(":BRIGHTNESS", brightness);
2594  query.bindValue(":COLOUR", colour);
2595  query.bindValue(":HUE", hue);
2596  query.bindValue(":DISEQCID", diseqcid);
2597  query.bindValue(":DVBEITSCAN", dvb_eitscan);
2598 
2599  if (!query.exec())
2600  {
2601  MythDB::DBError("CreateCaptureCard", query);
2602  return -1;
2603  }
2604 
2605  query.prepare("SELECT MAX(cardid) FROM capturecard");
2606 
2607  if (!query.exec())
2608  {
2609  MythDB::DBError("CreateCaptureCard maxinput", query);
2610  return -1;
2611  }
2612 
2613  int inputid = -1; /* must be int not uint because of return type. */
2614 
2615  if (query.next())
2616  {
2617  inputid = query.value(0).toInt();
2618  uint groupid = CardUtil::CreateDeviceInputGroup(inputid, inputtype,
2619  hostname, videodevice);
2620  CardUtil::LinkInputGroup(inputid, groupid);
2621  }
2622 
2623  return inputid;
2624 }
2625 
2627 {
2628  std::vector<uint> childids = GetChildInputIDs(inputid);
2629  for (uint childid : childids)
2630  {
2631  if (!DeleteInput(childid))
2632  {
2633  LOG(VB_GENERAL, LOG_ERR, LOC +
2634  QString("CardUtil: Failed to delete child input %1")
2635  .arg(childid));
2636  return false;
2637  }
2638  }
2639 
2640  MSqlQuery query(MSqlQuery::InitCon());
2641 
2642  DiSEqCDevTree tree;
2643  tree.Load(inputid);
2644 
2645  // Delete the capturecard row for this input
2646  query.prepare("DELETE FROM capturecard WHERE cardid = :INPUTID");
2647  query.bindValue(":INPUTID", inputid);
2648  if (!query.exec())
2649  {
2650  MythDB::DBError("DeleteCard -- delete capturecard", query);
2651  return false;
2652  }
2653 
2654  // Update the reclimit of the parent input
2655  query.prepare("UPDATE capturecard SET reclimit=reclimit-1 "
2656  "WHERE cardid = :INPUTID");
2657  query.bindValue(":INPUTID", inputid);
2658  if (!query.exec())
2659  {
2660  MythDB::DBError("DeleteCard -- update capturecard", query);
2661  return false;
2662  }
2663 
2664  // Delete the inputgroup rows for this input
2665  query.prepare("DELETE FROM inputgroup WHERE cardinputid = :INPUTID");
2666  query.bindValue(":INPUTID", inputid);
2667  if (!query.exec())
2668  {
2669  MythDB::DBError("DeleteCard -- delete inputgroup", query);
2670  return false;
2671  }
2672 
2673  // Delete the diseqc tree if no more inputs reference it.
2674  if (tree.Root())
2675  {
2676  query.prepare("SELECT cardid FROM capturecard "
2677  "WHERE diseqcid = :DISEQCID LIMIT 1");
2678  query.bindValue(":DISEQCID", tree.Root()->GetDeviceID());
2679  if (!query.exec())
2680  {
2681  MythDB::DBError("DeleteCard -- find diseqc tree", query);
2682  }
2683  else if (!query.next())
2684  {
2685  tree.SetRoot(nullptr);
2686  tree.Store(inputid);
2687  }
2688  }
2689 
2690  // delete any unused input groups
2691  UnlinkInputGroup(0, 0);
2692 
2693  return true;
2694 }
2695 
2697 {
2698  MSqlQuery query(MSqlQuery::InitCon());
2699  return (query.exec("TRUNCATE TABLE inputgroup") &&
2700  query.exec("TRUNCATE TABLE diseqc_config") &&
2701  query.exec("TRUNCATE TABLE diseqc_tree") &&
2702  query.exec("TRUNCATE TABLE capturecard") &&
2703  query.exec("TRUNCATE TABLE iptv_channel"));
2704 }
2705 
2706 std::vector<uint> CardUtil::GetInputList(void)
2707 {
2708  std::vector<uint> list;
2709 
2710  MSqlQuery query(MSqlQuery::InitCon());
2711  query.prepare(
2712  "SELECT cardid "
2713  "FROM capturecard "
2714  "ORDER BY cardid");
2715 
2716  if (!query.exec())
2717  MythDB::DBError("CardUtil::GetInputList()", query);
2718  else
2719  {
2720  while (query.next())
2721  list.push_back(query.value(0).toUInt());
2722  }
2723 
2724  return list;
2725 }
2726 
2727 std::vector<uint> CardUtil::GetSchedInputList(void)
2728 {
2729  std::vector<uint> list;
2730 
2731  MSqlQuery query(MSqlQuery::InitCon());
2732  query.prepare(
2733  "SELECT DISTINCT cardid "
2734  "FROM capturecard "
2735  "WHERE schedorder <> 0 "
2736  "ORDER BY schedorder, cardid");
2737 
2738  if (!query.exec())
2739  MythDB::DBError("CardUtil::GetSchedInputList()", query);
2740  else
2741  {
2742  while (query.next())
2743  list.push_back(query.value(0).toUInt());
2744  }
2745 
2746  return list;
2747 }
2748 
2749 std::vector<uint> CardUtil::GetLiveTVInputList(void)
2750 {
2751  std::vector<uint> list;
2752 
2753  MSqlQuery query(MSqlQuery::InitCon());
2754  query.prepare(
2755  "SELECT DISTINCT cardid "
2756  "FROM capturecard "
2757  "WHERE livetvorder <> 0 "
2758  "ORDER BY livetvorder, cardid");
2759 
2760  if (!query.exec())
2761  MythDB::DBError("CardUtil::GetLiveTVInputList()", query);
2762  else
2763  {
2764  while (query.next())
2765  list.push_back(query.value(0).toUInt());
2766  }
2767 
2768  return list;
2769 }
2770 
2771 QString CardUtil::GetDeviceName(dvb_dev_type_t type, const QString &device)
2772 {
2773  QString devname = QString(device);
2774 #if 0
2775  LOG(VB_RECORD, LOG_DEBUG, LOC + QString("DVB Device (%1)").arg(devname));
2776 #endif
2777 
2778  if (DVB_DEV_FRONTEND == type)
2779  {
2780  return devname;
2781  }
2782 
2783  if (DVB_DEV_DVR == type)
2784  {
2785  QString tmp = devname;
2786  tmp = tmp.replace(tmp.indexOf("frontend"), 8, "dvr");
2787  if (QFile::exists(tmp))
2788  {
2789  LOG(VB_RECORD, LOG_DEBUG, LOC +
2790  QString("Adapter Frontend dvr number matches (%1)").arg(tmp));
2791  return tmp;
2792  }
2793 
2794  // Use dvr0, allows multi-standard frontends which only have one dvr
2795  tmp = devname;
2796  tmp = tmp.replace(tmp.indexOf("frontend"), 9, "dvr0");
2797  if (QFile::exists(tmp))
2798  {
2799  LOG(VB_RECORD, LOG_DEBUG, LOC +
2800  QString("Adapter Frontend dvr number not matching, using dvr0 instead (%1)").arg(tmp));
2801  return tmp;
2802  }
2803 
2804  LOG(VB_RECORD, LOG_DEBUG, LOC +
2805  QString("Adapter Frontend no dvr device found for (%1)").arg(devname));
2806  return "";
2807  }
2808 
2809  if (DVB_DEV_DEMUX == type)
2810  {
2811  QString tmp = devname;
2812  tmp = tmp.replace(tmp.indexOf("frontend"), 8, "demux");
2813  if (QFile::exists(tmp))
2814  {
2815  LOG(VB_RECORD, LOG_DEBUG, LOC +
2816  QString("Adapter Frontend demux number matches (%1)").arg(tmp));
2817  return tmp;
2818  }
2819 
2820  // Use demux0, allows multi-standard frontends, which only have one demux
2821  tmp = devname;
2822  tmp = tmp.replace(tmp.indexOf("frontend"), 9, "demux0");
2823  if (QFile::exists(tmp))
2824  {
2825  LOG(VB_RECORD, LOG_DEBUG, LOC +
2826  QString("Adapter Frontend demux number not matching, using demux0 instead (%1)").arg(tmp));
2827  return tmp;
2828  }
2829 
2830  LOG(VB_RECORD, LOG_DEBUG, LOC +
2831  QString("Adapter Frontend no demux device found for (%1)").arg(devname));
2832  return "";
2833  }
2834 
2835  if (DVB_DEV_CA == type)
2836  {
2837  QString tmp = devname;
2838  tmp = tmp.replace(tmp.indexOf("frontend"), 8, "ca");
2839  if (QFile::exists(tmp))
2840  {
2841  LOG(VB_RECORD, LOG_DEBUG, LOC +
2842  QString("Adapter Frontend ca number matches (%1)").arg(tmp));
2843  return tmp;
2844  }
2845 
2846  // Use ca0, allows multi-standard frontends, which only have one ca
2847  tmp = devname;
2848  tmp = tmp.replace(tmp.indexOf("frontend"), 9, "ca0");
2849  if (QFile::exists(tmp))
2850  {
2851  LOG(VB_RECORD, LOG_DEBUG, LOC +
2852  QString("Adapter Frontend ca number not matching, using ca0 instead (%1)").arg(tmp));
2853  return tmp;
2854  }
2855 
2856  LOG(VB_RECORD, LOG_DEBUG, LOC +
2857  QString("Adapter Frontend no ca device found for (%1)").arg(devname));
2858  return "";
2859  }
2860 
2861  if (DVB_DEV_AUDIO == type)
2862  {
2863  return devname.replace(devname.indexOf("frontend"), 8, "audio");
2864  }
2865 
2866  if (DVB_DEV_VIDEO == type)
2867  {
2868  return devname.replace(devname.indexOf("frontend"), 8, "video");
2869  }
2870 
2871  return "";
2872 }
2873 
2874 
2884 bool CardUtil::HDHRdoesDVB(const QString &device)
2885 {
2886  (void) device;
2887 
2888 #ifdef USING_HDHOMERUN
2889  hdhomerun_device_t *hdhr =
2890  hdhomerun_device_create_from_str(device.toLatin1(), nullptr);
2891  if (!hdhr)
2892  return false;
2893 
2894  const char *model = hdhomerun_device_get_model_str(hdhr);
2895  if (model && strstr(model, "dvb"))
2896  {
2897  hdhomerun_device_destroy(hdhr);
2898  return true;
2899  }
2900 
2901  hdhomerun_device_destroy(hdhr);
2902 
2903 #endif
2904 
2905  return false;
2906 }
2907 
2912 bool CardUtil::HDHRdoesDVBC(const QString &device)
2913 {
2914  (void) device;
2915 
2916 #ifdef USING_HDHOMERUN
2917  hdhomerun_device_t *hdhr =
2918  hdhomerun_device_create_from_str(device.toLatin1(), nullptr);
2919  if (!hdhr)
2920  return false;
2921 
2922  const char *model = hdhomerun_device_get_model_str(hdhr);
2923  if (model && strstr(model, "dvbc"))
2924  {
2925  hdhomerun_device_destroy(hdhr);
2926  return true;
2927  }
2928 
2929  hdhomerun_device_destroy(hdhr);
2930 
2931 #endif
2932 
2933  return false;
2934 }
2935 
2940 QString CardUtil::GetHDHRdesc(const QString &device)
2941 {
2942  QString connectErr = QObject::tr("Unable to connect to device.");
2943 
2944 #ifdef USING_HDHOMERUN
2945  bool deviceIsIP = false;
2946 
2947  if (device.contains('.')) // Simplistic check, but also allows DNS names
2948  deviceIsIP = true;
2949  else
2950  {
2951  bool validID = false;
2952 
2953  uint32_t dev = device.toUInt(&validID, 16);
2954  if (!validID || !hdhomerun_discover_validate_device_id(dev))
2955  return QObject::tr("Invalid Device ID");
2956  }
2957  (void) deviceIsIP;
2958 
2959  LOG(VB_GENERAL, LOG_INFO, "CardUtil::GetHDHRdescription(" + device +
2960  ") - trying to locate device");
2961 
2962  hdhomerun_device_t *hdhr =
2963  hdhomerun_device_create_from_str(device.toLatin1(), nullptr);
2964  if (!hdhr)
2965  return QObject::tr("Invalid Device ID or address.");
2966 
2967  const char *model = hdhomerun_device_get_model_str(hdhr);
2968  if (!model)
2969  {
2970  hdhomerun_device_destroy(hdhr);
2971  return connectErr;
2972  }
2973 
2974 
2975  QString description = model;
2976  char *sVersion = nullptr;
2977  uint32_t iVersion = 0;
2978 
2979  if (hdhomerun_device_get_version(hdhr, &sVersion, &iVersion))
2980  description += QObject::tr(", firmware: %2").arg(sVersion);
2981 
2982  hdhomerun_device_destroy(hdhr);
2983 
2984  return description;
2985 #else
2986 
2987  (void) device;
2988  return connectErr;
2989 #endif
2990 }
2991 
2996 QString CardUtil::GetVBoxdesc(const QString &id, const QString &ip,
2997  const QString &tunerNo, const QString &tunerType)
2998 {
2999  QString connectErr = QObject::tr("Unable to connect to device.");
3000 
3001 #ifdef USING_VBOX
3002  VBox *vbox = new VBox(ip);
3003 
3004  if (!vbox->checkConnection())
3005  {
3006  delete vbox;
3007  return connectErr;
3008  }
3009 
3010  QString version;
3011 
3012  if (!vbox->checkVersion(version))
3013  {
3014  QString apiVersionErr = QObject::tr("The VBox software version is too old (%1), we require %2")
3016  delete vbox;
3017  return apiVersionErr;
3018 
3019  }
3020 
3021  delete vbox;
3022 
3023  return QString("V@Box TV Gateway - ID: %1, IP: %2, Tuner: %3-%4")
3024  .arg(id, ip, tunerNo, tunerType);
3025 
3026 #else
3027  (void) id;
3028  (void) ip;
3029  (void) tunerNo;
3030  (void) tunerType;
3031 
3032  return connectErr;
3033 #endif
3034 }
3035 
3036 #ifdef USING_ASI
3037 static QString sys_dev(uint device_num, const QString& dev)
3038 {
3039  return QString("/sys/class/asi/asirx%1/%2").arg(device_num).arg(dev);
3040 }
3041 
3042 static QString read_sys(const QString& sys_dev)
3043 {
3044  QFile f(sys_dev);
3045  f.open(QIODevice::ReadOnly);
3046  QByteArray sdba = f.readAll();
3047  f.close();
3048  return sdba;
3049 }
3050 
3051 static bool write_sys(const QString& sys_dev, const QString& str)
3052 {
3053  QFile f(sys_dev);
3054  f.open(QIODevice::WriteOnly);
3055  QByteArray ba = str.toLocal8Bit();
3056  qint64 offset = 0;
3057  for (uint tries = 0; (offset < ba.size()) && tries < 5; tries++)
3058  {
3059  qint64 written = f.write(ba.data()+offset, ba.size()-offset);
3060  if (written < 0)
3061  return false;
3062  offset += written;
3063  }
3064  return true;
3065 }
3066 #endif
3067 
3068 int CardUtil::GetASIDeviceNumber(const QString &device, QString *error)
3069 {
3070 #ifdef USING_ASI
3071  // basic confirmation
3072  struct stat statbuf {};
3073  if (stat(device.toLocal8Bit().constData(), &statbuf) < 0)
3074  {
3075  if (error)
3076  *error = QString("Unable to stat '%1'").arg(device) + ENO;
3077  return -1;
3078  }
3079 
3080  if (!S_ISCHR(statbuf.st_mode))
3081  {
3082  if (error)
3083  *error = QString("'%1' is not a character device").arg(device);
3084  return -1;
3085  }
3086 
3087  if (!(statbuf.st_rdev & 0x0080))
3088  {
3089  if (error)
3090  *error = QString("'%1' not a DVEO ASI receiver").arg(device);
3091  return -1;
3092  }
3093 
3094  int device_num = statbuf.st_rdev & 0x007f;
3095 
3096  // extra confirmation
3097  QString sys_dev_contents = read_sys(sys_dev(device_num, "dev"));
3098  QStringList sys_dev_clist = sys_dev_contents.split(":");
3099  if (2 != sys_dev_clist.size())
3100  {
3101  if (error)
3102  {
3103  *error = QString("Unable to read '%1'")
3104  .arg(sys_dev(device_num, "dev"));
3105  }
3106  return -1;
3107  }
3108  if (sys_dev_clist[0].toUInt() != (statbuf.st_rdev>>8))
3109  {
3110  if (error)
3111  *error = QString("'%1' not a DVEO ASI device").arg(device);
3112  return -1;
3113  }
3114 
3115  return device_num;
3116 #else
3117  (void) device;
3118  if (error)
3119  *error = "Not compiled with ASI support.";
3120  return -1;
3121 #endif
3122 }
3123 
3125 {
3126 #ifdef USING_ASI
3127  // get the buffer size
3128  QString sys_bufsize_contents = read_sys(sys_dev(device_num, "bufsize"));
3129  bool ok = false;
3130  uint buf_size = sys_bufsize_contents.toUInt(&ok);
3131  if (!ok)
3132  {
3133  if (error)
3134  {
3135  *error = QString("Failed to read buffer size from '%1'")
3136  .arg(sys_dev(device_num, "bufsize"));
3137  }
3138  return 0;
3139  }
3140  return buf_size;
3141 #else
3142  (void) device_num;
3143  if (error)
3144  *error = "Not compiled with ASI support.";
3145  return 0;
3146 #endif
3147 }
3148 
3150 {
3151 #ifdef USING_ASI
3152  // get the buffer size
3153  QString sys_numbuffers_contents = read_sys(sys_dev(device_num, "buffers"));
3154  bool ok = false;
3155  uint num_buffers = sys_numbuffers_contents.toUInt(&ok);
3156  if (!ok)
3157  {
3158  if (error)
3159  {
3160  *error = QString("Failed to read num buffers from '%1'")
3161  .arg(sys_dev(device_num, "buffers"));
3162  }
3163  return 0;
3164  }
3165  return num_buffers;
3166 #else
3167  (void) device_num;
3168  if (error)
3169  *error = "Not compiled with ASI support.";
3170  return 0;
3171 #endif
3172 }
3173 
3174 int CardUtil::GetASIMode(uint device_num, QString *error)
3175 {
3176 #ifdef USING_ASI
3177  QString sys_bufsize_contents = read_sys(sys_dev(device_num, "mode"));
3178  bool ok = false;
3179  uint mode = sys_bufsize_contents.toUInt(&ok);
3180  if (!ok)
3181  {
3182  if (error)
3183  {
3184  *error = QString("Failed to read mode from '%1'")
3185  .arg(sys_dev(device_num, "mode"));
3186  }
3187  return -1;
3188  }
3189  return mode;
3190 #else
3191  (void) device_num;
3192  if (error)
3193  *error = "Not compiled with ASI support.";
3194  return -1;
3195 #endif
3196 }
3197 
3198 bool CardUtil::SetASIMode(uint device_num, uint mode, QString *error)
3199 {
3200 #ifdef USING_ASI
3201  QString sys_bufsize_contents = read_sys(sys_dev(device_num, "mode"));
3202  bool ok = false;
3203  uint old_mode = sys_bufsize_contents.toUInt(&ok);
3204  if (ok && old_mode == mode)
3205  return true;
3206  ok = write_sys(sys_dev(device_num, "mode"), QString("%1\n").arg(mode));
3207  if (!ok && error)
3208  {
3209  *error = QString("Failed to set mode to %1 using '%2'")
3210  .arg(mode).arg(sys_dev(device_num, "mode"));
3211  }
3212  return ok;
3213 #else
3214  Q_UNUSED(device_num);
3215  Q_UNUSED(mode);
3216  if (error)
3217  *error = "Not compiled with ASI support.";
3218  return false;
3219 #endif
3220 }
3221 
3227 {
3228  // should only be called if inputtype == VBOX
3229  if (!inputid )
3230  {
3231  LOG(VB_GENERAL, LOG_ERR, QString("VBOX inputid (%1) not valid, redo mythtv-setup")
3232  .arg(inputid));
3233  return false;
3234  }
3235 
3236  // get sourceid and startchan from table capturecard for inputid
3237  uint chanid = 0;
3238  chanid = ChannelUtil::GetChannelValueInt("chanid",GetSourceID(inputid),GetStartingChannel(inputid));
3239  if (!chanid)
3240  {
3241  // no chanid, presume bad setup
3242  LOG(VB_GENERAL, LOG_ERR, QString("VBOX chanid (%1) not found for inputid (%2) , redo mythtv-setup")
3243  .arg(chanid).arg(inputid));
3244  return false;
3245  }
3246 
3247  // get timeouts for inputid
3248  std::chrono::milliseconds signal_timeout = 0ms;
3249  std::chrono::milliseconds tuning_timeout = 0ms;
3250  if (!GetTimeouts(inputid,signal_timeout,tuning_timeout))
3251  {
3252  LOG(VB_GENERAL, LOG_ERR, QString("Failed to get timeouts for inputid (%1)")
3253  .arg(inputid));
3254  return false;
3255  }
3256 
3257  // now get url from iptv_channel table
3258  QUrl url;
3259  MSqlQuery query(MSqlQuery::InitCon());
3260  query.prepare("SELECT url "
3261  "FROM iptv_channel "
3262  "WHERE chanid = :CHANID");
3263  query.bindValue(":CHANID", chanid);
3264 
3265  if (!query.exec())
3266  MythDB::DBError("CardUtil::IsVBoxPresent url", query);
3267  else if (query.next())
3268  url = query.value(0).toString();
3269 
3270  //now get just the IP address from the url
3271  QString ip = url.host();
3272  LOG(VB_GENERAL, LOG_INFO, QString("VBOX IP found (%1) for inputid (%2)")
3273  .arg(ip).arg(inputid));
3274 
3275  if (!ping(ip,signal_timeout))
3276  {
3277  LOG(VB_GENERAL, LOG_ERR, QString("VBOX at IP (%1) failed to respond to network ping for inputid (%2) timeout (%3)")
3278  .arg(ip).arg(inputid).arg(signal_timeout.count()));
3279  return false;
3280  }
3281 
3282  return true;
3283 }
CardUtil::HDHRdoesDVBC
static bool HDHRdoesDVBC(const QString &device)
If the device is valid, check if the model does DVB-C.
Definition: cardutil.cpp:2912
VBox::checkVersion
bool checkVersion(QString &version)
Definition: vboxutils.cpp:213
manager
static MythSystemLegacyManager * manager
Definition: mythsystemunix.cpp:56
MSqlQuery::isActive
bool isActive(void) const
Definition: mythdbcon.h:212
CardUtil::s_videoDeviceCache
static QMap< QString, QStringList > s_videoDeviceCache
Definition: cardutil.h:457
CardUtil::GetScanableInputTypes
static QString GetScanableInputTypes(void)
Definition: cardutil.cpp:62
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:802
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:124
CardUtil::IsTunerShared
static bool IsTunerShared(uint inputidA, uint inputidB)
Definition: cardutil.cpp:249
CardUtil::SetDeliverySystem
static int SetDeliverySystem(uint inputid)
Definition: cardutil.cpp:1096
CardUtil::GetInputIDs
static std::vector< uint > GetInputIDs(const QString &videodevice=QString(), const QString &rawtype=QString(), const QString &inputname=QString(), QString hostname=QString())
Returns all inputids of inputs that uses the specified videodevice if specified, and optionally rawty...
Definition: cardutil.cpp:1272
CardUtil::GetVBoxdesc
static QString GetVBoxdesc(const QString &id, const QString &ip, const QString &tunerNo, const QString &tunerType)
Get a nicely formatted string describing the device.
Definition: cardutil.cpp:2996
CardUtil::IsInNeedOfExternalInputConf
static bool IsInNeedOfExternalInputConf(uint inputid)
Definition: cardutil.cpp:2121
DiSEqCDevTree::IsInNeedOfConf
bool IsInNeedOfConf(void) const
Definition: diseqc.cpp:830
CardUtil::CreateCardInput
static int CreateCardInput(uint inputid, uint sourceid, const QString &inputname, const QString &externalcommand, const QString &changer_device, const QString &changer_model, const QString &hostname, const QString &tunechan, const QString &startchan, const QString &displayname, bool dishnet_eit, uint recpriority, uint quicktune, uint schedorder, uint livetvorder)
Definition: cardutil.cpp:1789
ENO
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:72
CardUtil::GetDisplayName
static QString GetDisplayName(uint inputid)
Definition: cardutil.cpp:1724
DTVTunerType::kTunerTypeDVBC
static const int kTunerTypeDVBC
Definition: dtvconfparserhelpers.h:95
VBox::checkConnection
bool checkConnection(void)
Definition: vboxutils.cpp:207
CardUtil::GetDeviceLabel
static QString GetDeviceLabel(const QString &inputtype, const QString &videodevice)
Definition: cardutil.cpp:2496
error
static void error(const char *str,...)
Definition: vbi.cpp:42
CardUtil::ProbeDeliverySystems
static QStringList ProbeDeliverySystems(const QString &device)
Definition: cardutil.cpp:575
mythdb.h
CardUtil::GetOrProbeDeliverySystem
static DTVModulationSystem GetOrProbeDeliverySystem(uint inputid, int fd)
Definition: cardutil.cpp:1046
DTVModulationSystem::kModulationSystem_DVBS2
@ kModulationSystem_DVBS2
Definition: dtvconfparserhelpers.h:662
CardUtil::GetVideoDevices
static QStringList GetVideoDevices(const QString &rawtype, QString hostname=QString())
Returns the videodevices of the matching inputs, duplicates removed.
Definition: cardutil.cpp:405
false
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
CardUtil::ClearVideoDeviceCache
static void ClearVideoDeviceCache()
Definition: cardutil.cpp:450
CardUtil::GetInputName
static QString GetInputName(uint inputid)
Definition: cardutil.cpp:1701
CardUtil::ProbeCurrentDeliverySystem
static DTVModulationSystem ProbeCurrentDeliverySystem(const QString &device)
Definition: cardutil.cpp:866
CardUtil::GetASIDeviceNumber
static int GetASIDeviceNumber(const QString &device, QString *error=nullptr)
Definition: cardutil.cpp:3068
V4L2util::DriverName
QString DriverName(void) const
Definition: v4l2util.h:48
CardUtil::DeleteAllInputs
static bool DeleteAllInputs(void)
Definition: cardutil.cpp:2696
DTVTunerType::kTunerTypeDVBS1
static const int kTunerTypeDVBS1
Definition: dtvconfparserhelpers.h:93
DVB_DEV_VIDEO
@ DVB_DEV_VIDEO
Definition: cardutil.h:34
CardUtil::SetStartChannel
static bool SetStartChannel(uint inputid, const QString &channum)
Definition: cardutil.cpp:1613
DTVModulationSystem::kModulationSystem_DTMB
@ kModulationSystem_DTMB
Definition: dtvconfparserhelpers.h:669
CardUtil::ProbeVideoInputs
static QStringList ProbeVideoInputs(const QString &device, const QString &inputtype=QString())
Definition: cardutil.cpp:2385
CardUtil::ProbeBestDeliverySystem
static DTVModulationSystem ProbeBestDeliverySystem(int fd)
Definition: cardutil.cpp:995
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:201
CardUtil::HasDVBCRCBug
static bool HasDVBCRCBug(const QString &device)
Returns true if and only if the device munges PAT/PMT tables, and then doesn't fix the CRC.
Definition: cardutil.cpp:739
V4L2util::HasTuner
bool HasTuner(void) const
Definition: v4l2util.cpp:685
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
set_on_input
bool set_on_input(const QString &to_set, uint inputid, const QString &value)
Definition: cardutil.cpp:1242
VBOX_MIN_API_VERSION
#define VBOX_MIN_API_VERSION
Definition: vboxutils.h:14
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythDownloadManager
Definition: mythdownloadmanager.h:50
DVB_DEV_CA
@ DVB_DEV_CA
Definition: cardutil.h:32
DiSEqCDevSettings::Load
bool Load(uint card_input_id)
Loads configuration chain from DB for specified card input id.
Definition: diseqc.cpp:123
read_sys
static QString read_sys(const QString &sys_dev)
Definition: cardutil.cpp:3042
CardUtil::ProbeTunerType
static DTVTunerType ProbeTunerType(int fd_frontend)
Definition: cardutil.cpp:807
CardUtil::CloneCard
static uint CloneCard(uint src_inputid, uint dst_inputid)
Definition: cardutil.cpp:1517
CardUtil::IsUniqueDisplayName
static bool IsUniqueDisplayName(const QString &name, uint exclude_inputid)
Definition: cardutil.cpp:1746
dvbchannel.h
CardUtil::GetFirewireChangerModel
static QString GetFirewireChangerModel(uint inputid)
Definition: cardutil.cpp:1572
close
#define close
Definition: compat.h:17
tmp
static guint32 * tmp
Definition: goom_core.cpp:31
CardUtil::ProbeSubTypeName
static QString ProbeSubTypeName(uint inputid)
Definition: cardutil.cpp:936
DTVModulationSystem::kModulationSystem_UNDEFINED
@ kModulationSystem_UNDEFINED
Definition: dtvconfparserhelpers.h:656
CardUtil::ProbeDefaultDeliverySystem
static QString ProbeDefaultDeliverySystem(const QString &device)
Definition: cardutil.cpp:654
DTVTunerType
Definition: dtvconfparserhelpers.h:76
CardUtil::GetASINumBuffers
static uint GetASINumBuffers(uint device_num, QString *error=nullptr)
Definition: cardutil.cpp:3149
CardUtil::ProbeDVBType
static QString ProbeDVBType(const QString &device)
Definition: cardutil.cpp:672
satiputils.h
CardUtil::ProbeVideoDevices
static QStringList ProbeVideoDevices(const QString &rawtype)
Definition: cardutil.cpp:456
DiSEqCDevSettings
DVB-S device settings class.
Definition: diseqc.h:36
CardUtil::SetDefaultDeliverySystem
static int SetDefaultDeliverySystem(uint inputid, int fd)
Definition: cardutil.cpp:1076
CardUtil::ProbeDVBFrontendName
static QString ProbeDVBFrontendName(const QString &device)
Returns the input type from the video device.
Definition: cardutil.cpp:693
CardUtil::GetASIBufferSize
static uint GetASIBufferSize(uint device_num, QString *error=nullptr)
Definition: cardutil.cpp:3124
CardUtil::GetInputGroups
static std::vector< uint > GetInputGroups(uint inputid)
Definition: cardutil.cpp:1999
sourceutil.h
CardUtil::UnlinkInputGroup
static bool UnlinkInputGroup(uint inputid, uint inputgroupid)
Definition: cardutil.cpp:1968
InputInfo::m_recPriority
int m_recPriority
Definition: inputinfo.h:53
CardUtil::GetAllInputInfo
static QList< InputInfo > GetAllInputInfo()
Definition: cardutil.cpp:1667
dvbtypes.h
mythlogging.h
CardUtil::GetInputList
static std::vector< uint > GetInputList(void)
Definition: cardutil.cpp:2706
SatIP::probeDevices
static QStringList probeDevices(void)
Definition: satiputils.cpp:21
InputInfo::m_liveTvOrder
uint m_liveTvOrder
order for live TV use
Definition: inputinfo.h:55
CardUtil::GetV4LInfo
static bool GetV4LInfo(int videofd, QString &input, QString &driver, uint32_t &version, uint32_t &capabilities)
Definition: cardutil.cpp:2166
v4l2util.h
CardUtil::IsSingleInputType
static bool IsSingleInputType(const QString &rawtype)
Definition: cardutil.h:207
CardUtil::GetMinSignalMonitoringDelay
static std::chrono::milliseconds GetMinSignalMonitoringDelay(const QString &device)
Definition: cardutil.cpp:746
DTVModulationSystem::kModulationSystem_DVBC_ANNEX_B
@ kModulationSystem_DVBC_ANNEX_B
Definition: dtvconfparserhelpers.h:658
CardUtil::CreateDeviceInputGroup
static uint CreateDeviceInputGroup(uint inputid, const QString &type, const QString &host, const QString &device)
Definition: cardutil.cpp:1891
CardUtil::ProbeDVBInputs
static QStringList ProbeDVBInputs(const QString &device)
Definition: cardutil.cpp:2476
DTVTunerType::kTunerTypeUnknown
static const int kTunerTypeUnknown
Definition: dtvconfparserhelpers.h:103
hardwareprofile.i18n.t
t
Definition: i18n.py:36
CardUtil::GetChildInputIDs
static std::vector< uint > GetChildInputIDs(uint inputid)
Definition: cardutil.cpp:1340
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:200
O_NONBLOCK
#define O_NONBLOCK
Definition: mythmedia.cpp:25
CardUtil::hasV4L2
static bool hasV4L2(int videofd)
Definition: cardutil.cpp:2153
DTVTunerType::toString
QString toString() const
Definition: dtvconfparserhelpers.h:154
vboxutils.h
CardUtil::ProbeV4LAudioInputs
static InputNames ProbeV4LAudioInputs(int videofd, bool &ok)
Definition: cardutil.cpp:2270
DiSEqCDevTree::Load
bool Load(const QString &device)
Loads the device tree from the database.
Definition: diseqc.cpp:306
CardUtil::GetDeliverySystemFromDB
static QString GetDeliverySystemFromDB(uint inputid)
Definition: cardutil.h:290
DVB_DEV_AUDIO
@ DVB_DEV_AUDIO
Definition: cardutil.h:33
CardUtil::HasTuner
static bool HasTuner(const QString &rawtype, const QString &device)
Definition: cardutil.cpp:223
DiSEqCDevTree::SetRoot
void SetRoot(DiSEqCDevDevice *root)
Changes the root node of the tree.
Definition: diseqc.cpp:629
dvb_dev_type_t
dvb_dev_type_t
Definition: cardutil.h:27
CardUtil::GetDeviceInputGroup
static uint GetDeviceInputGroup(uint inputid)
Definition: cardutil.cpp:1904
CardUtil::IsDVBInputType
static bool IsDVBInputType(const QString &inputType)
Returns true iff the input_type is one of the DVB types.
Definition: cardutil.cpp:983
CardUtil::GetTunerType
static DTVTunerType GetTunerType(uint inputid)
Definition: cardutil.cpp:799
uint
unsigned int uint
Definition: compat.h:140
CardUtil::GetTimeouts
static bool GetTimeouts(uint inputid, std::chrono::milliseconds &signal_timeout, std::chrono::milliseconds &channel_timeout)
Definition: cardutil.cpp:2098
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
DiSEqCDev::FindTree
static DiSEqCDevTree * FindTree(uint cardid)
Retrieve device tree.
Definition: diseqc.cpp:232
DiSEqCDevTree::Root
DiSEqCDevDevice * Root(void)
Retrieves the root node in the tree.
Definition: diseqc.h:93
DTVModulationSystem::kModulationSystem_ATSC
@ kModulationSystem_ATSC
Definition: dtvconfparserhelpers.h:667
CardUtil::GetFirewireChangerNode
static QString GetFirewireChangerNode(uint inputid)
Definition: cardutil.cpp:1555
ChannelUtil::GetChannelValueInt
static int GetChannelValueInt(const QString &channel_field, uint sourceid, const QString &channum)
Definition: channelutil.cpp:975
CardUtil::IsVBoxPresent
static bool IsVBoxPresent(uint inputid)
Returns true if the VBox responds to a ping.
Definition: cardutil.cpp:3226
InputInfo::m_inputId
uint m_inputId
unique key in DB for this input
Definition: inputinfo.h:49
DTVTunerType::kTunerTypeDVBS2
static const int kTunerTypeDVBS2
Definition: dtvconfparserhelpers.h:94
InputInfo::m_quickTune
bool m_quickTune
Definition: inputinfo.h:56
sys_dev
static QString sys_dev(uint device_num, const QString &dev)
Definition: cardutil.cpp:3037
DTVModulationSystem::toString
QString toString() const
Definition: dtvconfparserhelpers.h:719
CardUtil::GetQuickTuning
static uint GetQuickTuning(uint inputid, const QString &input_name)
Definition: cardutil.cpp:2132
LOC
#define LOC
Definition: cardutil.cpp:60
CardUtil::GetDeviceName
static QString GetDeviceName(dvb_dev_type_t type, const QString &device)
Definition: cardutil.cpp:2771
CardUtil::GetConfiguredDVBInputs
static InputNames GetConfiguredDVBInputs(const QString &device)
Definition: cardutil.cpp:2302
CardUtil::GetRawInputType
static QString GetRawInputType(uint inputid)
Definition: cardutil.h:282
InputInfo::m_scheduleOrder
uint m_scheduleOrder
Definition: inputinfo.h:54
CardUtil::IsInputTypePresent
static bool IsInputTypePresent(const QString &rawtype, QString hostname=QString())
Returns true if the input type is present and connected to an input.
Definition: cardutil.cpp:296
CardUtil::OpenVideoDevice
static int OpenVideoDevice(int inputid)
Definition: cardutil.cpp:1202
InputInfo::m_sourceId
uint m_sourceId
associated channel listings source
Definition: inputinfo.h:48
CardUtil::GetTunerTypeFromMultiplex
static DTVTunerType GetTunerTypeFromMultiplex(uint mplexid)
Definition: cardutil.cpp:823
clone_capturecard
static uint clone_capturecard(uint src_inputid, uint orig_dst_inputid)
Definition: cardutil.cpp:1368
V4L2util::IsOpen
bool IsOpen(void) const
Definition: v4l2util.h:29
CardUtil::IsCableCardPresent
static bool IsCableCardPresent(uint inputid, const QString &inputType)
Definition: cardutil.cpp:111
ping
bool ping(const QString &host, std::chrono::milliseconds timeout)
Can we ping host within timeout seconds?
Definition: mythmiscutil.cpp:247
DVB_DEV_DEMUX
@ DVB_DEV_DEMUX
Definition: cardutil.h:31
DiSEqCDevSettings::Store
bool Store(uint card_input_id) const
Stores configuration chain to DB for specified card input id.
Definition: diseqc.cpp:157
VERBOSE_LEVEL_CHECK
#define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_)
Definition: mythlogging.h:14
mythmiscutil.h
V4L2util
Definition: v4l2util.h:16
CardUtil::InputTypes
QMap< QString, QString > InputTypes
Definition: cardutil.h:43
DTVModulationSystem
Definition: dtvconfparserhelpers.h:644
cardutil.h
CardUtil::CreateCaptureCard
static int CreateCaptureCard(const QString &videodevice, const QString &audiodevice, const QString &vbidevice, const QString &inputtype, uint audioratelimit, const QString &hostname, uint dvb_swfilter, uint dvb_sat_type, bool dvb_wait_for_seqstart, bool skipbtaudio, bool dvb_on_demand, uint dvb_diseqc_type, uint firewire_speed, const QString &firewire_model, uint firewire_connection, std::chrono::milliseconds signal_timeout, std::chrono::milliseconds channel_timeout, uint dvb_tuning_delay, uint contrast, uint brightness, uint colour, uint hue, uint diseqcid, bool dvb_eitscan)
Definition: cardutil.cpp:2532
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:878
VBox
Definition: vboxutils.h:16
CardUtil::GetInputTypes
static InputTypes GetInputTypes(void)
Definition: cardutil.cpp:330
CardUtil::AddChildInput
static uint AddChildInput(uint parentid)
Definition: cardutil.cpp:1527
CardUtil::GetChildInputCount
static uint GetChildInputCount(uint inputid)
Definition: cardutil.cpp:1316
CardUtil::HDHRdoesDVB
static bool HDHRdoesDVB(const QString &device)
If the device is valid, check if the model does DVB.
Definition: cardutil.cpp:2884
CardUtil::GetDeliverySystem
static DTVModulationSystem GetDeliverySystem(uint inputid)
Definition: cardutil.cpp:857
CardUtil::ProbeAudioInputs
static QStringList ProbeAudioInputs(const QString &device, const QString &inputtype=QString())
Definition: cardutil.cpp:2399
CardUtil::GetHDHRdesc
static QString GetHDHRdesc(const QString &device)
Get a nicely formatted string describing the device.
Definition: cardutil.cpp:2940
CardUtil::GetSourceID
static uint GetSourceID(uint inputid)
Definition: cardutil.cpp:1770
inputinfo.h
CardUtil::GetSchedInputList
static std::vector< uint > GetSchedInputList(void)
Definition: cardutil.cpp:2727
InputInfo
Definition: inputinfo.h:14
VBox::probeDevices
static QStringList probeDevices(void)
Definition: vboxutils.cpp:27
CardUtil::IsTunerSharingCapable
static bool IsTunerSharingCapable(const QString &rawtype)
Definition: cardutil.h:172
DiSEqCDevTree
DVB-S device tree class. Represents a tree of DVB-S devices.
Definition: diseqc.h:74
get_on_input
QString get_on_input(const QString &to_get, uint inputid)
Definition: cardutil.cpp:1225
CardUtil::GetInputTypeNames
static QStringList GetInputTypeNames(uint sourceid)
Get a list of card input types for a source id.
Definition: cardutil.cpp:377
CardUtil::ConvertToTunerType
static DTVTunerType ConvertToTunerType(DTVModulationSystem delsys)
Definition: cardutil.cpp:756
DTVTunerType::kTunerTypeATSC
static const int kTunerTypeATSC
Definition: dtvconfparserhelpers.h:98
CardUtil::GetInputInfo
static bool GetInputInfo(InputInfo &input, std::vector< uint > *groupids=nullptr)
Definition: cardutil.cpp:1631
InputNames
QMap< int, QString > InputNames
Definition: cardutil.h:21
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:862
DVB_DEV_FRONTEND
@ DVB_DEV_FRONTEND
Definition: cardutil.h:29
DiSEqCDevTree::Store
bool Store(uint cardid, const QString &device="")
Stores the device tree to the database.
Definition: diseqc.cpp:417
CardUtil::ProbeV4LVideoInputs
static InputNames ProbeV4LVideoInputs(int videofd, bool &ok)
Definition: cardutil.cpp:2204
musicbrainzngs.caa.hostname
string hostname
Definition: caa.py:17
DiSEqCDevDevice::GetDeviceID
uint GetDeviceID(void) const
Definition: diseqc.h:170
DTVModulationSystem::kModulationSystem_DVBT2
@ kModulationSystem_DVBT2
Definition: dtvconfparserhelpers.h:672
DTVTunerType::kTunerTypeDVBT
static const int kTunerTypeDVBT
Definition: dtvconfparserhelpers.h:96
CardUtil::GetLiveTVInputList
static std::vector< uint > GetLiveTVInputList(void)
Definition: cardutil.cpp:2749
CardUtil::CapabilitiesToString
static QStringList CapabilitiesToString(uint64_t capabilities)
Definition: cardutil.cpp:2330
DTVModulationSystem::kModulationSystem_DVBC_ANNEX_C
@ kModulationSystem_DVBC_ANNEX_C
Definition: dtvconfparserhelpers.h:674
mythdownloadmanager.h
CardUtil::GetDeviceInputNames
static void GetDeviceInputNames(const QString &device, const QString &inputtype, QStringList &inputs)
Definition: cardutil.cpp:2518
DVB_DEV_DVR
@ DVB_DEV_DVR
Definition: cardutil.h:30
CardUtil::GetConflictingInputs
static std::vector< uint > GetConflictingInputs(uint inputid)
Definition: cardutil.cpp:2052
V4L2util::CardName
QString CardName(void) const
Definition: v4l2util.h:49
DTVTunerType::kTunerTypeDVBT2
static const int kTunerTypeDVBT2
Definition: dtvconfparserhelpers.h:97
CardUtil::GetGroupInputIDs
static std::vector< uint > GetGroupInputIDs(uint inputgroupid)
Definition: cardutil.cpp:2025
CardUtil::GetStartingChannel
static QString GetStartingChannel(uint inputid)
Definition: cardutil.cpp:1708
nv_python_libs.bbciplayer.bbciplayer_api.version
string version
Definition: bbciplayer_api.py:81
InputInfo::m_displayName
QString m_displayName
Definition: inputinfo.h:52
CardUtil::CreateInputGroup
static uint CreateInputGroup(const QString &name)
Definition: cardutil.cpp:1849
CardUtil::LinkInputGroup
static bool LinkInputGroup(uint inputid, uint inputgroupid)
Definition: cardutil.cpp:1928
DTVModulationSystem::kModulationSystem_DVBS
@ kModulationSystem_DVBS
Definition: dtvconfparserhelpers.h:661
videosource.h
DTVModulationSystem::kModulationSystem_DVBT
@ kModulationSystem_DVBT
Definition: dtvconfparserhelpers.h:659
diseqcsettings.h
CardUtil::SetASIMode
static bool SetASIMode(uint device_num, uint mode, QString *error=nullptr)
Definition: cardutil.cpp:3198
CardUtil::GetVideoDevice
static QString GetVideoDevice(uint inputid)
Definition: cardutil.h:284
DTVModulationSystem::kModulationSystem_DVBC_ANNEX_A
@ kModulationSystem_DVBC_ANNEX_A
Definition: dtvconfparserhelpers.h:657
InputInfo::m_name
QString m_name
input name
Definition: inputinfo.h:47
GetMythDownloadManager
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
Definition: mythdownloadmanager.cpp:145
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:827
write_sys
static bool write_sys(const QString &sys_dev, const QString &str)
Definition: cardutil.cpp:3051
DTVModulationSystem::Parse
bool Parse(const QString &_value)
Definition: dtvconfparserhelpers.h:716
CardUtil::GetASIMode
static int GetASIMode(uint device_num, QString *error=nullptr)
Definition: cardutil.cpp:3174
CardUtil::DeleteInput
static bool DeleteInput(uint inputid)
Definition: cardutil.cpp:2626