@@ -24,19 +24,6 @@ AmlogicGrabber::AmlogicGrabber(const unsigned width, const unsigned height) :
24
24
_height(height),
25
25
_amlogicCaptureDev(-1 )
26
26
{
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
- }
40
27
}
41
28
42
29
AmlogicGrabber::~AmlogicGrabber ()
@@ -70,18 +57,37 @@ void AmlogicGrabber::setVideoMode(const VideoMode videoMode)
70
57
void AmlogicGrabber::grabFrame (Image<ColorRgb> & image)
71
58
{
72
59
// 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 )
74
61
{
75
- image.resize (_rectangle. width , _rectangle. height );
62
+ image.resize (_width, _height );
76
63
}
77
64
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;
78
81
// Read the snapshot into the memory
79
82
void * image_ptr = image.memptr ();
80
83
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 );
82
85
if (bytesToRead != bytesRead)
83
86
{
84
87
// Read of snapshot failed
85
88
std::cerr << " [" << __PRETTY_FUNCTION__ << " ] Capture failed to grab entire image [bytesToRead(" << bytesToRead << " ) != bytesRead(" << bytesRead << " )]" << std::endl;
86
89
}
90
+
91
+ close (_amlogicCaptureDev);
92
+ _amlogicCaptureDev = -1 ;
87
93
}
0 commit comments