mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added logging to X11Grabber (#71)
* Added logging to X11Grabber * Added logging to Amlogic grabber. * Fixed mistake in amlogicgrabber.h * fixed compile issue * Trigger * cleaned up log messages
This commit is contained in:
parent
e5332c44de
commit
6327a38582
4
include/grabber/AmlogicGrabber.h
Normal file → Executable file
4
include/grabber/AmlogicGrabber.h
Normal file → Executable file
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// STL includes
|
// STL includes
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <utils/Logger.h>
|
||||||
// Utils includes
|
// Utils includes
|
||||||
#include <utils/Image.h>
|
#include <utils/Image.h>
|
||||||
#include <utils/ColorBgr.h>
|
#include <utils/ColorBgr.h>
|
||||||
@ -55,4 +55,6 @@ private:
|
|||||||
|
|
||||||
/** The snapshot/capture device of the amlogic video chip */
|
/** The snapshot/capture device of the amlogic video chip */
|
||||||
int _amlogicCaptureDev;
|
int _amlogicCaptureDev;
|
||||||
|
|
||||||
|
Logger * _log;
|
||||||
};
|
};
|
||||||
|
4
include/grabber/X11Grabber.h
Normal file → Executable file
4
include/grabber/X11Grabber.h
Normal file → Executable file
@ -3,7 +3,7 @@
|
|||||||
#include <utils/Image.h>
|
#include <utils/Image.h>
|
||||||
#include <utils/ColorRgb.h>
|
#include <utils/ColorRgb.h>
|
||||||
#include <utils/ImageResampler.h>
|
#include <utils/ImageResampler.h>
|
||||||
|
#include <utils/Logger.h>
|
||||||
// X11 includes
|
// X11 includes
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/extensions/Xrender.h>
|
#include <X11/extensions/Xrender.h>
|
||||||
@ -64,4 +64,6 @@ private:
|
|||||||
void setupResources();
|
void setupResources();
|
||||||
|
|
||||||
int updateScreenDimensions();
|
int updateScreenDimensions();
|
||||||
|
|
||||||
|
Logger * _log;
|
||||||
};
|
};
|
||||||
|
18
libsrc/grabber/amlogic/AmlogicGrabber.cpp
Normal file → Executable file
18
libsrc/grabber/amlogic/AmlogicGrabber.cpp
Normal file → Executable file
@ -3,7 +3,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <utils/Logger.h>
|
||||||
// Linux includes
|
// Linux includes
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -30,7 +30,7 @@ AmlogicGrabber::AmlogicGrabber(const unsigned width, const unsigned height) :
|
|||||||
_height(std::max(160u, height)),
|
_height(std::max(160u, height)),
|
||||||
_amlogicCaptureDev(-1)
|
_amlogicCaptureDev(-1)
|
||||||
{
|
{
|
||||||
std::cout << "AMLOGICGRABBER INFO: [" << __PRETTY_FUNCTION__ << "] constructed(" << _width << "x" << _height << ")" << std::endl;
|
Info(_log, "[%s] constructed(%s x %s)",__PRETTY_FUNCTION__,_width,_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
AmlogicGrabber::~AmlogicGrabber()
|
AmlogicGrabber::~AmlogicGrabber()
|
||||||
@ -39,7 +39,7 @@ AmlogicGrabber::~AmlogicGrabber()
|
|||||||
{
|
{
|
||||||
if (close(_amlogicCaptureDev) == -1)
|
if (close(_amlogicCaptureDev) == -1)
|
||||||
{
|
{
|
||||||
std::cerr << "AMLOGICGRABBER ERROR: [" << __PRETTY_FUNCTION__ << "] Failed to close device (" << errno << ")" << std::endl;
|
Error(_log, "[%s] Failed to close device (%s)",__PRETTY_FUNCTION__,errno);
|
||||||
}
|
}
|
||||||
_amlogicCaptureDev = -1;
|
_amlogicCaptureDev = -1;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ bool AmlogicGrabber::isVideoPlaying()
|
|||||||
int video_fd = open(videoDevice.c_str(), O_RDONLY);
|
int video_fd = open(videoDevice.c_str(), O_RDONLY);
|
||||||
if (video_fd < 0)
|
if (video_fd < 0)
|
||||||
{
|
{
|
||||||
std::cerr << "AMLOGICGRABBER ERROR: Failed to open video device(" << videoDevice << "): " << strerror(errno) << std::endl;
|
Error(_log, "Failed to open video device(%s): %s",videoDevice.c_str(),strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ bool AmlogicGrabber::isVideoPlaying()
|
|||||||
int videoDisabled;
|
int videoDisabled;
|
||||||
if (ioctl(video_fd, AMSTREAM_IOC_GET_VIDEO_DISABLE, &videoDisabled) == -1)
|
if (ioctl(video_fd, AMSTREAM_IOC_GET_VIDEO_DISABLE, &videoDisabled) == -1)
|
||||||
{
|
{
|
||||||
std::cerr << "AMLOGICGRABBER ERROR: Failed to retrieve video state from device: " << strerror(errno) << std::endl;
|
Error(_log, "Failed to retrieve video state from device: %s",strerror(errno));
|
||||||
close(video_fd);
|
close(video_fd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ int AmlogicGrabber::grabFrame(Image<ColorBgr> & image)
|
|||||||
// If the device is still not open, there is something wrong
|
// If the device is still not open, there is something wrong
|
||||||
if (_amlogicCaptureDev == -1)
|
if (_amlogicCaptureDev == -1)
|
||||||
{
|
{
|
||||||
std::cerr << "AMLOGICGRABBER ERROR:[" << __PRETTY_FUNCTION__ << "] Failed to open the AMLOGIC device (" << errno << "): " << strerror(errno) << std::endl;
|
Error(_log,"[%s] Failed to open the AMLOGIC device ():",__PRETTY_FUNCTION__,errno,strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ int AmlogicGrabber::grabFrame(Image<ColorBgr> & image)
|
|||||||
ioctl(_amlogicCaptureDev, AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT, _height) == -1)
|
ioctl(_amlogicCaptureDev, AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT, _height) == -1)
|
||||||
{
|
{
|
||||||
// Failed to configure frame width
|
// Failed to configure frame width
|
||||||
std::cerr << "AMLOGICGRABBER ERROR: [" << __PRETTY_FUNCTION__ << "] Failed to configure capture size (" << errno << "): " << strerror(errno) << std::endl;
|
Error(_log,"[%s] Failed to configure capture size (%s)",__PRETTY_FUNCTION__,errno,strerror(errno));
|
||||||
close(_amlogicCaptureDev);
|
close(_amlogicCaptureDev);
|
||||||
_amlogicCaptureDev = -1;
|
_amlogicCaptureDev = -1;
|
||||||
return -1;
|
return -1;
|
||||||
@ -134,7 +134,7 @@ int AmlogicGrabber::grabFrame(Image<ColorBgr> & image)
|
|||||||
const ssize_t bytesRead = pread(_amlogicCaptureDev, image_ptr, bytesToRead, 0);
|
const ssize_t bytesRead = pread(_amlogicCaptureDev, image_ptr, bytesToRead, 0);
|
||||||
if (bytesRead == -1)
|
if (bytesRead == -1)
|
||||||
{
|
{
|
||||||
std::cerr << "AMLOGICGRABBER ERROR: [" << __PRETTY_FUNCTION__ << "] Read of device failed (erno=" << errno << "): " << strerror(errno) << std::endl;
|
Error(_log,"[%s] Read of device failed (erno=%s): %s",__PRETTY_FUNCTION__,errno,strerror(errno));
|
||||||
close(_amlogicCaptureDev);
|
close(_amlogicCaptureDev);
|
||||||
_amlogicCaptureDev = -1;
|
_amlogicCaptureDev = -1;
|
||||||
return -1;
|
return -1;
|
||||||
@ -142,7 +142,7 @@ int AmlogicGrabber::grabFrame(Image<ColorBgr> & image)
|
|||||||
else if (bytesToRead != bytesRead)
|
else if (bytesToRead != bytesRead)
|
||||||
{
|
{
|
||||||
// Read of snapshot failed
|
// Read of snapshot failed
|
||||||
std::cerr << "AMLOGICGRABBER ERROR: [" << __PRETTY_FUNCTION__ << "] Capture failed to grab entire image [bytesToRead(" << bytesToRead << ") != bytesRead(" << bytesRead << ")]" << std::endl;
|
Error(_log,"[%s] Capture failed to grab entire image [bytesToRead(%s) != bytesRead(%s)]",__PRETTY_FUNCTION__,bytesToRead,bytesRead);
|
||||||
close(_amlogicCaptureDev);
|
close(_amlogicCaptureDev);
|
||||||
_amlogicCaptureDev = -1;
|
_amlogicCaptureDev = -1;
|
||||||
return -1;
|
return -1;
|
||||||
|
14
libsrc/grabber/x11/X11Grabber.cpp
Normal file → Executable file
14
libsrc/grabber/x11/X11Grabber.cpp
Normal file → Executable file
@ -1,6 +1,7 @@
|
|||||||
// STL includes
|
// STL includes
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <utils/Logger.h>
|
||||||
|
|
||||||
// X11Grabber includes
|
// X11Grabber includes
|
||||||
#include <grabber/X11Grabber.h>
|
#include <grabber/X11Grabber.h>
|
||||||
@ -22,7 +23,8 @@ X11Grabber::X11Grabber(bool useXGetImage, int cropLeft, int cropRight, int cropT
|
|||||||
_screenHeight(0),
|
_screenHeight(0),
|
||||||
_croppedWidth(0),
|
_croppedWidth(0),
|
||||||
_croppedHeight(0),
|
_croppedHeight(0),
|
||||||
_image(0,0)
|
_image(0,0),
|
||||||
|
_log(Logger::getInstance("X11GRABBER"))
|
||||||
{
|
{
|
||||||
_imageResampler.setHorizontalPixelDecimation(horizontalPixelDecimation);
|
_imageResampler.setHorizontalPixelDecimation(horizontalPixelDecimation);
|
||||||
_imageResampler.setVerticalPixelDecimation(verticalPixelDecimation);
|
_imageResampler.setVerticalPixelDecimation(verticalPixelDecimation);
|
||||||
@ -94,11 +96,11 @@ bool X11Grabber::Setup()
|
|||||||
_x11Display = XOpenDisplay(NULL);
|
_x11Display = XOpenDisplay(NULL);
|
||||||
if (_x11Display == nullptr)
|
if (_x11Display == nullptr)
|
||||||
{
|
{
|
||||||
std::cerr << "X11GRABBER ERROR: Unable to open display";
|
Error(_log, "Unable to open display");
|
||||||
if (getenv("DISPLAY")) {
|
if (getenv("DISPLAY")) {
|
||||||
std::cerr << " " << std::string(getenv("DISPLAY")) << std::endl;
|
Error(_log, "%s",getenv("DISPLAY"));
|
||||||
} else {
|
} else {
|
||||||
std::cerr << ". DISPLAY environment variable not set" << std::endl;
|
Error(_log, "DISPLAY environment variable not set");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -151,7 +153,7 @@ Image<ColorRgb> & X11Grabber::grab()
|
|||||||
|
|
||||||
if (_xImage == nullptr)
|
if (_xImage == nullptr)
|
||||||
{
|
{
|
||||||
std::cerr << "X11GRABBER ERROR: Grab failed" << std::endl;
|
Error(_log, "Grab Failed!");
|
||||||
return _image;
|
return _image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ int X11Grabber::updateScreenDimensions()
|
|||||||
const Status status = XGetWindowAttributes(_x11Display, _window, &_windowAttr);
|
const Status status = XGetWindowAttributes(_x11Display, _window, &_windowAttr);
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
{
|
{
|
||||||
std::cerr << "X11GRABBER ERROR: Failed to obtain window attributes" << std::endl;
|
Error(_log, "Failed to obtain window attributes");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user