Commit 174208b5 authored by Laurent Claustre's avatar Laurent Claustre

Enfin, pure video for v4l2, but still some bugs to be discovered

parent 044ea27f
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// Copyright (C) : 2009-2015
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
......@@ -27,12 +27,12 @@ namespace lima
{
namespace V4L2
{
class Camera;
class VideoCtrlObj;
class DetInfoCtrlObj : public HwDetInfoCtrlObj
{
DEB_CLASS_NAMESPC(DebModCamera, "DetInfoCtrlObj", "V4L2");
public:
DetInfoCtrlObj(int fd);
DetInfoCtrlObj(VideoCtrlObj& video);
virtual ~DetInfoCtrlObj();
virtual void getMaxImageSize(Size& max_image_size);
......@@ -49,15 +49,9 @@ namespace lima
virtual void registerMaxImageSizeCallback(HwMaxImageSizeCallback& cb);
virtual void unregisterMaxImageSizeCallback(HwMaxImageSizeCallback& cb);
void getAvailableFormat(std::list<int>& formats) const {formats = m_available_format;}
private:
void _maxImageSize(Size&);
void _getCurrentImageType(ImageType&);
HwMaxImageSizeCallbackGen m_mis_cb_gen;
int m_fd;
std::list<int> m_available_format;
std::string m_det_model;
VideoCtrlObj& m_video;
};
}
}
......
......@@ -30,7 +30,7 @@ namespace lima
{
class DetInfoCtrlObj;
class SyncCtrlObj;
class Camera;
class VideoCtrlObj;
class Interface : public HwInterface
{
DEB_CLASS_NAMESPC(DebModCamera, "Interface", "V4L2");
......@@ -48,16 +48,11 @@ namespace lima
virtual int getNbHwAcquiredFrames();
private:
class _Callback;
friend class _Callback;
int m_fd;
DetInfoCtrlObj* m_det_info;
SyncCtrlObj* m_sync;
Camera* m_cam;
_Callback* m_cbk;
CapList m_cap_list;
SoftBufferCtrlObj m_buffer_ctrl_obj;
CapList m_cap_list;
VideoCtrlObj* m_video;
};
}
}
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// Copyright (C) : 2009-2015
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
......@@ -28,12 +28,12 @@ namespace lima
{
namespace V4L2
{
class VideoCtrlObj;
class SyncCtrlObj : public HwSyncCtrlObj
{
friend class Interface;
DEB_CLASS_NAMESPC(DebModCamera, "SyncCtrlObj", "V4L2");
public:
SyncCtrlObj(Camera& cam);
SyncCtrlObj(VideoCtrlObj& video);
virtual ~SyncCtrlObj();
virtual bool checkTrigMode(TrigMode trig_mode);
......@@ -53,7 +53,7 @@ namespace lima
virtual void getValidRanges(ValidRangesType& valid_ranges);
private:
Camera& m_cam;
VideoCtrlObj& m_video;
int m_nb_frames;
};
}
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// Copyright (C) : 2009-2015
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
......@@ -22,6 +22,12 @@
#ifndef V4L2VIDEOCTRLOBJ_H
#define V4L2VIDEOCTRLOBJ_H
#include "lima/HwVideoCtrlObj.h"
#include "lima/HwInterface.h"
#include "lima/Debug.h"
#include "lima/SizeUtils.h"
#include "lima/Constants.h"
#include <linux/videodev2.h>
#include <libv4l2.h>
namespace lima
{
......@@ -32,9 +38,10 @@ namespace lima
{
DEB_CLASS_NAMESPC(DebModCamera,"VideoCtrlObj","V4L2");
public:
VideoCtrlObj(int fd,DetInfoCtrlObj&);
VideoCtrlObj(int fd);
virtual ~VideoCtrlObj();
// Video interface
virtual void getSupportedVideoMode(std::list<VideoMode>& list) const;
virtual void setVideoMode(VideoMode);
virtual void getVideoMode(VideoMode&) const;
......@@ -50,16 +57,52 @@ namespace lima
virtual void checkBin(Bin& bin);
virtual void checkRoi(const Roi& set_roi,Roi& hw_roi);
virtual void setBin(const Bin&);
virtual void setRoi(const Roi&);
virtual void setBin(const Bin&){};
virtual void setRoi(const Roi&){};
// --- Detector Info
void getMaxImageSize(Size&);
void getCurrImageType(ImageType&);
void setCurrImageType(ImageType);
private:
int m_fd;
DetInfoCtrlObj& m_det_info;
void getDetectorModel(std::string& det_model);
// --- Syn Obj
void getMinMaxExpTime(double& min,double& max);
void setExpTime(double exp_time);
void getExpTime(double& exp_time);
Cond m_cond;
bool m_acq_started;
int m_pipes[2];
void setNbHwFrames(int nb_frames);
void getNbHwFrames(int& nb_frames);
// --- Acquisition interface
void reset(HwInterface::ResetLevel reset_level);
void prepareAcq();
void startAcq();
void stopAcq();
void getStatus(HwInterface::StatusType& status);
int getNbHwAcquiredFrames();
int getV4l2Fd() { return m_fd; }
private:
class _AcqThread;
friend class _AcqThread;
std::string m_det_model;
int m_fd;
struct v4l2_buffer m_buffer;
unsigned char* m_buffers[2];
int m_nb_frames;
int m_acq_frame_id;
bool m_acq_started;
bool m_acq_thread_run;
std::list<int> m_available_format;
_AcqThread* m_acq_thread;
int m_pipes[2];
bool m_quit;
Cond m_cond;
bool m_live;
double m_gain;
};
}
}
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
namespace V4L2
{
class Camera
{
%TypeHeaderCode
#include <V4L2Camera.h>
%End
public:
class Callback
{
public:
virtual bool newFrame(int frame_id,const unsigned char*) = 0;
};
Camera(Callback*,const char* video_device = "/dev/video0");
~Camera();
// --- Detector Info
void getMaxImageSize(Size& /Out/);
void getCurrImageType(ImageType& /Out/);
void setCurrImageType(ImageType);
void getDetectorModel(std::string& det_model /Out/);
// --- Syn Obj
void getMinMaxExpTime(double& min /Out/,double& max /Out/);
void setExpTime(double exp_time);
void getExpTime(double& exp_time /out/);
void setNbHwFrames(int nb_frames);
void getNbHwFrames(int& nb_frames /Out/);
// --- Acquisition interface
void reset(HwInterface::ResetLevel reset_level);
void prepareAcq();
void startAcq();
void stopAcq();
void getStatus(HwInterface::StatusType& status /Out/);
int getNbHwAcquiredFrames();
};
};
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// Copyright (C) : 2009-2015
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
......
v4l2-objs = V4L2DetInfoCtrlObj.o V4L2SyncCtrlObj.o V4L2Interface.o V4L2Camera.o
v4l2-objs = V4L2DetInfoCtrlObj.o V4L2SyncCtrlObj.o V4L2Interface.o V4L2VideoCtrlObj.o
SRCS = $(v4l2-objs:.o=.cpp)
......@@ -25,8 +25,3 @@ check-syntax:
rm -f $*.d
-include $(SRCS:.cpp=.P)
.PHONY: check-syntax
check-syntax:
$(CXX) -Wall -Wextra -fsyntax-only $(CXXFLAGS) $(CHK_SOURCES)
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// Copyright (C) : 2009-2015
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
......@@ -21,121 +21,14 @@
//###########################################################################
#include <errno.h>
#include "V4L2DetInfoCtrlObj.h"
#include "V4L2Interface.h"
#include "V4L2Camera.h"
#include "V4L2VideoCtrlObj.h"
using namespace lima;
using namespace lima::V4L2;
DetInfoCtrlObj::DetInfoCtrlObj(int fd) : m_fd(fd)
DetInfoCtrlObj::DetInfoCtrlObj(VideoCtrlObj& video) : m_video(video)
{
DEB_CONSTRUCTOR();
struct v4l2_capability cap;
int ret = v4l2_ioctl(m_fd, VIDIOC_QUERYCAP, &cap);
if(ret == -1)
THROW_HW_ERROR(Error) << "Error querying cap: " << strerror(errno);
DEB_TRACE() << DEB_VAR1(cap.driver) << ","
<< DEB_VAR1(cap.card) << ","
<< DEB_VAR1(cap.bus_info);
m_det_model = (char*)cap.card;
if(!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
THROW_HW_ERROR(Error) << "Error: dev. doesn't have VIDEO_CAPTURE cap.";
struct v4l2_fmtdesc formatdesc;
formatdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
for(formatdesc.index = 0;v4l2_ioctl(m_fd, VIDIOC_ENUM_FMT, &formatdesc) != -1;
++formatdesc.index)
{
m_available_format.push_back(formatdesc.pixelformat);
switch(formatdesc.pixelformat)
{
/* RGB formats */
case V4L2_PIX_FMT_RGB332: DEB_TRACE() << "As V4L2_PIX_FMT_RGB332";break;
case V4L2_PIX_FMT_RGB444: DEB_TRACE() << "As V4L2_PIX_FMT_RGB444";break;
case V4L2_PIX_FMT_RGB555: DEB_TRACE() << "As V4L2_PIX_FMT_RGB555";break;
case V4L2_PIX_FMT_RGB565: DEB_TRACE() << "As V4L2_PIX_FMT_RGB565";break;
case V4L2_PIX_FMT_RGB555X: DEB_TRACE() << "As V4L2_PIX_FMT_RGB555X";break;
case V4L2_PIX_FMT_RGB565X: DEB_TRACE() << "As V4L2_PIX_FMT_RGB565X";break;
case V4L2_PIX_FMT_BGR24: DEB_TRACE() << "As V4L2_PIX_FMT_BGR24";break;
case V4L2_PIX_FMT_RGB24: DEB_TRACE() << "As V4L2_PIX_FMT_RGB24";break;
case V4L2_PIX_FMT_BGR32: DEB_TRACE() << "As V4L2_PIX_FMT_BGR32";break;
case V4L2_PIX_FMT_RGB32: DEB_TRACE() << "As V4L2_PIX_FMT_RGB32";break;
/* Grey formats */
case V4L2_PIX_FMT_GREY: DEB_TRACE() << "As V4L2_PIX_FMT_GREY";break;
case V4L2_PIX_FMT_Y16: DEB_TRACE() << "As V4L2_PIX_FMT_Y16";break;
/* Palette formats */
case V4L2_PIX_FMT_PAL8: DEB_TRACE() << "As V4L2_PIX_FMT_PAL8";break;
/* Luminance+Chrominance formats */
case V4L2_PIX_FMT_YVU410: DEB_TRACE() << "As V4L2_PIX_FMT_YVU410";break;
case V4L2_PIX_FMT_YVU420: DEB_TRACE() << "As V4L2_PIX_FMT_YVU420";break;
case V4L2_PIX_FMT_YUYV: DEB_TRACE() << "As V4L2_PIX_FMT_YUYV";break;
case V4L2_PIX_FMT_YYUV: DEB_TRACE() << "As V4L2_PIX_FMT_YYUV";break;
case V4L2_PIX_FMT_YVYU: DEB_TRACE() << "As V4L2_PIX_FMT_YVYU";break;
case V4L2_PIX_FMT_UYVY: DEB_TRACE() << "As V4L2_PIX_FMT_UYVY";break;
case V4L2_PIX_FMT_VYUY: DEB_TRACE() << "As V4L2_PIX_FMT_VYUY";break;
case V4L2_PIX_FMT_YUV422P: DEB_TRACE() << "As V4L2_PIX_FMT_YUV422P";break;
case V4L2_PIX_FMT_YUV411P: DEB_TRACE() << "As V4L2_PIX_FMT_YUV411P";break;
case V4L2_PIX_FMT_Y41P: DEB_TRACE() << "As V4L2_PIX_FMT_Y41P";break;
case V4L2_PIX_FMT_YUV444: DEB_TRACE() << "As V4L2_PIX_FMT_YUV444";break;
case V4L2_PIX_FMT_YUV555: DEB_TRACE() << "As V4L2_PIX_FMT_YUV555";break;
case V4L2_PIX_FMT_YUV565: DEB_TRACE() << "As V4L2_PIX_FMT_YUV565";break;
case V4L2_PIX_FMT_YUV32: DEB_TRACE() << "As V4L2_PIX_FMT_YUV32";break;
case V4L2_PIX_FMT_YUV410: DEB_TRACE() << "As V4L2_PIX_FMT_YUV410";break;
case V4L2_PIX_FMT_YUV420: DEB_TRACE() << "As V4L2_PIX_FMT_YUV420";break;
case V4L2_PIX_FMT_HI240: DEB_TRACE() << "As V4L2_PIX_FMT_HI240";break;
case V4L2_PIX_FMT_HM12: DEB_TRACE() << "As V4L2_PIX_FMT_HM12";break;
/* two planes -- one Y, one Cr + Cb interleaved */
case V4L2_PIX_FMT_NV12: DEB_TRACE() << "As V4L2_PIX_FMT_NV12";break;
case V4L2_PIX_FMT_NV21: DEB_TRACE() << "As V4L2_PIX_FMT_NV21";break;
case V4L2_PIX_FMT_NV16: DEB_TRACE() << "As V4L2_PIX_FMT_NV16";break;
case V4L2_PIX_FMT_NV61: DEB_TRACE() << "As V4L2_PIX_FMT_NV61";break;
/* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
case V4L2_PIX_FMT_SBGGR8: DEB_TRACE() << "As V4L2_PIX_FMT_SBGGR8";break;
case V4L2_PIX_FMT_SGBRG8: DEB_TRACE() << "As V4L2_PIX_FMT_SGBRG8";break;
case V4L2_PIX_FMT_SGRBG8: DEB_TRACE() << "As V4L2_PIX_FMT_SGRBG8";break;
case V4L2_PIX_FMT_SGRBG10: DEB_TRACE() << "As V4L2_PIX_FMT_SGRBG10";break;
/* 10bit raw bayer DPCM compressed to 8 bits */
case V4L2_PIX_FMT_SGRBG10DPCM8: DEB_TRACE() << "As V4L2_PIX_FMT_SGRBG10DPCM8";break;
/*
* 10bit raw bayer, expanded to 16 bits
* xxxxrrrrrrrrrrxxxxgggggggggg xxxxggggggggggxxxxbbbbbbbbbb...
*/
case V4L2_PIX_FMT_SBGGR16: DEB_TRACE() << "As V4L2_PIX_FMT_SBGGR16";break;
/* compressed formats */
case V4L2_PIX_FMT_MJPEG: DEB_TRACE() << "As V4L2_PIX_FMT_MJPEG";break;
case V4L2_PIX_FMT_JPEG: DEB_TRACE() << "As V4L2_PIX_FMT_JPEG";break;
case V4L2_PIX_FMT_DV: DEB_TRACE() << "As V4L2_PIX_FMT_DV";break;
case V4L2_PIX_FMT_MPEG: DEB_TRACE() << "As V4L2_PIX_FMT_MPEG";break;
/* Vendor-specific formats */
case V4L2_PIX_FMT_WNVA: DEB_TRACE() << "As V4L2_PIX_FMT_WNVA";break;
case V4L2_PIX_FMT_SN9C10X: DEB_TRACE() << "As V4L2_PIX_FMT_SN9C10X";break;
case V4L2_PIX_FMT_SN9C20X_I420: DEB_TRACE() << "As V4L2_PIX_FMT_SN9C20X_I420";break;
case V4L2_PIX_FMT_PWC1: DEB_TRACE() << "As V4L2_PIX_FMT_PWC1";break;
case V4L2_PIX_FMT_PWC2: DEB_TRACE() << "As V4L2_PIX_FMT_PWC2";break;
case V4L2_PIX_FMT_ET61X251: DEB_TRACE() << "As V4L2_PIX_FMT_ET61X251";break;
case V4L2_PIX_FMT_SPCA501: DEB_TRACE() << "As V4L2_PIX_FMT_SPCA501";break;
case V4L2_PIX_FMT_SPCA505: DEB_TRACE() << "As V4L2_PIX_FMT_SPCA505";break;
case V4L2_PIX_FMT_SPCA508: DEB_TRACE() << "As V4L2_PIX_FMT_SPCA508";break;
case V4L2_PIX_FMT_SPCA561: DEB_TRACE() << "As V4L2_PIX_FMT_SPCA561";break;
case V4L2_PIX_FMT_PAC207: DEB_TRACE() << "As V4L2_PIX_FMT_PAC207";break;
case V4L2_PIX_FMT_MR97310A: DEB_TRACE() << "As V4L2_PIX_FMT_MR97310A";break;
case V4L2_PIX_FMT_SQ905C: DEB_TRACE() << "As V4L2_PIX_FMT_SQ905C";break;
case V4L2_PIX_FMT_PJPG: DEB_TRACE() << "As V4L2_PIX_FMT_PJPG";break;
case V4L2_PIX_FMT_OV511: DEB_TRACE() << "As V4L2_PIX_FMT_OV511";break;
case V4L2_PIX_FMT_OV518: DEB_TRACE() << "As V4L2_PIX_FMT_OV518";break;
}
}
}
DetInfoCtrlObj::~DetInfoCtrlObj()
......@@ -144,65 +37,27 @@ DetInfoCtrlObj::~DetInfoCtrlObj()
void DetInfoCtrlObj::getMaxImageSize(Size& max_image_size)
{
_maxImageSize(max_image_size);
m_video.getMaxImageSize(max_image_size);
}
void DetInfoCtrlObj::getDetectorImageSize(Size& det_image_size)
{
_maxImageSize(det_image_size);
m_video.getMaxImageSize(det_image_size);
}
void DetInfoCtrlObj::getDefImageType(ImageType& def_image_type)
{
_getCurrentImageType(def_image_type);
m_video.getCurrImageType(def_image_type);
}
void DetInfoCtrlObj::getCurrImageType(ImageType& curr_image_type)
{
_getCurrentImageType(curr_image_type);
m_video.getCurrImageType(curr_image_type);
}
void DetInfoCtrlObj::setCurrImageType(ImageType image_format)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(image_format);
struct v4l2_format format;
format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
int ret = v4l2_ioctl(m_fd,VIDIOC_G_FMT,&format);
if(ret == -1)
THROW_HW_ERROR(Error) << "Can't get the format: " << strerror(errno);
bool found = false;
for(std::list<int>::iterator i = m_available_format.begin();
!found && i != m_available_format.end();++i)
{
switch(*i)
{
case V4L2_PIX_FMT_GREY:
case V4L2_PIX_FMT_YUV420:
case V4L2_PIX_FMT_YVU420:
if(image_format == Bpp8)
{
found = true;
format.fmt.pix.pixelformat = *i;
}
break;
case V4L2_PIX_FMT_Y16:
if(image_format == Bpp16)
{
found = true;
format.fmt.pix.pixelformat = *i;
}
break;
}
}
if(!found)
THROW_HW_ERROR(NotSupported) << "Not supported by the camera";
ret = v4l2_ioctl(m_fd,VIDIOC_S_FMT,&format);
if(ret == -1)
THROW_HW_ERROR(Error) << "Can't set the format: " << strerror(errno);
m_video.setCurrImageType(image_format);
}
void DetInfoCtrlObj::getPixelSize(double& x_size,double &y_size)
......@@ -217,11 +72,7 @@ void DetInfoCtrlObj::getDetectorType(std::string& det_type)
void DetInfoCtrlObj::getDetectorModel(std::string& det_model)
{
DEB_MEMBER_FUNCT();
det_model = m_det_model;
DEB_RETURN() << DEB_VAR1(det_model);
m_video.getDetectorModel(det_model);
}
void DetInfoCtrlObj::registerMaxImageSizeCallback(HwMaxImageSizeCallback& cb)
......@@ -233,44 +84,3 @@ void DetInfoCtrlObj::unregisterMaxImageSizeCallback(HwMaxImageSizeCallback& cb)
{
m_mis_cb_gen.unregisterMaxImageSizeCallback(cb);
}
void DetInfoCtrlObj::_maxImageSize(Size &max_size)
{
DEB_MEMBER_FUNCT();
struct v4l2_format format;
format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
int ret = v4l2_ioctl(m_fd,VIDIOC_G_FMT,&format);
if(ret == -1)
THROW_HW_ERROR(Error) << "Can't get the format: " << strerror(errno);
max_size = Size(format.fmt.pix.width,format.fmt.pix.height);
DEB_RETURN() << DEB_VAR1(max_size);
}
void DetInfoCtrlObj::_getCurrentImageType(ImageType& image_format)
{
DEB_MEMBER_FUNCT();
struct v4l2_format format;
format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
int ret = v4l2_ioctl(m_fd,VIDIOC_G_FMT,&format);
if(ret == -1)
THROW_HW_ERROR(Error) << "Can't get the format: " << strerror(errno);
switch(format.fmt.pix.pixelformat)
{
case V4L2_PIX_FMT_GREY:
case V4L2_PIX_FMT_YUYV:
case V4L2_PIX_FMT_YUV420:
case V4L2_PIX_FMT_YVU420:
image_format = Bpp8;break;
case V4L2_PIX_FMT_Y16:
image_format = Bpp16;break;
default:
THROW_HW_ERROR(NotSupported) << "Not yet managed";
}
DEB_RETURN() << DEB_VAR1(image_format);
}
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// Copyright (C) : 2009-2015
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
......@@ -19,47 +19,35 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include "V4L2Interface.h"
#include "V4L2DetInfoCtrlObj.h"
#include "V4L2SyncCtrlObj.h"
#include "V4L2VideoCtrlObj.h"
#include "V4L2Camera.h"
using namespace lima;
using namespace lima::V4L2;
class Interface::_Callback : public Camera::Callback
{
DEB_CLASS_NAMESPC(DebModCamera, "Interface::_Callback", "V4L2");
public:
_Callback(Interface& i) : m_interface(i) {}
virtual bool newFrame(int frame_id,const unsigned char* srcPt)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(frame_id);
StdBufferCbMgr& buffer_mgr = m_interface.m_buffer_ctrl_obj.getBuffer();
void* framePt = buffer_mgr.getFrameBufferPtr(frame_id);
const FrameDim& fDim = buffer_mgr.getFrameDim();
memcpy(framePt,srcPt,fDim.getMemSize());
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = frame_id;
return buffer_mgr.newFrameReady(frame_info);
}
private:
Interface& m_interface;
};
Interface::Interface(const char* dev_path)
{
DEB_CONSTRUCTOR();
m_cbk = new _Callback(*this);
m_cam = new Camera(m_cbk,dev_path);
m_det_info = new DetInfoCtrlObj(m_cam->getV4l2Fd());
m_sync = new SyncCtrlObj(*m_cam);
m_fd = v4l2_open(dev_path,O_RDWR);
if(m_fd < -1)
THROW_HW_ERROR(Error) << "Error opening: " << dev_path
<< "(" << strerror(errno) << ")";
m_video = new VideoCtrlObj(m_fd);
m_det_info = new DetInfoCtrlObj(*m_video);
m_sync = new SyncCtrlObj(*m_video);
m_cap_list.push_back(HwCap(m_sync));
m_cap_list.push_back(HwCap(m_det_info));
m_cap_list.push_back(HwCap(&m_buffer_ctrl_obj));
m_cap_list.push_back(HwCap(m_video));
m_cap_list.push_back(HwCap(&(m_video->getHwBufferCtrlObj())));
}
Interface::~Interface()
......@@ -68,7 +56,7 @@ Interface::~Interface()
delete m_sync;
delete m_det_info;
delete m_cam;
delete m_video;
}
void Interface::getCapList(CapList &cap_list) const
......@@ -85,31 +73,29 @@ void Interface::reset(ResetLevel reset_level)
void Interface::prepareAcq()
{
DEB_MEMBER_FUNCT();
m_cam->prepareAcq();
m_video->prepareAcq();
}
void Interface::startAcq()
{
DEB_MEMBER_FUNCT();
StdBufferCbMgr& buffer_mgr = m_buffer_ctrl_obj.getBuffer();
buffer_mgr.setStartTimestamp(Timestamp::now());
m_cam->startAcq();
m_video->getBuffer().setStartTimestamp(Timestamp::now());
m_video->startAcq();
}
void Interface::stopAcq()
{
DEB_MEMBER_FUNCT();
m_cam->stopAcq();
m_video->stopAcq();
}
void Interface::getStatus(StatusType &status)
{
DEB_MEMBER_FUNCT();
m_cam->getStatus(status);
m_video->getStatus(status);
DEB_RETURN() << DEB_VAR1(status);
}
......@@ -118,7 +104,7 @@ int Interface::getNbHwAcquiredFrames()
{
DEB_MEMBER_FUNCT();
int acq_frames = m_cam->getNbHwAcquiredFrames();
int acq_frames = m_video->getNbHwAcquiredFrames();
DEB_RETURN() << DEB_VAR1(acq_frames);
return acq_frames;
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// Copyright (C) : 2009-2015
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
......@@ -19,16 +19,15 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#include <cmath>
#include <errno.h>
//#include <cmath>
#include "V4L2SyncCtrlObj.h"
#include "V4L2Camera.h"
#include "V4L2VideoCtrlObj.h"
using namespace lima;
using namespace lima::V4L2;
SyncCtrlObj::SyncCtrlObj(Camera& cam) :
m_cam(cam),
SyncCtrlObj::SyncCtrlObj(VideoCtrlObj& video) :
m_video(video),
m_nb_frames(1)
{
}
......@@ -67,25 +66,16 @@ void SyncCtrlObj::getTrigMode(TrigMode& trig_mode)
DEB_RETURN() << DEB_VAR1(trig_mode);
}
void SyncCtrlObj::setExpTime(double)
void SyncCtrlObj::setExpTime(double exp_time)
{
DEB_MEMBER_FUNCT();
THROW_HW_ERROR(NotSupported) << "Should never been called?!?";
m_video.setExpTime(exp_time);
}
void SyncCtrlObj::getExpTime(double& exp_time)
{
DEB_MEMBER_FUNCT();
struct v4l2_control ctrl;
ctrl.id = V4L2_CID_EXPOSURE_ABSOLUTE;
int ret = v4l2_ioctl(m_cam.getV4l2Fd(),VIDIOC_G_CTRL,&ctrl);
if(ret == -1)
THROW_HW_ERROR(Error) << "Can't get exposure time " << strerror(errno);
exp_time = 1 / (ctrl.value * 5.); // Fixed me!!!
DEB_RETURN() << DEB_VAR1(exp_time);
m_video.getExpTime(exp_time);
}
bool SyncCtrlObj::checkAutoExposureMode(AutoExposureMode mode) const
......@@ -119,7 +109,7 @@ void SyncCtrlObj::setNbHwFrames(int nb_frames)
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(nb_frames);
m_nb_frames = nb_frames;
m_cam.setNbHwFrames(nb_frames);
m_video.setNbHwFrames(nb_frames);
}
void SyncCtrlObj::getNbHwFrames(int& nb_frames)
......@@ -127,7 +117,7 @@ void SyncCtrlObj::getNbHwFrames(int& nb_frames)
DEB_MEMBER_FUNCT();
// nb_frames = m_nb_frames;