From 844eab4ec63477613b4ec5747e6994521108d4b3 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Thu, 18 Oct 2012 15:58:17 +0200 Subject: [PATCH] fixed handling of active route changes. github issue #56 and issue #58 --- src/lib/devices/CECBusDevice.cpp | 20 +++++++++++++++++++ src/lib/devices/CECBusDevice.h | 1 + src/lib/implementations/CECCommandHandler.cpp | 15 +++++--------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 5137cfb..5fe6d4d 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -1066,6 +1066,26 @@ bool CCECBusDevice::TransmitPendingActiveSourceCommands(void) return bReturn; } +void CCECBusDevice::SetActiveRoute(uint16_t iRoute) +{ + CCECDeviceMap* map = m_processor->GetDevices(); + if (!map) + return; + + CCECBusDevice* previouslyActive = map->GetActiveSource(); + if (!previouslyActive) + return; + + CECDEVICEVEC devices; + m_processor->GetDevices()->GetChildrenOf(devices, this); + + for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++) + { + if (!CCECTypeUtils::PhysicalAddressIsIncluded(iRoute, (*it)->GetCurrentPhysicalAddress())) + (*it)->MarkAsInactiveSource(); + } +} + void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) { CLockObject lock(m_mutex); diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index fad7191..6cba39f 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -224,6 +224,7 @@ namespace CEC virtual bool TransmitImageViewOn(void); virtual bool TransmitInactiveSource(void); virtual bool TransmitPendingActiveSourceCommands(void); + virtual void SetActiveRoute(uint16_t iRoute); virtual void SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress = CEC_INVALID_PHYSICAL_ADDRESS); virtual bool PowerOn(const cec_logical_address initiator); diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 5398513..2be7f3a 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -488,13 +488,11 @@ int CCECCommandHandler::HandleRoutingChange(const cec_command &command) { if (command.parameters.size == 4) { - uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); - uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]); - CCECBusDevice *device = GetDevice(command.initiator); if (device) { - device->SetStreamPath(iNewAddress, iOldAddress); + uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]); + device->SetActiveRoute(iNewAddress); return COMMAND_HANDLED; } } @@ -506,11 +504,11 @@ int CCECCommandHandler::HandleRoutingInformation(const cec_command &command) { if (command.parameters.size == 2) { - uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); - CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress); + CCECBusDevice *device = GetDevice(command.initiator); if (device) { - device->MarkAsActiveSource(); + uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); + device->SetActiveRoute(iNewAddress); return COMMAND_HANDLED; } } @@ -570,9 +568,6 @@ int CCECCommandHandler::HandleSetStreamPath(const cec_command &command) uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %s (%x) sets stream path to physical address %04x", ToString(command.initiator), command.initiator, iStreamAddress); - // a device will only change the stream path when it's powered on - m_busDevice->SetPowerStatus(CEC_POWER_STATUS_ON); - /* one of the device handled by libCEC has been made active */ CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); if (device && device->IsHandledByLibCEC()) -- 2.34.1