Follow this link to skip to the main content

Mr1394_Hw_Camera Class Reference

#include <mr1394_hw_camera.h>

Collaboration diagram for Mr1394_Hw_Camera:

Collaboration graph
[legend]
List of all members.

Public Types

enum  Mr1394_State {
  CAMERA_STATE_DESTRUCTED, CAMERA_STATE_UNREADY, CAMERA_STATE_READY_UNSYNC, CAMERA_STATE_READY_SYNC,
  CAMERA_STATE_VIDEO, CAMERA_STATE_DESTRUCTED, CAMERA_STATE_UNREADY, CAMERA_STATE_READY_UNSYNC,
  CAMERA_STATE_READY_SYNC, CAMERA_STATE_VIDEO
}
enum  Camera_Brand {
  BRAND_UNKNOWN, BRAND_GENERIC_PT_GREY, BRAND_DRAGONFLY, BRAND_UNKNOWN,
  BRAND_GENERIC_PT_GREY, BRAND_DRAGONFLY
}
enum  Mr1394_State {
  CAMERA_STATE_DESTRUCTED, CAMERA_STATE_UNREADY, CAMERA_STATE_READY_UNSYNC, CAMERA_STATE_READY_SYNC,
  CAMERA_STATE_VIDEO, CAMERA_STATE_DESTRUCTED, CAMERA_STATE_UNREADY, CAMERA_STATE_READY_UNSYNC,
  CAMERA_STATE_READY_SYNC, CAMERA_STATE_VIDEO
}
enum  Camera_Brand {
  BRAND_UNKNOWN, BRAND_GENERIC_PT_GREY, BRAND_DRAGONFLY, BRAND_UNKNOWN,
  BRAND_GENERIC_PT_GREY, BRAND_DRAGONFLY
}

Public Member Functions

 Mr1394_Hw_Camera (const GUID_1394 &guid)
 ~Mr1394_Hw_Camera ()
void display_id (ostream &out=cout)
void display_formats (ostream &out=cout)
void display_state (ostream &out=cout)
void display_capabilities (ostream &out=cout)
void to_video_state () throw (exception)
void to_unready_state () throw (exception)
void to_ready_unsync_state () throw (exception)
void to_ready_sync_state () throw (exception)
void acquire (Image_Uint8 &image, Time *timestamp_ptr=NULL) throw (exception)
void acquire (uint8_t *data_ptr, size_t byte_count, Time *timestamp_ptr=NULL) throw (exception)
bool set_format (long color_coding, int desired_width, int desired_height) throw (exception)
Camera_Brand get_camera_brand () const
size_t get_pixel_width ()
size_t get_byte_width ()
size_t get_subframe_pixel_width ()
size_t get_subframe_byte_width ()
size_t get_height ()
size_t get_subframe_height ()
long get_format () const
void lock ()
void unlock ()
bool set_frame_rate_and_shutter (double frame_rate_hertz, double shutter_period_seconds)
 Mr1394_Hw_Camera (const GUID_1394 &guid)
 ~Mr1394_Hw_Camera ()
void display_id (ostream &out=cout)
void display_formats (ostream &out=cout)
void display_state (ostream &out=cout)
void display_capabilities (ostream &out=cout)
void to_video_state () throw (exception)
void to_unready_state () throw (exception)
void to_ready_unsync_state () throw (exception)
void to_ready_sync_state () throw (exception)
void acquire (Image_Uint8 &image, Time *timestamp_ptr=NULL) throw (exception)
void acquire (uint8_t *data_ptr, size_t byte_count, Time *timestamp_ptr=NULL) throw (exception)
bool set_format (long color_coding, int desired_width, int desired_height) throw (exception)
Camera_Brand get_camera_brand () const
size_t get_pixel_width ()
size_t get_byte_width ()
size_t get_subframe_pixel_width ()
size_t get_subframe_byte_width ()
size_t get_height ()
size_t get_subframe_height ()
long get_format () const
void lock ()
void unlock ()
bool set_frame_rate_and_shutter (double frame_rate_hertz, double shutter_period_seconds)

Static Public Member Functions

static void get_all_camera_guids (vector< GUID_1394 > &guids) throw (exception)
static void acquire_group (std::vector< Mr1394_Hw_Camera * > &cam_vec, std::vector< Image_Uint8 > &image_vec, std::vector< Time * > *timestamp_vec=NULL) throw (exception)
static void get_all_camera_guids (vector< GUID_1394 > &guids) throw (exception)
static void acquire_group (std::vector< Mr1394_Hw_Camera * > &cam_vec, std::vector< Image_Uint8 > &image_vec, std::vector< Time * > *timestamp_vec=NULL) throw (exception)

Public Attributes

DMA_Slotdma_slot_ptr
DMA_Slotdma_slot_ptr

Protected Member Functions

void _init (const GUID_1394 &guid)
const char * _iidc_state_string () const
const char * _last_error_string () const
Camera_Brand _get_camera_brand (long cam_index) const
size_t _get_bits_per_pixel () const
void _unready_to_ready_sync_state () throw (exception)
void _unready_to_ready_unsync_state () throw (exception)
void _ready_unsync_to_unready_state () throw (exception)
void _ready_sync_to_unready_state () throw (exception)
void _ready_unsync_to_sync_state () throw (exception)
void _ready_sync_to_unsync_state () throw (exception)
void _ready_sync_to_video_state () throw (exception)
void _video_to_ready_sync_state () throw (exception)
void _get_recent_image (Image_Uint8 &image)
void _attach_buffers (int buf_count)
void _deallocate_buffers ()
void _init (const GUID_1394 &guid)
const char * _iidc_state_string () const
const char * _last_error_string () const
Camera_Brand _get_camera_brand (long cam_index) const
size_t _get_bits_per_pixel () const
void _unready_to_ready_sync_state () throw (exception)
void _unready_to_ready_unsync_state () throw (exception)
void _ready_unsync_to_unready_state () throw (exception)
void _ready_sync_to_unready_state () throw (exception)
void _ready_unsync_to_sync_state () throw (exception)
void _ready_sync_to_unsync_state () throw (exception)
void _ready_sync_to_video_state () throw (exception)
void _video_to_ready_sync_state () throw (exception)
void _get_recent_image (Image_Uint8 &image)
void _attach_buffers (int buf_count)
void _deallocate_buffers ()

Static Protected Member Functions

static void _callback_function (long camera_index, HIIDC h, long event, long lparam, void *pparam)
static void _callback_function (long camera_index, HIIDC h, long event, long lparam, void *pparam)

Protected Attributes

HIIDC _handle
IIDC_CALLBACK _call_back_context
Mr1394_State _state
GUID_1394 _guid
Semaphore _camera_lock
Semaphore * _group_sem_ptr
Time _timestamp
Camera_Brand _camera_brand
void * _image_buf_array [_MAX_IMG_BUFS]
int _image_buf_count
int _pixel_width
int _pixel_height
long _image_format
Semaphore * _group_sem_ptr
void * _image_buf_array [_MAX_IMG_BUFS]

Static Protected Attributes

static const int _MAX_IMG_BUFS = 3

Classes

class  Image_Uint8

Detailed Description

Definition at line 33 of file hw_mr1394_camera/mr1394_hw_camera.h.


Member Enumeration Documentation

Enumerator:
CAMERA_STATE_DESTRUCTED 
CAMERA_STATE_UNREADY 
CAMERA_STATE_READY_UNSYNC 
CAMERA_STATE_READY_SYNC 
CAMERA_STATE_VIDEO 
CAMERA_STATE_DESTRUCTED 
CAMERA_STATE_UNREADY 
CAMERA_STATE_READY_UNSYNC 
CAMERA_STATE_READY_SYNC 
CAMERA_STATE_VIDEO 

Definition at line 35 of file hw_mr1394_camera/mr1394_hw_camera.h.

Enumerator:
BRAND_UNKNOWN 
BRAND_GENERIC_PT_GREY 
BRAND_DRAGONFLY 
BRAND_UNKNOWN 
BRAND_GENERIC_PT_GREY 
BRAND_DRAGONFLY 

Definition at line 40 of file hw_mr1394_camera/mr1394_hw_camera.h.

Enumerator:
CAMERA_STATE_DESTRUCTED 
CAMERA_STATE_UNREADY 
CAMERA_STATE_READY_UNSYNC 
CAMERA_STATE_READY_SYNC 
CAMERA_STATE_VIDEO 
CAMERA_STATE_DESTRUCTED 
CAMERA_STATE_UNREADY 
CAMERA_STATE_READY_UNSYNC 
CAMERA_STATE_READY_SYNC 
CAMERA_STATE_VIDEO 

Definition at line 19 of file mr1394_camera/mr1394_hw_camera.h.

Enumerator:
BRAND_UNKNOWN 
BRAND_GENERIC_PT_GREY 
BRAND_DRAGONFLY 
BRAND_UNKNOWN 
BRAND_GENERIC_PT_GREY 
BRAND_DRAGONFLY 

Definition at line 24 of file mr1394_camera/mr1394_hw_camera.h.


Constructor & Destructor Documentation

Mr1394_Hw_Camera::Mr1394_Hw_Camera ( const GUID_1394 &  guid  ) 

Definition at line 67 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _init().

Referenced by _callback_function().

00068   : _camera_lock(1)
00069 {
00070   _init(guid);
00071 }

Here is the call graph for this function:

Mr1394_Hw_Camera::~Mr1394_Hw_Camera (  ) 

Definition at line 77 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _call_back_context, _deallocate_buffers(), _handle, _iidc_state_string(), camera_table, mr1394_hw_camera_debug, and to_unready_state().

00078 {
00079   to_unready_state();
00080   _deallocate_buffers();
00081   if (mr1394_hw_camera_debug) {
00082       cout << "iidc_close: h=" << _handle << " iidc_state=" << _iidc_state_string()
00083            << endl;
00084   }
00085   iidc_close(_handle);
00086   long camera_index = _call_back_context.user_param;
00087   camera_table[camera_index] = NULL;
00088 }

Here is the call graph for this function:

Mr1394_Hw_Camera::Mr1394_Hw_Camera ( const GUID_1394 &  guid  ) 

Mr1394_Hw_Camera::~Mr1394_Hw_Camera (  ) 


Member Function Documentation

void Mr1394_Hw_Camera::get_all_camera_guids ( vector< GUID_1394 > &  guids  )  throw (exception) [static]

Definition at line 111 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References throw_claraty_exception.

Referenced by _init().

00113 {
00114   const long bufsize = 256;
00115   long stringsize;
00116   char buf[bufsize];
00117 
00118   guids.clear();
00119 
00120   long count = iidc_getcameracount();
00121   for ( int i = 0; i < count; ++i ) {
00122     stringsize = iidc_getstring( i, IIDCID_STRING_CAMERAID, buf, bufsize );
00123     buf[stringsize] = '\0';
00124     if ( stringsize == 0 ) {
00125       throw_claraty_exception("can't iidc_getstring");
00126     }
00127     // Parse the string.  We're assuming it is in the format
00128     // "0x0123456701234567"
00129     guids.push_back(GUID_1394::read_from_string(buf));
00130   }
00131 }

void Mr1394_Hw_Camera::display_id ( ostream &  out = cout  ) 

Definition at line 435 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _call_back_context, and throw_mr1394_camera_exception.

Referenced by display_state().

00436 {
00437   const int MAX_STR = 100;
00438   char str[MAX_STR+1];
00439   long cam_index = _call_back_context.user_param;
00440   long len = iidc_getstring(cam_index, IIDCID_STRING_CAMERAID, str, MAX_STR);
00441   if (len == 0) {
00442     throw_mr1394_camera_exception(*this, "can't iidc_getstring (1)");
00443   }
00444   str[len] = '\0';
00445   out << str;
00446   len = iidc_getstring(cam_index, IIDCID_STRING_VENDOR, str, MAX_STR);
00447   if (len == 0) {
00448     throw_mr1394_camera_exception(*this, "can't iidc_getstring (2)");
00449   }
00450   str[len] = '\0';
00451   out << " \"" << str << "\"";
00452   len = iidc_getstring(cam_index, IIDCID_STRING_MODEL, str, MAX_STR);
00453   if (len == 0) {
00454     throw_mr1394_camera_exception(*this, "can't iidc_getstring (3)");
00455   }
00456   str[len] = '\0';
00457   out << " \"" << str << "\"";
00458 }

void Mr1394_Hw_Camera::display_formats ( ostream &  out = cout  ) 

Definition at line 462 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, display_iidc_area(), display_iidc_format(), display_iidc_framerate_range(), and throw_mr1394_camera_exception.

00463 {
00464   long count = iidc_getformatcount(_handle);
00465   if (count == 0) {
00466     throw_mr1394_camera_exception(*this, "can't iidc_getformatcount");
00467   }
00468 
00469   long current_format_id = iidc_currentformat(_handle);
00470   if (current_format_id == 0) {
00471     throw_mr1394_camera_exception(*this, "can't iidc_getformatcount");
00472   }
00473 
00474   long idlist[count];
00475   if (iidc_getformatidlist(_handle, idlist, sizeof(idlist)) == 0) {
00476     throw_mr1394_camera_exception(*this, "can't iidc_getformatidlist");
00477   }
00478 
00479 
00480   IIDC_FORMATINFO info;
00481   for (int i = 0; i < count; ++i) {
00482     if (iidc_getformatinfo(_handle, &info, sizeof(info), idlist[i]) == 0) {
00483       throw_mr1394_camera_exception(*this, "can't iidc_getformatinfo");
00484     }
00485 
00486     if (current_format_id == idlist[i]) {
00487       out << "*";
00488     } else {
00489       out << " ";
00490     }
00491 
00492     if (display_iidc_format(out, info)) {
00493       IIDC_AREAINFO ainfo;
00494       if (iidc_getareainfo(_handle, &ainfo, sizeof(ainfo), idlist[i]) == 0) {
00495         throw_mr1394_camera_exception(*this, "can't iidc_getareainfo");
00496       }
00497       out << " ";
00498       display_iidc_area(out, ainfo);
00499     }
00500 
00501     if (info.capflags & iidcformat_capability_framerate) {
00502       IIDC_FRAMERATEINFO finfo;
00503       if (iidc_getframerateinfo(_handle, &finfo, sizeof(finfo),
00504                                 idlist[i]) == 0) {
00505         throw_mr1394_camera_exception(*this, "can't iidc_getframerateinfo");
00506       }
00507       out << "  ";
00508       display_iidc_framerate_range(out, finfo);
00509     }
00510     if (info.capflags & iidcformat_capability_lut) {
00511       out << " LUT";
00512     }
00513     out << endl;
00514   }
00515 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::display_state ( ostream &  out = cout  ) 

Definition at line 622 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _call_back_context, _handle, _iidc_state_string(), display_id(), display_iidc_area(), display_iidc_format(), and throw_mr1394_camera_exception.

00623 {
00624   out << "  Id: ";
00625   display_id(out);
00626   out << endl;
00627   IIDC_FORMATINFO info;
00628   if (iidc_getformatinfo(_handle, &info, sizeof(info),
00629                          IIDCID_FORMAT_CURRENT) == 0) {
00630     throw_mr1394_camera_exception(*this, "can't iidc_getformatinfo");
00631   }
00632   out << "  Format: ";
00633   if (display_iidc_format(out, info)) {
00634     IIDC_AREAINFO ainfo;
00635     if (iidc_getareainfo(_handle, &ainfo, sizeof(ainfo),
00636         IIDCID_FORMAT_CURRENT) == 0) {
00637       throw_mr1394_camera_exception(*this, "can't iidc_getareainfo");
00638     }
00639     out << " ";
00640     display_iidc_area(out, ainfo);
00641   }
00642   out << endl;
00643 
00644   IIDC_FRAMERATEINFO finfo;
00645   if (iidc_getframerateinfo(_handle, &finfo, sizeof(finfo),
00646                             IIDCID_FORMAT_CURRENT) == 0) {
00647     throw_mr1394_camera_exception(*this, "can't iidc_getframerateinfo");
00648   }
00649   float current_frame_rate = iidc_currentframerate(_handle);
00650   long cam_index = _call_back_context.user_param;
00651   long error_code = iidc_getlasterror(cam_index);
00652   if (current_frame_rate == 0.0 && error_code != IIDCERR_NOT_SUPPORT) {
00653     throw_mr1394_camera_exception(*this, "can't iidc_currentframerate");
00654   }
00655   out << "  FrameRate: " << current_frame_rate << endl;
00656   out << "  iidc_state: " << _iidc_state_string() << endl;
00657 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::display_capabilities ( ostream &  out = cout  ) 

Definition at line 597 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, display_capability(), and throw_mr1394_camera_exception.

00598 {
00599   bool was_shown = display_capability(out, _handle, IIDCID_FEATURE_BRIGHTNESS);
00600   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_AUTO_EXPOSURE);
00601   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_SHARPNESS);
00602   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_WHITE_BALANCE);
00603   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_HUE);
00604   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_SATURATION);
00605   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_GAMMA);
00606   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_SHUTTER);
00607   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_GAIN);
00608   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_IRIS);
00609   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_FOCUS);
00610   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_TEMPERATURE);
00611   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_TRIGGER);
00612   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_ZOOM);
00613   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_PAN);
00614   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_TILT);
00615   was_shown |= display_capability(out, _handle, IIDCID_FEATURE_OPTICAL_FILTER);
00616   if (!was_shown) {
00617     throw_mr1394_camera_exception(*this, "can't iidc_currentfeatureinfo");
00618   }
00619 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::to_video_state (  )  throw (exception)

Definition at line 1313 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _ready_sync_to_video_state(), _ready_unsync_to_sync_state(), _state, _unready_to_ready_sync_state(), CAMERA_STATE_READY_SYNC, CAMERA_STATE_READY_UNSYNC, CAMERA_STATE_UNREADY, CAMERA_STATE_VIDEO, and throw_claraty_exception.

01314 {
01315   switch(_state) {
01316   case CAMERA_STATE_UNREADY:
01317     _unready_to_ready_sync_state();
01318     _ready_sync_to_video_state();
01319     break;
01320   case CAMERA_STATE_READY_SYNC:
01321     _ready_sync_to_video_state();
01322     break;
01323   case CAMERA_STATE_READY_UNSYNC:
01324     _ready_unsync_to_sync_state();
01325     _ready_sync_to_video_state();
01326     break;
01327   case CAMERA_STATE_VIDEO:
01328     // Do nothing
01329     break;
01330   default:
01331     throw_claraty_exception("saw unknown state in _to_video_state");
01332   }
01333   _state = CAMERA_STATE_VIDEO;
01334 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::to_unready_state (  )  throw (exception)

Definition at line 1379 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _ready_sync_to_unready_state(), _ready_unsync_to_unready_state(), _state, _video_to_ready_sync_state(), CAMERA_STATE_READY_SYNC, CAMERA_STATE_READY_UNSYNC, CAMERA_STATE_UNREADY, CAMERA_STATE_VIDEO, and throw_claraty_exception.

Referenced by DMA_Slot::detach_camera(), and ~Mr1394_Hw_Camera().

01380 {
01381   switch(_state) {
01382   case CAMERA_STATE_UNREADY:
01383     // Do nothing
01384     break;
01385   case CAMERA_STATE_READY_SYNC:
01386     _ready_sync_to_unready_state();
01387     break;
01388   case CAMERA_STATE_READY_UNSYNC:
01389     _ready_unsync_to_unready_state();
01390     break;
01391   case CAMERA_STATE_VIDEO:
01392     _video_to_ready_sync_state();
01393     _ready_sync_to_unready_state();
01394     break;
01395   default:
01396     throw_claraty_exception("saw unknown state in _to_unready_state");
01397   }
01398   _state = CAMERA_STATE_UNREADY;
01399 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::to_ready_unsync_state (  )  throw (exception)

Definition at line 1357 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _ready_sync_to_unsync_state(), _state, _unready_to_ready_unsync_state(), _video_to_ready_sync_state(), CAMERA_STATE_READY_SYNC, CAMERA_STATE_READY_UNSYNC, CAMERA_STATE_UNREADY, CAMERA_STATE_VIDEO, and throw_claraty_exception.

01358 {
01359   switch(_state) {
01360   case CAMERA_STATE_UNREADY:
01361     _unready_to_ready_unsync_state();
01362     break;
01363   case CAMERA_STATE_READY_SYNC:
01364     _ready_sync_to_unsync_state();
01365     break;
01366   case CAMERA_STATE_READY_UNSYNC:
01367     // Do nothing
01368     break;
01369   case CAMERA_STATE_VIDEO:
01370     _video_to_ready_sync_state();
01371     _ready_sync_to_unsync_state();
01372     break;
01373   default:
01374     throw_claraty_exception("saw unknown state in _to_ready_unsync_state");
01375   }
01376   _state = CAMERA_STATE_READY_SYNC;
01377 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::to_ready_sync_state (  )  throw (exception)

Definition at line 1336 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _ready_unsync_to_sync_state(), _state, _unready_to_ready_sync_state(), _video_to_ready_sync_state(), CAMERA_STATE_READY_SYNC, CAMERA_STATE_READY_UNSYNC, CAMERA_STATE_UNREADY, CAMERA_STATE_VIDEO, and throw_claraty_exception.

01337 {
01338   switch(_state) {
01339   case CAMERA_STATE_UNREADY:
01340     _unready_to_ready_sync_state();
01341     break;
01342   case CAMERA_STATE_READY_SYNC:
01343     // Do nothing
01344     break;
01345   case CAMERA_STATE_READY_UNSYNC:
01346     _ready_unsync_to_sync_state();
01347     break;
01348   case CAMERA_STATE_VIDEO:
01349     _video_to_ready_sync_state();
01350     break;
01351   default:
01352     throw_claraty_exception("saw unknown state in _to_ready_sync_state");
01353   }
01354   _state = CAMERA_STATE_READY_SYNC;
01355 }

Here is the call graph for this function:

static void Mr1394_Hw_Camera::acquire_group ( std::vector< Mr1394_Hw_Camera * > &  cam_vec,
std::vector< Image_Uint8 > &  image_vec,
std::vector< Time * > *  timestamp_vec = NULL 
) throw (exception) [static]

void Mr1394_Hw_Camera::acquire ( Image_Uint8 image,
Time timestamp_ptr = NULL 
) throw (exception)

Definition at line 799 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References throw_mr1394_camera_exception.

Referenced by Mr1394_Camera::acquire().

00801 {
00802     to_ready_unsync_state();
00803     if (!iidc_capture(_handle, false)) {
00804         throw_mr1394_camera_exception(*this, "can't iidc_capture");
00805     }
00806     IIDC_WAIT wait_info;
00807     wait_info.event = iidcevent_captureend;
00808     wait_info.timeout = -1;  // wait forever
00809     if (!iidc_wait(_handle, &wait_info, sizeof(IIDC_WAIT))) {
00810         throw_mr1394_camera_exception(*this, "can't iidc_wait");
00811     }
00812     _get_recent_image(image);
00813 }

void Mr1394_Hw_Camera::acquire ( uint8_t *  data_ptr,
size_t  byte_count,
Time timestamp_ptr = NULL 
) throw (exception)

Definition at line 815 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References Mr1394_Hw_Camera::Image_Uint8::byte_count, and Mr1394_Hw_Camera::Image_Uint8::data_ptr.

00818 {
00819   Mr1394_Hw_Camera::Image_Uint8 image;
00820   image.data_ptr = data_ptr;
00821   image.byte_count = byte_count;
00822   acquire(image, timestamp_ptr);
00823 }

bool Mr1394_Hw_Camera::set_format ( long  color_coding,
int  desired_width,
int  desired_height 
) throw (exception)

Definition at line 148 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References is_better_width(), and throw_mr1394_camera_exception.

Referenced by _init().

00151 {
00152   /* color_coding is one of IIDCID_COLORCODING_MONO8,
00153                             IIDCID_COLORCODING_YUV411,
00154                             IIDCID_COLORCODING_YUV422,
00155                             IIDCID_COLORCODING_YUV444,
00156                             IIDCID_COLORCODING_RGB8,
00157                             IIDCID_COLORCODING_MONO16,
00158                             IIDCID_COLORCODING_RGB16 */
00159 
00160   const long format_count = iidc_getformatcount(_handle);
00161   if (format_count == 0) {
00162     throw_mr1394_camera_exception(*this, "can't iidc_getformatcount");
00163   }
00164   long idlist[format_count];
00165 
00166   if (!iidc_getformatidlist(_handle, idlist, sizeof(idlist))) {
00167     throw_mr1394_camera_exception(*this, "can't iidc_getformatidlist");
00168   }
00169 
00170   IIDC_FORMATINFO info;
00171   bool found = false;
00172   int best_width = (is_better_width(desired_width, 0, INT_MAX)) ? INT_MAX: 0;
00173   int best_height;
00174   long best_format;
00175 
00176   for (int i = 0; i < format_count; ++i) {
00177     if (!iidc_getformatinfo(_handle, &info, sizeof(info), idlist[i])) {
00178       throw_mr1394_camera_exception(*this, "can't iidc_getformatinfo");
00179     }
00180     if (info.colorcoding == color_coding &&
00181         !(info.capflags & iidcformat_capability_area) &&
00182         is_better_width(desired_width, info.width, best_width)) {
00183       best_width = info.width;
00184       best_height = info.height;
00185       best_format = idlist[i];
00186       found = true;
00187     }
00188   }
00189   if (mr1394_hw_camera_debug) {
00190       cout << "iidc_setformat " << best_format << ": h=" << _handle
00191            << " iidc_state=" << _iidc_state_string() << endl;
00192   }
00193   if (!iidc_setformat(_handle, best_format)) {
00194       throw_mr1394_camera_exception(*this, "can't iidc_setformat");
00195   }
00196   _pixel_width = best_width;
00197   _pixel_height = best_height;
00198   _image_format = color_coding;
00199   return found;
00200 }

Here is the call graph for this function:

Mr1394_Hw_Camera::Camera_Brand Mr1394_Hw_Camera::get_camera_brand (  )  const

Definition at line 251 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _call_back_context, and _get_camera_brand().

Referenced by set_frame_rate_and_shutter().

00252 {
00253   long cam_index = _call_back_context.user_param;
00254   return _get_camera_brand(cam_index);
00255 }

Here is the call graph for this function:

size_t Mr1394_Hw_Camera::get_pixel_width (  ) 

Definition at line 840 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _pixel_width.

Referenced by get_byte_width(), get_subframe_pixel_width(), and Mr1394_Camera::get_width().

00841 {
00842   return _pixel_width;
00843 }

size_t Mr1394_Hw_Camera::get_byte_width (  ) 

Definition at line 851 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _get_bits_per_pixel(), and get_pixel_width().

Referenced by get_subframe_byte_width().

00852 {
00853   return (get_pixel_width() * _get_bits_per_pixel()) / 8;
00854 }

Here is the call graph for this function:

size_t Mr1394_Hw_Camera::get_subframe_pixel_width (  ) 

Definition at line 845 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References get_pixel_width().

00846 {
00847   // No subframing implemented
00848   return get_pixel_width();
00849 }

Here is the call graph for this function:

size_t Mr1394_Hw_Camera::get_subframe_byte_width (  ) 

Definition at line 856 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References get_byte_width().

Referenced by _get_recent_image().

00857 {
00858   // No subframing implemented
00859   return get_byte_width();
00860 }

Here is the call graph for this function:

size_t Mr1394_Hw_Camera::get_height (  ) 

Definition at line 862 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _pixel_height.

Referenced by _get_recent_image(), and Mr1394_Camera::get_height().

00863 {
00864   return _pixel_height;
00865 }

size_t Mr1394_Hw_Camera::get_subframe_height (  ) 

long Mr1394_Hw_Camera::get_format (  )  const

Definition at line 202 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _image_format.

00203 {
00204   return _image_format;
00205 }

void Mr1394_Hw_Camera::lock (  )  [inline]

Definition at line 95 of file hw_mr1394_camera/mr1394_hw_camera.h.

References _camera_lock.

Referenced by DMA_Slot::wait_for_dma_slot(), and Mr1394_Camera::~Mr1394_Camera().

00095 { _camera_lock.acquire(); };

void Mr1394_Hw_Camera::unlock (  )  [inline]

Definition at line 96 of file hw_mr1394_camera/mr1394_hw_camera.h.

References _camera_lock.

Referenced by DMA_Slot::wait_for_dma_slot(), and Mr1394_Camera::~Mr1394_Camera().

00096 { _camera_lock.release(); };

bool Mr1394_Hw_Camera::set_frame_rate_and_shutter ( double  frame_rate_hertz,
double  shutter_period_seconds 
)

Definition at line 258 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References BRAND_DRAGONFLY, BRAND_GENERIC_PT_GREY, and get_camera_brand().

00260 { 
00261   // not implemented yet
00262   const Camera_Brand brand = get_camera_brand();
00263   if (brand == BRAND_GENERIC_PT_GREY || brand == BRAND_DRAGONFLY) {
00264   } else {
00265   }
00266   return false;
00267 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_callback_function ( long  camera_index,
HIIDC  h,
long  event,
long  lparam,
void *  pparam 
) [static, protected]

Definition at line 667 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _group_sem_ptr, _timestamp, callback_mutex, camera_table, and Mr1394_Hw_Camera().

Referenced by _init().

00672 {
00673   //ACE_OS::gettimeofday();
00674   // KLUDGE ALERT
00675 
00676 // IAN - use timers.h that is defined in the resource module to avoid any
00677 // OS specific code.
00678 
00679   struct timespec ts;
00680   clock_gettime(CLOCK_REALTIME, &ts);
00681   Time now = ts.tv_sec - 1158700000 + ((double)ts.tv_nsec / 1000000000.0);
00682 
00683   Mr1394_Hw_Camera* cam_ptr = camera_table[camera_index];
00684   Semaphore* group_sem_ptr = cam_ptr->_group_sem_ptr;
00685   callback_mutex.acquire();
00686   if (group_sem_ptr != NULL) {
00687     cam_ptr->_timestamp = now;
00688     group_sem_ptr->release();
00689   }
00690   callback_mutex.release();
00691 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_init ( const GUID_1394 &  guid  )  [protected]

Definition at line 269 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _call_back_context, _callback_function(), _camera_brand, _get_camera_brand(), _group_sem_ptr, _guid, _handle, _iidc_state_string(), _image_buf_count, _state, _timestamp, CAMERA_STATE_UNREADY, camera_table, check_for_module_init(), dma_slot_ptr, get_all_camera_guids(), MAX_1394_CAMERAS, set_format(), throw_claraty_exception, and throw_mr1394_camera_exception.

Referenced by Mr1394_Hw_Camera().

00270 {
00271   // the caller is asking to open a specific
00272   //   camera, so we'll try to find its index
00273 
00274   long camera_index;
00275   check_for_module_init();
00276         
00277   vector<GUID_1394> guids;
00278   get_all_camera_guids(guids);
00279 
00280   unsigned int i;
00281   for (i = 0; i < guids.size(); ++i) {
00282     if (guids[i] == guid) break;
00283   }
00284   if (i >= guids.size()) {
00285     ostringstream str;
00286     str << "in Mr1394_Hw_Camera constructor, no such GUID (" << guid << ")";
00287     throw_claraty_exception(str.str().c_str());
00288   }
00289 
00290   if (i > MAX_1394_CAMERAS) {
00291     throw_claraty_exception(
00292           "in Mr1394_Hw_Camera, MAX_1394_CAMERAS is too small");
00293   }
00294   if (camera_table[i] != NULL) {
00295     ostringstream str;
00296     str << "Mr1394_Hw_Camera with GUID " << guid
00297         << " has already been constructed";
00298     throw_claraty_exception(str.str().c_str());
00299   }
00300   camera_index = i;
00301 
00302   // At this point, camera_index will equal the index of the camera
00303   // we need to open.
00304 
00305   // Initialize all fields of the class.
00306 
00307   _guid = guid;
00308   _call_back_context.proc = _callback_function;
00309   _call_back_context.user_param = camera_index;
00310   _call_back_context.event_mask = iidcevent_dataframeend;
00311   _group_sem_ptr = NULL;
00312   _image_buf_count = 0;
00313   _state = CAMERA_STATE_UNREADY;
00314   _timestamp = 0.0;
00315   dma_slot_ptr = NULL;
00316 
00317   if (mr1394_hw_camera_debug) {
00318     cout << "iidc_open( " << camera_index << ") guid=" << guid
00319               << " iidc_state=" << _iidc_state_string() << endl;
00320   }
00321   _handle = iidc_open(camera_index);
00322   if (_handle == 0) {
00323     throw_mr1394_camera_exception(*this, "can't iidc_open");
00324   }
00325   _camera_brand = _get_camera_brand(_call_back_context.user_param);
00326 
00327   // UNSTABLE STATE
00328 
00329   if (!set_format(IIDCID_COLORCODING_MONO8, INT_MAX, INT_MAX)) {
00330       throw_mr1394_camera_exception(*this, "no mono8 format");
00331   }
00332 
00333   // IAN - add two member functions for 
00334   // set_frame_rate();
00335   // get_frame_rate();
00336   // this will give user control over this important parameter.
00337   // Set the framerate
00338   float actual_fps = iidc_setframerate( _handle, 3.75 );
00339   if( actual_fps == 0.0 ) {
00340     throw_mr1394_camera_exception(*this, "can't iidc_setframerate");
00341   }
00342 
00343   // Add this to the camera_table, so Mr1394_Hw_Camera can look
00344   // us up whenever an image is acquired.
00345 
00346   camera_table[camera_index] = this;
00347 
00348   if (mr1394_hw_camera_debug) {
00349       printf("leaving constructor: h=%d, iidc_state=%s\n",
00350              _handle, _iidc_state_string());
00351   }
00352 }

Here is the call graph for this function:

const char * Mr1394_Hw_Camera::_iidc_state_string (  )  const [protected]

Definition at line 895 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _call_back_context, and _handle.

Referenced by _attach_buffers(), _init(), _ready_sync_to_unready_state(), _ready_sync_to_unsync_state(), _ready_sync_to_video_state(), _ready_unsync_to_sync_state(), _ready_unsync_to_unready_state(), _unready_to_ready_sync_state(), _unready_to_ready_unsync_state(), _video_to_ready_sync_state(), display_state(), and ~Mr1394_Hw_Camera().

00896 {
00897   long error_code;
00898   if (_handle == 0)                     return "UNCONSTRUCTED";
00899   int iidc_state = iidc_getstatus(_handle);
00900   switch (iidc_state) {
00901     case iidcstatus_busy:               return "BUSY";
00902     case iidcstatus_ready:              return "READY";
00903     case iidcstatus_stable:             return "STABLE";
00904     case iidcstatus_unstable:           return "UNSTABLE";
00905     case 0:
00906       error_code = iidc_getlasterror(_call_back_context.user_param);
00907       switch (error_code) {
00908         case IIDCERR_INVALID_CAMERA:    return "INVALID_CAMERA";
00909         case IIDCERR_INVALID_PARAMETER: return "INVALID_PARAMETER";
00910         case IIDCERR_NOT_SUPPORT:       return "NOT_SUPPORTED";
00911         case 0:                         return "NO_ERROR???";
00912         default:                        return "UNEXPECTED_IIDCERR";
00913       }
00914     default:                            return "UNEXPECTED_STATE";
00915   }
00916 }

const char * Mr1394_Hw_Camera::_last_error_string (  )  const [protected]

Definition at line 923 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _call_back_context.

00924 {
00925   long camIndex = _call_back_context.user_param;
00926   long error = iidc_getlasterror(camIndex);
00927   switch (error)
00928   {
00929     case IIDCERR_INVALID_CAMERA:      return "Invalid camera handle";
00930     case IIDCERR_INVALID_PARAMETER:   return "Invalid parameter";
00931     case IIDCERR_INVALID_FORMATID:    return "Invalid format ID";
00932     case IIDCERR_INVALID_FEATUREID:   return "Invalid feature ID";
00933     case IIDCERR_INVALID_STRINGID:    return "Invalid string ID";
00934     case IIDCERR_INVALID_MESSAGEID:   return "Invalid message ID";
00935     case IIDCERR_INVALID_THREAD:      return "Invalid message thread";
00936     case IIDCERR_BUSY:                return "Camera in busy status";
00937     case IIDCERR_ABORT:               return "Operation aborted";
00938     case IIDCERR_TIMEOUT:             return "Timeout occured";
00939     case IIDCERR_NOT_BUSY:            return "Camera is not busy";
00940     case IIDCERR_NOT_READY:           return "Camera is not ready";
00941     case IIDCERR_NOT_STABLE:          return "Camera is not stable";
00942     case IIDCERR_NOT_UNSTABLE:        return "Camera is not unstable";
00943     case IIDCERR_ALREADY_OPENED:      return "Camera is already opened";
00944     case IIDCERR_ALREADY_LOCKING:     return "Frame is already locked";
00945     case IIDCERR_ALREADY_INITIALIZED: return "Library already initialized";
00946     case IIDCERR_NO_SUBMODULE:        return "No submodule";
00947     case IIDCERR_NO_RESOURCE:         return "Out of resources";
00948     case IIDCERR_NO_MEMORY:           return "Out of memory";
00949     case IIDCERR_NO_MODULE:           return "No module";
00950     case IIDCERR_NO_CAMERA:           return "No camera";
00951     case IIDCERR_UNREACH:             return "Camera unreachable";
00952     case IIDCERR_NOT_IMPLEMENT:       return "Not implemented";
00953     case IIDCERR_NOT_SUPPORT:         return "Not support";
00954     default:                          return "Unknown error";
00955   }
00956 }

Mr1394_Hw_Camera::Camera_Brand Mr1394_Hw_Camera::_get_camera_brand ( long  cam_index  )  const [protected]

Definition at line 209 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References BRAND_DRAGONFLY, BRAND_GENERIC_PT_GREY, BRAND_UNKNOWN, and throw_mr1394_camera_exception.

Referenced by _init(), and get_camera_brand().

00210 {
00211   const int MAX_STR = 100;
00212   char str[MAX_STR+1];
00213   long len = iidc_getstring(cam_index, IIDCID_STRING_CAMERAID, str, MAX_STR);
00214   if (len != 18) throw_mr1394_camera_exception(*this, "can't iidc_getstring");
00215   str[len] = '\0';
00216   if (str[0] != '0' || str[1] != 'x') {
00217     throw_mr1394_camera_exception(*this, "unrecognized iidc_getstring format");
00218   }
00219 
00220   // Parse the camera ID string.  Format is 0x0123456701234567.
00221 
00222   // High order 6 chars (3 bytes) represent the vendor id.
00223   char save_char = str[8];
00224   str[8] = '\0';
00225   unsigned long node_vendor_id;
00226   sscanf(str+2, "%lx", &node_vendor_id);
00227   str[8] = save_char;
00228 
00229   // Next 2 chars (1 byte) represent the high order part of the chip id.
00230   save_char = str[10];
00231   str[10] = '\0';
00232   unsigned long chip_id_hi;
00233   sscanf(str+8, "%lx", &chip_id_hi);
00234   str[10] = save_char;
00235 
00236   // Low order 8 chars (4 bytes) represent the low order part of the chip id.
00237   unsigned long chip_id_lo;
00238   sscanf(str+10, "%lx", &chip_id_lo);
00239 
00240   Mr1394_Hw_Camera::Camera_Brand brand = BRAND_UNKNOWN;
00241   if (node_vendor_id == 0x00B09DUL) {
00242     brand = BRAND_GENERIC_PT_GREY;
00243     if (chip_id_hi == 0x01UL && chip_id_lo == 0x00323438UL) {
00244       brand = BRAND_DRAGONFLY;
00245     }
00246   }
00247   return brand;
00248 }

size_t Mr1394_Hw_Camera::_get_bits_per_pixel (  )  const [protected]

Definition at line 825 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _image_format.

Referenced by get_byte_width().

00826 {
00827   switch (_image_format) {
00828   case IIDCID_COLORCODING_MONO8: return 8;
00829   case IIDCID_COLORCODING_YUV411: return 12;
00830   case IIDCID_COLORCODING_YUV422: return 16;
00831   case IIDCID_COLORCODING_YUV444: return 24;
00832   case IIDCID_COLORCODING_RGB8: return 24;
00833   case IIDCID_COLORCODING_MONO16: return 16;
00834   case IIDCID_COLORCODING_RGB16: return 48;
00835   }
00836   assert(false);
00837   return 0;
00838 }

void Mr1394_Hw_Camera::_unready_to_ready_sync_state (  )  throw (exception) [protected]

Definition at line 1173 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _attach_buffers(), _call_back_context, _handle, _iidc_state_string(), _MAX_IMG_BUFS, and throw_mr1394_camera_exception.

Referenced by _ready_unsync_to_sync_state(), to_ready_sync_state(), and to_video_state().

01174 {
01175     if (mr1394_hw_camera_debug) {
01176         printf("UNREADY ==> READY_SYNC  h=%d iidc_state=%s\n",
01177                _handle, _iidc_state_string());
01178     }
01179     _attach_buffers(_MAX_IMG_BUFS);
01180     if (iidc_setcallback(_handle, &_call_back_context, sizeof(IIDC_CALLBACK))
01181                                                                         == 0) {
01182         throw_mr1394_camera_exception(*this, "can't iidc_setcallback");
01183     }
01184 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_unready_to_ready_unsync_state (  )  throw (exception) [protected]

Definition at line 1152 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _attach_buffers(), _handle, and _iidc_state_string().

Referenced by _ready_sync_to_unsync_state(), and to_ready_unsync_state().

01153 {
01154 // IAN - why printf instead of cout?? With cout, we can overload 
01155     if (mr1394_hw_camera_debug) {
01156         printf("UNREADY ==> READY_UNSYNC  h=%d iidc_state=%s\n",
01157                _handle, _iidc_state_string());
01158     }
01159     _attach_buffers(1);
01160 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_ready_unsync_to_unready_state (  )  throw (exception) [protected]

Definition at line 1199 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, _iidc_state_string(), buffered_camera_count, and throw_mr1394_camera_exception.

Referenced by _ready_unsync_to_sync_state(), and to_unready_state().

01200 {
01201     if (mr1394_hw_camera_debug) {
01202         printf("READY UNSYNC ==> UNREADY  h=%d iidc_state=%s\n",
01203                _handle, _iidc_state_string());
01204     }
01205     if (!iidc_releasebuffer(_handle)) {
01206         throw_mr1394_camera_exception(*this, "can't iidc_releasebuffer");
01207     }
01208     --buffered_camera_count;
01209     if (!iidc_clearcapture(_handle)) {
01210         throw_mr1394_camera_exception(*this, "can't iidc_clearcapture");
01211     }
01212 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_ready_sync_to_unready_state (  )  throw (exception) [protected]

Definition at line 1227 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, _iidc_state_string(), buffered_camera_count, and throw_mr1394_camera_exception.

Referenced by _ready_sync_to_unsync_state(), and to_unready_state().

01228 {
01229     if (mr1394_hw_camera_debug) {
01230         printf("READY SYNC ==> UNREADY  h=%d iidc_state=%s\n",
01231                _handle, _iidc_state_string());
01232     }
01233     if (!iidc_cancelcallback(_handle)) {
01234         throw_mr1394_camera_exception(*this, "can't iidc_cancelcallback");
01235     }
01236     if (!iidc_releasebuffer(_handle)) {
01237         throw_mr1394_camera_exception(*this, "can't iidc_releasebuffer");
01238     }
01239     --buffered_camera_count;
01240     if (!iidc_clearcapture(_handle)) {
01241         throw_mr1394_camera_exception(*this, "can't iidc_clearcapture");
01242     }
01243     // UNSTABLE
01244 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_ready_unsync_to_sync_state (  )  throw (exception) [protected]

Definition at line 1252 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, _iidc_state_string(), _ready_unsync_to_unready_state(), and _unready_to_ready_sync_state().

Referenced by to_ready_sync_state(), and to_video_state().

01253 {
01254     if (mr1394_hw_camera_debug) {
01255         printf("READY UNSYNC ==> READY SYNC  h=%d iidc_state=%s\n",
01256                _handle, _iidc_state_string());
01257     }
01258     _ready_unsync_to_unready_state();
01259     _unready_to_ready_sync_state();
01260 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_ready_sync_to_unsync_state (  )  throw (exception) [protected]

Definition at line 1268 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, _iidc_state_string(), _ready_sync_to_unready_state(), and _unready_to_ready_unsync_state().

Referenced by to_ready_unsync_state().

01269 {
01270     if (mr1394_hw_camera_debug) {
01271         printf("READY SYNC ==> READY UNSYNC  h=%d iidc_state=%s\n",
01272                 _handle, _iidc_state_string());
01273     }
01274     _ready_sync_to_unready_state();
01275     _unready_to_ready_unsync_state();
01276 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_ready_sync_to_video_state (  )  throw (exception) [protected]

Definition at line 1288 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, _iidc_state_string(), and throw_claraty_exception.

Referenced by to_video_state().

01289 {
01290   if (mr1394_hw_camera_debug) {
01291       printf("READY SYNC ==> VIDEO  h=%d iidc_state=%s\n",
01292              _handle, _iidc_state_string());
01293   }
01294   if (!iidc_capture(_handle, true)) {
01295       throw_claraty_exception("can't iidc_capture");
01296   }
01297 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_video_to_ready_sync_state (  )  throw (exception) [protected]

Definition at line 1304 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, _iidc_state_string(), and throw_claraty_exception.

Referenced by to_ready_sync_state(), to_ready_unsync_state(), and to_unready_state().

01305 {
01306   if (mr1394_hw_camera_debug) {
01307       printf("VIDEO ==> READY SYNC  h=%d iidc_state=%s\n",
01308              _handle, _iidc_state_string());
01309   }
01310   if (!iidc_idle(_handle)) throw_claraty_exception("can't iidc_idle");
01311 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_get_recent_image ( Image_Uint8 image  )  [protected]

Definition at line 872 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, _image_buf_array, Mr1394_Hw_Camera::Image_Uint8::byte_count, Mr1394_Hw_Camera::Image_Uint8::data_ptr, get_height(), get_subframe_byte_width(), claraty::string_printf(), and throw_claraty_exception.

00873 {
00874     if (image.byte_count == 0) return;
00875     IIDC_TRANSFERINFO trans_info;
00876     iidc_gettransferinfo(_handle, &trans_info, sizeof(IIDC_TRANSFERINFO));
00877     int buf_index = trans_info.newest_frameindex;
00878     size_t required_byte_count = get_subframe_byte_width() * get_height();
00879     if (image.byte_count < required_byte_count) {
00880       throw_claraty_exception(string_printf(
00881           "acquire bad image size (%ld) on camera %s; expected %ld bytes",
00882           image.byte_count, this->_guid.write_to_string().c_str(),
00883           required_byte_count).c_str());
00884     }
00885     uint8_t * from = (uint8_t*)_image_buf_array[buf_index];
00886     memcpy(image.data_ptr, from, required_byte_count);
00887 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_attach_buffers ( int  buf_count  )  [protected]

Definition at line 976 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, _iidc_state_string(), _image_buf_array, _image_buf_count, _MAX_IMG_BUFS, buffered_camera_count, MAX_FRAME_BYTES, throw_claraty_exception, and throw_mr1394_camera_exception.

Referenced by _unready_to_ready_sync_state(), and _unready_to_ready_unsync_state().

00977 {
00978   if (_handle == 0) throw_claraty_exception("uninitialized handle");
00979   assert(iidc_getstatus(_handle) == iidcstatus_unstable);
00980   // UNSTABLE STATE
00981   if (mr1394_hw_camera_debug) {
00982     cout << "iidc_preparecapture: h=" << _handle << ", iidc_state="
00983               << _iidc_state_string() << endl;
00984   }
00985   if (!iidc_preparecapture(_handle)) {
00986     throw_mr1394_camera_exception(*this, "can't iidc_preparecapture");
00987   }
00988   // STABLE STATE
00989 
00990   // Get the buffer size associated with the current image format.
00991 
00992   // long byte_count = iidc_currentdataframebytes(_handle);
00993   long byte_count = MAX_FRAME_BYTES;
00994 
00995   // Allocate more image buffers if required.
00996 
00997   if (buf_count > _MAX_IMG_BUFS) buf_count = _MAX_IMG_BUFS;
00998   for (; _image_buf_count < buf_count; ++_image_buf_count) {
00999     _image_buf_array[_image_buf_count] = new uint8_t [byte_count];
01000     if (_image_buf_array[_image_buf_count] == NULL) break;
01001   }
01002   if (_image_buf_count < buf_count) {
01003     // Memory allocation problem
01004 
01005     if (mr1394_hw_camera_debug) {
01006       cout << "iidc_clearcapture: h=" << _handle << ", iidc_state="
01007            << _iidc_state_string() << endl;
01008     }
01009     iidc_clearcapture(_handle);
01010     // UNSTABLE STATE
01011     throw_claraty_exception("out of memory");
01012   }
01013 
01014   // Give control of the buffers to the driver.
01015 
01016   if (mr1394_hw_camera_debug) {
01017     cout << "iidc_attachbuffer: h=" << _handle << " buf_count=" << buf_count
01018          << " iidc_state=" << _iidc_state_string() << " _image_buf_array="
01019          << _image_buf_array << endl;
01020   }
01021 
01022   /* Only 4 cameras may be attached at one time.  However, iidc_attachbuffer
01023      does not check for this properly, and memory corruption occurs when
01024      you try to attach the 5th camera.  This is a bug confirmed by MindReady
01025      tech support.  Here we keep track of the number of cameras attached to
01026      avoid triggering this bad behavior.  Note that a semaphore is required
01027      to protect buffered_camera_count to make sure two cameras don't
01028      increment at the same time.
01029 
01030      The limitation is 4 cameras per MindReady IEEE1394 board, so adding
01031      more boards would get you more simultaneous cameras.  However, cameras
01032      attached to different boards would then not be synchronized.  MindReady
01033      tech support writes "There is no HW synchronization possible between
01034      the 2 cards. However, a software solution can be implemented based on
01035      a 1394 event (example a bus reset, a broadcast packet, ...). This
01036      solution required that the 2 cards are connected to the same 1394 bus."
01037   */
01038   //buffered_camera_count_mutex.acquire();
01039   if (buffered_camera_count > 3) {
01040     //buffered_camera_count_mutex.release();
01041     if (mr1394_hw_camera_debug) {
01042       cout << "iidc_clearcapture: h=" << _handle << ", iidc_state=" <<
01043              _iidc_state_string() << endl;
01044     }
01045     iidc_clearcapture(_handle);
01046     throw_claraty_exception("Only 4 cameras may be in simultaneous use.");
01047   }
01048   ++buffered_camera_count;
01049   //buffered_camera_count_mutex.release();
01050   
01051   if (iidc_attachbuffer(_handle, _image_buf_array,
01052                         buf_count * sizeof(unsigned char*)) != buf_count) {
01053     if (mr1394_hw_camera_debug) {
01054       cout << "iidc_clearcapture: h=" << _handle << ", iidc_state=" <<
01055              _iidc_state_string() << endl;
01056     }
01057     iidc_clearcapture(_handle);
01058     --buffered_camera_count;
01059     // UNSTABLE STATE
01060     throw_mr1394_camera_exception(*this, "can't iidc_attachbuffer");
01061   }
01062   if (mr1394_hw_camera_debug) {
01063     cout << "_attach_buffers attach: h=" << _handle << " iidc_state="
01064          << _iidc_state_string() << " buf_count=" << buf_count << endl;
01065     for (int i = 0; i < _image_buf_count; ++i) {
01066         cout << "buffer " << i << " = " << _image_buf_array[i] << endl;
01067     }
01068   }
01069   // READY STATE
01070 }

Here is the call graph for this function:

void Mr1394_Hw_Camera::_deallocate_buffers (  )  [protected]

Definition at line 1076 of file hw_mr1394_camera/mr1394_hw_camera.cc.

References _handle, _image_buf_array, and _image_buf_count.

Referenced by ~Mr1394_Hw_Camera().

01077 {
01078   // UNSTABLE STATE
01079   assert(iidc_getstatus(_handle) == iidcstatus_unstable);
01080   for (int i = 0; i < _image_buf_count; ++i) {
01081       delete [] (uint8_t*)_image_buf_array[i];
01082   }
01083   _image_buf_count = 0;
01084 }

static void Mr1394_Hw_Camera::get_all_camera_guids ( vector< GUID_1394 > &  guids  )  throw (exception) [static]

void Mr1394_Hw_Camera::display_id ( ostream &  out = cout  ) 

void Mr1394_Hw_Camera::display_formats ( ostream &  out = cout  ) 

void Mr1394_Hw_Camera::display_state ( ostream &  out = cout  ) 

void Mr1394_Hw_Camera::display_capabilities ( ostream &  out = cout  ) 

void Mr1394_Hw_Camera::to_video_state (  )  throw (exception)

void Mr1394_Hw_Camera::to_unready_state (  )  throw (exception)

void Mr1394_Hw_Camera::to_ready_unsync_state (  )  throw (exception)

void Mr1394_Hw_Camera::to_ready_sync_state (  )  throw (exception)

static void Mr1394_Hw_Camera::acquire_group ( std::vector< Mr1394_Hw_Camera * > &  cam_vec,
std::vector< Image_Uint8 > &  image_vec,
std::vector< Time * > *  timestamp_vec = NULL 
) throw (exception) [static]

void Mr1394_Hw_Camera::acquire ( Image_Uint8 image,
Time timestamp_ptr = NULL 
) throw (exception)

void Mr1394_Hw_Camera::acquire ( uint8_t *  data_ptr,
size_t  byte_count,
Time timestamp_ptr = NULL 
) throw (exception)

bool Mr1394_Hw_Camera::set_format ( long  color_coding,
int  desired_width,
int  desired_height 
) throw (exception)

Camera_Brand Mr1394_Hw_Camera::get_camera_brand (  )  const

size_t Mr1394_Hw_Camera::get_pixel_width (  ) 

size_t Mr1394_Hw_Camera::get_byte_width (  ) 

size_t Mr1394_Hw_Camera::get_subframe_pixel_width (  ) 

size_t Mr1394_Hw_Camera::get_subframe_byte_width (  ) 

size_t Mr1394_Hw_Camera::get_height (  ) 

size_t Mr1394_Hw_Camera::get_subframe_height (  ) 

long Mr1394_Hw_Camera::get_format (  )  const

void Mr1394_Hw_Camera::lock (  )  [inline]

Definition at line 79 of file mr1394_camera/mr1394_hw_camera.h.

References _camera_lock.

00079 { _camera_lock.acquire(); };

void Mr1394_Hw_Camera::unlock (  )  [inline]

Definition at line 80 of file mr1394_camera/mr1394_hw_camera.h.

References _camera_lock.

00080 { _camera_lock.release(); };

bool Mr1394_Hw_Camera::set_frame_rate_and_shutter ( double  frame_rate_hertz,
double  shutter_period_seconds 
)

static void Mr1394_Hw_Camera::_callback_function ( long  camera_index,
HIIDC  h,
long  event,
long  lparam,
void *  pparam 
) [static, protected]

void Mr1394_Hw_Camera::_init ( const GUID_1394 &  guid  )  [protected]

const char* Mr1394_Hw_Camera::_iidc_state_string (  )  const [protected]

const char* Mr1394_Hw_Camera::_last_error_string (  )  const [protected]

Camera_Brand Mr1394_Hw_Camera::_get_camera_brand ( long  cam_index  )  const [protected]

size_t Mr1394_Hw_Camera::_get_bits_per_pixel (  )  const [protected]

void Mr1394_Hw_Camera::_unready_to_ready_sync_state (  )  throw (exception) [protected]

void Mr1394_Hw_Camera::_unready_to_ready_unsync_state (  )  throw (exception) [protected]

void Mr1394_Hw_Camera::_ready_unsync_to_unready_state (  )  throw (exception) [protected]

void Mr1394_Hw_Camera::_ready_sync_to_unready_state (  )  throw (exception) [protected]

void Mr1394_Hw_Camera::_ready_unsync_to_sync_state (  )  throw (exception) [protected]

void Mr1394_Hw_Camera::_ready_sync_to_unsync_state (  )  throw (exception) [protected]

void Mr1394_Hw_Camera::_ready_sync_to_video_state (  )  throw (exception) [protected]

void Mr1394_Hw_Camera::_video_to_ready_sync_state (  )  throw (exception) [protected]

void Mr1394_Hw_Camera::_get_recent_image ( Image_Uint8 image  )  [protected]

void Mr1394_Hw_Camera::_attach_buffers ( int  buf_count  )  [protected]

void Mr1394_Hw_Camera::_deallocate_buffers (  )  [protected]


Member Data Documentation

static const int Mr1394_Hw_Camera::_MAX_IMG_BUFS = 3 [static, protected]

GUID_1394 Mr1394_Hw_Camera::_guid [protected]

Definition at line 134 of file hw_mr1394_camera/mr1394_hw_camera.h.

Referenced by _init().

Semaphore Mr1394_Hw_Camera::_camera_lock [protected]

Definition at line 135 of file hw_mr1394_camera/mr1394_hw_camera.h.

Referenced by lock(), and unlock().

Semaphore* Mr1394_Hw_Camera::_group_sem_ptr [protected]

Definition at line 136 of file hw_mr1394_camera/mr1394_hw_camera.h.

Referenced by _callback_function(), and _init().

Definition at line 137 of file hw_mr1394_camera/mr1394_hw_camera.h.

Referenced by _callback_function(), and _init().

Definition at line 138 of file hw_mr1394_camera/mr1394_hw_camera.h.

Referenced by _init().

Definition at line 141 of file hw_mr1394_camera/mr1394_hw_camera.h.

Referenced by get_pixel_width().

Definition at line 142 of file hw_mr1394_camera/mr1394_hw_camera.h.

Referenced by get_height().

Definition at line 143 of file hw_mr1394_camera/mr1394_hw_camera.h.

Referenced by _get_bits_per_pixel(), and get_format().

Semaphore* Mr1394_Hw_Camera::_group_sem_ptr [protected]

Definition at line 120 of file mr1394_camera/mr1394_hw_camera.h.


The documentation for this class was generated from the following files: