Merge pull request #300 from psyke83/cec4fix

Implement libcec4 compatibility
This commit is contained in:
Jools Wills 2017-11-12 06:26:41 +00:00 committed by GitHub
commit e94fb5c36d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,32 @@ extern int SDL_USER_CECBUTTONUP;
CECInput* CECInput::sInstance = nullptr; CECInput* CECInput::sInstance = nullptr;
#ifdef HAVE_LIBCEC #ifdef HAVE_LIBCEC
#if CEC_LIB_VERSION_MAJOR >= 4
static void onAlert(void* /*cbParam*/, const CEC::libcec_alert /*type*/, const CEC::libcec_parameter /*param*/)
{
return;
}
static void onCommand(void* /*cbParam*/, const CEC::cec_command* /*command*/)
{
return;
}
static void onKeyPress(void* /*cbParam*/, const CEC::cec_keypress* key)
{
SDL_Event event;
event.type = (key->duration > 0) ? SDL_USER_CECBUTTONUP : SDL_USER_CECBUTTONDOWN;
event.user.code = key->keycode;
SDL_PushEvent(&event);
return;
}
static void onLogMessage(void* /*cbParam*/, const CEC::cec_log_message* /*message*/)
{
return;
}
#else
static int onAlert(void* /*cbParam*/, const CEC::libcec_alert /*type*/, const CEC::libcec_parameter /*param*/) static int onAlert(void* /*cbParam*/, const CEC::libcec_alert /*type*/, const CEC::libcec_parameter /*param*/)
{ {
return 0; return 0;
@ -40,6 +66,7 @@ static int onLogMessage(void* /*cbParam*/, const CEC::cec_log_message /*message*
{ {
return 0; return 0;
} }
#endif
#endif // HAVE_LIBCEC #endif // HAVE_LIBCEC
void CECInput::init() void CECInput::init()
@ -70,34 +97,41 @@ CECInput::CECInput() : mlibCEC(nullptr)
config.callbacks = &callbacks; config.callbacks = &callbacks;
config.deviceTypes.Add(CEC::CEC_DEVICE_TYPE_PLAYBACK_DEVICE); config.deviceTypes.Add(CEC::CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
#if CEC_LIB_VERSION_MAJOR >= 4
callbacks.alert = &onAlert;
callbacks.commandReceived = &onCommand;
callbacks.keyPress = &onKeyPress;
callbacks.logMessage = &onLogMessage;
#else
callbacks.CBCecAlert = &onAlert; callbacks.CBCecAlert = &onAlert;
callbacks.CBCecCommand = &onCommand; callbacks.CBCecCommand = &onCommand;
callbacks.CBCecKeyPress = &onKeyPress; callbacks.CBCecKeyPress = &onKeyPress;
callbacks.CBCecLogMessage = &onLogMessage; callbacks.CBCecLogMessage = &onLogMessage;
#endif
mlibCEC = LibCecInitialise(&config); mlibCEC = LibCecInitialise(&config);
if(!mlibCEC) if(!mlibCEC)
{ {
LOG(LogInfo) << "CECInput::LibCecInitialise failed"; LOG(LogInfo) << "CECInput::LibCecInitialise failed";
return; return;
} }
CEC::cec_adapter adapters[10]; CEC::cec_adapter_descriptor adapters[10];
int8_t numAdapters = mlibCEC->FindAdapters(adapters, 10, nullptr); int8_t numAdapters = mlibCEC->DetectAdapters(adapters, 10, nullptr, true);
if(numAdapters <= 0) if(numAdapters <= 0)
{ {
LOG(LogInfo) << "CECInput::mAdapter->FindAdapters failed"; LOG(LogInfo) << "CECInput::mAdapter->DetectAdapters failed";
UnloadLibCec(mlibCEC); UnloadLibCec(mlibCEC);
mlibCEC = nullptr; mlibCEC = nullptr;
return; return;
} }
for(int i = 0; i < numAdapters; ++i) for(int i = 0; i < numAdapters; ++i)
LOG(LogDebug) << "adapter: " << i << " path: " << adapters[i].comm << " comm: " << adapters[i].comm; LOG(LogDebug) << "adapter: " << i << " path: " << adapters[i].strComPath << " name: " << adapters[i].strComName;
if(!mlibCEC->Open(adapters[0].comm)) if(!mlibCEC->Open(adapters[0].strComName))
{ {
LOG(LogInfo) << "CECInput::mAdapter->Open failed"; LOG(LogInfo) << "CECInput::mAdapter->Open failed";
UnloadLibCec(mlibCEC); UnloadLibCec(mlibCEC);