Ticket #11338: libcec-2-support.2.patch

File libcec-2-support.2.patch, 16.6 KB (added by macarno@…, 11 years ago)

Update

  • mythtv/configure

    diff --git a/mythtv/configure b/mythtv/configure
    index 7ab8aa7..7d5e39d 100755
    a b using namespace std; 
    51785178using namespace CEC;
    51795179#include <libcec/cecloader.h>
    51805180int main(void) {
     5181    if (CEC_LIB_VERSION_MAJOR == 2)
     5182        return 1;
    51815183    if (CEC_LIB_VERSION_MAJOR < 1 || (CEC_LIB_VERSION_MAJOR == 1 &&
    51825184                                      CEC_LIB_VERSION_MINOR < 5))
    51835185        return 0;
    5184     return (long) LibCecInit;
     5186    return 1;
    51855187}
    51865188EOF
    51875189fi
  • mythtv/libs/libmythui/cecadapter.cpp

    diff --git a/mythtv/libs/libmythui/cecadapter.cpp b/mythtv/libs/libmythui/cecadapter.cpp
    index edad8f6..5987d5d 100644
    a b  
    1414#include "cecadapter.h"
    1515#include <vector>
    1616
    17 #define MIN_LIBCEC_VERSION 1
     17#ifdef CEC_CLIENT_VERSION_CURRENT // 2.0.3 and up
     18#define CEC_CONFIG_VERSION CEC_CLIENT_VERSION_CURRENT;
     19#else
     20#ifdef LIBCEC_VERSION_CURRENT // 1.6.2 and up
     21#define CEC_CONFIG_VERSION LIBCEC_VERSION_CURRENT;
     22#else
     23#define CEC_CONFIG_VERSION 0;
     24#endif
     25#endif
     26
    1827#define MAX_CEC_DEVICES 10
    1928#define LOC QString("CECAdapter: ")
     29#define OSDNAME "MythTv"
     30
     31// TODO remove if we have a ui.
     32// hard code logical and physical address
     33#define CEC_DEFAULT_DEVICE_TYPE CEC_DEVICE_TYPE_RECORDING_DEVICE
     34#undef CEC_DEFAULT_HDMI_PORT
     35#define CEC_DEFAULT_HDMI_PORT 2
     36#undef CEC_DEFAULT_BASE_DEVICE
     37#define CEC_DEFAULT_BASE_DEVICE CECDEVICE_AUDIOSYSTEM
     38#define CEC_DEFAULT_PHYSICALADDRESS (quint16)0x2200
    2039
    2140#include <libcec/cec.h>
    2241#include <iostream>
    using namespace std; 
    2544#include <libcec/cecloader.h>
    2645
    2746QMutex* CECAdapter::gLock = new QMutex(QMutex::Recursive);
     47bool resetSafe = false;
    2848
    2949class CECAdapterPriv
    3050{
    3151  public:
    3252    CECAdapterPriv()
    33       : adapter(NULL), defaultDevice("auto"), defaultHDMIPort(1),
    34         defaultDeviceID(CECDEVICE_PLAYBACKDEVICE1), timer(NULL), valid(false),
     53      : adapter(NULL), defaultDevice("auto"), defaultHDMIPort(CEC_DEFAULT_HDMI_PORT),
     54        defaultDeviceID(CEC_DEFAULT_DEVICE_TYPE), timer(NULL), valid(false),
    3555        powerOffTV(false),  powerOffTVAllowed(false), powerOffTVOnExit(false),
    3656        powerOnTV(false),   powerOnTVAllowed(false),  powerOnTVOnStart(false),
    3757        switchInput(false), switchInputAllowed(true)
    3858    {
     59        callbacks.Clear();
     60        callbacks.CBCecLogMessage =            LogMessages;
     61        callbacks.CBCecKeyPress =              HandleKeyPresses;
     62        callbacks.CBCecCommand =               HandleCommands;
     63        callbacks.CBCecConfigurationChanged =  HandleConfigurationChanged;
     64        callbacks.CBCecAlert =                 HandleAlerts;
     65        callbacks.CBCecMenuStateChanged =      HandleMenuStateChanged;
     66        callbacks.CBCecSourceActivated =       HandleSourceActivated;
    3967    }
    4068
    4169    static QString addressToString(enum cec_logical_address addr, bool source)
    class CECAdapterPriv 
    6997    static QStringList GetDeviceList(void)
    7098    {
    7199        QStringList results;
    72         cec_device_type_list list;
    73         list.Clear();
    74         list.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
    75         ICECAdapter *adapter = LibCecInit("MythTV", list);
     100        libcec_configuration configuration;
     101        configuration.Clear();
     102        ICECAdapter *adapter = LibCecInitialise(&configuration);
    76103        if (!adapter)
    77104            return results;
    78105        cec_adapter *devices = new cec_adapter[MAX_CEC_DEVICES];
    79106        uint8_t num_devices = adapter->FindAdapters(devices, MAX_CEC_DEVICES, NULL);
     107        LOG(VB_GENERAL, LOG_INFO, LOC + QString("GetDeviceList() found %1 devices(s).")
     108            .arg(num_devices));
    80109        if (num_devices < 1)
    81110            return results;
    82111        for (uint8_t i = 0; i < num_devices; i++)
    class CECAdapterPriv 
    89118    {
    90119        // get settings
    91120        // N.B. these do not currently work as there is no UI
     121
     122        // There is no way current CEC adapters can find their physical address
     123        // on their own. The are only connected to the CEC pin of the HDMI connector.
     124        // To construct a valid physical address libCEC needs:
     125        // - the HDMI port (number) Myth is connected to
     126        // - the HDMI device (TV, Receiver) Myth is connected to (the logical address)
     127
     128        //The CEC adapter we want to connect to
    92129        defaultDevice     = gCoreContext->GetSetting(LIBCEC_DEVICE, "auto").trimmed();
     130        // The number of the HDMI port Myth is connected to
    93131        QString hdmi_port = gCoreContext->GetSetting(LIBCEC_PORT, "auto");
     132        // The logical address of the HDMI device Myth is connected to
     133        QString base_dev  = gCoreContext->GetSetting(LIBCEC_BASE, "auto");
     134        // Device type we want Myth to use
    94135        QString device_id = gCoreContext->GetSetting(LIBCEC_DEVICEID, "auto");
    95136        powerOffTVAllowed = (bool)gCoreContext->GetNumSetting(POWEROFFTV_ALLOWED, 1);
    96137        powerOffTVOnExit  = (bool)gCoreContext->GetNumSetting(POWEROFFTV_ONEXIT, 1);
    97138        powerOnTVAllowed  = (bool)gCoreContext->GetNumSetting(POWERONTV_ALLOWED, 1);
    98139        powerOnTVOnStart  = (bool)gCoreContext->GetNumSetting(POWERONTV_ONSTART, 1);
    99140
    100         defaultHDMIPort = 1;
    101141        if ("auto" != hdmi_port)
    102142        {
    103143            defaultHDMIPort = hdmi_port.toInt();
    104             if (defaultHDMIPort < 1 || defaultHDMIPort > 3)
    105                 defaultHDMIPort = 1;
     144            if (defaultHDMIPort < CEC_MIN_HDMI_PORTNUMBER || defaultHDMIPort > CEC_MAX_HDMI_PORTNUMBER)
     145                defaultHDMIPort = CEC_DEFAULT_HDMI_PORT;
     146        }
     147        else
     148        {
     149            defaultHDMIPort = CEC_DEFAULT_HDMI_PORT;
    106150        }
    107         defaultHDMIPort = defaultHDMIPort << 12;
    108151
    109         defaultDeviceID = CECDEVICE_PLAYBACKDEVICE1;
    110152        if ("auto" != device_id)
    111153        {
    112154            int id = device_id.toInt();
    113             if (id < 1 || id > 3)
    114                 id = 1;
    115             defaultDeviceID = (id == 1) ? CECDEVICE_PLAYBACKDEVICE1 :
    116                              ((id == 2) ? CECDEVICE_PLAYBACKDEVICE2 :
    117                                           CECDEVICE_PLAYBACKDEVICE3);
     155            switch (id)
     156            {
     157                case CEC_DEVICE_TYPE_TV:
     158                case CEC_DEVICE_TYPE_RECORDING_DEVICE:
     159                case CEC_DEVICE_TYPE_RESERVED:
     160                case CEC_DEVICE_TYPE_TUNER:
     161                case CEC_DEVICE_TYPE_PLAYBACK_DEVICE:
     162                case CEC_DEVICE_TYPE_AUDIO_SYSTEM:
     163                    defaultDeviceID = (cec_device_type)id;
     164                    break;
     165                default:
     166                    defaultDeviceID = CEC_DEFAULT_DEVICE_TYPE;
     167                    break;
     168            }
     169        }
     170        else
     171        {
     172            defaultDeviceID = CEC_DEFAULT_DEVICE_TYPE;
    118173        }
    119174
     175        LOG(VB_GENERAL, LOG_INFO, LOC + QString("base_dev= %1.")
     176            .arg(base_dev));
     177        if ("auto" != base_dev)
     178        {
     179            base_device = (cec_logical_address)base_dev.toInt();
     180        LOG(VB_GENERAL, LOG_INFO, LOC + QString("base_device= %1.")
     181            .arg(base_device));
     182            switch (base_device)
     183            {
     184                case CECDEVICE_TV:
     185                case CECDEVICE_RECORDINGDEVICE1:
     186                case CECDEVICE_RECORDINGDEVICE2:
     187                case CECDEVICE_TUNER1:
     188                case CECDEVICE_PLAYBACKDEVICE1:
     189                case CECDEVICE_AUDIOSYSTEM:
     190                case CECDEVICE_TUNER2:
     191                case CECDEVICE_TUNER3:
     192                case CECDEVICE_PLAYBACKDEVICE2:
     193                case CECDEVICE_RECORDINGDEVICE3:
     194                case CECDEVICE_TUNER4:
     195                case CECDEVICE_PLAYBACKDEVICE3:
     196                case CECDEVICE_FREEUSE:
     197                    break;
     198                case CECDEVICE_UNKNOWN:
     199                case CECDEVICE_RESERVED1:
     200                case CECDEVICE_RESERVED2:
     201                case CECDEVICE_BROADCAST:
     202                default:
     203                    base_device = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE;
     204                    break;
     205            }
     206        }
     207        else
     208        {
     209            base_device = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE;
     210        }
     211 
    120212        // create adapter interface
    121         cec_device_type_list list;
    122         list.Clear();
    123         list.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
    124         adapter = LibCecInit("MythTV", list);
     213        libcec_configuration configuration;
     214        configuration.Clear();
     215        configuration.clientVersion = LIBCEC_VERSION_CURRENT;
     216        snprintf(configuration.strDeviceName, 13, "MythTV");
     217        configuration.deviceTypes.Add(defaultDeviceID);
     218        configuration.iPhysicalAddress = CEC_DEFAULT_PHYSICALADDRESS;
     219        configuration.iHDMIPort = defaultHDMIPort;
     220        LOG(VB_GENERAL, LOG_INFO, LOC + QString("using HDMI port %1.")
     221            .arg(defaultHDMIPort));
     222        configuration.baseDevice = base_device;
     223        LOG(VB_GENERAL, LOG_INFO, LOC + QString("using base device %1.")
     224            .arg(configuration.baseDevice));
     225        configuration.callbacks    = &callbacks;
     226        ICECAdapter *adapter = LibCecInitialise(&configuration);
    125227
    126228        if (!adapter)
    127229        {
    class CECAdapterPriv 
    129231            return false;
    130232        }
    131233
    132         if (adapter->GetMinLibVersion() > MIN_LIBCEC_VERSION)
     234        if ((configuration.serverVersion >> 12) > CEC_MIN_LIB_VERSION)
    133235        {
    134236            LOG(VB_GENERAL, LOG_ERR, LOC +
    135237                QString("The installed libCEC supports version %1 and above. "
    136238                        "This version of MythTV only supports version %2.")
    137                 .arg(adapter->GetMinLibVersion()).arg(MIN_LIBCEC_VERSION));
     239                .arg(configuration.serverVersion).arg(CEC_MIN_LIB_VERSION));
    138240            return false;
    139241        }
    140242
    class CECAdapterPriv 
    185287        // get the vendor ID (for non-standard implementations)
    186288        adapter->GetDeviceVendorId(CECDEVICE_TV);
    187289
    188         // set the physical address
    189         adapter->SetPhysicalAddress(defaultHDMIPort);
    190 
    191         // set the logical address
    192         adapter->SetLogicalAddress(defaultDeviceID);
    193 
    194290        // switch input (if configured)
    195291        switchInput = true;
    196292        HandleActions();
    class CECAdapterPriv 
    210306
    211307            // delete adapter
    212308            adapter->Close();
    213             LogMessages();
    214309            UnloadLibCec(adapter);
    215310
    216311            LOG(VB_GENERAL, LOG_INFO, LOC + "Closing down CEC.");
    class CECAdapterPriv 
    219314        adapter = NULL;
    220315    }
    221316
    222     void LogMessages(void)
     317    #if CEC_LIB_VERSION_MAJOR < 2
     318    static int LogMessages(void *, const cec_log_message &message)
     319    #else
     320    static int LogMessages(void *, const cec_log_message message)
     321    #endif
    223322    {
    224         if (!adapter || !valid)
    225             return;
    226 
    227         cec_log_message message;
    228         while (adapter->GetNextLogMessage(&message))
    229         {
    230323            QString msg(message.message);
    231324            int lvl = LOG_UNKNOWN;
    232325            switch (message.level)
    class CECAdapterPriv 
    237330            case CEC_LOG_DEBUG:   lvl = LOG_DEBUG;   break;
    238331            }
    239332            LOG(VB_GENERAL, lvl, LOC + QString("%1").arg(msg));
    240         }
     333            return 0;
    241334    }
    242335
    243     void HandleCommands(void)
     336    #if CEC_LIB_VERSION_MAJOR < 2
     337    static int HandleCommands(void * /*cbParam*/, const cec_command &command)
     338    #else
     339    static int HandleCommands(void * /*cbParam*/, const cec_command command)
     340    #endif
    244341    {
    245         if (!adapter || !valid)
    246             return;
    247 
    248         LogMessages();
    249 
    250         cec_command command;
    251         while (adapter->GetNextCommand(&command))
    252         {
    253342            LOG(VB_GENERAL, LOG_DEBUG, LOC +
    254343                QString("Command %1 from '%2' (%3) - destination '%4' (%5)")
    255344                .arg(command.opcode)
    class CECAdapterPriv 
    260349
    261350            switch (command.opcode)
    262351            {
    263                 // TODO
     352                // TODO handle CEC commands.
    264353                default:
    265354                    break;
    266355            }
    267         }
     356            return 0;
     357    }
    268358
    269         LogMessages();
     359    #if CEC_LIB_VERSION_MAJOR < 2
     360    static int HandleConfigurationChanged(void * /*cbParam*/, const libcec_configuration &config)
     361    #else
     362    static int HandleConfigurationChanged(void * /*cbParam*/, const libcec_configuration config)
     363    #endif
     364    {
     365        LOG(VB_GENERAL, LOG_INFO, LOC + "Adapter configuration changed.");
     366        return 1;
    270367    }
    271368
    272     void HandleKeyPresses(void)
     369    #if CEC_LIB_VERSION_MAJOR < 2
     370    static int HandleAlerts(void * /*cbParam*/, const libcec_alert type, const libcec_parameter & /*param*/)
     371    #else
     372    static int HandleAlerts(void * /*cbParam*/, const libcec_alert type, const libcec_parameter /*param*/)
     373    #endif
    273374    {
    274         if (!adapter || !valid)
    275             return;
     375        switch (type) // TODO Handle alerts.
     376        {
     377        case CEC_ALERT_CONNECTION_LOST:
     378          LOG(VB_GENERAL, LOG_ERR, LOC + "Connection lost - TODO: need to handle this!");
     379          break;
     380        default:
     381          LOG(VB_GENERAL, LOG_ERR, LOC + "Received unknown alert.");
     382          break;
     383        }
     384        return 0;
     385    }
    276386
    277         cec_keypress key;
    278         if (!adapter->GetNextKeypress(&key))
    279             return;
     387    #if CEC_LIB_VERSION_MAJOR < 2
     388    static int HandleMenuStateChanged(void * /*cbParam*/, const cec_menu_state &state)
     389    #else
     390    static int HandleMenuStateChanged(void * /*cbParam*/, const cec_menu_state state)
     391    #endif
     392    {
     393        LOG(VB_GENERAL, LOG_INFO, LOC + QString("CEC menu state %1")
     394            .arg(state == CEC_MENU_STATE_ACTIVATED ? "Activated" : "Deactivated"));
     395        return 1;
     396    }
    280397
     398    #if CEC_LIB_VERSION_MAJOR < 2
     399    static void HandleSourceActivated(void * /*cbParam*/, const cec_logical_address &address, const &uint8_t activated)
     400    #else
     401    static void HandleSourceActivated(void * /*cbParam*/, const cec_logical_address address, const uint8_t activated)
     402    #endif
     403    {
     404        LOG(VB_GENERAL, LOG_INFO, LOC + QString("Source %1 %2")
     405            .arg(address).arg(activated ? "Activated" : "Deactivated"));
     406
     407        if (activated && resetSafe)
     408                GetMythUI()->ResetScreensaver();
     409        else
     410            resetSafe = true;
     411     }
     412
     413    #if CEC_LIB_VERSION_MAJOR < 2
     414    static int HandleKeyPresses(void * /*cbParam*/, const cec_keypress &key)
     415    #else
     416    static int HandleKeyPresses(void * /*cbParam*/, const cec_keypress key)
     417    #endif
     418    {
    281419        // Ignore key down events and wait for the key 'up'
    282420        if (key.duration < 1)
    283             return;
     421            return 0;
    284422
    285423        QString code;
    286424        int action = 0;
    class CECAdapterPriv 
    595733            .arg(code).arg(0 == action ? "(Not actioned)" : ""));
    596734
    597735        if (0 == action)
    598             return;
     736            return 0;
    599737
    600738        GetMythUI()->ResetScreensaver();
    601739        QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, action, Qt::NoModifier);
    602740        qApp->postEvent(GetMythMainWindow(), (QEvent*)ke);
    603 
    604         LogMessages();
     741        return 0;
    605742    }
    606743
    607744    void HandleActions(void)
    class CECAdapterPriv 
    629766        // HDMI input
    630767        if (switchInput && switchInputAllowed)
    631768        {
    632             if (adapter->SetActiveView())
     769            if (adapter->SetActiveSource())
    633770                LOG(VB_GENERAL, LOG_INFO, LOC + "Asked TV to switch to this input.");
    634771            else
    635772                LOG(VB_GENERAL, LOG_ERR,  LOC + "Failed to switch to this input.");
    class CECAdapterPriv 
    638775        powerOffTV  = false;
    639776        powerOnTV   = false;
    640777        switchInput = false;
    641 
    642         LogMessages();
    643778    }
    644779
    645780    ICECAdapter *adapter;
     781    ICECCallbacks callbacks;
    646782    QString      defaultDevice;
    647783    int          defaultHDMIPort;
    648     cec_logical_address defaultDeviceID;
     784    cec_device_type defaultDeviceID;
     785    cec_logical_address base_device;
    649786    QTimer      *timer;
    650787    bool         valid;
    651788    bool         powerOffTV;
    void CECAdapter::Action(const QString &action) 
    728865void CECAdapter::Process(void)
    729866{
    730867    gLock->lock();
    731     m_priv->HandleCommands();
    732     m_priv->HandleKeyPresses();
    733868    m_priv->HandleActions();
    734869    gLock->unlock();
    735870}
  • mythtv/libs/libmythui/cecadapter.h

    diff --git a/mythtv/libs/libmythui/cecadapter.h b/mythtv/libs/libmythui/cecadapter.h
    index e9cf6d6..bb5eba8 100644
    a b  
    77#define LIBCEC_ENABLED     QString("libCECEnabled")
    88#define LIBCEC_DEVICE      QString("libCECDevice")
    99#define LIBCEC_PORT        QString("libCECPort")
     10#define LIBCEC_BASE        QString("libCECBase")
    1011#define LIBCEC_DEVICEID    QString("libCECDeviceID")
    1112#define POWEROFFTV_ALLOWED QString("PowerOffTVAllowed")
    1213#define POWEROFFTV_ONEXIT  QString("PowerOffTVOnExit")