Ticket #6138: hdhomerun.multirecidchange.4.patch

File hdhomerun.multirecidchange.4.patch, 8.2 KB (added by cizek@…, 11 years ago)

Allow ID-tuner# or IP-tuner# devicename

  • mythtv/libs/libmythhdhomerun/hdhomerun_device.c

    diff -p -r -u -N -X /tmp/diff.exclude.16545 -x myth.20746.0626c -x myth.20746.0626d myth.20746.0626c/mythtv/libs/libmythhdhomerun/hdhomerun_device.c myth.20746.0626d/mythtv/libs/libmythhdhomerun/hdhomerun_device.c
    static struct hdhomerun_device_t *hdhome 
    145145static struct hdhomerun_device_t *hdhomerun_device_create_from_str_ip(const char *device_str)
    146146{
    147147        unsigned long a[4];
    148         if (sscanf(device_str, "%lu.%lu.%lu.%lu", &a[0], &a[1], &a[2], &a[3]) != 4) {
    149                 return NULL;
     148        unsigned int tuner;
     149
     150        if (sscanf(device_str, "%lu.%lu.%lu.%lu-%u", &a[0], &a[1], &a[2], &a[3], &tuner) != 5) {
     151                tuner = 0;
     152                if (sscanf(device_str, "%lu.%lu.%lu.%lu", &a[0], &a[1], &a[2], &a[3]) != 4) {
     153                        return NULL;
     154                }
    150155        }
    151156
    152157        unsigned long device_ip = (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | (a[3] << 0);
    153         return hdhomerun_device_create(HDHOMERUN_DEVICE_ID_WILDCARD, (uint32_t)device_ip, 0);
     158        return hdhomerun_device_create(HDHOMERUN_DEVICE_ID_WILDCARD, (uint32_t)device_ip, tuner);
    154159}
    155160
    156161static struct hdhomerun_device_t *hdhomerun_device_create_from_str_dns(const char *device_str)
  • mythtv/libs/libmythtv/hdhrstreamhandler.cpp

    diff -p -r -u -N -X /tmp/diff.exclude.16545 -x myth.20746.0626c -x myth.20746.0626d myth.20746.0626c/mythtv/libs/libmythtv/hdhrstreamhandler.cpp myth.20746.0626d/mythtv/libs/libmythtv/hdhrstreamhandler.cpp
    HDHRStreamHandler *HDHRStreamHandler::Ge 
    3535{
    3636    QMutexLocker locker(&_handlers_lock);
    3737
     38    QString devkey = devname.toUpper();
     39
    3840    QMap<QString,HDHRStreamHandler*>::iterator it =
    39         _handlers.find(devname);
     41        _handlers.find(devkey);
     42
     43    hdhr_id_data device_data;
    4044
    4145    if (it == _handlers.end())
    4246    {
    43         HDHRStreamHandler *newhandler = new HDHRStreamHandler(devname);
     47        // Not found in the current _handlers
     48        // Try to find the physical device and determine a unique device key
     49        // Then check to see if the unique key exists
     50        FindDevice(devname, device_data);
     51
     52        devkey = QString("%1-%2").arg(device_data.device_id, 8, 16)
     53                                 .arg(device_data.tuner);
     54
     55        // If the physical device is not found use the key "NOTFOUND-0"
     56        if (device_data.device_id == 0)
     57            devkey = "NOTFOUND-0";
     58
     59        devkey = devkey.toUpper();
     60        it = _handlers.find(devkey);
     61    }
     62
     63
     64    if (it == _handlers.end())
     65    {
     66        HDHRStreamHandler *newhandler = new HDHRStreamHandler(devkey, device_data);
    4467        newhandler->Open();
    45         _handlers[devname] = newhandler;
    46         _handlers_refcnt[devname] = 1;
     68        _handlers[devkey] = newhandler;
     69        _handlers_refcnt[devkey] = 1;
     70
     71        // If we are adding a "NOTFOUND" device, up its refcount so we never delete it.
     72        if (device_data.device_id == 0)
     73            _handlers_refcnt[devkey]++;
     74
    4775        VERBOSE(VB_RECORD,
    48                 QString("HDHRSH: Creating new stream handler for %1")
    49                 .arg(devname));
     76                QString("HDHRSH: Creating new stream handler %1 for %2")
     77                .arg(devkey).arg(devname));
    5078    }
    5179    else
    5280    {
    53         _handlers_refcnt[devname]++;
    54         uint rcount = _handlers_refcnt[devname];
     81        _handlers_refcnt[devkey]++;
     82        uint rcount = _handlers_refcnt[devkey];
    5583        VERBOSE(VB_RECORD,
    56                 QString("HDHRSH: Using existing stream handler for %1")
    57                 .arg(devname) + QString(" (%2 in use)").arg(rcount));
     84                QString("HDHRSH: Using existing stream handler %1 for %2")
     85                .arg(devkey).arg(devname) + QString(" (%1 in use)").arg(rcount));
    5886    }
    5987
    60     return _handlers[devname];
     88    return _handlers[devkey];
    6189}
    6290
    6391void HDHRStreamHandler::Return(HDHRStreamHandler * & ref)
    void HDHRStreamHandler::Return(HDHRStrea 
    98126    ref = NULL;
    99127}
    100128
    101 HDHRStreamHandler::HDHRStreamHandler(const QString &devicename) :
     129HDHRStreamHandler::HDHRStreamHandler(const QString &devicename, hdhr_id_data & device_data) :
    102130    _control_socket(NULL),
    103131    _video_socket(NULL),
     132    _device_id(device_data.device_id),
     133    _device_ip(device_data.device_ip),
     134    _tuner(device_data.tuner),
    104135    _devicename(devicename),
    105136
    106137    _start_stop_lock(QMutex::Recursive),
    PIDPriority HDHRStreamHandler::GetPIDPri 
    577608
    578609bool HDHRStreamHandler::Open(void)
    579610{
    580     if (!FindDevice())
     611    // By the time we get here we have a unique device_id & device_ip pair
     612    // for the hdhomerun. _device_id == 0 and _devicename == "NOTFOUND-0"
     613    // denote a device which is configured but we coudn't find.
     614    if (_device_id == 0)
    581615        return false;
    582 
    583616    return Connect();
    584617}
    585618
    bool HDHRStreamHandler::Connect(void) 
    613646    return true;
    614647}
    615648
    616 bool HDHRStreamHandler::FindDevice(void)
     649void HDHRStreamHandler::FindDevice(const QString & _devicename, hdhr_id_data &device_data)
    617650{
    618651    hdhomerun_device_t* thisdevice = hdhomerun_device_create_from_str(
    619652        _devicename.toLocal8Bit().constData());
    620653
    621654    if (thisdevice)
    622655    {
    623         _device_id = hdhomerun_device_get_device_id(thisdevice);
    624         _device_ip = hdhomerun_device_get_device_ip(thisdevice);
    625         _tuner     = hdhomerun_device_get_tuner(thisdevice);
     656        device_data.device_id = hdhomerun_device_get_device_id(thisdevice);
     657        device_data.device_ip = hdhomerun_device_get_device_ip(thisdevice);
     658        device_data.tuner     = hdhomerun_device_get_tuner(thisdevice);
    626659        hdhomerun_device_destroy(thisdevice);
    627660
    628         VERBOSE(VB_IMPORTANT, LOC +
    629                 QString("device %5 found at address %1.%2.%3.%4 tuner %6")
    630                 .arg((_device_ip>>24) & 0xFF).arg((_device_ip>>16) & 0xFF)
    631                 .arg((_device_ip>> 8) & 0xFF).arg((_device_ip>> 0) & 0xFF)
    632                 .arg(_devicename).arg(_tuner));
    633 
    634         return true;
     661        if (device_data.device_ip != 0)
     662        {
     663            VERBOSE(VB_IMPORTANT,
     664                    QString("HDHRSH: device %1 found at address %2.%3.%4.%5 tuner %6")
     665                    .arg(_devicename)
     666                    .arg((device_data.device_ip>>24) & 0xFF)
     667                    .arg((device_data.device_ip>>16) & 0xFF)
     668                    .arg((device_data.device_ip>> 8) & 0xFF)
     669                    .arg((device_data.device_ip>> 0) & 0xFF)
     670                    .arg(device_data.tuner));
     671        }
     672        else
     673        {
     674            VERBOSE(VB_IMPORTANT,
     675                    QString("HDHRSH: hdhomerun device %1 not found").arg(_devicename));
     676            device_data.device_id = 0;
     677            device_data.device_ip = hdhomerun_device_get_device_ip_requested(thisdevice);
     678            device_data.tuner     = 0;
     679        }
     680    }
     681    else
     682    {
     683        VERBOSE(VB_IMPORTANT,
     684                QString("HDHRSH: hdhomerun device %1 not found").arg(_devicename));
     685        device_data.device_id = 0;
     686        device_data.device_ip = 0;
     687        device_data.tuner     = 0;
    635688    }
    636     return false;
    637689}
    638690
    639691
  • mythtv/libs/libmythtv/hdhrstreamhandler.h

    diff -p -r -u -N -X /tmp/diff.exclude.16545 -x myth.20746.0626c -x myth.20746.0626d myth.20746.0626c/mythtv/libs/libmythtv/hdhrstreamhandler.h myth.20746.0626d/mythtv/libs/libmythtv/hdhrstreamhandler.h
    typedef QMap<uint,int> FilterMap; 
    3030
    3131//#define RETUNE_TIMEOUT 5000
    3232
     33struct hdhr_id_data {
     34    uint device_id;
     35    uint device_ip;
     36    uint tuner;
     37};
     38
    3339class HDHRStreamHandler : public ReaderPausedCB
    3440{
    3541    friend void *run_hdhr_stream_handler_thunk(void *param);
    class HDHRStreamHandler : public ReaderP 
    5561    virtual void ReaderPaused(int fd) { (void) fd; }
    5662
    5763  private:
    58     HDHRStreamHandler(const QString &);
     64    HDHRStreamHandler(const QString &, hdhr_id_data &);
    5965    ~HDHRStreamHandler();
    6066
    61     bool FindDevice(void);
     67    static void FindDevice(const QString &, hdhr_id_data &);
    6268    bool Connect(void);
    6369
    6470    QString DeviceGet(const QString &name,