Ticket #12746: Ticket_2746_Fix_CEC.patch

File Ticket_2746_Fix_CEC.patch, 3.4 KB (added by Peter Bennett <pgbennett@…>, 3 years ago)

Patch to fix CEC support

  • mythtv/libs/libmythui/cecadapter.cpp

    diff --git a/mythtv/libs/libmythui/cecadapter.cpp b/mythtv/libs/libmythui/cecadapter.cpp
    index 00a8c73..a761e32 100644
    a b class CECAdapterPriv 
    126126            return false;
    127127        }
    128128
     129        // initialise the host on which libCEC is running
     130        adapter->InitVideoStandalone();
     131
    129132        // find adapters
    130133        cec_adapter *devices = new cec_adapter[MAX_CEC_DEVICES];
    131134        uint8_t num_devices = adapter->FindAdapters(devices, MAX_CEC_DEVICES, NULL);
    class CECAdapterPriv 
    231234
    232235        switch (command.opcode)
    233236        {
    234             // TODO
     237            case CEC_OPCODE_MENU_REQUEST:
     238                cec_keypress key;
     239                key.keycode = CEC_USER_CONTROL_CODE_ROOT_MENU;
     240                key.duration = 5;
     241                HandleKeyPress(key);
     242                // SetMenuState could be used to disable the TV menu here
     243                // That may be a user-unfriendly thing to do
     244                // So they have to see both the TV menu and the MythTV menu
     245                break;
     246
    235247            default:
    236248                break;
    237249        }
    class CECAdapterPriv 
    252264
    253265        QString code;
    254266        int action = 0;
     267        Qt::KeyboardModifier modifier = Qt::NoModifier;
    255268        switch (key.keycode)
    256269        {
    257270            case CEC_USER_CONTROL_CODE_NUMBER0:
    class CECAdapterPriv 
    365378            case CEC_USER_CONTROL_CODE_PLAY:
    366379                action = Qt::Key_P;
    367380                code   = "PLAY";
     381                // Play set to control-p to differentiate from pause
     382                modifier = Qt::ControlModifier;
    368383                break;
    369384            case CEC_USER_CONTROL_CODE_PAUSE:
    370                 action = Qt::Key_P; // same as play
     385                action = Qt::Key_P;
    371386                code   = "PAUSE";
    372387                break;
    373388            case CEC_USER_CONTROL_CODE_STOP:
    class CECAdapterPriv 
    566581            return 1;
    567582
    568583        GetMythUI()->ResetScreensaver();
    569         QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, action, Qt::NoModifier);
     584        QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, action, modifier);
    570585        qApp->postEvent(GetMythMainWindow(), (QEvent*)ke);
    571586
    572587        return 1;
    CECAdapter::CECAdapter() : MThread("CECAdapter"), m_priv(new CECAdapterPriv) 
    721736
    722737void CECAdapter::run()
    723738{
    724     for (;;) {
     739    RunProlog();
     740    while (IsValid()) {
    725741        // Note that a lock is used because the QWaitCondition needs it
    726742        // None of the other HandleActions callers need the lock because
    727743        // they call HandleActions at open/close time, when
    728744        // nothing else can be calling it....
    729745        gHandleActionsLock->lock();
    730746        gActionsReady->wait(gHandleActionsLock);
    731         m_priv->HandleActions();
     747        if (IsValid()) {
     748            m_priv->HandleActions();
     749        }
    732750        gHandleActionsLock->unlock();
    733751    }
     752    RunEpilog();
    734753}
    735754
    736755CECAdapter::~CECAdapter()
    737756{
    738757    QMutexLocker lock(gLock);
    739758
    740     // stop thread
    741     if (isRunning())
    742     {
    743         LOG(VB_GENERAL, LOG_DEBUG, LOC + "Stopping thread.");
    744         exit();
    745     }
    746 
    747759    // delete the actual adapter
    748760    m_priv->Close();
     761    // Free the thread
     762    gActionsReady->wakeAll();
     763    // Wait for it to end
     764    wait();
    749765}
    750766
    751767bool CECAdapter::IsValid(void)
    752768{
    753     QMutexLocker lock(gLock);
    754769    return m_priv->valid;
    755770}
    756771