Skip to content

Commit 662872d

Browse files
feat: SchemaChecker & V4L2 enhancement (#734)
* libjpeg-turbo, QJsonSchemaChecker, V4L2 width/height/fps Signed-off-by: Paulchen-Panther <Paulchen-Panter@protonmail.com> * Implement hyperion-v4l cli args * Apply v4l2 settings during runtime * feat: Provide minimum values for input restriction * fix: merge mess Co-authored-by: brindosch <edeltraud70@gmx.de>
1 parent 20a5e5d commit 662872d

26 files changed

+363
-121
lines changed

CMakeLists.txt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,23 +298,32 @@ find_package(libusb-1.0 REQUIRED)
298298
find_package(Threads REQUIRED)
299299
add_definitions(${QT_DEFINITIONS})
300300

301-
# Add jpeg library
301+
# Add JPEG library
302302
if (ENABLE_V4L2)
303-
find_package(JPEG)
304-
if (JPEG_FOUND)
305-
add_definitions(-DHAVE_JPEG)
306-
message( STATUS "Using JPEG library: ${JPEG_LIBRARIES}")
307-
include_directories(${JPEG_INCLUDE_DIR})
303+
# Turbo JPEG
304+
find_package(TurboJPEG)
305+
if (TURBOJPEG_FOUND)
306+
add_definitions(-DHAVE_TURBO_JPEG)
307+
message( STATUS "Using Turbo JPEG library: ${TurboJPEG_LIBRARY}")
308+
include_directories(${TurboJPEG_INCLUDE_DIRS})
308309
else()
309-
message( STATUS "JPEG library not found, MJPEG camera format won't work in V4L2 grabber.")
310+
# System JPEG
311+
find_package(JPEG)
312+
if (JPEG_FOUND)
313+
add_definitions(-DHAVE_JPEG)
314+
message( STATUS "Using system JPEG library: ${JPEG_LIBRARIES}")
315+
include_directories(${JPEG_INCLUDE_DIR})
316+
else()
317+
message( STATUS "JPEG library not found, MJPEG camera format won't work in V4L2 grabber.")
318+
endif()
319+
endif (TurboJPEG_FOUND)
320+
321+
322+
if (TURBOJPEG_FOUND OR JPEG_FOUND)
323+
add_definitions(-DHAVE_JPEG_DECODER)
310324
endif()
311325
endif()
312326

313-
# TODO[TvdZ]: This linking directory should only be added if we are cross compiling
314-
#if(NOT APPLE)
315-
# link_directories(${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf)
316-
#endif()
317-
318327
if(APPLE)
319328
set(CMAKE_EXE_LINKER_FLAGS "-framework CoreGraphics")
320329
endif()

CompileHowto.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ wget -qN https://raw.github.com/hyperion-project/hyperion.ng/master/bin/scripts/
4040

4141
```
4242
sudo apt-get update
43-
sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libqt5sql5-sqlite libssl-dev
43+
sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite libssl-dev
4444
```
4545

4646
**on RPI you need the videocore IV headers**

CrossCompileHowto.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Use a clean Raspbian Stretch Lite (on target) and Ubuntu 18/19 (on host) to exec
44
## On the Target system (here Raspberry Pi)
55
Install required additional packages.
66
```
7-
sudo apt-get install qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libqt5sql5-sqlite aptitude show qt5-default rsync
7+
sudo apt-get install qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite aptitude show qt5-default rsync
88
```
99
## On the Host system (here Ubuntu)
1010
Update the Ubuntu environment to the latest stage and install required additional packages.
1111
```
1212
sudo apt-get update
1313
sudo apt-get upgrade
14-
sudo apt-get -qq -y install git rsync cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libqt5sql5-sqlite
14+
sudo apt-get -qq -y install git rsync cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite
1515
```
1616

1717
Refine the target IP or hostname, plus userID as required and set-up cross-compilation environment:

bin/compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CFG="${2:-Release}"
55
INST="$( [ "${3:-}" = "install" ] && echo true || echo false )"
66

77
sudo apt-get update
8-
sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libssl-dev || exit 1
8+
sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev libturbojpeg0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libssl-dev || exit 1
99

1010
if [ -e /dev/vc-cma -a -e /dev/vc-mem ]
1111
then

cmake/FindTurboJPEG.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# FindTurboJPEG.cmake
2+
# TURBOJPEG_FOUND
3+
# TurboJPEG_INCLUDE_DIRS
4+
# TurboJPEG_LIBRARY
5+
6+
find_path(TurboJPEG_INCLUDE_DIRS
7+
NAMES turbojpeg.h
8+
PATH_SUFFIXES include
9+
)
10+
11+
find_library(TurboJPEG_LIBRARY
12+
NAMES turbojpeg turbojpeg-static
13+
PATH_SUFFIXES bin lib
14+
)
15+
16+
if(TurboJPEG_INCLUDE_DIRS AND TurboJPEG_LIBRARY)
17+
include(CheckCSourceCompiles)
18+
include(CMakePushCheckState)
19+
20+
cmake_push_check_state(RESET)
21+
list(APPEND CMAKE_REQUIRED_INCLUDES ${TurboJPEG_INCLUDE_DIRS})
22+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${TurboJPEG_LIBRARY})
23+
24+
check_c_source_compiles("#include <turbojpeg.h>\nint main(void) { tjhandle h=tjInitCompress(); return 0; }" TURBOJPEG_WORKS)
25+
cmake_pop_check_state()
26+
endif()
27+
28+
include(FindPackageHandleStandardArgs)
29+
find_package_handle_standard_args(TurboJpeg
30+
FOUND_VAR TURBOJPEG_FOUND
31+
REQUIRED_VARS TurboJPEG_LIBRARY TurboJPEG_INCLUDE_DIRS TURBOJPEG_WORKS
32+
TurboJPEG_INCLUDE_DIRS TurboJPEG_LIBRARY
33+
)

config/hyperion.config.json.commented

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101

102102
/// Configuration for the embedded V4L2 grabber
103103
/// * device : V4L2 Device to use [default="auto"] (Auto detection)
104+
/// * width : The width of the grabbed frames (pixels) [default=0]
105+
/// * height : The height of the grabbed frames (pixels) [default=0]
104106
/// * standard : Video standard (PAL/NTSC/SECAM/NO_CHANGE) [default="NO_CHANGE"]
105107
/// * sizeDecimation : Size decimation factor [default=8]
106108
/// * cropLeft : Cropping from the left [default=0]
@@ -118,6 +120,8 @@
118120
"grabberV4L2" :
119121
{
120122
"device" : "auto",
123+
"width" : 0,
124+
"height" : 0,
121125
"standard" : "NO_CHANGE",
122126
"sizeDecimation" : 8,
123127
"priority" : 240,

config/hyperion.config.json.default

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,24 @@
5959

6060
"grabberV4L2" :
6161
{
62-
"device" : "auto",
63-
"standard" : "NO_CHANGE",
64-
"sizeDecimation" : 8,
65-
"cropLeft" : 0,
66-
"cropRight" : 0,
67-
"cropTop" : 0,
68-
"cropBottom" : 0,
69-
"redSignalThreshold" : 5,
70-
"greenSignalThreshold" : 5,
71-
"blueSignalThreshold" : 5,
72-
"signalDetection" : false,
73-
"sDVOffsetMin" : 0.25,
74-
"sDHOffsetMin" : 0.25,
75-
"sDVOffsetMax" : 0.75,
76-
"sDHOffsetMax" : 0.75
62+
"device" : "auto",
63+
"width" : 0,
64+
"height" : 0,
65+
"fps" : 15,
66+
"standard" : "NO_CHANGE",
67+
"sizeDecimation" : 8,
68+
"cropLeft" : 0,
69+
"cropRight" : 0,
70+
"cropTop" : 0,
71+
"cropBottom" : 0,
72+
"redSignalThreshold" : 5,
73+
"greenSignalThreshold" : 5,
74+
"blueSignalThreshold" : 5,
75+
"signalDetection" : false,
76+
"sDVOffsetMin" : 0.25,
77+
"sDHOffsetMin" : 0.25,
78+
"sDVOffsetMax" : 0.75,
79+
"sDHOffsetMax" : 0.75
7780
},
7881

7982
"framegrabber" :

include/grabber/V4L2Grabber.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@
1515
#include <grabber/VideoStandard.h>
1616
#include <utils/Components.h>
1717

18-
#ifdef HAVE_JPEG
18+
// general JPEG decoder includes
19+
#ifdef HAVE_JPEG_DECODER
1920
#include <QImage>
2021
#include <QColor>
22+
#endif
23+
24+
// System JPEG decoder
25+
#ifdef HAVE_JPEG
2126
#include <jpeglib.h>
2227
#include <csetjmp>
2328
#endif
2429

30+
// TurboJPEG decoder
31+
#ifdef HAVE_TURBO_JPEG
32+
#include <turbojpeg.h>
33+
#endif
34+
2535
/// Capture class for V4L2 devices
2636
///
2737
/// @see http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html
@@ -31,6 +41,9 @@ class V4L2Grabber : public Grabber
3141

3242
public:
3343
V4L2Grabber(const QString & device,
44+
const unsigned width,
45+
const unsigned height,
46+
const unsigned fps,
3447
VideoStandard videoStandard,
3548
PixelFormat pixelFormat,
3649
int pixelDecimation
@@ -46,11 +59,6 @@ class V4L2Grabber : public Grabber
4659

4760
int grabFrame(Image<ColorRgb> &);
4861

49-
///
50-
/// @brief overwrite Grabber.h implementation, as v4l doesn't use width/height
51-
///
52-
virtual void setWidthHeight(){};
53-
5462
///
5563
/// @brief set new PixelDecimation value to ImageResampler
5664
/// @param pixelDecimation The new pixelDecimation value
@@ -84,6 +92,16 @@ class V4L2Grabber : public Grabber
8492
///
8593
virtual void setDeviceVideoStandard(QString device, VideoStandard videoStandard);
8694

95+
///
96+
/// @brief overwrite Grabber.h implementation
97+
///
98+
virtual bool setFramerate(int fps);
99+
100+
///
101+
/// @brief overwrite Grabber.h implementation
102+
///
103+
virtual bool setWidthHeight(int width, int height);
104+
87105
public slots:
88106

89107
bool start();
@@ -173,6 +191,11 @@ private slots:
173191
errorManager* _error;
174192
#endif
175193

194+
#ifdef HAVE_TURBO_JPEG
195+
tjhandle _decompress = nullptr;
196+
int _subsamp;
197+
#endif
198+
176199
private:
177200
QString _deviceName;
178201
std::map<QString,QString> _v4lDevices;

include/grabber/V4L2Wrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class V4L2Wrapper : public GrabberWrapper
99

1010
public:
1111
V4L2Wrapper(const QString & device,
12+
const unsigned grabWidth,
13+
const unsigned grabHeight,
14+
const unsigned fps,
1215
VideoStandard videoStandard,
1316
PixelFormat pixelFormat,
1417
int pixelDecimation );

include/hyperion/Grabber.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class Grabber : public QObject
4040
///
4141
virtual bool setWidthHeight(int width, int height);
4242

43+
///
44+
/// @brief Apply new framerate (used from v4l)
45+
/// @param fps framesPerSecond
46+
///
47+
virtual bool setFramerate(int fps);
48+
4349
///
4450
/// @brief Apply new pixelDecimation (used from x11 and qt)
4551
///
@@ -111,6 +117,8 @@ class Grabber : public QObject
111117
/// Height of the captured snapshot [pixels]
112118
int _height;
113119

120+
int _fps;
121+
114122
// number of pixels to crop after capturing
115123
int _cropLeft, _cropRight, _cropTop, _cropBottom;
116124

0 commit comments

Comments
 (0)