virtual const char *ToString(const cec_system_audio_status mode) = 0;
virtual const char *ToString(const cec_audio_status status) = 0;
virtual const char *ToString(const cec_vendor_id vendor) = 0;
+ virtual const char *ToString(const cec_client_version version) = 0;
};
};
* @param iPhysicalAddress The physical address to assume on the bus. If set to 0, libCEC will try to autodetect the address, with the data provided via SetHDMIPort()
* @return An instance of ICECAdapter or NULL on error.
*/
-extern "C" DECLSPEC void * CECInit(const char *strDeviceName, CEC::cec_device_type_list devicesTypes, uint16_t iPhysicalAddress = 0);
+extern "C" DECLSPEC void * CECInit(const char *strDeviceName, CEC::cec_device_type_list deviceTypes, uint16_t iPhysicalAddress = 0);
+
+/*!
+ * @brief Load the CEC adapter library.
+ * @param configuration The configuration to pass to libCEC
+ * @return An instance of ICECAdapter or NULL on error.
+ */
+extern "C" DECLSPEC void * CECInitialise(const CEC::libcec_configuration *configuration);
/*!
* @brief Unload the CEC adapter library.
#endif
#ifdef __cplusplus
-extern DECLSPEC int cec_init_typed(const char *strDeviceName, CEC::cec_device_type_list devicesTypes);
+extern DECLSPEC int cec_initialise(CEC::libcec_configuration *configuration);
#else
-extern DECLSPEC int cec_init_typed(const char *strDeviceName, cec_device_type_list devicesTypes);
+extern DECLSPEC int cec_initialise(libcec_configuration *configuration);
+#endif
+
+#ifdef __cplusplus
+extern DECLSPEC int cec_init_typed(const char *strDeviceName, CEC::cec_device_type_list deviceTypes);
+#else
+extern DECLSPEC int cec_init_typed(const char *strDeviceName, cec_device_type_list deviceTypes);
#endif
extern DECLSPEC void cec_destroy(void);
return static_cast< CEC::ICECAdapter* > (LibCecInit(strDeviceName, types));
}
+/*!
+ * @brief Create a new libCEC instance.
+ * @param configuration The configuration to pass to libCEC
+ * @param strLib The name of and/or path to libCEC
+ * @return An instance of ICECAdapter or NULL on error.
+ */
+CEC::ICECAdapter *LibCecInitialise(const CEC::libcec_configuration *configuration, const char *strLib = NULL)
+{
+ if (!g_libCEC)
+#if defined(_WIN64)
+ g_libCEC = LoadLibrary(strLib ? strLib : "libcec.x64.dll");
+#else
+ g_libCEC = LoadLibrary(strLib ? strLib : "libcec.dll");
+#endif
+ if (!g_libCEC)
+ return NULL;
+
+ typedef void* (__cdecl*_LibCecInitialise)(const CEC::libcec_configuration *);
+ _LibCecInitialise LibCecInitialise;
+ LibCecInitialise = (_LibCecInitialise) (GetProcAddress(g_libCEC, "CECInitialise"));
+ if (!LibCecInitialise)
+ {
+ cout << "cannot find CECInitialise" << endl;
+ return NULL;
+ }
+
+ return static_cast< CEC::ICECAdapter* > (LibCecInitialise(configuration));
+}
+
/*!
* @brief Destroy an instance of libCEC.
* @param device The instance to destroy.
void *g_libCEC = NULL;
/*!
- * @deprecated Please use LibCecInit() instead
+ * @brief Create a new libCEC instance.
+ * @param strDeviceName The name of the primary device to pass to other CEC devices.
+ * @param types The list of device types to register on the bus.
+ * @param strLib The name of and/or path to libCEC
+ * @return An instance of libCEC or NULL when it failed to load.
*/
-CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS, const char *strLib = NULL)
+CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_list types, const char *strLib = NULL)
{
if (!g_libCEC)
{
}
}
- typedef void* _CreateLibCec(const char *, uint8_t, uint16_t);
- _CreateLibCec* CreateLibCec = (_CreateLibCec*) dlsym(g_libCEC, "CECCreate");
- if (!CreateLibCec)
+ typedef void* _LibCecInit(const char *, CEC::cec_device_type_list);
+ _LibCecInit* LibCecInit = (_LibCecInit*) dlsym(g_libCEC, "CECInit");
+ if (!LibCecInit)
{
- cout << "cannot find CECCreate" << endl;
+ cout << "cannot find CECInit" << endl;
return NULL;
}
- return (CEC::ICECAdapter*) CreateLibCec(strName, iLogicalAddress, iPhysicalAddress);
+ return (CEC::ICECAdapter*) LibCecInit(strDeviceName, types);
}
/*!
* @brief Create a new libCEC instance.
- * @param strDeviceName The name of the primary device to pass to other CEC devices.
- * @param types The list of device types to register on the bus.
- * @param strLib The name of and/or path to libCEC
- * @return An instance of libCEC or NULL when it failed to load.
+ * @param configuration The configuration to pass to libCEC
+ * @return An instance of ICECAdapter or NULL on error.
*/
-CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_list types, const char *strLib = NULL)
+CEC::ICECAdapter *LibCecInitialise(const CEC::CecAdapterConfiguration &configuration)
{
if (!g_libCEC)
{
}
}
- typedef void* _LibCecInit(const char *, CEC::cec_device_type_list);
- _LibCecInit* LibCecInit = (_LibCecInit*) dlsym(g_libCEC, "CECInit");
- if (!LibCecInit)
+ typedef void* _LibCecInitialise(const CEC::CecAdapterConfiguration &);
+ _LibCecInitialise* LibCecInitialise = (_LibCecInitialise*) dlsym(g_libCEC, "CECInitialise");
+ if (!LibCecInitialise)
{
- cout << "cannot find CECInit" << endl;
+ cout << "cannot find CECInitialise" << endl;
return NULL;
}
- return (CEC::ICECAdapter*) LibCecInit(strDeviceName, types);
+ return (CEC::ICECAdapter*) LibCecInitialise(configuration);
}
/*!
CBCecCommandType CBCecCommand;
} ICECCallbacks;
+typedef enum cec_client_version
+{
+ CEC_CLIENT_VERSION_PRE_1_5 = 0,
+ CEC_CLIENT_VERSION_1_5_0 = 1
+} cec_client_version;
+
+typedef struct libcec_configuration
+{
+ char strDeviceName[13]; /*!< how to name the device on the CEC bus */
+ cec_device_type_list deviceTypes; /*!< the CEC device types to emulate */
+ uint16_t iPhysicalAddress; /*!< the physical address of the CEC adapter */
+ cec_logical_address baseDevice; /*!< the logical address of the device to which the adapter is connected. only used when iPhysicalAddress = 0 */
+ uint8_t iHDMIPort; /*!< the HDMI port to which the adapter is connected. only used when iPhysicalAddress = 0 */
+ cec_client_version clientVersion; /*!< the version of the client that is connecting */
+
+ void * callbackParam; /*!< the object to pass along with a call of the callback methods. NULL to ignore */
+ ICECCallbacks * callbacks; /*!< the callback methods to use. set this to NULL when not using callbacks */
+
+#ifdef __cplusplus
+ void Clear(void)
+ {
+ memset(strDeviceName, 0, 13);
+ deviceTypes.clear();
+ iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
+ baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE;
+ iHDMIPort = CEC_DEFAULT_HDMI_PORT;
+ clientVersion = CEC_CLIENT_VERSION_PRE_1_5;
+ callbackParam = NULL;
+ callbacks = NULL;
+ }
+#endif
+} libcec_configuration;
+
#ifdef UNUSED
#elif defined(__GNUC__)
#define UNUSED(x) UNUSED_ ## x __attribute__((unused))
}
PrintToStdOut("=== USB-CEC Adapter Configuration Summary ===\n");
+ bool bHasAudiosystem = g_parser->IsActiveDevice(CECDEVICE_AUDIOSYSTEM);
+
PrintToStdOut("Physical address: %4X", iAddress);
g_parser->StandbyDevices();
using namespace std;
using namespace PLATFORM;
-CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress /* = 0 */) :
+CCECProcessor::CCECProcessor(CLibCEC *controller, const libcec_configuration *configuration) :
+ m_bInitialised(false),
+ m_iPhysicalAddress(configuration->iPhysicalAddress),
+ m_iHDMIPort(configuration->iHDMIPort),
+ m_iBaseDevice(configuration->baseDevice),
+ m_strDeviceName(configuration->strDeviceName),
+ m_types(configuration->deviceTypes),
+ m_communication(NULL),
+ m_controller(controller),
+ m_bMonitor(false),
+ m_iStandardLineTimeout(3),
+ m_iRetryLineTimeout(3),
+ m_iLastTransmission(0),
+ m_clientVersion(configuration->clientVersion)
+{
+ m_logicalAddresses.Clear();
+ CreateBusDevices();
+}
+
+CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress, cec_client_version clientVersion) :
m_bInitialised(false),
m_iPhysicalAddress(iPhysicalAddress),
m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
m_bMonitor(false),
m_iStandardLineTimeout(3),
m_iRetryLineTimeout(3),
- m_iLastTransmission(0)
+ m_iLastTransmission(0),
+ m_clientVersion(clientVersion)
{
m_logicalAddresses.Clear();
+ CreateBusDevices();
+}
+
+void CCECProcessor::CreateBusDevices(void)
+{
for (int iPtr = 0; iPtr < 16; iPtr++)
{
switch(iPtr)
}
if (bReturn)
- CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d", m_communication->GetFirmwareVersion());
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication->GetFirmwareVersion(), ToString(m_clientVersion));
return bReturn;
}
}
}
+const char *CCECProcessor::ToString(const cec_client_version version)
+{
+ switch (version)
+ {
+ case CEC_CLIENT_VERSION_PRE_1_5:
+ return "pre-1.5";
+ case CEC_CLIENT_VERSION_1_5_0:
+ return "1.5.0";
+ default:
+ return "Unknown";
+ }
+}
+
void *CCECBusScan::Process(void)
{
CCECBusDevice *device(NULL);
class CCECProcessor : public PLATFORM::CThread, public IAdapterCommunicationCallback
{
public:
- CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress = 0);
+ CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress, cec_client_version clientVersion);
+ CCECProcessor(CLibCEC *controller, const libcec_configuration *configuration);
virtual ~CCECProcessor(void);
virtual bool Start(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
const char *ToString(const cec_system_audio_status mode);
const char *ToString(const cec_audio_status status);
const char *ToString(const cec_vendor_id vendor);
+ const char *ToString(const cec_client_version version);
virtual bool Transmit(const cec_command &data);
virtual void TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs);
bool Initialise(void);
void SetInitialised(bool bSetTo = true);
+ void CreateBusDevices(void);
void ReplaceHandlers(void);
void ScanCECBus(void);
uint8_t m_iStandardLineTimeout;
uint8_t m_iRetryLineTimeout;
uint64_t m_iLastTransmission;
+ cec_client_version m_clientVersion;
};
class CCECBusScan : public PLATFORM::CThread
m_callbacks(NULL),
m_cbParam(NULL)
{
- m_cec = new CCECProcessor(this, strDeviceName, types, iPhysicalAddress);
+ m_cec = new CCECProcessor(this, strDeviceName, types, iPhysicalAddress, CEC_CLIENT_VERSION_PRE_1_5);
+}
+
+CLibCEC::CLibCEC(const libcec_configuration *configuration) :
+ m_iStartTime(GetTimeMs()),
+ m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
+ m_buttontime(0),
+ m_callbacks(configuration->callbacks),
+ m_cbParam(configuration->callbackParam)
+{
+ m_cec = new CCECProcessor(this, configuration);
}
CLibCEC::~CLibCEC(void)
return static_cast< void* > (lib);
}
+void * CECInitialise(const libcec_configuration *configuration)
+{
+ CLibCEC *lib = new CLibCEC(configuration);
+ CLibCEC::SetInstance(lib);
+ return static_cast< void* > (lib);
+}
+
void CECDestroy(CEC::ICECAdapter *UNUSED(instance))
{
CLibCEC::SetInstance(NULL);
{
return m_cec->ToString(vendor);
}
+
+const char *CLibCEC::ToString(const cec_client_version version)
+{
+ return m_cec->ToString(version);
+}
*/
//@{
CLibCEC(const char *strDeviceName, cec_device_type_list types, uint16_t iPhysicalAddress = 0);
+ CLibCEC(const libcec_configuration *configuration);
virtual ~CLibCEC(void);
virtual bool Open(const char *strPort, uint32_t iTimeout = 10000);
const char *ToString(const cec_system_audio_status mode);
const char *ToString(const cec_audio_status status);
const char *ToString(const cec_vendor_id vendor);
+ const char *ToString(const cec_client_version version);
//@}
static void AddLog(cec_log_level level, const char *strFormat, ...);
//@{
ICECAdapter *cec_parser;
-int cec_init_typed(const char *strDeviceName, cec_device_type_list devicesTypes)
+int cec_initialise(const libcec_configuration *configuration)
{
- cec_parser = (ICECAdapter *) CECInit(strDeviceName, devicesTypes);
+ cec_parser = (ICECAdapter *) CECInitialise(configuration);
+ return (cec_parser != NULL) ? 1 : 0;
+}
+
+int cec_init_typed(const char *strDeviceName, cec_device_type_list deviceTypes)
+{
+ cec_parser = (ICECAdapter *) CECInit(strDeviceName, deviceTypes);
return (cec_parser != NULL) ? 1 : 0;
}
using namespace std;
using namespace PLATFORM;
-#define CEC_TEST_CLIENT_VERSION 1
-
#include <cecloader.h>
+ICECCallbacks g_callbacks;
+libcec_configuration g_config;
int g_cecLogLevel(CEC_LOG_ALL);
ofstream g_logOutput;
bool g_bShortLog(false);
CStdString g_strPort;
-uint8_t g_iHDMIPort(CEC_DEFAULT_HDMI_PORT);
-cec_logical_address g_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE);
-cec_device_type_list g_typeList;
bool g_bSingleCommand(false);
bool g_bExit(false);
bool g_bHardExit(false);
CMutex g_outputMutex;
-ICECCallbacks g_callbacks;
inline void PrintToStdOut(const char *strFormat, ...)
{
"available commands" << endl;
}
-ICECAdapter *CreateParser(cec_device_type_list typeList)
-{
- ICECAdapter *parser = LibCecInit("CECTester", typeList);
- if (!parser || parser->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION)
- {
- #ifdef __WINDOWS__
- PrintToStdOut("Cannot load libcec.dll");
- #else
- PrintToStdOut("Cannot load libcec.so");
- #endif
- return NULL;
- }
-
- PrintToStdOut("CEC Parser created - libcec version %d.%d", parser->GetLibVersionMajor(), parser->GetLibVersionMinor());
-
- return parser;
-}
-
void ShowHelpConsole(void)
{
CLockObject lock(g_outputMutex);
{
if (!g_bSingleCommand)
cout << "== using device type 'playback device'" << endl;
- g_typeList.add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
+ g_config.deviceTypes.add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
}
else if (!strcmp(argv[iArgPtr + 1], "r"))
{
if (!g_bSingleCommand)
cout << "== using device type 'recording device'" << endl;
- g_typeList.add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
+ g_config.deviceTypes.add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
}
else if (!strcmp(argv[iArgPtr + 1], "t"))
{
if (!g_bSingleCommand)
cout << "== using device type 'tuner'" << endl;
- g_typeList.add(CEC_DEVICE_TYPE_TUNER);
+ g_config.deviceTypes.add(CEC_DEVICE_TYPE_TUNER);
}
else if (!strcmp(argv[iArgPtr + 1], "a"))
{
if (!g_bSingleCommand)
cout << "== using device type 'audio system'" << endl;
- g_typeList.add(CEC_DEVICE_TYPE_AUDIO_SYSTEM);
+ g_config.deviceTypes.add(CEC_DEVICE_TYPE_AUDIO_SYSTEM);
}
else
{
else if (!strcmp(argv[iArgPtr], "--list-devices") ||
!strcmp(argv[iArgPtr], "-l"))
{
- ICECAdapter *parser = CreateParser(g_typeList);
+ ICECAdapter *parser = LibCecInitialise(&g_config);
if (parser)
{
ListDevices(parser);
{
if (argc >= iArgPtr + 2)
{
- g_iBaseDevice = (cec_logical_address)atoi(argv[iArgPtr + 1]);
- cout << "using base device '" << (int)g_iBaseDevice << "'" << endl;
+ g_config.baseDevice = (cec_logical_address)atoi(argv[iArgPtr + 1]);
+ cout << "using base device '" << (int)g_config.baseDevice << "'" << endl;
++iArgPtr;
}
++iArgPtr;
{
if (argc >= iArgPtr + 2)
{
- g_iHDMIPort = (int8_t)atoi(argv[iArgPtr + 1]);
- cout << "using HDMI port '" << (int)g_iHDMIPort << "'" << endl;
+ g_config.iHDMIPort = (int8_t)atoi(argv[iArgPtr + 1]);
+ cout << "using HDMI port '" << (int)g_config.iHDMIPort << "'" << endl;
++iArgPtr;
}
++iArgPtr;
int main (int argc, char *argv[])
{
- g_typeList.clear();
+ g_config.Clear();
+ snprintf(g_config.strDeviceName, 13, "CECTester");
+ g_config.callbackParam = NULL;
+ g_config.clientVersion = CEC_CLIENT_VERSION_1_5_0;
+ g_callbacks.CBCecLogMessage = &CecLogMessage;
+ g_callbacks.CBCecKeyPress = &CecKeyPress;
+ g_callbacks.CBCecCommand = &CecCommand;
+ g_config.callbacks = &g_callbacks;
if (!ProcessCommandLineArguments(argc, argv))
return 0;
- if (g_typeList.IsEmpty())
+ if (g_config.deviceTypes.IsEmpty())
{
if (!g_bSingleCommand)
cout << "No device type given. Using 'recording device'" << endl;
- g_typeList.add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
+ g_config.deviceTypes.add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
}
- ICECAdapter *parser = LibCecInit("CECTester", g_typeList);
- if (!parser || parser->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION)
+ ICECAdapter *parser = LibCecInitialise(&g_config);
+ if (!parser)
{
#ifdef __WINDOWS__
cout << "Cannot load libcec.dll" << endl;
}
}
- EnableCallbacks(parser);
-
- parser->SetHDMIPort(g_iBaseDevice, g_iHDMIPort);
PrintToStdOut("opening a connection to the CEC adapter...");
if (!parser->Open(g_strPort.c_str()))