From 91345b55d136fdaeb737d17b4e562541b9676460 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 29 Oct 2017 17:59:36 +0000 Subject: [PATCH] Stretch: libcec4 changes --- remotelinux.cc | 84 ++++++++++++++++++++++++++++++++++++++++++++++++-- remotelinux.h | 9 +++++- 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/remotelinux.cc b/remotelinux.cc index 2d0270b..82069b0 100644 --- a/remotelinux.cc +++ b/remotelinux.cc @@ -131,14 +131,22 @@ int RemoteLinux::initCec() { Log::getInstance()->log("Remote", Log::NOTICE, "Init LibCEC"); cec_config.Clear(); cec_callbacks.Clear(); +#if CEC_LIB_VERSION_MAJOR >= 4 + cec_callbacks.logMessage = cecLogMessage; + cec_callbacks.keyPress = cecKeyPress; + cec_callbacks.commandReceived = cecCommand; + cec_callbacks.configurationChanged = cecConfigurationChanged; + cec_callbacks.sourceActivated = cecSourceActivated; +#else cec_callbacks.CBCecLogMessage = cecLogMessage; cec_callbacks.CBCecKeyPress = cecKeyPress; cec_callbacks.CBCecCommand = cecCommand; cec_callbacks.CBCecConfigurationChanged = cecConfigurationChanged; cec_callbacks.CBCecSourceActivated = cecSourceActivated; - cec_config.clientVersion=LIBCEC_VERSION_CURRENT; - cec_config.bActivateSource=1; cec_config.bUseTVMenuLanguage=1; +#endif + cec_config.clientVersion=LIBCEC_VERSION_CURRENT; + cec_config.bActivateSource=1; //cec_config.deviceTypes.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); cec_config.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); //cec_config.deviceTypes.Add(CEC_DEVICE_TYPE_TUNER); @@ -157,8 +165,13 @@ int RemoteLinux::initCec() { cec_adap->InitVideoStandalone(); +#if CEC_LIB_VERSION_MAJOR >= 4 + cec_adapter_descriptor cec_adapter_descriptors[10]; + int adap_num=cec_adap->DetectAdapters(cec_adapter_descriptors, 10); +#else cec_adapter cec_devices[10]; int adap_num=cec_adap->FindAdapters(cec_devices,10,NULL); +#endif if (adap_num<0) { Log::getInstance()->log("Remote", Log::ERR, "CEC:Failed to find adapter"); return 1; @@ -169,8 +182,12 @@ int RemoteLinux::initCec() { return 1; } +#if CEC_LIB_VERSION_MAJOR >= 4 + if (!cec_adap->Open(cec_adapter_descriptors[0].strComPath)) { +#else if (!cec_adap->Open(cec_devices[0].comm)) { - Log::getInstance()->log("Remote", Log::ERR, "CEC:Failed to open adapter"); +#endif + Log::getInstance()->log("Remote", Log::ERR, "CEC:Failed to open adapter"); return 1; } @@ -904,6 +921,61 @@ void RemoteLinux::changePowerState(bool poweron){ } } +#if CEC_LIB_VERSION_MAJOR >= 4 + +// libcec4 API changed these params to pointers rather than copies, and the returns to void +// Otherwise, these two blocks of code are the same + +void RemoteLinux::cecLogMessage(void *param, const cec_log_message* message) +{ + Log::getInstance()->log("Remote", Log::DEBUG, "CECLOG: %lld %d %s", message->time, message->level, message->message); +} + +void RemoteLinux::cecKeyPress(void*param, const cec_keypress* key) +{ + //Log::getInstance()->log("Remote", Log::DEBUG, "Incoming cec key %d %d", key->keycode,key->duration); + if (key->duration==0) ((RemoteLinux*)Remote::getInstance())->incomingCECkey(key->keycode); +} + +void RemoteLinux::cecCommand(void *param, const cec_command* command) +{ + Log::getInstance()->log("Remote", Log::DEBUG, "CECCommand: %d",command->opcode); + switch (command->opcode) { + case CEC_OPCODE_STANDBY: { + if (command->initiator==CECDEVICE_TV) { + ((RemoteLinux*)Remote::getInstance())->incomingPowerkey(POWEROFF); + } + } break; + case CEC_OPCODE_DECK_CONTROL: { + if (command->initiator==CECDEVICE_TV && command->parameters.size == 1 + && command->parameters[0]==CEC_DECK_CONTROL_MODE_STOP) { + ((RemoteLinux*)Remote::getInstance())->incomingCECkey(CEC_USER_CONTROL_CODE_STOP); + + } + + } break; + case CEC_OPCODE_PLAY: { + if (command->initiator==CECDEVICE_TV && command->parameters.size == 1) { + if (command->parameters[0]==CEC_PLAY_MODE_PLAY_FORWARD) { + ((RemoteLinux*)Remote::getInstance())->incomingCECkey(CEC_USER_CONTROL_CODE_PLAY); + } else if (command->parameters[0]==CEC_PLAY_MODE_PLAY_STILL) { + ((RemoteLinux*)Remote::getInstance())->incomingCECkey(CEC_USER_CONTROL_CODE_PAUSE); + } + } + + + } break; + default: + break; + }; +} + +void RemoteLinux::cecConfigurationChanged(void *param, const libcec_configuration* config) +{ + Log::getInstance()->log("Remote", Log::DEBUG, "CECConfig:"/*,config->string()*/); +} + +#else int RemoteLinux::cecLogMessage(void *param, const cec_log_message message) { @@ -958,6 +1030,8 @@ int RemoteLinux::cecConfigurationChanged(void *param, const libcec_configuration } +#endif + void RemoteLinux::cecSourceActivated(void*param, const cec_logical_address address, const uint8_t activated) { Log::getInstance()->log("Remote", Log::DEBUG, "CECSourceActivated: %d %d", address, activated); @@ -1054,6 +1128,10 @@ void RemoteLinux::volumeDown() void RemoteLinux::volumeMute() { +#if CEC_LIB_VERSION_MAJOR >= 4 + cec_adap->AudioToggleMute(); +#else cec_adap->MuteAudio(); +#endif } diff --git a/remotelinux.h b/remotelinux.h index da6b592..84462cf 100644 --- a/remotelinux.h +++ b/remotelinux.h @@ -92,11 +92,18 @@ class RemoteLinux : public Remote void incomingCECkey(int keys); void incomingPowerkey(UCHAR key); +#if CEC_LIB_VERSION_MAJOR >= 4 + static void cecLogMessage(void *param, const CEC::cec_log_message* message); + static void cecKeyPress(void*param, const CEC::cec_keypress* key); + static void cecCommand(void *param, const CEC::cec_command* command); + static void cecConfigurationChanged(void *param, const CEC::libcec_configuration* config); +#else static int cecLogMessage(void *param, const CEC::cec_log_message message); static int cecKeyPress(void*param, const CEC::cec_keypress key); static int cecCommand(void *param, const CEC::cec_command command); static int cecConfigurationChanged(void *param, const CEC::libcec_configuration config); - static void cecSourceActivated(void*param, const CEC::cec_logical_address address, const uint8_t activated); +#endif + static void cecSourceActivated(void*param, const CEC::cec_logical_address address, const uint8_t activated); }; -- 2.39.2