MythTV  master
satiputils.cpp
Go to the documentation of this file.
1 // C++
2 #include <chrono>
3 #include <thread>
4 
5 // Qt
6 #include <QString>
7 #include <QStringList>
8 
9 // MythTV headers
10 #include "cardutil.h"
11 #include "mythlogging.h"
12 #include "mythtimer.h"
13 #include "satiputils.h"
14 #include "ssdp.h"
15 
16 #define LOC QString("SatIP: ")
17 
18 static constexpr std::chrono::milliseconds SEARCH_TIME_MS { 3s };
19 #define SATIP_URI "urn:ses-com:device:SatIPServer:1"
20 
21 QStringList SatIP::probeDevices(void)
22 {
23  const std::chrono::milliseconds milliSeconds = SEARCH_TIME_MS;
24  auto seconds = duration_cast<std::chrono::seconds>(milliSeconds);
25 
26  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Using UPNP to search for Sat>IP servers (%1 secs)")
27  .arg(seconds.count()));
28 
30 
31  MythTimer totalTime; totalTime.start();
32  MythTimer searchTime; searchTime.start();
33 
34  while (totalTime.elapsed() < milliSeconds)
35  {
36  std::this_thread::sleep_for(25ms);
37  std::chrono::milliseconds ttl = milliSeconds - totalTime.elapsed();
38  if (searchTime.elapsed() > 249ms && ttl > 1s)
39  {
40  auto ttl_s = duration_cast<std::chrono::seconds>(ttl);
41  LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("UPNP search %1 ms")
42  .arg(ttl_s.count()));
44  searchTime.start();
45  }
46  }
47 
48  return SatIP::doUPNPsearch();
49 };
50 
51 QStringList SatIP::doUPNPsearch(void)
52 {
53  QStringList result;
54 
55  SSDPCacheEntries *satipservers = SSDP::Find(SATIP_URI);
56 
57  if (!satipservers)
58  {
59  LOG(VB_GENERAL, LOG_INFO, LOC + "No UPnP Sat>IP servers found");
60  return QStringList();
61  }
62 
63  int count = satipservers->Count();
64  if (count)
65  {
66  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Found %1 possible Sat>IP servers").arg(count));
67  }
68  else
69  {
70  LOG(VB_GENERAL, LOG_ERR, LOC + "No UPnP Sat>IP servers found, but SSDP::Find() != NULL");
71  }
72 
73  EntryMap map;
74  satipservers->GetEntryMap(map);
75 
76  for (auto *BE : qAsConst(map))
77  {
78  QString friendlyName = BE->GetFriendlyName();
79  UPnpDeviceDesc *desc = BE->GetDeviceDesc();
80 
81  if (!desc)
82  {
83  LOG(VB_GENERAL, LOG_ERR, LOC + QString("GetDeviceDesc() failed for %1").arg(friendlyName));
84  continue;
85  }
86 
87  QString ip = desc->m_hostUrl.host();
88  QString id = desc->m_rootDevice.GetUDN();
89  QList<NameValue> extraAttribs = desc->m_rootDevice.m_lstExtra;
90 
91  for (const auto& attrib : extraAttribs)
92  {
93  if (attrib.m_sName == "satip:X_SATIPCAP")
94  {
95  QStringList caps = attrib.m_sValue.split(",");
96 
97  for (const auto& cap : caps)
98  {
99  QStringList tuner = cap.split("-");
100 
101  if (tuner.size() != 2)
102  continue;
103 
104  int num_tuners = tuner.at(1).toInt();
105  for (int i = 0; i < num_tuners; i++)
106  {
107  QString device = QString("%1 %2 %3 %4 %5")
108  .arg(id,
109  friendlyName.remove(" "),
110  ip,
111  QString::number(i),
112  tuner.at(0));
113  result << device;
114  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Found %1").arg(device));
115  }
116  }
117  }
118  }
119  BE->DecrRef();
120  }
121 
122  satipservers->DecrRef();
123  satipservers = nullptr;
124 
125  return result;
126 };
127 
128 QString SatIP::findDeviceIP(const QString& deviceuuid)
129 {
130  QStringList devs = SatIP::probeDevices();
131 
132  for (const auto& dev : devs)
133  {
134  QStringList devinfo = dev.split(" ");
135  const QString& id = devinfo.at(0);
136 
137  if (id.toUpper() == deviceuuid.toUpper())
138  {
139  return devinfo.at(2);
140  }
141  }
142  return nullptr;
143 }
144 
146 {
147  QStringList dev = deviceid.split(":");
148  if (dev.length() < 3)
149  {
151  }
152 
153  QString type = dev.at(2).toUpper();
154  if (type == "DVBC")
155  {
156  return CardUtil::DVBC;
157  }
158  if (type == "DVBC2")
159  {
160  return CardUtil::DVBC; // DVB-C2 is not supported yet.
161  }
162  if (type == "DVBT")
163  {
164  return CardUtil::DVBT;
165  }
166  if (type == "DVBT2")
167  {
168  return CardUtil::DVBT2;
169  }
170  if (type == "DVBS2")
171  {
172  return CardUtil::DVBS2;
173  }
175 }
176 
177 int SatIP::toTunerType(const QString& deviceid)
178 {
179  QStringList devinfo = deviceid.split(":");
180  if (devinfo.length() < 3)
181  {
183  }
184 
185  QString type = devinfo.at(2).toUpper();
186 
187  if (type.startsWith("DVBC")) // DVB-C2 is not supported yet.
188  {
190  }
191  if (type == "DVBT")
192  {
194  }
195  if (type == "DVBT2")
196  {
198  }
199  if (type == "DVBS")
200  {
202  }
203  if (type == "DVBS2")
204  {
206  }
207 
209 }
210 
212 {
214  {
215  return "5";
216  }
218  {
219  return "6";
220  }
222  {
223  return "7";
224  }
226  {
227  return "8";
228  }
230  {
231  return "10";
232  }
234  {
235  return "1.712";
236  }
238  {
239  return "auto";
240  }
241  return "auto";
242 }
243 
244 QString SatIP::freq(uint64_t freq)
245 {
246  return QString::number(freq / 1000000.0, 'f', 2);
247 }
248 
250 {
252  {
253  return "dvbs";
254  }
256  {
257  return "dvbs2";
258  }
260  {
261  return "dvbt";
262  }
264  {
265  return "dvbt2";
266  }
268  {
269  return "dvbc";
270  }
271  // Not supported yet: DVB-C2
272  return "auto";
273 }
274 
276 {
278  {
279  return "qpsk";
280  }
282  {
283  return "8psk";
284  }
286  {
287  return "16qam";
288  }
290  {
291  return "32qam";
292  }
294  {
295  return "64qam";
296  }
298  {
299  return "128qam";
300  }
302  {
303  return "256qam";
304  }
305  return "auto";
306 }
307 
309 {
311  {
312  return "2k";
313  }
315  {
316  return "4k";
317  }
319  {
320  return "8k";
321  }
323  {
324  return "1k";
325  }
327  {
328  return "16k";
329  }
331  {
332  return "32k";
333  }
334  return "auto";
335 }
336 
338 {
340  {
341  return "14";
342  }
344  {
345  return "18";
346  }
348  {
349  return "116";
350  }
352  {
353  return "132";
354  }
356  {
357  return "1128";
358  }
360  {
361  return "19128";
362  }
364  {
365  return "19256";
366  }
367  return "auto";
368 }
369 
371 {
372  if (fec == DTVCodeRate::kFEC_1_2)
373  {
374  return "12";
375  }
376  if (fec == DTVCodeRate::kFEC_2_3)
377  {
378  return "23";
379  }
380  if (fec == DTVCodeRate::kFEC_3_4)
381  {
382  return "34";
383  }
384  if (fec == DTVCodeRate::kFEC_3_5)
385  {
386  return "35";
387  }
388  if (fec == DTVCodeRate::kFEC_4_5)
389  {
390  return "45";
391  }
392  if (fec == DTVCodeRate::kFEC_5_6)
393  {
394  return "56";
395  }
396  if (fec == DTVCodeRate::kFEC_6_7)
397  {
398  return "67";
399  }
400  if (fec == DTVCodeRate::kFEC_7_8)
401  {
402  return "78";
403  }
404  if (fec == DTVCodeRate::kFEC_8_9)
405  {
406  return "89";
407  }
409  {
410  return "910";
411  }
412  return "auto";
413 }
414 
416 {
418  {
419  return "0.35";
420  }
422  {
423  return "0.20";
424  }
426  {
427  return "0.25";
428  }
430  {
431  return "auto";
432  }
433  return "auto";
434 }
435 
437 {
439  {
440  return "v";
441  }
443  {
444  return "h";
445  }
447  {
448  return "r";
449  }
451  {
452  return "l";
453  }
454  return "auto";
455 }
DTVBandwidth::kBandwidth6MHz
@ kBandwidth6MHz
Definition: dtvconfparserhelpers.h:230
DTVGuardInterval::kGuardInterval_1_4
@ kGuardInterval_1_4
Definition: dtvconfparserhelpers.h:501
MythTimer::elapsed
std::chrono::milliseconds elapsed(void)
Returns milliseconds elapsed since last start() or restart()
Definition: mythtimer.cpp:91
DTVBandwidth
Definition: dtvconfparserhelpers.h:217
DTVCodeRate::kFEC_3_4
@ kFEC_3_4
Definition: dtvconfparserhelpers.h:294
DTVTunerType::kTunerTypeDVBC
static const int kTunerTypeDVBC
Definition: dtvconfparserhelpers.h:95
ReferenceCounter::DecrRef
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
Definition: referencecounter.cpp:125
DTVTransmitMode::kTransmissionMode32K
@ kTransmissionMode32K
Definition: dtvconfparserhelpers.h:441
SSDP::PerformSearch
void PerformSearch(const QString &sST, std::chrono::seconds timeout=2s)
Definition: ssdp.cpp:199
DTVTransmitMode::kTransmissionMode1K
@ kTransmissionMode1K
Definition: dtvconfparserhelpers.h:439
DTVModulationSystem::kModulationSystem_DVBS2
@ kModulationSystem_DVBS2
Definition: dtvconfparserhelpers.h:662
DTVCodeRate::kFEC_2_3
@ kFEC_2_3
Definition: dtvconfparserhelpers.h:293
MythTimer
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:13
SatIP::ro
static QString ro(DTVRollOff ro)
Definition: satiputils.cpp:415
CardUtil::ERROR_UNKNOWN
@ ERROR_UNKNOWN
Definition: cardutil.h:49
CardUtil::DVBT2
@ DVBT2
Definition: cardutil.h:68
SATIP_URI
#define SATIP_URI
Definition: satiputils.cpp:19
ssdp.h
DTVCodeRate::kFEC_5_6
@ kFEC_5_6
Definition: dtvconfparserhelpers.h:296
DTVTunerType::kTunerTypeDVBS1
static const int kTunerTypeDVBS1
Definition: dtvconfparserhelpers.h:93
freq
static const std::array< const uint32_t, 4 > freq
Definition: element.cpp:45
DTVTransmitMode::kTransmissionMode4K
@ kTransmissionMode4K
Definition: dtvconfparserhelpers.h:438
SatIP::bw
static QString bw(DTVBandwidth bw)
Definition: satiputils.cpp:211
UPnpDeviceDesc
Definition: upnpdevice.h:150
SSDP::Find
static SSDPCacheEntries * Find(const QString &sURI)
Definition: ssdp.h:126
DTVPolarity::kPolarityLeft
@ kPolarityLeft
Definition: dtvconfparserhelpers.h:617
MythTimer::start
void start(void)
starts measuring elapsed time.
Definition: mythtimer.cpp:47
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
DTVRollOff::kRollOff_35
@ kRollOff_35
Definition: dtvconfparserhelpers.h:736
SatIP::tmode
static QString tmode(DTVTransmitMode tmode)
Definition: satiputils.cpp:308
SSDPCacheEntries::GetEntryMap
void GetEntryMap(EntryMap &map)
Returns a copy of the EntryMap.
Definition: ssdpcache.cpp:92
SatIP::doUPNPsearch
static QStringList doUPNPsearch(void)
Definition: satiputils.cpp:51
DTVModulation::kModulationQPSK
@ kModulationQPSK
Definition: dtvconfparserhelpers.h:358
DTVGuardInterval
Definition: dtvconfparserhelpers.h:487
SatIP::findDeviceIP
static QString findDeviceIP(const QString &deviceuuid)
Definition: satiputils.cpp:128
DTVCodeRate
Definition: dtvconfparserhelpers.h:280
satiputils.h
DTVModulation::kModulationQAM256
@ kModulationQAM256
Definition: dtvconfparserhelpers.h:363
SSDP::Instance
static SSDP * Instance()
Definition: ssdp.cpp:52
SEARCH_TIME_MS
static constexpr std::chrono::milliseconds SEARCH_TIME_MS
Definition: satiputils.cpp:18
DTVGuardInterval::kGuardInterval_1_16
@ kGuardInterval_1_16
Definition: dtvconfparserhelpers.h:499
UPnpDeviceDesc::m_rootDevice
UPnpDevice m_rootDevice
Definition: upnpdevice.h:154
DTVModulation::kModulationQAM16
@ kModulationQAM16
Definition: dtvconfparserhelpers.h:359
CardUtil::DVBS2
@ DVBS2
Definition: cardutil.h:61
DTVCodeRate::kFEC_1_2
@ kFEC_1_2
Definition: dtvconfparserhelpers.h:292
mythlogging.h
SatIP::probeDevices
static QStringList probeDevices(void)
Definition: satiputils.cpp:21
DTVPolarity::kPolarityVertical
@ kPolarityVertical
Definition: dtvconfparserhelpers.h:614
UPnpDevice::m_lstExtra
NameValues m_lstExtra
Definition: upnpdevice.h:118
DTVTunerType::kTunerTypeUnknown
static const int kTunerTypeUnknown
Definition: dtvconfparserhelpers.h:103
LOC
#define LOC
Definition: satiputils.cpp:16
SatIP::toTunerType
static int toTunerType(const QString &deviceid)
Definition: satiputils.cpp:177
DTVCodeRate::kFEC_3_5
@ kFEC_3_5
Definition: dtvconfparserhelpers.h:301
DTVTransmitMode
Definition: dtvconfparserhelpers.h:424
DTVGuardInterval::kGuardInterval_19_256
@ kGuardInterval_19_256
Definition: dtvconfparserhelpers.h:505
DTVModulation::kModulationQAM128
@ kModulationQAM128
Definition: dtvconfparserhelpers.h:362
EntryMap
QMap< QString, DeviceLocation * > EntryMap
Key == Unique Service Name (USN)
Definition: ssdpcache.h:28
SatIP::toDVBInputType
static CardUtil::INPUT_TYPES toDVBInputType(const QString &deviceid)
Definition: satiputils.cpp:145
DTVModulation::kModulationQAM32
@ kModulationQAM32
Definition: dtvconfparserhelpers.h:360
UPnpDeviceDesc::m_hostUrl
QUrl m_hostUrl
Definition: upnpdevice.h:156
SatIP::freq
static QString freq(uint64_t freq)
Definition: satiputils.cpp:244
SatIP::gi
static QString gi(DTVGuardInterval gi)
Definition: satiputils.cpp:337
SSDPCacheEntries
Definition: ssdpcache.h:34
SatIP::pol
static QString pol(DTVPolarity pol)
Definition: satiputils.cpp:436
DTVTransmitMode::kTransmissionMode16K
@ kTransmissionMode16K
Definition: dtvconfparserhelpers.h:440
CardUtil::DVBC
@ DVBC
Definition: cardutil.h:52
DTVBandwidth::kBandwidthAuto
@ kBandwidthAuto
Definition: dtvconfparserhelpers.h:231
DTVBandwidth::kBandwidth5MHz
@ kBandwidth5MHz
Definition: dtvconfparserhelpers.h:232
DTVRollOff::kRollOff_Auto
@ kRollOff_Auto
Definition: dtvconfparserhelpers.h:739
DTVTunerType::kTunerTypeDVBS2
static const int kTunerTypeDVBS2
Definition: dtvconfparserhelpers.h:94
DTVRollOff::kRollOff_20
@ kRollOff_20
Definition: dtvconfparserhelpers.h:737
DTVModulationSystem
Definition: dtvconfparserhelpers.h:644
cardutil.h
DTVTransmitMode::kTransmissionMode8K
@ kTransmissionMode8K
Definition: dtvconfparserhelpers.h:436
DTVPolarity::kPolarityRight
@ kPolarityRight
Definition: dtvconfparserhelpers.h:616
DTVBandwidth::kBandwidth1712kHz
@ kBandwidth1712kHz
Definition: dtvconfparserhelpers.h:234
DTVTransmitMode::kTransmissionMode2K
@ kTransmissionMode2K
Definition: dtvconfparserhelpers.h:435
DTVRollOff::kRollOff_25
@ kRollOff_25
Definition: dtvconfparserhelpers.h:738
SatIP::fec
static QString fec(DTVCodeRate fec)
Definition: satiputils.cpp:370
mythtimer.h
DTVGuardInterval::kGuardInterval_1_32
@ kGuardInterval_1_32
Definition: dtvconfparserhelpers.h:498
DTVBandwidth::kBandwidth8MHz
@ kBandwidth8MHz
Definition: dtvconfparserhelpers.h:228
DTVCodeRate::kFEC_7_8
@ kFEC_7_8
Definition: dtvconfparserhelpers.h:298
DTVModulationSystem::kModulationSystem_DVBT2
@ kModulationSystem_DVBT2
Definition: dtvconfparserhelpers.h:672
DTVTunerType::kTunerTypeDVBT
static const int kTunerTypeDVBT
Definition: dtvconfparserhelpers.h:96
DTVPolarity::kPolarityHorizontal
@ kPolarityHorizontal
Definition: dtvconfparserhelpers.h:615
DTVCodeRate::kFEC_9_10
@ kFEC_9_10
Definition: dtvconfparserhelpers.h:302
UPnpDevice::GetUDN
QString GetUDN(void) const
Definition: upnpdevice.cpp:766
SSDPCacheEntries::Count
uint Count(void) const
Definition: ssdpcache.h:44
SatIP::msys
static QString msys(DTVModulationSystem msys)
Definition: satiputils.cpp:249
DTVTunerType::kTunerTypeDVBT2
static const int kTunerTypeDVBT2
Definition: dtvconfparserhelpers.h:97
DTVCodeRate::kFEC_8_9
@ kFEC_8_9
Definition: dtvconfparserhelpers.h:299
SatIP::mtype
static QString mtype(DTVModulation mtype)
Definition: satiputils.cpp:275
DTVModulation::kModulationQAM64
@ kModulationQAM64
Definition: dtvconfparserhelpers.h:361
DTVBandwidth::kBandwidth10MHz
@ kBandwidth10MHz
Definition: dtvconfparserhelpers.h:233
DTVCodeRate::kFEC_6_7
@ kFEC_6_7
Definition: dtvconfparserhelpers.h:297
DTVBandwidth::kBandwidth7MHz
@ kBandwidth7MHz
Definition: dtvconfparserhelpers.h:229
DTVModulationSystem::kModulationSystem_DVBS
@ kModulationSystem_DVBS
Definition: dtvconfparserhelpers.h:661
DTVGuardInterval::kGuardInterval_1_8
@ kGuardInterval_1_8
Definition: dtvconfparserhelpers.h:500
DTVModulationSystem::kModulationSystem_DVBT
@ kModulationSystem_DVBT
Definition: dtvconfparserhelpers.h:659
DTVModulation::kModulation8PSK
@ kModulation8PSK
Definition: dtvconfparserhelpers.h:367
CardUtil::DVBT
@ DVBT
Definition: cardutil.h:53
DTVPolarity
Definition: dtvconfparserhelpers.h:605
DTVModulation
Definition: dtvconfparserhelpers.h:347
DTVGuardInterval::kGuardInterval_19_128
@ kGuardInterval_19_128
Definition: dtvconfparserhelpers.h:504
DTVModulationSystem::kModulationSystem_DVBC_ANNEX_A
@ kModulationSystem_DVBC_ANNEX_A
Definition: dtvconfparserhelpers.h:657
DTVCodeRate::kFEC_4_5
@ kFEC_4_5
Definition: dtvconfparserhelpers.h:295
CardUtil::INPUT_TYPES
INPUT_TYPES
all the different inputs
Definition: cardutil.h:46
DTVGuardInterval::kGuardInterval_1_128
@ kGuardInterval_1_128
Definition: dtvconfparserhelpers.h:503
DTVRollOff
Definition: dtvconfparserhelpers.h:725