// make the primary device the active source if the option is set
if (m_configuration.bActivateSource == 1)
- GetPrimaryDevice()->ActivateSource();
+ GetPrimaryDevice()->ActivateSource(500);
return true;
}
m_deviceStatus (CEC_DEVICE_STATUS_UNKNOWN),
m_iHandlerUseCount (0),
m_bAwaitingReceiveFailed(false),
- m_bVendorIdRequested (false)
+ m_bVendorIdRequested (false),
+ m_waitForResponse (new CWaitForResponse)
{
m_handler = new CCECCommandHandler(this);
CCECBusDevice::~CCECBusDevice(void)
{
DELETE_AND_NULL(m_handler);
+ DELETE_AND_NULL(m_waitForResponse);
}
bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */)
if (CCECCommandHandler::HasSpecificHandler(m_vendor))
{
LIB_CEC->AddLog(CEC_LOG_DEBUG, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
+
+ int32_t iTransmitTimeout = m_handler->m_iTransmitTimeout;
+ int32_t iTransmitWait = m_handler->m_iTransmitWait;
+ int8_t iTransmitRetries = m_handler->m_iTransmitRetries;
+ int64_t iActiveSourcePending = m_handler->m_iActiveSourcePending;
+
DELETE_AND_NULL(m_handler);
switch (m_vendor)
{
case CEC_VENDOR_SAMSUNG:
- m_handler = new CANCommandHandler(this);
+ m_handler = new CANCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending);
break;
case CEC_VENDOR_LG:
- m_handler = new CSLCommandHandler(this);
+ m_handler = new CSLCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending);
break;
case CEC_VENDOR_PANASONIC:
- m_handler = new CVLCommandHandler(this);
+ m_handler = new CVLCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending);
break;
default:
- m_handler = new CCECCommandHandler(this);
+ m_handler = new CCECCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending);
break;
}
// signal threads that are waiting for a reponse
MarkBusy();
- m_handler->SignalOpcode(cec_command::GetResponseOpcode(opcode));
+ SignalOpcode(cec_command::GetResponseOpcode(opcode));
MarkReady();
}
m_iLastActive = 0;
m_bVendorIdRequested = false;
m_unsupportedFeatures.clear();
+ m_waitForResponse->Clear();
if (m_deviceStatus != CEC_DEVICE_STATUS_UNKNOWN)
LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress);
return bReturn;
}
-bool CCECBusDevice::ActivateSource(void)
+bool CCECBusDevice::ActivateSource(uint64_t iDelay /* = 0 */)
{
MarkAsActiveSource();
- LIB_CEC->AddLog(CEC_LOG_DEBUG, "activating source '%s'", ToString(m_iLogicalAddress));
MarkBusy();
- bool bReturn = m_handler->ActivateSource();
+ bool bReturn(true);
+ if (iDelay == 0)
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending active source message for '%s'", ToString(m_iLogicalAddress));
+ bReturn = m_handler->ActivateSource();
+ }
+ else
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "scheduling active source message for '%s'", ToString(m_iLogicalAddress));
+ m_handler->ScheduleActivateSource(iDelay);
+ }
MarkReady();
return bReturn;
}
{
return m_processor->GetClient(m_iLogicalAddress);
}
+
+void CCECBusDevice::SignalOpcode(cec_opcode opcode)
+{
+ m_waitForResponse->Received(opcode);
+}
+
+bool CCECBusDevice::WaitForOpcode(cec_opcode opcode)
+{
+ return m_waitForResponse->Wait(opcode);
+}
#include "../../../include/cectypes.h"
#include <set>
+#include <map>
#include "../platform/threads/mutex.h"
#include "../platform/util/StdString.h"
class CCECTuner;
class CCECTV;
+ class CResponse
+ {
+ public:
+ CResponse(cec_opcode opcode) :
+ m_opcode(opcode){}
+ ~CResponse(void)
+ {
+ Broadcast();
+ }
+
+ bool Wait(uint32_t iTimeout)
+ {
+ return m_event.Wait(iTimeout);
+ }
+
+ void Broadcast(void)
+ {
+ m_event.Broadcast();
+ }
+
+ private:
+ cec_opcode m_opcode;
+ PLATFORM::CEvent m_event;
+ };
+
+ class CWaitForResponse
+ {
+ public:
+ CWaitForResponse(void) {}
+ ~CWaitForResponse(void)
+ {
+ Clear();
+ }
+
+ void Clear()
+ {
+ PLATFORM::CLockObject lock(m_mutex);
+ for (std::map<cec_opcode, CResponse*>::iterator it = m_waitingFor.begin(); it != m_waitingFor.end(); it++)
+ it->second->Broadcast();
+ m_waitingFor.clear();
+ }
+
+ bool Wait(cec_opcode opcode, uint32_t iTimeout = CEC_DEFAULT_TRANSMIT_WAIT)
+ {
+ CResponse *response = GetEvent(opcode);
+ return response ? response->Wait(iTimeout) : false;
+ }
+
+ void Received(cec_opcode opcode)
+ {
+ CResponse *response = GetEvent(opcode);
+ if (response)
+ response->Broadcast();
+ }
+
+ private:
+ CResponse *GetEvent(cec_opcode opcode)
+ {
+ CResponse *retVal(NULL);
+ {
+ PLATFORM::CLockObject lock(m_mutex);
+ std::map<cec_opcode, CResponse*>::iterator it = m_waitingFor.find(opcode);
+ if (it != m_waitingFor.end())
+ {
+ retVal = it->second;
+ }
+ else
+ {
+ retVal = new CResponse(opcode);
+ m_waitingFor[opcode] = retVal;
+ }
+ return retVal;
+ }
+ }
+
+ PLATFORM::CMutex m_mutex;
+ std::map<cec_opcode, CResponse*> m_waitingFor;
+ };
+
class CCECBusDevice
{
friend class CCECProcessor;
virtual void SetMenuState(const cec_menu_state state);
virtual bool TransmitMenuState(const cec_logical_address destination);
- virtual bool ActivateSource(void);
+ virtual bool ActivateSource(uint64_t iDelay = 0);
virtual bool IsActiveSource(void) const { return m_bActiveSource; }
virtual bool RequestActiveSource(bool bWaitForResponse = true);
virtual void MarkAsActiveSource(void);
virtual bool TryLogicalAddress(void);
CCECClient * GetClient(void);
+ void SignalOpcode(cec_opcode opcode);
+ bool WaitForOpcode(cec_opcode opcode);
CCECAudioSystem * AsAudioSystem(void);
static CCECAudioSystem * AsAudioSystem(CCECBusDevice *device);
unsigned m_iHandlerUseCount;
bool m_bAwaitingReceiveFailed;
bool m_bVendorIdRequested;
+ CWaitForResponse *m_waitForResponse;
};
};
#define LIB_CEC m_busDevice->GetProcessor()->GetLib()
#define ToString(p) LIB_CEC->ToString(p)
-CANCommandHandler::CANCommandHandler(CCECBusDevice *busDevice) :
- CCECCommandHandler(busDevice)
+CANCommandHandler::CANCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */,
+ int32_t iTransmitWait /* = CEC_DEFAULT_TRANSMIT_WAIT */,
+ int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */,
+ int64_t iActiveSourcePending /* = 0 */) :
+ CCECCommandHandler(busDevice, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending)
{
m_vendorId = CEC_VENDOR_SAMSUNG;
m_bOPTSendDeckStatusUpdateOnActiveSource = false;
class CANCommandHandler : public CCECCommandHandler
{
public:
- CANCommandHandler(CCECBusDevice *busDevice);
+ CANCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout = CEC_DEFAULT_TRANSMIT_TIMEOUT,
+ int32_t iTransmitWait = CEC_DEFAULT_TRANSMIT_WAIT,
+ int8_t iTransmitRetries = CEC_DEFAULT_TRANSMIT_RETRIES,
+ int64_t iActiveSourcePending = 0);
virtual ~CANCommandHandler(void) {};
int HandleVendorRemoteButtonDown(const cec_command &command);
#define LIB_CEC m_busDevice->GetProcessor()->GetLib()
#define ToString(p) CCECTypeUtils::ToString(p)
-CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) :
+CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */,
+ int32_t iTransmitWait /* = CEC_DEFAULT_TRANSMIT_WAIT */,
+ int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */,
+ int64_t iActiveSourcePending /* = 0 */) :
m_busDevice(busDevice),
m_processor(m_busDevice->GetProcessor()),
- m_iTransmitTimeout(CEC_DEFAULT_TRANSMIT_TIMEOUT),
- m_iTransmitWait(CEC_DEFAULT_TRANSMIT_WAIT),
- m_iTransmitRetries(CEC_DEFAULT_TRANSMIT_RETRIES),
+ m_iTransmitTimeout(iTransmitTimeout),
+ m_iTransmitWait(iTransmitWait),
+ m_iTransmitRetries(iTransmitRetries),
m_bHandlerInited(false),
m_bOPTSendDeckStatusUpdateOnActiveSource(false),
m_vendorId(CEC_VENDOR_UNKNOWN),
- m_waitForResponse(new CWaitForResponse),
- m_iActiveSourcePending(0)
+ m_iActiveSourcePending(iActiveSourcePending)
{
}
-CCECCommandHandler::~CCECCommandHandler(void)
-{
- DELETE_AND_NULL(m_waitForResponse);
-}
-
bool CCECCommandHandler::HandleCommand(const cec_command &command)
{
if (command.opcode_set == 0)
}
if (iHandled == COMMAND_HANDLED)
- m_waitForResponse->Received((command.opcode == CEC_OPCODE_FEATURE_ABORT && command.parameters.size > 0) ? (cec_opcode)command.parameters[0] : command.opcode);
+ m_busDevice->SignalOpcode((command.opcode == CEC_OPCODE_FEATURE_ABORT && command.parameters.size > 0) ? (cec_opcode)command.parameters[0] : command.opcode);
else
UnhandledCommand(command, (cec_abort_reason)iHandled);
LIB_CEC->AddLog(CEC_LOG_DEBUG, "command transmitted");
if (bExpectResponse)
{
- bReturn = m_waitForResponse->Wait(expectedResponse);
+ bReturn = m_busDevice->WaitForOpcode(expectedResponse);
LIB_CEC->AddLog(CEC_LOG_DEBUG, bReturn ? "expected response received (%X: %s)" : "expected response not received (%X: %s)", (int)expectedResponse, ToString(expectedResponse));
}
}
return true;
}
-void CCECCommandHandler::SignalOpcode(cec_opcode opcode)
+void CCECCommandHandler::ScheduleActivateSource(uint64_t iDelay)
{
- m_waitForResponse->Received(opcode);
+ CLockObject lock(m_mutex);
+ m_iActiveSourcePending = GetTimeMs() + iDelay;
}
#include "../../../include/cectypes.h"
#include <vector>
-#include <map>
#include "../platform/threads/mutex.h"
#include "../platform/util/StdString.h"
class CCECProcessor;
class CCECBusDevice;
- class CResponse
- {
- public:
- CResponse(cec_opcode opcode) :
- m_opcode(opcode){}
- ~CResponse(void)
- {
- Broadcast();
- }
-
- bool Wait(uint32_t iTimeout)
- {
- return m_event.Wait(iTimeout);
- }
-
- void Broadcast(void)
- {
- m_event.Broadcast();
- }
-
- private:
- cec_opcode m_opcode;
- PLATFORM::CEvent m_event;
- };
-
- class CWaitForResponse
- {
- public:
- CWaitForResponse(void) {}
- ~CWaitForResponse(void)
- {
- PLATFORM::CLockObject lock(m_mutex);
- m_waitingFor.clear();
- }
-
- bool Wait(cec_opcode opcode, uint32_t iTimeout = CEC_DEFAULT_TRANSMIT_WAIT)
- {
- CResponse *response = GetEvent(opcode);
- return response ? response->Wait(iTimeout) : false;
- }
-
- void Received(cec_opcode opcode)
- {
- CResponse *response = GetEvent(opcode);
- if (response)
- response->Broadcast();
- }
-
- private:
- CResponse *GetEvent(cec_opcode opcode)
- {
- CResponse *retVal(NULL);
- {
- PLATFORM::CLockObject lock(m_mutex);
- std::map<cec_opcode, CResponse*>::iterator it = m_waitingFor.find(opcode);
- if (it != m_waitingFor.end())
- {
- retVal = it->second;
- }
- else
- {
- retVal = new CResponse(opcode);
- m_waitingFor[opcode] = retVal;
- }
- return retVal;
- }
- }
-
- PLATFORM::CMutex m_mutex;
- std::map<cec_opcode, CResponse*> m_waitingFor;
- };
-
class CCECCommandHandler
{
+ friend class CCECBusDevice;
+
public:
- CCECCommandHandler(CCECBusDevice *busDevice);
- virtual ~CCECCommandHandler(void);
+ CCECCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout = CEC_DEFAULT_TRANSMIT_TIMEOUT,
+ int32_t iTransmitWait = CEC_DEFAULT_TRANSMIT_WAIT,
+ int8_t iTransmitRetries = CEC_DEFAULT_TRANSMIT_RETRIES,
+ int64_t iActiveSourcePending = 0);
+ virtual ~CCECCommandHandler(void) {};
virtual bool HandleCommand(const cec_command &command);
virtual cec_vendor_id GetVendorId(void) { return m_vendorId; };
virtual bool TransmitSetStreamPath(uint16_t iStreamPath);
virtual bool SendDeckStatusUpdateOnActiveSource(void) const { return m_bOPTSendDeckStatusUpdateOnActiveSource; };
- virtual void SignalOpcode(cec_opcode opcode);
+ virtual void ScheduleActivateSource(uint64_t iDelay);
virtual bool SupportsDeviceType(const cec_device_type UNUSED(type)) const { return true; };
virtual cec_device_type GetReplacementDeviceType(const cec_device_type type) const { return type; }
bool m_bHandlerInited;
bool m_bOPTSendDeckStatusUpdateOnActiveSource;
cec_vendor_id m_vendorId;
- CWaitForResponse *m_waitForResponse;
int64_t m_iActiveSourcePending;
PLATFORM::CMutex m_mutex;
};
using namespace CEC;
using namespace PLATFORM;
-CRLCommandHandler::CRLCommandHandler(CCECBusDevice *busDevice) :
- CCECCommandHandler(busDevice)
+CRLCommandHandler::CRLCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */,
+ int32_t iTransmitWait /* = CEC_DEFAULT_TRANSMIT_WAIT */,
+ int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */,
+ int64_t iActiveSourcePending /* = 0 */) :
+ CCECCommandHandler(busDevice, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending)
{
m_vendorId = CEC_VENDOR_TOSHIBA;
}
class CRLCommandHandler : public CCECCommandHandler
{
public:
- CRLCommandHandler(CCECBusDevice *busDevice);
+ CRLCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout = CEC_DEFAULT_TRANSMIT_TIMEOUT,
+ int32_t iTransmitWait = CEC_DEFAULT_TRANSMIT_WAIT,
+ int8_t iTransmitRetries = CEC_DEFAULT_TRANSMIT_RETRIES,
+ int64_t iActiveSourcePending = 0);
virtual ~CRLCommandHandler(void) {};
bool InitHandler(void);
#define LIB_CEC m_busDevice->GetProcessor()->GetLib()
#define ToString(p) LIB_CEC->ToString(p)
-CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) :
- CCECCommandHandler(busDevice),
+CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */,
+ int32_t iTransmitWait /* = CEC_DEFAULT_TRANSMIT_WAIT */,
+ int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */,
+ int64_t iActiveSourcePending /* = 0 */) :
+ CCECCommandHandler(busDevice, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending),
m_bSLEnabled(false),
m_bActiveSourceSent(false)
{
class CSLCommandHandler : public CCECCommandHandler
{
public:
- CSLCommandHandler(CCECBusDevice *busDevice);
+ CSLCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout = CEC_DEFAULT_TRANSMIT_TIMEOUT,
+ int32_t iTransmitWait = CEC_DEFAULT_TRANSMIT_WAIT,
+ int8_t iTransmitRetries = CEC_DEFAULT_TRANSMIT_RETRIES,
+ int64_t iActiveSourcePending = 0);
virtual ~CSLCommandHandler(void) {};
bool InitHandler(void);
// wait this amount of ms before trying to switch sources after receiving the message from the TV that it's powered on
#define SOURCE_SWITCH_DELAY_MS 1000
-CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice) :
- CCECCommandHandler(busDevice),
+CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */,
+ int32_t iTransmitWait /* = CEC_DEFAULT_TRANSMIT_WAIT */,
+ int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */,
+ int64_t iActiveSourcePending /* = 0 */) :
+ CCECCommandHandler(busDevice, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending),
m_iPowerUpEventReceived(0)
{
m_vendorId = CEC_VENDOR_PANASONIC;
class CVLCommandHandler : public CCECCommandHandler
{
public:
- CVLCommandHandler(CCECBusDevice *busDevice);
+ CVLCommandHandler(CCECBusDevice *busDevice,
+ int32_t iTransmitTimeout = CEC_DEFAULT_TRANSMIT_TIMEOUT,
+ int32_t iTransmitWait = CEC_DEFAULT_TRANSMIT_WAIT,
+ int8_t iTransmitRetries = CEC_DEFAULT_TRANSMIT_RETRIES,
+ int64_t iActiveSourcePending = 0);
virtual ~CVLCommandHandler(void) {};
bool InitHandler(void);