+ if (!m_processor->IsHandledByLibCEC(iAddress))
+ {
+ CCECBusDevice *otherDevice = m_processor->GetDeviceByPhysicalAddress(iNewAddress);
+ CCECClient *client = otherDevice ? otherDevice->GetClient() : NULL;
+
+ CCECBusDevice *device = m_processor->GetDevice(iAddress);
+ if (device)
+ device->SetPhysicalAddress(iNewAddress);
+ else
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "device with logical address %X not found", iAddress);
+
+ /* another device reported the same physical address as ours */
+ if (client)
+ {
+ libcec_parameter param;
+ param.paramType = CEC_PARAMETER_TYPE_STRING;
+ param.paramData = (void*)"Physical address in use by another device. Please verify your settings";
+ client->Alert(CEC_ALERT_PHYSICAL_ADDRESS_ERROR, param);
+ client->ResetPhysicalAddress();
+ }
+ }
+ else
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "ignore physical address report for device %s (%X) because it's marked as handled by libCEC", ToString(iAddress), iAddress);
+ }
+}
+
+bool CCECCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+{
+ if (iDestination == CECDEVICE_TV)
+ return TransmitImageViewOn(iInitiator, iDestination);
+
+ return TransmitKeypress(iInitiator, iDestination, CEC_USER_CONTROL_CODE_POWER) &&
+ TransmitKeyRelease(iInitiator, iDestination);
+}
+
+bool CCECCommandHandler::TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_IMAGE_VIEW_ON);
+
+ if (Transmit(command, false, false))
+ {
+ CCECBusDevice* dest = m_processor->GetDevice(iDestination);
+ if (dest && dest->GetCurrentPowerStatus() != CEC_POWER_STATUS_ON)
+ dest->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
+ return true;
+ }
+ return false;
+}
+
+bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_STANDBY);
+
+ return Transmit(command, false, false);
+}
+
+bool CCECCommandHandler::TransmitRequestActiveSource(const cec_logical_address iInitiator, bool bWaitForResponse /* = true */)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REQUEST_ACTIVE_SOURCE);
+
+ return Transmit(command, !bWaitForResponse, false);
+}
+
+bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_CEC_VERSION);
+
+ return Transmit(command, !bWaitForResponse, false);
+}
+
+bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_MENU_LANGUAGE);
+
+ return Transmit(command, !bWaitForResponse, false);
+}
+
+bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_OSD_NAME);
+
+ return Transmit(command, !bWaitForResponse, false);
+}
+
+bool CCECCommandHandler::TransmitRequestAudioStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_AUDIO_STATUS);
+
+ return Transmit(command, !bWaitForResponse, false);
+}
+
+bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS);
+
+ return Transmit(command, !bWaitForResponse, false);
+}
+
+bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bUpdate, bool bWaitForResponse /* = true */)
+{
+ if (iDestination == CECDEVICE_TV)
+ {
+ int64_t now(GetTimeMs());
+ if (!bUpdate && now - m_iPowerStatusRequested < REQUEST_POWER_STATUS_TIMEOUT)
+ return true;
+ m_iPowerStatusRequested = now;
+ }
+
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< requesting power status of '%s' (%X)", m_busDevice->GetLogicalAddressName(), iDestination);
+
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS);
+
+ return Transmit(command, !bWaitForResponse, false);
+}
+
+bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
+
+ return Transmit(command, !bWaitForResponse, false);
+}
+
+bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
+ command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF));
+ command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF));
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_version cecVersion, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_CEC_VERSION);
+ command.parameters.PushBack((uint8_t)cecVersion);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, CECDEVICE_TV, CEC_OPCODE_INACTIVE_SOURCE);
+ command.parameters.PushBack((iPhysicalAddress >> 8) & 0xFF);
+ command.parameters.PushBack(iPhysicalAddress & 0xFF);
+
+ return Transmit(command, false, false);
+}
+
+bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_menu_state menuState, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_MENU_STATUS);
+ command.parameters.PushBack((uint8_t)menuState);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, std::string strDeviceName, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_NAME);
+ for (size_t iPtr = 0; iPtr < strDeviceName.length(); iPtr++)
+ command.parameters.PushBack(strDeviceName.at(iPtr));
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_display_control duration, const char *strMessage, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_STRING);
+ command.parameters.PushBack((uint8_t)duration);
+
+ size_t iLen = strlen(strMessage);
+ if (iLen > 13) iLen = 13;
+
+ for (size_t iPtr = 0; iPtr < iLen; iPtr++)
+ command.parameters.PushBack(strMessage[iPtr]);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInitiator, uint16_t iPhysicalAddress, cec_device_type type, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
+ command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF));
+ command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF));
+ command.parameters.PushBack((uint8_t) (type));
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitSetMenuLanguage(const cec_logical_address iInitiator, const char lang[4], bool bIsReply)
+{
+ cec_command command;
+ command.Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_SET_MENU_LANGUAGE);
+ command.parameters.PushBack((uint8_t) lang[0]);
+ command.parameters.PushBack((uint8_t) lang[1]);
+ command.parameters.PushBack((uint8_t) lang[2]);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_NONE);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_power_status state, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_POWER_STATUS);
+ command.parameters.PushBack((uint8_t) state);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator, const cec_logical_address UNUSED(iDestination), uint64_t iVendorId, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_DEVICE_VENDOR_ID);
+
+ command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 16) & 0xFF));
+ command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 8) & 0xFF));
+ command.parameters.PushBack((uint8_t) ((uint64_t)iVendorId & 0xFF));
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, uint8_t state, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_AUDIO_STATUS);
+ command.parameters.PushBack(state);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE);
+ command.parameters.PushBack((uint8_t)state);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitSetStreamPath(uint16_t iStreamPath, bool bIsReply)
+{
+ if (m_busDevice->GetLogicalAddress() != CECDEVICE_TV)
+ {
+ LIB_CEC->AddLog(CEC_LOG_ERROR, "only the TV is allowed to send CEC_OPCODE_SET_STREAM_PATH");
+ return false;
+ }
+ cec_command command;
+ cec_command::Format(command, m_busDevice->GetLogicalAddress(), CECDEVICE_BROADCAST, CEC_OPCODE_SET_STREAM_PATH);
+ command.parameters.PushBack((uint8_t) ((iStreamPath >> 8) & 0xFF));
+ command.parameters.PushBack((uint8_t) (iStreamPath & 0xFF));
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS);
+ command.parameters.PushBack((uint8_t)state);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_deck_info state, bool bIsReply)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_DECK_STATUS);
+ command.PushBack((uint8_t)state);
+
+ return Transmit(command, false, bIsReply);
+}
+
+bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_PRESSED);
+ command.parameters.PushBack((uint8_t)key);
+
+ return Transmit(command, !bWait, false);
+}
+
+bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWait /* = true */)
+{
+ cec_command command;
+ cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_RELEASE);
+
+ return Transmit(command, !bWait, false);
+}
+
+bool CCECCommandHandler::Transmit(cec_command &command, bool bSuppressWait, bool bIsReply)
+{
+ bool bReturn(false);
+ cec_opcode expectedResponse(cec_command::GetResponseOpcode(command.opcode));
+ bool bExpectResponse(expectedResponse != CEC_OPCODE_NONE && !bSuppressWait);
+ command.transmit_timeout = m_iTransmitTimeout;
+
+ if (command.initiator == CECDEVICE_UNKNOWN)
+ {
+ LIB_CEC->AddLog(CEC_LOG_ERROR, "not transmitting a command without a valid initiator");
+ return bReturn;
+ }
+
+ // check whether the destination is not marked as not present or handled by libCEC
+ if (command.destination != CECDEVICE_BROADCAST && command.opcode_set)
+ {
+ CCECBusDevice* destinationDevice = m_processor->GetDevice(command.destination);
+ cec_bus_device_status status = destinationDevice ? destinationDevice->GetStatus() : CEC_DEVICE_STATUS_NOT_PRESENT;
+ if (status == CEC_DEVICE_STATUS_NOT_PRESENT)
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "not sending command '%s': destination device '%s' marked as not present", ToString(command.opcode),ToString(command.destination));
+ return bReturn;
+ }
+ else if (status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "not sending command '%s': destination device '%s' marked as handled by libCEC", ToString(command.opcode),ToString(command.destination));
+ return bReturn;
+ }
+ else if (destinationDevice->IsUnsupportedFeature(command.opcode))
+ {
+ return true;
+ }
+ }
+