mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Added HyperionPng with similar interface as Hyperion to test frame-capture and handling.
This commit is contained in:
@@ -25,14 +25,14 @@ include_directories(${BCM_INCLUDE_DIRS})
|
||||
target_link_libraries(boblight-dispmanx
|
||||
# hyperion-png
|
||||
bob2hyperion
|
||||
${BCM_LIBS})
|
||||
${BCM_LIBRARIES})
|
||||
|
||||
add_executable(HyperionDispmanX
|
||||
HyperionDispmanX.cpp)
|
||||
|
||||
target_link_libraries(HyperionDispmanX
|
||||
hyperion
|
||||
${BCM_LIBS})
|
||||
${BCM_LIBRARIES})
|
||||
|
||||
|
||||
# Find the libPNG
|
||||
@@ -50,3 +50,5 @@ if(PNG_FOUND)
|
||||
hyperion-utils
|
||||
${PNG_LIBRARIES})
|
||||
endif(PNG_FOUND)
|
||||
|
||||
add_subdirectory(dispmanx-png)
|
||||
|
@@ -55,16 +55,15 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
|
||||
RgbImage* image_ptr = &(hyperion.image());
|
||||
void* image_vp = reinterpret_cast<void*>(image_ptr);
|
||||
const unsigned imageSize_bytes = width*height*3;
|
||||
const uint32_t pitch = width * 3;
|
||||
|
||||
timespec updateInterval;
|
||||
updateInterval.tv_sec = 0;
|
||||
updateInterval.tv_nsec = 100000000000;
|
||||
|
||||
updateInterval.tv_nsec = 100000000;
|
||||
while(running)
|
||||
{
|
||||
vc_dispmanx_snapshot(display, resource, VC_IMAGE_ROT0);
|
||||
vc_dispmanx_resource_read_data(resource, &rectangle, image_vp, imageSize_bytes);
|
||||
vc_dispmanx_resource_read_data(resource, &rectangle, image_vp, pitch);
|
||||
|
||||
hyperion.commit();
|
||||
|
||||
|
13
src/dispmanx-png/CMakeLists.txt
Normal file
13
src/dispmanx-png/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
# Find the BCM-package (VC control)
|
||||
find_package(BCM REQUIRED)
|
||||
|
||||
# Add the include dirs to the search path
|
||||
include_directories(${BCM_INCLUDE_DIRS})
|
||||
|
||||
add_executable(dispmanx-png
|
||||
dispmanx-png.cpp)
|
||||
|
||||
target_link_libraries(dispmanx-png
|
||||
hyperion-png
|
||||
${BCM_LIBRARIES})
|
91
src/dispmanx-png/dispmanx-png.cpp
Normal file
91
src/dispmanx-png/dispmanx-png.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
|
||||
// STL includes
|
||||
#include <csignal>
|
||||
|
||||
// VC includes
|
||||
#include <bcm_host.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperionpng/HyperionPng.h>
|
||||
|
||||
static volatile bool sRunning = true;
|
||||
|
||||
void signal_handler(int signum)
|
||||
{
|
||||
std::cout << "RECEIVED SIGNAL: " << signum << std::endl;
|
||||
sRunning = false;
|
||||
}
|
||||
|
||||
template <typename Hyperion_T>
|
||||
int dispmanx_process(Hyperion_T& hyperion, volatile bool& running)
|
||||
{
|
||||
// Configure the used image size
|
||||
const unsigned width = 64;
|
||||
const unsigned height = 64;
|
||||
hyperion.setInputSize(width, height);
|
||||
|
||||
// Initiase BCM
|
||||
bcm_host_init();
|
||||
|
||||
// Open the connection to the displaydisplay
|
||||
DISPMANX_DISPLAY_HANDLE_T display = vc_dispmanx_display_open(0);
|
||||
DISPMANX_MODEINFO_T info;
|
||||
int ret = vc_dispmanx_display_get_info(display, &info);
|
||||
assert(ret == 0);
|
||||
|
||||
// Create the resources for capturing image
|
||||
uint32_t vc_image_ptr;
|
||||
DISPMANX_RESOURCE_HANDLE_T resource = vc_dispmanx_resource_create(
|
||||
VC_IMAGE_RGB888,
|
||||
width,
|
||||
height,
|
||||
&vc_image_ptr);
|
||||
assert(resource);
|
||||
|
||||
VC_RECT_T rectangle;
|
||||
vc_dispmanx_rect_set(&rectangle, 0, 0, width, height);
|
||||
|
||||
RgbImage* image_ptr = &(hyperion.image());
|
||||
void* image_vp = reinterpret_cast<void*>(image_ptr);
|
||||
const uint32_t pitch = width * 3;
|
||||
|
||||
timespec updateInterval;
|
||||
updateInterval.tv_sec = 0;
|
||||
updateInterval.tv_nsec = 100000000;
|
||||
while(running)
|
||||
{
|
||||
std::cout << "Grabbing a frame from display" << std::endl;
|
||||
vc_dispmanx_snapshot(display, resource, VC_IMAGE_ROT0);
|
||||
vc_dispmanx_resource_read_data(resource, &rectangle, image_vp, pitch);
|
||||
|
||||
std::cout << "Commiting the frame to Hyperion" << std::endl;
|
||||
// hyperion.commit();
|
||||
|
||||
std::cout << "Waiting for next grab" << std::endl;
|
||||
nanosleep(&updateInterval, NULL);
|
||||
}
|
||||
|
||||
std::cout << "Cleaning VC resources" << std::endl;
|
||||
// Clean up resources
|
||||
vc_dispmanx_resource_delete(resource);
|
||||
vc_dispmanx_display_close(display);
|
||||
|
||||
std::cout << "Uninitialising BCM-Host" << std::endl;
|
||||
// De-init BCM
|
||||
bcm_host_deinit();
|
||||
|
||||
std::cout << "Exit success" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char** /*argv*/)
|
||||
{
|
||||
// Install signal-handlers to exit the processing loop
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
// Construct and initialise the PNG creator with preset size
|
||||
HyperionPng hyperion;
|
||||
return dispmanx_process(hyperion, sRunning);
|
||||
}
|
Reference in New Issue
Block a user