Commit 28a7b580 authored by Andreas Persson's avatar Andreas Persson

Camera: use SoftBufferCtrlObj

parent 194c491e
......@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <limits>
#include "HwBufferMgr.h"
#include "HwMaxImageSizeCallback.h"
#include "FlyCapture2.h"
......@@ -72,11 +73,17 @@ public:
void getStatus(Camera::Status& status);
// buffer control object
HwBufferCtrlObj* getBufferCtrlObj();
// detector info object
void getDetectorType(std::string& type);
void getDetectorModel(std::string& model);
void getDetectorImageSize(Size& size);
void getImageType(ImageType& type);
void setImageType(ImageType type);
// synch control object
void getTrigMode(TrigMode& mode);
void setTrigMode(TrigMode mode);
......@@ -103,14 +110,10 @@ public:
void getBin(Bin& bin);
void setBin(const Bin& bin);
// video control object
void getVideoMode(VideoMode& mode) const;
void setVideoMode(VideoMode mode);
// camera specific
void getGain(double& gain);
void setGain(double gain);
// camera specific
void getPacketSize(int& packet_size);
void setPacketSize(int packet_size);
......@@ -138,7 +141,7 @@ private:
void _stopAcq(bool internalFlag);
void _forcePGRY16Mode();
VideoCtrlObj *m_video;
SoftBufferCtrlObj m_buffer_ctrl_obj;
Camera::Status m_status;
int m_nb_frames;
......
......@@ -62,13 +62,11 @@ public:
void getAutoGain(bool& auto_gain) const;
void setAutoGain(bool auto_gain);
private:
Camera& m_cam;
CapList m_cap_list;
DetInfoCtrlObj *m_det_info;
SyncCtrlObj *m_sync;
VideoCtrlObj *m_video;
};
} // namespace PointGrey
......
//###########################################################################
// 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/>.
//###########################################################################
#ifndef POINTGREYVIDEOCTRLOBJ_H
#define POINTGREYVIDEOCTRLOBJ_H
#include "HwVideoCtrlObj.h"
namespace lima
{
namespace PointGrey
{
class Camera;
/*******************************************************************
* \class VideoCtrlObj
* \brief Control object providing PointGrey Video interface
*******************************************************************/
class VideoCtrlObj : public HwVideoCtrlObj
{
DEB_CLASS_NAMESPC(DebModCamera, "VideoCtrlObj", "PointGrey");
public:
VideoCtrlObj(Camera& cam);
virtual ~VideoCtrlObj() {};
virtual void getSupportedVideoMode(std::list<VideoMode> &aList) const;
virtual void getVideoMode(VideoMode&) const;
virtual void setVideoMode(VideoMode);
virtual void getLive(bool&) const;
virtual void setLive(bool);
virtual void getGain(double&) const;
virtual void setGain(double);
virtual void checkBin(Bin& bin){};
virtual void setBin(const Bin&){};
virtual void checkRoi(const Roi& set_roi, Roi& hw_roi){};
virtual void setRoi(const Roi&){};
private:
Camera& m_cam;
bool m_live;
};
} // namespace PointGrey
} // namespace lima
#endif // POINTGREYVIDEOCTRLOBJ_H
pointgrey-objs = PointGreyCamera.o \
PointGreyInterface.o \
PointGreyDetInfoCtrlObj.o \
PointGreySyncCtrlObj.o \
PointGreyVideoCtrlObj.o
PointGreySyncCtrlObj.o
SRCS = $(pointgrey-objs:.o=.cpp)
......
#include "PointGreyCamera.h"
#include "PointGreyInterface.h"
#include "PointGreyVideoCtrlObj.h"
using namespace lima;
using namespace lima::PointGrey;
......@@ -33,7 +32,6 @@ Camera::Camera(const int camera_serial,
, m_acq_started(false)
, m_thread_running(true)
, m_image_number(0)
, m_video(NULL)
, m_camera(NULL)
// camera properties
, m_frame_rate_property(FlyCapture2::FRAME_RATE)
......@@ -278,7 +276,9 @@ void Camera::startAcq()
DEB_MEMBER_FUNCT();
DEB_TRACE() << "Start acquisition";
m_video->getBuffer().setStartTimestamp(Timestamp::now());
StdBufferCbMgr& buffer_mgr = m_buffer_ctrl_obj.getBuffer();
buffer_mgr.setStartTimestamp(Timestamp::now());
m_error = m_camera->StartCapture();
if (m_error != FlyCapture2::PGRERROR_OK)
......@@ -329,6 +329,72 @@ void Camera::getDetectorModel(string& model)
DEB_RETURN() << DEB_VAR1(model);
}
//-----------------------------------------------------
//
//-----------------------------------------------------
void Camera::getImageType(ImageType& type)
{
DEB_MEMBER_FUNCT();
switch(m_image_settings.pixelFormat)
{
case FlyCapture2::PIXEL_FORMAT_MONO8:
type = Bpp8;
break;
case FlyCapture2::PIXEL_FORMAT_MONO16:
type = Bpp16;
break;
default:
THROW_HW_ERROR(Error) << "Unable to determine the image type";
}
DEB_RETURN() << DEB_VAR1(type);
}
//-----------------------------------------------------
//
//-----------------------------------------------------
void Camera::setImageType(ImageType type)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(type);
FlyCapture2::PixelFormat old_format, new_format;
bool valid;
old_format = m_image_settings.pixelFormat;
switch(type)
{
case Bpp8:
new_format = FlyCapture2::PIXEL_FORMAT_MONO8;
break;
case Bpp16:
new_format = FlyCapture2::PIXEL_FORMAT_MONO16;
break;
default:
THROW_HW_ERROR(Error) << "Unsupported image type";
}
if (new_format == old_format)
// nothing to do
return;
if (m_acq_started)
THROW_HW_ERROR(Error) << "Acquisition in progress";
m_image_settings.pixelFormat = new_format;
try
{
_applyImageSettings();
}
catch (Exception &e)
{
m_image_settings.pixelFormat = old_format;
THROW_HW_ERROR(Error) << e.getErrDesc();
}
maxImageSizeChanged(Size(m_image_settings_info.maxWidth, m_image_settings_info.maxHeight), type);
}
//-----------------------------------------------------
//
//-----------------------------------------------------
......@@ -543,6 +609,14 @@ void Camera::getStatus(Camera::Status& status)
DEB_RETURN() << DEB_VAR1(DEB_HEX(status));
}
//-----------------------------------------------------
//
//-----------------------------------------------------
HwBufferCtrlObj* Camera::getBufferCtrlObj()
{
return &m_buffer_ctrl_obj;
}
//-----------------------------------------------------
//
//-----------------------------------------------------
......@@ -598,75 +672,6 @@ void Camera::setBin(const Bin &aBin)
DEB_RETURN() << DEB_VAR1(aBin);
}
//-----------------------------------------------------
//
//-----------------------------------------------------
void Camera::getVideoMode(VideoMode& mode) const
{
DEB_MEMBER_FUNCT();
switch(m_image_settings.pixelFormat)
{
case FlyCapture2::PIXEL_FORMAT_MONO8:
mode = Y8;
break;
case FlyCapture2::PIXEL_FORMAT_MONO16:
mode = Y16;
break;
default:
THROW_HW_ERROR(Error) << "Unable to determine the video mode";
}
DEB_RETURN() << DEB_VAR1(mode);
}
//-----------------------------------------------------
//
//-----------------------------------------------------
void Camera::setVideoMode(VideoMode mode)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(mode);
FlyCapture2::PixelFormat old_format, new_format;
ImageType image_type;
bool valid;
old_format = m_image_settings.pixelFormat;
switch(mode)
{
case Y8:
new_format = FlyCapture2::PIXEL_FORMAT_MONO8;
image_type = Bpp8;
break;
case Y16:
new_format = FlyCapture2::PIXEL_FORMAT_MONO16;
image_type = Bpp16;
break;
default:
THROW_HW_ERROR(Error) << "Unsupported video mode";
}
if (new_format == old_format)
// nothing to do
return;
if (m_acq_started)
THROW_HW_ERROR(Error) << "Acquisition in progress";
m_image_settings.pixelFormat = new_format;
try
{
_applyImageSettings();
}
catch (Exception &e)
{
m_image_settings.pixelFormat = old_format;
THROW_HW_ERROR(Error) << e.getErrDesc();
}
maxImageSizeChanged(Size(m_image_settings_info.maxWidth, m_image_settings_info.maxHeight), image_type);
}
//-----------------------------------------------------
//
//-----------------------------------------------------
......@@ -841,7 +846,6 @@ void Camera::_AcqThread::threadFunction()
DEB_MEMBER_FUNCT();
FlyCapture2::Error error;
FlyCapture2::Image image;
VideoMode mode;
sched_param param;
param.sched_priority = sched_get_priority_max(SCHED_FIFO);
......@@ -851,6 +855,7 @@ void Camera::_AcqThread::threadFunction()
}
AutoMutex lock(m_cam.m_cond.mutex());
StdBufferCbMgr& buffer_mgr = m_cam.m_buffer_ctrl_obj.getBuffer();
while(true)
{
......@@ -885,10 +890,13 @@ void Camera::_AcqThread::threadFunction()
m_cam._setStatus(Camera::Readout, false);
DEB_TRACE() << "image# " << m_cam.m_image_number << " acquired";
void* framePt = buffer_mgr.getFrameBufferPtr(m_cam.m_image_number);
const FrameDim& fDim = buffer_mgr.getFrameDim();
memcpy(framePt, image.GetData(), fDim.getMemSize());
m_cam.m_video->getVideoMode(mode);
continue_acq = m_cam.m_video->callNewImage((char *)image.GetData(), image.GetCols(), image.GetRows(), mode);
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = m_cam.m_image_number;
continue_acq = buffer_mgr.newFrameReady(frame_info);
m_cam.m_image_number++;
}
else if (error == FlyCapture2::PGRERROR_IMAGE_CONSISTENCY_ERROR)
......
......@@ -59,7 +59,7 @@ void DetInfoCtrlObj::getDetectorImageSize(Size& size)
void DetInfoCtrlObj::getDefImageType(ImageType& image_type)
{
DEB_MEMBER_FUNCT();
image_type = Bpp16;
m_cam.getImageType(image_type);
}
//-----------------------------------------------------
......@@ -68,22 +68,7 @@ void DetInfoCtrlObj::getDefImageType(ImageType& image_type)
void DetInfoCtrlObj::getCurrImageType(ImageType& image_type)
{
DEB_MEMBER_FUNCT();
VideoMode video_mode;
m_cam.getVideoMode(video_mode);
switch (video_mode)
{
case Y8:
image_type = Bpp8;
break;
case Y16:
image_type = Bpp16;
break;
default:
// TODO: handle error
return;
}
m_cam.getImageType(image_type);
DEB_RETURN() << DEB_VAR1(image_type);
}
......@@ -94,21 +79,7 @@ void DetInfoCtrlObj::setCurrImageType(ImageType image_type)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(image_type);
VideoMode video_mode;
switch (image_type)
{
case Bpp8:
video_mode = Y8;
break;
case Bpp16:
video_mode = Y16;
break;
default:
// TODO: handle error
return;
}
m_cam.setVideoMode(video_mode);
m_cam.setImageType(image_type);
}
//-----------------------------------------------------
......
......@@ -24,7 +24,6 @@
#include "PointGreyCamera.h"
#include "PointGreyDetInfoCtrlObj.h"
#include "PointGreySyncCtrlObj.h"
#include "PointGreyVideoCtrlObj.h"
using namespace lima;
using namespace lima::PointGrey;
......@@ -41,13 +40,11 @@ Interface::Interface(Camera& cam)
DEB_CONSTRUCTOR();
m_det_info = new DetInfoCtrlObj(cam);
m_sync = new SyncCtrlObj(cam);
m_video = new VideoCtrlObj(cam);
m_cap_list.push_back(HwCap(m_det_info));
m_cap_list.push_back(HwCap(m_sync));
m_cap_list.push_back(HwCap(m_video));
HwBufferCtrlObj *buffer = &(m_video->getHwBufferCtrlObj());
HwBufferCtrlObj *buffer = cam.getBufferCtrlObj();
m_cap_list.push_back(HwCap(buffer));
}
......@@ -59,7 +56,6 @@ Interface::~Interface()
DEB_DESTRUCTOR();
delete m_det_info;
delete m_sync;
delete m_video;
}
//-----------------------------------------------------
......
//###########################################################################
// 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/>.
//###########################################################################
#include "PointGreyVideoCtrlObj.h"
#include "PointGreyCamera.h"
using namespace lima;
using namespace lima::PointGrey;
/*******************************************************************
* \brief VideoCtrlObj constructor
*******************************************************************/
VideoCtrlObj::VideoCtrlObj(Camera &cam)
: m_cam(cam)
, m_live(false)
{
DEB_CONSTRUCTOR();
m_cam.m_video = this;
}
void VideoCtrlObj::getSupportedVideoMode(std::list<VideoMode> &mode_list) const
{
DEB_MEMBER_FUNCT();
mode_list.push_back(Y8);
mode_list.push_back(Y16);
}
void VideoCtrlObj::getVideoMode(VideoMode& mode) const
{
DEB_MEMBER_FUNCT();
m_cam.getVideoMode(mode);
DEB_RETURN() << DEB_VAR1(mode);
}
void VideoCtrlObj::setVideoMode(VideoMode mode)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(mode);
m_cam.setVideoMode(mode);
}
void VideoCtrlObj::getLive(bool &live) const
{
DEB_MEMBER_FUNCT();
live = m_live;
DEB_RETURN() << DEB_VAR1(live);
}
void VideoCtrlObj::setLive(bool live)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(live);
m_live = live;
if (live){
m_cam.setNbFrames(0);
m_cam.startAcq();
}
else
m_cam.stopAcq();
}
void VideoCtrlObj::getGain(double &gain) const
{
DEB_MEMBER_FUNCT();
m_cam.getGain(gain);
DEB_RETURN() << DEB_VAR1(gain);
}
void VideoCtrlObj::setGain(double gain)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(gain);
m_cam.setGain(gain);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment