Ticket #13339: hdhr-locking-pooling-4.patch
File hdhr-locking-pooling-4.patch, 34.5 KB (added by , 5 years ago) |
---|
-
mythtv/libs/libmythtv/cardutil.cpp
diff --git a/mythtv/libs/libmythtv/cardutil.cpp b/mythtv/libs/libmythtv/cardutil.cpp index bf797e6a57..58bf4735bb 100644
a b QStringList CardUtil::ProbeVideoDevices(const QString &rawtype) 540 540 .arg((result_list[i].ip_addr>> 8) & 0xFF) 541 541 .arg((result_list[i].ip_addr>> 0) & 0xFF); 542 542 543 for (int tuner = 0; tuner < result_list[i].tuner_count; tuner++) 543 QString hwmodel = ""; 544 hdhomerun_device_t *device = hdhomerun_device_create( 545 result_list[i].device_id, 0, 0, nullptr); 546 if (device) 544 547 { 545 QString hdhrdev = id.toUpper() + " " + ip + " " + 546 QString("%1").arg(tuner); 547 devs.push_back(hdhrdev); 548 hwmodel = hdhomerun_device_get_hw_model_str(device); 549 hdhomerun_device_destroy(device); 548 550 } 551 552 QString hdhrdev = id.toUpper() + " " + ip + " " + hwmodel; 553 devs.push_back(hdhrdev); 549 554 } 550 555 } 551 556 #endif // USING_HDHOMERUN … … uint CardUtil::CreateDeviceInputGroup(uint inputid, 1396 1401 { 1397 1402 QString name = host + '|' + device; 1398 1403 if (type == "FREEBOX" || type == "IMPORT" || 1399 type == "DEMO" || type == "EXTERNAL") 1404 type == "DEMO" || type == "EXTERNAL" || 1405 type == "HDHOMERUN") 1400 1406 name += QString("|%1").arg(inputid); 1401 1407 return CreateInputGroup(name); 1402 1408 } -
mythtv/libs/libmythtv/recorders/channelbase.cpp
diff --git a/mythtv/libs/libmythtv/recorders/channelbase.cpp b/mythtv/libs/libmythtv/recorders/channelbase.cpp index 04d46da5e7..281583fb44 100644
a b ChannelBase *ChannelBase::CreateChannel( 805 805 { 806 806 if (channel && 807 807 ((genOpt.inputtype == "DVB" && dvbOpt.dvb_on_demand) || 808 genOpt.inputtype == "HDHOMERUN" || 808 809 CardUtil::IsV4L(genOpt.inputtype))) 809 810 { 810 811 channel->Close(); … … bool ChannelBase::IsExternalChannelChangeInUse(void) 835 836 836 837 return !m_externalChanger.isEmpty(); 837 838 } 839 840 int ChannelBase::GetMajorID(void) 841 { 842 return m_pParent ? m_pParent->GetMajorId() : m_inputid; 843 } -
mythtv/libs/libmythtv/recorders/channelbase.h
diff --git a/mythtv/libs/libmythtv/recorders/channelbase.h b/mythtv/libs/libmythtv/recorders/channelbase.h index 7711e10650..a326faffc6 100644
a b class ChannelBase 100 100 // \brief Set inputid for scanning 101 101 void SetInputID(uint _inputid) { m_inputid = _inputid; } 102 102 103 // \brief Get major input ID 104 int GetMajorID(void); 105 103 106 static ChannelBase *CreateChannel( 104 107 TVRec *tv_rec, 105 108 const GeneralDBOptions &genOpt, -
mythtv/libs/libmythtv/recorders/hdhrchannel.cpp
diff --git a/mythtv/libs/libmythtv/recorders/hdhrchannel.cpp b/mythtv/libs/libmythtv/recorders/hdhrchannel.cpp index 448a75635e..133fe827e1 100644
a b bool HDHRChannel::Open(void) 59 59 if (IsOpen()) 60 60 return true; 61 61 62 _stream_handler = HDHRStreamHandler::Get(_device_id, GetInputID()); 62 _stream_handler = HDHRStreamHandler::Get(GetDevice(), GetInputID(), 63 GetMajorID()); 63 64 64 65 _tuner_types = _stream_handler->GetTunerTypes(); 65 66 tunerType = (_tuner_types.empty()) ? … … void HDHRChannel::Close(void) 86 87 87 88 bool HDHRChannel::EnterPowerSavingMode(void) 88 89 { 89 if (IsOpen()) 90 return _stream_handler->EnterPowerSavingMode(); 91 else 92 return true; 90 Close(); 91 return true; 93 92 } 94 93 95 94 bool HDHRChannel::IsOpen(void) const -
mythtv/libs/libmythtv/recorders/hdhrrecorder.cpp
diff --git a/mythtv/libs/libmythtv/recorders/hdhrrecorder.cpp b/mythtv/libs/libmythtv/recorders/hdhrrecorder.cpp index 1138c8d046..f85c0015b5 100644
a b bool HDHRRecorder::Open(void) 36 36 ResetForNewFile(); 37 37 38 38 _stream_handler = HDHRStreamHandler::Get(_channel->GetDevice(), 39 (tvrec ? tvrec->GetInputId() : -1)); 39 _channel->GetInputID(), 40 _channel->GetMajorID()); 40 41 41 42 LOG(VB_RECORD, LOG_INFO, LOC + "HDHR opened successfully"); 42 43 -
mythtv/libs/libmythtv/recorders/hdhrsignalmonitor.cpp
diff --git a/mythtv/libs/libmythtv/recorders/hdhrsignalmonitor.cpp b/mythtv/libs/libmythtv/recorders/hdhrsignalmonitor.cpp index 71c0438a13..45c4857d98 100644
a b HDHRSignalMonitor::HDHRSignalMonitor(int db_cardnum, 51 51 52 52 AddFlags(kSigMon_WaitForSig); 53 53 54 streamHandler = HDHRStreamHandler::Get(channel->GetDevice(), inputid); 54 streamHandler = HDHRStreamHandler::Get(channel->GetDevice(), 55 channel->GetInputID(), 56 channel->GetMajorID()); 55 57 } 56 58 57 59 /** \fn HDHRSignalMonitor::~HDHRSignalMonitor() -
mythtv/libs/libmythtv/recorders/hdhrstreamhandler.cpp
diff --git a/mythtv/libs/libmythtv/recorders/hdhrstreamhandler.cpp b/mythtv/libs/libmythtv/recorders/hdhrstreamhandler.cpp index 4254732c82..644e7dfd8b 100644
a b 21 21 22 22 #define LOC QString("HDHRSH[%1](%2): ").arg(_inputid).arg(_device) 23 23 24 QMap< QString,HDHRStreamHandler*>HDHRStreamHandler::_handlers;25 QMap< QString,uint>HDHRStreamHandler::_handlers_refcnt;24 QMap<int,HDHRStreamHandler*> HDHRStreamHandler::_handlers; 25 QMap<int,uint> HDHRStreamHandler::_handlers_refcnt; 26 26 QMutex HDHRStreamHandler::_handlers_lock; 27 27 28 28 HDHRStreamHandler *HDHRStreamHandler::Get(const QString &devname, 29 int inputid )29 int inputid, int majorid) 30 30 { 31 31 QMutexLocker locker(&_handlers_lock); 32 32 33 QString devkey = devname.toUpper(); 34 35 QMap<QString,HDHRStreamHandler*>::iterator it = _handlers.find(devkey); 33 QMap<int,HDHRStreamHandler*>::iterator it = _handlers.find(majorid); 36 34 37 35 if (it == _handlers.end()) 38 36 { 39 HDHRStreamHandler *newhandler = new HDHRStreamHandler(devkey, inputid); 37 HDHRStreamHandler *newhandler = new HDHRStreamHandler(devname, inputid, 38 majorid); 40 39 newhandler->Open(); 41 _handlers[ devkey] = newhandler;42 _handlers_refcnt[ devkey] = 1;40 _handlers[majorid] = newhandler; 41 _handlers_refcnt[majorid] = 1; 43 42 44 43 LOG(VB_RECORD, LOG_INFO, 45 44 QString("HDHRSH[%1]: Creating new stream handler %2 for %3") 46 .arg(inputid).arg( devkey).arg(devname));45 .arg(inputid).arg(majorid).arg(devname)); 47 46 } 48 47 else 49 48 { 50 _handlers_refcnt[ devkey]++;51 uint rcount = _handlers_refcnt[ devkey];49 _handlers_refcnt[majorid]++; 50 uint rcount = _handlers_refcnt[majorid]; 52 51 LOG(VB_RECORD, LOG_INFO, 53 52 QString("HDHRSH[%1]: Using existing stream handler %2 for %3") 54 .arg(inputid).arg( devkey)53 .arg(inputid).arg(majorid) 55 54 .arg(devname) + QString(" (%1 in use)").arg(rcount)); 56 55 } 57 56 58 return _handlers[ devkey];57 return _handlers[majorid]; 59 58 } 60 59 61 60 void HDHRStreamHandler::Return(HDHRStreamHandler * & ref, int inputid) 62 61 { 63 62 QMutexLocker locker(&_handlers_lock); 64 63 65 QString devname = ref->_device;64 int majorid = ref->_majorid; 66 65 67 QMap< QString,uint>::iterator rit = _handlers_refcnt.find(devname);66 QMap<int,uint>::iterator rit = _handlers_refcnt.find(majorid); 68 67 if (rit == _handlers_refcnt.end()) 69 68 return; 70 69 71 QMap< QString,HDHRStreamHandler*>::iterator it = _handlers.find(devname);70 QMap<int,HDHRStreamHandler*>::iterator it = _handlers.find(majorid); 72 71 if (*rit > 1) 73 72 { 74 73 ref = nullptr; … … void HDHRStreamHandler::Return(HDHRStreamHandler * & ref, int inputid) 79 78 if ((it != _handlers.end()) && (*it == ref)) 80 79 { 81 80 LOG(VB_RECORD, LOG_INFO, QString("HDHRSH[%1]: Closing handler for %2") 82 .arg(inputid).arg( devname));81 .arg(inputid).arg(majorid)); 83 82 ref->Close(); 84 83 delete *it; 85 84 _handlers.erase(it); … … void HDHRStreamHandler::Return(HDHRStreamHandler * & ref, int inputid) 88 87 { 89 88 LOG(VB_GENERAL, LOG_ERR, 90 89 QString("HDHRSH[%1] Error: Couldn't find handler for %2") 91 .arg(inputid).arg( devname));90 .arg(inputid).arg(majorid)); 92 91 } 93 92 94 93 _handlers_refcnt.erase(rit); 95 94 ref = nullptr; 96 95 } 97 96 98 HDHRStreamHandler::HDHRStreamHandler(const QString &device, int inputid) 97 HDHRStreamHandler::HDHRStreamHandler(const QString &device, int inputid, 98 int majorid) 99 99 : StreamHandler(device, inputid) 100 100 , _hdhomerun_device(nullptr) 101 101 , _tuner(-1) 102 102 , _tune_mode(hdhrTuneModeNone) 103 , _majorid(majorid) 103 104 , _hdhr_lock(QMutex::Recursive) 104 105 { 105 106 setObjectName("HDHRStreamHandler"); … … HDHRStreamHandler::HDHRStreamHandler(const QString &device, int inputid) 110 111 */ 111 112 void HDHRStreamHandler::run(void) 112 113 { 113 int tunerLock = 0;114 char *error = nullptr;115 116 114 RunProlog(); 117 /* Get a tuner lock */ 118 tunerLock = hdhomerun_device_tuner_lockkey_request(_hdhomerun_device, &error); 119 if(tunerLock < 1) 120 { 121 LOG(VB_GENERAL, LOG_ERR, LOC + 122 QString("Get tuner lock failed. Aborting. Error: %1").arg(error)); 123 _error = true; 124 RunEpilog(); 125 return; 126 } 115 127 116 /* Create TS socket. */ 128 117 if (!hdhomerun_device_stream_start(_hdhomerun_device)) 129 118 { … … void HDHRStreamHandler::run(void) 221 210 222 211 LOG(VB_RECORD, LOG_INFO, LOC + "RunTS(): " + "end"); 223 212 224 if(tunerLock == 1)225 {226 LOG(VB_RECORD, LOG_INFO, LOC + "Release tuner lock.");227 hdhomerun_device_tuner_lockkey_release(_hdhomerun_device);228 }229 230 213 SetRunning(false, false, false); 214 231 215 RunEpilog(); 232 216 } 233 217 … … void HDHRStreamHandler::Close(void) 361 345 if (_hdhomerun_device) 362 346 { 363 347 TuneChannel("none"); 364 hdhomerun_device_ destroy(_hdhomerun_device);348 hdhomerun_device_tuner_lockkey_release(_hdhomerun_device); 365 349 _hdhomerun_device = nullptr; 366 350 } 351 if (_device_selector) 352 { 353 hdhomerun_device_selector_destroy(_device_selector, true); 354 _device_selector = nullptr; 355 } 367 356 } 368 357 369 358 bool HDHRStreamHandler::Connect(void) 370 359 { 371 _hdhomerun_device = hdhomerun_device_create_from_str( 372 _device.toLocal8Bit().constData(), nullptr); 373 374 if (!_hdhomerun_device) 360 _device_selector = hdhomerun_device_selector_create(nullptr); 361 if (!_device_selector) 375 362 { 376 LOG(VB_GENERAL, LOG_ERR, LOC + "Unable to create hdhomerun object");363 LOG(VB_GENERAL, LOG_ERR, LOC + "Unable to create device selector"); 377 364 return false; 378 365 } 379 366 380 _tuner = hdhomerun_device_get_tuner(_hdhomerun_device); 367 QStringList devices = _device.split(","); 368 for (int i = 0; i < devices.size(); ++i) 369 { 370 QByteArray ba = devices[i].toUtf8(); 371 int n = hdhomerun_device_selector_load_from_str( 372 _device_selector, ba.data()); 373 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Added %1 devices from %3") 374 .arg(n).arg(devices[i])); 375 } 381 376 382 if (hdhomerun_device_get_local_machine_addr(_hdhomerun_device) == 0) 377 _hdhomerun_device = hdhomerun_device_selector_choose_and_lock( 378 _device_selector, nullptr); 379 if (!_hdhomerun_device) 383 380 { 384 LOG(VB_GENERAL, LOG_ERR, LOC + "Unable to connect to device"); 381 LOG(VB_GENERAL, LOG_ERR, LOC + 382 QString("Unable to find a free device")); 383 hdhomerun_device_selector_destroy(_device_selector, true); 384 _device_selector = nullptr; 385 385 return false; 386 386 } 387 387 388 LOG(VB_RECORD, LOG_INFO, LOC + "Successfully connected to device"); 389 return true; 390 } 388 _tuner = hdhomerun_device_get_tuner(_hdhomerun_device); 391 389 392 bool HDHRStreamHandler::EnterPowerSavingMode(void) 393 { 394 QMutexLocker locker(&_listener_lock);390 LOG(VB_GENERAL, LOG_INFO, LOC + 391 QString("Connected to device(%1)") 392 .arg(hdhomerun_device_get_name(_hdhomerun_device))); 395 393 396 if (!_stream_data_list.empty()) 397 { 398 LOG(VB_RECORD, LOG_INFO, LOC + 399 "Ignoring request - video streaming active"); 400 return false; 401 } 402 else 403 { 404 locker.unlock(); // _listener_lock 405 return TuneChannel("none"); 406 } 394 return true; 407 395 } 408 396 409 397 QString HDHRStreamHandler::TunerGet( -
mythtv/libs/libmythtv/recorders/hdhrstreamhandler.h
diff --git a/mythtv/libs/libmythtv/recorders/hdhrstreamhandler.h b/mythtv/libs/libmythtv/recorders/hdhrstreamhandler.h index 70f8ae1853..02cb7f27b3 100644
a b class DeviceReadBuffer; 30 30 #endif 31 31 #else 32 32 struct hdhomerun_device_t { int dummy; }; 33 struct hdhomerun_device_selector_t { int dummy; }; 33 34 #endif 34 35 35 36 enum HDHRTuneMode { … … enum HDHRTuneMode { 49 50 class HDHRStreamHandler : public StreamHandler 50 51 { 51 52 public: 52 static HDHRStreamHandler *Get(const QString &devicename, int inputid); 53 static HDHRStreamHandler *Get(const QString &devicename, int inputid, 54 int majorid); 53 55 static void Return(HDHRStreamHandler * & ref, int inputid); 54 56 55 57 void AddListener(MPEGStreamData *data, … … class HDHRStreamHandler : public StreamHandler 68 70 bool TuneChannel(const QString &chanid); 69 71 bool TuneProgram(uint mpeg_prog_num); 70 72 bool TuneVChannel(const QString &vchn); 71 bool EnterPowerSavingMode(void);72 73 73 74 private: 74 explicit HDHRStreamHandler(const QString &, int inputid );75 explicit HDHRStreamHandler(const QString &, int inputid, int majorid); 75 76 76 77 bool Connect(void); 77 78 … … class HDHRStreamHandler : public StreamHandler 91 92 92 93 private: 93 94 hdhomerun_device_t *_hdhomerun_device; 95 hdhomerun_device_selector_t *_device_selector; 94 96 int _tuner; 95 97 vector<DTVTunerType> _tuner_types; 96 98 HDHRTuneMode _tune_mode; // debug self check 99 int _majorid; 97 100 98 101 mutable QMutex _hdhr_lock; 99 102 100 103 // for implementing Get & Return 101 104 static QMutex _handlers_lock; 102 static QMap< QString, HDHRStreamHandler*>_handlers;103 static QMap< QString, uint>_handlers_refcnt;105 static QMap<int, HDHRStreamHandler*> _handlers; 106 static QMap<int, uint> _handlers_refcnt; 104 107 }; 105 108 106 109 #endif // _HDHRSTREAMHANDLER_H_ -
mythtv/libs/libmythtv/tv_rec.h
diff --git a/mythtv/libs/libmythtv/tv_rec.h b/mythtv/libs/libmythtv/tv_rec.h index a493582d47..3d8321a339 100644
a b class MTV_PUBLIC TVRec : public SignalMonitorListener, public QRunnable 240 240 /// \brief Returns the inputid 241 241 uint GetInputId(void) { return inputid; } 242 242 uint GetParentId(void) { return parentid; } 243 uint GetMajorId(void) { return parentid ? parentid : inputid; } 243 244 /// \brief Returns true is "errored" is true, false otherwise. 244 245 bool IsErrored(void) const { return HasFlags(kFlagErrored); } 245 246 -
mythtv/libs/libmythtv/videosource.cpp
diff --git a/mythtv/libs/libmythtv/videosource.cpp b/mythtv/libs/libmythtv/videosource.cpp index 13d008bec5..06bffe4b38 100644
a b static void FirewireConfigurationGroup(CaptureCard& parent, CardType& cardtype) 1383 1383 // HDHomeRun Configuration 1384 1384 // ----------------------- 1385 1385 1386 HDHomeRunIP::HDHomeRunIP() 1386 HDHomeRunDeviceID::HDHomeRunDeviceID(const CaptureCard &parent, 1387 HDHomeRunConfigurationGroup &_group) : 1388 MythUITextEditSetting( 1389 new CaptureCardDBStorage(this, parent, "videodevice")), 1390 group(_group) 1387 1391 { 1388 setLabel(QObject::tr("IP Address")); 1389 setEnabled(false); 1390 connect(this, SIGNAL(valueChanged( const QString&)), 1391 this, SLOT( UpdateDevices(const QString&))); 1392 _oldValue=""; 1393 }; 1394 1395 void HDHomeRunIP::setEnabled(bool e) 1396 { 1397 MythUITextEditSetting::setEnabled(e); 1398 if (e) 1399 { 1400 if (!_oldValue.isEmpty()) 1401 setValue(_oldValue); 1402 emit NewIP(getValue()); 1403 } 1404 else 1405 { 1406 _oldValue = getValue(); 1407 _oldValue.detach(); 1408 } 1409 } 1410 1411 void HDHomeRunIP::UpdateDevices(const QString &v) 1412 { 1413 if (isEnabled()) 1414 { 1415 #if 0 1416 LOG(VB_GENERAL, LOG_DEBUG, QString("Emitting NewIP(%1)").arg(v)); 1417 #endif 1418 emit NewIP(v); 1419 } 1420 } 1421 1422 HDHomeRunTunerIndex::HDHomeRunTunerIndex() 1423 { 1424 setLabel(QObject::tr("Tuner")); 1425 setEnabled(false); 1426 connect(this, SIGNAL(valueChanged( const QString&)), 1427 this, SLOT( UpdateDevices(const QString&))); 1428 _oldValue = ""; 1392 setVisible(false); 1429 1393 }; 1430 1394 1431 void HDHomeRunTunerIndex::setEnabled(bool e)1432 {1433 MythUITextEditSetting::setEnabled(e);1434 if (e) {1435 if (!_oldValue.isEmpty())1436 setValue(_oldValue);1437 emit NewTuner(getValue());1438 }1439 else1440 {1441 _oldValue = getValue();1442 }1443 }1444 1445 void HDHomeRunTunerIndex::UpdateDevices(const QString &v)1446 {1447 if (isEnabled())1448 {1449 #if 01450 LOG(VB_GENERAL, LOG_DEBUG, QString("Emitting NewTuner(%1)").arg(v));1451 #endif1452 emit NewTuner(v);1453 }1454 }1455 1456 HDHomeRunDeviceID::HDHomeRunDeviceID(const CaptureCard &parent) :1457 MythUITextEditSetting(new CaptureCardDBStorage(this, parent, "videodevice"))1458 {1459 setLabel(tr("Device ID"));1460 setHelpText(tr("Device ID of HDHomeRun device"));1461 setEnabled(false);1462 }1463 1464 void HDHomeRunDeviceID::SetIP(const QString &ip)1465 {1466 #if 01467 LOG(VB_GENERAL, LOG_DEBUG, QString("Setting IP to %1").arg(ip));1468 #endif1469 _ip = ip;1470 setValue(QString("%1-%2").arg(_ip).arg(_tuner));1471 #if 01472 LOG(VB_GENERAL, LOG_DEBUG, QString("Done Setting IP to %1").arg(ip));1473 #endif1474 }1475 1476 void HDHomeRunDeviceID::SetTuner(const QString &tuner)1477 {1478 #if 01479 LOG(VB_GENERAL, LOG_DEBUG, QString("Setting Tuner to %1").arg(tuner));1480 #endif1481 _tuner = tuner;1482 setValue(QString("%1-%2").arg(_ip).arg(_tuner));1483 #if 01484 LOG(VB_GENERAL, LOG_DEBUG, QString("Done Setting Tuner to %1").arg(tuner));1485 #endif1486 }1487 1488 void HDHomeRunDeviceID::SetOverrideDeviceID(const QString &deviceid)1489 {1490 _overridedeviceid = deviceid;1491 setValue(deviceid);1492 }1493 1494 1395 void HDHomeRunDeviceID::Load(void) 1495 1396 { 1496 GetStorage()->Load(); 1497 if (!_overridedeviceid.isEmpty()) 1498 { 1499 setValue(_overridedeviceid); 1500 _overridedeviceid.clear(); 1501 } 1502 } 1503 1504 HDHomeRunDeviceIDList::HDHomeRunDeviceIDList( 1505 HDHomeRunDeviceID *deviceid, 1506 StandardSetting *desc, 1507 HDHomeRunIP *cardip, 1508 HDHomeRunTunerIndex *cardtuner, 1509 HDHomeRunDeviceList *devicelist, 1510 const CaptureCard &parent) : 1511 _deviceid(deviceid), 1512 _desc(desc), 1513 _cardip(cardip), 1514 _cardtuner(cardtuner), 1515 _devicelist(devicelist), 1516 m_parent(parent) 1517 { 1518 setLabel(QObject::tr("Available devices")); 1519 setHelpText( 1520 QObject::tr( 1521 "Device ID and Tuner Number of available HDHomeRun devices.")); 1522 1523 connect(this, SIGNAL(valueChanged( const QString&)), 1524 this, SLOT( UpdateDevices(const QString&))); 1525 1526 _oldValue = ""; 1527 }; 1528 1529 /// \brief Adds all available device-tuner combinations to list 1530 /// If current is >= 0 it will be considered available even 1531 /// if no device exists for it on the network 1532 void HDHomeRunDeviceIDList::fillSelections(const QString &cur) 1533 { 1534 clearSelections(); 1535 1536 vector<QString> devs; 1537 QMap<QString, bool> in_use; 1538 1539 QString current = cur; 1540 1541 #if 0 1542 LOG(VB_GENERAL, LOG_DEBUG, QString("Filling List, current = '%1'") 1543 .arg(current)); 1544 #endif 1545 1546 HDHomeRunDeviceList::iterator it = _devicelist->begin(); 1547 for (; it != _devicelist->end(); ++it) 1548 { 1549 if ((*it).discovered) 1550 { 1551 devs.push_back(it.key()); 1552 in_use[it.key()] = (*it).inuse; 1553 } 1554 } 1555 1556 QString man_addr = HDHomeRunDeviceIDList::tr("Manually Enter IP Address"); 1557 QString sel = man_addr; 1558 devs.push_back(sel); 1559 1560 if (3 == devs.size() && current.startsWith("FFFFFFFF", Qt::CaseInsensitive)) 1561 { 1562 current = sel = (current.endsWith("0")) ? 1563 *(devs.begin()) : *(++devs.begin()); 1564 } 1565 else 1566 { 1567 vector<QString>::const_iterator it = devs.begin(); 1568 for (; it != devs.end(); ++it) 1569 sel = (current == *it) ? *it : sel; 1570 } 1571 1572 QString usestr = QString(" -- "); 1573 usestr += QObject::tr("Warning: already in use"); 1574 1575 for (uint i = 0; i < devs.size(); i++) 1576 { 1577 const QString dev = devs[i]; 1578 QString desc = dev + (in_use[devs[i]] ? usestr : ""); 1579 desc = (current == devs[i]) ? dev : desc; 1580 addSelection(desc, dev, dev == sel); 1581 } 1582 1583 if (current != cur) 1584 { 1585 _deviceid->SetOverrideDeviceID(current); 1586 } 1587 else if (sel == man_addr && !current.isEmpty()) 1588 { 1589 // Populate the proper values for IP address and tuner 1590 QStringList selection = current.split("-"); 1591 1592 _cardip->SetOldValue(selection.first()); 1593 _cardtuner->SetOldValue(selection.last()); 1594 1595 _cardip->setValue(selection.first()); 1596 _cardtuner->setValue(selection.last()); 1597 } 1397 MythUITextEditSetting::Load(); 1398 group.SetDeviceCheckBoxes(getValue()); 1598 1399 } 1599 1400 1600 void HDHomeRunDeviceID List::Load(void)1401 void HDHomeRunDeviceID::Save(void) 1601 1402 { 1602 clearSelections(); 1603 1604 int cardid = m_parent.getCardID(); 1605 QString device = CardUtil::GetVideoDevice(cardid); 1606 fillSelections(device); 1403 setValue(group.GetDeviceCheckBoxes()); 1404 MythUITextEditSetting::Save(); 1607 1405 } 1608 1406 1609 void HDHomeRunDeviceIDList::UpdateDevices(const QString &v)1610 {1611 #if 01612 LOG(VB_GENERAL, LOG_DEBUG, QString("Got signal with %1").arg(v));1613 #endif1614 if (v == HDHomeRunDeviceIDList::tr("Manually Enter IP Address"))1615 {1616 _cardip->setEnabled(true);1617 _cardtuner->setEnabled(true);1618 #if 01619 LOG(VB_GENERAL, LOG_DEBUG, "Done");1620 #endif1621 }1622 else if (!v.isEmpty())1623 {1624 if (_oldValue == HDHomeRunDeviceIDList::tr("Manually Enter IP Address"))1625 {1626 _cardip->setEnabled(false);1627 _cardtuner->setEnabled(false);1628 }1629 _deviceid->setValue(v);1630 1631 // Update _cardip and cardtuner1632 _cardip->setValue((*_devicelist)[v].cardip);1633 _cardtuner->setValue(QString("%1").arg((*_devicelist)[v].cardtuner));1634 _desc->setValue((*_devicelist)[v].desc);1635 }1636 _oldValue = v;1637 };1638 1639 1407 // ----------------------- 1640 1408 // VBOX Configuration 1641 1409 // ----------------------- … … class HDHomeRunEITScan : public MythUICheckBoxSetting 2078 1846 }; 2079 1847 2080 1848 1849 class UseHDHomeRunDevice : public TransMythUICheckBoxSetting 1850 { 1851 public: 1852 explicit UseHDHomeRunDevice(QString &deviceid, QString &hwmodel, 1853 QString &ipaddr) : 1854 TransMythUICheckBoxSetting() 1855 { 1856 setLabel(QObject::tr("Use HDHomeRun %1 (%2 %3)") 1857 .arg(deviceid).arg(hwmodel).arg(ipaddr)); 1858 setValue(false); 1859 setHelpText( 1860 QObject::tr("If enabled, use tuners from this HDHomeRun " 1861 "device.")); 1862 }; 1863 }; 1864 2081 1865 HDHomeRunConfigurationGroup::HDHomeRunConfigurationGroup 2082 1866 (CaptureCard& a_parent, CardType &a_cardtype) : 2083 1867 parent(a_parent) … … HDHomeRunConfigurationGroup::HDHomeRunConfigurationGroup 2087 1871 // Fill Device list 2088 1872 FillDeviceList(); 2089 1873 2090 deviceid = new HDHomeRunDeviceID(parent); 2091 desc = new GroupSetting(); 2092 desc->setLabel(tr("Description")); 2093 cardip = new HDHomeRunIP(); 2094 cardtuner = new HDHomeRunTunerIndex(); 2095 deviceidlist = new HDHomeRunDeviceIDList( 2096 deviceid, desc, cardip, cardtuner, &devicelist, parent); 1874 deviceid = new HDHomeRunDeviceID(parent, *this); 2097 1875 2098 a_cardtype.addTargetedChild("HDHOMERUN", deviceidlist); 1876 QMap<QString, HDHomeRunDevice>::iterator dit; 1877 for (dit = devicelist.begin(); dit != devicelist.end(); ++dit) 1878 { 1879 HDHomeRunDevice &dev = *dit; 1880 dev.checkbox = new UseHDHomeRunDevice( 1881 dev.deviceid, dev.hwmodel, dev.cardip); 1882 a_cardtype.addTargetedChild("HDHOMERUN", dev.checkbox); 1883 } 2099 1884 a_cardtype.addTargetedChild("HDHOMERUN", new EmptyAudioDevice(parent)); 2100 1885 a_cardtype.addTargetedChild("HDHOMERUN", new EmptyVBIDevice(parent)); 2101 1886 a_cardtype.addTargetedChild("HDHOMERUN", deviceid); 2102 a_cardtype.addTargetedChild("HDHOMERUN", desc);2103 a_cardtype.addTargetedChild("HDHOMERUN", cardip);2104 a_cardtype.addTargetedChild("HDHOMERUN", cardtuner);2105 1887 2106 1888 GroupSetting *buttonRecOpt = new GroupSetting(); 2107 1889 buttonRecOpt->setLabel(tr("Recording Options")); … … HDHomeRunConfigurationGroup::HDHomeRunConfigurationGroup 2109 1891 buttonRecOpt->addChild(new ChannelTimeout(parent, 3000, 1750)); 2110 1892 buttonRecOpt->addChild(new HDHomeRunEITScan(parent)); 2111 1893 a_cardtype.addTargetedChild("HDHOMERUN", buttonRecOpt); 2112 2113 connect(cardip, SIGNAL(NewIP(const QString&)),2114 deviceid, SLOT( SetIP(const QString&)));2115 connect(cardtuner, SIGNAL(NewTuner(const QString&)),2116 deviceid, SLOT( SetTuner(const QString&)));2117 1894 }; 2118 1895 2119 1896 void HDHomeRunConfigurationGroup::FillDeviceList(void) … … void HDHomeRunConfigurationGroup::FillDeviceList(void) 2132 1909 QStringList devinfo = dev.split(" "); 2133 1910 QString devid = devinfo.at(0); 2134 1911 QString devip = devinfo.at(1); 2135 QString devtuner= devinfo.at(2);1912 QString hwmodel = devinfo.at(2); 2136 1913 2137 1914 HDHomeRunDevice tmpdevice; 2138 tmpdevice.deviceid = devid; 2139 tmpdevice.desc = CardUtil::GetHDHRdesc(devid); 2140 tmpdevice.cardip = devip; 2141 tmpdevice.inuse = false; 2142 tmpdevice.discovered = true; 2143 tmpdevice.cardtuner = devtuner; 2144 tmpdevice.mythdeviceid = 2145 tmpdevice.deviceid + "-" + tmpdevice.cardtuner; 2146 devicelist[tmpdevice.mythdeviceid] = tmpdevice; 2147 } 2148 uint found_device_count = devicelist.size(); 2149 2150 // Now find configured devices 2151 2152 // returns "xxxxxxxx-n" or "ip.ip.ip.ip-n" values 2153 QStringList db = CardUtil::GetVideoDevices("HDHOMERUN"); 2154 2155 for (it = db.begin(); it != db.end(); ++it) 2156 { 2157 QMap<QString, HDHomeRunDevice>::iterator dit; 2158 2159 dit = devicelist.find(*it); 2160 2161 if (dit == devicelist.end()) 2162 { 2163 if ((*it).toUpper() == "FFFFFFFF-0" && 2 == found_device_count) 2164 dit = devicelist.begin(); 2165 2166 if ((*it).toUpper() == "FFFFFFFF-1" && 2 == found_device_count) 2167 { 2168 dit = devicelist.begin(); 2169 ++dit; 2170 } 2171 } 2172 2173 if (dit != devicelist.end()) 2174 { 2175 (*dit).inuse = true; 2176 continue; 2177 } 2178 2179 HDHomeRunDevice tmpdevice; 2180 tmpdevice.mythdeviceid = *it; 2181 tmpdevice.inuse = true; 2182 tmpdevice.discovered = false; 2183 2184 if (ProbeCard(tmpdevice)) 2185 devicelist[tmpdevice.mythdeviceid] = tmpdevice; 1915 tmpdevice.hwmodel = hwmodel; 1916 tmpdevice.cardip = devip; 1917 tmpdevice.deviceid = devid; 1918 devicelist[tmpdevice.deviceid] = tmpdevice; 2186 1919 } 2187 1920 2188 1921 #if 0 … … void HDHomeRunConfigurationGroup::FillDeviceList(void) 2190 1923 QMap<QString, HDHomeRunDevice>::iterator debugit; 2191 1924 for (debugit = devicelist.begin(); debugit != devicelist.end(); ++debugit) 2192 1925 { 2193 LOG(VB_GENERAL, LOG_DEBUG, QString("%1: %2 %3 %4 %5 %6 %7") 2194 .arg(debugit.key()) 2195 .arg((*debugit).mythdeviceid) 2196 .arg((*debugit).deviceid) 2197 .arg((*debugit).cardip) 2198 .arg((*debugit).cardtuner) 2199 .arg((*debugit).inuse) 2200 .arg((*debugit).discovered)); 1926 LOG(VB_GENERAL, LOG_DEBUG, QString("%1: %2 %3") 1927 .arg(debugit.key()).arg((*debugit).hwmodel) 1928 .arg((*debugit).cardip)); 2201 1929 } 2202 1930 #endif 2203 1931 } 2204 1932 2205 bool HDHomeRunConfigurationGroup::ProbeCard(HDHomeRunDevice &tmpdevice)1933 void HDHomeRunConfigurationGroup::SetDeviceCheckBoxes(QString devices) 2206 1934 { 2207 #ifdef USING_HDHOMERUN 2208 hdhomerun_device_t *thisdevice = 2209 hdhomerun_device_create_from_str( 2210 tmpdevice.mythdeviceid.toLocal8Bit().constData(), nullptr); 2211 2212 if (thisdevice) 1935 QStringList devstrs = devices.split(","); 1936 for (int i = 0; i < devstrs.size(); ++i) 2213 1937 { 2214 uint device_id = hdhomerun_device_get_device_id(thisdevice); 2215 uint device_ip = hdhomerun_device_get_device_ip(thisdevice); 2216 uint tuner = hdhomerun_device_get_tuner(thisdevice); 2217 hdhomerun_device_destroy(thisdevice); 2218 2219 if (device_id == 0) 2220 tmpdevice.deviceid = "NOTFOUND"; 2221 else 2222 { 2223 tmpdevice.deviceid = QString("%1").arg(device_id, 8, 16); 2224 tmpdevice.desc = CardUtil::GetHDHRdesc(tmpdevice.deviceid); 2225 } 2226 2227 tmpdevice.deviceid = tmpdevice.deviceid.toUpper(); 1938 // Get the HDHomeRun device ID using libhdhomerun. We need to 1939 // do it this way because legacy configurations could use an 1940 // IP address and a tuner nubmer. 1941 QByteArray ba = devstrs[i].toUtf8(); 1942 hdhomerun_device_t *device = hdhomerun_device_create_from_str( 1943 ba.data(), nullptr); 1944 if (!device) 1945 continue; 1946 QString devid = QString("%1").arg( 1947 hdhomerun_device_get_device_id(device), 8, 16).toUpper(); 1948 hdhomerun_device_destroy(device); 2228 1949 2229 tmpdevice.cardip = QString("%1.%2.%3.%4") 2230 .arg((device_ip>>24) & 0xFF).arg((device_ip>>16) & 0xFF) 2231 .arg((device_ip>> 8) & 0xFF).arg((device_ip>> 0) & 0xFF); 1950 // If we know about this device, set its checkbox to on. 1951 QMap<QString, HDHomeRunDevice>::iterator dit; 1952 dit = devicelist.find(devid); 1953 if (dit != devicelist.end()) 1954 (*dit).checkbox->setValue(true); 1955 } 1956 } 2232 1957 2233 tmpdevice.cardtuner = QString("%1").arg(tuner); 2234 return true; 1958 QString HDHomeRunConfigurationGroup::GetDeviceCheckBoxes(void) 1959 { 1960 // Return a string listing each HDHomeRun device with its checbox 1961 // turned on. 1962 QStringList devstrs; 1963 QMap<QString, HDHomeRunDevice>::iterator dit; 1964 for (dit = devicelist.begin(); dit != devicelist.end(); ++dit) 1965 { 1966 if ((*dit).checkbox->boolValue()) 1967 devstrs << (*dit).deviceid; 2235 1968 } 2236 #endif // USING_HDHOMERUN 2237 Q_UNUSED(tmpdevice); 2238 return false; 1969 QString devices = devstrs.join(","); 1970 return devices; 2239 1971 } 2240 1972 2241 1973 // ----------------------- -
mythtv/libs/libmythtv/videosource.h
diff --git a/mythtv/libs/libmythtv/videosource.h b/mythtv/libs/libmythtv/videosource.h index a18fde4ee7..00f443950b 100644
a b public: 380 380 static void fillSelections(MythUIComboBoxSetting* setting); 381 381 }; 382 382 383 class UseHDHomeRunDevice; 384 383 385 class HDHomeRunDevice 384 386 { 385 387 public: 386 QString mythdeviceid;387 388 QString deviceid; 388 QString desc;389 QString hwmodel; 389 390 QString cardip; 390 QString cardtuner; 391 bool inuse; 392 bool discovered; 391 UseHDHomeRunDevice *checkbox; 393 392 }; 394 393 395 394 typedef QMap<QString, HDHomeRunDevice> HDHomeRunDeviceList; 396 395 397 class HDHomeRunDeviceIDList;398 396 class HDHomeRunDeviceID; 399 class HDHomeRunIP;400 class HDHomeRunTunerIndex;401 397 class HDHomeRunConfigurationGroup : public GroupSetting 402 398 { 403 399 Q_OBJECT … … class HDHomeRunConfigurationGroup : public GroupSetting 406 402 407 403 public: 408 404 HDHomeRunConfigurationGroup(CaptureCard &parent, CardType &cardtype); 405 void SetDeviceCheckBoxes(QString devices); 406 QString GetDeviceCheckBoxes(void); 409 407 410 408 private: 411 409 void FillDeviceList(void); 412 bool ProbeCard(HDHomeRunDevice&);413 410 414 411 private: 415 412 CaptureCard &parent; 416 StandardSetting *desc;417 HDHomeRunDeviceIDList *deviceidlist;418 413 HDHomeRunDeviceID *deviceid; 419 HDHomeRunIP *cardip;420 HDHomeRunTunerIndex *cardtuner;421 414 HDHomeRunDeviceList devicelist; 422 415 }; 423 416 … … class CardInput : public GroupSetting 878 871 MythUICheckBoxSetting *schedgroup; 879 872 }; 880 873 881 class HDHomeRunDeviceID;882 class HDHomeRunTunerIndex;883 884 class HDHomeRunIP : public MythUITextEditSetting885 {886 Q_OBJECT887 888 public:889 HDHomeRunIP();890 891 void setEnabled(bool e) override; // StandardSetting892 void SetOldValue(const QString &s)893 { _oldValue = s; _oldValue.detach(); };894 895 signals:896 void NewIP(const QString&);897 898 public slots:899 void UpdateDevices(const QString&);900 901 private:902 QString _oldValue;903 };904 905 class HDHomeRunTunerIndex : public MythUITextEditSetting906 {907 Q_OBJECT908 909 public:910 HDHomeRunTunerIndex();911 912 void setEnabled(bool e) override; // StandardSetting913 void SetOldValue(const QString &s)914 { _oldValue = s; _oldValue.detach(); };915 916 signals:917 void NewTuner(const QString&);918 919 public slots:920 void UpdateDevices(const QString&);921 922 private:923 QString _oldValue;924 };925 926 927 class HDHomeRunDeviceIDList : public TransMythUIComboBoxSetting928 {929 Q_OBJECT930 931 public:932 HDHomeRunDeviceIDList(HDHomeRunDeviceID *deviceid,933 StandardSetting *desc,934 HDHomeRunIP *cardip,935 HDHomeRunTunerIndex *cardtuner,936 HDHomeRunDeviceList *devicelist,937 const CaptureCard &parent);938 939 void fillSelections(const QString ¤t);940 941 void Load(void) override; // StandardSetting942 943 public slots:944 void UpdateDevices(const QString&);945 946 private:947 HDHomeRunDeviceID *_deviceid;948 StandardSetting *_desc;949 HDHomeRunIP *_cardip;950 HDHomeRunTunerIndex *_cardtuner;951 HDHomeRunDeviceList *_devicelist;952 const CaptureCard &m_parent;953 954 QString _oldValue;955 };956 957 874 class HDHomeRunDeviceID : public MythUITextEditSetting 958 875 { 959 876 Q_OBJECT 960 877 961 878 public: 962 explicit HDHomeRunDeviceID(const CaptureCard &parent);963 879 HDHomeRunDeviceID(const CaptureCard &parent, 880 HDHomeRunConfigurationGroup &_group); 964 881 void Load(void) override; // StandardSetting 965 966 public slots: 967 void SetIP(const QString&); 968 void SetTuner(const QString&); 969 void SetOverrideDeviceID(const QString&); 882 void Save(void) override; // StandardSetting 970 883 971 884 private: 972 QString _ip; 973 QString _tuner; 974 QString _overridedeviceid; 885 HDHomeRunConfigurationGroup &group; 975 886 }; 976 887 977 888 ///