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
00027
00028 #ifndef PANGOLIN_FIREWIRE_H
00029 #define PANGOLIN_FIREWIRE_H
00030
00031 #include <pangolin/pangolin.h>
00032 #include <pangolin/video.h>
00033
00034 #include <dc1394/dc1394.h>
00035
00036 #ifndef _WIN32
00037 #include <unistd.h>
00038 #endif
00039
00040
00041
00042 namespace pangolin
00043 {
00044
00045 std::string Dc1394ColorCodingToString(dc1394color_coding_t coding);
00046
00047 dc1394color_coding_t Dc1394ColorCodingFromString(std::string coding);
00048
00049 void Dc1394ModeDetails(dc1394video_mode_t mode, unsigned& w, unsigned& h, std::string& format );
00050
00051 class FirewireFrame
00052 {
00053 friend class FirewireVideo;
00054 public:
00055 bool isValid()
00056 {
00057 return frame;
00058 }
00059 unsigned char* Image()
00060 {
00061 return frame ? frame->image : 0;
00062 }
00063 unsigned Width() const
00064 {
00065 return frame ? frame->size[0] : 0;
00066 }
00067 unsigned Height() const
00068 {
00069 return frame ? frame->size[1] : 0;
00070 }
00071
00072 protected:
00073 FirewireFrame(dc1394video_frame_t* frame) : frame(frame) {}
00074 dc1394video_frame_t *frame;
00075 };
00076
00077 struct Guid
00078 {
00079 Guid(uint64_t guid):guid(guid) {}
00080 uint64_t guid;
00081 };
00082
00083 class FirewireVideo : public VideoInterface
00084 {
00085 public:
00086 const static int MAX_FR = -1;
00087 const static int EXT_TRIG = -1;
00088
00089 FirewireVideo(
00090 unsigned deviceid = 0,
00091 dc1394video_mode_t video_mode = DC1394_VIDEO_MODE_640x480_RGB8,
00092 dc1394framerate_t framerate = DC1394_FRAMERATE_30,
00093 dc1394speed_t iso_speed = DC1394_ISO_SPEED_400,
00094 int dma_buffers = 10
00095 );
00096
00097 FirewireVideo(
00098 Guid guid,
00099 dc1394video_mode_t video_mode = DC1394_VIDEO_MODE_640x480_RGB8,
00100 dc1394framerate_t framerate = DC1394_FRAMERATE_30,
00101 dc1394speed_t iso_speed = DC1394_ISO_SPEED_400,
00102 int dma_buffers = 10
00103 );
00104
00105 FirewireVideo(
00106 Guid guid,
00107 dc1394video_mode_t video_mode,
00108 int framerate,
00109 uint32_t width, uint32_t height,
00110 uint32_t left, uint32_t top,
00111 dc1394speed_t iso_speed,
00112 int dma_buffers, bool reset_at_boot=false
00113 );
00114
00115 FirewireVideo(
00116 unsigned deviceid,
00117 dc1394video_mode_t video_mode,
00118 int framerate,
00119 uint32_t width, uint32_t height,
00120 uint32_t left, uint32_t top,
00121 dc1394speed_t iso_speed,
00122 int dma_buffers, bool reset_at_boot=false
00123 );
00124
00125 ~FirewireVideo();
00126
00128 unsigned Width() const
00129 {
00130 return width;
00131 }
00132
00134 unsigned Height() const
00135 {
00136 return height;
00137 }
00138
00140 size_t SizeBytes() const;
00141
00143 std::string PixFormat() const;
00144
00146 void Start();
00147
00149 void Stop();
00150
00152 bool GrabNext( unsigned char* image, bool wait = true );
00153
00155 bool GrabNewest( unsigned char* image, bool wait = true );
00156
00160 FirewireFrame GetNext(bool wait = true);
00161
00165 FirewireFrame GetNewest(bool wait = true);
00166
00169 void PutFrame(FirewireFrame& frame);
00170
00172 float GetShutterTime() const;
00173
00175 void SetShutterTime(float val);
00176
00178 void SetAutoShutterTime();
00179
00181 float GetGain() const;
00182
00184 void SetGain(float val);
00185
00187 void SetAutoGain();
00188
00190 float GetGamma() const;
00191
00193 void SetShutterTimeQuant(int shutter);
00194
00196 void SetInternalTrigger();
00197
00199 void SetExternalTrigger(
00200 dc1394trigger_mode_t mode=DC1394_TRIGGER_MODE_0,
00201 dc1394trigger_polarity_t polarity=DC1394_TRIGGER_ACTIVE_HIGH,
00202 dc1394trigger_source_t source=DC1394_TRIGGER_SOURCE_0
00203 );
00204
00205 protected:
00206
00207 void init_camera(
00208 uint64_t guid, int dma_frames,
00209 dc1394speed_t iso_speed,
00210 dc1394video_mode_t video_mode,
00211 dc1394framerate_t framerate
00212 );
00213
00214 void init_format7_camera(
00215 uint64_t guid, int dma_frames,
00216 dc1394speed_t iso_speed,
00217 dc1394video_mode_t video_mode,
00218 int framerate,
00219 uint32_t width, uint32_t height,
00220 uint32_t left, uint32_t top, bool reset_at_boot
00221 );
00222
00223 static int nearest_value(int value, int step, int min, int max);
00224 static double bus_period_from_iso_speed(dc1394speed_t iso_speed);
00225
00226 bool running;
00227 dc1394camera_t *camera;
00228 unsigned width, height, top, left;
00229
00230 dc1394_t * d;
00231 dc1394camera_list_t * list;
00232 mutable dc1394error_t err;
00233
00234 };
00235
00236 }
00237
00238 #endif // PANGOLIN_FIREWIRE_H