Fixed json value lookup

Only close the amlogic device every 20th succesfull reads.


Former-commit-id: 46c0cf1465b8c8b33d696bb2aeac5cabb1cb2819
This commit is contained in:
T.van der Zwan 2015-09-03 21:37:49 +02:00
parent a3db06e90e
commit ad876b0d8c
2 changed files with 16 additions and 5 deletions

View File

@ -122,6 +122,8 @@ int AmlogicGrabber::grabFrame(Image<ColorBgr> & image)
{
// Failed to configure frame width
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Failed to configure capture size (" << errno << "): " << strerror(errno) << std::endl;
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
return -1;
}
@ -133,18 +135,27 @@ int AmlogicGrabber::grabFrame(Image<ColorBgr> & image)
if (bytesRead == -1)
{
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Read of device failed (erno=" << errno << "): " << strerror(errno) << std::endl;
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
return -1;
}
else if (bytesToRead != bytesRead)
{
// Read of snapshot failed
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Capture failed to grab entire image [bytesToRead(" << bytesToRead << ") != bytesRead(" << bytesRead << ")]" << std::endl;
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
return -1;
}
// For now we always close the device again
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
// For now we always close the device now and again
static int readCnt = 0;
++readCnt;
if (readCnt > 20)
{
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
readCnt = 0;
}
return 0;
}

View File

@ -274,7 +274,7 @@ int main(int argc, char** argv)
FramebufferWrapper * fbGrabber = nullptr;
if (config.isMember("framebuffergrabber") || config.isMember("framegrabber"))
{
const Json::Value & grabberConfig = config.isMember("framebuffergrabber")? config["framebuffergrabber"] : config.isMember("framegrabber");
const Json::Value & grabberConfig = config.isMember("framebuffergrabber")? config["framebuffergrabber"] : config["framegrabber"];
fbGrabber = new FramebufferWrapper(
grabberConfig.get("device", "/dev/fb0").asString(),
grabberConfig["width"].asUInt(),