Ticket #13339: hdhr-locking-pooling-2.patch

File hdhr-locking-pooling-2.patch, 30.4 KB (added by gigem, 5 years ago)
  • mythtv/libs/libmythtv/cardutil.cpp

    diff --git a/mythtv/libs/libmythtv/cardutil.cpp b/mythtv/libs/libmythtv/cardutil.cpp
    index bf797e6a57..246e70a29e 100644
    a b QStringList CardUtil::ProbeVideoDevices(const QString &rawtype) 
    540540                                 .arg((result_list[i].ip_addr>> 8) & 0xFF)
    541541                                 .arg((result_list[i].ip_addr>> 0) & 0xFF);
    542542
    543             for (int tuner = 0; tuner < result_list[i].tuner_count; tuner++)
    544             {
    545                 QString hdhrdev = id.toUpper() + " " + ip + " " +
    546                                   QString("%1").arg(tuner);
    547                 devs.push_back(hdhrdev);
    548             }
     543            QString hdhrdev = id.toUpper() + " " + ip;
     544            devs.push_back(hdhrdev);
    549545        }
    550546    }
    551547#endif // USING_HDHOMERUN
    uint CardUtil::CreateDeviceInputGroup(uint inputid, 
    13961392{
    13971393    QString name = host + '|' + device;
    13981394    if (type == "FREEBOX" || type == "IMPORT" ||
    1399         type == "DEMO"    || type == "EXTERNAL")
     1395        type == "DEMO"    || type == "EXTERNAL" ||
     1396        type == "HDHOMERUN")
    14001397        name += QString("|%1").arg(inputid);
    14011398    return CreateInputGroup(name);
    14021399}
  • mythtv/libs/libmythtv/recorders/channelbase.cpp

    diff --git a/mythtv/libs/libmythtv/recorders/channelbase.cpp b/mythtv/libs/libmythtv/recorders/channelbase.cpp
    index 04d46da5e7..9380d4a15d 100644
    a b ChannelBase *ChannelBase::CreateChannel( 
    805805    {
    806806        if (channel &&
    807807            ((genOpt.inputtype == "DVB" && dvbOpt.dvb_on_demand) ||
     808             genOpt.inputtype == "HDHOMERUN" ||
    808809             CardUtil::IsV4L(genOpt.inputtype)))
    809810        {
    810811            channel->Close();
    bool ChannelBase::IsExternalChannelChangeInUse(void) 
    835836
    836837    return !m_externalChanger.isEmpty();
    837838}
     839
     840int ChannelBase::GetMasterId(void)
     841{
     842    return m_pParent ? m_pParent->GetMasterId() : 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..2898090a5a 100644
    a b class ChannelBase 
    100100    // \brief Set inputid for scanning
    101101    void SetInputID(uint _inputid) { m_inputid = _inputid; }
    102102
     103    // \brief Get master input ID
     104    int GetMasterId(void);
     105
    103106    static ChannelBase *CreateChannel(
    104107        TVRec                    *tv_rec,
    105108        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 faca66682e..111576d8d8 100644
    a b bool HDHRChannel::Open(void) 
    5959    if (IsOpen())
    6060        return true;
    6161
    62     _stream_handler = HDHRStreamHandler::Get(_device_id);
     62    _stream_handler = HDHRStreamHandler::Get(_device_id, GetMasterId());
    6363
    6464    _tuner_types = _stream_handler->GetTunerTypes();
    6565    tunerType = (_tuner_types.empty()) ?
    void HDHRChannel::Close(void) 
    8686
    8787bool HDHRChannel::EnterPowerSavingMode(void)
    8888{
    89     if (IsOpen())
    90         return _stream_handler->EnterPowerSavingMode();
    91     else
    92         return true;
     89    Close();
     90    return true;
    9391}
    9492
    9593bool 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..dfe079022a 100644
    a b bool HDHRRecorder::Open(void) 
    3636    ResetForNewFile();
    3737
    3838    _stream_handler = HDHRStreamHandler::Get(_channel->GetDevice(),
     39                                             _channel->GetMasterId(),
    3940                                     (tvrec ? tvrec->GetInputId() : -1));
    4041
    4142    LOG(VB_RECORD, LOG_INFO, LOC + "HDHR opened successfully");
  • mythtv/libs/libmythtv/recorders/hdhrsignalmonitor.cpp

    diff --git a/mythtv/libs/libmythtv/recorders/hdhrsignalmonitor.cpp b/mythtv/libs/libmythtv/recorders/hdhrsignalmonitor.cpp
    index e15fe16538..fbddd3821a 100644
    a b HDHRSignalMonitor::HDHRSignalMonitor(int db_cardnum, 
    5151
    5252    AddFlags(kSigMon_WaitForSig);
    5353
    54     streamHandler = HDHRStreamHandler::Get(_channel->GetDevice());
     54    streamHandler = HDHRStreamHandler::Get(_channel->GetDevice(),
     55                                           _channel->GetMasterId());
    5556}
    5657
    5758/** \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 7eed3abf80..63061cb837 100644
    a b  
    1919#include "cardutil.h"
    2020#include "mythlogging.h"
    2121
    22 #define LOC      QString("HDHRSH%1(%2): ").arg(_recorder_ids_string) \
    23                                           .arg(_device)
     22#define LOC      QString("HDHRSH%1(%2,%3): ").arg(_recorder_ids_string) \
     23                                             .arg(_devkey).arg(_device)
    2424
    25 QMap<QString,HDHRStreamHandler*> HDHRStreamHandler::_handlers;
    26 QMap<QString,uint>               HDHRStreamHandler::_handlers_refcnt;
     25QMap<int,HDHRStreamHandler*>    HDHRStreamHandler::_handlers;
     26QMap<int,uint>                   HDHRStreamHandler::_handlers_refcnt;
    2727QMutex                           HDHRStreamHandler::_handlers_lock;
     28HDHRDevSelectorCache             HDHRStreamHandler::_selectors;
    2829
    29 HDHRStreamHandler *HDHRStreamHandler::Get(const QString &devname,
     30HDHRStreamHandler *HDHRStreamHandler::Get(const QString &devname, int devkey,
    3031                                          int recorder_id)
    3132{
    3233    QMutexLocker locker(&_handlers_lock);
    3334
    34     QString devkey = devname.toUpper();
    35 
    36     QMap<QString,HDHRStreamHandler*>::iterator it = _handlers.find(devkey);
     35    QMap<int,HDHRStreamHandler*>::iterator it = _handlers.find(devkey);
    3736
    3837    if (it == _handlers.end())
    3938    {
    40         HDHRStreamHandler *newhandler = new HDHRStreamHandler(devkey);
     39        HDHRStreamHandler *newhandler = new HDHRStreamHandler(devname, devkey);
    4140        newhandler->Open();
    4241        _handlers[devkey] = newhandler;
    4342        _handlers_refcnt[devkey] = 1;
    void HDHRStreamHandler::Return(HDHRStreamHandler * & ref, int recorder_id) 
    6463{
    6564    QMutexLocker locker(&_handlers_lock);
    6665
    67     QString devname = ref->_device;
     66    int devkey = ref->_devkey;
    6867
    69     QMap<QString,uint>::iterator rit = _handlers_refcnt.find(devname);
     68    QMap<int,uint>::iterator rit = _handlers_refcnt.find(devkey);
    7069    if (rit == _handlers_refcnt.end())
    7170        return;
    7271
    73     QMap<QString,HDHRStreamHandler*>::iterator it = _handlers.find(devname);
     72    QMap<int,HDHRStreamHandler*>::iterator it = _handlers.find(devkey);
    7473    if (it != _handlers.end())
    7574        (*it)->DelRecorderId(recorder_id);
    7675
    void HDHRStreamHandler::Return(HDHRStreamHandler * & ref, int recorder_id) 
    8483    if ((it != _handlers.end()) && (*it == ref))
    8584    {
    8685        LOG(VB_RECORD, LOG_INFO, QString("HDHRSH: Closing handler for %1")
    87                            .arg(devname));
     86                           .arg(devkey));
    8887        ref->Close();
    8988        delete *it;
    9089        _handlers.erase(it);
    void HDHRStreamHandler::Return(HDHRStreamHandler * & ref, int recorder_id) 
    9392    {
    9493        LOG(VB_GENERAL, LOG_ERR,
    9594            QString("HDHRSH Error: Couldn't find handler for %1")
    96                 .arg(devname));
     95                .arg(devkey));
    9796    }
    9897
    9998    _handlers_refcnt.erase(rit);
    10099    ref = nullptr;
    101100}
    102101
    103 HDHRStreamHandler::HDHRStreamHandler(const QString &device) :
     102HDHRStreamHandler::HDHRStreamHandler(const QString &device, int devkey) :
    104103    StreamHandler(device),
    105104    _hdhomerun_device(nullptr),
    106105    _tuner(-1),
    107106    _tune_mode(hdhrTuneModeNone),
     107    _devkey(devkey),
    108108    _hdhr_lock(QMutex::Recursive)
    109109{
    110110    setObjectName("HDHRStreamHandler");
    HDHRStreamHandler::HDHRStreamHandler(const QString &device) : 
    115115 */
    116116void HDHRStreamHandler::run(void)
    117117{
    118     int tunerLock = 0;
    119     char *error = nullptr;
    120 
    121118    RunProlog();
    122     /* Get a tuner lock */
    123     tunerLock = hdhomerun_device_tuner_lockkey_request(_hdhomerun_device, &error);
    124     if(tunerLock < 1)
    125     {
    126         LOG(VB_GENERAL, LOG_ERR, LOC +
    127             QString("Get tuner lock failed. Aborting. Error: %1").arg(error));
    128         _error = true;
    129         RunEpilog();
    130         return;
    131     }
     119
    132120    /* Create TS socket. */
    133121    if (!hdhomerun_device_stream_start(_hdhomerun_device))
    134122    {
    void HDHRStreamHandler::run(void) 
    226214
    227215    LOG(VB_RECORD, LOG_INFO, LOC + "RunTS(): " + "end");
    228216
    229     if(tunerLock == 1)
    230     {
    231         LOG(VB_RECORD, LOG_INFO, LOC + "Release tuner lock.");
    232         hdhomerun_device_tuner_lockkey_release(_hdhomerun_device);
    233     }
    234 
    235217    SetRunning(false, false, false);
     218
    236219    RunEpilog();
    237220}
    238221
    void HDHRStreamHandler::Close(void) 
    366349    if (_hdhomerun_device)
    367350    {
    368351        TuneChannel("none");
    369         hdhomerun_device_destroy(_hdhomerun_device);
     352        hdhomerun_device_tuner_lockkey_release(_hdhomerun_device);
    370353        _hdhomerun_device = nullptr;
    371354    }
    372355}
    373356
    374357bool HDHRStreamHandler::Connect(void)
    375358{
    376     _hdhomerun_device = hdhomerun_device_create_from_str(
    377         _device.toLocal8Bit().constData(), nullptr);
    378 
    379     if (!_hdhomerun_device)
     359    hdhomerun_device_selector_t *selector = _selectors.Get(_devkey, _device);
     360    if (!selector)
    380361    {
    381         LOG(VB_GENERAL, LOG_ERR, LOC + "Unable to create hdhomerun object");
     362        LOG(VB_GENERAL, LOG_ERR, LOC +
     363            QString("Unable to get device selector"));
    382364        return false;
    383365    }
    384366
    385     _tuner = hdhomerun_device_get_tuner(_hdhomerun_device);
    386 
    387     if (hdhomerun_device_get_local_machine_addr(_hdhomerun_device) == 0)
     367    _hdhomerun_device = hdhomerun_device_selector_choose_and_lock(
     368        selector, nullptr);
     369    if (!_hdhomerun_device)
    388370    {
    389         LOG(VB_GENERAL, LOG_ERR, LOC + "Unable to connect to device");
     371        LOG(VB_GENERAL, LOG_ERR, LOC +
     372            QString("Unable to find a free device"));
    390373        return false;
    391374    }
    392375
    393     LOG(VB_RECORD, LOG_INFO, LOC + "Successfully connected to device");
    394     return true;
    395 }
     376    _tuner = hdhomerun_device_get_tuner(_hdhomerun_device);
    396377
    397 bool HDHRStreamHandler::EnterPowerSavingMode(void)
    398 {
    399     QMutexLocker locker(&_listener_lock);
     378    LOG(VB_GENERAL, LOG_INFO, LOC +
     379        QString("Connected to device(%1)")
     380        .arg(hdhomerun_device_get_name(_hdhomerun_device)));
    400381
    401     if (!_stream_data_list.empty())
    402     {
    403         LOG(VB_RECORD, LOG_INFO, LOC +
    404             "Ignoring request - video streaming active");
    405         return false;
    406     }
    407     else
    408     {
    409         locker.unlock(); // _listener_lock
    410         return TuneChannel("none");
    411     }
     382    return true;
    412383}
    413384
    414385QString HDHRStreamHandler::TunerGet(
    bool HDHRStreamHandler::TuneVChannel(const QString &vchn) 
    551522    LOG(VB_RECORD, LOG_INFO, LOC + QString("Tuning vchannel %1").arg(vchn));
    552523    return !TunerSet("vchannel", vchn).isEmpty();
    553524}
     525
     526HDHRDevSelectorCache::HDHRDevSelectorCache(void)
     527    : _map()
     528{
     529}
     530
     531HDHRDevSelectorCache::~HDHRDevSelectorCache(void)
     532{
     533    while (_map.size())
     534    {
     535        hdhomerun_device_selector_t *selector = _map.first();
     536        hdhomerun_device_selector_destroy(selector, true);
     537        _map.erase(_map.begin());
     538    }
     539}
     540
     541hdhomerun_device_selector_t *HDHRDevSelectorCache::Get(int devkey,
     542                                                       QString device)
     543{
     544    QMap<int, hdhomerun_device_selector_t*>::iterator iter;
     545    iter = _map.find(devkey);
     546    if (iter != _map.end())
     547        return *iter;
     548
     549    hdhomerun_device_selector_t *selector =
     550        hdhomerun_device_selector_create(nullptr);
     551    _map[devkey] = selector;
     552
     553    if (!selector)
     554    {
     555        LOG(VB_GENERAL, LOG_ERR,
     556            QString("HDHRDevSelectorCache::Get(%1): "
     557                    "Unable to create device selector").arg(device));
     558        return nullptr;
     559    }
     560
     561    QStringList devices = device.split(",");
     562    for (int i = 0; i < devices.size(); ++i)
     563    {
     564        QByteArray ba = devices[i].toUtf8();
     565        int n = hdhomerun_device_selector_load_from_str(selector, ba.data());
     566        LOG(VB_GENERAL, LOG_INFO,
     567            QString("HDHRDevSelectorCache::Get(%1): "
     568                    "Added %2 devices from %3")
     569            .arg(device).arg(n).arg(devices[i]));
     570    }
     571
     572    return selector;
     573}
  • mythtv/libs/libmythtv/recorders/hdhrstreamhandler.h

    diff --git a/mythtv/libs/libmythtv/recorders/hdhrstreamhandler.h b/mythtv/libs/libmythtv/recorders/hdhrstreamhandler.h
    index fd14751948..d3f8fc38aa 100644
    a b class DeviceReadBuffer; 
    3030#endif
    3131#else
    3232struct hdhomerun_device_t { int dummy; };
     33struct hdhomerun_device_selector_t { int dummy; };
    3334#endif
    3435
     36class HDHRDevSelectorCache
     37{
     38  public:
     39    HDHRDevSelectorCache(void);
     40    ~HDHRDevSelectorCache(void);
     41    hdhomerun_device_selector_t *Get(int devkey, QString device);
     42
     43  private:
     44    HDHRDevSelectorCache(const HDHRDevSelectorCache&);
     45    HDHRDevSelectorCache& operator=(const HDHRDevSelectorCache&);
     46
     47    QMap<int, hdhomerun_device_selector_t*> _map;
     48};
     49
    3550enum HDHRTuneMode {
    3651    hdhrTuneModeNone = 0,
    3752    hdhrTuneModeFrequency,
    enum HDHRTuneMode { 
    4964class HDHRStreamHandler : public StreamHandler
    5065{
    5166  public:
    52     static HDHRStreamHandler *Get(const QString &devicename,
     67    static HDHRStreamHandler *Get(const QString &devicename, int devkey,
    5368                                  int recorder_id = -1);
    5469    static void Return(HDHRStreamHandler * & ref, int recorder_id = -1);
    5570
    class HDHRStreamHandler : public StreamHandler 
    6984    bool TuneChannel(const QString &chanid);
    7085    bool TuneProgram(uint mpeg_prog_num);
    7186    bool TuneVChannel(const QString &vchn);
    72     bool EnterPowerSavingMode(void);
    7387
    7488  private:
    75     explicit HDHRStreamHandler(const QString &);
     89    explicit HDHRStreamHandler(const QString &, int devkey);
    7690
    7791    bool Connect(void);
    7892
    class HDHRStreamHandler : public StreamHandler 
    95109    int                     _tuner;
    96110    vector<DTVTunerType>    _tuner_types;
    97111    HDHRTuneMode            _tune_mode; // debug self check
     112    int                     _devkey;
    98113
    99114    mutable QMutex          _hdhr_lock;
    100115
    101116    // for implementing Get & Return
    102117    static QMutex                            _handlers_lock;
    103     static QMap<QString, HDHRStreamHandler*> _handlers;
    104     static QMap<QString, uint>               _handlers_refcnt;
     118    static QMap<int, HDHRStreamHandler*>     _handlers;
     119    static QMap<int, uint>                   _handlers_refcnt;
     120    static HDHRDevSelectorCache              _selectors;
    105121};
    106122
    107123#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..4d0ca5aa54 100644
    a b class MTV_PUBLIC TVRec : public SignalMonitorListener, public QRunnable 
    240240    /// \brief Returns the inputid
    241241    uint GetInputId(void) { return inputid; }
    242242    uint GetParentId(void) { return parentid; }
     243    uint GetMasterId(void) { return parentid ? parentid : inputid; }
    243244    /// \brief Returns true is "errored" is true, false otherwise.
    244245    bool IsErrored(void)  const { return HasFlags(kFlagErrored); }
    245246
  • mythtv/libs/libmythtv/videosource.cpp

    diff --git a/mythtv/libs/libmythtv/videosource.cpp b/mythtv/libs/libmythtv/videosource.cpp
    index 13d008bec5..4db1fa8dc9 100644
    a b static void FirewireConfigurationGroup(CaptureCard& parent, CardType& cardtype) 
    13831383// HDHomeRun Configuration
    13841384// -----------------------
    13851385
    1386 HDHomeRunIP::HDHomeRunIP()
    1387 {
    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()
     1386HDHomeRunDeviceID::HDHomeRunDeviceID(const CaptureCard &parent) :
     1387    MythUITextEditSetting(
     1388        new CaptureCardDBStorage(this, parent, "videodevice"))
    14231389{
    1424     setLabel(QObject::tr("Tuner"));
    1425     setEnabled(false);
     1390    setLabel(QObject::tr("Devices"));
     1391    setHelpText(
     1392        QObject::tr(
     1393            "Device IDs, IP addresses or hostnames of HDHomerun devices. "
     1394            "Separate values by ',' to pool the tuners from multiple devices. "
     1395            "When devices are pooled, all devices must support the same set "
     1396            "of channels."));
    14261397    connect(this, SIGNAL(valueChanged( const QString&)),
    14271398            this, SLOT(  UpdateDevices(const QString&)));
    1428     _oldValue = "";
    14291399};
    14301400
    1431 void HDHomeRunTunerIndex::setEnabled(bool e)
     1401void HDHomeRunDeviceID::UpdateDevices(const QString &v)
    14321402{
    1433     MythUITextEditSetting::setEnabled(e);
    1434     if (e) {
    1435         if (!_oldValue.isEmpty())
    1436             setValue(_oldValue);
    1437         emit NewTuner(getValue());
    1438     }
    1439     else
    1440     {
    1441         _oldValue = getValue();
    1442     }
    1443 }
    1444 
    1445 void HDHomeRunTunerIndex::UpdateDevices(const QString &v)
    1446 {
    1447    if (isEnabled())
    1448    {
    1449 #if 0
    1450        LOG(VB_GENERAL, LOG_DEBUG, QString("Emitting NewTuner(%1)").arg(v));
    1451 #endif
    1452        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 0
    1467     LOG(VB_GENERAL, LOG_DEBUG, QString("Setting IP to %1").arg(ip));
    1468 #endif
    1469     _ip = ip;
    1470     setValue(QString("%1-%2").arg(_ip).arg(_tuner));
    1471 #if 0
    1472     LOG(VB_GENERAL, LOG_DEBUG, QString("Done Setting IP to %1").arg(ip));
    1473 #endif
    1474 }
    1475 
    1476 void HDHomeRunDeviceID::SetTuner(const QString &tuner)
    1477 {
    1478 #if 0
    1479     LOG(VB_GENERAL, LOG_DEBUG, QString("Setting Tuner to %1").arg(tuner));
    1480 #endif
    1481     _tuner = tuner;
    1482     setValue(QString("%1-%2").arg(_ip).arg(_tuner));
    1483 #if 0
    1484     LOG(VB_GENERAL, LOG_DEBUG, QString("Done Setting Tuner to %1").arg(tuner));
    1485 #endif
    1486 }
    1487 
    1488 void HDHomeRunDeviceID::SetOverrideDeviceID(const QString &deviceid)
    1489 {
    1490     _overridedeviceid = deviceid;
    1491     setValue(deviceid);
    1492 }
    1493 
    1494 void HDHomeRunDeviceID::Load(void)
    1495 {
    1496     GetStorage()->Load();
    1497     if (!_overridedeviceid.isEmpty())
    1498     {
    1499         setValue(_overridedeviceid);
    1500         _overridedeviceid.clear();
    1501     }
     1403    emit NewDeviceID(v);
    15021404}
    15031405
    15041406HDHomeRunDeviceIDList::HDHomeRunDeviceIDList(
    1505     HDHomeRunDeviceID   *deviceid,
    15061407    StandardSetting     *desc,
    1507     HDHomeRunIP         *cardip,
    1508     HDHomeRunTunerIndex *cardtuner,
     1408    StandardSetting     *cardip,
     1409    HDHomeRunDeviceID   *deviceid,
    15091410    HDHomeRunDeviceList *devicelist,
    15101411    const CaptureCard &parent) :
    1511     _deviceid(deviceid),
    15121412    _desc(desc),
    15131413    _cardip(cardip),
    1514     _cardtuner(cardtuner),
     1414    _deviceid(deviceid),
    15151415    _devicelist(devicelist),
    15161416    m_parent(parent)
    15171417{
    15181418    setLabel(QObject::tr("Available devices"));
    15191419    setHelpText(
    15201420        QObject::tr(
    1521             "Device ID and Tuner Number of available HDHomeRun devices."));
     1421            "Device ID of available HDHomeRun devices."));
    15221422
    15231423    connect(this, SIGNAL(valueChanged( const QString&)),
    15241424            this, SLOT(  UpdateDevices(const QString&)));
    void HDHomeRunDeviceIDList::fillSelections(const QString &cur) 
    15531453        }
    15541454    }
    15551455
    1556     QString man_addr = HDHomeRunDeviceIDList::tr("Manually Enter IP Address");
     1456    QString man_addr = HDHomeRunDeviceIDList::tr("Manually Enter Devices");
    15571457    QString sel = man_addr;
    15581458    devs.push_back(sel);
    15591459
    1560     if (3 == devs.size() && current.startsWith("FFFFFFFF", Qt::CaseInsensitive))
     1460    if (devs.size() > 0 &&
     1461        current.compare("FFFFFFFF", Qt::CaseInsensitive) == 0)
    15611462    {
    1562         current = sel = (current.endsWith("0")) ?
    1563             *(devs.begin()) : *(++devs.begin());
     1463        current = sel = *(devs.begin());
    15641464    }
    15651465    else
    15661466    {
    void HDHomeRunDeviceIDList::fillSelections(const QString &cur) 
    15791479        desc = (current == devs[i]) ? dev : desc;
    15801480        addSelection(desc, dev, dev == sel);
    15811481    }
    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     }
    15981482}
    15991483
    16001484void HDHomeRunDeviceIDList::Load(void)
    void HDHomeRunDeviceIDList::Load(void) 
    16081492
    16091493void HDHomeRunDeviceIDList::UpdateDevices(const QString &v)
    16101494{
    1611 #if 0
    1612     LOG(VB_GENERAL, LOG_DEBUG, QString("Got signal with %1").arg(v));
    1613 #endif
    1614     if (v == HDHomeRunDeviceIDList::tr("Manually Enter IP Address"))
    1615     {
    1616         _cardip->setEnabled(true);
    1617         _cardtuner->setEnabled(true);
    1618 #if 0
    1619         LOG(VB_GENERAL, LOG_DEBUG, "Done");
    1620 #endif
    1621     }
    1622     else if (!v.isEmpty())
     1495    if (!v.isEmpty())
    16231496    {
    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 cardtuner
    1632         _cardip->setValue((*_devicelist)[v].cardip);
    1633         _cardtuner->setValue(QString("%1").arg((*_devicelist)[v].cardtuner));
     1497        _deviceid->setValue((*_devicelist)[v].mythdeviceid);
    16341498        _desc->setValue((*_devicelist)[v].desc);
     1499        _cardip->setValue((*_devicelist)[v].cardip);
    16351500    }
    16361501    _oldValue = v;
    16371502};
    HDHomeRunConfigurationGroup::HDHomeRunConfigurationGroup 
    20871952    // Fill Device list
    20881953    FillDeviceList();
    20891954
    2090     deviceid     = new HDHomeRunDeviceID(parent);
    20911955    desc         = new GroupSetting();
    20921956    desc->setLabel(tr("Description"));
    2093     cardip       = new HDHomeRunIP();
    2094     cardtuner    = new HDHomeRunTunerIndex();
     1957    cardip       = new GroupSetting();
     1958    cardip->setLabel(tr("IP Address"));
     1959    deviceid     = new HDHomeRunDeviceID(parent);
    20951960    deviceidlist = new HDHomeRunDeviceIDList(
    2096         deviceid, desc, cardip, cardtuner, &devicelist, parent);
     1961        desc, cardip, deviceid, &devicelist, parent);
    20971962
    20981963    a_cardtype.addTargetedChild("HDHOMERUN", deviceidlist);
    20991964    a_cardtype.addTargetedChild("HDHOMERUN", new EmptyAudioDevice(parent));
    21001965    a_cardtype.addTargetedChild("HDHOMERUN", new EmptyVBIDevice(parent));
    2101     a_cardtype.addTargetedChild("HDHOMERUN", deviceid);
    21021966    a_cardtype.addTargetedChild("HDHOMERUN", desc);
    21031967    a_cardtype.addTargetedChild("HDHOMERUN", cardip);
    2104     a_cardtype.addTargetedChild("HDHOMERUN", cardtuner);
     1968    a_cardtype.addTargetedChild("HDHOMERUN", deviceid);
    21051969
    21061970    GroupSetting *buttonRecOpt = new GroupSetting();
    21071971    buttonRecOpt->setLabel(tr("Recording Options"));
    HDHomeRunConfigurationGroup::HDHomeRunConfigurationGroup 
    21091973    buttonRecOpt->addChild(new ChannelTimeout(parent, 3000, 1750));
    21101974    buttonRecOpt->addChild(new HDHomeRunEITScan(parent));
    21111975    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&)));
    21171976};
    21181977
    21191978void HDHomeRunConfigurationGroup::FillDeviceList(void)
    void HDHomeRunConfigurationGroup::FillDeviceList(void) 
    21321991        QStringList devinfo = dev.split(" ");
    21331992        QString devid = devinfo.at(0);
    21341993        QString devip = devinfo.at(1);
    2135         QString devtuner = devinfo.at(2);
     1994        QString devtuner = "";
     1995        if (devinfo.size() > 2)
     1996            devtuner = devinfo.at(2);
    21361997
    21371998        HDHomeRunDevice tmpdevice;
    2138         tmpdevice.deviceid   = devid;
    21391999        tmpdevice.desc       = CardUtil::GetHDHRdesc(devid);
    21402000        tmpdevice.cardip     = devip;
    21412001        tmpdevice.inuse      = false;
    21422002        tmpdevice.discovered = true;
    2143         tmpdevice.cardtuner = devtuner;
    2144         tmpdevice.mythdeviceid =
    2145             tmpdevice.deviceid + "-" + tmpdevice.cardtuner;
     2003        tmpdevice.mythdeviceid = devid;
    21462004        devicelist[tmpdevice.mythdeviceid] = tmpdevice;
    21472005    }
    21482006    uint found_device_count = devicelist.size();
    void HDHomeRunConfigurationGroup::FillDeviceList(void) 
    21902048    QMap<QString, HDHomeRunDevice>::iterator debugit;
    21912049    for (debugit = devicelist.begin(); debugit != devicelist.end(); ++debugit)
    21922050    {
    2193         LOG(VB_GENERAL, LOG_DEBUG, QString("%1: %2 %3 %4 %5 %6 %7")
     2051        LOG(VB_GENERAL, LOG_DEBUG, QString("%1: %2 %3 %4 %5 %6")
    21942052                .arg(debugit.key())
    21952053                .arg((*debugit).mythdeviceid)
    21962054                .arg((*debugit).deviceid)
    2197                 .arg((*debugit).cardip)
    2198                 .arg((*debugit).cardtuner)
     2055                .arg((*debugit).deviceid)
    21992056                .arg((*debugit).inuse)
    22002057                .arg((*debugit).discovered));
    22012058    }
    bool HDHomeRunConfigurationGroup::ProbeCard(HDHomeRunDevice &tmpdevice) 
    22132070    {
    22142071        uint device_id = hdhomerun_device_get_device_id(thisdevice);
    22152072        uint device_ip = hdhomerun_device_get_device_ip(thisdevice);
    2216         uint tuner     = hdhomerun_device_get_tuner(thisdevice);
    22172073        hdhomerun_device_destroy(thisdevice);
    22182074
    2219         if (device_id == 0)
    2220             tmpdevice.deviceid = "NOTFOUND";
    2221         else
     2075        if (device_id != 0)
    22222076        {
    2223             tmpdevice.deviceid = QString("%1").arg(device_id, 8, 16);
    2224             tmpdevice.desc     = CardUtil::GetHDHRdesc(tmpdevice.deviceid);
     2077            tmpdevice.desc     = CardUtil::GetHDHRdesc(tmpdevice.mythdeviceid);
    22252078        }
    22262079
    2227         tmpdevice.deviceid = tmpdevice.deviceid.toUpper();
    2228 
    22292080        tmpdevice.cardip = QString("%1.%2.%3.%4")
    22302081            .arg((device_ip>>24) & 0xFF).arg((device_ip>>16) & 0xFF)
    22312082            .arg((device_ip>> 8) & 0xFF).arg((device_ip>> 0) & 0xFF);
    22322083
    2233         tmpdevice.cardtuner = QString("%1").arg(tuner);
    22342084        return true;
    22352085    }
    22362086#endif // USING_HDHOMERUN
  • mythtv/libs/libmythtv/videosource.h

    diff --git a/mythtv/libs/libmythtv/videosource.h b/mythtv/libs/libmythtv/videosource.h
    index a18fde4ee7..4682846157 100644
    a b class HDHomeRunDevice 
    384384{
    385385  public:
    386386    QString mythdeviceid;
    387     QString deviceid;
    388387    QString desc;
    389388    QString cardip;
    390     QString cardtuner;
     389    QString deviceid;
    391390    bool    inuse;
    392391    bool    discovered;
    393392};
    typedef QMap<QString, HDHomeRunDevice> HDHomeRunDeviceList; 
    396395
    397396class HDHomeRunDeviceIDList;
    398397class HDHomeRunDeviceID;
    399 class HDHomeRunIP;
    400 class HDHomeRunTunerIndex;
    401398class HDHomeRunConfigurationGroup : public GroupSetting
    402399{
    403400    Q_OBJECT
    class HDHomeRunConfigurationGroup : public GroupSetting 
    414411  private:
    415412    CaptureCard           &parent;
    416413    StandardSetting       *desc;
     414    StandardSetting       *cardip;
    417415    HDHomeRunDeviceIDList *deviceidlist;
    418416    HDHomeRunDeviceID     *deviceid;
    419     HDHomeRunIP           *cardip;
    420     HDHomeRunTunerIndex   *cardtuner;
    421417    HDHomeRunDeviceList    devicelist;
    422418};
    423419
    class CardInput : public GroupSetting 
    878874    MythUICheckBoxSetting *schedgroup;
    879875};
    880876
    881 class HDHomeRunDeviceID;
    882 class HDHomeRunTunerIndex;
    883 
    884 class HDHomeRunIP : public MythUITextEditSetting
    885 {
    886     Q_OBJECT
    887 
    888   public:
    889     HDHomeRunIP();
    890 
    891     void setEnabled(bool e) override; // StandardSetting
    892     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 MythUITextEditSetting
     877class HDHomeRunDeviceID : public MythUITextEditSetting
    906878{
    907879    Q_OBJECT
    908880
    909881  public:
    910     HDHomeRunTunerIndex();
    911 
    912     void setEnabled(bool e) override; // StandardSetting
    913     void SetOldValue(const QString &s)
    914         { _oldValue = s; _oldValue.detach(); };
     882    HDHomeRunDeviceID(const CaptureCard &parent);
    915883
    916884  signals:
    917     void NewTuner(const QString&);
     885    void NewDeviceID(const QString&);
    918886
    919887  public slots:
    920888    void UpdateDevices(const QString&);
    921 
    922   private:
    923     QString _oldValue;
    924889};
    925890
    926 
    927891class HDHomeRunDeviceIDList : public TransMythUIComboBoxSetting
    928892{
    929893    Q_OBJECT
    930894
    931895  public:
    932     HDHomeRunDeviceIDList(HDHomeRunDeviceID *deviceid,
    933                           StandardSetting *desc,
    934                           HDHomeRunIP       *cardip,
    935                           HDHomeRunTunerIndex *cardtuner,
     896    HDHomeRunDeviceIDList(StandardSetting *desc,
     897                          StandardSetting *cardip,
     898                          HDHomeRunDeviceID *deviceid,
    936899                          HDHomeRunDeviceList *devicelist,
    937900                          const CaptureCard &parent);
    938901
    class HDHomeRunDeviceIDList : public TransMythUIComboBoxSetting 
    944907    void UpdateDevices(const QString&);
    945908
    946909  private:
    947     HDHomeRunDeviceID   *_deviceid;
    948910    StandardSetting     *_desc;
    949     HDHomeRunIP         *_cardip;
    950     HDHomeRunTunerIndex *_cardtuner;
     911    StandardSetting     *_cardip;
     912    HDHomeRunDeviceID   *_deviceid;
    951913    HDHomeRunDeviceList *_devicelist;
    952914    const CaptureCard &m_parent;
    953915
    954916    QString              _oldValue;
    955917};
    956918
    957 class HDHomeRunDeviceID : public MythUITextEditSetting
    958 {
    959     Q_OBJECT
    960 
    961   public:
    962     explicit HDHomeRunDeviceID(const CaptureCard &parent);
    963 
    964     void Load(void) override; // StandardSetting
    965 
    966   public slots:
    967     void SetIP(const QString&);
    968     void SetTuner(const QString&);
    969     void SetOverrideDeviceID(const QString&);
    970 
    971   private:
    972     QString _ip;
    973     QString _tuner;
    974     QString _overridedeviceid;
    975 };
    976 
    977919///
    978920class VBoxDeviceID;
    979921class VBoxTunerIndex;