30#define ISP_META_WIDTH 272
31#define ISP_META_HEIGHT 1
39#ifdef JEVOIS_PLATFORM_A33
47#ifdef JEVOIS_PLATFORM_PRO
56 while (itsDev.empty() ==
false) itsDev.pop_back();
59 unsigned int capw = m.
cw, caph = m.
ch;
int preset = -1;
61 std::string pstr;
if (preset != -1) pstr =
" [preset " + std::to_string(preset) +
']';
62 LINFO(itsSensor <<
": using native video capture size " << capw <<
'x' << caph << pstr <<
" + crop/resize as needed");
67 case jevois::CropType::Scale:
71 if (capw != m.
cw || caph != m.
ch)
73 LINFO(
"Capture: " << capw <<
'x' << caph <<
", rescale to " << m.
cw <<
'x' << m.
ch);
76 itsDev.push_back(std::make_shared<jevois::CameraDevice>(itsDevName, 2,
true));
77 itsDev.back()->setFormat(m.
cfmt, capw, caph, m.
cfps, m.
cw, m.
ch, preset);
79 itsDev.push_back(std::make_shared<jevois::CameraDevice>(itsDevName, 2,
true));
83 itsDev.push_back(std::make_shared<jevois::CameraDevice>(itsDevName, itsNbufs,
false));
84 itsDev.back()->setFormat(m.
cfmt, m.
cw, m.
ch, 0.0F, m.
cw, m.
ch);
86 itsFd = itsDev.back()->getFd(); itsDevIdx = itsDev.size() - 1;
87 itsFd2 = -1; itsDev2Idx = -1;
93 case jevois::CropType::Crop:
95 if (capw == m.
cw && caph == m.
ch)
LINFO(
"Capture: " << capw <<
'x' << caph);
96 else LINFO(
"Capture: " << capw <<
'x' << caph <<
", crop to " << m.
cw <<
'x' << m.
ch);
99 itsDev.push_back(std::make_shared<jevois::CameraDevice>(itsDevName, itsNbufs,
false));
100 itsDev.back()->setFormat(m.
cfmt, capw, caph, m.
cfps, m.
cw, m.
ch, preset);
102 itsFd = itsDev.back()->getFd(); itsDevIdx = itsDev.size() - 1;
103 itsFd2 = -1; itsDev2Idx = -1;
107 case jevois::CropType::CropScale:
109 LINFO(
"Capture: " << capw <<
'x' << caph <<
", plus ISP scaled to " << m.
c2w <<
'x' << m.
c2h);
112 itsDev.push_back(std::make_shared<jevois::CameraDevice>(itsDevName, 2,
false));
113 itsDev.back()->setFormat(m.
cfmt, capw, caph, m.
cfps, m.
cw, m.
ch, preset);
115 itsDev.push_back(std::make_shared<jevois::CameraDevice>(itsDevName, 2,
true));
119 itsDev.push_back(std::make_shared<jevois::CameraDevice>(itsDevName, itsNbufs,
false));
122 itsFd = itsDev.front()->getFd(); itsDevIdx = 0;
123 itsFd2 = itsDev.back()->getFd(); itsDev2Idx = itsDev.size() - 1;
127 default:
LFATAL(
"Invalid crop type: " <<
int(m.
crop));
140 while (itsDev.empty() ==
false) itsDev.pop_back();
143 itsDev.push_back(std::make_shared<jevois::CameraDevice>(itsDevName, itsNbufs,
false));
145 itsFd = itsDev.back()->getFd(); itsDevIdx = itsDev.size() - 1;
146 itsFd2 = -1; itsDev2Idx = -1;
194 if (itsDevIdx == -1)
LFATAL(
"Need to call setFormat() first");
195 itsDev[itsDevIdx]->get(img);
201 return (itsDev2Idx != -1);
210 if (itsDev2Idx == -1)
LFATAL(
"No JeVois Pro Platform ISP-scaled image available");
211 itsDev[itsDev2Idx]->get(img);
219 if (itsDevIdx == -1)
LFATAL(
"Need to call setFormat() first");
220 itsDev[itsDevIdx]->done(img);
228 if (itsDev2Idx == -1)
LFATAL(
"No JeVois Pro Platform ISP-scaled image available");
229 itsDev[itsDev2Idx]->done(img);
236 if (itsFd == -1)
LFATAL(
"Not initialized");
244 if (itsFd == -1)
LFATAL(
"Not initialized");
252 if (itsFd == -1)
LFATAL(
"Not initialized");
253#ifdef JEVOIS_PLATFORM_A33
264 if (itsFd == -1)
LFATAL(
"Not initialized");
265#ifdef JEVOIS_PLATFORM_A33
276 if (itsFd == -1)
LFATAL(
"Not initialized");
279 std::ofstream ofs(
"/sys/devices/platform/sensor/sreg");
282 unsigned short data[2] = { reg, val };
283 LDEBUG(
"Writing 0x" << std::hex << val <<
" to 0x" << reg);
284 XIOCTL(itsFd, _IOW(
'V', 192,
int), data);
292 if (itsFd == -1)
LFATAL(
"Not initialized");
295 std::ofstream ofs(
"/sys/devices/platform/sensor/sreg");
298 std::ifstream ifs(
"/sys/devices/platform/sensor/sreg");
299 unsigned short val; ifs >> std::hex >> val;
302 unsigned short data[2] = { reg, 0 };
303 XIOCTL(itsFd, _IOWR(
'V', 193,
int), data);
304 LDEBUG(
"Register 0x" << std::hex << reg <<
" has value 0x" << data[1]);
313 if (itsFd == -1)
LFATAL(
"Not initialized");
326 int fd = open(itsDevName.c_str(), O_RDWR | O_NONBLOCK, 0);
330 try {
XIOCTL(fd, _IOWR(
'V', 198,
int), &data); }
#define ISP_V4L2_PIX_FMT_META
Metadata V4L2 format used by Amlogic A311D camera ISP.
void abortStream() override
Abort streaming.
unsigned short readRegister(unsigned short reg)
Read a value from one of the camera's registers.
void getControl(struct v4l2_control &ctrl) const
Get a control's current value, throw if unsupported by hardware.
~Camera()
Close the device and free all resources.
void setFormat(VideoMapping const &m) override
Set the video format and frame rate.
void get(RawImage &img) override
Get the next captured buffer.
Camera(std::string const &devname, jevois::CameraSensor s=jevois::CameraSensor::any, unsigned int const nbufs=0)
Construct and open the device.
void done2(RawImage &img) override
Indicate that user processing is done with an image previously obtained via get2()
bool hasScaledImage() const override
Check whether a second input image scaled by the JeVoisPro Platform ISP is available.
void get2(RawImage &img) override
Get the next captured buffer, for second ISP-scaled image.
void unlock()
Unlock the camera that was previously locked by lock()
void streamOn() override
Start streaming.
void setControl(struct v4l2_control const &ctrl) override
Set a control, throw if control not supported or the hardware rejects the value.
Flags readFlags()
Get the sensor flags.
void queryMenu(struct v4l2_querymenu &qm) const override
Get the available menu entry names for a menu-type control, throw if unsupported by hardware.
int lock()
Lock the camera and return its file descriptor.
void queryControl(struct v4l2_queryctrl &qc) const override
Get information about a control, throw if unsupported by hardware.
void streamOff() override
Stop streaming.
void done(RawImage &img) override
Indicate that user processing is done with an image previously obtained via get()
void writeRegister(unsigned short reg, unsigned short val)
Write a value to one of the camera's registers.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
void sensorPrepareSetFormat(CameraSensor s, VideoMapping const &m, unsigned int &capw, unsigned int &caph, int &preset)
Load a sensor preset (JeVois-Pro only) and return native sensor grab dims (when cropping and/or scali...
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
#define LDEBUG(msg)
Convenience macro for users to print out console or syslog messages, DEBUG level.
#define JEVOIS_TIMED_LOCK(mtx)
Helper macro to create a timed_lock_guard object.
std::string warnAndIgnoreException(std::string const &prefix="")
Convenience function to catch an exception, issue some LERROR (depending on type),...
#define JEVOIS_TRACE(level)
Trace object.
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level.
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
#define XIOCTL_QUIET(dev, req, mem)
Helper macro to execute an ioctl, ignore interruptions, and, if error throw quietly.
std::string sformat(char const *fmt,...) __attribute__((format(__printf__
Create a string using printf style arguments.
#define XIOCTL(dev, req, mem)
Helper macro to execute an ioctl, ignore interruptions, and, if error, issue a fatal message and thro...
Main namespace for all JeVois classes and functions.
Simple struct to hold video mapping definitions for the processing Engine.
unsigned int cfmt
camera pixel format
unsigned int c2fmt
When crop is CropScale, pixel format of the scaled images, otherwise 0.
unsigned int c2w
When crop is CropScale, width of the scaled images, otherwise 0.
CropType crop
Type of crop/scale to apply if camera size does not match sensor native.
float cfps
camera frame rate in frames/sec
unsigned int cw
camera width
unsigned int c2h
When crop is CropScale, height of the scaled images, otherwise 0.
unsigned int ch
camera height