From 37b0c5724f06a98e14686695b5089f66ac657f11 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Fri, 9 Dec 2011 11:37:45 +0100 Subject: [PATCH] cec: fixed - mark a device as active source before transmitting the active source command, not after. renamed IsActiveDevice() -> IsPresentDevice() internally, to avoid confusion with IsActiveSource(). --- src/lib/CECProcessor.cpp | 52 +++++++++---------- src/lib/CECProcessor.h | 6 +-- src/lib/LibCEC.cpp | 4 +- src/lib/devices/CECBusDevice.cpp | 2 +- src/lib/devices/CECBusDevice.h | 2 +- src/lib/implementations/CECCommandHandler.cpp | 22 ++++---- src/lib/implementations/SLCommandHandler.cpp | 2 +- 7 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index a3c22df..565d226 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -176,12 +176,6 @@ bool CCECProcessor::TryLogicalAddress(cec_logical_address address) { if (m_busDevices[address]->TryLogicalAddress()) { - /* only set our OSD name and active source for the primary device */ - if (m_logicalAddresses.IsEmpty()) - { - m_busDevices[address]->m_strDeviceName = m_strDeviceName; - m_busDevices[address]->m_bActiveSource = true; - } m_logicalAddresses.Set(address); return true; } @@ -262,6 +256,10 @@ void *CCECProcessor::Process(void) } else { + /* only set our OSD name and active source for the primary device */ + m_busDevices[m_logicalAddresses.primary]->m_strDeviceName = m_strDeviceName; + m_busDevices[m_logicalAddresses.primary]->m_bActiveSource = true; + SetAckMask(m_logicalAddresses.AckMask()); CLockObject lock(&m_mutex); @@ -331,8 +329,8 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE } } - bReturn = m_busDevices[addr]->TransmitActiveSource() && - SetStreamPath(m_busDevices[addr]->GetPhysicalAddress(false)); + m_busDevices[addr]->SetActiveSource(); + bReturn = m_busDevices[addr]->TransmitActiveSource(); if (bReturn && (m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) @@ -343,6 +341,20 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE return bReturn; } +bool CCECProcessor::SetActiveSource(uint16_t iStreamPath) +{ + bool bReturn(false); + + CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath); + if (device) + { + device->SetActiveSource(); + bReturn = true; + } + + return bReturn; +} + void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout) { CLockObject lock(&m_mutex); @@ -460,20 +472,6 @@ bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress) return false; } -bool CCECProcessor::SetStreamPath(uint16_t iStreamPath) -{ - bool bReturn(false); - - CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath); - if (device) - { - device->SetActiveDevice(); - bReturn = true; - } - - return bReturn; -} - bool CCECProcessor::TransmitInactiveSource(void) { if (!IsRunning()) @@ -590,7 +588,7 @@ bool CCECProcessor::PollDevice(cec_logical_address iAddress) uint8_t CCECProcessor::VolumeUp(void) { uint8_t status = 0; - if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) + if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM)) status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(); return status; @@ -599,7 +597,7 @@ uint8_t CCECProcessor::VolumeUp(void) uint8_t CCECProcessor::VolumeDown(void) { uint8_t status = 0; - if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) + if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM)) status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(); return status; @@ -608,7 +606,7 @@ uint8_t CCECProcessor::VolumeDown(void) uint8_t CCECProcessor::MuteAudio(void) { uint8_t status = 0; - if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) + if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM)) status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(); return status; @@ -933,12 +931,12 @@ cec_logical_addresses CCECProcessor::GetActiveDevices(void) return addresses; } -bool CCECProcessor::IsActiveDevice(cec_logical_address address) +bool CCECProcessor::IsPresentDevice(cec_logical_address address) { return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT; } -bool CCECProcessor::IsActiveDeviceType(cec_device_type type) +bool CCECProcessor::IsPresentDeviceType(cec_device_type type) { for (unsigned int iPtr = 0; iPtr < 15; iPtr++) { diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index d2aa222..a0e0e73 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -70,8 +70,8 @@ namespace CEC virtual cec_logical_addresses GetActiveDevices(void); virtual uint16_t GetDevicePhysicalAddress(cec_logical_address iAddress); virtual bool HasLogicalAddress(cec_logical_address address) const { return m_logicalAddresses.IsSet(address); } - virtual bool IsActiveDevice(cec_logical_address address); - virtual bool IsActiveDeviceType(cec_device_type type); + virtual bool IsPresentDevice(cec_logical_address address); + virtual bool IsPresentDeviceType(cec_device_type type); virtual uint16_t GetPhysicalAddress(void) const; virtual uint64_t GetLastTransmission(void) const { return m_iLastTransmission; } virtual bool IsStarted(void) const { return m_bStarted; } @@ -87,7 +87,7 @@ namespace CEC virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress); virtual bool SetMenuState(cec_menu_state state, bool bSendUpdate = true); virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress); - virtual bool SetStreamPath(uint16_t iStreamPath); + virtual bool SetActiveSource(uint16_t iStreamPath); virtual bool SwitchMonitoring(bool bEnable); virtual bool PollDevice(cec_logical_address iAddress); virtual uint8_t VolumeUp(void); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index f43071c..0ca0188 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -267,14 +267,14 @@ cec_logical_addresses CLibCEC::GetActiveDevices(void) bool CLibCEC::IsActiveDevice(cec_logical_address iAddress) { if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) - return m_cec->IsActiveDevice(iAddress); + return m_cec->IsPresentDevice(iAddress); return false; } bool CLibCEC::IsActiveDeviceType(cec_device_type type) { if (m_cec && type >= CEC_DEVICE_TYPE_TV && type <= CEC_DEVICE_TYPE_AUDIO_SYSTEM) - return m_cec->IsActiveDeviceType(type); + return m_cec->IsPresentDeviceType(type); return false; } diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 8b42781..f03f0cb 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -440,7 +440,7 @@ void CCECBusDevice::SetInactiveDevice(void) m_bActiveSource = false; } -void CCECBusDevice::SetActiveDevice(void) +void CCECBusDevice::SetActiveSource(void) { CLockObject lock(&m_writeMutex); diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 14f3302..f1786f9 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -76,7 +76,7 @@ namespace CEC virtual void SetInactiveDevice(void); - virtual void SetActiveDevice(void); + virtual void SetActiveSource(void); virtual bool TryLogicalAddress(void); virtual void SetDeviceStatus(const cec_bus_device_status newStatus); diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 5c6a52f..c7b0305 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -178,7 +178,7 @@ bool CCECCommandHandler::HandleActiveSource(const cec_command &command) if (command.parameters.size == 2) { uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); - return m_processor->SetStreamPath(iAddress); + return m_processor->SetActiveSource(iAddress); } return true; @@ -319,7 +319,7 @@ bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &comm bool CCECCommandHandler::HandleImageViewOn(const cec_command &command) { - m_processor->SetStreamPath(m_processor->m_busDevices[command.initiator]->GetPhysicalAddress(false)); + m_processor->m_busDevices[command.initiator]->SetActiveSource(); return true; } @@ -409,7 +409,7 @@ bool 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]); - m_processor->SetStreamPath(iNewAddress); + m_processor->SetActiveSource(iNewAddress); } return false; @@ -464,14 +464,12 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); - if (m_processor->SetStreamPath(iStreamAddress)) + CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); + if (device) { - CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); - if (device) - { - return device->TransmitActiveSource() && - device->TransmitMenuState(command.initiator); - } + device->SetActiveSource(); + return device->TransmitActiveSource() && + device->TransmitMenuState(command.initiator); } } return false; @@ -491,7 +489,7 @@ bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress); if (newActiveDevice) - m_processor->SetStreamPath(newActiveDevice->GetPhysicalAddress(false)); + newActiveDevice->SetActiveSource(); return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); } else @@ -545,7 +543,7 @@ bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) { - m_processor->SetStreamPath(m_processor->m_busDevices[command.initiator]->GetPhysicalAddress(false)); + m_processor->m_busDevices[command.initiator]->SetActiveSource(); return true; } diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index c23099e..0f00717 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -145,8 +145,8 @@ void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command &command) void CSLCommandHandler::HandleVendorCommandSLConnect(const cec_command &command) { m_bSLEnabled = true; + m_processor->m_busDevices[command.initiator]->SetActiveSource(); m_processor->m_busDevices[command.destination]->TransmitActiveSource(); - m_processor->SetStreamPath(m_processor->m_busDevices[command.destination]->GetPhysicalAddress(false)); TransmitVendorCommand05(command.destination, command.initiator); TransmitDeckStatus(command.initiator); } -- 2.34.1