mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added framerate decimation
Former-commit-id: 8f7eb09978aef5364cbab1f5dfe12afbf60e6cac
This commit is contained in:
parent
558ad6a11f
commit
421ec6926f
@ -19,13 +19,16 @@
|
||||
|
||||
#define CLEAR(x) memset(&(x), 0, sizeof(x))
|
||||
|
||||
V4L2Grabber::V4L2Grabber(const std::string &device, int input, VideoStandard videoStandard, double fps) :
|
||||
V4L2Grabber::V4L2Grabber(const std::string &device, int input, VideoStandard videoStandard, int frameDecimation, int pixelDecimation) :
|
||||
_deviceName(device),
|
||||
_ioMethod(IO_METHOD_MMAP),
|
||||
_fileDescriptor(-1),
|
||||
_buffers(),
|
||||
_width(0),
|
||||
_height(0)
|
||||
_height(0),
|
||||
_frameDecimation(frameDecimation),
|
||||
_pixelDecimation(pixelDecimation),
|
||||
_currentFrame(0)
|
||||
{
|
||||
open_device();
|
||||
init_device(videoStandard, input);
|
||||
@ -42,23 +45,24 @@ void V4L2Grabber::start()
|
||||
start_capturing();
|
||||
}
|
||||
|
||||
void V4L2Grabber::capture()
|
||||
void V4L2Grabber::capture(int frameCount)
|
||||
{
|
||||
int count = 1;
|
||||
while (count-- > 0) {
|
||||
for (;;) {
|
||||
for (int count = 0; count < frameCount || frameCount < 0; ++count)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
// the set of file descriptors for select
|
||||
fd_set fds;
|
||||
struct timeval tv;
|
||||
int r;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(_fileDescriptor, &fds);
|
||||
|
||||
/* Timeout. */
|
||||
// timeout
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 2;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
r = select(_fileDescriptor + 1, &fds, NULL, NULL, &tv);
|
||||
// block until data is available
|
||||
int r = select(_fileDescriptor + 1, &fds, NULL, NULL, &tv);
|
||||
|
||||
if (-1 == r)
|
||||
{
|
||||
@ -545,6 +549,10 @@ int V4L2Grabber::read_frame()
|
||||
|
||||
void V4L2Grabber::process_image(const void *p, int size)
|
||||
{
|
||||
if (++_currentFrame >= _frameDecimation)
|
||||
{
|
||||
// We do want a new frame...
|
||||
|
||||
if (size != 2*_width*_height)
|
||||
{
|
||||
std::cout << "Frame too small: " << size << " != " << (2*_width*_height) << std::endl;
|
||||
@ -552,6 +560,8 @@ void V4L2Grabber::process_image(const void *p, int size)
|
||||
else
|
||||
{
|
||||
process_image(reinterpret_cast<const uint8_t *>(p));
|
||||
_currentFrame = 0; // restart counting
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,12 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
V4L2Grabber(const std::string & device, int input, VideoStandard videoStandard, double fps);
|
||||
V4L2Grabber(const std::string & device, int input, VideoStandard videoStandard, int frameDecimation, int pixelDecimation);
|
||||
virtual ~V4L2Grabber();
|
||||
|
||||
void start();
|
||||
|
||||
void capture();
|
||||
void capture(int frameCount = -1);
|
||||
|
||||
void stop();
|
||||
|
||||
@ -73,4 +73,8 @@ private:
|
||||
|
||||
int _width;
|
||||
int _height;
|
||||
const int _frameDecimation;
|
||||
const int _pixelDecimation;
|
||||
|
||||
int _currentFrame;
|
||||
};
|
||||
|
@ -40,9 +40,9 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
V4L2Grabber grabber("/dev/video0", 0, V4L2Grabber::PAL, 10.0);
|
||||
V4L2Grabber grabber("/dev/video0", 0, V4L2Grabber::PAL, 25, 8);
|
||||
grabber.start();
|
||||
grabber.capture();
|
||||
grabber.capture(250);
|
||||
grabber.stop();
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user