Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_Centaurus.cpp
1 /*
2  * VideoSource_SonyX300.cpp
3  *
4  * Created on: Dec 8, 2009
5  * Author: africk
6  */
7 
8 #include <VideoSource/VideoSource_Centaurus.hh>
9 
10 using namespace std;
11 using namespace BIAS;
12 
13 char VideoSource_Centaurus::setup = 0;
14 
15 VideoSource_Centaurus::VideoSource_Centaurus() {
16  cam_handleP_ = NULL;
17  inputFifoP_ = NULL;
18  setup1_ = "PCI,card:0,channel:0";
19  setup2_ = "PCI,card:0,channel:1";
20 }
21 
22 VideoSource_Centaurus::~VideoSource_Centaurus() {
23  CloseDevice();
24 }
25 
26 int VideoSource_Centaurus::OpenDevice() {
27  char setup = 0;
28  int res = OpenDevice(&setup, SV_OPENPROGRAM_DEFAULT, SV_OPENTYPE_DEFAULT, 0, 0);
29 
30  return res;
31 }
32 
33 int VideoSource_Centaurus::OpenDevice(char * setup)
34 {
35  int res = OpenDevice(setup, SV_OPENPROGRAM_DEFAULT, SV_OPENTYPE_DEFAULT, 0, 0);
36 
37  return res;
38 }
39 
40 int VideoSource_Centaurus::OpenDevice(char * setup, int openprogram,
41  int opentype, int timeout, int spare) {
42  int res = sv_openex(&cam_handleP_, setup, openprogram, opentype, timeout,
43  spare);
44  if (res != SV_OK) {
45  BIASERR("sv_openex : " << sv_geterrortext(res) << endl)
46  }
47 
48  // res = sv_jack_option_set(cam_handleP_, 1, SV_OPTION_VIDEOMODE, mode);
49  // if (res != SV_OK) {
50  // BIASERR(sv_geterrortext(res) << endl)
51  // }
52  // res = sv_jack_option_set(cam_handleP_, 1, SV_OPTION_IOMODE, SV_IOMODE_YUV422);
53  // if (res != SV_OK) {
54  // BIASERR(sv_geterrortext(res) << endl)
55  // }
56 
57  std::string s = setup;
58  if (s==setup1_) {
59  res = sv_option_set(cam_handleP_,SV_OPTION_MULTICHANNEL,SV_MULTICHANNEL_INPUT);
60  if (res != SV_OK) {
61  BIASERR(sv_geterrortext(res) << endl)
62  }
63  }
64  return res;
65 }
66 
67 int VideoSource_Centaurus::CloseDevice() {
68  int res = 0;
69  if (cam_handleP_ != NULL) {
70  res = sv_close(cam_handleP_);
71  if (res != SV_OK) {
72  BIASERR("sv_close : " << sv_geterrortext(res) << endl)
73  } else {
74  cam_handleP_ = NULL;
75  }
76  }
77 
78  return res;
79 }
80 
81 int VideoSource_Centaurus::SetVideoMode(int mode) {
82  int res = sv_videomode(cam_handleP_, mode);
83  if (res != SV_OK) {
84  BIASERR("sv_videomode : " << sv_geterrortext(res) << endl);
85  }
86 
87  return res;
88 }
89 
90 int VideoSource_Centaurus::InitFiFo() {
91  int res = sv_fifo_init(cam_handleP_, &inputFifoP_, 1, 0, 1,
92  SV_FIFO_FLAG_VIDEOONLY, 0);
93  if (res != SV_OK) {
94  BIASERR("sv_fifo_init : " << sv_geterrortext(res) << endl);
95  }
96 
97  res = sv_fifo_start(cam_handleP_, inputFifoP_);
98  if (res != SV_OK) {
99  BIASERR("sv_fifo_start " << sv_geterrortext(res) << endl);
100  }
101 
102  return res;
103 }
104 
105 int VideoSource_Centaurus::GrabSingle(Camera<unsigned char> &image) {
106 
107  int res = -1;
108 
109  if (cam_handleP_ != NULL) {
110  if (inputFifoP_ != NULL) {
111  int flags = 0;
112  flags |= SV_FIFO_FLAG_VSYNCWAIT;
113  flags |= SV_FIFO_FLAG_FLUSH;
114 
115  sv_fifo_buffer* sv_buffer;
116  res = sv_fifo_getbuffer(cam_handleP_, inputFifoP_, &sv_buffer,
117  NULL, flags);
118  if (res != SV_OK) {
119  BIASERR("sv_fifo_getbuffer : " << sv_geterrortext(res) << endl);
120  }
121 
122  sv_buffer->dma.addr = (char*) image.GetImageData();
123  sv_buffer->dma.size = image.GetWidth() * image.GetHeight()
124  * image.GetChannelCount();
125 
126  res = sv_fifo_putbuffer(cam_handleP_, inputFifoP_, sv_buffer, NULL);
127  if (res != SV_OK) {
128  BIASERR("sv_fifo_putbuffer : " << sv_geterrortext(res) << endl);
129  }
130 
131  } else {
132  BIASERR("call InitFiFo(...) first");
133  }
134  } else {
135  BIASERR("call OpenDevice(...) first " << endl);
136  }
137 
138  return res;
139 }
140 
141 int VideoSource_Centaurus::InitImage(BIAS::ImageBase &image) {
142 
143  bool alreadyOpend = false;
144  if (cam_handleP_ == NULL) {
145  OpenDevice();
146  } else {
147  alreadyOpend = true;
148  }
149 
150  sv_storageinfo storageInfo;
151  int res = sv_storage_status(cam_handleP_, 0, NULL, &storageInfo,
152  sizeof(storageInfo), 0);
153  if (res != SV_OK) {
154  BIASERR("sv_storage_status : " << sv_geterrortext(res) << endl);
155  }
156 
157  int colorMode = storageInfo.colormode;
158 
159  int width = storageInfo.xsize;
160  int height = storageInfo.ysize;
161 
162  switch (colorMode) {
163  case SV_COLORMODE_YUV422_YUYV:
164  image.Init(width, height, 2, ImageBase::ST_unsignedchar);
165  image.SetColorModel(ImageBase::CM_YUYV422);
166  cout << "color mode : YUV422_YUYV " << endl;
167  break;
168  default:
169  break;
170  }
171 
172  int videoMode = storageInfo.videomode;
173  switch (videoMode & SV_MODE_MASK) {
174  case SV_MODE_SMPTE274_25sF:
175  cout << "video mode : SV_MODE_SMPTE274_25sF " << endl;
176  break;
177  default:
178  break;
179  }
180 
181  int fps = storageInfo.fps;
182  cout << "FPS : " << fps << endl;
183 
184  if (!alreadyOpend) {
185  CloseDevice();
186  }
187 
188  return res;
189 }
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
unsigned int GetWidth() const
Definition: ImageBase.hh:312
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
unsigned int GetHeight() const
Definition: ImageBase.hh:319
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
Definition: ImageBase.cpp:229
This is the base class for images in BIAS.
Definition: ImageBase.hh:102