@@ -24,19 +24,6 @@ AmlogicGrabber::AmlogicGrabber(const unsigned width, const unsigned height) :
2424 _height(height),
2525 _amlogicCaptureDev(-1 )
2626{
27- _amlogicCaptureDev = open (" /dev/amvideocap0" , O_RDONLY, 0 );
28- if (_amlogicCaptureDev == -1 )
29- {
30- std::cerr << " [" << __PRETTY_FUNCTION__ << " ] Failed to open the AMLOGIC device (" << errno << " )" << std::endl;
31- return ;
32- }
33-
34- if (ioctl (_amlogicCaptureDev, AMVIDEOCAP_IOW_SET_WANTFRAME_WIDTH, _width) == -1 ||
35- ioctl (_amlogicCaptureDev, AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT, _height) == -1 )
36- {
37- // Failed to configure frame width
38- std::cerr << " [" << __PRETTY_FUNCTION__ << " ] Failed to configure capture size (" << errno << " )" << std::endl;
39- }
4027}
4128
4229AmlogicGrabber::~AmlogicGrabber ()
@@ -70,18 +57,37 @@ void AmlogicGrabber::setVideoMode(const VideoMode videoMode)
7057void AmlogicGrabber::grabFrame (Image<ColorRgb> & image)
7158{
7259 // resize the given image if needed
73- if (image.width () != unsigned (_rectangle. width ) || image.height () != unsigned (_rectangle. height ) )
60+ if (image.width () != _width || image.height () != _height )
7461 {
75- image.resize (_rectangle. width , _rectangle. height );
62+ image.resize (_width, _height );
7663 }
7764
65+ _amlogicCaptureDev = open (" /dev/amvideocap0" , O_RDONLY, 0 );
66+ if (_amlogicCaptureDev == -1 )
67+ {
68+ std::cerr << " [" << __PRETTY_FUNCTION__ << " ] Failed to open the AMLOGIC device (" << errno << " )" << std::endl;
69+ return ;
70+ }
71+
72+ if (ioctl (_amlogicCaptureDev, AMVIDEOCAP_IOW_SET_WANTFRAME_WIDTH, _width) == -1 ||
73+ ioctl (_amlogicCaptureDev, AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT, _height) == -1 )
74+ {
75+ // Failed to configure frame width
76+ std::cerr << " [" << __PRETTY_FUNCTION__ << " ] Failed to configure capture size (" << errno << " )" << std::endl;
77+ return ;
78+ }
79+
80+ std::cout << " AMLOGIC grabber created (size " << _width << " x" << _height << " )" << std::endl;
7881 // Read the snapshot into the memory
7982 void * image_ptr = image.memptr ();
8083 const size_t bytesToRead = _width * _height * sizeof (ColorRgb);
81- const size_t bytesRead = pread (amlogicCaptureDev , image_ptr, bytesToRead, 0 )
84+ const size_t bytesRead = pread (_amlogicCaptureDev , image_ptr, bytesToRead, 0 );
8285 if (bytesToRead != bytesRead)
8386 {
8487 // Read of snapshot failed
8588 std::cerr << " [" << __PRETTY_FUNCTION__ << " ] Capture failed to grab entire image [bytesToRead(" << bytesToRead << " ) != bytesRead(" << bytesRead << " )]" << std::endl;
8689 }
90+
91+ close (_amlogicCaptureDev);
92+ _amlogicCaptureDev = -1 ;
8793}
0 commit comments