From ed21be2a64e3fe66dddffbd822c32f38e3b9192f Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Mon, 28 Nov 2011 01:27:49 +0100 Subject: [PATCH] cec: added GetOSDName()/cec_get_osd_name(). only request the values we need in CCECProcessor::ScanCECBus() --- include/cec.h | 7 +++++++ include/cecc.h | 5 +++++ include/cectypes.h | 6 ++++++ src/lib/CECProcessor.cpp | 14 +++++++++++-- src/lib/CECProcessor.h | 1 + src/lib/LibCEC.cpp | 12 +++++++++++ src/lib/LibCEC.h | 1 + src/lib/LibCECC.cpp | 12 +++++++++++ src/lib/devices/CECBusDevice.cpp | 34 ++++++++++++++++++++++++++++++++ src/lib/devices/CECBusDevice.h | 2 ++ src/testclient/main.cpp | 14 +++++++++++++ 11 files changed, 106 insertions(+), 2 deletions(-) diff --git a/include/cec.h b/include/cec.h index 70c17ce..9aa944b 100644 --- a/include/cec.h +++ b/include/cec.h @@ -307,6 +307,13 @@ namespace CEC * @return True when the keypress was acked, false otherwise. */ virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false) = 0; + + /*! + * @brief Get the OSD name of a device on the CEC bus. + * @param iAddress The device to get the OSD name for. + * @return The OSD name. + */ + virtual cec_osd_name GetOSDName(cec_logical_address iAddress) = 0; }; }; diff --git a/include/cecc.h b/include/cecc.h index 07050bc..6c28506 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -205,6 +205,11 @@ extern DECLSPEC int cec_send_key_release(CEC::cec_logical_address iDestination, extern DECLSPEC int cec_send_key_release(cec_logical_address iDestination, int bWait); #endif +#ifdef __cplusplus +extern DECLSPEC CEC::cec_osd_name cec_get_osd_name(CEC::cec_logical_address iAddress); +#else +extern DECLSPEC cec_osd_name cec_get_osd_name(cec_logical_address iAddress); +#endif #ifdef __cplusplus }; diff --git a/include/cectypes.h b/include/cectypes.h index 96ac603..ede11f4 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -607,6 +607,12 @@ typedef struct cec_menu_language cec_logical_address device; } cec_menu_language; +typedef struct cec_osd_name +{ + char name[14]; + cec_logical_address device; +} cec_osd_name; + typedef struct cec_log_message { char message[1024]; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 7f688dd..8c95da7 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -396,9 +396,8 @@ void CCECProcessor::ScanCECBus(void) if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT) { device->GetPhysicalAddress(); - device->GetVendorId(); device->GetCecVersion(); - device->GetPowerStatus(); + device->GetVendorId(); } } } @@ -580,6 +579,17 @@ cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress) return m_busDevices[iAddress]->GetCecVersion(); } +cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress) +{ + CStdString strOSDName = m_busDevices[iAddress]->GetOSDName(); + cec_osd_name retVal; + + snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str()); + retVal.device = iAddress; + + return retVal; +} + bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) { if (m_busDevices[iAddress]) diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 6cd9ba4..08a21a6 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -62,6 +62,7 @@ namespace CEC virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress); virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language); virtual const std::string & GetDeviceName(void) { return m_strDeviceName; } + virtual cec_osd_name GetDeviceOSDName(cec_logical_address iAddress); virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress); virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress); virtual cec_logical_address GetLogicalAddress(void) const { return m_logicalAddresses.primary; } diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 50239bc..92f00c3 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -316,6 +316,18 @@ bool CLibCEC::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = f return false; } +cec_osd_name CLibCEC::GetOSDName(cec_logical_address iAddress) +{ + cec_osd_name retVal; + retVal.device = iAddress; + retVal.name[0] = 0; + + if (m_cec) + retVal = m_cec->GetDeviceOSDName(iAddress); + + return retVal; +} + void CLibCEC::AddLog(cec_log_level level, const string &strMessage) { if (m_cec) diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 050fcc1..3d46873 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -93,6 +93,7 @@ namespace CEC virtual uint8_t MuteAudio(bool bWait = true); virtual bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = false); virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false); + virtual cec_osd_name GetOSDName(cec_logical_address iAddress); //@} virtual void AddLog(cec_log_level level, const std::string &strMessage); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index f1e80fa..54b82f9 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -306,4 +306,16 @@ int cec_send_key_release(cec_logical_address iDestination, int bWait) return -1; } +cec_osd_name cec_get_osd_name(cec_logical_address iAddress) +{ + cec_osd_name retVal; + retVal.device = iAddress; + retVal.name[0] = 0; + + if (cec_parser) + retVal = cec_parser->GetOSDName(iAddress); + + return retVal; +} + //@} diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index b4c11f1..52d71df 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -214,6 +214,40 @@ uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const return m_processor->GetPhysicalAddress(); } +CStdString CCECBusDevice::GetOSDName(void) +{ + if (GetStatus() == CEC_DEVICE_STATUS_PRESENT) + { + CLockObject lock(&m_mutex); + if (m_strDeviceName.Equals(ToString(m_iLogicalAddress))) + { + lock.Leave(); + RequestOSDName(); + lock.Lock(); + } + } + + CLockObject lock(&m_mutex); + return m_strDeviceName; +} + +bool CCECBusDevice::RequestOSDName(void) +{ + bool bReturn(false); + if (!MyLogicalAddressContains(m_iLogicalAddress)) + { + CStdString strLog; + strLog.Format("<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); + AddLog(CEC_LOG_NOTICE, strLog); + cec_command command; + cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_OSD_NAME); + CLockObject lock(&m_transmitMutex); + if (m_processor->Transmit(command)) + bReturn = m_condition.Wait(&m_transmitMutex, 1000); + } + return bReturn; +} + uint16_t CCECBusDevice::GetPhysicalAddress(bool bRefresh /* = true */) { if (GetStatus() == CEC_DEVICE_STATUS_PRESENT) diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index c86a1f2..d8d751c 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -63,6 +63,7 @@ namespace CEC virtual cec_menu_language & GetMenuLanguage(void); virtual cec_logical_address GetMyLogicalAddress(void) const; virtual uint16_t GetMyPhysicalAddress(void) const; + virtual CStdString GetOSDName(void); virtual uint16_t GetPhysicalAddress(bool bRefresh = true); virtual cec_power_status GetPowerStatus(void); virtual CCECProcessor * GetProcessor(void) const { return m_processor; } @@ -77,6 +78,7 @@ namespace CEC bool RequestPowerStatus(void); bool RequestVendorId(void); bool RequestPhysicalAddress(void); + bool RequestOSDName(void); virtual void SetInactiveDevice(void); virtual void SetActiveDevice(void); diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index d9ad277..d8daa8d 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -233,6 +233,7 @@ void ShowHelpConsole(void) "[ven] {addr} get the vendor ID of the specified device." << endl << "[lang] {addr} get the menu language of the specified device." << endl << "[pow] {addr} get the power status of the specified device." << endl << + "[name] {addr} get the OSD name of the specified device." << endl << "[poll] {addr} poll the specified device." << endl << "[lad] lists active devices on the bus" << endl << "[ad] {addr} checks whether the specified device is active." << endl << @@ -720,6 +721,19 @@ int main (int argc, char *argv[]) } } } + else if (command == "name") + { + CStdString strDev; + if (GetWord(input, strDev)) + { + int iDev = atoi(strDev); + if (iDev >= 0 && iDev < 15) + { + cec_osd_name name = parser->GetOSDName((cec_logical_address)iDev); + cout << "OSD name of device " << iDev << " is '" << name.name << "'" << endl; + } + } + } else if (command == "lad") { cout << "listing active devices:" << endl; -- 2.34.1