X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fimplementations%2FVLCommandHandler.cpp;h=59eb5747cb6cc9693415286f836337647c5e1aab;hb=5f2f3609d7ee857ac7e5d03600fbd735e99c892f;hp=f0d59dbb0644b2bb3cae4f86d0a4f7d9910f40e6;hpb=d79b67d88e372b75312481b672bd0d0bd94f5e09;p=deb_libcec.git diff --git a/src/lib/implementations/VLCommandHandler.cpp b/src/lib/implementations/VLCommandHandler.cpp index f0d59db..59eb574 100644 --- a/src/lib/implementations/VLCommandHandler.cpp +++ b/src/lib/implementations/VLCommandHandler.cpp @@ -1,7 +1,7 @@ /* * This file is part of the libCEC(R) library. * - * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. + * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. * libCEC(R) is an original work, containing original code. * * libCEC(R) is a trademark of Pulse-Eight Limited. @@ -33,21 +33,126 @@ #include "VLCommandHandler.h" #include "../devices/CECBusDevice.h" #include "../CECProcessor.h" +#include "../LibCEC.h" +#include "../CECClient.h" + +#define VL_POWER_CHANGE 0x20 +#define VL_POWERED_UP 0x00 +#define VL_POWERED_DOWN 0x01 using namespace CEC; +using namespace PLATFORM; + +#define LIB_CEC m_busDevice->GetProcessor()->GetLib() +#define ToString(p) LIB_CEC->ToString(p) CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice) : - CCECCommandHandler(busDevice) + CCECCommandHandler(busDevice), + m_bActiveSourcePending(false), + m_bPowerUpEventReceived(false) { m_vendorId = CEC_VENDOR_PANASONIC; + + /* use the VL commandhandler for the primary device that is handled by libCEC */ + if (busDevice->GetLogicalAddress() == CECDEVICE_TV) + { + CCECBusDevice *primary = m_processor->GetPrimaryDevice(); + if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) + { + primary->SetVendorId(CEC_VENDOR_PANASONIC); + primary->ReplaceHandler(false); + } + } } bool CVLCommandHandler::InitHandler(void) { CCECBusDevice *primary = m_processor->GetPrimaryDevice(); if (primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) + return m_processor->GetPrimaryClient()->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE, CEC_DEVICE_TYPE_PLAYBACK_DEVICE); + + return CCECCommandHandler::InitHandler(); +} + +bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) +{ + if (command.initiator == CECDEVICE_TV && + command.destination == CECDEVICE_BROADCAST && + command.parameters.At(3) == VL_POWER_CHANGE) { - return m_processor->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE, CEC_DEVICE_TYPE_PLAYBACK_DEVICE); + if (command.parameters.At(4) == VL_POWERED_UP) + { + LIB_CEC->AddLog(CEC_LOG_DEBUG, "TV powered up"); + { + CLockObject lock(m_mutex); + m_bPowerUpEventReceived = true; + } + m_processor->TransmitPendingActiveSourceCommands(); + } + else if (command.parameters.At(4) == VL_POWERED_DOWN) + LIB_CEC->AddLog(CEC_LOG_DEBUG, "TV powered down"); + else if (command.parameters.At(4) == VL_POWERED_DOWN) + LIB_CEC->AddLog(CEC_LOG_DEBUG, "unknown vendor command"); + + return true; } - return CCECCommandHandler::InitHandler(); + + return CCECCommandHandler::HandleDeviceVendorCommandWithId(command); +} + +bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress) +{ + bool bPowerUpEventReceived(false); + + CCECBusDevice *tv = m_processor->GetDevice(CECDEVICE_TV); + if (tv && tv->GetCurrentVendorId() == CEC_VENDOR_PANASONIC) + { + CVLCommandHandler *handler = static_cast(tv->GetHandler()); + bPowerUpEventReceived = handler ? handler->PowerUpEventReceived() : false; + } + + if (!bPowerUpEventReceived) + { + CLockObject lock(m_mutex); + // wait until we received the event + m_bActiveSourcePending = true; + return true; + } + else + { + // transmit standard active source message + return CCECCommandHandler::TransmitActiveSource(iInitiator, iPhysicalAddress); + } +} + +bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void) +{ + bool bTransmitCommand(false); + { + CLockObject lock(m_mutex); + bTransmitCommand = m_bActiveSourcePending; + m_bActiveSourcePending = false; + } + + if (bTransmitCommand) + { + LIB_CEC->AddLog(CEC_LOG_DEBUG, "transmitting delayed activate source command"); + return CCECCommandHandler::TransmitActiveSource(m_busDevice->GetLogicalAddress(), m_busDevice->GetCurrentPhysicalAddress()); + } + return true; +} + +bool CVLCommandHandler::PowerUpEventReceived(void) +{ + { + CLockObject lock(m_mutex); + if (m_bPowerUpEventReceived) + return true; + } + + cec_power_status powerStatus = m_busDevice->GetCurrentPowerStatus(); + + CLockObject lock(m_mutex); + m_bPowerUpEventReceived = (powerStatus == CEC_POWER_STATUS_ON); + return m_bPowerUpEventReceived; }