diff --git a/include/grabber/AmlogicGrabber.h b/include/grabber/AmlogicGrabber.h old mode 100644 new mode 100755 index 05694853..158f91f5 --- a/include/grabber/AmlogicGrabber.h +++ b/include/grabber/AmlogicGrabber.h @@ -2,7 +2,7 @@ // STL includes #include - +#include // Utils includes #include #include @@ -55,4 +55,6 @@ private: /** The snapshot/capture device of the amlogic video chip */ int _amlogicCaptureDev; + + Logger * _log; }; diff --git a/include/grabber/X11Grabber.h b/include/grabber/X11Grabber.h old mode 100644 new mode 100755 index 7715299f..6ac5d220 --- a/include/grabber/X11Grabber.h +++ b/include/grabber/X11Grabber.h @@ -3,7 +3,7 @@ #include #include #include - +#include // X11 includes #include #include @@ -64,4 +64,6 @@ private: void setupResources(); int updateScreenDimensions(); + + Logger * _log; }; diff --git a/libsrc/grabber/amlogic/AmlogicGrabber.cpp b/libsrc/grabber/amlogic/AmlogicGrabber.cpp old mode 100644 new mode 100755 index 11cd2809..5620dde7 --- a/libsrc/grabber/amlogic/AmlogicGrabber.cpp +++ b/libsrc/grabber/amlogic/AmlogicGrabber.cpp @@ -3,7 +3,7 @@ #include #include #include - +#include // Linux includes #include #include @@ -30,7 +30,7 @@ AmlogicGrabber::AmlogicGrabber(const unsigned width, const unsigned height) : _height(std::max(160u, height)), _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() @@ -39,7 +39,7 @@ AmlogicGrabber::~AmlogicGrabber() { 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; } @@ -69,7 +69,7 @@ bool AmlogicGrabber::isVideoPlaying() int video_fd = open(videoDevice.c_str(), O_RDONLY); 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; } @@ -77,7 +77,7 @@ bool AmlogicGrabber::isVideoPlaying() int videoDisabled; 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); return false; } @@ -111,7 +111,7 @@ int AmlogicGrabber::grabFrame(Image & image) // If the device is still not open, there is something wrong 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; } } @@ -121,7 +121,7 @@ int AmlogicGrabber::grabFrame(Image & image) ioctl(_amlogicCaptureDev, AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT, _height) == -1) { // 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); _amlogicCaptureDev = -1; return -1; @@ -134,7 +134,7 @@ int AmlogicGrabber::grabFrame(Image & image) const ssize_t bytesRead = pread(_amlogicCaptureDev, image_ptr, bytesToRead, 0); 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); _amlogicCaptureDev = -1; return -1; @@ -142,7 +142,7 @@ int AmlogicGrabber::grabFrame(Image & image) else if (bytesToRead != bytesRead) { // 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); _amlogicCaptureDev = -1; return -1; diff --git a/libsrc/grabber/x11/X11Grabber.cpp b/libsrc/grabber/x11/X11Grabber.cpp old mode 100644 new mode 100755 index 9aa56232..6e382fa5 --- a/libsrc/grabber/x11/X11Grabber.cpp +++ b/libsrc/grabber/x11/X11Grabber.cpp @@ -1,6 +1,7 @@ // STL includes #include #include +#include // X11Grabber includes #include @@ -22,7 +23,8 @@ X11Grabber::X11Grabber(bool useXGetImage, int cropLeft, int cropRight, int cropT _screenHeight(0), _croppedWidth(0), _croppedHeight(0), - _image(0,0) + _image(0,0), + _log(Logger::getInstance("X11GRABBER")) { _imageResampler.setHorizontalPixelDecimation(horizontalPixelDecimation); _imageResampler.setVerticalPixelDecimation(verticalPixelDecimation); @@ -94,11 +96,11 @@ bool X11Grabber::Setup() _x11Display = XOpenDisplay(NULL); if (_x11Display == nullptr) { - std::cerr << "X11GRABBER ERROR: Unable to open display"; + Error(_log, "Unable to open display"); if (getenv("DISPLAY")) { - std::cerr << " " << std::string(getenv("DISPLAY")) << std::endl; + Error(_log, "%s",getenv("DISPLAY")); } else { - std::cerr << ". DISPLAY environment variable not set" << std::endl; + Error(_log, "DISPLAY environment variable not set"); } return false; } @@ -151,7 +153,7 @@ Image & X11Grabber::grab() if (_xImage == nullptr) { - std::cerr << "X11GRABBER ERROR: Grab failed" << std::endl; + Error(_log, "Grab Failed!"); return _image; } @@ -165,7 +167,7 @@ int X11Grabber::updateScreenDimensions() const Status status = XGetWindowAttributes(_x11Display, _window, &_windowAttr); if (status == 0) { - std::cerr << "X11GRABBER ERROR: Failed to obtain window attributes" << std::endl; + Error(_log, "Failed to obtain window attributes"); return -1; }