00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __OPENKN_CONTROLLER__LIN_DVCAM_HPP__
00027 #define __OPENKN_CONTROLLER__LIN_DVCAM_HPP__
00028
00029
00030
00031
00032 #include "CameraController.hpp"
00033
00034
00035
00036
00037 #include <libiec61883/iec61883.h>
00038 #include <boost/thread.hpp>
00039
00040 #include <libdv/dv_types.h>
00041 #include <libdv/dv.h>
00042
00043
00044
00045
00046 namespace kn{
00047
00054 struct DVCamParams : CameraParams
00055 {
00056
00057 int port;
00058
00062 DVCamParams(const int& p = 0,
00063 const std::string& dn = "",
00064 const size_t& expectedwidth = 720,
00065 const size_t& expectedheight = 576)
00066 :CameraParams(dn,expectedwidth,expectedheight),port(p) {}
00067
00068 };
00069
00070
00071
00099 class DVCam :CameraController
00100 {
00101 private:
00102
00106 iec61883_dv_fb_t frame;
00107
00111 raw1394handle_t handle;
00112
00116 dv_decoder_t *td;
00117
00121 unsigned int currentframe;
00122
00126 static const size_t maxframe = 10;
00127
00131 int pitches[1];
00132
00136 unsigned char ***pixels;
00137
00141 bool isgrabbing;
00142
00146 bool isenable;
00147
00151 boost::thread *thrd;
00152
00156 boost::mutex dvmutex;
00157
00164 void Handler(void);
00165
00173 int ReadFrame(unsigned char *data);
00174
00185 static int callbackReadFrame(unsigned char *data,
00186 int length,
00187 int complete,
00188 void *callback_data);
00189
00190 void ResetHandler( void );
00191
00192 static int ResetHandlerProxy( raw1394handle_t handle, unsigned int generation );
00193
00194 public:
00195
00196
00201 DVCam(void):CameraController(){
00202 handle = 0;
00203 isenable=false;
00204 isgrabbing=false;
00205 td=0;
00206 pitches[0]=720*3;
00207 pitches[1]=pitches[2]=0;
00208 pixels = new unsigned char** [maxframe];
00209 for(unsigned int i = 0; i < maxframe; ++i){
00210 pixels[i] = new unsigned char* [3];
00211 pixels[i][0] = new unsigned char [720*576*3];
00212 }
00213 thrd=0;
00214 currentframe = 0;
00215 }
00216
00224 ~DVCam(void){
00225 closeDevice();
00226 if(pixels){
00227 for(unsigned int i = 0; i < maxframe; ++i){
00228 if(pixels[i]){
00229 if(pixels[i][0])
00230 delete[] pixels[i][0];
00231 delete[] pixels[i];
00232 }
00233 }
00234 delete[] pixels;
00235 }
00236 }
00237
00247 void openDevice(const DVCamParams& params);
00248
00249 void openDevice(void){openDevice(DVCamParams());}
00250
00260 void closeDevice(void);
00261
00270 void start(void);
00271
00280 void stop();
00281
00294 unsigned char* getImage(void);
00295
00304 inline size_t width(void) const {return this->camwidth;}
00305
00314 inline size_t height(void) const {return this->camheight;}
00315
00322 inline bool isStarted(void) const {return isgrabbing;}
00323
00330 inline bool isOpen(void) const {return isenable;}
00331
00332
00333 };
00334 }
00335
00336 #endif