X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECClient.cpp;h=837214f456f54e724c29032664087064875874f9;hb=f1f5731982c4a545a4d561fb7def1014bb648e34;hp=d6f8100dec9daa25b26b7e55986eeaf8e85f6858;hpb=90b7066f7129c01c5bd012a00677ebdc0c42ae89;p=deb_libcec.git diff --git a/src/lib/CECClient.cpp b/src/lib/CECClient.cpp index d6f8100..837214f 100644 --- a/src/lib/CECClient.cpp +++ b/src/lib/CECClient.cpp @@ -1,7 +1,7 @@ /* * This file is part of the libCEC(R) library. * - * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. + * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. * libCEC(R) is an original work, containing original code. * * libCEC(R) is a trademark of Pulse-Eight Limited. @@ -47,9 +47,6 @@ using namespace PLATFORM; #define LIB_CEC m_processor->GetLib() #define ToString(x) CCECTypeUtils::ToString(x) -#define COMBO_KEY CEC_USER_CONTROL_CODE_STOP -#define COMBO_TIMEOUT_MS 1000 - CCECClient::CCECClient(CCECProcessor *processor, const libcec_configuration &configuration) : m_processor(processor), m_bInitialised(false), @@ -184,8 +181,18 @@ bool CCECClient::SetHDMIPort(const cec_logical_address iBaseDevice, const uint8_ // set the default address when something went wrong if (!bReturn) { - LIB_CEC->AddLog(CEC_LOG_WARNING, "failed to set the physical address to %04X, setting it to the default value %04X", iPhysicalAddress, CEC_DEFAULT_PHYSICAL_ADDRESS); - iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS; + uint16_t iEepromAddress = m_processor->GetPhysicalAddressFromEeprom(); + if (CLibCEC::IsValidPhysicalAddress(iEepromAddress)) + { + LIB_CEC->AddLog(CEC_LOG_WARNING, "failed to set the physical address to %04X, setting it to the value that was persisted in the eeprom, %04X", iPhysicalAddress, iEepromAddress); + iPhysicalAddress = iEepromAddress; + bReturn = true; + } + else + { + LIB_CEC->AddLog(CEC_LOG_WARNING, "failed to set the physical address to %04X, setting it to the default value %04X", iPhysicalAddress, CEC_DEFAULT_PHYSICAL_ADDRESS); + iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS; + } } // and set the address @@ -198,7 +205,7 @@ bool CCECClient::SetHDMIPort(const cec_logical_address iBaseDevice, const uint8_ void CCECClient::ResetPhysicalAddress(void) { - SetPhysicalAddress(m_configuration); + SetPhysicalAddress(CEC_DEFAULT_PHYSICAL_ADDRESS); } void CCECClient::SetPhysicalAddress(const libcec_configuration &configuration) @@ -738,6 +745,45 @@ uint8_t CCECClient::SendMuteAudio(void) (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; } +uint8_t CCECClient::AudioToggleMute(void) +{ + CCECBusDevice *device = GetPrimaryDevice(); + CCECAudioSystem *audio = m_processor->GetAudioSystem(); + + return device && audio && audio->IsPresent() ? + audio->MuteAudio(device->GetLogicalAddress()) : + (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; +} + +uint8_t CCECClient::AudioMute(void) +{ + CCECBusDevice *device = GetPrimaryDevice(); + CCECAudioSystem *audio = m_processor->GetAudioSystem(); + uint8_t iStatus = device && audio && audio->IsPresent() ? audio->GetAudioStatus(device->GetLogicalAddress()) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; + if ((iStatus & CEC_AUDIO_MUTE_STATUS_MASK) != CEC_AUDIO_MUTE_STATUS_MASK) + iStatus = audio->MuteAudio(device->GetLogicalAddress()); + + return iStatus; +} + +uint8_t CCECClient::AudioUnmute(void) +{ + CCECBusDevice *device = GetPrimaryDevice(); + CCECAudioSystem *audio = m_processor->GetAudioSystem(); + uint8_t iStatus = device && audio && audio->IsPresent() ? audio->GetAudioStatus(device->GetLogicalAddress()) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; + if ((iStatus & CEC_AUDIO_MUTE_STATUS_MASK) == CEC_AUDIO_MUTE_STATUS_MASK) + iStatus = audio->MuteAudio(device->GetLogicalAddress()); + + return iStatus; +} + +uint8_t CCECClient::AudioStatus(void) +{ + CCECBusDevice *device = GetPrimaryDevice(); + CCECAudioSystem *audio = m_processor->GetAudioSystem(); + return device && audio && audio->IsPresent() ? audio->GetAudioStatus(device->GetLogicalAddress()) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; +} + bool CCECClient::SendKeypress(const cec_logical_address iDestination, const cec_user_control_code key, bool bWait /* = true */) { CCECBusDevice *dest = m_processor->GetDevice(iDestination); @@ -776,6 +822,7 @@ bool CCECClient::GetCurrentConfiguration(libcec_configuration &configuration) configuration.wakeDevices = m_configuration.wakeDevices; configuration.powerOffDevices = m_configuration.powerOffDevices; configuration.bPowerOffScreensaver = m_configuration.bPowerOffScreensaver; + configuration.bPowerOnScreensaver = m_configuration.bPowerOnScreensaver; configuration.bPowerOffOnStandby = m_configuration.bPowerOffOnStandby; configuration.bSendInactiveSource = m_configuration.bSendInactiveSource; configuration.logicalAddresses = m_configuration.logicalAddresses; @@ -793,6 +840,7 @@ bool CCECClient::GetCurrentConfiguration(libcec_configuration &configuration) bool CCECClient::SetConfiguration(const libcec_configuration &configuration) { + libcec_configuration defaultSettings; bool bIsRunning(m_processor && m_processor->CECInitialised()); CCECBusDevice *primary = bIsRunning ? GetPrimaryDevice() : NULL; uint16_t iPA = primary ? primary->GetCurrentPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS; @@ -828,7 +876,24 @@ bool CCECClient::SetConfiguration(const libcec_configuration &configuration) m_configuration.bMonitorOnly = configuration.bMonitorOnly; m_configuration.cecVersion = configuration.cecVersion; m_configuration.adapterType = configuration.adapterType; - m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); + m_configuration.iDoubleTapTimeoutMs = configuration.iDoubleTapTimeoutMs; + m_configuration.deviceTypes.Add(configuration.deviceTypes[0]); + + if (m_configuration.clientVersion >= CEC_CLIENT_VERSION_2_0_5) + { + m_configuration.comboKey = configuration.comboKey; + m_configuration.iComboKeyTimeoutMs = configuration.iComboKeyTimeoutMs; + } + else + { + m_configuration.comboKey = defaultSettings.comboKey; + m_configuration.iComboKeyTimeoutMs = defaultSettings.iComboKeyTimeoutMs; + } + + if (m_configuration.clientVersion >= CEC_CLIENT_VERSION_2_1_0) + m_configuration.bPowerOnScreensaver = configuration.bPowerOnScreensaver; + else + m_configuration.bPowerOnScreensaver = defaultSettings.bPowerOnScreensaver; } bool bNeedReinit(false); @@ -908,7 +973,10 @@ void CCECClient::AddKey(bool bSendComboKey /* = false */) { key.duration = (unsigned int) (GetTimeMs() - m_buttontime); - if (key.duration > COMBO_TIMEOUT_MS || m_iCurrentButton != COMBO_KEY || bSendComboKey) + if (key.duration > m_configuration.iComboKeyTimeoutMs || + m_configuration.iComboKeyTimeoutMs == 0 || + m_iCurrentButton != m_configuration.comboKey || + bSendComboKey) { key.keycode = m_iCurrentButton; @@ -927,24 +995,27 @@ void CCECClient::AddKey(bool bSendComboKey /* = false */) void CCECClient::AddKey(const cec_keypress &key) { - // send back the previous key if there is one - AddKey(); + if (key.keycode > CEC_USER_CONTROL_CODE_MAX || + key.keycode < CEC_USER_CONTROL_CODE_SELECT) + { + // send back the previous key if there is one + AddKey(); + return; + } cec_keypress transmitKey(key); + cec_user_control_code comboKey(m_configuration.clientVersion >= CEC_CLIENT_VERSION_2_0_5 ? + m_configuration.comboKey : CEC_USER_CONTROL_CODE_STOP); { CLockObject lock(m_mutex); - if (key.duration > 0 || key.keycode > CEC_USER_CONTROL_CODE_MAX) - { - transmitKey.keycode = CEC_USER_CONTROL_CODE_UNKNOWN; - } - else if (m_iCurrentButton == COMBO_KEY) + if (m_configuration.iComboKeyTimeoutMs > 0 && m_iCurrentButton == comboKey && key.duration == 0) { // stop + ok -> exit if (key.keycode == CEC_USER_CONTROL_CODE_SELECT) transmitKey.keycode = CEC_USER_CONTROL_CODE_EXIT; // stop + pause -> root menu - else if (key.keycode == CEC_USER_CONTROL_CODE_ROOT_MENU) + else if (key.keycode == CEC_USER_CONTROL_CODE_PAUSE) transmitKey.keycode = CEC_USER_CONTROL_CODE_ROOT_MENU; // stop + play -> dot (which is handled as context menu in xbmc) else if (key.keycode == CEC_USER_CONTROL_CODE_PLAY) @@ -954,12 +1025,26 @@ void CCECClient::AddKey(const cec_keypress &key) AddKey(true); } - m_iCurrentButton = transmitKey.keycode; - m_buttontime = m_iCurrentButton == CEC_USER_CONTROL_CODE_UNKNOWN || key.duration > 0 ? 0 : GetTimeMs(); + if (m_iCurrentButton == key.keycode) + { + m_buttontime = GetTimeMs(); + } + else + { + AddKey(); + if (key.duration == 0) + { + m_iCurrentButton = transmitKey.keycode; + m_buttontime = m_iCurrentButton == CEC_USER_CONTROL_CODE_UNKNOWN || key.duration > 0 ? 0 : GetTimeMs(); + } + } } - LIB_CEC->AddLog(CEC_LOG_DEBUG, "key pressed: %s (%1x)", ToString(transmitKey.keycode), transmitKey.keycode); - CallbackAddKey(transmitKey); + if (key.keycode != comboKey || key.duration > 0) + { + LIB_CEC->AddLog(CEC_LOG_DEBUG, "key pressed: %s (%1x)", ToString(transmitKey.keycode), transmitKey.keycode); + CallbackAddKey(transmitKey); + } } void CCECClient::SetCurrentButton(const cec_user_control_code iButtonCode) @@ -979,10 +1064,14 @@ void CCECClient::CheckKeypressTimeout(void) { CLockObject lock(m_mutex); uint64_t iNow = GetTimeMs(); + cec_user_control_code comboKey(m_configuration.clientVersion >= CEC_CLIENT_VERSION_2_0_5 ? + m_configuration.comboKey : CEC_USER_CONTROL_CODE_STOP); + uint32_t iTimeoutMs(m_configuration.clientVersion >= CEC_CLIENT_VERSION_2_0_5 ? + m_configuration.iComboKeyTimeoutMs : CEC_DEFAULT_COMBO_TIMEOUT_MS); if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN && - ((m_iCurrentButton == COMBO_KEY && iNow - m_buttontime > COMBO_TIMEOUT_MS) || - (m_iCurrentButton != COMBO_KEY && iNow - m_buttontime > CEC_BUTTON_TIMEOUT))) + ((m_iCurrentButton == comboKey && iTimeoutMs > 0 && iNow - m_buttontime > iTimeoutMs) || + (m_iCurrentButton != comboKey && iNow - m_buttontime > CEC_BUTTON_TIMEOUT))) { key.duration = (unsigned int) (iNow - m_buttontime); key.keycode = m_iCurrentButton; @@ -1245,7 +1334,7 @@ bool CCECClient::PollDevice(const cec_logical_address iAddress) CCECBusDevice *primary = GetPrimaryDevice(); // poll the destination, with the primary as source if (primary) - return primary->TransmitPoll(iAddress, false); + return primary->TransmitPoll(iAddress, true); return m_processor ? m_processor->PollDevice(iAddress) : false; } @@ -1344,7 +1433,7 @@ bool CCECClient::IsLibCECActiveSource(void) cec_logical_address activeSource = m_processor->GetActiveSource(); CCECBusDevice *device = m_processor->GetDevice(activeSource); if (device) - bReturn = device->IsHandledByLibCEC(); + bReturn = device->IsHandledByLibCEC() && !device->GetHandler()->ActiveSourcePending(); } return bReturn; }