Skip to content

Commit

Permalink
Feature/CEC detection (hyperion-project#877)
Browse files Browse the repository at this point in the history
* Add CEC functionality

* Initial commit

* removed libCEC from the system skip list

Co-authored-by: Paulchen Panther <[email protected]>
  • Loading branch information
m-seker and Paulchen-Panther authored Jul 20, 2020
1 parent a3ce4fa commit c124e21
Show file tree
Hide file tree
Showing 35 changed files with 651 additions and 89 deletions.
25 changes: 15 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,19 @@ SET ( DEFAULT_USE_SYSTEM_MBEDTLS_LIBS OFF )
SET ( DEFAULT_TESTS OFF )

IF ( ${CMAKE_SYSTEM} MATCHES "Linux" )
SET ( DEFAULT_V4L2 ON )
SET ( DEFAULT_SPIDEV ON )
SET ( DEFAULT_TINKERFORGE ON)
SET ( DEFAULT_FB ON )
SET ( DEFAULT_USB_HID ON )
SET ( DEFAULT_V4L2 ON )
SET ( DEFAULT_SPIDEV ON )
SET ( DEFAULT_TINKERFORGE ON )
SET ( DEFAULT_FB ON )
SET ( DEFAULT_USB_HID ON )
SET ( DEFAULT_CEC ON )
ELSE()
SET ( DEFAULT_V4L2 OFF )
SET ( DEFAULT_FB OFF )
SET ( DEFAULT_SPIDEV OFF )
SET ( DEFAULT_TINKERFORGE OFF)
SET ( DEFAULT_USB_HID OFF )
SET ( DEFAULT_V4L2 OFF )
SET ( DEFAULT_FB OFF )
SET ( DEFAULT_SPIDEV OFF )
SET ( DEFAULT_TINKERFORGE OFF )
SET ( DEFAULT_USB_HID OFF )
SET ( DEFAULT_CEC OFF )
ENDIF()

if ( NOT DEFINED PLATFORM )
Expand Down Expand Up @@ -173,6 +175,9 @@ message(STATUS "ENABLE_AVAHI = " ${ENABLE_AVAHI})
option(ENABLE_USB_HID "Enable the libusb and hid devices" ${DEFAULT_USB_HID} )
message(STATUS "ENABLE_USB_HID = ${ENABLE_USB_HID}")

option(ENABLE_CEC "Enable the libcec and CEC control" ${DEFAULT_CEC} )
message(STATUS "ENABLE_CEC = ${ENABLE_CEC}")

option(ENABLE_X11 "Enable the X11 grabber" ${DEFAULT_X11})
message(STATUS "ENABLE_X11 = ${ENABLE_X11}")

Expand Down
2 changes: 1 addition & 1 deletion CompileHowto.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ wget -qN https://raw.github.com/hyperion-project/hyperion.ng/master/bin/scripts/

```
sudo apt-get update
sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite libssl-dev zlib1g-dev
sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libcec-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite libssl-dev zlib1g-dev
```

**on RPI you need the videocore IV headers**
Expand Down
4 changes: 2 additions & 2 deletions CrossCompileHowto.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Use a clean Raspbian Stretch Lite (on target) and Ubuntu 18/19 (on host) to exec
## On the Target system (here Raspberry Pi)
Install required additional packages.
```
sudo apt-get install qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite aptitude qt5-default rsync libssl-dev zlib1g-dev
sudo apt-get install qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libcec-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite aptitude qt5-default rsync libssl-dev zlib1g-dev
```
## On the Host system (here Ubuntu)
Update the Ubuntu environment to the latest stage and install required additional packages.
```
sudo apt-get update
sudo apt-get upgrade
sudo apt-get -qq -y install git rsync cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite libssl-dev zlib1g-dev
sudo apt-get -qq -y install git rsync cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libcec-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite libssl-dev zlib1g-dev
```

Refine the target IP or hostname, plus userID as required and set-up cross-compilation environment:
Expand Down
3 changes: 3 additions & 0 deletions HyperionConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
// Define to enable avahi
#cmakedefine ENABLE_AVAHI

// Define to enable cec
#cmakedefine ENABLE_CEC

// Define to enable the usb / hid devices
#cmakedefine ENABLE_USB_HID

Expand Down
2 changes: 2 additions & 0 deletions assets/webconfig/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@
"edt_conf_v4l2_cropTop_expl" : "Count of pixels on the top side that are removed from the picture.",
"edt_conf_v4l2_cropBottom_title" : "Crop bottom",
"edt_conf_v4l2_cropBottom_expl" : "Count of pixels on the bottom side that are removed from the picture.",
"edt_conf_v4l2_cecDetection_title" : "CEC detection",
"edt_conf_v4l2_cecDetection_expl" : "If enabled, usb capture will be temporarily disabled when CEC standby event received from HDMI bus.",
"edt_conf_v4l2_signalDetection_title" : "Signal detection",
"edt_conf_v4l2_signalDetection_expl" : "If enabled, usb capture will be temporarily disabled when no signal was found. This will happen when the picture fall below the threshold value for a period of 4 seconds.",
"edt_conf_v4l2_redSignalThreshold_title" : "Red signal threshold",
Expand Down
3 changes: 2 additions & 1 deletion assets/webconfig/js/hyperion.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ async function requestLedDeviceProperties(type, params)
function requestLedDeviceIdentification(type, params)
{
sendToHyperion("leddevice", "identify", '"ledDeviceType": "'+type+'","params": '+JSON.stringify(params)+'');

//let data = {ledDeviceType: type, params: params};
//sendToHyperion("leddevice", "identify", data );
}

2 changes: 1 addition & 1 deletion bin/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CFG="${2:-Release}"
INST="$( [ "${3:-}" = "install" ] && echo true || echo false )"

sudo apt-get update
sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev libturbojpeg0-dev python3-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libssl-dev libjpeg-dev libqt5sql5-sqlite zlib1g-dev || exit 1
sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev libturbojpeg0-dev python3-dev libcec-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libssl-dev libjpeg-dev libqt5sql5-sqlite zlib1g-dev || exit 1

if [ -e /dev/vc-cma -a -e /dev/vc-mem ]
then
Expand Down
31 changes: 0 additions & 31 deletions bin/create_oe_depedencies.sh

This file was deleted.

2 changes: 1 addition & 1 deletion bin/create_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if ! [ -d "$builddir" ]; then
echo "Could not find build director"
exit 1
fi

outfile="$repodir/deploy/hyperion_$buildid.tar.gz"
echo create $outfile

Expand Down
1 change: 0 additions & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ macro(DeployUnix TARGET)
"libusb-1"
"libutil"
"libX11"
"libz"
)

if (APPLE)
Expand Down
19 changes: 19 additions & 0 deletions cmake/FindCEC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# - Try to find CEC
# Once done this will define
#
# CEC_FOUND - system has libcec
# CEC_INCLUDE_DIRS - the libcec include directory
# CEC_LIBRARIES - The libcec libraries

if(PKG_CONFIG_FOUND)
pkg_check_modules (CEC libcec>=3.0.0)
else()
find_path(CEC_INCLUDE_DIRS libcec/cec.h)
find_library(CEC_LIBRARIES cec)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CEC DEFAULT_MSG CEC_INCLUDE_DIRS CEC_LIBRARIES)

list(APPEND CEC_DEFINITIONS -DHAVE_LIBCEC=1)
mark_as_advanced(CEC_INCLUDE_DIRS CEC_LIBRARIES CEC_DEFINITIONS)
2 changes: 2 additions & 0 deletions config/hyperion.config.json.commented
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
/// * cropTop : Cropping from the top [default=0]
/// * cropBottom : Cropping from the bottom [default=0]
/// * signalDetection : enable/disable signal detection [default=true]
/// * cecDetection : enable/disable cec detection [default=true]
/// * redSignalThreshold : Signal threshold for the red channel between 0 and 100 [default=5]
/// * greenSignalThreshold : Signal threshold for the green channel between 0 and 100 [default=5]
/// * blueSignalThreshold : Signal threshold for the blue channel between 0 and 100 [default=5]
Expand All @@ -133,6 +134,7 @@
"greenSignalThreshold" : 5,
"blueSignalThreshold" : 5,
"signalDetection" : false,
"cecDetection" : false,
"sDVOffsetMin" : 0.25,
"sDHOffsetMin" : 0.25,
"sDVOffsetMax" : 0.75,
Expand Down
1 change: 1 addition & 0 deletions config/hyperion.config.json.default
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"greenSignalThreshold" : 5,
"blueSignalThreshold" : 5,
"signalDetection" : false,
"cecDetection" : false,
"sDVOffsetMin" : 0.25,
"sDHOffsetMin" : 0.25,
"sDVOffsetMax" : 0.75,
Expand Down
2 changes: 1 addition & 1 deletion include/api/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,4 @@ private slots:

// current instance index
quint8 _currInstanceIndex;
};
};
8 changes: 8 additions & 0 deletions include/cec/CECEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

enum class CECEvent
{
On,
Off
};

69 changes: 69 additions & 0 deletions include/cec/CECHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once

#include <QObject>
#include <QVector>

#include <iostream>

#include <libcec/cec.h>

#include <cec/CECEvent.h>

using CECCallbacks = CEC::ICECCallbacks;
using CECAdapter = CEC::ICECAdapter;
using CECAdapterDescriptor = CEC::cec_adapter_descriptor;
using CECLogMessage = CEC::cec_log_message;
using CECKeyPress = CEC::cec_keypress;
using CECCommand = CEC::cec_command;
using CECLogicalAddress = CEC::cec_logical_address;
using CECLogicalAddresses = CEC::cec_logical_addresses;
using CECMenuState = CEC::cec_menu_state;
using CECPowerStatus = CEC::cec_power_status;
using CECVendorId = CEC::cec_vendor_id;
using CECParameter = CEC::libcec_parameter;
using CECConfig = CEC::libcec_configuration;
using CECAlert = CEC::libcec_alert;

class Logger;

class CECHandler : public QObject
{
Q_OBJECT
public:
CECHandler();
~CECHandler() override;

QString scan() const;

public slots:
bool start();
void stop();

signals:
void cecEvent(CECEvent event);

private:
/* CEC Callbacks */
static void onCecLogMessage (void * context, const CECLogMessage * message);
static void onCecKeyPress (void * context, const CECKeyPress * key);
static void onCecAlert (void * context, const CECAlert alert, const CECParameter data);
static void onCecConfigurationChanged (void * context, const CECConfig * configuration);
static void onCecCommandReceived (void * context, const CECCommand * command);
static void onCecSourceActivated (void * context, const CECLogicalAddress address, const uint8_t activated);
static int onCecMenuStateChanged (void * context, const CECMenuState state);

/* CEC Adapter helpers */
QVector<CECAdapterDescriptor> getAdapters() const;
bool openAdapter(const CECAdapterDescriptor & descriptor);
void printAdapter(const CECAdapterDescriptor & descriptor) const;

/* CEC Helpers */
CECCallbacks getCallbacks() const;
CECConfig getConfig() const;

CECAdapter * _cecAdapter {};
CECCallbacks _cecCallbacks {};
CECConfig _cecConfig {};

Logger * _logger {};
};
11 changes: 11 additions & 0 deletions include/grabber/V4L2Grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <hyperion/Grabber.h>
#include <grabber/VideoStandard.h>
#include <utils/Components.h>
#include <cec/CECEvent.h>

// general JPEG decoder includes
#ifdef HAVE_JPEG_DECODER
Expand Down Expand Up @@ -67,6 +68,7 @@ class V4L2Grabber : public Grabber
}

bool getSignalDetectionEnabled() { return _signalDetectionEnabled; }
bool getCecDetectionEnabled() { return _cecDetectionEnabled; }

int grabFrame(Image<ColorRgb> &);

Expand Down Expand Up @@ -98,6 +100,11 @@ class V4L2Grabber : public Grabber
///
void setSignalDetectionEnable(bool enable) override;

///
/// @brief overwrite Grabber.h implementation
///
void setCecDetectionEnable(bool enable) override;

///
/// @brief overwrite Grabber.h implementation
///
Expand Down Expand Up @@ -149,6 +156,8 @@ public slots:

void stop();

void handleCecEvent(CECEvent event);

signals:
void newFrame(const Image<ColorRgb> & image);
void readError(const char* err);
Expand Down Expand Up @@ -257,6 +266,8 @@ private slots:
int _noSignalCounterThreshold;
ColorRgb _noSignalThresholdColor;
bool _signalDetectionEnabled;
bool _cecDetectionEnabled;
bool _cecStandbyActivated;
bool _noSignalDetected;
int _noSignalCounter;
double _x_frac_min;
Expand Down
5 changes: 3 additions & 2 deletions include/grabber/V4L2Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class V4L2Wrapper : public GrabberWrapper
~V4L2Wrapper() override;

bool getSignalDetectionEnable();
bool getCecDetectionEnable();

public slots:
bool start();
Expand All @@ -28,9 +29,9 @@ public slots:
void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom);
void setSignalDetectionOffset(double verticalMin, double horizontalMin, double verticalMax, double horizontalMax);
void setSignalDetectionEnable(bool enable);
void setCecDetectionEnable(bool enable);
void setDeviceVideoStandard(QString device, VideoStandard videoStandard);

signals:
void handleCecEvent(CECEvent event);

private slots:
void newFrame(const Image<ColorRgb> & image);
Expand Down
5 changes: 5 additions & 0 deletions include/hyperion/Grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class Grabber : public QObject
///
virtual void setSignalDetectionEnable(bool enable) {}

///
/// @brief Apply CecDetectionEnable (used from v4l)
///
virtual void setCecDetectionEnable(bool enable) {}

///
/// @brief Apply device and videoStanded (used from v4l)
///
Expand Down
1 change: 0 additions & 1 deletion include/hyperion/Hyperion.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,5 @@ private slots:
/// Boblight instance
BoblightServer* _boblightServer;

/// mutex
QMutex _changes;
};
8 changes: 6 additions & 2 deletions libsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ add_subdirectory(db)
add_subdirectory(api)
add_subdirectory(python)

if(ENABLE_CEC)
add_subdirectory(cec)
endif()

if(ENABLE_AVAHI)
add_subdirectory(bonjour)
endif()
add_subdirectory(bonjour)
endif()
2 changes: 1 addition & 1 deletion libsrc/api/JSONRPC_schema/schema-leddevice.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"params": {
"type" : "object",
"required" : false
}
}
},
"additionalProperties": false
}
1 change: 0 additions & 1 deletion libsrc/api/JsonAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,6 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject &message, const QString &
*/ {
if (subc == "discover")
{

QJsonObject config;
config.insert("type", devType);

Expand Down
Loading

0 comments on commit c124e21

Please sign in to comment.