use log4cpp instead of printf

This commit is contained in:
Michel Promonet 2015-03-14 16:47:23 +01:00
parent 4a7cc43d5f
commit ff3b345c77

View File

@ -18,6 +18,7 @@
#include <libv4l2.h>
// project
#include "logger.h"
#include "V4l2DeviceSource.h"
// ---------------------------------
@ -29,10 +30,7 @@ int V4L2DeviceSource::Stats::notify(int tv_sec, int framesize, int verbose)
m_size+=framesize;
if (tv_sec != m_fps_sec)
{
if (verbose >= 1)
{
std::cout << m_msg << "tv_sec:" << tv_sec << " fps:" << m_fps << " bandwidth:"<< (m_size/128) << "kbps\n";
}
LOG(INFO) << m_msg << "tv_sec:" << tv_sec << " fps:" << m_fps << " bandwidth:"<< (m_size/128) << "kbps\n";
m_fps_sec = tv_sec;
m_fps = 0;
m_size = 0;
@ -94,7 +92,7 @@ void* V4L2DeviceSource::thread()
FD_ZERO(&fdset);
timeval tv;
envir() << "begin thread\n";
LOG(NOTICE) << "begin thread\n";
while (!stop)
{
FD_SET(m_device->getFd(), &fdset);
@ -107,18 +105,18 @@ void* V4L2DeviceSource::thread()
{
if (this->getNextFrame() <= 0)
{
envir() << "error:" << strerror(errno) << "\n";
LOG(ERROR) << "error:" << strerror(errno) << "\n";
stop=1;
}
}
}
else if (ret == -1)
{
envir() << "stop " << strerror(errno) << "\n";
LOG(ERROR) << "stop " << strerror(errno) << "\n";
stop=1;
}
}
envir() << "end thread\n";
LOG(NOTICE) << "end thread\n";
return NULL;
}
@ -134,7 +132,7 @@ void V4L2DeviceSource::doGetNextFrame()
// stopping FrameSource callback
void V4L2DeviceSource::doStopGettingFrames()
{
envir() << "V4L2DeviceSource::doStopGettingFrames\n";
LOG(NOTICE) << "V4L2DeviceSource::doStopGettingFrames\n";
FramedSource::doStopGettingFrames();
}
@ -148,7 +146,7 @@ void V4L2DeviceSource::deliverFrame()
if (m_captureQueue.empty())
{
if (m_verbose >= 2) envir() << "Queue is empty \n";
LOG(DEBUG) << "Queue is empty \n";
}
else
{
@ -169,10 +167,7 @@ void V4L2DeviceSource::deliverFrame()
timeval diff;
timersub(&fPresentationTime,&(frame->m_timestamp),&diff);
if (m_verbose >= 2)
{
printf ("deliverFrame\ttimestamp:%ld.%06ld\tsize:%d diff:%d ms queue:%d\n",fPresentationTime.tv_sec, fPresentationTime.tv_usec, fFrameSize, (int)(diff.tv_sec*1000+diff.tv_usec/1000), m_captureQueue.size());
}
LOG(DEBUG) << "deliverFrame\ttimestamp:" << fPresentationTime.tv_sec << "." << fPresentationTime.tv_usec << "\tsize:" << fFrameSize <<"\tdiff" << (diff.tv_sec*1000+diff.tv_usec/1000) << "ms\tqueue:" << m_captureQueue.size();
memcpy(fTo, frame->m_buffer, fFrameSize);
delete frame;
@ -193,12 +188,12 @@ int V4L2DeviceSource::getNextFrame()
if (frameSize < 0)
{
envir() << "V4L2DeviceSource::getNextFrame errno:" << errno << " " << strerror(errno) << "\n";
LOG(NOTICE) << "V4L2DeviceSource::getNextFrame errno:" << errno << " " << strerror(errno) << "\n";
handleClosure(this);
}
else if (frameSize == 0)
{
envir() << "V4L2DeviceSource::getNextFrame no data errno:" << errno << " " << strerror(errno) << "\n";
LOG(NOTICE) << "V4L2DeviceSource::getNextFrame no data errno:" << errno << " " << strerror(errno) << "\n";
handleClosure(this);
}
else
@ -208,10 +203,7 @@ int V4L2DeviceSource::getNextFrame()
timeval diff;
timersub(&tv,&ref,&diff);
m_in.notify(tv.tv_sec, frameSize, m_verbose);
if (m_verbose >=2)
{
printf ("getNextFrame\ttimestamp:%ld.%06ld\tsize:%d diff:%d ms queue:%d\n", ref.tv_sec, ref.tv_usec, frameSize, (int)(diff.tv_sec*1000+diff.tv_usec/1000), m_captureQueue.size());
}
LOG(DEBUG) << "getNextFrame\ttimestamp:" << ref.tv_sec << "." << ref.tv_usec << "\tsize:" << frameSize <<"\tdiff" << (diff.tv_sec*1000+diff.tv_usec/1000) << "ms\tqueue:" << m_captureQueue.size();
processFrame(buffer,frameSize,ref);
}
return frameSize;
@ -234,13 +226,9 @@ void V4L2DeviceSource::processFrame(char * frame, int frameSize, const timeval &
memcpy(buf, frame.first, size);
queueFrame(buf,size,ref);
if (m_verbose >=2)
{
printf ("queueFrame\ttimestamp:%ld.%06ld\tsize:%d diff:%d ms queue:%d data:%02X%02X%02X%02X%02X...\n", ref.tv_sec, ref.tv_usec, size, (int)(diff.tv_sec*1000+diff.tv_usec/1000), m_captureQueue.size(), buf[0], buf[1], buf[2], buf[3], buf[4]);
}
LOG(DEBUG) << "queueFrame\ttimestamp:" << ref.tv_sec << "." << ref.tv_usec << "\tsize:" << frameSize <<"\tdiff" << (diff.tv_sec*1000+diff.tv_usec/1000) << "ms\tqueue:" << m_captureQueue.size();
if (m_outfd != -1) write(m_outfd, buf, size);
frameList.pop_front();
}
}
@ -250,10 +238,7 @@ void V4L2DeviceSource::queueFrame(char * frame, int frameSize, const timeval &tv
{
while (m_captureQueue.size() >= m_queueSize)
{
if (m_verbose >=2)
{
envir() << "Queue full size drop frame size:" << (int)m_captureQueue.size() << " \n";
}
LOG(DEBUG) << "Queue full size drop frame size:" << (int)m_captureQueue.size() << " \n";
delete m_captureQueue.front();
m_captureQueue.pop_front();
}