Ticket #6881: hdhr-device-api.patch

File hdhr-device-api.patch, 8.6 KB (added by mikeb@…, 10 years ago)

update api calls

  • mythtv/libs/libmythtv/hdhrstreamhandler.cpp

     
    129129
    130130HDHRStreamHandler::HDHRStreamHandler(const QString &devicename,
    131131                                     hdhr_id_data  &device_data) :
    132     _control_socket(NULL),
    133     _video_socket(NULL),
     132    _hdhomerun_device(NULL),
    134133    _device_id(device_data.device_id),
    135134    _device_ip(device_data.device_ip),
    136135    _tuner(device_data.tuner),
     
    284283    buffersize = max(49 * TSPacket::SIZE * 128, buffersize);
    285284
    286285    /* Create TS socket. */
    287     _video_socket = hdhomerun_video_create(0, buffersize, NULL);
    288     if (!_video_socket)
     286    if (!hdhomerun_device_stream_start(_hdhomerun_device))
    289287    {
    290         VERBOSE(VB_IMPORTANT, LOC + "Open() failed to open socket");
    291         return;
    292     }
    293 
    294     uint localPort = hdhomerun_video_get_local_port(_video_socket);
    295     if (!DeviceSetTarget(localPort))
    296     {
    297288        VERBOSE(VB_IMPORTANT, LOC_ERR +
    298289                "Starting recording (set target failed). Aborting.");
    299290        return;
    300291    }
    301     hdhomerun_video_flush(_video_socket);
     292    hdhomerun_device_stream_flush(_hdhomerun_device);
    302293
    303294    bool _error = false;
    304295
     
    313304        read_size *= VIDEO_DATA_PACKET_SIZE;
    314305
    315306        size_t data_length;
    316         unsigned char *data_buffer =
    317             hdhomerun_video_recv(_video_socket, read_size, &data_length);
     307        unsigned char *data_buffer = hdhomerun_device_stream_recv(
     308            _hdhomerun_device, read_size, &data_length);
    318309
    319310        if (!data_buffer)
    320311        {
     
    350341
    351342    RemoveAllPIDFilters();
    352343
    353     DeviceClearTarget();
     344    hdhomerun_device_stream_stop(_hdhomerun_device);
    354345    VERBOSE(VB_RECORD, LOC + "RunTS(): " + "end");
    355346
    356     hdhomerun_video_sock_t* tmp_video_socket;
    357     {
    358         QMutexLocker locker(&_hdhr_lock);
    359         tmp_video_socket = _video_socket;
    360         _video_socket=NULL;
    361     }
    362 
    363     hdhomerun_video_destroy(tmp_video_socket);
    364 
    365     VERBOSE(VB_RECORD, LOC + "RunTS(): " + "end");
    366 
    367347    SetRunning(false);
    368348}
    369349
     
    620600
    621601void HDHRStreamHandler::Close(void)
    622602{
    623     if (_control_socket)
     603    if (_hdhomerun_device)
    624604    {
    625605        TuneChannel("none");
    626         hdhomerun_control_destroy(_control_socket);
    627         _control_socket=NULL;
     606        hdhomerun_device_destroy(_hdhomerun_device);
     607        _hdhomerun_device=NULL;
    628608    }
    629609}
    630610
    631611bool HDHRStreamHandler::Connect(void)
    632612{
    633     _control_socket = hdhomerun_control_create(_device_id, _device_ip, NULL);
     613    _hdhomerun_device = hdhomerun_device_create(_device_id, _device_ip, _tuner, NULL);
    634614
    635     if (!_control_socket)
     615    if (!_hdhomerun_device)
    636616    {
    637         VERBOSE(VB_IMPORTANT, LOC_ERR + "Unable to create control socket");
     617        VERBOSE(VB_IMPORTANT, LOC_ERR + "Unable to create hdhomerun object");
    638618        return false;
    639619    }
    640620
    641     if (hdhomerun_control_get_local_addr(_control_socket) == 0)
     621    if (hdhomerun_device_get_local_machine_addr(_hdhomerun_device) == 0)
    642622    {
    643623        VERBOSE(VB_IMPORTANT, LOC_ERR + "Unable to connect to device");
    644624        return false;
     
    694674
    695675bool HDHRStreamHandler::EnterPowerSavingMode(void)
    696676{
    697     if (_video_socket)
     677    if (!hdhomerun_device_get_video_sock(_hdhomerun_device))
    698678    {
    699679        VERBOSE(VB_RECORD, LOC + "Ignoring request - video streaming active");
    700680        return false;
     
    710690{
    711691    QMutexLocker locker(&_hdhr_lock);
    712692
    713     if (!_control_socket)
     693    if (!_hdhomerun_device)
    714694    {
    715695        VERBOSE(VB_IMPORTANT, LOC_ERR + "Get request failed (not connected)");
    716696        return QString::null;
     
    718698
    719699    char *value = NULL;
    720700    char *error = NULL;
    721     if (hdhomerun_control_get(
    722             _control_socket, name.toLocal8Bit().constData(),
     701    if (hdhomerun_device_get_var(
     702            _hdhomerun_device, name.toLocal8Bit().constData(),
    723703            &value, &error) < 0)
    724704    {
    725705        VERBOSE(VB_IMPORTANT, LOC_ERR + "Get request failed" + ENO);
     
    746726{
    747727    QMutexLocker locker(&_hdhr_lock);
    748728
    749     if (!_control_socket)
     729    if (!_hdhomerun_device)
    750730    {
    751731        VERBOSE(VB_IMPORTANT, LOC_ERR + "Set request failed (not connected)");
    752732        return QString::null;
     
    754734
    755735    char *value = NULL;
    756736    char *error = NULL;
    757     if (hdhomerun_control_set(
    758             _control_socket, name.toLocal8Bit().constData(),
     737    if (hdhomerun_device_set_var(
     738            _hdhomerun_device, name.toLocal8Bit().constData(),
    759739            val.toLocal8Bit().constData(), &value, &error) < 0)
    760740    {
    761741        VERBOSE(VB_IMPORTANT, LOC_ERR + "Set request failed" + ENO);
     
    800780        return false;
    801781    }
    802782
    803     unsigned long localIP = hdhomerun_control_get_local_addr(_control_socket);
     783    unsigned long localIP = hdhomerun_device_get_local_machine_addr(
     784        _hdhomerun_device);
    804785    if (localIP == 0)
    805786    {
    806787        return false;
     
    830811    return !TunerSet("target", "0.0.0.0:0").isEmpty();
    831812}
    832813
    833 QString HDHRStreamHandler::GetTunerStatus(void) const
     814void HDHRStreamHandler::GetTunerStatus(struct hdhomerun_tuner_status_t *status)
    834815{
    835     return TunerGet("status");
     816    hdhomerun_device_get_tuner_status(_hdhomerun_device, NULL, status);
    836817}
    837818
    838819bool HDHRStreamHandler::IsConnected(void) const
    839820{
    840     return (_control_socket != NULL);
     821    return (_hdhomerun_device != NULL);
    841822}
    842823
    843824bool HDHRStreamHandler::TuneChannel(const QString &chn)
  • mythtv/libs/libmythtv/hdhrsignalmonitor.cpp

     
    103103        return;
    104104    }
    105105
    106     QString msg = streamHandler->GetTunerStatus();
    107     //ss  = signal strength,        [0,100]
    108     //snq = signal to noise quality [0,100]
    109     //seq = signal error quality    [0,100]
    110     int loc_sig = msg.indexOf("ss="),  loc_snq = msg.indexOf("snq=");
    111     int loc_seq = msg.indexOf("seq="), loc_end = msg.length();
    112     bool ok0, ok1, ok2;
    113     uint sig = msg.mid(loc_sig + 3, loc_snq - loc_sig - 4).toUInt(&ok0);
    114     uint snq = msg.mid(loc_snq + 4, loc_seq - loc_snq - 5).toUInt(&ok1);
    115     uint seq = msg.mid(loc_seq + 4, loc_end - loc_seq - 4).toUInt(&ok2);
     106    struct hdhomerun_tuner_status_t status;
     107    streamHandler->GetTunerStatus(&status);
     108
     109    uint sig = status.signal_strength;
     110    uint snq = status.signal_to_noise_quality;
     111    uint seq = status.symbol_error_quality;
     112
    116113    (void) snq; // TODO should convert to S/N
    117114    (void) seq; // TODO should report this...
    118115
     
    124121    bool isLocked = false;
    125122    {
    126123        QMutexLocker locker(&statusLock);
    127         if (loc_sig > 0 && loc_snq > 0 && ok0)
    128             signalStrength.SetValue(sig);
    129         signalLock.SetValue(signalStrength.IsGood() ? 1 : 0);
     124        signalStrength.SetValue(sig);
     125        signalLock.SetValue(status.lock_supported);
    130126        isLocked = signalLock.IsGood();
    131127    }
    132128
  • mythtv/libs/libmythtv/hdhrchannel.cpp

     
    2727#include "channelutil.h"
    2828#include "hdhrstreamhandler.h"
    2929
    30 // HDHomeRun header
    31 #include "hdhomerun.h"
    32 
    3330#define DEBUG_PID_FILTERS
    3431
    3532#define LOC     QString("HDHRChan(%1): ").arg(GetDevice())
  • mythtv/libs/libmythtv/hdhrstreamhandler.h

     
    2222// HDHomeRun headers
    2323#ifdef USING_HDHOMERUN
    2424#include "hdhomerun.h"
    25 #undef max
    26 #undef min
    2725#else
    28 struct hdhomerun_control_sock_t { int dummy; };
     26struct hdhomerun_device_t { int dummy; };
    2927#endif
    3028
    3129typedef QMap<uint,int> FilterMap;
     
    5048    void RemoveListener(MPEGStreamData *data);
    5149
    5250    bool IsRunning(void) const { return _running; }
    53     QString GetTunerStatus(void) const;
     51    void GetTunerStatus(struct hdhomerun_tuner_status_t *status);
    5452    bool IsConnected(void) const;
    5553
    5654    // Commands
     
    107105    PIDPriority GetPIDPriority(uint pid) const;
    108106
    109107  private:
    110     hdhomerun_control_sock_t  *_control_socket;
    111     hdhomerun_video_sock_t    *_video_socket;
     108    hdhomerun_device_t  *_hdhomerun_device;
    112109    uint                       _device_id;
    113110    uint                       _device_ip;
    114111    uint                       _tuner;